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: