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

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

Issue 110303003: Revert 240548 "Enable platform echo cancellation through the Aud..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
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"
15 #include "media/audio/android/opensles_input.h" 14 #include "media/audio/android/opensles_input.h"
16 #include "media/audio/android/opensles_output.h" 15 #include "media/audio/android/opensles_output.h"
17 #include "media/audio/audio_manager.h" 16 #include "media/audio/audio_manager.h"
18 #include "media/audio/audio_parameters.h" 17 #include "media/audio/audio_parameters.h"
19 #include "media/audio/fake_audio_input_stream.h" 18 #include "media/audio/fake_audio_input_stream.h"
20 #include "media/base/channel_layout.h" 19 #include "media/base/channel_layout.h"
21 20
22 using base::android::AppendJavaStringArrayToStringVector; 21 using base::android::AppendJavaStringArrayToStringVector;
23 using base::android::AttachCurrentThread; 22 using base::android::AttachCurrentThread;
24 using base::android::ConvertJavaStringToUTF8; 23 using base::android::ConvertJavaStringToUTF8;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 96 }
98 97
99 void AudioManagerAndroid::GetAudioOutputDeviceNames( 98 void AudioManagerAndroid::GetAudioOutputDeviceNames(
100 AudioDeviceNames* device_names) { 99 AudioDeviceNames* device_names) {
101 // TODO(henrika): enumerate using GetAudioInputDeviceNames(). 100 // TODO(henrika): enumerate using GetAudioInputDeviceNames().
102 AddDefaultDevice(device_names); 101 AddDefaultDevice(device_names);
103 } 102 }
104 103
105 AudioParameters AudioManagerAndroid::GetInputStreamParameters( 104 AudioParameters AudioManagerAndroid::GetInputStreamParameters(
106 const std::string& device_id) { 105 const std::string& device_id) {
107 JNIEnv* env = AttachCurrentThread();
108 // 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
109 // resources. Using mono also avoids a driver issue seen on Samsung 107 // resources. Using mono also avoids a driver issue seen on Samsung
110 // 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.
111 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; 109 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
112 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( 110 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize(
113 env, GetNativeOutputSampleRate(), 111 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(),
114 ChannelLayoutToChannelCount(channel_layout)); 112 ChannelLayoutToChannelCount(channel_layout));
115 int effects = AudioParameters::NO_EFFECTS; 113
116 effects |= Java_AudioManagerAndroid_shouldUseAcousticEchoCanceler(env) ? 114 return AudioParameters(
117 AudioParameters::ECHO_CANCELLER : AudioParameters::NO_EFFECTS; 115 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
118 AudioParameters params(
119 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, 0,
120 GetNativeOutputSampleRate(), 16, 116 GetNativeOutputSampleRate(), 16,
121 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size, effects); 117 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size);
122 return params;
123 } 118 }
124 119
125 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( 120 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream(
126 const AudioParameters& params, 121 const AudioParameters& params,
127 const std::string& device_id, 122 const std::string& device_id,
128 const std::string& input_device_id) { 123 const std::string& input_device_id) {
129 AudioOutputStream* stream = 124 AudioOutputStream* stream =
130 AudioManagerBase::MakeAudioOutputStream(params, std::string(), 125 AudioManagerBase::MakeAudioOutputStream(params, std::string(),
131 std::string()); 126 std::string());
132 if (stream && output_stream_count() == 1) { 127 if (stream && output_stream_count() == 1) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 182
188 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( 183 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream(
189 const AudioParameters& params, const std::string& device_id) { 184 const AudioParameters& params, const std::string& device_id) {
190 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 185 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
191 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; 186 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!";
192 // Utilize the device ID to select the correct input device. 187 // Utilize the device ID to select the correct input device.
193 // Note that the input device is always associated with a certain output 188 // Note that the input device is always associated with a certain output
194 // device, i.e., this selection does also switch the output device. 189 // device, i.e., this selection does also switch the output device.
195 // All input and output streams will be affected by the device selection. 190 // All input and output streams will be affected by the device selection.
196 SetAudioDevice(device_id); 191 SetAudioDevice(device_id);
197
198 if (params.effects() != AudioParameters::NO_EFFECTS) {
199 // Platform effects can only be enabled through the AudioRecord path.
200 // An effect should only have been requested here if recommended by
201 // AudioManagerAndroid.shouldUse<Effect>.
202 //
203 // Creating this class requires Jelly Bean, which is already guaranteed by
204 // shouldUse<Effect>. Only DCHECK on that condition to allow tests to use
205 // the effect settings as a way to select the input path.
206 DCHECK_GE(base::android::BuildInfo::GetInstance()->sdk_int(), 16);
207 DVLOG(1) << "Creating AudioRecordInputStream";
208 return new AudioRecordInputStream(this, params);
209 }
210 DVLOG(1) << "Creating OpenSLESInputStream";
211 return new OpenSLESInputStream(this, params); 192 return new OpenSLESInputStream(this, params);
212 } 193 }
213 194
214 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, 195 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate,
215 int channels) { 196 int channels) {
216 if (IsAudioLowLatencySupported()) { 197 if (IsAudioLowLatencySupported()) {
217 return GetAudioLowLatencyOutputFrameSize(); 198 return GetAudioLowLatencyOutputFrameSize();
218 } else { 199 } else {
219 return std::max(kDefaultOutputBufferSize, 200 return std::max(kDefaultOutputBufferSize,
220 Java_AudioManagerAndroid_getMinOutputFrameSize( 201 Java_AudioManagerAndroid_getMinOutputFrameSize(
(...skipping 21 matching lines...) Expand all
242 buffer_size = GetOptimalOutputFrameSize( 223 buffer_size = GetOptimalOutputFrameSize(
243 sample_rate, ChannelLayoutToChannelCount(channel_layout)); 224 sample_rate, ChannelLayoutToChannelCount(channel_layout));
244 } 225 }
245 226
246 int user_buffer_size = GetUserBufferSize(); 227 int user_buffer_size = GetUserBufferSize();
247 if (user_buffer_size) 228 if (user_buffer_size)
248 buffer_size = user_buffer_size; 229 buffer_size = user_buffer_size;
249 230
250 return AudioParameters( 231 return AudioParameters(
251 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, 232 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
252 sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); 233 sample_rate, bits_per_sample, buffer_size);
253 } 234 }
254 235
255 // static 236 // static
256 bool AudioManagerAndroid::RegisterAudioManager(JNIEnv* env) { 237 bool AudioManagerAndroid::RegisterAudioManager(JNIEnv* env) {
257 return RegisterNativesImpl(env); 238 return RegisterNativesImpl(env);
258 } 239 }
259 240
260 void AudioManagerAndroid::Init() { 241 void AudioManagerAndroid::Init() {
261 Java_AudioManagerAndroid_init( 242 Java_AudioManagerAndroid_init(
262 base::android::AttachCurrentThread(), 243 base::android::AttachCurrentThread(),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 j_audio_manager_.obj()); 299 j_audio_manager_.obj());
319 } 300 }
320 301
321 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { 302 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() {
322 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( 303 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize(
323 base::android::AttachCurrentThread(), 304 base::android::AttachCurrentThread(),
324 j_audio_manager_.obj()); 305 j_audio_manager_.obj());
325 } 306 }
326 307
327 } // namespace media 308 } // namespace media
OLDNEW
« no previous file with comments | « trunk/src/media/audio/android/audio_manager_android.h ('k') | trunk/src/media/audio/android/audio_record_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698