Avoid locking when flushing DownTrack (#594)
This commit is contained in:
@@ -49,15 +49,14 @@ func (u *UpTrackManager) Start() {
|
|||||||
func (u *UpTrackManager) Close() {
|
func (u *UpTrackManager) Close() {
|
||||||
u.lock.Lock()
|
u.lock.Lock()
|
||||||
u.closed = true
|
u.closed = true
|
||||||
|
|
||||||
// remove all subscribers
|
|
||||||
for _, t := range u.publishedTracks {
|
|
||||||
t.RemoveAllSubscribers()
|
|
||||||
}
|
|
||||||
|
|
||||||
notify := len(u.publishedTracks) == 0
|
notify := len(u.publishedTracks) == 0
|
||||||
u.lock.Unlock()
|
u.lock.Unlock()
|
||||||
|
|
||||||
|
// remove all subscribers
|
||||||
|
for _, t := range u.GetPublishedTracks() {
|
||||||
|
t.RemoveAllSubscribers()
|
||||||
|
}
|
||||||
|
|
||||||
if notify && u.onClose != nil {
|
if notify && u.onClose != nil {
|
||||||
u.onClose()
|
u.onClose()
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -45,6 +45,7 @@ const (
|
|||||||
|
|
||||||
keyFrameIntervalMin = 200
|
keyFrameIntervalMin = 200
|
||||||
keyFrameIntervalMax = 1000
|
keyFrameIntervalMax = 1000
|
||||||
|
flushTimeout = 1 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -569,7 +570,18 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
|
|||||||
// display buffer and there could be a brief moment where the previous stream is displayed.
|
// display buffer and there could be a brief moment where the previous stream is displayed.
|
||||||
d.logger.Infow("close down track", "peerID", d.peerID, "trackID", d.id, "flushBlankFrame", flush)
|
d.logger.Infow("close down track", "peerID", d.peerID, "trackID", d.id, "flushBlankFrame", flush)
|
||||||
if flush {
|
if flush {
|
||||||
_ = d.writeBlankFrameRTP()
|
doneFlushing := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(doneFlushing)
|
||||||
|
_ = d.writeBlankFrameRTP()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// wait a limited time to flush
|
||||||
|
timer := time.NewTimer(flushTimeout)
|
||||||
|
select {
|
||||||
|
case <-doneFlushing:
|
||||||
|
case <-timer.C:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.closeOnce.Do(func() {
|
d.closeOnce.Do(func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user