niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_ |
| 12 | #define MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
kwiberg | 3747838 | 2016-02-14 20:40:57 -0800 | [diff] [blame] | 14 | #include <memory> |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 15 | |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 16 | #include "absl/strings/string_view.h" |
Karl Wiberg | 895ce82 | 2018-10-01 17:26:11 +0200 | [diff] [blame] | 17 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 18 | #include "api/audio_codecs/audio_encoder_factory.h" |
| 19 | #include "common_audio/vad/include/vad.h" |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 +0000 | [diff] [blame] | 20 | #include "modules/audio_coding/acm2/acm_receiver.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 22 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "modules/audio_coding/test/Channel.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 25 | namespace webrtc { |
| 26 | |
Niels Möller | 3bdc5e9 | 2020-03-10 09:28:33 +0100 | [diff] [blame] | 27 | // This class records the frame type, and delegates actual sending to the |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 28 | // `next_` AudioPacketizationCallback. |
Niels Möller | 3bdc5e9 | 2020-03-10 09:28:33 +0100 | [diff] [blame] | 29 | class MonitoringAudioPacketizationCallback : public AudioPacketizationCallback { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 30 | public: |
Niels Möller | 3bdc5e9 | 2020-03-10 09:28:33 +0100 | [diff] [blame] | 31 | explicit MonitoringAudioPacketizationCallback( |
| 32 | AudioPacketizationCallback* next); |
| 33 | |
| 34 | int32_t SendData(AudioFrameType frame_type, |
| 35 | uint8_t payload_type, |
| 36 | uint32_t timestamp, |
| 37 | const uint8_t* payload_data, |
| 38 | size_t payload_len_bytes, |
| 39 | int64_t absolute_capture_timestamp_ms) override; |
| 40 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 41 | void PrintStatistics(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 42 | void ResetStatistics(); |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 43 | void GetStatistics(uint32_t* stats); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 44 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 45 | private: |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 46 | // 0 - kEmptyFrame |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 47 | // 1 - kAudioFrameSpeech |
| 48 | // 2 - kAudioFrameCN |
Niels Möller | c936cb6 | 2019-03-19 14:10:16 +0100 | [diff] [blame] | 49 | uint32_t counter_[3]; |
Niels Möller | 3bdc5e9 | 2020-03-10 09:28:33 +0100 | [diff] [blame] | 50 | AudioPacketizationCallback* const next_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 53 | // TestVadDtx is to verify that VAD/DTX perform as they should. It runs through |
| 54 | // an audio file and check if the occurrence of various packet types follows |
| 55 | // expectation. TestVadDtx needs its derived class to implement the Perform() |
| 56 | // to put the test together. |
Karl Wiberg | 3ff52ff | 2018-10-01 12:31:22 +0200 | [diff] [blame] | 57 | class TestVadDtx { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 58 | public: |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 59 | static const int kOutputFreqHz = 16000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 61 | TestVadDtx(); |
| 62 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 63 | protected: |
Karl Wiberg | 895ce82 | 2018-10-01 17:26:11 +0200 | [diff] [blame] | 64 | // Returns true iff CN was added. |
| 65 | bool RegisterCodec(const SdpAudioFormat& codec_format, |
| 66 | absl::optional<Vad::Aggressiveness> vad_mode); |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 67 | |
| 68 | // Encoding a file and see if the numbers that various packets occur follow |
| 69 | // the expectation. Saves result to a file. |
| 70 | // expects[x] means |
| 71 | // -1 : do not care, |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 72 | // 0 : there have been no packets of type `x`, |
| 73 | // 1 : there have been packets of type `x`, |
| 74 | // with `x` indicates the following packet types |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 75 | // 0 - kEmptyFrame |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 76 | // 1 - kAudioFrameSpeech |
| 77 | // 2 - kAudioFrameCN |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 78 | void Run(absl::string_view in_filename, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 79 | int frequency, |
| 80 | int channels, |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 81 | absl::string_view out_filename, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 82 | bool append, |
| 83 | const int* expects); |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 84 | |
Karl Wiberg | 895ce82 | 2018-10-01 17:26:11 +0200 | [diff] [blame] | 85 | const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_; |
| 86 | const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
kwiberg | 3747838 | 2016-02-14 20:40:57 -0800 | [diff] [blame] | 87 | std::unique_ptr<AudioCodingModule> acm_send_; |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 +0000 | [diff] [blame] | 88 | std::unique_ptr<acm2::AcmReceiver> acm_receive_; |
kwiberg | 3747838 | 2016-02-14 20:40:57 -0800 | [diff] [blame] | 89 | std::unique_ptr<Channel> channel_; |
Niels Möller | 3bdc5e9 | 2020-03-10 09:28:33 +0100 | [diff] [blame] | 90 | std::unique_ptr<MonitoringAudioPacketizationCallback> packetization_callback_; |
ossu | 63fb95a | 2016-07-06 09:34:22 -0700 | [diff] [blame] | 91 | uint32_t time_stamp_ = 0x12345678; |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | // TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should. |
| 95 | class TestWebRtcVadDtx final : public TestVadDtx { |
| 96 | public: |
| 97 | TestWebRtcVadDtx(); |
| 98 | |
Karl Wiberg | 3ff52ff | 2018-10-01 12:31:22 +0200 | [diff] [blame] | 99 | void Perform(); |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 100 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 101 | private: |
Karl Wiberg | 895ce82 | 2018-10-01 17:26:11 +0200 | [diff] [blame] | 102 | void RunTestCases(const SdpAudioFormat& codec_format); |
| 103 | void Test(bool new_outfile, bool expect_dtx_enabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 105 | int output_file_num_; |
| 106 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 108 | // TestOpusDtx is to verify that the Opus DTX performs as it should. |
| 109 | class TestOpusDtx final : public TestVadDtx { |
| 110 | public: |
Karl Wiberg | 3ff52ff | 2018-10-01 12:31:22 +0200 | [diff] [blame] | 111 | void Perform(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 114 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 116 | #endif // MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_ |