Move UpdateManifest test from unit_tests into extensions_unittests.
[chromium-blink-merge.git] / media / base / fake_audio_renderer_sink.cc
blob4c4233b5e08a25888fe3edc4655e05651dfde561
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"
12 namespace media {
14 FakeAudioRendererSink::FakeAudioRendererSink()
15 : state_(kUninitialized),
16 callback_(NULL) {
19 FakeAudioRendererSink::~FakeAudioRendererSink() {
20 DCHECK(!callback_);
23 void FakeAudioRendererSink::Initialize(const AudioParameters& params,
24 RenderCallback* callback) {
25 DCHECK_EQ(state_, kUninitialized);
26 DCHECK(!callback_);
27 DCHECK(callback);
29 callback_ = callback;
30 ChangeState(kInitialized);
33 void FakeAudioRendererSink::Start() {
34 DCHECK_EQ(state_, kInitialized);
35 ChangeState(kStarted);
38 void FakeAudioRendererSink::Stop() {
39 callback_ = NULL;
40 ChangeState(kStopped);
43 void FakeAudioRendererSink::Pause() {
44 DCHECK(state_ == kStarted || state_ == kPlaying) << "state_ " << state_;
45 ChangeState(kPaused);
48 void FakeAudioRendererSink::Play() {
49 DCHECK(state_ == kStarted || state_ == kPaused) << "state_ " << state_;
50 DCHECK_EQ(state_, kPaused);
51 ChangeState(kPlaying);
54 bool FakeAudioRendererSink::SetVolume(double volume) {
55 return true;
58 void FakeAudioRendererSink::SwitchOutputDevice(
59 const std::string& device_id,
60 const GURL& security_origin,
61 const SwitchOutputDeviceCB& callback) {
62 callback.Run(SWITCH_OUTPUT_DEVICE_RESULT_SUCCESS);
65 bool FakeAudioRendererSink::Render(AudioBus* dest, int audio_delay_milliseconds,
66 int* frames_written) {
67 if (state_ != kPlaying)
68 return false;
70 *frames_written = callback_->Render(dest, audio_delay_milliseconds);
71 return true;
74 void FakeAudioRendererSink::OnRenderError() {
75 DCHECK_NE(state_, kUninitialized);
76 DCHECK_NE(state_, kStopped);
78 callback_->OnRenderError();
81 void FakeAudioRendererSink::ChangeState(State new_state) {
82 static const char* kStateNames[] = {
83 "kUninitialized",
84 "kInitialized",
85 "kStarted",
86 "kPaused",
87 "kPlaying",
88 "kStopped"
91 DVLOG(1) << __FUNCTION__ << " : "
92 << kStateNames[state_] << " -> " << kStateNames[new_state];
93 state_ = new_state;
96 } // namespace media