| 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 <CoreAudio/AudioHardware.h> | 7 #include <CoreAudio/AudioHardware.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 AudioManagerMac::AudioManagerMac(AudioLogFactory* audio_log_factory) | 223 AudioManagerMac::AudioManagerMac(AudioLogFactory* audio_log_factory) |
| 224 : AudioManagerBase(audio_log_factory), | 224 : AudioManagerBase(audio_log_factory), |
| 225 current_sample_rate_(0) { | 225 current_sample_rate_(0) { |
| 226 current_output_device_ = kAudioDeviceUnknown; | 226 current_output_device_ = kAudioDeviceUnknown; |
| 227 | 227 |
| 228 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 228 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 229 | 229 |
| 230 // Task must be posted last to avoid races from handing out "this" to the | 230 // Task must be posted last to avoid races from handing out "this" to the |
| 231 // audio thread. Always PostTask even if we're on the right thread since | 231 // audio thread. Always PostTask even if we're on the right thread since |
| 232 // AudioManager creation is on the startup path and this may be slow. | 232 // AudioManager creation is on the startup path and this may be slow. |
| 233 GetMessageLoop()->PostTask(FROM_HERE, base::Bind( | 233 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
| 234 &AudioManagerMac::CreateDeviceListener, base::Unretained(this))); | 234 &AudioManagerMac::CreateDeviceListener, base::Unretained(this))); |
| 235 } | 235 } |
| 236 | 236 |
| 237 AudioManagerMac::~AudioManagerMac() { | 237 AudioManagerMac::~AudioManagerMac() { |
| 238 if (GetMessageLoop()->BelongsToCurrentThread()) { | 238 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 239 DestroyDeviceListener(); | 239 DestroyDeviceListener(); |
| 240 } else { | 240 } else { |
| 241 // It's safe to post a task here since Shutdown() will wait for all tasks to | 241 // It's safe to post a task here since Shutdown() will wait for all tasks to |
| 242 // complete before returning. | 242 // complete before returning. |
| 243 GetMessageLoop()->PostTask(FROM_HERE, base::Bind( | 243 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
| 244 &AudioManagerMac::DestroyDeviceListener, base::Unretained(this))); | 244 &AudioManagerMac::DestroyDeviceListener, base::Unretained(this))); |
| 245 } | 245 } |
| 246 | 246 |
| 247 Shutdown(); | 247 Shutdown(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 bool AudioManagerMac::HasAudioOutputDevices() { | 250 bool AudioManagerMac::HasAudioOutputDevices() { |
| 251 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); | 251 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); |
| 252 } | 252 } |
| 253 | 253 |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 input_channels, | 686 input_channels, |
| 687 hardware_sample_rate, | 687 hardware_sample_rate, |
| 688 16, | 688 16, |
| 689 buffer_size, | 689 buffer_size, |
| 690 AudioParameters::NO_EFFECTS); | 690 AudioParameters::NO_EFFECTS); |
| 691 | 691 |
| 692 return params; | 692 return params; |
| 693 } | 693 } |
| 694 | 694 |
| 695 void AudioManagerMac::CreateDeviceListener() { | 695 void AudioManagerMac::CreateDeviceListener() { |
| 696 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); | 696 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 697 | 697 |
| 698 // Get a baseline for the sample-rate and current device, | 698 // Get a baseline for the sample-rate and current device, |
| 699 // so we can intelligently handle device notifications only when necessary. | 699 // so we can intelligently handle device notifications only when necessary. |
| 700 current_sample_rate_ = HardwareSampleRate(); | 700 current_sample_rate_ = HardwareSampleRate(); |
| 701 if (!GetDefaultOutputDevice(¤t_output_device_)) | 701 if (!GetDefaultOutputDevice(¤t_output_device_)) |
| 702 current_output_device_ = kAudioDeviceUnknown; | 702 current_output_device_ = kAudioDeviceUnknown; |
| 703 | 703 |
| 704 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind( | 704 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind( |
| 705 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this)))); | 705 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this)))); |
| 706 } | 706 } |
| 707 | 707 |
| 708 void AudioManagerMac::DestroyDeviceListener() { | 708 void AudioManagerMac::DestroyDeviceListener() { |
| 709 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); | 709 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 710 output_device_listener_.reset(); | 710 output_device_listener_.reset(); |
| 711 } | 711 } |
| 712 | 712 |
| 713 void AudioManagerMac::HandleDeviceChanges() { | 713 void AudioManagerMac::HandleDeviceChanges() { |
| 714 if (!GetMessageLoop()->BelongsToCurrentThread()) { | 714 if (!GetTaskRunner()->BelongsToCurrentThread()) { |
| 715 GetMessageLoop()->PostTask(FROM_HERE, base::Bind( | 715 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
| 716 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this))); | 716 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this))); |
| 717 return; | 717 return; |
| 718 } | 718 } |
| 719 | 719 |
| 720 int new_sample_rate = HardwareSampleRate(); | 720 int new_sample_rate = HardwareSampleRate(); |
| 721 AudioDeviceID new_output_device; | 721 AudioDeviceID new_output_device; |
| 722 GetDefaultOutputDevice(&new_output_device); | 722 GetDefaultOutputDevice(&new_output_device); |
| 723 | 723 |
| 724 if (current_sample_rate_ == new_sample_rate && | 724 if (current_sample_rate_ == new_sample_rate && |
| 725 current_output_device_ == new_output_device) | 725 current_output_device_ == new_output_device) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 745 } | 745 } |
| 746 | 746 |
| 747 return buffer_size; | 747 return buffer_size; |
| 748 } | 748 } |
| 749 | 749 |
| 750 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 750 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { |
| 751 return new AudioManagerMac(audio_log_factory); | 751 return new AudioManagerMac(audio_log_factory); |
| 752 } | 752 } |
| 753 | 753 |
| 754 } // namespace media | 754 } // namespace media |
| OLD | NEW |