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

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: Fixed all unit tests 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 29 matching lines...) Expand all
60 void SetMute(JNIEnv* env, jobject obj, jboolean muted); 64 void SetMute(JNIEnv* env, jobject obj, jboolean muted);
61 65
62 protected: 66 protected:
63 virtual ~AudioManagerAndroid(); 67 virtual ~AudioManagerAndroid();
64 68
65 virtual AudioParameters GetPreferredOutputStreamParameters( 69 virtual AudioParameters GetPreferredOutputStreamParameters(
66 const std::string& output_device_id, 70 const std::string& output_device_id,
67 const AudioParameters& input_params) OVERRIDE; 71 const AudioParameters& input_params) OVERRIDE;
68 72
69 private: 73 private:
70 bool HadNoAudioStreams(); 74 // Implementation of MessageLoop::DestructionObserver.
75 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
76
77 void CreateAndInitOnAudioThread();
78 void DoCreateAndInitOnAudioThread(base::WaitableEvent* event);
79 void CloseOnAudioThread();
80
81 bool HasNoAudioStreams();
71 void Init(); 82 void Init();
72 void Close(); 83 void Close();
73 void SetCommunicationAudioModeOn(bool on); 84 void SetCommunicationAudioModeOn(bool on);
74 bool SetAudioDevice(const std::string& device_id); 85 bool SetAudioDevice(const std::string& device_id);
75 int GetNativeOutputSampleRate(); 86 int GetNativeOutputSampleRate();
76 bool IsAudioLowLatencySupported(); 87 bool IsAudioLowLatencySupported();
77 int GetAudioLowLatencyOutputFrameSize(); 88 int GetAudioLowLatencyOutputFrameSize();
78 int GetOptimalOutputFrameSize(int sample_rate, int channels); 89 int GetOptimalOutputFrameSize(int sample_rate, int channels);
79 90
91 void GetAudioInputDeviceNamesOnAudioThread(
92 base::WaitableEvent* event, AudioDeviceNames* device_names);
80 void DoSetMuteOnAudioThread(bool muted); 93 void DoSetMuteOnAudioThread(bool muted);
81 94
82 // Allow the AudioAndroidTest to access private methods.
83 FRIEND_TEST_ALL_PREFIXES(AudioAndroidOutputTest, IsAudioLowLatencySupported);
84
85 // Java AudioManager instance. 95 // Java AudioManager instance.
86 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_; 96 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_;
87 97
88 typedef std::set<OpenSLESOutputStream*> OutputStreams; 98 typedef std::set<OpenSLESOutputStream*> OutputStreams;
89 OutputStreams streams_; 99 OutputStreams streams_;
90 // TODO(wjia): remove this lock once unit test modules are fixed to call 100 // TODO(wjia): remove this lock once unit test modules are fixed to call
91 // AudioManager::MakeAudioOutputStream on the audio thread. For now, this 101 // AudioManager::MakeAudioOutputStream on the audio thread. For now, this
92 // lock is used to guard access to |streams_|. 102 // lock is used to guard access to |streams_|.
93 base::Lock streams_lock_; 103 base::Lock streams_lock_;
94 104
95 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid); 105 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid);
96 }; 106 };
97 107
98 } // namespace media 108 } // namespace media
99 109
100 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 110 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698