Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: media/audio/android/audio_manager_android.h

Issue 131503006: Initialization of audio manager for Android is now done on the audio thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 5 #ifndef MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
6 #define MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 6 #define MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/message_loop/message_loop.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/synchronization/waitable_event.h"
13 #include "media/audio/audio_manager_base.h" 15 #include "media/audio/audio_manager_base.h"
14 16
15 namespace media { 17 namespace media {
16 18
17 class OpenSLESOutputStream; 19 class OpenSLESOutputStream;
18 20
19 // Android implemention of AudioManager. 21 // Android implemention of AudioManager.
20 class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase { 22 class MEDIA_EXPORT AudioManagerAndroid
23 : public AudioManagerBase,
24 public base::MessageLoop::DestructionObserver {
21 public: 25 public:
22 AudioManagerAndroid(AudioLogFactory* audio_log_factory); 26 AudioManagerAndroid(AudioLogFactory* audio_log_factory);
23 27
24 // Implementation of AudioManager. 28 // Implementation of AudioManager.
25 virtual bool HasAudioOutputDevices() OVERRIDE; 29 virtual bool HasAudioOutputDevices() OVERRIDE;
26 virtual bool HasAudioInputDevices() OVERRIDE; 30 virtual bool HasAudioInputDevices() OVERRIDE;
27 virtual void GetAudioInputDeviceNames( 31 virtual void GetAudioInputDeviceNames(
28 AudioDeviceNames* device_names) OVERRIDE; 32 AudioDeviceNames* device_names) OVERRIDE;
29 virtual void GetAudioOutputDeviceNames( 33 virtual void GetAudioOutputDeviceNames(
30 AudioDeviceNames* device_names) OVERRIDE; 34 AudioDeviceNames* device_names) OVERRIDE;
(...skipping 27 matching lines...) Expand all
58 void SetMute(JNIEnv* env, jobject obj, jboolean muted); 62 void SetMute(JNIEnv* env, jobject obj, jboolean muted);
59 63
60 protected: 64 protected:
61 virtual ~AudioManagerAndroid(); 65 virtual ~AudioManagerAndroid();
62 66
63 virtual AudioParameters GetPreferredOutputStreamParameters( 67 virtual AudioParameters GetPreferredOutputStreamParameters(
64 const std::string& output_device_id, 68 const std::string& output_device_id,
65 const AudioParameters& input_params) OVERRIDE; 69 const AudioParameters& input_params) OVERRIDE;
66 70
67 private: 71 private:
68 bool HadNoAudioStreams(); 72 // Implementation of MessageLoop::DestructionObserver.
73 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
74
75 void CreateAndInitOnAudioThread();
76 void CloseOnAudioThread();
77
78 bool HasNoAudioStreams();
69 void Init(); 79 void Init();
70 void Close(); 80 void Close();
71 void SetCommunicationAudioModeOn(bool on); 81 void SetCommunicationAudioModeOn(bool on);
72 bool SetAudioDevice(const std::string& device_id); 82 bool SetAudioDevice(const std::string& device_id);
73 int GetNativeOutputSampleRate(); 83 int GetNativeOutputSampleRate();
74 bool IsAudioLowLatencySupported(); 84 bool IsAudioLowLatencySupported();
75 int GetAudioLowLatencyOutputFrameSize(); 85 int GetAudioLowLatencyOutputFrameSize();
76 int GetOptimalOutputFrameSize(int sample_rate, int channels); 86 int GetOptimalOutputFrameSize(int sample_rate, int channels);
77 87
78 void DoSetMuteOnAudioThread(bool muted); 88 void DoSetMuteOnAudioThread(bool muted);
79 89
80 // Allow the AudioAndroidTest to access private methods.
81 FRIEND_TEST_ALL_PREFIXES(AudioAndroidOutputTest, IsAudioLowLatencySupported);
82
83 // Java AudioManager instance. 90 // Java AudioManager instance.
84 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_; 91 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_;
85 92
86 typedef std::set<OpenSLESOutputStream*> OutputStreams; 93 typedef std::set<OpenSLESOutputStream*> OutputStreams;
87 OutputStreams streams_; 94 OutputStreams streams_;
88 // TODO(wjia): remove this lock once unit test modules are fixed to call
89 // AudioManager::MakeAudioOutputStream on the audio thread. For now, this
90 // lock is used to guard access to |streams_|.
91 base::Lock streams_lock_;
92 95
93 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid); 96 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid);
94 }; 97 };
95 98
96 } // namespace media 99 } // namespace media
97 100
98 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 101 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698