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

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

Issue 2466463005: Support (E)AC3 passthrough
Patch Set: Improve CastMediaClient::IsSupportedPassthroughAudio() Created 4 years, 1 month 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/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"
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "jni/AudioManagerAndroid_jni.h" 16 #include "jni/AudioManagerAndroid_jni.h"
17 #include "media/audio/android/audio_record_input.h" 17 #include "media/audio/android/audio_record_input.h"
18 #include "media/audio/android/audio_track_output_stream.h"
18 #include "media/audio/android/opensles_input.h" 19 #include "media/audio/android/opensles_input.h"
19 #include "media/audio/android/opensles_output.h" 20 #include "media/audio/android/opensles_output.h"
20 #include "media/audio/audio_device_description.h" 21 #include "media/audio/audio_device_description.h"
21 #include "media/audio/audio_manager.h" 22 #include "media/audio/audio_manager.h"
22 #include "media/audio/fake_audio_input_stream.h" 23 #include "media/audio/fake_audio_input_stream.h"
23 #include "media/base/audio_parameters.h" 24 #include "media/base/audio_parameters.h"
24 #include "media/base/channel_layout.h" 25 #include "media/base/channel_layout.h"
25 26
26 using base::android::AppendJavaStringArrayToStringVector; 27 using base::android::AppendJavaStringArrayToStringVector;
27 using base::android::AttachCurrentThread; 28 using base::android::AttachCurrentThread;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return params; 162 return params;
162 } 163 }
163 164
164 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( 165 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream(
165 const AudioParameters& params, 166 const AudioParameters& params,
166 const std::string& device_id, 167 const std::string& device_id,
167 const LogCallback& log_callback) { 168 const LogCallback& log_callback) {
168 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 169 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
169 AudioOutputStream* stream = AudioManagerBase::MakeAudioOutputStream( 170 AudioOutputStream* stream = AudioManagerBase::MakeAudioOutputStream(
170 params, std::string(), AudioManager::LogCallback()); 171 params, std::string(), AudioManager::LogCallback());
171 streams_.insert(static_cast<OpenSLESOutputStream*>(stream)); 172 streams_.insert(static_cast<MuteableAudioOutputStream*>(stream));
172 return stream; 173 return stream;
173 } 174 }
174 175
175 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( 176 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream(
176 const AudioParameters& params, 177 const AudioParameters& params,
177 const std::string& device_id, 178 const std::string& device_id,
178 const LogCallback& log_callback) { 179 const LogCallback& log_callback) {
179 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 180 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
180 bool has_no_input_streams = HasNoAudioInputStreams(); 181 bool has_no_input_streams = HasNoAudioInputStreams();
181 AudioInputStream* stream = AudioManagerBase::MakeAudioInputStream( 182 AudioInputStream* stream = AudioManagerBase::MakeAudioInputStream(
182 params, device_id, AudioManager::LogCallback()); 183 params, device_id, AudioManager::LogCallback());
183 184
184 // The audio manager for Android creates streams intended for real-time 185 // The audio manager for Android creates streams intended for real-time
185 // VoIP sessions and therefore sets the audio mode to MODE_IN_COMMUNICATION. 186 // 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 187 // If a Bluetooth headset is used, the audio stream will use the SCO
187 // channel and therefore have a limited bandwidth (8kHz). 188 // channel and therefore have a limited bandwidth (8kHz).
188 if (stream && has_no_input_streams) { 189 if (stream && has_no_input_streams) {
189 communication_mode_is_on_ = true; 190 communication_mode_is_on_ = true;
190 SetCommunicationAudioModeOn(true); 191 SetCommunicationAudioModeOn(true);
191 } 192 }
192 return stream; 193 return stream;
193 } 194 }
194 195
195 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) { 196 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) {
196 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 197 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
197 streams_.erase(static_cast<OpenSLESOutputStream*>(stream)); 198 streams_.erase(static_cast<MuteableAudioOutputStream*>(stream));
198 AudioManagerBase::ReleaseOutputStream(stream); 199 AudioManagerBase::ReleaseOutputStream(stream);
199 } 200 }
200 201
201 void AudioManagerAndroid::ReleaseInputStream(AudioInputStream* stream) { 202 void AudioManagerAndroid::ReleaseInputStream(AudioInputStream* stream) {
202 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 203 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
203 AudioManagerBase::ReleaseInputStream(stream); 204 AudioManagerBase::ReleaseInputStream(stream);
204 205
205 // Restore the audio mode which was used before the first communication- 206 // Restore the audio mode which was used before the first communication-
206 // mode stream was created. 207 // mode stream was created.
207 if (HasNoAudioInputStreams()) { 208 if (HasNoAudioInputStreams()) {
(...skipping 17 matching lines...) Expand all
225 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; 226 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!";
226 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 227 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
227 228
228 // 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
229 // the Android audio manager. 230 // the Android audio manager.
230 const SLint32 stream_type = communication_mode_is_on_ ? 231 const SLint32 stream_type = communication_mode_is_on_ ?
231 SL_ANDROID_STREAM_VOICE : SL_ANDROID_STREAM_MEDIA; 232 SL_ANDROID_STREAM_VOICE : SL_ANDROID_STREAM_MEDIA;
232 return new OpenSLESOutputStream(this, params, stream_type); 233 return new OpenSLESOutputStream(this, params, stream_type);
233 } 234 }
234 235
236 AudioOutputStream* AudioManagerAndroid::MakeRawOutputStream(
237 const AudioParameters& params,
238 const std::string& device_id,
239 const LogCallback& log_callback) {
240 DCHECK(params.IsRawFormat());
241 return new AudioTrackOutputStream(this, params);
242 }
243
235 AudioInputStream* AudioManagerAndroid::MakeLinearInputStream( 244 AudioInputStream* AudioManagerAndroid::MakeLinearInputStream(
236 const AudioParameters& params, 245 const AudioParameters& params,
237 const std::string& device_id, 246 const std::string& device_id,
238 const LogCallback& log_callback) { 247 const LogCallback& log_callback) {
239 // TODO(henrika): add support for device selection if/when any client 248 // TODO(henrika): add support for device selection if/when any client
240 // needs it. 249 // needs it.
241 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; 250 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!";
242 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); 251 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
243 return new OpenSLESInputStream(this, params); 252 return new OpenSLESInputStream(this, params);
244 } 253 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 output_volume_override_ = volume; 428 output_volume_override_ = volume;
420 429
421 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 430 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
422 for (OutputStreams::iterator it = streams_.begin(); 431 for (OutputStreams::iterator it = streams_.begin();
423 it != streams_.end(); ++it) { 432 it != streams_.end(); ++it) {
424 (*it)->SetVolume(volume); 433 (*it)->SetVolume(volume);
425 } 434 }
426 } 435 }
427 436
428 } // namespace media 437 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698