mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
improve examples (#778)
This commit is contained in:
@@ -62,6 +62,7 @@ func (c *client) read() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// notify the server that we are ready
|
||||
stream := c.server.setStreamReady(desc)
|
||||
defer c.server.setStreamUnready()
|
||||
|
||||
|
@@ -4,8 +4,8 @@ import "log"
|
||||
|
||||
// This example shows how to
|
||||
// 1. create a server that serves a single stream.
|
||||
// 2. create a client, read an existing stream from an external server or camera,
|
||||
// pass the stream to the server in order to serve it.
|
||||
// 2. create a client, that reads an existing stream from another server or camera.
|
||||
// 3. route the stream from the client to the server, and from the server to all connected readers.
|
||||
|
||||
func main() {
|
||||
// allocate the server.
|
||||
@@ -13,11 +13,11 @@ func main() {
|
||||
s.initialize()
|
||||
|
||||
// allocate the client.
|
||||
// give client access to the server.
|
||||
// allow client to use the server.
|
||||
c := &client{server: s}
|
||||
c.initialize()
|
||||
|
||||
// start server and wait until a fatal error
|
||||
log.Printf("server is ready on %s", s.server.RTSPAddress)
|
||||
s.server.StartAndWait()
|
||||
panic(s.server.StartAndWait())
|
||||
}
|
||||
|
@@ -19,9 +19,9 @@ func (s *server) initialize() {
|
||||
// configure the server
|
||||
s.server = &gortsplib.Server{
|
||||
Handler: s,
|
||||
RTSPAddress: ":8554",
|
||||
UDPRTPAddress: ":8000",
|
||||
UDPRTCPAddress: ":8001",
|
||||
RTSPAddress: ":8556",
|
||||
UDPRTPAddress: ":8002",
|
||||
UDPRTCPAddress: ":8003",
|
||||
MulticastIPRange: "224.1.0.0/16",
|
||||
MulticastRTPPort: 8002,
|
||||
MulticastRTCPPort: 8003,
|
||||
@@ -98,20 +98,24 @@ func (s *server) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response,
|
||||
func (s *server) setStreamReady(desc *description.Session) *gortsplib.ServerStream {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
s.stream = &gortsplib.ServerStream{
|
||||
Server: s.server,
|
||||
Desc: desc,
|
||||
}
|
||||
|
||||
err := s.stream.Initialize()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return s.stream
|
||||
}
|
||||
|
||||
func (s *server) setStreamUnready() {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
s.stream.Close()
|
||||
s.stream = nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user