You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.5 KiB

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