Index: media/audio/mac/audio_manager_mac.cc |
=================================================================== |
--- media/audio/mac/audio_manager_mac.cc (revision 106297) |
+++ media/audio/mac/audio_manager_mac.cc (working copy) |
@@ -5,6 +5,7 @@ |
#include <CoreAudio/AudioHardware.h> |
#include "base/mac/mac_util.h" |
+#include "base/sys_string_conversions.h" |
#include "media/audio/fake_audio_input_stream.h" |
#include "media/audio/fake_audio_output_stream.h" |
#include "media/audio/mac/audio_input_mac.h" |
@@ -65,6 +66,103 @@ |
output_device_id != kAudioObjectUnknown; |
} |
+static void GetAudioDeviceInfo(bool is_input, |
+ media::AudioDeviceNames* device_names) { |
+ if (!device_names) |
scherkus (not reviewing)
2011/10/19 18:19:26
is this valid? seems like programmer error -- I'd
no longer working on chromium
2011/10/21 12:35:30
Agree, let me just put a DCHECK here.
|
+ return; |
+ |
+ device_names->clear(); |
+ |
+ // Query the number of total devices. |
+ AudioObjectPropertyAddress property_address = { |
+ kAudioHardwarePropertyDevices, // mSelector |
+ kAudioObjectPropertyScopeGlobal, // mScope |
+ kAudioObjectPropertyElementMaster // mElement |
+ }; |
+ UInt32 size = 0; |
+ OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, |
+ &property_address, |
+ 0, |
+ NULL, |
+ &size); |
+ if (result || !size) |
+ return; |
+ |
+ int device_count = 0; |
+ device_count = size / sizeof(AudioDeviceID); |
+ |
+ // Get the array of device id for each device. |
+ scoped_ptr_malloc<AudioDeviceID> |
+ devices(reinterpret_cast<AudioDeviceID*>(malloc(size))); |
+ AudioDeviceID* device_ids = devices.get(); |
+ result = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
+ &property_address, |
+ 0, |
+ NULL, |
+ &size, |
+ device_ids); |
+ if (result) |
+ return; |
+ |
+ // Iterate each device to gather information. |
+ for (int i = 0; i < device_count; ++i) { |
+ { |
+ int channels = 0; |
+ // Get the number of input or output channels of the device, exclude |
+ // those devices without any right type of channel. |
+ AudioDeviceGetPropertyInfo(device_ids[i], |
+ 0, |
+ is_input, |
+ kAudioDevicePropertyStreamConfiguration, |
+ &size, |
+ NULL); |
+ scoped_ptr_malloc<AudioBufferList> |
+ buffer(reinterpret_cast<AudioBufferList*>(malloc(size))); |
scherkus (not reviewing)
2011/10/19 18:19:26
maybe I'm missing something -- but doesn't the for
no longer working on chromium
2011/10/21 12:35:30
True, I was quite tired at that late evening that
|
+ AudioBufferList* buffer_list = buffer.get(); |
+ AudioDeviceGetProperty(device_ids[i], |
+ 0, |
+ is_input, |
+ kAudioDevicePropertyStreamConfiguration, |
+ &size, |
+ buffer_list); |
+ |
+ for (uint32 j = 0; j < buffer_list->mNumberBuffers; ++j) |
+ channels += buffer_list->mBuffers[j].mNumberChannels; |
+ |
+ if (!channels) |
+ continue; |
+ } |
+ |
+ // Get device UID. |
+ CFStringRef uid = NULL; |
+ size = sizeof(uid); |
+ result = AudioDeviceGetProperty(device_ids[i], |
+ 0, |
+ is_input, |
+ kAudioDevicePropertyDeviceUID, |
+ &size, |
+ &uid); |
+ if (result) |
+ continue; |
+ |
+ // Get device name. |
+ CFStringRef name = NULL; |
+ result = AudioDeviceGetProperty(device_ids[i], |
+ 0, |
+ is_input, |
+ kAudioObjectPropertyName, |
+ &size, |
+ &name); |
+ if (result) |
+ continue; |
+ |
+ media::AudioDeviceName device_name; |
+ device_name.device_name = base::SysCFStringRefToUTF8(name); |
+ device_name.unique_id = base::SysCFStringRefToUTF8(uid); |
+ device_names->push_back(device_name); |
+ } |
+} |
+ |
AudioManagerMac::AudioManagerMac() |
: num_output_streams_(0) { |
} |
@@ -82,15 +180,15 @@ |
void AudioManagerMac::GetAudioInputDeviceNames( |
media::AudioDeviceNames* device_names) { |
- // TODO(xians): query a full list of valid devices. |
- if (HasAudioInputDevices()) { |
- // Add the default device to the list. |
- // We use index 0 to make up the unique_id to identify the |
- // default devices. |
+ GetAudioDeviceInfo(true, device_names); |
+ if (!device_names->empty()) { |
+ // Prepend the default device to the list since we always want it to be |
+ // on the top of the list for all platforms. There is no duplicate |
+ // counting here since the default device has been abstracted out before. |
media::AudioDeviceName name; |
name.device_name = AudioManagerBase::kDefaultDeviceName; |
name.unique_id = "0"; |
- device_names->push_back(name); |
+ device_names->push_front(name); |
} |
} |