Handle large jumps in RTCP sender report timestamp. (#2674)
* Handle large jumps in RTCP sender report timestamp. Seeing cases of RTCP Sender Report spaced apart by more than half the RTP Timestamp range. Maybe a case of laptop going to sleep and waking up. Handle it using time diff from last report and calculating expected timestamp. * try go 1.22
This commit is contained in:
@@ -17,9 +17,9 @@ name: Test
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -35,7 +35,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: "1.21"
|
go-version: "1.22"
|
||||||
|
|
||||||
- name: Set up gotestfmt
|
- name: Set up gotestfmt
|
||||||
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@v2.4.1
|
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@v2.4.1
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ const (
|
|||||||
cPropagationDelayDeltaHighResetNumReports = 2
|
cPropagationDelayDeltaHighResetNumReports = 2
|
||||||
cPropagationDelayDeltaHighResetWait = 10 * time.Second
|
cPropagationDelayDeltaHighResetWait = 10 * time.Second
|
||||||
cPropagationDelayDeltaLongTermAdaptationThreshold = 50 * time.Millisecond
|
cPropagationDelayDeltaLongTermAdaptationThreshold = 50 * time.Millisecond
|
||||||
|
|
||||||
|
// number of seconds the current report RTP timestamp can be off from expected RTP timestamp
|
||||||
|
cReportSlack = float64(60.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
type RTPFlowState struct {
|
type RTPFlowState struct {
|
||||||
@@ -295,14 +298,38 @@ func (r *RTPStatsReceiver) SetRtcpSenderReportData(srData *RTCPSenderReportData)
|
|||||||
|
|
||||||
tsCycles := uint64(0)
|
tsCycles := uint64(0)
|
||||||
if r.srNewest != nil {
|
if r.srNewest != nil {
|
||||||
tsCycles = r.srNewest.RTPTimestampExt & 0xFFFF_FFFF_0000_0000
|
// use time since last sender report to ensure long gaps where the time stamp might
|
||||||
if (srData.RTPTimestamp-r.srNewest.RTPTimestamp) < (1<<31) && srData.RTPTimestamp < r.srNewest.RTPTimestamp {
|
// jump more than half the range
|
||||||
tsCycles += (1 << 32)
|
timeSinceLastReport := srData.NTPTimestamp.Time().Sub(r.srNewest.NTPTimestamp.Time())
|
||||||
}
|
expectedRTPTimestampExt := r.srNewest.RTPTimestampExt + uint64(timeSinceLastReport.Nanoseconds()*int64(r.params.ClockRate)/1e9)
|
||||||
|
lbound := expectedRTPTimestampExt - uint64(cReportSlack*float64(r.params.ClockRate))
|
||||||
|
ubound := expectedRTPTimestampExt + uint64(cReportSlack*float64(r.params.ClockRate))
|
||||||
|
isInRange := (srData.RTPTimestamp-uint32(lbound) < (1 << 31)) && (uint32(ubound)-srData.RTPTimestamp < (1 << 31))
|
||||||
|
if isInRange {
|
||||||
|
lbTSCycles := lbound & 0xFFFF_FFFF_0000_0000
|
||||||
|
ubTSCycles := ubound & 0xFFFF_FFFF_0000_0000
|
||||||
|
if lbTSCycles == ubTSCycles {
|
||||||
|
tsCycles = lbTSCycles
|
||||||
|
} else {
|
||||||
|
if srData.RTPTimestamp < (1 << 31) {
|
||||||
|
// rolled over
|
||||||
|
tsCycles = ubTSCycles
|
||||||
|
} else {
|
||||||
|
tsCycles = lbTSCycles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// ideally this method should not be required, but there are clients
|
||||||
|
// negotiating one clock rate, but actually send media at a different rate.
|
||||||
|
tsCycles = r.srNewest.RTPTimestampExt & 0xFFFF_FFFF_0000_0000
|
||||||
|
if (srData.RTPTimestamp-r.srNewest.RTPTimestamp) < (1<<31) && srData.RTPTimestamp < r.srNewest.RTPTimestamp {
|
||||||
|
tsCycles += (1 << 32)
|
||||||
|
}
|
||||||
|
|
||||||
if tsCycles >= (1 << 32) {
|
if tsCycles >= (1 << 32) {
|
||||||
if (srData.RTPTimestamp-r.srNewest.RTPTimestamp) >= (1<<31) && srData.RTPTimestamp > r.srNewest.RTPTimestamp {
|
if (srData.RTPTimestamp-r.srNewest.RTPTimestamp) >= (1<<31) && srData.RTPTimestamp > r.srNewest.RTPTimestamp {
|
||||||
tsCycles -= (1 << 32)
|
tsCycles -= (1 << 32)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user