Browse code

dshow: support choosing between devices with same name

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Ramiro Polla authored on 2011/10/01 05:49:09
Showing 2 changed files
... ...
@@ -104,6 +104,14 @@ If set to @option{true}, print a list of devices and exit.
104 104
 If set to @option{true}, print a list of selected device's options
105 105
 and exit.
106 106
 
107
+@item video_device_number
108
+Set video device number for devices with same name (starts at 0,
109
+defaults to 0).
110
+
111
+@item audio_device_number
112
+Set audio device number for devices with same name (starts at 0,
113
+defaults to 0).
114
+
107 115
 @end table
108 116
 
109 117
 @subsection Examples
... ...
@@ -123,6 +131,12 @@ $ ffmpeg -f dshow -i video="Camera"
123 123
 @end example
124 124
 
125 125
 @item
126
+Open second video device with name @var{Camera}:
127
+@example
128
+$ ffmpeg -f dshow -video_device_number 1 -i video="Camera"
129
+@end example
130
+
131
+@item
126 132
 Open video device @var{Camera} and audio device @var{Microphone}:
127 133
 @example
128 134
 $ ffmpeg -f dshow -i video="Camera":audio="Microphone"
... ...
@@ -31,6 +31,8 @@ struct dshow_ctx {
31 31
     IGraphBuilder *graph;
32 32
 
33 33
     char *device_name[2];
34
+    int video_device_number;
35
+    int audio_device_number;
34 36
 
35 37
     int   list_options;
36 38
     int   list_devices;
... ...
@@ -249,6 +251,8 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
249 249
     IEnumMoniker *classenum = NULL;
250 250
     IMoniker *m = NULL;
251 251
     const char *device_name = ctx->device_name[devtype];
252
+    int skip = (devtype == VideoDevice) ? ctx->video_device_number
253
+                                        : ctx->audio_device_number;
252 254
     int r;
253 255
 
254 256
     const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
... ...
@@ -283,6 +287,7 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
283 283
             if (strcmp(device_name, buf))
284 284
                 goto fail1;
285 285
 
286
+            if (!skip--)
286 287
             IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);
287 288
         } else {
288 289
             av_log(avctx, AV_LOG_INFO, " \"%s\"\n", buf);
... ...
@@ -938,6 +943,8 @@ static const AVOption options[] = {
938 938
     { "list_options", "list available options for specified device", OFFSET(list_options), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_options" },
939 939
     { "true", "", 0, AV_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_options" },
940 940
     { "false", "", 0, AV_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_options" },
941
+    { "video_device_number", "set video device number for devices with same name (starts at 0)", OFFSET(video_device_number), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC },
942
+    { "audio_device_number", "set audio device number for devices with same name (starts at 0)", OFFSET(audio_device_number), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC },
941 943
     { NULL },
942 944
 };
943 945