mirror of
https://github.com/Monibuca/plugin-gb28181.git
synced 2025-12-24 13:27:57 +08:00
update auto media ip
This commit is contained in:
@@ -66,7 +66,7 @@ func (c *Channel) CreateRequst(Method sip.RequestMethod) (req sip.Request) {
|
||||
//DisplayName: sip.String{Str: d.serverConfig.Serial},
|
||||
Uri: &sip.SipUri{
|
||||
FUser: sip.String{Str: d.config.Serial},
|
||||
FHost: d.config.SipIP,
|
||||
FHost: d.serAddr,
|
||||
FPort: &port,
|
||||
},
|
||||
Params: sip.NewParams().Add("tag", sip.String{Str: utils.RandNumString(9)}),
|
||||
@@ -236,10 +236,10 @@ func (channel *Channel) Invite(start, end string) (code int) {
|
||||
}
|
||||
sdpInfo := []string{
|
||||
"v=0",
|
||||
fmt.Sprintf("o=%s 0 0 IN IP4 %s", channel.DeviceID, d.config.MediaIP),
|
||||
fmt.Sprintf("o=%s 0 0 IN IP4 %s", channel.DeviceID, d.serAddr),
|
||||
"s=" + s,
|
||||
"u=" + channel.DeviceID + ":0",
|
||||
"c=IN IP4 " + d.config.MediaIP,
|
||||
"c=IN IP4 " + d.serAddr,
|
||||
fmt.Sprintf("t=%d %d", sint, eint),
|
||||
fmt.Sprintf("m=video %d %sRTP/AVP 96", port, protocol),
|
||||
"a=recvonly",
|
||||
|
||||
@@ -56,6 +56,7 @@ type Device struct {
|
||||
Channels []*Channel
|
||||
sn int
|
||||
addr sip.Address
|
||||
serAddr string //设备对应网卡的服务器ip
|
||||
tx *sip.ServerTransaction
|
||||
NetAddr string
|
||||
channelMap map[string]*Channel
|
||||
@@ -82,12 +83,14 @@ func (config *GB28181Config) StoreDevice(id string, req sip.Request, tx *sip.Ser
|
||||
d.NetAddr = req.Source()
|
||||
d.addr = deviceAddr
|
||||
} else {
|
||||
deviceIp := from.Address.Host()
|
||||
d = &Device{
|
||||
ID: id,
|
||||
RegisterTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
Status: string(sip.REGISTER),
|
||||
addr: deviceAddr,
|
||||
serAddr: config.routes[deviceIp[0:strings.LastIndex(deviceIp, ".")]],
|
||||
tx: tx,
|
||||
NetAddr: req.Source(),
|
||||
channelMap: make(map[string]*Channel),
|
||||
@@ -191,7 +194,7 @@ func (d *Device) CreateRequest(Method sip.RequestMethod) (req sip.Request) {
|
||||
//DisplayName: sip.String{Str: d.config.Serial},
|
||||
Uri: &sip.SipUri{
|
||||
FUser: sip.String{Str: d.config.Serial},
|
||||
FHost: d.config.SipIP,
|
||||
FHost: d.serAddr,
|
||||
FPort: &port,
|
||||
},
|
||||
Params: sip.NewParams().Add("tag", sip.String{Str: utils.RandNumString(9)}),
|
||||
|
||||
202
main.go
202
main.go
@@ -1,88 +1,114 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/config"
|
||||
)
|
||||
|
||||
type GB28181Config struct {
|
||||
AutoInvite bool
|
||||
PreFetchRecord bool
|
||||
|
||||
//sip服务器的配置
|
||||
SipNetwork string //传输协议,默认UDP,可选TCP
|
||||
SipIP string //sip 服务器公网IP
|
||||
SipPort uint16 //sip 服务器端口,默认 5060
|
||||
Serial string //sip 服务器 id, 默认 34020000002000000001
|
||||
Realm string //sip 服务器域,默认 3402000000
|
||||
Username string //sip 服务器账号
|
||||
Password string //sip 服务器密码
|
||||
|
||||
AckTimeout uint16 //sip 服务应答超时,单位秒
|
||||
RegisterValidity int //注册有效期,单位秒,默认 3600
|
||||
RegisterInterval int //注册间隔,单位秒,默认 60
|
||||
HeartbeatInterval int //心跳间隔,单位秒,默认 60
|
||||
HeartbeatRetry int //心跳超时次数,默认 3
|
||||
|
||||
//媒体服务器配置
|
||||
MediaIP string //媒体服务器地址
|
||||
MediaPort uint16 //媒体服务器端口
|
||||
MediaNetwork string //媒体传输协议,默认UDP,可选TCP
|
||||
MediaPortMin uint16
|
||||
MediaPortMax uint16
|
||||
MediaIdleTimeout uint16 //推流超时时间,超过则断开链接,让设备重连
|
||||
|
||||
LogVerbose bool
|
||||
// WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
|
||||
RemoveBanInterval int //移除禁止设备间隔
|
||||
UdpCacheSize int //udp缓存大小
|
||||
|
||||
config.Publish
|
||||
Server
|
||||
}
|
||||
|
||||
func (c *GB28181Config) OnEvent(event any) {
|
||||
switch event.(type) {
|
||||
case FirstConfig:
|
||||
if c.MediaIP == "" {
|
||||
c.MediaIP = c.SipIP
|
||||
}
|
||||
c.startServer()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) IsMediaNetworkTCP() bool {
|
||||
return strings.ToLower(c.MediaNetwork) == "tcp"
|
||||
}
|
||||
|
||||
var conf = &GB28181Config{
|
||||
AutoInvite: true,
|
||||
PreFetchRecord: false,
|
||||
UdpCacheSize: 0,
|
||||
SipNetwork: "udp",
|
||||
SipIP: "127.0.0.1",
|
||||
SipPort: 5060,
|
||||
Serial: "34020000002000000001",
|
||||
Realm: "3402000000",
|
||||
Username: "",
|
||||
Password: "",
|
||||
|
||||
AckTimeout: 10,
|
||||
RegisterValidity: 60,
|
||||
RegisterInterval: 60,
|
||||
HeartbeatInterval: 60,
|
||||
HeartbeatRetry: 3,
|
||||
|
||||
MediaIP: "",
|
||||
MediaPort: 58200,
|
||||
MediaIdleTimeout: 30,
|
||||
MediaNetwork: "udp",
|
||||
|
||||
RemoveBanInterval: 600,
|
||||
LogVerbose: false,
|
||||
// WaitKeyFrame: true,
|
||||
}
|
||||
|
||||
var plugin = InstallPlugin(conf)
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/config"
|
||||
"m7s.live/engine/v4/log"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type GB28181Config struct {
|
||||
AutoInvite bool
|
||||
PreFetchRecord bool
|
||||
|
||||
//sip服务器的配置
|
||||
SipNetwork string //传输协议,默认UDP,可选TCP
|
||||
SipIP string //sip 服务器公网IP
|
||||
SipPort uint16 //sip 服务器端口,默认 5060
|
||||
Serial string //sip 服务器 id, 默认 34020000002000000001
|
||||
Realm string //sip 服务器域,默认 3402000000
|
||||
Username string //sip 服务器账号
|
||||
Password string //sip 服务器密码
|
||||
|
||||
AckTimeout uint16 //sip 服务应答超时,单位秒
|
||||
RegisterValidity int //注册有效期,单位秒,默认 3600
|
||||
RegisterInterval int //注册间隔,单位秒,默认 60
|
||||
HeartbeatInterval int //心跳间隔,单位秒,默认 60
|
||||
HeartbeatRetry int //心跳超时次数,默认 3
|
||||
|
||||
//媒体服务器配置
|
||||
MediaIP string //媒体服务器地址
|
||||
MediaPort uint16 //媒体服务器端口
|
||||
MediaNetwork string //媒体传输协议,默认UDP,可选TCP
|
||||
MediaPortMin uint16
|
||||
MediaPortMax uint16
|
||||
MediaIdleTimeout uint16 //推流超时时间,超过则断开链接,让设备重连
|
||||
|
||||
LogVerbose bool
|
||||
// WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
|
||||
RemoveBanInterval int //移除禁止设备间隔
|
||||
UdpCacheSize int //udp缓存大小
|
||||
|
||||
config.Publish
|
||||
Server
|
||||
routes map[string]string
|
||||
}
|
||||
|
||||
func (c *GB28181Config) OnEvent(event any) {
|
||||
switch event.(type) {
|
||||
case FirstConfig:
|
||||
if c.MediaIP == "" {
|
||||
c.MediaIP = c.SipIP
|
||||
}
|
||||
c.startServer()
|
||||
}
|
||||
}
|
||||
func (c *GB28181Config) InitRoutes() {
|
||||
c.routes = make(map[string]string)
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Errorf("gb28181 init routes failed.")
|
||||
return
|
||||
}
|
||||
for _, i := range interfaces {
|
||||
byName, err := net.InterfaceByName(i.Name)
|
||||
if err != nil {
|
||||
log.Errorf("gb28181 get %s interface failed.", i.Name)
|
||||
return
|
||||
}
|
||||
addresses, err := byName.Addrs()
|
||||
for _, v := range addresses {
|
||||
ip := v.String()
|
||||
if strings.Index(ip, ":") != -1 || strings.Index(ip, "127.0") != -1 {
|
||||
continue
|
||||
}
|
||||
ip = strings.Split(ip, "/")[0]
|
||||
route := ip[0:strings.LastIndex(ip, ".")]
|
||||
c.routes[route] = ip
|
||||
}
|
||||
}
|
||||
}
|
||||
func (c *GB28181Config) IsMediaNetworkTCP() bool {
|
||||
return strings.ToLower(c.MediaNetwork) == "tcp"
|
||||
}
|
||||
|
||||
var conf = &GB28181Config{
|
||||
AutoInvite: true,
|
||||
PreFetchRecord: false,
|
||||
UdpCacheSize: 0,
|
||||
SipNetwork: "udp",
|
||||
SipIP: "127.0.0.1",
|
||||
SipPort: 5060,
|
||||
Serial: "34020000002000000001",
|
||||
Realm: "3402000000",
|
||||
Username: "",
|
||||
Password: "",
|
||||
|
||||
AckTimeout: 10,
|
||||
RegisterValidity: 60,
|
||||
RegisterInterval: 60,
|
||||
HeartbeatInterval: 60,
|
||||
HeartbeatRetry: 3,
|
||||
|
||||
MediaIP: "",
|
||||
MediaPort: 58200,
|
||||
MediaIdleTimeout: 30,
|
||||
MediaNetwork: "udp",
|
||||
|
||||
RemoveBanInterval: 600,
|
||||
LogVerbose: false,
|
||||
// WaitKeyFrame: true,
|
||||
}
|
||||
|
||||
var plugin = InstallPlugin(conf)
|
||||
|
||||
Reference in New Issue
Block a user