| Index: media/audio/fake_audio_worker.cc
|
| diff --git a/media/audio/fake_audio_consumer.cc b/media/audio/fake_audio_worker.cc
|
| similarity index 63%
|
| rename from media/audio/fake_audio_consumer.cc
|
| rename to media/audio/fake_audio_worker.cc
|
| index ca99424f419bc8c174615226f042038cdf06659a..44177d385eca7d0304fb001c8b3631dfd2f3c334 100644
|
| --- a/media/audio/fake_audio_consumer.cc
|
| +++ b/media/audio/fake_audio_worker.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "media/audio/fake_audio_consumer.h"
|
| +#include "media/audio/fake_audio_worker.h"
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| @@ -15,18 +15,17 @@
|
| #include "base/threading/thread_checker.h"
|
| #include "base/time/time.h"
|
| #include "media/audio/audio_parameters.h"
|
| -#include "media/base/audio_bus.h"
|
|
|
| namespace media {
|
|
|
| -class FakeAudioConsumer::Worker
|
| - : public base::RefCountedThreadSafe<FakeAudioConsumer::Worker> {
|
| +class FakeAudioWorker::Worker
|
| + : public base::RefCountedThreadSafe<FakeAudioWorker::Worker> {
|
| public:
|
| Worker(const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
|
| const AudioParameters& params);
|
|
|
| bool IsStopped();
|
| - void Start(const ReadCB& read_cb);
|
| + void Start(const base::Closure& worker_cb);
|
| void Stop();
|
|
|
| private:
|
| @@ -39,114 +38,110 @@ class FakeAudioConsumer::Worker
|
| // Cancel any delayed callbacks to DoRead() in the worker loop's queue.
|
| void DoCancel();
|
|
|
| - // Task that regularly calls |read_cb_| according to the playback rate as
|
| + // Task that regularly calls |worker_cb_| according to the playback rate as
|
| // determined by the audio parameters given during construction. Runs on
|
| // the worker loop.
|
| void DoRead();
|
|
|
| const scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
|
| - const scoped_ptr<AudioBus> audio_bus_;
|
| const base::TimeDelta buffer_duration_;
|
|
|
| - base::Lock read_cb_lock_; // Held while mutating or running |read_cb_|.
|
| - ReadCB read_cb_;
|
| + base::Lock worker_cb_lock_; // Held while mutating or running |worker_cb_|.
|
| + base::Closure worker_cb_;
|
| base::TimeTicks next_read_time_;
|
|
|
| // Used to cancel any delayed tasks still inside the worker loop's queue.
|
| - base::CancelableClosure read_task_cb_;
|
| + base::CancelableClosure worker_task_cb_;
|
|
|
| base::ThreadChecker thread_checker_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(Worker);
|
| };
|
|
|
| -FakeAudioConsumer::FakeAudioConsumer(
|
| +FakeAudioWorker::FakeAudioWorker(
|
| const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
|
| const AudioParameters& params)
|
| : worker_(new Worker(worker_task_runner, params)) {
|
| }
|
|
|
| -FakeAudioConsumer::~FakeAudioConsumer() {
|
| +FakeAudioWorker::~FakeAudioWorker() {
|
| DCHECK(worker_->IsStopped());
|
| }
|
|
|
| -void FakeAudioConsumer::Start(const ReadCB& read_cb) {
|
| +void FakeAudioWorker::Start(const base::Closure& worker_cb) {
|
| DCHECK(worker_->IsStopped());
|
| - worker_->Start(read_cb);
|
| + worker_->Start(worker_cb);
|
| }
|
|
|
| -void FakeAudioConsumer::Stop() {
|
| +void FakeAudioWorker::Stop() {
|
| worker_->Stop();
|
| }
|
|
|
| -FakeAudioConsumer::Worker::Worker(
|
| +FakeAudioWorker::Worker::Worker(
|
| const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
|
| const AudioParameters& params)
|
| : worker_task_runner_(worker_task_runner),
|
| - audio_bus_(AudioBus::Create(params)),
|
| buffer_duration_(base::TimeDelta::FromMicroseconds(
|
| params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond /
|
| static_cast<float>(params.sample_rate()))) {
|
| - audio_bus_->Zero();
|
| -
|
| // Worker can be constructed on any thread, but will DCHECK that its
|
| // Start/Stop methods are called from the same thread.
|
| thread_checker_.DetachFromThread();
|
| }
|
|
|
| -FakeAudioConsumer::Worker::~Worker() {
|
| - DCHECK(read_cb_.is_null());
|
| +FakeAudioWorker::Worker::~Worker() {
|
| + DCHECK(worker_cb_.is_null());
|
| }
|
|
|
| -bool FakeAudioConsumer::Worker::IsStopped() {
|
| - base::AutoLock scoped_lock(read_cb_lock_);
|
| - return read_cb_.is_null();
|
| +bool FakeAudioWorker::Worker::IsStopped() {
|
| + base::AutoLock scoped_lock(worker_cb_lock_);
|
| + return worker_cb_.is_null();
|
| }
|
|
|
| -void FakeAudioConsumer::Worker::Start(const ReadCB& read_cb) {
|
| +void FakeAudioWorker::Worker::Start(const base::Closure& worker_cb) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - DCHECK(!read_cb.is_null());
|
| + DCHECK(!worker_cb.is_null());
|
| {
|
| - base::AutoLock scoped_lock(read_cb_lock_);
|
| - DCHECK(read_cb_.is_null());
|
| - read_cb_ = read_cb;
|
| + base::AutoLock scoped_lock(worker_cb_lock_);
|
| + DCHECK(worker_cb_.is_null());
|
| + worker_cb_ = worker_cb;
|
| }
|
| worker_task_runner_->PostTask(FROM_HERE, base::Bind(&Worker::DoStart, this));
|
| }
|
|
|
| -void FakeAudioConsumer::Worker::DoStart() {
|
| +void FakeAudioWorker::Worker::DoStart() {
|
| DCHECK(worker_task_runner_->BelongsToCurrentThread());
|
| next_read_time_ = base::TimeTicks::Now();
|
| - read_task_cb_.Reset(base::Bind(&Worker::DoRead, this));
|
| - read_task_cb_.callback().Run();
|
| + worker_task_cb_.Reset(base::Bind(&Worker::DoRead, this));
|
| + worker_task_cb_.callback().Run();
|
| }
|
|
|
| -void FakeAudioConsumer::Worker::Stop() {
|
| +void FakeAudioWorker::Worker::Stop() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| {
|
| - base::AutoLock scoped_lock(read_cb_lock_);
|
| - if (read_cb_.is_null())
|
| + base::AutoLock scoped_lock(worker_cb_lock_);
|
| + if (worker_cb_.is_null())
|
| return;
|
| - read_cb_.Reset();
|
| + worker_cb_.Reset();
|
| }
|
| worker_task_runner_->PostTask(FROM_HERE, base::Bind(&Worker::DoCancel, this));
|
| }
|
|
|
| -void FakeAudioConsumer::Worker::DoCancel() {
|
| +void FakeAudioWorker::Worker::DoCancel() {
|
| DCHECK(worker_task_runner_->BelongsToCurrentThread());
|
| - read_task_cb_.Cancel();
|
| + worker_task_cb_.Cancel();
|
| }
|
|
|
| -void FakeAudioConsumer::Worker::DoRead() {
|
| +void FakeAudioWorker::Worker::DoRead() {
|
| DCHECK(worker_task_runner_->BelongsToCurrentThread());
|
|
|
| {
|
| - base::AutoLock scoped_lock(read_cb_lock_);
|
| - if (!read_cb_.is_null())
|
| - read_cb_.Run(audio_bus_.get());
|
| + base::AutoLock scoped_lock(worker_cb_lock_);
|
| + if (!worker_cb_.is_null())
|
| + worker_cb_.Run();
|
| }
|
|
|
| - // Need to account for time spent here due to the cost of |read_cb_| as well
|
| + // Need to account for time spent here due to the cost of |worker_cb| as well
|
| // as the imprecision of PostDelayedTask().
|
| const base::TimeTicks now = base::TimeTicks::Now();
|
| base::TimeDelta delay = next_read_time_ + buffer_duration_ - now;
|
| @@ -157,7 +152,7 @@ void FakeAudioConsumer::Worker::DoRead() {
|
| next_read_time_ = now + delay;
|
|
|
| worker_task_runner_->PostDelayedTask(
|
| - FROM_HERE, read_task_cb_.callback(), delay);
|
| + FROM_HERE, worker_task_cb_.callback(), delay);
|
| }
|
|
|
| } // namespace media
|
|
|