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,100 @@ |
| output_device_id != kAudioObjectUnknown; |
| } |
| +static void GetAudioDeviceInfo(bool is_input, |
| + media::AudioDeviceNames* device_names) { |
| + DCHECK(device_names); |
| + |
|
scherkus (not reviewing)
2011/10/24 18:32:13
nit: get rid of blank line
no longer working on chromium
2011/10/24 22:32:30
Done.
|
| + device_names->clear(); |
| + |
| + // Query the number of total devices. |
| + AudioObjectPropertyAddress property_address = { |
| + kAudioHardwarePropertyDevices, // mSelector |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
Why did you add these comments? Does not say much.
no longer working on chromium
2011/10/24 22:32:30
It is code/comment copied from CL http://coderevie
|
| + kAudioObjectPropertyScopeGlobal, // mScope |
| + kAudioObjectPropertyElementMaster // mElement |
| + }; |
| + UInt32 size = 0; |
| + OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, |
| + &property_address, |
| + 0, |
| + NULL, |
| + &size); |
| + if (result || !size) |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
Assume that there are no devices if we enter this
no longer working on chromium
2011/10/24 22:32:30
I think the code has been quite clear. hope it is
|
| + return; |
| + |
| + int device_count = 0; |
| + device_count = size / sizeof(AudioDeviceID); |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
Why not:
int device_count = size / ..
no longer working on chromium
2011/10/24 22:32:30
Good catch, thanks.
Done
|
| + |
| + // Get the array of device id for each device. |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
Can you make this comment more clear. What does th
no longer working on chromium
2011/10/24 22:32:30
Done.
The story behind this is that we need to ch
|
| + 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. |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
I would say "Iterate over all available devices ..
no longer working on chromium
2011/10/24 22:32:30
Done.
|
| + for (int i = 0; i < device_count; ++i) { |
| + int channels = 0; |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
Why declaration here?
no longer working on chromium
2011/10/24 22:32:30
For each device, we need to check if it has channe
|
| + // Get the number of input or output channels of the device, exclude |
| + // those devices without any right type of channel. |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
What does "without any right type of channel" mean
no longer working on chromium
2011/10/24 22:32:30
Done.
I improved the comments a bit by separating
|
| + AudioDeviceGetPropertyInfo(device_ids[i], |
| + 0, |
| + is_input, |
| + kAudioDevicePropertyStreamConfiguration, |
| + &size, |
| + NULL); |
| + scoped_ptr_malloc<AudioBufferList> |
| + buffer(reinterpret_cast<AudioBufferList*>(malloc(size))); |
| + 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) |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
What does this section do?
no longer working on chromium
2011/10/24 22:32:30
It just gets the buffer list about the device whic
|
| + channels += buffer_list->mBuffers[j].mNumberChannels; |
| + |
| + if (!channels) |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
Sorry, this part is not clear. Where has it been s
no longer working on chromium
2011/10/24 22:32:30
Just two lines above we add to channels with the n
|
| + 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; |
|
henrika (OOO until Aug 14)
2011/10/24 18:51:36
Add comment about what you actually produce and st
no longer working on chromium
2011/10/24 22:32:30
Done.
|
| + 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 +177,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); |
| } |
| } |