| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/audio_mixer_pulse.h" | 5 #include "chrome/browser/chromeos/audio_mixer_pulse.h" |
| 6 | 6 |
| 7 #include <pulse/pulseaudio.h> | 7 #include <pulse/pulseaudio.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" |
| 10 #include "base/task.h" | 11 #include "base/task.h" |
| 11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 12 | 13 |
| 13 namespace chromeos { | 14 namespace chromeos { |
| 14 | 15 |
| 15 // Using asynchronous versions of the threaded PulseAudio API, as well | 16 // Using asynchronous versions of the threaded PulseAudio API, as well |
| 16 // as a worker thread so gets, sets, and the init sequence do not block the | 17 // as a worker thread so gets, sets, and the init sequence do not block the |
| 17 // calling thread. GetVolume() and IsMute() can still be called synchronously | 18 // calling thread. GetVolume() and IsMute() can still be called synchronously |
| 18 // if needed, but take a bit longer (~2ms vs ~0.3ms). | 19 // if needed, but take a bit longer (~2ms vs ~0.3ms). |
| 19 // | 20 // |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 pa_mainloop_(NULL) { | 58 pa_mainloop_(NULL) { |
| 58 } | 59 } |
| 59 | 60 |
| 60 AudioMixerPulse::~AudioMixerPulse() { | 61 AudioMixerPulse::~AudioMixerPulse() { |
| 61 PulseAudioFree(); | 62 PulseAudioFree(); |
| 62 if (thread_ != NULL) { | 63 if (thread_ != NULL) { |
| 63 // A ScopedAllowIO object is required to join the thread when calling Stop. | 64 // A ScopedAllowIO object is required to join the thread when calling Stop. |
| 64 // The worker thread should be idle at this time. | 65 // The worker thread should be idle at this time. |
| 65 // See http://crosbug.com/11110 for discussion. | 66 // See http://crosbug.com/11110 for discussion. |
| 66 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; | 67 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; |
| 68 thread_->message_loop()->AssertIdle(); |
| 67 | 69 |
| 68 thread_->Stop(); | 70 thread_->Stop(); |
| 69 thread_.reset(); | 71 thread_.reset(); |
| 70 } | 72 } |
| 71 } | 73 } |
| 72 | 74 |
| 73 void AudioMixerPulse::Init(InitDoneCallback* callback) { | 75 void AudioMixerPulse::Init(InitDoneCallback* callback) { |
| 74 DCHECK(callback); | 76 DCHECK(callback); |
| 75 if (!InitThread()) { | 77 if (!InitThread()) { |
| 76 callback->Run(false); | 78 callback->Run(false); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 if (mixer_state_ != READY) | 463 if (mixer_state_ != READY) |
| 462 return false; | 464 return false; |
| 463 if (!pa_mainloop_) | 465 if (!pa_mainloop_) |
| 464 return false; | 466 return false; |
| 465 pa_threaded_mainloop_lock(pa_mainloop_); | 467 pa_threaded_mainloop_lock(pa_mainloop_); |
| 466 ++mainloop_lock_count_; | 468 ++mainloop_lock_count_; |
| 467 return true; | 469 return true; |
| 468 } | 470 } |
| 469 | 471 |
| 470 } // namespace chromeos | 472 } // namespace chromeos |
| 471 | |
| OLD | NEW |