From 11be4a17d157e1c4c344c0ee1748662739bb52b3 Mon Sep 17 00:00:00 2001 From: "joe_zhang2006@163.com" Date: Mon, 30 Oct 2023 15:05:44 +0800 Subject: [PATCH] =?UTF-8?q?[fix]aac=E8=A7=A3=E6=9E=90=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=81=B6=E5=B0=94=E4=BA=A7=E7=94=9F=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srt/pub.go | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/srt/pub.go b/srt/pub.go index 0feab9e..1a8af48 100644 --- a/srt/pub.go +++ b/srt/pub.go @@ -75,10 +75,17 @@ func (p *Publisher) Run() { PayloadType: base.AvPacketPtAac, Pts: int64(preAudioDts), } - Payload := frame[aac.AdtsHeaderLength:ctx.AdtsLength] - frame = frame[ctx.AdtsLength:] - aacPacket.Payload = Payload - p.ss.FeedAvPacket(aacPacket) + if len(frame) >= int(ctx.AdtsLength) { + Payload := frame[aac.AdtsHeaderLength:ctx.AdtsLength] + if len(frame) > int(ctx.AdtsLength) { + frame = frame[ctx.AdtsLength:] + } else { + frame = frame[0:0] + } + aacPacket.Payload = Payload + p.ss.FeedAvPacket(aacPacket) + } + } } else if cid == ts.TS_STREAM_H264 { pkt.Payload = frame @@ -94,20 +101,9 @@ func (p *Publisher) Run() { p.ss.FeedAvPacket(pkt) } } - - for { - select { - case <-p.ctx.Done(): - return - default: - - } - - err := p.demuxer.Input(bufio.NewReader(p.conn)) - if err != nil { - nazalog.Infof("stream [%s] disconnected", p.streamName) - break - } - return + err := p.demuxer.Input(bufio.NewReader(p.conn)) + if err != nil { + nazalog.Infof("stream [%s] disconnected", p.streamName) } + return }