xref: /aosp_15_r20/external/webrtc/modules/audio_coding/acm2/acm_receive_test.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2014 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_ACM2_ACM_RECEIVE_TEST_H_
12 #define MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_
13 
14 #include <stddef.h>  // for size_t
15 
16 #include <memory>
17 #include <string>
18 
19 #include "api/audio_codecs/audio_decoder_factory.h"
20 #include "api/scoped_refptr.h"
21 #include "system_wrappers/include/clock.h"
22 
23 namespace webrtc {
24 class AudioCodingModule;
25 class AudioDecoder;
26 
27 namespace test {
28 class AudioSink;
29 class PacketSource;
30 
31 class AcmReceiveTestOldApi {
32  public:
33   enum NumOutputChannels : size_t {
34     kArbitraryChannels = 0,
35     kMonoOutput = 1,
36     kStereoOutput = 2,
37     kQuadOutput = 4
38   };
39 
40   AcmReceiveTestOldApi(PacketSource* packet_source,
41                        AudioSink* audio_sink,
42                        int output_freq_hz,
43                        NumOutputChannels exptected_output_channels,
44                        rtc::scoped_refptr<AudioDecoderFactory> decoder_factory);
45   virtual ~AcmReceiveTestOldApi();
46 
47   AcmReceiveTestOldApi(const AcmReceiveTestOldApi&) = delete;
48   AcmReceiveTestOldApi& operator=(const AcmReceiveTestOldApi&) = delete;
49 
50   // Registers the codecs with default parameters from ACM.
51   void RegisterDefaultCodecs();
52 
53   // Registers codecs with payload types matching the pre-encoded NetEq test
54   // files.
55   void RegisterNetEqTestCodecs();
56 
57   // Runs the test and returns true if successful.
58   void Run();
59 
get_acm()60   AudioCodingModule* get_acm() { return acm_.get(); }
61 
62  protected:
63   // Method is called after each block of output audio is received from ACM.
AfterGetAudio()64   virtual void AfterGetAudio() {}
65 
66   SimulatedClock clock_;
67   std::unique_ptr<AudioCodingModule> acm_;
68   PacketSource* packet_source_;
69   AudioSink* audio_sink_;
70   int output_freq_hz_;
71   NumOutputChannels exptected_output_channels_;
72 };
73 
74 // This test toggles the output frequency every `toggle_period_ms`. The test
75 // starts with `output_freq_hz_1`. Except for the toggling, it does the same
76 // thing as AcmReceiveTestOldApi.
77 class AcmReceiveTestToggleOutputFreqOldApi : public AcmReceiveTestOldApi {
78  public:
79   AcmReceiveTestToggleOutputFreqOldApi(
80       PacketSource* packet_source,
81       AudioSink* audio_sink,
82       int output_freq_hz_1,
83       int output_freq_hz_2,
84       int toggle_period_ms,
85       NumOutputChannels exptected_output_channels);
86 
87  protected:
88   void AfterGetAudio() override;
89 
90   const int output_freq_hz_1_;
91   const int output_freq_hz_2_;
92   const int toggle_period_ms_;
93   int64_t last_toggle_time_ms_;
94 };
95 
96 }  // namespace test
97 }  // namespace webrtc
98 #endif  // MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_
99