From cb733b368f56f37df6e547e10c72c3f111bba357 Mon Sep 17 00:00:00 2001 From: unknown <17080854@sn.suning.ad> Date: Thu, 9 Jul 2020 20:04:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=BF=9E=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 25 +++++++++++++++++++++---- main.go | 3 ++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index d0b89de..a765191 100644 --- a/client.go +++ b/client.go @@ -7,8 +7,6 @@ import ( "encoding/binary" "errors" "fmt" - . "github.com/Monibuca/engine/v2" - . "github.com/Monibuca/plugin-rtp" "io" "net" "net/url" @@ -16,6 +14,9 @@ import ( "strconv" "strings" "time" + + . "github.com/Monibuca/engine/v2" + . "github.com/Monibuca/plugin-rtp" ) // PullStream 从外部拉流 @@ -229,7 +230,11 @@ func (client *RTSP) requestStream() (err error) { if audioInfo, ok := client.SDPMap["audio"]; ok { client.AControl = audioInfo.Control client.ACodec = audioInfo.Codec - client.WriteASC(audioInfo.Config) + if len(audioInfo.Config) < 2 { + Printf("Setup audio err codec not support: %s", client.ACodec) + } else { + client.WriteASC(audioInfo.Config) + } var _url = "" if strings.Index(strings.ToLower(client.AControl), "rtsp://") == 0 { _url = client.AControl @@ -272,7 +277,19 @@ func (client *RTSP) requestStream() (err error) { func (client *RTSP) startStream() { //startTime := time.Now() //loggerTime := time.Now().Add(-10 * time.Second) - defer client.Stop() + if config.Reconnect { + defer func() { + Printf("reconnecting:", client.URL) + if err := client.requestStream(); err != nil { + Println(err) + client.Close() + return + } + go client.startStream() + }() + } else { + defer client.Stop() + } for client.Err() == nil { //if client.OptionIntervalMillis > 0 { // if time.Since(startTime) > time.Duration(client.OptionIntervalMillis)*time.Millisecond { diff --git a/main.go b/main.go index ab50dfc..8031658 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,8 @@ var config = struct { AutoPull bool RemoteAddr string Timeout int -}{":554", false, "rtsp://localhost/${streamPath}", 0} + Reconnect bool +}{":554", false, "rtsp://localhost/${streamPath}", 0,false} func init() { InstallPlugin(&PluginConfig{