mirror of
https://github.com/aler9/gortsplib
synced 2025-10-01 05:22:22 +08:00
client: fix OnResponse() not getting called when playing / recording (#290)
This commit is contained in:
49
async_processor.go
Normal file
49
async_processor.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"github.com/bluenviron/gortsplib/v3/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) queue(cb func()) {
|
||||
w.buffer.Push(cb)
|
||||
}
|
Reference in New Issue
Block a user