mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
client: fix panic
This commit is contained in:
48
client.go
48
client.go
@@ -1022,7 +1022,7 @@ func (c *Client) doOptions(u *base.URL) (*base.Response, error) {
|
|||||||
if res.StatusCode == base.StatusNotFound {
|
if res.StatusCode == base.StatusNotFound {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
return res, liberrors.ErrClientBadStatusCode{Code: res.StatusCode, Message: res.StatusMessage}
|
return nil, liberrors.ErrClientBadStatusCode{Code: res.StatusCode, Message: res.StatusMessage}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.useGetParameter = func() bool {
|
c.useGetParameter = func() bool {
|
||||||
@@ -1361,7 +1361,7 @@ func (c *Client) doSetup(
|
|||||||
return c.doSetup(forPlay, track, baseURL, 0, 0)
|
return c.doSetup(forPlay, track, baseURL, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, liberrors.ErrClientBadStatusCode{Code: res.StatusCode, Message: res.StatusMessage}
|
return nil, liberrors.ErrClientBadStatusCode{Code: res.StatusCode, Message: res.StatusMessage}
|
||||||
}
|
}
|
||||||
|
|
||||||
var thRes headers.Transport
|
var thRes headers.Transport
|
||||||
@@ -1576,14 +1576,11 @@ func (c *Client) doPlay(ra *headers.Range, isSwitchingProtocol bool) (*base.Resp
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.state = clientStatePlay
|
|
||||||
|
|
||||||
// setup UDP communication before sending the request.
|
// setup UDP communication before sending the request.
|
||||||
if *c.protocol == TransportUDP || *c.protocol == TransportUDPMulticast {
|
if *c.protocol == TransportUDP || *c.protocol == TransportUDPMulticast {
|
||||||
// start UDP listeners
|
|
||||||
for _, cct := range c.tracks {
|
for _, cct := range c.tracks {
|
||||||
cct.udpRTPListener.start()
|
cct.udpRTPListener.start(true)
|
||||||
cct.udpRTCPListener.start()
|
cct.udpRTCPListener.start(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// open the firewall by sending packets to the counterpart.
|
// open the firewall by sending packets to the counterpart.
|
||||||
@@ -1596,8 +1593,6 @@ func (c *Client) doPlay(ra *headers.Range, isSwitchingProtocol bool) (*base.Resp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
header := make(base.Header)
|
|
||||||
|
|
||||||
// Range is mandatory in Parrot Streaming Server
|
// Range is mandatory in Parrot Streaming Server
|
||||||
if ra == nil {
|
if ra == nil {
|
||||||
ra = &headers.Range{
|
ra = &headers.Range{
|
||||||
@@ -1606,14 +1601,22 @@ func (c *Client) doPlay(ra *headers.Range, isSwitchingProtocol bool) (*base.Resp
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
header["Range"] = ra.Write()
|
|
||||||
|
|
||||||
res, err := c.do(&base.Request{
|
res, err := c.do(&base.Request{
|
||||||
Method: base.Play,
|
Method: base.Play,
|
||||||
URL: c.streamBaseURL,
|
URL: c.streamBaseURL,
|
||||||
Header: header,
|
Header: base.Header{
|
||||||
|
"Range": ra.Write(),
|
||||||
|
},
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if *c.protocol == TransportUDP || *c.protocol == TransportUDPMulticast {
|
||||||
|
for _, cct := range c.tracks {
|
||||||
|
cct.udpRTPListener.stop()
|
||||||
|
cct.udpRTCPListener.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1625,15 +1628,13 @@ func (c *Client) doPlay(ra *headers.Range, isSwitchingProtocol bool) (*base.Resp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.state = clientStatePrePlay
|
|
||||||
|
|
||||||
return nil, liberrors.ErrClientBadStatusCode{
|
return nil, liberrors.ErrClientBadStatusCode{
|
||||||
Code: res.StatusCode, Message: res.StatusMessage,
|
Code: res.StatusCode, Message: res.StatusMessage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.lastRange = ra
|
c.lastRange = ra
|
||||||
|
c.state = clientStatePlay
|
||||||
c.playRecordStart()
|
c.playRecordStart()
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
@@ -1674,13 +1675,10 @@ func (c *Client) doRecord() (*base.Response, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.state = clientStateRecord
|
|
||||||
|
|
||||||
if *c.protocol == TransportUDP {
|
if *c.protocol == TransportUDP {
|
||||||
// start UDP listeners
|
|
||||||
for _, cct := range c.tracks {
|
for _, cct := range c.tracks {
|
||||||
cct.udpRTPListener.start()
|
cct.udpRTPListener.start(false)
|
||||||
cct.udpRTCPListener.start()
|
cct.udpRTCPListener.start(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1689,6 +1687,13 @@ func (c *Client) doRecord() (*base.Response, error) {
|
|||||||
URL: c.streamBaseURL,
|
URL: c.streamBaseURL,
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if *c.protocol == TransportUDP {
|
||||||
|
for _, cct := range c.tracks {
|
||||||
|
cct.udpRTPListener.stop()
|
||||||
|
cct.udpRTCPListener.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1700,13 +1705,12 @@ func (c *Client) doRecord() (*base.Response, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.state = clientStatePreRecord
|
|
||||||
|
|
||||||
return nil, liberrors.ErrClientBadStatusCode{
|
return nil, liberrors.ErrClientBadStatusCode{
|
||||||
Code: res.StatusCode, Message: res.StatusMessage,
|
Code: res.StatusCode, Message: res.StatusMessage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.state = clientStateRecord
|
||||||
c.playRecordStart()
|
c.playRecordStart()
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -1761,7 +1765,7 @@ func (c *Client) doPause() (*base.Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != base.StatusOK {
|
if res.StatusCode != base.StatusOK {
|
||||||
return res, liberrors.ErrClientBadStatusCode{
|
return nil, liberrors.ErrClientBadStatusCode{
|
||||||
Code: res.StatusCode, Message: res.StatusMessage,
|
Code: res.StatusCode, Message: res.StatusMessage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -128,8 +128,8 @@ func (l *clientUDPListener) port() int {
|
|||||||
return l.pc.LocalAddr().(*net.UDPAddr).Port
|
return l.pc.LocalAddr().(*net.UDPAddr).Port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *clientUDPListener) start() {
|
func (l *clientUDPListener) start(forPlay bool) {
|
||||||
if l.c.state == clientStatePlay {
|
if forPlay {
|
||||||
if l.isRTP {
|
if l.isRTP {
|
||||||
l.processFunc = l.processPlayRTP
|
l.processFunc = l.processPlayRTP
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user