fix: 修复错误的流地址导致的Disconnect时panic

This commit is contained in:
Ynit
2023-08-31 00:12:07 +08:00
parent 9936b2ca20
commit 5df8f237de

View File

@@ -28,7 +28,7 @@ func (p *RTSPClient) Disconnect() {
} }
func (p *RTSPPuller) Connect() error { func (p *RTSPPuller) Connect() error {
p.Client = &gortsplib.Client{ client := &gortsplib.Client{
DialContext: p.DialContext, DialContext: p.DialContext,
ReadBufferCount: rtspConfig.ReadBufferCount, ReadBufferCount: rtspConfig.ReadBufferCount,
AnyPortEnable: true, AnyPortEnable: true,
@@ -37,10 +37,10 @@ func (p *RTSPPuller) Connect() error {
switch rtspConfig.PullProtocol { switch rtspConfig.PullProtocol {
case "tcp", "TCP": case "tcp", "TCP":
p.Transport = gortsplib.TransportTCP p.Transport = gortsplib.TransportTCP
p.Client.Transport = &p.Transport client.Transport = &p.Transport
case "udp", "UDP": case "udp", "UDP":
p.Transport = gortsplib.TransportUDP p.Transport = gortsplib.TransportUDP
p.Client.Transport = &p.Transport client.Transport = &p.Transport
} }
// parse URL // parse URL
u, err := url.Parse(p.RemoteURL) u, err := url.Parse(p.RemoteURL)
@@ -48,9 +48,10 @@ func (p *RTSPPuller) Connect() error {
return err return err
} }
// connect to the server // connect to the server
if err = p.Client.Start(u.Scheme, u.Host); err != nil { if err = client.Start(u.Scheme, u.Host); err != nil {
return err return err
} }
p.Client = client
p.SetIO(p.Client) p.SetIO(p.Client)
return nil return nil
} }