3
* Copyright 2004--2010, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#include "talk/sound/nullsoundsystem.h"
30
#include "talk/base/logging.h"
31
#include "talk/sound/sounddevicelocator.h"
32
#include "talk/sound/soundinputstreaminterface.h"
33
#include "talk/sound/soundoutputstreaminterface.h"
43
// Name used for the single device and the sound system itself.
44
static const char kNullName[] = "null";
46
class NullSoundDeviceLocator : public SoundDeviceLocator {
48
NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {}
50
virtual SoundDeviceLocator *Copy() const {
51
return new NullSoundDeviceLocator();
55
class NullSoundInputStream : public SoundInputStreamInterface {
57
virtual bool StartReading() {
61
virtual bool StopReading() {
65
virtual bool GetVolume(int *volume) {
66
*volume = SoundSystemInterface::kMinVolume;
70
virtual bool SetVolume(int volume) {
74
virtual bool Close() {
78
virtual int LatencyUsecs() {
83
class NullSoundOutputStream : public SoundOutputStreamInterface {
85
virtual bool EnableBufferMonitoring() {
89
virtual bool DisableBufferMonitoring() {
93
virtual bool WriteSamples(const void *sample_data,
95
LOG(LS_VERBOSE) << "Got " << size << " bytes of playback samples";
99
virtual bool GetVolume(int *volume) {
100
*volume = SoundSystemInterface::kMinVolume;
104
virtual bool SetVolume(int volume) {
108
virtual bool Close() {
112
virtual int LatencyUsecs() {
117
NullSoundSystem::~NullSoundSystem() {
120
bool NullSoundSystem::Init() {
124
void NullSoundSystem::Terminate() {
128
bool NullSoundSystem::EnumeratePlaybackDevices(
129
SoundSystemInterface::SoundDeviceLocatorList *devices) {
130
ClearSoundDeviceLocatorList(devices);
131
SoundDeviceLocator *device;
132
GetDefaultPlaybackDevice(&device);
133
devices->push_back(device);
137
bool NullSoundSystem::EnumerateCaptureDevices(
138
SoundSystemInterface::SoundDeviceLocatorList *devices) {
139
ClearSoundDeviceLocatorList(devices);
140
SoundDeviceLocator *device;
141
GetDefaultCaptureDevice(&device);
142
devices->push_back(device);
146
bool NullSoundSystem::GetDefaultPlaybackDevice(
147
SoundDeviceLocator **device) {
148
*device = new NullSoundDeviceLocator();
152
bool NullSoundSystem::GetDefaultCaptureDevice(
153
SoundDeviceLocator **device) {
154
*device = new NullSoundDeviceLocator();
158
SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice(
159
const SoundDeviceLocator *device,
160
const OpenParams ¶ms) {
161
return new NullSoundOutputStream();
164
SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice(
165
const SoundDeviceLocator *device,
166
const OpenParams ¶ms) {
167
return new NullSoundInputStream();
170
const char *NullSoundSystem::GetName() const {
174
} // namespace cricket