Skip to content

Commit

Permalink
rtcpsender: improve precision of NTPTime
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Nov 5, 2022
1 parent ededb49 commit f20350d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions pkg/rtcpsender/rtcpsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ func (rs *RTCPSender) report(ts time.Time) rtcp.Packet {
SSRC: *rs.senderSSRC,
NTPTime: func() uint64 {
// seconds since 1st January 1900
s := (float64(ts.UnixNano()) / 1000000000) + 2208988800

// higher 32 bits are the integer part, lower 32 bits are the fractional part
integerPart := uint32(s)
fractionalPart := uint32((s - float64(integerPart)) * 0xFFFFFFFF)
return uint64(integerPart)<<32 | uint64(fractionalPart)
s := uint64(ts.UnixNano()) + 2208988800*1000000000
return (s/1000000000)<<32 | (s % 1000000000)
}(),
RTPTime: *rs.lastRTPTimeRTP + uint32((ts.Sub(rs.lastRTPTimeTime)).Seconds()*rs.clockRate),
PacketCount: rs.packetCount,
Expand Down
2 changes: 1 addition & 1 deletion pkg/rtcpsender/rtcpsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestRTCPSender(t *testing.T) {
rs := New(250*time.Millisecond, 90000, func(pkt rtcp.Packet) {
require.Equal(t, &rtcp.SenderReport{
SSRC: 0xba9da416,
NTPTime: 0xcbddcc34999997ff,
NTPTime: 14690122083862791680,
RTPTime: 0x4d185ae8,
PacketCount: 3,
OctetCount: 6,
Expand Down

0 comments on commit f20350d

Please sign in to comment.