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 "rtc_base/constructor_magic.h"
22 #include "system_wrappers/include/clock.h"
23 
24 namespace webrtc {
25 class AudioCodingModule;
26 class AudioDecoder;
27 
28 namespace test {
29 class AudioSink;
30 class PacketSource;
31 
32 class AcmReceiveTestOldApi {
33  public:
34   enum NumOutputChannels : size_t {
35     kArbitraryChannels = 0,
36     kMonoOutput = 1,
37     kStereoOutput = 2,
38     kQuadOutput = 4
39   };
40 
41   AcmReceiveTestOldApi(PacketSource* packet_source,
42                        AudioSink* audio_sink,
43                        int output_freq_hz,
44                        NumOutputChannels exptected_output_channels,
45                        rtc::scoped_refptr<AudioDecoderFactory> decoder_factory);
46   virtual ~AcmReceiveTestOldApi();
47 
48   // Registers the codecs with default parameters from ACM.
49   void RegisterDefaultCodecs();
50 
51   // Registers codecs with payload types matching the pre-encoded NetEq test
52   // files.
53   void RegisterNetEqTestCodecs();
54 
55   // Runs the test and returns true if successful.
56   void Run();
57 
get_acm()58   AudioCodingModule* get_acm() { return acm_.get(); }
59 
60  protected:
61   // Method is called after each block of output audio is received from ACM.
AfterGetAudio()62   virtual void AfterGetAudio() {}
63 
64   SimulatedClock clock_;
65   std::unique_ptr<AudioCodingModule> acm_;
66   PacketSource* packet_source_;
67   AudioSink* audio_sink_;
68   int output_freq_hz_;
69   NumOutputChannels exptected_output_channels_;
70 
71   RTC_DISALLOW_COPY_AND_ASSIGN(AcmReceiveTestOldApi);
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