Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <CoreAudio/AudioHardware.h> | 5 #include <CoreAudio/AudioHardware.h> |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/sys_string_conversions.h" | |
| 8 #include "media/audio/fake_audio_input_stream.h" | 9 #include "media/audio/fake_audio_input_stream.h" |
| 9 #include "media/audio/fake_audio_output_stream.h" | 10 #include "media/audio/fake_audio_output_stream.h" |
| 10 #include "media/audio/mac/audio_input_mac.h" | 11 #include "media/audio/mac/audio_input_mac.h" |
| 11 #include "media/audio/mac/audio_low_latency_input_mac.h" | 12 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 12 #include "media/audio/mac/audio_low_latency_output_mac.h" | 13 #include "media/audio/mac/audio_low_latency_output_mac.h" |
| 13 #include "media/audio/mac/audio_manager_mac.h" | 14 #include "media/audio/mac/audio_manager_mac.h" |
| 14 #include "media/audio/mac/audio_output_mac.h" | 15 #include "media/audio/mac/audio_output_mac.h" |
| 15 #include "media/base/limits.h" | 16 #include "media/base/limits.h" |
| 16 | 17 |
| 17 static const int kMaxInputChannels = 2; | 18 static const int kMaxInputChannels = 2; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 59 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
| 59 &property_address, | 60 &property_address, |
| 60 0, // inQualifierDataSize | 61 0, // inQualifierDataSize |
| 61 NULL, // inQualifierData | 62 NULL, // inQualifierData |
| 62 &output_device_id_size, | 63 &output_device_id_size, |
| 63 &output_device_id); | 64 &output_device_id); |
| 64 return err == kAudioHardwareNoError && | 65 return err == kAudioHardwareNoError && |
| 65 output_device_id != kAudioObjectUnknown; | 66 output_device_id != kAudioObjectUnknown; |
| 66 } | 67 } |
| 67 | 68 |
| 69 static void GetAudioDeviceInfo(bool is_input, | |
| 70 media::AudioDeviceNames* device_names) { | |
| 71 DCHECK(device_names); | |
| 72 | |
|
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.
| |
| 73 device_names->clear(); | |
| 74 | |
| 75 // Query the number of total devices. | |
| 76 AudioObjectPropertyAddress property_address = { | |
| 77 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
| |
| 78 kAudioObjectPropertyScopeGlobal, // mScope | |
| 79 kAudioObjectPropertyElementMaster // mElement | |
| 80 }; | |
| 81 UInt32 size = 0; | |
| 82 OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, | |
| 83 &property_address, | |
| 84 0, | |
| 85 NULL, | |
| 86 &size); | |
| 87 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
| |
| 88 return; | |
| 89 | |
| 90 int device_count = 0; | |
| 91 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
| |
| 92 | |
| 93 // 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
| |
| 94 scoped_ptr_malloc<AudioDeviceID> | |
| 95 devices(reinterpret_cast<AudioDeviceID*>(malloc(size))); | |
| 96 AudioDeviceID* device_ids = devices.get(); | |
| 97 result = AudioObjectGetPropertyData(kAudioObjectSystemObject, | |
| 98 &property_address, | |
| 99 0, | |
| 100 NULL, | |
| 101 &size, | |
| 102 device_ids); | |
| 103 if (result) | |
| 104 return; | |
| 105 | |
| 106 // 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.
| |
| 107 for (int i = 0; i < device_count; ++i) { | |
| 108 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
| |
| 109 // Get the number of input or output channels of the device, exclude | |
| 110 // 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
| |
| 111 AudioDeviceGetPropertyInfo(device_ids[i], | |
| 112 0, | |
| 113 is_input, | |
| 114 kAudioDevicePropertyStreamConfiguration, | |
| 115 &size, | |
| 116 NULL); | |
| 117 scoped_ptr_malloc<AudioBufferList> | |
| 118 buffer(reinterpret_cast<AudioBufferList*>(malloc(size))); | |
| 119 AudioBufferList* buffer_list = buffer.get(); | |
| 120 AudioDeviceGetProperty(device_ids[i], | |
| 121 0, | |
| 122 is_input, | |
| 123 kAudioDevicePropertyStreamConfiguration, | |
| 124 &size, | |
| 125 buffer_list); | |
| 126 | |
| 127 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
| |
| 128 channels += buffer_list->mBuffers[j].mNumberChannels; | |
| 129 | |
| 130 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
| |
| 131 continue; | |
| 132 | |
| 133 // Get device UID. | |
| 134 CFStringRef uid = NULL; | |
| 135 size = sizeof(uid); | |
| 136 result = AudioDeviceGetProperty(device_ids[i], | |
| 137 0, | |
| 138 is_input, | |
| 139 kAudioDevicePropertyDeviceUID, | |
| 140 &size, | |
| 141 &uid); | |
| 142 if (result) | |
| 143 continue; | |
| 144 | |
| 145 // Get device name. | |
| 146 CFStringRef name = NULL; | |
| 147 result = AudioDeviceGetProperty(device_ids[i], | |
| 148 0, | |
| 149 is_input, | |
| 150 kAudioObjectPropertyName, | |
| 151 &size, | |
| 152 &name); | |
| 153 if (result) | |
| 154 continue; | |
| 155 | |
| 156 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.
| |
| 157 device_name.device_name = base::SysCFStringRefToUTF8(name); | |
| 158 device_name.unique_id = base::SysCFStringRefToUTF8(uid); | |
| 159 device_names->push_back(device_name); | |
| 160 } | |
| 161 } | |
| 162 | |
| 68 AudioManagerMac::AudioManagerMac() | 163 AudioManagerMac::AudioManagerMac() |
| 69 : num_output_streams_(0) { | 164 : num_output_streams_(0) { |
| 70 } | 165 } |
| 71 | 166 |
| 72 AudioManagerMac::~AudioManagerMac() { | 167 AudioManagerMac::~AudioManagerMac() { |
| 73 } | 168 } |
| 74 | 169 |
| 75 bool AudioManagerMac::HasAudioOutputDevices() { | 170 bool AudioManagerMac::HasAudioOutputDevices() { |
| 76 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); | 171 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); |
| 77 } | 172 } |
| 78 | 173 |
| 79 bool AudioManagerMac::HasAudioInputDevices() { | 174 bool AudioManagerMac::HasAudioInputDevices() { |
| 80 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); | 175 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); |
| 81 } | 176 } |
| 82 | 177 |
| 83 void AudioManagerMac::GetAudioInputDeviceNames( | 178 void AudioManagerMac::GetAudioInputDeviceNames( |
| 84 media::AudioDeviceNames* device_names) { | 179 media::AudioDeviceNames* device_names) { |
| 85 // TODO(xians): query a full list of valid devices. | 180 GetAudioDeviceInfo(true, device_names); |
| 86 if (HasAudioInputDevices()) { | 181 if (!device_names->empty()) { |
| 87 // Add the default device to the list. | 182 // Prepend the default device to the list since we always want it to be |
| 88 // We use index 0 to make up the unique_id to identify the | 183 // on the top of the list for all platforms. There is no duplicate |
| 89 // default devices. | 184 // counting here since the default device has been abstracted out before. |
| 90 media::AudioDeviceName name; | 185 media::AudioDeviceName name; |
| 91 name.device_name = AudioManagerBase::kDefaultDeviceName; | 186 name.device_name = AudioManagerBase::kDefaultDeviceName; |
| 92 name.unique_id = "0"; | 187 name.unique_id = "0"; |
| 93 device_names->push_back(name); | 188 device_names->push_front(name); |
| 94 } | 189 } |
| 95 } | 190 } |
| 96 | 191 |
| 97 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( | 192 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( |
| 98 const AudioParameters& params) { | 193 const AudioParameters& params) { |
| 99 if (!params.IsValid()) | 194 if (!params.IsValid()) |
| 100 return NULL; | 195 return NULL; |
| 101 | 196 |
| 102 // Limit the number of audio streams opened. This is to prevent using | 197 // Limit the number of audio streams opened. This is to prevent using |
| 103 // excessive resources for a large number of audio streams. More | 198 // excessive resources for a large number of audio streams. More |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 246 |
| 152 // Called by the stream when it has been released by calling Close(). | 247 // Called by the stream when it has been released by calling Close(). |
| 153 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { | 248 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { |
| 154 delete stream; | 249 delete stream; |
| 155 } | 250 } |
| 156 | 251 |
| 157 // static | 252 // static |
| 158 AudioManager* AudioManager::CreateAudioManager() { | 253 AudioManager* AudioManager::CreateAudioManager() { |
| 159 return new AudioManagerMac(); | 254 return new AudioManagerMac(); |
| 160 } | 255 } |
| OLD | NEW |