blob: 68b2c1e23232856fd33cc51a0afeb2d21a267e5e [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
Karl Wiberg895ce822018-10-01 17:26:11 +020016#include "api/audio_codecs/audio_decoder_factory.h"
17#include "api/audio_codecs/audio_encoder_factory.h"
18#include "common_audio/vad/include/vad.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_coding/include/audio_coding_module.h"
21#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/audio_coding/test/Channel.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000024namespace webrtc {
25
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000026class ActivityMonitor : public ACMVADCallback {
27 public:
28 ActivityMonitor();
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +000029 int32_t InFrameType(FrameType 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);
Yves Gerey665174f2018-06-19 15:03:05 +020033
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000034 private:
pbos22993e12015-10-19 02:39:06 -070035 // 0 - kEmptyFrame
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +000036 // 1 - kAudioFrameSpeech
37 // 2 - kAudioFrameCN
38 // 3 - kVideoFrameKey (not used by audio)
39 // 4 - kVideoFrameDelta (not used by audio)
40 uint32_t counter_[5];
niklase@google.com470e71d2011-07-07 08:21:25 +000041};
42
minyue@webrtc.org05617162015-03-03 12:02:30 +000043// TestVadDtx is to verify that VAD/DTX perform as they should. It runs through
44// an audio file and check if the occurrence of various packet types follows
45// expectation. TestVadDtx needs its derived class to implement the Perform()
46// to put the test together.
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020047class TestVadDtx {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000048 public:
minyue@webrtc.org05617162015-03-03 12:02:30 +000049 static const int kOutputFreqHz = 16000;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
minyue@webrtc.org05617162015-03-03 12:02:30 +000051 TestVadDtx();
52
minyue@webrtc.org05617162015-03-03 12:02:30 +000053 protected:
Karl Wiberg895ce822018-10-01 17:26:11 +020054 // Returns true iff CN was added.
55 bool RegisterCodec(const SdpAudioFormat& codec_format,
56 absl::optional<Vad::Aggressiveness> vad_mode);
minyue@webrtc.org05617162015-03-03 12:02:30 +000057
58 // Encoding a file and see if the numbers that various packets occur follow
59 // the expectation. Saves result to a file.
60 // expects[x] means
61 // -1 : do not care,
62 // 0 : there have been no packets of type |x|,
63 // 1 : there have been packets of type |x|,
64 // with |x| indicates the following packet types
pbos22993e12015-10-19 02:39:06 -070065 // 0 - kEmptyFrame
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +000066 // 1 - kAudioFrameSpeech
67 // 2 - kAudioFrameCN
68 // 3 - kVideoFrameKey (not used by audio)
69 // 4 - kVideoFrameDelta (not used by audio)
Yves Gerey665174f2018-06-19 15:03:05 +020070 void Run(std::string in_filename,
71 int frequency,
72 int channels,
73 std::string out_filename,
74 bool append,
75 const int* expects);
minyue@webrtc.org05617162015-03-03 12:02:30 +000076
Karl Wiberg895ce822018-10-01 17:26:11 +020077 const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
78 const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
kwiberg37478382016-02-14 20:40:57 -080079 std::unique_ptr<AudioCodingModule> acm_send_;
80 std::unique_ptr<AudioCodingModule> acm_receive_;
81 std::unique_ptr<Channel> channel_;
82 std::unique_ptr<ActivityMonitor> monitor_;
ossu63fb95a2016-07-06 09:34:22 -070083 uint32_t time_stamp_ = 0x12345678;
minyue@webrtc.org05617162015-03-03 12:02:30 +000084};
85
86// TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should.
87class TestWebRtcVadDtx final : public TestVadDtx {
88 public:
89 TestWebRtcVadDtx();
90
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020091 void Perform();
minyue@webrtc.org05617162015-03-03 12:02:30 +000092
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000093 private:
Karl Wiberg895ce822018-10-01 17:26:11 +020094 void RunTestCases(const SdpAudioFormat& codec_format);
95 void Test(bool new_outfile, bool expect_dtx_enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
minyue@webrtc.org05617162015-03-03 12:02:30 +000097 int output_file_num_;
98};
niklase@google.com470e71d2011-07-07 08:21:25 +000099
minyue@webrtc.org05617162015-03-03 12:02:30 +0000100// TestOpusDtx is to verify that the Opus DTX performs as it should.
101class TestOpusDtx final : public TestVadDtx {
102 public:
Karl Wiberg3ff52ff2018-10-01 12:31:22 +0200103 void Perform();
niklase@google.com470e71d2011-07-07 08:21:25 +0000104};
105
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000106} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200108#endif // MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_