Skip to content
Merged
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
16 changes: 15 additions & 1 deletion pkg/synchronizer/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (t *TrackSynchronizer) Initialize(pkt *rtp.Packet) {
t.lastTS = pkt.Timestamp
t.lastPTS = 0
t.lastPTSAdjusted = t.currentPTSOffset
t.logger.Infow("initialized track synchronizer",
"startRTP", t.startRTP,
"currentPTSOffset", t.currentPTSOffset,
)
}

// GetPTS will reset sequence numbers and/or offsets if necessary
Expand All @@ -126,8 +130,18 @@ func (t *TrackSynchronizer) GetPTS(pkt *rtp.Packet) (time.Duration, error) {
pts := t.lastPTS + t.toDuration(ts-t.lastTS)
estimatedPTS := time.Since(t.startTime)
if pts < t.lastPTS || !t.acceptable(pts-estimatedPTS) {
newStartRTP := ts - t.toRTP(estimatedPTS)
t.logger.Infow("correcting PTS",
"TS", ts,
"lastTS", t.lastTS,
"PTS", pts,
"lastPTS", t.lastPTS,
"estimatedPTS", estimatedPTS,
"startRTP", t.startRTP,
"newStartRTP", newStartRTP,
)
pts = estimatedPTS
t.startRTP = ts - t.toRTP(pts)
t.startRTP = newStartRTP
}

if t.shouldAdjustPTS() {
Expand Down
Loading