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