| 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. |
| 236 static const AudioObjectPropertyAddress kDeviceChangePropertyAddress = { |
| 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 &kDeviceChangePropertyAddress, |
| 265 &OnDefaultDeviceChangedCallback, |
| 266 &listener_cb_); |
| 267 |
| 268 if (result != noErr) { |
| 269 OSSTATUS_DLOG(ERROR, result) << "AudioObjectAddPropertyListener() failed!"; |
| 270 listener_cb_.Reset(); |
| 271 } |
| 235 } | 272 } |
| 236 | 273 |
| 237 AudioManagerMac::~AudioManagerMac() { | 274 AudioManagerMac::~AudioManagerMac() { |
| 275 if (!listener_cb_.is_null()) { |
| 276 OSStatus result = AudioObjectRemovePropertyListener( |
| 277 kAudioObjectSystemObject, |
| 278 &kDeviceChangePropertyAddress, |
| 279 &OnDefaultDeviceChangedCallback, |
| 280 &listener_cb_); |
| 281 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 282 << "AudioObjectRemovePropertyListener() failed!"; |
| 283 } |
| 284 |
| 238 Shutdown(); | 285 Shutdown(); |
| 239 } | 286 } |
| 240 | 287 |
| 241 bool AudioManagerMac::HasAudioOutputDevices() { | 288 bool AudioManagerMac::HasAudioOutputDevices() { |
| 242 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); | 289 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); |
| 243 } | 290 } |
| 244 | 291 |
| 245 bool AudioManagerMac::HasAudioInputDevices() { | 292 bool AudioManagerMac::HasAudioInputDevices() { |
| 246 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); | 293 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); |
| 247 } | 294 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 stream = new AUAudioInputStream(this, params, audio_device_id); | 350 stream = new AUAudioInputStream(this, params, audio_device_id); |
| 304 | 351 |
| 305 return stream; | 352 return stream; |
| 306 } | 353 } |
| 307 | 354 |
| 308 AudioManager* CreateAudioManager() { | 355 AudioManager* CreateAudioManager() { |
| 309 return new AudioManagerMac(); | 356 return new AudioManagerMac(); |
| 310 } | 357 } |
| 311 | 358 |
| 312 } // namespace media | 359 } // namespace media |
| OLD | NEW |