每次重连切换连接方式

This commit is contained in:
dexter
2021-11-23 12:40:21 +08:00
parent 4107d31c79
commit 00ecd3469f
2 changed files with 20 additions and 10 deletions

View File

@@ -34,6 +34,11 @@ func (rtsp *RTSPClient) PullStream(streamPath string, rtspUrl string) (err error
go func() {
for rtsp.startStream(); rtsp.Err() == nil; rtsp.startStream() {
Printf("reconnecting:%s in 5 seconds", rtspUrl)
if rtsp.Transport == gortsplib.TransportTCP {
rtsp.Transport = gortsplib.TransportUDP
} else {
rtsp.Transport = gortsplib.TransportTCP
}
time.Sleep(time.Second * 5)
}
if rtsp.IsTimeout {
@@ -166,11 +171,13 @@ func (client *RTSPClient) startStream() {
// find published tracks
tracks, baseURL, res, err := client.Describe(u)
if err != nil {
Printf("Describe:%s error:%v", baseURL.String(), err)
Printf("Describe:%s error:%v", client.URL, err)
return
}
Println(res)
client.setTracks(tracks)
if client.processFunc == nil {
client.setTracks(tracks)
}
for _, track := range tracks {
if res, err = client.Setup(true, baseURL, track, 0, 0); err != nil {
Printf("Setup:%s error:%v", baseURL.String(), err)