RtpCodec.h 3 KB
Newer Older
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
3 4 5
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
xiongziliang committed
6 7 8
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
9
 */
10 11 12 13 14 15 16

#ifndef ZLMEDIAKIT_RTPCODEC_H
#define ZLMEDIAKIT_RTPCODEC_H

#include <memory>
#include "Util/RingBuffer.h"
#include "Player/PlayerBase.h"
xiongziliang committed
17
using namespace toolkit;
18

xiongziliang committed
19
namespace mediakit{
20

xiongziliang committed
21
class RtpRing{
22
public:
xiongziliang committed
23
    typedef std::shared_ptr<RtpRing> Ptr;
24 25
    typedef RingBuffer<RtpPacket::Ptr> RingType;

xiongziliang committed
26 27
    RtpRing(){}
    virtual ~RtpRing(){}
xiongziliang committed
28 29 30 31 32

    /**
     * 获取rtp环形缓存
     * @return
     */
xiongziliang committed
33 34 35
    virtual RingType::Ptr getRtpRing() const {
        return _rtpRing;
    }
xiongziliang committed
36 37 38 39 40

    /**
     * 设置rtp环形缓存
     * @param ring
     */
xiongziliang committed
41 42 43
    virtual void setRtpRing(const RingType::Ptr &ring){
        _rtpRing = ring;
    }
xiongziliang committed
44 45 46 47 48 49 50

    /**
     * 输入rtp包
     * @param rtp rtp包
     * @param key_pos 是否为关键帧第一个rtp包
     * @return 是否为关键帧第一个rtp包
     */
xiongziliang committed
51
    virtual bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos){
xiongziliang committed
52 53 54
        if(_rtpRing){
            _rtpRing->write(rtp,key_pos);
        }
xiongziliang committed
55
        return key_pos;
56
    }
57 58
protected:
    RingType::Ptr _rtpRing;
59 60 61
};


xiongziliang committed
62
class RtpInfo : public  ResourcePoolHelper<RtpPacket>{
63
public:
xiongziliang committed
64
    typedef std::shared_ptr<RtpInfo> Ptr;
65

xiongziliang committed
66
    RtpInfo(uint32_t ui32Ssrc,
67 68
            uint32_t ui32MtuSize,
            uint32_t ui32SampleRate,
xiongziliang committed
69
            uint8_t ui8PayloadType,
70 71 72 73
            uint8_t ui8Interleaved) {
        if(ui32Ssrc == 0){
            ui32Ssrc = ((uint64_t)this) & 0xFFFFFFFF;
        }
74 75 76
        _ui32Ssrc = ui32Ssrc;
        _ui32SampleRate = ui32SampleRate;
        _ui32MtuSize = ui32MtuSize;
xiongziliang committed
77
        _ui8PayloadType = ui8PayloadType;
78
        _ui8Interleaved = ui8Interleaved;
79 80
    }

xiongziliang committed
81
    virtual ~RtpInfo(){}
82 83

    int getInterleaved() const {
84
        return _ui8Interleaved;
85 86
    }

xiongziliang committed
87 88
    int getPayloadType() const {
        return _ui8PayloadType;
89 90 91
    }

    int getSampleRate() const {
92
        return _ui32SampleRate;
93 94 95
    }

    uint32_t getSsrc() const {
96
        return _ui32Ssrc;
97 98 99
    }

    uint16_t getSeqence() const {
100
        return _ui16Sequence;
101 102
    }
    uint32_t getTimestamp() const {
103
        return _ui32TimeStamp;
104 105
    }
    uint32_t getMtuSize() const {
106
        return _ui32MtuSize;
107
    }
xiongziliang committed
108
    RtpPacket::Ptr makeRtp(TrackType type,const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
109

110
protected:
111 112 113
    uint32_t _ui32Ssrc;
    uint32_t _ui32SampleRate;
    uint32_t _ui32MtuSize;
xiongziliang committed
114
    uint8_t _ui8PayloadType;
115 116 117
    uint8_t _ui8Interleaved;
    uint16_t _ui16Sequence = 0;
    uint32_t _ui32TimeStamp = 0;
118 119
};

xiongziliang committed
120
class RtpCodec : public RtpRing, public FrameDispatcher , public CodecInfo{
121 122 123 124 125
public:
    typedef std::shared_ptr<RtpCodec> Ptr;
    RtpCodec(){}
    virtual ~RtpCodec(){}
};
126

xiongziliang committed
127
}//namespace mediakit
128 129 130



131

132
#endif //ZLMEDIAKIT_RTPCODEC_H