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"
11 FakeAudioRendererSink::FakeAudioRendererSink()
12 : state_(kUninitialized
),
16 FakeAudioRendererSink::~FakeAudioRendererSink() {
20 void FakeAudioRendererSink::Initialize(const AudioParameters
& params
,
21 RenderCallback
* callback
) {
22 DCHECK_EQ(state_
, kUninitialized
);
27 ChangeState(kInitialized
);
30 void FakeAudioRendererSink::Start() {
31 DCHECK_EQ(state_
, kInitialized
);
32 ChangeState(kStarted
);
35 void FakeAudioRendererSink::Stop() {
37 ChangeState(kStopped
);
40 void FakeAudioRendererSink::Pause() {
41 DCHECK(state_
== kStarted
|| state_
== kPlaying
) << "state_ " << state_
;
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
) {
55 bool FakeAudioRendererSink::Render(AudioBus
* dest
, int audio_delay_milliseconds
,
56 int* frames_written
) {
57 if (state_
!= kPlaying
)
60 *frames_written
= callback_
->Render(dest
, audio_delay_milliseconds
);
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
[] = {
81 DVLOG(1) << __FUNCTION__
<< " : "
82 << kStateNames
[state_
] << " -> " << kStateNames
[new_state
];