srpcgen: Use 'const char*' for string parameters
[chromium-blink-merge.git] / media / audio / fake_audio_output_stream.cc
blobfe0d857a1c46c749740ec2a9f4d676e936f24d70
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;
13 // static
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;
28 return new_stream;
31 // static
32 FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() {
33 return last_fake_stream_;
36 bool FakeAudioOutputStream::Open() {
37 if (packet_size_ < sizeof(int16))
38 return false;
39 buffer_.reset(new uint8[packet_size_]);
40 return true;
43 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
44 callback_ = callback;
45 memset(buffer_.get(), 0, packet_size_);
46 callback_->OnMoreData(this, buffer_.get(), packet_size_,
47 AudioBuffersState(0, 0));
50 void FakeAudioOutputStream::Stop() {
51 callback_ = NULL;
54 void FakeAudioOutputStream::SetVolume(double volume) {
55 volume_ = volume;
58 void FakeAudioOutputStream::GetVolume(double* volume) {
59 *volume = volume_;
62 void FakeAudioOutputStream::Close() {
63 closed_ = true;
66 FakeAudioOutputStream::FakeAudioOutputStream(const AudioParameters& params)
67 : volume_(0),
68 callback_(NULL),
69 packet_size_(params.GetPacketSize()),
70 closed_(false) {
73 FakeAudioOutputStream::~FakeAudioOutputStream() {}
75 // static
76 void FakeAudioOutputStream::DestroyLastFakeStream(void* param) {
77 if (last_fake_stream_) {
78 DCHECK(last_fake_stream_->closed_);
79 delete last_fake_stream_;