From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3B1F740054 for ; Tue, 22 Mar 2022 16:39:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4707E68B16B; Tue, 22 Mar 2022 18:39:21 +0200 (EET) Received: from srv-infra-2.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D58368A066 for ; Tue, 22 Mar 2022 18:39:14 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-2.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 59C6E42A93; Tue, 22 Mar 2022 16:39:13 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Tue, 22 Mar 2022 17:39:11 +0100 Message-Id: <20220322163911.64772-2-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220322163911.64772-1-nicolas.gaullier@cji.paris> References: <20220322163911.64772-1-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/2] lavf/mpegenc: fix termination following a fifo overrun X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nicolas Gaullier Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Avoid an infinite 'retry' loop in output_packet when flushing. A fatal error mentions the availability of fifo_size_limit option. Signed-off-by: Nicolas Gaullier --- libavformat/mpegenc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 5d755e3bdd..eff4531037 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -85,6 +85,7 @@ typedef struct MpegMuxContext { int preload; uint32_t fifo_size_limit; + int fifo_size_exceeded; } MpegMuxContext; extern const AVOutputFormat ff_mpeg1vcd_muxer; @@ -1153,7 +1154,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) StreamInfo *stream = st->priv_data; int64_t pts, dts; PacketDesc *pkt_desc; - int preload; + int preload, ret; const int is_iframe = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY); @@ -1220,10 +1221,17 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) } } - av_fifo_write(stream->fifo, buf, size); + ret = av_fifo_write(stream->fifo, buf, size); + if (ret == AVERROR(ENOSPC)) { + s->fifo_size_exceeded = 1; + av_log(s, AV_LOG_FATAL, "Input stream buffer overrun. " + "To avoid, increase fifo_size_limit option.\n"); + } + if (ret < 0) + return ret; for (;;) { - int ret = output_packet(ctx, 0); + ret = output_packet(ctx, 0); if (ret <= 0) return ret; } @@ -1231,9 +1239,13 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) static int mpeg_mux_end(AVFormatContext *ctx) { + MpegMuxContext *s = ctx->priv_data; StreamInfo *stream; int i; + if (s->fifo_size_exceeded) + return 0; + for (;;) { int ret = output_packet(ctx, 1); if (ret < 0) -- 2.34.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".