blob: 773d3795e24de95f75d7b1eeef7c124a1d612d37 [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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TESTVADDTX_H_
12#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TESTVADDTX_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
minyue@webrtc.org05617162015-03-03 12:02:30 +000014
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000015#include "webrtc/base/scoped_ptr.h"
minyue@webrtc.org05617162015-03-03 12:02:30 +000016#include "webrtc/common_types.h"
17#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
18#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000019#include "webrtc/modules/audio_coding/main/test/ACMTest.h"
20#include "webrtc/modules/audio_coding/main/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:
minyue@webrtc.org05617162015-03-03 12:02:30 +000026 static const int kPacketTypes = 6;
27
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000028 ActivityMonitor();
minyue@webrtc.org05617162015-03-03 12:02:30 +000029 int32_t InFrameType(int16_t frame_type);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000030 void PrintStatistics();
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000031 void ResetStatistics();
minyue@webrtc.org05617162015-03-03 12:02:30 +000032 void GetStatistics(uint32_t* stats);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000033 private:
34 // Counting according to
minyue@webrtc.org05617162015-03-03 12:02:30 +000035 // counter_[0] - kNoEncoding,
36 // counter_[1] - kActiveNormalEncoded,
37 // counter_[2] - kPassiveNormalEncoded,
38 // counter_[3] - kPassiveDTXNB,
39 // counter_[4] - kPassiveDTXWB,
40 // counter_[5] - kPassiveDTXSWB
41 uint32_t counter_[kPacketTypes];
niklase@google.com470e71d2011-07-07 08:21:25 +000042};
43
minyue@webrtc.org05617162015-03-03 12:02:30 +000044
45// TestVadDtx is to verify that VAD/DTX perform as they should. It runs through
46// an audio file and check if the occurrence of various packet types follows
47// expectation. TestVadDtx needs its derived class to implement the Perform()
48// to put the test together.
49class TestVadDtx : public ACMTest {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050 public:
minyue@webrtc.org05617162015-03-03 12:02:30 +000051 static const int kOutputFreqHz = 16000;
52 static const int kPacketTypes = 6;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
minyue@webrtc.org05617162015-03-03 12:02:30 +000054 TestVadDtx();
55
56 virtual void Perform() = 0;
57
58 protected:
59 void RegisterCodec(CodecInst codec_param);
60
61 // Encoding a file and see if the numbers that various packets occur follow
62 // the expectation. Saves result to a file.
63 // expects[x] means
64 // -1 : do not care,
65 // 0 : there have been no packets of type |x|,
66 // 1 : there have been packets of type |x|,
67 // with |x| indicates the following packet types
68 // 0 - kNoEncoding
69 // 1 - kActiveNormalEncoded
70 // 2 - kPassiveNormalEncoded
71 // 3 - kPassiveDTXNB
72 // 4 - kPassiveDTXWB
73 // 5 - kPassiveDTXSWB
74 void Run(std::string in_filename, int frequency, int channels,
75 std::string out_filename, bool append, const int* expects);
76
77 rtc::scoped_ptr<AudioCodingModule> acm_send_;
78 rtc::scoped_ptr<AudioCodingModule> acm_receive_;
79 rtc::scoped_ptr<Channel> channel_;
80 rtc::scoped_ptr<ActivityMonitor> monitor_;
81};
82
83// TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should.
84class TestWebRtcVadDtx final : public TestVadDtx {
85 public:
86 TestWebRtcVadDtx();
87
88 void Perform() override;
89
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000090 private:
minyue@webrtc.org05617162015-03-03 12:02:30 +000091 void RunTestCases();
92 void Test(bool new_outfile);
93 void SetVAD(bool enable_dtx, bool enable_vad, ACMVADMode vad_mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000094
minyue@webrtc.org05617162015-03-03 12:02:30 +000095 bool vad_enabled_;
96 bool dtx_enabled_;
97 bool use_webrtc_dtx_;
98 int output_file_num_;
99};
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
minyue@webrtc.org05617162015-03-03 12:02:30 +0000101// TestOpusDtx is to verify that the Opus DTX performs as it should.
102class TestOpusDtx final : public TestVadDtx {
103 public:
104 void Perform() override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105};
106
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000107} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000109#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TESTVADDTX_H_