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 | |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
| 20 | #include "api/test/neteq_simulator.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_coding/neteq/include/neteq.h" |
| 22 | #include "modules/audio_coding/neteq/tools/audio_sink.h" |
| 23 | #include "modules/audio_coding/neteq/tools/neteq_input.h" |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | namespace test { |
| 27 | |
| 28 | class NetEqTestErrorCallback { |
| 29 | public: |
| 30 | virtual ~NetEqTestErrorCallback() = default; |
Henrik Lundin | c417d9e | 2017-06-14 12:29:03 +0200 | [diff] [blame] | 31 | virtual void OnInsertPacketError(const NetEqInput::PacketData& packet) {} |
| 32 | virtual void OnGetAudioError() {} |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | class DefaultNetEqTestErrorCallback : public NetEqTestErrorCallback { |
Henrik Lundin | c417d9e | 2017-06-14 12:29:03 +0200 | [diff] [blame] | 36 | void OnInsertPacketError(const NetEqInput::PacketData& packet) override; |
| 37 | void OnGetAudioError() override; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 40 | class NetEqPostInsertPacket { |
| 41 | public: |
| 42 | virtual ~NetEqPostInsertPacket() = default; |
| 43 | virtual void AfterInsertPacket(const NetEqInput::PacketData& packet, |
| 44 | NetEq* neteq) = 0; |
| 45 | }; |
| 46 | |
| 47 | class NetEqGetAudioCallback { |
| 48 | public: |
| 49 | virtual ~NetEqGetAudioCallback() = default; |
| 50 | virtual void BeforeGetAudio(NetEq* neteq) = 0; |
| 51 | virtual void AfterGetAudio(int64_t time_now_ms, |
| 52 | const AudioFrame& audio_frame, |
| 53 | bool muted, |
| 54 | NetEq* neteq) = 0; |
| 55 | }; |
| 56 | |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 57 | class NetEqSimulationEndedCallback { |
| 58 | public: |
| 59 | virtual ~NetEqSimulationEndedCallback() = default; |
| 60 | virtual void SimulationEnded(int64_t simulation_time_ms) = 0; |
| 61 | }; |
| 62 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 63 | // Class that provides an input--output test for NetEq. The input (both packets |
| 64 | // and output events) is provided by a NetEqInput object, while the output is |
| 65 | // directed to an AudioSink object. |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 66 | class NetEqTest : public NetEqSimulator { |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 67 | public: |
| 68 | using DecoderMap = std::map<int, std::pair<NetEqDecoder, std::string> >; |
| 69 | |
| 70 | struct ExternalDecoderInfo { |
| 71 | AudioDecoder* decoder; |
| 72 | NetEqDecoder codec; |
| 73 | std::string codec_name; |
| 74 | }; |
| 75 | |
| 76 | using ExtDecoderMap = std::map<int, ExternalDecoderInfo>; |
| 77 | |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 78 | struct Callbacks { |
| 79 | NetEqTestErrorCallback* error_callback = nullptr; |
| 80 | NetEqPostInsertPacket* post_insert_packet = nullptr; |
| 81 | NetEqGetAudioCallback* get_audio_callback = nullptr; |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 82 | NetEqSimulationEndedCallback* simulation_ended_callback = nullptr; |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 85 | // Sets up the test with given configuration, codec mappings, input, ouput, |
| 86 | // and callback objects for error reporting. |
| 87 | NetEqTest(const NetEq::Config& config, |
| 88 | const DecoderMap& codecs, |
| 89 | const ExtDecoderMap& ext_codecs, |
| 90 | std::unique_ptr<NetEqInput> input, |
| 91 | std::unique_ptr<AudioSink> output, |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 92 | Callbacks callbacks); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 93 | |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 94 | ~NetEqTest() override; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 95 | |
| 96 | // Runs the test. Returns the duration of the produced audio in ms. |
| 97 | int64_t Run(); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 98 | // Runs the simulation until we hit the next GetAudio event. If the simulation |
| 99 | // is finished, is_simulation_finished will be set to true in the returned |
| 100 | // SimulationStepResult. |
| 101 | SimulationStepResult RunToNextGetAudio() override; |
| 102 | |
| 103 | void SetNextAction(Action next_operation) override; |
| 104 | NetEqState GetNetEqState() override; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 105 | |
| 106 | // Returns the statistics from NetEq. |
| 107 | NetEqNetworkStatistics SimulationStats(); |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 108 | NetEqLifetimeStatistics LifetimeStats() const; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 109 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 110 | static DecoderMap StandardDecoderMap(); |
| 111 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 112 | private: |
| 113 | void RegisterDecoders(const DecoderMap& codecs); |
| 114 | void RegisterExternalDecoders(const ExtDecoderMap& codecs); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 115 | absl::optional<Action> next_action_; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 116 | std::unique_ptr<NetEq> neteq_; |
| 117 | std::unique_ptr<NetEqInput> input_; |
| 118 | std::unique_ptr<AudioSink> output_; |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 119 | Callbacks callbacks_; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 120 | int sample_rate_hz_; |
| 121 | }; |
| 122 | |
| 123 | } // namespace test |
| 124 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 125 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_ |