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 WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_FILE_SOURCE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_FILE_SOURCE_H_
13
14#include <stdio.h>
15#include <string>
16
17#include "webrtc/base/constructormagic.h"
18#include "webrtc/base/scoped_ptr.h"
19#include "webrtc/common_types.h"
20#include "webrtc/modules/audio_coding/neteq/tools/packet_source.h"
21#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22
23namespace webrtc {
24
25class RtpHeaderParser;
26
27namespace test {
28
29class RtpFileReader;
30
31class 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(const std::string& file_name);
36
37  // Checks whether a files is a valid RTP dump or PCAP (Wireshark) file.
38  static bool ValidRtpDump(const std::string& file_name);
39  static bool ValidPcap(const std::string& file_name);
40
41  virtual ~RtpFileSource();
42
43  // Registers an RTP header extension and binds it to |id|.
44  virtual bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
45
46  // Returns a pointer to the next packet. Returns NULL if end of file was
47  // reached, or if a the data was corrupt.
48  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  RtpFileSource();
56
57  bool OpenFile(const std::string& file_name);
58
59  rtc::scoped_ptr<RtpFileReader> rtp_reader_;
60  rtc::scoped_ptr<RtpHeaderParser> parser_;
61
62  RTC_DISALLOW_COPY_AND_ASSIGN(RtpFileSource);
63};
64
65}  // namespace test
66}  // namespace webrtc
67#endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_FILE_SOURCE_H_
68