mirror of
https://github.com/Monibuca/plugin-gb28181.git
synced 2025-12-24 13:27:57 +08:00
feat:增加配置文件支持多端口多路复用
This commit is contained in:
@@ -33,6 +33,7 @@ gb28181:
|
||||
port:
|
||||
sip: udp:5060 #sip服务器端口
|
||||
media: tcp:58200-59200 #媒体服务器端口,用于接收设备的流
|
||||
fdm: false #端口复用,单端口默认多路复用,多端口多路复用根据这个
|
||||
|
||||
removebaninterval: 10m #定时移除注册失败的设备黑名单,单位秒,默认10分钟(600秒)
|
||||
loglevel: info
|
||||
|
||||
@@ -371,20 +371,21 @@ func (channel *Channel) Invite(opt *InviteOptions) (code int, err error) {
|
||||
}
|
||||
protocol := ""
|
||||
networkType := "udp"
|
||||
reusePort := true
|
||||
|
||||
// 根据配置文件判断是否多路复用
|
||||
reusePort := conf.Port.Fdm
|
||||
|
||||
if conf.IsMediaNetworkTCP() {
|
||||
networkType = "tcp"
|
||||
protocol = "TCP/"
|
||||
if conf.tcpPorts.Valid {
|
||||
opt.MediaPort, err = conf.tcpPorts.GetPort()
|
||||
opt.recyclePort = conf.tcpPorts.Recycle
|
||||
reusePort = false
|
||||
}
|
||||
} else {
|
||||
if conf.udpPorts.Valid {
|
||||
opt.MediaPort, err = conf.udpPorts.GetPort()
|
||||
opt.recyclePort = conf.udpPorts.Recycle
|
||||
reusePort = false
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@@ -392,6 +393,8 @@ func (channel *Channel) Invite(opt *InviteOptions) (code int, err error) {
|
||||
}
|
||||
if opt.MediaPort == 0 {
|
||||
opt.MediaPort = conf.MediaPort
|
||||
// 单端口默认多路复用
|
||||
reusePort = true
|
||||
}
|
||||
|
||||
sdpInfo := []string{
|
||||
|
||||
1
main.go
1
main.go
@@ -34,6 +34,7 @@ type GB28181Config struct {
|
||||
Port struct { // 新配置方式
|
||||
Sip string `default:"udp:5060" desc:"sip服务端口号"`
|
||||
Media string `default:"tcp:58200-59200" desc:"媒体服务端口号"`
|
||||
Fdm bool `default:"false" desc:"多路复用"`
|
||||
}
|
||||
RegisterValidity time.Duration `default:"3600s" desc:"注册有效期"` //注册有效期,单位秒,默认 3600
|
||||
HeartbeatInterval time.Duration `default:"60s" desc:"心跳间隔"` //心跳间隔,单位秒,默认 60
|
||||
|
||||
@@ -3,15 +3,19 @@ package gb28181
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var ErrNoAvailablePorts = errors.New("no available ports")
|
||||
|
||||
type PortManager struct {
|
||||
recycle chan uint16
|
||||
start uint16
|
||||
max uint16
|
||||
pos uint16
|
||||
Valid bool
|
||||
}
|
||||
|
||||
func (pm *PortManager) Init(start, end uint16) {
|
||||
pm.start = start
|
||||
pm.pos = start - 1
|
||||
pm.max = end
|
||||
if pm.pos > 0 && pm.max > pm.pos {
|
||||
@@ -43,7 +47,12 @@ func (pm *PortManager) GetPort() (p uint16, err error) {
|
||||
p = pm.pos
|
||||
return
|
||||
} else {
|
||||
return 0, ErrNoAvailablePorts
|
||||
if conf.Port.Fdm == false {
|
||||
return 0, ErrNoAvailablePorts
|
||||
}
|
||||
pm.pos = pm.start - 1
|
||||
p = pm.pos
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user