[FFmpeg-cvslog] cmdutils: sort codec lists.
Nicolas George
git at videolan.org
Sun Sep 23 21:06:41 CEST 2012
ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Sat Sep 22 19:26:27 2012 +0200| [7200fecd9b3a097948c152e72a991723019001be] | committer: Nicolas George
cmdutils: sort codec lists.
The lists are sorted first by type (video first)
and then alphabetically by name.
Fix ticket #1669.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7200fecd9b3a097948c152e72a991723019001be
---
cmdutils.c | 44 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 40 insertions(+), 4 deletions(-)
diff --git a/cmdutils.c b/cmdutils.c
index bd4ba4a..5639751 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)
More information about the ffmpeg-cvslog
mailing list