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 MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_PACKET_SOURCE_INPUT_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_PACKET_SOURCE_INPUT_H_
13 
14 #include <map>
15 #include <memory>
16 #include <string>
17 
18 #include "absl/types/optional.h"
19 #include "modules/audio_coding/neteq/tools/neteq_input.h"
20 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
21 
22 namespace webrtc {
23 namespace test {
24 
25 class RtpFileSource;
26 
27 // An adapter class to dress up a PacketSource object as a NetEqInput.
28 class NetEqPacketSourceInput : public NetEqInput {
29  public:
30   using RtpHeaderExtensionMap = std::map<int, webrtc::RTPExtensionType>;
31 
32   NetEqPacketSourceInput();
33   absl::optional<int64_t> NextPacketTime() const override;
34   std::unique_ptr<PacketData> PopPacket() override;
35   absl::optional<RTPHeader> NextHeader() const override;
ended()36   bool ended() const override { return !next_output_event_ms_; }
37 
38  protected:
39   virtual PacketSource* source() = 0;
40   void LoadNextPacket();
41 
42   absl::optional<int64_t> next_output_event_ms_;
43 
44  private:
45   std::unique_ptr<Packet> packet_;
46 };
47 
48 // Implementation of NetEqPacketSourceInput to be used with an RtpFileSource.
49 class NetEqRtpDumpInput final : public NetEqPacketSourceInput {
50  public:
51   NetEqRtpDumpInput(const std::string& file_name,
52                     const RtpHeaderExtensionMap& hdr_ext_map,
53                     absl::optional<uint32_t> ssrc_filter);
54 
55   absl::optional<int64_t> NextOutputEventTime() const override;
56   void AdvanceOutputEvent() override;
57 
58  protected:
59   PacketSource* source() override;
60 
61  private:
62   static constexpr int64_t kOutputPeriodMs = 10;
63 
64   std::unique_ptr<RtpFileSource> source_;
65 };
66 
67 }  // namespace test
68 }  // namespace webrtc
69 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_PACKET_SOURCE_INPUT_H_
70