]> git.sesse.net Git - vlc/blob - modules/access/dc1394.c
vpx: fix leak
[vlc] / modules / access / dc1394.c
1 /*****************************************************************************
2  * dc1394.c: IIDC (DCAM) FireWire input module
3  *****************************************************************************
4  * Copyright (C) 2006-2009 VideoLAN
5  *
6  * Authors: Xant Majere <xant@xant.net>
7  *          Rob Shortt <rob@tvcentric.com> - libdc1394 V2 API updates
8  *          Frederic Benoist <fridorik@gmail.com> - updates from Rob's work
9  *
10  *****************************************************************************
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU Lesser General Public License as published by
14  * the Free Software Foundation; either version 2.1 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program; if not, write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_demux.h>
38
39 #include <dc1394/dc1394.h>
40
41 #define MAX_IEEE1394_HOSTS 32
42 #define MAX_CAMERA_NODES 32
43
44 /*****************************************************************************
45  * Module descriptor
46  *****************************************************************************/
47 static int  Open ( vlc_object_t * );
48 static void Close( vlc_object_t * );
49
50 vlc_module_begin()
51     set_shortname( N_("DC1394") )
52     set_description( N_("IIDC Digital Camera (FireWire) input") )
53     set_capability( "access_demux", 10 )
54     set_callbacks( Open, Close )
55 vlc_module_end()
56
57 struct demux_sys_t
58 {
59     /* camera info */
60     dc1394_t            *p_dccontext;
61     uint32_t            num_cameras;
62     dc1394camera_t      *camera;
63     int                 selected_camera;
64     uint64_t            selected_uid;
65     uint32_t            dma_buffers;
66     dc1394featureset_t  features;
67     bool                reset_bus;
68
69     /* video info */
70     char                *video_device;
71     dc1394video_mode_t  video_mode;
72     int                 width;
73     int                 height;
74     int                 frame_size;
75     int                 frame_rate;
76     unsigned int        brightness;
77     unsigned int        focus;
78     es_out_id_t         *p_es_video;
79     dc1394video_frame_t *frame;
80 };
81
82 /*****************************************************************************
83  * Local prototypes
84  *****************************************************************************/
85 static int Demux( demux_t *p_demux );
86 static int Control( demux_t *, int, va_list );
87 static block_t *GrabVideo( demux_t *p_demux );
88 static int process_options( demux_t *p_demux);
89
90 /*****************************************************************************
91  * FindCameras
92  *****************************************************************************/
93 static int FindCamera( demux_sys_t *sys, demux_t *p_demux )
94 {
95     dc1394camera_list_t *list;
96     int i_ret = VLC_EGENERIC;
97
98     msg_Dbg( p_demux, "Scanning for ieee1394 ports ..." );
99
100     if( dc1394_camera_enumerate (sys->p_dccontext, &list) != DC1394_SUCCESS )
101     {
102         msg_Err(p_demux, "Can not ennumerate cameras");
103         goto end;
104     }
105
106     if( list->num == 0 )
107     {
108         msg_Err(p_demux, "Can not find cameras");
109         goto end;
110     }
111
112     sys->num_cameras = list->num;
113     msg_Dbg( p_demux, "Found %d dc1394 cameras.", list->num);
114
115     if( sys->selected_uid )
116     {
117         int found = 0;
118         for( unsigned i = 0; i < sys->num_cameras; i++ )
119         {
120             if( list->ids[i].guid == sys->selected_uid )
121             {
122                 sys->camera = dc1394_camera_new(sys->p_dccontext,
123                                                 list->ids[i].guid);
124                 found++;
125                 break;
126             }
127         }
128         if( !found )
129         {
130             msg_Err( p_demux, "Can't find camera with uid : 0x%"PRIx64".",
131                      sys->selected_uid );
132             goto end;
133         }
134     }
135     else if( sys->selected_camera >= (int)list->num )
136     {
137         msg_Err( p_demux, "There are not this many cameras. (%d/%d)",
138                  sys->selected_camera, sys->num_cameras );
139         goto end;
140     }
141     else if( sys->selected_camera >= 0 )
142     {
143         sys->camera = dc1394_camera_new(sys->p_dccontext,
144                     list->ids[sys->selected_camera].guid);
145     }
146     else
147     {
148         sys->camera = dc1394_camera_new(sys->p_dccontext,
149                                           list->ids[0].guid);
150     }
151
152     i_ret = VLC_SUCCESS;
153
154 end:
155     dc1394_camera_free_list (list);
156     return i_ret;
157 }
158
159 /*****************************************************************************
160  * Open:
161  *****************************************************************************/
162 static int Open( vlc_object_t *p_this )
163 {
164     demux_t      *p_demux = (demux_t*)p_this;
165     demux_sys_t  *p_sys;
166     es_format_t   fmt;
167     dc1394error_t res;
168
169     if( strncmp(p_demux->psz_access, "dc1394", 6) != 0 )
170         return VLC_EGENERIC;
171
172     /* Set up p_demux */
173     p_demux->pf_demux = Demux;
174     p_demux->pf_control = Control;
175     p_demux->info.i_update = 0;
176     p_demux->info.i_title = 0;
177     p_demux->info.i_seekpoint = 0;
178
179     p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
180     if( !p_sys )
181         return VLC_ENOMEM;
182
183     memset( &fmt, 0, sizeof( es_format_t ) );
184
185     /* DEFAULTS */
186     p_sys->video_mode      = DC1394_VIDEO_MODE_640x480_YUV422;
187     p_sys->width           = 640;
188     p_sys->height          = 480;
189     p_sys->frame_rate      = DC1394_FRAMERATE_15;
190     p_sys->brightness      = 200;
191     p_sys->focus           = 0;
192     p_sys->p_dccontext     = NULL;
193     p_sys->camera          = NULL;
194     p_sys->selected_camera = -1;
195     p_sys->dma_buffers     = 1;
196     p_sys->reset_bus       = 0;
197
198     /* PROCESS INPUT OPTIONS */
199     if( process_options(p_demux) != VLC_SUCCESS )
200     {
201         msg_Err( p_demux, "Bad MRL, please check the option line "
202                           "(MRL was: %s)",
203                           p_demux->psz_location );
204         free( p_sys );
205         return VLC_EGENERIC;
206     }
207
208     p_sys->p_dccontext = dc1394_new();
209     if( !p_sys->p_dccontext )
210     {
211         msg_Err( p_demux, "Failed to initialise libdc1394");
212         free( p_sys );
213         return VLC_EGENERIC;
214     }
215
216     if( FindCamera( p_sys, p_demux ) != VLC_SUCCESS )
217     {
218         dc1394_free( p_sys->p_dccontext );
219         free( p_sys );
220         return VLC_EGENERIC;
221     }
222
223     if( !p_sys->camera )
224     {
225         msg_Err( p_demux, "No camera found !!" );
226         dc1394_free( p_sys->p_dccontext );
227         free( p_sys );
228         return VLC_EGENERIC;
229     }
230
231     if( p_sys->reset_bus )
232     {
233         if( dc1394_reset_bus( p_sys->camera ) != DC1394_SUCCESS )
234         {
235             msg_Err( p_demux, "Unable to reset IEEE 1394 bus");
236             Close( p_this );
237             return VLC_EGENERIC;
238         }
239         else msg_Dbg( p_demux, "Successfully reset IEEE 1394 bus");
240     }
241
242     if( dc1394_camera_reset( p_sys->camera ) != DC1394_SUCCESS )
243     {
244         msg_Err( p_demux, "Unable to reset camera");
245         Close( p_this );
246         return VLC_EGENERIC;
247     }
248
249     if( dc1394_camera_print_info( p_sys->camera,
250                   stderr ) != DC1394_SUCCESS )
251     {
252         msg_Err( p_demux, "Unable to print camera info");
253         Close( p_this );
254         return VLC_EGENERIC;
255     }
256
257     if( dc1394_feature_get_all( p_sys->camera,
258                 &p_sys->features ) != DC1394_SUCCESS )
259     {
260         msg_Err( p_demux, "Unable to get feature set");
261         Close( p_this );
262         return VLC_EGENERIC;
263     }
264     // TODO: only print features if verbosity increased
265     dc1394_feature_print_all(&p_sys->features, stderr);
266
267 #if 0 //"Note that you need to execute this function only if you use exotic video1394 device names. /dev/video1394, /dev/video1394/* and /dev/video1394-* are automatically recognized." http://damien.douxchamps.net/ieee1394/libdc1394/v2.x/api/capture/
268     if( p_sys->video_device )
269     {
270         if( dc1394_capture_set_device_filename( p_sys->camera,
271                         p_sys->video_device ) != DC1394_SUCCESS )
272         {
273             msg_Err( p_demux, "Unable to set video device");
274             Close( p_this );
275             return VLC_EGENERIC;
276         }
277     }
278 #endif
279
280     if( p_sys->focus )
281     {
282         if( dc1394_feature_set_value( p_sys->camera,
283                       DC1394_FEATURE_FOCUS,
284                       p_sys->focus ) != DC1394_SUCCESS )
285         {
286             msg_Err( p_demux, "Unable to set initial focus to %u",
287                      p_sys->focus );
288         }
289         else
290             msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus );
291     }
292
293     if( dc1394_feature_set_value( p_sys->camera,
294                   DC1394_FEATURE_FOCUS,
295                   p_sys->brightness ) != DC1394_SUCCESS )
296     {
297         msg_Err( p_demux, "Unable to set initial brightness to %u",
298                  p_sys->brightness );
299     }
300     else
301         msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness );
302
303     if( dc1394_video_set_framerate( p_sys->camera,
304                     p_sys->frame_rate ) != DC1394_SUCCESS )
305     {
306         msg_Err( p_demux, "Unable to set framerate");
307         Close( p_this );
308         return VLC_EGENERIC;
309     }
310
311     if( dc1394_video_set_mode( p_sys->camera,
312                    p_sys->video_mode ) != DC1394_SUCCESS )
313     {
314         msg_Err( p_demux, "Unable to set video mode");
315         Close( p_this );
316         return VLC_EGENERIC;
317     }
318
319     if( dc1394_video_set_iso_speed( p_sys->camera,
320                     DC1394_ISO_SPEED_400 ) != DC1394_SUCCESS )
321     {
322         msg_Err( p_demux, "Unable to set iso speed");
323         Close( p_this );
324         return VLC_EGENERIC;
325     }
326
327     /* and setup capture */
328     res = dc1394_capture_setup( p_sys->camera,
329                     p_sys->dma_buffers,
330                 DC1394_CAPTURE_FLAGS_DEFAULT);
331     if( res != DC1394_SUCCESS )
332     {
333         if( res == DC1394_NO_BANDWIDTH )
334         {
335             msg_Err( p_demux ,"No bandwidth: try adding the "
336              "\"resetbus\" option" );
337         }
338         else
339         {
340             msg_Err( p_demux ,"Unable to setup capture" );
341         }
342         Close( p_this );
343         return VLC_EGENERIC;
344     }
345
346     /* TODO - UYV444 chroma converter is missing, when it will be available
347      * fourcc will become variable (and not just a fixed value for UYVY)
348      */
349     es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_UYVY );
350
351     fmt.video.i_width = p_sys->width;
352     fmt.video.i_height = p_sys->height;
353
354     msg_Dbg( p_demux, "Added new video es %4.4s %dx%d",
355              (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
356
357     p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
358
359     /* have the camera start sending us data */
360     if( dc1394_video_set_transmission( p_sys->camera,
361                        DC1394_ON ) != DC1394_SUCCESS )
362     {
363         msg_Err( p_demux, "Unable to start camera iso transmission" );
364         dc1394_capture_stop( p_sys->camera );
365         Close( p_this );
366         return VLC_EGENERIC;
367     }
368     msg_Dbg( p_demux, "Set iso transmission" );
369     // TODO: reread camera
370     return VLC_SUCCESS;
371 }
372
373 /*****************************************************************************
374  * Close:
375  *****************************************************************************/
376 static void Close( vlc_object_t *p_this )
377 {
378     demux_t     *p_demux = (demux_t*)p_this;
379     demux_sys_t *p_sys = p_demux->p_sys;
380
381     /* Stop data transmission */
382     if( dc1394_video_set_transmission( p_sys->camera,
383                        DC1394_OFF ) != DC1394_SUCCESS )
384         msg_Err( p_demux, "Unable to stop camera iso transmission" );
385
386     /* Close camera */
387     dc1394_capture_stop( p_sys->camera );
388
389     dc1394_camera_free(p_sys->camera);
390     dc1394_free(p_sys->p_dccontext);
391
392     free( p_sys->video_device );
393     free( p_sys );
394 }
395
396 #if 0
397 static void MovePixelUYVY( void *src, int spos, void *dst, int dpos )
398 {
399     char u,v,y;
400     u_char  *sc;
401     u_char  *dc;
402
403     sc = (u_char *)src + (spos*2);
404     if( spos % 2 )
405     {
406         v = sc[0];
407         y = sc[1];
408         u = *(sc -2);
409     }
410     else
411     {
412         u = sc[0];
413         y = sc[1];
414         v = sc[2];
415     }
416     dc = (u_char *)dst+(dpos*2);
417     if( dpos % 2 )
418     {
419         dc[0] = v;
420         dc[1] = y;
421     }
422     else
423     {
424         dc[0] = u;
425         dc[1] = y;
426     }
427 }
428 #endif
429
430 /*****************************************************************************
431  * Demux:
432  *****************************************************************************/
433 static block_t *GrabVideo( demux_t *p_demux )
434 {
435     demux_sys_t *p_sys = p_demux->p_sys;
436     block_t     *p_block = NULL;
437
438     if( dc1394_capture_dequeue( p_sys->camera,
439                 DC1394_CAPTURE_POLICY_WAIT,
440                 &p_sys->frame ) != DC1394_SUCCESS )
441     {
442         msg_Err( p_demux, "Unable to capture a frame" );
443         return NULL;
444     }
445
446     p_block = block_Alloc( p_sys->frame->size[0] * p_sys->frame->size[1] * 2 );
447     if( !p_block )
448     {
449         msg_Err( p_demux, "Can not get block" );
450         return NULL;
451     }
452
453     if( !p_sys->frame->image )
454     {
455         msg_Err (p_demux, "Capture buffer empty");
456         block_Release( p_block );
457         return NULL;
458     }
459
460     memcpy( p_block->p_buffer, (const char *)p_sys->frame->image,
461             p_sys->width * p_sys->height * 2 );
462
463     p_block->i_pts = p_block->i_dts = mdate();
464     dc1394_capture_enqueue( p_sys->camera, p_sys->frame );
465     return p_block;
466 }
467
468 static int Demux( demux_t *p_demux )
469 {
470     demux_sys_t *p_sys = p_demux->p_sys;
471     block_t *p_blockv = NULL;
472
473     /* Try grabbing video frame */
474     p_blockv = GrabVideo( p_demux );
475
476     if( !p_blockv )
477     {
478         /* Sleep so we do not consume all the cpu, 10ms seems
479          * like a good value (100fps)
480          */
481         msleep( 10000 );
482         return 1;
483     }
484
485     if( p_blockv )
486     {
487         es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_blockv->i_pts );
488         es_out_Send( p_demux->out, p_sys->p_es_video, p_blockv );
489     }
490     return 1;
491 }
492
493 /*****************************************************************************
494  * Control:
495  *****************************************************************************/
496 static int Control( demux_t *p_demux, int i_query, va_list args )
497 {
498     VLC_UNUSED( p_demux );
499     switch( i_query )
500     {
501         /* Special for access_demux */
502         case DEMUX_CAN_PAUSE:
503         case DEMUX_CAN_SEEK:
504         case DEMUX_SET_PAUSE_STATE:
505         case DEMUX_CAN_CONTROL_PACE:
506             *va_arg( args, bool * ) = false;
507             return VLC_SUCCESS;
508
509         case DEMUX_GET_PTS_DELAY:
510             *va_arg( args, int64_t * ) = (int64_t)DEFAULT_PTS_DELAY;
511             return VLC_SUCCESS;
512
513         case DEMUX_GET_TIME:
514             *va_arg( args, int64_t * ) = mdate();
515             return VLC_SUCCESS;
516
517         /* TODO implement others */
518         default:
519             return VLC_EGENERIC;
520     }
521     return VLC_EGENERIC;
522 }
523
524 static int process_options( demux_t *p_demux )
525 {
526     demux_sys_t *p_sys = p_demux->p_sys;
527     char *psz_dup;
528     char *psz_parser;
529     char *token = NULL;
530     char *state = NULL;
531     const char *in_size = NULL;
532     const char *in_fmt = NULL;
533     float rate_f;
534
535     psz_dup = strdup( p_demux->psz_location );
536     psz_parser = psz_dup;
537     for( token = strtok_r( psz_parser,":",&state); token;
538          token = strtok_r( NULL, ":", &state ) )
539     {
540         if( strncmp( token, "size=", strlen("size=") ) == 0 )
541         {
542             token += strlen("size=");
543             if( strncmp( token, "160x120", 7 ) == 0 )
544             {
545                 /* TODO - UYV444 chroma converter is needed ...
546                     * video size of 160x120 is temporarily disabled
547                     */
548                 msg_Err( p_demux,
549                     "video size of 160x120 is actually disabled for lack of"
550                     "chroma support. It will relased ASAP, until then try "
551                     "an higher size (320x240 and 640x480 are fully supported)" );
552                 free(psz_dup);
553                 return VLC_EGENERIC;
554 #if 0
555                 in_size = "160x120";
556                 p_sys->width = 160;
557                 p_sys->height = 120;
558 #endif
559             }
560             else if( strncmp( token, "320x240", 7 ) == 0 )
561             {
562                 in_size = "320x240";
563                 p_sys->width = 320;
564                 p_sys->height = 240;
565             }
566             else if( strncmp( token, "640x480", 7 ) == 0 )
567             {
568                 in_size = "640x480";
569                 p_sys->width = 640;
570                 p_sys->height = 480;
571             }
572             else
573             {
574                 msg_Err( p_demux,
575                     "This program currently suppots frame sizes of"
576                     " 160x120, 320x240, and 640x480. "
577                     "Please specify one of them. You have specified %s.",
578                     token );
579                 free(psz_dup);
580                 return VLC_EGENERIC;
581             }
582             msg_Dbg( p_demux, "Requested video size : %s",token );
583         }
584         if( strncmp( token, "format=", strlen("format=") ) == 0 )
585         {
586             token += strlen("format=");
587             if( strncmp( token, "YUV411", 6 ) == 0 )
588             {
589                 in_fmt = "YUV411";
590             }
591             else if( strncmp( token, "YUV422", 6 ) == 0 )
592             {
593                 in_fmt = "YUV422";
594             }
595             else if( strncmp( token, "YUV444", 6 ) == 0 )
596             {
597                 in_fmt = "YUV444";
598             }
599             else if( strncmp( token, "RGB8", 4 ) == 0 )
600             {
601                 in_fmt = "RGB8";
602             }
603             else if( strncmp( token, "MONO8", 5 ) == 0 )
604             {
605                 in_fmt = "MONO8";
606             }
607             else if( strncmp( token, "MONO16", 6 ) == 0 )
608             {
609                 in_fmt = "MONO16";
610             }
611             else
612             {
613                 msg_Err( p_demux, "Invalid format %s.", token );
614                 free(psz_dup);
615                 return VLC_EGENERIC;
616             }
617             msg_Dbg( p_demux, "Requested video format : %s", token );
618         }
619         else if( strncmp( token, "fps=", strlen( "fps=" ) ) == 0 )
620         {
621             token += strlen("fps=");
622             sscanf( token, "%g", &rate_f );
623             if( rate_f == 1.875 )
624                 p_sys->frame_rate = DC1394_FRAMERATE_1_875;
625             else if( rate_f == 3.75 )
626                 p_sys->frame_rate = DC1394_FRAMERATE_3_75;
627             else if( rate_f == 7.5 )
628                 p_sys->frame_rate = DC1394_FRAMERATE_7_5;
629             else if( rate_f == 15 )
630                 p_sys->frame_rate = DC1394_FRAMERATE_15;
631             else if( rate_f == 30 )
632                 p_sys->frame_rate = DC1394_FRAMERATE_30;
633             else if( rate_f == 60 )
634                 p_sys->frame_rate = DC1394_FRAMERATE_60;
635             else
636             {
637                 msg_Err( p_demux ,
638                     "This program supports framerates of"
639                     " 1.875, 3.75, 7.5, 15, 30, 60. "
640                     "Please specify one of them. You have specified %s.",
641                     token);
642                 free(psz_dup);
643                 return VLC_EGENERIC;
644             }
645             msg_Dbg( p_demux, "Requested frame rate : %s",token );
646         }
647         else if( strncmp( token, "resetbus", strlen( "resetbus" ) ) == 0 )
648         {
649             token += strlen("resetbus");
650             p_sys->reset_bus = 1;
651         }
652         else if( strncmp( token, "brightness=", strlen( "brightness=" ) ) == 0 )
653         {
654             int nr = 0;
655             token += strlen("brightness=");
656             nr = sscanf( token, "%u", &p_sys->brightness);
657             if( nr != 1 )
658             {
659                 msg_Err( p_demux, "Bad brightness value '%s', "
660                                   "must be an unsigned integer.",
661                                   token );
662                 free(psz_dup);
663                 return VLC_EGENERIC;
664             }
665         }
666         else if( strncmp( token, "buffers=", strlen( "buffers=" ) ) == 0 )
667         {
668             int nr = 0;
669             int in_buf = 0;
670             token += strlen("buffers=");
671             nr = sscanf( token, "%d", &in_buf);
672             if( nr != 1 || in_buf < 1 )
673             {
674                 msg_Err( p_demux, "DMA buffers must be 1 or greater." );
675                 free(psz_dup);
676                 return VLC_EGENERIC;
677             }
678             else p_sys->dma_buffers = in_buf;
679         }
680 #if 0
681         // NOTE: If controller support is added back, more logic will needed to be added
682         //       after the cameras are scanned.
683         else if( strncmp( token, "controller=", strlen( "controller=" ) ) == 0 )
684         {
685             int nr = 0;
686             token += strlen("controller=");
687             nr = sscanf( token, "%u", &p_sys->controller );
688             if( nr != 1)
689             {
690                 msg_Err(p_demux, "Bad controller value '%s', "
691                                  "must be an unsigned integer.",
692                                  token );
693                 return VLC_EGENERIC;
694             }
695         }
696 #endif
697         else if( strncmp( token, "camera=", strlen( "camera=" ) ) == 0 )
698         {
699             int nr = 0;
700             token += strlen("camera=");
701             nr = sscanf(token,"%u",&p_sys->selected_camera);
702             if( nr != 1)
703             {
704                 msg_Err( p_demux, "Bad camera number '%s', "
705                                   "must be an unsigned integer.",
706                                   token );
707                 free(psz_dup);
708                 return VLC_EGENERIC;
709             }
710         }
711         else if( strncmp( token, "vdev=", strlen( "vdev=" ) ) == 0)
712         {
713             token += strlen("vdev=");
714             p_sys->video_device = strdup(token);
715             msg_Dbg( p_demux, "Using video device '%s'.", token );
716         }
717         else if( strncmp( token, "focus=", strlen("focus=" ) ) == 0)
718         {
719             int nr = 0;
720             token += strlen("focus=");
721             nr = sscanf( token, "%u", &p_sys->focus );
722             if( nr != 1 )
723             {
724                 msg_Err( p_demux, "Bad focus value '%s', "
725                                   "must be an unsigned integer.",
726                                   token );
727                 free(psz_dup);
728                 return VLC_EGENERIC;
729             }
730         }
731         else if( strncmp( token, "uid=", strlen("uid=") ) == 0)
732         {
733             token += strlen("uid=");
734             sscanf( token, "0x%"SCNx64, &p_sys->selected_uid );
735         }
736     }
737
738     // The mode is a combination of size and format and not every format
739     // is supported by every size.
740     if( in_size)
741     {
742         if( strcmp( in_size, "160x120") == 0)
743         {
744             if( in_fmt && (strcmp( in_fmt, "YUV444") != 0) )
745                 msg_Err(p_demux, "160x120 only supports YUV444 - forcing");
746             p_sys->video_mode = DC1394_VIDEO_MODE_160x120_YUV444;
747         }
748         else if( strcmp( in_size, "320x240") == 0)
749         {
750             if( in_fmt && (strcmp( in_fmt, "YUV422") != 0) )
751                 msg_Err(p_demux, "320x240 only supports YUV422 - forcing");
752             p_sys->video_mode = DC1394_VIDEO_MODE_320x240_YUV422;
753         }
754     }
755     else
756     { // 640x480 default
757         if( in_fmt )
758         {
759             if( strcmp( in_fmt, "RGB8") == 0)
760                 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_RGB8;
761             else if( strcmp( in_fmt, "MONO8") == 0)
762                 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_MONO8;
763             else if( strcmp( in_fmt, "MONO16") == 0)
764                 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_MONO16;
765             else if( strcmp( in_fmt, "YUV411") == 0)
766                 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV411;
767             else // YUV422 default
768                 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
769         }
770         else // YUV422 default
771             p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
772     }
773
774     free( psz_dup );
775     return VLC_SUCCESS;
776 }