Commit 419c855f authored by Yuri Wiitala's avatar Yuri Wiitala Committed by Commit Bot

Add worker thread to audio::OwningAudioManagerAccessor.

When the Audio Service will be running in its standalone process, the
worker thread will be used to drive the audio flows for the loopback
streams, as well as all the fake streams (including the those used for
muting). These things should not become blocked by long-running control
tasks on the main thread.

Bug: 824019
Change-Id: I6b7fd4cb110842c70a26072161dc91929ed4f19d
Reviewed-on: https://chromium-review.googlesource.com/1046153
Commit-Queue: Yuri Wiitala <miu@chromium.org>
Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556369}
parent 3391a0dc
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
#include "services/audio/owning_audio_manager_accessor.h" #include "services/audio/owning_audio_manager_accessor.h"
#include <memory>
#include <utility>
#include "base/macros.h" #include "base/macros.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "media/audio/audio_manager.h" #include "media/audio/audio_manager.h"
#include "media/audio/audio_thread.h" #include "media/audio/audio_thread.h"
...@@ -14,7 +18,8 @@ namespace audio { ...@@ -14,7 +18,8 @@ namespace audio {
namespace { namespace {
// Thread class for hosting owned AudioManager on the main thread of the // Thread class for hosting owned AudioManager on the main thread of the
// service. // service, with a separate worker thread (started on-demand) for running things
// that shouldn't be blocked by main-thread tasks.
class MainThread : public media::AudioThread { class MainThread : public media::AudioThread {
public: public:
MainThread(); MainThread();
...@@ -27,10 +32,17 @@ class MainThread : public media::AudioThread { ...@@ -27,10 +32,17 @@ class MainThread : public media::AudioThread {
private: private:
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// This is not started until the first time GetWorkerTaskRunner() is called.
base::Thread worker_thread_;
scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
DISALLOW_COPY_AND_ASSIGN(MainThread); DISALLOW_COPY_AND_ASSIGN(MainThread);
}; };
MainThread::MainThread() : task_runner_(base::ThreadTaskRunnerHandle::Get()) {} MainThread::MainThread()
: task_runner_(base::ThreadTaskRunnerHandle::Get()),
worker_thread_("AudioWorkerThread") {}
MainThread::~MainThread() { MainThread::~MainThread() {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
...@@ -38,6 +50,10 @@ MainThread::~MainThread() { ...@@ -38,6 +50,10 @@ MainThread::~MainThread() {
void MainThread::Stop() { void MainThread::Stop() {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
if (worker_task_runner_) {
worker_task_runner_ = nullptr;
worker_thread_.Stop();
}
} }
base::SingleThreadTaskRunner* MainThread::GetTaskRunner() { base::SingleThreadTaskRunner* MainThread::GetTaskRunner() {
...@@ -45,8 +61,12 @@ base::SingleThreadTaskRunner* MainThread::GetTaskRunner() { ...@@ -45,8 +61,12 @@ base::SingleThreadTaskRunner* MainThread::GetTaskRunner() {
} }
base::SingleThreadTaskRunner* MainThread::GetWorkerTaskRunner() { base::SingleThreadTaskRunner* MainThread::GetWorkerTaskRunner() {
NOTREACHED(); DCHECK(task_runner_->BelongsToCurrentThread());
return task_runner_.get(); if (!worker_task_runner_) {
CHECK(worker_thread_.Start());
worker_task_runner_ = worker_thread_.task_runner();
}
return worker_task_runner_.get();
} }
} // namespace } // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment