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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int effects = AudioParameters::NO_EFFECTS; |
114 return AudioParameters( | 116 effects |= Java_AudioManagerAndroid_shouldUseAcousticEchoCanceler(env) ? |
115 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 117 AudioParameters::ECHO_CANCELLER : AudioParameters::NO_EFFECTS; |
| 118 AudioParameters params( |
| 119 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, 0, |
116 GetNativeOutputSampleRate(), 16, | 120 GetNativeOutputSampleRate(), 16, |
117 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size); | 121 buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size, effects); |
| 122 return params; |
118 } | 123 } |
119 | 124 |
120 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( | 125 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( |
121 const AudioParameters& params, | 126 const AudioParameters& params, |
122 const std::string& device_id, | 127 const std::string& device_id, |
123 const std::string& input_device_id) { | 128 const std::string& input_device_id) { |
124 AudioOutputStream* stream = | 129 AudioOutputStream* stream = |
125 AudioManagerBase::MakeAudioOutputStream(params, std::string(), | 130 AudioManagerBase::MakeAudioOutputStream(params, std::string(), |
126 std::string()); | 131 std::string()); |
127 if (stream && output_stream_count() == 1) { | 132 if (stream && output_stream_count() == 1) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 187 |
183 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( | 188 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( |
184 const AudioParameters& params, const std::string& device_id) { | 189 const AudioParameters& params, const std::string& device_id) { |
185 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 190 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
186 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; | 191 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; |
187 // Utilize the device ID to select the correct input device. | 192 // Utilize the device ID to select the correct input device. |
188 // Note that the input device is always associated with a certain output | 193 // Note that the input device is always associated with a certain output |
189 // device, i.e., this selection does also switch the output device. | 194 // device, i.e., this selection does also switch the output device. |
190 // All input and output streams will be affected by the device selection. | 195 // All input and output streams will be affected by the device selection. |
191 SetAudioDevice(device_id); | 196 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"; |
192 return new OpenSLESInputStream(this, params); | 211 return new OpenSLESInputStream(this, params); |
193 } | 212 } |
194 | 213 |
195 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, | 214 int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate, |
196 int channels) { | 215 int channels) { |
197 if (IsAudioLowLatencySupported()) { | 216 if (IsAudioLowLatencySupported()) { |
198 return GetAudioLowLatencyOutputFrameSize(); | 217 return GetAudioLowLatencyOutputFrameSize(); |
199 } else { | 218 } else { |
200 return std::max(kDefaultOutputBufferSize, | 219 return std::max(kDefaultOutputBufferSize, |
201 Java_AudioManagerAndroid_getMinOutputFrameSize( | 220 Java_AudioManagerAndroid_getMinOutputFrameSize( |
(...skipping 21 matching lines...) Expand all Loading... |
223 buffer_size = GetOptimalOutputFrameSize( | 242 buffer_size = GetOptimalOutputFrameSize( |
224 sample_rate, ChannelLayoutToChannelCount(channel_layout)); | 243 sample_rate, ChannelLayoutToChannelCount(channel_layout)); |
225 } | 244 } |
226 | 245 |
227 int user_buffer_size = GetUserBufferSize(); | 246 int user_buffer_size = GetUserBufferSize(); |
228 if (user_buffer_size) | 247 if (user_buffer_size) |
229 buffer_size = user_buffer_size; | 248 buffer_size = user_buffer_size; |
230 | 249 |
231 return AudioParameters( | 250 return AudioParameters( |
232 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, | 251 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
233 sample_rate, bits_per_sample, buffer_size); | 252 sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); |
234 } | 253 } |
235 | 254 |
236 // static | 255 // static |
237 bool AudioManagerAndroid::RegisterAudioManager(JNIEnv* env) { | 256 bool AudioManagerAndroid::RegisterAudioManager(JNIEnv* env) { |
238 return RegisterNativesImpl(env); | 257 return RegisterNativesImpl(env); |
239 } | 258 } |
240 | 259 |
241 void AudioManagerAndroid::Init() { | 260 void AudioManagerAndroid::Init() { |
242 Java_AudioManagerAndroid_init( | 261 Java_AudioManagerAndroid_init( |
243 base::android::AttachCurrentThread(), | 262 base::android::AttachCurrentThread(), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 j_audio_manager_.obj()); | 318 j_audio_manager_.obj()); |
300 } | 319 } |
301 | 320 |
302 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { | 321 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { |
303 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( | 322 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( |
304 base::android::AttachCurrentThread(), | 323 base::android::AttachCurrentThread(), |
305 j_audio_manager_.obj()); | 324 j_audio_manager_.obj()); |
306 } | 325 } |
307 | 326 |
308 } // namespace media | 327 } // namespace media |
OLD | NEW |