OLD | NEW |
(Empty) | |
| 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 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_ |
| 13 |
| 14 #include <map> |
| 15 #include <memory> |
| 16 #include <string> |
| 17 #include <utility> |
| 18 |
| 19 #include "webrtc/modules/audio_coding/neteq/include/neteq.h" |
| 20 #include "webrtc/modules/audio_coding/neteq/tools/audio_sink.h" |
| 21 #include "webrtc/modules/audio_coding/neteq/tools/neteq_input.h" |
| 22 |
| 23 namespace webrtc { |
| 24 namespace test { |
| 25 |
| 26 class NetEqTestErrorCallback { |
| 27 public: |
| 28 virtual ~NetEqTestErrorCallback() = default; |
| 29 virtual void OnInsertPacketError(int error_code, |
| 30 const NetEqInput::PacketData& packet) {} |
| 31 virtual void OnGetAudioError(int error_code) {} |
| 32 }; |
| 33 |
| 34 class DefaultNetEqTestErrorCallback : public NetEqTestErrorCallback { |
| 35 void OnInsertPacketError(int error_code, |
| 36 const NetEqInput::PacketData& packet) override; |
| 37 void OnGetAudioError(int error_code) override; |
| 38 }; |
| 39 |
| 40 // Class that provides an input--output test for NetEq. The input (both packets |
| 41 // and output events) is provided by a NetEqInput object, while the output is |
| 42 // directed to an AudioSink object. |
| 43 class NetEqTest { |
| 44 public: |
| 45 using DecoderMap = std::map<int, std::pair<NetEqDecoder, std::string> >; |
| 46 |
| 47 struct ExternalDecoderInfo { |
| 48 AudioDecoder* decoder; |
| 49 NetEqDecoder codec; |
| 50 std::string codec_name; |
| 51 }; |
| 52 |
| 53 using ExtDecoderMap = std::map<int, ExternalDecoderInfo>; |
| 54 |
| 55 // Sets up the test with given configuration, codec mappings, input, ouput, |
| 56 // and callback objects for error reporting. |
| 57 NetEqTest(const NetEq::Config& config, |
| 58 const DecoderMap& codecs, |
| 59 const ExtDecoderMap& ext_codecs, |
| 60 std::unique_ptr<NetEqInput> input, |
| 61 std::unique_ptr<AudioSink> output, |
| 62 NetEqTestErrorCallback* error_callback); |
| 63 |
| 64 ~NetEqTest() = default; |
| 65 |
| 66 // Runs the test. Returns the duration of the produced audio in ms. |
| 67 int64_t Run(); |
| 68 |
| 69 // Returns the statistics from NetEq. |
| 70 NetEqNetworkStatistics SimulationStats(); |
| 71 |
| 72 private: |
| 73 void RegisterDecoders(const DecoderMap& codecs); |
| 74 void RegisterExternalDecoders(const ExtDecoderMap& codecs); |
| 75 |
| 76 std::unique_ptr<NetEq> neteq_; |
| 77 std::unique_ptr<NetEqInput> input_; |
| 78 std::unique_ptr<AudioSink> output_; |
| 79 NetEqTestErrorCallback* error_callback_ = nullptr; |
| 80 int sample_rate_hz_; |
| 81 }; |
| 82 |
| 83 } // namespace test |
| 84 } // namespace webrtc |
| 85 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_H_ |
OLD | NEW |