Create an initial chrome://supervised-user-internals page
[chromium-blink-merge.git] / media / audio / null_audio_sink.cc
blobba257180a6ce06e8bc6f89d3d9148617b3ea789f
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"
7 #include "base/bind.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"
13 namespace media {
15 NullAudioSink::NullAudioSink(
16 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
17 : initialized_(false),
18 playing_(false),
19 callback_(NULL),
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);
30 callback_ = callback;
31 initialized_ = true;
34 void NullAudioSink::Start() {
35 DCHECK(task_runner_->BelongsToCurrentThread());
36 DCHECK(!playing_);
39 void NullAudioSink::Stop() {
40 DCHECK(task_runner_->BelongsToCurrentThread());
42 // Stop may be called at any time, so we have to check before stopping.
43 if (fake_worker_)
44 fake_worker_->Stop();
47 void NullAudioSink::Play() {
48 DCHECK(task_runner_->BelongsToCurrentThread());
49 DCHECK(initialized_);
51 if (playing_)
52 return;
54 fake_worker_->Start(base::Bind(
55 &NullAudioSink::CallRender, base::Unretained(this)));
56 playing_ = true;
59 void NullAudioSink::Pause() {
60 DCHECK(task_runner_->BelongsToCurrentThread());
62 if (!playing_)
63 return;
65 fake_worker_->Stop();
66 playing_ = false;
69 bool NullAudioSink::SetVolume(double volume) {
70 // Audio is always muted.
71 return volume == 0.0;
74 OutputDevice* NullAudioSink::GetOutputDevice() {
75 return nullptr;
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)
83 return;
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();
97 } // namespace media