blob: d0195dddc6c0f4935901cd1439e645afe72d6c8e [file] [log] [blame]
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_
12#define MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000013
Yves Gerey665174f2018-06-19 15:03:05 +020014#include <stddef.h> // for size_t
Jonas Olssona4d87372019-07-05 19:08:33 +020015
kwiberg16c5a962016-02-15 02:27:22 -080016#include <memory>
henrik.lundin4cf61dd2015-12-09 06:20:58 -080017#include <string>
18
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/audio_codecs/audio_decoder_factory.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010020#include "api/scoped_refptr.h"
Henrik Lundin84f75692023-02-01 12:07:10 +000021#include "modules/audio_coding/acm2/acm_receiver.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "system_wrappers/include/clock.h"
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000023
24namespace webrtc {
25class AudioCodingModule;
kwiberg4e14f092015-08-24 05:27:22 -070026class AudioDecoder;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000027
28namespace test {
29class AudioSink;
30class PacketSource;
31
32class AcmReceiveTestOldApi {
33 public:
Oleh Prypinfd7df982017-12-21 16:25:19 +010034 enum NumOutputChannels : size_t {
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000035 kArbitraryChannels = 0,
36 kMonoOutput = 1,
Alex Loiko65438812019-02-22 10:13:44 +010037 kStereoOutput = 2,
38 kQuadOutput = 4
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000039 };
40
41 AcmReceiveTestOldApi(PacketSource* packet_source,
42 AudioSink* audio_sink,
43 int output_freq_hz,
kwiberg5adaf732016-10-04 09:33:27 -070044 NumOutputChannels exptected_output_channels,
45 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory);
kwibergb8e56ee2016-08-29 06:37:33 -070046 virtual ~AcmReceiveTestOldApi();
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000047
Byoungchan Lee604fd2f2022-01-21 09:49:39 +090048 AcmReceiveTestOldApi(const AcmReceiveTestOldApi&) = delete;
49 AcmReceiveTestOldApi& operator=(const AcmReceiveTestOldApi&) = delete;
50
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000051 // Registers the codecs with default parameters from ACM.
52 void RegisterDefaultCodecs();
53
54 // Registers codecs with payload types matching the pre-encoded NetEq test
55 // files.
56 void RegisterNetEqTestCodecs();
57
58 // Runs the test and returns true if successful.
59 void Run();
60
henrik.lundin@webrtc.org81a78932014-10-14 10:49:58 +000061 protected:
62 // Method is called after each block of output audio is received from ACM.
63 virtual void AfterGetAudio() {}
64
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000065 SimulatedClock clock_;
Henrik Lundin84f75692023-02-01 12:07:10 +000066 std::unique_ptr<acm2::AcmReceiver> acm_receiver_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000067 PacketSource* packet_source_;
68 AudioSink* audio_sink_;
henrik.lundin@webrtc.org81a78932014-10-14 10:49:58 +000069 int output_freq_hz_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000070 NumOutputChannels exptected_output_channels_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000071};
72
Artem Titovd00ce742021-07-28 20:00:17 +020073// This test toggles the output frequency every `toggle_period_ms`. The test
74// starts with `output_freq_hz_1`. Except for the toggling, it does the same
henrik.lundin@webrtc.org81a78932014-10-14 10:49:58 +000075// thing as AcmReceiveTestOldApi.
76class AcmReceiveTestToggleOutputFreqOldApi : public AcmReceiveTestOldApi {
77 public:
78 AcmReceiveTestToggleOutputFreqOldApi(
79 PacketSource* packet_source,
80 AudioSink* audio_sink,
81 int output_freq_hz_1,
82 int output_freq_hz_2,
83 int toggle_period_ms,
84 NumOutputChannels exptected_output_channels);
85
86 protected:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000087 void AfterGetAudio() override;
henrik.lundin@webrtc.org81a78932014-10-14 10:49:58 +000088
89 const int output_freq_hz_1_;
90 const int output_freq_hz_2_;
91 const int toggle_period_ms_;
92 int64_t last_toggle_time_ms_;
93};
94
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000095} // namespace test
96} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020097#endif // MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_