From 824be6cbd573a068ab2296906dcaece2a09a35e9 Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Wed, 4 Dec 2024 10:46:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9BH264?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=B5=81=E7=BC=BA=E5=B0=91sps=20pps=E5=B8=A7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#4050=20#4047=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ext-codec/H264.cpp | 15 ++++++++++----- ext-codec/H264.h | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ext-codec/H264.cpp b/ext-codec/H264.cpp index 50dcfb22..38c1d9bc 100644 --- a/ext-codec/H264.cpp +++ b/ext-codec/H264.cpp @@ -267,31 +267,32 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame) { switch (type) { case H264Frame::NAL_SPS: { _sps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize()); - _latest_is_config_frame = true; + _latest_is_sps = true; ret = VideoTrack::inputFrame(frame); break; } case H264Frame::NAL_PPS: { _pps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize()); - _latest_is_config_frame = true; + _latest_is_pps = true; ret = VideoTrack::inputFrame(frame); break; } default: // 避免识别不出关键帧 [AUTO-TRANSLATED:8eb84679] // Avoid not being able to recognize keyframes - if (_latest_is_config_frame && !frame->dropAble()) { + if (latestIsConfigFrame() && !frame->dropAble()) { if (!frame->keyFrame()) { const_cast(frame) = std::make_shared(frame, true); } } // 判断是否是I帧, 并且如果是,那判断前面是否插入过config帧, 如果插入过就不插入了 [AUTO-TRANSLATED:40733cd8] // Determine if it is an I frame, and if it is, determine if a config frame has been inserted before, and if it has been inserted, do not insert it - if (frame->keyFrame() && !_latest_is_config_frame) { + if (frame->keyFrame() && !latestIsConfigFrame()) { insertConfigFrame(frame); } if(!frame->dropAble()){ - _latest_is_config_frame = false; + _latest_is_pps = false; + _latest_is_sps = false; } ret = VideoTrack::inputFrame(frame); break; @@ -313,6 +314,10 @@ void H264Track::insertConfigFrame(const Frame::Ptr &frame) { } } +bool H264Track::latestIsConfigFrame(){ + return _latest_is_sps && _latest_is_pps; +} + class H264Sdp : public Sdp { public: H264Sdp(const string &strSPS, const string &strPPS, int payload_type, int bitrate) : Sdp(90000, payload_type) { diff --git a/ext-codec/H264.h b/ext-codec/H264.h index c65c8479..55b6f1ff 100644 --- a/ext-codec/H264.h +++ b/ext-codec/H264.h @@ -146,8 +146,11 @@ private: bool inputFrame_l(const Frame::Ptr &frame); void insertConfigFrame(const Frame::Ptr &frame); + bool latestIsConfigFrame(); + private: - bool _latest_is_config_frame = false; + bool _latest_is_pps = false; + bool _latest_is_sps = false; int _width = 0; int _height = 0; float _fps = 0;