From patchwork Wed Mar 23 15:57:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34941 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922266uaj; Wed, 23 Mar 2022 08:58:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkM7580aH5h8wCJXac7uInrrcoMNE1CRii0/1Umgea4FVausfCEz+MTecTaTq0tHLiaCrD X-Received: by 2002:a17:906:dc8d:b0:6db:572b:df24 with SMTP id cs13-20020a170906dc8d00b006db572bdf24mr712493ejc.193.1648051124336; Wed, 23 Mar 2022 08:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051124; cv=none; d=google.com; s=arc-20160816; b=zuqSPTt+zeTzfmdffsZw5tx+vY4QdEqW4uSEe4S0xP6yCFTrzc2syUxdZynnMebTQ3 WQ6O5b9VwaZ5GGZT9Ep/zjShaYWO1fCnxXFLDFmh6OgvN12PoNKQ9vsez7MXrC6C0KFs rrvVdlvkoq+TfIUxXqbyY+ZNotkVey8it/r8ZdAVX1ut+ARWfTiY+mqO9Iv3NBd00hBk 5BNwjFb6Iv4h6zT519NRgjy0T/KeA2/E4WnsoS0U6DmwZBmnOn6eXmb5yWO0VDCoLBCJ ZaHiXiQM890MDsKma7kyiXbvjwH4EIbOp+a2E45ixPATsaUcMFPS4Rdnl9Hik4Uv84gA oJhg== 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=1SA1aW0LMpgafHWELruKc3CS48aeCeekub1A/0hTx98=; b=ZfuygzcqbgW4eN0GOpMb/Y3g23eVVqj7v2Equj8HKV69QN9+xKezMc207cTKyCjA5y gxx5v6FIZeG1AIQQ1FCyr+pdnUyd4fpKCTpGA2Ma3Ye3cUagqWV8PkLI1GHBMNNQFEsj WE+qSJYiYO+hG7PaYD+Nt3Tqt6eQ6CdXcYW5lyDf7FShesxF2DdEW1g3ZS4z/9CMDhIq 3A3gvtKYcuGolGn8+/SMgXWABCsEY6HeEri5WTJtllDTo0ngUyEkOG/K50pFTctK3blR ZTGJofujc+gjr2HdApJrYC+/b0Yhph166t72geuN/0vqsFieI65k6uro1XFFByCrp3Z6 5ZSQ== 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 ky19-20020a170907779300b006df76385c26si12718329ejc.198.2022.03.23.08.58.43; Wed, 23 Mar 2022 08:58:44 -0700 (PDT) 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 50A2A68B192; Wed, 23 Mar 2022 17:57:48 +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 8FD9E68B192 for ; Wed, 23 Mar 2022 17:57:41 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D8B39240506 for ; Wed, 23 Mar 2022 16:57:37 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id iaCuxDPTfDGJ for ; Wed, 23 Mar 2022 16:57:36 +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 96C5124017C for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 921183A0189; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:14 +0100 Message-Id: <20220323155720.20017-2-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220323155720.20017-1-anton@khirnov.net> References: <20220323155720.20017-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] lavc/avcodec: only allocate the encoding frame for encoders 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: dOyvXc/QhcPg And only when needed, i.e. for encoders using the simple API. --- libavcodec/avcodec.c | 4 +--- libavcodec/encode.c | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index dbaa9f78a2..c7daa385e7 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -180,14 +180,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->buffer_frame = av_frame_alloc(); avci->buffer_pkt = av_packet_alloc(); - avci->es.in_frame = av_frame_alloc(); avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), AV_FIFO_FLAG_AUTO_GROW); if (!avci->buffer_frame || !avci->buffer_pkt || - !avci->es.in_frame || !avci->in_pkt || - !avci->last_pkt_props || !avci->pkt_props) { + !avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 70bd8da81f..837ffaa40d 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -412,6 +412,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * int ff_encode_preinit(AVCodecContext *avctx) { + AVCodecInternal *avci = avctx->internal; int i; if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { @@ -563,5 +564,11 @@ FF_ENABLE_DEPRECATION_WARNINGS if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY; + if (ffcodec(avctx->codec)->encode2) { + avci->es.in_frame = av_frame_alloc(); + if (!avci->es.in_frame) + return AVERROR(ENOMEM); + } + return 0; }