Make sender report pass through an option. (#2861)

Enabled by default.

Also, tweak the long term propagation delay a bit. The first propagation
delay itself was too high and the long term initialized with a high
value. Prevent that and also ensure large negtaives do not have an
effect by using a lower bound of 0. Lower bound of 0 is okay as the main
purpose is to track sustained high positive values.
This commit is contained in:
Raja Subramanian
2024-07-15 11:27:31 +05:30
committed by GitHub
parent a995c71f84
commit faa66d1138
8 changed files with 144 additions and 70 deletions
+1
View File
@@ -141,6 +141,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
Trailer: trailer, Trailer: trailer,
Logger: LoggerWithTrack(sub.GetLogger().WithComponent(sutils.ComponentSub), trackID, t.params.IsRelayed), Logger: LoggerWithTrack(sub.GetLogger().WithComponent(sutils.ComponentSub), trackID, t.params.IsRelayed),
RTCPWriter: sub.WriteSubscriberRTCP, RTCPWriter: sub.WriteSubscriberRTCP,
DisableSenderReportPassThrough: sub.GetDisableSenderReportPassThrough(),
}) })
if err != nil { if err != nil {
return nil, err return nil, err
+5
View File
@@ -143,6 +143,7 @@ type ParticipantParams struct {
PlayoutDelay *livekit.PlayoutDelay PlayoutDelay *livekit.PlayoutDelay
SyncStreams bool SyncStreams bool
ForwardStats *sfu.ForwardStats ForwardStats *sfu.ForwardStats
DisableSenderReportPassThrough bool
} }
type ParticipantImpl struct { type ParticipantImpl struct {
@@ -320,6 +321,10 @@ func (p *ParticipantImpl) GetPacer() pacer.Pacer {
return p.TransportManager.GetSubscriberPacer() return p.TransportManager.GetSubscriberPacer()
} }
func (p *ParticipantImpl) GetDisableSenderReportPassThrough() bool {
return p.params.DisableSenderReportPassThrough
}
func (p *ParticipantImpl) ID() livekit.ParticipantID { func (p *ParticipantImpl) ID() livekit.ParticipantID {
return p.params.SID return p.params.SID
} }
+2
View File
@@ -427,6 +427,8 @@ type LocalParticipant interface {
SetSubscriberChannelCapacity(channelCapacity int64) SetSubscriberChannelCapacity(channelCapacity int64)
GetPacer() pacer.Pacer GetPacer() pacer.Pacer
GetDisableSenderReportPassThrough() bool
} }
// Room is a container of participants, and can provide room-level actions // Room is a container of participants, and can provide room-level actions
@@ -266,6 +266,16 @@ type FakeLocalParticipant struct {
getConnectionQualityReturnsOnCall map[int]struct { getConnectionQualityReturnsOnCall map[int]struct {
result1 *livekit.ConnectionQualityInfo result1 *livekit.ConnectionQualityInfo
} }
GetDisableSenderReportPassThroughStub func() bool
getDisableSenderReportPassThroughMutex sync.RWMutex
getDisableSenderReportPassThroughArgsForCall []struct {
}
getDisableSenderReportPassThroughReturns struct {
result1 bool
}
getDisableSenderReportPassThroughReturnsOnCall map[int]struct {
result1 bool
}
GetICEConnectionDetailsStub func() []*types.ICEConnectionDetails GetICEConnectionDetailsStub func() []*types.ICEConnectionDetails
getICEConnectionDetailsMutex sync.RWMutex getICEConnectionDetailsMutex sync.RWMutex
getICEConnectionDetailsArgsForCall []struct { getICEConnectionDetailsArgsForCall []struct {
@@ -2306,6 +2316,59 @@ func (fake *FakeLocalParticipant) GetConnectionQualityReturnsOnCall(i int, resul
}{result1} }{result1}
} }
func (fake *FakeLocalParticipant) GetDisableSenderReportPassThrough() bool {
fake.getDisableSenderReportPassThroughMutex.Lock()
ret, specificReturn := fake.getDisableSenderReportPassThroughReturnsOnCall[len(fake.getDisableSenderReportPassThroughArgsForCall)]
fake.getDisableSenderReportPassThroughArgsForCall = append(fake.getDisableSenderReportPassThroughArgsForCall, struct {
}{})
stub := fake.GetDisableSenderReportPassThroughStub
fakeReturns := fake.getDisableSenderReportPassThroughReturns
fake.recordInvocation("GetDisableSenderReportPassThrough", []interface{}{})
fake.getDisableSenderReportPassThroughMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *FakeLocalParticipant) GetDisableSenderReportPassThroughCallCount() int {
fake.getDisableSenderReportPassThroughMutex.RLock()
defer fake.getDisableSenderReportPassThroughMutex.RUnlock()
return len(fake.getDisableSenderReportPassThroughArgsForCall)
}
func (fake *FakeLocalParticipant) GetDisableSenderReportPassThroughCalls(stub func() bool) {
fake.getDisableSenderReportPassThroughMutex.Lock()
defer fake.getDisableSenderReportPassThroughMutex.Unlock()
fake.GetDisableSenderReportPassThroughStub = stub
}
func (fake *FakeLocalParticipant) GetDisableSenderReportPassThroughReturns(result1 bool) {
fake.getDisableSenderReportPassThroughMutex.Lock()
defer fake.getDisableSenderReportPassThroughMutex.Unlock()
fake.GetDisableSenderReportPassThroughStub = nil
fake.getDisableSenderReportPassThroughReturns = struct {
result1 bool
}{result1}
}
func (fake *FakeLocalParticipant) GetDisableSenderReportPassThroughReturnsOnCall(i int, result1 bool) {
fake.getDisableSenderReportPassThroughMutex.Lock()
defer fake.getDisableSenderReportPassThroughMutex.Unlock()
fake.GetDisableSenderReportPassThroughStub = nil
if fake.getDisableSenderReportPassThroughReturnsOnCall == nil {
fake.getDisableSenderReportPassThroughReturnsOnCall = make(map[int]struct {
result1 bool
})
}
fake.getDisableSenderReportPassThroughReturnsOnCall[i] = struct {
result1 bool
}{result1}
}
func (fake *FakeLocalParticipant) GetICEConnectionDetails() []*types.ICEConnectionDetails { func (fake *FakeLocalParticipant) GetICEConnectionDetails() []*types.ICEConnectionDetails {
fake.getICEConnectionDetailsMutex.Lock() fake.getICEConnectionDetailsMutex.Lock()
ret, specificReturn := fake.getICEConnectionDetailsReturnsOnCall[len(fake.getICEConnectionDetailsArgsForCall)] ret, specificReturn := fake.getICEConnectionDetailsReturnsOnCall[len(fake.getICEConnectionDetailsArgsForCall)]
@@ -6646,6 +6709,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
defer fake.getClientInfoMutex.RUnlock() defer fake.getClientInfoMutex.RUnlock()
fake.getConnectionQualityMutex.RLock() fake.getConnectionQualityMutex.RLock()
defer fake.getConnectionQualityMutex.RUnlock() defer fake.getConnectionQualityMutex.RUnlock()
fake.getDisableSenderReportPassThroughMutex.RLock()
defer fake.getDisableSenderReportPassThroughMutex.RUnlock()
fake.getICEConnectionDetailsMutex.RLock() fake.getICEConnectionDetailsMutex.RLock()
defer fake.getICEConnectionDetailsMutex.RUnlock() defer fake.getICEConnectionDetailsMutex.RUnlock()
fake.getLoggerMutex.RLock() fake.getLoggerMutex.RLock()
+2 -4
View File
@@ -37,8 +37,6 @@ const (
cFirstPacketTimeAdjustWindow = 2 * time.Minute cFirstPacketTimeAdjustWindow = 2 * time.Minute
cFirstPacketTimeAdjustThreshold = 15 * 1e9 cFirstPacketTimeAdjustThreshold = 15 * 1e9
cPassthroughNTPTimestamp = true
cSequenceNumberLargeJumpThreshold = 100 cSequenceNumberLargeJumpThreshold = 100
) )
@@ -122,8 +120,8 @@ type RTCPSenderReportData struct {
AtAdjusted time.Time AtAdjusted time.Time
} }
func (r *RTCPSenderReportData) PropagationDelay() time.Duration { func (r *RTCPSenderReportData) PropagationDelay(passThrough bool) time.Duration {
if cPassthroughNTPTimestamp { if passThrough {
return 0 return 0
} }
+6 -4
View File
@@ -260,7 +260,7 @@ func (r *RTPStatsReceiver) Update(
r.largeJumpCount++ r.largeJumpCount++
if (r.largeJumpCount-1)%100 == 0 { if (r.largeJumpCount-1)%100 == 0 {
r.logger.Warnw( r.logger.Warnw(
"large sequence number gap OR time reversed", nil, "large sequence number gap", nil,
append(getLoggingFields(), "count", r.largeJumpCount)..., append(getLoggingFields(), "count", r.largeJumpCount)...,
) )
} }
@@ -492,7 +492,6 @@ func (r *RTPStatsReceiver) updatePropagationDelayAndRecordSenderReport(srData *R
deltaPropagationDelay = propagationDelay - r.propagationDelay deltaPropagationDelay = propagationDelay - r.propagationDelay
if deltaPropagationDelay > cPropagationDelayDeltaThresholdMin { // ignore small changes for path change consideration if deltaPropagationDelay > cPropagationDelayDeltaThresholdMin { // ignore small changes for path change consideration
if r.longTermDeltaPropagationDelay != 0 && if r.longTermDeltaPropagationDelay != 0 &&
deltaPropagationDelay > 0 &&
deltaPropagationDelay > r.longTermDeltaPropagationDelay*time.Duration(cPropagationDelayDeltaThresholdMaxFactor) { deltaPropagationDelay > r.longTermDeltaPropagationDelay*time.Duration(cPropagationDelayDeltaThresholdMaxFactor) {
r.logger.Debugw("sharp increase in propagation delay", getPropagationFields()...) r.logger.Debugw("sharp increase in propagation delay", getPropagationFields()...)
r.propagationDelayDeltaHighCount++ r.propagationDelayDeltaHighCount++
@@ -522,10 +521,10 @@ func (r *RTPStatsReceiver) updatePropagationDelayAndRecordSenderReport(srData *R
r.propagationDelay += time.Duration(factor * float64(propagationDelay-r.propagationDelay)) r.propagationDelay += time.Duration(factor * float64(propagationDelay-r.propagationDelay))
} }
if deltaPropagationDelay < cPropagationDelayDeltaLongTermAdaptationThreshold {
if r.longTermDeltaPropagationDelay == 0 { if r.longTermDeltaPropagationDelay == 0 {
r.longTermDeltaPropagationDelay = deltaPropagationDelay r.longTermDeltaPropagationDelay = deltaPropagationDelay
} else { } else {
if deltaPropagationDelay < cPropagationDelayDeltaLongTermAdaptationThreshold {
// do not adapt to large +ve spikes, can happen when channel is congested and reports are delivered very late // do not adapt to large +ve spikes, can happen when channel is congested and reports are delivered very late
// if the spike is in fact a path change, it will persist and handled by path change detection above // if the spike is in fact a path change, it will persist and handled by path change detection above
sinceLastReport := srData.NTPTimestamp.Time().Sub(r.srNewest.NTPTimestamp.Time()) sinceLastReport := srData.NTPTimestamp.Time().Sub(r.srNewest.NTPTimestamp.Time())
@@ -533,6 +532,9 @@ func (r *RTPStatsReceiver) updatePropagationDelayAndRecordSenderReport(srData *R
r.longTermDeltaPropagationDelay += time.Duration(adaptationFactor * float64(deltaPropagationDelay-r.longTermDeltaPropagationDelay)) r.longTermDeltaPropagationDelay += time.Duration(adaptationFactor * float64(deltaPropagationDelay-r.longTermDeltaPropagationDelay))
} }
} }
if r.longTermDeltaPropagationDelay < 0 {
r.longTermDeltaPropagationDelay = 0
}
} }
// adjust receive time to estimated propagation delay // adjust receive time to estimated propagation delay
srData.AtAdjusted = ntpTime.Add(r.propagationDelay) srData.AtAdjusted = ntpTime.Add(r.propagationDelay)
@@ -563,8 +565,8 @@ func (r *RTPStatsReceiver) SetRtcpSenderReportData(srData *RTCPSenderReportData)
return false return false
} }
r.checkRTPClockSkewForSenderReport(srDataExt)
r.updatePropagationDelayAndRecordSenderReport(srDataExt) r.updatePropagationDelayAndRecordSenderReport(srDataExt)
r.checkRTPClockSkewForSenderReport(srDataExt)
r.checkRTPClockSkewAgainstMediaPathForSenderReport(srDataExt) r.checkRTPClockSkewAgainstMediaPathForSenderReport(srDataExt)
if err, loggingFields := r.maybeAdjustFirstPacketTime(r.srNewest, 0, r.timestamp.GetExtendedStart()); err != nil { if err, loggingFields := r.maybeAdjustFirstPacketTime(r.srNewest, 0, r.timestamp.GetExtendedStart()); err != nil {
+2 -2
View File
@@ -606,7 +606,7 @@ func (r *RTPStatsSender) GetExpectedRTPTimestamp(at time.Time) (expectedTSExt ui
return return
} }
func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *RTCPSenderReportData, tsOffset uint64) *rtcp.SenderReport { func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *RTCPSenderReportData, tsOffset uint64, passThrough bool) *rtcp.SenderReport {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@@ -620,7 +620,7 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *RTCPS
nowNTP mediatransportutil.NtpTime nowNTP mediatransportutil.NtpTime
nowRTPExt uint64 nowRTPExt uint64
) )
if cPassthroughNTPTimestamp { if passThrough {
nowNTP = publisherSRData.NTPTimestamp nowNTP = publisherSRData.NTPTimestamp
nowRTPExt = publisherSRData.RTPTimestampExt - tsOffset nowRTPExt = publisherSRData.RTPTimestampExt - tsOffset
} else { } else {
+3 -2
View File
@@ -214,6 +214,7 @@ type DowntrackParams struct {
Logger logger.Logger Logger logger.Logger
Trailer []byte Trailer []byte
RTCPWriter func([]rtcp.Packet) error RTCPWriter func([]rtcp.Packet) error
DisableSenderReportPassThrough bool
} }
// DownTrack implements TrackLocal, is the track used to write packets // DownTrack implements TrackLocal, is the track used to write packets
@@ -813,7 +814,7 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
_, _, refSenderReport := d.forwarder.GetSenderReportParams() _, _, refSenderReport := d.forwarder.GetSenderReportParams()
if refSenderReport != nil { if refSenderReport != nil {
actExtCopy := *extPkt.AbsCaptureTimeExt actExtCopy := *extPkt.AbsCaptureTimeExt
if err = actExtCopy.Rewrite(refSenderReport.PropagationDelay()); err == nil { if err = actExtCopy.Rewrite(refSenderReport.PropagationDelay(!d.params.DisableSenderReportPassThrough)); err == nil {
actBytes, err = actExtCopy.Marshal() actBytes, err = actExtCopy.Marshal()
if err == nil { if err == nil {
extensions = append( extensions = append(
@@ -1404,7 +1405,7 @@ func (d *DownTrack) CreateSenderReport() *rtcp.SenderReport {
} }
_, tsOffset, refSenderReport := d.forwarder.GetSenderReportParams() _, tsOffset, refSenderReport := d.forwarder.GetSenderReportParams()
return d.rtpStats.GetRtcpSenderReport(d.ssrc, refSenderReport, tsOffset) return d.rtpStats.GetRtcpSenderReport(d.ssrc, refSenderReport, tsOffset, !d.params.DisableSenderReportPassThrough)
} }
func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan struct{} { func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan struct{} {