xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/test/neteq_decoding_test.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_NETEQ_TEST_NETEQ_DECODING_TEST_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TEST_NETEQ_DECODING_TEST_H_
13 
14 #include <memory>
15 #include <set>
16 #include <string>
17 
18 #include "absl/strings/string_view.h"
19 #include "api/audio/audio_frame.h"
20 #include "api/neteq/neteq.h"
21 #include "api/rtp_headers.h"
22 #include "modules/audio_coding/neteq/tools/packet.h"
23 #include "modules/audio_coding/neteq/tools/rtp_file_source.h"
24 #include "system_wrappers/include/clock.h"
25 #include "test/gtest.h"
26 
27 namespace webrtc {
28 
29 class NetEqDecodingTest : public ::testing::Test {
30  protected:
31   // NetEQ must be polled for data once every 10 ms.
32   // Thus, none of the constants below can be changed.
33   static constexpr int kTimeStepMs = 10;
34   static constexpr size_t kBlockSize8kHz = kTimeStepMs * 8;
35   static constexpr size_t kBlockSize16kHz = kTimeStepMs * 16;
36   static constexpr size_t kBlockSize32kHz = kTimeStepMs * 32;
37   static constexpr size_t kBlockSize48kHz = kTimeStepMs * 48;
38   static constexpr int kInitSampleRateHz = 8000;
39 
40   NetEqDecodingTest();
41   virtual void SetUp();
42   virtual void TearDown();
43   void OpenInputFile(absl::string_view rtp_file);
44   void Process();
45 
46   void DecodeAndCompare(absl::string_view rtp_file,
47                         absl::string_view output_checksum,
48                         absl::string_view network_stats_checksum,
49                         bool gen_ref);
50 
51   static void PopulateRtpInfo(int frame_index,
52                               int timestamp,
53                               RTPHeader* rtp_info);
54   static void PopulateCng(int frame_index,
55                           int timestamp,
56                           RTPHeader* rtp_info,
57                           uint8_t* payload,
58                           size_t* payload_len);
59 
60   void WrapTest(uint16_t start_seq_no,
61                 uint32_t start_timestamp,
62                 const std::set<uint16_t>& drop_seq_numbers,
63                 bool expect_seq_no_wrap,
64                 bool expect_timestamp_wrap);
65 
66   void LongCngWithClockDrift(double drift_factor,
67                              double network_freeze_ms,
68                              bool pull_audio_during_freeze,
69                              int delay_tolerance_ms,
70                              int max_time_to_speech_ms);
71 
72   SimulatedClock clock_;
73   std::unique_ptr<NetEq> neteq_;
74   NetEq::Config config_;
75   std::unique_ptr<test::RtpFileSource> rtp_source_;
76   std::unique_ptr<test::Packet> packet_;
77   AudioFrame out_frame_;
78   int output_sample_rate_;
79   int algorithmic_delay_ms_;
80 };
81 
82 class NetEqDecodingTestTwoInstances : public NetEqDecodingTest {
83  public:
NetEqDecodingTestTwoInstances()84   NetEqDecodingTestTwoInstances() : NetEqDecodingTest() {}
85 
86   void SetUp() override;
87 
88   void CreateSecondInstance();
89 
90  protected:
91   std::unique_ptr<NetEq> neteq2_;
92   NetEq::Config config2_;
93 };
94 
95 }  // namespace webrtc
96 #endif  // MODULES_AUDIO_CODING_NETEQ_TEST_NETEQ_DECODING_TEST_H_
97