mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +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
|
// 3. allow multiple clients to read that stream with TCP
|
||||||
|
|
||||||
type serverHandler struct {
|
type serverHandler struct {
|
||||||
|
s *gortsplib.Server
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
stream *gortsplib.ServerStream
|
stream *gortsplib.ServerStream
|
||||||
publisher *gortsplib.ServerSession
|
publisher *gortsplib.ServerSession
|
||||||
@@ -88,7 +89,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the stream and save the publisher
|
// 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
|
sh.publisher = ctx.Session
|
||||||
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
@@ -146,13 +147,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configure the server
|
// configure the server
|
||||||
s := &gortsplib.Server{
|
h := &serverHandler{}
|
||||||
Handler: &serverHandler{},
|
h.s = &gortsplib.Server{
|
||||||
|
Handler: h,
|
||||||
TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}},
|
TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}},
|
||||||
RTSPAddress: ":8322",
|
RTSPAddress: ":8322",
|
||||||
}
|
}
|
||||||
|
|
||||||
// start server and wait until a fatal error
|
// start server and wait until a fatal error
|
||||||
log.Printf("server is ready")
|
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
|
// 3. allow multiple clients to read that stream with TCP, UDP or UDP-multicast
|
||||||
|
|
||||||
type serverHandler struct {
|
type serverHandler struct {
|
||||||
|
s *gortsplib.Server
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
stream *gortsplib.ServerStream
|
stream *gortsplib.ServerStream
|
||||||
publisher *gortsplib.ServerSession
|
publisher *gortsplib.ServerSession
|
||||||
@@ -87,7 +88,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the stream and save the publisher
|
// 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
|
sh.publisher = ctx.Session
|
||||||
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
@@ -137,8 +138,9 @@ func (sh *serverHandler) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*bas
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// configure the server
|
// configure the server
|
||||||
s := &gortsplib.Server{
|
h := &serverHandler{}
|
||||||
Handler: &serverHandler{},
|
h.s = &gortsplib.Server{
|
||||||
|
Handler: h,
|
||||||
RTSPAddress: ":8554",
|
RTSPAddress: ":8554",
|
||||||
UDPRTPAddress: ":8000",
|
UDPRTPAddress: ":8000",
|
||||||
UDPRTCPAddress: ":8001",
|
UDPRTCPAddress: ":8001",
|
||||||
@@ -149,5 +151,5 @@ func main() {
|
|||||||
|
|
||||||
// start server and wait until a fatal error
|
// start server and wait until a fatal error
|
||||||
log.Printf("server is ready")
|
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 stream *gortsplib.ServerStream
|
||||||
var publisher *gortsplib.ServerSession
|
var publisher *gortsplib.ServerSession
|
||||||
|
|
||||||
s := &gortsplib.Server{
|
var s *gortsplib.Server
|
||||||
|
s = &gortsplib.Server{
|
||||||
Handler: &testServerHandler{
|
Handler: &testServerHandler{
|
||||||
onSessionClose: func(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) {
|
onSessionClose: func(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
@@ -328,7 +329,7 @@ func TestServerRecordRead(t *testing.T) {
|
|||||||
}, fmt.Errorf("someone is already publishing")
|
}, fmt.Errorf("someone is already publishing")
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = gortsplib.NewServerStream(ctx.Server, ctx.Medias)
|
stream = gortsplib.NewServerStream(s, ctx.Medias)
|
||||||
publisher = ctx.Session
|
publisher = ctx.Session
|
||||||
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
|
@@ -83,7 +83,6 @@ type ServerHandlerOnDescribe interface {
|
|||||||
|
|
||||||
// ServerHandlerOnAnnounceCtx is the context of OnAnnounce.
|
// ServerHandlerOnAnnounceCtx is the context of OnAnnounce.
|
||||||
type ServerHandlerOnAnnounceCtx struct {
|
type ServerHandlerOnAnnounceCtx struct {
|
||||||
Server *Server
|
|
||||||
Session *ServerSession
|
Session *ServerSession
|
||||||
Conn *ServerConn
|
Conn *ServerConn
|
||||||
Request *base.Request
|
Request *base.Request
|
||||||
@@ -100,7 +99,6 @@ type ServerHandlerOnAnnounce interface {
|
|||||||
|
|
||||||
// ServerHandlerOnSetupCtx is the context of OnSetup.
|
// ServerHandlerOnSetupCtx is the context of OnSetup.
|
||||||
type ServerHandlerOnSetupCtx struct {
|
type ServerHandlerOnSetupCtx struct {
|
||||||
Server *Server
|
|
||||||
Session *ServerSession
|
Session *ServerSession
|
||||||
Conn *ServerConn
|
Conn *ServerConn
|
||||||
Request *base.Request
|
Request *base.Request
|
||||||
|
@@ -219,11 +219,12 @@ func TestServerRecordPath(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
s := &Server{
|
var s *Server
|
||||||
|
s = &Server{
|
||||||
Handler: &testServerHandler{
|
Handler: &testServerHandler{
|
||||||
onAnnounce: func(ctx *ServerHandlerOnAnnounceCtx) (*base.Response, error) {
|
onAnnounce: func(ctx *ServerHandlerOnAnnounceCtx) (*base.Response, error) {
|
||||||
// make sure that media URLs are not overridden by NewServerStream()
|
// make sure that media URLs are not overridden by NewServerStream()
|
||||||
stream := NewServerStream(ctx.Server, ctx.Medias)
|
stream := NewServerStream(s, ctx.Medias)
|
||||||
defer stream.Close()
|
defer stream.Close()
|
||||||
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
|
@@ -549,7 +549,6 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
res, err := ss.s.Handler.(ServerHandlerOnAnnounce).OnAnnounce(&ServerHandlerOnAnnounceCtx{
|
res, err := ss.s.Handler.(ServerHandlerOnAnnounce).OnAnnounce(&ServerHandlerOnAnnounceCtx{
|
||||||
Server: ss.s,
|
|
||||||
Session: ss,
|
Session: ss,
|
||||||
Conn: sc,
|
Conn: sc,
|
||||||
Request: req,
|
Request: req,
|
||||||
@@ -681,7 +680,6 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
res, stream, err := ss.s.Handler.(ServerHandlerOnSetup).OnSetup(&ServerHandlerOnSetupCtx{
|
res, stream, err := ss.s.Handler.(ServerHandlerOnSetup).OnSetup(&ServerHandlerOnSetupCtx{
|
||||||
Server: ss.s,
|
|
||||||
Session: ss,
|
Session: ss,
|
||||||
Conn: sc,
|
Conn: sc,
|
||||||
Request: req,
|
Request: req,
|
||||||
|
Reference in New Issue
Block a user