H265Rtmp.h 2.14 KB
Newer Older
xiongziliang committed
1 2 3
/*
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
xiongziliang committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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.
 */

#ifndef ZLMEDIAKIT_H265RTMPCODEC_H
#define ZLMEDIAKIT_H265RTMPCODEC_H

#include "Rtmp/RtmpCodec.h"
#include "Extension/Track.h"
#include "Util/ResourcePool.h"
#include "Extension/H265.h"
using namespace toolkit;

namespace mediakit{
/**
 * h265 Rtmp解码类
 * 将 h265 over rtmp 解复用出 h265-Frame
 */
25
class H265RtmpDecoder : public RtmpCodec {
xiongziliang committed
26 27 28 29 30 31 32 33 34 35
public:
    typedef std::shared_ptr<H265RtmpDecoder> Ptr;

    H265RtmpDecoder();
    ~H265RtmpDecoder() {}

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

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

xiongziliang committed
42
protected:
43
    void onGetH265(const char *pcData, size_t iLen, uint32_t dts,uint32_t pts);
xiongziliang committed
44
    H265Frame::Ptr obtainFrame();
45

xiongziliang committed
46 47 48 49 50 51 52
protected:
    H265Frame::Ptr _h265frame;
};

/**
 * 265 Rtmp打包类
 */
xia-chu committed
53
class H265RtmpEncoder : public H265RtmpDecoder{
xiongziliang committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
public:
    typedef std::shared_ptr<H265RtmpEncoder> Ptr;

    /**
     * 构造函数,track可以为空,此时则在inputFrame时输入sps pps
     * 如果track不为空且包含sps pps信息,
     * 那么inputFrame时可以不输入sps pps
     * @param track
     */
    H265RtmpEncoder(const Track::Ptr &track);
    ~H265RtmpEncoder() {}

    /**
     * 输入265帧,可以不带sps pps
     * @param frame 帧数据
     */
    void inputFrame(const Frame::Ptr &frame) override;

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

xiongziliang committed
77 78
private:
    void makeVideoConfigPkt();
79

xiongziliang committed
80
private:
ziyue committed
81
    bool _got_config_frame = false;
xiongziliang committed
82 83 84 85
    string _vps;
    string _sps;
    string _pps;
    H265Track::Ptr _track;
ziyue committed
86
    RtmpPacket::Ptr _rtmp_packet;
87
    FrameMerger _merger{FrameMerger::mp4_nal_size};
xiongziliang committed
88 89 90 91 92
};

}//namespace mediakit

#endif //ZLMEDIAKIT_H265RTMPCODEC_H