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"
14 FakeAudioRendererSink::FakeAudioRendererSink()
15 : state_(kUninitialized
),
19 FakeAudioRendererSink::~FakeAudioRendererSink() {
23 void FakeAudioRendererSink::Initialize(const AudioParameters
& params
,
24 RenderCallback
* callback
) {
25 DCHECK_EQ(state_
, kUninitialized
);
30 ChangeState(kInitialized
);
33 void FakeAudioRendererSink::Start() {
34 DCHECK_EQ(state_
, kInitialized
);
35 ChangeState(kStarted
);
38 void FakeAudioRendererSink::Stop() {
40 ChangeState(kStopped
);
43 void FakeAudioRendererSink::Pause() {
44 DCHECK(state_
== kStarted
|| state_
== kPlaying
) << "state_ " << state_
;
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
) {
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
)
70 *frames_written
= callback_
->Render(dest
, audio_delay_milliseconds
);
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
[] = {
91 DVLOG(1) << __FUNCTION__
<< " : "
92 << kStateNames
[state_
] << " -> " << kStateNames
[new_state
];