H265.h 3.63 KB
Newer Older
1
/*
xiongziliang committed
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
 *
 * 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.
 */
10 11 12 13 14 15

#ifndef ZLMEDIAKIT_H265_H
#define ZLMEDIAKIT_H265_H

#include "Frame.h"
#include "Track.h"
xiongziliang committed
16
#include "Util/base64.h"
17
#include "H264.h"
xiongziliang committed
18
#define H265_TYPE(v) (((uint8_t)(v) >> 1) & 0x3f)
19
using namespace toolkit;
20

xiongziliang committed
21 22
namespace mediakit {

xiongziliang committed
23
bool getHEVCInfo(const string &strVps, const string &strSps, int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
zqsong committed
24

25
/**
xiongziliang committed
26 27 28
 * 265帧类
 */
class H265Frame : public FrameImp {
29
public:
30 31
    using Ptr = std::shared_ptr<H265Frame>;
    enum {
xiongziliang committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
        NAL_TRAIL_N = 0,
        NAL_TRAIL_R = 1,
        NAL_TSA_N = 2,
        NAL_TSA_R = 3,
        NAL_STSA_N = 4,
        NAL_STSA_R = 5,
        NAL_RADL_N = 6,
        NAL_RADL_R = 7,
        NAL_RASL_N = 8,
        NAL_RASL_R = 9,
        NAL_BLA_W_LP = 16,
        NAL_BLA_W_RADL = 17,
        NAL_BLA_N_LP = 18,
        NAL_IDR_W_RADL = 19,
        NAL_IDR_N_LP = 20,
        NAL_CRA_NUT = 21,
48 49 50
        NAL_RSV_IRAP_VCL22 = 22,
        NAL_RSV_IRAP_VCL23 = 23,

xiongziliang committed
51 52 53 54 55 56 57 58 59
        NAL_VPS = 32,
        NAL_SPS = 33,
        NAL_PPS = 34,
        NAL_AUD = 35,
        NAL_EOS_NUT = 36,
        NAL_EOB_NUT = 37,
        NAL_FD_NUT = 38,
        NAL_SEI_PREFIX = 39,
        NAL_SEI_SUFFIX = 40,
60
    };
61

62 63 64
    bool keyFrame() const override;
    bool configFrame() const override;
    static bool isKeyFrame(int type);
xiongziliang committed
65

66 67 68 69
protected:
    friend class FrameImp;
    friend class ResourcePool_l<H265Frame>;
    H265Frame();
70 71
};

xiongziliang committed
72
class H265FrameNoCacheAble : public FrameFromPtr {
73
public:
74
    using Ptr = std::shared_ptr<H265FrameNoCacheAble>;
xiongziliang committed
75

76 77 78
    H265FrameNoCacheAble(char *ptr, size_t size, uint32_t dts,uint32_t pts, size_t prefix_size = 4);
    bool keyFrame() const override;
    bool configFrame() const override;
xiongziliang committed
79 80 81 82 83 84 85
};

/**
* 265视频通道
*/
class H265Track : public VideoTrack {
public:
86
    using Ptr = std::shared_ptr<H265Track>;
xiongziliang committed
87 88 89 90 91

    /**
     * 不指定sps pps构造h265类型的媒体
     * 在随后的inputFrame中获取sps pps
     */
92
    H265Track() = default;
xiongziliang committed
93 94 95

    /**
     * 构造h265类型的媒体
xiongziliang committed
96
     * @param vps vps帧数据
xiongziliang committed
97 98
     * @param sps sps帧数据
     * @param pps pps帧数据
xiongziliang committed
99
     * @param vps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
xiongziliang committed
100 101 102
     * @param sps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
     * @param pps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
     */
103
    H265Track(const string &vps,const string &sps, const string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4);
xiongziliang committed
104 105

    /**
106
     * 返回不带0x00 00 00 01头的vps/sps/pps
xiongziliang committed
107
     */
108 109 110
    const string &getVps() const;
    const string &getSps() const;
    const string &getPps() const;
xiongziliang committed
111

112 113 114 115 116 117
    bool ready() override;
    CodecId getCodecId() const override;
    int getVideoWidth() const override;
    int getVideoHeight() const override;
    float getVideoFps() const override;
    void inputFrame(const Frame::Ptr &frame) override;
118 119

private:
120 121 122 123 124
    void onReady();
    Sdp::Ptr getSdp() override;
    Track::Ptr clone() override;
    void inputFrame_l(const Frame::Ptr &frame);
    void insertConfigFrame(const Frame::Ptr &frame);
125

xiongziliang committed
126
private:
127 128 129 130
    bool _is_idr = false;
    int _width = 0;
    int _height = 0;
    float _fps = 0;
xiongziliang committed
131 132 133
    string _vps;
    string _sps;
    string _pps;
134 135
};

136
}//namespace mediakit
xiongziliang committed
137
#endif //ZLMEDIAKIT_H265_H