Skip to content

Commit

Permalink
client: send TEARDOWN even when PLAY or RECORD have not been sent yet
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jan 19, 2023
1 parent 71bd86c commit e3f21fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
14 changes: 9 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,19 +529,22 @@ func (c *Client) runInner() error {
}

func (c *Client) doClose() {
if c.state != clientStatePlay && c.state != clientStateRecord && c.conn != nil {
c.connCloserStop()
}

if c.state == clientStatePlay || c.state == clientStateRecord {
c.playRecordStop(true)
}

if c.baseURL != nil {
c.do(&base.Request{
Method: base.Teardown,
URL: c.baseURL,
}, true, false)
}

c.nconn.Close()
c.nconn = nil
c.conn = nil
} else if c.nconn != nil {
c.connCloserStop()
if c.nconn != nil {
c.nconn.Close()
c.nconn = nil
c.conn = nil
Expand Down Expand Up @@ -1259,6 +1262,7 @@ func (c *Client) doSetup(
// switch transport automatically
if c.effectiveTransport == nil &&
c.Transport == nil {
c.baseURL = baseURL
return c.trySwitchingProtocol2(medi, baseURL)
}

Expand Down
9 changes: 9 additions & 0 deletions client_play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,15 @@ func TestClientPlayAutomaticProtocol(t *testing.T) {
})
require.NoError(t, err)

req, err = co.ReadRequest()
require.NoError(t, err)
require.Equal(t, base.Teardown, req.Method)

err = co.WriteResponse(&base.Response{
StatusCode: base.StatusOK,
})
require.NoError(t, err)

_, err = co.ReadRequest()
require.Error(t, err)
}()
Expand Down
1 change: 0 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func TestClientSession(t *testing.T) {
req, err = conn.ReadRequest()
require.NoError(t, err)
require.Equal(t, base.Describe, req.Method)

require.Equal(t, base.HeaderValue{"123456"}, req.Header["Session"])

medias := media.Medias{testH264Media}
Expand Down

0 comments on commit e3f21fc

Please sign in to comment.