mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
@@ -19,7 +19,7 @@ import (
|
||||
// 3. allow multiple clients to read that stream with TCP
|
||||
|
||||
type serverHandler struct {
|
||||
s *gortsplib.Server
|
||||
server *gortsplib.Server
|
||||
mutex sync.RWMutex
|
||||
stream *gortsplib.ServerStream
|
||||
publisher *gortsplib.ServerSession
|
||||
@@ -44,8 +44,8 @@ func (sh *serverHandler) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpen
|
||||
func (sh *serverHandler) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) {
|
||||
log.Printf("session closed")
|
||||
|
||||
sh.mutex.Lock()
|
||||
defer sh.mutex.Unlock()
|
||||
sh.mutex.RLock()
|
||||
defer sh.mutex.RUnlock()
|
||||
|
||||
// if the session is the publisher,
|
||||
// close the stream and disconnect any reader.
|
||||
@@ -79,8 +79,8 @@ func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (
|
||||
func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) {
|
||||
log.Printf("announce request")
|
||||
|
||||
sh.mutex.Lock()
|
||||
defer sh.mutex.Unlock()
|
||||
sh.mutex.RLock()
|
||||
defer sh.mutex.RUnlock()
|
||||
|
||||
// disconnect existing publisher
|
||||
if sh.stream != nil {
|
||||
@@ -90,7 +90,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
||||
|
||||
// create the stream and save the publisher
|
||||
sh.stream = &gortsplib.ServerStream{
|
||||
Server: sh.s,
|
||||
Server: sh.server,
|
||||
Desc: ctx.Description,
|
||||
}
|
||||
err := sh.stream.Initialize()
|
||||
@@ -165,13 +165,13 @@ func main() {
|
||||
|
||||
// configure the server
|
||||
h := &serverHandler{}
|
||||
h.s = &gortsplib.Server{
|
||||
h.server = &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(h.s.StartAndWait())
|
||||
log.Printf("server is ready on %s", h.server.RTSPAddress)
|
||||
panic(h.server.StartAndWait())
|
||||
}
|
||||
|
Reference in New Issue
Block a user