From patchwork Sun Feb 20 18:07:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 34417 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp2729381nkx; Sun, 20 Feb 2022 10:06:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgh+KK64fzb96Jy0Ud8hlEt6edir+XHBTBmuF4tUVfRguzCMdtaBfv6Gf9OK23AAm0Ijxi X-Received: by 2002:a05:6402:11d0:b0:412:cbf3:d87d with SMTP id j16-20020a05640211d000b00412cbf3d87dmr12237649edw.300.1645380390543; Sun, 20 Feb 2022 10:06:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645380390; cv=none; d=google.com; s=arc-20160816; b=noPvWbkaWpt7b6VQwPq+Vk8/KU8d4OwVGP+OPKytmnv805i7RYO/CiZsP4zxhDVukL ZmTLGlkP/SNgdhQD2zpZVdTmIzRH2fqev16qCqijqJwGvQQOBYh3q5mIHXq4HGfIZMiT wK3LLd+dK4X2MBVz6iuO08OHc5KLGovXmZyP7Df60MB/49+iBItmbQatCPByo4tWTMHm cMlasy+2zHKjLIe5ogvQkat2/5nME5OZFTcAleA1E3shJyq65nHIwFy/M3QQDxqzXMTE M63L5oDHuhpPfaNr8tFYtaBgmvfTd7iQVlZrUvGEjKM3dYGSXCrXxHBKOaV3hvv+mZ2N Ut+g== 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 :dkim-signature:delivered-to; bh=qHpr6kVeZ0c3eMrxa9LaURym50ppjnfOSKvbq7Zk5Ng=; b=NtpfNscxP3QWHc3YA7ooCbFkz0XP4RmT+fbnuZHQr01S+U3c7kiNbl9DpzqeAZWnXK rfJRZL9cXlpi/FznRKw/0liuwxewAPru9Ep6EDOeySfGc+9ep4CWda3eCaoY0NkxXvhZ Vv8M6M1Wde0Hh6/XNtSplaOyi1ki6+0MjEcWozP4c9CDoJzDy1IFm8SRxrq3yjcQfIiV WhoIGumADQ6Ggt10J97eFyfqvkMlvcJgxfxuaZ9uOMNmesfhpmJyHiqCuKObRl1XL8xm bTbgRWvfEJ3ONiynMhZ+ec6vxRj56NEzLF1grHwLcHYiZGGwR/6UIAgSiWI7nHg3d6PF SntQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=QEfB4Pti; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a19si9254398eds.21.2022.02.20.10.06.29; Sun, 20 Feb 2022 10:06:30 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=QEfB4Pti; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D3AA268B0EE; Sun, 20 Feb 2022 20:06:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9398368A6CD for ; Sun, 20 Feb 2022 20:06:19 +0200 (EET) Received: by mail-ed1-f41.google.com with SMTP id cm8so15283284edb.3 for ; Sun, 20 Feb 2022 10:06:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Wm3m7KtTrd86LAgBcrx8qT79MYy+A3YdIVvlKCPBOs=; b=QEfB4PtiF62cqNaoebY9N8DTRuI47hUm+5q9+s0WG4+e/hF/rvUEdv9Ry8K/2o9cIU uLflDKyaGJjYvFSFaFkrkKeFfY7GVB7Mm1ipqSeFbTvW/fkFGBHu/x5X2EMFTQwvnVL2 JocD+zsOXrKcfHqsOQbk6QwWzmuyTL/561UXkIDisiOyME5ffAoqooSejWq8DKXl9qd2 EbD+6wJYcMKidH82WGkxA6+amMHhD03mG+lsiLw9eyLH/dhKLIi/Uc6BMDStbiPV1j+9 A8oZuloexhsCYvrZHp2R1EVjQSbUeYY2kA5NToqL63RG14N3qU/AR4VbjIsUVe6bKmzS Q49g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Wm3m7KtTrd86LAgBcrx8qT79MYy+A3YdIVvlKCPBOs=; b=vOekhnIJ6mWGsCJ88xOCCx/fjSmugNAqs9AlHPbjlIH/mReo0+bEuC8I4lRws2qw/0 W5qe0DSSsRra7dGdgiG4uN3yvMjU+32qV4T/wGjUHe/fyO4LcXBjHqCh12iUDbwcr37w 2yVUFG9KQHBlTBpOeH6gpTluox1etwPUz9Ov+GLOcIetfGOhY1PBJqoSJHSC34Eb5K/K F5CeupnNXi2uOOsruCDiBhLLQoDQZQhtlAJIS5XKfQanJU80XUHCm71Bn8NhNy4BhdK4 jZEzMfSzcIOM118DigReOYjaiF5Ou+VX463Ud7S5RTnR/99JBl78L0UVko4QN+L22P5c JB4Q== X-Gm-Message-State: AOAM530ht1P5EwlUAN2r6dSJjbHFc9MyIh0kwnyQVWpZmYqT4C7uZ5DX BBeFH6aOPmfFCTOAsCzME4LsMViKams= X-Received: by 2002:aa7:d403:0:b0:40f:739c:cbae with SMTP id z3-20020aa7d403000000b0040f739ccbaemr18265298edq.267.1645380379036; Sun, 20 Feb 2022 10:06:19 -0800 (PST) Received: from localhost.localdomain ([95.168.120.42]) by smtp.gmail.com with ESMTPSA id eg42sm5700618edb.79.2022.02.20.10.06.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Feb 2022 10:06:18 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 19:07:47 +0100 Message-Id: <20220220180747.291489-1-onemda@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/framepool: fix alignment requirements for audio and video filters 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: EN9krnEgb2N9 Signed-off-by: Paul B Mahol --- libavfilter/audio.c | 11 +++++------ libavfilter/framepool.c | 18 ++++++++---------- libavfilter/video.c | 11 +++++------ 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index cebc9709dd..a0408226a3 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -22,15 +22,13 @@ #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" +#include "libavutil/cpu.h" #include "audio.h" #include "avfilter.h" #include "framepool.h" #include "internal.h" -#define BUFFER_ALIGN 0 - - AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples) { return ff_get_audio_buffer(link->dst->outputs[0], nb_samples); @@ -41,12 +39,13 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) AVFrame *frame = NULL; int channels = link->channels; int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout); + int align = av_cpu_max_align(); av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels); if (!link->frame_pool) { link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, - nb_samples, link->format, BUFFER_ALIGN); + nb_samples, link->format, align); if (!link->frame_pool) return NULL; } else { @@ -62,11 +61,11 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) } if (pool_channels != channels || pool_nb_samples < nb_samples || - pool_format != link->format || pool_align != BUFFER_ALIGN) { + pool_format != link->format || pool_align != align) { ff_frame_pool_uninit((FFFramePool **)&link->frame_pool); link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, - nb_samples, link->format, BUFFER_ALIGN); + nb_samples, link->format, align); if (!link->frame_pool) return NULL; } diff --git a/libavfilter/framepool.c b/libavfilter/framepool.c index aab408d355..aaf1642b4f 100644 --- a/libavfilter/framepool.c +++ b/libavfilter/framepool.c @@ -76,15 +76,13 @@ FFFramePool *ff_frame_pool_video_init(AVBufferRef* (*alloc)(size_t size), } if (!pool->linesize[0]) { - for(i = 1; i <= align; i += i) { - ret = av_image_fill_linesizes(pool->linesize, pool->format, - FFALIGN(pool->width, i)); - if (ret < 0) { - goto fail; - } - if (!(pool->linesize[0] & (pool->align - 1))) - break; + ret = av_image_fill_linesizes(pool->linesize, pool->format, + FFALIGN(pool->width, align)); + if (ret < 0) { + goto fail; } + if ((pool->linesize[0] & (pool->align - 1))) + goto fail; for (i = 0; i < 4 && pool->linesize[i]; i++) { pool->linesize[i] = FFALIGN(pool->linesize[i], pool->align); @@ -92,11 +90,11 @@ FFFramePool *ff_frame_pool_video_init(AVBufferRef* (*alloc)(size_t size), } for (i = 0; i < 4 && pool->linesize[i]; i++) { - int h = FFALIGN(pool->height, 32); + int h = pool->height; if (i == 1 || i == 2) h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h); - pool->pools[i] = av_buffer_pool_init(pool->linesize[i] * h + 16 + 16 - 0, + pool->pools[i] = av_buffer_pool_init(pool->linesize[i] * h, alloc); if (!pool->pools[i]) goto fail; diff --git a/libavfilter/video.c b/libavfilter/video.c index 7ef04144e4..fa3d588044 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -24,6 +24,7 @@ #include #include "libavutil/buffer.h" +#include "libavutil/cpu.h" #include "libavutil/hwcontext.h" #include "libavutil/imgutils.h" @@ -32,9 +33,6 @@ #include "internal.h" #include "video.h" -#define BUFFER_ALIGN 32 - - AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h) { return ff_get_video_buffer(link->dst->outputs[0], w, h); @@ -46,6 +44,7 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) int pool_width = 0; int pool_height = 0; int pool_align = 0; + int align = av_cpu_max_align(); enum AVPixelFormat pool_format = AV_PIX_FMT_NONE; if (link->hw_frames_ctx && @@ -65,7 +64,7 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) if (!link->frame_pool) { link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h, - link->format, BUFFER_ALIGN); + link->format, align); if (!link->frame_pool) return NULL; } else { @@ -76,11 +75,11 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) } if (pool_width != w || pool_height != h || - pool_format != link->format || pool_align != BUFFER_ALIGN) { + pool_format != link->format || pool_align != align) { ff_frame_pool_uninit((FFFramePool **)&link->frame_pool); link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h, - link->format, BUFFER_ALIGN); + link->format, align); if (!link->frame_pool) return NULL; }