tor-browser

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

audio_transport_impl.h (4191B)


      1 /*
      2 *  Copyright (c) 2016 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 AUDIO_AUDIO_TRANSPORT_IMPL_H_
     12 #define AUDIO_AUDIO_TRANSPORT_IMPL_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <memory>
     17 #include <optional>
     18 #include <vector>
     19 
     20 #include "api/audio/audio_device_defines.h"
     21 #include "api/audio/audio_mixer.h"
     22 #include "api/audio/audio_processing.h"
     23 #include "api/scoped_refptr.h"
     24 #include "common_audio/resampler/include/push_resampler.h"
     25 #include "modules/async_audio_processing/async_audio_processing.h"
     26 #include "rtc_base/synchronization/mutex.h"
     27 #include "rtc_base/thread_annotations.h"
     28 
     29 namespace webrtc {
     30 
     31 class AudioSender;
     32 
     33 class AudioTransportImpl : public AudioTransport {
     34 public:
     35  AudioTransportImpl(
     36      AudioMixer* mixer,
     37      AudioProcessing* audio_processing,
     38      AsyncAudioProcessing::Factory* async_audio_processing_factory);
     39 
     40  AudioTransportImpl() = delete;
     41  AudioTransportImpl(const AudioTransportImpl&) = delete;
     42  AudioTransportImpl& operator=(const AudioTransportImpl&) = delete;
     43 
     44  ~AudioTransportImpl() override;
     45 
     46  // TODO(bugs.webrtc.org/13620) Deprecate this function
     47  int32_t RecordedDataIsAvailable(const void* audioSamples,
     48                                  size_t nSamples,
     49                                  size_t nBytesPerSample,
     50                                  size_t nChannels,
     51                                  uint32_t samplesPerSec,
     52                                  uint32_t totalDelayMS,
     53                                  int32_t clockDrift,
     54                                  uint32_t currentMicLevel,
     55                                  bool keyPressed,
     56                                  uint32_t& newMicLevel) override;
     57 
     58  int32_t RecordedDataIsAvailable(
     59      const void* audioSamples,
     60      size_t nSamples,
     61      size_t nBytesPerSample,
     62      size_t nChannels,
     63      uint32_t samplesPerSec,
     64      uint32_t totalDelayMS,
     65      int32_t clockDrift,
     66      uint32_t currentMicLevel,
     67      bool keyPressed,
     68      uint32_t& newMicLevel,
     69      std::optional<int64_t> estimated_capture_time_ns) override;
     70 
     71  int32_t NeedMorePlayData(size_t nSamples,
     72                           size_t nBytesPerSample,
     73                           size_t nChannels,
     74                           uint32_t samplesPerSec,
     75                           void* audioSamples,
     76                           size_t& nSamplesOut,
     77                           int64_t* elapsed_time_ms,
     78                           int64_t* ntp_time_ms) override;
     79 
     80  void PullRenderData(int bits_per_sample,
     81                      int sample_rate,
     82                      size_t number_of_channels,
     83                      size_t number_of_frames,
     84                      void* audio_data,
     85                      int64_t* elapsed_time_ms,
     86                      int64_t* ntp_time_ms) override;
     87 
     88  void UpdateAudioSenders(std::vector<AudioSender*> senders,
     89                          int send_sample_rate_hz,
     90                          size_t send_num_channels);
     91  void SetStereoChannelSwapping(bool enable);
     92 
     93 private:
     94  void SendProcessedData(std::unique_ptr<AudioFrame> audio_frame);
     95 
     96  // Shared.
     97  AudioProcessing* audio_processing_ = nullptr;
     98 
     99  // Capture side.
    100 
    101  // Thread-safe.
    102  const std::unique_ptr<AsyncAudioProcessing> async_audio_processing_;
    103 
    104  mutable Mutex capture_lock_;
    105  std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
    106  int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
    107  size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
    108  bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false;
    109  PushResampler<int16_t> capture_resampler_;
    110 
    111  // Render side.
    112 
    113  scoped_refptr<AudioMixer> mixer_;
    114  AudioFrame mixed_frame_;
    115  // Converts mixed audio to the audio device output rate.
    116  PushResampler<int16_t> render_resampler_;
    117 };
    118 }  // namespace webrtc
    119 
    120 #endif  // AUDIO_AUDIO_TRANSPORT_IMPL_H_