Skip to content

Commit

Permalink
Merge pull request #56 from joestarzxh/master
Browse files Browse the repository at this point in the history
[fix]解决gb udp无法播放,gb结束后无法再重新播放的问题
  • Loading branch information
ZSC714725 authored Mar 11, 2024
2 parents 994c32e + 97a03a1 commit 117ba69
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
12 changes: 5 additions & 7 deletions conf/lalmax.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@
"enable": true,
"serial": "34020000002000000001",
"realm": "3402000000",
"sipNetwork": "tcp",
"sipIp": "100.100.108.230",
"sipIp": "192.168.254.165",
"sipPort": 5060,
"sipNetwork": "udp",
"username": "",
"quickLogin": true,
"media_config": {
"mediaIp": "100.100.108.230",
"tcp_listen_port": 30000,
"udp_listen_port": 30000
}
"mediaIp": "192.168.254.165"
},
"quickLogin": true
},
"onvif_config": {
"enable": true
Expand Down
10 changes: 7 additions & 3 deletions gb28181/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ChannelInfo struct {
Longitude string `xml:"Longitude"` // 经度
Latitude string `xml:"Latitude"` // 纬度
StreamName string `xml:"-"`
serial string
}

type ChannelStatus string
Expand Down Expand Up @@ -131,12 +132,15 @@ func (channel *Channel) Invite(opt *InviteOptions, conf config.GB28181Config, st
d := channel.device
s := "Play"

//依据deviceId生成ssrc,取设备ID最后六位,然后按顺序生成,一个channel最大999 方便排查问题,也能保证唯一性
//然后按顺序生成,一个channel最大999 方便排查问题,也能保证唯一性
channel.number++
if channel.number > 999 {
channel.number = 1
}
opt.CreateSSRC(channel.ChannelId, channel.number)
if len(channel.serial) == 0 {
channel.serial = RandNumString(6)
}
opt.CreateSSRC(channel.serial, channel.number)

protocol := ""
nazalog.Info("networkType:", network)
Expand Down Expand Up @@ -174,7 +178,7 @@ func (channel *Channel) Invite(opt *InviteOptions, conf config.GB28181Config, st
invite.SetBody(strings.Join(sdpInfo, "\r\n")+"\r\n", true)

subject := sip.GenericHeader{
HeaderName: "Subject", Contents: fmt.Sprintf("%s:%s,%s:0", channel.ChannelId, opt.ssrc, ""),
HeaderName: "Subject", Contents: fmt.Sprintf("%s:%s,%s:0", channel.ChannelId, opt.ssrc, conf.Serial),
}
invite.AppendHeader(&subject)
inviteRes, err := d.SipRequestForResponse(invite)
Expand Down
2 changes: 1 addition & 1 deletion gb28181/inviteoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (o InviteOptions) String() string {

func (o *InviteOptions) CreateSSRC(serial string, number uint16) {
//不按gb生成标准,取ID最后六位,然后按顺序生成,一个channel最大999
o.ssrc = fmt.Sprintf("%d%s%03d", 0, serial[14:], number)
o.ssrc = fmt.Sprintf("%d%s%03d", 0, serial, number)
_ssrc, _ := strconv.ParseInt(o.ssrc, 10, 0)
o.SSRC = uint32(_ssrc)
}
5 changes: 5 additions & 0 deletions gb28181/mediaserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func (s *GB28181MediaServer) Start() (err error) {
}

c := NewConn(conn, s.lalServer)
c.CheckSsrc = s.CheckSsrc
c.NotifyClose = s.NotifyClose
go c.Serve()
}

Expand All @@ -89,5 +91,8 @@ func (s *GB28181MediaServer) CheckSsrc(ssrc uint32) (string, bool) {
}

func (s *GB28181MediaServer) NotifyClose(streamName string) {
if s.NotifyCloseFunc != nil {
s.NotifyCloseFunc(streamName)
}

}

0 comments on commit 117ba69

Please sign in to comment.