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/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "media/audio/fake_audio_worker.h"
11 #include "media/base/audio_hash.h"
15 NullAudioSink::NullAudioSink(
16 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
)
17 : initialized_(false),
20 task_runner_(task_runner
) {
23 NullAudioSink::~NullAudioSink() {}
25 void NullAudioSink::Initialize(const AudioParameters
& params
,
26 RenderCallback
* callback
) {
27 DCHECK(!initialized_
);
28 fake_worker_
.reset(new FakeAudioWorker(task_runner_
, params
));
29 audio_bus_
= AudioBus::Create(params
);
34 void NullAudioSink::Start() {
35 DCHECK(task_runner_
->BelongsToCurrentThread());
39 void NullAudioSink::Stop() {
40 DCHECK(task_runner_
->BelongsToCurrentThread());
42 // Stop may be called at any time, so we have to check before stopping.
47 void NullAudioSink::Play() {
48 DCHECK(task_runner_
->BelongsToCurrentThread());
54 fake_worker_
->Start(base::Bind(
55 &NullAudioSink::CallRender
, base::Unretained(this)));
59 void NullAudioSink::Pause() {
60 DCHECK(task_runner_
->BelongsToCurrentThread());
69 bool NullAudioSink::SetVolume(double volume
) {
70 // Audio is always muted.
74 OutputDevice
* NullAudioSink::GetOutputDevice() {
78 void NullAudioSink::CallRender() {
79 DCHECK(task_runner_
->BelongsToCurrentThread());
81 int frames_received
= callback_
->Render(audio_bus_
.get(), 0);
82 if (!audio_hash_
|| frames_received
<= 0)
85 audio_hash_
->Update(audio_bus_
.get(), frames_received
);
88 void NullAudioSink::StartAudioHashForTesting() {
89 DCHECK(!initialized_
);
90 audio_hash_
.reset(new AudioHash());
93 std::string
NullAudioSink::GetAudioHashForTesting() {
94 return audio_hash_
? audio_hash_
->ToString() : std::string();