From ba947cb6b530732c153f9f8a21a5b07454d403ab Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 5 Aug 2022 17:42:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4switch=20case=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5=E7=BC=A9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/H264.cpp | 50 +++++++++++++++++++++--------------------- srt/Packet.cpp | 14 ++++-------- webrtc/SrtpSession.cpp | 19 ++++------------ 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/Extension/H264.cpp b/src/Extension/H264.cpp index 94dd3686..3426f5cc 100644 --- a/src/Extension/H264.cpp +++ b/src/Extension/H264.cpp @@ -179,32 +179,32 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame) { int type = H264_TYPE(frame->data()[frame->prefixSize()]); bool ret = true; switch (type) { - case H264Frame::NAL_SPS: { - _sps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize()); - _latest_is_config_frame = 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; - ret = VideoTrack::inputFrame(frame); - break; - } - default: - // 避免识别不出关键帧 - if (_latest_is_config_frame && !frame->dropAble()) { - if (!frame->keyFrame()) { - const_cast(frame) = std::make_shared(frame, true); + case H264Frame::NAL_SPS: { + _sps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize()); + _latest_is_config_frame = 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; + ret = VideoTrack::inputFrame(frame); + break; + } + default: + // 避免识别不出关键帧 + if (_latest_is_config_frame && !frame->dropAble()) { + if (!frame->keyFrame()) { + const_cast(frame) = std::make_shared(frame, true); + } } - } - // 判断是否是I帧, 并且如果是,那判断前面是否插入过config帧, 如果插入过就不插入了 - if (frame->keyFrame() && !_latest_is_config_frame) { - insertConfigFrame(frame); - } - _latest_is_config_frame = false; - ret = VideoTrack::inputFrame(frame); - break; + // 判断是否是I帧, 并且如果是,那判断前面是否插入过config帧, 如果插入过就不插入了 + if (frame->keyFrame() && !_latest_is_config_frame) { + insertConfigFrame(frame); + } + _latest_is_config_frame = false; + ret = VideoTrack::inputFrame(frame); + break; } if (_width == 0 && ready()) { diff --git a/srt/Packet.cpp b/srt/Packet.cpp index 2e4bd8e1..f3649fca 100644 --- a/srt/Packet.cpp +++ b/srt/Packet.cpp @@ -321,16 +321,10 @@ bool HandshakePacket::loadExtMessage(uint8_t *buf, size_t len) { type = loadUint16(ptr); length = loadUint16(ptr + 2); switch (type) { - case HSExt::SRT_CMD_HSREQ: - case HSExt::SRT_CMD_HSRSP: - ext = std::make_shared(); - break; - case HSExt::SRT_CMD_SID: - ext = std::make_shared(); - break; - default: - WarnL << "not support ext " << type; - break; + case HSExt::SRT_CMD_HSREQ: + case HSExt::SRT_CMD_HSRSP: ext = std::make_shared(); break; + case HSExt::SRT_CMD_SID: ext = std::make_shared(); break; + default: WarnL << "not support ext " << type; break; } if (ext) { if (ext->loadFromData(ptr, length * 4 + 4)) { diff --git a/webrtc/SrtpSession.cpp b/webrtc/SrtpSession.cpp index 698b1f7b..8aaa368a 100644 --- a/webrtc/SrtpSession.cpp +++ b/webrtc/SrtpSession.cpp @@ -123,21 +123,10 @@ DepLibSRTP::DepLibSRTP() { err = srtp_install_event_handler([](srtp_event_data_t *data) { MS_TRACE(); switch (data->event) { - case event_ssrc_collision: - MS_WARN_TAG(srtp, "SSRC collision occurred"); - break; - - case event_key_soft_limit: - MS_WARN_TAG(srtp, "stream reached the soft key usage limit and will expire soon"); - break; - - case event_key_hard_limit: - MS_WARN_TAG(srtp, "stream reached the hard key usage limit and has expired"); - break; - - case event_packet_index_limit: - MS_WARN_TAG(srtp, "stream reached the hard packet limit (2^48 packets)"); - break; + case event_ssrc_collision: MS_WARN_TAG(srtp, "SSRC collision occurred"); break; + case event_key_soft_limit: MS_WARN_TAG(srtp, "stream reached the soft key usage limit and will expire soon"); break; + case event_key_hard_limit: MS_WARN_TAG(srtp, "stream reached the hard key usage limit and has expired"); break; + case event_packet_index_limit: MS_WARN_TAG(srtp, "stream reached the hard packet limit (2^48 packets)"); break; } });