[FFmpeg-devel] [PATCH 5/7] dshow: add option to list audio/video options

Ramiro Polla ramiro.polla at gmail.com
Fri Sep 2 06:45:13 CEST 2011


---
 libavdevice/dshow.c |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 4cda218..133e7be 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -32,6 +32,7 @@ struct dshow_ctx {
 
     char *device_name[2];
 
+    int   list_options;
     int   list_devices;
 
     IBaseFilter *device_filter[2];
@@ -223,7 +224,7 @@ fail:
 
 static int
 dshow_set_format(AVFormatContext *avctx, enum dshowDeviceType devtype,
-                 IPin *pin, AM_MEDIA_TYPE *type)
+                 IPin *pin, AM_MEDIA_TYPE *type, int list_options)
 {
     struct dshow_ctx *ctx = avctx->priv_data;
     IAMStreamConfig *c = NULL;
@@ -265,6 +266,14 @@ dshow_set_format(AVFormatContext *avctx, enum dshowDeviceType devtype,
             } else {
                 continue;
             }
+            if (list_options) {
+                av_log(avctx, AV_LOG_INFO, "  %ldx%ld %gfps -> %ldx%ld %gfps\n",
+                       vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
+                       1. / (1e-7 * vcaps->MinFrameInterval),
+                       vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
+                       1. / (1e-7 * vcaps->MaxFrameInterval));
+                continue;
+            }
             if (ctx->framerate) {
                 int64_t framerate = (ctx->requested_framerate.den*10000000)
                                   /  ctx->requested_framerate.num;
@@ -293,6 +302,12 @@ dshow_set_format(AVFormatContext *avctx, enum dshowDeviceType devtype,
             } else {
                 continue;
             }
+            if (list_options) {
+                av_log(avctx, AV_LOG_INFO, "  %luch %lu-bit %6luHz -> %luch %lu-bit %6luHz\n",
+                       acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency,
+                       acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency);
+                continue;
+            }
             if (ctx->sample_rate) {
                 if (ctx->sample_rate > acaps->MaximumSampleFrequency ||
                     ctx->sample_rate < acaps->MinimumSampleFrequency)
@@ -339,6 +354,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
     libAVPin *capture_pin = NULL;
     libAVFilter *capture_filter = NULL;
     const char *device_name = ctx->device_name[devtype];
+    int list_options = ctx->list_options;
     int ret = AVERROR(EIO);
     IPin *pin;
     int r;
@@ -420,6 +436,10 @@ fail1:
         goto error;
     }
 
+    if (list_options) {
+        av_log(avctx, AV_LOG_INFO, "DirectShow %s device \"%s\" options\n",
+               devtypename, device_name);
+    }
     while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {
         IKsPropertySet *p = NULL;
         IEnumMediaTypes *types;
@@ -441,8 +461,13 @@ fail1:
         if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
             goto next;
 
-        if (set_format) {
-            format_set = dshow_set_format(avctx, devtype, pin, type);
+        if (set_format || list_options) {
+            if (list_options) {
+                char *buf = dup_wchar_to_utf8(info.achName);
+                av_log(avctx, AV_LOG_INFO, " Pin \"%s\"\n", buf);
+                av_free(buf);
+            }
+            format_set = dshow_set_format(avctx, devtype, pin, type, list_options);
             if (!format_set) {
                 goto next;
             }
@@ -468,6 +493,9 @@ next:
         if (device_pin != pin)
             IPin_Release(pin);
     }
+    if (list_options) {
+        goto error;
+    }
     if (!format_set) {
         av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename);
         goto error;
@@ -809,6 +837,9 @@ static const AVOption options[] = {
     { "list_devices", "list available devices", OFFSET(list_devices), FF_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_devices" },
     { "true", "", 0, FF_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_devices" },
     { "false", "", 0, FF_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_devices" },
+    { "list_options", "list available options for specified device", OFFSET(list_options), FF_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_options" },
+    { "true", "", 0, FF_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_options" },
+    { "false", "", 0, FF_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_options" },
     { NULL },
 };
 
-- 
1.7.4.1



More information about the ffmpeg-devel mailing list