tor-browser

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

audio_mixer_impl.h (2839B)


      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 
     11 #ifndef MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
     12 #define MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
     13 
     14 #include <stddef.h>
     15 
     16 #include <memory>
     17 #include <vector>
     18 
     19 #include "api/array_view.h"
     20 #include "api/audio/audio_frame.h"
     21 #include "api/audio/audio_mixer.h"
     22 #include "api/scoped_refptr.h"
     23 #include "modules/audio_mixer/frame_combiner.h"
     24 #include "modules/audio_mixer/output_rate_calculator.h"
     25 #include "rtc_base/synchronization/mutex.h"
     26 #include "rtc_base/thread_annotations.h"
     27 
     28 namespace webrtc {
     29 
     30 class AudioMixerImpl : public AudioMixer {
     31 public:
     32  struct SourceStatus;
     33 
     34  // AudioProcessing only accepts 10 ms frames.
     35  static const int kFrameDurationInMs = 10;
     36 
     37  static scoped_refptr<AudioMixerImpl> Create();
     38 
     39  static scoped_refptr<AudioMixerImpl> Create(
     40      std::unique_ptr<OutputRateCalculator> output_rate_calculator,
     41      bool use_limiter);
     42 
     43  ~AudioMixerImpl() override;
     44 
     45  AudioMixerImpl(const AudioMixerImpl&) = delete;
     46  AudioMixerImpl& operator=(const AudioMixerImpl&) = delete;
     47 
     48  // AudioMixer functions
     49  bool AddSource(Source* audio_source) override;
     50  void RemoveSource(Source* audio_source) override;
     51 
     52  void Mix(size_t number_of_channels,
     53           AudioFrame* audio_frame_for_mixing) override
     54      RTC_LOCKS_EXCLUDED(mutex_);
     55 
     56 protected:
     57  AudioMixerImpl(std::unique_ptr<OutputRateCalculator> output_rate_calculator,
     58                 bool use_limiter);
     59 
     60 private:
     61  struct HelperContainers;
     62 
     63  void UpdateSourceCountStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
     64 
     65  // Fetches audio frames to mix from sources.
     66  ArrayView<AudioFrame* const> GetAudioFromSources(int output_frequency)
     67      RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
     68 
     69  // The critical section lock guards audio source insertion and
     70  // removal, which can be done from any thread. The race checker
     71  // checks that mixing is done sequentially.
     72  mutable Mutex mutex_;
     73 
     74  std::unique_ptr<OutputRateCalculator> output_rate_calculator_;
     75 
     76  // List of all audio sources.
     77  std::vector<std::unique_ptr<SourceStatus>> audio_source_list_
     78      RTC_GUARDED_BY(mutex_);
     79  const std::unique_ptr<HelperContainers> helper_containers_
     80      RTC_GUARDED_BY(mutex_);
     81 
     82  // Component that handles actual adding of audio frames.
     83  FrameCombiner frame_combiner_;
     84 
     85  // The highest source count this mixer has ever had. Used for UMA stats.
     86  size_t max_source_count_ever_ = 0;
     87 };
     88 }  // namespace webrtc
     89 
     90 #endif  // MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_