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: Twcc wraparound uint16 promotion case #2101

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/source/PeerConnection/PeerConnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ static STATUS twccRollingWindowDeletion(PKvsPeerConnection pKvsPeerConnection, P
}
// reset before next iteration
tempTwccRtpPktInfo = NULL;
} while (!isCheckComplete && updatedSeqNum != (endingSeqNum + 1));
} while (!isCheckComplete && updatedSeqNum != (UINT16) (endingSeqNum + 1));

// Update regardless. The loop checks until current RTP packets seq number irrespective of the failure
pKvsPeerConnection->pTwccManager->firstSeqNumInRollingWindow = updatedSeqNum;
Expand Down
2 changes: 1 addition & 1 deletion src/source/PeerConnection/Rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ STATUS updateTwccHashTable(PTwccManager pTwccManager, PINT64 duration, PUINT64 r
// We also check for twcc->lastReportedSeqNum + 1 to include the last seq number in the
// report. Without this, we do not check for the seqNum that could cause it to not be cleared
// from memory
for (seqNum = baseSeqNum; seqNum != (pTwccManager->lastReportedSeqNum + 1); seqNum++) {
for (seqNum = baseSeqNum; seqNum != (UINT16) (pTwccManager->lastReportedSeqNum + 1); seqNum++) {
if (!localStartTimeRecorded) {
// This could happen if the prev packet was deleted as part of rolling window or if there
// is an overlap of RTP packet statuses between TWCC packets. This could also fail if it is
Expand Down
38 changes: 38 additions & 0 deletions tst/RtcpFunctionalityTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,44 @@ TEST_F(RtcpFunctionalityTest, updateTwccHashTableTest)
EXPECT_EQ(STATUS_SUCCESS, freePeerConnection(&pRtcPeerConnection));
}

TEST_F(RtcpFunctionalityTest, updateTwccHashTableIntPromotionCase) {
PRtcPeerConnection pRtcPeerConnection = NULL;
PKvsPeerConnection pKvsPeerConnection = NULL;
RtcConfiguration config{};
EXPECT_EQ(STATUS_SUCCESS, createPeerConnection(&config, &pRtcPeerConnection));
pKvsPeerConnection = reinterpret_cast<PKvsPeerConnection>(pRtcPeerConnection);
PTwccRtpPacketInfo pTwccRtpPacketInfo = NULL;
INT64 duration = 0;
UINT64 receivedBytes = 0, receivedPackets = 0, sentBytes = 0, sentPackets = 0;
UINT16 i;

// Grab the hash table
PHashTable pTwccRtpPktInfosHashTable = pKvsPeerConnection->pTwccManager->pTwccRtpPktInfosHashTable;
UINT16 hashTableInsertionCount = 0;

// Set up the hash table
pKvsPeerConnection->pTwccManager->prevReportedBaseSeqNum = UINT16_MAX;
pKvsPeerConnection->pTwccManager->lastReportedSeqNum = UINT16_MAX;

// Add packet at UINT16_MAX
pTwccRtpPacketInfo = (PTwccRtpPacketInfo) MEMCALLOC(1, SIZEOF(TwccRtpPacketInfo));
EXPECT_EQ(STATUS_SUCCESS, hashTableUpsert(pTwccRtpPktInfosHashTable, UINT16_MAX, (UINT64) pTwccRtpPacketInfo));
hashTableInsertionCount++;

// Even though pTwccManager->lastReportedSeqNum is a UINT16, (pTwccManager->lastReportedSeqNum + 1) can get
// promoted to an int (32) when pTwccManager->lastReportedSeqNum == UINT16_MAX
EXPECT_EQ(STATUS_SUCCESS, updateTwccHashTable(pKvsPeerConnection->pTwccManager, &duration,
&receivedBytes, &receivedPackets,
&sentBytes, &sentPackets));

EXPECT_EQ(0, pTwccRtpPktInfosHashTable->itemCount); // Ensure the table is cleared again

MUTEX_LOCK(pKvsPeerConnection->twccLock);
MUTEX_UNLOCK(pKvsPeerConnection->twccLock);

EXPECT_EQ(STATUS_SUCCESS, freePeerConnection(&pRtcPeerConnection));
}

} // namespace webrtcclient
} // namespace video
} // namespace kinesis
Expand Down
Loading