Chromium Code Reviews| 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/mac/audio_unified_mac.h" | 5 #include "media/audio/mac/audio_unified_mac.h" |
| 6 | 6 |
| 7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 | 388 |
| 389 return audio_output->Render( | 389 return audio_output->Render( |
| 390 device, | 390 device, |
| 391 now, | 391 now, |
| 392 input_data, | 392 input_data, |
| 393 input_time, | 393 input_time, |
| 394 output_data, | 394 output_data, |
| 395 output_time); | 395 output_time); |
| 396 } | 396 } |
| 397 | 397 |
| 398 bool AudioHardwareUnifiedStream::GetDefaultOutputDevice( | |
|
DaleCurtis
2013/03/06 19:19:30
I think this code should live in AudioManagerMac.
Chris Rogers
2013/03/07 00:34:17
I've moved the functions to AudioManagerMac. I ag
| |
| 399 AudioDeviceID* device) { | |
| 400 if (!device) | |
| 401 return false; | |
| 402 | |
| 403 // Obtain the current output device selected by the user. | |
| 404 AudioObjectPropertyAddress pa; | |
| 405 pa.mSelector = kAudioHardwarePropertyDefaultOutputDevice; | |
| 406 pa.mScope = kAudioObjectPropertyScopeGlobal; | |
| 407 pa.mElement = kAudioObjectPropertyElementMaster; | |
| 408 | |
| 409 UInt32 size = sizeof(*device); | |
| 410 | |
| 411 OSStatus result = AudioObjectGetPropertyData( | |
| 412 kAudioObjectSystemObject, | |
| 413 &pa, | |
| 414 0, | |
| 415 0, | |
| 416 &size, | |
| 417 device); | |
| 418 | |
| 419 if ((result != kAudioHardwareNoError) || (*device == kAudioDeviceUnknown)) { | |
| 420 LOG(ERROR) << "Error getting default output AudioDevice."; | |
| 421 return false; | |
| 422 } | |
| 423 | |
| 424 return true; | |
| 425 } | |
| 426 | |
| 427 bool AudioHardwareUnifiedStream::GetDefaultOutputChannels( | |
| 428 int* channels, int* channels_per_frame) { | |
| 429 AudioDeviceID device; | |
| 430 if (!GetDefaultOutputDevice(&device)) | |
| 431 return false; | |
| 432 | |
| 433 return GetDeviceChannels(device, | |
| 434 kAudioDevicePropertyScopeOutput, | |
| 435 channels, | |
| 436 channels_per_frame); | |
| 437 } | |
| 438 | |
| 439 bool AudioHardwareUnifiedStream::GetDeviceChannels( | |
| 440 AudioDeviceID device, | |
| 441 AudioObjectPropertyScope scope, | |
| 442 int* channels, | |
| 443 int* channels_per_frame) { | |
| 444 if (!channels || !channels_per_frame) | |
| 445 return false; | |
| 446 | |
| 447 // Get stream configuration. | |
| 448 AudioObjectPropertyAddress pa; | |
| 449 pa.mSelector = kAudioDevicePropertyStreamConfiguration; | |
| 450 pa.mScope = scope; | |
| 451 pa.mElement = kAudioObjectPropertyElementMaster; | |
| 452 | |
| 453 UInt32 size; | |
| 454 OSStatus result = AudioObjectGetPropertyDataSize(device, &pa, 0, 0, &size); | |
| 455 OSSTATUS_DCHECK(result == noErr, result); | |
| 456 | |
| 457 if (result == noErr && size > 0) { | |
| 458 // Allocate storage. | |
| 459 scoped_array<uint8> list_storage(new uint8[size]); | |
| 460 AudioBufferList& buffer_list = | |
| 461 *reinterpret_cast<AudioBufferList*>(list_storage.get()); | |
| 462 | |
| 463 result = AudioObjectGetPropertyData( | |
| 464 device, | |
| 465 &pa, | |
| 466 0, | |
| 467 0, | |
| 468 &size, | |
| 469 &buffer_list); | |
| 470 OSSTATUS_DCHECK(result == noErr, result); | |
| 471 | |
| 472 if (result == noErr) { | |
| 473 // Determine number of input channels. | |
| 474 *channels_per_frame = buffer_list.mNumberBuffers > 0 ? | |
| 475 buffer_list.mBuffers[0].mNumberChannels : 0; | |
| 476 if (*channels_per_frame == 1 && buffer_list.mNumberBuffers > 1) { | |
| 477 // Non-interleaved. | |
| 478 *channels = buffer_list.mNumberBuffers; | |
| 479 } else { | |
| 480 // Interleaved. | |
| 481 *channels = *channels_per_frame; | |
| 482 } | |
| 483 } | |
| 484 } | |
| 485 | |
| 486 return result == noErr; | |
| 487 } | |
| 488 | |
| 398 } // namespace media | 489 } // namespace media |
| OLD | NEW |