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/include/module_common_types.h"
18
19enum stereoModes {
20    stereoModeMono,
21    stereoModeSample1,
22    stereoModeSample2,
23    stereoModeFrame,
24    stereoModeDuplicate
25};
26
27class NETEQTEST_RTPpacket
28{
29public:
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);
38    void blockPT(uint8_t pt);
39    virtual void parseHeader();
40    void parseHeader(webrtc::WebRtcRTPHeader* rtp_header);
41    const webrtc::WebRtcRTPHeader* RTPinfo() const;
42    uint8_t * datagram() const;
43    uint8_t * payload() const;
44    size_t payloadLen();
45    int16_t dataLen() const;
46    bool isParsed() const;
47    bool isLost() const;
48    uint32_t time() const { return _receiveTime; };
49
50    uint8_t  payloadType() const;
51    uint16_t sequenceNumber() const;
52    uint32_t timeStamp() const;
53    uint32_t SSRC() const;
54    uint8_t  markerBit() const;
55
56    int setPayloadType(uint8_t pt);
57    int setSequenceNumber(uint16_t sn);
58    int setTimeStamp(uint32_t ts);
59    int setSSRC(uint32_t ssrc);
60    int setMarkerBit(uint8_t mb);
61    void setTime(uint32_t receiveTime) { _receiveTime = receiveTime; };
62
63    int setRTPheader(const webrtc::WebRtcRTPHeader* RTPinfo);
64
65    int splitStereo(NETEQTEST_RTPpacket* slaveRtp, enum stereoModes mode);
66
67    int extractRED(int index, webrtc::WebRtcRTPHeader& red);
68
69    void scramblePayload(void);
70
71    uint8_t *       _datagram;
72    uint8_t *       _payloadPtr;
73    int                 _memSize;
74    int16_t         _datagramLen;
75    size_t          _payloadLen;
76    webrtc::WebRtcRTPHeader _rtpInfo;
77    bool                _rtpParsed;
78    uint32_t        _receiveTime;
79    bool                _lost;
80    std::map<uint8_t, bool> _blockList;
81
82protected:
83    static const int _kRDHeaderLen;
84    static const int _kBasicHeaderLen;
85
86    void parseBasicHeader(webrtc::WebRtcRTPHeader* RTPinfo, int *i_P, int *i_X,
87                          int *i_CC) const;
88    int calcHeaderLength(int i_X, int i_CC) const;
89
90private:
91    void makeRTPheader(unsigned char* rtp_data, uint8_t payloadType,
92                       uint16_t seqNo, uint32_t timestamp,
93                       uint32_t ssrc, uint8_t markerBit) const;
94    uint16_t parseRTPheader(webrtc::WebRtcRTPHeader* RTPinfo,
95                            uint8_t **payloadPtr = NULL) const;
96    uint16_t parseRTPheader(uint8_t **payloadPtr = NULL)
97        { return parseRTPheader(&_rtpInfo, payloadPtr);};
98    int calcPadLength(int i_P) const;
99    void splitStereoSample(NETEQTEST_RTPpacket* slaveRtp, int stride);
100    void splitStereoFrame(NETEQTEST_RTPpacket* slaveRtp);
101    void splitStereoDouble(NETEQTEST_RTPpacket* slaveRtp);
102};
103
104#endif //NETEQTEST_RTPPACKET_H
105