| Index: media/audio/mac/audio_unified_mac.cc
|
| ===================================================================
|
| --- media/audio/mac/audio_unified_mac.cc (revision 185058)
|
| +++ media/audio/mac/audio_unified_mac.cc (working copy)
|
| @@ -395,4 +395,95 @@
|
| output_time);
|
| }
|
|
|
| +bool AudioHardwareUnifiedStream::GetDefaultOutputDevice(
|
| + AudioDeviceID* device) {
|
| + if (!device)
|
| + return false;
|
| +
|
| + // Obtain the current output device selected by the user.
|
| + AudioObjectPropertyAddress pa;
|
| + pa.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
| + pa.mScope = kAudioObjectPropertyScopeGlobal;
|
| + pa.mElement = kAudioObjectPropertyElementMaster;
|
| +
|
| + UInt32 size = sizeof(*device);
|
| +
|
| + OSStatus result = AudioObjectGetPropertyData(
|
| + kAudioObjectSystemObject,
|
| + &pa,
|
| + 0,
|
| + 0,
|
| + &size,
|
| + device);
|
| +
|
| + if ((result != kAudioHardwareNoError) || (*device == kAudioDeviceUnknown)) {
|
| + LOG(ERROR) << "Error getting default output AudioDevice.";
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool AudioHardwareUnifiedStream::GetDefaultOutputChannels(
|
| + int* channels, int* channels_per_frame) {
|
| + AudioDeviceID device;
|
| + if (!GetDefaultOutputDevice(&device))
|
| + return false;
|
| +
|
| + return GetDeviceChannels(device,
|
| + kAudioDevicePropertyScopeOutput,
|
| + channels,
|
| + channels_per_frame);
|
| +}
|
| +
|
| +bool AudioHardwareUnifiedStream::GetDeviceChannels(
|
| + AudioDeviceID device,
|
| + AudioObjectPropertyScope scope,
|
| + int* channels,
|
| + int* channels_per_frame) {
|
| + if (!channels || !channels_per_frame)
|
| + return false;
|
| +
|
| + // Get stream configuration.
|
| + AudioObjectPropertyAddress pa;
|
| + pa.mSelector = kAudioDevicePropertyStreamConfiguration;
|
| + pa.mScope = scope;
|
| + pa.mElement = kAudioObjectPropertyElementMaster;
|
| +
|
| + UInt32 size;
|
| + OSStatus result = AudioObjectGetPropertyDataSize(device, &pa, 0, 0, &size);
|
| + OSSTATUS_DCHECK(result == noErr, result);
|
| +
|
| + if (result == noErr && size > 0) {
|
| + // Allocate storage.
|
| + scoped_array<uint8> list_storage(new uint8[size]);
|
| + AudioBufferList& buffer_list =
|
| + *reinterpret_cast<AudioBufferList*>(list_storage.get());
|
| +
|
| + result = AudioObjectGetPropertyData(
|
| + device,
|
| + &pa,
|
| + 0,
|
| + 0,
|
| + &size,
|
| + &buffer_list);
|
| + OSSTATUS_DCHECK(result == noErr, result);
|
| +
|
| + if (result == noErr) {
|
| + // Determine number of input channels.
|
| + *channels_per_frame = buffer_list.mNumberBuffers > 0 ?
|
| + buffer_list.mBuffers[0].mNumberChannels : 0;
|
| + if (*channels_per_frame == 1 && buffer_list.mNumberBuffers > 1) {
|
| + // Non-interleaved.
|
| + *channels = buffer_list.mNumberBuffers;
|
| + } else {
|
| + // Interleaved.
|
| + *channels = *channels_per_frame;
|
| + }
|
| + }
|
| + }
|
| +
|
| + return result == noErr;
|
| +}
|
| +
|
| } // namespace media
|
|
|