From a84bcec4aa3a960f8bc4a7197a27fae2d1f803fa Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 16 May 2021 20:56:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84rtp=20ext=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 6 ++++-- webrtc/WebRtcTransport.cpp | 41 ++++++++++++++++++++++---------------- webrtc/WebRtcTransport.h | 1 + 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 299655e4..5bd993b3 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1412,7 +1412,8 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){ RtpExtType::csrc_audio_level, RtpExtType::abs_send_time, RtpExtType::transport_cc, - RtpExtType::sdes_mid, + //rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放 + //RtpExtType::sdes_mid, RtpExtType::sdes_rtp_stream_id, RtpExtType::sdes_repaired_rtp_stream_id }; @@ -1425,7 +1426,8 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){ extmap = { RtpExtType::abs_send_time, RtpExtType::transport_cc, - RtpExtType::sdes_mid, + //rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放 + //RtpExtType::sdes_mid, RtpExtType::sdes_rtp_stream_id, RtpExtType::sdes_repaired_rtp_stream_id, RtpExtType::video_timing, diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index d898c31a..5d7b0cdc 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -668,24 +668,30 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) { /////////////////////////////////////////////////////////////////// -static void setExtType(RtpExt &ext, uint8_t tp) {} -static void setExtType(RtpExt &ext, RtpExtType tp) { - ext.setType(tp); -} - -template -static void changeRtpExtId(const RtpHeader *header, const Type &map) { +void WebRtcTransportImp::changeRtpExtId(const RtpHeader *header, bool is_recv, bool is_rtx) const{ auto ext_map = RtpExt::getExtValue(header); for (auto &pr : ext_map) { - auto it = map.find((typename Type::key_type) (pr.first)); - if (it == map.end()) { - WarnL << "未处理的rtp ext, 类型不识别:" << (int) pr.first; - pr.second.clearExt(); - continue; + if (is_recv) { + auto it = _rtp_ext_id_to_type.find(pr.first); + if (it == _rtp_ext_id_to_type.end()) { + WarnL << "接收rtp时,忽略不识别的rtp ext, id=" << (int) pr.first; + pr.second.clearExt(); + continue; + } + pr.second.setType(it->second); + //重新赋值ext id为 ext type,作为后面处理ext的统一中间类型 + pr.second.setExtId((uint8_t) it->second); + } else { + pr.second.setType((RtpExtType) pr.first); + auto it = _rtp_ext_type_to_id.find((RtpExtType) pr.first); + if (it == _rtp_ext_type_to_id.end()) { + WarnL << "发送rtp时, 忽略不被客户端支持rtp ext:" << pr.second.dumpString(); + pr.second.clearExt(); + continue; + } + //重新赋值ext id为客户端sdp声明的类型 + pr.second.setExtId(it->second); } - setExtType(pr.second, it->first); - setExtType(pr.second, it->second); - pr.second.setExtId((uint8_t) it->second); } } @@ -726,7 +732,7 @@ void WebRtcTransportImp::onRtp_l(const char *buf, size_t len, bool rtx) { info->rtcp_context_recv->onRtp(seq, stamp_ms, len); } //修改ext id至统一 - changeRtpExtId(rtp, _rtp_ext_id_to_type); + changeRtpExtId(rtp, true); //解析并排序rtp info->receiver->inputRtp(info->media->type, info->plan_rtp->sample_rate, (uint8_t *) buf, len); return; @@ -808,14 +814,15 @@ void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool r void WebRtcTransportImp::onBeforeEncryptRtp(const char *buf, size_t &len, void *ctx) { auto pr = (pair *) ctx; auto header = (RtpHeader *) buf; - changeRtpExtId(header, _rtp_ext_type_to_id); if (!pr->first || !pr->second->plan_rtx) { //普通的rtp,或者不支持rtx, 修改目标pt和ssrc + changeRtpExtId(header, false, false); header->pt = pr->second->plan_rtp->pt; header->ssrc = htonl(pr->second->answer_ssrc_rtp); } else { //重传的rtp, rtx + changeRtpExtId(header, false, true); header->pt = pr->second->plan_rtx->pt; if (pr->second->answer_ssrc_rtx) { //有rtx单独的ssrc,有些情况下,浏览器支持rtx,但是未指定rtx单独的ssrc diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index 11544eb6..7ed7b9dc 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -338,6 +338,7 @@ private: SdpAttrCandidate::Ptr getIceCandidate() const; bool canSendRtp() const; bool canRecvRtp() const; + void changeRtpExtId(const RtpHeader *header, bool is_recv, bool is_rtx = false) const; class RtpPayloadInfo { public: