From d554ba1c0cb76cc5397f43b4e5d98cfdfbec7862 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 27 Aug 2026 23:05:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebrtc=20sdp=E4=B8=AD?= =?UTF-8?q?=E4=B8=8D=E4=BC=A0=E9=80=92aac=20fmtp=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 72 ++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 8a4096c1..ee9c3a12 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -799,7 +799,7 @@ void RtcSession::loadFrom(const string &str) { rtc_media.fingerprint = sdp.getItemClass('a', "fingerprint"); } rtc_media.ice_lite = media.getItem('a', "ice-lite").operator bool(); - rtc_media.bundle_only = media.getItem('a', "bundle-only").operator bool(); + rtc_media.bundle_only = media.getItem('a', "bundle-only").operator bool(); auto ice_options = media.getItemClass('a', "ice-options"); rtc_media.ice_trickle = ice_options.trickle; rtc_media.ice_renomination = ice_options.renomination; @@ -1651,23 +1651,23 @@ static RtpDirection matchDirection(RtpDirection offer_direction, RtpDirection su } } -static DtlsRole mathDtlsRole(DtlsRole role) { - switch (role) { - case DtlsRole::actpass: - case DtlsRole::active: return DtlsRole::passive; - case DtlsRole::passive: return DtlsRole::active; - default: CHECK(0, "invalid role:", getDtlsRoleString(role)); return DtlsRole::passive; - } -} - -static uint16_t getAnswerMediaPort(const RtcMedia &offer_media) { - // RFC 8843: bundle-only m-lines may use port=0 in the offer but still need a - // real port placeholder in the accepted answer. - if (!offer_media.port && offer_media.bundle_only) { - return 9; - } - return offer_media.port; -} +static DtlsRole mathDtlsRole(DtlsRole role) { + switch (role) { + case DtlsRole::actpass: + case DtlsRole::active: return DtlsRole::passive; + case DtlsRole::passive: return DtlsRole::active; + default: CHECK(0, "invalid role:", getDtlsRoleString(role)); return DtlsRole::passive; + } +} + +static uint16_t getAnswerMediaPort(const RtcMedia &offer_media) { + // RFC 8843: bundle-only m-lines may use port=0 in the offer but still need a + // real port placeholder in the accepted answer. + if (!offer_media.port && offer_media.bundle_only) { + return 9; + } + return offer_media.port; +} void RtcConfigure::createMediaOffer(const std::shared_ptr &ret) const { int index = 0; @@ -1834,14 +1834,14 @@ void RtcConfigure::matchMedia(const std::shared_ptr &ret, const RtcM RETRY: - if (offer_media.type == TrackApplication) { - RtcMedia answer_media = offer_media; - answer_media.port = getAnswerMediaPort(offer_media); - answer_media.role = mathDtlsRole(offer_media.role); - answer_media.ice_ufrag = configure.ice_ufrag; - answer_media.ice_pwd = configure.ice_pwd; - answer_media.fingerprint = configure.fingerprint; - answer_media.ice_lite = configure.ice_lite; + if (offer_media.type == TrackApplication) { + RtcMedia answer_media = offer_media; + answer_media.port = getAnswerMediaPort(offer_media); + answer_media.role = mathDtlsRole(offer_media.role); + answer_media.ice_ufrag = configure.ice_ufrag; + answer_media.ice_pwd = configure.ice_pwd; + answer_media.fingerprint = configure.fingerprint; + answer_media.ice_lite = configure.ice_lite; #ifdef ENABLE_SCTP answer_media.candidate = configure.candidate; #else @@ -1878,14 +1878,14 @@ RETRY: // All codecs for this media in the offer are not supported continue; } - RtcMedia answer_media; - answer_media.type = offer_media.type; - answer_media.mid = offer_media.mid; - answer_media.proto = offer_media.proto; - answer_media.port = getAnswerMediaPort(offer_media); - answer_media.addr = offer_media.addr; - answer_media.bandwidth = offer_media.bandwidth; - answer_media.rtcp_addr = offer_media.rtcp_addr; + RtcMedia answer_media; + answer_media.type = offer_media.type; + answer_media.mid = offer_media.mid; + answer_media.proto = offer_media.proto; + answer_media.port = getAnswerMediaPort(offer_media); + answer_media.addr = offer_media.addr; + answer_media.bandwidth = offer_media.bandwidth; + answer_media.rtcp_addr = offer_media.rtcp_addr; answer_media.rtcp_mux = offer_media.rtcp_mux && configure.rtcp_mux; answer_media.rtcp_rsize = offer_media.rtcp_rsize && configure.rtcp_rsize; answer_media.ice_trickle = offer_media.ice_trickle && configure.ice_trickle; @@ -2085,6 +2085,10 @@ void RtcConfigure::onSelectPlan(RtcCodecPlan &plan, CodecId codec) const { GET_CONFIG(bool, h264_stap_a, Rtp::kH264StapA); plan.fmtp[kMode] = mode.empty() ? std::to_string(h264_stap_a) : mode; } + if (_rtsp_audio_plan && codec == CodecAAC && getCodecId(_rtsp_audio_plan->codec) == CodecAAC) { + // aac时,设置fmtp + plan.fmtp = _rtsp_audio_plan->fmtp; + } } } // namespace mediakit