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