H264Rtp.h 2.29 KB
Newer Older
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
3
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
5
 *
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

45
private:
46
    bool decodeRtp(const RtpPacket::Ptr &rtp);
xiongziliang committed
47
    void onGetH264(const H264Frame::Ptr &frame);
48
    H264Frame::Ptr obtainFrame();
49

50
private:
51
    uint16_t _lastSeq = 0;
52
    H264Frame::Ptr _h264frame;
53
    DtsGenerator _dts_generator;
54 55
};

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

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

77 78 79 80
    /**
     * 输入264帧
     * @param frame 帧数据,必须
     */
81
    void inputFrame(const Frame::Ptr &frame) override;
82

xiongziliang committed
83
private:
84
    void makeH264Rtp(const void *pData, size_t uiLen, bool bMark,  bool gop_pos, uint32_t uiStamp);
xiongziliang committed
85 86
};

xiongziliang committed
87
}//namespace mediakit{
88 89

#endif //ZLMEDIAKIT_H264RTPCODEC_H