Do not post close callback in ops queue if not started. (#649)

* Do not post close callback in ops queue if not started.

Ops queue is started in `Bind()`. If `Close()` is called
when bind did not happen (because the underlying peer connection
closed before bind), the close callback does not run.

Check if ops queue is running before posting close callback
into the queue.

Not pretty, but covers this case. Need to think about it more.

* correct check
This commit is contained in:
Raja Subramanian
2022-04-24 11:40:22 +05:30
committed by GitHub
parent b7d22c4f34
commit d38566850a
2 changed files with 34 additions and 9 deletions
+17 -9
View File
@@ -595,17 +595,25 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
d.rtpStats.Stop()
d.logger.Debugw("rtp stats", "stats", d.rtpStats.ToString())
if d.onMaxLayerChanged != nil && d.kind == webrtc.RTPCodecTypeVideo {
d.callbacksQueue.Enqueue(func() {
d.onMaxLayerChanged(d, InvalidLayerSpatial)
})
}
if d.callbacksQueue.IsStarted() {
if d.kind == webrtc.RTPCodecTypeVideo {
d.callbacksQueue.Enqueue(func() {
if d.onMaxLayerChanged != nil {
d.onMaxLayerChanged(d, InvalidLayerSpatial)
}
})
}
if d.onCloseHandler != nil {
d.callbacksQueue.Enqueue(d.onCloseHandler)
}
if d.onCloseHandler != nil {
d.callbacksQueue.Enqueue(d.onCloseHandler)
}
d.callbacksQueue.Stop()
d.callbacksQueue.Stop()
} else {
if d.onCloseHandler != nil {
d.onCloseHandler()
}
}
d.stopKeyFrameRequester()
})
}
+17
View File
@@ -13,6 +13,7 @@ type OpsQueue struct {
lock sync.RWMutex
ops chan func()
isStarted bool
isStopped bool
}
@@ -30,6 +31,15 @@ func (oq *OpsQueue) SetLogger(logger logger.Logger) {
}
func (oq *OpsQueue) Start() {
oq.lock.Lock()
if oq.isStarted {
oq.lock.Unlock()
return
}
oq.isStarted = true
oq.lock.Unlock()
go oq.process()
}
@@ -45,6 +55,13 @@ func (oq *OpsQueue) Stop() {
oq.lock.Unlock()
}
func (oq *OpsQueue) IsStarted() bool {
oq.lock.RLock()
defer oq.lock.RUnlock()
return oq.isStarted
}
func (oq *OpsQueue) Enqueue(op func()) {
oq.lock.RLock()
if oq.isStopped {