| OLD | NEW |
| 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 Loading... |
| 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: |
| 74 // Implementation of MessageLoop::DestructionObserver. |
| 75 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 76 |
| 70 bool HadNoAudioStreams(); | 77 bool HadNoAudioStreams(); |
| 71 void Init(); | 78 void Init(); |
| 72 void Close(); | 79 void Close(); |
| 73 void SetCommunicationAudioModeOn(bool on); | 80 void SetCommunicationAudioModeOn(bool on); |
| 74 bool SetAudioDevice(const std::string& device_id); | 81 bool SetAudioDevice(const std::string& device_id); |
| 75 int GetNativeOutputSampleRate(); | 82 int GetNativeOutputSampleRate(); |
| 76 bool IsAudioLowLatencySupported(); | 83 bool IsAudioLowLatencySupported(); |
| 77 int GetAudioLowLatencyOutputFrameSize(); | 84 int GetAudioLowLatencyOutputFrameSize(); |
| 78 int GetOptimalOutputFrameSize(int sample_rate, int channels); | 85 int GetOptimalOutputFrameSize(int sample_rate, int channels); |
| 79 | 86 |
| 87 void InitializeOnAudioThread(); |
| 88 void CloseOnAudioThread(); |
| 89 void GetAudioInputDeviceNamesOnAudioThread( |
| 90 base::WaitableEvent* event, AudioDeviceNames* device_names); |
| 80 void DoSetMuteOnAudioThread(bool muted); | 91 void DoSetMuteOnAudioThread(bool muted); |
| 81 | 92 |
| 82 // Allow the AudioAndroidTest to access private methods. | 93 // Allow the AudioAndroidTest to access private methods. |
| 83 FRIEND_TEST_ALL_PREFIXES(AudioAndroidOutputTest, IsAudioLowLatencySupported); | 94 FRIEND_TEST_ALL_PREFIXES(AudioAndroidOutputTest, IsAudioLowLatencySupported); |
| 84 | 95 |
| 85 // Java AudioManager instance. | 96 // Java AudioManager instance. |
| 86 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_; | 97 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_; |
| 87 | 98 |
| 88 typedef std::set<OpenSLESOutputStream*> OutputStreams; | 99 typedef std::set<OpenSLESOutputStream*> OutputStreams; |
| 89 OutputStreams streams_; | 100 OutputStreams streams_; |
| 90 // TODO(wjia): remove this lock once unit test modules are fixed to call | 101 // TODO(wjia): remove this lock once unit test modules are fixed to call |
| 91 // AudioManager::MakeAudioOutputStream on the audio thread. For now, this | 102 // AudioManager::MakeAudioOutputStream on the audio thread. For now, this |
| 92 // lock is used to guard access to |streams_|. | 103 // lock is used to guard access to |streams_|. |
| 93 base::Lock streams_lock_; | 104 base::Lock streams_lock_; |
| 105 bool initialized_on_audio_thread_; |
| 94 | 106 |
| 95 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid); | 107 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid); |
| 96 }; | 108 }; |
| 97 | 109 |
| 98 } // namespace media | 110 } // namespace media |
| 99 | 111 |
| 100 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ | 112 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ |
| OLD | NEW |