Skip to content

Commit

Permalink
Fix incorrect RTP timestamp in RTCP SR
Browse files Browse the repository at this point in the history
Changes:
  * Add unit test CONVERT_TIMESTAMP_TO_RTP with math operations
  * Add parentheses in CONVERT_TIMESTAMP_TO_RTP parameters
  • Loading branch information
lherman-cs committed Nov 11, 2020
1 parent b5ee7ac commit 8a64e7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/source/PeerConnection/Rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ STATUS freeKvsRtpTransceiver(PKvsRtpTransceiver*);

STATUS kvsRtpTransceiverSetJitterBuffer(PKvsRtpTransceiver, PJitterBuffer);

#define CONVERT_TIMESTAMP_TO_RTP(clockRate, pts) ((UINT64)((DOUBLE) pts * ((DOUBLE) clockRate / HUNDREDS_OF_NANOS_IN_A_SECOND)))
#define CONVERT_TIMESTAMP_TO_RTP(clockRate, pts) ((UINT64)((DOUBLE)(pts) * ((DOUBLE)(clockRate) / HUNDREDS_OF_NANOS_IN_A_SECOND)))

STATUS writeRtpPacket(PKvsPeerConnection pKvsPeerConnection, PRtpPacket pRtpPacket);

Expand Down
9 changes: 9 additions & 0 deletions tst/PeerConnectionApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ TEST_F(PeerConnectionApiTest, CONVERT_TIMESTAMP_TO_RTP_BigTimestamp)
EXPECT_EQ(144312782076270, rtpTimestamp);
}

TEST_F(PeerConnectionApiTest, CONVERT_TIMESTAMP_TO_RTP_MacroWithMathOperations)
{
UINT64 rtpTimestamp = CONVERT_TIMESTAMP_TO_RTP(40000 + 50000, HUNDREDS_OF_NANOS_IN_A_SECOND);
EXPECT_EQ(90000, rtpTimestamp);

This comment has been minimized.

Copy link
@suggestedfixes

suggestedfixes Nov 11, 2020

Contributor

Because of different floating point precision and formats, EXPECT_EQ can be flaky in different architectures, a better check would be something like approximately equal.

This comment has been minimized.

Copy link
@MushMal

MushMal Nov 11, 2020

Contributor

In this particular case it shouldn't really matter due to no hardware-specific loss of precision. If this really proves to be an issue, a cast to UINT64 can be done.

This comment has been minimized.

Copy link
@suggestedfixes

suggestedfixes Nov 16, 2020

Contributor

Just an example, because of binary precision or some odd choice of the mantissa bit length, some floating-point architecture can compute this value to be 89999.999???, and truncate this conversion to become 89999. Maybe there is a standard for C floating point standard?.


rtpTimestamp = CONVERT_TIMESTAMP_TO_RTP(90000, HUNDREDS_OF_NANOS_IN_A_SECOND + HUNDREDS_OF_NANOS_IN_A_SECOND);
EXPECT_EQ(180000, rtpTimestamp);
}

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

0 comments on commit 8a64e7f

Please sign in to comment.