From 99ab975065af32a6dd408e9ade44f023d88953a0 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 30 Jul 2019 13:54:19 +0800 Subject: [PATCH] =?UTF-8?q?h265=E6=94=AF=E6=8C=81=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E5=A4=8D=E5=90=88=E5=B8=A7=20=E6=8B=86=E5=B8=A7=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=A4=8D=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/H264.h | 45 +++++++++++++++++++++++--------------------- src/Extension/H265.h | 33 ++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/Extension/H264.h b/src/Extension/H264.h index 853c7f60..400f5474 100644 --- a/src/Extension/H264.h +++ b/src/Extension/H264.h @@ -128,13 +128,14 @@ public: * 一个复合帧可以通过无内存拷贝的方式切割成多个H264FrameSubFrame * 提供该类的目的是切换复合帧时防止内存拷贝,提高性能 */ -class H264FrameSubFrame : public H264FrameNoCacheAble{ +template +class FrameInternal : public Parent{ public: - typedef std::shared_ptr 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 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 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(frame, - frame->data(), - len + frame->prefixSize(), - frame->prefixSize()); - inputFrame_l(sub_frame); - first_frame = false; - }else{ - H264FrameSubFrame::Ptr sub_frame = std::make_shared(frame, - (char *)ptr, - len , - 3); - inputFrame_l(sub_frame); - } - }); + if(first_frame){ + H264FrameInternal::Ptr sub_frame = std::make_shared(frame, + frame->data(), + len + frame->prefixSize(), + frame->prefixSize()); + inputFrame_l(sub_frame); + first_frame = false; + }else{ + H264FrameInternal::Ptr sub_frame = std::make_shared(frame, + (char *)ptr, + len , + 3); + inputFrame_l(sub_frame); + } + }); } else{ inputFrame_l(frame); } diff --git a/src/Extension/H265.h b/src/Extension/H265.h index 9ba82458..cd367b66 100644 --- a/src/Extension/H265.h +++ b/src/Extension/H265.h @@ -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 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(frame, + frame->data(), + len + frame->prefixSize(), + frame->prefixSize()); + inputFrame_l(sub_frame); + first_frame = false; + }else{ + H265FrameInternal::Ptr sub_frame = std::make_shared(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::type>(*this); }