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.
5 #ifndef MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
6 #define MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
10 #include "base/android/jni_android.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/synchronization/lock.h"
13 #include "media/audio/audio_manager_base.h"
17 class OpenSLESOutputStream
;
19 // Android implemention of AudioManager.
20 class MEDIA_EXPORT AudioManagerAndroid
: public AudioManagerBase
{
22 AudioManagerAndroid(AudioLogFactory
* audio_log_factory
);
24 // Implementation of AudioManager.
25 virtual bool HasAudioOutputDevices() OVERRIDE
;
26 virtual bool HasAudioInputDevices() OVERRIDE
;
27 virtual void GetAudioInputDeviceNames(
28 AudioDeviceNames
* device_names
) OVERRIDE
;
29 virtual void GetAudioOutputDeviceNames(
30 AudioDeviceNames
* device_names
) OVERRIDE
;
31 virtual AudioParameters
GetInputStreamParameters(
32 const std::string
& device_id
) OVERRIDE
;
34 virtual AudioOutputStream
* MakeAudioOutputStream(
35 const AudioParameters
& params
,
36 const std::string
& device_id
) OVERRIDE
;
37 virtual AudioInputStream
* MakeAudioInputStream(
38 const AudioParameters
& params
,
39 const std::string
& device_id
) OVERRIDE
;
40 virtual void ReleaseOutputStream(AudioOutputStream
* stream
) OVERRIDE
;
41 virtual void ReleaseInputStream(AudioInputStream
* stream
) OVERRIDE
;
43 // Implementation of AudioManagerBase.
44 virtual AudioOutputStream
* MakeLinearOutputStream(
45 const AudioParameters
& params
) OVERRIDE
;
46 virtual AudioOutputStream
* MakeLowLatencyOutputStream(
47 const AudioParameters
& params
,
48 const std::string
& device_id
) OVERRIDE
;
49 virtual AudioInputStream
* MakeLinearInputStream(
50 const AudioParameters
& params
,
51 const std::string
& device_id
) OVERRIDE
;
52 virtual AudioInputStream
* MakeLowLatencyInputStream(
53 const AudioParameters
& params
,
54 const std::string
& device_id
) OVERRIDE
;
56 static bool RegisterAudioManager(JNIEnv
* env
);
58 void SetMute(JNIEnv
* env
, jobject obj
, jboolean muted
);
61 virtual ~AudioManagerAndroid();
63 virtual AudioParameters
GetPreferredOutputStreamParameters(
64 const std::string
& output_device_id
,
65 const AudioParameters
& input_params
) OVERRIDE
;
68 bool HadNoAudioStreams();
71 void SetCommunicationAudioModeOn(bool on
);
72 bool SetAudioDevice(const std::string
& device_id
);
73 int GetNativeOutputSampleRate();
74 bool IsAudioLowLatencySupported();
75 int GetAudioLowLatencyOutputFrameSize();
76 int GetOptimalOutputFrameSize(int sample_rate
, int channels
);
78 void DoSetMuteOnAudioThread(bool muted
);
80 // Allow the AudioAndroidTest to access private methods.
81 FRIEND_TEST_ALL_PREFIXES(AudioAndroidOutputTest
, IsAudioLowLatencySupported
);
83 // Java AudioManager instance.
84 base::android::ScopedJavaGlobalRef
<jobject
> j_audio_manager_
;
86 typedef std::set
<OpenSLESOutputStream
*> OutputStreams
;
87 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_
;
93 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid
);
98 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_