From patchwork Thu Mar 22 02:01:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 8091 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp272046jad; Wed, 21 Mar 2018 19:01:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELuaby0T12Mtxs1Ny5XyjlSaBW+AHqf1J0VHyj8Jb6dULZFJ3NG0E3xRdm82I1Yi8rxqe6pz X-Received: by 10.28.55.129 with SMTP id e123mr3885994wma.141.1521684103864; Wed, 21 Mar 2018 19:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521684103; cv=none; d=google.com; s=arc-20160816; b=T8uny+cTkq8u7PzlozKRoOYBed9j4dvmI1afGpqoqRZmdlwZwlBFOxUwqSOSPkQl+Q jigomWmFkFN1pcFofTJSiuOVJbwH0veU5B04i/41f4HwQqJmFHjlgLfMq7dLDTA89uTL YDFaixh4GR4dsSqUpKfih8uUPlbgNLuSmYu4ndSRUk98d64WHj8kYhN2JvY6KKqQygiz viqBJZClEpKu/7BkXbAVQg2bZxR5xUzdOPZvQrFo2TE2FlkYwEovPyL3rlHm2kjpatVU 7UjTt01kdir1pay2JpnD7nqg/gEXfK3cC1fPJQl5M20/YL3h5vBCVoDBKt0gs9QBHzvG EL7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-signature:delivered-to :arc-authentication-results; bh=33opnw/HRK0G4wlPd7jsy2ZlWvisva1uwBfZVv1F03w=; b=Zq+99va+qNt4e5+4BQjsUt5jz/V1oJUczCBlPOmdQrYyLo+57MLyQnayscSXsjD+wN W3sZEQQqMeSzZ6lP5jHntqF6NwCDyrajA/Ol5VYLfBx8nEIz2BmqMacJiIZJ9GAjaDm3 zTzKKNNgXvTDgr1muJwkhnjCKFX6QnhwOg2nSu6oqYMgZ+cu6JY/6xEsAzZ7vtXyodZ2 dqHNbb+I/ypS5njVCln/UvU+sBhlDFn8nstHmwEyPIyRupkJ48WH10/OEJL6U98mFH1y nwJhLi394FaE3RCbFMUDCun9hCzq4ruF7mpuZDtjbOxE0GFDXtJ+nsQDoDgl2IleT3Uh 3VaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@itanimul.li header.s=fm1 header.b=7Of6M2e/; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm2 header.b=cs7M3KJP; 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 h1si3691682wrc.271.2018.03.21.19.01.43; Wed, 21 Mar 2018 19:01:43 -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=@itanimul.li header.s=fm1 header.b=7Of6M2e/; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm2 header.b=cs7M3KJP; 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 06018689C8D; Thu, 22 Mar 2018 04:01:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18210689C5B for ; Thu, 22 Mar 2018 04:01:21 +0200 (EET) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7064421B9A for ; Wed, 21 Mar 2018 22:01:35 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Wed, 21 Mar 2018 22:01:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itanimul.li; h= date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=ao6JHINIM5a0Ya6/j zZ0kIUAPPPTnGHhZI7kiabQO64=; b=7Of6M2e/lBLBIcDcX4A2JMAHLfjgCZ6sj 3lQlgo6aeobMWNU4HEpw1CUbYzG7hhcev3/dDRR4X4k/w6/AwYiLqEpm8mdB/93x MLKf58IkO6AsYWPZtCP7TwhRJA8o9C03bTZVUl6+s2vXkCmzrq6pH5LoUvIbTP98 7eSi5B3PCZxmIaH1/9rEzr6y2flxiq0fN+WFX8zLmDaxanygYa234tkqVD5BPQia 8FNehhwQxNIMxOGVtEA5Jr9BiY7/cBaCmNHDXyMhYxJ2rrOCv9UQm1obRwTDVc3O d7x5APuCHr+JgmuQ9Qj6enLlzbl6RnydfqNI0dBt558OfwsgEv+vg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=ao6JHINIM5a0Ya6/jzZ0kIUAPPPTnGHhZI7kiabQO64=; b=cs7M3KJP mqcdBAjG2pJoXaX6p23qXAPk3YY8illXEkamVhtKEyAYsg0noYgtJM9j+Ni7Eoxg LoscvyxOgcXg1f5iFvFxGDI0vsXIQlqPGpU2t1FV2dmRXfpHp7GwLH30SVAqSo11 ue1F8NpwOy0P+RyrS5+7o+SzFqhdhYb2gnSDzPKej1uWDt3TDIgLdDJmHM+7a9SO Q2PPwCrTxyytyHQyxRfRSdAmcmOUkE1OEucmrkiukKa/tzICr7Ueq2tjQMyB+vCS Ltcq+Na/v7rvVlBiTYqvT/vg+RPXo5UCMwL8BfTwpgWaFmnaWCTjOutowEjo47ml DQvvFVg/Jtx1iQ== X-ME-Sender: Received: from localhost.localdomain (cpc75394-sotn16-2-0-cust168.15-1.cable.virginm.net [82.22.8.169]) by mail.messagingengine.com (Postfix) with ESMTPA id 047B27E16D for ; Wed, 21 Mar 2018 22:01:33 -0400 (EDT) From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Mar 2018 02:01:27 +0000 Message-Id: <20180322020127.82915-1-josh@itanimul.li> X-Mailer: git-send-email 2.14.3 (Apple Git-98) In-Reply-To: <20180319204836.GB1618490@phare.normalesup.org> References: <20180319204836.GB1618490@phare.normalesup.org> Subject: [FFmpeg-devel] [PATCH v4 3/7] cmdutils: use new iteration APIs 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- I have -ffunroll'd the macros for you Nicolas. fftools/cmdutils.c | 248 ++++++++++++++++++++++++++++------------------------- 1 file changed, 129 insertions(+), 119 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 708a849f51..956eb7b974 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1250,19 +1250,11 @@ int show_license(void *optctx, const char *opt, const char *arg) return 0; } -static int is_device(const AVClass *avclass) -{ - if (!avclass) - return 0; - return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category); -} - static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only, int muxdemuxers) { - AVInputFormat *ifmt = NULL; - AVOutputFormat *ofmt = NULL; + const AVInputFormat *ifmt = NULL; + const AVOutputFormat *ofmt = NULL; const char *last_name; - int is_dev; printf("%s\n" " D. = Demuxing supported\n" @@ -1270,46 +1262,63 @@ static int show_formats_devices(void *optctx, const char *opt, const char *arg, " --\n", device_only ? "Devices:" : "File formats:"); last_name = "000"; for (;;) { - int decode = 0; - int encode = 0; + int is_ifmt = 0; + int is_ofmt = 0; const char *name = NULL; const char *long_name = NULL; - if (muxdemuxers !=SHOW_DEMUXERS) { - while ((ofmt = av_oformat_next(ofmt))) { - is_dev = is_device(ofmt->priv_class); - if (!is_dev && device_only) - continue; - if ((!name || strcmp(ofmt->name, name) < 0) && - strcmp(ofmt->name, last_name) > 0) { - name = ofmt->name; + void *opaque = 0; + if (muxdemuxers != SHOW_DEMUXERS && !device_only) { + while ((ofmt = av_muxer_iterate(&opaque))) { + if ((!name || strcmp(ofmt->name, name) < 0) && strcmp(ofmt->name, last_name) > 0) { + name = ofmt->name; long_name = ofmt->long_name; - encode = 1; + is_ofmt = 1; } } } - if (muxdemuxers != SHOW_MUXERS) { - while ((ifmt = av_iformat_next(ifmt))) { - is_dev = is_device(ifmt->priv_class); - if (!is_dev && device_only) - continue; - if ((!name || strcmp(ifmt->name, name) < 0) && - strcmp(ifmt->name, last_name) > 0) { - name = ifmt->name; + + opaque = 0; + if (muxdemuxers != SHOW_MUXERS && !device_only) { + while ((ifmt = av_demuxer_iterate(&opaque))) { + if ((!name || strcmp(ifmt->name, name) < 0) && strcmp(ifmt->name, last_name) > 0) { + name = ifmt->name; long_name = ifmt->long_name; - encode = 0; + is_ifmt = 1; + } + } + } +#ifdef CONFIG_AVDEVICE + opaque = 0; + if (muxdemuxers != SHOW_DEMUXERS) { + while ((ofmt = av_outdev_iterate(&opaque))) { + if ((!name || strcmp(ofmt-> name, name) < 0) && strcmp(ofmt-> name, last_name) > 0) { + name = ofmt - > name; + long_name = ofmt - > long_name; + is_ofmt = 1; } - if (name && strcmp(ifmt->name, name) == 0) - decode = 1; } } + + opaque = 0; + if (muxdemuxers != SHOW_MUXERS) { + while ((ifmt = av_indev_iterate(&opaque))) { + if ((!name || strcmp(ifmt-> name, name) < 0) && strcmp(ifmt-> name, last_name) > 0) { + name = ifmt - > name; + long_name = ifmt - > long_name; + is_ifmt = 1; + } + } + } +#endif + if (!name) break; last_name = name; printf(" %s%s %-15s %s\n", - decode ? "D" : " ", - encode ? "E" : " ", + is_ifmt ? "D" : " ", + is_ofmt ? "E" : " ", name, long_name ? long_name:" "); } @@ -1439,15 +1448,45 @@ static char get_media_type_char(enum AVMediaType type) } } -static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev, - int encoder) + +static int compare_codec(const void *a, const void *b) +{ + const AVCodec * const *ca = a; + const AVCodec * const *cb = b; + + return strcmp((*ca)->name, (*cb)->name); +} + +static unsigned get_codecs_sorted(enum AVCodecID id, const AVCodec ***rcodecs, int encoder) { - while ((prev = av_codec_next(prev))) { - if (prev->id == id && - (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev))) - return prev; + const AVCodec *codec = NULL; + const AVCodec **codecs; + unsigned nb_codecs = 0, i = 0; + void *opaque = 0; + + while ((codec = av_codec_iterate(&opaque))) { + if (codec->id == id && + (encoder ? av_codec_is_encoder(codec) : av_codec_is_decoder(codec))) + nb_codecs++; } - return NULL; + + if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) { + av_log(NULL, AV_LOG_ERROR, "Out of memory\n"); + exit_program(1); + } + + opaque = 0; + while ((codec = av_codec_iterate(&opaque))) { + if (codec->id == id && + (encoder ? av_codec_is_encoder(codec) : av_codec_is_decoder(codec))) + codecs[i++] = codec; + } + + av_assert0(i == nb_codecs); + qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec); + *rcodecs = codecs; + + return nb_codecs; } static int compare_codec_desc(const void *a, const void *b) @@ -1459,7 +1498,7 @@ static int compare_codec_desc(const void *a, const void *b) strcmp((*da)->name, (*db)->name); } -static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs) +static unsigned get_codec_descs_sorted(const AVCodecDescriptor ***rcodecs) { const AVCodecDescriptor *desc = NULL; const AVCodecDescriptor **codecs; @@ -1480,22 +1519,10 @@ static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs) return nb_codecs; } -static void print_codecs_for_id(enum AVCodecID id, int encoder) -{ - const AVCodec *codec = NULL; - - printf(" (%s: ", encoder ? "encoders" : "decoders"); - - while ((codec = next_codec_for_id(id, codec, encoder))) - printf("%s ", codec->name); - - printf(")"); -} - int show_codecs(void *optctx, const char *opt, const char *arg) { const AVCodecDescriptor **codecs; - unsigned i, nb_codecs = get_codecs_sorted(&codecs); + unsigned i, nb_codecs = get_codec_descs_sorted(&codecs); printf("Codecs:\n" " D..... = Decoding supported\n" @@ -1509,7 +1536,6 @@ int show_codecs(void *optctx, const char *opt, const char *arg) " -------\n"); for (i = 0; i < nb_codecs; i++) { const AVCodecDescriptor *desc = codecs[i]; - const AVCodec *codec = NULL; if (strstr(desc->name, "_deprecated")) continue; @@ -1525,22 +1551,22 @@ int show_codecs(void *optctx, const char *opt, const char *arg) printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : ""); - /* print decoders/encoders when there's more than one or their - * names are different from codec name */ - while ((codec = next_codec_for_id(desc->id, codec, 0))) { - if (strcmp(codec->name, desc->name)) { - print_codecs_for_id(desc->id, 0); - break; + for (int encoder = 0; encoder < 2; encoder++) { + const AVCodec **codec_codecs; + const int nb_codec_codecs = get_codecs_sorted(desc->id, &codec_codecs, encoder); + if (nb_codec_codecs == 1 && !strcmp(desc->name, codec_codecs[0]->name)) { + av_free(codec_codecs); + continue; } - } - codec = NULL; - while ((codec = next_codec_for_id(desc->id, codec, 1))) { - if (strcmp(codec->name, desc->name)) { - print_codecs_for_id(desc->id, 1); - break; + if (nb_codec_codecs) { + printf(" (%s: ", encoder ? "encoders" : "decoders"); + for (int j = 0; j < nb_codec_codecs; j++) { + printf("%s ", codec_codecs[j]->name); + } + printf(")"); } + av_free(codec_codecs); } - printf("\n"); } av_free(codecs); @@ -1550,7 +1576,7 @@ int show_codecs(void *optctx, const char *opt, const char *arg) static void print_codecs(int encoder) { const AVCodecDescriptor **codecs; - unsigned i, nb_codecs = get_codecs_sorted(&codecs); + unsigned i, nb_codecs = get_codec_descs_sorted(&codecs); printf("%s:\n" " V..... = Video\n" @@ -1566,8 +1592,11 @@ static void print_codecs(int encoder) for (i = 0; i < nb_codecs; i++) { const AVCodecDescriptor *desc = codecs[i]; const AVCodec *codec = NULL; + const AVCodec **codec_codecs; + const int nb_codec_codecs = get_codecs_sorted(desc->id, &codec_codecs, encoder); - while ((codec = next_codec_for_id(desc->id, codec, encoder))) { + for (int j = 0; j < nb_codec_codecs; j++) { + codec = codec_codecs[j]; printf(" %c", get_media_type_char(desc->type)); printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : "."); printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : "."); @@ -1581,6 +1610,7 @@ static void print_codecs(int encoder) printf("\n"); } + av_free(codec_codecs); } av_free(codecs); } @@ -1628,6 +1658,7 @@ int show_filters(void *optctx, const char *opt, const char *arg) { #if CONFIG_AVFILTER const AVFilter *filter = NULL; + void *opaque = 0; char descr[64], *descr_cur; int i, j; const AVFilterPad *pad; @@ -1640,7 +1671,7 @@ int show_filters(void *optctx, const char *opt, const char *arg) " V = Video input/output\n" " N = Dynamic number and/or type of input/output\n" " | = Source or sink filter\n"); - while ((filter = avfilter_next(filter))) { + while ((filter = av_filter_iterate(&opaque))) { descr_cur = descr; for (i = 0; i < 2; i++) { if (i) { @@ -1771,19 +1802,17 @@ static void show_help_codec(const char *name, int encoder) if (codec) print_codec(codec); else if ((desc = avcodec_descriptor_get_by_name(name))) { - int printed = 0; + const AVCodec **codec_codecs; - while ((codec = next_codec_for_id(desc->id, codec, encoder))) { - printed = 1; - print_codec(codec); - } - - if (!printed) { + if (get_codecs_sorted(desc->id, &codec_codecs, encoder)) { + print_codec(codec_codecs[0]); + } else { av_log(NULL, AV_LOG_ERROR, "Codec '%s' is known to FFmpeg, " "but no %s for it are available. FFmpeg might need to be " "recompiled with additional external libraries.\n", name, encoder ? "encoders" : "decoders"); } + av_free(codec_codecs); } else { av_log(NULL, AV_LOG_ERROR, "Codec '%s' is not recognized by FFmpeg.\n", name); @@ -2132,7 +2161,7 @@ double get_rotation(AVStream *st) } #if CONFIG_AVDEVICE -static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts) +static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts) { int ret, i; AVDeviceInfoList *device_list = NULL; @@ -2147,7 +2176,7 @@ static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts) goto fail; } - if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) { + if ((ret = avdevice_list_input_sources((AVInputFormat*)fmt, NULL, opts, &device_list)) < 0) { printf("Cannot list sources.\n"); goto fail; } @@ -2162,7 +2191,7 @@ static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts) return ret; } -static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts) +static int print_device_sinks(const AVOutputFormat *fmt, AVDictionary *opts) { int ret, i; AVDeviceInfoList *device_list = NULL; @@ -2177,7 +2206,7 @@ static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts) goto fail; } - if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) { + if ((ret = avdevice_list_output_sinks((AVOutputFormat*)fmt, NULL, opts, &device_list)) < 0) { printf("Cannot list sinks.\n"); goto fail; } @@ -2216,7 +2245,8 @@ static int show_sinks_sources_parse_arg(const char *arg, char **dev, AVDictionar int show_sources(void *optctx, const char *opt, const char *arg) { - AVInputFormat *fmt = NULL; + const AVInputFormat *fmt = NULL; + void *i = 0; char *dev = NULL; AVDictionary *opts = NULL; int ret = 0; @@ -2227,24 +2257,14 @@ int show_sources(void *optctx, const char *opt, const char *arg) if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0) goto fail; - do { - fmt = av_input_audio_device_next(fmt); - if (fmt) { - if (!strcmp(fmt->name, "lavfi")) - continue; //it's pointless to probe lavfi - if (dev && !av_match_name(dev, fmt->name)) - continue; - print_device_sources(fmt, opts); - } - } while (fmt); - do { - fmt = av_input_video_device_next(fmt); - if (fmt) { - if (dev && !av_match_name(dev, fmt->name)) - continue; - print_device_sources(fmt, opts); - } - } while (fmt); + while ((fmt = av_indev_iterate(&i))) { + if (!strcmp(fmt->name, "lavfi")) + continue; //it's pointless to probe lavfi + if (dev && !av_match_name(dev, fmt->name)) + continue; + print_device_sources(fmt, opts); + } + fail: av_dict_free(&opts); av_free(dev); @@ -2254,7 +2274,8 @@ int show_sources(void *optctx, const char *opt, const char *arg) int show_sinks(void *optctx, const char *opt, const char *arg) { - AVOutputFormat *fmt = NULL; + const AVOutputFormat *fmt = NULL; + void *i = 0; char *dev = NULL; AVDictionary *opts = NULL; int ret = 0; @@ -2265,22 +2286,11 @@ int show_sinks(void *optctx, const char *opt, const char *arg) if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0) goto fail; - do { - fmt = av_output_audio_device_next(fmt); - if (fmt) { - if (dev && !av_match_name(dev, fmt->name)) - continue; - print_device_sinks(fmt, opts); - } - } while (fmt); - do { - fmt = av_output_video_device_next(fmt); - if (fmt) { - if (dev && !av_match_name(dev, fmt->name)) - continue; - print_device_sinks(fmt, opts); - } - } while (fmt); + while ((fmt = av_outdev_iterate(&i))) { + if (dev && !av_match_name(dev, fmt->name)) + continue; + print_device_sinks(fmt, opts); + } fail: av_dict_free(&opts); av_free(dev);