Move probe observer to pacer (#3214)
* Probe ID pass * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * clean up * typo * populate desired bytes * correct num probes calculation * debug log * remove unused constant * log channel observer * debug * clear isInProbe flag on end * clear probe flag on reset * re-arrange
This commit is contained in:
+30
-59
@@ -37,6 +37,7 @@ import (
|
||||
"github.com/livekit/protocol/utils/mono"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/ccutils"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||
act "github.com/livekit/livekit-server/pkg/sfu/rtpextension/abscapturetime"
|
||||
@@ -190,9 +191,6 @@ type DownTrackStreamAllocatorListener interface {
|
||||
// stream resumed
|
||||
OnResume(dt *DownTrack)
|
||||
|
||||
// packet(s) sent
|
||||
OnPacketsSent(dt *DownTrack, size int)
|
||||
|
||||
/* STREAM-ALLOCATOR-DATA
|
||||
// NACKs received
|
||||
OnNACK(dt *DownTrack, nackInfos []NackInfo)
|
||||
@@ -291,14 +289,13 @@ type DownTrack struct {
|
||||
|
||||
activePaddingOnMuteUpTrack atomic.Bool
|
||||
|
||||
streamAllocatorLock sync.RWMutex
|
||||
streamAllocatorListener DownTrackStreamAllocatorListener
|
||||
streamAllocatorReportGeneration int
|
||||
streamAllocatorBytesCounter atomic.Uint32
|
||||
streamAllocatorLock sync.RWMutex
|
||||
streamAllocatorListener DownTrackStreamAllocatorListener
|
||||
/* STREAM-ALLOCATOR-DATA
|
||||
bytesSent atomic.Uint32
|
||||
bytesRetransmitted atomic.Uint32
|
||||
*/
|
||||
probeClusterId atomic.Uint32
|
||||
|
||||
playoutDelay *PlayoutDelayController
|
||||
|
||||
@@ -627,48 +624,8 @@ func (d *DownTrack) getStreamAllocatorListener() DownTrackStreamAllocatorListene
|
||||
return d.streamAllocatorListener
|
||||
}
|
||||
|
||||
func (d *DownTrack) SetStreamAllocatorReportInterval(interval time.Duration) {
|
||||
d.ClearStreamAllocatorReportInterval()
|
||||
|
||||
if interval == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
d.streamAllocatorLock.Lock()
|
||||
d.streamAllocatorBytesCounter.Store(0)
|
||||
|
||||
d.streamAllocatorReportGeneration++
|
||||
gen := d.streamAllocatorReportGeneration
|
||||
d.streamAllocatorLock.Unlock()
|
||||
|
||||
go func(generation int) {
|
||||
timer := time.NewTimer(interval)
|
||||
for {
|
||||
<-timer.C
|
||||
|
||||
d.streamAllocatorLock.Lock()
|
||||
if generation != d.streamAllocatorReportGeneration {
|
||||
d.streamAllocatorLock.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
sal := d.streamAllocatorListener
|
||||
bytes := d.streamAllocatorBytesCounter.Swap(0)
|
||||
d.streamAllocatorLock.Unlock()
|
||||
|
||||
if sal != nil {
|
||||
sal.OnPacketsSent(d, int(bytes))
|
||||
}
|
||||
|
||||
timer.Reset(interval)
|
||||
}
|
||||
}(gen)
|
||||
}
|
||||
|
||||
func (d *DownTrack) ClearStreamAllocatorReportInterval() {
|
||||
d.streamAllocatorLock.Lock()
|
||||
d.streamAllocatorReportGeneration++
|
||||
d.streamAllocatorLock.Unlock()
|
||||
func (d *DownTrack) SetProbeClusterId(probeClusterId ccutils.ProbeClusterId) {
|
||||
d.probeClusterId.Store(uint32(probeClusterId))
|
||||
}
|
||||
|
||||
// ID is the unique identifier for this Track. This should be unique for the
|
||||
@@ -942,18 +899,21 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
||||
)
|
||||
}
|
||||
|
||||
headerSize := hdr.MarshalSize()
|
||||
d.updateStats(updateStatsParams{
|
||||
packetTime: extPkt.Arrival,
|
||||
extSequenceNumber: tp.rtp.extSequenceNumber,
|
||||
extTimestamp: tp.rtp.extTimestamp,
|
||||
isOutOfOrder: extPkt.IsOutOfOrder,
|
||||
headerSize: hdr.MarshalSize(),
|
||||
headerSize: headerSize,
|
||||
payloadSize: len(payload),
|
||||
marker: hdr.Marker,
|
||||
})
|
||||
d.pacer.Enqueue(&pacer.Packet{
|
||||
Header: hdr,
|
||||
HeaderSize: headerSize,
|
||||
Payload: payload,
|
||||
ProbeClusterId: ccutils.ProbeClusterId(d.probeClusterId.Load()),
|
||||
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
||||
TransportWideExtID: uint8(d.transportWideExtID),
|
||||
WriteStream: d.writeStream,
|
||||
@@ -986,7 +946,11 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
||||
|
||||
// WritePaddingRTP tries to write as many padding only RTP packets as necessary
|
||||
// to satisfy given size to the DownTrack
|
||||
func (d *DownTrack) WritePaddingRTP(bytesToSend int, paddingOnMute bool, forceMarker bool) int {
|
||||
func (d *DownTrack) WritePaddingRTP(
|
||||
bytesToSend int,
|
||||
paddingOnMute bool,
|
||||
forceMarker bool,
|
||||
) int {
|
||||
if !d.writable.Load() {
|
||||
return 0
|
||||
}
|
||||
@@ -1070,7 +1034,10 @@ func (d *DownTrack) WritePaddingRTP(bytesToSend int, paddingOnMute bool, forceMa
|
||||
})
|
||||
d.pacer.Enqueue(&pacer.Packet{
|
||||
Header: hdr,
|
||||
HeaderSize: hdrSize,
|
||||
Payload: payload,
|
||||
ProbeClusterId: ccutils.ProbeClusterId(d.probeClusterId.Load()),
|
||||
IsProbe: true,
|
||||
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
||||
TransportWideExtID: uint8(d.transportWideExtID),
|
||||
WriteStream: d.writeStream,
|
||||
@@ -1227,8 +1194,6 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
|
||||
if onCloseHandler := d.getOnCloseHandler(); onCloseHandler != nil {
|
||||
onCloseHandler(!flush)
|
||||
}
|
||||
|
||||
d.ClearStreamAllocatorReportInterval()
|
||||
}
|
||||
|
||||
func (d *DownTrack) SetMaxSpatialLayer(spatialLayer int32) {
|
||||
@@ -1614,16 +1579,19 @@ func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan
|
||||
return
|
||||
}
|
||||
|
||||
headerSize := hdr.MarshalSize()
|
||||
d.updateStats(updateStatsParams{
|
||||
packetTime: mono.UnixNano(),
|
||||
extSequenceNumber: snts[i].extSequenceNumber,
|
||||
extTimestamp: snts[i].extTimestamp,
|
||||
headerSize: hdr.MarshalSize(),
|
||||
headerSize: headerSize,
|
||||
payloadSize: len(payload),
|
||||
})
|
||||
d.pacer.Enqueue(&pacer.Packet{
|
||||
Header: hdr,
|
||||
HeaderSize: headerSize,
|
||||
Payload: payload,
|
||||
ProbeClusterId: ccutils.ProbeClusterId(d.probeClusterId.Load()),
|
||||
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
||||
TransportWideExtID: uint8(d.transportWideExtID),
|
||||
WriteStream: d.writeStream,
|
||||
@@ -1964,18 +1932,21 @@ func (d *DownTrack) retransmitPackets(nacks []uint16) {
|
||||
}
|
||||
d.addDummyExtensions(&pkt.Header)
|
||||
|
||||
headerSize := pkt.Header.MarshalSize()
|
||||
d.updateStats(updateStatsParams{
|
||||
packetTime: mono.UnixNano(),
|
||||
extSequenceNumber: epm.extSequenceNumber,
|
||||
extTimestamp: epm.extTimestamp,
|
||||
isOutOfOrder: true,
|
||||
headerSize: pkt.Header.MarshalSize(),
|
||||
headerSize: headerSize,
|
||||
payloadSize: len(payload),
|
||||
isRTX: true,
|
||||
})
|
||||
d.pacer.Enqueue(&pacer.Packet{
|
||||
Header: &pkt.Header,
|
||||
HeaderSize: headerSize,
|
||||
Payload: payload,
|
||||
ProbeClusterId: ccutils.ProbeClusterId(d.probeClusterId.Load()),
|
||||
IsRTX: true,
|
||||
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
||||
TransportWideExtID: uint8(d.transportWideExtID),
|
||||
@@ -2178,18 +2149,21 @@ func (d *DownTrack) sendSilentFrameOnMuteForOpus() {
|
||||
return
|
||||
}
|
||||
|
||||
headerSize := hdr.MarshalSize()
|
||||
d.updateStats(updateStatsParams{
|
||||
packetTime: mono.UnixNano(),
|
||||
extSequenceNumber: snts[i].extSequenceNumber,
|
||||
extTimestamp: snts[i].extTimestamp,
|
||||
headerSize: hdr.MarshalSize(),
|
||||
headerSize: headerSize,
|
||||
payloadSize: len(payload),
|
||||
// although this is using empty frames, mark as padding as these are used to trigger Pion OnTrack only
|
||||
isPadding: true,
|
||||
})
|
||||
d.pacer.Enqueue(&pacer.Packet{
|
||||
Header: hdr,
|
||||
HeaderSize: headerSize,
|
||||
Payload: payload,
|
||||
ProbeClusterId: ccutils.ProbeClusterId(d.probeClusterId.Load()),
|
||||
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
||||
TransportWideExtID: uint8(d.transportWideExtID),
|
||||
WriteStream: d.writeStream,
|
||||
@@ -2235,9 +2209,6 @@ type updateStatsParams struct {
|
||||
|
||||
func (d *DownTrack) updateStats(params updateStatsParams) {
|
||||
if !params.disableCounter {
|
||||
// STREAM-ALLOCATOR-TODO: remove this stream allocator bytes counter once stream allocator changes fully to pull bytes counter
|
||||
size := uint32(params.headerSize + params.payloadSize)
|
||||
d.streamAllocatorBytesCounter.Add(size)
|
||||
/* STREAM-ALLOCATOR-DATA
|
||||
if params.isRTX {
|
||||
d.bytesRetransmitted.Add(size)
|
||||
|
||||
Reference in New Issue
Block a user