怎加初始拉流功能

This commit is contained in:
langhuihui
2020-10-01 20:12:26 +08:00
parent d6384dcbd5
commit 7e61ba71f7
4 changed files with 27 additions and 9 deletions

View File

@@ -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

2
go.mod
View File

@@ -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

2
go.sum
View File

@@ -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=

27
main.go
View File

@@ -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