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 * 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);

View File

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