tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_audio_device_impl.h (7838B)


      1 /*
      2 *  Copyright (c) 2023 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 
     11 #ifndef MODULES_AUDIO_DEVICE_TEST_AUDIO_DEVICE_IMPL_H_
     12 #define MODULES_AUDIO_DEVICE_TEST_AUDIO_DEVICE_IMPL_H_
     13 
     14 #include <cstdint>
     15 #include <memory>
     16 #include <vector>
     17 
     18 #include "api/audio/audio_device.h"
     19 #include "api/audio/audio_device_defines.h"
     20 #include "api/environment/environment.h"
     21 #include "api/task_queue/task_queue_base.h"
     22 #include "modules/audio_device/audio_device_buffer.h"
     23 #include "modules/audio_device/audio_device_generic.h"
     24 #include "modules/audio_device/include/test_audio_device.h"
     25 #include "rtc_base/buffer.h"
     26 #include "rtc_base/synchronization/mutex.h"
     27 #include "rtc_base/thread_annotations.h"
     28 
     29 namespace webrtc {
     30 
     31 class TestAudioDevice : public AudioDeviceGeneric {
     32 public:
     33  // Creates a new TestAudioDevice. When capturing or playing, 10 ms audio
     34  // frames will be processed every 10ms / `speed`.
     35  // `capturer` is an object that produces audio data. Can be nullptr if this
     36  // device is never used for recording.
     37  // `renderer` is an object that receives audio data that would have been
     38  // played out. Can be nullptr if this device is never used for playing.
     39  TestAudioDevice(const Environment& env,
     40                  std::unique_ptr<TestAudioDeviceModule::Capturer> capturer,
     41                  std::unique_ptr<TestAudioDeviceModule::Renderer> renderer,
     42                  float speed = 1);
     43  TestAudioDevice(const TestAudioDevice&) = delete;
     44  TestAudioDevice& operator=(const TestAudioDevice&) = delete;
     45  ~TestAudioDevice() override = default;
     46 
     47  // Retrieve the currently utilized audio layer
     48  int32_t ActiveAudioLayer(
     49      AudioDeviceModule::AudioLayer& /* audioLayer */) const override {
     50    return 0;
     51  }
     52 
     53  // Main initializaton and termination
     54  InitStatus Init() override;
     55  int32_t Terminate() override { return 0; }
     56  bool Initialized() const override { return true; }
     57 
     58  // Device enumeration
     59  int16_t PlayoutDevices() override { return 0; }
     60  int16_t RecordingDevices() override { return 0; }
     61  int32_t PlayoutDeviceName(uint16_t /* index */,
     62                            char /* name */[kAdmMaxDeviceNameSize],
     63                            char /* guid */[kAdmMaxGuidSize]) override {
     64    return 0;
     65  }
     66  int32_t RecordingDeviceName(uint16_t /* index */,
     67                              char /* name */[kAdmMaxDeviceNameSize],
     68                              char /* guid */[kAdmMaxGuidSize]) override {
     69    return 0;
     70  }
     71 
     72  // Device selection
     73  int32_t SetPlayoutDevice(uint16_t /* index */) override { return 0; }
     74  int32_t SetPlayoutDevice(
     75      AudioDeviceModule::WindowsDeviceType /* device */) override {
     76    return 0;
     77  }
     78  int32_t SetRecordingDevice(uint16_t /* index */) override { return 0; }
     79  int32_t SetRecordingDevice(
     80      AudioDeviceModule::WindowsDeviceType /* device */) override {
     81    return 0;
     82  }
     83 
     84  // Audio transport initialization
     85  int32_t PlayoutIsAvailable(bool& available) override;
     86  int32_t InitPlayout() override;
     87  bool PlayoutIsInitialized() const override;
     88  int32_t RecordingIsAvailable(bool& available) override;
     89  int32_t InitRecording() override;
     90  bool RecordingIsInitialized() const override;
     91 
     92  // Audio transport control
     93  int32_t StartPlayout() override;
     94  int32_t StopPlayout() override;
     95  bool Playing() const override;
     96  int32_t StartRecording() override;
     97  int32_t StopRecording() override;
     98  bool Recording() const override;
     99 
    100  // Audio mixer initialization
    101  int32_t InitSpeaker() override { return 0; }
    102  bool SpeakerIsInitialized() const override { return true; }
    103  int32_t InitMicrophone() override { return 0; }
    104  bool MicrophoneIsInitialized() const override { return true; }
    105 
    106  // Speaker volume controls
    107  int32_t SpeakerVolumeIsAvailable(bool& /* available */) override { return 0; }
    108  int32_t SetSpeakerVolume(uint32_t /* volume */) override { return 0; }
    109  int32_t SpeakerVolume(uint32_t& /* volume */) const override { return 0; }
    110  int32_t MaxSpeakerVolume(uint32_t& /* maxVolume */) const override {
    111    return 0;
    112  }
    113  int32_t MinSpeakerVolume(uint32_t& /* minVolume */) const override {
    114    return 0;
    115  }
    116 
    117  // Microphone volume controls
    118  int32_t MicrophoneVolumeIsAvailable(bool& /* available */) override {
    119    return 0;
    120  }
    121  int32_t SetMicrophoneVolume(uint32_t /* volume */) override { return 0; }
    122  int32_t MicrophoneVolume(uint32_t& /* volume */) const override { return 0; }
    123  int32_t MaxMicrophoneVolume(uint32_t& /* maxVolume */) const override {
    124    return 0;
    125  }
    126  int32_t MinMicrophoneVolume(uint32_t& /* minVolume */) const override {
    127    return 0;
    128  }
    129 
    130  // Speaker mute control
    131  int32_t SpeakerMuteIsAvailable(bool& /* available */) override { return 0; }
    132  int32_t SetSpeakerMute(bool /* enable */) override { return 0; }
    133  int32_t SpeakerMute(bool& /* enabled */) const override { return 0; }
    134 
    135  // Microphone mute control
    136  int32_t MicrophoneMuteIsAvailable(bool& /* available */) override {
    137    return 0;
    138  }
    139  int32_t SetMicrophoneMute(bool /* enable */) override { return 0; }
    140  int32_t MicrophoneMute(bool& /* enabled */) const override { return 0; }
    141 
    142  // Stereo support
    143  int32_t StereoPlayoutIsAvailable(bool& available) override {
    144    available = false;
    145    return 0;
    146  }
    147  int32_t SetStereoPlayout(bool /* enable */) override { return 0; }
    148  int32_t StereoPlayout(bool& /* enabled */) const override { return 0; }
    149  int32_t StereoRecordingIsAvailable(bool& available) override {
    150    available = false;
    151    return 0;
    152  }
    153  int32_t SetStereoRecording(bool /* enable */) override { return 0; }
    154  int32_t StereoRecording(bool& /* enabled */) const override { return 0; }
    155 
    156  // Delay information and control
    157  int32_t PlayoutDelay(uint16_t& delayMS) const override {
    158    delayMS = 0;
    159    return 0;
    160  }
    161 
    162  // Android only
    163  bool BuiltInAECIsAvailable() const override { return false; }
    164  bool BuiltInAGCIsAvailable() const override { return false; }
    165  bool BuiltInNSIsAvailable() const override { return false; }
    166 
    167  // Windows Core Audio and Android only.
    168  int32_t EnableBuiltInAEC(bool /* enable */) override { return -1; }
    169  int32_t EnableBuiltInAGC(bool /* enable */) override { return -1; }
    170  int32_t EnableBuiltInNS(bool /* enable */) override { return -1; }
    171 
    172  // Play underrun count.
    173  int32_t GetPlayoutUnderrunCount() const override { return -1; }
    174 
    175 // iOS only.
    176 // TODO(henrika): add Android support.
    177 #if defined(WEBRTC_IOS)
    178  int GetPlayoutAudioParameters(AudioParameters* params) const override {
    179    return -1;
    180  }
    181  int GetRecordAudioParameters(AudioParameters* params) const override {
    182    return -1;
    183  }
    184 #endif  // WEBRTC_IOS
    185 
    186  void AttachAudioBuffer(AudioDeviceBuffer* audio_buffer) override;
    187 
    188 private:
    189  void ProcessAudio();
    190 
    191  const Environment env_;
    192  const std::unique_ptr<TestAudioDeviceModule::Capturer> capturer_
    193      RTC_GUARDED_BY(lock_);
    194  const std::unique_ptr<TestAudioDeviceModule::Renderer> renderer_
    195      RTC_GUARDED_BY(lock_);
    196  const int64_t process_interval_us_;
    197 
    198  mutable Mutex lock_;
    199  AudioDeviceBuffer* audio_buffer_ RTC_GUARDED_BY(lock_) = nullptr;
    200  bool rendering_ RTC_GUARDED_BY(lock_) = false;
    201  bool capturing_ RTC_GUARDED_BY(lock_) = false;
    202  bool rendering_initialized_ RTC_GUARDED_BY(lock_) = false;
    203  bool capturing_initialized_ RTC_GUARDED_BY(lock_) = false;
    204 
    205  std::vector<int16_t> playout_buffer_ RTC_GUARDED_BY(lock_);
    206  BufferT<int16_t> recording_buffer_ RTC_GUARDED_BY(lock_);
    207  std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue_;
    208 };
    209 
    210 }  // namespace webrtc
    211 
    212 #endif  // MODULES_AUDIO_DEVICE_TEST_AUDIO_DEVICE_IMPL_H_