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
3 // found in the LICENSE file.
5 #include "media/audio/null_audio_sink.h"
8 #include "base/single_thread_task_runner.h"
9 #include "media/audio/fake_audio_worker.h"
10 #include "media/base/audio_hash.h"
14 NullAudioSink::NullAudioSink(
15 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
)
16 : initialized_(false),
19 task_runner_(task_runner
) {
22 NullAudioSink::~NullAudioSink() {}
24 void NullAudioSink::Initialize(const AudioParameters
& params
,
25 RenderCallback
* callback
) {
26 DCHECK(!initialized_
);
27 fake_worker_
.reset(new FakeAudioWorker(task_runner_
, params
));
28 audio_bus_
= AudioBus::Create(params
);
33 void NullAudioSink::Start() {
34 DCHECK(task_runner_
->BelongsToCurrentThread());
38 void NullAudioSink::Stop() {
39 DCHECK(task_runner_
->BelongsToCurrentThread());
41 // Stop may be called at any time, so we have to check before stopping.
46 void NullAudioSink::Play() {
47 DCHECK(task_runner_
->BelongsToCurrentThread());
53 fake_worker_
->Start(base::Bind(
54 &NullAudioSink::CallRender
, base::Unretained(this)));
58 void NullAudioSink::Pause() {
59 DCHECK(task_runner_
->BelongsToCurrentThread());
68 bool NullAudioSink::SetVolume(double volume
) {
69 // Audio is always muted.
73 void NullAudioSink::CallRender() {
74 DCHECK(task_runner_
->BelongsToCurrentThread());
76 int frames_received
= callback_
->Render(audio_bus_
.get(), 0);
77 if (!audio_hash_
|| frames_received
<= 0)
80 audio_hash_
->Update(audio_bus_
.get(), frames_received
);
83 void NullAudioSink::StartAudioHashForTesting() {
84 DCHECK(!initialized_
);
85 audio_hash_
.reset(new AudioHash());
88 std::string
NullAudioSink::GetAudioHashForTesting() {
89 return audio_hash_
? audio_hash_
->ToString() : std::string();