[FFmpeg-devel] [PATCH 3/4] move supported list printing code from cmdutils to lavc

Michael Niedermayer michaelni at gmx.at
Mon Oct 22 02:01:36 CEST 2012


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 cmdutils.c           |   25 +++---------------------
 libavcodec/avcodec.h |   10 ++++++++++
 libavcodec/utils.c   |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 22 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index 5b9111a..acea36b 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -806,20 +806,7 @@ int show_formats(void *optctx, const char *opt, const char *arg)
             long_name ? long_name:" ");
     }
     return 0;
-}
-
-#define PRINT_CODEC_SUPPORTED(ctx, codec, field, type, list_name, term, get_name) \
-    if (codec->field) {                                                      \
-        const type *p = codec->field;                                        \
-                                                                             \
-        av_log(ctx, AV_LOG_INFO, "    Supported " list_name ":");            \
-        while (*p != term) {                                                 \
-            get_name(*p);                                                    \
-            av_log(ctx, AV_LOG_INFO, " %s", name);                           \
-            p++;                                                             \
-        }                                                                    \
-        av_log(ctx, AV_LOG_INFO, "\n");                                      \
-    }                                                                        \
+}                                                                       \
 
 static void print_codec(const AVCodec *c)
 {
@@ -851,14 +838,8 @@ static void print_codec(const AVCodec *c)
         }
         printf("\n");
     }
-    PRINT_CODEC_SUPPORTED(NULL, c, pix_fmts, enum AVPixelFormat, "pixel formats",
-                          AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
-    PRINT_CODEC_SUPPORTED(NULL, c, supported_samplerates, int, "sample rates", 0,
-                          GET_SAMPLE_RATE_NAME);
-    PRINT_CODEC_SUPPORTED(NULL, c, sample_fmts, enum AVSampleFormat, "sample formats",
-                          AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
-    PRINT_CODEC_SUPPORTED(NULL, c, channel_layouts, uint64_t, "channel layouts",
-                          0, GET_CH_LAYOUT_DESC);
+
+    avcodec_print_supported(NULL, c, NULL);
 
     if (c->priv_class) {
         show_help_children(c->priv_class,
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3936d5e..40b909f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3780,6 +3780,16 @@ AVCodec *avcodec_find_decoder(enum AVCodecID id);
  */
 AVCodec *avcodec_find_decoder_by_name(const char *name);
 
+/**
+ * Print list of supported "things" of a codec.
+ *
+ * @param type one of "pixel formats", "sample rates", "sample formats", "channel layouts"
+ *             or NULL to print all lists
+ * @return negative on error othewise non negative
+ */
+int avcodec_print_supported(void *log_ctx, const AVCodec *c, const char *type);
+
+
 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index f736714..85df446 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -304,6 +304,58 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
     *width              = FFALIGN(*width, align);
 }
 
+#define GET_PIX_FMT_NAME(pix_fmt)\
+    const char *name = av_get_pix_fmt_name(pix_fmt);
+
+#define GET_SAMPLE_FMT_NAME(sample_fmt)\
+    const char *name = av_get_sample_fmt_name(sample_fmt)
+
+#define GET_SAMPLE_RATE_NAME(rate)\
+    char name[16];\
+    snprintf(name, sizeof(name), "%d", rate);
+
+#define GET_CH_LAYOUT_NAME(ch_layout)\
+    char name[16];\
+    snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
+
+#define GET_CH_LAYOUT_DESC(ch_layout)\
+    char name[128];\
+    av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
+
+#define PRINT_CODEC_SUPPORTED(ctx, codec, field, t, list_name, term, get_name) \
+    if (codec->field) {                                                      \
+        const t *p = codec->field;                                           \
+                                                                             \
+        av_log(ctx, AV_LOG_INFO, "    Supported " list_name ":");            \
+        while (*p != term) {                                                 \
+            get_name(*p);                                                    \
+            av_log(ctx, AV_LOG_INFO, " %s", name);                           \
+            p++;                                                             \
+        }                                                                    \
+        av_log(ctx, AV_LOG_INFO, "\n");                                      \
+    }
+
+int avcodec_print_supported(void *log_ctx, const AVCodec *c, const char *type)
+{
+    if (!type || !strcmp(type, "pixel formats")) {
+        PRINT_CODEC_SUPPORTED(log_ctx, c, pix_fmts, enum AVPixelFormat, "pixel formats",
+                              AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
+    }
+    if (!type || !strcmp(type, "sample rates")) {
+        PRINT_CODEC_SUPPORTED(log_ctx, c, supported_samplerates, int, "sample rates",
+                              0, GET_SAMPLE_RATE_NAME);
+    }
+    if (!type || !strcmp(type, "sample formats")) {
+        PRINT_CODEC_SUPPORTED(log_ctx, c, sample_fmts, enum AVSampleFormat, "sample formats",
+                              AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
+    }
+    if (!type || !strcmp(type, "channel layouts")) {
+        PRINT_CODEC_SUPPORTED(log_ctx, c, channel_layouts, uint64_t, "channel layouts",
+                              0, GET_CH_LAYOUT_DESC);
+    }
+    return 0;
+}
+
 void ff_init_buffer_info(AVCodecContext *s, AVFrame *frame)
 {
     if (s->pkt) {
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list