blob: 29200086e2195fbbd8a5dbfa6e5ff6a9544da9f9 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004--2010, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
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.
15 *
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.
26 */
27
28#include "talk/sound/nullsoundsystem.h"
29
30#include "talk/base/logging.h"
31#include "talk/sound/sounddevicelocator.h"
32#include "talk/sound/soundinputstreaminterface.h"
33#include "talk/sound/soundoutputstreaminterface.h"
34
35namespace talk_base {
36
37class Thread;
38
39}
40
41namespace cricket {
42
43// Name used for the single device and the sound system itself.
44static const char kNullName[] = "null";
45
46class NullSoundDeviceLocator : public SoundDeviceLocator {
47 public:
48 NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {}
49
50 virtual SoundDeviceLocator *Copy() const {
51 return new NullSoundDeviceLocator();
52 }
53};
54
55class NullSoundInputStream : public SoundInputStreamInterface {
56 public:
57 virtual bool StartReading() {
58 return true;
59 }
60
61 virtual bool StopReading() {
62 return true;
63 }
64
65 virtual bool GetVolume(int *volume) {
66 *volume = SoundSystemInterface::kMinVolume;
67 return true;
68 }
69
70 virtual bool SetVolume(int volume) {
71 return false;
72 }
73
74 virtual bool Close() {
75 return true;
76 }
77
78 virtual int LatencyUsecs() {
79 return 0;
80 }
81};
82
83class NullSoundOutputStream : public SoundOutputStreamInterface {
84 public:
85 virtual bool EnableBufferMonitoring() {
86 return true;
87 }
88
89 virtual bool DisableBufferMonitoring() {
90 return true;
91 }
92
93 virtual bool WriteSamples(const void *sample_data,
94 size_t size) {
95 LOG(LS_VERBOSE) << "Got " << size << " bytes of playback samples";
96 return true;
97 }
98
99 virtual bool GetVolume(int *volume) {
100 *volume = SoundSystemInterface::kMinVolume;
101 return true;
102 }
103
104 virtual bool SetVolume(int volume) {
105 return false;
106 }
107
108 virtual bool Close() {
109 return true;
110 }
111
112 virtual int LatencyUsecs() {
113 return 0;
114 }
115};
116
117NullSoundSystem::~NullSoundSystem() {
118}
119
120bool NullSoundSystem::Init() {
121 return true;
122}
123
124void NullSoundSystem::Terminate() {
125 // Nothing to do.
126}
127
128bool NullSoundSystem::EnumeratePlaybackDevices(
129 SoundSystemInterface::SoundDeviceLocatorList *devices) {
130 ClearSoundDeviceLocatorList(devices);
131 SoundDeviceLocator *device;
132 GetDefaultPlaybackDevice(&device);
133 devices->push_back(device);
134 return true;
135}
136
137bool NullSoundSystem::EnumerateCaptureDevices(
138 SoundSystemInterface::SoundDeviceLocatorList *devices) {
139 ClearSoundDeviceLocatorList(devices);
140 SoundDeviceLocator *device;
141 GetDefaultCaptureDevice(&device);
142 devices->push_back(device);
143 return true;
144}
145
146bool NullSoundSystem::GetDefaultPlaybackDevice(
147 SoundDeviceLocator **device) {
148 *device = new NullSoundDeviceLocator();
149 return true;
150}
151
152bool NullSoundSystem::GetDefaultCaptureDevice(
153 SoundDeviceLocator **device) {
154 *device = new NullSoundDeviceLocator();
155 return true;
156}
157
158SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice(
159 const SoundDeviceLocator *device,
160 const OpenParams &params) {
161 return new NullSoundOutputStream();
162}
163
164SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice(
165 const SoundDeviceLocator *device,
166 const OpenParams &params) {
167 return new NullSoundInputStream();
168}
169
170const char *NullSoundSystem::GetName() const {
171 return kNullName;
172}
173
174} // namespace cricket