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 class Thread; 20 } 21 22 namespace rtc { 23 24 // Name used for the single device and the sound system itself. 25 static const char kNullName[] = "null"; 26 27 class NullSoundDeviceLocator : public SoundDeviceLocator { 28 public: NullSoundDeviceLocator()29 NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {} 30 Copy() const31 SoundDeviceLocator *Copy() const override { 32 return new NullSoundDeviceLocator(); 33 } 34 }; 35 36 class NullSoundInputStream : public SoundInputStreamInterface { 37 public: StartReading()38 bool StartReading() override { 39 return true; 40 } 41 StopReading()42 bool StopReading() override { 43 return true; 44 } 45 GetVolume(int * volume)46 bool GetVolume(int *volume) override { 47 *volume = SoundSystemInterface::kMinVolume; 48 return true; 49 } 50 SetVolume(int volume)51 bool SetVolume(int volume) override { 52 return false; 53 } 54 Close()55 bool Close() override { 56 return true; 57 } 58 LatencyUsecs()59 int LatencyUsecs() override { 60 return 0; 61 } 62 }; 63 64 class NullSoundOutputStream : public SoundOutputStreamInterface { 65 public: EnableBufferMonitoring()66 bool EnableBufferMonitoring() override { 67 return true; 68 } 69 DisableBufferMonitoring()70 bool DisableBufferMonitoring() override { 71 return true; 72 } 73 WriteSamples(const void * sample_data,size_t size)74 bool WriteSamples(const void *sample_data, size_t size) override { 75 LOG(LS_VERBOSE) << "Got " << size << " bytes of playback samples"; 76 return true; 77 } 78 GetVolume(int * volume)79 bool GetVolume(int *volume) override { 80 *volume = SoundSystemInterface::kMinVolume; 81 return true; 82 } 83 SetVolume(int volume)84 bool SetVolume(int volume) override { 85 return false; 86 } 87 Close()88 bool Close() override { 89 return true; 90 } 91 LatencyUsecs()92 int LatencyUsecs() override { 93 return 0; 94 } 95 }; 96 ~NullSoundSystem()97NullSoundSystem::~NullSoundSystem() { 98 } 99 Init()100bool NullSoundSystem::Init() { 101 return true; 102 } 103 Terminate()104void NullSoundSystem::Terminate() { 105 // Nothing to do. 106 } 107 EnumeratePlaybackDevices(SoundSystemInterface::SoundDeviceLocatorList * devices)108bool NullSoundSystem::EnumeratePlaybackDevices( 109 SoundSystemInterface::SoundDeviceLocatorList *devices) { 110 ClearSoundDeviceLocatorList(devices); 111 SoundDeviceLocator *device; 112 GetDefaultPlaybackDevice(&device); 113 devices->push_back(device); 114 return true; 115 } 116 EnumerateCaptureDevices(SoundSystemInterface::SoundDeviceLocatorList * devices)117bool NullSoundSystem::EnumerateCaptureDevices( 118 SoundSystemInterface::SoundDeviceLocatorList *devices) { 119 ClearSoundDeviceLocatorList(devices); 120 SoundDeviceLocator *device; 121 GetDefaultCaptureDevice(&device); 122 devices->push_back(device); 123 return true; 124 } 125 GetDefaultPlaybackDevice(SoundDeviceLocator ** device)126bool NullSoundSystem::GetDefaultPlaybackDevice( 127 SoundDeviceLocator **device) { 128 *device = new NullSoundDeviceLocator(); 129 return true; 130 } 131 GetDefaultCaptureDevice(SoundDeviceLocator ** device)132bool NullSoundSystem::GetDefaultCaptureDevice( 133 SoundDeviceLocator **device) { 134 *device = new NullSoundDeviceLocator(); 135 return true; 136 } 137 OpenPlaybackDevice(const SoundDeviceLocator * device,const OpenParams & params)138SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice( 139 const SoundDeviceLocator *device, 140 const OpenParams ¶ms) { 141 return new NullSoundOutputStream(); 142 } 143 OpenCaptureDevice(const SoundDeviceLocator * device,const OpenParams & params)144SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice( 145 const SoundDeviceLocator *device, 146 const OpenParams ¶ms) { 147 return new NullSoundInputStream(); 148 } 149 GetName() const150const char *NullSoundSystem::GetName() const { 151 return kNullName; 152 } 153 154 } // namespace rtc 155