修改rtp pt时,确保不影响其他播放器

This commit is contained in:
xiongziliang 2021-04-04 21:42:11 +08:00
parent 2abb5078f9
commit c70721a520
4 changed files with 10 additions and 13 deletions

View File

@ -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(); MS_TRACE();
@ -226,6 +226,7 @@ namespace RTC
} }
std::memcpy(EncryptBuffer, *data, *len); std::memcpy(EncryptBuffer, *data, *len);
EncryptBuffer[1] |= (pt & 0x7F);
srtp_err_status_t err = srtp_err_status_t err =
srtp_protect(this->session, static_cast<void*>(EncryptBuffer), reinterpret_cast<int*>(len)); srtp_protect(this->session, static_cast<void*>(EncryptBuffer), reinterpret_cast<int*>(len));

View File

@ -46,7 +46,7 @@ namespace RTC
~SrtpSession(); ~SrtpSession();
public: 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 DecryptSrtp(uint8_t* data, size_t* len);
bool EncryptRtcp(const uint8_t** data, size_t* len); bool EncryptRtcp(const uint8_t** data, size_t* len);
bool DecryptSrtcp(uint8_t* data, size_t* len); bool DecryptSrtcp(uint8_t* data, size_t* len);

View File

@ -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; const uint8_t *p = (uint8_t *) buf;
bool ret = false; bool ret = false;
if (_srtp_session_send) { if (_srtp_session_send) {
ret = _srtp_session_send->EncryptRtp(&p, &len); ret = _srtp_session_send->EncryptRtp(&p, &len, pt);
} }
if (ret) { if (ret) {
onSendSockData((char *) p, len, flush); 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){ 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; return;
} }
auto tmp = rtp->getHeader()->pt; sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush, pt);
//设置pt
rtp->getHeader()->pt = _send_rtp_pt[rtp->type];
sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush);
//统计rtp发送情况好做sr汇报 //统计rtp发送情况好做sr汇报
_rtp_receiver[_send_rtp_pt[rtp->type]].rtcp_context_send->onRtp(rtp->getSeq(), rtp->getStampMS(), rtp->size() - RtpPacket::kRtpTcpHeaderSize); _rtp_receiver[pt].rtcp_context_send->onRtp(rtp->getSeq(), rtp->getStampMS(), rtp->size() - RtpPacket::kRtpTcpHeaderSize);
//还原pt
rtp->getHeader()->pt = tmp;
} }

View File

@ -45,7 +45,7 @@ public:
* @param buf rtcp内容 * @param buf rtcp内容
* @param len 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); void sendRtcpPacket(char *buf, size_t len, bool flush);
protected: protected: