summaryrefslogtreecommitdiff
path: root/chromium/third_party/webrtc/sound/nullsoundsystem.cc
blob: 962f4105727d51de683d19a4f4b88c4cd9cde101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "webrtc/sound/nullsoundsystem.h"

#include "webrtc/sound/sounddevicelocator.h"
#include "webrtc/sound/soundinputstreaminterface.h"
#include "webrtc/sound/soundoutputstreaminterface.h"
#include "webrtc/base/logging.h"

namespace rtc {

class Thread;

}

namespace rtc {

// Name used for the single device and the sound system itself.
static const char kNullName[] = "null";

class NullSoundDeviceLocator : public SoundDeviceLocator {
 public:
  NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {}

  virtual SoundDeviceLocator *Copy() const {
    return new NullSoundDeviceLocator();
  }
};

class NullSoundInputStream : public SoundInputStreamInterface {
 public:
  virtual bool StartReading() {
    return true;
  }

  virtual bool StopReading() {
    return true;
  }

  virtual bool GetVolume(int *volume) {
    *volume = SoundSystemInterface::kMinVolume;
    return true;
  }

  virtual bool SetVolume(int volume) {
    return false;
  }

  virtual bool Close() {
    return true;
  }

  virtual int LatencyUsecs() {
    return 0;
  }
};

class NullSoundOutputStream : public SoundOutputStreamInterface {
 public:
  virtual bool EnableBufferMonitoring() {
    return true;
  }

  virtual bool DisableBufferMonitoring() {
    return true;
  }

  virtual bool WriteSamples(const void *sample_data,
                            size_t size) {
    LOG(LS_VERBOSE) << "Got " << size << " bytes of playback samples";
    return true;
  }

  virtual bool GetVolume(int *volume) {
    *volume = SoundSystemInterface::kMinVolume;
    return true;
  }

  virtual bool SetVolume(int volume) {
    return false;
  }

  virtual bool Close() {
    return true;
  }

  virtual int LatencyUsecs() {
    return 0;
  }
};

NullSoundSystem::~NullSoundSystem() {
}

bool NullSoundSystem::Init() {
  return true;
}

void NullSoundSystem::Terminate() {
  // Nothing to do.
}

bool NullSoundSystem::EnumeratePlaybackDevices(
      SoundSystemInterface::SoundDeviceLocatorList *devices) {
  ClearSoundDeviceLocatorList(devices);
  SoundDeviceLocator *device;
  GetDefaultPlaybackDevice(&device);
  devices->push_back(device);
  return true;
}

bool NullSoundSystem::EnumerateCaptureDevices(
      SoundSystemInterface::SoundDeviceLocatorList *devices) {
  ClearSoundDeviceLocatorList(devices);
  SoundDeviceLocator *device;
  GetDefaultCaptureDevice(&device);
  devices->push_back(device);
  return true;
}

bool NullSoundSystem::GetDefaultPlaybackDevice(
    SoundDeviceLocator **device) {
  *device = new NullSoundDeviceLocator();
  return true;
}

bool NullSoundSystem::GetDefaultCaptureDevice(
    SoundDeviceLocator **device) {
  *device = new NullSoundDeviceLocator();
  return true;
}

SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice(
      const SoundDeviceLocator *device,
      const OpenParams &params) {
  return new NullSoundOutputStream();
}

SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice(
      const SoundDeviceLocator *device,
      const OpenParams &params) {
  return new NullSoundInputStream();
}

const char *NullSoundSystem::GetName() const {
  return kNullName;
}

}  // namespace rtc