Experimental flag to try time stamp adjustment to control drift. (#1687)
* Experimental flag to try time stamp adjustment to control drift. There is a config to enable this. Using a PID controller to try and keep the sample rate at expected value. Need to be seen if this works well. Adjustment are limited to 25 ms max at a time to ensure there are no large jumps. And it is applied when doing RTCP sender report which happens once in 5 seconds currently for both audio and video tracks. A nice introduction to PID controllers - https://alphaville.github.io/qub/pid-101/#/ Implementation borrowed from - https://github.com/pms67/PID A few things TODO 1. PID controller tuning is a process. Have picked values from test from that implementation above. May not be the best. Need to try. 2. Can potentially run this more often. Rather than running it only when running RTCP sender report (which is once in 5 seconds now), can potentially run it every second and limit the amount of change to something like 10 ms max. * remove unused variable * debug log a bit more
This commit is contained in:
@@ -494,9 +494,11 @@ func (s *StreamTrackerManager) GetReferenceLayerRTPTimestamp(ts uint32, layer in
|
||||
return 0, fmt.Errorf("invalid layer, target: %d, reference: %d", layer, referenceLayer)
|
||||
}
|
||||
|
||||
/* TODO-RESTORE-AFTER-DEBUG - this is just fast path, below calculations should yield same
|
||||
if layer == referenceLayer {
|
||||
return ts, nil
|
||||
}
|
||||
*/
|
||||
|
||||
var srLayer *buffer.RTCPSenderReportData
|
||||
if int(layer) < len(s.senderReports) {
|
||||
@@ -521,6 +523,20 @@ func (s *StreamTrackerManager) GetReferenceLayerRTPTimestamp(ts uint32, layer in
|
||||
ntpDiff := srRef.NTPTimestamp.Time().Sub(srLayer.NTPTimestamp.Time())
|
||||
rtpDiff := ntpDiff.Nanoseconds() * int64(s.clockRate) / 1e9
|
||||
normalizedTS := srLayer.RTPTimestamp + uint32(rtpDiff)
|
||||
s.logger.Debugw(
|
||||
"getting reference timestaml",
|
||||
"layer", layer,
|
||||
"referenceLayer", referenceLayer,
|
||||
"incomingTS", ts,
|
||||
"layerNTP", srLayer.NTPTimestamp.Time().String(),
|
||||
"refNTP", srRef.NTPTimestamp.Time().String(),
|
||||
"ntpDiff", ntpDiff.String(),
|
||||
"layerRTP", srLayer.RTPTimestamp,
|
||||
"refRTP", srRef.RTPTimestamp,
|
||||
"rtpDiff", rtpDiff,
|
||||
"normalizedTS", normalizedTS,
|
||||
"mappedTS", ts+(srRef.RTPTimestamp-normalizedTS),
|
||||
)
|
||||
|
||||
// now that both RTP timestamps correspond to roughly the same NTP time,
|
||||
// the diff between them is the offset in RTP timestamp units between layer and referenceLayer.
|
||||
|
||||
Reference in New Issue
Block a user