audio_device_impl.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_
  11. #define MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_
  12. #if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
  13. #include <stdint.h>
  14. #include <memory>
  15. #include "api/task_queue/task_queue_factory.h"
  16. #include "modules/audio_device/audio_device_buffer.h"
  17. #include "modules/audio_device/include/audio_device.h"
  18. namespace webrtc {
  19. class AudioDeviceGeneric;
  20. class AudioManager;
  21. class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
  22. public:
  23. enum PlatformType {
  24. kPlatformNotSupported = 0,
  25. kPlatformWin32 = 1,
  26. kPlatformWinCe = 2,
  27. kPlatformLinux = 3,
  28. kPlatformMac = 4,
  29. kPlatformAndroid = 5,
  30. kPlatformIOS = 6
  31. };
  32. int32_t CheckPlatform();
  33. int32_t CreatePlatformSpecificObjects();
  34. int32_t AttachAudioBuffer();
  35. AudioDeviceModuleImpl(AudioLayer audio_layer,
  36. TaskQueueFactory* task_queue_factory);
  37. ~AudioDeviceModuleImpl() override;
  38. // Retrieve the currently utilized audio layer
  39. int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override;
  40. // Full-duplex transportation of PCM audio
  41. int32_t RegisterAudioCallback(AudioTransport* audioCallback) override;
  42. // Main initializaton and termination
  43. int32_t Init() override;
  44. int32_t Terminate() override;
  45. bool Initialized() const override;
  46. // Device enumeration
  47. int16_t PlayoutDevices() override;
  48. int16_t RecordingDevices() override;
  49. int32_t PlayoutDeviceName(uint16_t index,
  50. char name[kAdmMaxDeviceNameSize],
  51. char guid[kAdmMaxGuidSize]) override;
  52. int32_t RecordingDeviceName(uint16_t index,
  53. char name[kAdmMaxDeviceNameSize],
  54. char guid[kAdmMaxGuidSize]) override;
  55. // Device selection
  56. int32_t SetPlayoutDevice(uint16_t index) override;
  57. int32_t SetPlayoutDevice(WindowsDeviceType device) override;
  58. int32_t SetRecordingDevice(uint16_t index) override;
  59. int32_t SetRecordingDevice(WindowsDeviceType device) override;
  60. // Audio transport initialization
  61. int32_t PlayoutIsAvailable(bool* available) override;
  62. int32_t InitPlayout() override;
  63. bool PlayoutIsInitialized() const override;
  64. int32_t RecordingIsAvailable(bool* available) override;
  65. int32_t InitRecording() override;
  66. bool RecordingIsInitialized() const override;
  67. // Audio transport control
  68. int32_t StartPlayout() override;
  69. int32_t StopPlayout() override;
  70. bool Playing() const override;
  71. int32_t StartRecording() override;
  72. int32_t StopRecording() override;
  73. bool Recording() const override;
  74. // Audio mixer initialization
  75. int32_t InitSpeaker() override;
  76. bool SpeakerIsInitialized() const override;
  77. int32_t InitMicrophone() override;
  78. bool MicrophoneIsInitialized() const override;
  79. // Speaker volume controls
  80. int32_t SpeakerVolumeIsAvailable(bool* available) override;
  81. int32_t SetSpeakerVolume(uint32_t volume) override;
  82. int32_t SpeakerVolume(uint32_t* volume) const override;
  83. int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override;
  84. int32_t MinSpeakerVolume(uint32_t* minVolume) const override;
  85. // Microphone volume controls
  86. int32_t MicrophoneVolumeIsAvailable(bool* available) override;
  87. int32_t SetMicrophoneVolume(uint32_t volume) override;
  88. int32_t MicrophoneVolume(uint32_t* volume) const override;
  89. int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override;
  90. int32_t MinMicrophoneVolume(uint32_t* minVolume) const override;
  91. // Speaker mute control
  92. int32_t SpeakerMuteIsAvailable(bool* available) override;
  93. int32_t SetSpeakerMute(bool enable) override;
  94. int32_t SpeakerMute(bool* enabled) const override;
  95. // Microphone mute control
  96. int32_t MicrophoneMuteIsAvailable(bool* available) override;
  97. int32_t SetMicrophoneMute(bool enable) override;
  98. int32_t MicrophoneMute(bool* enabled) const override;
  99. // Stereo support
  100. int32_t StereoPlayoutIsAvailable(bool* available) const override;
  101. int32_t SetStereoPlayout(bool enable) override;
  102. int32_t StereoPlayout(bool* enabled) const override;
  103. int32_t StereoRecordingIsAvailable(bool* available) const override;
  104. int32_t SetStereoRecording(bool enable) override;
  105. int32_t StereoRecording(bool* enabled) const override;
  106. // Delay information and control
  107. int32_t PlayoutDelay(uint16_t* delayMS) const override;
  108. bool BuiltInAECIsAvailable() const override;
  109. int32_t EnableBuiltInAEC(bool enable) override;
  110. bool BuiltInAGCIsAvailable() const override;
  111. int32_t EnableBuiltInAGC(bool enable) override;
  112. bool BuiltInNSIsAvailable() const override;
  113. int32_t EnableBuiltInNS(bool enable) override;
  114. // Play underrun count.
  115. int32_t GetPlayoutUnderrunCount() const override;
  116. #if defined(WEBRTC_IOS)
  117. int GetPlayoutAudioParameters(AudioParameters* params) const override;
  118. int GetRecordAudioParameters(AudioParameters* params) const override;
  119. #endif // WEBRTC_IOS
  120. #if defined(WEBRTC_ANDROID)
  121. // Only use this acccessor for test purposes on Android.
  122. AudioManager* GetAndroidAudioManagerForTest() {
  123. return audio_manager_android_.get();
  124. }
  125. #endif
  126. AudioDeviceBuffer* GetAudioDeviceBuffer() { return &audio_device_buffer_; }
  127. int RestartPlayoutInternally() override { return -1; }
  128. int RestartRecordingInternally() override { return -1; }
  129. int SetPlayoutSampleRate(uint32_t sample_rate) override { return -1; }
  130. int SetRecordingSampleRate(uint32_t sample_rate) override { return -1; }
  131. private:
  132. PlatformType Platform() const;
  133. AudioLayer PlatformAudioLayer() const;
  134. AudioLayer audio_layer_;
  135. PlatformType platform_type_ = kPlatformNotSupported;
  136. bool initialized_ = false;
  137. #if defined(WEBRTC_ANDROID)
  138. // Should be declared first to ensure that it outlives other resources.
  139. std::unique_ptr<AudioManager> audio_manager_android_;
  140. #endif
  141. AudioDeviceBuffer audio_device_buffer_;
  142. std::unique_ptr<AudioDeviceGeneric> audio_device_;
  143. };
  144. } // namespace webrtc
  145. #endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
  146. #endif // MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_