Compare commits

...

5 Commits

Author SHA1 Message Date
dexter
eb6004d6ef 🐛 FIX: 防止dts自动生成 2022-10-17 11:37:30 +08:00
dexter
cce5f67ab9 🐛 FIX: initRoutes索引越界 2022-10-13 16:23:32 +08:00
dexter
fdfb462d46 Merge pull request #70 from WXC9102/v4
更新通道panic
2022-09-26 18:52:23 +08:00
weixuechao
c05adce562 1.更新通道时会偶发panic, 2.新增/删除通道信息没有更新 2022-09-26 16:54:55 +08:00
dexter
aa3727f582 🐛 FIX: unlock时的判空 2022-09-19 00:21:48 +08:00
4 changed files with 45 additions and 9 deletions

View File

@@ -51,6 +51,28 @@ type Channel struct {
*ChannelEx //自定义属性
}
func (c *Channel) Copy(v *Channel) {
if v == nil {
return
}
c.DeviceID = v.DeviceID
c.ParentID = v.ParentID
c.Name = v.Name
c.Manufacturer = v.Manufacturer
c.Model = v.Model
c.Owner = v.Owner
c.CivilCode = v.CivilCode
c.Address = v.Address
c.Parental = v.Parental
c.SafetyWay = v.SafetyWay
c.RegisterWay = v.RegisterWay
c.Secrecy = v.Secrecy
c.Status = v.Status
c.Status = v.Status
c.ChannelEx = v.ChannelEx
}
func (c *Channel) CreateRequst(Method sip.RequestMethod) (req sip.Request) {
d := c.device
d.sn++

View File

@@ -233,10 +233,13 @@ func (d *Device) UpdateChannels(list []*Channel) {
go c.QueryRecord(n.Format(TIME_LAYOUT), n.Add(time.Hour*24-time.Second).Format(TIME_LAYOUT))
}
}
old.Copy(c)
c = old
} else {
c.ChannelEx = &ChannelEx{
device: d,
}
d.channelMap[c.DeviceID] = c
}
if conf.AutoInvite && (c.LivePublisher == nil) {
go c.Invite(InviteOptions{})
@@ -246,7 +249,6 @@ func (d *Device) UpdateChannels(list []*Channel) {
} else {
c.LiveSubSP = ""
}
d.channelMap[c.DeviceID] = c
}
}
func (d *Device) UpdateRecord(channelId string, list []*Record) {
@@ -456,7 +458,7 @@ func (d *Device) UpdateChannelStatus(deviceList []*notifyMessage) {
d.channelOffline(v.DeviceID)
case "ADD":
plugin.Debug("收到通道新增通知")
channel := Channel{
channel := &Channel{
DeviceID: v.DeviceID,
ParentID: v.ParentID,
Name: v.Name,
@@ -471,11 +473,12 @@ func (d *Device) UpdateChannelStatus(deviceList []*notifyMessage) {
Secrecy: v.Secrecy,
Status: v.Status,
}
d.addChannel(&channel)
channels := []*Channel{channel}
d.UpdateChannels(channels)
case "DEL":
//删除
plugin.Debug("收到通道删除通知")
delete(d.channelMap, v.DeviceID)
d.channelOffline(v.DeviceID)
case "UPDATE":
plugin.Debug("收到通道更新通知")
// 更新通道

View File

@@ -52,7 +52,9 @@ func (c *GB28181Config) initRoutes() {
tempIps := myip.LocalAndInternalIPs()
for k, v := range tempIps {
c.routes[k] = v
c.routes[k[0:strings.LastIndex(k, ".")]] = k
if lastdot := strings.LastIndex(k, "."); lastdot >= 0 {
c.routes[k[0:lastdot]] = k
}
}
plugin.Info(fmt.Sprintf("LocalAndInternalIPs detail: %s", c.routes))
}

View File

@@ -59,14 +59,18 @@ func (p *GBPublisher) OnEvent(event any) {
case SEwaitPublish:
//掉线自动重新拉流
if p.IsLive() {
p.channel.LivePublisher = nil
p.channel.liveInviteLock.Unlock()
if p.channel.LivePublisher != nil {
p.channel.LivePublisher = nil
p.channel.liveInviteLock.Unlock()
}
go p.channel.Invite(InviteOptions{})
}
case SEclose, SEKick:
if p.IsLive() {
p.channel.LivePublisher = nil
p.channel.liveInviteLock.Unlock()
if p.channel.LivePublisher != nil {
p.channel.LivePublisher = nil
p.channel.liveInviteLock.Unlock()
}
} else {
p.channel.RecordPublisher = nil
}
@@ -113,6 +117,9 @@ func (p *GBPublisher) PushVideo(pts uint32, dts uint32, payload []byte) {
}
}
p.PrintDump(fmt.Sprintf("<td>pts:%d dts:%d data: % 2X</td>", pts, dts, payload[:10]))
if dts == 0 {
dts = pts
}
p.VideoTrack.WriteAnnexB(pts, dts, payload)
}
func (p *GBPublisher) PushAudio(ts uint32, payload []byte) {
@@ -232,10 +239,12 @@ func (p *GBPublisher) ListenUDP() (port uint16, err error) {
plugin.Error("listen media server udp err", zap.String("addr", addr), zap.Error(err))
return 0, err
}
p.SetIO(conn)
go func() {
bufUDP := make([]byte, networkBuffer)
plugin.Info("Media udp server start.", zap.Uint16("port", port))
defer plugin.Info("Media udp server stop", zap.Uint16("port", port))
defer conf.udpPorts.Recycle(port)
dumpLen := make([]byte, 6)
for n, _, err := conn.ReadFromUDP(bufUDP); err == nil; n, _, err = conn.ReadFromUDP(bufUDP) {
ps := bufUDP[:n]