diff --git a/README.md b/README.md index b3ef534..bab7d74 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,15 @@ ListenAddr = ":554" BufferLength = 2048 AutoPull = false RemoteAddr = "rtsp://localhost/${streamPath}" +[[RTSP.AutoPullList]] +URL = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=1&subtype=1" +StreamPath = "live/rtsp" ``` - ListenAddr 是监听端口,可以将rtsp流推到Monibuca中 - BufferLength是指解析拉取的rtp包的缓冲大小 - AutoPull是指当有用户订阅一个新流的时候自动向远程拉流转发 - RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。 - +- AutoPullList 是一个数组,如果配置了该数组,则会在程序启动时自动启动拉流,StreamPath一定要是唯一的,不能重复 ## 使用方法(拉流转发) ```go diff --git a/go.mod b/go.mod index 177f597..82fba05 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Monibuca/plugin-rtsp go 1.13 require ( - github.com/Monibuca/engine/v2 v2.2.1 + github.com/Monibuca/engine/v2 v2.2.2 github.com/Monibuca/plugin-rtp v1.0.0 github.com/logrusorgru/aurora v2.0.3+incompatible // indirect github.com/mattn/go-colorable v0.1.7 // indirect diff --git a/go.sum b/go.sum index 6a27f09..187416a 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/Monibuca/engine/v2 v2.2.0 h1:A4SyWwzVLegd8Oa6LfSW3LpNfBmWq+MHJJLO55gv github.com/Monibuca/engine/v2 v2.2.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc= github.com/Monibuca/engine/v2 v2.2.1 h1:I9mcnj9ZABl974n+HKGWe4pFcn9z8kETLVpD1fx2zEI= github.com/Monibuca/engine/v2 v2.2.1/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc= +github.com/Monibuca/engine/v2 v2.2.2 h1:ho5M3aFW9Mlj9Lb56Qvk0m+9L8yWc7RhwPh8dRWAeBk= +github.com/Monibuca/engine/v2 v2.2.2/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc= github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb h1:CnmoQ8XsWxs/6mulbQfTGUa8cPr6c/3bkkTsNozRBwE= github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb/go.mod h1:8HxBilkF835Lepe/DLUCjaw1mRiu3MxTDsG7g9UcfZA= github.com/Monibuca/plugin-rtp v1.0.0 h1:yksNsIIGxoKX8UZirkAUK+mGZ/XoEeS2vqbIqtqXyCg= diff --git a/main.go b/main.go index 8881eb0..8f4bac4 100644 --- a/main.go +++ b/main.go @@ -18,12 +18,16 @@ import ( var collection sync.Map var config = struct { - ListenAddr string - AutoPull bool - RemoteAddr string - Timeout int - Reconnect bool -}{":554", false, "rtsp://localhost/${streamPath}", 0, false} + ListenAddr string + AutoPull bool + RemoteAddr string + Timeout int + Reconnect bool + AutoPullList []*struct { + URL string + StreamPath string + } +}{":554", false, "rtsp://localhost/${streamPath}", 0, false, nil} func init() { InstallPlugin(&PluginConfig{ @@ -67,6 +71,13 @@ func runPlugin() { w.Write([]byte(fmt.Sprintf(`{"code":1,"msg":"%s"}`, err.Error()))) } }) + if len(config.AutoPullList) > 0 { + for _, info := range config.AutoPullList { + if err := new(RTSP).PullStream(info.StreamPath, info.URL); err != nil { + Println(err) + } + } + } if config.ListenAddr != "" { log.Fatal(ListenRtsp(config.ListenAddr)) } @@ -144,7 +155,8 @@ type RTSP struct { UDPClient *UDPClient Auth func(string) string } -func (rtsp *RTSP) setAudioFormat(){ + +func (rtsp *RTSP) setAudioFormat() { switch rtsp.ASdp.Codec { case "aac": rtsp.AudioInfo.SoundFormat = 10 @@ -158,6 +170,7 @@ func (rtsp *RTSP) setAudioFormat(){ rtsp.AudioInfo.SoundSize = 16 } } + type RTSPClientInfo struct { Agent string Session string