Skip to content

Commit

Permalink
support receiving requests while receiving interleaved frames (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jul 4, 2020
1 parent f7a9d2f commit d2522f5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
43 changes: 32 additions & 11 deletions server-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,27 +869,48 @@ 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)
}
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()
Expand Down
8 changes: 4 additions & 4 deletions streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d2522f5

Please sign in to comment.