From 48063df5b8cdad301deed6490d6397eae596bca8 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Fri, 7 Mar 2025 23:12:20 -0800 Subject: [PATCH] load mime type before calling writeBlankFrameRTP (#3502) --- pkg/sfu/downtrack.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/sfu/downtrack.go b/pkg/sfu/downtrack.go index 670f02b28..5aff620e8 100644 --- a/pkg/sfu/downtrack.go +++ b/pkg/sfu/downtrack.go @@ -1266,7 +1266,7 @@ func (d *DownTrack) handleMute(muted bool, changed bool) { // mute too. d.blankFramesGeneration.Inc() if d.kind == webrtc.RTPCodecTypeAudio && muted { - d.writeBlankFrameRTP(RTPBlankFramesMuteSeconds, d.blankFramesGeneration.Load()) + d.writeBlankFrameRTP(RTPBlankFramesMuteSeconds, d.blankFramesGeneration.Load(), d.Mime()) } } @@ -1293,9 +1293,7 @@ func (d *DownTrack) CloseWithFlush(flush bool) { } d.params.Logger.Debugw("close down track", "flushBlankFrame", flush) - isBound := d.bindState.Load() == bindStateBound - d.bindLock.Unlock() - if isBound { + if d.bindState.Load() == bindStateBound { d.forwarder.Mute(true, true) // write blank frames after disabling so that other frames do not interfere. @@ -1303,7 +1301,7 @@ func (d *DownTrack) CloseWithFlush(flush bool) { // Otherwise, with transceiver re-use last frame from previous stream is held in the // display buffer and there could be a brief moment where the previous stream is displayed. if flush { - doneFlushing := d.writeBlankFrameRTP(RTPBlankFramesCloseSeconds, d.blankFramesGeneration.Inc()) + doneFlushing := d.writeBlankFrameRTP(RTPBlankFramesCloseSeconds, d.blankFramesGeneration.Inc(), d.mimeTypeLocked()) // wait a limited time to flush timer := time.NewTimer(flushTimeout) @@ -1319,7 +1317,6 @@ func (d *DownTrack) CloseWithFlush(flush bool) { d.params.Logger.Debugw("closing sender", "kind", d.kind) } - d.bindLock.Lock() d.setBindStateLocked(bindStateUnbound) d.Receiver().DeleteDownTrack(d.SubscriberID()) @@ -1691,7 +1688,7 @@ func (d *DownTrack) CreateSenderReport() *rtcp.SenderReport { // not sending RTCP Sender Report for RTX } -func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan struct{} { +func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32, mimeType mime.MimeType) chan struct{} { done := make(chan struct{}) go func() { // don't send if not writable OR nothing has been sent @@ -1700,7 +1697,6 @@ func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan return } - mimeType := d.Mime() var getBlankFrame func(bool) ([]byte, error) switch mimeType { case mime.MimeTypeOpus: