- improve SRTP decoder API

This commit is contained in:
Dmytro Bogovych 2025-08-24 14:01:43 +03:00
parent 6b7b086bf7
commit e6cb2a22f7
4 changed files with 18 additions and 17 deletions

View File

@ -306,18 +306,22 @@ void AudioStream::dataArrived(PDatagramSocket s, const void* buffer, int length,
int receiveLength = length;
memcpy(mReceiveBuffer, buffer, length);
bool srtpResult;
if (mSrtpSession.active())
{
bool srtpResult;
size_t srcLength = length; size_t dstLength = sizeof mSrtpDecodeBuffer;
if (RtpHelper::isRtp(mReceiveBuffer, receiveLength))
srtpResult = mSrtpSession.unprotectRtp(mReceiveBuffer, &receiveLength);
srtpResult = mSrtpSession.unprotectRtp(mReceiveBuffer, srcLength, mSrtpDecodeBuffer, &dstLength);
else
srtpResult = mSrtpSession.unprotectRtcp(mReceiveBuffer, &receiveLength);
srtpResult = mSrtpSession.unprotectRtcp(mReceiveBuffer, srcLength, mSrtpDecodeBuffer, &dstLength);
if (!srtpResult)
{
ICELogError(<<"Cannot decrypt SRTP packet.");
return;
}
memcpy(mReceiveBuffer, mSrtpDecodeBuffer, dstLength);
receiveLength = dstLength;
}
switch (source.family())

View File

@ -87,7 +87,8 @@ protected:
mCaptureResampler32,
mCaptureResampler48;
DtmfContext mDtmfContext;
char mReceiveBuffer[MAX_VALID_UDPPACKET_SIZE];
char mReceiveBuffer[MAX_VALID_UDPPACKET_SIZE],
mSrtpDecodeBuffer[MAX_VALID_UDPPACKET_SIZE];
struct
{

View File

@ -209,36 +209,32 @@ bool SrtpSession::protectRtcp(void* buffer, int* length)
return false;
}
bool SrtpSession::unprotectRtp(void* buffer, int* length)
bool SrtpSession::unprotectRtp(const void* src, size_t srcLength, void* dst, size_t* dstLength)
{
//addSsrc(RtpHelper::findSsrc(buffer, *length), sdIncoming);
Lock l(mGuard);
if (mInboundSession)
{
size_t rtp_len = MAX_VALID_UDPPACKET_SIZE;
auto code = srtp_unprotect(mInboundSession,
(const uint8_t*)buffer, (size_t)*length,
(uint8_t*)buffer, &rtp_len);
*length = rtp_len;
auto code = srtp_unprotect(mInboundSession,
(const uint8_t*)src, srcLength,
(uint8_t*)dst, dstLength);
return code == 0;
}
else
return false;
}
bool SrtpSession::unprotectRtcp(void* buffer, int* length)
bool SrtpSession::unprotectRtcp(const void* src, size_t srcLength, void* dst, size_t* dstLength)
{
//addSsrc(RtpHelper::findSsrc(buffer, *length), sdIncoming);
Lock l(mGuard);
if (mInboundSession)
{
size_t rtp_len = MAX_VALID_UDPPACKET_SIZE;
auto code = srtp_unprotect_rtcp(mInboundSession,
(const uint8_t*)buffer, (size_t)*length,
(uint8_t*)buffer, (size_t*)rtp_len);
*length = rtp_len;
(const uint8_t*)src, srcLength,
(uint8_t*)dst, dstLength);
return code == 0;
}
else

View File

@ -48,8 +48,8 @@ public:
/* bufferPtr is RTP packet data i.e. header + payload. Buffer must be big enough to hold encrypted data. */
bool protectRtp(void* buffer, int* length);
bool protectRtcp(void* buffer, int* length);
bool unprotectRtp(void* buffer, int* length);
bool unprotectRtcp(void* buffer, int* length);
bool unprotectRtp(const void* src, size_t srcLength, void* dst, size_t* dstLength);
bool unprotectRtcp(const void* src, size_t srcLength, void* dst, size_t* dstLength);
static void initSrtp();