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/context_utils.h" | 8 #include "base/android/context_utils.h" |
9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 buffer_size = user_buffer_size; | 156 buffer_size = user_buffer_size; |
157 | 157 |
158 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 158 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
159 GetNativeOutputSampleRate(), 16, buffer_size); | 159 GetNativeOutputSampleRate(), 16, buffer_size); |
160 params.set_effects(effects); | 160 params.set_effects(effects); |
161 return params; | 161 return params; |
162 } | 162 } |
163 | 163 |
164 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( | 164 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( |
165 const AudioParameters& params, | 165 const AudioParameters& params, |
166 const std::string& device_id, | 166 const std::string& device_id) { |
167 const LogCallback& log_callback) { | |
168 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 167 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
169 AudioOutputStream* stream = AudioManagerBase::MakeAudioOutputStream( | 168 AudioOutputStream* stream = |
170 params, std::string(), AudioManager::LogCallback()); | 169 AudioManagerBase::MakeAudioOutputStream(params, std::string()); |
171 streams_.insert(static_cast<OpenSLESOutputStream*>(stream)); | 170 streams_.insert(static_cast<OpenSLESOutputStream*>(stream)); |
172 return stream; | 171 return stream; |
173 } | 172 } |
174 | 173 |
175 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( | 174 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( |
176 const AudioParameters& params, | 175 const AudioParameters& params, const std::string& device_id) { |
177 const std::string& device_id, | |
178 const LogCallback& log_callback) { | |
179 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 176 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
180 bool has_no_input_streams = HasNoAudioInputStreams(); | 177 bool has_no_input_streams = HasNoAudioInputStreams(); |
181 AudioInputStream* stream = AudioManagerBase::MakeAudioInputStream( | 178 AudioInputStream* stream = |
182 params, device_id, AudioManager::LogCallback()); | 179 AudioManagerBase::MakeAudioInputStream(params, device_id); |
183 | 180 |
184 // The audio manager for Android creates streams intended for real-time | 181 // The audio manager for Android creates streams intended for real-time |
185 // VoIP sessions and therefore sets the audio mode to MODE_IN_COMMUNICATION. | 182 // VoIP sessions and therefore sets the audio mode to MODE_IN_COMMUNICATION. |
186 // If a Bluetooth headset is used, the audio stream will use the SCO | 183 // If a Bluetooth headset is used, the audio stream will use the SCO |
187 // channel and therefore have a limited bandwidth (8kHz). | 184 // channel and therefore have a limited bandwidth (8kHz). |
188 if (stream && has_no_input_streams) { | 185 if (stream && has_no_input_streams) { |
189 communication_mode_is_on_ = true; | 186 communication_mode_is_on_ = true; |
190 SetCommunicationAudioModeOn(true); | 187 SetCommunicationAudioModeOn(true); |
191 } | 188 } |
192 return stream; | 189 return stream; |
(...skipping 12 matching lines...) Expand all Loading... |
205 | 202 |
206 // Restore the audio mode which was used before the first communication- | 203 // Restore the audio mode which was used before the first communication- |
207 // mode stream was created. | 204 // mode stream was created. |
208 if (HasNoAudioInputStreams()) { | 205 if (HasNoAudioInputStreams()) { |
209 communication_mode_is_on_ = false; | 206 communication_mode_is_on_ = false; |
210 SetCommunicationAudioModeOn(false); | 207 SetCommunicationAudioModeOn(false); |
211 } | 208 } |
212 } | 209 } |
213 | 210 |
214 AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream( | 211 AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream( |
215 const AudioParameters& params, | 212 const AudioParameters& params) { |
216 const LogCallback& log_callback) { | |
217 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 213 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
218 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 214 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
219 return new OpenSLESOutputStream(this, params, SL_ANDROID_STREAM_MEDIA); | 215 return new OpenSLESOutputStream(this, params, SL_ANDROID_STREAM_MEDIA); |
220 } | 216 } |
221 | 217 |
222 AudioOutputStream* AudioManagerAndroid::MakeLowLatencyOutputStream( | 218 AudioOutputStream* AudioManagerAndroid::MakeLowLatencyOutputStream( |
223 const AudioParameters& params, | 219 const AudioParameters& params, |
224 const std::string& device_id, | 220 const std::string& device_id) { |
225 const LogCallback& log_callback) { | |
226 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; | 221 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; |
227 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 222 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
228 | 223 |
229 // Set stream type which matches the current system-wide audio mode used by | 224 // Set stream type which matches the current system-wide audio mode used by |
230 // the Android audio manager. | 225 // the Android audio manager. |
231 const SLint32 stream_type = communication_mode_is_on_ ? | 226 const SLint32 stream_type = communication_mode_is_on_ ? |
232 SL_ANDROID_STREAM_VOICE : SL_ANDROID_STREAM_MEDIA; | 227 SL_ANDROID_STREAM_VOICE : SL_ANDROID_STREAM_MEDIA; |
233 return new OpenSLESOutputStream(this, params, stream_type); | 228 return new OpenSLESOutputStream(this, params, stream_type); |
234 } | 229 } |
235 | 230 |
236 AudioInputStream* AudioManagerAndroid::MakeLinearInputStream( | 231 AudioInputStream* AudioManagerAndroid::MakeLinearInputStream( |
237 const AudioParameters& params, | 232 const AudioParameters& params, const std::string& device_id) { |
238 const std::string& device_id, | |
239 const LogCallback& log_callback) { | |
240 // TODO(henrika): add support for device selection if/when any client | 233 // TODO(henrika): add support for device selection if/when any client |
241 // needs it. | 234 // needs it. |
242 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; | 235 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; |
243 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 236 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
244 return new OpenSLESInputStream(this, params); | 237 return new OpenSLESInputStream(this, params); |
245 } | 238 } |
246 | 239 |
247 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( | 240 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( |
248 const AudioParameters& params, | 241 const AudioParameters& params, const std::string& device_id) { |
249 const std::string& device_id, | |
250 const LogCallback& log_callback) { | |
251 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 242 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
252 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 243 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
253 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; | 244 DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; |
254 | 245 |
255 // Use the device ID to select the correct input device. | 246 // Use the device ID to select the correct input device. |
256 // Note that the input device is always associated with a certain output | 247 // Note that the input device is always associated with a certain output |
257 // device, i.e., this selection does also switch the output device. | 248 // device, i.e., this selection does also switch the output device. |
258 // All input and output streams will be affected by the device selection. | 249 // All input and output streams will be affected by the device selection. |
259 if (!SetAudioDevice(device_id)) { | 250 if (!SetAudioDevice(device_id)) { |
260 LOG(ERROR) << "Unable to select audio device!"; | 251 LOG(ERROR) << "Unable to select audio device!"; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 output_volume_override_ = volume; | 420 output_volume_override_ = volume; |
430 | 421 |
431 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 422 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
432 for (OutputStreams::iterator it = streams_.begin(); | 423 for (OutputStreams::iterator it = streams_.begin(); |
433 it != streams_.end(); ++it) { | 424 it != streams_.end(); ++it) { |
434 (*it)->SetVolume(volume); | 425 (*it)->SetVolume(volume); |
435 } | 426 } |
436 } | 427 } |
437 | 428 |
438 } // namespace media | 429 } // namespace media |
OLD | NEW |