From e2c526b3b8757d89f20d4e0217304a5da53b6ff3 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:26:42 +0200 Subject: [PATCH] remove ServerHandler.Server --- examples/server-tls/main.go | 10 ++++++---- examples/server/main.go | 10 ++++++---- internal/highleveltests/server_test.go | 5 +++-- server_handler.go | 2 -- server_record_test.go | 5 +++-- server_session.go | 2 -- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/examples/server-tls/main.go b/examples/server-tls/main.go index 92d4a07e..4326e4f1 100644 --- a/examples/server-tls/main.go +++ b/examples/server-tls/main.go @@ -19,6 +19,7 @@ import ( // 3. allow multiple clients to read that stream with TCP type serverHandler struct { + s *gortsplib.Server mutex sync.Mutex stream *gortsplib.ServerStream publisher *gortsplib.ServerSession @@ -88,7 +89,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) ( } // create the stream and save the publisher - sh.stream = gortsplib.NewServerStream(ctx.Server, ctx.Medias) + sh.stream = gortsplib.NewServerStream(sh.s, ctx.Medias) sh.publisher = ctx.Session return &base.Response{ @@ -146,13 +147,14 @@ func main() { } // configure the server - s := &gortsplib.Server{ - Handler: &serverHandler{}, + h := &serverHandler{} + h.s = &gortsplib.Server{ + Handler: h, TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}}, RTSPAddress: ":8322", } // start server and wait until a fatal error log.Printf("server is ready") - panic(s.StartAndWait()) + panic(h.s.StartAndWait()) } diff --git a/examples/server/main.go b/examples/server/main.go index 8513ca53..dfcbc434 100644 --- a/examples/server/main.go +++ b/examples/server/main.go @@ -18,6 +18,7 @@ import ( // 3. allow multiple clients to read that stream with TCP, UDP or UDP-multicast type serverHandler struct { + s *gortsplib.Server mutex sync.Mutex stream *gortsplib.ServerStream publisher *gortsplib.ServerSession @@ -87,7 +88,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) ( } // create the stream and save the publisher - sh.stream = gortsplib.NewServerStream(ctx.Server, ctx.Medias) + sh.stream = gortsplib.NewServerStream(sh.s, ctx.Medias) sh.publisher = ctx.Session return &base.Response{ @@ -137,8 +138,9 @@ func (sh *serverHandler) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*bas func main() { // configure the server - s := &gortsplib.Server{ - Handler: &serverHandler{}, + h := &serverHandler{} + h.s = &gortsplib.Server{ + Handler: h, RTSPAddress: ":8554", UDPRTPAddress: ":8000", UDPRTCPAddress: ":8001", @@ -149,5 +151,5 @@ func main() { // start server and wait until a fatal error log.Printf("server is ready") - panic(s.StartAndWait()) + panic(h.s.StartAndWait()) } diff --git a/internal/highleveltests/server_test.go b/internal/highleveltests/server_test.go index da912b5f..f878f924 100644 --- a/internal/highleveltests/server_test.go +++ b/internal/highleveltests/server_test.go @@ -269,7 +269,8 @@ func TestServerRecordRead(t *testing.T) { var stream *gortsplib.ServerStream var publisher *gortsplib.ServerSession - s := &gortsplib.Server{ + var s *gortsplib.Server + s = &gortsplib.Server{ Handler: &testServerHandler{ onSessionClose: func(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) { mutex.Lock() @@ -328,7 +329,7 @@ func TestServerRecordRead(t *testing.T) { }, fmt.Errorf("someone is already publishing") } - stream = gortsplib.NewServerStream(ctx.Server, ctx.Medias) + stream = gortsplib.NewServerStream(s, ctx.Medias) publisher = ctx.Session return &base.Response{ diff --git a/server_handler.go b/server_handler.go index 6ec8a5b8..0ed4a8b6 100644 --- a/server_handler.go +++ b/server_handler.go @@ -83,7 +83,6 @@ type ServerHandlerOnDescribe interface { // ServerHandlerOnAnnounceCtx is the context of OnAnnounce. type ServerHandlerOnAnnounceCtx struct { - Server *Server Session *ServerSession Conn *ServerConn Request *base.Request @@ -100,7 +99,6 @@ type ServerHandlerOnAnnounce interface { // ServerHandlerOnSetupCtx is the context of OnSetup. type ServerHandlerOnSetupCtx struct { - Server *Server Session *ServerSession Conn *ServerConn Request *base.Request diff --git a/server_record_test.go b/server_record_test.go index 35163343..c5b06211 100644 --- a/server_record_test.go +++ b/server_record_test.go @@ -219,11 +219,12 @@ func TestServerRecordPath(t *testing.T) { }, } { t.Run(ca.name, func(t *testing.T) { - s := &Server{ + var s *Server + s = &Server{ Handler: &testServerHandler{ onAnnounce: func(ctx *ServerHandlerOnAnnounceCtx) (*base.Response, error) { // make sure that media URLs are not overridden by NewServerStream() - stream := NewServerStream(ctx.Server, ctx.Medias) + stream := NewServerStream(s, ctx.Medias) defer stream.Close() return &base.Response{ diff --git a/server_session.go b/server_session.go index e109d8e6..19c6051f 100644 --- a/server_session.go +++ b/server_session.go @@ -549,7 +549,6 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) ( } res, err := ss.s.Handler.(ServerHandlerOnAnnounce).OnAnnounce(&ServerHandlerOnAnnounceCtx{ - Server: ss.s, Session: ss, Conn: sc, Request: req, @@ -681,7 +680,6 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) ( } res, stream, err := ss.s.Handler.(ServerHandlerOnSetup).OnSetup(&ServerHandlerOnSetupCtx{ - Server: ss.s, Session: ss, Conn: sc, Request: req,