Chromium Code Reviews| 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,93 @@ |
| output_device_id != kAudioObjectUnknown; |
| } |
| +static void GetAudioDeviceInfo( |
| + bool is_input, media::AudioDeviceNames* device_names) { |
|
scherkus (not reviewing)
2011/10/19 17:38:51
nit: should go on previous line and align paramete
no longer working on chromium
2011/10/19 18:13:21
Done.
|
| + if (!device_names) |
| + return; |
| + |
| + device_names->clear(); |
| + |
| + // Query the number of total devices. |
| + UInt32 size = 0; |
| + OSStatus result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, |
| + &size, |
| + NULL); |
| + 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 = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, |
|
scherkus (not reviewing)
2011/10/19 17:38:51
I'm curious do we need malloc() or does new[] work
no longer working on chromium
2011/10/19 18:13:21
The Apple sample code is using malloc, I am not su
|
| + &size, |
| + device_ids); |
| + if (result) |
| + return; |
| + |
| + // Iterate each device to gather information. |
| + for (int i = 0; i < device_count; ++i) { |
| + { |
|
scherkus (not reviewing)
2011/10/19 17:38:51
why do we have the separate scope?
no longer working on chromium
2011/10/19 18:13:21
Because it is in a loop and we need to allocate dy
|
| + 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 17:38:51
ditto
no longer working on chromium
2011/10/19 18:13:21
ditto.
|
| + 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 +170,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); |
| } |
| } |