From b0454b00a207fce0ad6cbb3540a5be759ab6f3bb Mon Sep 17 00:00:00 2001 From: Artur Shellunts Date: Mon, 20 Dec 2021 12:04:50 +0100 Subject: [PATCH] Count padding bytes in telemetry (#264) Count padding bytes in telemetry outgoing total bytes --- pkg/rtc/mediatrack.go | 3 +++ pkg/sfu/downtrack.go | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/rtc/mediatrack.go b/pkg/rtc/mediatrack.go index 7a2b07710..b7795a93d 100644 --- a/pkg/rtc/mediatrack.go +++ b/pkg/rtc/mediatrack.go @@ -267,6 +267,9 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error { downTrack.OnPacketSent(func(_ *sfu.DownTrack, size int) { t.params.Telemetry.OnDownstreamPacket(sub.ID(), size) }) + downTrack.OnPaddingSent(func(_ *sfu.DownTrack, size int) { + t.params.Telemetry.OnDownstreamPacket(sub.ID(), size) + }) downTrack.OnRTCP(func(pkts []rtcp.Packet) { t.params.Telemetry.HandleRTCP(livekit.StreamType_DOWNSTREAM, sub.ID(), pkts) }) diff --git a/pkg/sfu/downtrack.go b/pkg/sfu/downtrack.go index 5c2195b19..d4da3f577 100644 --- a/pkg/sfu/downtrack.go +++ b/pkg/sfu/downtrack.go @@ -120,6 +120,9 @@ type DownTrack struct { // packet sent callback onPacketSent []func(dt *DownTrack, size int) + + // padding packet sent callback + onPaddingSent []func(dt *DownTrack, size int) } // NewDownTrack returns a DownTrack. @@ -375,12 +378,9 @@ func (d *DownTrack) WritePaddingRTP(bytesToSend int) int { size := hdr.MarshalSize() + len(payload) d.UpdatePaddingStats(uint32(size)) - // LK-TOOD-START: - // Maybe call onPacketSent callbacks? But, a couple of issues to think about - // - Analytics - should padding bytes be counted? - // - StreamAllocator probing - should not include padding - // Maybe a separate callback for `onPaddingSent`? - // LK-TODO-END + for _, f := range d.onPaddingSent { + f(d, size) + } // LK-TODO-START // NACK buffer for these probe packets. @@ -510,6 +510,10 @@ func (d *DownTrack) OnPacketSent(fn func(dt *DownTrack, size int)) { d.onPacketSent = append(d.onPacketSent, fn) } +func (d *DownTrack) OnPaddingSent(fn func(dt *DownTrack, size int)) { + d.onPaddingSent = append(d.onPaddingSent, fn) +} + func (d *DownTrack) IsDeficient() bool { return d.forwarder.IsDeficient() }