From patchwork Wed Feb 7 21:07:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 7526 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp1063091jai; Wed, 7 Feb 2018 13:07:52 -0800 (PST) X-Google-Smtp-Source: AH8x226WM7c+usoE7P7Fnkcwm6AYm1y/7lWafDXbCjBcnFiJI3VEO1GDQWc+E4OK6wUgPCmm9G9G X-Received: by 10.28.87.20 with SMTP id l20mr5603184wmb.48.1518037671985; Wed, 07 Feb 2018 13:07:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518037671; cv=none; d=google.com; s=arc-20160816; b=rizmUTA5NeXX7sVYtyLy8dThGeZMIvjrt2TwcshpRPeI5EgXEweUFX4ALrlZQRogDm 2lfBxsJVVhMjhQ8A7Sz//5HEnP7+oHtGQ33LWznG743RnGpiR3i72IkDFZpiQhI0rPPF yLVEEISZkAVmEuehzFpfG1CWmc8/Lb1F2WyxtjdIOfEOAVTFcTkh/SBrNHBMlyM+v6bQ OSWsIvZ1bb+ES4anwY5cwvX6N7nhhci4m65IAHBV+sdJXv6wPAfu8QECXgeh5jNaNezB I8OuE0Mr3WYe9ID+nO1LrK0UYRzmSIcUu7WPQAs5wa6JeilFxJaL16MXjwygeubWgAk8 juyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:user-agent:content-disposition:mime-version :message-id:to:from:date:dkim-signature:dkim-signature:delivered-to :arc-authentication-results; bh=utIMal70kgT/LMsr1dARNCTPwQzpaD5xDq4WBJPBYvI=; b=o6GUa8OKB2X1aFgM/IPe7jokjGhVfad2VEGwxclIX+5RPM7sCQ3rRkskaTiuhjEYu4 bQLQaOuw2IQS4AH6t1QniAyv8iWhmJJeFD+NLLwyr/tFowOPuPNv/cIt9Xlm/UhvDy4C 0j/dcBfhe5jmWsh09dRrmGIZ86blWGnksDNtjF3tV5mvrMtX6lmOTMiJYQE1POG4Yu/q yeXzS2hufYfv9FfOZF+fQgfiJ3fKw/J68C+muFLhC2lHZnSyrgT+OqAPt/LtV5djRbwK O7ye9ESxCaf76agfZnURZMCQucd93jtO13zmVrlhbYnrTG+GQjIF0eL5aTvw5vuNumnZ bf4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@itanimul.li header.s=fm1 header.b=YCUBsOIb; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm1 header.b=OztdtEt5; 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 r141si1794824wmb.155.2018.02.07.13.07.51; Wed, 07 Feb 2018 13:07:51 -0800 (PST) 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=YCUBsOIb; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm1 header.b=OztdtEt5; 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 E6D8B688252; Wed, 7 Feb 2018 23:07:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0136E6805C5 for ; Wed, 7 Feb 2018 23:07:34 +0200 (EET) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DA2552103F for ; Wed, 7 Feb 2018 16:07:42 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Wed, 07 Feb 2018 16:07:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itanimul.li; h= content-type:date:from:message-id:mime-version:reply-to:subject :to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=i4YXY84vYYia7c 1f3n2iaCnRnz7HPtTVWkmc/sgQ8EA=; b=YCUBsOIbKLZRk1GZ9XMt0fcZ3hEdAb A8mtzR1kFaUd986xZ89Og7ngFNpBOmA/xF1zmEIXaUWmmhxwdI6r9brQ+Nh55/y/ 34m/MrG6ShKZcCFsCrAReo7Jve8W9oB+l7Np7op52l0ky11w+Vxh1bCt7tjdUt6a 404kumrEmc5lzptSJSC2SDKs9qOv5zkkfSlvyllenPud23If50XXN+kkU5tqBH5l pFar9Gw1L2HodD6iFdscwrjIWVEGSsglgpD39tKUlj7FBIlPXaXTyVUY4lGPPL8B +KCwpz+EKO2k1MuVQhadc+2HPENe9y/GYsvEbYlF60iO+f5pa5y65y8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:reply-to:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=i4YXY84vYYia7c1f3n2iaCnRnz7HPtTVWkmc/sgQ8 EA=; b=OztdtEt5Wa2lsLH/AoAmX/tNhMm5jQdb3RRG6cliQzBYKK3czfeZEJGuA AdLw7v04puUDJWkgu1YQvKjgOGt/Vy8B18U4A+AmK0osmZ6h2WKZAH+GUIF/fs3B toszGVCYZ12f0brw3Hb3aarhebdpFvU/M4mrsZVehTcUQ1y9nNCUCjQq6M8o36qA 2P1TazdC/7MiyrijOySbh1FwsheyoOYOJgP4lNydluYV3q11lAp8tKIkG5Kiwda2 W+lDeYrW6XMRMyAhV/WKu/vt/LtoByXnUmzVxeE2ZuN/hUyLdL2/Wfm3hPBjh8Y+ A0f37pUMSqGXDs0tEJmt8OaY+2FoQ== X-ME-Sender: Received: from DESKTOP-UATPK6A.localdomain (cpc75394-sotn16-2-0-cust168.15-1.cable.virginm.net [82.22.8.169]) by mail.messagingengine.com (Postfix) with ESMTPA id 5175D24550 for ; Wed, 7 Feb 2018 16:07:42 -0500 (EST) Date: Wed, 7 Feb 2018 21:07:39 +0000 From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Message-ID: <20180207210737.GA23162@DESKTOP-UATPK6A.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Subject: [FFmpeg-devel] [PATCH] cmdutils: fix printing of codecs 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" Yes, my bad. It looked like it worked initially (was more worried about getting a fix out quickly), but it didnt. Try this one. --- fftools/cmdutils.c | 104 +++++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 0b06ccc..83088f0 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1421,16 +1421,43 @@ 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) { - void *i = 0; - while ((prev = av_codec_iterate(&i))) { - if (prev->id == id && - (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev))) - return prev; + const AVCodec * const *da = a; + const AVCodec * const *db = b; + + return strcmp((*da)->name, (*db)->name); +} + +static unsigned get_codecs_sorted(enum AVCodecID id, const AVCodec ***rcodecs, int encoder) +{ + 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) @@ -1442,7 +1469,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; @@ -1463,22 +1490,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" @@ -1492,7 +1507,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; @@ -1508,22 +1522,18 @@ 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; - } - } - 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; + 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) { + 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); @@ -1533,7 +1543,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" @@ -1549,8 +1559,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" : "."); @@ -1564,6 +1577,7 @@ static void print_codecs(int encoder) printf("\n"); } + av_free(codec_codecs); } av_free(codecs); } @@ -1754,19 +1768,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; - - while ((codec = next_codec_for_id(desc->id, codec, encoder))) { - printed = 1; - print_codec(codec); - } + const AVCodec **codec_codecs; - 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);