Update V8 to version 4.7.56.
[chromium-blink-merge.git] / media / base / fake_audio_renderer_sink.cc
blobd8a72629d961c8fdb374861b4032ef5f47b9a559
1 // Copyright 2013 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/base/fake_audio_renderer_sink.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
11 #include "media/base/fake_output_device.h"
13 namespace media {
15 FakeAudioRendererSink::FakeAudioRendererSink()
16 : state_(kUninitialized),
17 callback_(NULL),
18 output_device_(new FakeOutputDevice) {}
20 FakeAudioRendererSink::~FakeAudioRendererSink() {
21 DCHECK(!callback_);
24 void FakeAudioRendererSink::Initialize(const AudioParameters& params,
25 RenderCallback* callback) {
26 DCHECK_EQ(state_, kUninitialized);
27 DCHECK(!callback_);
28 DCHECK(callback);
30 callback_ = callback;
31 ChangeState(kInitialized);
34 void FakeAudioRendererSink::Start() {
35 DCHECK_EQ(state_, kInitialized);
36 ChangeState(kStarted);
39 void FakeAudioRendererSink::Stop() {
40 callback_ = NULL;
41 ChangeState(kStopped);
44 void FakeAudioRendererSink::Pause() {
45 DCHECK(state_ == kStarted || state_ == kPlaying) << "state_ " << state_;
46 ChangeState(kPaused);
49 void FakeAudioRendererSink::Play() {
50 DCHECK(state_ == kStarted || state_ == kPaused) << "state_ " << state_;
51 DCHECK_EQ(state_, kPaused);
52 ChangeState(kPlaying);
55 bool FakeAudioRendererSink::SetVolume(double volume) {
56 return true;
59 OutputDevice* FakeAudioRendererSink::GetOutputDevice() {
60 return output_device_.get();
63 bool FakeAudioRendererSink::Render(AudioBus* dest, int audio_delay_milliseconds,
64 int* frames_written) {
65 if (state_ != kPlaying)
66 return false;
68 *frames_written = callback_->Render(dest, audio_delay_milliseconds);
69 return true;
72 void FakeAudioRendererSink::OnRenderError() {
73 DCHECK_NE(state_, kUninitialized);
74 DCHECK_NE(state_, kStopped);
76 callback_->OnRenderError();
79 void FakeAudioRendererSink::ChangeState(State new_state) {
80 static const char* kStateNames[] = {
81 "kUninitialized",
82 "kInitialized",
83 "kStarted",
84 "kPaused",
85 "kPlaying",
86 "kStopped"
89 DVLOG(1) << __FUNCTION__ << " : "
90 << kStateNames[state_] << " -> " << kStateNames[new_state];
91 state_ = new_state;
94 } // namespace media