add *Server argument to NewServerStream()

This commit is contained in:
aler9
2023-08-12 20:19:29 +02:00
parent ca87733ded
commit 68d4bf8da0
10 changed files with 191 additions and 156 deletions

View File

@@ -2,7 +2,6 @@ package main
import (
"log"
"sync"
"time"
"github.com/bluenviron/gortsplib/v4"
@@ -18,12 +17,13 @@ const (
)
type client struct {
mutex sync.RWMutex
stream *gortsplib.ServerStream
s *server
}
func newClient() *client {
c := &client{}
func newClient(s *server) *client {
c := &client{
s: s,
}
// start a separated routine
go c.run()
@@ -40,12 +40,6 @@ func (c *client) run() {
}
}
func (c *client) getStream() *gortsplib.ServerStream {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.stream
}
func (c *client) read() error {
rc := gortsplib.Client{}
@@ -74,24 +68,11 @@ func (c *client) read() error {
return err
}
// create a server stream
stream := gortsplib.NewServerStream(medias)
defer stream.Close()
stream := c.s.setStreamReady(medias)
defer c.s.setStreamUnready()
log.Printf("stream is ready and can be read from the server at rtsp://localhost:8554/stream\n")
// make stream available by using getStream()
c.mutex.Lock()
c.stream = stream
c.mutex.Unlock()
defer func() {
// remove stream from getStream()
c.mutex.Lock()
c.stream = nil
c.mutex.Unlock()
}()
// called when a RTP packet arrives
rc.OnPacketRTPAny(func(medi *media.Media, forma formats.Format, pkt *rtp.Packet) {
// route incoming packets to the server stream