Skip to content

Commit

Permalink
Merge pull request #99 from jaysooong/master
Browse files Browse the repository at this point in the history
gb主动关闭rtp链接
  • Loading branch information
joestarzxh authored Jul 18, 2024
2 parents 75dbbeb + 4afeeaa commit d5b10b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gb28181/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,21 @@ func (channel *Channel) byeClear() (err error) {
return
}
func (channel *Channel) Bye(streamName string) (err error) {
err = channel.stopMediaServer()

if channel.ackReq != nil {
byeReq := channel.ackReq
channel.ackReq = nil
byeReq.SetMethod(sip.BYE)
seq, _ := byeReq.CSeq()
seq.SeqNo += 1
sipsvr.Send(byeReq)
return err
} else {
return errors.New("channel has been closed")
err = errors.New("channel has been closed")
}

channel.stopMediaServer()
return err

}
func (channel *Channel) CreateRequst(Method sip.RequestMethod, conf config.GB28181Config) (req sip.Request) {
d := channel.device
Expand Down
9 changes: 9 additions & 0 deletions gb28181/mediaserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type GB28181MediaServer struct {
disposeOnce sync.Once
observer IGbObserver
mediaKey string

conn *Conn //增加链接对象,目前只适用于多端口
}

func NewGB28181MediaServer(listenPort int, mediaKey string, observer IGbObserver, lal logic.ILalServer) *GB28181MediaServer {
Expand Down Expand Up @@ -59,6 +61,8 @@ func (s *GB28181MediaServer) Start(listener net.Listener) (err error) {

c := NewConn(conn, s.observer, s.lalServer)
c.SetKey(s.mediaKey)

s.conn = c
go c.Serve()
}
}()
Expand All @@ -67,6 +71,11 @@ func (s *GB28181MediaServer) Start(listener net.Listener) (err error) {
}
func (s *GB28181MediaServer) Dispose() {
s.disposeOnce.Do(func() {

if s.conn != nil {
s.conn.conn.Close()
}

if s.listener != nil {
s.listener.Close()
s.listener = nil
Expand Down

0 comments on commit d5b10b8

Please sign in to comment.