1 // Copyright (c) 2010 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/audio/fake_audio_output_stream.h"
7 #include "base/at_exit.h"
8 #include "base/logging.h"
10 bool FakeAudioOutputStream::has_created_fake_stream_
= false;
11 FakeAudioOutputStream
* FakeAudioOutputStream::last_fake_stream_
= NULL
;
14 AudioOutputStream
* FakeAudioOutputStream::MakeFakeStream(
15 const AudioParameters
& params
) {
16 if (!has_created_fake_stream_
)
17 base::AtExitManager::RegisterCallback(&DestroyLastFakeStream
, NULL
);
18 has_created_fake_stream_
= true;
20 FakeAudioOutputStream
* new_stream
= new FakeAudioOutputStream(params
);
22 if (last_fake_stream_
) {
23 DCHECK(last_fake_stream_
->closed_
);
24 delete last_fake_stream_
;
26 last_fake_stream_
= new_stream
;
32 FakeAudioOutputStream
* FakeAudioOutputStream::GetLastFakeStream() {
33 return last_fake_stream_
;
36 bool FakeAudioOutputStream::Open() {
37 if (packet_size_
< sizeof(int16
))
39 buffer_
.reset(new uint8
[packet_size_
]);
43 void FakeAudioOutputStream::Start(AudioSourceCallback
* callback
) {
45 memset(buffer_
.get(), 0, packet_size_
);
46 callback_
->OnMoreData(this, buffer_
.get(), packet_size_
,
47 AudioBuffersState(0, 0));
50 void FakeAudioOutputStream::Stop() {
54 void FakeAudioOutputStream::SetVolume(double volume
) {
58 void FakeAudioOutputStream::GetVolume(double* volume
) {
62 void FakeAudioOutputStream::Close() {
66 FakeAudioOutputStream::FakeAudioOutputStream(const AudioParameters
& params
)
69 packet_size_(params
.GetPacketSize()),
73 FakeAudioOutputStream::~FakeAudioOutputStream() {}
76 void FakeAudioOutputStream::DestroyLastFakeStream(void* param
) {
77 if (last_fake_stream_
) {
78 DCHECK(last_fake_stream_
->closed_
);
79 delete last_fake_stream_
;