mirror of
https://github.com/Monibuca/plugin-gb28181.git
synced 2025-12-24 13:27:57 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05fd8c38f7 |
20
channel.go
20
channel.go
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
type ChannelEx struct {
|
||||
device *Device
|
||||
RecordPublisher *GBPublisher `json:"-"`
|
||||
RecordPublisher *GBPublisher `json:"-" yaml:"-"`
|
||||
LivePublisher *GBPublisher
|
||||
LiveSubSP string //实时子码流
|
||||
Records []*Record
|
||||
@@ -47,7 +47,7 @@ type Channel struct {
|
||||
RegisterWay int
|
||||
Secrecy int
|
||||
Status string
|
||||
Children []*Channel `json:"-"`
|
||||
Children []*Channel `json:"-" yaml:"-"`
|
||||
ChannelEx //自定义属性
|
||||
}
|
||||
|
||||
@@ -75,9 +75,13 @@ func (channel *Channel) CreateRequst(Method sip.RequestMethod) (req sip.Request)
|
||||
//非同一域的目标地址需要使用@host
|
||||
host := conf.Realm
|
||||
if channel.DeviceID[0:9] != host {
|
||||
deviceIp := d.NetAddr
|
||||
deviceIp = deviceIp[0:strings.LastIndex(deviceIp, ":")]
|
||||
host = fmt.Sprintf("%s:%d", deviceIp, channel.Port)
|
||||
if channel.Port != 0 {
|
||||
deviceIp := d.NetAddr
|
||||
deviceIp = deviceIp[0:strings.LastIndex(deviceIp, ":")]
|
||||
host = fmt.Sprintf("%s:%d", deviceIp, channel.Port)
|
||||
} else {
|
||||
host = d.NetAddr
|
||||
}
|
||||
}
|
||||
|
||||
channelAddr := sip.Address{
|
||||
@@ -299,9 +303,9 @@ func (channel *Channel) Invite(opt *InviteOptions) (code int, err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if conf.UdpCacheSize > 0 && !conf.IsMediaNetworkTCP() {
|
||||
publisher.udpCache = utils.NewPqRtp()
|
||||
}
|
||||
// if conf.UdpCacheSize > 0 && !conf.IsMediaNetworkTCP() {
|
||||
// publisher.udpCache = utils.NewPqRtp()
|
||||
// }
|
||||
if err = plugin.Publish(streamPath, publisher); err != nil {
|
||||
code = ServerInternalError
|
||||
return
|
||||
|
||||
@@ -47,7 +47,7 @@ var (
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
//*transaction.Core `json:"-"`
|
||||
//*transaction.Core `json:"-" yaml:"-"`
|
||||
ID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
|
||||
31
main.go
31
main.go
@@ -9,6 +9,7 @@ import (
|
||||
myip "github.com/husanpao/ip"
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/config"
|
||||
"m7s.live/engine/v4/util"
|
||||
)
|
||||
|
||||
type GB28181PositionConfig struct {
|
||||
@@ -30,7 +31,10 @@ type GB28181Config struct {
|
||||
Realm string `default:"3402000000"` //sip 服务器域,默认 3402000000
|
||||
Username string //sip 服务器账号
|
||||
Password string //sip 服务器密码
|
||||
|
||||
Port struct { // 新配置方式
|
||||
Sip string `default:"udp:5060"`
|
||||
Media string `default:"tcp:58200"`
|
||||
}
|
||||
// AckTimeout uint16 //sip 服务应答超时,单位秒
|
||||
RegisterValidity time.Duration `default:"60s"` //注册有效期,单位秒,默认 3600
|
||||
// RegisterInterval int //注册间隔,单位秒,默认 60
|
||||
@@ -47,11 +51,11 @@ type GB28181Config struct {
|
||||
|
||||
// WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
|
||||
RemoveBanInterval time.Duration `default:"600s"` //移除禁止设备间隔
|
||||
UdpCacheSize int //udp缓存大小
|
||||
LogLevel string `default:"info"` //trace, debug, info, warn, error, fatal, panic
|
||||
routes map[string]string
|
||||
DumpPath string //dump PS流本地文件路径
|
||||
RtpReorder bool `default:"true"`
|
||||
// UdpCacheSize int //udp缓存大小
|
||||
LogLevel string `default:"info"` //trace, debug, info, warn, error, fatal, panic
|
||||
routes map[string]string
|
||||
DumpPath string //dump PS流本地文件路径
|
||||
RtpReorder bool `default:"true"`
|
||||
config.Publish
|
||||
Server
|
||||
|
||||
@@ -72,6 +76,21 @@ func (c *GB28181Config) initRoutes() {
|
||||
func (c *GB28181Config) OnEvent(event any) {
|
||||
switch event.(type) {
|
||||
case FirstConfig:
|
||||
if c.Port.Sip != "udp:5060" {
|
||||
protocol, ports := util.Conf2Listener(c.Port.Sip)
|
||||
c.SipNetwork = protocol
|
||||
c.SipPort = ports[0]
|
||||
}
|
||||
if c.Port.Media != "tcp:58200" {
|
||||
protocol, ports := util.Conf2Listener(c.Port.Media)
|
||||
c.MediaNetwork = protocol
|
||||
if len(ports) > 1 {
|
||||
c.MediaPortMin = ports[0]
|
||||
c.MediaPortMax = ports[1]
|
||||
} else {
|
||||
c.MediaPort = ports[0]
|
||||
}
|
||||
}
|
||||
os.MkdirAll(c.DumpPath, 0766)
|
||||
c.ReadDevices()
|
||||
go c.initRoutes()
|
||||
|
||||
@@ -14,15 +14,14 @@ import (
|
||||
"go.uber.org/zap"
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/util"
|
||||
"m7s.live/plugin/gb28181/v4/utils"
|
||||
)
|
||||
|
||||
type GBPublisher struct {
|
||||
PSPublisher
|
||||
*InviteOptions
|
||||
channel *Channel
|
||||
inviteRes sip.Response
|
||||
udpCache *utils.PriorityQueueRtp
|
||||
channel *Channel
|
||||
inviteRes sip.Response
|
||||
// udpCache *utils.PriorityQueueRtp
|
||||
dumpFile *os.File
|
||||
dumpPrint io.Writer
|
||||
lastReceive time.Time
|
||||
@@ -80,7 +79,7 @@ func (p *GBPublisher) OnEvent(event any) {
|
||||
if p.dumpFile != nil {
|
||||
p.dumpFile.Close()
|
||||
}
|
||||
p.Bye()
|
||||
go p.Bye()
|
||||
}
|
||||
p.Publisher.OnEvent(event)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user