blob: e3840f795a6d14b50a536252edbd53c2f799d65b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_
12#define MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kwiberg37478382016-02-14 20:40:57 -080014#include <memory>
minyue@webrtc.org05617162015-03-03 12:02:30 +000015
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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.com470e71d2011-07-07 08:21:25 +000021
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000022namespace webrtc {
23
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000024class ActivityMonitor : public ACMVADCallback {
25 public:
26 ActivityMonitor();
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +000027 int32_t InFrameType(FrameType frame_type);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000028 void PrintStatistics();
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000029 void ResetStatistics();
minyue@webrtc.org05617162015-03-03 12:02:30 +000030 void GetStatistics(uint32_t* stats);
Yves Gerey665174f2018-06-19 15:03:05 +020031
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000032 private:
pbos22993e12015-10-19 02:39:06 -070033 // 0 - kEmptyFrame
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +000034 // 1 - kAudioFrameSpeech
35 // 2 - kAudioFrameCN
36 // 3 - kVideoFrameKey (not used by audio)
37 // 4 - kVideoFrameDelta (not used by audio)
38 uint32_t counter_[5];
niklase@google.com470e71d2011-07-07 08:21:25 +000039};
40
minyue@webrtc.org05617162015-03-03 12:02:30 +000041// 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.
45class TestVadDtx : public ACMTest {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000046 public:
minyue@webrtc.org05617162015-03-03 12:02:30 +000047 static const int kOutputFreqHz = 16000;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
minyue@webrtc.org05617162015-03-03 12:02:30 +000049 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
pbos22993e12015-10-19 02:39:06 -070063 // 0 - kEmptyFrame
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +000064 // 1 - kAudioFrameSpeech
65 // 2 - kAudioFrameCN
66 // 3 - kVideoFrameKey (not used by audio)
67 // 4 - kVideoFrameDelta (not used by audio)
Yves Gerey665174f2018-06-19 15:03:05 +020068 void Run(std::string in_filename,
69 int frequency,
70 int channels,
71 std::string out_filename,
72 bool append,
73 const int* expects);
minyue@webrtc.org05617162015-03-03 12:02:30 +000074
kwiberg37478382016-02-14 20:40:57 -080075 std::unique_ptr<AudioCodingModule> acm_send_;
76 std::unique_ptr<AudioCodingModule> acm_receive_;
77 std::unique_ptr<Channel> channel_;
78 std::unique_ptr<ActivityMonitor> monitor_;
ossu63fb95a2016-07-06 09:34:22 -070079 uint32_t time_stamp_ = 0x12345678;
minyue@webrtc.org05617162015-03-03 12:02:30 +000080};
81
82// TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should.
83class TestWebRtcVadDtx final : public TestVadDtx {
84 public:
85 TestWebRtcVadDtx();
86
87 void Perform() override;
88
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000089 private:
minyue@webrtc.org05617162015-03-03 12:02:30 +000090 void RunTestCases();
91 void Test(bool new_outfile);
92 void SetVAD(bool enable_dtx, bool enable_vad, ACMVADMode vad_mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000093
minyue@webrtc.org05617162015-03-03 12:02:30 +000094 bool vad_enabled_;
95 bool dtx_enabled_;
minyue@webrtc.org05617162015-03-03 12:02:30 +000096 int output_file_num_;
97};
niklase@google.com470e71d2011-07-07 08:21:25 +000098
minyue@webrtc.org05617162015-03-03 12:02:30 +000099// TestOpusDtx is to verify that the Opus DTX performs as it should.
100class TestOpusDtx final : public TestVadDtx {
101 public:
102 void Perform() override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103};
104
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000105} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200107#endif // MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_