mirror of
https://github.com/Monibuca/plugin-gb28181.git
synced 2025-12-24 13:27:57 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2cc62ff9e | ||
|
|
2e8aa47bc5 | ||
|
|
585d5949d3 | ||
|
|
0285236cce | ||
|
|
12895fa2cc | ||
|
|
c66303e7e8 |
@@ -133,8 +133,8 @@ http 200 表示成功,404流不存在
|
||||
| --------- | ---- | -------------------------------------------- |
|
||||
| id | 是 | 设备ID |
|
||||
| channel | 是 | 通道编号 |
|
||||
| startTime | 否 | 开始时间(字符串,格式:2021-7-23T12:00:00) |
|
||||
| endTime | 否 | 结束时间(字符串格式同上) |
|
||||
| startTime | 否 | 开始时间(Unix时间戳) |
|
||||
| endTime | 否 | 结束时间(Unix时间戳) |
|
||||
|
||||
### 移动位置订阅
|
||||
|
||||
|
||||
42
channel.go
42
channel.go
@@ -209,16 +209,19 @@ func (channel *Channel) QueryRecord(startTime, endTime string) ([]*Record, error
|
||||
request := d.CreateRequest(sip.MESSAGE)
|
||||
contentType := sip.ContentType("Application/MANSCDP+xml")
|
||||
request.AppendHeader(&contentType)
|
||||
body := fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>RecordInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<StartTime>%s</StartTime>
|
||||
<EndTime>%s</EndTime>
|
||||
<Secrecy>0</Secrecy>
|
||||
<Type>all</Type>
|
||||
</Query>`, d.sn, channel.DeviceID, startTime, endTime)
|
||||
// body := fmt.Sprintf(`<?xml version="1.0"?>
|
||||
// <Query>
|
||||
// <CmdType>RecordInfo</CmdType>
|
||||
// <SN>%d</SN>
|
||||
// <DeviceID>%s</DeviceID>
|
||||
// <StartTime>%s</StartTime>
|
||||
// <EndTime>%s</EndTime>
|
||||
// <Secrecy>0</Secrecy>
|
||||
// <Type>all</Type>
|
||||
// </Query>`, d.sn, channel.DeviceID, startTime, endTime)
|
||||
start, _ := strconv.ParseInt(startTime, 10, 0)
|
||||
end, _ := strconv.ParseInt(endTime, 10, 0)
|
||||
body := BuildRecordInfoXML(d.sn, channel.DeviceID, start, end)
|
||||
request.SetBody(body, true)
|
||||
|
||||
resultCh := RecordQueryLink.WaitResult(d.ID, channel.DeviceID, d.sn, QUERY_RECORD_TIMEOUT)
|
||||
@@ -340,20 +343,20 @@ func (channel *Channel) Invite(opt *InviteOptions) (code int, err error) {
|
||||
}
|
||||
protocol := ""
|
||||
networkType := "udp"
|
||||
resuePort := true
|
||||
reusePort := true
|
||||
if conf.IsMediaNetworkTCP() {
|
||||
networkType = "tcp"
|
||||
protocol = "TCP/"
|
||||
if conf.tcpPorts.Valid {
|
||||
opt.MediaPort, err = conf.tcpPorts.GetPort()
|
||||
opt.recyclePort = conf.tcpPorts.Recycle
|
||||
resuePort = false
|
||||
reusePort = false
|
||||
}
|
||||
} else {
|
||||
if conf.udpPorts.Valid {
|
||||
opt.MediaPort, err = conf.udpPorts.GetPort()
|
||||
opt.recyclePort = conf.udpPorts.Recycle
|
||||
resuePort = false
|
||||
reusePort = false
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@@ -406,11 +409,20 @@ func (channel *Channel) Invite(opt *InviteOptions) (code int, err error) {
|
||||
} else {
|
||||
channel.Error("read invite response y ", zap.Error(err))
|
||||
}
|
||||
break
|
||||
// break
|
||||
}
|
||||
if ls[0] == "m" && len(ls[1]) > 0 {
|
||||
netinfo := strings.Split(ls[1], " ")
|
||||
if strings.ToUpper(netinfo[2]) == "TCP/RTP/AVP" {
|
||||
channel.Debug("Device support tcp")
|
||||
} else {
|
||||
channel.Debug("Device not support tcp")
|
||||
networkType = "udp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
err = ps.Receive(streamPath, opt.dump, fmt.Sprintf("%s:%d", networkType, opt.MediaPort), opt.SSRC, resuePort)
|
||||
err = ps.Receive(streamPath, opt.dump, fmt.Sprintf("%s:%d", networkType, opt.MediaPort), opt.SSRC, reusePort)
|
||||
if err == nil {
|
||||
PullStreams.Store(streamPath, &PullStream{
|
||||
opt: opt,
|
||||
|
||||
17
main.go
17
main.go
@@ -98,8 +98,21 @@ func (c *GB28181Config) OnEvent(event any) {
|
||||
c.startServer()
|
||||
case *Stream:
|
||||
if c.InviteMode == INVIDE_MODE_ONSUBSCRIBE {
|
||||
if channel := FindChannel(e.AppName, e.StreamName); channel != nil {
|
||||
channel.TryAutoInvite(&InviteOptions{})
|
||||
//流可能是回放流,stream path是device/channel/start-end形式
|
||||
streamNames := strings.Split(e.StreamName, "/")
|
||||
if channel := FindChannel(e.AppName, streamNames[0]); channel != nil {
|
||||
opt := InviteOptions{}
|
||||
if len(streamNames) > 1 {
|
||||
last := len(streamNames) - 1
|
||||
timestr := streamNames[last]
|
||||
trange := strings.Split(timestr, "-")
|
||||
if len(trange) == 2 {
|
||||
startTime := trange[0]
|
||||
endTime := trange[1]
|
||||
opt.Validate(startTime, endTime)
|
||||
}
|
||||
}
|
||||
channel.TryAutoInvite(&opt)
|
||||
}
|
||||
}
|
||||
case SEpublish:
|
||||
|
||||
14
manscdp.go
14
manscdp.go
@@ -2,6 +2,7 @@ package gb28181
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -43,6 +44,17 @@ var (
|
||||
</Query>`
|
||||
)
|
||||
|
||||
func intTotime(t int64) time.Time {
|
||||
tstr := strconv.FormatInt(t, 10)
|
||||
if len(tstr) == 10 {
|
||||
return time.Unix(t, 0)
|
||||
}
|
||||
if len(tstr) == 13 {
|
||||
return time.UnixMilli(t)
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
// BuildDeviceInfoXML 获取设备详情指令
|
||||
func BuildDeviceInfoXML(sn int, id string) string {
|
||||
return fmt.Sprintf(DeviceInfoXML, sn, id)
|
||||
@@ -55,7 +67,7 @@ func BuildCatalogXML(sn int, id string) string {
|
||||
|
||||
// BuildRecordInfoXML 获取录像文件列表指令
|
||||
func BuildRecordInfoXML(sn int, id string, start, end int64) string {
|
||||
return fmt.Sprintf(RecordInfoXML, sn, id, time.Unix(start, 0).Format("2006-01-02T15:04:05"), time.Unix(end, 0).Format("2006-01-02T15:04:05"))
|
||||
return fmt.Sprintf(RecordInfoXML, sn, id, intTotime(start).Format("2006-01-02T15:04:05"), intTotime(end).Format("2006-01-02T15:04:05"))
|
||||
}
|
||||
|
||||
// BuildDevicePositionXML 订阅设备位置
|
||||
|
||||
Reference in New Issue
Block a user