From patchwork Thu Apr 16 15:28:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 19004 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8D7BF44A8FC for ; Thu, 16 Apr 2020 18:29:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5C16668B72A; Thu, 16 Apr 2020 18:29:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6E3DE689AB1 for ; Thu, 16 Apr 2020 18:29:03 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 03GFT2qN014904 for ; Thu, 16 Apr 2020 17:29:02 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 73B9EE8C4D; Thu, 16 Apr 2020 17:29:02 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Apr 2020 17:28:57 +0200 Message-Id: <20200416152900.145027-1-george@nsup.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 16 Apr 2020 17:29:02 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/4] lavfi/formats: add ff_formats_pixdesc_filter(). X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Signed-off-by: Nicolas George --- libavfilter/formats.c | 41 +++++++++++++++++++++++++++++++++++++++++ libavfilter/formats.h | 10 ++++++++++ 2 files changed, 51 insertions(+) I need it in new code. diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 33c64668a0..784f604483 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -373,6 +373,47 @@ const int64_t avfilter_all_channel_layouts[] = { -1 }; +int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned rej) +{ + unsigned nb_formats, fmt, flags; + AVFilterFormats *formats = NULL; + + while (1) { + nb_formats = 0; + for (fmt = 0;; fmt++) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); + if (!desc) + break; + flags = desc->flags; + if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) && + !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) && + (desc->log2_chroma_w || desc->log2_chroma_h)) + flags |= FF_PIX_FMT_FLAG_SW_FLAT_SUB; + if ((flags & (want | rej)) != want) + continue; + if (formats) + formats->formats[nb_formats] = fmt; + nb_formats++; + } + if (formats) { + av_assert0(formats->nb_formats == nb_formats); + *rfmts = formats; + return 0; + } + formats = av_mallocz(sizeof(*formats)); + if (!formats) + return AVERROR(ENOMEM); + formats->nb_formats = nb_formats; + if (nb_formats) { + formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats)); + if (!formats->formats) { + av_freep(&formats); + return AVERROR(ENOMEM); + } + } + } +} + // AVFilterFormats *avfilter_make_all_channel_layouts(void) // { // return avfilter_make_format64_list(avfilter_all_channel_layouts); diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 870809b5a0..cc588f30d8 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -221,6 +221,16 @@ int ff_add_format(AVFilterFormats **avff, int64_t fmt); av_warn_unused_result AVFilterFormats *ff_all_formats(enum AVMediaType type); +/** + * Construct a formats list containing all pixel formats with certain + * properties + */ +av_warn_unused_result +int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned rej); + +//* format is software, non-planar with sub-sampling +#define FF_PIX_FMT_FLAG_SW_FLAT_SUB (1 << 24) + /** * Construct a formats list containing all planar sample formats. */