Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gb主动关闭rtp链接 #99

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading