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

Unified Diff: media/audio/audio_manager_base.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from patch 48 Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/audio_manager_base.h ('k') | media/audio/audio_manager_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_manager_base.cc
diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc
index 8a6acc2e7bc89afafedffcb1e857f3c653063028..8845585f6a468ae781e0f8fa1cb837bccd91be74 100644
--- a/media/audio/audio_manager_base.cc
+++ b/media/audio/audio_manager_base.cc
@@ -89,8 +89,12 @@ bool AudioManagerBase::UseSessionIdToSelectDevice(
return session_id && device_id.empty();
}
-AudioManagerBase::AudioManagerBase(AudioLogFactory* audio_log_factory)
- : max_num_output_streams_(kDefaultMaxOutputStreams),
+AudioManagerBase::AudioManagerBase(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
+ AudioLogFactory* audio_log_factory)
+ : AudioManager(std::move(task_runner), std::move(worker_task_runner)),
+ max_num_output_streams_(kDefaultMaxOutputStreams),
max_num_input_streams_(kDefaultMaxInputStreams),
num_output_streams_(0),
num_input_streams_(0),
@@ -99,42 +103,21 @@ AudioManagerBase::AudioManagerBase(AudioLogFactory* audio_log_factory)
// block the UI thread when swapping devices.
output_listeners_(
base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY),
- audio_log_factory_(audio_log_factory) {
-}
+ audio_log_factory_(audio_log_factory) {}
AudioManagerBase::~AudioManagerBase() {
- // The platform specific AudioManager implementation must have already
- // stopped the audio thread. Otherwise, we may destroy audio streams before
- // stopping the thread, resulting an unexpected behavior.
- // This way we make sure activities of the audio streams are all stopped
- // before we destroy them.
- CHECK(!audio_thread_);
+ DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+
// All the output streams should have been deleted.
- DCHECK_EQ(0, num_output_streams_);
+ CHECK_EQ(0, num_output_streams_);
// All the input streams should have been deleted.
- DCHECK_EQ(0, num_input_streams_);
+ CHECK_EQ(0, num_input_streams_);
}
base::string16 AudioManagerBase::GetAudioInputDeviceModel() {
return base::string16();
}
-scoped_refptr<base::SingleThreadTaskRunner> AudioManagerBase::GetTaskRunner() {
- if (!audio_thread_) {
- audio_thread_.reset(new base::Thread("AudioThread"));
-#if defined(OS_WIN)
- audio_thread_->init_com_with_mta(true);
-#endif
- CHECK(audio_thread_->Start());
- }
- return audio_thread_->task_runner();
-}
-
-scoped_refptr<base::SingleThreadTaskRunner>
-AudioManagerBase::GetWorkerTaskRunner() {
- return GetTaskRunner();
-}
-
AudioOutputStream* AudioManagerBase::MakeAudioOutputStream(
const AudioParameters& params,
const std::string& device_id) {
@@ -329,26 +312,8 @@ void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) {
}
void AudioManagerBase::Shutdown() {
- // Only true when we're sharing the UI message loop with the browser. The UI
- // loop is no longer running at this time and browser destruction is imminent.
- auto task_runner = GetTaskRunner();
- if (task_runner->BelongsToCurrentThread()) {
- ShutdownOnAudioThread();
- } else {
- task_runner->PostTask(FROM_HERE,
- base::Bind(&AudioManagerBase::ShutdownOnAudioThread,
- base::Unretained(this)));
- }
-
- // Stop() will wait for any posted messages to be processed first.
- if (audio_thread_) {
- audio_thread_->Stop();
- audio_thread_.reset();
- }
-}
-
-void AudioManagerBase::ShutdownOnAudioThread() {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+ // Close all output streams.
while (!output_dispatchers_.empty()) {
output_dispatchers_.back()->dispatcher->Shutdown();
output_dispatchers_.pop_back();
« no previous file with comments | « media/audio/audio_manager_base.h ('k') | media/audio/audio_manager_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698