Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | |
| 9 #include "base/mac/mac_logging.h" | 10 #include "base/mac/mac_logging.h" |
| 10 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 12 #include "media/audio/mac/audio_input_mac.h" | 13 #include "media/audio/mac/audio_input_mac.h" |
| 13 #include "media/audio/mac/audio_low_latency_input_mac.h" | 14 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 14 #include "media/audio/mac/audio_low_latency_output_mac.h" | 15 #include "media/audio/mac/audio_low_latency_output_mac.h" |
| 15 #include "media/audio/mac/audio_manager_mac.h" | 16 #include "media/audio/mac/audio_manager_mac.h" |
| 16 #include "media/audio/mac/audio_output_mac.h" | 17 #include "media/audio/mac/audio_output_mac.h" |
| 18 #include "media/audio/mac/audio_synchronized_mac.h" | |
| 19 #include "media/audio/mac/audio_unified_mac.h" | |
| 17 #include "media/base/limits.h" | 20 #include "media/base/limits.h" |
| 21 #include "media/base/media_switches.h" | |
| 18 | 22 |
| 19 namespace media { | 23 namespace media { |
| 20 | 24 |
| 21 // Maximum number of output streams that can be open simultaneously. | 25 // Maximum number of output streams that can be open simultaneously. |
| 22 static const int kMaxOutputStreams = 50; | 26 static const int kMaxOutputStreams = 50; |
| 23 | 27 |
| 24 static bool HasAudioHardware(AudioObjectPropertySelector selector) { | 28 static bool HasAudioHardware(AudioObjectPropertySelector selector) { |
| 25 AudioDeviceID output_device_id = kAudioObjectUnknown; | 29 AudioDeviceID output_device_id = kAudioObjectUnknown; |
| 26 const AudioObjectPropertyAddress property_address = { | 30 const AudioObjectPropertyAddress property_address = { |
| 27 selector, | 31 selector, |
| 28 kAudioObjectPropertyScopeGlobal, // mScope | 32 kAudioObjectPropertyScopeGlobal, // mScope |
| 29 kAudioObjectPropertyElementMaster // mElement | 33 kAudioObjectPropertyElementMaster // mElement |
| 30 }; | 34 }; |
| 31 size_t output_device_id_size = sizeof(output_device_id); | 35 size_t output_device_id_size = sizeof(output_device_id); |
| 32 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 36 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
| 33 &property_address, | 37 &property_address, |
| 34 0, // inQualifierDataSize | 38 0, // inQualifierDataSize |
| 35 NULL, // inQualifierData | 39 NULL, // inQualifierData |
| 36 &output_device_id_size, | 40 &output_device_id_size, |
| 37 &output_device_id); | 41 &output_device_id); |
| 38 return err == kAudioHardwareNoError && | 42 return err == kAudioHardwareNoError && |
| 39 output_device_id != kAudioObjectUnknown; | 43 output_device_id != kAudioObjectUnknown; |
| 40 } | 44 } |
| 41 | 45 |
| 46 // Returns if the default input device is the same as the default output. | |
|
scherkus (not reviewing)
2012/09/17 23:07:17
Returns... true? :)
Chris Rogers
2012/09/18 00:22:36
Done.
| |
| 47 static bool HasUnifiedDefaultIO() { | |
| 48 AudioDeviceID input_id, output_id; | |
| 49 | |
| 50 AudioObjectPropertyAddress pa; | |
| 51 pa.mSelector = kAudioHardwarePropertyDefaultInputDevice; | |
| 52 pa.mScope = kAudioObjectPropertyScopeGlobal; | |
| 53 pa.mElement = kAudioObjectPropertyElementMaster; | |
| 54 UInt32 size = sizeof(input_id); | |
| 55 | |
| 56 // Get the default input. | |
| 57 OSStatus result = AudioObjectGetPropertyData( | |
| 58 kAudioObjectSystemObject, | |
| 59 &pa, | |
| 60 0, | |
| 61 0, | |
| 62 &size, | |
| 63 &input_id); | |
| 64 | |
| 65 if (result != noErr) | |
| 66 return false; | |
| 67 | |
| 68 // Get the default output. | |
| 69 pa.mSelector = kAudioHardwarePropertyDefaultOutputDevice; | |
| 70 result = AudioObjectGetPropertyData( | |
| 71 kAudioObjectSystemObject, | |
| 72 &pa, | |
| 73 0, | |
| 74 0, | |
| 75 &size, | |
| 76 &output_id); | |
| 77 | |
| 78 if (result != noErr) | |
| 79 return false; | |
| 80 | |
| 81 return input_id == output_id; | |
| 82 } | |
| 83 | |
| 42 static void GetAudioDeviceInfo(bool is_input, | 84 static void GetAudioDeviceInfo(bool is_input, |
| 43 media::AudioDeviceNames* device_names) { | 85 media::AudioDeviceNames* device_names) { |
| 44 DCHECK(device_names); | 86 DCHECK(device_names); |
| 45 device_names->clear(); | 87 device_names->clear(); |
| 46 | 88 |
| 47 // Query the number of total devices. | 89 // Query the number of total devices. |
| 48 AudioObjectPropertyAddress property_address = { | 90 AudioObjectPropertyAddress property_address = { |
| 49 kAudioHardwarePropertyDevices, | 91 kAudioHardwarePropertyDevices, |
| 50 kAudioObjectPropertyScopeGlobal, | 92 kAudioObjectPropertyScopeGlobal, |
| 51 kAudioObjectPropertyElementMaster | 93 kAudioObjectPropertyElementMaster |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 | 285 |
| 244 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( | 286 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( |
| 245 const AudioParameters& params) { | 287 const AudioParameters& params) { |
| 246 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 288 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 247 return new PCMQueueOutAudioOutputStream(this, params); | 289 return new PCMQueueOutAudioOutputStream(this, params); |
| 248 } | 290 } |
| 249 | 291 |
| 250 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( | 292 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( |
| 251 const AudioParameters& params) { | 293 const AudioParameters& params) { |
| 252 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 294 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 295 | |
| 296 // TODO(crogers): remove once we properly handle input device selection. | |
| 297 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 298 switches::kEnableWebAudioInput)) { | |
| 299 if (HasUnifiedDefaultIO()) { | |
| 300 return new AudioHardwareUnifiedStream(this, params); | |
| 301 } else { | |
|
scherkus (not reviewing)
2012/09/17 23:07:17
nit: no need for else due to early return
Chris Rogers
2012/09/18 00:22:36
Done.
| |
| 302 // kAudioDeviceUnknown translates to "use default" here. | |
| 303 return new AudioSynchronizedStream(this, | |
| 304 params, | |
| 305 kAudioDeviceUnknown, | |
| 306 kAudioDeviceUnknown); | |
| 307 } | |
| 308 } | |
| 309 | |
| 253 return new AUAudioOutputStream(this, params); | 310 return new AUAudioOutputStream(this, params); |
| 254 } | 311 } |
| 255 | 312 |
| 256 AudioInputStream* AudioManagerMac::MakeLinearInputStream( | 313 AudioInputStream* AudioManagerMac::MakeLinearInputStream( |
| 257 const AudioParameters& params, const std::string& device_id) { | 314 const AudioParameters& params, const std::string& device_id) { |
| 258 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 315 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 259 return new PCMQueueInAudioInputStream(this, params); | 316 return new PCMQueueInAudioInputStream(this, params); |
| 260 } | 317 } |
| 261 | 318 |
| 262 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( | 319 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( |
| 263 const AudioParameters& params, const std::string& device_id) { | 320 const AudioParameters& params, const std::string& device_id) { |
| 264 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 321 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 265 // Gets the AudioDeviceID that refers to the AudioOutputDevice with the device | 322 // Gets the AudioDeviceID that refers to the AudioOutputDevice with the device |
| 266 // unique id. This AudioDeviceID is used to set the device for Audio Unit. | 323 // unique id. This AudioDeviceID is used to set the device for Audio Unit. |
| 267 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); | 324 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); |
| 268 AudioInputStream* stream = NULL; | 325 AudioInputStream* stream = NULL; |
| 269 if (audio_device_id != kAudioObjectUnknown) | 326 if (audio_device_id != kAudioObjectUnknown) |
| 270 stream = new AUAudioInputStream(this, params, audio_device_id); | 327 stream = new AUAudioInputStream(this, params, audio_device_id); |
| 271 | 328 |
| 272 return stream; | 329 return stream; |
| 273 } | 330 } |
| 274 | 331 |
| 275 AudioManager* CreateAudioManager() { | 332 AudioManager* CreateAudioManager() { |
| 276 return new AudioManagerMac(); | 333 return new AudioManagerMac(); |
| 277 } | 334 } |
| 278 | 335 |
| 279 } // namespace media | 336 } // namespace media |
| OLD | NEW |