mirror of
https://github.com/aler9/gortsplib
synced 2025-10-18 05:00:47 +08:00
convert Tracks into Medias and Formats (#155)
* split tracks from medias * move tracks into dedicated package * move media into dedicated package * edit Medias.Marshal() in order to return SDP * add medias.Find() and simplify examples * improve coverage * fix rebase errors * replace TrackIDs with MediaIDs * implement media-specific and track-specific callbacks for reading RTCP and RTP packets * rename publish into record, read into play * add v2 tag * rename tracks into formats
This commit is contained in:
45
serverwriter.go
Normal file
45
serverwriter.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"github.com/aler9/gortsplib/v2/pkg/ringbuffer"
|
||||
)
|
||||
|
||||
type serverWriter struct {
|
||||
running bool
|
||||
buffer *ringbuffer.RingBuffer
|
||||
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func (sw *serverWriter) start() {
|
||||
if !sw.running {
|
||||
sw.running = true
|
||||
sw.done = make(chan struct{})
|
||||
go sw.run()
|
||||
}
|
||||
}
|
||||
|
||||
func (sw *serverWriter) stop() {
|
||||
if sw.running {
|
||||
sw.buffer.Close()
|
||||
<-sw.done
|
||||
sw.running = false
|
||||
}
|
||||
}
|
||||
|
||||
func (sw *serverWriter) run() {
|
||||
defer close(sw.done)
|
||||
|
||||
for {
|
||||
tmp, ok := sw.buffer.Pull()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
tmp.(func())()
|
||||
}
|
||||
}
|
||||
|
||||
func (sw *serverWriter) queue(cb func()) {
|
||||
sw.buffer.Push(cb)
|
||||
}
|
Reference in New Issue
Block a user