Compare commits

...

80 Commits

Author SHA1 Message Date
dexter
e6d0489d9c Merge pull request #20 from ziminghua/aler9
解决发布超时后,重连RTSP,无法播放的BUG
2022-02-22 21:17:24 +08:00
訾明华
68d0d9aa08 解决发布超时后,重连RTSP,无法播放的BUG
清空rtsp.processFunc数据,避免接收到流时,指向旧的track,导致新stream无法播放
2022-02-22 21:15:35 +08:00
dexter
e411d30e91 Merge pull request #17 from jianglieshan/aler9
fix:修改rtsp插件作为服务端出流时,ssrc为0的bug
2022-01-16 13:12:11 +08:00
jianglieshan
709a4cee7b fix:修改rtsp插件作为服务端出流时,ssrc为0的bug 2022-01-15 16:50:40 +08:00
dexter
a90f52769d Merge pull request #16 from ziminghua/aler9
增加RTSPClient关闭的事件订阅,同步关闭客户端连接
2022-01-11 17:00:40 +08:00
訾明华
3764a26bbd 增加RTSPClient关闭的事件订阅,同步关闭客户端连接
增加RTSPClient关闭的事件订阅,同步关闭客户端连接
2022-01-11 16:52:14 +08:00
dexter
2533ab2604 Merge pull request #15 from ziminghua/aler9
多slice的情况下,同步同一帧的时间戳
2022-01-11 11:40:38 +08:00
訾明华
db07f0d588 多slice的情况下,同步同一帧的时间戳
`vpacketer.Packetize`再打包的过程中会把当前的timestamp+samples作为下一次打包的时间戳,如果多slice会连续传递samples导致同一帧的时间戳不一致
2022-01-11 11:34:29 +08:00
dexter
f110513d70 增加配置项ReadBufferSize 2021-12-29 22:59:45 +08:00
dexter
8901f4c117 修复bug 2021-12-29 22:16:11 +08:00
dexter
2f7c2de352 增加读取缓存大小,设置Mark标志位 2021-12-29 20:18:12 +08:00
dexter
af053bb5e6 对处理回调判空 2021-12-27 20:42:06 +08:00
dexter
bed7ba8a87 修复一个低级错误 2021-12-22 16:32:06 +08:00
dexter
0cbc4beb0f Merge pull request #13 from lhong1001/rtsp-syld
modified by syld 2021-12-20
2021-12-20 18:24:49 +08:00
root
edbfc07275 modified by syld 2021-12-20 2021-12-20 17:43:08 +08:00
dexter
329f93022e 修复流终止时仍然在拉流的bug 2021-12-14 14:21:52 +08:00
dexter
4895f2ec42 修复获取rtsp列表信息 2021-12-13 10:17:54 +08:00
dexter
9eb117811d 改名 2021-11-28 23:08:13 +08:00
dexter
00ecd3469f 每次重连切换连接方式 2021-11-23 12:40:21 +08:00
dexter
4107d31c79 默认拉tcp 2021-11-19 21:24:30 +08:00
dexter
5094fd0db7 加入转推功能 2021-11-18 19:29:31 +08:00
dexter
ef106e42f8 跟随升级gotsplib 2021-11-18 19:05:06 +08:00
dexter
0ac9513920 更新readme 2021-11-16 19:14:23 +08:00
dexter
a900613c70 初步改造完成 2021-11-16 19:06:24 +08:00
dexter
ac8aa96350 format 2021-10-06 09:22:59 +08:00
dexter
f267b1ca52 rtp依赖1.6.5不能用1.7版本 2021-08-08 08:07:22 +08:00
dexter
229370c083 更改类型适配pion的rtp类型升级 2021-08-08 07:40:52 +08:00
dexter
bb1e8ba1d8 适配3.3 2021-08-07 22:00:28 +08:00
dexter
8cf3e0c0fc 增加对publisher的非空判断 2021-08-04 15:27:55 +08:00
dexter
1ecb45d904 修改readme 2021-08-03 15:33:55 +08:00
dexter
3ea5bb7f27 更新readme 2021-08-02 09:21:38 +08:00
langhuihui
9aec4ec4be 防止json循环引用 2021-07-24 11:38:24 +08:00
langhuihui
da2fc9d462 更新重连逻辑 2021-07-24 09:38:22 +08:00
李宇翔
f68a3ee14b 实现rtsp拉流播放 2021-07-19 20:07:01 +08:00
langhuihui
a2f5cb87b1 修复音频初始化问题 2021-07-12 23:24:04 +08:00
langhuihui
5cdbc220de 修改rtsp自动拉流配置结构 2021-07-11 21:43:15 +08:00
langhuihui
f0a00f3db9 更新readme 2021-07-10 17:52:50 +08:00
langhuihui
fd8ebcd87c 内存复制 2021-07-09 22:50:33 +08:00
langhuihui
cc731a25f0 适配3.1 2021-07-09 08:18:19 +08:00
dexter
ba9f39853f Merge pull request #9 from dwdcth/v3
修复sps pps vps为空
2021-06-24 17:29:20 +08:00
banshan
0c8bd62e81 修复sps pps vps为空 2021-06-24 16:35:57 +08:00
李宇翔
dfe462a7d1 修复对Codec判断 2021-06-23 17:54:53 +08:00
李宇翔
cc7b899922 优化track设定 2021-06-23 15:57:44 +08:00
langhuihui
b0c3cdb21a 适配引擎版本升级 2021-06-15 08:06:40 +08:00
李宇翔
d08230bf0c v3去除UI 2021-03-30 18:52:30 +08:00
dexter
8a7fdedc0f Merge pull request #8 from dwdcth/patch-1
embed
2021-03-20 12:53:07 +08:00
banshan
b7d59b0198 embed 2021-03-19 14:22:34 +08:00
dwdcth
dc65348ccb Update go.mod 2021-03-19 14:13:53 +08:00
langhuihui
7fa6d0dcce 修改API 2021-02-26 22:03:50 +08:00
langhuihui
0689154012 适配3.0 2021-02-23 13:23:39 +08:00
langhuihui
2e39eabcba 适配3.0 2021-02-17 21:54:37 +08:00
langhuihui
a9cb4cd853 增加cors头 2020-11-16 21:23:16 +08:00
langhuihui
7e61ba71f7 怎加初始拉流功能 2020-10-01 20:12:26 +08:00
langhuihui
d6384dcbd5 版本更新 2020-09-23 23:04:07 +08:00
langhuihui
2159a6fd9b 解决rtsp推流无视频时的报错 2020-09-23 22:55:52 +08:00
langhuihui
02f3e91085 对其他音频的支持 2020-09-20 15:54:27 +08:00
langhuihui
7f40078b50 添加对engine版本的依赖 2020-08-29 08:00:25 +08:00
dexter
bb563d64c7 Merge pull request #5 from ourfor-pp/master
修复保活请求的bug
2020-08-29 07:48:16 +08:00
mqh
f7cb146b89 修复client.Session未保存,导致保活请求未携带session的bug 2020-08-28 17:05:45 +08:00
dexter
9bb49cb9f7 Merge pull request #4 from ourfor-pp/master
修改保活请求
2020-08-28 13:53:48 +08:00
mqh
087d1aab4d 增加basic登录(大华录像机测试验证) 2020-08-28 09:56:01 +08:00
mqh
f949464328 Merge branch 'master' of https://github.com/ourfor-pp/plugin-rtsp 2020-08-28 09:33:53 +08:00
mqh
d89f1e2405 将保活请求由OPTIONS改为GET_PARAMETER(来自VLC保活参考) 2020-08-28 09:26:57 +08:00
langhuihui
1d3fbfc20b 增加对纯音频的播放的支持 2020-08-27 08:50:45 +08:00
dexter
fd64a69a12 Merge pull request #2 from zbjlala/master
master
2020-08-26 22:17:37 +08:00
zbj
0e4406ad14 [fix]宇视摄像头DESCRIBE 有两个RTSP流 一个video matedata 需要两个SETUP才可播放 2020-08-25 11:55:49 +08:00
zbj
22f33886a9 [fix]宇视摄像头不支持该OPTIONS操作 551 2020-08-25 11:44:54 +08:00
langhuihui
8b1892209d 增加5分钟重连机制 2020-07-12 10:40:02 +08:00
langhuihui
2e9cf9a4ca 重连机制修复 2020-07-11 21:54:59 +08:00
langhuihui
67da93d8e2 增加重连时的判断 2020-07-09 22:04:00 +08:00
unknown
cb733b368f 增加重连功能 2020-07-09 20:06:35 +08:00
langhuihui
fadeccddab 更新依赖engine的版本 2020-06-09 07:12:20 +08:00
langhuihui
93df7632a6 修正升级带来的bug 2020-06-09 07:09:25 +08:00
langhuihui
53c4788df2 改用RTP插件 2020-05-31 10:01:29 +08:00
langhuihui
f5bdd6a298 内存复用 2020-05-24 22:58:38 +08:00
李宇翔
eaddc60775 过滤开头的NonIDR 2020-05-21 18:16:56 +08:00
langhuihui
655170cb24 修复中止拉流的操作 2020-05-20 09:55:39 +08:00
李宇翔
55bd2ce785 增加中止操作 2020-05-19 19:25:44 +08:00
李宇翔
2004a6afc1 删除错误引用StartTime 2020-05-11 11:25:45 +08:00
langhuihui
1873861e8b 新增RTSP server功能 2020-05-10 18:28:05 +08:00
21 changed files with 933 additions and 11303 deletions

21
LICENSE Normal file
View 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.

View File

@@ -1,24 +1,63 @@
# Monibuca 的RTSP 插件 # RTSP插件
主要功能是对RTSP地址进行拉流转换 ## 插件地址
## 插件名称 github.com/Monibuca/plugin-rtsp
RTSP ## 插件引入
```go
import (
_ "github.com/Monibuca/plugin-rtsp"
)
```
## 默认插件配置
## 配置
```toml ```toml
[RTSP] [RTSP]
BufferLength = 2048 # 端口接收推流
AutoPull = false ListenAddr = ":554"
RemoteAddr = "rtsp://localhost/${streamPath}" Reconnect = true
[RTSP.AutoPullList]
"live/rtsp1" = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=1&subtype=1"
"live/rtsp2" = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=2&subtype=1"
``` ```
- BufferLength是指解析拉取的rtp包的缓冲大小
- AutoPull是指当有用户订阅一个新房间的时候自动向远程拉流转发
- RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。
- `ListenAddr`是监听的地址
- `Reconnect` 是否自动重连
- `RTSP.AutoPullList` 可以配置多项用于自动拉流key是streamPathvalue是远程rtsp地址
## 使用方法(拉流转发) ### 特殊功能
当自动拉流列表中当的streamPath为sub/xxx 这种形式的话在gb28181的分屏显示时会优先采用rtsp流已实现分屏观看子码流效果
## 插件功能
### 接收RTSP协议的推流
例如通过ffmpeg向m7s进行推流
```bash
ffmpeg -i **** rtsp://localhost/live/test
```
会在m7s内部形成一个名为live/test的流
### 从远程拉取rtsp到m7s中
可调用接口
`/api/rtsp/pull?target=[RTSP地址]&streamPath=[流标识]`
## 使用编程方式拉流
```go ```go
new(RTSP).Publish("live/user1","rtsp://xxx.xxx.xxx.xxx/live/user1") new(RTSPClient).PullStream("live/user1","rtsp://xxx.xxx.xxx.xxx/live/user1")
``` ```
### 罗列所有的rtsp协议的流
可调用接口
`/api/rtsp/list`
### 从m7s中拉取rtsp协议流
直接通过协议rtsp://xxx.xxx.xxx.xxx/live/user1 即可播放
> h265 编码拉流尚未实现,敬请期待

724
client.go
View File

@@ -1,546 +1,214 @@
package rtspplugin package rtsp
import ( import (
"crypto/md5" "errors"
b64 "encoding/base64"
"encoding/hex"
"fmt"
"io"
"log"
"net"
"net/url"
"regexp"
"strconv"
"strings"
"time" "time"
"unsafe"
. "github.com/Monibuca/engine/v3"
. "github.com/Monibuca/utils/v3"
"github.com/Monibuca/utils/v3/codec"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/aac"
"github.com/aler9/gortsplib/pkg/base"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
) )
var ( type RTSPClient struct {
VideoWidth int RTSPublisher
VideoHeight int Transport gortsplib.Transport
spropReg *regexp.Regexp *gortsplib.Client `json:"-"`
configReg *regexp.Regexp
)
func init() {
spropReg, _ = regexp.Compile("sprop-parameter-sets=([^;]+)")
configReg, _ = regexp.Compile("config=([^;]+)")
} }
type RtspClient struct { // PullStream 从外部拉流
socket net.Conn func (rtsp *RTSPClient) PullStream(streamPath string, rtspUrl string) (err error) {
OutGoing chan []byte //out chanel rtsp.Stream = &Stream{
Signals chan bool //Signals quit StreamPath: streamPath,
host string //host Type: "RTSP Pull",
port string //port ExtraProp: rtsp,
uri string //url
auth bool //aut
login string
password string //password
session string //rtsp session
responce string //responce string
bauth string //string b auth
track []string //rtsp track
cseq int //qury number
videow int
videoh int
SPS []byte
PPS []byte
Header string
AudioSpecificConfig []byte
}
//RtspClientNew 返回空的初始化对象
func RtspClientNew(bufferLength int) *RtspClient {
Obj := &RtspClient{
cseq: 1, //查询起始号码
Signals: make(chan bool, 1), //一个消息缓冲通道
OutGoing: make(chan []byte, bufferLength), //输出通道
} }
return Obj if result := rtsp.Publish(); result {
} rtsp.URL = rtspUrl
if config.Reconnect {
func (this *RtspClient) Client(rtsp_url string) (bool, string) { go func() {
//Check back url for rtsp.pullStream(); rtsp.Err() == nil; rtsp.pullStream() {
if !this.ParseUrl(rtsp_url) { Printf("reconnecting:%s in 5 seconds", rtspUrl)
return false, "Incorrect url" if rtsp.Transport == gortsplib.TransportTCP {
} rtsp.Transport = gortsplib.TransportUDP
//Install connect to camera
if !this.Connect() {
return false, "cannot connect"
}
//Phase 1 options camera phase 1
//Send options request
if !this.Write("OPTIONS " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\n\r\n") {
return false, "Unable to send options message"
}
//Read the response to the options request
if status, message := this.Read(); !status {
return false, "Unable to read options response connection lost"
} else if status && strings.Contains(message, "Digest") {
if !this.AuthDigest("OPTIONS", message) {
return false, "Summary of authorization required"
}
} else if status && strings.Contains(message, "Basic") {
if !this.AuthBasic("OPTIONS", message) {
return false, "Need certification Basic"
}
} else if !strings.Contains(message, "200") {
return false, "error OPTIONS not status code 200 OK " + message
}
////////////PHASE 2 DESCRIBE
log.Println("DESCRIBE " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + this.bauth + "\r\n\r\n")
if !this.Write("DESCRIBE " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + this.bauth + "\r\n\r\n") {
return false, "Unable to send query DESCRIBE"
}
if status, message := this.Read(); !status {
return false, "Can't read response for decscribe connection loss?"
} else if status && strings.Contains(message, "Digest") {
if !this.AuthDigest("DESCRIBE", message) {
return false, "Summary of authorization required"
}
} else if status && strings.Contains(message, "Basic") {
if !this.AuthBasic("DESCRIBE", message) {
return false, "Basis of authorization required"
}
} else if !strings.Contains(message, "200") {
return false, "error DESCRIBE not status code 200 OK " + message
} else {
this.Header = message
this.track = this.ParseMedia(message)
}
if len(this.track) == 0 {
return false, "error track not found "
}
//PHASE 3 SETUP
log.Println("SETUP " + this.uri + "/" + this.track[0] + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nTransport: RTP/AVP/TCP;unicast;interleaved=0-1" + this.bauth + "\r\n\r\n")
if !this.Write("SETUP " + this.uri + "/" + this.track[0] + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nTransport: RTP/AVP/TCP;unicast;interleaved=0-1" + this.bauth + "\r\n\r\n") {
return false, ""
}
if status, message := this.Read(); !status {
return false, "Unable to read response for missing setup connection."
} else if !strings.Contains(message, "200") {
if strings.Contains(message, "401") {
str := this.AuthDigest_Only("SETUP", message)
if !this.Write("SETUP " + this.uri + "/" + this.track[0] + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nTransport: RTP/AVP/TCP;unicast;interleaved=0-1" + this.bauth + str + "\r\n\r\n") {
return false, ""
}
if status, message := this.Read(); !status {
return false, "Unable to read response for missing setup connection."
} else if !strings.Contains(message, "200") {
return false, "error SETUP not status code 200 OK " + message
} else {
this.session = ParseSession(message)
}
} else {
return false, "error SETUP not status code 200 OK " + message
}
} else {
log.Println(message)
this.session = ParseSession(message)
log.Println(this.session)
}
if len(this.track) > 1 {
if !this.Write("SETUP " + this.uri + "/" + this.track[1] + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nTransport: RTP/AVP/TCP;unicast;interleaved=2-3" + "\r\nSession: " + this.session + this.bauth + "\r\n\r\n") {
return false, ""
}
if status, message := this.Read(); !status {
return false, "Unable to read response for missing setup audio connection."
} else if !strings.Contains(message, "200") {
if strings.Contains(message, "401") {
str := this.AuthDigest_Only("SETUP", message)
if !this.Write("SETUP " + this.uri + "/" + this.track[1] + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nTransport: RTP/AVP/TCP;unicast;interleaved=2-3" + this.bauth + str + "\r\n\r\n") {
return false, ""
}
if status, message := this.Read(); !status {
return false, "Unable to read response for missing setup audio connection."
} else if !strings.Contains(message, "200") {
return false, "error SETUP not status code 200 OK " + message
} else {
log.Println(message)
this.session = ParseSession(message)
}
} else {
return false, "error SETUP not status code 200 OK " + message
}
} else {
log.Println(message)
this.session = ParseSession(message)
}
}
//PHASE 4 SETUP
log.Println("PLAY " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nSession: " + this.session + this.bauth + "\r\n\r\n")
if !this.Write("PLAY " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nSession: " + this.session + this.bauth + "\r\n\r\n") {
return false, ""
}
if status, message := this.Read(); !status {
return false, "Unable to read play response lost connection"
} else if !strings.Contains(message, "200") {
//return false, "Ошибка PLAY not status code 200 OK " + message
if strings.Contains(message, "401") {
str := this.AuthDigest_Only("PLAY", message)
if !this.Write("PLAY " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nSession: " + this.session + this.bauth + str + "\r\n\r\n") {
return false, ""
}
if status, message := this.Read(); !status {
return false, "Unable to read play response lost connection"
} else if !strings.Contains(message, "200") {
return false, "error PLAY not status code 200 OK " + message
} else {
//this.session = ParseSession(message)
log.Print(message)
go this.RtspRtpLoop()
return true, "ok"
}
} else {
return false, "error PLAY not status code 200 OK " + message
}
} else {
log.Print(message)
go this.RtspRtpLoop()
return true, "ok"
}
return false, "other error"
}
/*
The RTP header has the following format:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=2|P|X| CC |M| PT | sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| synchronization source (SSRC) identifier |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
| contributing source (CSRC) identifiers |
| .... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
version (V): 2 bits
This field identifies the version of RTP. The version defined by
this specification is two (2). (The value 1 is used by the first
draft version of RTP and the value 0 is used by the protocol
initially implemented in the "vat" audio tool.)
padding (P): 1 bit
If the padding bit is set, the packet contains one or more
additional padding octets at the end which are not part of the
payload. The last octet of the padding contains a count of how
many padding octets should be ignored, including itself. Padding
may be needed by some encryption algorithms with fixed block sizes
or for carrying several RTP packets in a lower-layer protocol data
unit.
extension (X): 1 bit
If the extension bit is set, the fixed header MUST be followed by
exactly one header extension, with a format defined in Section
5.3.1.
*/
func (this *RtspClient) RtspRtpLoop() {
defer func() {
this.Signals <- true
}()
header := make([]byte, 4)
payload := make([]byte, 4096)
//sync := make([]byte, 256)
sync_b := make([]byte, 1)
timer := time.Now()
for {
if int(time.Now().Sub(timer).Seconds()) > 50 {
if !this.Write("OPTIONS " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + "\r\nSession: " + this.session + this.bauth + "\r\n\r\n") {
return
}
timer = time.Now()
}
this.socket.SetDeadline(time.Now().Add(50 * time.Second))
//read rtp hdr 4
if n, err := io.ReadFull(this.socket, header); err != nil || n != 4 {
//rtp hdr read error
return
}
//log.Println(header)
if header[0] != 36 {
//log.Println("desync?", this.host)
for {
///////////////////////////skeep/////////////////////////////////////
if n, err := io.ReadFull(this.socket, sync_b); err != nil && n != 1 {
return
} else if sync_b[0] == 36 {
header[0] = 36
if n, err := io.ReadFull(this.socket, header[1:]); err != nil && n == 3 {
return
}
break
}
}
/*
//вычитываем 256 в попытке отсять мусор обрезать RTSP
if string(header) == "RTSP" {
if n, err := io.ReadFull(this.socket, sync); err != nil && n == 256 {
return
} else { } else {
rtsp_rtp := []byte(strings.Split(string(sync), "\r\n\r\n")[1]) rtsp.Transport = gortsplib.TransportTCP
//отправим все что есть в буфере
this.SendBufer(rtsp_rtp)
continue
} }
time.Sleep(time.Second * 5)
}
if rtsp.IsTimeout {
rtsp.processFunc = nil
go rtsp.PullStream(streamPath, rtspUrl)
}
}()
} else {
go rtsp.pullStream()
}
return
}
return errors.New("publish badname")
}
func (rtsp *RTSPClient) PushStream(streamPath string, rtspUrl string) (err error) {
if s := FindStream(streamPath); s != nil {
var tracks gortsplib.Tracks
var sub RTSPSubscriber
sub.Type = "RTSP push out"
sub.vt = s.WaitVideoTrack("h264", "h265")
sub.at = s.WaitAudioTrack("aac", "pcma", "pcmu")
ssrc := uintptr(unsafe.Pointer(&sub))
var trackIds = 0
if sub.vt != nil {
trackId := trackIds
var vtrack *gortsplib.Track
var vpacketer rtp.Packetizer
switch sub.vt.CodecID {
case codec.CodecID_H264:
if vtrack, err = gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{
SPS: sub.vt.ExtraData.NALUs[0],
PPS: sub.vt.ExtraData.NALUs[1],
}); err == nil {
vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &codecs.H264Payloader{}, rtp.NewFixedSequencer(1), 90000)
} else { } else {
log.Println("full desync") return err
return
} }
*/ case codec.CodecID_H265:
vtrack = NewH265Track(96, sub.vt.ExtraData.NALUs)
vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &H265Payloader{}, rtp.NewFixedSequencer(1), 90000)
}
var st uint32
onVideo := func(ts uint32, pack *VideoPack) {
for _, nalu := range pack.NALUs {
for _, pack := range vpacketer.Packetize(nalu, (ts-st)*90) {
rtp, _ := pack.Marshal()
rtsp.WritePacketRTP(trackId, rtp)
}
}
st = ts
}
sub.OnVideo = func(ts uint32, pack *VideoPack) {
if st = ts; st != 0 {
sub.OnVideo = onVideo
}
onVideo(ts, pack)
}
tracks = append(tracks, vtrack)
trackIds++
} }
if sub.at != nil {
payloadLen := (int)(header[2])<<8 + (int)(header[3]) var st uint32
//log.Println("payloadLen", payloadLen) trackId := trackIds
if payloadLen > 4096 || payloadLen < 12 { switch sub.at.CodecID {
log.Println("desync", this.uri, payloadLen) case codec.CodecID_PCMA, codec.CodecID_PCMU:
atrack := NewG711Track(97, map[byte]string{7: "pcma", 8: "pcmu"}[sub.at.CodecID])
apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &codecs.G711Payloader{}, rtp.NewFixedSequencer(1), 8000)
sub.OnAudio = func(ts uint32, pack *AudioPack) {
for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*8) {
buf, _ := pack.Marshal()
rtsp.WritePacketRTP(trackId, buf)
}
st = ts
}
tracks = append(tracks, atrack)
case codec.CodecID_AAC:
var mpegConf aac.MPEG4AudioConfig
mpegConf.Decode(sub.at.ExtraData[2:])
conf := &gortsplib.TrackConfigAAC{
Type: int(mpegConf.Type),
SampleRate: mpegConf.SampleRate,
ChannelCount: mpegConf.ChannelCount,
AOTSpecificConfig: mpegConf.AOTSpecificConfig,
}
if atrack, err := gortsplib.NewTrackAAC(97, conf); err == nil {
apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &AACPayloader{}, rtp.NewFixedSequencer(1), uint32(mpegConf.SampleRate))
sub.OnAudio = func(ts uint32, pack *AudioPack) {
for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*uint32(mpegConf.SampleRate)/1000) {
buf, _ := pack.Marshal()
rtsp.WritePacketRTP(trackId, buf)
}
st = ts
}
tracks = append(tracks, atrack)
}
}
}
return rtsp.StartPublishing(rtspUrl, tracks)
}
return errors.New("stream not exist")
}
func (client *RTSPClient) pullStream() {
if client.Err() != nil {
return
}
client.Client = &gortsplib.Client{
OnPacketRTP: func(trackID int, payload []byte) {
// Println("OnPacketRTP", trackID, len(payload))
if f := client.processFunc[trackID]; f != nil {
var clone []byte
f(append(clone, payload...))
}
},
ReadBufferSize: config.ReadBufferSize,
Transport: &client.Transport,
}
// parse URL
u, err := base.ParseURL(client.URL)
if err != nil {
Printf("ParseURL:%s error:%v", client.URL, err)
return
}
// connect to the server
if err = client.Start(u.Scheme, u.Host); err != nil {
Printf("connect:%s error:%v", client.URL, err)
return
}
client.OnClose = func() {
client.Client.Close()
}
//client.close should be after connected!
defer client.Client.Close()
var res *base.Response
if res, err = client.Options(u); err != nil {
Printf("option:%s error:%v", client.URL, err)
return
}
Println(res)
// find published tracks
tracks, baseURL, res, err := client.Describe(u)
if err != nil {
Printf("Describe:%s error:%v", client.URL, err)
return
}
Println(res)
if client.processFunc == nil {
client.setTracks(tracks)
}
for _, track := range tracks {
if res, err = client.Setup(true, track, baseURL, 0, 0); err != nil {
Printf("Setup:%s error:%v", baseURL.String(), err)
return return
} }
if n, err := io.ReadFull(this.socket, payload[:payloadLen]); err != nil || n != payloadLen { Println(res)
return
} else {
this.OutGoing <- append(header, payload[:n]...)
}
} }
// start reading tracks
} if res, err = client.Play(nil); err != nil {
Printf("Play:%s error:%v", baseURL.String(), err)
//unsafe! return
func (this *RtspClient) SendBufer(bufer []byte) { }
//Here you need to send all the packages from the send all buffer? Println(res)
payload := make([]byte, 4096) // wait until a fatal error
for { var fatalChan = make(chan error)
if len(bufer) < 4 { go func() {
log.Fatal("bufer small") fatalChan <- client.Wait()
} }()
dataLength := (int)(bufer[2])<<8 + (int)(bufer[3]) select {
if dataLength > len(bufer)+4 { case err := <-fatalChan:
if n, err := io.ReadFull(this.socket, payload[:dataLength-len(bufer)+4]); err != nil { Printf("Wait:%s error:%v", baseURL.String(), err)
return case <-client.Done():
} else { Printf("client:%s done", client.URL)
this.OutGoing <- append(bufer, payload[:n]...)
return
}
} else {
this.OutGoing <- bufer[:dataLength+4]
bufer = bufer[dataLength+4:]
}
} }
} }
func (this *RtspClient) Connect() bool {
d := &net.Dialer{Timeout: 3 * time.Second}
conn, err := d.Dial("tcp", this.host+":"+this.port)
if err != nil {
return false
}
this.socket = conn
return true
}
func (this *RtspClient) Write(message string) bool {
this.cseq += 1
if _, e := this.socket.Write([]byte(message)); e != nil {
return false
}
return true
}
func (this *RtspClient) Read() (bool, string) {
buffer := make([]byte, 4096)
if nb, err := this.socket.Read(buffer); err != nil || nb <= 0 {
log.Println("socket read failed", err)
return false, ""
} else {
return true, string(buffer[:nb])
}
}
func (this *RtspClient) AuthBasic(phase string, message string) bool {
this.bauth = "\r\nAuthorization: Basic " + b64.StdEncoding.EncodeToString([]byte(this.login+":"+this.password))
if !this.Write(phase + " " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + this.bauth + "\r\n\r\n") {
return false
}
if status, message := this.Read(); status && strings.Contains(message, "200") {
this.track = this.ParseMedia(message)
return true
}
return false
}
func (this *RtspClient) AuthDigest(phase string, message string) bool {
nonce := ParseDirective(message, "nonce")
realm := ParseDirective(message, "realm")
hs1 := GetMD5Hash(this.login + ":" + realm + ":" + this.password)
hs2 := GetMD5Hash(phase + ":" + this.uri)
responce := GetMD5Hash(hs1 + ":" + nonce + ":" + hs2)
dauth := "\r\n" + `Authorization: Digest username="` + this.login + `", realm="` + realm + `", nonce="` + nonce + `", uri="` + this.uri + `", response="` + responce + `"`
if !this.Write(phase + " " + this.uri + " RTSP/1.0\r\nCSeq: " + strconv.Itoa(this.cseq) + dauth + "\r\n\r\n") {
return false
}
if status, message := this.Read(); status && strings.Contains(message, "200") {
this.track = this.ParseMedia(message)
return true
}
return false
}
func (this *RtspClient) AuthDigest_Only(phase string, message string) string {
nonce := ParseDirective(message, "nonce")
realm := ParseDirective(message, "realm")
hs1 := GetMD5Hash(this.login + ":" + realm + ":" + this.password)
hs2 := GetMD5Hash(phase + ":" + this.uri)
responce := GetMD5Hash(hs1 + ":" + nonce + ":" + hs2)
dauth := "\r\n" + `Authorization: Digest username="` + this.login + `", realm="` + realm + `", nonce="` + nonce + `", uri="` + this.uri + `", response="` + responce + `"`
return dauth
}
func (this *RtspClient) ParseUrl(rtsp_url string) bool {
u, err := url.Parse(rtsp_url)
if err != nil {
return false
}
phost := strings.Split(u.Host, ":")
this.host = phost[0]
if len(phost) == 2 {
this.port = phost[1]
} else {
this.port = "554"
}
this.login = u.User.Username()
this.password, this.auth = u.User.Password()
if u.RawQuery != "" {
this.uri = "rtsp://" + this.host + ":" + this.port + u.Path + "?" + string(u.RawQuery)
} else {
this.uri = "rtsp://" + this.host + ":" + this.port + u.Path
}
return true
}
func (this *RtspClient) Close() {
if this.socket != nil {
this.socket.Close()
}
}
func ParseDirective(header, name string) string {
index := strings.Index(header, name)
if index == -1 {
return ""
}
start := 1 + index + strings.Index(header[index:], `"`)
end := start + strings.Index(header[start:], `"`)
return strings.TrimSpace(header[start:end])
}
func ParseSession(header string) string {
mparsed := strings.Split(header, "\r\n")
for _, element := range mparsed {
if strings.Contains(element, "Session:") {
if strings.Contains(element, ";") {
fist := strings.Split(element, ";")[0]
return fist[9:]
} else {
return element[9:]
}
}
}
return ""
}
// func ParseMedia(header string) []string {
// letters := []string{}
// mparsed := strings.Split(header, "\r\n")
// paste := ""
// // if true {
// // log.Println("headers", header)
// // }
// for _, element := range mparsed {
// if strings.Contains(element, "a=control:") && !strings.Contains(element, "*") {
// paste = element[10:]
// if strings.Contains(element, "/") {
// striped := strings.Split(element, "/")
// paste = striped[len(striped)-1]
// }
// letters = append(letters, paste)
// }
// dimensionsPrefix := "a=x-dimensions:"
// if strings.HasPrefix(element, dimensionsPrefix) {
// dims := []int{}
// for _, s := range strings.Split(element[len(dimensionsPrefix):], ",") {
// v := 0
// fmt.Sscanf(s, "%d", &v)
// if v <= 0 {
// break
// }
// dims = append(dims, v)
// }
// if len(dims) == 2 {
// VideoWidth = dims[0]
// VideoHeight = dims[1]
// }
// }
// if strings.Contains(element, "sprop-parameter-sets") {
// group := spropReg.FindAllStringSubmatch(element, -1)
// log.Println(group[1])
// }
// }
// return letters
// }
func GetMD5Hash(text string) string {
hash := md5.Sum([]byte(text))
return hex.EncodeToString(hash[:])
}
func (this *RtspClient) ParseMedia(header string) []string {
letters := []string{}
log.Println(header)
mparsed := strings.Split(header, "\r\n")
paste := ""
for _, element := range mparsed {
if strings.Contains(element, "a=control:") && !strings.Contains(element, "*") {
paste = element[10:]
if strings.Contains(element, "/") {
striped := strings.Split(element, "/")
paste = striped[len(striped)-1]
}
letters = append(letters, paste)
}
dimensionsPrefix := "a=x-dimensions:"
if strings.HasPrefix(element, dimensionsPrefix) {
dims := []int{}
for _, s := range strings.Split(element[len(dimensionsPrefix):], ",") {
v := 0
fmt.Sscanf(s, "%d", &v)
if v <= 0 {
break
}
dims = append(dims, v)
}
if len(dims) == 2 {
this.videow = dims[0]
this.videoh = dims[1]
}
}
group := spropReg.FindAllStringSubmatch(element, -1)
if len(group) > 0 {
group := strings.Split(group[0][1], ",")
this.SPS, _ = b64.StdEncoding.DecodeString(group[0])
this.PPS, _ = b64.StdEncoding.DecodeString(group[1])
} else if group = configReg.FindAllStringSubmatch(element, -1); len(group) > 0 {
this.AudioSpecificConfig, _ = hex.DecodeString(group[0][1])
}
}
return letters
}

11
go.mod
View File

@@ -1,8 +1,11 @@
module github.com/Monibuca/plugin-rtsp module github.com/Monibuca/plugin-rtsp/v3
go 1.13 go 1.16
require ( require (
github.com/Monibuca/engine v1.2.1 github.com/Monibuca/engine/v3 v3.4.1
github.com/Monibuca/engine/v2 v2.0.0 // indirect github.com/Monibuca/utils/v3 v3.0.5
github.com/aler9/gortsplib v0.0.0-20211212220644-6f374e396529
github.com/pion/rtp v1.7.4
github.com/pion/sdp/v3 v3.0.4
) )

110
go.sum
View File

@@ -1,47 +1,101 @@
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 v1.2.1 h1:TJmC6eZA1lR1MScWgempZLiEZD4T6aY/nn/rlQ9UdK8= github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/Monibuca/engine v1.2.1/go.mod h1:WbDkXENLjcPjyjCR1Mix1GA+uAlwORkv/+8aMVrDX2g= github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Monibuca/engine v1.2.2 h1:hNjsrZpOmui8lYhgCJ5ltJU8g/k0Rrdysx2tHNGGnbI= github.com/Monibuca/engine/v3 v3.4.1 h1:Ap2VbwTkMUkv80NPeUX2sNdV5Vz5nPVoU/6RU51PSAc=
github.com/Monibuca/engine/v2 v2.0.0 h1:8FjaScrtN8QdbcxO9zZYABMC0Re3I1O1T4p94zAXYb0= github.com/Monibuca/engine/v3 v3.4.1/go.mod h1:rgAUey5ziRhlh6WugWyA5fYKyGOvcwhtTMDk4sukE7E=
github.com/Monibuca/engine/v2 v2.0.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc= github.com/Monibuca/utils/v3 v3.0.5 h1:w14x0HkWTbF4MmHbINLlOwe4VJNoSOeaQChMk5E/4es=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= github.com/Monibuca/utils/v3 v3.0.5/go.mod h1:RpNS95gapWs6gimwh8Xn2x72FN5tO7Powabj7dTFyvE=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/aler9/gortsplib v0.0.0-20211212220644-6f374e396529 h1:j2tfs+eUubyZnuwmYWzK+IS681IixfUyD8bivz4sqAw=
github.com/aler9/gortsplib v0.0.0-20211212220644-6f374e396529/go.mod h1:fyQrQyHo8QvdR/h357tkv1g36VesZlzEPsdAu2VrHHc=
github.com/asticode/go-astikit v0.20.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astits v1.10.0/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCqjLVGvO0DygQ=
github.com/cnotch/apirouter v0.0.0-20200731232942-89e243a791f3/go.mod h1:5deJPLON/x/s2dLOQfuKS0lenhOIT4xX0pvtN/OEIuY=
github.com/cnotch/ipchub v1.1.0 h1:hH0lh2mU3AZXPiqMwA0pdtqrwo7PFIMRGush9OobMUs=
github.com/cnotch/ipchub v1.1.0/go.mod h1:2PbeBs2q2VxxTVCn1eYCDwpAWuVXbq1+N0FU7GimOH4=
github.com/cnotch/loader v0.0.0-20200405015128-d9d964d09439/go.mod h1:oWpDagHB6p+Kqqq7RoRZKyC4XAXft50hR8pbTxdbYYs=
github.com/cnotch/queue v0.0.0-20200326024423-6e88bdbf2ad4/go.mod h1:zOssjAlNusOxvtaqT+EMA+Iyi8rrtKr4/XfzN1Fgoeg=
github.com/cnotch/queue v0.0.0-20201224060551-4191569ce8f6/go.mod h1:zOssjAlNusOxvtaqT+EMA+Iyi8rrtKr4/XfzN1Fgoeg=
github.com/cnotch/scheduler v0.0.0-20200522024700-1d2da93eefc5/go.mod h1:F4GE3SZkJZ8an1Y0ZCqvSM3jeozNuKzoC67erG1PhIo=
github.com/cnotch/xlog v0.0.0-20201208005456-cfda439cd3a0/go.mod h1:RW9oHsR79ffl3sR3yMGgxYupMn2btzdtJUwoxFPUE5E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 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/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/emitter-io/address v1.0.0/go.mod h1:GfZb5+S/o8694B1GMGK2imUYQyn2skszMvGNA5D84Ug=
github.com/falconray0704/gortmp v0.0.0-20170613085150-e3f9bb02c7c8/go.mod h1:/JBZajtCDe9Z4j84v5QWo4PLn1K6jcBHh6qXN/bm/vw= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0= 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/slab v0.0.0-20180511031532-b1fad5e5d478/go.mod h1:0j1+svBH8ABEIPdUP0AIg4qedsybnXGJBakCEw8cfoo=
github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg= github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg=
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/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 h1:bqDmpDG49ZRnB5PcgP0RXtQvnMSgIF14M7CBd2shtXs= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/icza/bitio v1.0.0 h1:squ/m1SHyFeCA6+6Gyol1AxV9nmPPlJFT8c2vKdj3U8=
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= github.com/icza/bitio v1.0.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
github.com/kelindar/process v0.0.0-20170730150328-69a29e249ec3/go.mod h1:+lTCLnZFXOkqwD8sLPl6u4erAc0cP8wFegQHfipz7KE=
github.com/kelindar/rate v1.0.0/go.mod h1:AjT4G+hTItNwt30lucEGZIz8y7Uk5zPho6vurIZ+1Es=
github.com/kelindar/tcp v1.0.0/go.mod h1:JB5hj1cshLU60XrLij2BBxW3JQ4hOye8vqbyvuKb52k=
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/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
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/pixelbender/go-sdp v1.0.0 h1:hLP2ALBN4sLpgp2r3EDcFUSN3AyOkg1jonuWEJniotY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/pixelbender/go-sdp v1.0.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.4 h1:NT3H5LkUGgaEapvp0HGik+a+CpflRF7KTD7H+o7OWIM=
github.com/pion/rtcp v1.2.4/go.mod h1:52rMNPWFsjr39z9B9MhnkqhPLoeHTv1aN63o/42bWE0=
github.com/pion/rtp v1.6.1/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pion/rtp v1.7.4 h1:4dMbjb1SuynU5OpA3kz1zHK+u+eOCQjW3MAeVHf1ODA=
github.com/pion/rtp v1.7.4/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pion/sdp/v3 v3.0.2/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk=
github.com/pion/sdp/v3 v3.0.4 h1:2Kf+dgrzJflNCSw3TV5v2VLeI0s/qkzy2r5jlR0wzf8=
github.com/pion/sdp/v3 v3.0.4/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk=
github.com/pixelbender/go-sdp v1.1.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 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/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=
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/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY=
github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0=
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A=
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.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
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/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8/go.mod h1:RZd/IqzNpFANwOB9rVmsnAYpo/6KesK4PqrN1a5cRgg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
github.com/zhangpeihao/log v0.0.0-20170117094621-62e921e41859/go.mod h1:OAvmouyIV28taMw4SC4+hSnouObQqQkTQNOhU3Zowl0= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A=
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 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= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

263
main.go
View File

@@ -1,220 +1,113 @@
package rtspplugin package rtsp
import ( import (
"bytes" "encoding/json"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"strings"
"sync"
"time" "time"
. "github.com/Monibuca/engine/v2" . "github.com/Monibuca/engine/v3"
. "github.com/Monibuca/engine/v2/avformat" . "github.com/Monibuca/utils/v3"
"github.com/Monibuca/engine/v2/util" "github.com/aler9/gortsplib"
) )
var collection = sync.Map{}
var config = struct { var config = struct {
BufferLength int ListenAddr string
AutoPull bool UDPAddr string
RemoteAddr string RTCPAddr string
}{2048, true, "rtsp://localhost/${streamPath}"} Timeout int
Reconnect bool
AutoPullList map[string]string
AutoPushList map[string]string
ReadBufferSize int
}{":554", ":8000", ":8001", 0, false, nil, nil, 2048}
var pconfig = PluginConfig{
Name: "RTSP",
Config: &config,
}
func init() { func init() {
InstallPlugin(&PluginConfig{ pconfig.Install(runPlugin)
Name: "RTSP", }
Type: PLUGIN_PUBLISHER | PLUGIN_HOOK,
Config: &config, func getRtspList() (info []*Stream) {
Run: runPlugin, for _, s := range Streams.ToList() {
HotConfig: map[string]func(interface{}){ switch s.ExtraProp.(type) {
"AutoPull": func(value interface{}) { case *RTSPublisher:
config.AutoPull = value.(bool) info = append(info, s)
}, case *RTSPClient:
}, info = append(info, s)
}) }
}
return
} }
func runPlugin() { func runPlugin() {
OnSubscribeHooks.AddHook(func(s *Subscriber) { http.HandleFunc("/api/rtsp/list", func(w http.ResponseWriter, r *http.Request) {
if config.AutoPull && s.Publisher == nil { CORS(w, r)
new(RTSP).Publish(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1)) if r.URL.Query().Get("json") != "" {
if jsonData, err := json.Marshal(getRtspList()); err == nil {
w.Write(jsonData)
} else {
w.WriteHeader(500)
}
return
} }
}) sse := NewSSE(w, r.Context())
http.HandleFunc("/rtsp/list", func(w http.ResponseWriter, r *http.Request) {
sse := util.NewSSE(w, r.Context())
var err error var err error
for tick := time.NewTicker(time.Second); err == nil; <-tick.C { for tick := time.NewTicker(time.Second); err == nil; <-tick.C {
var info []*RTSPInfo err = sse.WriteJSON(getRtspList())
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
})
err = sse.WriteJSON(info)
} }
}) })
http.HandleFunc("/rtsp/pull", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/rtsp/pull", func(w http.ResponseWriter, r *http.Request) {
CORS(w, r)
targetURL := r.URL.Query().Get("target") targetURL := r.URL.Query().Get("target")
streamPath := r.URL.Query().Get("streamPath") streamPath := r.URL.Query().Get("streamPath")
var err error save := r.URL.Query().Get("save")
if err == nil { if err := (&RTSPClient{Transport: gortsplib.TransportTCP}).PullStream(streamPath, targetURL); err == nil {
new(RTSP).Publish(streamPath, targetURL) if save == "1" {
if config.AutoPullList == nil {
config.AutoPullList = make(map[string]string)
}
config.AutoPullList[streamPath] = targetURL
if err := pconfig.Save(); err != nil {
Println(err)
}
}
w.Write([]byte(`{"code":0}`)) w.Write([]byte(`{"code":0}`))
} else { } else {
w.Write([]byte(fmt.Sprintf(`{"code":1,"msg":"%s"}`, err.Error()))) w.Write([]byte(fmt.Sprintf(`{"code":1,"msg":"%s"}`, err.Error())))
} }
}) })
} for streamPath, url := range config.AutoPullList {
if err := (&RTSPClient{Transport: gortsplib.TransportTCP}).PullStream(streamPath, url); err != nil {
type RTSP struct { Println(err)
Publisher
*RtspClient
RTSPInfo
}
type RTSPInfo struct {
SyncCount int64
Header *string
BufferRate 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 go AddHook(HOOK_PUBLISH, func(s *Stream) {
ts := (int64(data[8]) << 24) + (int64(data[9]) << 16) + (int64(data[10]) << 8) + (int64(data[11])) for streamPath, url := range config.AutoPushList {
if s.StreamPath == streamPath {
//packet number (&RTSPClient{}).PushStream(streamPath, url)
//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
}
}
} }
} }
})
if config.ListenAddr != "" {
go log.Fatal(ListenRtsp(config.ListenAddr))
} }
} }
func (rtsp *RTSP) Publish(streamPath string, rtspUrl string) (result bool) {
if result = rtsp.Publisher.Publish(streamPath); result { func ListenRtsp(addr string) error {
rtsp.Type = "RTSP" defer log.Println("rtsp server start!")
rtsp.RTSPInfo.StreamInfo = &rtsp.Stream.StreamInfo s := &gortsplib.Server{
rtsp.RtspClient = RtspClientNew(config.BufferLength) Handler: &RTSPServer{},
rtsp.RTSPInfo.Header = &rtsp.RtspClient.Header RTSPAddress: addr,
if status, message := rtsp.RtspClient.Client(rtspUrl); !status { UDPRTPAddress: config.UDPAddr,
log.Println(message) UDPRTCPAddress: config.RTCPAddr,
return false MulticastIPRange: "224.1.0.0/16",
} MulticastRTPPort: 8002,
collection.Store(streamPath, rtsp) MulticastRTCPPort: 8003,
go rtsp.run()
} }
return return s.StartAndWait()
} }

24
payloader.go Normal file
View File

@@ -0,0 +1,24 @@
package rtsp
// AACayloader payloads AAC packets
type AACPayloader struct{}
// Payload fragments an AAC packet across one or more byte arrays
func (p *AACPayloader) Payload(mtu uint16, payload []byte) [][]byte {
var out [][]byte
o := make([]byte, len(payload)+4)
//AU_HEADER_LENGTH,因为单位是bit, 除以8就是auHeader的字节长度又因为单个auheader字节长度2字节所以再除以2就是auheader的个数。
o[0] = 0x00 //高位
o[1] = 0x10 //低位
//AU_HEADER
o[2] = (byte)((len(payload) & 0x1fe0) >> 5) //高位
o[3] = (byte)((len(payload) & 0x1f) << 3) //低位
copy(o[4:], payload)
return append(out, o)
}
type H265Payloader struct{}
func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte {
return nil
}

121
publisher.go Normal file
View File

@@ -0,0 +1,121 @@
package rtsp
import (
"encoding/base64"
"encoding/hex"
"strconv"
"strings"
. "github.com/Monibuca/engine/v3"
. "github.com/Monibuca/utils/v3"
"github.com/aler9/gortsplib"
)
type RTSPublisher struct {
*Stream `json:"-"`
stream *gortsplib.ServerStream
processFunc []func([]byte)
}
func (p *RTSPublisher) setTracks(tracks gortsplib.Tracks) {
if p.processFunc != nil {
p.processFunc = p.processFunc[:len(tracks)]
return
} else {
p.processFunc = make([]func([]byte), len(tracks))
}
for i, track := range tracks {
v, ok := track.Media.Attribute("rtpmap")
if !ok {
continue
}
fmtp := make(map[string]string)
if v, ok := track.Media.Attribute("fmtp"); ok {
if tmp := strings.SplitN(v, " ", 2); len(tmp) == 2 {
for _, kv := range strings.Split(tmp[1], ";") {
kv = strings.Trim(kv, " ")
if len(kv) == 0 {
continue
}
tmp := strings.SplitN(kv, "=", 2)
if len(tmp) == 2 {
fmtp[strings.TrimSpace(tmp[0])] = tmp[1]
}
}
}
}
v = strings.TrimSpace(v)
vals := strings.Split(v, " ")
if len(vals) != 2 {
continue
}
timeScale := 0
keyval := strings.Split(vals[1], "/")
if i, err := strconv.Atoi(keyval[1]); err == nil {
timeScale = i
}
if len(keyval) >= 2 {
Printf("track %d is %s", i, keyval[0])
switch strings.ToLower(keyval[0]) {
case "h264":
vt := p.NewRTPVideo(7)
if conf, err := track.ExtractConfigH264(); err == nil {
vt.PushNalu(0, 0, conf.SPS, conf.PPS)
}
p.processFunc[i] = vt.Push
case "h265", "hevc":
vt := p.NewRTPVideo(12)
if v, ok := fmtp["sprop-vps"]; ok {
vps, _ := base64.StdEncoding.DecodeString(v)
vt.PushNalu(0, 0, vps)
}
if v, ok := fmtp["sprop-sps"]; ok {
sps, _ := base64.StdEncoding.DecodeString(v)
vt.PushNalu(0, 0, sps)
}
if v, ok := fmtp["sprop-pps"]; ok {
pps, _ := base64.StdEncoding.DecodeString(v)
vt.PushNalu(0, 0, pps)
}
p.processFunc[i] = vt.Push
case "pcma":
at := p.NewRTPAudio(7)
at.SoundRate = timeScale
at.SoundSize = 16
if len(keyval) >= 3 {
x, _ := strconv.Atoi(keyval[2])
at.Channels = byte(x)
} else {
at.Channels = 1
}
at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)}
p.processFunc[i] = at.Push
case "pcmu":
at := p.NewRTPAudio(8)
at.SoundRate = timeScale
at.SoundSize = 16
if len(keyval) >= 3 {
x, _ := strconv.Atoi(keyval[2])
at.Channels = byte(x)
} else {
at.Channels = 1
}
at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)}
p.processFunc[i] = at.Push
case "mpeg4-generic":
at := p.NewRTPAudio(0)
if config, ok := fmtp["config"]; ok {
asc, _ := hex.DecodeString(config)
at.SetASC(asc)
} else {
Println("aac no config")
}
at.SoundSize = 16
p.processFunc[i] = at.Push
}
}
}
}

264
server.go Normal file
View File

@@ -0,0 +1,264 @@
package rtsp
import (
"fmt"
"sync"
"unsafe"
"github.com/Monibuca/engine/v3"
. "github.com/Monibuca/utils/v3"
"github.com/Monibuca/utils/v3/codec"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/aac"
"github.com/aler9/gortsplib/pkg/base"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
)
// 接收RTSP推流OnConnOpen->OnAnnounce->OnSetup->OnSessionOpen
// 接收RTSP拉流OnConnOpen->OnDescribe->OnSetup->OnSessionOpen
type RTSPServer struct {
sync.Map
}
type RTSPSubscriber struct {
stream *gortsplib.ServerStream
engine.Subscriber
vt *engine.VideoTrack
at *engine.AudioTrack
}
// called after a connection is opened.
func (sh *RTSPServer) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx) {
Printf("rtsp conn opened")
}
// called after a connection is closed.
func (sh *RTSPServer) OnConnClose(ctx *gortsplib.ServerHandlerOnConnCloseCtx) {
Printf("rtsp conn closed (%v)", ctx.Error)
if p, ok := sh.Load(ctx.Conn); ok {
switch v := p.(type) {
case *RTSPublisher:
v.Close()
case *RTSPSubscriber:
v.Close()
}
sh.Delete(ctx.Conn)
}
}
// called after a session is opened.
func (sh *RTSPServer) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx) {
Printf("rtsp session opened")
}
// called after a session is closed.
func (sh *RTSPServer) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) {
Printf("rtsp session closed")
if v, ok := sh.LoadAndDelete(ctx.Session); ok {
switch v := v.(type) {
case *RTSPublisher:
v.Close()
case *RTSPSubscriber:
v.Close()
}
}
}
// called after receiving a DESCRIBE request.
func (sh *RTSPServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
Printf("describe request")
var err error
if s := engine.FindStream(ctx.Path); s != nil {
var tracks gortsplib.Tracks
var stream *gortsplib.ServerStream
var sub RTSPSubscriber
sub.Type = "RTSP pull"
sub.vt = s.WaitVideoTrack("h264", "h265")
sub.at = s.WaitAudioTrack("aac", "pcma", "pcmu")
ssrc := uintptr(unsafe.Pointer(&stream))
var trackIds = 0
if sub.vt != nil {
trackId := trackIds
var vtrack *gortsplib.Track
var vpacketer rtp.Packetizer
switch sub.vt.CodecID {
case codec.CodecID_H264:
if vtrack, err = gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{
SPS: sub.vt.ExtraData.NALUs[0],
PPS: sub.vt.ExtraData.NALUs[1],
}); err == nil {
vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &codecs.H264Payloader{}, rtp.NewFixedSequencer(1), 90000)
} else {
return nil, nil, err
}
case codec.CodecID_H265:
vtrack = NewH265Track(96, sub.vt.ExtraData.NALUs)
vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &H265Payloader{}, rtp.NewFixedSequencer(1), 90000)
}
var st uint32
onVideo := func(ts uint32, pack *engine.VideoPack) {
for i, nalu := range pack.NALUs {
var samples uint32
if i == len(pack.NALUs)-1 {
samples = (ts - st) * 90
} else {
samples = 0
}
packs := vpacketer.Packetize(nalu, samples)
for j, rtpack := range packs {
rtpack.Marker = i == len(pack.NALUs)-1 && j == len(packs)-1
rtp, _ := rtpack.Marshal()
stream.WritePacketRTP(trackId, rtp)
}
}
st = ts
}
sub.OnVideo = func(ts uint32, pack *engine.VideoPack) {
if st = ts; st != 0 {
sub.OnVideo = onVideo
}
onVideo(ts, pack)
}
tracks = append(tracks, vtrack)
trackIds++
}
if sub.at != nil {
var st uint32
trackId := trackIds
switch sub.at.CodecID {
case codec.CodecID_PCMA, codec.CodecID_PCMU:
atrack := NewG711Track(97, map[byte]string{7: "pcma", 8: "pcmu"}[sub.at.CodecID])
apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &codecs.G711Payloader{}, rtp.NewFixedSequencer(1), 8000)
sub.OnAudio = func(ts uint32, pack *engine.AudioPack) {
for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*8) {
buf, _ := pack.Marshal()
stream.WritePacketRTP(trackId, buf)
}
st = ts
}
tracks = append(tracks, atrack)
case codec.CodecID_AAC:
var mpegConf aac.MPEG4AudioConfig
mpegConf.Decode(sub.at.ExtraData[2:])
conf := &gortsplib.TrackConfigAAC{
Type: int(mpegConf.Type),
SampleRate: mpegConf.SampleRate,
ChannelCount: mpegConf.ChannelCount,
AOTSpecificConfig: mpegConf.AOTSpecificConfig,
}
if atrack, err := gortsplib.NewTrackAAC(97, conf); err == nil {
apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &AACPayloader{}, rtp.NewFixedSequencer(1), uint32(mpegConf.SampleRate))
sub.OnAudio = func(ts uint32, pack *engine.AudioPack) {
for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*uint32(mpegConf.SampleRate)/1000) {
buf, _ := pack.Marshal()
stream.WritePacketRTP(trackId, buf)
}
st = ts
}
tracks = append(tracks, atrack)
}
}
}
stream = gortsplib.NewServerStream(tracks)
sub.stream = stream
sh.Store(ctx.Conn, &sub)
return &base.Response{
StatusCode: base.StatusOK,
}, stream, nil
// if stream, ok := s.ExtraProp.(*gortsplib.ServerStream); ok {
// return &base.Response{
// StatusCode: base.StatusOK,
// }, stream, nil
// }
}
return &base.Response{
StatusCode: base.StatusNotFound,
}, nil, nil
}
// called after receiving an ANNOUNCE request.
func (sh *RTSPServer) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) {
Printf("announce request")
p := &RTSPublisher{
Stream: &engine.Stream{
StreamPath: ctx.Path,
Type: "RTSP push",
},
}
p.ExtraProp = p
p.URL = ctx.Req.URL.String()
if p.Publish() {
p.setTracks(ctx.Tracks)
p.stream = gortsplib.NewServerStream(ctx.Tracks)
sh.Store(ctx.Conn, p)
sh.Store(ctx.Session, p)
} else {
return &base.Response{
StatusCode: base.StatusBadRequest,
}, fmt.Errorf("streamPath is already exist")
}
return &base.Response{
StatusCode: base.StatusOK,
}, nil
}
// called after receiving a SETUP request.
func (sh *RTSPServer) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
Printf("setup request")
if p, ok := sh.Load(ctx.Conn); ok {
switch v := p.(type) {
case *RTSPublisher:
return &base.Response{
StatusCode: base.StatusOK,
}, v.stream, nil
case *RTSPSubscriber:
return &base.Response{
StatusCode: base.StatusOK,
}, v.stream, nil
}
}
return &base.Response{
StatusCode: base.StatusNotFound,
}, nil, nil
}
// called after receiving a PLAY request.
func (sh *RTSPServer) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
Printf("play request")
if p, ok := sh.Load(ctx.Conn); ok {
if sub := p.(*RTSPSubscriber); sub.Subscribe(ctx.Path) == nil {
go func() {
sub.Play(sub.at, sub.vt)
ctx.Conn.Close()
}()
return &base.Response{
StatusCode: base.StatusOK,
}, nil
}
}
return &base.Response{
StatusCode: base.StatusNotFound,
}, nil
}
// called after receiving a RECORD request.
func (sh *RTSPServer) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.Response, error) {
Printf("record request")
return &base.Response{
StatusCode: base.StatusOK,
}, nil
}
// called after receiving a frame.
func (sh *RTSPServer) OnPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) {
if p, ok := sh.Load(ctx.Session); ok {
rtsp := p.(*RTSPublisher)
if rtsp.Err() != nil {
ctx.Session.Close()
return
}
if f := rtsp.processFunc[ctx.TrackID]; f != nil {
f(ctx.Payload)
}
}
}

87
track.go Normal file
View File

@@ -0,0 +1,87 @@
package rtsp
import (
"encoding/base64"
"fmt"
"strconv"
"github.com/aler9/gortsplib"
psdp "github.com/pion/sdp/v3"
)
// func NewTrackAAC(payloadType uint8, conf *gortsplib.TrackConfigAAC) (*gortsplib.Track, error) {
// mpegConf, err := aac.MPEG4AudioConfig{
// Type: aac.MPEG4AudioType(conf.Type),
// SampleRate: conf.SampleRate,
// ChannelCount: conf.ChannelCount,
// AOTSpecificConfig: conf.AOTSpecificConfig,
// }.Encode()
// if err != nil {
// return nil, err
// }
// typ := strconv.FormatInt(int64(payloadType), 10)
// return &gortsplib.Track{
// Media: &psdp.MediaDescription{
// MediaName: psdp.MediaName{
// Media: "audio",
// Protos: []string{"RTP", "AVP"},
// Formats: []string{typ},
// },
// Attributes: []psdp.Attribute{
// {
// Key: "rtpmap",
// Value: typ + " mpeg4-generic/" + strconv.FormatInt(int64(conf.SampleRate), 10) +
// "/" + strconv.FormatInt(int64(conf.ChannelCount), 10),
// },
// {
// Key: "fmtp",
// Value: typ + " profile-level-id=1; " +
// "mode=AAC-hbr; " +
// "sizelength=6; " +
// "indexlength=2; " +
// "indexdeltalength=2; " +
// "config=" + hex.EncodeToString(mpegConf),
// },
// },
// },
// }, nil
// }
func NewG711Track(payloadType uint8, law string) *gortsplib.Track {
return &gortsplib.Track{
Media: &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{strconv.FormatInt(int64(payloadType), 10)}},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: fmt.Sprintf("%d %s/8000/1", payloadType, law),
},
},
},
}
}
func NewH265Track(payloadType uint8, sprop [][]byte) *gortsplib.Track {
return &gortsplib.Track{
Media: &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "video",
Protos: []string{"RTP", "AVP"},
Formats: []string{fmt.Sprintf("%d", payloadType)},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: fmt.Sprintf("%d H265/90000", payloadType),
},
{
Key: "fmtp",
Value: fmt.Sprintf("%d packetization-mode=1;sprop-vps=%s;sprop-sps=%s;sprop-pps=%s;", payloadType, base64.StdEncoding.EncodeToString(sprop[0]), base64.StdEncoding.EncodeToString(sprop[1]), base64.StdEncoding.EncodeToString(sprop[2])),
},
},
},
}
}

19
ui/dist/demo.html vendored
View File

@@ -1,19 +0,0 @@
<meta charset="utf-8">
<title>plugin-rtsp demo</title>
<script src="https://unpkg.com/vue"></script>
<script src="./plugin-rtsp.umd.js"></script>
<link rel="stylesheet" href="./plugin-rtsp.css">
<div id="app">
<demo></demo>
</div>
<script>
new Vue({
components: {
demo: plugin-rtsp
}
}).$mount('#app')
</script>

View File

@@ -1,408 +0,0 @@
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "fb15");
/******/ })
/************************************************************************/
/******/ ({
/***/ "034f":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("85ec");
/* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__);
/* unused harmony reexport * */
/* unused harmony default export */ var _unused_webpack_default_export = (_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default.a);
/***/ }),
/***/ "85ec":
/***/ (function(module, exports, __webpack_require__) {
// extracted by mini-css-extract-plugin
/***/ }),
/***/ "f6fd":
/***/ (function(module, exports) {
// document.currentScript polyfill by Adam Miller
// MIT license
(function(document){
var currentScript = "currentScript",
scripts = document.getElementsByTagName('script'); // Live NodeList collection
// If browser needs currentScript polyfill, add get currentScript() to the document object
if (!(currentScript in document)) {
Object.defineProperty(document, currentScript, {
get: function(){
// IE 6-10 supports script readyState
// IE 10+ support stack trace
try { throw new Error(); }
catch (err) {
// Find the second match for the "at" string to get file src url from stack.
// Specifically works with the format of stack traces in IE.
var i, res = ((/.*at [^\(]*\((.*):.+:.+\)$/ig).exec(err.stack) || [false])[1];
// For all scripts on the page, if src matches or if ready state is interactive, return the script tag
for(i in scripts){
if(scripts[i].src == res || scripts[i].readyState == "interactive"){
return scripts[i];
}
}
// If no match, return null
return null;
}
}
});
}
})(document);
/***/ }),
/***/ "fb15":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js
// This file is imported into lib/wc client bundles.
if (typeof window !== 'undefined') {
if (true) {
__webpack_require__("f6fd")
}
var i
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) {
__webpack_require__.p = i[1] // eslint-disable-line
}
}
// 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&
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)}
var staticRenderFns = []
// CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=0225c7f1&
// 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&
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
let listES = null;
/* harmony default export */ var Appvue_type_script_lang_js_ = ({
components: {
StartTime
},
data() {
return {
currentStream: null,
Streams: null,
remoteAddr: "",
streamPath: "",
openPull: false,
columns:["StreamPath","开始时间","缓冲","同步数","操作" ].map(title=>({title}))
};
},
methods: {
fetchlist() {
listES = new EventSource(this.apiHost + "/rtsp/list");
listES.onmessage = evt => {
if (!evt.data) return;
this.Streams = JSON.parse(evt.data) || [];
this.Streams.sort((a, b) =>
a.StreamInfo.StreamPath > b.StreamInfo.StreamPath ? 1 : -1
);
};
},
showHeader(item) {
this.$Modal.info({
title: "RTSP Header",
width: "1000px",
scrollable: true,
content: item.Header
});
},
addPull() {
this.openPull = false;
this.ajax
.getJSON(this.apiHost + "/rtsp/pull", {
target: this.remoteAddr,
streamPath: this.streamPath
})
.then(x => {
if (x.code == 0) {
this.$toast.success("已启动拉流");
} else {
this.$toast.error(x.msg);
}
});
}
},
mounted() {
this.fetchlist();
let _this = this;
this.$parent.titleOps = [
{
template:'<m-button @click="onClick">拉流转发</m-button>',
methods:{
onClick(){
_this.openPull = true;
}
}
}
]
},
destroyed() {
listES.close();
}
});
// CONCATENATED MODULE: ./src/App.vue?vue&type=script&lang=js&
/* harmony default export */ var src_Appvue_type_script_lang_js_ = (Appvue_type_script_lang_js_);
// EXTERNAL MODULE: ./src/App.vue?vue&type=style&index=0&lang=css&
var Appvue_type_style_index_0_lang_css_ = __webpack_require__("034f");
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
function normalizeComponent (
scriptExports,
render,
staticRenderFns,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier, /* server only */
shadowMode /* vue-cli only */
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (render) {
options.render = render
options.staticRenderFns = staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 'data-v-' + scopeId
}
var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = shadowMode
? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
: injectStyles
}
if (hook) {
if (options.functional) {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functional component in vue file
var originalRender = options.render
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return originalRender(h, context)
}
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
}
}
return {
exports: scriptExports,
options: options
}
}
// CONCATENATED MODULE: ./src/App.vue
/* normalize component */
var component = normalizeComponent(
src_Appvue_type_script_lang_js_,
render,
staticRenderFns,
false,
null,
null,
null
)
/* harmony default export */ var App = (component.exports);
// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js
/* harmony default export */ var entry_lib = __webpack_exports__["default"] = (App);
/***/ })
/******/ })["default"];
//# sourceMappingURL=plugin-rtsp.common.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
.empty{color:#eb5e46;width:100%;min-height:500px;display:flex;justify-content:center;align-items:center}.layout{padding-bottom:30px;display:flex;flex-wrap:wrap}.ts-info{width:300px}.hls-info{width:350px;display:flex;flex-direction:column}

View File

@@ -1,418 +0,0 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["plugin-rtsp"] = factory();
else
root["plugin-rtsp"] = factory();
})((typeof self !== 'undefined' ? self : this), function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "fb15");
/******/ })
/************************************************************************/
/******/ ({
/***/ "034f":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("85ec");
/* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__);
/* unused harmony reexport * */
/* unused harmony default export */ var _unused_webpack_default_export = (_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default.a);
/***/ }),
/***/ "85ec":
/***/ (function(module, exports, __webpack_require__) {
// extracted by mini-css-extract-plugin
/***/ }),
/***/ "f6fd":
/***/ (function(module, exports) {
// document.currentScript polyfill by Adam Miller
// MIT license
(function(document){
var currentScript = "currentScript",
scripts = document.getElementsByTagName('script'); // Live NodeList collection
// If browser needs currentScript polyfill, add get currentScript() to the document object
if (!(currentScript in document)) {
Object.defineProperty(document, currentScript, {
get: function(){
// IE 6-10 supports script readyState
// IE 10+ support stack trace
try { throw new Error(); }
catch (err) {
// Find the second match for the "at" string to get file src url from stack.
// Specifically works with the format of stack traces in IE.
var i, res = ((/.*at [^\(]*\((.*):.+:.+\)$/ig).exec(err.stack) || [false])[1];
// For all scripts on the page, if src matches or if ready state is interactive, return the script tag
for(i in scripts){
if(scripts[i].src == res || scripts[i].readyState == "interactive"){
return scripts[i];
}
}
// If no match, return null
return null;
}
}
});
}
})(document);
/***/ }),
/***/ "fb15":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js
// This file is imported into lib/wc client bundles.
if (typeof window !== 'undefined') {
if (true) {
__webpack_require__("f6fd")
}
var i
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) {
__webpack_require__.p = i[1] // eslint-disable-line
}
}
// 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&
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)}
var staticRenderFns = []
// CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=0225c7f1&
// 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&
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
let listES = null;
/* harmony default export */ var Appvue_type_script_lang_js_ = ({
components: {
StartTime
},
data() {
return {
currentStream: null,
Streams: null,
remoteAddr: "",
streamPath: "",
openPull: false,
columns:["StreamPath","开始时间","缓冲","同步数","操作" ].map(title=>({title}))
};
},
methods: {
fetchlist() {
listES = new EventSource(this.apiHost + "/rtsp/list");
listES.onmessage = evt => {
if (!evt.data) return;
this.Streams = JSON.parse(evt.data) || [];
this.Streams.sort((a, b) =>
a.StreamInfo.StreamPath > b.StreamInfo.StreamPath ? 1 : -1
);
};
},
showHeader(item) {
this.$Modal.info({
title: "RTSP Header",
width: "1000px",
scrollable: true,
content: item.Header
});
},
addPull() {
this.openPull = false;
this.ajax
.getJSON(this.apiHost + "/rtsp/pull", {
target: this.remoteAddr,
streamPath: this.streamPath
})
.then(x => {
if (x.code == 0) {
this.$toast.success("已启动拉流");
} else {
this.$toast.error(x.msg);
}
});
}
},
mounted() {
this.fetchlist();
let _this = this;
this.$parent.titleOps = [
{
template:'<m-button @click="onClick">拉流转发</m-button>',
methods:{
onClick(){
_this.openPull = true;
}
}
}
]
},
destroyed() {
listES.close();
}
});
// CONCATENATED MODULE: ./src/App.vue?vue&type=script&lang=js&
/* harmony default export */ var src_Appvue_type_script_lang_js_ = (Appvue_type_script_lang_js_);
// EXTERNAL MODULE: ./src/App.vue?vue&type=style&index=0&lang=css&
var Appvue_type_style_index_0_lang_css_ = __webpack_require__("034f");
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
function normalizeComponent (
scriptExports,
render,
staticRenderFns,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier, /* server only */
shadowMode /* vue-cli only */
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (render) {
options.render = render
options.staticRenderFns = staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 'data-v-' + scopeId
}
var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = shadowMode
? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
: injectStyles
}
if (hook) {
if (options.functional) {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functional component in vue file
var originalRender = options.render
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return originalRender(h, context)
}
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
}
}
return {
exports: scriptExports,
options: options
}
}
// CONCATENATED MODULE: ./src/App.vue
/* normalize component */
var component = normalizeComponent(
src_Appvue_type_script_lang_js_,
render,
staticRenderFns,
false,
null,
null,
null
)
/* harmony default export */ var App = (component.exports);
// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js
/* harmony default export */ var entry_lib = __webpack_exports__["default"] = (App);
/***/ })
/******/ })["default"];
});
//# sourceMappingURL=plugin-rtsp.umd.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,2 +0,0 @@
(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"]}));
//# sourceMappingURL=plugin-rtsp.umd.min.js.map

File diff suppressed because one or more lines are too long

9560
ui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +0,0 @@
{
"name": "dashboard",
"version": "1.0.0",
"description": "dashboard of rtsp plugin for monibuca",
"main": "index.js",
"scripts": {
"build": "vue-cli-service build --target lib --name plugin-rtsp"
},
"author": "dexter",
"license": "ISC",
"devDependencies": {
"@vue/cli-service": "^4.2.3",
"vue-template-compiler": "^2.6.11"
}
}

View File

@@ -1,118 +0,0 @@
<template>
<div>
<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>
</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-button slot="actions" flat color="primary" @click="addPull">确定</mu-button>
</mu-dialog>
</div>
</template>
<script>
let listES = null;
export default {
components: {
StartTime
},
data() {
return {
currentStream: null,
Streams: null,
remoteAddr: "",
streamPath: "",
openPull: false,
columns:["StreamPath","开始时间","缓冲","同步数","操作" ].map(title=>({title}))
};
},
methods: {
fetchlist() {
listES = new EventSource(this.apiHost + "/rtsp/list");
listES.onmessage = evt => {
if (!evt.data) return;
this.Streams = JSON.parse(evt.data) || [];
this.Streams.sort((a, b) =>
a.StreamInfo.StreamPath > b.StreamInfo.StreamPath ? 1 : -1
);
};
},
showHeader(item) {
this.$Modal.info({
title: "RTSP Header",
width: "1000px",
scrollable: true,
content: item.Header
});
},
addPull() {
this.openPull = false;
this.ajax
.getJSON(this.apiHost + "/rtsp/pull", {
target: this.remoteAddr,
streamPath: this.streamPath
})
.then(x => {
if (x.code == 0) {
this.$toast.success("已启动拉流");
} else {
this.$toast.error(x.msg);
}
});
}
},
mounted() {
this.fetchlist();
let _this = this;
this.$parent.titleOps = [
{
template:'<m-button @click="onClick">拉流转发</m-button>',
methods:{
onClick(){
_this.openPull = true;
}
}
}
]
},
destroyed() {
listES.close();
}
};
</script>
<style>
.empty {
color: #eb5e46;
width: 100%;
min-height: 500px;
display: flex;
justify-content: center;
align-items: center;
}
.layout {
padding-bottom: 30px;
display: flex;
flex-wrap: wrap;
}
.ts-info {
width: 300px;
}
.hls-info {
width: 350px;
display: flex;
flex-direction: column;
}
</style>