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 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 16 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 18 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 19 | #include "modules/audio_coding/test/ACMTest.h" |
| 20 | #include "modules/audio_coding/test/Channel.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 24 | class ActivityMonitor : public ACMVADCallback { |
| 25 | public: |
| 26 | ActivityMonitor(); |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 27 | int32_t InFrameType(FrameType frame_type); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 28 | void PrintStatistics(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 29 | void ResetStatistics(); |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 30 | void GetStatistics(uint32_t* stats); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 31 | private: |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 32 | // 0 - kEmptyFrame |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 33 | // 1 - kAudioFrameSpeech |
| 34 | // 2 - kAudioFrameCN |
| 35 | // 3 - kVideoFrameKey (not used by audio) |
| 36 | // 4 - kVideoFrameDelta (not used by audio) |
| 37 | uint32_t counter_[5]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 40 | |
| 41 | // TestVadDtx is to verify that VAD/DTX perform as they should. It runs through |
| 42 | // an audio file and check if the occurrence of various packet types follows |
| 43 | // expectation. TestVadDtx needs its derived class to implement the Perform() |
| 44 | // to put the test together. |
| 45 | class TestVadDtx : public ACMTest { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 46 | public: |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 47 | static const int kOutputFreqHz = 16000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 49 | TestVadDtx(); |
| 50 | |
| 51 | virtual void Perform() = 0; |
| 52 | |
| 53 | protected: |
| 54 | void RegisterCodec(CodecInst codec_param); |
| 55 | |
| 56 | // Encoding a file and see if the numbers that various packets occur follow |
| 57 | // the expectation. Saves result to a file. |
| 58 | // expects[x] means |
| 59 | // -1 : do not care, |
| 60 | // 0 : there have been no packets of type |x|, |
| 61 | // 1 : there have been packets of type |x|, |
| 62 | // with |x| indicates the following packet types |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 63 | // 0 - kEmptyFrame |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 64 | // 1 - kAudioFrameSpeech |
| 65 | // 2 - kAudioFrameCN |
| 66 | // 3 - kVideoFrameKey (not used by audio) |
| 67 | // 4 - kVideoFrameDelta (not used by audio) |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 68 | void Run(std::string in_filename, int frequency, int channels, |
| 69 | std::string out_filename, bool append, const int* expects); |
| 70 | |
kwiberg | 3747838 | 2016-02-14 20:40:57 -0800 | [diff] [blame] | 71 | std::unique_ptr<AudioCodingModule> acm_send_; |
| 72 | std::unique_ptr<AudioCodingModule> acm_receive_; |
| 73 | std::unique_ptr<Channel> channel_; |
| 74 | std::unique_ptr<ActivityMonitor> monitor_; |
ossu | 63fb95a | 2016-07-06 09:34:22 -0700 | [diff] [blame] | 75 | uint32_t time_stamp_ = 0x12345678; |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | // TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should. |
| 79 | class TestWebRtcVadDtx final : public TestVadDtx { |
| 80 | public: |
| 81 | TestWebRtcVadDtx(); |
| 82 | |
| 83 | void Perform() override; |
| 84 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 85 | private: |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 86 | void RunTestCases(); |
| 87 | void Test(bool new_outfile); |
| 88 | void SetVAD(bool enable_dtx, bool enable_vad, ACMVADMode vad_mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 90 | bool vad_enabled_; |
| 91 | bool dtx_enabled_; |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 92 | int output_file_num_; |
| 93 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 95 | // TestOpusDtx is to verify that the Opus DTX performs as it should. |
| 96 | class TestOpusDtx final : public TestVadDtx { |
| 97 | public: |
| 98 | void Perform() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 101 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 103 | #endif // MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_ |