From 7deb6a16a86ff4252cd78ebc061fc530acffc3b1 Mon Sep 17 00:00:00 2001 From: "joe_zhang2006@163.com" Date: Wed, 24 Jul 2024 16:29:10 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E8=A7=A3=E5=86=B3gb=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E5=81=B6=E5=B0=94=E4=BC=9A=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fmp4/hls/session.go | 32 +++++++++++++++++--------------- gb28181/mediaserver/conn.go | 4 +++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/fmp4/hls/session.go b/fmp4/hls/session.go index 540fa25..2f16af1 100644 --- a/fmp4/hls/session.go +++ b/fmp4/hls/session.go @@ -49,7 +49,7 @@ func NewHlsSession(streamName string, conf config.HlsConfig) *HlsSession { }, audioCodecId: -1, videoCodecId: -1, - maxMsgSize: 10, + maxMsgSize: 128, data: make([]Frame, 10)[0:0], streamName: streamName, SessionId: u.String(), @@ -284,27 +284,29 @@ func (session *HlsSession) drain() { } for _, data := range session.data { - if data.codecType == base.RtmpCodecIdAvc || data.codecType == base.RtmpCodecIdHevc { + if (data.codecType == base.RtmpCodecIdAvc || data.codecType == base.RtmpCodecIdHevc) && session.videoCodecId != -1 { err := session.muxer.WriteH26x(data.ntp, data.pts, data.au) if err != nil { nazalog.Error("hls-fmp4 WriteH26x failed, err:", err) continue } - } else if data.codecType == base.RtmpSoundFormatAac { - err := session.muxer.WriteMPEG4Audio(data.ntp, data.pts, data.au) - if err != nil { - nazalog.Error("hls-fmp4 WriteMPEG4Audio failed, err:", err) - continue - } - } else if data.codecType == base.RtmpSoundFormatOpus { - err := session.muxer.WriteOpus(data.ntp, data.pts, data.au) - if err != nil { - nazalog.Error("hls-fmp4 WriteMPEG4Audio failed, err:", err) + } else if session.audioCodecId != -1 { + if data.codecType == base.RtmpSoundFormatAac { + err := session.muxer.WriteMPEG4Audio(data.ntp, data.pts, data.au) + if err != nil { + nazalog.Error("hls-fmp4 WriteMPEG4Audio failed, err:", err) + continue + } + } else if data.codecType == base.RtmpSoundFormatOpus { + err := session.muxer.WriteOpus(data.ntp, data.pts, data.au) + if err != nil { + nazalog.Error("hls-fmp4 WriteMPEG4Audio failed, err:", err) + continue + } + } else { + // gohlslib不支持g711 continue } - } else { - // gohlslib不支持g711 - continue } } diff --git a/gb28181/mediaserver/conn.go b/gb28181/mediaserver/conn.go index 85d91bf..500a009 100644 --- a/gb28181/mediaserver/conn.go +++ b/gb28181/mediaserver/conn.go @@ -87,7 +87,9 @@ func (c *Conn) Serve() (err error) { if c.psDumpFile != nil { c.psDumpFile.Close() } - c.lalServer.DelCustomizePubSession(c.lalSession) + if c.lalSession != nil { + c.lalServer.DelCustomizePubSession(c.lalSession) + } }() nazalog.Info("gb28181 conn, remoteaddr:", c.conn.RemoteAddr().String(), " localaddr:", c.conn.LocalAddr().String())