拷贝后再修改rtp,防止修改共享数据

This commit is contained in:
xiongziliang
2021-05-08 21:16:51 +08:00
parent 47dc661bb2
commit 60a6d4af0b
4 changed files with 36 additions and 59 deletions

View File

@@ -231,23 +231,11 @@ namespace RTC
}
}
bool SrtpSession::EncryptRtp(const uint8_t** data, size_t* len, uint8_t pt)
bool SrtpSession::EncryptRtp(uint8_t* data, size_t* len)
{
MS_TRACE();
// Ensure that the resulting SRTP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize)
{
MS_WARN_TAG(srtp, "cannot encrypt RTP packet, size too big (%zu bytes)", *len);
return false;
}
std::memcpy(EncryptBuffer, *data, *len);
EncryptBuffer[1] = (pt & 0x7F) | (EncryptBuffer[1] & 0x80);
srtp_err_status_t err =
srtp_protect(this->session, static_cast<void*>(EncryptBuffer), reinterpret_cast<int*>(len));
srtp_protect(this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
if (DepLibSRTP::IsError(err))
{
@@ -256,9 +244,6 @@ namespace RTC
return false;
}
// Update the given data pointer.
*data = (const uint8_t*)EncryptBuffer;
return true;
}
@@ -279,22 +264,11 @@ namespace RTC
return true;
}
bool SrtpSession::EncryptRtcp(const uint8_t** data, size_t* len)
bool SrtpSession::EncryptRtcp(uint8_t* data, size_t* len)
{
MS_TRACE();
// Ensure that the resulting SRTCP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize)
{
MS_WARN_TAG(srtp, "cannot encrypt RTCP packet, size too big (%zu bytes)", *len);
return false;
}
std::memcpy(EncryptBuffer, *data, *len);
srtp_err_status_t err = srtp_protect_rtcp(
this->session, static_cast<void*>(EncryptBuffer), reinterpret_cast<int*>(len));
this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
if (DepLibSRTP::IsError(err))
{
@@ -303,9 +277,6 @@ namespace RTC
return false;
}
// Update the given data pointer.
*data = (const uint8_t*)EncryptBuffer;
return true;
}