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 {
p.Client = &gortsplib.Client{
client := &gortsplib.Client{
DialContext: p.DialContext,
ReadBufferCount: rtspConfig.ReadBufferCount,
AnyPortEnable: true,
@@ -37,10 +37,10 @@ func (p *RTSPPuller) Connect() error {
switch rtspConfig.PullProtocol {
case "tcp", "TCP":
p.Transport = gortsplib.TransportTCP
p.Client.Transport = &p.Transport
client.Transport = &p.Transport
case "udp", "UDP":
p.Transport = gortsplib.TransportUDP
p.Client.Transport = &p.Transport
client.Transport = &p.Transport
}
// parse URL
u, err := url.Parse(p.RemoteURL)
@@ -48,9 +48,10 @@ func (p *RTSPPuller) Connect() error {
return err
}
// 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
}
p.Client = client
p.SetIO(p.Client)
return nil
}