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_INPUT_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_INPUT_H_ |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 13 | |
| 14 | #include <algorithm> |
| 15 | #include <memory> |
henrik.lundin | 7a38fd2 | 2017-04-28 01:35:53 -0700 | [diff] [blame] | 16 | #include <string> |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/optional.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 19 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_coding/neteq/tools/packet.h" |
| 21 | #include "modules/audio_coding/neteq/tools/packet_source.h" |
| 22 | #include "rtc_base/buffer.h" |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | namespace test { |
| 26 | |
| 27 | // Interface class for input to the NetEqTest class. |
| 28 | class NetEqInput { |
| 29 | public: |
| 30 | struct PacketData { |
henrik.lundin | 7a38fd2 | 2017-04-28 01:35:53 -0700 | [diff] [blame] | 31 | std::string ToString() const; |
| 32 | |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 33 | RTPHeader header; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 34 | rtc::Buffer payload; |
| 35 | double time_ms; |
| 36 | }; |
| 37 | |
| 38 | virtual ~NetEqInput() = default; |
| 39 | |
| 40 | // Returns at what time (in ms) NetEq::InsertPacket should be called next, or |
| 41 | // empty if the source is out of packets. |
| 42 | virtual rtc::Optional<int64_t> NextPacketTime() const = 0; |
| 43 | |
| 44 | // Returns at what time (in ms) NetEq::GetAudio should be called next, or |
| 45 | // empty if no more output events are available. |
| 46 | virtual rtc::Optional<int64_t> NextOutputEventTime() const = 0; |
| 47 | |
| 48 | // Returns the time (in ms) for the next event from either NextPacketTime() |
| 49 | // or NextOutputEventTime(), or empty if both are out of events. |
| 50 | rtc::Optional<int64_t> NextEventTime() const { |
| 51 | const auto a = NextPacketTime(); |
| 52 | const auto b = NextOutputEventTime(); |
| 53 | // Return the minimum of non-empty |a| and |b|, or empty if both are empty. |
| 54 | if (a) { |
| 55 | return b ? rtc::Optional<int64_t>(std::min(*a, *b)) : a; |
| 56 | } |
| 57 | return b ? b : rtc::Optional<int64_t>(); |
| 58 | } |
| 59 | |
| 60 | // Returns the next packet to be inserted into NetEq. The packet following the |
| 61 | // returned one is pre-fetched in the NetEqInput object, such that future |
| 62 | // calls to NextPacketTime() or NextHeader() will return information from that |
| 63 | // packet. |
| 64 | virtual std::unique_ptr<PacketData> PopPacket() = 0; |
| 65 | |
| 66 | // Move to the next output event. This will make NextOutputEventTime() return |
| 67 | // a new value (potentially the same if several output events share the same |
| 68 | // time). |
| 69 | virtual void AdvanceOutputEvent() = 0; |
| 70 | |
henrik.lundin | 58466f6 | 2016-10-05 02:27:42 -0700 | [diff] [blame] | 71 | // Returns true if the source has come to an end. An implementation must |
| 72 | // eventually return true from this method, or the test will end up in an |
| 73 | // infinite loop. |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 74 | virtual bool ended() const = 0; |
| 75 | |
| 76 | // Returns the RTP header for the next packet, i.e., the packet that will be |
| 77 | // delivered next by PopPacket(). |
| 78 | virtual rtc::Optional<RTPHeader> NextHeader() const = 0; |
| 79 | }; |
| 80 | |
| 81 | } // namespace test |
| 82 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 83 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_INPUT_H_ |