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/message_loop/message_loop_proxy.h"
9 #include "media/audio/fake_audio_consumer.h"
10 #include "media/base/audio_hash.h"
14 NullAudioSink::NullAudioSink(
15 const scoped_refptr
<base::MessageLoopProxy
>& message_loop
)
16 : initialized_(false),
19 message_loop_(message_loop
) {
22 NullAudioSink::~NullAudioSink() {}
24 void NullAudioSink::Initialize(const AudioParameters
& params
,
25 RenderCallback
* callback
) {
26 DCHECK(!initialized_
);
27 fake_consumer_
.reset(new FakeAudioConsumer(message_loop_
, params
));
32 void NullAudioSink::Start() {
33 DCHECK(message_loop_
->BelongsToCurrentThread());
37 void NullAudioSink::Stop() {
38 DCHECK(message_loop_
->BelongsToCurrentThread());
40 // Stop may be called at any time, so we have to check before stopping.
42 fake_consumer_
->Stop();
45 void NullAudioSink::Play() {
46 DCHECK(message_loop_
->BelongsToCurrentThread());
52 fake_consumer_
->Start(base::Bind(
53 &NullAudioSink::CallRender
, base::Unretained(this)));
57 void NullAudioSink::Pause() {
58 DCHECK(message_loop_
->BelongsToCurrentThread());
63 fake_consumer_
->Stop();
67 bool NullAudioSink::SetVolume(double volume
) {
68 // Audio is always muted.
72 void NullAudioSink::CallRender(AudioBus
* audio_bus
) {
73 DCHECK(message_loop_
->BelongsToCurrentThread());
75 int frames_received
= callback_
->Render(audio_bus
, 0);
76 if (!audio_hash_
|| frames_received
<= 0)
79 audio_hash_
->Update(audio_bus
, frames_received
);
82 void NullAudioSink::StartAudioHashForTesting() {
83 DCHECK(!initialized_
);
84 audio_hash_
.reset(new AudioHash());
87 std::string
NullAudioSink::GetAudioHashForTesting() {
88 return audio_hash_
? audio_hash_
->ToString() : std::string();