audio_device_generic.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (c) 2012 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. #ifndef AUDIO_DEVICE_AUDIO_DEVICE_GENERIC_H_
  11. #define AUDIO_DEVICE_AUDIO_DEVICE_GENERIC_H_
  12. #include <stdint.h>
  13. #include "modules/audio_device/audio_device_buffer.h"
  14. #include "modules/audio_device/include/audio_device.h"
  15. #include "modules/audio_device/include/audio_device_defines.h"
  16. namespace webrtc {
  17. class AudioDeviceGeneric {
  18. public:
  19. // For use with UMA logging. Must be kept in sync with histograms.xml in
  20. // Chrome, located at
  21. // https://cs.chromium.org/chromium/src/tools/metrics/histograms/histograms.xml
  22. enum class InitStatus {
  23. OK = 0,
  24. PLAYOUT_ERROR = 1,
  25. RECORDING_ERROR = 2,
  26. OTHER_ERROR = 3,
  27. NUM_STATUSES = 4
  28. };
  29. // Retrieve the currently utilized audio layer
  30. virtual int32_t ActiveAudioLayer(
  31. AudioDeviceModule::AudioLayer& audioLayer) const = 0;
  32. // Main initializaton and termination
  33. virtual InitStatus Init() = 0;
  34. virtual int32_t Terminate() = 0;
  35. virtual bool Initialized() const = 0;
  36. // Device enumeration
  37. virtual int16_t PlayoutDevices() = 0;
  38. virtual int16_t RecordingDevices() = 0;
  39. virtual int32_t PlayoutDeviceName(uint16_t index,
  40. char name[kAdmMaxDeviceNameSize],
  41. char guid[kAdmMaxGuidSize]) = 0;
  42. virtual int32_t RecordingDeviceName(uint16_t index,
  43. char name[kAdmMaxDeviceNameSize],
  44. char guid[kAdmMaxGuidSize]) = 0;
  45. // Device selection
  46. virtual int32_t SetPlayoutDevice(uint16_t index) = 0;
  47. virtual int32_t SetPlayoutDevice(
  48. AudioDeviceModule::WindowsDeviceType device) = 0;
  49. virtual int32_t SetRecordingDevice(uint16_t index) = 0;
  50. virtual int32_t SetRecordingDevice(
  51. AudioDeviceModule::WindowsDeviceType device) = 0;
  52. // Audio transport initialization
  53. virtual int32_t PlayoutIsAvailable(bool& available) = 0;
  54. virtual int32_t InitPlayout() = 0;
  55. virtual bool PlayoutIsInitialized() const = 0;
  56. virtual int32_t RecordingIsAvailable(bool& available) = 0;
  57. virtual int32_t InitRecording() = 0;
  58. virtual bool RecordingIsInitialized() const = 0;
  59. // Audio transport control
  60. virtual int32_t StartPlayout() = 0;
  61. virtual int32_t StopPlayout() = 0;
  62. virtual bool Playing() const = 0;
  63. virtual int32_t StartRecording() = 0;
  64. virtual int32_t StopRecording() = 0;
  65. virtual bool Recording() const = 0;
  66. // Audio mixer initialization
  67. virtual int32_t InitSpeaker() = 0;
  68. virtual bool SpeakerIsInitialized() const = 0;
  69. virtual int32_t InitMicrophone() = 0;
  70. virtual bool MicrophoneIsInitialized() const = 0;
  71. // Speaker volume controls
  72. virtual int32_t SpeakerVolumeIsAvailable(bool& available) = 0;
  73. virtual int32_t SetSpeakerVolume(uint32_t volume) = 0;
  74. virtual int32_t SpeakerVolume(uint32_t& volume) const = 0;
  75. virtual int32_t MaxSpeakerVolume(uint32_t& maxVolume) const = 0;
  76. virtual int32_t MinSpeakerVolume(uint32_t& minVolume) const = 0;
  77. // Microphone volume controls
  78. virtual int32_t MicrophoneVolumeIsAvailable(bool& available) = 0;
  79. virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0;
  80. virtual int32_t MicrophoneVolume(uint32_t& volume) const = 0;
  81. virtual int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const = 0;
  82. virtual int32_t MinMicrophoneVolume(uint32_t& minVolume) const = 0;
  83. // Speaker mute control
  84. virtual int32_t SpeakerMuteIsAvailable(bool& available) = 0;
  85. virtual int32_t SetSpeakerMute(bool enable) = 0;
  86. virtual int32_t SpeakerMute(bool& enabled) const = 0;
  87. // Microphone mute control
  88. virtual int32_t MicrophoneMuteIsAvailable(bool& available) = 0;
  89. virtual int32_t SetMicrophoneMute(bool enable) = 0;
  90. virtual int32_t MicrophoneMute(bool& enabled) const = 0;
  91. // Stereo support
  92. virtual int32_t StereoPlayoutIsAvailable(bool& available) = 0;
  93. virtual int32_t SetStereoPlayout(bool enable) = 0;
  94. virtual int32_t StereoPlayout(bool& enabled) const = 0;
  95. virtual int32_t StereoRecordingIsAvailable(bool& available) = 0;
  96. virtual int32_t SetStereoRecording(bool enable) = 0;
  97. virtual int32_t StereoRecording(bool& enabled) const = 0;
  98. // Delay information and control
  99. virtual int32_t PlayoutDelay(uint16_t& delayMS) const = 0;
  100. // Android only
  101. virtual bool BuiltInAECIsAvailable() const;
  102. virtual bool BuiltInAGCIsAvailable() const;
  103. virtual bool BuiltInNSIsAvailable() const;
  104. // Windows Core Audio and Android only.
  105. virtual int32_t EnableBuiltInAEC(bool enable);
  106. virtual int32_t EnableBuiltInAGC(bool enable);
  107. virtual int32_t EnableBuiltInNS(bool enable);
  108. // Play underrun count.
  109. virtual int32_t GetPlayoutUnderrunCount() const;
  110. // iOS only.
  111. // TODO(henrika): add Android support.
  112. #if defined(WEBRTC_IOS)
  113. virtual int GetPlayoutAudioParameters(AudioParameters* params) const;
  114. virtual int GetRecordAudioParameters(AudioParameters* params) const;
  115. #endif // WEBRTC_IOS
  116. virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) = 0;
  117. virtual ~AudioDeviceGeneric() {}
  118. };
  119. } // namespace webrtc
  120. #endif // AUDIO_DEVICE_AUDIO_DEVICE_GENERIC_H_