1 /*
2  *  Copyright (c) 2014 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_RTP_FILE_SOURCE_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_FILE_SOURCE_H_
13 
14 #include <stdio.h>
15 
16 #include <memory>
17 #include <string>
18 
19 #include "absl/types/optional.h"
20 #include "modules/audio_coding/neteq/tools/packet_source.h"
21 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22 #include "modules/rtp_rtcp/source/rtp_utility.h"
23 #include "rtc_base/constructor_magic.h"
24 
25 namespace webrtc {
26 
27 namespace test {
28 
29 class RtpFileReader;
30 
31 class RtpFileSource : public PacketSource {
32  public:
33   // Creates an RtpFileSource reading from |file_name|. If the file cannot be
34   // opened, or has the wrong format, NULL will be returned.
35   static RtpFileSource* Create(
36       const std::string& file_name,
37       absl::optional<uint32_t> ssrc_filter = absl::nullopt);
38 
39   // Checks whether a files is a valid RTP dump or PCAP (Wireshark) file.
40   static bool ValidRtpDump(const std::string& file_name);
41   static bool ValidPcap(const std::string& file_name);
42 
43   ~RtpFileSource() override;
44 
45   // Registers an RTP header extension and binds it to |id|.
46   virtual bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
47 
48   std::unique_ptr<Packet> NextPacket() override;
49 
50  private:
51   static const int kFirstLineLength = 40;
52   static const int kRtpFileHeaderSize = 4 + 4 + 4 + 2 + 2;
53   static const size_t kPacketHeaderSize = 8;
54 
55   explicit RtpFileSource(absl::optional<uint32_t> ssrc_filter);
56 
57   bool OpenFile(const std::string& file_name);
58 
59   std::unique_ptr<RtpFileReader> rtp_reader_;
60   const absl::optional<uint32_t> ssrc_filter_;
61   RtpHeaderExtensionMap rtp_header_extension_map_;
62 
63   RTC_DISALLOW_COPY_AND_ASSIGN(RtpFileSource);
64 };
65 
66 }  // namespace test
67 }  // namespace webrtc
68 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_FILE_SOURCE_H_
69