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 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 6 #define MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 7 8 #include <set> 9 10 #include "base/android/jni_android.h" 11 #include "base/gtest_prod_util.h" 12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/waitable_event.h" 14 #include "media/audio/audio_manager_base.h" 15 16 namespace media { 17 18 class OpenSLESOutputStream; 19 20 // Android implemention of AudioManager. 21 class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase { 22 public: 23 AudioManagerAndroid(AudioLogFactory* audio_log_factory); 24 25 // Implementation of AudioManager. 26 virtual bool HasAudioOutputDevices() OVERRIDE; 27 virtual bool HasAudioInputDevices() OVERRIDE; 28 virtual void GetAudioInputDeviceNames( 29 AudioDeviceNames* device_names) OVERRIDE; 30 virtual void GetAudioOutputDeviceNames( 31 AudioDeviceNames* device_names) OVERRIDE; 32 virtual AudioParameters GetInputStreamParameters( 33 const std::string& device_id) OVERRIDE; 34 35 virtual AudioOutputStream* MakeAudioOutputStream( 36 const AudioParameters& params, 37 const std::string& device_id) OVERRIDE; 38 virtual AudioInputStream* MakeAudioInputStream( 39 const AudioParameters& params, 40 const std::string& device_id) OVERRIDE; 41 virtual void ReleaseOutputStream(AudioOutputStream* stream) OVERRIDE; 42 virtual void ReleaseInputStream(AudioInputStream* stream) OVERRIDE; 43 44 // Implementation of AudioManagerBase. 45 virtual AudioOutputStream* MakeLinearOutputStream( 46 const AudioParameters& params) OVERRIDE; 47 virtual AudioOutputStream* MakeLowLatencyOutputStream( 48 const AudioParameters& params, 49 const std::string& device_id) OVERRIDE; 50 virtual AudioInputStream* MakeLinearInputStream( 51 const AudioParameters& params, 52 const std::string& device_id) OVERRIDE; 53 virtual AudioInputStream* MakeLowLatencyInputStream( 54 const AudioParameters& params, 55 const std::string& device_id) OVERRIDE; 56 57 static bool RegisterAudioManager(JNIEnv* env); 58 59 void SetMute(JNIEnv* env, jobject obj, jboolean muted); 60 61 protected: 62 virtual ~AudioManagerAndroid(); 63 64 virtual AudioParameters GetPreferredOutputStreamParameters( 65 const std::string& output_device_id, 66 const AudioParameters& input_params) OVERRIDE; 67 68 private: 69 void InitializeOnAudioThread(); 70 void ShutdownOnAudioThread(); 71 72 bool HasNoAudioInputStreams(); 73 void SetCommunicationAudioModeOn(bool on); 74 bool SetAudioDevice(const std::string& device_id); 75 int GetNativeOutputSampleRate(); 76 bool IsAudioLowLatencySupported(); 77 int GetAudioLowLatencyOutputFrameSize(); 78 int GetOptimalOutputFrameSize(int sample_rate, int channels); 79 80 void DoSetMuteOnAudioThread(bool muted); 81 82 // Java AudioManager instance. 83 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_; 84 85 typedef std::set<OpenSLESOutputStream*> OutputStreams; 86 OutputStreams streams_; 87 88 // Enabled when first input stream is created and set to false when last 89 // input stream is destroyed. Also affects the stream type of output streams. 90 bool communication_mode_is_on_; 91 92 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid); 93 }; 94 95 } // namespace media 96 97 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 98