From 204ef6e204b8f8ef630934893c5616cc321d8ce7 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 6 Apr 2021 23:21:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=B9=E9=85=8DH264=20profile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index fc7f2154..81355d0b 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1524,12 +1524,41 @@ void RtcConfigure::setPlayRtspInfo(const string &sdp){ } } +static map toMap(const vector > &fmt) { + map ret; + for (auto &pr : fmt) { + ret.emplace(pr); + } + return ret; +} + +static const string kProfile{"profile-level-id"}; +static const string kMode{"packetization-mode"}; + bool RtcConfigure::onMatchCodecPlan(const RtcCodecPlan &plan, CodecId codec){ if (_rtsp_audio_plan && codec == getCodecId(_rtsp_audio_plan->codec)) { if (plan.sample_rate != _rtsp_audio_plan->sample_rate || plan.channel != _rtsp_audio_plan->channel) { //音频采样率和通道数必须相同 return false; } + return true; } + if (_rtsp_video_plan && codec == CodecH264 && getCodecId(_rtsp_video_plan->codec) == CodecH264) { + //h264时,匹配packetization-mode和profile-level-id + auto rtc_fmt_map = toMap(plan.fmtp); + auto rtsp_fmt_map = toMap(_rtsp_video_plan->fmtp); + auto &profile = rtsp_fmt_map[kProfile]; + if (!profile.empty() && profile != rtc_fmt_map[kProfile]) { + //profile-level-id 不匹配 + return false; + } + auto &mode = rtsp_fmt_map[kMode]; + if (!mode.empty() && mode != rtc_fmt_map[kMode]) { + //packetization-mode不匹配 + return false; + } + return true; + } + return true; }