From patchwork Fri Apr 5 18:57:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 47860 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1157586pzd; Fri, 5 Apr 2024 11:57:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWt8qnLyGO7C+zS6jaj7sC0Ncbc5G71LgAjofogARgBf1M0/DI9xlB5j48nTyjm2dQ4sPyp+D9IWetRnOg0hWIKvK/c/txcbh4pTw== X-Google-Smtp-Source: AGHT+IGsqrJfEJgOwZMm3GF0mmGrwKOJr18LFP98AH4xAoN+KVd5IDpl2efSwj54xuCuULiEwS7F X-Received: by 2002:a17:906:cc15:b0:a51:930c:5713 with SMTP id ml21-20020a170906cc1500b00a51930c5713mr1443914ejb.5.1712343458247; Fri, 05 Apr 2024 11:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712343458; cv=none; d=google.com; s=arc-20160816; b=DugpLhW5ry4b1Gnuexy1LFp2AbtNAvyw5wr5GEKLddIqmZvRjIytbDuMZQrySUI2Mf oWYPVEvl+Zjwss7Xg4WibuRShdCSXExNzE05OnSyUxQVhgK9uepEMw633ijnadZQzdx1 5VddBCxXvGjiCFcATDevQJy0nJ4SRgQhVUkapo4UCuoOuz+RXblTYDjdYwhO6ugwDkXc ADY2H6vxjXlzdqxIe6TUZQa0M6tdRuza4I4ynEDXN5ESLIwHdEJOHd/B6GKAq6qtqkrv 2ujS5bkOGwMkJRA8RSK+WzbfcYRWcNC+PzRB74jOZ+cpsj8KmgO8+wqoWSEdP957Axso 5kOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=MkKCGPGmYsgDRq/bExWureUWfJvRml2wp4whKVuR2O0=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=gdUCRM1KZyhg8vM5CnjnRE99Dk/0y+qGSn67qtjjkBRgswxnBQRDNrYPiSm9bp2Gi8 8A3hh9Q2y2j+CORpnnXvMtHLYZdal490rMJX1Af3AX38pz6ioYmUdOqiQLa1iWLJdznH XLNYCeoZ9eYjQ4HM1Sok3Vou/cqw7COezA1cWczMPFKfqQbDvczQgQlaI9HS5K0rGUUT L1zuAYm9n62P3QZQ4ty+pjYI2EP0rJ44+Q5LpLSVLRQU4+jHzGpuNjBYAjHl6i7muhLu rjFHAiD7IxuAzBqQ80hmy4oojqHqyei+R4N/uyeRnl0SJGzNWvdwpt3bNOH3AfBOD31p pXAg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ApNggkUu; 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 pj12-20020a170906d78c00b00a51a0a1aeaesi951735ejb.675.2024.04.05.11.57.37; Fri, 05 Apr 2024 11:57:38 -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; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ApNggkUu; 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 4FE9068D135; Fri, 5 Apr 2024 21:57:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 353D868D095 for ; Fri, 5 Apr 2024 21:57:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1712343445; bh=ymHusjWhgngbWdDmjBB2I1v2nAT1oCkQ45qEpwiIs24=; h=From:To:Cc:Subject:Date:From; b=ApNggkUu3q33hmwA/dQcPZtpCYwLAhAtmW5mTGIj2GZIqW1GonoTqiggKRj3wc1kR fI1qdTgGbb33p7XpTyRrRc1D9C+NdeebXFNim02VDeGzKPQ5SvuY+xjTsGDNLOBdlx y2zgixIRb+4/kgGE/exaMpq+JVn91/EnJxYh7G3w= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id DF54F402FF; Fri, 5 Apr 2024 20:57:25 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 20:57:11 +0200 Message-ID: <20240405185721.111072-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: EhqPAColjfnF From: Niklas Haas This replaces the myriad of existing lists in AVCodec by a unified API call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite substantially, while also making this more trivially extensible. In addition to the already covered lists, add two new entries for color space and color range, mirroring the newly added negotiable fields in libavfilter. I decided to drop the explicit length field from the API proposed by Andreas Rheinhardt, because having it in place ended up complicating both the codec side and the client side implementations, while also being strictly less flexible (it's trivial to recover a length given a terminator, but requires allocation to add a terminator given a length). Using a terminator also presents less of a porting challenge for existing users of the current API. Once the deprecation period passes for the existing public fields, the rough plan is to move the commonly used fields (such as pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video configuration types, and then implement the rarely used fields with custom callbacks. --- doc/APIchanges | 5 ++++ libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++ libavcodec/avcodec.h | 27 ++++++++++++++++++++ libavcodec/codec.h | 19 +++++++++++--- libavcodec/codec_internal.h | 21 +++++++++++++++ libavcodec/version.h | 4 +-- 6 files changed, 121 insertions(+), 6 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 0a39b6d7ab8..fdeae67159d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,11 @@ The last version increases of all libraries were on 2024-03-07 API changes, most recent first: +2024-04-xx - xxxxxxxxxx - lavc 59.6.100 - avcodec.h + Add avcodec_get_supported_config() and enum AVCodecConfig; deprecate + AVCodec.pix_fmts, AVCodec.sample_fmts, AVCodec.supported_framerates, + AVCodec.supported_samplerates and AVCodec.ch_layouts. + 2024-04-03 - xxxxxxxxxx - lavu 59.13.100 - pixfmt.h Add AVCOL_SPC_IPT_C2, AVCOL_SPC_YCGCO_RE and AVCOL_SPC_YCGCO_RO to map new matrix coefficients defined by H.273 v3. diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 525fe516bd2..3615dc7c1f3 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -700,3 +700,54 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr return ff_decode_receive_frame(avctx, frame); return ff_encode_receive_frame(avctx, frame); } + +#define WRAP_CONFIG(allowed_type, field) \ + do { \ + if (codec->type != (allowed_type)) \ + return AVERROR(EINVAL); \ + *out_configs = (field); \ + return 0; \ + } while (0) + +int ff_default_get_supported_config(const AVCodecContext *avctx, + const AVCodec *codec, + enum AVCodecConfig config, + unsigned flags, + const void **out_configs) +{ + switch (config) { +FF_DISABLE_DEPRECATION_WARNINGS + case AV_CODEC_CONFIG_PIX_FORMAT: + WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts); + case AV_CODEC_CONFIG_FRAME_RATE: + WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates); + case AV_CODEC_CONFIG_SAMPLE_RATE: + WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->supported_samplerates); + case AV_CODEC_CONFIG_SAMPLE_FORMAT: + WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->sample_fmts); + case AV_CODEC_CONFIG_CHANNEL_LAYOUT: + WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->ch_layouts); +FF_ENABLE_DEPRECATION_WARNINGS + case AV_CODEC_CONFIG_COLOR_RANGE: + case AV_CODEC_CONFIG_COLOR_SPACE: + *out_configs = NULL; + return 0; + default: + return AVERROR(EINVAL); + } +} + +int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, + enum AVCodecConfig config, unsigned flags, + const void **out) +{ + const FFCodec *codec2; + if (!codec) + codec = avctx->codec; + codec2 = ffcodec(codec); + if (codec2->get_supported_config) { + return codec2->get_supported_config(avctx, codec, config, flags, out); + } else { + return ff_default_get_supported_config(avctx, codec, config, flags, out); + } +} diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 83dc487251c..64f31375fc6 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2690,6 +2690,33 @@ int avcodec_get_hw_frames_parameters(AVCodecContext *avctx, enum AVPixelFormat hw_pix_fmt, AVBufferRef **out_frames_ref); +enum AVCodecConfig { + AV_CODEC_CONFIG_PIX_FORMAT, ///< AVPixelFormat, terminated by AV_PIX_FMT_NONE + AV_CODEC_CONFIG_FRAME_RATE, ///< AVRational, terminated by {0, 0} + AV_CODEC_CONFIG_SAMPLE_RATE, ///< int, terminated by 0 + AV_CODEC_CONFIG_SAMPLE_FORMAT, ///< AVSampleFormat, terminated by AV_SAMPLE_FMT_NONE + AV_CODEC_CONFIG_CHANNEL_LAYOUT, ///< AVChannelLayout, terminated by {0} + AV_CODEC_CONFIG_COLOR_RANGE, ///< AVColorRange, terminated by AVCOL_RANGE_UNSPECIFIED + AV_CODEC_CONFIG_COLOR_SPACE, ///< AVColorSpace, terminated by AVCOL_SPC_UNSPECIFIED +}; + +/** + * Retrieve a list of all supported values for a given configuration type. + * + * @param avctx An optional context to use. Values such as + * `strict_std_compliance` may affect the result. If NULL, + * default values are used. + * @param codec The codec to query, or NULL to use avctx->codec. + * @param config The configuration to query. + * @param flags Currently unused; should be set to zero. + * @param out_configs On success, set to a list of configurations, terminated + * by a config-specific terminator, or NULL if all + * possible values are supported. + */ +int avcodec_get_supported_config(const AVCodecContext *avctx, + const AVCodec *codec, enum AVCodecConfig config, + unsigned flags, const void **out_configs); + /** diff --git a/libavcodec/codec.h b/libavcodec/codec.h index 6f9b42760d7..f7541ffc42b 100644 --- a/libavcodec/codec.h +++ b/libavcodec/codec.h @@ -205,10 +205,19 @@ typedef struct AVCodec { */ int capabilities; uint8_t max_lowres; ///< maximum value for lowres supported by the decoder - const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0} - const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1 - const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0 - const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1 + + /** + * Deprecated codec capabilities. + */ + attribute_deprecated + const AVRational *supported_framerates; ///< @deprecated use avcodec_get_supported_config() + attribute_deprecated + const enum AVPixelFormat *pix_fmts; ///< @deprecated use avcodec_get_supported_config() + attribute_deprecated + const int *supported_samplerates; ///< @deprecated use avcodec_get_supported_config() + attribute_deprecated + const enum AVSampleFormat *sample_fmts; ///< @deprecated use avcodec_get_supported_config() + const AVClass *priv_class; ///< AVClass for the private context const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN} @@ -226,7 +235,9 @@ typedef struct AVCodec { /** * Array of supported channel layouts, terminated with a zeroed layout. + * @deprecated use avcodec_get_supported_config() */ + attribute_deprecated const AVChannelLayout *ch_layouts; } AVCodec; diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h index d6757e2deff..3c6328364cb 100644 --- a/libavcodec/codec_internal.h +++ b/libavcodec/codec_internal.h @@ -22,6 +22,7 @@ #include #include "libavutil/attributes.h" +#include "avcodec.h" #include "codec.h" #include "config.h" @@ -264,8 +265,28 @@ typedef struct FFCodec { * List of supported codec_tags, terminated by FF_CODEC_TAGS_END. */ const uint32_t *codec_tags; + + /** + * Custom callback for avcodec_get_supported_config(). If absent, + * ff_default_get_supported_config() will be used. + */ + int (*get_supported_config)(const AVCodecContext *avctx, + const AVCodec *codec, + enum AVCodecConfig config, + unsigned flags, + const void **out_configs); } FFCodec; +/** + * Default implementation for avcodec_get_supported_config(). Will return the + * relevant fields from AVCodec if present, or NULL otherwise. + */ +int ff_default_get_supported_config(const AVCodecContext *avctx, + const AVCodec *codec, + enum AVCodecConfig config, + unsigned flags, + const void **out_configs); + #if CONFIG_SMALL #define CODEC_LONG_NAME(str) .p.long_name = NULL #else diff --git a/libavcodec/version.h b/libavcodec/version.h index 84a1c02ce4a..da54f878874 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,8 +29,8 @@ #include "version_major.h" -#define LIBAVCODEC_VERSION_MINOR 5 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MINOR 6 +#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \