blob: 8bfa28e21e409e5fd0096d3be0904fdc1a0a2a2c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/fake_audio_output_stream.h"
#include "base/at_exit.h"
bool FakeAudioOutputStream::has_created_fake_stream_ = false;
FakeAudioOutputStream* FakeAudioOutputStream::last_fake_stream_ = NULL;
// static
AudioOutputStream* FakeAudioOutputStream::MakeFakeStream() {
if (!has_created_fake_stream_)
base::AtExitManager::RegisterCallback(&DestroyLastFakeStream, NULL);
has_created_fake_stream_ = true;
return new FakeAudioOutputStream();
}
// static
FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() {
return last_fake_stream_;
}
bool FakeAudioOutputStream::Open(uint32 packet_size) {
if (packet_size < sizeof(int16))
return false;
packet_size_ = packet_size;
buffer_.reset(new char[packet_size_]);
return true;
}
void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
callback_ = callback;
memset(buffer_.get(), 0, packet_size_);
callback_->OnMoreData(this, buffer_.get(), packet_size_, 0);
}
void FakeAudioOutputStream::Stop() {
}
void FakeAudioOutputStream::SetVolume(double volume) {
volume_ = volume;
}
void FakeAudioOutputStream::GetVolume(double* volume) {
*volume = volume_;
}
void FakeAudioOutputStream::Close() {
callback_->OnClose(this);
callback_ = NULL;
if (last_fake_stream_)
delete last_fake_stream_;
last_fake_stream_ = this;
}
FakeAudioOutputStream::FakeAudioOutputStream()
: volume_(0),
callback_(NULL),
packet_size_(0) {
}
// static
void FakeAudioOutputStream::DestroyLastFakeStream(void* param) {
if (last_fake_stream_)
delete last_fake_stream_;
}
|