mirror of
https://github.com/Monibuca/plugin-rtsp.git
synced 2025-10-04 23:32:54 +08:00
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7e61ba71f7 | ||
![]() |
d6384dcbd5 | ||
![]() |
2159a6fd9b | ||
![]() |
02f3e91085 | ||
![]() |
7f40078b50 | ||
![]() |
bb563d64c7 | ||
![]() |
f7cb146b89 | ||
![]() |
9bb49cb9f7 | ||
![]() |
087d1aab4d | ||
![]() |
f949464328 | ||
![]() |
d89f1e2405 | ||
![]() |
1d3fbfc20b | ||
![]() |
fd64a69a12 | ||
![]() |
0e4406ad14 | ||
![]() |
22f33886a9 | ||
![]() |
8b1892209d | ||
![]() |
2e9cf9a4ca | ||
![]() |
67da93d8e2 | ||
![]() |
cb733b368f | ||
![]() |
fadeccddab | ||
![]() |
93df7632a6 | ||
![]() |
53c4788df2 | ||
![]() |
f5bdd6a298 | ||
![]() |
eaddc60775 | ||
![]() |
655170cb24 | ||
![]() |
55bd2ce785 | ||
![]() |
2004a6afc1 | ||
![]() |
1873861e8b |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019-present, dexter
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
13
README.md
13
README.md
@@ -1,6 +1,6 @@
|
||||
# Monibuca 的RTSP 插件
|
||||
|
||||
主要功能是对RTSP地址进行拉流转换
|
||||
主要功能是提供RTSP的端口监听接受RTSP推流,以及对RTSP地址进行拉流转发
|
||||
|
||||
## 插件名称
|
||||
|
||||
@@ -9,16 +9,21 @@ RTSP
|
||||
## 配置
|
||||
```toml
|
||||
[RTSP]
|
||||
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是指当有用户订阅一个新房间的时候自动向远程拉流转发
|
||||
- AutoPull是指当有用户订阅一个新流的时候自动向远程拉流转发
|
||||
- RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。
|
||||
|
||||
- AutoPullList 是一个数组,如果配置了该数组,则会在程序启动时自动启动拉流,StreamPath一定要是唯一的,不能重复
|
||||
|
||||
## 使用方法(拉流转发)
|
||||
```go
|
||||
new(RTSP).Publish("live/user1","rtsp://xxx.xxx.xxx.xxx/live/user1")
|
||||
new(RTSP).PullStream("live/user1","rtsp://xxx.xxx.xxx.xxx/live/user1")
|
||||
```
|
10
go.mod
10
go.mod
@@ -3,6 +3,12 @@ module github.com/Monibuca/plugin-rtsp
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/Monibuca/engine v1.2.1
|
||||
github.com/Monibuca/engine/v2 v2.0.0 // indirect
|
||||
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
|
||||
github.com/pion/rtp v1.6.0 // indirect
|
||||
github.com/shirou/gopsutil v2.20.7+incompatible // indirect
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
|
||||
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16 // indirect
|
||||
)
|
||||
|
44
go.sum
44
go.sum
@@ -1,16 +1,25 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Monibuca/engine v1.2.1 h1:TJmC6eZA1lR1MScWgempZLiEZD4T6aY/nn/rlQ9UdK8=
|
||||
github.com/Monibuca/engine v1.2.1/go.mod h1:WbDkXENLjcPjyjCR1Mix1GA+uAlwORkv/+8aMVrDX2g=
|
||||
github.com/Monibuca/engine v1.2.2 h1:hNjsrZpOmui8lYhgCJ5ltJU8g/k0Rrdysx2tHNGGnbI=
|
||||
github.com/Monibuca/engine/v2 v2.0.0 h1:8FjaScrtN8QdbcxO9zZYABMC0Re3I1O1T4p94zAXYb0=
|
||||
github.com/Monibuca/engine/v2 v2.0.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.1.0 h1:pHeDCEFDusKFsZLpconYj8U5LCaWApnjd+yQRHYgQsQ=
|
||||
github.com/Monibuca/engine/v2 v2.1.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.1.2 h1:7dUrHJAPEtvGFOO4GsKGjfMCmcbMrtLyYQ7WoK5EpG0=
|
||||
github.com/Monibuca/engine/v2 v2.1.2/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.1.9 h1:IulMIeP24qv8xWaI+tcg233Y7w3mCaLXxt4iQaVpT7s=
|
||||
github.com/Monibuca/engine/v2 v2.1.9/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.2.0 h1:A4SyWwzVLegd8Oa6LfSW3LpNfBmWq+MHJJLO55gvaYI=
|
||||
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=
|
||||
github.com/Monibuca/plugin-rtp v1.0.0/go.mod h1:0xkNm23a/BjVnEMz1zXyOqfEjoVmGe3PJqPNF1KyFGc=
|
||||
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/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/falconray0704/gortmp v0.0.0-20170613085150-e3f9bb02c7c8 h1:Bkx+0neYCcHW7BUeVCbR2GOn47NesdImh8nHHOKccD4=
|
||||
github.com/falconray0704/gortmp v0.0.0-20170613085150-e3f9bb02c7c8/go.mod h1:/JBZajtCDe9Z4j84v5QWo4PLn1K6jcBHh6qXN/bm/vw=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478/go.mod h1:0j1+svBH8ABEIPdUP0AIg4qedsybnXGJBakCEw8cfoo=
|
||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg=
|
||||
@@ -19,28 +28,41 @@ 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/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 v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
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 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
||||
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/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/pixelbender/go-sdp v1.0.0 h1:hLP2ALBN4sLpgp2r3EDcFUSN3AyOkg1jonuWEJniotY=
|
||||
github.com/pixelbender/go-sdp v1.0.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs=
|
||||
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/rtp v1.5.4 h1:PuNg6xqV3brIUihatcKZj1YDUs+M45L0ZbrZWYtkDxY=
|
||||
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/go.mod h1:QgfogHsMBVE/RFNno467U/KBqfUywEH+HK+0rtnwsdI=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
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/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.7+incompatible h1:Ymv4OD12d6zm+2yONe39VSmp2XooJe8za7ngOLW/o/w=
|
||||
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/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
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/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
||||
github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8/go.mod h1:RZd/IqzNpFANwOB9rVmsnAYpo/6KesK4PqrN1a5cRgg=
|
||||
github.com/zhangpeihao/log v0.0.0-20170117094621-62e921e41859/go.mod h1:OAvmouyIV28taMw4SC4+hSnouObQqQkTQNOhU3Zowl0=
|
||||
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-20200828161417-c663848e9a16 h1:54u1berWyLujz9htI1BHtZpcCEYaYNUSDFLXMNDd7To=
|
||||
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
|
293
main.go
293
main.go
@@ -1,25 +1,33 @@
|
||||
package rtspplugin
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
. "github.com/Monibuca/engine/v2/avformat"
|
||||
"github.com/Monibuca/engine/v2/util"
|
||||
. "github.com/Monibuca/plugin-rtp"
|
||||
"github.com/teris-io/shortid"
|
||||
)
|
||||
|
||||
var collection = sync.Map{}
|
||||
var collection sync.Map
|
||||
var config = struct {
|
||||
BufferLength int
|
||||
ListenAddr string
|
||||
AutoPull bool
|
||||
RemoteAddr string
|
||||
}{2048, true, "rtsp://localhost/${streamPath}"}
|
||||
Timeout int
|
||||
Reconnect bool
|
||||
AutoPullList []*struct {
|
||||
URL string
|
||||
StreamPath string
|
||||
}
|
||||
}{":554", false, "rtsp://localhost/${streamPath}", 0, false, nil}
|
||||
|
||||
func init() {
|
||||
InstallPlugin(&PluginConfig{
|
||||
@@ -37,7 +45,7 @@ func init() {
|
||||
func runPlugin() {
|
||||
OnSubscribeHooks.AddHook(func(s *Subscriber) {
|
||||
if config.AutoPull && s.Publisher == nil {
|
||||
new(RTSP).Publish(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1))
|
||||
new(RTSP).PullStream(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1))
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/rtsp/list", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -48,7 +56,6 @@ func runPlugin() {
|
||||
collection.Range(func(key, value interface{}) bool {
|
||||
rtsp := value.(*RTSP)
|
||||
pinfo := &rtsp.RTSPInfo
|
||||
pinfo.BufferRate = len(rtsp.OutGoing) * 100 / config.BufferLength
|
||||
info = append(info, pinfo)
|
||||
return true
|
||||
})
|
||||
@@ -58,163 +65,147 @@ func runPlugin() {
|
||||
http.HandleFunc("/rtsp/pull", func(w http.ResponseWriter, r *http.Request) {
|
||||
targetURL := r.URL.Query().Get("target")
|
||||
streamPath := r.URL.Query().Get("streamPath")
|
||||
var err error
|
||||
if err == nil {
|
||||
new(RTSP).Publish(streamPath, targetURL)
|
||||
if err := new(RTSP).PullStream(streamPath, targetURL); err == nil {
|
||||
w.Write([]byte(`{"code":0}`))
|
||||
} else {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
func ListenRtsp(addr string) error {
|
||||
defer log.Println("rtsp server start!")
|
||||
listener, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var tempDelay time.Duration
|
||||
networkBuffer := 204800
|
||||
timeoutMillis := config.Timeout
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
conn.(*net.TCPConn).SetNoDelay(false)
|
||||
if err != nil {
|
||||
if ne, ok := err.(net.Error); ok && ne.Temporary() {
|
||||
if tempDelay == 0 {
|
||||
tempDelay = 5 * time.Millisecond
|
||||
} else {
|
||||
tempDelay *= 2
|
||||
}
|
||||
if max := 1 * time.Second; tempDelay > max {
|
||||
tempDelay = max
|
||||
}
|
||||
fmt.Printf("rtsp: Accept error: %v; retrying in %v", err, tempDelay)
|
||||
time.Sleep(tempDelay)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
tempDelay = 0
|
||||
timeoutTCPConn := &RichConn{conn, time.Duration(timeoutMillis) * time.Millisecond}
|
||||
go (&RTSP{
|
||||
ID: shortid.MustGenerate(),
|
||||
Conn: timeoutTCPConn,
|
||||
connRW: bufio.NewReadWriter(bufio.NewReaderSize(timeoutTCPConn, networkBuffer), bufio.NewWriterSize(timeoutTCPConn, networkBuffer)),
|
||||
Timeout: config.Timeout,
|
||||
vRTPChannel: -1,
|
||||
vRTPControlChannel: -1,
|
||||
aRTPChannel: -1,
|
||||
aRTPControlChannel: -1,
|
||||
}).AcceptPush()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type RTSP struct {
|
||||
Publisher
|
||||
*RtspClient
|
||||
RTP
|
||||
RTSPInfo
|
||||
RTSPClientInfo
|
||||
ID string
|
||||
Conn *RichConn
|
||||
connRW *bufio.ReadWriter
|
||||
connWLock sync.RWMutex
|
||||
Type SessionType
|
||||
TransType TransType
|
||||
|
||||
SDPMap map[string]*SDPInfo
|
||||
nonce string
|
||||
closeOld bool
|
||||
ASdp *SDPInfo
|
||||
VSdp *SDPInfo
|
||||
aacsent bool
|
||||
Timeout int
|
||||
//tcp channels
|
||||
aRTPChannel int
|
||||
aRTPControlChannel int
|
||||
vRTPChannel int
|
||||
vRTPControlChannel int
|
||||
UDPServer *UDPServer
|
||||
UDPClient *UDPClient
|
||||
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 {
|
||||
Agent string
|
||||
Session string
|
||||
authLine string
|
||||
Seq int
|
||||
}
|
||||
type RTSPInfo struct {
|
||||
SyncCount int64
|
||||
Header *string
|
||||
BufferRate int
|
||||
URL string
|
||||
SDPRaw string
|
||||
InBytes int
|
||||
OutBytes int
|
||||
StreamInfo *StreamInfo
|
||||
}
|
||||
|
||||
func (rtsp *RTSP) run() {
|
||||
fuBuffer := []byte{}
|
||||
iframeHead := []byte{0x17, 0x01, 0, 0, 0}
|
||||
pframeHead := []byte{0x27, 0x01, 0, 0, 0}
|
||||
spsHead := []byte{0xE1, 0, 0}
|
||||
ppsHead := []byte{0x01, 0, 0}
|
||||
nalLength := []byte{0, 0, 0, 0}
|
||||
avcsent := false
|
||||
aacsent := false
|
||||
handleNALU := func(nalType byte, payload []byte, ts int64) {
|
||||
rtsp.SyncCount++
|
||||
vl := len(payload)
|
||||
switch nalType {
|
||||
// case NALU_SPS:
|
||||
// r := bytes.NewBuffer([]byte{})
|
||||
// r.Write(RTMP_AVC_HEAD)
|
||||
// util.BigEndian.PutUint16(spsHead[1:], uint16(vl))
|
||||
// r.Write(spsHead)
|
||||
// r.Write(payload)
|
||||
// case NALU_PPS:
|
||||
// r := bytes.NewBuffer([]byte{})
|
||||
// util.BigEndian.PutUint16(ppsHead[1:], uint16(vl))
|
||||
// r.Write(ppsHead)
|
||||
// r.Write(payload)
|
||||
// rtsp.PushVideo(0, r.Bytes())
|
||||
// avcsent = true
|
||||
case NALU_IDR_Picture:
|
||||
if !avcsent {
|
||||
r := bytes.NewBuffer([]byte{})
|
||||
r.Write(RTMP_AVC_HEAD)
|
||||
util.BigEndian.PutUint16(spsHead[1:], uint16(len(rtsp.SPS)))
|
||||
r.Write(spsHead)
|
||||
r.Write(rtsp.SPS)
|
||||
util.BigEndian.PutUint16(ppsHead[1:], uint16(len(rtsp.PPS)))
|
||||
r.Write(ppsHead)
|
||||
r.Write(rtsp.PPS)
|
||||
rtsp.PushVideo(0, r.Bytes())
|
||||
avcsent = true
|
||||
}
|
||||
r := bytes.NewBuffer([]byte{})
|
||||
util.BigEndian.PutUint24(iframeHead[2:], 0)
|
||||
r.Write(iframeHead)
|
||||
util.BigEndian.PutUint32(nalLength, uint32(vl))
|
||||
r.Write(nalLength)
|
||||
r.Write(payload)
|
||||
rtsp.PushVideo(uint32(ts), r.Bytes())
|
||||
case NALU_Non_IDR_Picture:
|
||||
r := bytes.NewBuffer([]byte{})
|
||||
util.BigEndian.PutUint24(pframeHead[2:], 0)
|
||||
r.Write(pframeHead)
|
||||
util.BigEndian.PutUint32(nalLength, uint32(vl))
|
||||
r.Write(nalLength)
|
||||
r.Write(payload)
|
||||
rtsp.PushVideo(uint32(ts), r.Bytes())
|
||||
}
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-rtsp.Done():
|
||||
return
|
||||
case data, ok := <-rtsp.OutGoing:
|
||||
if ok && data[0] == 36 {
|
||||
if data[1] == 0 {
|
||||
cc := data[4] & 0xF
|
||||
//rtp header
|
||||
rtphdr := 12 + cc*4
|
||||
|
||||
//packet time
|
||||
ts := (int64(data[8]) << 24) + (int64(data[9]) << 16) + (int64(data[10]) << 8) + (int64(data[11]))
|
||||
|
||||
//packet number
|
||||
//packno := (int64(data[6]) << 8) + int64(data[7])
|
||||
data = data[4+rtphdr:]
|
||||
nalType := data[0] & 0x1F
|
||||
|
||||
if nalType >= 1 && nalType <= 23 {
|
||||
handleNALU(nalType, data, ts)
|
||||
} else if nalType == 28 {
|
||||
isStart := data[1]&0x80 != 0
|
||||
isEnd := data[1]&0x40 != 0
|
||||
nalType := data[1] & 0x1F
|
||||
//nri := (data[1]&0x60)>>5
|
||||
nal := data[0]&0xE0 | data[1]&0x1F
|
||||
if isStart {
|
||||
fuBuffer = []byte{0}
|
||||
}
|
||||
fuBuffer = append(fuBuffer, data[2:]...)
|
||||
if isEnd {
|
||||
fuBuffer[0] = nal
|
||||
handleNALU(nalType, fuBuffer, ts)
|
||||
}
|
||||
}
|
||||
|
||||
} else if data[1] == 2 {
|
||||
// audio
|
||||
if !aacsent {
|
||||
rtsp.PushAudio(0, append([]byte{0xAF, 0x00}, rtsp.AudioSpecificConfig...))
|
||||
aacsent = true
|
||||
}
|
||||
cc := data[4] & 0xF
|
||||
rtphdr := 12 + cc*4
|
||||
payload := data[4+rtphdr:]
|
||||
auHeaderLen := (int16(payload[0]) << 8) + int16(payload[1])
|
||||
auHeaderLen = auHeaderLen >> 3
|
||||
auHeaderCount := int(auHeaderLen / 2)
|
||||
var auLenArray []int
|
||||
for iIndex := 0; iIndex < int(auHeaderCount); iIndex++ {
|
||||
auHeaderInfo := (int16(payload[2+2*iIndex]) << 8) + int16(payload[2+2*iIndex+1])
|
||||
auLen := auHeaderInfo >> 3
|
||||
auLenArray = append(auLenArray, int(auLen))
|
||||
}
|
||||
startOffset := 2 + 2*auHeaderCount
|
||||
for _, auLen := range auLenArray {
|
||||
endOffset := startOffset + auLen
|
||||
addHead := []byte{0xAF, 0x01}
|
||||
rtsp.PushAudio(0, append(addHead, payload[startOffset:endOffset]...))
|
||||
startOffset = startOffset + auLen
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
type RichConn struct {
|
||||
net.Conn
|
||||
timeout time.Duration
|
||||
}
|
||||
func (rtsp *RTSP) Publish(streamPath string, rtspUrl string) (result bool) {
|
||||
if result = rtsp.Publisher.Publish(streamPath); result {
|
||||
rtsp.Type = "RTSP"
|
||||
rtsp.RTSPInfo.StreamInfo = &rtsp.Stream.StreamInfo
|
||||
rtsp.RtspClient = RtspClientNew(config.BufferLength)
|
||||
rtsp.RTSPInfo.Header = &rtsp.RtspClient.Header
|
||||
if status, message := rtsp.RtspClient.Client(rtspUrl); !status {
|
||||
log.Println(message)
|
||||
return false
|
||||
|
||||
func (conn *RichConn) Read(b []byte) (n int, err error) {
|
||||
if conn.timeout > 0 {
|
||||
conn.Conn.SetReadDeadline(time.Now().Add(conn.timeout))
|
||||
} else {
|
||||
var t time.Time
|
||||
conn.Conn.SetReadDeadline(t)
|
||||
}
|
||||
collection.Store(streamPath, rtsp)
|
||||
go rtsp.run()
|
||||
}
|
||||
return
|
||||
return conn.Conn.Read(b)
|
||||
}
|
||||
|
||||
func (conn *RichConn) Write(b []byte) (n int, err error) {
|
||||
if conn.timeout > 0 {
|
||||
conn.Conn.SetWriteDeadline(time.Now().Add(conn.timeout))
|
||||
} else {
|
||||
var t time.Time
|
||||
conn.Conn.SetWriteDeadline(t)
|
||||
}
|
||||
return conn.Conn.Write(b)
|
||||
}
|
||||
|
100
request.go
Normal file
100
request.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RTSP_VERSION = "RTSP/1.0"
|
||||
)
|
||||
|
||||
const (
|
||||
// Client to server for presentation and stream objects; recommended
|
||||
DESCRIBE = "DESCRIBE"
|
||||
// Bidirectional for client and stream objects; optional
|
||||
ANNOUNCE = "ANNOUNCE"
|
||||
// Bidirectional for client and stream objects; optional
|
||||
GET_PARAMETER = "GET_PARAMETER"
|
||||
// Bidirectional for client and stream objects; required for Client to server, optional for server to client
|
||||
OPTIONS = "OPTIONS"
|
||||
// Client to server for presentation and stream objects; recommended
|
||||
PAUSE = "PAUSE"
|
||||
// Client to server for presentation and stream objects; required
|
||||
PLAY = "PLAY"
|
||||
// Client to server for presentation and stream objects; optional
|
||||
RECORD = "RECORD"
|
||||
// Server to client for presentation and stream objects; optional
|
||||
REDIRECT = "REDIRECT"
|
||||
// Client to server for stream objects; required
|
||||
SETUP = "SETUP"
|
||||
// Bidirectional for presentation and stream objects; optional
|
||||
SET_PARAMETER = "SET_PARAMETER"
|
||||
// Client to server for presentation and stream objects; required
|
||||
TEARDOWN = "TEARDOWN"
|
||||
DATA = "DATA"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
Method string
|
||||
URL string
|
||||
Version string
|
||||
Header map[string]string
|
||||
Content string
|
||||
Body string
|
||||
}
|
||||
|
||||
func NewRequest(content string) *Request {
|
||||
lines := strings.Split(strings.TrimSpace(content), "\r\n")
|
||||
if len(lines) == 0 {
|
||||
return nil
|
||||
}
|
||||
items := regexp.MustCompile("\\s+").Split(strings.TrimSpace(lines[0]), -1)
|
||||
if len(items) < 3 {
|
||||
return nil
|
||||
}
|
||||
if !strings.HasPrefix(items[2], "RTSP") {
|
||||
log.Printf("invalid rtsp request, line[0] %s", lines[0])
|
||||
return nil
|
||||
}
|
||||
header := make(map[string]string)
|
||||
for i := 1; i < len(lines); i++ {
|
||||
line := strings.TrimSpace(lines[i])
|
||||
headerItems := regexp.MustCompile(":\\s+").Split(line, 2)
|
||||
if len(headerItems) < 2 {
|
||||
continue
|
||||
}
|
||||
header[headerItems[0]] = headerItems[1]
|
||||
}
|
||||
return &Request{
|
||||
Method: items[0],
|
||||
URL: items[1],
|
||||
Version: items[2],
|
||||
Header: header,
|
||||
Content: content,
|
||||
Body: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Request) String() string {
|
||||
str := fmt.Sprintf("%s %s %s\r\n", r.Method, r.URL, r.Version)
|
||||
for key, value := range r.Header {
|
||||
str += fmt.Sprintf("%s: %s\r\n", key, value)
|
||||
}
|
||||
str += "\r\n"
|
||||
str += r.Body
|
||||
return str
|
||||
}
|
||||
|
||||
func (r *Request) GetContentLength() int {
|
||||
v, err := strconv.ParseInt(r.Header["Content-Length"], 10, 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
} else {
|
||||
return int(v)
|
||||
}
|
||||
}
|
||||
|
51
response.go
Normal file
51
response.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Version string
|
||||
StatusCode int
|
||||
Status string
|
||||
Header map[string]interface{}
|
||||
Body string
|
||||
}
|
||||
|
||||
func NewResponse(statusCode int, status, cSeq, sid, body string) *Response {
|
||||
res := &Response{
|
||||
Version: RTSP_VERSION,
|
||||
StatusCode: statusCode,
|
||||
Status: status,
|
||||
Header: map[string]interface{}{"CSeq": cSeq, "Session": sid},
|
||||
Body: body,
|
||||
}
|
||||
len := len(body)
|
||||
if len > 0 {
|
||||
res.Header["Content-Length"] = strconv.Itoa(len)
|
||||
} else {
|
||||
delete(res.Header, "Content-Length")
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (r *Response) String() string {
|
||||
str := fmt.Sprintf("%s %d %s\r\n", r.Version, r.StatusCode, r.Status)
|
||||
for key, value := range r.Header {
|
||||
str += fmt.Sprintf("%s: %s\r\n", key, value)
|
||||
}
|
||||
str += "\r\n"
|
||||
str += r.Body
|
||||
return str
|
||||
}
|
||||
|
||||
func (r *Response) SetBody(body string) {
|
||||
len := len(body)
|
||||
r.Body = body
|
||||
if len > 0 {
|
||||
r.Header["Content-Length"] = strconv.Itoa(len)
|
||||
} else {
|
||||
delete(r.Header, "Content-Length")
|
||||
}
|
||||
}
|
68
rtp-parser.go
Normal file
68
rtp-parser.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
const (
|
||||
RTP_FIXED_HEADER_LENGTH = 12
|
||||
)
|
||||
|
||||
type RTPInfo struct {
|
||||
Version int
|
||||
Padding bool
|
||||
Extension bool
|
||||
CSRCCnt int
|
||||
Marker bool
|
||||
PayloadType int
|
||||
SequenceNumber int
|
||||
Timestamp int
|
||||
SSRC int
|
||||
Payload []byte
|
||||
PayloadOffset int
|
||||
}
|
||||
|
||||
func ParseRTP(rtpBytes []byte) *RTPInfo {
|
||||
if len(rtpBytes) < RTP_FIXED_HEADER_LENGTH {
|
||||
return nil
|
||||
}
|
||||
firstByte := rtpBytes[0]
|
||||
secondByte := rtpBytes[1]
|
||||
info := &RTPInfo{
|
||||
Version: int(firstByte >> 6),
|
||||
Padding: (firstByte>>5)&1 == 1,
|
||||
Extension: (firstByte>>4)&1 == 1,
|
||||
CSRCCnt: int(firstByte & 0x0f),
|
||||
|
||||
Marker: secondByte>>7 == 1,
|
||||
PayloadType: int(secondByte & 0x7f),
|
||||
SequenceNumber: int(binary.BigEndian.Uint16(rtpBytes[2:])),
|
||||
Timestamp: int(binary.BigEndian.Uint32(rtpBytes[4:])),
|
||||
SSRC: int(binary.BigEndian.Uint32(rtpBytes[8:])),
|
||||
}
|
||||
offset := RTP_FIXED_HEADER_LENGTH
|
||||
end := len(rtpBytes)
|
||||
if end-offset >= 4*info.CSRCCnt {
|
||||
offset += 4 * info.CSRCCnt
|
||||
}
|
||||
if info.Extension && end-offset >= 4 {
|
||||
extLen := 4 * int(binary.BigEndian.Uint16(rtpBytes[offset+2:]))
|
||||
offset += 4
|
||||
if end-offset >= extLen {
|
||||
offset += extLen
|
||||
}
|
||||
}
|
||||
if info.Padding && end-offset > 0 {
|
||||
paddingLen := int(rtpBytes[end-1])
|
||||
if end-offset >= paddingLen {
|
||||
end -= paddingLen
|
||||
}
|
||||
}
|
||||
info.Payload = rtpBytes[offset:end]
|
||||
info.PayloadOffset = offset
|
||||
if end-offset < 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
105
sdp-parser.go
Normal file
105
sdp-parser.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SDPInfo struct {
|
||||
AVType string
|
||||
Codec string
|
||||
TimeScale int
|
||||
Control string
|
||||
Rtpmap int
|
||||
Config []byte
|
||||
SpropParameterSets [][]byte
|
||||
PayloadType int
|
||||
SizeLength int
|
||||
IndexLength int
|
||||
}
|
||||
|
||||
func ParseSDP(sdpRaw string) map[string]*SDPInfo {
|
||||
sdpMap := make(map[string]*SDPInfo)
|
||||
var info *SDPInfo
|
||||
for _, line := range strings.Split(sdpRaw, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
typeval := strings.SplitN(line, "=", 2)
|
||||
if len(typeval) == 2 {
|
||||
fields := strings.SplitN(typeval[1], " ", 2)
|
||||
switch typeval[0] {
|
||||
case "m":
|
||||
if len(fields) > 0 {
|
||||
info = &SDPInfo{AVType: fields[0]}
|
||||
sdpMap[info.AVType] = info
|
||||
mfields := strings.Split(fields[1], " ")
|
||||
if len(mfields) >= 3 {
|
||||
info.PayloadType, _ = strconv.Atoi(mfields[2])
|
||||
}
|
||||
}
|
||||
case "a":
|
||||
if info != nil {
|
||||
for _, field := range fields {
|
||||
keyval := strings.SplitN(field, ":", 2)
|
||||
if len(keyval) >= 2 {
|
||||
key := keyval[0]
|
||||
val := keyval[1]
|
||||
switch key {
|
||||
case "control":
|
||||
info.Control = val
|
||||
case "rtpmap":
|
||||
info.Rtpmap, _ = strconv.Atoi(val)
|
||||
}
|
||||
}
|
||||
keyval = strings.Split(field, "/")
|
||||
if len(keyval) >= 2 {
|
||||
key := keyval[0]
|
||||
switch key {
|
||||
case "PCMA":
|
||||
info.Codec = "pcma"
|
||||
case "PCMU":
|
||||
info.Codec = "pcmu"
|
||||
case "MPEG4-GENERIC":
|
||||
info.Codec = "aac"
|
||||
case "H264":
|
||||
info.Codec = "h264"
|
||||
case "H265":
|
||||
info.Codec = "h265"
|
||||
}
|
||||
if i, err := strconv.Atoi(keyval[1]); err == nil {
|
||||
info.TimeScale = i
|
||||
}
|
||||
}
|
||||
keyval = strings.Split(field, ";")
|
||||
if len(keyval) > 1 {
|
||||
for _, field := range keyval {
|
||||
keyval := strings.SplitN(field, "=", 2)
|
||||
if len(keyval) == 2 {
|
||||
key := strings.TrimSpace(keyval[0])
|
||||
val := keyval[1]
|
||||
switch key {
|
||||
case "config":
|
||||
info.Config, _ = hex.DecodeString(val)
|
||||
case "sizelength":
|
||||
info.SizeLength, _ = strconv.Atoi(val)
|
||||
case "indexlength":
|
||||
info.IndexLength, _ = strconv.Atoi(val)
|
||||
case "sprop-parameter-sets":
|
||||
fields := strings.Split(val, ",")
|
||||
for _, field := range fields {
|
||||
val, _ := base64.StdEncoding.DecodeString(field)
|
||||
info.SpropParameterSets = append(info.SpropParameterSets, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return sdpMap
|
||||
}
|
604
session.go
Normal file
604
session.go
Normal file
@@ -0,0 +1,604 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
. "github.com/Monibuca/plugin-rtp"
|
||||
"github.com/teris-io/shortid"
|
||||
)
|
||||
|
||||
type SessionType int
|
||||
|
||||
const (
|
||||
SESSION_TYPE_PUSHER SessionType = iota
|
||||
SESSEION_TYPE_PLAYER
|
||||
)
|
||||
|
||||
func (st SessionType) String() string {
|
||||
switch st {
|
||||
case SESSION_TYPE_PUSHER:
|
||||
return "pusher"
|
||||
case SESSEION_TYPE_PLAYER:
|
||||
return "player"
|
||||
}
|
||||
return "unknow"
|
||||
}
|
||||
|
||||
type TransType int
|
||||
|
||||
const (
|
||||
TRANS_TYPE_TCP TransType = iota
|
||||
TRANS_TYPE_UDP
|
||||
)
|
||||
|
||||
func (tt TransType) String() string {
|
||||
switch tt {
|
||||
case TRANS_TYPE_TCP:
|
||||
return "TCP"
|
||||
case TRANS_TYPE_UDP:
|
||||
return "UDP"
|
||||
}
|
||||
return "unknow"
|
||||
}
|
||||
|
||||
const UDP_BUF_SIZE = 1048576
|
||||
|
||||
func (session *RTSP) SessionString() string {
|
||||
return fmt.Sprintf("session[%v][%v][%s][%s][%s]", session.Type, session.TransType, session.StreamPath, session.ID, session.Conn.RemoteAddr().String())
|
||||
}
|
||||
|
||||
func (session *RTSP) Stop() {
|
||||
if session.Conn != nil {
|
||||
session.connRW.Flush()
|
||||
session.Conn.Close()
|
||||
session.Conn = nil
|
||||
}
|
||||
if session.UDPClient != nil {
|
||||
session.UDPClient.Stop()
|
||||
session.UDPClient = nil
|
||||
}
|
||||
if session.UDPServer != nil {
|
||||
session.UDPServer.Stop()
|
||||
session.UDPServer = nil
|
||||
}
|
||||
if session.Running() {
|
||||
session.Cancel()
|
||||
}
|
||||
if session.Stream != nil {
|
||||
collection.Delete(session.StreamPath)
|
||||
}
|
||||
}
|
||||
|
||||
// AcceptPush 接受推流
|
||||
func (session *RTSP) AcceptPush() {
|
||||
defer session.Stop()
|
||||
buf2 := make([]byte, 2)
|
||||
timer := time.Unix(0, 0)
|
||||
for {
|
||||
buf1, err := session.connRW.ReadByte()
|
||||
if err != nil {
|
||||
Println(err)
|
||||
return
|
||||
}
|
||||
if buf1 == 0x24 { //rtp data
|
||||
if buf1, err = session.connRW.ReadByte(); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
}
|
||||
if _, err := io.ReadFull(session.connRW, buf2); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
}
|
||||
channel := int(buf1)
|
||||
rtpLen := int(binary.BigEndian.Uint16(buf2))
|
||||
pack := new(RTPPack)
|
||||
rtpBytes := make([]byte, rtpLen)
|
||||
if _, err := io.ReadFull(session.connRW, rtpBytes); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
}
|
||||
if err = pack.Unmarshal(rtpBytes); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
}
|
||||
switch channel {
|
||||
case session.aRTPChannel:
|
||||
pack.Type = RTP_TYPE_AUDIO
|
||||
elapsed := time.Now().Sub(timer)
|
||||
if elapsed >= 30*time.Second {
|
||||
Println("Recv an audio RTP package")
|
||||
timer = time.Now()
|
||||
}
|
||||
case session.aRTPControlChannel:
|
||||
pack.Type = RTP_TYPE_AUDIOCONTROL
|
||||
case session.vRTPChannel:
|
||||
pack.Type = RTP_TYPE_VIDEO
|
||||
elapsed := time.Now().Sub(timer)
|
||||
if elapsed >= 30*time.Second {
|
||||
Println("Recv an video RTP package")
|
||||
timer = time.Now()
|
||||
}
|
||||
case session.vRTPControlChannel:
|
||||
pack.Type = RTP_TYPE_VIDEOCONTROL
|
||||
default:
|
||||
Printf("unknow rtp pack type, %v", pack.Type)
|
||||
continue
|
||||
}
|
||||
session.InBytes += rtpLen + 4
|
||||
session.PushPack(pack)
|
||||
} else { // rtsp cmd
|
||||
reqBuf := bytes.NewBuffer(nil)
|
||||
reqBuf.WriteByte(buf1)
|
||||
for {
|
||||
if line, isPrefix, err := session.connRW.ReadLine(); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
} else {
|
||||
reqBuf.Write(line)
|
||||
if !isPrefix {
|
||||
reqBuf.WriteString("\r\n")
|
||||
}
|
||||
if len(line) == 0 {
|
||||
req := NewRequest(reqBuf.String())
|
||||
if req == nil {
|
||||
break
|
||||
}
|
||||
session.InBytes += reqBuf.Len()
|
||||
contentLen := req.GetContentLength()
|
||||
session.InBytes += contentLen
|
||||
if contentLen > 0 {
|
||||
bodyBuf := make([]byte, contentLen)
|
||||
if n, err := io.ReadFull(session.connRW, bodyBuf); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
} else if n != contentLen {
|
||||
Printf("read rtsp request body failed, expect size[%d], got size[%d]", contentLen, n)
|
||||
return
|
||||
}
|
||||
req.Body = string(bodyBuf)
|
||||
}
|
||||
session.handleRequest(req)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (session *RTSP) CheckAuth(authLine string, method string) error {
|
||||
realmRex := regexp.MustCompile(`realm="(.*?)"`)
|
||||
nonceRex := regexp.MustCompile(`nonce="(.*?)"`)
|
||||
usernameRex := regexp.MustCompile(`username="(.*?)"`)
|
||||
responseRex := regexp.MustCompile(`response="(.*?)"`)
|
||||
uriRex := regexp.MustCompile(`uri="(.*?)"`)
|
||||
|
||||
realm := ""
|
||||
nonce := ""
|
||||
username := ""
|
||||
response := ""
|
||||
uri := ""
|
||||
result1 := realmRex.FindStringSubmatch(authLine)
|
||||
if len(result1) == 2 {
|
||||
realm = result1[1]
|
||||
} else {
|
||||
return fmt.Errorf("CheckAuth error : no realm found")
|
||||
}
|
||||
result1 = nonceRex.FindStringSubmatch(authLine)
|
||||
if len(result1) == 2 {
|
||||
nonce = result1[1]
|
||||
} else {
|
||||
return fmt.Errorf("CheckAuth error : no nonce found")
|
||||
}
|
||||
if session.nonce != nonce {
|
||||
return fmt.Errorf("CheckAuth error : sessionNonce not same as nonce")
|
||||
}
|
||||
|
||||
result1 = usernameRex.FindStringSubmatch(authLine)
|
||||
if len(result1) == 2 {
|
||||
username = result1[1]
|
||||
} else {
|
||||
return fmt.Errorf("CheckAuth error : username not found")
|
||||
}
|
||||
|
||||
result1 = responseRex.FindStringSubmatch(authLine)
|
||||
if len(result1) == 2 {
|
||||
response = result1[1]
|
||||
} else {
|
||||
return fmt.Errorf("CheckAuth error : response not found")
|
||||
}
|
||||
|
||||
result1 = uriRex.FindStringSubmatch(authLine)
|
||||
if len(result1) == 2 {
|
||||
uri = result1[1]
|
||||
} else {
|
||||
return fmt.Errorf("CheckAuth error : uri not found")
|
||||
}
|
||||
// var user models.User
|
||||
// err := db.SQLite.Where("Username = ?", username).First(&user).Error
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("CheckAuth error : user not exists")
|
||||
// }
|
||||
md5UserRealmPwd := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s:%s", username, realm, session.Auth(username)))))
|
||||
md5MethodURL := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s", method, uri))))
|
||||
myResponse := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s:%s", md5UserRealmPwd, nonce, md5MethodURL))))
|
||||
if myResponse != response {
|
||||
return fmt.Errorf("CheckAuth error : response not equal")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (session *RTSP) handleRequest(req *Request) {
|
||||
//if session.Timeout > 0 {
|
||||
// session.Conn.SetDeadline(time.Now().Add(time.Duration(session.Timeout) * time.Second))
|
||||
//}
|
||||
Printf("<<<\n%s", req)
|
||||
res := NewResponse(200, "OK", req.Header["CSeq"], session.ID, "")
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
Printf("handleRequest err ocurs:%v", p)
|
||||
res.StatusCode = 500
|
||||
res.Status = fmt.Sprintf("Inner Server Error, %v", p)
|
||||
}
|
||||
Printf(">>>\n%s", res)
|
||||
outBytes := []byte(res.String())
|
||||
session.connWLock.Lock()
|
||||
session.connRW.Write(outBytes)
|
||||
session.connRW.Flush()
|
||||
session.connWLock.Unlock()
|
||||
session.OutBytes += len(outBytes)
|
||||
switch req.Method {
|
||||
case "PLAY", "RECORD":
|
||||
switch session.Type {
|
||||
case SESSEION_TYPE_PLAYER:
|
||||
// if session.Pusher.HasPlayer(session.Player) {
|
||||
// session.Player.Pause(false)
|
||||
// } else {
|
||||
// session.Pusher.AddPlayer(session.Player)
|
||||
// }
|
||||
}
|
||||
case "TEARDOWN":
|
||||
{
|
||||
session.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
if res.StatusCode != 200 && res.StatusCode != 401 {
|
||||
Printf("Response request error[%d]. stop session.", res.StatusCode)
|
||||
session.Stop()
|
||||
}
|
||||
}()
|
||||
if req.Method != "OPTIONS" {
|
||||
if session.Auth != nil {
|
||||
authLine := req.Header["Authorization"]
|
||||
authFailed := true
|
||||
if authLine != "" {
|
||||
err := session.CheckAuth(authLine, req.Method)
|
||||
if err == nil {
|
||||
authFailed = false
|
||||
} else {
|
||||
Printf("%v", err)
|
||||
}
|
||||
}
|
||||
if authFailed {
|
||||
res.StatusCode = 401
|
||||
res.Status = "Unauthorized"
|
||||
nonce := fmt.Sprintf("%x", md5.Sum([]byte(shortid.MustGenerate())))
|
||||
session.nonce = nonce
|
||||
res.Header["WWW-Authenticate"] = fmt.Sprintf(`Digest realm="EasyDarwin", nonce="%s", algorithm="MD5"`, nonce)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
switch req.Method {
|
||||
case "OPTIONS":
|
||||
res.Header["Public"] = "DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD"
|
||||
case "ANNOUNCE":
|
||||
session.Type = SESSION_TYPE_PUSHER
|
||||
session.URL = req.URL
|
||||
|
||||
url, err := url.Parse(req.URL)
|
||||
if err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = "Invalid URL"
|
||||
return
|
||||
}
|
||||
streamPath := strings.TrimPrefix(url.Path, "/")
|
||||
|
||||
session.SDPRaw = req.Body
|
||||
session.SDPMap = ParseSDP(req.Body)
|
||||
if session.Publish(streamPath) {
|
||||
if session.ASdp, session.HasAudio = session.SDPMap["audio"]; session.HasAudio {
|
||||
if len(session.ASdp.Control) > 0 {
|
||||
session.WriteASC(session.ASdp.Config)
|
||||
} else {
|
||||
session.setAudioFormat()
|
||||
}
|
||||
Printf("audio codec[%s]\n", session.ASdp.Codec)
|
||||
}
|
||||
if session.VSdp, session.HasVideo = session.SDPMap["video"]; session.HasVideo {
|
||||
if len(session.VSdp.SpropParameterSets) > 1 {
|
||||
session.WriteSPS(session.VSdp.SpropParameterSets[0])
|
||||
session.WritePPS(session.VSdp.SpropParameterSets[1])
|
||||
}
|
||||
Printf("video codec[%s]\n", session.VSdp.Codec)
|
||||
}
|
||||
session.Stream.Type = "RTSP"
|
||||
session.RTSPInfo.StreamInfo = &session.Stream.StreamInfo
|
||||
collection.Store(streamPath, session)
|
||||
}
|
||||
case "DESCRIBE":
|
||||
session.Type = SESSEION_TYPE_PLAYER
|
||||
session.URL = req.URL
|
||||
url, err := url.Parse(req.URL)
|
||||
if err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = "Invalid URL"
|
||||
return
|
||||
}
|
||||
streamPath := url.Path
|
||||
stream := FindStream(streamPath)
|
||||
if stream == nil {
|
||||
return
|
||||
}
|
||||
//
|
||||
//res.SetBody(session.SDPRaw)
|
||||
case "SETUP":
|
||||
ts := req.Header["Transport"]
|
||||
// control字段可能是`stream=1`字样,也可能是rtsp://...字样。即control可能是url的path,也可能是整个url
|
||||
// 例1:
|
||||
// a=control:streamid=1
|
||||
// 例2:
|
||||
// a=control:rtsp://192.168.1.64/trackID=1
|
||||
// 例3:
|
||||
// a=control:?ctype=video
|
||||
setupUrl, err := url.Parse(req.URL)
|
||||
if err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = "Invalid URL"
|
||||
return
|
||||
}
|
||||
if setupUrl.Port() == "" {
|
||||
setupUrl.Host = fmt.Sprintf("%s:554", setupUrl.Host)
|
||||
}
|
||||
setupPath := setupUrl.String()
|
||||
|
||||
// error status. SETUP without ANNOUNCE or DESCRIBE.
|
||||
//if session.Pusher == nil {
|
||||
// res.StatusCode = 500
|
||||
// res.Status = "Error Status"
|
||||
// return
|
||||
//}
|
||||
var vPath, aPath string
|
||||
if session.HasVideo {
|
||||
if strings.Index(strings.ToLower(session.VSdp.Control), "rtsp://") == 0 {
|
||||
vControlUrl, err := url.Parse(session.VSdp.Control)
|
||||
if err != nil {
|
||||
res.StatusCode = 500
|
||||
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 session.HasAudio {
|
||||
if strings.Index(strings.ToLower(session.ASdp.Control), "rtsp://") == 0 {
|
||||
aControlUrl, err := url.Parse(session.ASdp.Control)
|
||||
if err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = "Invalid AControl"
|
||||
return
|
||||
}
|
||||
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+))?")
|
||||
mudp := regexp.MustCompile("client_port=(\\d+)(-(\\d+))?")
|
||||
|
||||
if tcpMatchs := mtcp.FindStringSubmatch(ts); tcpMatchs != nil {
|
||||
session.TransType = TRANS_TYPE_TCP
|
||||
if setupPath == aPath || aPath != "" && strings.LastIndex(setupPath, aPath) == len(setupPath)-len(aPath) {
|
||||
session.aRTPChannel, _ = strconv.Atoi(tcpMatchs[1])
|
||||
session.aRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3])
|
||||
} else if setupPath == vPath || vPath != "" && strings.LastIndex(setupPath, vPath) == len(setupPath)-len(vPath) {
|
||||
session.vRTPChannel, _ = strconv.Atoi(tcpMatchs[1])
|
||||
session.vRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3])
|
||||
} else {
|
||||
res.StatusCode = 500
|
||||
res.Status = fmt.Sprintf("SETUP [TCP] got UnKown control:%s", setupPath)
|
||||
Printf("SETUP [TCP] got UnKown control:%s", setupPath)
|
||||
}
|
||||
Printf("Parse SETUP req.TRANSPORT:TCP.Session.Type:%d,control:%s, AControl:%s,VControl:%s", session.Type, setupPath, aPath, vPath)
|
||||
} else if udpMatchs := mudp.FindStringSubmatch(ts); udpMatchs != nil {
|
||||
session.TransType = TRANS_TYPE_UDP
|
||||
// no need for tcp timeout.
|
||||
session.Conn.timeout = 0
|
||||
if session.Type == SESSEION_TYPE_PLAYER && session.UDPClient == nil {
|
||||
session.UDPClient = &UDPClient{}
|
||||
}
|
||||
if session.Type == SESSION_TYPE_PUSHER && session.UDPServer == nil {
|
||||
session.UDPServer = &UDPServer{
|
||||
Session: session,
|
||||
}
|
||||
}
|
||||
Printf("Parse SETUP req.TRANSPORT:UDP.Session.Type:%d,control:%s, AControl:%s,VControl:%s", session.Type, setupPath, aPath, vPath)
|
||||
if setupPath == aPath || aPath != "" && strings.LastIndex(setupPath, aPath) == len(setupPath)-len(aPath) {
|
||||
if session.Type == SESSEION_TYPE_PLAYER {
|
||||
session.UDPClient.APort, _ = strconv.Atoi(udpMatchs[1])
|
||||
session.UDPClient.AControlPort, _ = strconv.Atoi(udpMatchs[3])
|
||||
if err := session.UDPClient.SetupAudio(); err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = fmt.Sprintf("udp client setup audio error, %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if session.Type == SESSION_TYPE_PUSHER {
|
||||
if err := session.UDPServer.SetupAudio(); err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = fmt.Sprintf("udp server setup audio error, %v", err)
|
||||
return
|
||||
}
|
||||
tss := strings.Split(ts, ";")
|
||||
idx := -1
|
||||
for i, val := range tss {
|
||||
if val == udpMatchs[0] {
|
||||
idx = i
|
||||
}
|
||||
}
|
||||
tail := append([]string{}, tss[idx+1:]...)
|
||||
tss = append(tss[:idx+1], fmt.Sprintf("server_port=%d-%d", session.UDPServer.APort, session.UDPServer.AControlPort))
|
||||
tss = append(tss, tail...)
|
||||
ts = strings.Join(tss, ";")
|
||||
}
|
||||
} else if setupPath == vPath || vPath != "" && strings.LastIndex(setupPath, vPath) == len(setupPath)-len(vPath) {
|
||||
if session.Type == SESSEION_TYPE_PLAYER {
|
||||
session.UDPClient.VPort, _ = strconv.Atoi(udpMatchs[1])
|
||||
session.UDPClient.VControlPort, _ = strconv.Atoi(udpMatchs[3])
|
||||
if err := session.UDPClient.SetupVideo(); err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = fmt.Sprintf("udp client setup video error, %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if session.Type == SESSION_TYPE_PUSHER {
|
||||
if err := session.UDPServer.SetupVideo(); err != nil {
|
||||
res.StatusCode = 500
|
||||
res.Status = fmt.Sprintf("udp server setup video error, %v", err)
|
||||
return
|
||||
}
|
||||
tss := strings.Split(ts, ";")
|
||||
idx := -1
|
||||
for i, val := range tss {
|
||||
if val == udpMatchs[0] {
|
||||
idx = i
|
||||
}
|
||||
}
|
||||
tail := append([]string{}, tss[idx+1:]...)
|
||||
tss = append(tss[:idx+1], fmt.Sprintf("server_port=%d-%d", session.UDPServer.VPort, session.UDPServer.VControlPort))
|
||||
tss = append(tss, tail...)
|
||||
ts = strings.Join(tss, ";")
|
||||
}
|
||||
} else {
|
||||
Printf("SETUP [UDP] got UnKown control:%s", setupPath)
|
||||
}
|
||||
}
|
||||
res.Header["Transport"] = ts
|
||||
case "PLAY":
|
||||
// error status. PLAY without ANNOUNCE or DESCRIBE.
|
||||
// if session.Pusher == nil {
|
||||
// res.StatusCode = 500
|
||||
// res.Status = "Error Status"
|
||||
// return
|
||||
// }
|
||||
res.Header["Range"] = req.Header["Range"]
|
||||
case "RECORD":
|
||||
// error status. RECORD without ANNOUNCE or DESCRIBE.
|
||||
// if session.Pusher == nil {
|
||||
// res.StatusCode = 500
|
||||
// res.Status = "Error Status"
|
||||
// return
|
||||
// }
|
||||
case "PAUSE":
|
||||
// if session.Player == nil {
|
||||
// res.StatusCode = 500
|
||||
// res.Status = "Error Status"
|
||||
// return
|
||||
// }
|
||||
// session.Player.Pause(true)
|
||||
}
|
||||
}
|
||||
|
||||
func (session *RTSP) SendRTP(pack *RTPPack) (err error) {
|
||||
if pack == nil {
|
||||
err = fmt.Errorf("player send rtp got nil pack")
|
||||
return
|
||||
}
|
||||
if session.TransType == TRANS_TYPE_UDP {
|
||||
if session.UDPClient == nil {
|
||||
err = fmt.Errorf("player use udp transport but udp client not found")
|
||||
return
|
||||
}
|
||||
err = session.UDPClient.SendRTP(pack)
|
||||
session.OutBytes += len(pack.Raw)
|
||||
return
|
||||
}
|
||||
switch pack.Type {
|
||||
case RTP_TYPE_AUDIO:
|
||||
bufChannel := make([]byte, 2)
|
||||
bufChannel[0] = 0x24
|
||||
bufChannel[1] = byte(session.aRTPChannel)
|
||||
session.connWLock.Lock()
|
||||
session.connRW.Write(bufChannel)
|
||||
bufLen := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Raw)))
|
||||
session.connRW.Write(bufLen)
|
||||
session.connRW.Write(pack.Raw)
|
||||
session.connRW.Flush()
|
||||
session.connWLock.Unlock()
|
||||
session.OutBytes += len(pack.Raw) + 4
|
||||
case RTP_TYPE_AUDIOCONTROL:
|
||||
bufChannel := make([]byte, 2)
|
||||
bufChannel[0] = 0x24
|
||||
bufChannel[1] = byte(session.aRTPControlChannel)
|
||||
session.connWLock.Lock()
|
||||
session.connRW.Write(bufChannel)
|
||||
bufLen := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Raw)))
|
||||
session.connRW.Write(bufLen)
|
||||
session.connRW.Write(pack.Raw)
|
||||
session.connRW.Flush()
|
||||
session.connWLock.Unlock()
|
||||
session.OutBytes += len(pack.Raw) + 4
|
||||
case RTP_TYPE_VIDEO:
|
||||
bufChannel := make([]byte, 2)
|
||||
bufChannel[0] = 0x24
|
||||
bufChannel[1] = byte(session.vRTPChannel)
|
||||
session.connWLock.Lock()
|
||||
session.connRW.Write(bufChannel)
|
||||
bufLen := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Raw)))
|
||||
session.connRW.Write(bufLen)
|
||||
session.connRW.Write(pack.Raw)
|
||||
session.connRW.Flush()
|
||||
session.connWLock.Unlock()
|
||||
session.OutBytes += len(pack.Raw) + 4
|
||||
case RTP_TYPE_VIDEOCONTROL:
|
||||
bufChannel := make([]byte, 2)
|
||||
bufChannel[0] = 0x24
|
||||
bufChannel[1] = byte(session.vRTPControlChannel)
|
||||
session.connWLock.Lock()
|
||||
session.connRW.Write(bufChannel)
|
||||
bufLen := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Raw)))
|
||||
session.connRW.Write(bufLen)
|
||||
session.connRW.Write(pack.Raw)
|
||||
session.connRW.Flush()
|
||||
session.connWLock.Unlock()
|
||||
session.OutBytes += len(pack.Raw) + 4
|
||||
default:
|
||||
err = fmt.Errorf("session tcp send rtp got unkown pack type[%v]", pack.Type)
|
||||
}
|
||||
return
|
||||
}
|
161
udp-client.go
Normal file
161
udp-client.go
Normal file
@@ -0,0 +1,161 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
. "github.com/Monibuca/plugin-rtp"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UDPClient struct {
|
||||
APort int
|
||||
AConn *net.UDPConn
|
||||
AControlPort int
|
||||
AControlConn *net.UDPConn
|
||||
VPort int
|
||||
VConn *net.UDPConn
|
||||
VControlPort int
|
||||
VControlConn *net.UDPConn
|
||||
|
||||
Stoped bool
|
||||
}
|
||||
|
||||
func (s *UDPClient) Stop() {
|
||||
if s.Stoped {
|
||||
return
|
||||
}
|
||||
s.Stoped = true
|
||||
if s.AConn != nil {
|
||||
s.AConn.Close()
|
||||
s.AConn = nil
|
||||
}
|
||||
if s.AControlConn != nil {
|
||||
s.AControlConn.Close()
|
||||
s.AControlConn = nil
|
||||
}
|
||||
if s.VConn != nil {
|
||||
s.VConn.Close()
|
||||
s.VConn = nil
|
||||
}
|
||||
if s.VControlConn != nil {
|
||||
s.VControlConn.Close()
|
||||
s.VControlConn = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *UDPClient) SetupAudio() (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
Println(err)
|
||||
c.Stop()
|
||||
}
|
||||
}()
|
||||
host := c.AConn.RemoteAddr().String()
|
||||
host = host[:strings.LastIndex(host, ":")]
|
||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.APort))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.AConn, err = net.DialUDP("udp", nil, addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
networkBuffer := 1048576
|
||||
if err := c.AConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client audio conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := c.AConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client audio conn set write buffer error, %v", err)
|
||||
}
|
||||
|
||||
addr, err = net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.AControlPort))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.AControlConn, err = net.DialUDP("udp", nil, addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.AControlConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client audio control conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := c.AControlConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client audio control conn set write buffer error, %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *UDPClient) SetupVideo() (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
Println(err)
|
||||
c.Stop()
|
||||
}
|
||||
}()
|
||||
host := c.VConn.RemoteAddr().String()
|
||||
host = host[:strings.LastIndex(host, ":")]
|
||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.VPort))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.VConn, err = net.DialUDP("udp", nil, addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
networkBuffer := 1048576
|
||||
if err := c.VConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client video conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := c.VConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client video conn set write buffer error, %v", err)
|
||||
}
|
||||
|
||||
addr, err = net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.VControlPort))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.VControlConn, err = net.DialUDP("udp", nil, addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.VControlConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client video control conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := c.VControlConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp client video control conn set write buffer error, %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *UDPClient) SendRTP(pack *RTPPack) (err error) {
|
||||
if pack == nil {
|
||||
err = fmt.Errorf("udp client send rtp got nil pack")
|
||||
return
|
||||
}
|
||||
var conn *net.UDPConn
|
||||
switch pack.Type {
|
||||
case RTP_TYPE_AUDIO:
|
||||
conn = c.AConn
|
||||
case RTP_TYPE_AUDIOCONTROL:
|
||||
conn = c.AControlConn
|
||||
case RTP_TYPE_VIDEO:
|
||||
conn = c.VConn
|
||||
case RTP_TYPE_VIDEOCONTROL:
|
||||
conn = c.VControlConn
|
||||
default:
|
||||
err = fmt.Errorf("udp client send rtp got unkown pack type[%v]", pack.Type)
|
||||
return
|
||||
}
|
||||
if conn == nil {
|
||||
err = fmt.Errorf("udp client send rtp pack type[%v] failed, conn not found", pack.Type)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = conn.Write(pack.Raw); err != nil {
|
||||
err = fmt.Errorf("udp client write bytes error, %v", err)
|
||||
return
|
||||
}
|
||||
// Printf("udp client write [%d/%d]", n, pack.Buffer.Len())
|
||||
return
|
||||
}
|
235
udp-server.go
Normal file
235
udp-server.go
Normal file
@@ -0,0 +1,235 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
. "github.com/Monibuca/plugin-rtp"
|
||||
)
|
||||
|
||||
type UDPServer struct {
|
||||
Session *RTSP
|
||||
UDPClient
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func (s *UDPServer) AddInputBytes(bytes int) {
|
||||
if s.Session != nil {
|
||||
s.Session.InBytes += bytes
|
||||
return
|
||||
}
|
||||
panic(fmt.Errorf("session and RTSPClient both nil"))
|
||||
}
|
||||
|
||||
func (s *UDPServer) HandleRTP(pack *RTPPack) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
if s.Session != nil {
|
||||
s.Session.PushPack(pack)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UDPServer) Stop() {
|
||||
if s.Stoped {
|
||||
return
|
||||
}
|
||||
s.Stoped = true
|
||||
if s.AConn != nil {
|
||||
s.AConn.Close()
|
||||
s.AConn = nil
|
||||
}
|
||||
if s.AControlConn != nil {
|
||||
s.AControlConn.Close()
|
||||
s.AControlConn = nil
|
||||
}
|
||||
if s.VConn != nil {
|
||||
s.VConn.Close()
|
||||
s.VConn = nil
|
||||
}
|
||||
if s.VControlConn != nil {
|
||||
s.VControlConn.Close()
|
||||
s.VControlConn = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UDPServer) SetupAudio() (err error) {
|
||||
addr, err := net.ResolveUDPAddr("udp", ":0")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s.AConn, err = net.ListenUDP("udp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
networkBuffer := 1048576
|
||||
if err := s.AConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server audio conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := s.AConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server audio conn set write buffer error, %v", err)
|
||||
}
|
||||
la := s.AConn.LocalAddr().String()
|
||||
strPort := la[strings.LastIndex(la, ":")+1:]
|
||||
s.APort, err = strconv.Atoi(strPort)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
bufUDP := make([]byte, UDP_BUF_SIZE)
|
||||
Printf("udp server start listen audio port[%d]", s.APort)
|
||||
defer Printf("udp server stop listen audio port[%d]", s.APort)
|
||||
timer := time.Unix(0, 0)
|
||||
for !s.Stoped {
|
||||
if n, _, err := s.AConn.ReadFromUDP(bufUDP); err == nil {
|
||||
elapsed := time.Now().Sub(timer)
|
||||
if elapsed >= 30*time.Second {
|
||||
Printf("Package recv from AConn.len:%d\n", n)
|
||||
timer = time.Now()
|
||||
}
|
||||
s.AddInputBytes(n)
|
||||
pack := &RTPPack{
|
||||
Type: RTP_TYPE_AUDIO,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
} else {
|
||||
Println("udp server read audio pack error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
addr, err = net.ResolveUDPAddr("udp", ":0")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s.AControlConn, err = net.ListenUDP("udp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := s.AControlConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server audio control conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := s.AControlConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server audio control conn set write buffer error, %v", err)
|
||||
}
|
||||
la = s.AControlConn.LocalAddr().String()
|
||||
strPort = la[strings.LastIndex(la, ":")+1:]
|
||||
s.AControlPort, err = strconv.Atoi(strPort)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
bufUDP := make([]byte, UDP_BUF_SIZE)
|
||||
Printf("udp server start listen audio control port[%d]", s.AControlPort)
|
||||
defer Printf("udp server stop listen audio control port[%d]", s.AControlPort)
|
||||
for !s.Stoped {
|
||||
if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil {
|
||||
//Printf("Package recv from AControlConn.len:%d\n", n)
|
||||
s.AddInputBytes(n)
|
||||
pack := &RTPPack{
|
||||
Type: RTP_TYPE_AUDIOCONTROL,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
} else {
|
||||
Println("udp server read audio control pack error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UDPServer) SetupVideo() (err error) {
|
||||
addr, err := net.ResolveUDPAddr("udp", ":0")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s.VConn, err = net.ListenUDP("udp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
networkBuffer := 1048576
|
||||
if err := s.VConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server video conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := s.VConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server video conn set write buffer error, %v", err)
|
||||
}
|
||||
la := s.VConn.LocalAddr().String()
|
||||
strPort := la[strings.LastIndex(la, ":")+1:]
|
||||
s.VPort, err = strconv.Atoi(strPort)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
bufUDP := make([]byte, UDP_BUF_SIZE)
|
||||
Printf("udp server start listen video port[%d]", s.VPort)
|
||||
defer Printf("udp server stop listen video port[%d]", s.VPort)
|
||||
timer := time.Unix(0, 0)
|
||||
for !s.Stoped {
|
||||
if n, _, err := s.VConn.ReadFromUDP(bufUDP); err == nil {
|
||||
elapsed := time.Now().Sub(timer)
|
||||
if elapsed >= 30*time.Second {
|
||||
Printf("Package recv from VConn.len:%d\n", n)
|
||||
timer = time.Now()
|
||||
}
|
||||
s.AddInputBytes(n)
|
||||
pack := &RTPPack{
|
||||
Type: RTP_TYPE_VIDEO,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
} else {
|
||||
Println("udp server read video pack error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
addr, err = net.ResolveUDPAddr("udp", ":0")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s.VControlConn, err = net.ListenUDP("udp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := s.VControlConn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server video control conn set read buffer error, %v", err)
|
||||
}
|
||||
if err := s.VControlConn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server video control conn set write buffer error, %v", err)
|
||||
}
|
||||
la = s.VControlConn.LocalAddr().String()
|
||||
strPort = la[strings.LastIndex(la, ":")+1:]
|
||||
s.VControlPort, err = strconv.Atoi(strPort)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
bufUDP := make([]byte, UDP_BUF_SIZE)
|
||||
Printf("udp server start listen video control port[%d]", s.VControlPort)
|
||||
defer Printf("udp server stop listen video control port[%d]", s.VControlPort)
|
||||
for !s.Stoped {
|
||||
if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil {
|
||||
//Printf("Package recv from VControlConn.len:%d\n", n)
|
||||
s.AddInputBytes(n)
|
||||
pack := &RTPPack{
|
||||
Type: RTP_TYPE_VIDEOCONTROL,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
} else {
|
||||
Println("udp server read video control pack error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
55
ui/dist/plugin-rtsp.common.js
vendored
55
ui/dist/plugin-rtsp.common.js
vendored
@@ -172,14 +172,14 @@ if (typeof window !== 'undefined') {
|
||||
// Indicate to webpack that this file can be concatenated
|
||||
/* harmony default export */ var setPublicPath = (null);
|
||||
|
||||
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"29918b3a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=template&id=0225c7f1&
|
||||
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"29918b3a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=template&id=de44c72c&
|
||||
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('mu-data-table',{attrs:{"data":_vm.Streams,"columns":_vm.columns},scopedSlots:_vm._u([{key:"default",fn:function(ref){
|
||||
var item = ref.row;
|
||||
return [_c('td',[_vm._v(_vm._s(item.StreamInfo.StreamPath))]),_c('td',[_c('StartTime',{attrs:{"value":item.StreamInfo.StartTime}})],1),_c('td',[_c('Progress',{attrs:{"stroke-width":20,"percent":Math.ceil(item.BufferRate),"text-inside":""}})],1),_c('td',[_vm._v(_vm._s(item.SyncCount))]),_c('td',[_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.showHeader(item)}}},[_vm._v("头信息")])],1)]}}])}),_c('mu-dialog',{attrs:{"title":"拉流转发","width":"360","open":_vm.openPull},on:{"update:open":function($event){_vm.openPull=$event}}},[_c('mu-text-field',{attrs:{"label":"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:(_vm.remoteAddr),callback:function ($$v) {_vm.remoteAddr=$$v},expression:"remoteAddr"}}),_c('mu-text-field',{attrs:{"label":"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:(_vm.streamPath),callback:function ($$v) {_vm.streamPath=$$v},expression:"streamPath"}}),_c('mu-button',{attrs:{"slot":"actions","flat":"","color":"primary"},on:{"click":_vm.addPull},slot:"actions"},[_vm._v("确定")])],1)],1)}
|
||||
return [_c('td',[_vm._v(_vm._s(item.StreamInfo.StreamPath))]),_c('td',[_c('StartTime',{attrs:{"value":item.StreamInfo.StartTime}})],1),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.InBytes)))]),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.OutBytes)))]),_c('td',[_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.showHeader(item)}}},[_vm._v("头信息")]),_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.stop(item)}}},[_vm._v("中止")])],1)]}}])}),_c('mu-dialog',{attrs:{"title":"拉流转发","width":"360","open":_vm.openPull},on:{"update:open":function($event){_vm.openPull=$event}}},[_c('mu-text-field',{attrs:{"label":"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:(_vm.remoteAddr),callback:function ($$v) {_vm.remoteAddr=$$v},expression:"remoteAddr"}}),_c('mu-text-field',{attrs:{"label":"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:(_vm.streamPath),callback:function ($$v) {_vm.streamPath=$$v},expression:"streamPath"}}),_c('mu-button',{attrs:{"slot":"actions","flat":"","color":"primary"},on:{"click":_vm.addPull},slot:"actions"},[_vm._v("确定")])],1)],1)}
|
||||
var staticRenderFns = []
|
||||
|
||||
|
||||
// CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=0225c7f1&
|
||||
// CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=de44c72c&
|
||||
|
||||
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
|
||||
//
|
||||
@@ -203,12 +203,22 @@ var staticRenderFns = []
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
let listES = null;
|
||||
/* harmony default export */ var Appvue_type_script_lang_js_ = ({
|
||||
components: {
|
||||
StartTime
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
currentStream: null,
|
||||
@@ -216,7 +226,13 @@ let listES = null;
|
||||
remoteAddr: "",
|
||||
streamPath: "",
|
||||
openPull: false,
|
||||
columns:["StreamPath","开始时间","缓冲","同步数","操作" ].map(title=>({title}))
|
||||
columns: [
|
||||
"StreamPath",
|
||||
"开始时间",
|
||||
"总接收",
|
||||
"总发送",
|
||||
"操作"
|
||||
].map(title => ({ title }))
|
||||
};
|
||||
},
|
||||
|
||||
@@ -233,10 +249,10 @@ let listES = null;
|
||||
},
|
||||
showHeader(item) {
|
||||
this.$Modal.info({
|
||||
title: "RTSP Header",
|
||||
title: "RTSP SDPRaw",
|
||||
width: "1000px",
|
||||
scrollable: true,
|
||||
content: item.Header
|
||||
content: item.SDPRaw
|
||||
});
|
||||
},
|
||||
addPull() {
|
||||
@@ -253,6 +269,19 @@ let listES = null;
|
||||
this.$toast.error(x.msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
stop(item) {
|
||||
this.ajax
|
||||
.get(this.apiHost + "/api/stop", {
|
||||
stream: item.StreamInfo.StreamPath
|
||||
})
|
||||
.then(x => {
|
||||
if (x == "success") {
|
||||
this.$toast.success("已停止拉流");
|
||||
} else {
|
||||
this.$toast.error(x.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -260,14 +289,14 @@ let listES = null;
|
||||
let _this = this;
|
||||
this.$parent.titleOps = [
|
||||
{
|
||||
template:'<m-button @click="onClick">拉流转发</m-button>',
|
||||
methods:{
|
||||
onClick(){
|
||||
template: '<m-button @click="onClick">拉流转发</m-button>',
|
||||
methods: {
|
||||
onClick() {
|
||||
_this.openPull = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
},
|
||||
destroyed() {
|
||||
listES.close();
|
||||
|
2
ui/dist/plugin-rtsp.common.js.map
vendored
2
ui/dist/plugin-rtsp.common.js.map
vendored
File diff suppressed because one or more lines are too long
55
ui/dist/plugin-rtsp.umd.js
vendored
55
ui/dist/plugin-rtsp.umd.js
vendored
@@ -181,14 +181,14 @@ if (typeof window !== 'undefined') {
|
||||
// Indicate to webpack that this file can be concatenated
|
||||
/* harmony default export */ var setPublicPath = (null);
|
||||
|
||||
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"29918b3a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=template&id=0225c7f1&
|
||||
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"29918b3a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=template&id=de44c72c&
|
||||
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('mu-data-table',{attrs:{"data":_vm.Streams,"columns":_vm.columns},scopedSlots:_vm._u([{key:"default",fn:function(ref){
|
||||
var item = ref.row;
|
||||
return [_c('td',[_vm._v(_vm._s(item.StreamInfo.StreamPath))]),_c('td',[_c('StartTime',{attrs:{"value":item.StreamInfo.StartTime}})],1),_c('td',[_c('Progress',{attrs:{"stroke-width":20,"percent":Math.ceil(item.BufferRate),"text-inside":""}})],1),_c('td',[_vm._v(_vm._s(item.SyncCount))]),_c('td',[_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.showHeader(item)}}},[_vm._v("头信息")])],1)]}}])}),_c('mu-dialog',{attrs:{"title":"拉流转发","width":"360","open":_vm.openPull},on:{"update:open":function($event){_vm.openPull=$event}}},[_c('mu-text-field',{attrs:{"label":"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:(_vm.remoteAddr),callback:function ($$v) {_vm.remoteAddr=$$v},expression:"remoteAddr"}}),_c('mu-text-field',{attrs:{"label":"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:(_vm.streamPath),callback:function ($$v) {_vm.streamPath=$$v},expression:"streamPath"}}),_c('mu-button',{attrs:{"slot":"actions","flat":"","color":"primary"},on:{"click":_vm.addPull},slot:"actions"},[_vm._v("确定")])],1)],1)}
|
||||
return [_c('td',[_vm._v(_vm._s(item.StreamInfo.StreamPath))]),_c('td',[_c('StartTime',{attrs:{"value":item.StreamInfo.StartTime}})],1),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.InBytes)))]),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.OutBytes)))]),_c('td',[_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.showHeader(item)}}},[_vm._v("头信息")]),_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.stop(item)}}},[_vm._v("中止")])],1)]}}])}),_c('mu-dialog',{attrs:{"title":"拉流转发","width":"360","open":_vm.openPull},on:{"update:open":function($event){_vm.openPull=$event}}},[_c('mu-text-field',{attrs:{"label":"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:(_vm.remoteAddr),callback:function ($$v) {_vm.remoteAddr=$$v},expression:"remoteAddr"}}),_c('mu-text-field',{attrs:{"label":"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:(_vm.streamPath),callback:function ($$v) {_vm.streamPath=$$v},expression:"streamPath"}}),_c('mu-button',{attrs:{"slot":"actions","flat":"","color":"primary"},on:{"click":_vm.addPull},slot:"actions"},[_vm._v("确定")])],1)],1)}
|
||||
var staticRenderFns = []
|
||||
|
||||
|
||||
// CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=0225c7f1&
|
||||
// CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=de44c72c&
|
||||
|
||||
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
|
||||
//
|
||||
@@ -212,12 +212,22 @@ var staticRenderFns = []
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
let listES = null;
|
||||
/* harmony default export */ var Appvue_type_script_lang_js_ = ({
|
||||
components: {
|
||||
StartTime
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
currentStream: null,
|
||||
@@ -225,7 +235,13 @@ let listES = null;
|
||||
remoteAddr: "",
|
||||
streamPath: "",
|
||||
openPull: false,
|
||||
columns:["StreamPath","开始时间","缓冲","同步数","操作" ].map(title=>({title}))
|
||||
columns: [
|
||||
"StreamPath",
|
||||
"开始时间",
|
||||
"总接收",
|
||||
"总发送",
|
||||
"操作"
|
||||
].map(title => ({ title }))
|
||||
};
|
||||
},
|
||||
|
||||
@@ -242,10 +258,10 @@ let listES = null;
|
||||
},
|
||||
showHeader(item) {
|
||||
this.$Modal.info({
|
||||
title: "RTSP Header",
|
||||
title: "RTSP SDPRaw",
|
||||
width: "1000px",
|
||||
scrollable: true,
|
||||
content: item.Header
|
||||
content: item.SDPRaw
|
||||
});
|
||||
},
|
||||
addPull() {
|
||||
@@ -262,6 +278,19 @@ let listES = null;
|
||||
this.$toast.error(x.msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
stop(item) {
|
||||
this.ajax
|
||||
.get(this.apiHost + "/api/stop", {
|
||||
stream: item.StreamInfo.StreamPath
|
||||
})
|
||||
.then(x => {
|
||||
if (x == "success") {
|
||||
this.$toast.success("已停止拉流");
|
||||
} else {
|
||||
this.$toast.error(x.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -269,14 +298,14 @@ let listES = null;
|
||||
let _this = this;
|
||||
this.$parent.titleOps = [
|
||||
{
|
||||
template:'<m-button @click="onClick">拉流转发</m-button>',
|
||||
methods:{
|
||||
onClick(){
|
||||
template: '<m-button @click="onClick">拉流转发</m-button>',
|
||||
methods: {
|
||||
onClick() {
|
||||
_this.openPull = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
},
|
||||
destroyed() {
|
||||
listES.close();
|
||||
|
2
ui/dist/plugin-rtsp.umd.js.map
vendored
2
ui/dist/plugin-rtsp.umd.js.map
vendored
File diff suppressed because one or more lines are too long
2
ui/dist/plugin-rtsp.umd.min.js
vendored
2
ui/dist/plugin-rtsp.umd.min.js
vendored
@@ -1,2 +1,2 @@
|
||||
(function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["plugin-rtsp"]=e():t["plugin-rtsp"]=e()})("undefined"!==typeof self?self:this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s="fb15")}({"034f":function(t,e,r){"use strict";var n=r("85ec"),o=r.n(n);o.a},"85ec":function(t,e,r){},f6fd:function(t,e){(function(t){var e="currentScript",r=t.getElementsByTagName("script");e in t||Object.defineProperty(t,e,{get:function(){try{throw new Error}catch(n){var t,e=(/.*at [^\(]*\((.*):.+:.+\)$/gi.exec(n.stack)||[!1])[1];for(t in r)if(r[t].src==e||"interactive"==r[t].readyState)return r[t];return null}}})})(document)},fb15:function(t,e,r){"use strict";var n;(r.r(e),"undefined"!==typeof window)&&(r("f6fd"),(n=window.document.currentScript)&&(n=n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))&&(r.p=n[1]));var o=function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("div",[r("mu-data-table",{attrs:{data:t.Streams,columns:t.columns},scopedSlots:t._u([{key:"default",fn:function(e){var n=e.row;return[r("td",[t._v(t._s(n.StreamInfo.StreamPath))]),r("td",[r("StartTime",{attrs:{value:n.StreamInfo.StartTime}})],1),r("td",[r("Progress",{attrs:{"stroke-width":20,percent:Math.ceil(n.BufferRate),"text-inside":""}})],1),r("td",[t._v(t._s(n.SyncCount))]),r("td",[r("mu-button",{attrs:{flat:""},on:{click:function(e){return t.showHeader(n)}}},[t._v("头信息")])],1)]}}])}),r("mu-dialog",{attrs:{title:"拉流转发",width:"360",open:t.openPull},on:{"update:open":function(e){t.openPull=e}}},[r("mu-text-field",{attrs:{label:"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:t.remoteAddr,callback:function(e){t.remoteAddr=e},expression:"remoteAddr"}}),r("mu-text-field",{attrs:{label:"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:t.streamPath,callback:function(e){t.streamPath=e},expression:"streamPath"}}),r("mu-button",{attrs:{slot:"actions",flat:"",color:"primary"},on:{click:t.addPull},slot:"actions"},[t._v("确定")])],1)],1)},a=[];let s=null;var i={components:{StartTime:StartTime},data(){return{currentStream:null,Streams:null,remoteAddr:"",streamPath:"",openPull:!1,columns:["StreamPath","开始时间","缓冲","同步数","操作"].map(t=>({title:t}))}},methods:{fetchlist(){s=new EventSource(this.apiHost+"/rtsp/list"),s.onmessage=t=>{t.data&&(this.Streams=JSON.parse(t.data)||[],this.Streams.sort((t,e)=>t.StreamInfo.StreamPath>e.StreamInfo.StreamPath?1:-1))}},showHeader(t){this.$Modal.info({title:"RTSP Header",width:"1000px",scrollable:!0,content:t.Header})},addPull(){this.openPull=!1,this.ajax.getJSON(this.apiHost+"/rtsp/pull",{target:this.remoteAddr,streamPath:this.streamPath}).then(t=>{0==t.code?this.$toast.success("已启动拉流"):this.$toast.error(t.msg)})}},mounted(){this.fetchlist();let t=this;this.$parent.titleOps=[{template:'<m-button @click="onClick">拉流转发</m-button>',methods:{onClick(){t.openPull=!0}}}]},destroyed(){s.close()}},l=i;r("034f");function u(t,e,r,n,o,a,s,i){var l,u="function"===typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=r,u._compiled=!0),n&&(u.functional=!0),a&&(u._scopeId="data-v-"+a),s?(l=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},u._ssrRegister=l):o&&(l=i?function(){o.call(this,this.$root.$options.shadowRoot)}:o),l)if(u.functional){u._injectStyles=l;var c=u.render;u.render=function(t,e){return l.call(e),c(t,e)}}else{var d=u.beforeCreate;u.beforeCreate=d?[].concat(d,l):[l]}return{exports:t,options:u}}var c=u(l,o,a,!1,null,null,null),d=c.exports;e["default"]=d}})["default"]}));
|
||||
(function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["plugin-rtsp"]=e():t["plugin-rtsp"]=e()})("undefined"!==typeof self?self:this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s="fb15")}({"034f":function(t,e,r){"use strict";var n=r("85ec"),o=r.n(n);o.a},"85ec":function(t,e,r){},f6fd:function(t,e){(function(t){var e="currentScript",r=t.getElementsByTagName("script");e in t||Object.defineProperty(t,e,{get:function(){try{throw new Error}catch(n){var t,e=(/.*at [^\(]*\((.*):.+:.+\)$/gi.exec(n.stack)||[!1])[1];for(t in r)if(r[t].src==e||"interactive"==r[t].readyState)return r[t];return null}}})})(document)},fb15:function(t,e,r){"use strict";var n;(r.r(e),"undefined"!==typeof window)&&(r("f6fd"),(n=window.document.currentScript)&&(n=n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))&&(r.p=n[1]));var o=function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("div",[r("mu-data-table",{attrs:{data:t.Streams,columns:t.columns},scopedSlots:t._u([{key:"default",fn:function(e){var n=e.row;return[r("td",[t._v(t._s(n.StreamInfo.StreamPath))]),r("td",[r("StartTime",{attrs:{value:n.StreamInfo.StartTime}})],1),r("td",[t._v(t._s(t.unitFormat(n.InBytes)))]),r("td",[t._v(t._s(t.unitFormat(n.OutBytes)))]),r("td",[r("mu-button",{attrs:{flat:""},on:{click:function(e){return t.showHeader(n)}}},[t._v("头信息")]),r("mu-button",{attrs:{flat:""},on:{click:function(e){return t.stop(n)}}},[t._v("中止")])],1)]}}])}),r("mu-dialog",{attrs:{title:"拉流转发",width:"360",open:t.openPull},on:{"update:open":function(e){t.openPull=e}}},[r("mu-text-field",{attrs:{label:"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:t.remoteAddr,callback:function(e){t.remoteAddr=e},expression:"remoteAddr"}}),r("mu-text-field",{attrs:{label:"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:t.streamPath,callback:function(e){t.streamPath=e},expression:"streamPath"}}),r("mu-button",{attrs:{slot:"actions",flat:"",color:"primary"},on:{click:t.addPull},slot:"actions"},[t._v("确定")])],1)],1)},a=[];let s=null;var i={data(){return{currentStream:null,Streams:null,remoteAddr:"",streamPath:"",openPull:!1,columns:["StreamPath","开始时间","总接收","总发送","操作"].map(t=>({title:t}))}},methods:{fetchlist(){s=new EventSource(this.apiHost+"/rtsp/list"),s.onmessage=t=>{t.data&&(this.Streams=JSON.parse(t.data)||[],this.Streams.sort((t,e)=>t.StreamInfo.StreamPath>e.StreamInfo.StreamPath?1:-1))}},showHeader(t){this.$Modal.info({title:"RTSP SDPRaw",width:"1000px",scrollable:!0,content:t.SDPRaw})},addPull(){this.openPull=!1,this.ajax.getJSON(this.apiHost+"/rtsp/pull",{target:this.remoteAddr,streamPath:this.streamPath}).then(t=>{0==t.code?this.$toast.success("已启动拉流"):this.$toast.error(t.msg)})},stop(t){this.ajax.get(this.apiHost+"/api/stop",{stream:t.StreamInfo.StreamPath}).then(t=>{"success"==t?this.$toast.success("已停止拉流"):this.$toast.error(t.msg)})}},mounted(){this.fetchlist();let t=this;this.$parent.titleOps=[{template:'<m-button @click="onClick">拉流转发</m-button>',methods:{onClick(){t.openPull=!0}}}]},destroyed(){s.close()}},l=i;r("034f");function u(t,e,r,n,o,a,s,i){var l,u="function"===typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=r,u._compiled=!0),n&&(u.functional=!0),a&&(u._scopeId="data-v-"+a),s?(l=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},u._ssrRegister=l):o&&(l=i?function(){o.call(this,this.$root.$options.shadowRoot)}:o),l)if(u.functional){u._injectStyles=l;var c=u.render;u.render=function(t,e){return l.call(e),c(t,e)}}else{var f=u.beforeCreate;u.beforeCreate=f?[].concat(f,l):[l]}return{exports:t,options:u}}var c=u(l,o,a,!1,null,null,null),f=c.exports;e["default"]=f}})["default"]}));
|
||||
//# sourceMappingURL=plugin-rtsp.umd.min.js.map
|
2
ui/dist/plugin-rtsp.umd.min.js.map
vendored
2
ui/dist/plugin-rtsp.umd.min.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -3,17 +3,30 @@
|
||||
<mu-data-table :data="Streams" :columns="columns">
|
||||
<template #default="{row:item}">
|
||||
<td>{{item.StreamInfo.StreamPath}}</td>
|
||||
<td><StartTime :value="item.StreamInfo.StartTime"></StartTime></td>
|
||||
<td><Progress :stroke-width="20" :percent="Math.ceil(item.BufferRate)" text-inside /></td>
|
||||
<td>{{item.SyncCount}}</td>
|
||||
<td><mu-button flat @click="showHeader(item)">头信息</mu-button></td>
|
||||
<td>
|
||||
<StartTime :value="item.StreamInfo.StartTime"></StartTime>
|
||||
</td>
|
||||
<td>{{unitFormat(item.InBytes)}}</td>
|
||||
<td>{{unitFormat(item.OutBytes)}}</td>
|
||||
<td>
|
||||
<mu-button flat @click="showHeader(item)">头信息</mu-button>
|
||||
<mu-button flat @click="stop(item)">中止</mu-button>
|
||||
</td>
|
||||
</template>
|
||||
</mu-data-table>
|
||||
<mu-dialog title="拉流转发" width="360" :open.sync="openPull">
|
||||
<mu-text-field v-model="remoteAddr" label="rtsp url" label-float help-text="Please enter URL of rtsp...">
|
||||
</mu-text-field>
|
||||
<mu-text-field v-model="streamPath" label="streamPath" label-float
|
||||
help-text="Please enter streamPath to publish."></mu-text-field>
|
||||
<mu-text-field
|
||||
v-model="remoteAddr"
|
||||
label="rtsp url"
|
||||
label-float
|
||||
help-text="Please enter URL of rtsp..."
|
||||
></mu-text-field>
|
||||
<mu-text-field
|
||||
v-model="streamPath"
|
||||
label="streamPath"
|
||||
label-float
|
||||
help-text="Please enter streamPath to publish."
|
||||
></mu-text-field>
|
||||
<mu-button slot="actions" flat color="primary" @click="addPull">确定</mu-button>
|
||||
</mu-dialog>
|
||||
</div>
|
||||
@@ -22,9 +35,6 @@
|
||||
<script>
|
||||
let listES = null;
|
||||
export default {
|
||||
components: {
|
||||
StartTime
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
currentStream: null,
|
||||
@@ -32,7 +42,13 @@ export default {
|
||||
remoteAddr: "",
|
||||
streamPath: "",
|
||||
openPull: false,
|
||||
columns:["StreamPath","开始时间","缓冲","同步数","操作" ].map(title=>({title}))
|
||||
columns: [
|
||||
"StreamPath",
|
||||
"开始时间",
|
||||
"总接收",
|
||||
"总发送",
|
||||
"操作"
|
||||
].map(title => ({ title }))
|
||||
};
|
||||
},
|
||||
|
||||
@@ -49,10 +65,10 @@ export default {
|
||||
},
|
||||
showHeader(item) {
|
||||
this.$Modal.info({
|
||||
title: "RTSP Header",
|
||||
title: "RTSP SDPRaw",
|
||||
width: "1000px",
|
||||
scrollable: true,
|
||||
content: item.Header
|
||||
content: item.SDPRaw
|
||||
});
|
||||
},
|
||||
addPull() {
|
||||
@@ -69,6 +85,19 @@ export default {
|
||||
this.$toast.error(x.msg);
|
||||
}
|
||||
});
|
||||
},
|
||||
stop(item) {
|
||||
this.ajax
|
||||
.get(this.apiHost + "/api/stop", {
|
||||
stream: item.StreamInfo.StreamPath
|
||||
})
|
||||
.then(x => {
|
||||
if (x == "success") {
|
||||
this.$toast.success("已停止拉流");
|
||||
} else {
|
||||
this.$toast.error(x.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -76,14 +105,14 @@ export default {
|
||||
let _this = this;
|
||||
this.$parent.titleOps = [
|
||||
{
|
||||
template:'<m-button @click="onClick">拉流转发</m-button>',
|
||||
methods:{
|
||||
onClick(){
|
||||
template: '<m-button @click="onClick">拉流转发</m-button>',
|
||||
methods: {
|
||||
onClick() {
|
||||
_this.openPull = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
},
|
||||
destroyed() {
|
||||
listES.close();
|
||||
|
Reference in New Issue
Block a user