Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: media/audio/android/audio_manager_android.cc

Issue 99033003: Enable platform echo cancellation through the AudioRecord path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PlatformEffects, unittests and clean up. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 97 }
97 98
98 void AudioManagerAndroid::GetAudioOutputDeviceNames( 99 void AudioManagerAndroid::GetAudioOutputDeviceNames(
99 AudioDeviceNames* device_names) { 100 AudioDeviceNames* device_names) {
100 // TODO(henrika): enumerate using GetAudioInputDeviceNames(). 101 // TODO(henrika): enumerate using GetAudioInputDeviceNames().
101 AddDefaultDevice(device_names); 102 AddDefaultDevice(device_names);
102 } 103 }
103 104
104 AudioParameters AudioManagerAndroid::GetInputStreamParameters( 105 AudioParameters AudioManagerAndroid::GetInputStreamParameters(
105 const std::string& device_id) { 106 const std::string& device_id) {
107 JNIEnv* env = AttachCurrentThread();
106 // Use mono as preferred number of input channels on Android to save 108 // Use mono as preferred number of input channels on Android to save
107 // resources. Using mono also avoids a driver issue seen on Samsung 109 // resources. Using mono also avoids a driver issue seen on Samsung
108 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. 110 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details.
109 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; 111 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
110 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( 112 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize(
111 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), 113 env, GetNativeOutputSampleRate(),
112 ChannelLayoutToChannelCount(channel_layout)); 114 ChannelLayoutToChannelCount(channel_layout));
113 115
114 return AudioParameters( 116 AudioParameters params(
115 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, 117 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
116 GetNativeOutputSampleRate(), 16, 118 GetNativeOutputSampleRate(), 16,
117 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size); 119 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size);
120
121 AudioParameters::PlatformEffects effects;
122 effects.echo_canceller =
123 Java_AudioManagerAndroid_shouldUseAcousticEchoCanceler(env);
124 params.SetPlatformEffects(effects);
125 return params;
118 } 126 }
119 127
120 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( 128 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream(
121 const AudioParameters& params, 129 const AudioParameters& params,
122 const std::string& device_id, 130 const std::string& device_id,
123 const std::string& input_device_id) { 131 const std::string& input_device_id) {
124 AudioOutputStream* stream = 132 AudioOutputStream* stream =
125 AudioManagerBase::MakeAudioOutputStream(params, std::string(), 133 AudioManagerBase::MakeAudioOutputStream(params, std::string(),
126 std::string()); 134 std::string());
127 if (stream && output_stream_count() == 1) { 135 if (stream && output_stream_count() == 1) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 190
183 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( 191 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream(
184 const AudioParameters& params, const std::string& device_id) { 192 const AudioParameters& params, const std::string& device_id) {
185 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 193 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
186 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; 194 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!";
187 // Utilize the device ID to select the correct input device. 195 // Utilize the device ID to select the correct input device.
188 // Note that the input device is always associated with a certain output 196 // Note that the input device is always associated with a certain output
189 // device, i.e., this selection does also switch the output device. 197 // device, i.e., this selection does also switch the output device.
190 // All input and output streams will be affected by the device selection. 198 // All input and output streams will be affected by the device selection.
191 SetAudioDevice(device_id); 199 SetAudioDevice(device_id);
200
201 if (params.effects().echo_canceller) {
202 // Platform effects can only be enabled through the AudioRecord path.
203 // An effect should only have been requested here if recommended by
204 // AudioManagerAndroid.shouldUse<Effect>.
205 //
206 // Creating this class requires Jelly Bean, which is already guaranteed by
207 // shouldUse<Effect>. Only DCHECK on that condition to allow tests to use
208 // the effect settings as a way to select the input path.
209 DCHECK_GE(base::android::BuildInfo::GetInstance()->sdk_int(), 16);
210 DVLOG(1) << "Creating AudioRecordInputStream";
211 return new AudioRecordInputStream(this, params);
212 }
213 DVLOG(1) << "Creating OpenSLESInputStream";
192 return new OpenSLESInputStream(this, params); 214 return new OpenSLESInputStream(this, params);
193 } 215 }
194 216
195 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, 217 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate,
196 int channels) { 218 int channels) {
197 if (IsAudioLowLatencySupported()) { 219 if (IsAudioLowLatencySupported()) {
198 return GetAudioLowLatencyOutputFrameSize(); 220 return GetAudioLowLatencyOutputFrameSize();
199 } else { 221 } else {
200 return std::max(kDefaultOutputBufferSize, 222 return std::max(kDefaultOutputBufferSize,
201 Java_AudioManagerAndroid_getMinOutputFrameSize( 223 Java_AudioManagerAndroid_getMinOutputFrameSize(
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 j_audio_manager_.obj()); 321 j_audio_manager_.obj());
300 } 322 }
301 323
302 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { 324 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() {
303 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( 325 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize(
304 base::android::AttachCurrentThread(), 326 base::android::AttachCurrentThread(),
305 j_audio_manager_.obj()); 327 j_audio_manager_.obj());
306 } 328 }
307 329
308 } // namespace media 330 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698