1 /* 2 * Copyright (c) 2012 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_TEST_RTPFILE_H_ 12 #define MODULES_AUDIO_CODING_TEST_RTPFILE_H_ 13 14 #include <stdio.h> 15 16 #include <queue> 17 18 #include "api/rtp_headers.h" 19 #include "rtc_base/synchronization/rw_lock_wrapper.h" 20 21 namespace webrtc { 22 23 class RTPStream { 24 public: ~RTPStream()25 virtual ~RTPStream() {} 26 27 virtual void Write(const uint8_t payloadType, 28 const uint32_t timeStamp, 29 const int16_t seqNo, 30 const uint8_t* payloadData, 31 const size_t payloadSize, 32 uint32_t frequency) = 0; 33 34 // Returns the packet's payload size. Zero should be treated as an 35 // end-of-stream (in the case that EndOfFile() is true) or an error. 36 virtual size_t Read(RTPHeader* rtp_Header, 37 uint8_t* payloadData, 38 size_t payloadSize, 39 uint32_t* offset) = 0; 40 virtual bool EndOfFile() const = 0; 41 42 protected: 43 void MakeRTPheader(uint8_t* rtpHeader, 44 uint8_t payloadType, 45 int16_t seqNo, 46 uint32_t timeStamp, 47 uint32_t ssrc); 48 49 void ParseRTPHeader(RTPHeader* rtp_header, const uint8_t* rtpHeader); 50 }; 51 52 class RTPPacket { 53 public: 54 RTPPacket(uint8_t payloadType, 55 uint32_t timeStamp, 56 int16_t seqNo, 57 const uint8_t* payloadData, 58 size_t payloadSize, 59 uint32_t frequency); 60 61 ~RTPPacket(); 62 63 uint8_t payloadType; 64 uint32_t timeStamp; 65 int16_t seqNo; 66 uint8_t* payloadData; 67 size_t payloadSize; 68 uint32_t frequency; 69 }; 70 71 class RTPBuffer : public RTPStream { 72 public: 73 RTPBuffer(); 74 75 ~RTPBuffer(); 76 77 void Write(const uint8_t payloadType, 78 const uint32_t timeStamp, 79 const int16_t seqNo, 80 const uint8_t* payloadData, 81 const size_t payloadSize, 82 uint32_t frequency) override; 83 84 size_t Read(RTPHeader* rtp_header, 85 uint8_t* payloadData, 86 size_t payloadSize, 87 uint32_t* offset) override; 88 89 bool EndOfFile() const override; 90 91 private: 92 RWLockWrapper* _queueRWLock; 93 std::queue<RTPPacket*> _rtpQueue; 94 }; 95 96 class RTPFile : public RTPStream { 97 public: ~RTPFile()98 ~RTPFile() {} 99 RTPFile()100 RTPFile() : _rtpFile(NULL), _rtpEOF(false) {} 101 102 void Open(const char* outFilename, const char* mode); 103 104 void Close(); 105 106 void WriteHeader(); 107 108 void ReadHeader(); 109 110 void Write(const uint8_t payloadType, 111 const uint32_t timeStamp, 112 const int16_t seqNo, 113 const uint8_t* payloadData, 114 const size_t payloadSize, 115 uint32_t frequency) override; 116 117 size_t Read(RTPHeader* rtp_header, 118 uint8_t* payloadData, 119 size_t payloadSize, 120 uint32_t* offset) override; 121 EndOfFile()122 bool EndOfFile() const override { return _rtpEOF; } 123 124 private: 125 FILE* _rtpFile; 126 bool _rtpEOF; 127 }; 128 129 } // namespace webrtc 130 131 #endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_ 132