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

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

Issue 14273018: Use the browser UI thread for audio on OSX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix device listener. Created 7 years, 6 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
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 235
236 SetMaxOutputStreamsAllowed(kMaxOutputStreams); 236 SetMaxOutputStreamsAllowed(kMaxOutputStreams);
237 237
238 // Task must be posted last to avoid races from handing out "this" to the 238 // Task must be posted last to avoid races from handing out "this" to the
239 // audio thread. 239 // audio thread.
240 GetMessageLoop()->PostTask(FROM_HERE, base::Bind( 240 GetMessageLoop()->PostTask(FROM_HERE, base::Bind(
241 &AudioManagerMac::CreateDeviceListener, base::Unretained(this))); 241 &AudioManagerMac::CreateDeviceListener, base::Unretained(this)));
242 } 242 }
243 243
244 AudioManagerMac::~AudioManagerMac() { 244 AudioManagerMac::~AudioManagerMac() {
245 // It's safe to post a task here since Shutdown() will wait for all tasks to 245 if (GetMessageLoop()->BelongsToCurrentThread()) {
246 // complete before returning. 246 DestroyDeviceListener();
247 GetMessageLoop()->PostTask(FROM_HERE, base::Bind( 247 } else {
248 &AudioManagerMac::DestroyDeviceListener, base::Unretained(this))); 248 // It's safe to post a task here since Shutdown() will wait for all tasks to
249 // complete before returning.
250 GetMessageLoop()->PostTask(FROM_HERE, base::Bind(
251 &AudioManagerMac::DestroyDeviceListener, base::Unretained(this)));
252 }
249 253
250 Shutdown(); 254 Shutdown();
251 } 255 }
252 256
253 bool AudioManagerMac::HasAudioOutputDevices() { 257 bool AudioManagerMac::HasAudioOutputDevices() {
254 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); 258 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice);
255 } 259 }
256 260
257 bool AudioManagerMac::HasAudioInputDevices() { 261 bool AudioManagerMac::HasAudioInputDevices() {
258 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); 262 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 542
539 void AudioManagerMac::CreateDeviceListener() { 543 void AudioManagerMac::CreateDeviceListener() {
540 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 544 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
541 545
542 // Get a baseline for the sample-rate and current device, 546 // Get a baseline for the sample-rate and current device,
543 // so we can intelligently handle device notifications only when necessary. 547 // so we can intelligently handle device notifications only when necessary.
544 current_sample_rate_ = HardwareSampleRate(); 548 current_sample_rate_ = HardwareSampleRate();
545 if (!GetDefaultOutputDevice(&current_output_device_)) 549 if (!GetDefaultOutputDevice(&current_output_device_))
546 current_output_device_ = kAudioDeviceUnknown; 550 current_output_device_ = kAudioDeviceUnknown;
547 551
548 output_device_listener_.reset(new AudioDeviceListenerMac(BindToLoop( 552 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind(
549 GetMessageLoop(), base::Bind( 553 &AudioManagerMac::HandleDeviceChanges, base::Unretained(this))));
550 &AudioManagerMac::HandleDeviceChanges,
551 base::Unretained(this)))));
552 } 554 }
553 555
554 void AudioManagerMac::DestroyDeviceListener() { 556 void AudioManagerMac::DestroyDeviceListener() {
555 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 557 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
556 output_device_listener_.reset(); 558 output_device_listener_.reset();
557 } 559 }
558 560
559 void AudioManagerMac::HandleDeviceChanges() { 561 void AudioManagerMac::HandleDeviceChanges() {
560 int new_sample_rate = HardwareSampleRate(); 562 int new_sample_rate = HardwareSampleRate();
561 AudioDeviceID new_output_device; 563 AudioDeviceID new_output_device;
562 GetDefaultOutputDevice(&new_output_device); 564 GetDefaultOutputDevice(&new_output_device);
563 565
564 if (current_sample_rate_ == new_sample_rate && 566 if (current_sample_rate_ == new_sample_rate &&
565 current_output_device_ == new_output_device) 567 current_output_device_ == new_output_device)
566 return; 568 return;
567 569
568 current_sample_rate_ = new_sample_rate; 570 current_sample_rate_ = new_sample_rate;
569 current_output_device_ = new_output_device; 571 current_output_device_ = new_output_device;
570 NotifyAllOutputDeviceChangeListeners(); 572 NotifyAllOutputDeviceChangeListeners();
571 } 573 }
572 574
573 AudioManager* CreateAudioManager() { 575 AudioManager* CreateAudioManager() {
574 return new AudioManagerMac(); 576 return new AudioManagerMac();
575 } 577 }
576 578
577 } // namespace media 579 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698