allow calling PLAY twice (#128)

This commit is contained in:
aler9 2020-11-24 23:39:09 +01:00
parent 359a7f0f2f
commit bed42ab2b6
1 changed files with 23 additions and 15 deletions

View File

@ -770,31 +770,35 @@ func (c *Client) handleRequest(req *base.Request) error {
} }
case base.PLAY: case base.PLAY:
// play can be sent twice, allow calling it even if we're already playing
err := c.checkState(map[state]struct{}{ err := c.checkState(map[state]struct{}{
statePrePlay: {}, statePrePlay: {},
statePlay: {},
}) })
if err != nil { if err != nil {
c.writeResError(cseq, base.StatusBadRequest, err) c.writeResError(cseq, base.StatusBadRequest, err)
return errStateTerminate return errStateTerminate
} }
basePath, ok := req.URL.BasePath() if c.state == statePrePlay {
if !ok { basePath, ok := req.URL.BasePath()
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL)) if !ok {
return errStateTerminate c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL))
} return errStateTerminate
}
// path can end with a slash, remove it // path can end with a slash, remove it
basePath = strings.TrimSuffix(basePath, "/") basePath = strings.TrimSuffix(basePath, "/")
if basePath != c.path.Name() { if basePath != c.path.Name() {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("path has changed, was '%s', now is '%s'", c.path.Name(), basePath)) c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("path has changed, was '%s', now is '%s'", c.path.Name(), basePath))
return errStateTerminate return errStateTerminate
} }
if len(c.streamTracks) == 0 { if len(c.streamTracks) == 0 {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("no tracks have been setup")) c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("no tracks have been setup"))
return errStateTerminate return errStateTerminate
}
} }
// write response before setting state // write response before setting state
@ -807,7 +811,11 @@ func (c *Client) handleRequest(req *base.Request) error {
"Session": base.HeaderValue{sessionId}, "Session": base.HeaderValue{sessionId},
}, },
}) })
return errStatePlay
if c.state == statePrePlay {
return errStatePlay
}
return nil
case base.RECORD: case base.RECORD:
err := c.checkState(map[state]struct{}{ err := c.checkState(map[state]struct{}{