blob: 993ba04c8f2380d5138d56a6d58d8f051d631874 [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_INPUT_H_
12#define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_INPUT_H_
henrik.lundine8a77e32016-06-22 06:34:03 -070013
14#include <algorithm>
15#include <memory>
henrik.lundin7a38fd22017-04-28 01:35:53 -070016#include <string>
henrik.lundine8a77e32016-06-22 06:34:03 -070017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/optional.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#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.lundine8a77e32016-06-22 06:34:03 -070023
24namespace webrtc {
25namespace test {
26
27// Interface class for input to the NetEqTest class.
28class NetEqInput {
29 public:
30 struct PacketData {
henrik.lundin7a38fd22017-04-28 01:35:53 -070031 std::string ToString() const;
32
henrik.lundin246ef3e2017-04-24 09:14:32 -070033 RTPHeader header;
henrik.lundine8a77e32016-06-22 06:34:03 -070034 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.lundin58466f62016-10-05 02:27:42 -070071 // 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.lundine8a77e32016-06-22 06:34:03 -070074 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 Bonadei92ea95e2017-09-15 06:47:31 +020083#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_INPUT_H_