diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2012-09-22 19:26:27 +0200 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2012-09-23 21:05:29 +0200 |
commit | 7200fecd9b3a097948c152e72a991723019001be (patch) | |
tree | 759642fc6b1d6928bd2ca5504cb5a91e958d488c | |
parent | f25d53d95f62693724a59a4be8454c8ae58b8359 (diff) | |
download | ffmpeg-7200fecd9b3a097948c152e72a991723019001be.tar.gz |
cmdutils: sort codec lists.
The lists are sorted first by type (video first)
and then alphabetically by name.
Fix ticket #1669.
-rw-r--r-- | cmdutils.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/cmdutils.c b/cmdutils.c index bd4ba4ad2d..5639751e3a 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -890,6 +890,36 @@ static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev, return NULL; } +static int compare_codec_desc(const void *a, const void *b) +{ + const AVCodecDescriptor * const *da = a; + const AVCodecDescriptor * const *db = b; + + return (*da)->type != (*db)->type ? (*da)->type - (*db)->type : + strcmp((*da)->name, (*db)->name); +} + +static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs) +{ + const AVCodecDescriptor *desc = NULL; + const AVCodecDescriptor **codecs; + unsigned nb_codecs = 0, i = 0; + + while ((desc = avcodec_descriptor_next(desc))) + nb_codecs++; + if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) { + av_log(0, AV_LOG_ERROR, "Out of memory\n"); + exit_program(1); + } + desc = NULL; + while ((desc = avcodec_descriptor_next(desc))) + codecs[i++] = desc; + av_assert0(i == nb_codecs); + qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec_desc); + *rcodecs = codecs; + return nb_codecs; +} + static void print_codecs_for_id(enum AVCodecID id, int encoder) { const AVCodec *codec = NULL; @@ -904,7 +934,8 @@ static void print_codecs_for_id(enum AVCodecID id, int encoder) int show_codecs(void *optctx, const char *opt, const char *arg) { - const AVCodecDescriptor *desc = NULL; + const AVCodecDescriptor **codecs; + unsigned i, nb_codecs = get_codecs_sorted(&codecs); printf("Codecs:\n" " D..... = Decoding supported\n" @@ -916,7 +947,8 @@ int show_codecs(void *optctx, const char *opt, const char *arg) " ....L. = Lossy compression\n" " .....S = Lossless compression\n" " -------\n"); - while ((desc = avcodec_descriptor_next(desc))) { + for (i = 0; i < nb_codecs; i++) { + const AVCodecDescriptor *desc = codecs[i]; const AVCodec *codec = NULL; printf(" "); @@ -948,12 +980,14 @@ int show_codecs(void *optctx, const char *opt, const char *arg) printf("\n"); } + av_free(codecs); return 0; } static void print_codecs(int encoder) { - const AVCodecDescriptor *desc = NULL; + const AVCodecDescriptor **codecs; + unsigned i, nb_codecs = get_codecs_sorted(&codecs); printf("%s:\n" " V..... = Video\n" @@ -966,7 +1000,8 @@ static void print_codecs(int encoder) " .....D = Supports direct rendering method 1\n" " ------\n", encoder ? "Encoders" : "Decoders"); - while ((desc = avcodec_descriptor_next(desc))) { + for (i = 0; i < nb_codecs; i++) { + const AVCodecDescriptor *desc = codecs[i]; const AVCodec *codec = NULL; while ((codec = next_codec_for_id(desc->id, codec, encoder))) { @@ -984,6 +1019,7 @@ static void print_codecs(int encoder) printf("\n"); } } + av_free(codecs); } int show_decoders(void *optctx, const char *opt, const char *arg) |