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 #include "media/audio/android/audio_manager_android.h" | 5 #include "media/audio/android/audio_manager_android.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "jni/AudioManagerAndroid_jni.h" | 8 #include "jni/AudioManagerAndroid_jni.h" |
9 #include "media/audio/android/opensles_input.h" | 9 #include "media/audio/android/opensles_input.h" |
10 #include "media/audio/android/opensles_output.h" | 10 #include "media/audio/android/opensles_output.h" |
11 #include "media/audio/audio_manager.h" | 11 #include "media/audio/audio_manager.h" |
12 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
13 #include "media/audio/audio_util.h" | 13 #include "media/audio/audio_util.h" |
14 #include "media/audio/fake_audio_input_stream.h" | 14 #include "media/audio/fake_audio_input_stream.h" |
15 #include "media/base/channel_layout.h" | 15 #include "media/base/channel_layout.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
| 19 static void AddDefaultDevice(AudioDeviceNames* device_names) { |
| 20 DCHECK(device_names->empty()); |
| 21 device_names->push_front( |
| 22 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, |
| 23 AudioManagerBase::kDefaultDeviceId)); |
| 24 } |
| 25 |
19 // Maximum number of output streams that can be open simultaneously. | 26 // Maximum number of output streams that can be open simultaneously. |
20 static const int kMaxOutputStreams = 10; | 27 static const int kMaxOutputStreams = 10; |
21 | 28 |
22 static const int kAudioModeNormal = 0x00000000; | 29 static const int kAudioModeNormal = 0x00000000; |
23 static const int kAudioModeInCommunication = 0x00000003; | 30 static const int kAudioModeInCommunication = 0x00000003; |
24 | 31 |
25 static const int kDefaultInputBufferSize = 1024; | 32 static const int kDefaultInputBufferSize = 1024; |
26 static const int kDefaultOutputBufferSize = 2048; | 33 static const int kDefaultOutputBufferSize = 2048; |
27 | 34 |
28 AudioManager* CreateAudioManager() { | 35 AudioManager* CreateAudioManager() { |
(...skipping 15 matching lines...) Expand all Loading... |
44 | 51 |
45 bool AudioManagerAndroid::HasAudioOutputDevices() { | 52 bool AudioManagerAndroid::HasAudioOutputDevices() { |
46 return true; | 53 return true; |
47 } | 54 } |
48 | 55 |
49 bool AudioManagerAndroid::HasAudioInputDevices() { | 56 bool AudioManagerAndroid::HasAudioInputDevices() { |
50 return true; | 57 return true; |
51 } | 58 } |
52 | 59 |
53 void AudioManagerAndroid::GetAudioInputDeviceNames( | 60 void AudioManagerAndroid::GetAudioInputDeviceNames( |
54 media::AudioDeviceNames* device_names) { | 61 AudioDeviceNames* device_names) { |
55 DCHECK(device_names->empty()); | 62 AddDefaultDevice(device_names); |
56 device_names->push_front( | 63 } |
57 media::AudioDeviceName(kDefaultDeviceName, kDefaultDeviceId)); | 64 |
| 65 void AudioManagerAndroid::GetAudioOutputDeviceNames( |
| 66 AudioDeviceNames* device_names) { |
| 67 AddDefaultDevice(device_names); |
58 } | 68 } |
59 | 69 |
60 AudioParameters AudioManagerAndroid::GetInputStreamParameters( | 70 AudioParameters AudioManagerAndroid::GetInputStreamParameters( |
61 const std::string& device_id) { | 71 const std::string& device_id) { |
62 // Use mono as preferred number of input channels on Android to save | 72 // Use mono as preferred number of input channels on Android to save |
63 // resources. Using mono also avoids a driver issue seen on Samsung | 73 // resources. Using mono also avoids a driver issue seen on Samsung |
64 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. | 74 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. |
65 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; | 75 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; |
66 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( | 76 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( |
67 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), | 77 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), |
(...skipping 15 matching lines...) Expand all Loading... |
83 if (stream && output_stream_count() == 1) { | 93 if (stream && output_stream_count() == 1) { |
84 SetAudioMode(kAudioModeInCommunication); | 94 SetAudioMode(kAudioModeInCommunication); |
85 RegisterHeadsetReceiver(); | 95 RegisterHeadsetReceiver(); |
86 } | 96 } |
87 return stream; | 97 return stream; |
88 } | 98 } |
89 | 99 |
90 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( | 100 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( |
91 const AudioParameters& params, const std::string& device_id) { | 101 const AudioParameters& params, const std::string& device_id) { |
92 AudioInputStream* stream = | 102 AudioInputStream* stream = |
93 AudioManagerBase::MakeAudioInputStream(params, device_id); | 103 AudioManagerBase::MakeAudioInputStream(params, device_id); |
94 return stream; | 104 return stream; |
95 } | 105 } |
96 | 106 |
97 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) { | 107 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) { |
98 AudioManagerBase::ReleaseOutputStream(stream); | 108 AudioManagerBase::ReleaseOutputStream(stream); |
99 if (!output_stream_count()) { | 109 if (!output_stream_count()) { |
100 UnregisterHeadsetReceiver(); | 110 UnregisterHeadsetReceiver(); |
101 SetAudioMode(kAudioModeNormal); | 111 SetAudioMode(kAudioModeNormal); |
102 } | 112 } |
103 } | 113 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 j_audio_manager_.obj()); | 219 j_audio_manager_.obj()); |
210 } | 220 } |
211 | 221 |
212 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { | 222 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { |
213 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( | 223 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( |
214 base::android::AttachCurrentThread(), | 224 base::android::AttachCurrentThread(), |
215 j_audio_manager_.obj()); | 225 j_audio_manager_.obj()); |
216 } | 226 } |
217 | 227 |
218 } // namespace media | 228 } // namespace media |
OLD | NEW |