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
+13 -12
View File
@@ -129,18 +129,19 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
} }
downTrack, err := sfu.NewDownTrack(sfu.DowntrackParams{ downTrack, err := sfu.NewDownTrack(sfu.DowntrackParams{
Codecs: codecs, Codecs: codecs,
Source: t.params.MediaTrack.Source(), Source: t.params.MediaTrack.Source(),
Receiver: wr, Receiver: wr,
BufferFactory: sub.GetBufferFactory(), BufferFactory: sub.GetBufferFactory(),
SubID: subscriberID, SubID: subscriberID,
StreamID: streamID, StreamID: streamID,
MaxTrack: maxTrack, MaxTrack: maxTrack,
PlayoutDelayLimit: sub.GetPlayoutDelayConfig(), PlayoutDelayLimit: sub.GetPlayoutDelayConfig(),
Pacer: sub.GetPacer(), Pacer: sub.GetPacer(),
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
+36 -31
View File
@@ -112,37 +112,38 @@ type ParticipantParams struct {
PLIThrottleConfig config.PLIThrottleConfig PLIThrottleConfig config.PLIThrottleConfig
CongestionControlConfig config.CongestionControlConfig CongestionControlConfig config.CongestionControlConfig
// codecs that are enabled for this room // codecs that are enabled for this room
PublishEnabledCodecs []*livekit.Codec PublishEnabledCodecs []*livekit.Codec
SubscribeEnabledCodecs []*livekit.Codec SubscribeEnabledCodecs []*livekit.Codec
Logger logger.Logger Logger logger.Logger
SimTracks map[uint32]SimulcastTrackInfo SimTracks map[uint32]SimulcastTrackInfo
Grants *auth.ClaimGrants Grants *auth.ClaimGrants
InitialVersion uint32 InitialVersion uint32
ClientConf *livekit.ClientConfiguration ClientConf *livekit.ClientConfiguration
ClientInfo ClientInfo ClientInfo ClientInfo
Region string Region string
Migration bool Migration bool
AdaptiveStream bool AdaptiveStream bool
AllowTCPFallback bool AllowTCPFallback bool
TCPFallbackRTTThreshold int TCPFallbackRTTThreshold int
AllowUDPUnstableFallback bool AllowUDPUnstableFallback bool
TURNSEnabled bool TURNSEnabled bool
GetParticipantInfo func(pID livekit.ParticipantID) *livekit.ParticipantInfo GetParticipantInfo func(pID livekit.ParticipantID) *livekit.ParticipantInfo
GetRegionSettings func(ip string) *livekit.RegionSettings GetRegionSettings func(ip string) *livekit.RegionSettings
DisableSupervisor bool DisableSupervisor bool
ReconnectOnPublicationError bool ReconnectOnPublicationError bool
ReconnectOnSubscriptionError bool ReconnectOnSubscriptionError bool
ReconnectOnDataChannelError bool ReconnectOnDataChannelError bool
DataChannelMaxBufferedAmount uint64 DataChannelMaxBufferedAmount uint64
VersionGenerator utils.TimedVersionGenerator VersionGenerator utils.TimedVersionGenerator
TrackResolver types.MediaTrackResolver TrackResolver types.MediaTrackResolver
DisableDynacast bool DisableDynacast bool
SubscriberAllowPause bool SubscriberAllowPause bool
SubscriptionLimitAudio int32 SubscriptionLimitAudio int32
SubscriptionLimitVideo int32 SubscriptionLimitVideo int32
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
} }
+9 -7
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 r.longTermDeltaPropagationDelay == 0 { if deltaPropagationDelay < cPropagationDelayDeltaLongTermAdaptationThreshold {
r.longTermDeltaPropagationDelay = deltaPropagationDelay if r.longTermDeltaPropagationDelay == 0 {
} else { r.longTermDeltaPropagationDelay = deltaPropagationDelay
if deltaPropagationDelay < cPropagationDelayDeltaLongTermAdaptationThreshold { } else {
// 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 {
+15 -14
View File
@@ -202,18 +202,19 @@ type DownTrackStreamAllocatorListener interface {
type ReceiverReportListener func(dt *DownTrack, report *rtcp.ReceiverReport) type ReceiverReportListener func(dt *DownTrack, report *rtcp.ReceiverReport)
type DowntrackParams struct { type DowntrackParams struct {
Codecs []webrtc.RTPCodecParameters Codecs []webrtc.RTPCodecParameters
Source livekit.TrackSource Source livekit.TrackSource
Receiver TrackReceiver Receiver TrackReceiver
BufferFactory *buffer.Factory BufferFactory *buffer.Factory
SubID livekit.ParticipantID SubID livekit.ParticipantID
StreamID string StreamID string
MaxTrack int MaxTrack int
PlayoutDelayLimit *livekit.PlayoutDelay PlayoutDelayLimit *livekit.PlayoutDelay
Pacer pacer.Pacer Pacer pacer.Pacer
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{} {