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

Side by Side Diff: media/audio/mac/audio_manager_mac.cc

Issue 12316131: Moved AudioUtil static functions to AudioManager interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged GetPreferredLowLatencyOutputStreamParameters to GetDefaultOutputStreamParameters Created 7 years, 9 months 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/mac/audio_manager_mac.h" 5 #include "media/audio/mac/audio_manager_mac.h"
6 6
7 #include <CoreAudio/AudioHardware.h> 7 #include <CoreAudio/AudioHardware.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/mac/mac_logging.h" 12 #include "base/mac/mac_logging.h"
13 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "media/audio/audio_util.h" 15 #include "media/audio/audio_parameters.h"
16 #include "media/audio/mac/audio_input_mac.h" 16 #include "media/audio/mac/audio_input_mac.h"
17 #include "media/audio/mac/audio_low_latency_input_mac.h" 17 #include "media/audio/mac/audio_low_latency_input_mac.h"
18 #include "media/audio/mac/audio_low_latency_output_mac.h" 18 #include "media/audio/mac/audio_low_latency_output_mac.h"
19 #include "media/audio/mac/audio_output_mac.h" 19 #include "media/audio/mac/audio_output_mac.h"
20 #include "media/audio/mac/audio_synchronized_mac.h" 20 #include "media/audio/mac/audio_synchronized_mac.h"
21 #include "media/audio/mac/audio_unified_mac.h" 21 #include "media/audio/mac/audio_unified_mac.h"
22 #include "media/base/bind_to_loop.h" 22 #include "media/base/bind_to_loop.h"
23 #include "media/base/channel_layout.h"
23 #include "media/base/limits.h" 24 #include "media/base/limits.h"
24 #include "media/base/media_switches.h" 25 #include "media/base/media_switches.h"
25 26
26 namespace media { 27 namespace media {
27 28
28 // Maximum number of output streams that can be open simultaneously. 29 // Maximum number of output streams that can be open simultaneously.
29 static const int kMaxOutputStreams = 50; 30 static const int kMaxOutputStreams = 50;
30 31
32 // Default buffer size in samples for low-latency input and output streams.
33 static const int kDefaultLowLatencyBufferSize = 128;
34
31 static bool HasAudioHardware(AudioObjectPropertySelector selector) { 35 static bool HasAudioHardware(AudioObjectPropertySelector selector) {
32 AudioDeviceID output_device_id = kAudioObjectUnknown; 36 AudioDeviceID output_device_id = kAudioObjectUnknown;
33 const AudioObjectPropertyAddress property_address = { 37 const AudioObjectPropertyAddress property_address = {
34 selector, 38 selector,
35 kAudioObjectPropertyScopeGlobal, // mScope 39 kAudioObjectPropertyScopeGlobal, // mScope
36 kAudioObjectPropertyElementMaster // mElement 40 kAudioObjectPropertyElementMaster // mElement
37 }; 41 };
38 UInt32 output_device_id_size = static_cast<UInt32>(sizeof(output_device_id)); 42 UInt32 output_device_id_size = static_cast<UInt32>(sizeof(output_device_id));
39 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, 43 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject,
40 &property_address, 44 &property_address,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Prepend the default device to the list since we always want it to be 270 // Prepend the default device to the list since we always want it to be
267 // on the top of the list for all platforms. There is no duplicate 271 // on the top of the list for all platforms. There is no duplicate
268 // counting here since the default device has been abstracted out before. 272 // counting here since the default device has been abstracted out before.
269 media::AudioDeviceName name; 273 media::AudioDeviceName name;
270 name.device_name = AudioManagerBase::kDefaultDeviceName; 274 name.device_name = AudioManagerBase::kDefaultDeviceName;
271 name.unique_id = AudioManagerBase::kDefaultDeviceId; 275 name.unique_id = AudioManagerBase::kDefaultDeviceId;
272 device_names->push_front(name); 276 device_names->push_front(name);
273 } 277 }
274 } 278 }
275 279
280 AudioParameters AudioManagerMac::GetDefaultOutputStreamParameters(
281 const AudioParameters& input_params) {
282 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
283 int input_channels = 0;
284 if (input_params.IsValid()) {
285 channel_layout = input_params.channel_layout();
286 input_channels = input_params.input_channels();
287
288 if (CommandLine::ForCurrentProcess()->HasSwitch(
289 switches::kEnableWebAudioInput)) {
290 // TODO(crogers): given the limitations of the AudioOutputStream
291 // back-ends used with kEnableWebAudioInput, we hard-code to stereo.
292 // Specifically, this is a limitation of AudioSynchronizedStream which
293 // can be removed as part of the work to consolidate these back-ends.
294 channel_layout = CHANNEL_LAYOUT_STEREO;
295 }
296 }
297
298 return AudioParameters(
299 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
300 AUAudioOutputStream::HardwareSampleRate(), 16,
301 kDefaultLowLatencyBufferSize);
302 }
303
304 AudioParameters AudioManagerMac::GetInputStreamParameters(
305 const std::string& device_id) {
306 // TODO(xians): query the native channel layout for the specific device.
307 return AudioParameters(
308 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
309 AUAudioInputStream::HardwareSampleRate(), 16,
310 kDefaultLowLatencyBufferSize);
311 }
312
276 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( 313 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream(
277 const AudioParameters& params) { 314 const AudioParameters& params) {
278 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); 315 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
279 return new PCMQueueOutAudioOutputStream(this, params); 316 return new PCMQueueOutAudioOutputStream(this, params);
280 } 317 }
281 318
282 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( 319 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream(
283 const AudioParameters& params) { 320 const AudioParameters& params) {
284 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 321 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
285 322
(...skipping 28 matching lines...) Expand all
314 // Gets the AudioDeviceID that refers to the AudioOutputDevice with the device 351 // Gets the AudioDeviceID that refers to the AudioOutputDevice with the device
315 // unique id. This AudioDeviceID is used to set the device for Audio Unit. 352 // unique id. This AudioDeviceID is used to set the device for Audio Unit.
316 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); 353 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id);
317 AudioInputStream* stream = NULL; 354 AudioInputStream* stream = NULL;
318 if (audio_device_id != kAudioObjectUnknown) 355 if (audio_device_id != kAudioObjectUnknown)
319 stream = new AUAudioInputStream(this, params, audio_device_id); 356 stream = new AUAudioInputStream(this, params, audio_device_id);
320 357
321 return stream; 358 return stream;
322 } 359 }
323 360
324 AudioParameters AudioManagerMac::GetPreferredLowLatencyOutputStreamParameters(
325 const AudioParameters& input_params) {
326 if (CommandLine::ForCurrentProcess()->HasSwitch(
327 switches::kEnableWebAudioInput)) {
328 // TODO(crogers): given the limitations of the AudioOutputStream
329 // back-ends used with kEnableWebAudioInput, we hard-code to stereo.
330 // Specifically, this is a limitation of AudioSynchronizedStream which
331 // can be removed as part of the work to consolidate these back-ends.
332 return AudioParameters(
333 AudioParameters::AUDIO_PCM_LOW_LATENCY,
334 CHANNEL_LAYOUT_STEREO, input_params.input_channels(),
335 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize());
336 }
337
338 return AudioManagerBase::GetPreferredLowLatencyOutputStreamParameters(
339 input_params);
340 }
341
342 void AudioManagerMac::CreateDeviceListener() { 361 void AudioManagerMac::CreateDeviceListener() {
343 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 362 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
344 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind( 363 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind(
345 &AudioManagerMac::DelayedDeviceChange, base::Unretained(this)))); 364 &AudioManagerMac::DelayedDeviceChange, base::Unretained(this))));
346 } 365 }
347 366
348 void AudioManagerMac::DestroyDeviceListener() { 367 void AudioManagerMac::DestroyDeviceListener() {
349 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 368 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
350 output_device_listener_.reset(); 369 output_device_listener_.reset();
351 } 370 }
352 371
353 void AudioManagerMac::DelayedDeviceChange() { 372 void AudioManagerMac::DelayedDeviceChange() {
354 // TODO(dalecurtis): This is ridiculous, but we need to delay device changes 373 // TODO(dalecurtis): This is ridiculous, but we need to delay device changes
355 // to workaround threading issues with OSX property listener callbacks. See 374 // to workaround threading issues with OSX property listener callbacks. See
356 // http://crbug.com/158170 375 // http://crbug.com/158170
357 GetMessageLoop()->PostDelayedTask(FROM_HERE, base::Bind( 376 GetMessageLoop()->PostDelayedTask(FROM_HERE, base::Bind(
358 &AudioManagerMac::NotifyAllOutputDeviceChangeListeners, 377 &AudioManagerMac::NotifyAllOutputDeviceChangeListeners,
359 base::Unretained(this)), base::TimeDelta::FromSeconds(2)); 378 base::Unretained(this)), base::TimeDelta::FromSeconds(2));
360 } 379 }
361 380
362 AudioManager* CreateAudioManager() { 381 AudioManager* CreateAudioManager() {
363 return new AudioManagerMac(); 382 return new AudioManagerMac();
364 } 383 }
365 384
366 } // namespace media 385 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698