2018-10-30 14:59:42 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2018-10-30 14:59:42 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2018-10-30 14:59:42 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* 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.
|
2018-10-30 14:59:42 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_H265RTPCODEC_H
|
|
|
|
|
#define ZLMEDIAKIT_H265RTPCODEC_H
|
|
|
|
|
|
2019-06-28 17:30:13 +08:00
|
|
|
|
#include "Rtsp/RtpCodec.h"
|
2018-10-30 14:59:42 +08:00
|
|
|
|
#include "Extension/H265.h"
|
2022-11-29 11:07:13 +08:00
|
|
|
|
// for DtsGenerator
|
2020-01-14 10:04:24 +08:00
|
|
|
|
#include "Common/Stamp.h"
|
2018-10-30 14:59:42 +08:00
|
|
|
|
|
|
|
|
|
namespace mediakit{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* h265 rtp解码类
|
2019-08-30 11:17:27 +08:00
|
|
|
|
* 将 h265 over rtsp-rtp 解复用出 h265-Frame
|
|
|
|
|
* 《草案(H265-over-RTP)draft-ietf-payload-rtp-h265-07.pdf》
|
2018-10-30 14:59:42 +08:00
|
|
|
|
*/
|
2021-02-05 11:51:16 +08:00
|
|
|
|
class H265RtpDecoder : public RtpCodec {
|
2018-10-30 14:59:42 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<H265RtpDecoder>;
|
2018-10-30 14:59:42 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-01-17 18:31:50 +08:00
|
|
|
|
|
2018-10-30 14:59:42 +08:00
|
|
|
|
private:
|
2022-08-08 17:13:39 +08:00
|
|
|
|
bool unpackAp(const RtpPacket::Ptr &rtp, const uint8_t *ptr, ssize_t size, uint64_t stamp);
|
|
|
|
|
bool mergeFu(const RtpPacket::Ptr &rtp, const uint8_t *ptr, ssize_t size, uint64_t stamp, uint16_t seq);
|
|
|
|
|
bool singleFrame(const RtpPacket::Ptr &rtp, const uint8_t *ptr, ssize_t size, uint64_t stamp);
|
2021-01-23 09:43:16 +08:00
|
|
|
|
|
2021-07-29 16:22:43 +08:00
|
|
|
|
bool decodeRtp(const RtpPacket::Ptr &rtp);
|
2018-10-30 14:59:42 +08:00
|
|
|
|
H265Frame::Ptr obtainFrame();
|
2021-07-29 16:22:43 +08:00
|
|
|
|
void outputFrame(const RtpPacket::Ptr &rtp, const H265Frame::Ptr &frame);
|
2021-01-17 18:31:50 +08:00
|
|
|
|
|
2018-10-30 14:59:42 +08:00
|
|
|
|
private:
|
2021-01-23 09:43:16 +08:00
|
|
|
|
bool _using_donl_field = false;
|
2021-07-29 16:22:43 +08:00
|
|
|
|
bool _gop_dropped = false;
|
|
|
|
|
bool _fu_dropped = true;
|
2021-01-23 09:43:16 +08:00
|
|
|
|
uint16_t _last_seq = 0;
|
|
|
|
|
H265Frame::Ptr _frame;
|
2020-01-14 10:04:24 +08:00
|
|
|
|
DtsGenerator _dts_generator;
|
2018-10-30 14:59:42 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 265 rtp打包类
|
|
|
|
|
*/
|
|
|
|
|
class H265RtpEncoder : public H265RtpDecoder ,public RtpInfo{
|
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<H265RtpEncoder>;
|
2018-10-30 14:59:42 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ui32Ssrc ssrc
|
|
|
|
|
* @param ui32MtuSize mtu大小
|
|
|
|
|
* @param ui32SampleRate 采样率,强制为90000
|
2020-05-25 13:51:00 +08:00
|
|
|
|
* @param ui8PayloadType pt类型
|
2018-10-30 14:59:42 +08:00
|
|
|
|
* @param ui8Interleaved rtsp interleaved
|
|
|
|
|
*/
|
|
|
|
|
H265RtpEncoder(uint32_t ui32Ssrc,
|
|
|
|
|
uint32_t ui32MtuSize = 1400,
|
|
|
|
|
uint32_t ui32SampleRate = 90000,
|
2020-05-25 13:51:00 +08:00
|
|
|
|
uint8_t ui8PayloadType = 96,
|
2018-10-30 14:59:42 +08:00
|
|
|
|
uint8_t ui8Interleaved = TrackVideo * 2);
|
|
|
|
|
~H265RtpEncoder() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入265帧
|
|
|
|
|
* @param frame 帧数据,必须
|
|
|
|
|
*/
|
2021-09-27 13:12:53 +08:00
|
|
|
|
bool inputFrame(const Frame::Ptr &frame) override;
|
2023-04-06 19:54:59 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 刷新输出所有frame缓存
|
|
|
|
|
*/
|
|
|
|
|
void flush() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void packRtp(const char *ptr, size_t len, uint64_t pts, bool is_mark, bool gop_pos);
|
|
|
|
|
void packRtpFu(const char *ptr, size_t len, uint64_t pts, bool is_mark, bool gop_pos);
|
|
|
|
|
void insertConfigFrame(uint64_t pts);
|
|
|
|
|
bool inputFrame_l(const Frame::Ptr &frame, bool is_mark);
|
|
|
|
|
private:
|
|
|
|
|
Frame::Ptr _sps;
|
|
|
|
|
Frame::Ptr _pps;
|
|
|
|
|
Frame::Ptr _vps;
|
|
|
|
|
Frame::Ptr _last_frame;
|
2018-10-30 14:59:42 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}//namespace mediakit{
|
|
|
|
|
|
|
|
|
|
#endif //ZLMEDIAKIT_H265RTPCODEC_H
|