h265支持输入复合帧 拆帧代码复用

This commit is contained in:
xiongziliang 2019-07-30 13:54:19 +08:00
parent d507220869
commit 99ab975065
2 changed files with 55 additions and 23 deletions

View File

@ -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);
}

View File

@ -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);
}