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