mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 06:46:42 +08:00
remove ServerHandler.Server
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
@@ -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())
|
||||
}
|
||||
|
@@ -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{
|
||||
|
@@ -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
|
||||
|
@@ -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{
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user