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

Unified Diff: media/audio/mac/audio_unified_mac.cc

Issue 12387006: Pass more detailed audio hardware configuration information to the renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698