From bbd668796ef3963e4a2c8c38c6085c47152a5b43 Mon Sep 17 00:00:00 2001 From: dexter <178529795@qq.com> Date: Mon, 11 Oct 2021 15:40:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E8=BF=9E=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index c855aa9..5f9eb7f 100644 --- a/client.go +++ b/client.go @@ -35,7 +35,22 @@ func (rtsp *RTSP) PullStream(streamPath string, rtspUrl string) (err error) { rtsp.aRTPControlChannel = 3 rtsp.URL = rtspUrl rtsp.UDPServer = &UDPServer{Session: rtsp} - go rtsp.startStream() + if config.Reconnect { + go func() { + for rtsp.Err() == nil { + rtsp.RTSPClientInfo = RTSPClientInfo{} + Printf("reconnecting:%s in 5 seconds", rtspUrl) + rtsp.startStream() + } + rtsp.Stop() + }() + } else { + rtsp.RTSPClientInfo = RTSPClientInfo{} + go func() { + rtsp.startStream() + rtsp.Stop() + }() + } return } return errors.New("publish badname") @@ -266,15 +281,6 @@ func (client *RTSP) startStream() { } startTime := time.Now() //loggerTime := time.Now().Add(-10 * time.Second) - defer func() { - if client.Err() == nil && config.Reconnect { - client.RTSPClientInfo = RTSPClientInfo{} - Printf("reconnecting:%s in 5 seconds", client.URL) - time.AfterFunc(time.Second*5, client.startStream) - } else { - client.Stop() - } - }() if err := client.requestStream(); err != nil { Printf("rtsp requestStream err:%v", err) return