niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame^] | 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_RTPFILE_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_RTPFILE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <queue> |
| 16 | |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame^] | 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 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 24 | class RTPStream { |
| 25 | public: |
| 26 | virtual ~RTPStream() { |
| 27 | } |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 28 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 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; |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 32 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 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; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 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); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 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; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 62 | class RTPBuffer : public RTPStream { |
| 63 | public: |
| 64 | RTPBuffer(); |
| 65 | |
| 66 | ~RTPBuffer(); |
| 67 | |
| 68 | 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); |
| 71 | |
| 72 | uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData, |
| 73 | uint16_t payloadSize, uint32_t* offset); |
| 74 | |
| 75 | virtual bool EndOfFile() const; |
| 76 | |
| 77 | private: |
| 78 | RWLockWrapper* _queueRWLock; |
| 79 | std::queue<RTPPacket *> _rtpQueue; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 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 | 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); |
| 103 | |
| 104 | uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData, |
| 105 | uint16_t payloadSize, uint32_t* offset); |
| 106 | |
| 107 | bool EndOfFile() const { |
| 108 | return _rtpEOF; |
| 109 | } |
| 110 | |
| 111 | private: |
| 112 | FILE* _rtpFile; |
| 113 | bool _rtpEOF; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 116 | } // namespace webrtc |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame^] | 117 | |
| 118 | #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_RTPFILE_H_ |