• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
35 namespace talk_base {
36 
37 class Thread;
38 
39 }
40 
41 namespace cricket {
42 
43 // Name used for the single device and the sound system itself.
44 static const char kNullName[] = "null";
45 
46 class NullSoundDeviceLocator : public SoundDeviceLocator {
47  public:
NullSoundDeviceLocator()48   NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {}
49 
Copy() const50   virtual SoundDeviceLocator *Copy() const {
51     return new NullSoundDeviceLocator();
52   }
53 };
54 
55 class NullSoundInputStream : public SoundInputStreamInterface {
56  public:
StartReading()57   virtual bool StartReading() {
58     return true;
59   }
60 
StopReading()61   virtual bool StopReading() {
62     return true;
63   }
64 
GetVolume(int * volume)65   virtual bool GetVolume(int *volume) {
66     *volume = SoundSystemInterface::kMinVolume;
67     return true;
68   }
69 
SetVolume(int volume)70   virtual bool SetVolume(int volume) {
71     return false;
72   }
73 
Close()74   virtual bool Close() {
75     return true;
76   }
77 
LatencyUsecs()78   virtual int LatencyUsecs() {
79     return 0;
80   }
81 };
82 
83 class NullSoundOutputStream : public SoundOutputStreamInterface {
84  public:
EnableBufferMonitoring()85   virtual bool EnableBufferMonitoring() {
86     return true;
87   }
88 
DisableBufferMonitoring()89   virtual bool DisableBufferMonitoring() {
90     return true;
91   }
92 
WriteSamples(const void * sample_data,size_t size)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 
GetVolume(int * volume)99   virtual bool GetVolume(int *volume) {
100     *volume = SoundSystemInterface::kMinVolume;
101     return true;
102   }
103 
SetVolume(int volume)104   virtual bool SetVolume(int volume) {
105     return false;
106   }
107 
Close()108   virtual bool Close() {
109     return true;
110   }
111 
LatencyUsecs()112   virtual int LatencyUsecs() {
113     return 0;
114   }
115 };
116 
~NullSoundSystem()117 NullSoundSystem::~NullSoundSystem() {
118 }
119 
Init()120 bool NullSoundSystem::Init() {
121   return true;
122 }
123 
Terminate()124 void NullSoundSystem::Terminate() {
125   // Nothing to do.
126 }
127 
EnumeratePlaybackDevices(SoundSystemInterface::SoundDeviceLocatorList * devices)128 bool 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 
EnumerateCaptureDevices(SoundSystemInterface::SoundDeviceLocatorList * devices)137 bool 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 
GetDefaultPlaybackDevice(SoundDeviceLocator ** device)146 bool NullSoundSystem::GetDefaultPlaybackDevice(
147     SoundDeviceLocator **device) {
148   *device = new NullSoundDeviceLocator();
149   return true;
150 }
151 
GetDefaultCaptureDevice(SoundDeviceLocator ** device)152 bool NullSoundSystem::GetDefaultCaptureDevice(
153     SoundDeviceLocator **device) {
154   *device = new NullSoundDeviceLocator();
155   return true;
156 }
157 
OpenPlaybackDevice(const SoundDeviceLocator * device,const OpenParams & params)158 SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice(
159       const SoundDeviceLocator *device,
160       const OpenParams &params) {
161   return new NullSoundOutputStream();
162 }
163 
OpenCaptureDevice(const SoundDeviceLocator * device,const OpenParams & params)164 SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice(
165       const SoundDeviceLocator *device,
166       const OpenParams &params) {
167   return new NullSoundInputStream();
168 }
169 
GetName() const170 const char *NullSoundSystem::GetName() const {
171   return kNullName;
172 }
173 
174 }  // namespace cricket
175