1 Star 0 Fork 0

我还是我 / gortsplib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
async_processor.go 839 Bytes
一键复制 编辑 原始数据 按行查看 历史
package gortsplib
import (
"github.com/bluenviron/gortsplib/v4/pkg/ringbuffer"
)
// this struct contains a queue that allows to detach the routine that is reading a stream
// from the routine that is writing a stream.
type asyncProcessor struct {
running bool
buffer *ringbuffer.RingBuffer
done chan struct{}
}
func (w *asyncProcessor) allocateBuffer(size int) {
w.buffer, _ = ringbuffer.New(uint64(size))
}
func (w *asyncProcessor) start() {
w.running = true
w.done = make(chan struct{})
go w.run()
}
func (w *asyncProcessor) stop() {
if w.running {
w.buffer.Close()
<-w.done
w.running = false
}
}
func (w *asyncProcessor) run() {
defer close(w.done)
for {
tmp, ok := w.buffer.Pull()
if !ok {
return
}
tmp.(func())()
}
}
func (w *asyncProcessor) push(cb func()) bool {
return w.buffer.Push(cb)
}
Go
1
https://gitee.com/likunde_admin/gortsplib.git
git@gitee.com:likunde_admin/gortsplib.git
likunde_admin
gortsplib
gortsplib
main

搜索帮助