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.

129 lines
4.9 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. #ifndef TALK_SOUND_SOUNDSYSTEMINTERFACE_H_
  28. #define TALK_SOUND_SOUNDSYSTEMINTERFACE_H_
  29. #include <vector>
  30. #include "talk/base/constructormagic.h"
  31. namespace cricket {
  32. class SoundDeviceLocator;
  33. class SoundInputStreamInterface;
  34. class SoundOutputStreamInterface;
  35. // Interface for a platform's sound system.
  36. // Implementations must guarantee thread-safety for at least the following use
  37. // cases:
  38. // 1) Concurrent enumeration and opening of devices from different threads.
  39. // 2) Concurrent use of different Sound(Input|Output)StreamInterface
  40. // instances from different threads (but concurrent use of the _same_ one from
  41. // different threads need not be supported).
  42. class SoundSystemInterface {
  43. public:
  44. typedef std::vector<SoundDeviceLocator *> SoundDeviceLocatorList;
  45. enum SampleFormat {
  46. // Only one supported sample format at this time.
  47. // The values here may be used in lookup tables, so they shouldn't change.
  48. FORMAT_S16LE = 0,
  49. };
  50. enum Flags {
  51. // Enable reporting the current stream latency in
  52. // Sound(Input|Output)StreamInterface. See those classes for more details.
  53. FLAG_REPORT_LATENCY = (1 << 0),
  54. };
  55. struct OpenParams {
  56. // Format for the sound stream.
  57. SampleFormat format;
  58. // Sampling frequency in hertz.
  59. unsigned int freq;
  60. // Number of channels in the PCM stream.
  61. unsigned int channels;
  62. // Misc flags. Should be taken from the Flags enum above.
  63. int flags;
  64. // Desired latency, measured as number of bytes of sample data
  65. int latency;
  66. };
  67. // Special values for the "latency" field of OpenParams.
  68. // Use this one to say you don't care what the latency is. The sound system
  69. // will optimize for other things instead.
  70. static const int kNoLatencyRequirements = -1;
  71. // Use this one to say that you want the sound system to pick an appropriate
  72. // small latency value. The sound system may pick the minimum allowed one, or
  73. // a slightly higher one in the event that the true minimum requires an
  74. // undesirable trade-off.
  75. static const int kLowLatency = 0;
  76. // Max value for the volume parameters for Sound(Input|Output)StreamInterface.
  77. static const int kMaxVolume = 255;
  78. // Min value for the volume parameters for Sound(Input|Output)StreamInterface.
  79. static const int kMinVolume = 0;
  80. // Helper for clearing a locator list and deleting the entries.
  81. static void ClearSoundDeviceLocatorList(SoundDeviceLocatorList *devices);
  82. virtual ~SoundSystemInterface() {}
  83. virtual bool Init() = 0;
  84. virtual void Terminate() = 0;
  85. // Enumerates the available devices. (Any pre-existing locators in the lists
  86. // are deleted.)
  87. virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices) = 0;
  88. virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices) = 0;
  89. // Gets a special locator for the default device.
  90. virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device) = 0;
  91. virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device) = 0;
  92. // Opens the given device, or returns NULL on error.
  93. virtual SoundOutputStreamInterface *OpenPlaybackDevice(
  94. const SoundDeviceLocator *device,
  95. const OpenParams &params) = 0;
  96. virtual SoundInputStreamInterface *OpenCaptureDevice(
  97. const SoundDeviceLocator *device,
  98. const OpenParams &params) = 0;
  99. // A human-readable name for this sound system.
  100. virtual const char *GetName() const = 0;
  101. protected:
  102. SoundSystemInterface() {}
  103. private:
  104. DISALLOW_COPY_AND_ASSIGN(SoundSystemInterface);
  105. };
  106. } // namespace cricket
  107. #endif // TALK_SOUND_SOUNDSYSTEMINTERFACE_H_