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