From patchwork Wed Mar 23 15:57:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34936 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922049uaj; Wed, 23 Mar 2022 08:57:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOWfe8lzIsQWKemhbjzaI6FBsGvy8HD3icmjSZru2nqM6FdoRBjRhXjTo0GqkrfWmODljx X-Received: by 2002:a05:6402:1255:b0:419:3808:3d98 with SMTP id l21-20020a056402125500b0041938083d98mr983823edw.134.1648051067784; Wed, 23 Mar 2022 08:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051067; cv=none; d=google.com; s=arc-20160816; b=dsH4/pQf7BPM25y+lJ/EiwmL7fPoi89C2vJSZEsZvmgLYS0g/h+Dg6q22hRWrI70eV ZpFiXEKvVxs88w4r+PN65AoyP5vEudY0+1aQXGY7iVjUT1UkWKPooCGC99sPalJZ7R1m 5KX0uTDay/2Vz4yWdAqAFY1QCCJ35Pmql9IrcFEp5I2v4/1sYBGjBMxfOZRWeJ5QYAWr 6hHSau9VpGKYglZi8W1jELYkHID6xYRU4UeUVYCEa/+x40fH+mdp8/1O7Ef7aoq4ocXD hSQqs1qeHe/Bo4Sj6yItecr6Tec6mNl1leE3BcSaqNL9tA8kWH23aYU6iTndCBiaiE2L aNPw== 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:message-id:date:to:from :delivered-to; bh=twNJuILOPa7efr+n16ruHZbBPR/L8zsr+3Qukekqs0Y=; b=gI8l3v5a0IOkRyLjfM3mfOqTQWa9FIpuw/fqI2o7EdFPOfwTWQInygb/yWl8DH7nF4 /4ivhGw1dAMeKGzxzjlN7bWkQ0ZIeMy5OT7baSC/nJbfCXebTLW08vBY7eCulA9De7SF L8a5Hftc4L3Ivlvqu+Ct4p9ZPFH305lF2qDmAKmyTR/QEb0XU0okfK4dPefSEeCeUd3y 2XnVKcMmR+6usYWbj6DuTKP5T/Gzig3d3HGgXiiMBMu+i3bYlgOXWMGQD36fSnnuBsXM Rf5CQ5vhksV1iisCSst3NfFth3pgxitZfBz/Iy9lzclVEZqv5+xsHYCTGDB0h8wlIrCa 067g== 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 u5-20020a509505000000b00418c2b5bed4si15182450eda.438.2022.03.23.08.57.46; Wed, 23 Mar 2022 08:57:47 -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 97C9168B155; Wed, 23 Mar 2022 17:57:42 +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 5736468B03F for ; Wed, 23 Mar 2022 17:57:36 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C75A2240511 for ; Wed, 23 Mar 2022 16:57:35 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id DQTh5vDT3X9P for ; Wed, 23 Mar 2022 16:57:34 +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 923FC240179 for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 90F833A0406; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:13 +0100 Message-Id: <20220323155720.20017-1-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/8] lavc/avcodec: simplify codec id/type validity checking 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: web93oRaMYfn On entry to avcodec_open2(), the type and id either have to be UNKNOWN/NONE or have to match the codec to be used. --- libavcodec/avcodec.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index fbe4a5e413..dbaa9f78a2 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -158,17 +158,15 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code codec = avctx->codec; codec2 = ffcodec(codec); - if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && - avctx->codec_id == AV_CODEC_ID_NONE) { - avctx->codec_type = codec->type; - avctx->codec_id = codec->id; - } - if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type && - avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { + if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) || + (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) { av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); return AVERROR(EINVAL); } - avctx->codec = codec; + + avctx->codec_type = codec->type; + avctx->codec_id = codec->id; + avctx->codec = codec; if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); 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; } From patchwork Wed Mar 23 15:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34939 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922215uaj; Wed, 23 Mar 2022 08:58:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOECWhB0bQQhOaKq8jaFBNaMUDP8XkLb0LfZ2U5bCO50yeMaYM7PrOyq/cOwT2T2I354pi X-Received: by 2002:a50:f68a:0:b0:418:e6e8:5ee2 with SMTP id d10-20020a50f68a000000b00418e6e85ee2mr976656edn.190.1648051109635; Wed, 23 Mar 2022 08:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051109; cv=none; d=google.com; s=arc-20160816; b=CoO+Mmuoxk4ra9Xgma63nJ/HMGtBwSCPMoLZfWHWtGhPb9vlni6XCYVZTn3aaUq6Lx yroX0TeyAKlZLkWNON2eWpxzEkUpGFUBfDxezi1ry6G80I88TOkfe0qM4OFo6wiLQZMe e+qD3GSDevaWEBHiNX6d2e5UlOC8S2Pnm9jjfGcte66ytQ8KraCjqxwoIMXhyZ6uT0eb hjal8QJku1LRSo4ggyvRCiAF/CHE3AhT4YLUfCBq9zeNJUAXPIZLw27BM13ylBjq3oql ZNTI5CGDHl4O6uhv6bRkVlpxX0zqLP8dpPx/mhy97kbPK++QGDx8f+qH+4lk6hdgqQHb L+vg== 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=tAdhvm442ys+1qEDjGQlnAieAKS8YnknPYBzVkTsn04=; b=icc3nTeXZkX8ngWs/9mmQ7/OWXqlke5031o5f46j9hSHpNDYm7q3wT2tIUKZ7MnIQO A1sx/gqZvtJeRN30ocGTIuyMXY6OfJO9cFKRBxwAFmKlZPHDC4SNwz4/FR2z92YNhlT1 VnToKELk3etOJVu+kekgfX46XqmQKRg8A3rrJHx19zgA0BfG/FABkPyvaRUeNpQxnvVM OISmswlBHuD2EXU+DWgjvJkS2cY7jKDu6D7KcWjbPJAITEMS53qTy0QUOz8a1BbmHh80 hUuTwmUJR6uZKLExvOMLjK1VaN3OT/UsF/dr+1oaElQlqnArOP1q9NhsEFhvnHC+gWzg 3+kA== 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 10-20020a170906024a00b006df76385d96si13088843ejl.566.2022.03.23.08.58.20; Wed, 23 Mar 2022 08:58:29 -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 6AC2068B174; Wed, 23 Mar 2022 17:57:45 +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 8DEB168B12A for ; Wed, 23 Mar 2022 17:57:37 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0E8152404FE 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 FkwIOtpe1nSi for ; Wed, 23 Mar 2022 16:57:35 +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 97B3624017E for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 984923A0663; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:15 +0100 Message-Id: <20220323155720.20017-3-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 3/8] lavc: move default get_buffer2() to its own file 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: LHf2egSIk4PD It is also used by some encoders, so decode.c is not the right place for it. --- libavcodec/Makefile | 1 + libavcodec/decode.c | 278 ----------------------------------- libavcodec/get_buffer.c | 312 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 313 insertions(+), 278 deletions(-) create mode 100644 libavcodec/get_buffer.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index fb8b0e824b..a24d8a3873 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -43,6 +43,7 @@ OBJS = ac3_parser.o \ dirac.o \ dv_profile.o \ encode.o \ + get_buffer.o \ imgconvert.o \ jni.o \ mathtables.o \ diff --git a/libavcodec/decode.c b/libavcodec/decode.c index f9fdb935f6..fffad5f700 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -48,25 +48,6 @@ #include "internal.h" #include "thread.h" -typedef struct FramePool { - /** - * Pools for each data plane. For audio all the planes have the same size, - * so only pools[0] is used. - */ - AVBufferPool *pools[4]; - - /* - * Pool parameters - */ - int format; - int width, height; - int stride_align[AV_NUM_DATA_POINTERS]; - int linesize[4]; - int planes; - int channels; - int samples; -} FramePool; - static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt) { int ret; @@ -1250,265 +1231,6 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) return ret; } -static void frame_pool_free(void *opaque, uint8_t *data) -{ - FramePool *pool = (FramePool*)data; - int i; - - for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++) - av_buffer_pool_uninit(&pool->pools[i]); - - av_freep(&data); -} - -static AVBufferRef *frame_pool_alloc(void) -{ - FramePool *pool = av_mallocz(sizeof(*pool)); - AVBufferRef *buf; - - if (!pool) - return NULL; - - buf = av_buffer_create((uint8_t*)pool, sizeof(*pool), - frame_pool_free, NULL, 0); - if (!buf) { - av_freep(&pool); - return NULL; - } - - return buf; -} - -static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) -{ - FramePool *pool = avctx->internal->pool ? - (FramePool*)avctx->internal->pool->data : NULL; - AVBufferRef *pool_buf; - int i, ret, ch, planes; - - if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { - int planar = av_sample_fmt_is_planar(frame->format); - ch = frame->ch_layout.nb_channels; -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - if (!ch) - ch = frame->channels; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - planes = planar ? ch : 1; - } - - if (pool && pool->format == frame->format) { - if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && - pool->width == frame->width && pool->height == frame->height) - return 0; - if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && pool->planes == planes && - pool->channels == ch && frame->nb_samples == pool->samples) - return 0; - } - - pool_buf = frame_pool_alloc(); - if (!pool_buf) - return AVERROR(ENOMEM); - pool = (FramePool*)pool_buf->data; - - switch (avctx->codec_type) { - case AVMEDIA_TYPE_VIDEO: { - int linesize[4]; - int w = frame->width; - int h = frame->height; - int unaligned; - ptrdiff_t linesize1[4]; - size_t size[4]; - - avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align); - - do { - // NOTE: do not align linesizes individually, this breaks e.g. assumptions - // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 - ret = av_image_fill_linesizes(linesize, avctx->pix_fmt, w); - if (ret < 0) - goto fail; - // increase alignment of w for next try (rhs gives the lowest bit set in w) - w += w & ~(w - 1); - - unaligned = 0; - for (i = 0; i < 4; i++) - unaligned |= linesize[i] % pool->stride_align[i]; - } while (unaligned); - - for (i = 0; i < 4; i++) - linesize1[i] = linesize[i]; - ret = av_image_fill_plane_sizes(size, avctx->pix_fmt, h, linesize1); - if (ret < 0) - goto fail; - - for (i = 0; i < 4; i++) { - pool->linesize[i] = linesize[i]; - if (size[i]) { - if (size[i] > INT_MAX - (16 + STRIDE_ALIGN - 1)) { - ret = AVERROR(EINVAL); - goto fail; - } - pool->pools[i] = av_buffer_pool_init(size[i] + 16 + STRIDE_ALIGN - 1, - CONFIG_MEMORY_POISONING ? - NULL : - av_buffer_allocz); - if (!pool->pools[i]) { - ret = AVERROR(ENOMEM); - goto fail; - } - } - } - pool->format = frame->format; - pool->width = frame->width; - pool->height = frame->height; - - break; - } - case AVMEDIA_TYPE_AUDIO: { - ret = av_samples_get_buffer_size(&pool->linesize[0], ch, - frame->nb_samples, frame->format, 0); - if (ret < 0) - goto fail; - - pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL); - if (!pool->pools[0]) { - ret = AVERROR(ENOMEM); - goto fail; - } - - pool->format = frame->format; - pool->planes = planes; - pool->channels = ch; - pool->samples = frame->nb_samples; - break; - } - default: av_assert0(0); - } - - av_buffer_unref(&avctx->internal->pool); - avctx->internal->pool = pool_buf; - - return 0; -fail: - av_buffer_unref(&pool_buf); - return ret; -} - -static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) -{ - FramePool *pool = (FramePool*)avctx->internal->pool->data; - int planes = pool->planes; - int i; - - frame->linesize[0] = pool->linesize[0]; - - if (planes > AV_NUM_DATA_POINTERS) { - frame->extended_data = av_calloc(planes, sizeof(*frame->extended_data)); - frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS; - frame->extended_buf = av_calloc(frame->nb_extended_buf, - sizeof(*frame->extended_buf)); - if (!frame->extended_data || !frame->extended_buf) { - av_freep(&frame->extended_data); - av_freep(&frame->extended_buf); - return AVERROR(ENOMEM); - } - } else { - frame->extended_data = frame->data; - av_assert0(frame->nb_extended_buf == 0); - } - - for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) { - frame->buf[i] = av_buffer_pool_get(pool->pools[0]); - if (!frame->buf[i]) - goto fail; - frame->extended_data[i] = frame->data[i] = frame->buf[i]->data; - } - for (i = 0; i < frame->nb_extended_buf; i++) { - frame->extended_buf[i] = av_buffer_pool_get(pool->pools[0]); - if (!frame->extended_buf[i]) - goto fail; - frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data; - } - - if (avctx->debug & FF_DEBUG_BUFFERS) - av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame); - - return 0; -fail: - av_frame_unref(frame); - return AVERROR(ENOMEM); -} - -static int video_get_buffer(AVCodecContext *s, AVFrame *pic) -{ - FramePool *pool = (FramePool*)s->internal->pool->data; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format); - int i; - - if (pic->data[0] || pic->data[1] || pic->data[2] || pic->data[3]) { - av_log(s, AV_LOG_ERROR, "pic->data[*]!=NULL in avcodec_default_get_buffer\n"); - return -1; - } - - if (!desc) { - av_log(s, AV_LOG_ERROR, - "Unable to get pixel format descriptor for format %s\n", - av_get_pix_fmt_name(pic->format)); - return AVERROR(EINVAL); - } - - memset(pic->data, 0, sizeof(pic->data)); - pic->extended_data = pic->data; - - for (i = 0; i < 4 && pool->pools[i]; i++) { - pic->linesize[i] = pool->linesize[i]; - - pic->buf[i] = av_buffer_pool_get(pool->pools[i]); - if (!pic->buf[i]) - goto fail; - - pic->data[i] = pic->buf[i]->data; - } - for (; i < AV_NUM_DATA_POINTERS; i++) { - pic->data[i] = NULL; - pic->linesize[i] = 0; - } - - if (s->debug & FF_DEBUG_BUFFERS) - av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic); - - return 0; -fail: - av_frame_unref(pic); - return AVERROR(ENOMEM); -} - -int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags) -{ - int ret; - - if (avctx->hw_frames_ctx) { - ret = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0); - frame->width = avctx->coded_width; - frame->height = avctx->coded_height; - return ret; - } - - if ((ret = update_frame_pool(avctx, frame)) < 0) - return ret; - - switch (avctx->codec_type) { - case AVMEDIA_TYPE_VIDEO: - return video_get_buffer(avctx, frame); - case AVMEDIA_TYPE_AUDIO: - return audio_get_buffer(avctx, frame); - default: - return -1; - } -} - static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) { size_t size; diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c new file mode 100644 index 0000000000..3e45a0479f --- /dev/null +++ b/libavcodec/get_buffer.c @@ -0,0 +1,312 @@ +/* + * The default get_buffer2() implementation + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/avassert.h" +#include "libavutil/avutil.h" +#include "libavutil/buffer.h" +#include "libavutil/frame.h" +#include "libavutil/hwcontext.h" +#include "libavutil/imgutils.h" +#include "libavutil/mem.h" +#include "libavutil/samplefmt.h" +#include "libavutil/version.h" + +#include "avcodec.h" +#include "internal.h" + +typedef struct FramePool { + /** + * Pools for each data plane. For audio all the planes have the same size, + * so only pools[0] is used. + */ + AVBufferPool *pools[4]; + + /* + * Pool parameters + */ + int format; + int width, height; + int stride_align[AV_NUM_DATA_POINTERS]; + int linesize[4]; + int planes; + int channels; + int samples; +} FramePool; + +static void frame_pool_free(void *opaque, uint8_t *data) +{ + FramePool *pool = (FramePool*)data; + int i; + + for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++) + av_buffer_pool_uninit(&pool->pools[i]); + + av_freep(&data); +} + +static AVBufferRef *frame_pool_alloc(void) +{ + FramePool *pool = av_mallocz(sizeof(*pool)); + AVBufferRef *buf; + + if (!pool) + return NULL; + + buf = av_buffer_create((uint8_t*)pool, sizeof(*pool), + frame_pool_free, NULL, 0); + if (!buf) { + av_freep(&pool); + return NULL; + } + + return buf; +} + +static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) +{ + FramePool *pool = avctx->internal->pool ? + (FramePool*)avctx->internal->pool->data : NULL; + AVBufferRef *pool_buf; + int i, ret, ch, planes; + + if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { + int planar = av_sample_fmt_is_planar(frame->format); + ch = frame->ch_layout.nb_channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!ch) + ch = frame->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + planes = planar ? ch : 1; + } + + if (pool && pool->format == frame->format) { + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && + pool->width == frame->width && pool->height == frame->height) + return 0; + if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && pool->planes == planes && + pool->channels == ch && frame->nb_samples == pool->samples) + return 0; + } + + pool_buf = frame_pool_alloc(); + if (!pool_buf) + return AVERROR(ENOMEM); + pool = (FramePool*)pool_buf->data; + + switch (avctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: { + int linesize[4]; + int w = frame->width; + int h = frame->height; + int unaligned; + ptrdiff_t linesize1[4]; + size_t size[4]; + + avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align); + + do { + // NOTE: do not align linesizes individually, this breaks e.g. assumptions + // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 + ret = av_image_fill_linesizes(linesize, avctx->pix_fmt, w); + if (ret < 0) + goto fail; + // increase alignment of w for next try (rhs gives the lowest bit set in w) + w += w & ~(w - 1); + + unaligned = 0; + for (i = 0; i < 4; i++) + unaligned |= linesize[i] % pool->stride_align[i]; + } while (unaligned); + + for (i = 0; i < 4; i++) + linesize1[i] = linesize[i]; + ret = av_image_fill_plane_sizes(size, avctx->pix_fmt, h, linesize1); + if (ret < 0) + goto fail; + + for (i = 0; i < 4; i++) { + pool->linesize[i] = linesize[i]; + if (size[i]) { + if (size[i] > INT_MAX - (16 + STRIDE_ALIGN - 1)) { + ret = AVERROR(EINVAL); + goto fail; + } + pool->pools[i] = av_buffer_pool_init(size[i] + 16 + STRIDE_ALIGN - 1, + CONFIG_MEMORY_POISONING ? + NULL : + av_buffer_allocz); + if (!pool->pools[i]) { + ret = AVERROR(ENOMEM); + goto fail; + } + } + } + pool->format = frame->format; + pool->width = frame->width; + pool->height = frame->height; + + break; + } + case AVMEDIA_TYPE_AUDIO: { + ret = av_samples_get_buffer_size(&pool->linesize[0], ch, + frame->nb_samples, frame->format, 0); + if (ret < 0) + goto fail; + + pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL); + if (!pool->pools[0]) { + ret = AVERROR(ENOMEM); + goto fail; + } + + pool->format = frame->format; + pool->planes = planes; + pool->channels = ch; + pool->samples = frame->nb_samples; + break; + } + default: av_assert0(0); + } + + av_buffer_unref(&avctx->internal->pool); + avctx->internal->pool = pool_buf; + + return 0; +fail: + av_buffer_unref(&pool_buf); + return ret; +} + +static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) +{ + FramePool *pool = (FramePool*)avctx->internal->pool->data; + int planes = pool->planes; + int i; + + frame->linesize[0] = pool->linesize[0]; + + if (planes > AV_NUM_DATA_POINTERS) { + frame->extended_data = av_calloc(planes, sizeof(*frame->extended_data)); + frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS; + frame->extended_buf = av_calloc(frame->nb_extended_buf, + sizeof(*frame->extended_buf)); + if (!frame->extended_data || !frame->extended_buf) { + av_freep(&frame->extended_data); + av_freep(&frame->extended_buf); + return AVERROR(ENOMEM); + } + } else { + frame->extended_data = frame->data; + av_assert0(frame->nb_extended_buf == 0); + } + + for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) { + frame->buf[i] = av_buffer_pool_get(pool->pools[0]); + if (!frame->buf[i]) + goto fail; + frame->extended_data[i] = frame->data[i] = frame->buf[i]->data; + } + for (i = 0; i < frame->nb_extended_buf; i++) { + frame->extended_buf[i] = av_buffer_pool_get(pool->pools[0]); + if (!frame->extended_buf[i]) + goto fail; + frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data; + } + + if (avctx->debug & FF_DEBUG_BUFFERS) + av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame); + + return 0; +fail: + av_frame_unref(frame); + return AVERROR(ENOMEM); +} + +static int video_get_buffer(AVCodecContext *s, AVFrame *pic) +{ + FramePool *pool = (FramePool*)s->internal->pool->data; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format); + int i; + + if (pic->data[0] || pic->data[1] || pic->data[2] || pic->data[3]) { + av_log(s, AV_LOG_ERROR, "pic->data[*]!=NULL in avcodec_default_get_buffer\n"); + return -1; + } + + if (!desc) { + av_log(s, AV_LOG_ERROR, + "Unable to get pixel format descriptor for format %s\n", + av_get_pix_fmt_name(pic->format)); + return AVERROR(EINVAL); + } + + memset(pic->data, 0, sizeof(pic->data)); + pic->extended_data = pic->data; + + for (i = 0; i < 4 && pool->pools[i]; i++) { + pic->linesize[i] = pool->linesize[i]; + + pic->buf[i] = av_buffer_pool_get(pool->pools[i]); + if (!pic->buf[i]) + goto fail; + + pic->data[i] = pic->buf[i]->data; + } + for (; i < AV_NUM_DATA_POINTERS; i++) { + pic->data[i] = NULL; + pic->linesize[i] = 0; + } + + if (s->debug & FF_DEBUG_BUFFERS) + av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic); + + return 0; +fail: + av_frame_unref(pic); + return AVERROR(ENOMEM); +} + +int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags) +{ + int ret; + + if (avctx->hw_frames_ctx) { + ret = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0); + frame->width = avctx->coded_width; + frame->height = avctx->coded_height; + return ret; + } + + if ((ret = update_frame_pool(avctx, frame)) < 0) + return ret; + + switch (avctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: + return video_get_buffer(avctx, frame); + case AVMEDIA_TYPE_AUDIO: + return audio_get_buffer(avctx, frame); + default: + return -1; + } +} From patchwork Wed Mar 23 15:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34938 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922147uaj; Wed, 23 Mar 2022 08:58:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQYCsT65BYB27XFDS1cpoCJzg4B7+Y/ESFU2AJu2V/VcaofVJJwQqIPxAX74y8+wXV2wQD X-Received: by 2002:a17:907:da6:b0:6e0:c59:f3ad with SMTP id go38-20020a1709070da600b006e00c59f3admr718419ejc.85.1648051088466; Wed, 23 Mar 2022 08:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051088; cv=none; d=google.com; s=arc-20160816; b=fDlwztN9jPCLHeRSrctLFz/ManIhehZwikNG1sbPSVKKOFICTydbBUrqtFz+1OzWWS 7Xlf+Ab7kh5ZkK45yp+taQvm2KkYiunU8cA726MKKCeCguEebMZdbdsYgonA8/2kvaZc 5t7kGzhkyWhwe0GMCNDhKViu9EAYeVUIikm2FrR4RGfayyykTQUl7UGXqN9R/wAWgQt4 vzYn21OKHqrROqieuRe8xsPFG/kGDHaxWMFkqPdH5vT5nPK+Vd9ULshmFkSvbm4JTsTj CGVdECvorwyqHaE7n6H6cC0v3C436aZR2qVv3/4ubHPej7btrWRrHom+JJWsjja2oC8k yP6Q== 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=S813cgAkXmMcdk87/UOkQVGcu+Z2y6wSnthtWH28cus=; b=qz3YYrdHiucrK9rlMGOl01Snhpv2ViqX1bl0lxLvB13/zk8xPFiqlQ4XyRd4lcKzRu LGkRKnVkbmCGsGk7V/bTQNTeBaGEdNwfgt5tEU/Is16O/avhQOoMS6a7Y5Uv5pMiofdS pbccmfD5UKpe4zLapBZxqmCk1Zn7PmhXgLn41Zuq8nKytEgMQSOzg+kfePYyKJVRlV3D G/GECLfjO3gb4hOslnFnlFEFoxXHsEprRIe6ouyQkmJS5mDxD+IhM+cHdK5QESPu6eSZ 5/+XxDgyzHIUAZ02liZNvj2/u6kyxrGwnR+j7jNXToxF7HDRHislL4qCWMemCg6faiR0 EMLA== 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 hr39-20020a1709073fa700b006df76385d16si14190616ejc.438.2022.03.23.08.58.08; Wed, 23 Mar 2022 08:58:08 -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 8642368B185; Wed, 23 Mar 2022 17:57:44 +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 0E69768B03F for ; Wed, 23 Mar 2022 17:57:37 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 862DC2400F5 for ; Wed, 23 Mar 2022 16:57:36 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id x1YIMnopV-Qz 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 995172404FE for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 9C28A3A06CD; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:16 +0100 Message-Id: <20220323155720.20017-4-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 4/8] lavc/snow: only allocate mconly_picture for decoding 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: mnV05FoMKQPE It is not used in the encoder. --- libavcodec/snow.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 0a500695ce..1224b95491 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -513,20 +513,23 @@ int ff_snow_common_init_after_header(AVCodecContext *avctx) { int ret, emu_buf_size; if(!s->scratchbuf) { - if ((ret = ff_get_buffer(s->avctx, s->mconly_picture, - AV_GET_BUFFER_FLAG_REF)) < 0) - return ret; + if (av_codec_is_decoder(avctx->codec)) { + if ((ret = ff_get_buffer(s->avctx, s->mconly_picture, + AV_GET_BUFFER_FLAG_REF)) < 0) + return ret; + + if (s->mconly_picture->format != avctx->pix_fmt) { + av_log(avctx, AV_LOG_ERROR, "pixel format changed\n"); + return AVERROR_INVALIDDATA; + } + } + emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1); if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf, FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) || !FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size)) return AVERROR(ENOMEM); } - if(s->mconly_picture->format != avctx->pix_fmt) { - av_log(avctx, AV_LOG_ERROR, "pixel format changed\n"); - return AVERROR_INVALIDDATA; - } - for(plane_index=0; plane_index < s->nb_planes; plane_index++){ int w= s->avctx->width; int h= s->avctx->height; From patchwork Wed Mar 23 15:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34937 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922109uaj; Wed, 23 Mar 2022 08:57:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPoy/loGNdoaTR3DagFBFh/LBVFj33yOVOZzJ3R+svHpGuEa8BvbiTZLVBU4YqP+wdoVSb X-Received: by 2002:a17:906:7948:b0:6da:64ed:178e with SMTP id l8-20020a170906794800b006da64ed178emr691048ejo.523.1648051078131; Wed, 23 Mar 2022 08:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051078; cv=none; d=google.com; s=arc-20160816; b=RB/Fuf44RorAQlcAT9Sl1Qgccduj95CpLAAsOGE0Ou38tUAdsJ791zbJPWPyA2+lCE mWK4JKMw1xWHie+Chq1NzffkPzcaYD+VUmgEO8NDlYSS3pJhcWuKh9BM9r0zh04euoNN N2CXWeHRQLW3V1Kp736+oFZAo5soGd93+VxRkKaymupysYDsbc8IMi90eQXwZF5dqExX 77MVs0QwVnThAIASy3InIJf1Si7yjQJQKikfveUPOkt+5jcR93PveHnUXS3FkgLFbVvT OCv1hWomJk+GwvP7D1fCQbMVOR9LDHAtxZutuKoRtCScuBRLM9Kn9DeArERd4QsKx8O/ RnMA== 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=0FUClB5eB97YWMIy0Xfc6GgeL5UquGQyuuaVySjbfkE=; b=gujmfXiN5ALmOV1aR2O0VXHf29qn19MrsfQ5f3FxgLIvnGZ558FhBx4b2PsyYBeNGF dPxKwGNW4mOP7nrlwrAiBKp0nX4F3kS56/KHp+HtTHUMC13xgtWEeyz4ZP4L0m4b3FNM 5FNh0S1r0IJgnVjsXJ8Nyzg+fqwgnJqx7YWF+ar5p0oIYztN2JHazz8c/Vu+Z5S1FmGs YBNlKSmPgpx78zPzKy6rGtQGX0p3ZOD62ZNAJ3buLzFpfOigpPaZrJJjxTjYD1pzAsrn g8UYnOWNBJIiCb6m+4gE1WZ/Axn9L2JnvMZhB8lnkV60dJcYd9AluFs6vbzJus2iKYVF 0WRg== 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 e28-20020a170906749c00b006df76385bafsi12368710ejl.79.2022.03.23.08.57.57; Wed, 23 Mar 2022 08:57:58 -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 990FD68B14F; Wed, 23 Mar 2022 17:57:43 +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 8C1A968B03F for ; Wed, 23 Mar 2022 17:57:36 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0C39E240179 for ; Wed, 23 Mar 2022 16:57:36 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0slPaajUt6s2 for ; Wed, 23 Mar 2022 16:57:34 +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 881312400F5 for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id A00263A06EC; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:17 +0100 Message-Id: <20220323155720.20017-5-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 5/8] lavc/encode: add an encoder-specific get_buffer() variant 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: heIANPa9hyyo Several encoders (roqvideo, svq1, snow, and the mpegvideo family) currently call ff_get_buffer(). However this function is written assuming it is called by a decoder. Though nothing has been obviously broken by this until now, this may change in the future. To avoid potential future issues, introduce a simple encode-specific wrapper around avcodec_default_get_buffer2() and enforce its use in encoders. --- libavcodec/decode.c | 2 ++ libavcodec/encode.c | 34 ++++++++++++++++++++++++++++++++++ libavcodec/encode.h | 5 +++++ libavcodec/mpegpicture.c | 16 +++++++++------- libavcodec/roqvideoenc.c | 4 ++-- libavcodec/snow.c | 8 ++++++-- libavcodec/svq1enc.c | 4 ++-- 7 files changed, 60 insertions(+), 13 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index fffad5f700..3733e6d4b8 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1405,6 +1405,8 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) int override_dimensions = 1; int ret; + av_assert0(av_codec_is_decoder(avctx->codec)); + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN || (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) { diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 837ffaa40d..ec8d06d068 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -572,3 +572,37 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } + +int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame) +{ + int ret; + + switch (avctx->codec->type) { + case AVMEDIA_TYPE_VIDEO: + frame->format = avctx->pix_fmt; + if (frame->width <= 0 || frame->height <= 0) { + frame->width = FFMAX(avctx->width, avctx->coded_width); + frame->height = FFMAX(avctx->height, avctx->coded_height); + } + + break; + case AVMEDIA_TYPE_AUDIO: + frame->sample_rate = avctx->sample_rate; + frame->format = avctx->sample_fmt; + if (!frame->ch_layout.nb_channels) { + int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); + if (ret < 0) + return ret; + } + break; + } + + ret = avcodec_default_get_buffer2(avctx, frame, 0); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + av_frame_unref(frame); + return ret; + } + + return 0; +} diff --git a/libavcodec/encode.h b/libavcodec/encode.h index 97b3acf9df..b2536bf0f3 100644 --- a/libavcodec/encode.h +++ b/libavcodec/encode.h @@ -44,6 +44,11 @@ int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame); */ int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags); +/** + * Allocate buffers for a frame. Encoder equivalent to ff_get_buffer(). + */ +int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame); + /** * Check AVPacket size and allocate data. * diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index 681ccc2b82..aaa1df0bd8 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -26,6 +26,7 @@ #include "libavutil/imgutils.h" #include "avcodec.h" +#include "encode.h" #include "motion_est.h" #include "mpegpicture.h" #include "mpegutils.h" @@ -123,14 +124,15 @@ static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, int r, ret; pic->tf.f = pic->f; - if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && - avctx->codec_id != AV_CODEC_ID_VC1IMAGE && - avctx->codec_id != AV_CODEC_ID_MSS2) { - if (edges_needed) { - pic->f->width = avctx->width + 2 * EDGE_WIDTH; - pic->f->height = avctx->height + 2 * EDGE_WIDTH; - } + if (edges_needed) { + pic->f->width = avctx->width + 2 * EDGE_WIDTH; + pic->f->height = avctx->height + 2 * EDGE_WIDTH; + + r = ff_encode_alloc_frame(avctx, pic->f); + } else if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && + avctx->codec_id != AV_CODEC_ID_VC1IMAGE && + avctx->codec_id != AV_CODEC_ID_MSS2) { r = ff_thread_get_ext_buffer(avctx, &pic->tf, pic->reference ? AV_GET_BUFFER_FLAG_REF : 0); } else { diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c index ef7861088d..95db514140 100644 --- a/libavcodec/roqvideoenc.c +++ b/libavcodec/roqvideoenc.c @@ -1081,8 +1081,8 @@ static int roq_encode_frame(AVCodecContext *avctx, AVPacket *pkt, if (enc->first_frame) { /* Alloc memory for the reconstruction data (we must know the stride for that) */ - if ((ret = ff_get_buffer(avctx, roq->current_frame, 0)) < 0 || - (ret = ff_get_buffer(avctx, roq->last_frame, 0)) < 0) + if ((ret = ff_encode_alloc_frame(avctx, roq->current_frame)) < 0 || + (ret = ff_encode_alloc_frame(avctx, roq->last_frame )) < 0) return ret; /* Before the first video frame, write a "video info" chunk */ diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 1224b95491..bc0d9a8983 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -23,6 +23,7 @@ #include "libavutil/opt.h" #include "libavutil/thread.h" #include "avcodec.h" +#include "encode.h" #include "me_cmp.h" #include "snow_dwt.h" #include "internal.h" @@ -76,8 +77,11 @@ int ff_snow_get_buffer(SnowContext *s, AVFrame *frame) if (edges_needed) { frame->width += 2 * EDGE_WIDTH; frame->height += 2 * EDGE_WIDTH; - } - if ((ret = ff_get_buffer(s->avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) + + ret = ff_encode_alloc_frame(s->avctx, frame); + } else + ret = ff_get_buffer(s->avctx, frame, AV_GET_BUFFER_FLAG_REF); + if (ret < 0) return ret; if (edges_needed) { for (i = 0; frame->data[i]; i++) { diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index 706bc2e42e..cb0d0308fc 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -595,12 +595,12 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, } if (!s->current_picture->data[0]) { - if ((ret = ff_get_buffer(avctx, s->current_picture, 0)) < 0) { + if ((ret = ff_encode_alloc_frame(avctx, s->current_picture)) < 0) { return ret; } } if (!s->last_picture->data[0]) { - ret = ff_get_buffer(avctx, s->last_picture, 0); + ret = ff_encode_alloc_frame(avctx, s->last_picture); if (ret < 0) return ret; } From patchwork Wed Mar 23 15:57:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34940 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922223uaj; Wed, 23 Mar 2022 08:58:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx1lWf2tJKE5VTlR8lkU51r1QvbsTkl12ZmT1NU1Ylw0ALiUVKkMtYId6fvZYK92GbmRPZ X-Received: by 2002:a17:906:99c2:b0:6d7:4a6a:e35d with SMTP id s2-20020a17090699c200b006d74a6ae35dmr651413ejn.633.1648051112365; Wed, 23 Mar 2022 08:58:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051112; cv=none; d=google.com; s=arc-20160816; b=ziJcgZRib+yN6+A00ek8k4aIHOXnzNjxT8+y9hhZ0jd9yS+ca6VKkeEMUu7g+NGqiB FLSoTKB2pvalLltjRW4+QPyLra87FyE95UVlr7yYqnwcBYty4bT60Zxu9znXq0qjpIZX Pw1WlR6g89F/t9SzuAlmSG3YApW/wKZLkqFoS3o1Aa++78Xdkr6rXGkKqmU/P2Z8pz8B 8cSTfLhu3aDZD+58+CCA07sJbuPdnydYKyPm0zTH9u8sbSSm+rwsFZ7L7KUzCnNYMRnK G+/hGWKcFJlGKq+TP2v9fIlK8CJUF9j4oL7sJXJF2Ho7wo8v/xeu9vdZQsCaRik+riha D4LQ== 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=QmlrSRylJnMYzTM+G7ysz8tIZmVOsKrdnC69ZY5ruQo=; b=idFUuLwpxkN8fJr85wxHm8cFMZHyi2oOK4jby7TRS/6w9LWY/6I4cp1VoobXrkO8NX Z0l4lpsic+dXIoEwzj0+0e8knw+yIZLXxdk1ZeXx7eg3NYNVdYOleIn2gzIPY4wRKEr5 5LWpSWGuCWNyU+cyxAHwH/Rl6JEBw5jKIKy1O1RteQ8moNOAQE3Cik/I4mpk9A+E9GxR Yg860vsvKWNyy3heGFRwm6DwDc8MKrV8HNgB0bwI2BOgmhYcabX9bxfcxSmEYKUQLON8 W/IiwW45W4ltjofIiv9i4GTZKwPTqOXgUpasxsqUDgHqWFt+51fMJHsYYgkUfx0cLFit npZA== 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 ss24-20020a170907c01800b006dfd81499c7si9414166ejc.828.2022.03.23.08.58.31; Wed, 23 Mar 2022 08:58:32 -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 4009168B167; Wed, 23 Mar 2022 17:57:46 +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 11A7068B15A for ; Wed, 23 Mar 2022 17:57:38 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8235424017E 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 UgPqCYMOfApd for ; Wed, 23 Mar 2022 16:57:37 +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 B98D2240506 for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id A37F93A0763; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:18 +0100 Message-Id: <20220323155720.20017-6-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 6/8] lavc/avcodec: only allocate decoding packets for decoders 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: 6bdq0Bwc5q4s --- libavcodec/avcodec.c | 7 +------ libavcodec/decode.c | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c7daa385e7..5fd988a41c 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -180,12 +180,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->buffer_frame = av_frame_alloc(); avci->buffer_pkt = av_packet_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->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { + if (!avci->buffer_frame || !avci->buffer_pkt) { ret = AVERROR(ENOMEM); goto free_and_end; } diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 3733e6d4b8..bb3857afd9 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1527,6 +1527,7 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) int ff_decode_preinit(AVCodecContext *avctx) { + AVCodecInternal *avci = avctx->internal; int ret = 0; /* if the decoder init function was already called previously, @@ -1605,6 +1606,13 @@ FF_ENABLE_DEPRECATION_WARNINGS avctx->export_side_data |= AV_CODEC_EXPORT_DATA_MVS; } + 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->in_pkt || !avci->last_pkt_props || !avci->pkt_props) + return AVERROR(ENOMEM); + ret = decode_bsfs_init(avctx); if (ret < 0) return ret; From patchwork Wed Mar 23 15:57:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34942 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922330uaj; Wed, 23 Mar 2022 08:58:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMG2K7uq1zP2U9oK73iwAXnnlIwpUNLdPp0nEPLmdMTzVupDXiP1S2JCNJfHX0nbreox7/ X-Received: by 2002:a17:906:c0d6:b0:6ca:457e:f1b7 with SMTP id bn22-20020a170906c0d600b006ca457ef1b7mr694152ejb.399.1648051137557; Wed, 23 Mar 2022 08:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051137; cv=none; d=google.com; s=arc-20160816; b=LFgDuKo2uEMKCKHkmQKoIbHJmsmZE/5RAgBr3+qOdgJPjOEAKIUV+MsA98iDT14uUD GW1D9gywzJd2aLNu92yDDWo4xwJFw802WRIEmID5e5ieTl/GvP2XAGr4kzZGI6JSbxIl E/xZMQLCZf5nQfwPSnhrYuRCHNC/0jbqR7WSNkHDksA3Bvhhb6duNzmo86hAO5D5Nkhw uY2h2OwcqoOhFrGsSTtD5uS2ceNWmUWkHDh6CIgghtB2m9/HRkHR6gctbarHV4mtPtPx AJKI/LCOnboCiSSIZwe73M23B4KSPJru9uCNYA6Qx2Lg0FyFefTii7tf4mDlKjp+0Jm3 3wTA== 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=Xc23PERtwaM6tfuQp5Etwe3RaYyHI8v2S5Vt6BAvJxw=; b=zd1xGGvXyL9wTUip7EYe4ZjrciYHwXhfSJAbAgfAE/2Z6FzHKjLP1MfUmaBS+5s5f/ XxKD0u2PrSlo8jnha7RfyOzLmc7004/0ztrqU7Y5xT+JjbxugvnpQxW7TksTMdmbb8H7 jrRLoD4skmJsRU+8SpfupNX13P5HnfvdqcufNocGNQBS30eWEHlyZcwNgty/7mUCKZ4G GiXLZSJSkIN3Zs/OKasfP9neX8FUBhEoVtt2KfQPgomvw9O/cJ9BDOMZDjZualOpByWO iC+3KXKA8Als/w/T5eBzoNKyzeuPwcZVOKQaj1DXM18Hgln9VQxzIhd79zcf3PEUbCHg M9Jg== 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 p26-20020a17090628da00b006df76385e94si12472193ejd.820.2022.03.23.08.58.54; Wed, 23 Mar 2022 08:58:57 -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 1E62A68B159; Wed, 23 Mar 2022 17:57:49 +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 98C5A68B1A3 for ; Wed, 23 Mar 2022 17:57:41 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0745724017C for ; Wed, 23 Mar 2022 16:57:38 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id qvvbEPIS0lLE for ; Wed, 23 Mar 2022 16:57:37 +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 BC4C9240507 for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id A6F993A07AE; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:19 +0100 Message-Id: <20220323155720.20017-7-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 7/8] lavc/pthread_frame: do not copy AVCodecInternal contents 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: kUtHrqNCm7ZG None of its fields have meaningful values at that point that would need to be copied to frame thread workers. --- libavcodec/pthread_frame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index aa971bd74d..4ae1c02f62 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -791,7 +791,7 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, p->parent = fctx; p->avctx = copy; - copy->internal = av_memdup(avctx->internal, sizeof(*avctx->internal)); + copy->internal = av_mallocz(sizeof(*copy->internal)); if (!copy->internal) return AVERROR(ENOMEM); copy->internal->thread_ctx = p; From patchwork Wed Mar 23 15:57:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 34943 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp922358uaj; Wed, 23 Mar 2022 08:59:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt5eH7+smMyFM+xefZFq9xrP8zDQMoNhriXO4Pz2QbHzcu67hINTfqDqdOYCYsrDWf0BJe X-Received: by 2002:a17:907:2d06:b0:6e0:2ec:c7bd with SMTP id gs6-20020a1709072d0600b006e002ecc7bdmr762688ejc.656.1648051144677; Wed, 23 Mar 2022 08:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648051144; cv=none; d=google.com; s=arc-20160816; b=rzT4FKKnm4VThsC7TY05o3XevNnl47RsHwWfxi6mOIic8S/sllaCFSOyOkjfhhT3VS saiI9PRfEUa4oZaMjdcRbxCrjAb65BQw/w8C0AmBAN15hmA8vJDYh6frolJ1XQgkBedD 5y39Rc8bzG2WxJ0IZmUSWO3xOqtz9bYpoAXtpYnJytB+IkLtSlMWhTHvqTf5qA126BvH I8mvItEQjS45m3FF1ghYuBlhh/SFoSHjipQdCzsCDO8GeEW8H4TpOQgvEuRlYQJeirhL ezm1CCXZ3wgTwiL5gGTiXqCMpsxHXcwmQ5XrE1K2YG9wOAs4aeRz12cziNZ/rFFgZGkP stuA== 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=ofZU3OzFH1mb34JHZYyJX4zkD4/6jMqdnYrKTOm5i00=; b=LQd1aU/5ShQYLU88HlpeQ5FPyrkRS4EurKDt9JG+MT7b/ZTByXkW6MKoU9k8dYlvR2 zwgwkv9OGEB4FdZEEMj5fnoBNjcGFU4XqGa0EkqFWSW6CuM6OScyg7HiPnXZBh4XKfbT YPsUOPXBXzKd+SPyjcl97tHhrVqIx6VMWX1s/Y7FJwUohqxVc7tzuoMeTEkhSoMMmOEE VoLWSVFMxKEntv7+PBBVJiFTJ6Nzb5no+7CFbQ5p542kbUZ1mdRck94eibVnaY7Rq2pG tjuxTC/hPbYfCduGV7pxWJYcLNoc6v9Ve2b4iKDOwBmT8AkGlpkZXvaLnHqmcqOBzd8o fDng== 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 e11-20020a50d4cb000000b0041918e1f694si12543865edj.498.2022.03.23.08.59.04; Wed, 23 Mar 2022 08:59:04 -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 2081B68B1DF; Wed, 23 Mar 2022 17:57:50 +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 C497068B192 for ; Wed, 23 Mar 2022 17:57:41 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5A731240507 for ; Wed, 23 Mar 2022 16:57:38 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cRzdYvPew3yp for ; Wed, 23 Mar 2022 16:57:37 +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 BD98024050B for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id AA77B3A0836; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:20 +0100 Message-Id: <20220323155720.20017-8-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 8/8] lavc: drop a confusing message about "thread emulation" 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: qtDbH5+v+wat There is no such thing. --- libavcodec/avcodec.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 5fd988a41c..dec09476cc 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -309,9 +309,6 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ret < 0) goto free_and_end; - if (!HAVE_THREADS) - av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n"); - if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) { ret = ff_frame_thread_encoder_init(avctx); if (ret < 0)