Browse Source

support receiving requests while receiving interleaved frames (#19)

pull/31/head v0.8.4
aler9 5 years ago
parent
commit
d2522f5c10
  1. 2
      go.mod
  2. 4
      go.sum
  3. 43
      server-client.go
  4. 8
      streamer.go

2
go.mod

@ -5,7 +5,7 @@ go 1.13 @@ -5,7 +5,7 @@ go 1.13
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aler9/gortsplib v0.0.0-20200630132544-e557f0263207
github.com/aler9/gortsplib v0.0.0-20200704162620-4c712d2370a3
github.com/stretchr/testify v1.4.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.2.2

4
go.sum

@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo @@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/gortsplib v0.0.0-20200630132544-e557f0263207 h1:dazXsv+MFMwiclP/Cl9MKqGtbIfbF7mq7YdKCLXNAfo=
github.com/aler9/gortsplib v0.0.0-20200630132544-e557f0263207/go.mod h1:sL64nUkmrTVhlT/GCaxRXyI2Xk7m8XSdw5Uv8xKGPdc=
github.com/aler9/gortsplib v0.0.0-20200704162620-4c712d2370a3 h1:pEigKatFbio1Z6YBbBvBqQ0BI4DqkMK95MlOYnmfrLg=
github.com/aler9/gortsplib v0.0.0-20200704162620-4c712d2370a3/go.mod h1:sL64nUkmrTVhlT/GCaxRXyI2Xk7m8XSdw5Uv8xKGPdc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

43
server-client.go

@ -869,7 +869,7 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool { @@ -869,7 +869,7 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
frame.Content = frame.Content[:cap(frame.Content)]
c.readCurBuf = !c.readCurBuf
err := c.conn.ReadInterleavedFrame(frame)
recv, err := c.conn.ReadInterleavedFrameOrRequest(frame)
if err != nil {
if err != io.EOF {
c.log("ERR: %s", err)
@ -877,19 +877,40 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool { @@ -877,19 +877,40 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
return false
}
trackId, trackFlowType := interleavedChannelToTrack(frame.Channel)
switch recvt := recv.(type) {
case *gortsplib.InterleavedFrame:
trackId, trackFlowType := interleavedChannelToTrack(frame.Channel)
if trackId >= len(c.streamTracks) {
c.log("ERR: invalid track id '%d'", trackId)
return false
}
if trackId >= len(c.streamTracks) {
c.log("ERR: invalid track id '%d'", trackId)
return false
}
c.p.events <- programEventClientFrameTcp{
c.path,
trackId,
trackFlowType,
frame.Content,
}
c.p.events <- programEventClientFrameTcp{
c.path,
trackId,
trackFlowType,
frame.Content,
case *gortsplib.Request:
cseq, ok := recvt.Header["CSeq"]
if !ok || len(cseq) != 1 {
c.writeResError(recvt, gortsplib.StatusBadRequest, fmt.Errorf("cseq missing"))
return false
}
switch recvt.Method {
case gortsplib.TEARDOWN:
// close connection silently
return false
default:
c.writeResError(recvt, gortsplib.StatusBadRequest, fmt.Errorf("unhandled method '%s'", recvt.Method))
return false
}
}
}
} else {
c.udpLastFrameTime = time.Now()

8
streamer.go

@ -562,16 +562,16 @@ outer: @@ -562,16 +562,16 @@ outer:
frame.Content = frame.Content[:cap(frame.Content)]
s.readCurBuf = !s.readCurBuf
vres, err := conn.ReadInterleavedFrameOrResponse(frame)
recv, err := conn.ReadInterleavedFrameOrResponse(frame)
if err != nil {
s.log("ERR: %s", err)
return true
}
switch res := vres.(type) {
switch recvt := recv.(type) {
case *gortsplib.Response:
if res.StatusCode != gortsplib.StatusOK {
s.log("ERR: PLAY returned code %d (%s)", res.StatusCode, res.StatusMessage)
if recvt.StatusCode != gortsplib.StatusOK {
s.log("ERR: PLAY returned code %d (%s)", recvt.StatusCode, recvt.StatusMessage)
return true
}
break outer

Loading…
Cancel
Save