sfu: broadcast RTP to down tracks without per-packet allocations (#4875)
* sfu: broadcast RTP to down tracks without a per-packet closure Every forwarded packet allocated a closure capturing the packet and layer, and an atomic write counter that escaped with it, even for tracks with a single subscriber. Add BroadcastRTP, which carries the packet and layer in the worker state and sums the writes per worker. The serial path no longer allocates; the parallel path allocates the shared state and the worker funcval only. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * sfu: reuse the forwarded packet copy in the RED receivers Both RED receivers copied the ExtPacket (and the opus one the rtp.Packet) per forwarded packet, and the copies moved to the heap because the broadcast takes their address. Keep them on the receiver like the existing redPayloadBuf: ForwardRTP runs on one goroutine and down tracks do not keep the packet past WriteRTP. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * sfu: skip BroadcastRTP allocation assertion under the race detector Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * sfu: group BroadcastRTP and its interfaces after the spreader methods Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
4ea0facf85
commit
48700da3f3
@@ -962,12 +962,9 @@ func (r *ReceiverBase) forwardRTP(
|
||||
continue
|
||||
}
|
||||
|
||||
var writeCount atomic.Int32
|
||||
r.downTrackSpreader.Broadcast(func(dt TrackSender) {
|
||||
writeCount.Add(dt.WriteRTP(extPkt, spatialLayer))
|
||||
})
|
||||
writeCount := sfuutils.BroadcastRTP(r.downTrackSpreader, extPkt, spatialLayer)
|
||||
if rt := r.loadREDTransformer(); rt != nil {
|
||||
writeCount.Add(rt.ForwardRTP(extPkt, spatialLayer))
|
||||
writeCount += rt.ForwardRTP(extPkt, spatialLayer)
|
||||
}
|
||||
|
||||
// track delay/jitter
|
||||
@@ -977,13 +974,13 @@ func (r *ReceiverBase) forwardRTP(
|
||||
// delivered back-to-back) which the single forwarder goroutine drains
|
||||
// serially, inflating the measured transit for the tail of the burst. That
|
||||
// reflects loss recovery rather than steady-state forwarding health.
|
||||
if writeCount.Load() > 0 && r.forwardStats != nil && !extPkt.IsBuffered && !extPkt.IsOutOfOrder {
|
||||
if writeCount > 0 && r.forwardStats != nil && !extPkt.IsBuffered && !extPkt.IsOutOfOrder {
|
||||
if latency, isHigh := r.forwardStats.Update(extPkt.Arrival, mono.UnixNano()); isHigh {
|
||||
r.params.Logger.Debugw(
|
||||
"high forwarding latency",
|
||||
"latency", time.Duration(latency),
|
||||
"queuingLatency", time.Duration(dequeuedAt-extPkt.Arrival),
|
||||
"writeCount", writeCount.Load(),
|
||||
"writeCount", writeCount,
|
||||
"isOutOfOrder", extPkt.IsOutOfOrder,
|
||||
"layer", layer,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user