Chromium Code Reviews| Index: media/audio/mac/audio_manager_mac.cc |
| =================================================================== |
| --- media/audio/mac/audio_manager_mac.cc (revision 105059) |
| +++ media/audio/mac/audio_manager_mac.cc (working copy) |
| @@ -65,6 +65,105 @@ |
| output_device_id != kAudioObjectUnknown; |
| } |
| +static std::string CFStringToSTLString(const CFStringRef cfstr) |
|
Chris Rogers
2011/10/19 01:31:50
I think it would be a lot better to avoid creating
no longer working on chromium
2011/10/19 17:32:18
Done.
Thanks for pointing out, it has a API calle
|
| +{ |
|
scherkus (not reviewing)
2011/10/19 17:38:51
{ should go on previous line
no longer working on chromium
2011/10/19 18:13:21
The code has been removed.
|
| + // The method is currently only for kCFStringEncodingUTF8 encoding. |
| + CFIndex buf_len = 1 + CFStringGetMaximumSizeForEncoding( |
| + CFStringGetLength(cfstr), kCFStringEncodingUTF8); |
| + scoped_array<char> buffer(new char[buf_len]); |
| + CFStringGetCString(cfstr, buffer.get(), buf_len, kCFStringEncodingUTF8); |
| + |
| + std::string std_string(buffer.get()); |
| + return std_string; |
| +} |
| + |
| +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 then align paramet
no longer working on chromium
2011/10/19 18:13:21
Done.
|
| + CFStringRef uid = NULL; |
| + CFStringRef name = NULL; |
| + int device_number = 0; |
|
Chris Rogers
2011/10/19 01:31:50
"device_count" is probably a better name than "dev
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| + UInt32 size = 0; |
|
Chris Rogers
2011/10/19 01:31:50
Please move variables to closest point of usage.
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| + |
| + device_names->clear(); |
|
Chris Rogers
2011/10/19 01:31:50
Just to be careful, probably best to check "device
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| + |
| + // Query the number of total devices. |
| + OSStatus result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, |
| + &size, |
| + NULL); |
| + if (result) |
|
Chris Rogers
2011/10/19 01:31:50
Can make this simpler:
if (result || !size)
then
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| + return; |
| + |
| + device_number = size / sizeof(AudioDeviceID); |
| + if (!device_number) |
| + return; |
| + |
| + // Get the array of device id for each device. |
| + scoped_ptr_malloc<AudioDeviceID> |
| + devices(reinterpret_cast<AudioDeviceID*>(malloc(size))); |
|
scherkus (not reviewing)
2011/10/19 17:38:51
I'm curious -- is malloc required?
no longer working on chromium
2011/10/19 18:13:21
That is how the apple sample code looks like, I th
|
| + AudioDeviceID* device_ids = devices.get(); |
| + result = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, |
| + &size, |
| + device_ids); |
| + if (result) |
| + return; |
| + |
| + // Iterate each device to gather information. |
| + for(int i = 0; i < device_number; ++i) { |
|
Chris Rogers
2011/10/19 01:31:50
nit: space after "for"
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| + { |
| + 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))); |
| + 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) |
|
Chris Rogers
2011/10/19 01:31:50
nit: space after "for"
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| + channels += buffer_list->mBuffers[j].mNumberChannels; |
| + |
| + if (!channels) |
| + continue; |
| + } |
| + |
| + size = sizeof(uid); |
|
Chris Rogers
2011/10/19 01:31:50
I'd move this line down just below the comment
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| + // Get device UID. |
| + result = AudioDeviceGetProperty(device_ids[i], |
| + 0, |
| + is_input, |
| + kAudioDevicePropertyDeviceUID, |
| + &size, |
| + &uid); |
| + if (result) |
| + continue; |
| + |
| + // Get device name. |
| + result = AudioDeviceGetProperty(device_ids[i], |
| + 0, |
| + is_input, |
| + kAudioObjectPropertyName, |
| + &size, |
| + &name); |
| + if (result) |
| + continue; |
| + |
| + media::AudioDeviceName device_name; |
| + device_name.device_name = CFStringToSTLString(name); |
| + device_name.unique_id = CFStringToSTLString(uid); |
| + device_names->push_back(device_name); |
| + } |
| +} |
| + |
| AudioManagerMac::AudioManagerMac() |
| : num_output_streams_(0) { |
| } |
| @@ -82,15 +181,15 @@ |
| void AudioManagerMac::GetAudioInputDeviceNames( |
| media::AudioDeviceNames* device_names) { |
| - // TODO(xians): query a full list of valid devices. |
| - if (HasAudioInputDevices()) { |
| + GetAudioDeviceInfo(true, device_names); |
| + if (!device_names->empty()) { |
| // Add the default device to the list. |
| // We use index 0 to make up the unique_id to identify the |
| // default devices. |
| media::AudioDeviceName name; |
| name.device_name = AudioManagerBase::kDefaultDeviceName; |
| name.unique_id = "0"; |
| - device_names->push_back(name); |
| + device_names->push_front(name); |
|
Chris Rogers
2011/10/19 01:31:50
Probably worth a comment to describe why you're pu
no longer working on chromium
2011/10/19 17:32:18
Done.
|
| } |
| } |