From dc485c6211ef7fe20f69c855ffe66f98f354ac88 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 2 Apr 2021 21:08:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A0=B9=E6=8D=AE=E6=83=85?= =?UTF-8?q?=E5=86=B5=E9=80=89=E6=8B=A9=E6=98=AF=E5=90=A6=E5=8F=91=E7=94=9F?= =?UTF-8?q?rtp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/DtlsTransport.hpp | 2 +- webrtc/SrtpSession.hpp | 2 +- webrtc/WebRtcTransport.cpp | 35 +++++++++++++++-------------------- webrtc/WebRtcTransport.h | 3 ++- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/webrtc/DtlsTransport.hpp b/webrtc/DtlsTransport.hpp index b3fa244e..41fa4c09 100644 --- a/webrtc/DtlsTransport.hpp +++ b/webrtc/DtlsTransport.hpp @@ -228,7 +228,7 @@ namespace RTC bool handshakeDoneNow{ false }; std::string remoteCert; //最大不超过mtu - static constexpr int SslReadBufferSize{ 1600 }; + static constexpr int SslReadBufferSize{ 2000 }; uint8_t sslReadBuffer[SslReadBufferSize]; }; } // namespace RTC diff --git a/webrtc/SrtpSession.hpp b/webrtc/SrtpSession.hpp index fb21ea9f..c601ca69 100644 --- a/webrtc/SrtpSession.hpp +++ b/webrtc/SrtpSession.hpp @@ -59,7 +59,7 @@ namespace RTC // Allocated by this. srtp_t session{ nullptr }; //rtp包最大1600 - static constexpr size_t EncryptBufferSize{ 1600 }; + static constexpr size_t EncryptBufferSize{ 2000 }; uint8_t EncryptBuffer[EncryptBufferSize]; DepLibSRTP::Ptr _env; }; diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index e79e8516..e35381c6 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -226,23 +226,17 @@ void WebRtcTransportImp::onStartWebRTC() { }); } -uint8_t WebRtcTransportImp::getSendPayloadType(TrackType type) { - for (auto &m : getSdp(SdpType::answer).media) { - if (m.type == type) { - return m.plan[0].pt; - } - } - return 0; -} - void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){ - //需要修改pt - if (rtp->type == TrackVideo) { - rtp->getHeader()->pt = getSendPayloadType(rtp->type); - sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush); - } else { - + if (!_send_rtp_pt[rtp->type]) { + //忽略,对方不支持该编码类型 + return; } + auto tmp = rtp->getHeader()->pt; + //设置pt + rtp->getHeader()->pt = _send_rtp_pt[rtp->type]; + sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush); + //还原pt + rtp->getHeader()->pt = tmp; } bool WebRtcTransportImp::canSendRtp() const{ @@ -250,7 +244,6 @@ bool WebRtcTransportImp::canSendRtp() const{ return sdp.media[0].direction == RtpDirection::sendrecv || sdp.media[0].direction == RtpDirection::sendonly; } - void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{ WebRtcTransport::onCheckSdp(type, sdp); if (type != SdpType::answer || !canSendRtp()) { @@ -263,19 +256,21 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{ } m.rtp_ssrc.ssrc = _src->getSsrc(m.type); m.rtp_ssrc.cname = "zlmediakit-rtc"; + auto rtsp_media = _rtsp_send_sdp.getMedia(m.type); + if (rtsp_media && getCodecId(rtsp_media->plan[0].codec) == getCodecId(m.plan[0].codec)) { + _send_rtp_pt[m.type] = m.plan[0].pt; + } } } void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const { WebRtcTransport::onRtcConfigure(configure); - - RtcSession sdp; - sdp.loadFrom(_src->getSdp(), false); + _rtsp_send_sdp.loadFrom(_src->getSdp(), false); configure.audio.enable = false; configure.video.enable = false; - for (auto &m : sdp.media) { + for (auto &m : _rtsp_send_sdp.media) { switch (m.type) { case TrackVideo: { configure.video.enable = true; diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index ed8d357a..441be5db 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -127,7 +127,6 @@ private: void onDestory() override; void onSendRtp(const RtpPacket::Ptr &rtp, bool flush); SdpAttrCandidate::Ptr getIceCandidate() const; - uint8_t getSendPayloadType(TrackType type); bool canSendRtp() const; private: @@ -135,6 +134,8 @@ private: RtspMediaSource::Ptr _src; RtspMediaSource::RingType::RingReader::Ptr _reader; RtcSession _answer_sdp; + mutable RtcSession _rtsp_send_sdp; + mutable uint8_t _send_rtp_pt[2] = {0, 0}; };