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 | |
| 11 | #ifndef RTPFILE_H |
| 12 | #define RTPFILE_H |
| 13 | |
| 14 | #include "audio_coding_module.h" |
| 15 | #include "module_common_types.h" |
| 16 | #include "typedefs.h" |
| 17 | #include "rw_lock_wrapper.h" |
| 18 | #include <stdio.h> |
| 19 | #include <queue> |
| 20 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | class RTPStream |
| 24 | { |
| 25 | public: |
| 26 | virtual ~RTPStream(){} |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 27 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 28 | virtual void Write(const uint8_t payloadType, const uint32_t timeStamp, |
| 29 | const int16_t seqNo, const uint8_t* payloadData, |
| 30 | const uint16_t payloadSize, uint32_t frequency) = 0; |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 31 | |
| 32 | // Returns the packet's payload size. Zero should be treated as an |
| 33 | // end-of-stream (in the case that EndOfFile() is true) or an error. |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 34 | virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, |
| 35 | uint8_t* payloadData, |
| 36 | uint16_t payloadSize, |
| 37 | uint32_t* offset) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | virtual bool EndOfFile() const = 0; |
| 39 | |
| 40 | protected: |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 41 | void MakeRTPheader(uint8_t* rtpHeader, |
| 42 | uint8_t payloadType, int16_t seqNo, |
| 43 | uint32_t timeStamp, uint32_t ssrc); |
| 44 | void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | class RTPPacket |
| 48 | { |
| 49 | public: |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 50 | RTPPacket(uint8_t payloadType, uint32_t timeStamp, |
| 51 | int16_t seqNo, const uint8_t* payloadData, |
| 52 | uint16_t payloadSize, uint32_t frequency); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | ~RTPPacket(); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 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 | |
| 62 | class RTPBuffer : public RTPStream |
| 63 | { |
| 64 | public: |
| 65 | RTPBuffer(); |
| 66 | ~RTPBuffer(); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 67 | void Write(const uint8_t payloadType, const uint32_t timeStamp, |
| 68 | const int16_t seqNo, const uint8_t* payloadData, |
| 69 | const uint16_t payloadSize, uint32_t frequency); |
| 70 | uint16_t Read(WebRtcRTPHeader* rtpInfo, |
| 71 | uint8_t* payloadData, |
| 72 | uint16_t payloadSize, |
| 73 | uint32_t* offset); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | virtual bool EndOfFile() const; |
| 75 | private: |
| 76 | RWLockWrapper* _queueRWLock; |
| 77 | std::queue<RTPPacket *> _rtpQueue; |
| 78 | }; |
| 79 | |
| 80 | class RTPFile : public RTPStream |
| 81 | { |
| 82 | public: |
| 83 | ~RTPFile(){} |
| 84 | RTPFile() : _rtpFile(NULL),_rtpEOF(false) {} |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 85 | void Open(const char *outFilename, const char *mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | void Close(); |
| 87 | void WriteHeader(); |
| 88 | void ReadHeader(); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 89 | void Write(const uint8_t payloadType, const uint32_t timeStamp, |
| 90 | const int16_t seqNo, const uint8_t* payloadData, |
| 91 | const uint16_t payloadSize, uint32_t frequency); |
| 92 | uint16_t Read(WebRtcRTPHeader* rtpInfo, |
| 93 | uint8_t* payloadData, |
| 94 | uint16_t payloadSize, |
| 95 | uint32_t* offset); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | bool EndOfFile() const { return _rtpEOF; } |
| 97 | private: |
| 98 | FILE* _rtpFile; |
| 99 | bool _rtpEOF; |
| 100 | }; |
| 101 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 102 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | #endif |