Fix(buffer): fix simulcast multiple calls to close buffer
@@ -37,6 +37,7 @@ type Buffer struct {
audioPool *sync.Pool
packetChan chan rtp.Packet
pPackets []pendingPackets
+ closeOnce sync.Once
mediaSSRC uint32
clockRate uint32
maxBitrate uint64
@@ -220,6 +221,7 @@ func (b *Buffer) Close() error {
b.Lock()
defer b.Unlock()
+ b.closeOnce.Do(func() {
b.closed = true
if b.bucket != nil && b.codecType == webrtc.RTPCodecTypeVideo {
b.videoPool.Put(b.bucket.buf)
@@ -229,6 +231,7 @@ func (b *Buffer) Close() error {
}
b.onClose()
close(b.packetChan)
+ })
return nil
}
