mirror of
https://github.com/Monibuca/plugin-rtsp.git
synced 2025-09-27 20:12:14 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7ff13d89ce | ||
![]() |
a9cb4cd853 | ||
![]() |
7e61ba71f7 | ||
![]() |
d6384dcbd5 | ||
![]() |
2159a6fd9b | ||
![]() |
02f3e91085 |
@@ -13,12 +13,15 @@ ListenAddr = ":554"
|
|||||||
BufferLength = 2048
|
BufferLength = 2048
|
||||||
AutoPull = false
|
AutoPull = false
|
||||||
RemoteAddr = "rtsp://localhost/${streamPath}"
|
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中
|
- ListenAddr 是监听端口,可以将rtsp流推到Monibuca中
|
||||||
- BufferLength是指解析拉取的rtp包的缓冲大小
|
- BufferLength是指解析拉取的rtp包的缓冲大小
|
||||||
- AutoPull是指当有用户订阅一个新流的时候自动向远程拉流转发
|
- AutoPull是指当有用户订阅一个新流的时候自动向远程拉流转发
|
||||||
- RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。
|
- RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。
|
||||||
|
- AutoPullList 是一个数组,如果配置了该数组,则会在程序启动时自动启动拉流,StreamPath一定要是唯一的,不能重复
|
||||||
|
|
||||||
## 使用方法(拉流转发)
|
## 使用方法(拉流转发)
|
||||||
```go
|
```go
|
||||||
|
@@ -231,10 +231,10 @@ func (client *RTSP) requestStream() (err error) {
|
|||||||
client.Conn.timeout = 0 // UDP ignore timeout
|
client.Conn.timeout = 0 // UDP ignore timeout
|
||||||
}
|
}
|
||||||
case "audio":
|
case "audio":
|
||||||
if len(sdpInfo.Config) < 2 {
|
if len(sdpInfo.Config) > 0 {
|
||||||
Printf("Setup audio err codec not support: %s", client.ASdp.Codec)
|
|
||||||
} else {
|
|
||||||
client.WriteASC(sdpInfo.Config)
|
client.WriteASC(sdpInfo.Config)
|
||||||
|
}else{
|
||||||
|
client.setAudioFormat()
|
||||||
}
|
}
|
||||||
if client.TransType == TRANS_TYPE_TCP {
|
if client.TransType == TRANS_TYPE_TCP {
|
||||||
headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.aRTPChannel, client.aRTPControlChannel)
|
headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.aRTPChannel, client.aRTPControlChannel)
|
||||||
@@ -337,9 +337,6 @@ func (client *RTSP) startStream() {
|
|||||||
pack = &RTPPack{
|
pack = &RTPPack{
|
||||||
Type: RTP_TYPE_AUDIO,
|
Type: RTP_TYPE_AUDIO,
|
||||||
}
|
}
|
||||||
if client.ASdp.Codec != "aac" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
case client.aRTPControlChannel:
|
case client.aRTPControlChannel:
|
||||||
pack = &RTPPack{
|
pack = &RTPPack{
|
||||||
Type: RTP_TYPE_AUDIOCONTROL,
|
Type: RTP_TYPE_AUDIOCONTROL,
|
||||||
|
4
go.mod
4
go.mod
@@ -3,8 +3,8 @@ module github.com/Monibuca/plugin-rtsp
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Monibuca/engine/v2 v2.1.9
|
github.com/Monibuca/engine/v2 v2.4.0
|
||||||
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb
|
github.com/Monibuca/plugin-rtp v1.0.0
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||||
github.com/mattn/go-colorable v0.1.7 // indirect
|
github.com/mattn/go-colorable v0.1.7 // indirect
|
||||||
github.com/pion/rtp v1.6.0 // indirect
|
github.com/pion/rtp v1.6.0 // indirect
|
||||||
|
21
go.sum
21
go.sum
@@ -1,13 +1,10 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Monibuca/engine/v2 v2.1.0 h1:pHeDCEFDusKFsZLpconYj8U5LCaWApnjd+yQRHYgQsQ=
|
github.com/Monibuca/engine/v2 v2.2.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||||
github.com/Monibuca/engine/v2 v2.1.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
github.com/Monibuca/engine/v2 v2.4.0 h1:aa647MW5ToMdVQlB4nehfc3Vcos6752aLYRAkRnMLqo=
|
||||||
github.com/Monibuca/engine/v2 v2.1.2 h1:7dUrHJAPEtvGFOO4GsKGjfMCmcbMrtLyYQ7WoK5EpG0=
|
github.com/Monibuca/engine/v2 v2.4.0/go.mod h1:LBuAJFcTtUjVsGKWcUKQpIftRECf7Ii9DfuGWHL3Ngg=
|
||||||
github.com/Monibuca/engine/v2 v2.1.2/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
github.com/Monibuca/plugin-rtp v1.0.0 h1:yksNsIIGxoKX8UZirkAUK+mGZ/XoEeS2vqbIqtqXyCg=
|
||||||
github.com/Monibuca/engine/v2 v2.1.9 h1:IulMIeP24qv8xWaI+tcg233Y7w3mCaLXxt4iQaVpT7s=
|
github.com/Monibuca/plugin-rtp v1.0.0/go.mod h1:0xkNm23a/BjVnEMz1zXyOqfEjoVmGe3PJqPNF1KyFGc=
|
||||||
github.com/Monibuca/engine/v2 v2.1.9/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/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
@@ -18,11 +15,11 @@ github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1B
|
|||||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500/go.mod h1:mUn39tBov9jKnTWV1RlOYoNzxdBFHiSzXWdY1FoNGGg=
|
github.com/funny/utest v0.0.0-20161029064919-43870a374500/go.mod h1:mUn39tBov9jKnTWV1RlOYoNzxdBFHiSzXWdY1FoNGGg=
|
||||||
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
||||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||||
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 h1:bqDmpDG49ZRnB5PcgP0RXtQvnMSgIF14M7CBd2shtXs=
|
|
||||||
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||||
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
github.com/mask-pp/rtp-ps v1.0.0 h1:JFxuJL9N+gD1ldgJlAy3b7rYfY8wAVHi9ODNmdP4+EE=
|
||||||
|
github.com/mask-pp/rtp-ps v1.0.0/go.mod h1:jCxsZ2G7z/jX+aqFypEWMePnhNrfnUiXUEKm6Xp0vgU=
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
|
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
|
||||||
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
@@ -30,7 +27,6 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
|
|||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||||
github.com/pion/randutil v0.0.0 h1:aLWLVhTG2jzoD25F0OlW6nXvXrjoGwiXq2Sz7j7NzL0=
|
github.com/pion/randutil v0.0.0 h1:aLWLVhTG2jzoD25F0OlW6nXvXrjoGwiXq2Sz7j7NzL0=
|
||||||
github.com/pion/randutil v0.0.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
github.com/pion/randutil v0.0.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||||
github.com/pion/rtp v1.5.4 h1:PuNg6xqV3brIUihatcKZj1YDUs+M45L0ZbrZWYtkDxY=
|
|
||||||
github.com/pion/rtp v1.5.4/go.mod h1:bg60AL5GotNOlYZsqycbhDtEV3TkfbpXG0KBiUq29Mg=
|
github.com/pion/rtp v1.5.4/go.mod h1:bg60AL5GotNOlYZsqycbhDtEV3TkfbpXG0KBiUq29Mg=
|
||||||
github.com/pion/rtp v1.6.0 h1:4Ssnl/T5W2LzxHj9ssYpGVEQh3YYhQFNVmSWO88MMwk=
|
github.com/pion/rtp v1.6.0 h1:4Ssnl/T5W2LzxHj9ssYpGVEQh3YYhQFNVmSWO88MMwk=
|
||||||
github.com/pion/rtp v1.6.0/go.mod h1:QgfogHsMBVE/RFNno467U/KBqfUywEH+HK+0rtnwsdI=
|
github.com/pion/rtp v1.6.0/go.mod h1:QgfogHsMBVE/RFNno467U/KBqfUywEH+HK+0rtnwsdI=
|
||||||
@@ -38,18 +34,15 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/shirou/gopsutil v2.20.1+incompatible h1:oIq9Cq4i84Hk8uQAUOG3eNdI/29hBawGrD5YRl6JRDY=
|
|
||||||
github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
github.com/shirou/gopsutil v2.20.7+incompatible h1:Ymv4OD12d6zm+2yONe39VSmp2XooJe8za7ngOLW/o/w=
|
github.com/shirou/gopsutil v2.20.7+incompatible h1:Ymv4OD12d6zm+2yONe39VSmp2XooJe8za7ngOLW/o/w=
|
||||||
github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
|
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
|
||||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16 h1:54u1berWyLujz9htI1BHtZpcCEYaYNUSDFLXMNDd7To=
|
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16 h1:54u1berWyLujz9htI1BHtZpcCEYaYNUSDFLXMNDd7To=
|
||||||
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
45
main.go
45
main.go
@@ -2,6 +2,7 @@ package rtsp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@@ -16,14 +17,21 @@ import (
|
|||||||
"github.com/teris-io/shortid"
|
"github.com/teris-io/shortid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed ui/*
|
||||||
|
//go:embed README.md
|
||||||
|
var ui embed.FS
|
||||||
var collection sync.Map
|
var collection sync.Map
|
||||||
var config = struct {
|
var config = struct {
|
||||||
ListenAddr string
|
ListenAddr string
|
||||||
AutoPull bool
|
AutoPull bool
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
Timeout int
|
Timeout int
|
||||||
Reconnect bool
|
Reconnect bool
|
||||||
}{":554", false, "rtsp://localhost/${streamPath}", 0, false}
|
AutoPullList []*struct {
|
||||||
|
URL string
|
||||||
|
StreamPath string
|
||||||
|
}
|
||||||
|
}{":554", false, "rtsp://localhost/${streamPath}", 0, false, nil}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
InstallPlugin(&PluginConfig{
|
InstallPlugin(&PluginConfig{
|
||||||
@@ -36,6 +44,7 @@ func init() {
|
|||||||
config.AutoPull = value.(bool)
|
config.AutoPull = value.(bool)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
UIFile: &ui,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func runPlugin() {
|
func runPlugin() {
|
||||||
@@ -59,6 +68,7 @@ func runPlugin() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
http.HandleFunc("/rtsp/pull", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/rtsp/pull", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
targetURL := r.URL.Query().Get("target")
|
targetURL := r.URL.Query().Get("target")
|
||||||
streamPath := r.URL.Query().Get("streamPath")
|
streamPath := r.URL.Query().Get("streamPath")
|
||||||
if err := new(RTSP).PullStream(streamPath, targetURL); err == nil {
|
if err := new(RTSP).PullStream(streamPath, targetURL); err == nil {
|
||||||
@@ -67,6 +77,13 @@ func runPlugin() {
|
|||||||
w.Write([]byte(fmt.Sprintf(`{"code":1,"msg":"%s"}`, err.Error())))
|
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 != "" {
|
if config.ListenAddr != "" {
|
||||||
log.Fatal(ListenRtsp(config.ListenAddr))
|
log.Fatal(ListenRtsp(config.ListenAddr))
|
||||||
}
|
}
|
||||||
@@ -144,6 +161,22 @@ type RTSP struct {
|
|||||||
UDPClient *UDPClient
|
UDPClient *UDPClient
|
||||||
Auth func(string) string
|
Auth func(string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rtsp *RTSP) setAudioFormat() {
|
||||||
|
switch rtsp.ASdp.Codec {
|
||||||
|
case "aac":
|
||||||
|
rtsp.AudioInfo.SoundFormat = 10
|
||||||
|
case "pcma":
|
||||||
|
rtsp.AudioInfo.SoundFormat = 7
|
||||||
|
rtsp.AudioInfo.SoundRate = rtsp.ASdp.TimeScale
|
||||||
|
rtsp.AudioInfo.SoundSize = 16
|
||||||
|
case "pcmu":
|
||||||
|
rtsp.AudioInfo.SoundFormat = 8
|
||||||
|
rtsp.AudioInfo.SoundRate = rtsp.ASdp.TimeScale
|
||||||
|
rtsp.AudioInfo.SoundSize = 16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type RTSPClientInfo struct {
|
type RTSPClientInfo struct {
|
||||||
Agent string
|
Agent string
|
||||||
Session string
|
Session string
|
||||||
|
67
session.go
67
session.go
@@ -318,12 +318,15 @@ func (session *RTSP) handleRequest(req *Request) {
|
|||||||
session.SDPRaw = req.Body
|
session.SDPRaw = req.Body
|
||||||
session.SDPMap = ParseSDP(req.Body)
|
session.SDPMap = ParseSDP(req.Body)
|
||||||
if session.Publish(streamPath) {
|
if session.Publish(streamPath) {
|
||||||
var ok bool
|
if session.ASdp, session.HasAudio = session.SDPMap["audio"]; session.HasAudio {
|
||||||
if session.ASdp, ok = session.SDPMap["audio"]; ok {
|
if len(session.ASdp.Control) > 0 {
|
||||||
session.WriteASC(session.ASdp.Config)
|
session.WriteASC(session.ASdp.Config)
|
||||||
|
} else {
|
||||||
|
session.setAudioFormat()
|
||||||
|
}
|
||||||
Printf("audio codec[%s]\n", session.ASdp.Codec)
|
Printf("audio codec[%s]\n", session.ASdp.Codec)
|
||||||
}
|
}
|
||||||
if session.VSdp, ok = session.SDPMap["video"]; ok {
|
if session.VSdp, session.HasVideo = session.SDPMap["video"]; session.HasVideo {
|
||||||
if len(session.VSdp.SpropParameterSets) > 1 {
|
if len(session.VSdp.SpropParameterSets) > 1 {
|
||||||
session.WriteSPS(session.VSdp.SpropParameterSets[0])
|
session.WriteSPS(session.VSdp.SpropParameterSets[0])
|
||||||
session.WritePPS(session.VSdp.SpropParameterSets[1])
|
session.WritePPS(session.VSdp.SpropParameterSets[1])
|
||||||
@@ -376,36 +379,38 @@ func (session *RTSP) handleRequest(req *Request) {
|
|||||||
// res.Status = "Error Status"
|
// res.Status = "Error Status"
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
vPath := ""
|
var vPath, aPath string
|
||||||
if strings.Index(strings.ToLower(session.VSdp.Control), "rtsp://") == 0 {
|
if session.HasVideo {
|
||||||
vControlUrl, err := url.Parse(session.VSdp.Control)
|
if strings.Index(strings.ToLower(session.VSdp.Control), "rtsp://") == 0 {
|
||||||
if err != nil {
|
vControlUrl, err := url.Parse(session.VSdp.Control)
|
||||||
res.StatusCode = 500
|
if err != nil {
|
||||||
res.Status = "Invalid VControl"
|
res.StatusCode = 500
|
||||||
return
|
res.Status = "Invalid VControl"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if vControlUrl.Port() == "" {
|
||||||
|
vControlUrl.Host = fmt.Sprintf("%s:554", vControlUrl.Host)
|
||||||
|
}
|
||||||
|
vPath = vControlUrl.String()
|
||||||
|
} else {
|
||||||
|
vPath = session.VSdp.Control
|
||||||
}
|
}
|
||||||
if vControlUrl.Port() == "" {
|
|
||||||
vControlUrl.Host = fmt.Sprintf("%s:554", vControlUrl.Host)
|
|
||||||
}
|
|
||||||
vPath = vControlUrl.String()
|
|
||||||
} else {
|
|
||||||
vPath = session.VSdp.Control
|
|
||||||
}
|
}
|
||||||
|
if session.HasAudio {
|
||||||
aPath := ""
|
if strings.Index(strings.ToLower(session.ASdp.Control), "rtsp://") == 0 {
|
||||||
if strings.Index(strings.ToLower(session.ASdp.Control), "rtsp://") == 0 {
|
aControlUrl, err := url.Parse(session.ASdp.Control)
|
||||||
aControlUrl, err := url.Parse(session.ASdp.Control)
|
if err != nil {
|
||||||
if err != nil {
|
res.StatusCode = 500
|
||||||
res.StatusCode = 500
|
res.Status = "Invalid AControl"
|
||||||
res.Status = "Invalid AControl"
|
return
|
||||||
return
|
}
|
||||||
|
if aControlUrl.Port() == "" {
|
||||||
|
aControlUrl.Host = fmt.Sprintf("%s:554", aControlUrl.Host)
|
||||||
|
}
|
||||||
|
aPath = aControlUrl.String()
|
||||||
|
} else {
|
||||||
|
aPath = session.ASdp.Control
|
||||||
}
|
}
|
||||||
if aControlUrl.Port() == "" {
|
|
||||||
aControlUrl.Host = fmt.Sprintf("%s:554", aControlUrl.Host)
|
|
||||||
}
|
|
||||||
aPath = aControlUrl.String()
|
|
||||||
} else {
|
|
||||||
aPath = session.ASdp.Control
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mtcp := regexp.MustCompile("interleaved=(\\d+)(-(\\d+))?")
|
mtcp := regexp.MustCompile("interleaved=(\\d+)(-(\\d+))?")
|
||||||
|
Reference in New Issue
Block a user