henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 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 NETEQTEST_RTPPACKET_H |
| 12 | #define NETEQTEST_RTPPACKET_H |
| 13 | |
| 14 | #include <map> |
| 15 | #include <stdio.h> |
| 16 | #include "webrtc/typedefs.h" |
| 17 | #include "webrtc/modules/interface/module_common_types.h" |
| 18 | |
| 19 | enum stereoModes { |
| 20 | stereoModeMono, |
| 21 | stereoModeSample1, |
| 22 | stereoModeSample2, |
| 23 | stereoModeFrame, |
| 24 | stereoModeDuplicate |
| 25 | }; |
| 26 | |
| 27 | class NETEQTEST_RTPpacket |
| 28 | { |
| 29 | public: |
| 30 | NETEQTEST_RTPpacket(); |
| 31 | bool operator !() const { return (dataLen() < 0); }; |
| 32 | virtual ~NETEQTEST_RTPpacket(); |
| 33 | void reset(); |
| 34 | static int skipFileHeader(FILE *fp); |
| 35 | virtual int readFromFile(FILE *fp); |
| 36 | int readFixedFromFile(FILE *fp, size_t len); |
| 37 | virtual int writeToFile(FILE *fp); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 38 | void blockPT(uint8_t pt); |
| 39 | //int16_t payloadType(); |
henrik.lundin@webrtc.org | e6ab21b | 2014-02-05 08:46:46 | [diff] [blame^] | 40 | virtual void parseHeader(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 41 | void parseHeader(webrtc::WebRtcRTPHeader* rtp_header); |
| 42 | const webrtc::WebRtcRTPHeader* RTPinfo() const; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 43 | uint8_t * datagram() const; |
| 44 | uint8_t * payload() const; |
| 45 | int16_t payloadLen(); |
| 46 | int16_t dataLen() const; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 47 | bool isParsed() const; |
| 48 | bool isLost() const; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 49 | uint32_t time() const { return _receiveTime; }; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 50 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 51 | uint8_t payloadType() const; |
| 52 | uint16_t sequenceNumber() const; |
| 53 | uint32_t timeStamp() const; |
| 54 | uint32_t SSRC() const; |
| 55 | uint8_t markerBit() const; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 56 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 57 | int setPayloadType(uint8_t pt); |
| 58 | int setSequenceNumber(uint16_t sn); |
| 59 | int setTimeStamp(uint32_t ts); |
| 60 | int setSSRC(uint32_t ssrc); |
| 61 | int setMarkerBit(uint8_t mb); |
| 62 | void setTime(uint32_t receiveTime) { _receiveTime = receiveTime; }; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 63 | |
| 64 | int setRTPheader(const webrtc::WebRtcRTPHeader* RTPinfo); |
| 65 | |
| 66 | int splitStereo(NETEQTEST_RTPpacket* slaveRtp, enum stereoModes mode); |
| 67 | |
| 68 | int extractRED(int index, webrtc::WebRtcRTPHeader& red); |
| 69 | |
| 70 | void scramblePayload(void); |
| 71 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 72 | uint8_t * _datagram; |
| 73 | uint8_t * _payloadPtr; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 74 | int _memSize; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 75 | int16_t _datagramLen; |
| 76 | int16_t _payloadLen; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 77 | webrtc::WebRtcRTPHeader _rtpInfo; |
| 78 | bool _rtpParsed; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 79 | uint32_t _receiveTime; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 80 | bool _lost; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 81 | std::map<uint8_t, bool> _blockList; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 82 | |
| 83 | protected: |
| 84 | static const int _kRDHeaderLen; |
| 85 | static const int _kBasicHeaderLen; |
| 86 | |
| 87 | void parseBasicHeader(webrtc::WebRtcRTPHeader* RTPinfo, int *i_P, int *i_X, |
| 88 | int *i_CC) const; |
| 89 | int calcHeaderLength(int i_X, int i_CC) const; |
| 90 | |
| 91 | private: |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 | [diff] [blame] | 92 | void makeRTPheader(unsigned char* rtp_data, uint8_t payloadType, |
| 93 | uint16_t seqNo, uint32_t timestamp, |
| 94 | uint32_t ssrc, uint8_t markerBit) const; |
| 95 | uint16_t parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo, |
| 96 | uint8_t **payloadPtr = NULL) const; |
| 97 | uint16_t parseRTPheader(uint8_t **payloadPtr = NULL) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 98 | { return parseRTPheader(&_rtpInfo, payloadPtr);}; |
| 99 | int calcPadLength(int i_P) const; |
| 100 | void splitStereoSample(NETEQTEST_RTPpacket* slaveRtp, int stride); |
| 101 | void splitStereoFrame(NETEQTEST_RTPpacket* slaveRtp); |
| 102 | void splitStereoDouble(NETEQTEST_RTPpacket* slaveRtp); |
| 103 | }; |
| 104 | |
| 105 | #endif //NETEQTEST_RTPPACKET_H |