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"
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"
15 FakeAudioRendererSink::FakeAudioRendererSink()
16 : state_(kUninitialized
),
18 output_device_(new FakeOutputDevice
) {}
20 FakeAudioRendererSink::~FakeAudioRendererSink() {
24 void FakeAudioRendererSink::Initialize(const AudioParameters
& params
,
25 RenderCallback
* callback
) {
26 DCHECK_EQ(state_
, kUninitialized
);
31 ChangeState(kInitialized
);
34 void FakeAudioRendererSink::Start() {
35 DCHECK_EQ(state_
, kInitialized
);
36 ChangeState(kStarted
);
39 void FakeAudioRendererSink::Stop() {
41 ChangeState(kStopped
);
44 void FakeAudioRendererSink::Pause() {
45 DCHECK(state_
== kStarted
|| state_
== kPlaying
) << "state_ " << state_
;
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
) {
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
)
68 *frames_written
= callback_
->Render(dest
, audio_delay_milliseconds
);
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
[] = {
89 DVLOG(1) << __FUNCTION__
<< " : "
90 << kStateNames
[state_
] << " -> " << kStateNames
[new_state
];