From 15232560bc7667160fda228230c2c8fc30a7e7a0 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Thu, 23 Feb 2023 09:35:12 +0530 Subject: [PATCH] Send stream start on initial start (#1456) A couple of other bits 1. Use request layer for sending PLI on bind and connected. 2. When adjusting for overshoot, do not adjust target unless current is at max. If not, it could get stuck in a lower layer in the following scenario a. Overshoot to layer 2 b. Max layer is 1, start sending PLI c. Get key frame for layer 0, adjust for overshoot as we have something at a layer lower than max. d. Adjust for overshoot. e. Setting target to max means that current and target are equal and no further adjustment happens. --- pkg/sfu/downtrack.go | 6 +++--- pkg/sfu/forwarder.go | 2 +- pkg/sfu/streamallocator.go | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/sfu/downtrack.go b/pkg/sfu/downtrack.go index 33fa429a6..587e1b770 100644 --- a/pkg/sfu/downtrack.go +++ b/pkg/sfu/downtrack.go @@ -1593,9 +1593,9 @@ func (d *DownTrack) GetNackStats() (totalPackets uint32, totalRepeatedNACKs uint func (d *DownTrack) onBindAndConnected() { if d.connected.Load() && d.bound.Load() && !d.bindAndConnectedOnce.Swap(true) { if d.kind == webrtc.RTPCodecTypeVideo { - targetLayers := d.forwarder.TargetLayers() - if targetLayers != InvalidLayers { - d.receiver.SendPLI(targetLayers.Spatial, true) + _, layer := d.forwarder.CheckSync() + if layer != InvalidLayerSpatial { + d.receiver.SendPLI(layer, true) } } diff --git a/pkg/sfu/forwarder.go b/pkg/sfu/forwarder.go index c155a20b4..99bcb2848 100644 --- a/pkg/sfu/forwarder.go +++ b/pkg/sfu/forwarder.go @@ -1515,10 +1515,10 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in "feed", extPkt.Packet.SSRC, ) f.currentLayers.Spatial = layer - f.targetLayers.Spatial = layer if f.currentLayers.Spatial >= f.maxLayers.Spatial || f.currentLayers.Spatial == f.maxPublishedLayer { tp.isSwitchingToMaxLayer = true + f.targetLayers.Spatial = layer } } } diff --git a/pkg/sfu/streamallocator.go b/pkg/sfu/streamallocator.go index 3885158ec..54906c964 100644 --- a/pkg/sfu/streamallocator.go +++ b/pkg/sfu/streamallocator.go @@ -1340,6 +1340,7 @@ func newTrack( isSimulcast: isSimulcast, publisherID: publisherID, logger: logger, + isPaused: true, } t.SetPriority(0) t.SetMaxLayers(downTrack.MaxLayers())