mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
h265支持输入复合帧 拆帧代码复用
This commit is contained in:
parent
d507220869
commit
99ab975065
@ -128,13 +128,14 @@ public:
|
||||
* 一个复合帧可以通过无内存拷贝的方式切割成多个H264FrameSubFrame
|
||||
* 提供该类的目的是切换复合帧时防止内存拷贝,提高性能
|
||||
*/
|
||||
class H264FrameSubFrame : public H264FrameNoCacheAble{
|
||||
template<typename Parent>
|
||||
class FrameInternal : public Parent{
|
||||
public:
|
||||
typedef std::shared_ptr<H264FrameSubFrame> Ptr;
|
||||
H264FrameSubFrame(const Frame::Ptr &parent_frame,
|
||||
char *ptr,
|
||||
uint32_t size,
|
||||
int prefixeSize) : H264FrameNoCacheAble(ptr,size,parent_frame->dts(),parent_frame->pts(),prefixeSize){
|
||||
typedef std::shared_ptr<FrameInternal> Ptr;
|
||||
FrameInternal(const Frame::Ptr &parent_frame,
|
||||
char *ptr,
|
||||
uint32_t size,
|
||||
int prefixeSize) : Parent(ptr,size,parent_frame->dts(),parent_frame->pts(),prefixeSize){
|
||||
_parent_frame = parent_frame;
|
||||
}
|
||||
bool cacheAble() const override {
|
||||
@ -144,6 +145,8 @@ private:
|
||||
Frame::Ptr _parent_frame;
|
||||
};
|
||||
|
||||
typedef FrameInternal<H264FrameNoCacheAble> H264FrameInternal;
|
||||
|
||||
/**
|
||||
* 264视频通道
|
||||
*/
|
||||
@ -243,21 +246,21 @@ public:
|
||||
splitH264(frame->data() + frame->prefixSize(),
|
||||
frame->size() - frame->prefixSize(),
|
||||
[&](const char *ptr, int len){
|
||||
if(first_frame){
|
||||
H264FrameSubFrame::Ptr sub_frame = std::make_shared<H264FrameSubFrame>(frame,
|
||||
frame->data(),
|
||||
len + frame->prefixSize(),
|
||||
frame->prefixSize());
|
||||
inputFrame_l(sub_frame);
|
||||
first_frame = false;
|
||||
}else{
|
||||
H264FrameSubFrame::Ptr sub_frame = std::make_shared<H264FrameSubFrame>(frame,
|
||||
(char *)ptr,
|
||||
len ,
|
||||
3);
|
||||
inputFrame_l(sub_frame);
|
||||
}
|
||||
});
|
||||
if(first_frame){
|
||||
H264FrameInternal::Ptr sub_frame = std::make_shared<H264FrameInternal>(frame,
|
||||
frame->data(),
|
||||
len + frame->prefixSize(),
|
||||
frame->prefixSize());
|
||||
inputFrame_l(sub_frame);
|
||||
first_frame = false;
|
||||
}else{
|
||||
H264FrameInternal::Ptr sub_frame = std::make_shared<H264FrameInternal>(frame,
|
||||
(char *)ptr,
|
||||
len ,
|
||||
3);
|
||||
inputFrame_l(sub_frame);
|
||||
}
|
||||
});
|
||||
} else{
|
||||
inputFrame_l(frame);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "Frame.h"
|
||||
#include "Track.h"
|
||||
#include "Util/base64.h"
|
||||
#include "H264.h"
|
||||
using namespace toolkit;
|
||||
#define H265_TYPE(v) (((uint8_t)(v) >> 1) & 0x3f)
|
||||
|
||||
@ -147,6 +148,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef FrameInternal<H265FrameNoCacheAble> H265FrameInternal;
|
||||
|
||||
/**
|
||||
* 265视频通道
|
||||
@ -209,11 +211,38 @@ public:
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 输入数据帧,并获取sps pps
|
||||
* @param frame 数据帧
|
||||
*/
|
||||
void inputFrame(const Frame::Ptr &frame) override{
|
||||
bool first_frame = true;
|
||||
splitH264(frame->data() + frame->prefixSize(),
|
||||
frame->size() - frame->prefixSize(),
|
||||
[&](const char *ptr, int len){
|
||||
if(first_frame){
|
||||
H265FrameInternal::Ptr sub_frame = std::make_shared<H265FrameInternal>(frame,
|
||||
frame->data(),
|
||||
len + frame->prefixSize(),
|
||||
frame->prefixSize());
|
||||
inputFrame_l(sub_frame);
|
||||
first_frame = false;
|
||||
}else{
|
||||
H265FrameInternal::Ptr sub_frame = std::make_shared<H265FrameInternal>(frame,
|
||||
(char *)ptr,
|
||||
len ,
|
||||
3);
|
||||
inputFrame_l(sub_frame);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* 输入数据帧,并获取sps pps
|
||||
* @param frame 数据帧
|
||||
*/
|
||||
void inputFrame(const Frame::Ptr &frame) override {
|
||||
void inputFrame_l(const Frame::Ptr &frame) {
|
||||
int type = H265_TYPE(((uint8_t *) frame->data() + frame->prefixSize())[0]);
|
||||
if (H265Frame::isKeyFrame(type)) {
|
||||
insertConfigFrame(frame);
|
||||
@ -250,7 +279,7 @@ public:
|
||||
break;
|
||||
}
|
||||
}
|
||||
private:
|
||||
|
||||
Track::Ptr clone() override {
|
||||
return std::make_shared<std::remove_reference<decltype(*this)>::type>(*this);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user