Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix key frame #394

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/transport/SrtpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,31 @@ TEST_F(SrtpTest, muteUntilRoc1)
}
}

// sequence number starts close to 65535 and all packets with roc = 0 are lost.
// First packet seen is on ROC 1 already
TEST_F(SrtpTest, unprotect1st)
{
setupDtls();
connect();

uint32_t roc = 0;

auto packet = memory::makeUniquePacket(_allocator, _audioPacket);
auto header = rtp::RtpHeader::fromPacket(*packet);
header->ssrc = 1;
header->sequenceNumber = 670;
header->timestamp = 160;
const auto audioPacketLength = packet->getLength();
const auto packetCopy = memory::makeUniquePacket(_allocator, *packet);

ASSERT_TRUE(_srtp1->protect(*packet));

ASSERT_TRUE(_srtp2->unprotectFirstRtp(*packet, roc));
EXPECT_EQ(roc, 0);
ASSERT_TRUE(packet->getLength() == audioPacketLength);
EXPECT_EQ(0, std::memcmp(packet->get(), packetCopy->get(), packetCopy->getLength()));
}

// sequence number starts close to 65535 and all packets with roc = 0 are lost.
// First packet seen is on ROC 1 already
TEST_F(SrtpTest, losePacketsBeforeRoc1)
Expand All @@ -573,6 +598,7 @@ TEST_F(SrtpTest, losePacketsBeforeRoc1)
header->ssrc = 1;
header->sequenceNumber = i & 0xFFFFu;
header->timestamp = i * 160;
const auto audioPacketLength = packet->getLength();

ASSERT_TRUE(_srtp1->protect(*packet));
const uint32_t continuationPoint = 65550;
Expand All @@ -594,6 +620,7 @@ TEST_F(SrtpTest, losePacketsBeforeRoc1)
EXPECT_EQ(roc, 1);
unprotectedExtSeqNo = i;
++unprotectCount;
ASSERT_TRUE(packet->getLength() == audioPacketLength);
}
}
EXPECT_EQ(unprotectedExtSeqNo, 65600);
Expand Down
4 changes: 3 additions & 1 deletion transport/dtls/SrtpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ bool SrtpClient::unprotectFirstRtp(memory::Packet& packet, uint32_t& rolloverCou
const auto result = srtp_unprotect(_remoteSrtp, packet.get(), &bufferLength);
if (result == srtp_err_status_ok)
{
packet.setLength(utils::checkedCast<size_t>(bufferLength));
return true;
}

Expand All @@ -936,8 +937,8 @@ bool SrtpClient::unprotectFirstRtp(memory::Packet& packet, uint32_t& rolloverCou
assert(false);
return false;
}
const uint32_t ssrc = header->ssrc;

const uint32_t ssrc = header->ssrc;
{
// use remote srtp context to fake a packet with ROC=0
alignas(sizeof(uint32_t)) uint8_t fakePacketRoc0[40]{0};
Expand Down Expand Up @@ -972,6 +973,7 @@ bool SrtpClient::unprotectFirstRtp(memory::Packet& packet, uint32_t& rolloverCou

if (srtp_err_status_ok == srtp_unprotect(_remoteSrtp, packet.get(), &bufferLength))
{
packet.setLength(utils::checkedCast<size_t>(bufferLength));
return true;
}
}
Expand Down
Loading