Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / audio / android / audio_manager_android.h
blobc64e6ee267de608aea7c3a0da25bd77c43acd980
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_
8 #include <set>
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"
16 namespace media {
18 class OpenSLESOutputStream;
20 // Android implemention of AudioManager.
21 class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase {
22 public:
23 AudioManagerAndroid(AudioLogFactory* audio_log_factory);
25 // Implementation of AudioManager.
26 bool HasAudioOutputDevices() override;
27 bool HasAudioInputDevices() override;
28 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override;
29 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override;
30 AudioParameters GetInputStreamParameters(
31 const std::string& device_id) override;
33 AudioOutputStream* MakeAudioOutputStream(
34 const AudioParameters& params,
35 const std::string& device_id) override;
36 AudioInputStream* MakeAudioInputStream(const AudioParameters& params,
37 const std::string& device_id) override;
38 void ReleaseOutputStream(AudioOutputStream* stream) override;
39 void ReleaseInputStream(AudioInputStream* stream) override;
41 // Implementation of AudioManagerBase.
42 AudioOutputStream* MakeLinearOutputStream(
43 const AudioParameters& params) override;
44 AudioOutputStream* MakeLowLatencyOutputStream(
45 const AudioParameters& params,
46 const std::string& device_id) override;
47 AudioInputStream* MakeLinearInputStream(
48 const AudioParameters& params,
49 const std::string& device_id) override;
50 AudioInputStream* MakeLowLatencyInputStream(
51 const AudioParameters& params,
52 const std::string& device_id) override;
54 static bool RegisterAudioManager(JNIEnv* env);
56 void SetMute(JNIEnv* env, jobject obj, jboolean muted);
58 // Sets a volume that applies to all this manager's output audio streams.
59 // This overrides other SetVolume calls (e.g. through AudioHostMsg_SetVolume).
60 void SetOutputVolumeOverride(double volume);
61 bool HasOutputVolumeOverride(double* out_volume) const;
63 protected:
64 ~AudioManagerAndroid() override;
66 AudioParameters GetPreferredOutputStreamParameters(
67 const std::string& output_device_id,
68 const AudioParameters& input_params) override;
70 private:
71 void InitializeOnAudioThread();
72 void ShutdownOnAudioThread();
74 bool HasNoAudioInputStreams();
75 void SetCommunicationAudioModeOn(bool on);
76 bool SetAudioDevice(const std::string& device_id);
77 int GetNativeOutputSampleRate();
78 bool IsAudioLowLatencySupported();
79 int GetAudioLowLatencyOutputFrameSize();
80 int GetOptimalOutputFrameSize(int sample_rate, int channels);
82 void DoSetMuteOnAudioThread(bool muted);
83 void DoSetVolumeOnAudioThread(double volume);
85 // Java AudioManager instance.
86 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_;
88 typedef std::set<OpenSLESOutputStream*> OutputStreams;
89 OutputStreams streams_;
91 // Enabled when first input stream is created and set to false when last
92 // input stream is destroyed. Also affects the stream type of output streams.
93 bool communication_mode_is_on_;
95 // If set, overrides volume level on output streams
96 bool output_volume_override_set_;
97 double output_volume_override_;
99 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid);
102 } // namespace media
104 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_