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/common_types.h" 19 #include "webrtc/modules/audio_coding/neteq/tools/packet_source.h" 20 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" 21 #include "webrtc/system_wrappers/interface/scoped_ptr.h" 22 23 namespace webrtc { 24 25 class RtpHeaderParser; 26 27 namespace test { 28 29 class RtpFileSource : public PacketSource { 30 public: 31 // Creates an RtpFileSource reading from |file_name|. If the file cannot be 32 // opened, or has the wrong format, NULL will be returned. 33 static RtpFileSource* Create(const std::string& file_name); 34 35 virtual ~RtpFileSource(); 36 37 // Registers an RTP header extension and binds it to |id|. 38 virtual bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); 39 40 // Returns a pointer to the next packet. Returns NULL if end of file was 41 // reached, or if a the data was corrupt. 42 virtual Packet* NextPacket(); 43 44 // Returns true if the end of file has been reached. 45 virtual bool EndOfFile() const; 46 47 private: 48 static const int kFirstLineLength = 40; 49 static const int kRtpFileHeaderSize = 4 + 4 + 4 + 2 + 2; 50 static const size_t kPacketHeaderSize = 8; 51 52 RtpFileSource(); 53 54 bool OpenFile(const std::string& file_name); 55 56 bool SkipFileHeader(); 57 58 FILE* in_file_; 59 int64_t file_end_; 60 scoped_ptr<RtpHeaderParser> parser_; 61 62 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