From ad2cd11eecd656547113a660ce8dc951d3be330c Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 9 Jun 2021 10:18:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=A4=E6=96=ADh265?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E5=85=B3=E9=94=AE=E5=B8=A7=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/H265.cpp | 25 +++++++------------------ src/Extension/H265.h | 2 +- src/Extension/H265Rtp.cpp | 4 ++-- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/Extension/H265.cpp b/src/Extension/H265.cpp index 23177030..e2967567 100644 --- a/src/Extension/H265.cpp +++ b/src/Extension/H265.cpp @@ -51,7 +51,7 @@ bool getHEVCInfo(const string &strVps, const string &strSps, int &iVideoWidth, i ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool H265Frame::keyFrame() const { - return isKeyFrame(H265_TYPE(_buffer[_prefix_size]), _buffer.data(), _prefix_size); + return isKeyFrame(H265_TYPE(_buffer[_prefix_size]), _buffer.data() + _prefix_size); } bool H265Frame::configFrame() const { @@ -63,22 +63,12 @@ bool H265Frame::configFrame() const { } } -bool H265Frame::isKeyFrame(int type, const char* ptr, uint32_t prefix_size) { - if (nullptr != ptr) - { - if (type == NAL_IDR_W_RADL) - { - uint32_t r = 0; - r = ((*((uint8_t*)ptr + prefix_size + 2)) >> 7) & 0x01; - if (r == 1) - return true; - else - return false; - }else - return type >= NAL_BLA_W_LP && type <= NAL_RSV_IRAP_VCL23; - } +bool H265Frame::isKeyFrame(int type, const char *ptr) { + if (!ptr || type != NAL_IDR_W_RADL) { return type >= NAL_BLA_W_LP && type <= NAL_RSV_IRAP_VCL23; } + return (((*((uint8_t *) ptr + 2)) >> 7) & 0x01) == 1; +} H265Frame::H265Frame(){ _codec_id = CodecH265; @@ -96,7 +86,7 @@ H265FrameNoCacheAble::H265FrameNoCacheAble(char *ptr, size_t size, uint32_t dts, } bool H265FrameNoCacheAble::keyFrame() const { - return H265Frame::isKeyFrame(H265_TYPE(((uint8_t *) _ptr)[_prefix_size]), _ptr, _prefix_size); + return H265Frame::isKeyFrame(H265_TYPE(((uint8_t *) _ptr)[_prefix_size]), _ptr + _prefix_size); } bool H265FrameNoCacheAble::configFrame() const { @@ -165,13 +155,12 @@ void H265Track::inputFrame(const Frame::Ptr &frame) { void H265Track::inputFrame_l(const Frame::Ptr &frame) { int type = H265_TYPE(((uint8_t *) frame->data() + frame->prefixSize())[0]); - if (H265Frame::isKeyFrame(type, frame->data(), frame->prefixSize())) { + if (H265Frame::isKeyFrame(type, frame->data() + frame->prefixSize())) { insertConfigFrame(frame); VideoTrack::inputFrame(frame); _is_idr = true; return; } - _is_idr = false; //非idr帧 diff --git a/src/Extension/H265.h b/src/Extension/H265.h index 2d1fad49..fe24df3f 100644 --- a/src/Extension/H265.h +++ b/src/Extension/H265.h @@ -61,7 +61,7 @@ public: bool keyFrame() const override; bool configFrame() const override; - static bool isKeyFrame(int type, const char* ptr, uint32_t prefix_size); + static bool isKeyFrame(int type, const char* ptr); protected: friend class FrameImp; diff --git a/src/Extension/H265Rtp.cpp b/src/Extension/H265Rtp.cpp index 0a947a98..c3079313 100644 --- a/src/Extension/H265Rtp.cpp +++ b/src/Extension/H265Rtp.cpp @@ -269,7 +269,7 @@ void H265RtpEncoder::inputFrame(const Frame::Ptr &frame) { //H265 数据 memcpy(payload + 3, ptr + offset, max_size); //输入到rtp环形缓存 - RtpCodec::inputRtp(rtp, fu_start && H265Frame::isKeyFrame(nal_type, frame->data(), frame->prefixSize())); + RtpCodec::inputRtp(rtp, fu_start && H265Frame::isKeyFrame(nal_type, frame->data() + frame->prefixSize())); } offset += max_size; @@ -281,7 +281,7 @@ void H265RtpEncoder::inputFrame(const Frame::Ptr &frame) { } void H265RtpEncoder::makeH265Rtp(int nal_type,const void* data, size_t len, bool mark, bool first_packet, uint32_t uiStamp) { - RtpCodec::inputRtp(makeRtp(getTrackType(),data,len,mark,uiStamp),first_packet && H265Frame::isKeyFrame(nal_type, (const char*)data, prefixSize((const char*)data, len))); + RtpCodec::inputRtp(makeRtp(getTrackType(),data,len,mark,uiStamp),first_packet && H265Frame::isKeyFrame(nal_type, (const char*)data + prefixSize((const char*)data, len))); } }//namespace mediakit