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_MAIN_TEST_RTPFILE_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_RTPFILE_H_ 13 14 #include <stdio.h> 15 #include <queue> 16 17 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" 18 #include "webrtc/modules/interface/module_common_types.h" 19 #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" 20 #include "webrtc/typedefs.h" 21 22 namespace webrtc { 23 24 class RTPStream { 25 public: 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 uint16_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 uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData, 36 uint16_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, uint16_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 uint16_t payloadSize; 59 uint32_t frequency; 60 }; 61 62 class RTPBuffer : public RTPStream { 63 public: 64 RTPBuffer(); 65 66 ~RTPBuffer(); 67 68 virtual void Write(const uint8_t payloadType, const uint32_t timeStamp, 69 const int16_t seqNo, const uint8_t* payloadData, 70 const uint16_t payloadSize, uint32_t frequency) OVERRIDE; 71 72 virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData, 73 uint16_t payloadSize, uint32_t* offset) OVERRIDE; 74 75 virtual bool EndOfFile() const OVERRIDE; 76 77 private: 78 RWLockWrapper* _queueRWLock; 79 std::queue<RTPPacket *> _rtpQueue; 80 }; 81 82 class RTPFile : public RTPStream { 83 public: 84 ~RTPFile() { 85 } 86 87 RTPFile() 88 : _rtpFile(NULL), 89 _rtpEOF(false) { 90 } 91 92 void Open(const char *outFilename, const char *mode); 93 94 void Close(); 95 96 void WriteHeader(); 97 98 void ReadHeader(); 99 100 virtual void Write(const uint8_t payloadType, const uint32_t timeStamp, 101 const int16_t seqNo, const uint8_t* payloadData, 102 const uint16_t payloadSize, uint32_t frequency) OVERRIDE; 103 104 virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData, 105 uint16_t payloadSize, uint32_t* offset) OVERRIDE; 106 107 virtual bool EndOfFile() const OVERRIDE { 108 return _rtpEOF; 109 } 110 111 private: 112 FILE* _rtpFile; 113 bool _rtpEOF; 114 }; 115 116 } // namespace webrtc 117 118 #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_RTPFILE_H_ 119