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/bind.h" | |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/mac/mac_logging.h" | 11 #include "base/mac/mac_logging.h" |
| 11 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 13 #include "media/audio/mac/audio_input_mac.h" | 14 #include "media/audio/mac/audio_input_mac.h" |
| 14 #include "media/audio/mac/audio_low_latency_input_mac.h" | 15 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 15 #include "media/audio/mac/audio_low_latency_output_mac.h" | 16 #include "media/audio/mac/audio_low_latency_output_mac.h" |
| 16 #include "media/audio/mac/audio_manager_mac.h" | 17 #include "media/audio/mac/audio_manager_mac.h" |
| 17 #include "media/audio/mac/audio_output_mac.h" | 18 #include "media/audio/mac/audio_output_mac.h" |
| 18 #include "media/audio/mac/audio_synchronized_mac.h" | 19 #include "media/audio/mac/audio_synchronized_mac.h" |
| 19 #include "media/audio/mac/audio_unified_mac.h" | 20 #include "media/audio/mac/audio_unified_mac.h" |
| 21 #include "media/base/bind_to_loop.h" | |
| 20 #include "media/base/limits.h" | 22 #include "media/base/limits.h" |
| 21 #include "media/base/media_switches.h" | 23 #include "media/base/media_switches.h" |
| 22 | 24 |
| 23 namespace media { | 25 namespace media { |
| 24 | 26 |
| 25 // Maximum number of output streams that can be open simultaneously. | 27 // Maximum number of output streams that can be open simultaneously. |
| 26 static const int kMaxOutputStreams = 50; | 28 static const int kMaxOutputStreams = 50; |
| 27 | 29 |
| 28 static bool HasAudioHardware(AudioObjectPropertySelector selector) { | 30 static bool HasAudioHardware(AudioObjectPropertySelector selector) { |
| 29 AudioDeviceID output_device_id = kAudioObjectUnknown; | 31 AudioDeviceID output_device_id = kAudioObjectUnknown; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 } | 225 } |
| 224 | 226 |
| 225 if (result) { | 227 if (result) { |
| 226 OSSTATUS_DLOG(WARNING, result) << "Unable to query device " << device_id | 228 OSSTATUS_DLOG(WARNING, result) << "Unable to query device " << device_id |
| 227 << " for AudioDeviceID"; | 229 << " for AudioDeviceID"; |
| 228 } | 230 } |
| 229 | 231 |
| 230 return audio_device_id; | 232 return audio_device_id; |
| 231 } | 233 } |
| 232 | 234 |
| 235 // Property address to monitor for device changes. | |
|
scherkus (not reviewing)
2012/11/01 01:20:14
how about replacing this comment by changing kPA t
DaleCurtis
2012/11/01 01:28:17
Whoops, yeah that old name is a bad choice now. Do
| |
| 236 static const AudioObjectPropertyAddress kPropertyAddress = { | |
| 237 kAudioHardwarePropertyDefaultOutputDevice, | |
| 238 kAudioObjectPropertyScopeGlobal, | |
| 239 kAudioObjectPropertyElementMaster | |
| 240 }; | |
| 241 | |
| 242 // Callback from the system when the default device changes. This can be called | |
| 243 // either on the main thread or on an audio thread managed by the system | |
| 244 // depending on what kAudioHardwarePropertyRunLoop is set to. | |
| 245 static OSStatus OnDefaultDeviceChangedCallback( | |
| 246 AudioObjectID object, | |
| 247 UInt32 size, | |
| 248 const AudioObjectPropertyAddress addresses[], | |
| 249 void* context) { | |
| 250 static_cast<base::Closure*>(context)->Run(); | |
| 251 return noErr; | |
| 252 } | |
| 253 | |
| 233 AudioManagerMac::AudioManagerMac() { | 254 AudioManagerMac::AudioManagerMac() { |
| 234 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 255 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 256 | |
| 257 // Register a callback for device changes. | |
| 258 listener_cb_ = BindToLoop(GetMessageLoop(), base::Bind( | |
| 259 &AudioManagerMac::NotifyAllOutputDeviceChangeListeners, | |
| 260 base::Unretained(this))); | |
| 261 | |
| 262 OSStatus result = AudioObjectAddPropertyListener( | |
| 263 kAudioObjectSystemObject, | |
| 264 &kPropertyAddress, | |
| 265 &OnDefaultDeviceChangedCallback, | |
| 266 &listener_cb_); | |
| 267 | |
| 268 // Clear |listener_cb_| so we don't try to remove the listener later. | |
|
scherkus (not reviewing)
2012/11/01 01:20:14
comment isn't adding value given proximity to dtor
DaleCurtis
2012/11/01 01:28:17
Done.
| |
| 269 if (result != noErr) { | |
| 270 OSSTATUS_DLOG(ERROR, result) << "AudioObjectAddPropertyListener() failed!"; | |
| 271 listener_cb_.Reset(); | |
| 272 } | |
| 235 } | 273 } |
| 236 | 274 |
| 237 AudioManagerMac::~AudioManagerMac() { | 275 AudioManagerMac::~AudioManagerMac() { |
| 276 // Tear down our listener. | |
|
scherkus (not reviewing)
2012/11/01 01:20:14
comment isn't adding value
DaleCurtis
2012/11/01 01:28:17
Done.
| |
| 277 if (!listener_cb_.is_null()) { | |
| 278 OSStatus result = AudioObjectRemovePropertyListener( | |
| 279 kAudioObjectSystemObject, | |
| 280 &kPropertyAddress, | |
| 281 &OnDefaultDeviceChangedCallback, | |
| 282 &listener_cb_); | |
| 283 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | |
| 284 << "AudioObjectRemovePropertyListener() failed!"; | |
| 285 } | |
| 286 | |
| 238 Shutdown(); | 287 Shutdown(); |
| 239 } | 288 } |
| 240 | 289 |
| 241 bool AudioManagerMac::HasAudioOutputDevices() { | 290 bool AudioManagerMac::HasAudioOutputDevices() { |
| 242 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); | 291 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); |
| 243 } | 292 } |
| 244 | 293 |
| 245 bool AudioManagerMac::HasAudioInputDevices() { | 294 bool AudioManagerMac::HasAudioInputDevices() { |
| 246 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); | 295 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); |
| 247 } | 296 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 stream = new AUAudioInputStream(this, params, audio_device_id); | 352 stream = new AUAudioInputStream(this, params, audio_device_id); |
| 304 | 353 |
| 305 return stream; | 354 return stream; |
| 306 } | 355 } |
| 307 | 356 |
| 308 AudioManager* CreateAudioManager() { | 357 AudioManager* CreateAudioManager() { |
| 309 return new AudioManagerMac(); | 358 return new AudioManagerMac(); |
| 310 } | 359 } |
| 311 | 360 |
| 312 } // namespace media | 361 } // namespace media |
| OLD | NEW |