ZLMediaKit/src/Extension/H264Rtp.h

93 lines
2.3 KiB
C++
Raw Normal View History

2018-10-25 10:00:17 +08:00
/*
2020-04-04 20:30:09 +08:00
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
2018-10-25 10:00:17 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
2018-10-25 10:00:17 +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-25 10:00:17 +08:00
*/
2018-10-18 23:48:00 +08:00
#ifndef ZLMEDIAKIT_H264RTPCODEC_H
#define ZLMEDIAKIT_H264RTPCODEC_H
2019-06-28 17:30:13 +08:00
#include "Rtsp/RtpCodec.h"
2018-10-21 21:21:14 +08:00
#include "Util/ResourcePool.h"
2018-10-30 14:59:42 +08:00
#include "Extension/H264.h"
#include "Common/Stamp.h"
2018-10-24 17:17:55 +08:00
using namespace toolkit;
2018-10-18 23:48:00 +08:00
2018-10-24 17:17:55 +08:00
namespace mediakit{
2018-10-21 21:21:14 +08:00
2018-10-21 22:24:24 +08:00
/**
* h264 rtp解码类
2019-08-30 11:17:27 +08:00
* h264 over rtsp-rtp h264-Frame
* rfc3984
2018-10-21 22:24:24 +08:00
*/
2021-02-05 11:51:16 +08:00
class H264RtpDecoder : public RtpCodec{
2018-10-18 23:48:00 +08:00
public:
2018-10-23 18:39:17 +08:00
typedef std::shared_ptr<H264RtpDecoder> Ptr;
2018-10-21 22:24:24 +08:00
H264RtpDecoder();
2018-10-21 21:45:44 +08:00
~H264RtpDecoder() {}
2018-10-21 22:24:24 +08:00
/**
* 264 rtp包
* @param rtp rtp包
* @param key_pos
*/
2018-10-23 18:39:17 +08:00
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = true) override;
2018-10-23 11:09:21 +08:00
CodecId getCodecId() const override{
return CodecH264;
}
2018-10-18 23:48:00 +08:00
private:
2018-10-21 22:24:24 +08:00
bool decodeRtp(const RtpPacket::Ptr &rtp);
2018-10-21 21:21:14 +08:00
void onGetH264(const H264Frame::Ptr &frame);
2018-10-21 22:24:24 +08:00
H264Frame::Ptr obtainFrame();
2018-10-18 23:48:00 +08:00
private:
2021-02-07 18:29:48 +08:00
uint16_t _last_seq = 0;
size_t _max_frame_size = 0;
H264Frame::Ptr _frame;
DtsGenerator _dts_generator;
2018-10-18 23:48:00 +08:00
};
2018-10-21 22:24:24 +08:00
/**
* 264 rtp打包类
*/
2018-10-23 11:38:56 +08:00
class H264RtpEncoder : public H264RtpDecoder ,public RtpInfo{
2018-10-21 21:45:44 +08:00
public:
2018-10-23 18:39:17 +08:00
typedef std::shared_ptr<H264RtpEncoder> Ptr;
2018-10-21 22:24:24 +08:00
/**
2021-02-07 18:29:48 +08:00
* @param ssrc ssrc
* @param mtu mtu大小
* @param sample_rate 90000
* @param pt pt类型
* @param interleaved rtsp interleaved
2018-10-21 22:24:24 +08:00
*/
2021-02-07 18:29:48 +08:00
H264RtpEncoder(uint32_t ssrc,
uint32_t mtu = 1400,
uint32_t sample_rate = 90000,
uint8_t pt = 96,
uint8_t interleaved = TrackVideo * 2);
2018-10-21 21:45:44 +08:00
~H264RtpEncoder() {}
2018-10-21 22:24:24 +08:00
/**
* 264
* @param frame
*/
2018-10-23 21:41:45 +08:00
void inputFrame(const Frame::Ptr &frame) override;
2018-10-21 21:45:44 +08:00
private:
void makeH264Rtp(const void *pData, size_t uiLen, bool bMark, bool gop_pos, uint32_t uiStamp);
2021-04-15 00:15:41 +08:00
string _sps;
string _pps;
2018-10-21 21:45:44 +08:00
};
2018-10-24 17:17:55 +08:00
}//namespace mediakit{
2018-10-18 23:48:00 +08:00
#endif //ZLMEDIAKIT_H264RTPCODEC_H