From patchwork Tue Jun 7 13:25:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 36090 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp6879880pzj; Tue, 7 Jun 2022 06:26:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf0p/atWGTfgY9QBetjvfK+W0Yhe4zuyply62NqY3qsjvF7/7QKX+yextPMEG1361Jv+zd X-Received: by 2002:a17:906:804a:b0:70c:1dac:9bb8 with SMTP id x10-20020a170906804a00b0070c1dac9bb8mr24004818ejw.92.1654608362436; Tue, 07 Jun 2022 06:26:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654608362; cv=none; d=google.com; s=arc-20160816; b=dg0atjpn3njQXayCqydJoxSTY25DW7ndDFEZc9eVNvdnQ8Lzf3c+cVy8nXav2PRBcN EY+DtQZ67XrGVEaDuvyGpr8UgKGkQjrsItqn+bZVV7MlubQ+gNTLQm2Bh0BW/9MRcBC9 57V17DE1fB62YsXhbUCjQssuWvSh5p1oJoE2nQaDbgjp0tDPMV6wMtYzunMLTuUlSvqU O3sC8/SwWnDUW0Y2aKCBcrnVVR77ivJyOFh6xkdsaIOAl8tI/GShI+YEcKU9k9yMOtxY EuSDOdTeBCSCWTE75VHVEvuncgTLmmHR3h4ZcZZeTpnorDIbAqihadIR2gCkaIDKRlB8 dHMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:from:to :content-language:mime-version:date:message-id:dkim-signature :delivered-to; bh=liotXiuwPxbB+85boxh8duReGZXj2FekMQHtkWKqhX0=; b=goV0QcbIFTSDDzRHMC8PoeJkOKmoFijB2xdDzUvpp5A0CeEtICTjiIkeuH5mciMGWC 7nK+CivHFaRBq0muwDnVMEB4Y8KssPcuu2YG/zPfaGbevYLY5GPssw51QThha83+YwpY aQORDPsxJ3AxMFQXulic8r7t4jIS9TjEK01adb7MP/KyrPhE+KnPift00AvipXkLr7Pi SnZNIXGqQYmYH5mGb1DpoGb+hpPixnGktd4vw7693NdmCCghc7IpKhL2T5vODjXN3iST 9ZZPGU9bLxB1SdYbcpFOb+yEpebykogWSXwWAJpdRIUbOxrJL/HFCN52kLdq4HTsGQfD 7M8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=ysdnp7bo; 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=NONE dis=NONE) header.from=mail.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v16-20020a056402349000b0042e01b7a11fsi12611446edc.178.2022.06.07.06.26.00; Tue, 07 Jun 2022 06:26:02 -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=@mail.de header.s=mailde202009 header.b=ysdnp7bo; 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=NONE dis=NONE) header.from=mail.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF8A668B45D; Tue, 7 Jun 2022 16:25:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5392F68B45D for ; Tue, 7 Jun 2022 16:25:50 +0300 (EEST) Received: from postfix01.mail.de (postfix01.bt.mail.de [10.0.121.125]) by shout02.mail.de (Postfix) with ESMTP id B9028A0C66 for ; Tue, 7 Jun 2022 15:25:49 +0200 (CEST) Received: from smtp02.mail.de (smtp02.bt.mail.de [10.0.121.212]) by postfix01.mail.de (Postfix) with ESMTP id A0633800C1 for ; Tue, 7 Jun 2022 15:25:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1654608349; bh=M7SoUoePkMlTWH9zWtvgsZbhxedc/tUw0Ikn5NKVAtI=; h=Message-ID:Date:To:From:Subject:From:To:CC:Subject:Reply-To; b=ysdnp7bo7Ef61oDG87j8wuZEf0kxW8D3eAlDOTRGNd8ge+xHV45UPmVyYTx66DMan MDxQyCNpVEOyCv9tpHIgJQuxf3gYqZk6RqW6HfynZqr9sPy75uQyS3nJyAma49WLHE PkErJIw0bDX5GKdGmBkfhF4xiK9/Pk7VF9xpqzIzqyKPRsMBlmJBFSEXnq2UoFlsLw Z+WHPyX1lV0qwj6Sg4S17licp//uVduBy7fL2+w36UYPytZanu/k4TNxjnZqxDNFjx Cem1HWeYTVNwzh16BCJVks/uwCmeBu/u8YFTYCAA8/h2o/3yxet5vpKcpGw24lL3HQ SYh0vdVf+omTg== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtp02.mail.de (Postfix) with ESMTPSA id 8BBAAA079A for ; Tue, 7 Jun 2022 15:25:48 +0200 (CEST) Message-ID: <84557813-39af-2393-ccb1-6479318e50ab@mail.de> Date: Tue, 7 Jun 2022 15:25:47 +0200 MIME-Version: 1.0 Content-Language: en-US To: FFmpeg development discussions and patches From: Thilo Borgmann X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 9318 X-purgate-ID: 154282::1654608348-0000737C-771DE0B5/0/0 Subject: [FFmpeg-devel] [RFC] User-defined default enc/dec/mux/dem/etc 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: Oy/WMrjHlVuC Hi, currently, if -c:{a,v} is not given, the list of all codecs is successively searched until the first enc/dec is found. If I have two or more enc/dec's for the same codec ID (like by having libx264, libfdk-aac, etc..) it will still be the first in the list that is found that is used if no -c:{v,a} is given. Having a list of user-defined default enc/dec's avoids having the user to always specify their favorite via -c:{v,a}. This patch creates a (redundant) list of default codecs user-defined via configure options. This list is then searched before the complete list of codecs is searched so that all user defaults will be found first. An alternative would be messing with the order of codecs during configure and creation of lavc/codec_list.c to have the defaults found first - which I think is not a good idea. Maybe do something else entirely instead...? For the case you have hwaccel's for the codec ID in question, a default specified currently uses the hwaccel-enc/-dec even if no "-hwaccel something" is given on the command line. What would we want to happen? Stick to use only if given like auto hwaccel decoding? The patch is of course dirty/wip and my shell-Fu is for sure not sufficient to our standards. Anyways, might also be useful to have this for mux/demux, if this is not a horrible idea for some reason to start with? Any comments appreciated before I'd forge it into an actual patch! Thanks, Thilo From c32f4e9ce13685690543d2d295a5edcc39b74899 Mon Sep 17 00:00:00 2001 From: Thilo Borgmann Date: Tue, 7 Jun 2022 11:33:28 +0200 Subject: [PATCH] defaults --- configure | 48 ++++++++++++++++++++++++++++++++++++++++++ libavcodec/allcodecs.c | 34 ++++++++++++++++++++++++++++++ libavcodec/codec.h | 11 ++++++++++ 3 files changed, 93 insertions(+) diff --git a/configure b/configure index 196873c4aa..6053c59078 100755 --- a/configure +++ b/configure @@ -4046,6 +4046,19 @@ done enable $ARCH_EXT_LIST +ENCODER_DEFAULT_LIST= +DECODER_DEFAULT_LIST= + +default_encoder(){ + enabled $1 && + ENCODER_DEFAULT_LIST="$ENCODER_DEFAULT_LIST $1" +} + +default_decoder(){ + enabled $1 && + DECODER_DEFAULT_LIST="$DECODER_DEFAULT_LIST $1" +} + die_unknown(){ echo "Unknown option \"$1\"." echo "See $0 --help for available options." @@ -4156,6 +4169,16 @@ for opt do [ "$list" = "" ] && warn "Option $opt did not match anything" test $action = enable && warn_if_gets_disabled $list $action $list + ;; + --default-*=*) + eval $(echo "${opt%%=*}" | sed 's/--/action=/;s/-/ thing=/') + is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt" + eval list=\$$(toupper $thing)_LIST + name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing} + list=$(filter "$name" $list) + [ "$list" = "" ] && warn "Option $opt did not match anything" + warn_if_gets_disabled $list + ${action}_${thing} $list ;; --enable-yasm|--disable-yasm) warn "The ${opt} option is only provided for compatibility and will be\n"\ @@ -7597,6 +7620,30 @@ if test -n "$WARNINGS"; then enabled fatal_warnings && exit 1 fi +# remove disabled defaults from list +check_encoder_default_list(){ + ENCODER_DEFAULT_LIST="" + for def in "$@"; do + enabled $def && ENCODER_DEFAULT_LIST="$ENCODER_DEFAULT_LIST $def" + done +} + +check_decoder_default_list(){ + DECODER_DEFAULT_LIST="" + for def in "$@"; do + enabled $def && DECODER_DEFAULT_LIST="$DECODER_DEFAULT_LIST $def" + done +} + +check_encoder_default_list $ENCODER_DEFAULT_LIST +check_decoder_default_list $DECODER_DEFAULT_LIST + +CODEC_DEFAULT_LIST=" + $ENCODER_DEFAULT_LIST + $DECODER_DEFAULT_LIST +" +echo "CODEC_DEFAULT_LIST=" $CODEC_DEFAULT_LIST + test -e Makefile || echo "include $source_path/Makefile" > Makefile esc(){ @@ -7883,6 +7930,7 @@ print_enabled_components(){ print_enabled_components libavfilter/filter_list.c AVFilter filter_list $FILTER_LIST print_enabled_components libavcodec/codec_list.c FFCodec codec_list $CODEC_LIST +print_enabled_components libavcodec/codec_default_list.c FFCodec codec_default_list $CODEC_DEFAULT_LIST print_enabled_components libavcodec/parser_list.c AVCodecParser parser_list $PARSER_LIST print_enabled_components libavcodec/bsf_list.c FFBitStreamFilter bitstream_filters $BSF_LIST print_enabled_components libavformat/demuxer_list.c AVInputFormat demuxer_list $DEMUXER_LIST diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index c47133aa18..1a86ecf353 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -866,8 +866,14 @@ const FFCodec * codec_list[] = { NULL, NULL }; +const FFCodec * codec_default_list[] = { + NULL, + NULL, + NULL +}; #else #include "libavcodec/codec_list.c" +#include "libavcodec/codec_default_list.c" #endif static AVOnce av_codec_static_init = AV_ONCE_INIT; @@ -893,6 +899,21 @@ const AVCodec *av_codec_iterate(void **opaque) return NULL; } +const AVCodec *av_codec_iterate2(const void **list, void **opaque) +{ + uintptr_t i = (uintptr_t)*opaque; + const FFCodec **codecs = (const FFCodec**)list; + const FFCodec *c = codecs[i]; + + ff_thread_once(&av_codec_static_init, av_codec_init_static); + + if (c) { + *opaque = (void*)(i + 1); + return &c->p; + } + return NULL; +} + static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id) { switch(id){ @@ -909,6 +930,19 @@ static const AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *)) id = remap_deprecated_codec_id(id); + while ((p = av_codec_iterate2((const void**)codec_default_list, &i))) { + if (!x(p)) + continue; + if (p->id == id) { + if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) { + experimental = p; + } else + return p; + } + } + + i = 0; + while ((p = av_codec_iterate(&i))) { if (!x(p)) continue; diff --git a/libavcodec/codec.h b/libavcodec/codec.h index 03e8be90a2..f9cb40bda4 100644 --- a/libavcodec/codec.h +++ b/libavcodec/codec.h @@ -257,6 +257,17 @@ typedef struct AVCodec { */ const AVCodec *av_codec_iterate(void **opaque); +/** + * Iterate over all registered codecs in a given array of codecs. + * + * @param opaque a pointer where libavcodec will store the iteration state. Must + * point to NULL to start the iteration. + * + * @return the next default codec or NULL when the iteration is + * finished + */ +const AVCodec *av_codec_iterate2(const void **list, void **opaque); + /** * Find a registered decoder with a matching codec ID. *