From patchwork Sat Feb 4 10:41:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40248 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp1868580pzk; Sat, 4 Feb 2023 02:44:26 -0800 (PST) X-Google-Smtp-Source: AK7set9LBNjdlIA0rPUvw+rbKjSsncSkiZ64amswit9Lp9VvJBx3U5oEQX/1qdlFOFIk9kgGnRTQ X-Received: by 2002:a17:906:c04:b0:885:6d0f:4660 with SMTP id s4-20020a1709060c0400b008856d0f4660mr12720829ejf.22.1675507466473; Sat, 04 Feb 2023 02:44:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675507466; cv=none; d=google.com; s=arc-20160816; b=VNe1vJvEDb9YOqVQ8SxKNcJltjDfJJ0gLTfytg4pAOXYokTtfZa8RRuhIqs3omtNST YyDK+MGeOd7CbHqEoNvd1jHjw+fNCJpJmDj5l0hcMU+Bij9OaEgpVQQ9+JJfCZVSMwEL /r1gtxnNqizeOzj3x9tEdhSsQoyQwoNLEo6NPhTqieXLH7w6zTMFR/mEPpHIQuKeXLYU 6S+b+X6pXLuk5CZmjHcZ9783szVyXJaj0jyg8JuBvM3hh2jbxpCNbkCOQCtPZGq8lpQF GEwZgkZ4UjpoAl3IrZIHHg57hEKutgntlTwK0qftM1RpUCs/1qPIRWEat5bAxOdqLbLW LpDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=gQmwOcoau8M3RhskelID5KkpSuw6yuUgXHIHr2VD4tM=; b=SboCIU7LplAXoVULLX/bL4cr16CQBcBpvuO8kpbBoz1jlD2T4ltChB9DzK1YAJkRXk MlN+0wgqcxM2cv76TD0DDVoh4/u2XS8gFZHM7KTqthax25Wj/ukhsV3XbRGoU/f6NJ6+ Q0Edo0TotxAMBQadeAVANcm6zGK57SQ6tN0xWVuf6UIXsHDGSxewHx9tAwl+CBnvlZql K55nGnzObbH9IU9+EwU1Y+l7s333d4iWHgMCrzlLi1NKz0wX/RK2VMVF03Gt4lrT8lZV 07wOWMDM02b2yMgpIBsEEJreQv9jcfdvzSF49P5Vdqf6W767Hgy9DjlTrY3jOBH0curR w0ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id et17-20020a170907295100b008953acbe3e8si797760ejc.271.2023.02.04.02.44.26; Sat, 04 Feb 2023 02:44:26 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AD6A468BEA3; Sat, 4 Feb 2023 12:44:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 16B2168B213 for ; Sat, 4 Feb 2023 12:44:08 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D5813240D28 for ; Sat, 4 Feb 2023 11:44:07 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id et02dWCqPl6k for ; Sat, 4 Feb 2023 11:44:07 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id AB6C72404F5 for ; Sat, 4 Feb 2023 11:44:06 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2C32F3A0354 for ; Sat, 4 Feb 2023 11:44:05 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Feb 2023 11:41:35 +0100 Message-Id: <20230204104204.20721-5-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230204104204.20721-1-anton@khirnov.net> References: <20230204104204.20721-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 04/33] avformat/demux: Avoid stack packet when decoding frame 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /+Um82Pg592Z From: Andreas Rheinhardt Possible now that avcodec_decode_subtitle2() accepts a const AVPacket*. Signed-off-by: Andreas Rheinhardt Signed-off-by: Anton Khirnov --- libavformat/demux.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index 2dfd82a63ca..ba2991750bc 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1984,7 +1984,7 @@ static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr) /* returns 1 or 0 if or if not decoded data was returned, or a negative error */ static int try_decode_frame(AVFormatContext *s, AVStream *st, - const AVPacket *avpkt, AVDictionary **options) + const AVPacket *pkt, AVDictionary **options) { FFStream *const sti = ffstream(st); AVCodecContext *const avctx = sti->avctx; @@ -1992,9 +1992,9 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, int got_picture = 1, ret = 0; AVFrame *frame = av_frame_alloc(); AVSubtitle subtitle; - AVPacket pkt = *avpkt; int do_skip_frame = 0; enum AVDiscard skip_frame; + int pkt_to_send = pkt->size > 0; if (!frame) return AVERROR(ENOMEM); @@ -2043,7 +2043,7 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, avctx->skip_frame = AVDISCARD_ALL; } - while ((pkt.size > 0 || (!pkt.data && got_picture)) && + while ((pkt_to_send || (!pkt->data && got_picture)) && ret >= 0 && (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || (!sti->codec_info_nb_frames && @@ -2051,11 +2051,11 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, got_picture = 0; if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO) { - ret = avcodec_send_packet(avctx, &pkt); + ret = avcodec_send_packet(avctx, pkt); if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) break; if (ret >= 0) - pkt.size = 0; + pkt_to_send = 0; ret = avcodec_receive_frame(avctx, frame); if (ret >= 0) got_picture = 1; @@ -2063,11 +2063,11 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, ret = 0; } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { ret = avcodec_decode_subtitle2(avctx, &subtitle, - &got_picture, &pkt); + &got_picture, pkt); if (got_picture) avsubtitle_free(&subtitle); if (ret >= 0) - pkt.size = 0; + pkt_to_send = 0; } if (ret >= 0) { if (got_picture)