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; }