sfu: add opt-in verbatim abs-capture-time forwarding (#4812)
* sfu: add opt-in verbatim abs-capture-time forwarding Downtrack ACT forwarding gates on an RTCP sender report and unconditionally rewrites the capture timestamp into SFU clock domain, which suits cross-stream A/V sync but breaks consumers that need the original publisher capture time (e.g. end-to-end latency measurement). Add ForwardAbsCaptureTimeVerbatim (RTC config: forward_abs_capture_time_verbatim), off by default, which skips both the gate and the rewrite. * fix: use DisableSenderReportPassThrough setting to also gate abs-capture-time forwarding
This commit is contained in:
+24
-18
@@ -1098,24 +1098,30 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) int32 {
|
|||||||
}
|
}
|
||||||
var actBytes []byte
|
var actBytes []byte
|
||||||
if extPkt.AbsCaptureTimeExt != nil && d.absCaptureTimeExtID != 0 {
|
if extPkt.AbsCaptureTimeExt != nil && d.absCaptureTimeExtID != 0 {
|
||||||
// normalize capture time to SFU clock.
|
if !d.params.DisableSenderReportPassThrough {
|
||||||
// NOTE: even if there is estimated offset populated, just re-map the
|
// pass through the original publisher capture time verbatim, consistent
|
||||||
// absolute capture time stamp as it should be the same RTCP sender report
|
// with sender reports also being passed through unchanged.
|
||||||
// clock domain of publisher. SFU is normalising sender reports of publisher
|
actBytes, err = extPkt.AbsCaptureTimeExt.Marshal()
|
||||||
// to SFU clock before sending to subscribers. So, capture time should be
|
if err == nil {
|
||||||
// normalized to the same clock. Clear out any offset.
|
hdr.SetExtension(uint8(d.absCaptureTimeExtID), actBytes)
|
||||||
_, _, _, refSenderReport := d.forwarder.GetSenderReportParams()
|
}
|
||||||
if refSenderReport != nil {
|
} else {
|
||||||
actExtCopy := *extPkt.AbsCaptureTimeExt
|
// normalize capture time to SFU clock.
|
||||||
if err = actExtCopy.Rewrite(
|
// NOTE: even if there is estimated offset populated, just re-map the
|
||||||
rtpstats.RTCPSenderReportPropagationDelay(
|
// absolute capture time stamp as it should be the same RTCP sender report
|
||||||
refSenderReport,
|
// clock domain of publisher. SFU is normalising sender reports of publisher
|
||||||
!d.params.DisableSenderReportPassThrough,
|
// to SFU clock before sending to subscribers. So, capture time should be
|
||||||
),
|
// normalized to the same clock. Clear out any offset.
|
||||||
); err == nil {
|
_, _, _, refSenderReport := d.forwarder.GetSenderReportParams()
|
||||||
actBytes, err = actExtCopy.Marshal()
|
if refSenderReport != nil {
|
||||||
if err == nil {
|
actExtCopy := *extPkt.AbsCaptureTimeExt
|
||||||
hdr.SetExtension(uint8(d.absCaptureTimeExtID), actBytes)
|
if err = actExtCopy.Rewrite(
|
||||||
|
rtpstats.RTCPSenderReportPropagationDelay(refSenderReport),
|
||||||
|
); err == nil {
|
||||||
|
actBytes, err = actExtCopy.Marshal()
|
||||||
|
if err == nil {
|
||||||
|
hdr.SetExtension(uint8(d.absCaptureTimeExtID), actBytes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,11 +193,7 @@ func (w WrappedRTCPSenderReportStateLogger) MarshalLogObject(e zapcore.ObjectEnc
|
|||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
func RTCPSenderReportPropagationDelay(rsrs *livekit.RTCPSenderReportState, passThrough bool) time.Duration {
|
func RTCPSenderReportPropagationDelay(rsrs *livekit.RTCPSenderReportState) time.Duration {
|
||||||
if passThrough {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return time.Unix(0, rsrs.AtAdjusted).Sub(mediatransportutil.NtpTime(rsrs.NtpTimestamp).Time())
|
return time.Unix(0, rsrs.AtAdjusted).Sub(mediatransportutil.NtpTime(rsrs.NtpTimestamp).Time())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user