mirror of
https://github.com/livekit/livekit.git
synced 2026-08-27 22:34:25 +00:00
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:
+17
-9
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user