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/mac/scoped_cftyperef.h" | |
| 8 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 9 #include "media/audio/fake_audio_input_stream.h" | 10 #include "media/audio/fake_audio_input_stream.h" |
| 10 #include "media/audio/fake_audio_output_stream.h" | 11 #include "media/audio/fake_audio_output_stream.h" |
| 11 #include "media/audio/mac/audio_input_mac.h" | 12 #include "media/audio/mac/audio_input_mac.h" |
| 12 #include "media/audio/mac/audio_low_latency_input_mac.h" | 13 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 13 #include "media/audio/mac/audio_low_latency_output_mac.h" | 14 #include "media/audio/mac/audio_low_latency_output_mac.h" |
| 14 #include "media/audio/mac/audio_manager_mac.h" | 15 #include "media/audio/mac/audio_manager_mac.h" |
| 15 #include "media/audio/mac/audio_output_mac.h" | 16 #include "media/audio/mac/audio_output_mac.h" |
| 16 #include "media/base/limits.h" | 17 #include "media/base/limits.h" |
| 17 | 18 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 // We are responsible for releasing the returned CFObject. See the | 176 // We are responsible for releasing the returned CFObject. See the |
| 176 // comment in the AudioHardware.h for constant | 177 // comment in the AudioHardware.h for constant |
| 177 // kAudioDevicePropertyDeviceUID. | 178 // kAudioDevicePropertyDeviceUID. |
| 178 if (uid) | 179 if (uid) |
| 179 CFRelease(uid); | 180 CFRelease(uid); |
| 180 if (name) | 181 if (name) |
| 181 CFRelease(name); | 182 CFRelease(name); |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 | 185 |
| 186 static AudioDeviceID GetAudioDeviceIdByUId(bool is_input, | |
| 187 const std::string& device_uid) { | |
| 188 AudioObjectPropertyAddress property_address = { | |
| 189 kAudioHardwarePropertyDevices, | |
| 190 kAudioObjectPropertyScopeGlobal, | |
| 191 kAudioObjectPropertyElementMaster | |
| 192 }; | |
| 193 AudioDeviceID audio_device_id = kAudioObjectUnknown; | |
| 194 UInt32 device_size = sizeof(audio_device_id); | |
| 195 OSStatus result = -1; | |
| 196 | |
| 197 if (device_id == AudioManagerBase::kDefaultDeviceId) { | |
| 198 // Default Device. | |
| 199 if (is_input) | |
| 200 property_address.mSelector = kAudioHardwarePropertyDefaultInputDevice; | |
|
tommi (sloooow) - chröme
2011/11/17 10:24:16
nit: instead of if/else for this kind of initializ
no longer working on chromium
2011/11/17 14:15:26
Done.
| |
| 201 else | |
| 202 property_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice; | |
| 203 | |
| 204 result = AudioObjectGetPropertyData(kAudioObjectSystemObject, | |
| 205 &property_address, | |
| 206 0, | |
| 207 0, | |
| 208 &device_size, | |
| 209 &audio_device_id); | |
| 210 } else { // Non-default device. | |
|
henrika (OOO until Aug 14)
2011/11/17 11:26:15
comment on separate line
no longer working on chromium
2011/11/17 14:15:26
Done.
| |
| 211 base::mac::ScopedCFTypeRef<CFStringRef> | |
| 212 uid(base::SysUTF8ToCFStringRef(device_uid)); | |
| 213 AudioValueTranslation value; | |
| 214 value.mInputData = &uid; | |
| 215 value.mInputDataSize = sizeof(CFStringRef); | |
| 216 value.mOutputData = &audio_device_id; | |
| 217 value.mOutputDataSize = device_size; | |
| 218 UInt32 translation_size = sizeof(AudioValueTranslation); | |
| 219 | |
| 220 property_address.mSelector = kAudioHardwarePropertyDeviceForUID; | |
| 221 result = AudioObjectGetPropertyData(kAudioObjectSystemObject, | |
| 222 &property_address, | |
| 223 0, //translation_size, | |
|
tommi (sloooow) - chröme
2011/11/17 10:24:16
are you going to remove these comments?
no longer working on chromium
2011/11/17 14:15:26
Done.
| |
| 224 0, //&value, | |
| 225 &translation_size, | |
| 226 &value); | |
| 227 } | |
| 228 | |
| 229 if (result) | |
| 230 DLOG(WARNING) << "Unable to query device " << device_id | |
| 231 << " for AudioDeviceID "; | |
|
tommi (sloooow) - chröme
2011/11/17 10:24:16
use {} when the body spans more than one line.
no longer working on chromium
2011/11/17 14:15:26
Done.
| |
| 232 | |
| 233 return audio_device_id; | |
| 234 } | |
| 235 | |
| 185 AudioManagerMac::AudioManagerMac() | 236 AudioManagerMac::AudioManagerMac() |
| 186 : num_output_streams_(0) { | 237 : num_output_streams_(0) { |
| 187 } | 238 } |
| 188 | 239 |
| 189 AudioManagerMac::~AudioManagerMac() { | 240 AudioManagerMac::~AudioManagerMac() { |
| 190 } | 241 } |
| 191 | 242 |
| 192 bool AudioManagerMac::HasAudioOutputDevices() { | 243 bool AudioManagerMac::HasAudioOutputDevices() { |
| 193 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); | 244 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); |
| 194 } | 245 } |
| 195 | 246 |
| 196 bool AudioManagerMac::HasAudioInputDevices() { | 247 bool AudioManagerMac::HasAudioInputDevices() { |
| 197 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); | 248 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); |
| 198 } | 249 } |
| 199 | 250 |
| 200 void AudioManagerMac::GetAudioInputDeviceNames( | 251 void AudioManagerMac::GetAudioInputDeviceNames( |
| 201 media::AudioDeviceNames* device_names) { | 252 media::AudioDeviceNames* device_names) { |
| 202 // This is needed because AudioObjectGetPropertyDataSize has memory leak | 253 // This is needed because AudioObjectGetPropertyDataSize has memory leak |
| 203 // when there is no soundcard in the machine. | 254 // when there is no soundcard in the machine. |
| 204 if (!HasAudioInputDevices()) | 255 if (!HasAudioInputDevices()) |
| 205 return; | 256 return; |
| 206 | 257 |
| 207 GetAudioDeviceInfo(true, device_names); | 258 GetAudioDeviceInfo(true, device_names); |
| 208 if (!device_names->empty()) { | 259 if (!device_names->empty()) { |
| 209 // Prepend the default device to the list since we always want it to be | 260 // Prepend the default device to the list since we always want it to be |
| 210 // on the top of the list for all platforms. There is no duplicate | 261 // on the top of the list for all platforms. There is no duplicate |
| 211 // counting here since the default device has been abstracted out before. | 262 // counting here since the default device has been abstracted out before. |
| 212 media::AudioDeviceName name; | 263 media::AudioDeviceName name; |
| 213 name.device_name = AudioManagerBase::kDefaultDeviceName; | 264 name.device_name = AudioManagerBase::kDefaultDeviceName; |
| 214 name.unique_id = "0"; | 265 name.unique_id = AudioManagerBase::kDefaultDeviceId; |
| 215 device_names->push_front(name); | 266 device_names->push_front(name); |
| 216 } | 267 } |
| 217 } | 268 } |
| 218 | 269 |
| 219 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( | 270 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( |
| 220 const AudioParameters& params) { | 271 const AudioParameters& params) { |
| 221 if (!params.IsValid()) | 272 if (!params.IsValid()) |
| 222 return NULL; | 273 return NULL; |
| 223 | 274 |
| 224 // Limit the number of audio streams opened. This is to prevent using | 275 // Limit the number of audio streams opened. This is to prevent using |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 235 num_output_streams_++; | 286 num_output_streams_++; |
| 236 return new PCMQueueOutAudioOutputStream(this, params); | 287 return new PCMQueueOutAudioOutputStream(this, params); |
| 237 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 288 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| 238 num_output_streams_++; | 289 num_output_streams_++; |
| 239 return new AUAudioOutputStream(this, params); | 290 return new AUAudioOutputStream(this, params); |
| 240 } | 291 } |
| 241 return NULL; | 292 return NULL; |
| 242 } | 293 } |
| 243 | 294 |
| 244 AudioInputStream* AudioManagerMac::MakeAudioInputStream( | 295 AudioInputStream* AudioManagerMac::MakeAudioInputStream( |
| 245 const AudioParameters& params) { | 296 const AudioParameters& params, const std::string& device_id) { |
| 246 if (!params.IsValid() || (params.channels > kMaxInputChannels)) | 297 if (!params.IsValid() || (params.channels > kMaxInputChannels)) |
| 247 return NULL; | 298 return NULL; |
| 248 | 299 |
| 249 if (params.format == AudioParameters::AUDIO_MOCK) { | 300 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 250 return FakeAudioInputStream::MakeFakeStream(params); | 301 return FakeAudioInputStream::MakeFakeStream(params); |
| 251 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 302 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
| 252 return new PCMQueueInAudioInputStream(this, params); | 303 return new PCMQueueInAudioInputStream(this, params); |
| 253 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 304 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| 254 return new AUAudioInputStream(this, params); | 305 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); |
|
henrika (OOO until Aug 14)
2011/11/17 11:26:15
Lots of IDs here..
At lest add a comment explainin
no longer working on chromium
2011/11/17 14:15:26
Done.
| |
| 306 if (audio_device_id != kAudioObjectUnknown) | |
| 307 return new AUAudioInputStream(this, params, audio_device_id); | |
| 255 } | 308 } |
| 256 return NULL; | 309 return NULL; |
| 257 } | 310 } |
| 258 | 311 |
| 259 void AudioManagerMac::MuteAll() { | 312 void AudioManagerMac::MuteAll() { |
| 260 // TODO(cpu): implement. | 313 // TODO(cpu): implement. |
| 261 } | 314 } |
| 262 | 315 |
| 263 void AudioManagerMac::UnMuteAll() { | 316 void AudioManagerMac::UnMuteAll() { |
| 264 // TODO(cpu): implement. | 317 // TODO(cpu): implement. |
| 265 } | 318 } |
| 266 | 319 |
| 267 // Called by the stream when it has been released by calling Close(). | 320 // Called by the stream when it has been released by calling Close(). |
| 268 void AudioManagerMac::ReleaseOutputStream(AudioOutputStream* stream) { | 321 void AudioManagerMac::ReleaseOutputStream(AudioOutputStream* stream) { |
| 269 DCHECK(stream); | 322 DCHECK(stream); |
| 270 num_output_streams_--; | 323 num_output_streams_--; |
| 271 delete stream; | 324 delete stream; |
| 272 } | 325 } |
| 273 | 326 |
| 274 // Called by the stream when it has been released by calling Close(). | 327 // Called by the stream when it has been released by calling Close(). |
| 275 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { | 328 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { |
| 276 delete stream; | 329 delete stream; |
| 277 } | 330 } |
| 278 | 331 |
| 279 // static | 332 // static |
| 280 AudioManager* AudioManager::CreateAudioManager() { | 333 AudioManager* AudioManager::CreateAudioManager() { |
| 281 return new AudioManagerMac(); | 334 return new AudioManagerMac(); |
| 282 } | 335 } |
| OLD | NEW |