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/android/build_info.h" | 7 #include "base/android/build_info.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "jni/AudioManagerAndroid_jni.h" | 13 #include "jni/AudioManagerAndroid_jni.h" |
14 #include "media/audio/android/audio_record_input.h" | |
14 #include "media/audio/android/opensles_input.h" | 15 #include "media/audio/android/opensles_input.h" |
15 #include "media/audio/android/opensles_output.h" | 16 #include "media/audio/android/opensles_output.h" |
16 #include "media/audio/audio_manager.h" | 17 #include "media/audio/audio_manager.h" |
17 #include "media/audio/audio_parameters.h" | 18 #include "media/audio/audio_parameters.h" |
18 #include "media/audio/fake_audio_input_stream.h" | 19 #include "media/audio/fake_audio_input_stream.h" |
19 #include "media/base/channel_layout.h" | 20 #include "media/base/channel_layout.h" |
20 | 21 |
21 using base::android::AppendJavaStringArrayToStringVector; | 22 using base::android::AppendJavaStringArrayToStringVector; |
22 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
23 using base::android::ConvertJavaStringToUTF8; | 24 using base::android::ConvertJavaStringToUTF8; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 AudioParameters AudioManagerAndroid::GetInputStreamParameters( | 105 AudioParameters AudioManagerAndroid::GetInputStreamParameters( |
105 const std::string& device_id) { | 106 const std::string& device_id) { |
106 // Use mono as preferred number of input channels on Android to save | 107 // Use mono as preferred number of input channels on Android to save |
107 // resources. Using mono also avoids a driver issue seen on Samsung | 108 // resources. Using mono also avoids a driver issue seen on Samsung |
108 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. | 109 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. |
109 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; | 110 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; |
110 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( | 111 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( |
111 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), | 112 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), |
112 ChannelLayoutToChannelCount(channel_layout)); | 113 ChannelLayoutToChannelCount(channel_layout)); |
113 | 114 |
114 return AudioParameters( | 115 AudioParameters params( |
115 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 116 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
116 GetNativeOutputSampleRate(), 16, | 117 GetNativeOutputSampleRate(), 16, |
117 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size); | 118 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size); |
119 params.set_use_platform_aec(Java_AudioManagerAndroid_isPlatformAECSupported( | |
120 base::android::AttachCurrentThread())); | |
henrika (OOO until Aug 14)
2013/12/06 22:51:57
Any chance you would consider following the exampl
ajm
2013/12/10 06:37:16
Absolutely :)
| |
121 return params; | |
118 } | 122 } |
119 | 123 |
120 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( | 124 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( |
121 const AudioParameters& params, | 125 const AudioParameters& params, |
122 const std::string& device_id, | 126 const std::string& device_id, |
123 const std::string& input_device_id) { | 127 const std::string& input_device_id) { |
124 AudioOutputStream* stream = | 128 AudioOutputStream* stream = |
125 AudioManagerBase::MakeAudioOutputStream(params, std::string(), | 129 AudioManagerBase::MakeAudioOutputStream(params, std::string(), |
126 std::string()); | 130 std::string()); |
127 if (stream && output_stream_count() == 1) { | 131 if (stream && output_stream_count() == 1) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 | 186 |
183 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( | 187 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( |
184 const AudioParameters& params, const std::string& device_id) { | 188 const AudioParameters& params, const std::string& device_id) { |
185 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 189 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
186 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; | 190 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; |
187 // Utilize the device ID to select the correct input device. | 191 // Utilize the device ID to select the correct input device. |
188 // Note that the input device is always associated with a certain output | 192 // Note that the input device is always associated with a certain output |
189 // device, i.e., this selection does also switch the output device. | 193 // device, i.e., this selection does also switch the output device. |
190 // All input and output streams will be affected by the device selection. | 194 // All input and output streams will be affected by the device selection. |
191 SetAudioDevice(device_id); | 195 SetAudioDevice(device_id); |
192 return new OpenSLESInputStream(this, params); | 196 if (params.use_platform_aec()) { |
197 // The platform AEC can only be enabled through the AudioRecord path. | |
198 DVLOG(1) << "Creating AudioRecordInputStream"; | |
199 return new AudioRecordInputStream(this, params); | |
200 } else { | |
201 DVLOG(1) << "Creating OpenSLESInputStream"; | |
202 return new OpenSLESInputStream(this, params); | |
203 } | |
193 } | 204 } |
194 | 205 |
195 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, | 206 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, |
196 int channels) { | 207 int channels) { |
197 if (IsAudioLowLatencySupported()) { | 208 if (IsAudioLowLatencySupported()) { |
198 return GetAudioLowLatencyOutputFrameSize(); | 209 return GetAudioLowLatencyOutputFrameSize(); |
199 } else { | 210 } else { |
200 return std::max(kDefaultOutputBufferSize, | 211 return std::max(kDefaultOutputBufferSize, |
201 Java_AudioManagerAndroid_getMinOutputFrameSize( | 212 Java_AudioManagerAndroid_getMinOutputFrameSize( |
202 base::android::AttachCurrentThread(), | 213 base::android::AttachCurrentThread(), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 j_audio_manager_.obj()); | 310 j_audio_manager_.obj()); |
300 } | 311 } |
301 | 312 |
302 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { | 313 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { |
303 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( | 314 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( |
304 base::android::AttachCurrentThread(), | 315 base::android::AttachCurrentThread(), |
305 j_audio_manager_.obj()); | 316 j_audio_manager_.obj()); |
306 } | 317 } |
307 | 318 |
308 } // namespace media | 319 } // namespace media |
OLD | NEW |