henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_ |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <utility> |
| 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 19 | #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.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | namespace test { |
| 25 | |
| 26 | class NetEqTestErrorCallback { |
| 27 | public: |
| 28 | virtual ~NetEqTestErrorCallback() = default; |
Henrik Lundin | c417d9e | 2017-06-14 12:29:03 +0200 | [diff] [blame] | 29 | virtual void OnInsertPacketError(const NetEqInput::PacketData& packet) {} |
| 30 | virtual void OnGetAudioError() {} |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | class DefaultNetEqTestErrorCallback : public NetEqTestErrorCallback { |
Henrik Lundin | c417d9e | 2017-06-14 12:29:03 +0200 | [diff] [blame] | 34 | void OnInsertPacketError(const NetEqInput::PacketData& packet) override; |
| 35 | void OnGetAudioError() override; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 38 | class NetEqPostInsertPacket { |
| 39 | public: |
| 40 | virtual ~NetEqPostInsertPacket() = default; |
| 41 | virtual void AfterInsertPacket(const NetEqInput::PacketData& packet, |
| 42 | NetEq* neteq) = 0; |
| 43 | }; |
| 44 | |
| 45 | class 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.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 55 | // 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. |
| 58 | class 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.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 70 | struct Callbacks { |
| 71 | NetEqTestErrorCallback* error_callback = nullptr; |
| 72 | NetEqPostInsertPacket* post_insert_packet = nullptr; |
| 73 | NetEqGetAudioCallback* get_audio_callback = nullptr; |
| 74 | }; |
| 75 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 76 | // 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.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 83 | Callbacks callbacks); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 84 | |
| 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.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 100 | Callbacks callbacks_; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 101 | int sample_rate_hz_; |
| 102 | }; |
| 103 | |
| 104 | } // namespace test |
| 105 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 106 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_ |