H265Rtp.h 2.53 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_H265RTPCODEC_H
#define ZLMEDIAKIT_H265RTPCODEC_H

xiongziliang committed
14
#include "Rtsp/RtpCodec.h"
15 16
#include "Util/ResourcePool.h"
#include "Extension/H265.h"
17
#include "Common/Stamp.h"
18 19 20 21 22 23 24

using namespace toolkit;

namespace mediakit{

/**
 * h265 rtp解码类
3503207480@qq.com committed
25 26
 * 将 h265 over rtsp-rtp 解复用出 h265-Frame
 * 《草案(H265-over-RTP)draft-ietf-payload-rtp-h265-07.pdf》
27
 */
28
class H265RtpDecoder : public RtpCodec {
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
public:
    typedef std::shared_ptr<H265RtpDecoder> Ptr;

    H265RtpDecoder();
    ~H265RtpDecoder() {}

    /**
     * 输入265 rtp包
     * @param rtp rtp包
     * @param key_pos 此参数忽略之
     */
    bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = true) override;

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

46
private:
xiongziliang committed
47 48 49 50
    bool unpackAp(const uint8_t *ptr, ssize_t size, uint32_t stamp);
    bool mergeFu(const uint8_t *ptr, ssize_t size, uint16_t seq, uint32_t stamp);
    bool singleFrame(const uint8_t *ptr, ssize_t size, uint32_t stamp);

51
    H265Frame::Ptr obtainFrame();
xiongziliang committed
52
    void outputFrame(const H265Frame::Ptr &frame);
53

54
private:
xiongziliang committed
55 56 57
    bool _using_donl_field = false;
    uint16_t _last_seq = 0;
    H265Frame::Ptr _frame;
58
    DtsGenerator _dts_generator;
59 60 61 62 63 64 65 66 67 68 69 70 71
};

/**
 * 265 rtp打包类
 */
class H265RtpEncoder : public H265RtpDecoder ,public RtpInfo{
public:
    typedef std::shared_ptr<H265RtpEncoder> Ptr;

    /**
     * @param ui32Ssrc ssrc
     * @param ui32MtuSize mtu大小
     * @param ui32SampleRate 采样率,强制为90000
xiongziliang committed
72
     * @param ui8PayloadType pt类型
73 74 75 76 77
     * @param ui8Interleaved rtsp interleaved
     */
    H265RtpEncoder(uint32_t ui32Ssrc,
                   uint32_t ui32MtuSize = 1400,
                   uint32_t ui32SampleRate = 90000,
xiongziliang committed
78
                   uint8_t ui8PayloadType = 96,
79 80 81 82 83 84 85 86 87
                   uint8_t ui8Interleaved = TrackVideo * 2);
    ~H265RtpEncoder() {}

    /**
     * 输入265帧
     * @param frame 帧数据,必须
     */
    void inputFrame(const Frame::Ptr &frame) override;
private:
88
    void makeH265Rtp(int nal_type,const void *pData, size_t uiLen, bool bMark, bool first_packet,uint32_t uiStamp);
89 90 91 92 93
};

}//namespace mediakit{

#endif //ZLMEDIAKIT_H265RTPCODEC_H