修复相互引用内存泄露问题

This commit is contained in:
yangjiechina
2024-06-30 22:37:17 +08:00
parent 9e52dc69c4
commit 5f619972c1
6 changed files with 35 additions and 3 deletions

View File

@@ -39,3 +39,9 @@ func (u *UDPSource) InputRtp(pkt *rtp.Packet) error {
u.jitterBuffer.Push(pkt.SequenceNumber, pkt)
return nil
}
func (u *UDPSource) Close() {
u.jitterBuffer.Flush()
u.jitterBuffer.Close()
u.BaseGBSource.Close()
}

View File

@@ -287,6 +287,11 @@ func (s *Session) Close() {
s.videoBuffer.Clear()
}
if s.Conn != nil {
s.Conn.Close()
s.Conn = nil
}
s.PublishSource.Close()
}

View File

@@ -84,6 +84,11 @@ func (s *session) response(response *http.Response, body []byte) error {
}
func (s *session) close() {
if s.conn != nil {
s.conn.Close()
s.conn = nil
}
if s.sink_ != nil {
s.sink_.Close()
s.sink_ = nil

View File

@@ -166,6 +166,16 @@ func (t *tranStream) AddTrack(stream utils.AVStream) error {
return nil
}
func (t *tranStream) Close() error {
for _, track := range t.rtpTracks {
if track != nil {
track.Close()
}
}
return nil
}
func (t *tranStream) WriteHeader() error {
description := sdp.SessionDescription{
Version: 0,

View File

@@ -19,6 +19,13 @@ type rtspTrack struct {
tmpExtraDataBuffer [][]byte //缓存带有编码信息的rtp包, 整个过程会多次回调(sps->pps->sei...), 先保存到临时区, 最后再缓存到extraDataBuffer
}
func (r *rtspTrack) Close() {
if r.muxer != nil {
r.muxer.Close()
r.muxer = nil
}
}
func NewRTSPTrack(muxer librtp.Muxer, pt byte, rate int, mediaType utils.AVMediaType) *rtspTrack {
stream := &rtspTrack{
pt: pt,

View File

@@ -1,7 +1,6 @@
package stream
import (
"github.com/yangjiechina/avformat/stream"
"github.com/yangjiechina/avformat/utils"
)
@@ -31,8 +30,8 @@ type TransStream interface {
}
type BaseTransStream struct {
Sinks map[SinkId]Sink
muxer stream.Muxer
Sinks map[SinkId]Sink
//muxer stream.Muxer
Tracks []utils.AVStream
Completed bool
ExistVideo bool