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