tor-browser

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

TestVADDTX.h (4089B)


      1 /*
      2 *  Copyright (c) 2011 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_CODING_TEST_TESTVADDTX_H_
     12 #define MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <memory>
     17 #include <optional>
     18 
     19 #include "absl/strings/string_view.h"
     20 #include "api/audio_codecs/audio_decoder_factory.h"
     21 #include "api/audio_codecs/audio_encoder_factory.h"
     22 #include "api/audio_codecs/audio_format.h"
     23 #include "api/environment/environment.h"
     24 #include "api/neteq/neteq.h"
     25 #include "api/scoped_refptr.h"
     26 #include "common_audio/vad/include/vad.h"
     27 #include "modules/audio_coding/acm2/acm_resampler.h"
     28 #include "modules/audio_coding/include/audio_coding_module.h"
     29 #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
     30 #include "modules/audio_coding/test/Channel.h"
     31 
     32 namespace webrtc {
     33 
     34 // This class records the frame type, and delegates actual sending to the
     35 // `next_` AudioPacketizationCallback.
     36 class MonitoringAudioPacketizationCallback : public AudioPacketizationCallback {
     37 public:
     38  explicit MonitoringAudioPacketizationCallback(
     39      AudioPacketizationCallback* next);
     40 
     41  int32_t SendData(AudioFrameType frame_type,
     42                   uint8_t payload_type,
     43                   uint32_t timestamp,
     44                   const uint8_t* payload_data,
     45                   size_t payload_len_bytes,
     46                   int64_t absolute_capture_timestamp_ms) override;
     47 
     48  void PrintStatistics();
     49  void ResetStatistics();
     50  void GetStatistics(uint32_t* stats);
     51 
     52 private:
     53  // 0 - kEmptyFrame
     54  // 1 - kAudioFrameSpeech
     55  // 2 - kAudioFrameCN
     56  uint32_t counter_[3];
     57  AudioPacketizationCallback* const next_;
     58 };
     59 
     60 // TestVadDtx is to verify that VAD/DTX perform as they should. It runs through
     61 // an audio file and check if the occurrence of various packet types follows
     62 // expectation. TestVadDtx needs its derived class to implement the Perform()
     63 // to put the test together.
     64 class TestVadDtx {
     65 public:
     66  static const int kOutputFreqHz = 16000;
     67 
     68  TestVadDtx();
     69 
     70 protected:
     71  // Returns true iff CN was added.
     72  bool RegisterCodec(const SdpAudioFormat& codec_format,
     73                     std::optional<Vad::Aggressiveness> vad_mode);
     74 
     75  // Encoding a file and see if the numbers that various packets occur follow
     76  // the expectation. Saves result to a file.
     77  // expects[x] means
     78  // -1 : do not care,
     79  // 0  : there have been no packets of type `x`,
     80  // 1  : there have been packets of type `x`,
     81  // with `x` indicates the following packet types
     82  // 0 - kEmptyFrame
     83  // 1 - kAudioFrameSpeech
     84  // 2 - kAudioFrameCN
     85  void Run(absl::string_view in_filename,
     86           int frequency,
     87           int channels,
     88           absl::string_view out_filename,
     89           bool append,
     90           const int* expects);
     91 
     92  const Environment env_;
     93  const scoped_refptr<AudioEncoderFactory> encoder_factory_;
     94  const scoped_refptr<AudioDecoderFactory> decoder_factory_;
     95  std::unique_ptr<AudioCodingModule> acm_send_;
     96  std::unique_ptr<NetEq> neteq_;
     97  acm2::ResamplerHelper resampler_helper_;
     98  std::unique_ptr<Channel> channel_;
     99  std::unique_ptr<MonitoringAudioPacketizationCallback> packetization_callback_;
    100  uint32_t time_stamp_ = 0x12345678;
    101 };
    102 
    103 // TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should.
    104 class TestWebRtcVadDtx final : public TestVadDtx {
    105 public:
    106  TestWebRtcVadDtx();
    107 
    108  void Perform();
    109 
    110 private:
    111  void RunTestCases(const SdpAudioFormat& codec_format);
    112  void Test(bool new_outfile, bool expect_dtx_enabled);
    113 
    114  int output_file_num_;
    115 };
    116 
    117 // TestOpusDtx is to verify that the Opus DTX performs as it should.
    118 class TestOpusDtx final : public TestVadDtx {
    119 public:
    120  void Perform();
    121 };
    122 
    123 }  // namespace webrtc
    124 
    125 #endif  // MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_