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. 4 5#include "media/base/fake_audio_renderer_sink.h" 6 7#include "base/logging.h" 8 9namespace media { 10 11FakeAudioRendererSink::FakeAudioRendererSink() 12 : state_(kUninitialized), 13 callback_(NULL) { 14} 15 16FakeAudioRendererSink::~FakeAudioRendererSink() { 17 DCHECK(!callback_); 18} 19 20void FakeAudioRendererSink::Initialize(const AudioParameters& params, 21 RenderCallback* callback) { 22 DCHECK_EQ(state_, kUninitialized); 23 DCHECK(!callback_); 24 DCHECK(callback); 25 26 callback_ = callback; 27 ChangeState(kInitialized); 28} 29 30void FakeAudioRendererSink::Start() { 31 DCHECK_EQ(state_, kInitialized); 32 ChangeState(kStarted); 33} 34 35void FakeAudioRendererSink::Stop() { 36 callback_ = NULL; 37 ChangeState(kStopped); 38} 39 40void FakeAudioRendererSink::Pause() { 41 DCHECK(state_ == kStarted || state_ == kPlaying) << "state_ " << state_; 42 ChangeState(kPaused); 43} 44 45void FakeAudioRendererSink::Play() { 46 DCHECK(state_ == kStarted || state_ == kPaused) << "state_ " << state_; 47 DCHECK_EQ(state_, kPaused); 48 ChangeState(kPlaying); 49} 50 51bool FakeAudioRendererSink::SetVolume(double volume) { 52 return true; 53} 54 55bool FakeAudioRendererSink::Render(AudioBus* dest, int audio_delay_milliseconds, 56 int* frames_written) { 57 if (state_ != kPlaying) 58 return false; 59 60 *frames_written = callback_->Render(dest, audio_delay_milliseconds); 61 return true; 62} 63 64void FakeAudioRendererSink::OnRenderError() { 65 DCHECK_NE(state_, kUninitialized); 66 DCHECK_NE(state_, kStopped); 67 68 callback_->OnRenderError(); 69} 70 71void FakeAudioRendererSink::ChangeState(State new_state) { 72 static const char* kStateNames[] = { 73 "kUninitialized", 74 "kInitialized", 75 "kStarted", 76 "kPaused", 77 "kPlaying", 78 "kStopped" 79 }; 80 81 DVLOG(1) << __FUNCTION__ << " : " 82 << kStateNames[state_] << " -> " << kStateNames[new_state]; 83 state_ = new_state; 84} 85 86} // namespace media 87