mirror of
https://github.com/livekit/livekit.git
synced 2026-11-23 02:29:22 +00:00
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:
1 parent
502346df00
commit
f07dd913e9
2 files changed
+25
-23
No files matched your search
+24
-18
@@ -1098,24 +1098,30 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) int32 {
|
||||
}
|
||||
var actBytes []byte
|
||||
if extPkt.AbsCaptureTimeExt != nil && d.absCaptureTimeExtID != 0 {
|
||||
// normalize capture time to SFU clock.
|
||||
// NOTE: even if there is estimated offset populated, just re-map the
|
||||
// absolute capture time stamp as it should be the same RTCP sender report
|
||||
// clock domain of publisher. SFU is normalising sender reports of publisher
|
||||
// to SFU clock before sending to subscribers. So, capture time should be
|
||||
// normalized to the same clock. Clear out any offset.
|
||||
_, _, _, refSenderReport := d.forwarder.GetSenderReportParams()
|
||||
if refSenderReport != nil {
|
||||
actExtCopy := *extPkt.AbsCaptureTimeExt
|
||||
if err = actExtCopy.Rewrite(
|
||||
rtpstats.RTCPSenderReportPropagationDelay(
|
||||
refSenderReport,
|
||||
!d.params.DisableSenderReportPassThrough,
|
||||
),
|
||||
); err == nil {
|
||||
actBytes, err = actExtCopy.Marshal()
|
||||
if err == nil {
|
||||
hdr.SetExtension(uint8(d.absCaptureTimeExtID), actBytes)
|
||||
if !d.params.DisableSenderReportPassThrough {
|
||||
// pass through the original publisher capture time verbatim, consistent
|
||||
// with sender reports also being passed through unchanged.
|
||||
actBytes, err = extPkt.AbsCaptureTimeExt.Marshal()
|
||||
if err == nil {
|
||||
hdr.SetExtension(uint8(d.absCaptureTimeExtID), actBytes)
|
||||
}
|
||||
} else {
|
||||
// normalize capture time to SFU clock.
|
||||
// NOTE: even if there is estimated offset populated, just re-map the
|
||||
// absolute capture time stamp as it should be the same RTCP sender report
|
||||
// clock domain of publisher. SFU is normalising sender reports of publisher
|
||||
// to SFU clock before sending to subscribers. So, capture time should be
|
||||
// normalized to the same clock. Clear out any offset.
|
||||
_, _, _, refSenderReport := d.forwarder.GetSenderReportParams()
|
||||
if refSenderReport != nil {
|
||||
actExtCopy := *extPkt.AbsCaptureTimeExt
|
||||
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 {
|
||||
if passThrough {
|
||||
return 0
|
||||
}
|
||||
|
||||
func RTCPSenderReportPropagationDelay(rsrs *livekit.RTCPSenderReportState) time.Duration {
|
||||
return time.Unix(0, rsrs.AtAdjusted).Sub(mediatransportutil.NtpTime(rsrs.NtpTimestamp).Time())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user