H264Rtp.h 2.29 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

#ifndef ZLMEDIAKIT_H264RTPCODEC_H
#define ZLMEDIAKIT_H264RTPCODEC_H

xiongziliang committed
14
#include "Rtsp/RtpCodec.h"
xiongziliang committed
15
#include "Util/ResourcePool.h"
16
#include "Extension/H264.h"
17
#include "Common/Stamp.h"
xiongziliang committed
18
using namespace toolkit;
19

xiongziliang committed
20
namespace mediakit{
xiongziliang committed
21

22 23
/**
 * h264 rtp解码类
3503207480@qq.com committed
24 25
 * 将 h264 over rtsp-rtp 解复用出 h264-Frame
 * rfc3984
26
 */
27
class H264RtpDecoder : public RtpCodec , public ResourcePoolHelper<H264Frame> {
28
public:
xiongziliang committed
29 30
    typedef std::shared_ptr<H264RtpDecoder> Ptr;

31
    H264RtpDecoder();
xiongziliang committed
32 33
    ~H264RtpDecoder() {}

34 35 36 37 38
    /**
     * 输入264 rtp包
     * @param rtp rtp包
     * @param key_pos 此参数忽略之
     */
xiongziliang committed
39
    bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = true) override;
40 41 42 43

    CodecId getCodecId() const override{
        return CodecH264;
    }
44
private:
45
    bool decodeRtp(const RtpPacket::Ptr &rtp);
xiongziliang committed
46
    void onGetH264(const H264Frame::Ptr &frame);
47
    H264Frame::Ptr obtainFrame();
48
private:
49
    H264Frame::Ptr _h264frame;
50
    DtsGenerator _dts_generator;
51
    int _lastSeq = 0;
52 53
};

54 55 56
/**
 * 264 rtp打包类
 */
57
class H264RtpEncoder : public H264RtpDecoder ,public RtpInfo{
xiongziliang committed
58
public:
xiongziliang committed
59
    typedef std::shared_ptr<H264RtpEncoder> Ptr;
60 61 62 63 64

    /**
     * @param ui32Ssrc ssrc
     * @param ui32MtuSize mtu大小
     * @param ui32SampleRate 采样率,强制为90000
xiongziliang committed
65
     * @param ui8PayloadType pt类型
66 67
     * @param ui8Interleaved rtsp interleaved
     */
xiongziliang committed
68 69 70
    H264RtpEncoder(uint32_t ui32Ssrc,
                   uint32_t ui32MtuSize = 1400,
                   uint32_t ui32SampleRate = 90000,
xiongziliang committed
71
                   uint8_t ui8PayloadType = 96,
xiongziliang committed
72 73 74
                   uint8_t ui8Interleaved = TrackVideo * 2);
    ~H264RtpEncoder() {}

75 76 77 78
    /**
     * 输入264帧
     * @param frame 帧数据,必须
     */
79
    void inputFrame(const Frame::Ptr &frame) override;
xiongziliang committed
80
private:
81
    void makeH264Rtp(const void *pData, unsigned int uiLen, bool bMark,  bool gop_pos, uint32_t uiStamp);
xiongziliang committed
82 83
};

xiongziliang committed
84
}//namespace mediakit{
85 86

#endif //ZLMEDIAKIT_H264RTPCODEC_H