blob: 2c0a07caada3d6f996afaaf30883f84bc00da356 [file] [log] [blame]
henrik.lundine8a77e32016-06-22 06:34:03 -07001/*
2 * Copyright (c) 2016 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_NETEQ_TOOLS_NETEQ_TEST_H_
12#define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_
henrik.lundine8a77e32016-06-22 06:34:03 -070013
14#include <map>
15#include <memory>
16#include <string>
17#include <utility>
18
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_coding/neteq/include/neteq.h"
20#include "modules/audio_coding/neteq/tools/audio_sink.h"
21#include "modules/audio_coding/neteq/tools/neteq_input.h"
henrik.lundine8a77e32016-06-22 06:34:03 -070022
23namespace webrtc {
24namespace test {
25
26class NetEqTestErrorCallback {
27 public:
28 virtual ~NetEqTestErrorCallback() = default;
Henrik Lundinc417d9e2017-06-14 12:29:03 +020029 virtual void OnInsertPacketError(const NetEqInput::PacketData& packet) {}
30 virtual void OnGetAudioError() {}
henrik.lundine8a77e32016-06-22 06:34:03 -070031};
32
33class DefaultNetEqTestErrorCallback : public NetEqTestErrorCallback {
Henrik Lundinc417d9e2017-06-14 12:29:03 +020034 void OnInsertPacketError(const NetEqInput::PacketData& packet) override;
35 void OnGetAudioError() override;
henrik.lundine8a77e32016-06-22 06:34:03 -070036};
37
henrik.lundin02739d92017-05-04 06:09:06 -070038class NetEqPostInsertPacket {
39 public:
40 virtual ~NetEqPostInsertPacket() = default;
41 virtual void AfterInsertPacket(const NetEqInput::PacketData& packet,
42 NetEq* neteq) = 0;
43};
44
45class NetEqGetAudioCallback {
46 public:
47 virtual ~NetEqGetAudioCallback() = default;
48 virtual void BeforeGetAudio(NetEq* neteq) = 0;
49 virtual void AfterGetAudio(int64_t time_now_ms,
50 const AudioFrame& audio_frame,
51 bool muted,
52 NetEq* neteq) = 0;
53};
54
henrik.lundine8a77e32016-06-22 06:34:03 -070055// Class that provides an input--output test for NetEq. The input (both packets
56// and output events) is provided by a NetEqInput object, while the output is
57// directed to an AudioSink object.
58class NetEqTest {
59 public:
60 using DecoderMap = std::map<int, std::pair<NetEqDecoder, std::string> >;
61
62 struct ExternalDecoderInfo {
63 AudioDecoder* decoder;
64 NetEqDecoder codec;
65 std::string codec_name;
66 };
67
68 using ExtDecoderMap = std::map<int, ExternalDecoderInfo>;
69
henrik.lundin02739d92017-05-04 06:09:06 -070070 struct Callbacks {
71 NetEqTestErrorCallback* error_callback = nullptr;
72 NetEqPostInsertPacket* post_insert_packet = nullptr;
73 NetEqGetAudioCallback* get_audio_callback = nullptr;
74 };
75
henrik.lundine8a77e32016-06-22 06:34:03 -070076 // Sets up the test with given configuration, codec mappings, input, ouput,
77 // and callback objects for error reporting.
78 NetEqTest(const NetEq::Config& config,
79 const DecoderMap& codecs,
80 const ExtDecoderMap& ext_codecs,
81 std::unique_ptr<NetEqInput> input,
82 std::unique_ptr<AudioSink> output,
henrik.lundin02739d92017-05-04 06:09:06 -070083 Callbacks callbacks);
henrik.lundine8a77e32016-06-22 06:34:03 -070084
85 ~NetEqTest() = default;
86
87 // Runs the test. Returns the duration of the produced audio in ms.
88 int64_t Run();
89
90 // Returns the statistics from NetEq.
91 NetEqNetworkStatistics SimulationStats();
92
93 private:
94 void RegisterDecoders(const DecoderMap& codecs);
95 void RegisterExternalDecoders(const ExtDecoderMap& codecs);
96
97 std::unique_ptr<NetEq> neteq_;
98 std::unique_ptr<NetEqInput> input_;
99 std::unique_ptr<AudioSink> output_;
henrik.lundin02739d92017-05-04 06:09:06 -0700100 Callbacks callbacks_;
henrik.lundine8a77e32016-06-22 06:34:03 -0700101 int sample_rate_hz_;
102};
103
104} // namespace test
105} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200106#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_