From patchwork Thu Feb 25 14:05:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25987 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 715F4449789 for ; Thu, 25 Feb 2021 16:05:44 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5AED168A583; Thu, 25 Feb 2021 16:05:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB085687FA1 for ; Thu, 25 Feb 2021 16:05:37 +0200 (EET) Received: by mail-wm1-f45.google.com with SMTP id a11so1430898wmd.5 for ; Thu, 25 Feb 2021 06:05:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a9O6PBM3DW+fWvqN7XR9EcInqbK3GB5QuZ9x8ACqJBA=; b=K5iwS58wNIlT458jh/IPMkqLi4Mag9oRNU7WFMgCK7bhVpfpzzTwz3o1F/Z4s+UblA ACZ78iGpa6o276z6BhqlLUyL316ktB3DmqjGKaiGLDKsHnkFEwNYUHSJmu3Yk3DSJvBp h3ycPeBdKU0FsXyhRWz6Tam0/GKgvMF9SUEiTEzM5wssjrPwE7UqKPueFnvRhBpL5Wdg 9XUbXtHmbcVBpMMkj8tcpLuRf6E+uLNmGfFGJqGaVDhpM10U9GTpYcKnDJlKiJH8jWg/ 18SkYLU7+lw9NCAxrcbinz+EfNP3KNKARR3eUhDS4hY1nwn5eDXyMMIKe7qf87QBrrNd UJPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a9O6PBM3DW+fWvqN7XR9EcInqbK3GB5QuZ9x8ACqJBA=; b=ZTzZooK6qPQqB+vfTq/ECdbfZ9oxjKLnr1nC8t1OrGFGOIVThHpnP7xshc2MrH3G4u MzC03NFf8io2fsIU7V2pXcctVgSrfSeoJtB73QrMaXx/R0yYTjEDjNq4z5qrn+GxaHLM yw1oOy5B4NRrCWWLNkwhnfnnxlcD6t7P5vlYvfSDxIkGY+6HiI2z2cK/Hz6SJBtdl644 vO8glDRyMg2IarVeA3Bs1mDrsIbkigYUCzctElcClVIQ/BVzZJlXe0b154W4uLIrndns DaArREuGoCCwaDbQB6UbB4q2qO/oBVNHsuLUy0XZzjL9rqX49zdoeOAC/jDPRTS73rlT h4eA== X-Gm-Message-State: AOAM530LQNE3lHi+OIzsvS7UHpzoHT3MBsX520t8flUqIVpkxWyxpowk CzbG1xjLfnWGwe6QZebggMZZ9zmyqvI= X-Google-Smtp-Source: ABdhPJxj2BKUFJ+KHTPeVDh+4mitlnMZCF9JHXOR7KUt9Mz5+HLQlcWkaE+zlyOsDbtGNEWJAKIvmA== X-Received: by 2002:a05:600c:2048:: with SMTP id p8mr3472006wmg.170.1614261937082; Thu, 25 Feb 2021 06:05:37 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j11sm7952229wrm.13.2021.02.25.06.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 06:05:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Feb 2021 15:05:04 +0100 Message-Id: <20210225140505.1249855-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210225140505.1249855-1-andreas.rheinhardt@gmail.com> References: <20210225140505.1249855-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] fftools: Switch to const AVCodec * where possible 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The obstacle to do so was in filter_codec_opts: It uses searches the AVCodec for options via the AV_OPT_SEARCH_FAKE_OBJ method, which requires using a void * that points to a pointer to a const AVClass. When using const AVCodec *, one can not simply use a pointer that points to the AVCodec's pointer to its AVClass, as said pointer is const, too. This is fixed by using a temporary pointer to the AVClass. Signed-off-by: Andreas Rheinhardt --- The actual obstacle in av_opt_find2 is in the fact that the child_next callback uses a void* for the object. (Is it really intended that any child_next ever modifies it?) fftools/cmdutils.c | 7 ++++--- fftools/cmdutils.h | 2 +- fftools/ffmpeg.c | 6 +++--- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_opt.c | 4 ++-- fftools/ffplay.c | 2 +- fftools/ffprobe.c | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 4eb68d2201..dca6ae3d23 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -2103,7 +2103,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) } AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, - AVFormatContext *s, AVStream *st, AVCodec *codec) + AVFormatContext *s, AVStream *st, const AVCodec *codec) { AVDictionary *ret = NULL; AVDictionaryEntry *t = NULL; @@ -2132,6 +2132,7 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, } while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) { + const AVClass *priv_class; char *p = strchr(t->key, ':'); /* check stream specification in opt name */ @@ -2144,8 +2145,8 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) || !codec || - (codec->priv_class && - av_opt_find(&codec->priv_class, t->key, NULL, flags, + ((priv_class = codec->priv_class) && + av_opt_find(&priv_class, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ))) av_dict_set(&ret, t->key, t->value, 0); else if (t->key[0] == prefix && diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 1917510589..5da9f4c88f 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -414,7 +414,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec); * @return a pointer to the created dictionary */ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, - AVFormatContext *s, AVStream *st, AVCodec *codec); + AVFormatContext *s, AVStream *st, const AVCodec *codec); /** * Setup AVCodecContext options for avformat_find_stream_info(). diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index add5a3e505..5d52d36470 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -688,7 +688,7 @@ void assert_avoptions(AVDictionary *m) } } -static void abort_codec_experimental(AVCodec *c, int encoder) +static void abort_codec_experimental(const AVCodec *c, int encoder) { exit_program(1); } @@ -2943,7 +2943,7 @@ static int init_input_stream(int ist_index, char *error, int error_len) InputStream *ist = input_streams[ist_index]; if (ist->decoding_needed) { - AVCodec *codec = ist->dec; + const AVCodec *codec = ist->dec; if (!codec) { snprintf(error, error_len, "Decoder (codec %s) not found for input stream #%d:%d", avcodec_get_name(ist->dec_ctx->codec_id), ist->file_index, ist->st->index); @@ -3523,7 +3523,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, int ret = 0; if (ost->encoding_needed) { - AVCodec *codec = ost->enc; + const AVCodec *codec = ost->enc; AVCodecContext *dec = NULL; InputStream *ist; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 423da071dc..8813eaf2e3 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -307,7 +307,7 @@ typedef struct InputStream { #define DECODING_FOR_FILTER 2 AVCodecContext *dec_ctx; - AVCodec *dec; + const AVCodec *dec; AVFrame *decoded_frame; AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */ @@ -470,7 +470,7 @@ typedef struct OutputStream { AVCodecContext *enc_ctx; AVCodecParameters *ref_par; /* associated input codec parameters with encoders options applied */ - AVCodec *enc; + const AVCodec *enc; int64_t max_frames; AVFrame *filtered_frame; AVFrame *last_frame; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 1cb601f7c7..85feeb89f2 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -766,13 +766,13 @@ static AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int e return codec; } -static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st) +static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st) { char *codec_name = NULL; MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st); if (codec_name) { - AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); + const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); st->codecpar->codec_id = codec->id; return codec; } else diff --git a/fftools/ffplay.c b/fftools/ffplay.c index b9a30cdb11..cce3b538a9 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -2573,7 +2573,7 @@ static int stream_component_open(VideoState *is, int stream_index) { AVFormatContext *ic = is->ic; AVCodecContext *avctx; - AVCodec *codec; + const AVCodec *codec; const char *forced_codec_name = NULL; AVDictionary *opts = NULL; AVDictionaryEntry *t = NULL; diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index de70c20eb4..740e759958 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2996,7 +2996,7 @@ static int open_input_file(InputFile *ifile, const char *filename, for (i = 0; i < fmt_ctx->nb_streams; i++) { InputStream *ist = &ifile->streams[i]; AVStream *stream = fmt_ctx->streams[i]; - AVCodec *codec; + const AVCodec *codec; ist->st = stream;