client: fix OnResponse() not getting called when playing / recording (#290)

This commit is contained in:
Alessandro Ros
2023-05-28 12:12:25 +02:00
committed by GitHub
parent f254503cf5
commit 1e1e10b031
5 changed files with 277 additions and 214 deletions

49
async_processor.go Normal file
View 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)
}