H264Rtmp.h 2.12 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_H264RTMPCODEC_H
#define ZLMEDIAKIT_H264RTMPCODEC_H

xiongziliang committed
14
#include "Rtmp/RtmpCodec.h"
15
#include "Extension/Track.h"
16
#include "Util/ResourcePool.h"
17
#include "Extension/H264.h"
xiongziliang committed
18
using namespace toolkit;
19

xiongziliang committed
20
namespace mediakit{
21 22
/**
 * h264 Rtmp解码类
3503207480@qq.com committed
23
 * 将 h264 over rtmp 解复用出 h264-Frame
24
 */
25
class H264RtmpDecoder : public RtmpCodec {
26 27 28 29 30 31 32 33 34 35
public:
    typedef std::shared_ptr<H264RtmpDecoder> Ptr;

    H264RtmpDecoder();
    ~H264RtmpDecoder() {}

    /**
     * 输入264 Rtmp包
     * @param rtmp Rtmp包
     */
36
    void inputRtmp(const RtmpPacket::Ptr &rtmp) override;
37 38 39 40

    CodecId getCodecId() const override{
        return CodecH264;
    }
41

42
protected:
43
    void onGetH264(const char *pcData, size_t iLen, uint32_t dts,uint32_t pts);
44
    H264Frame::Ptr obtainFrame();
45

46
protected:
47 48 49
    H264Frame::Ptr _h264frame;
    string _sps;
    string _pps;
50 51 52 53 54
};

/**
 * 264 Rtmp打包类
 */
xia-chu committed
55
class H264RtmpEncoder : public H264RtmpDecoder{
56 57 58
public:
    typedef std::shared_ptr<H264RtmpEncoder> Ptr;

59 60 61 62 63 64 65
    /**
     * 构造函数,track可以为空,此时则在inputFrame时输入sps pps
     * 如果track不为空且包含sps pps信息,
     * 那么inputFrame时可以不输入sps pps
     * @param track
     */
    H264RtmpEncoder(const Track::Ptr &track);
66 67 68
    ~H264RtmpEncoder() {}

    /**
69
     * 输入264帧,可以不带sps pps
70 71 72
     * @param frame 帧数据
     */
    void inputFrame(const Frame::Ptr &frame) override;
73 74 75 76 77

    /**
     * 生成config包
     */
    void makeConfigPacket() override;
78

79 80
private:
    void makeVideoConfigPkt();
81

82
private:
ziyue committed
83
    bool _got_config_frame = false;
84
    H264Track::Ptr _track;
ziyue committed
85
    RtmpPacket::Ptr _rtmp_packet;
86
    FrameMerger _merger{FrameMerger::mp4_nal_size};
87 88
};

xiongziliang committed
89 90
}//namespace mediakit

91
#endif //ZLMEDIAKIT_H264RTMPCODEC_H