Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: media/audio/mac/audio_manager_mac.cc

Issue 187693006: Always PostTask device change notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rietveld!!! Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 const AudioParameters& params, 559 const AudioParameters& params,
560 const std::string& device_id) { 560 const std::string& device_id) {
561 AudioDeviceID device = GetAudioDeviceIdByUId(false, device_id); 561 AudioDeviceID device = GetAudioDeviceIdByUId(false, device_id);
562 if (device == kAudioObjectUnknown) { 562 if (device == kAudioObjectUnknown) {
563 DLOG(ERROR) << "Failed to open output device: " << device_id; 563 DLOG(ERROR) << "Failed to open output device: " << device_id;
564 return NULL; 564 return NULL;
565 } 565 }
566 566
567 // Lazily create the audio device listener on the first stream creation. 567 // Lazily create the audio device listener on the first stream creation.
568 if (!output_device_listener_) { 568 if (!output_device_listener_) {
569 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind( 569 output_device_listener_.reset(
wolenetz 2014/03/06 16:01:42 nit: add comment about why BTCL is required here v
DaleCurtis 2014/03/06 19:27:37 Done.
570 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this)))); 570 new AudioDeviceListenerMac(BindToCurrentLoop(base::Bind(
wolenetz 2014/03/06 16:01:42 I'm not too familiar with audio pipeline. Is it po
DaleCurtis 2014/03/06 19:27:37 No, in most cases AM shutdown blocks on the audio
571 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this)))));
571 // Only set the current output device for the default device. 572 // Only set the current output device for the default device.
572 if (device_id == AudioManagerBase::kDefaultDeviceId || device_id.empty()) 573 if (device_id == AudioManagerBase::kDefaultDeviceId || device_id.empty())
573 current_output_device_ = device; 574 current_output_device_ = device;
574 // Just use the current sample rate since we don't allow non-native sample 575 // Just use the current sample rate since we don't allow non-native sample
575 // rates on OSX. 576 // rates on OSX.
576 current_sample_rate_ = params.sample_rate(); 577 current_sample_rate_ = params.sample_rate();
577 } 578 }
578 579
579 return new AUHALStream(this, params, device); 580 return new AUHALStream(this, params, device);
580 } 581 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 power_observer_.reset(new AudioPowerObserver()); 692 power_observer_.reset(new AudioPowerObserver());
692 } 693 }
693 694
694 void AudioManagerMac::ShutdownOnAudioThread() { 695 void AudioManagerMac::ShutdownOnAudioThread() {
695 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 696 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
696 output_device_listener_.reset(); 697 output_device_listener_.reset();
697 power_observer_.reset(); 698 power_observer_.reset();
698 } 699 }
699 700
700 void AudioManagerMac::HandleDeviceChanges() { 701 void AudioManagerMac::HandleDeviceChanges() {
701 if (!GetTaskRunner()->BelongsToCurrentThread()) { 702 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
702 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( 703 const int new_sample_rate = HardwareSampleRate();
703 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this)));
704 return;
705 }
706
707 int new_sample_rate = HardwareSampleRate();
708 AudioDeviceID new_output_device; 704 AudioDeviceID new_output_device;
709 GetDefaultOutputDevice(&new_output_device); 705 GetDefaultOutputDevice(&new_output_device);
710 706
711 if (current_sample_rate_ == new_sample_rate && 707 if (current_sample_rate_ == new_sample_rate &&
712 current_output_device_ == new_output_device) 708 current_output_device_ == new_output_device)
713 return; 709 return;
714 710
715 current_sample_rate_ = new_sample_rate; 711 current_sample_rate_ = new_sample_rate;
716 current_output_device_ = new_output_device; 712 current_output_device_ = new_output_device;
717 NotifyAllOutputDeviceChangeListeners(); 713 NotifyAllOutputDeviceChangeListeners();
(...skipping 19 matching lines...) Expand all
737 bool AudioManagerMac::ShouldDeferOutputStreamStart() { 733 bool AudioManagerMac::ShouldDeferOutputStreamStart() {
738 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 734 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
739 return power_observer_->ShouldDeferOutputStreamStart(); 735 return power_observer_->ShouldDeferOutputStreamStart();
740 } 736 }
741 737
742 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { 738 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) {
743 return new AudioManagerMac(audio_log_factory); 739 return new AudioManagerMac(audio_log_factory);
744 } 740 }
745 741
746 } // namespace media 742 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698