From c70721a520d8948d420e1dd9ab40e9cbc2d6b3c8 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 4 Apr 2021 21:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9rtp=20pt=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E4=B8=8D=E5=BD=B1=E5=93=8D=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/SrtpSession.cpp | 3 ++- webrtc/SrtpSession.hpp | 2 +- webrtc/WebRtcTransport.cpp | 16 ++++++---------- webrtc/WebRtcTransport.h | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/webrtc/SrtpSession.cpp b/webrtc/SrtpSession.cpp index a970fd7c..64c1bca0 100644 --- a/webrtc/SrtpSession.cpp +++ b/webrtc/SrtpSession.cpp @@ -213,7 +213,7 @@ namespace RTC } } - bool SrtpSession::EncryptRtp(const uint8_t** data, size_t* len) + bool SrtpSession::EncryptRtp(const uint8_t** data, size_t* len, uint8_t pt) { MS_TRACE(); @@ -226,6 +226,7 @@ namespace RTC } std::memcpy(EncryptBuffer, *data, *len); + EncryptBuffer[1] |= (pt & 0x7F); srtp_err_status_t err = srtp_protect(this->session, static_cast(EncryptBuffer), reinterpret_cast(len)); diff --git a/webrtc/SrtpSession.hpp b/webrtc/SrtpSession.hpp index c601ca69..5b3edefd 100644 --- a/webrtc/SrtpSession.hpp +++ b/webrtc/SrtpSession.hpp @@ -46,7 +46,7 @@ namespace RTC ~SrtpSession(); public: - bool EncryptRtp(const uint8_t** data, size_t* len); + bool EncryptRtp(const uint8_t** data, size_t* len, uint8_t pt); bool DecryptSrtp(uint8_t* data, size_t* len); bool EncryptRtcp(const uint8_t** data, size_t* len); bool DecryptSrtcp(uint8_t* data, size_t* len); diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 23dc13e0..9920157e 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -179,11 +179,11 @@ void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple * } } -void WebRtcTransport::sendRtpPacket(char *buf, size_t len, bool flush) { +void WebRtcTransport::sendRtpPacket(char *buf, size_t len, bool flush, uint8_t pt) { const uint8_t *p = (uint8_t *) buf; bool ret = false; if (_srtp_session_send) { - ret = _srtp_session_send->EncryptRtp(&p, &len); + ret = _srtp_session_send->EncryptRtp(&p, &len, pt); } if (ret) { onSendSockData((char *) p, len, flush); @@ -467,16 +467,12 @@ void WebRtcTransportImp::onBeforeSortedRtp(const RtpPayloadInfo &info, const Rtp } void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){ - if (!_send_rtp_pt[rtp->type]) { + auto &pt = _send_rtp_pt[rtp->type]; + if (!pt) { //忽略,对方不支持该编码类型 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); + sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush, pt); //统计rtp发送情况,好做sr汇报 - _rtp_receiver[_send_rtp_pt[rtp->type]].rtcp_context_send->onRtp(rtp->getSeq(), rtp->getStampMS(), rtp->size() - RtpPacket::kRtpTcpHeaderSize); - //还原pt - rtp->getHeader()->pt = tmp; + _rtp_receiver[pt].rtcp_context_send->onRtp(rtp->getSeq(), rtp->getStampMS(), rtp->size() - RtpPacket::kRtpTcpHeaderSize); } diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index f8d4f6b7..3495fe84 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -45,7 +45,7 @@ public: * @param buf rtcp内容 * @param len rtcp长度 */ - void sendRtpPacket(char *buf, size_t len, bool flush); + void sendRtpPacket(char *buf, size_t len, bool flush, uint8_t pt); void sendRtcpPacket(char *buf, size_t len, bool flush); protected: