| 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 "media/audio/mac/audio_manager_mac.h" | 5 #include "media/audio/mac/audio_manager_mac.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/mac/mac_logging.h" | 11 #include "base/mac/mac_logging.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/free_deleter.h" | 14 #include "base/memory/free_deleter.h" |
| 15 #include "base/power_monitor/power_monitor.h" | 15 #include "base/power_monitor/power_monitor.h" |
| 16 #include "base/power_monitor/power_observer.h" | 16 #include "base/power_monitor/power_observer.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "media/audio/audio_device_description.h" |
| 19 #include "media/audio/mac/audio_auhal_mac.h" | 20 #include "media/audio/mac/audio_auhal_mac.h" |
| 20 #include "media/audio/mac/audio_input_mac.h" | 21 #include "media/audio/mac/audio_input_mac.h" |
| 21 #include "media/audio/mac/audio_low_latency_input_mac.h" | 22 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 22 #include "media/base/audio_parameters.h" | 23 #include "media/base/audio_parameters.h" |
| 23 #include "media/base/bind_to_current_loop.h" | 24 #include "media/base/bind_to_current_loop.h" |
| 24 #include "media/base/channel_layout.h" | 25 #include "media/base/channel_layout.h" |
| 25 #include "media/base/limits.h" | 26 #include "media/base/limits.h" |
| 26 #include "media/base/media_switches.h" | 27 #include "media/base/media_switches.h" |
| 27 | 28 |
| 28 namespace media { | 29 namespace media { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (uid) | 203 if (uid) |
| 203 CFRelease(uid); | 204 CFRelease(uid); |
| 204 if (name) | 205 if (name) |
| 205 CFRelease(name); | 206 CFRelease(name); |
| 206 } | 207 } |
| 207 | 208 |
| 208 if (!device_names->empty()) { | 209 if (!device_names->empty()) { |
| 209 // Prepend the default device to the list since we always want it to be | 210 // 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 | 211 // 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. | 212 // counting here since the default device has been abstracted out before. |
| 212 media::AudioDeviceName name; | 213 device_names->push_front(media::AudioDeviceName::CreateDefault()); |
| 213 name.device_name = AudioManager::GetDefaultDeviceName(); | |
| 214 name.unique_id = AudioManagerBase::kDefaultDeviceId; | |
| 215 device_names->push_front(name); | |
| 216 } | 214 } |
| 217 } | 215 } |
| 218 | 216 |
| 219 static AudioDeviceID GetAudioDeviceIdByUId(bool is_input, | 217 static AudioDeviceID GetAudioDeviceIdByUId(bool is_input, |
| 220 const std::string& device_id) { | 218 const std::string& device_id) { |
| 221 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 219 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 222 AudioObjectPropertyAddress property_address = { | 220 AudioObjectPropertyAddress property_address = { |
| 223 kAudioHardwarePropertyDevices, | 221 kAudioHardwarePropertyDevices, |
| 224 kAudioObjectPropertyScopeGlobal, | 222 kAudioObjectPropertyScopeGlobal, |
| 225 kAudioObjectPropertyElementMaster | 223 kAudioObjectPropertyElementMaster |
| 226 }; | 224 }; |
| 227 AudioDeviceID audio_device_id = kAudioObjectUnknown; | 225 AudioDeviceID audio_device_id = kAudioObjectUnknown; |
| 228 UInt32 device_size = sizeof(audio_device_id); | 226 UInt32 device_size = sizeof(audio_device_id); |
| 229 OSStatus result = -1; | 227 OSStatus result = -1; |
| 230 | 228 |
| 231 if (device_id == AudioManagerBase::kDefaultDeviceId || device_id.empty()) { | 229 if (AudioDeviceDescription::IsDefaultDevice(device_id)) { |
| 232 // Default Device. | 230 // Default Device. |
| 233 property_address.mSelector = is_input ? | 231 property_address.mSelector = is_input ? |
| 234 kAudioHardwarePropertyDefaultInputDevice : | 232 kAudioHardwarePropertyDefaultInputDevice : |
| 235 kAudioHardwarePropertyDefaultOutputDevice; | 233 kAudioHardwarePropertyDefaultOutputDevice; |
| 236 | 234 |
| 237 result = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 235 result = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
| 238 &property_address, | 236 &property_address, |
| 239 0, | 237 0, |
| 240 0, | 238 0, |
| 241 &device_size, | 239 &device_size, |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 AudioDeviceID device = GetAudioDeviceIdByUId(false, device_id); | 621 AudioDeviceID device = GetAudioDeviceIdByUId(false, device_id); |
| 624 if (device == kAudioObjectUnknown) { | 622 if (device == kAudioObjectUnknown) { |
| 625 DLOG(ERROR) << "Failed to open output device: " << device_id; | 623 DLOG(ERROR) << "Failed to open output device: " << device_id; |
| 626 return NULL; | 624 return NULL; |
| 627 } | 625 } |
| 628 | 626 |
| 629 // Only set the device and sample rate if we just initialized the device | 627 // Only set the device and sample rate if we just initialized the device |
| 630 // listener. | 628 // listener. |
| 631 if (device_listener_first_init) { | 629 if (device_listener_first_init) { |
| 632 // Only set the current output device for the default device. | 630 // Only set the current output device for the default device. |
| 633 if (device_id == AudioManagerBase::kDefaultDeviceId || device_id.empty()) | 631 if (AudioDeviceDescription::IsDefaultDevice(device_id)) |
| 634 current_output_device_ = device; | 632 current_output_device_ = device; |
| 635 // Just use the current sample rate since we don't allow non-native sample | 633 // Just use the current sample rate since we don't allow non-native sample |
| 636 // rates on OSX. | 634 // rates on OSX. |
| 637 current_sample_rate_ = params.sample_rate(); | 635 current_sample_rate_ = params.sample_rate(); |
| 638 } | 636 } |
| 639 | 637 |
| 640 AUHALStream* stream = new AUHALStream(this, params, device); | 638 AUHALStream* stream = new AUHALStream(this, params, device); |
| 641 output_streams_.push_back(stream); | 639 output_streams_.push_back(stream); |
| 642 return stream; | 640 return stream; |
| 643 } | 641 } |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 ScopedAudioManagerPtr CreateAudioManager( | 935 ScopedAudioManagerPtr CreateAudioManager( |
| 938 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 936 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 939 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 937 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 940 AudioLogFactory* audio_log_factory) { | 938 AudioLogFactory* audio_log_factory) { |
| 941 return ScopedAudioManagerPtr( | 939 return ScopedAudioManagerPtr( |
| 942 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), | 940 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), |
| 943 audio_log_factory)); | 941 audio_log_factory)); |
| 944 } | 942 } |
| 945 | 943 |
| 946 } // namespace media | 944 } // namespace media |
| OLD | NEW |