| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 AudioParameters AudioManagerAndroid::GetInputStreamParameters( | 104 AudioParameters AudioManagerAndroid::GetInputStreamParameters( |
| 104 const std::string& device_id) { | 105 const std::string& device_id) { |
| 105 // Use mono as preferred number of input channels on Android to save | 106 // Use mono as preferred number of input channels on Android to save |
| 106 // resources. Using mono also avoids a driver issue seen on Samsung | 107 // resources. Using mono also avoids a driver issue seen on Samsung |
| 107 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. | 108 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. |
| 108 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; | 109 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; |
| 109 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( | 110 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( |
| 110 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), | 111 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), |
| 111 ChannelLayoutToChannelCount(channel_layout)); | 112 ChannelLayoutToChannelCount(channel_layout)); |
| 112 | 113 |
| 113 return AudioParameters( | 114 AudioParameters params( |
| 114 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 115 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 115 GetNativeOutputSampleRate(), 16, | 116 GetNativeOutputSampleRate(), 16, |
| 116 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size); | 117 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size); |
| 118 params.set_use_platform_aec(Java_AudioManagerAndroid_isPlatformAECSupported( |
| 119 base::android::AttachCurrentThread())); |
| 120 return params; |
| 117 } | 121 } |
| 118 | 122 |
| 119 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( | 123 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( |
| 120 const AudioParameters& params, | 124 const AudioParameters& params, |
| 121 const std::string& device_id, | 125 const std::string& device_id, |
| 122 const std::string& input_device_id) { | 126 const std::string& input_device_id) { |
| 123 AudioOutputStream* stream = | 127 AudioOutputStream* stream = |
| 124 AudioManagerBase::MakeAudioOutputStream(params, std::string(), | 128 AudioManagerBase::MakeAudioOutputStream(params, std::string(), |
| 125 std::string()); | 129 std::string()); |
| 126 if (stream && output_stream_count() == 1) { | 130 if (stream && output_stream_count() == 1) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 177 |
| 174 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( | 178 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( |
| 175 const AudioParameters& params, const std::string& device_id) { | 179 const AudioParameters& params, const std::string& device_id) { |
| 176 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 180 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 177 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; | 181 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; |
| 178 // Utilize the device ID to select the correct input device. | 182 // Utilize the device ID to select the correct input device. |
| 179 // Note that the input device is always associated with a certain output | 183 // Note that the input device is always associated with a certain output |
| 180 // device, i.e., this selection does also switch the output device. | 184 // device, i.e., this selection does also switch the output device. |
| 181 // All input and output streams will be affected by the device selection. | 185 // All input and output streams will be affected by the device selection. |
| 182 SetAudioDevice(device_id); | 186 SetAudioDevice(device_id); |
| 183 return new OpenSLESInputStream(this, params); | 187 if (params.use_platform_aec()) { |
| 188 // The platform AEC can only be enabled through the AudioRecord path. |
| 189 DVLOG(1) << "Creating AudioRecordInputStream"; |
| 190 return new AudioRecordInputStream(this, params); |
| 191 } else { |
| 192 DVLOG(1) << "Creating OpenSLESInputStream"; |
| 193 return new OpenSLESInputStream(this, params); |
| 194 } |
| 184 } | 195 } |
| 185 | 196 |
| 186 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, | 197 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, |
| 187 int channels) { | 198 int channels) { |
| 188 if (IsAudioLowLatencySupported()) { | 199 if (IsAudioLowLatencySupported()) { |
| 189 return GetAudioLowLatencyOutputFrameSize(); | 200 return GetAudioLowLatencyOutputFrameSize(); |
| 190 } else { | 201 } else { |
| 191 return std::max(kDefaultOutputBufferSize, | 202 return std::max(kDefaultOutputBufferSize, |
| 192 Java_AudioManagerAndroid_getMinOutputFrameSize( | 203 Java_AudioManagerAndroid_getMinOutputFrameSize( |
| 193 base::android::AttachCurrentThread(), | 204 base::android::AttachCurrentThread(), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 j_audio_manager_.obj()); | 284 j_audio_manager_.obj()); |
| 274 } | 285 } |
| 275 | 286 |
| 276 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { | 287 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { |
| 277 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( | 288 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( |
| 278 base::android::AttachCurrentThread(), | 289 base::android::AttachCurrentThread(), |
| 279 j_audio_manager_.obj()); | 290 j_audio_manager_.obj()); |
| 280 } | 291 } |
| 281 | 292 |
| 282 } // namespace media | 293 } // namespace media |
| OLD | NEW |