h264_rtp打包解包类及实现demo

打包头文件:

class CH2642Rtp
{
public:
    CH2642Rtp(uint32_t ssrc, uint8_t payloadType = 96, uint8_t fps = 25, int32_t rtpsizeMax = RTP_PACK_SIZE_MAX);
    ~CH2642Rtp(void);

    int getOneRtp(uint8_t *buf, uint16_t bufsize, bool_t *eof);

    int setOneFrame(const uint8_t *nalbuf, uint16_t nalsize);

private:
    void resetRtpInfo();

private:

    uint8_t   m_sps[SPS_SIZE_MAX], m_pps[SPS_SIZE_MAX];
    uint32_t  m_spslen, m_ppslen;

    uint8_t   m_fps;
    uint32_t  m_ts;
    uint16_t  m_vseq;
    bool_t    m_vfirst;
    uint8_t   m_payloadType;
    uint32_t  m_ssrc ;
    int32_t   m_rtpsizeMax;


    int32_t   m_naltype;
    uint8_t   *m_nalbuf;
    uint16_t  m_nalsize;
    uint8_t   *m_cur;
    bool_t    m_eof;
};

  

解包头文件:

class CRtp2H264
{
public:
    CRtp2H264(uint8_t payloadType = 96);
    ~CRtp2H264(void);

    /**
     * @brief  根据传入的rtp数据输出一帧H264
     * @param  [in] buf
     * @param  [in] bufsize
     * @param  [out] pkt h264帧(sps/pps/I/P/B)
     * @return >0: normal h264 data, =0: 当前rtp data不足以输出一帧数据, <0: error happen 
     */
    int32_t readFrame(const uint8_t *buf, uint16_t bufsize, AvPacket* pkt);

private:
    int32_t _parseRtp(struct rtpheader *rh, const uint8_t *buf, uint16_t bufsize, payload_t *payload);

    int32_t _parseH264(const uint8_t *buf, uint16_t bufsize, AvPacket* pkt);

private:
    statics_unpack_t m_statics;

    uint8_t   m_sps[SPS_SIZE_MAX], m_pps[SPS_SIZE_MAX];
    uint32_t  m_spslen, m_ppslen;

    uint16_t  m_vseq;
    bool_t    m_vfirst;
    uint8_t   m_payloadType ;
    int32_t   m_ssrc ;
};  

demo(linux x64环境下运行)及h264裸流测试文件下载地址:

http://www.srcbin.net/index.php/soft/detail.html?id=46

源码下载地址:

http://www.srcbin.net/index.php/file/code.html?id=18

 

你可能感兴趣的:(h264_rtp打包解包类及实现demo)