|
|
@ -4,7 +4,6 @@ import ( |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"log" |
|
|
|
|
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
@ -108,9 +107,7 @@ func (c *serverClient) close() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *serverClient) log(format string, args ...interface{}) { |
|
|
|
func (c *serverClient) log(format string, args ...interface{}) { |
|
|
|
// keep remote address outside format, since it can contain %
|
|
|
|
c.p.log("[client %s] "+format, append([]interface{}{c.conn.NetConn().RemoteAddr().String()}, args...)...) |
|
|
|
log.Println("[RTSP client " + c.conn.NetConn().RemoteAddr().String() + "] " + |
|
|
|
|
|
|
|
fmt.Sprintf(format, args...)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *serverClient) ip() net.IP { |
|
|
|
func (c *serverClient) ip() net.IP { |
|
|
@ -122,8 +119,6 @@ func (c *serverClient) zone() string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *serverClient) run() { |
|
|
|
func (c *serverClient) run() { |
|
|
|
c.log("connected") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if c.p.args.preScript != "" { |
|
|
|
if c.p.args.preScript != "" { |
|
|
|
preScript := exec.Command(c.p.args.preScript) |
|
|
|
preScript := exec.Command(c.p.args.preScript) |
|
|
|
err := preScript.Run() |
|
|
|
err := preScript.Run() |
|
|
@ -147,12 +142,15 @@ func (c *serverClient) run() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
c.log("disconnected") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if c.udpCheckStreamTicker != nil { |
|
|
|
if c.udpCheckStreamTicker != nil { |
|
|
|
c.udpCheckStreamTicker.Stop() |
|
|
|
c.udpCheckStreamTicker.Stop() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
|
|
|
for range c.write { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
func() { |
|
|
|
func() { |
|
|
|
if c.p.args.postScript != "" { |
|
|
|
if c.p.args.postScript != "" { |
|
|
|
postScript := exec.Command(c.p.args.postScript) |
|
|
|
postScript := exec.Command(c.p.args.postScript) |
|
|
@ -682,6 +680,11 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set state
|
|
|
|
|
|
|
|
res = make(chan error) |
|
|
|
|
|
|
|
c.p.events <- programEventClientPlay2{res, c} |
|
|
|
|
|
|
|
<-res |
|
|
|
|
|
|
|
|
|
|
|
c.log("is receiving on path '%s', %d %s via %s", c.path, len(c.streamTracks), func() string { |
|
|
|
c.log("is receiving on path '%s', %d %s via %s", c.path, len(c.streamTracks), func() string { |
|
|
|
if len(c.streamTracks) == 1 { |
|
|
|
if len(c.streamTracks) == 1 { |
|
|
|
return "track" |
|
|
|
return "track" |
|
|
@ -689,11 +692,6 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool { |
|
|
|
return "tracks" |
|
|
|
return "tracks" |
|
|
|
}(), c.streamProtocol) |
|
|
|
}(), c.streamProtocol) |
|
|
|
|
|
|
|
|
|
|
|
// set state
|
|
|
|
|
|
|
|
res = make(chan error) |
|
|
|
|
|
|
|
c.p.events <- programEventClientPlay2{res, c} |
|
|
|
|
|
|
|
<-res |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// when protocol is TCP, the RTSP connection becomes a RTP connection
|
|
|
|
// when protocol is TCP, the RTSP connection becomes a RTP connection
|
|
|
|
if c.streamProtocol == _STREAM_PROTOCOL_TCP { |
|
|
|
if c.streamProtocol == _STREAM_PROTOCOL_TCP { |
|
|
|
// write RTP frames sequentially
|
|
|
|
// write RTP frames sequentially
|
|
|
@ -770,6 +768,10 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res := make(chan error) |
|
|
|
|
|
|
|
c.p.events <- programEventClientRecord{res, c} |
|
|
|
|
|
|
|
<-res |
|
|
|
|
|
|
|
|
|
|
|
c.log("is publishing on path '%s', %d %s via %s", c.path, len(c.streamTracks), func() string { |
|
|
|
c.log("is publishing on path '%s', %d %s via %s", c.path, len(c.streamTracks), func() string { |
|
|
|
if len(c.streamTracks) == 1 { |
|
|
|
if len(c.streamTracks) == 1 { |
|
|
|
return "track" |
|
|
|
return "track" |
|
|
@ -777,10 +779,6 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool { |
|
|
|
return "tracks" |
|
|
|
return "tracks" |
|
|
|
}(), c.streamProtocol) |
|
|
|
}(), c.streamProtocol) |
|
|
|
|
|
|
|
|
|
|
|
res := make(chan error) |
|
|
|
|
|
|
|
c.p.events <- programEventClientRecord{res, c} |
|
|
|
|
|
|
|
<-res |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// when protocol is TCP, the RTSP connection becomes a RTP connection
|
|
|
|
// when protocol is TCP, the RTSP connection becomes a RTP connection
|
|
|
|
// receive RTP data and parse it
|
|
|
|
// receive RTP data and parse it
|
|
|
|
if c.streamProtocol == _STREAM_PROTOCOL_TCP { |
|
|
|
if c.streamProtocol == _STREAM_PROTOCOL_TCP { |
|
|
|