1 /* 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "webrtc/sound/nullsoundsystem.h" 12 13 #include "webrtc/sound/sounddevicelocator.h" 14 #include "webrtc/sound/soundinputstreaminterface.h" 15 #include "webrtc/sound/soundoutputstreaminterface.h" 16 #include "webrtc/base/logging.h" 17 18 namespace rtc { 19 20 class Thread; 21 22 } 23 24 namespace rtc { 25 26 // Name used for the single device and the sound system itself. 27 static const char kNullName[] = "null"; 28 29 class NullSoundDeviceLocator : public SoundDeviceLocator { 30 public: NullSoundDeviceLocator()31 NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {} 32 Copy() const33 virtual SoundDeviceLocator *Copy() const { 34 return new NullSoundDeviceLocator(); 35 } 36 }; 37 38 class NullSoundInputStream : public SoundInputStreamInterface { 39 public: StartReading()40 virtual bool StartReading() { 41 return true; 42 } 43 StopReading()44 virtual bool StopReading() { 45 return true; 46 } 47 GetVolume(int * volume)48 virtual bool GetVolume(int *volume) { 49 *volume = SoundSystemInterface::kMinVolume; 50 return true; 51 } 52 SetVolume(int volume)53 virtual bool SetVolume(int volume) { 54 return false; 55 } 56 Close()57 virtual bool Close() { 58 return true; 59 } 60 LatencyUsecs()61 virtual int LatencyUsecs() { 62 return 0; 63 } 64 }; 65 66 class NullSoundOutputStream : public SoundOutputStreamInterface { 67 public: EnableBufferMonitoring()68 virtual bool EnableBufferMonitoring() { 69 return true; 70 } 71 DisableBufferMonitoring()72 virtual bool DisableBufferMonitoring() { 73 return true; 74 } 75 WriteSamples(const void * sample_data,size_t size)76 virtual bool WriteSamples(const void *sample_data, 77 size_t size) { 78 LOG(LS_VERBOSE) << "Got " << size << " bytes of playback samples"; 79 return true; 80 } 81 GetVolume(int * volume)82 virtual bool GetVolume(int *volume) { 83 *volume = SoundSystemInterface::kMinVolume; 84 return true; 85 } 86 SetVolume(int volume)87 virtual bool SetVolume(int volume) { 88 return false; 89 } 90 Close()91 virtual bool Close() { 92 return true; 93 } 94 LatencyUsecs()95 virtual int LatencyUsecs() { 96 return 0; 97 } 98 }; 99 ~NullSoundSystem()100NullSoundSystem::~NullSoundSystem() { 101 } 102 Init()103bool NullSoundSystem::Init() { 104 return true; 105 } 106 Terminate()107void NullSoundSystem::Terminate() { 108 // Nothing to do. 109 } 110 EnumeratePlaybackDevices(SoundSystemInterface::SoundDeviceLocatorList * devices)111bool NullSoundSystem::EnumeratePlaybackDevices( 112 SoundSystemInterface::SoundDeviceLocatorList *devices) { 113 ClearSoundDeviceLocatorList(devices); 114 SoundDeviceLocator *device; 115 GetDefaultPlaybackDevice(&device); 116 devices->push_back(device); 117 return true; 118 } 119 EnumerateCaptureDevices(SoundSystemInterface::SoundDeviceLocatorList * devices)120bool NullSoundSystem::EnumerateCaptureDevices( 121 SoundSystemInterface::SoundDeviceLocatorList *devices) { 122 ClearSoundDeviceLocatorList(devices); 123 SoundDeviceLocator *device; 124 GetDefaultCaptureDevice(&device); 125 devices->push_back(device); 126 return true; 127 } 128 GetDefaultPlaybackDevice(SoundDeviceLocator ** device)129bool NullSoundSystem::GetDefaultPlaybackDevice( 130 SoundDeviceLocator **device) { 131 *device = new NullSoundDeviceLocator(); 132 return true; 133 } 134 GetDefaultCaptureDevice(SoundDeviceLocator ** device)135bool NullSoundSystem::GetDefaultCaptureDevice( 136 SoundDeviceLocator **device) { 137 *device = new NullSoundDeviceLocator(); 138 return true; 139 } 140 OpenPlaybackDevice(const SoundDeviceLocator * device,const OpenParams & params)141SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice( 142 const SoundDeviceLocator *device, 143 const OpenParams ¶ms) { 144 return new NullSoundOutputStream(); 145 } 146 OpenCaptureDevice(const SoundDeviceLocator * device,const OpenParams & params)147SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice( 148 const SoundDeviceLocator *device, 149 const OpenParams ¶ms) { 150 return new NullSoundInputStream(); 151 } 152 GetName() const153const char *NullSoundSystem::GetName() const { 154 return kNullName; 155 } 156 157 } // namespace rtc 158