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