Skip to content

Commit 6ac1a41

Browse files
committed
improve documentation
1 parent 0ece753 commit 6ac1a41

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

pkg/ntp/ntp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Package ntp contains functions to encode and decode timestamps to/from NTP format.
1+
// Package ntp contains functions to encode and decode timestamps to/from the NTP format.
22
package ntp
33

44
import (
55
"math"
66
"time"
77
)
88

9-
// Encode encodes a timestamp in NTP format.
9+
// Encode encodes a timestamp in the NTP format.
1010
// Specification: RFC3550, section 4
1111
func Encode(t time.Time) uint64 {
1212
ntp := uint64(t.UnixNano()) + 2208988800*1000000000
@@ -15,7 +15,7 @@ func Encode(t time.Time) uint64 {
1515
return secs<<32 | fractional
1616
}
1717

18-
// Decode decodes a timestamp from NTP format.
18+
// Decode decodes a timestamp from the NTP format.
1919
// Specification: RFC3550, section 4
2020
func Decode(v uint64) time.Time {
2121
secs := int64((v >> 32) - 2208988800)

pkg/rtpreceiver/receiver.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ type Receiver struct {
5151
sequenceNumberCycles uint16
5252
lastValidSeqNum uint16
5353
remoteSSRC uint32
54-
lastTimeRTP uint32
55-
lastTimeSystem time.Time
54+
lastRTP uint32
55+
lastSystem time.Time
5656
totalLost uint32
5757
totalLostSinceReport uint32
5858
totalSinceReport uint32
@@ -195,8 +195,8 @@ func (rr *Receiver) ProcessPacket2(
195195

196196
if ptsEqualsDTS {
197197
rr.timeInitialized = true
198-
rr.lastTimeRTP = pkt.Timestamp
199-
rr.lastTimeSystem = system
198+
rr.lastRTP = pkt.Timestamp
199+
rr.lastSystem = system
200200
}
201201

202202
return []*rtp.Packet{pkt}, 0
@@ -240,17 +240,17 @@ func (rr *Receiver) ProcessPacket2(
240240
if rr.timeInitialized && rr.ClockRate != 0 {
241241
// update jitter
242242
// https://tools.ietf.org/html/rfc3550#page-39
243-
D := system.Sub(rr.lastTimeSystem).Seconds()*float64(rr.ClockRate) -
244-
(float64(pkt.Timestamp) - float64(rr.lastTimeRTP))
243+
D := system.Sub(rr.lastSystem).Seconds()*float64(rr.ClockRate) -
244+
(float64(pkt.Timestamp) - float64(rr.lastRTP))
245245
if D < 0 {
246246
D = -D
247247
}
248248
rr.jitter += (D - rr.jitter) / 16
249249
}
250250

251251
rr.timeInitialized = true
252-
rr.lastTimeRTP = pkt.Timestamp
253-
rr.lastTimeSystem = system
252+
rr.lastRTP = pkt.Timestamp
253+
rr.lastSystem = system
254254
}
255255
}
256256

@@ -404,12 +404,12 @@ func (rr *Receiver) Stats() *Stats {
404404
return nil
405405
}
406406

407-
ntp, _ := rr.packetNTPUnsafe(rr.lastTimeRTP)
407+
ntp, _ := rr.packetNTPUnsafe(rr.lastRTP)
408408

409409
return &Stats{
410410
RemoteSSRC: rr.remoteSSRC,
411411
LastSequenceNumber: rr.lastValidSeqNum,
412-
LastRTP: rr.lastTimeRTP,
412+
LastRTP: rr.lastRTP,
413413
LastNTP: ntp,
414414
Jitter: rr.jitter,
415415
TotalReceived: rr.totalReceived,

pkg/rtpsender/sender.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ type Sender struct {
2424

2525
// data from RTP packets
2626
firstRTPPacketSent bool
27-
lastTimeRTP uint32
28-
lastTimeNTP time.Time
29-
lastTimeSystem time.Time
27+
lastRTP uint32
28+
lastNTP time.Time
29+
lastSystem time.Time
3030
localSSRC uint32
3131
lastSequenceNumber uint16
3232
packetCount uint32
@@ -83,9 +83,9 @@ func (rs *Sender) report() rtcp.Packet {
8383
return nil
8484
}
8585

86-
systemTimeDiff := rs.TimeNow().Sub(rs.lastTimeSystem)
87-
ntpTime := rs.lastTimeNTP.Add(systemTimeDiff)
88-
rtpTime := rs.lastTimeRTP + uint32(systemTimeDiff.Seconds()*float64(rs.ClockRate))
86+
systemDiffDiff := rs.TimeNow().Sub(rs.lastSystem)
87+
ntpTime := rs.lastNTP.Add(systemDiffDiff)
88+
rtpTime := rs.lastRTP + uint32(systemDiffDiff.Seconds()*float64(rs.ClockRate))
8989

9090
return &rtcp.SenderReport{
9191
SSRC: rs.localSSRC,
@@ -103,9 +103,9 @@ func (rs *Sender) ProcessPacket(pkt *rtp.Packet, ntp time.Time, ptsEqualsDTS boo
103103

104104
if ptsEqualsDTS {
105105
rs.firstRTPPacketSent = true
106-
rs.lastTimeRTP = pkt.Timestamp
107-
rs.lastTimeNTP = ntp
108-
rs.lastTimeSystem = rs.TimeNow()
106+
rs.lastRTP = pkt.Timestamp
107+
rs.lastNTP = ntp
108+
rs.lastSystem = rs.TimeNow()
109109
rs.localSSRC = pkt.SSRC
110110
}
111111

@@ -135,8 +135,8 @@ func (rs *Sender) Stats() *Stats {
135135

136136
return &Stats{
137137
LastSequenceNumber: rs.lastSequenceNumber,
138-
LastRTP: rs.lastTimeRTP,
139-
LastNTP: rs.lastTimeNTP,
138+
LastRTP: rs.lastRTP,
139+
LastNTP: rs.lastNTP,
140140
TotalSent: rs.packetCount2,
141141
}
142142
}

pkg/rtptime/global_decoder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type GlobalDecoderTrack interface {
3939
type GlobalDecoder struct {
4040
mutex sync.Mutex
4141
leadingTrack GlobalDecoderTrack
42-
startNTP time.Time
42+
startSystem time.Time
4343
startPTS int64
4444
startPTSClockRate int64
4545
tracks map[GlobalDecoderTrack]*globalDecoderTrackData
@@ -74,14 +74,14 @@ func (d *GlobalDecoder) Decode(
7474

7575
if d.leadingTrack == nil {
7676
d.leadingTrack = track
77-
d.startNTP = now
77+
d.startSystem = now
7878
d.startPTS = 0
7979
d.startPTSClockRate = int64(track.ClockRate())
8080
}
8181

8282
// start from the PTS of the leading track
8383
startPTS := multiplyAndDivide(d.startPTS, int64(track.ClockRate()), d.startPTSClockRate)
84-
startPTS += multiplyAndDivide(int64(now.Sub(d.startNTP)), int64(track.ClockRate()), int64(time.Second))
84+
startPTS += multiplyAndDivide(int64(now.Sub(d.startSystem)), int64(track.ClockRate()), int64(time.Second))
8585

8686
d.tracks[track] = &globalDecoderTrackData{
8787
overall: startPTS,
@@ -93,10 +93,10 @@ func (d *GlobalDecoder) Decode(
9393

9494
pts := df.decode(pkt.Timestamp)
9595

96-
// update startNTP / startPTS
96+
// update startSystem / startPTS
9797
if d.leadingTrack == track && track.PTSEqualsDTS(pkt) {
9898
now := timeNow()
99-
d.startNTP = now
99+
d.startSystem = now
100100
d.startPTS = pts
101101
}
102102

0 commit comments

Comments
 (0)