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
18namespace rtc {
19
20class Thread;
21
22}
23
24namespace rtc {
25
26// Name used for the single device and the sound system itself.
27static const char kNullName[] = "null";
28
29class NullSoundDeviceLocator : public SoundDeviceLocator {
30 public:
31  NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {}
32
33  virtual SoundDeviceLocator *Copy() const {
34    return new NullSoundDeviceLocator();
35  }
36};
37
38class NullSoundInputStream : public SoundInputStreamInterface {
39 public:
40  virtual bool StartReading() {
41    return true;
42  }
43
44  virtual bool StopReading() {
45    return true;
46  }
47
48  virtual bool GetVolume(int *volume) {
49    *volume = SoundSystemInterface::kMinVolume;
50    return true;
51  }
52
53  virtual bool SetVolume(int volume) {
54    return false;
55  }
56
57  virtual bool Close() {
58    return true;
59  }
60
61  virtual int LatencyUsecs() {
62    return 0;
63  }
64};
65
66class NullSoundOutputStream : public SoundOutputStreamInterface {
67 public:
68  virtual bool EnableBufferMonitoring() {
69    return true;
70  }
71
72  virtual bool DisableBufferMonitoring() {
73    return true;
74  }
75
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
82  virtual bool GetVolume(int *volume) {
83    *volume = SoundSystemInterface::kMinVolume;
84    return true;
85  }
86
87  virtual bool SetVolume(int volume) {
88    return false;
89  }
90
91  virtual bool Close() {
92    return true;
93  }
94
95  virtual int LatencyUsecs() {
96    return 0;
97  }
98};
99
100NullSoundSystem::~NullSoundSystem() {
101}
102
103bool NullSoundSystem::Init() {
104  return true;
105}
106
107void NullSoundSystem::Terminate() {
108  // Nothing to do.
109}
110
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
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
129bool NullSoundSystem::GetDefaultPlaybackDevice(
130    SoundDeviceLocator **device) {
131  *device = new NullSoundDeviceLocator();
132  return true;
133}
134
135bool NullSoundSystem::GetDefaultCaptureDevice(
136    SoundDeviceLocator **device) {
137  *device = new NullSoundDeviceLocator();
138  return true;
139}
140
141SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice(
142      const SoundDeviceLocator *device,
143      const OpenParams &params) {
144  return new NullSoundOutputStream();
145}
146
147SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice(
148      const SoundDeviceLocator *device,
149      const OpenParams &params) {
150  return new NullSoundInputStream();
151}
152
153const char *NullSoundSystem::GetName() const {
154  return kNullName;
155}
156
157}  // namespace rtc
158