[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / media / base / fake_audio_renderer_sink.cc
blobd42db6de1b9a7eba16f42c4417c56aa218112576
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/logging.h"
9 namespace media {
11 FakeAudioRendererSink::FakeAudioRendererSink()
12 : state_(kUninitialized),
13 callback_(NULL) {
16 FakeAudioRendererSink::~FakeAudioRendererSink() {
17 DCHECK(!callback_);
20 void FakeAudioRendererSink::Initialize(const AudioParameters& params,
21 RenderCallback* callback) {
22 DCHECK_EQ(state_, kUninitialized);
23 DCHECK(!callback_);
24 DCHECK(callback);
26 callback_ = callback;
27 ChangeState(kInitialized);
30 void FakeAudioRendererSink::Start() {
31 DCHECK_EQ(state_, kInitialized);
32 ChangeState(kStarted);
35 void FakeAudioRendererSink::Stop() {
36 callback_ = NULL;
37 ChangeState(kStopped);
40 void FakeAudioRendererSink::Pause() {
41 DCHECK(state_ == kStarted || state_ == kPlaying) << "state_ " << state_;
42 ChangeState(kPaused);
45 void FakeAudioRendererSink::Play() {
46 DCHECK(state_ == kStarted || state_ == kPaused) << "state_ " << state_;
47 DCHECK_EQ(state_, kPaused);
48 ChangeState(kPlaying);
51 bool FakeAudioRendererSink::SetVolume(double volume) {
52 return true;
55 bool FakeAudioRendererSink::Render(AudioBus* dest, int audio_delay_milliseconds,
56 int* frames_written) {
57 if (state_ != kPlaying)
58 return false;
60 *frames_written = callback_->Render(dest, audio_delay_milliseconds);
61 return true;
64 void FakeAudioRendererSink::OnRenderError() {
65 DCHECK_NE(state_, kUninitialized);
66 DCHECK_NE(state_, kStopped);
68 callback_->OnRenderError();
71 void FakeAudioRendererSink::ChangeState(State new_state) {
72 static const char* kStateNames[] = {
73 "kUninitialized",
74 "kInitialized",
75 "kStarted",
76 "kPaused",
77 "kPlaying",
78 "kStopped"
81 DVLOG(1) << __FUNCTION__ << " : "
82 << kStateNames[state_] << " -> " << kStateNames[new_state];
83 state_ = new_state;
86 } // namespace media