dc1394.c 24.1 KB
Newer Older
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 8
 *          Rob Shortt <rob@tvcentric.com> - libdc1394 V2 API updates
 *          Frederic Benoist <fridorik@gmail.com> - updates from Rob's work
9 10 11
 *
 *****************************************************************************
 *
12 13 14 15
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
16
 *
17 18
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Lesser General Public License for more details.
21
 *
22 23 24
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 26 27 28 29 30
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

31 32 33 34
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

35
#include <vlc_common.h>
36
#include <vlc_plugin.h>
37
#include <vlc_demux.h>
38

39
#include <dc1394/dc1394.h>
40 41 42 43 44 45 46 47 48 49

#define MAX_IEEE1394_HOSTS 32
#define MAX_CAMERA_NODES 32

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
static int  Open ( vlc_object_t * );
static void Close( vlc_object_t * );

50
vlc_module_begin()
51 52
    set_shortname( N_("DC1394") )
    set_description( N_("IIDC Digital Camera (FireWire) input") )
53 54
    set_capability( "access_demux", 10 )
    set_callbacks( Open, Close )
55
vlc_module_end()
56

57
struct demux_sys_t
58
{
59 60 61 62
    /* camera info */
    dc1394_t            *p_dccontext;
    uint32_t            num_cameras;
    dc1394camera_t      *camera;
63
    int                 selected_camera;
64 65 66 67
    uint64_t            selected_uid;
    uint32_t            dma_buffers;
    dc1394featureset_t  features;
    bool                reset_bus;
68

69 70 71
    /* video info */
    char                *video_device;
    dc1394video_mode_t  video_mode;
72 73 74 75 76 77 78
    int                 width;
    int                 height;
    int                 frame_size;
    int                 frame_rate;
    unsigned int        brightness;
    unsigned int        focus;
    es_out_id_t         *p_es_video;
79 80
    dc1394video_frame_t *frame;
};
81 82 83 84 85 86 87 88 89 90

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int Demux( demux_t *p_demux );
static int Control( demux_t *, int, va_list );
static block_t *GrabVideo( demux_t *p_demux );
static int process_options( demux_t *p_demux);

/*****************************************************************************
91
 * FindCameras
92
 *****************************************************************************/
93
static int FindCamera( demux_sys_t *sys, demux_t *p_demux )
94
{
95
    dc1394camera_list_t *list;
Rémi Duraffort's avatar
Rémi Duraffort committed
96
    int i_ret = VLC_EGENERIC;
97 98 99

    msg_Dbg( p_demux, "Scanning for ieee1394 ports ..." );

100 101 102
    if( dc1394_camera_enumerate (sys->p_dccontext, &list) != DC1394_SUCCESS )
    {
        msg_Err(p_demux, "Can not ennumerate cameras");
Rémi Duraffort's avatar
Rémi Duraffort committed
103
        goto end;
104
    }
105

106 107 108
    if( list->num == 0 )
    {
        msg_Err(p_demux, "Can not find cameras");
Rémi Duraffort's avatar
Rémi Duraffort committed
109
        goto end;
110 111 112 113
    }

    sys->num_cameras = list->num;
    msg_Dbg( p_demux, "Found %d dc1394 cameras.", list->num);
114

115 116 117 118 119 120
    if( sys->selected_uid )
    {
        int found = 0;
        for( unsigned i = 0; i < sys->num_cameras; i++ )
        {
            if( list->ids[i].guid == sys->selected_uid )
121
            {
122 123 124 125
                sys->camera = dc1394_camera_new(sys->p_dccontext,
                                                list->ids[i].guid);
                found++;
                break;
126 127
            }
        }
128 129
        if( !found )
        {
Rémi Duraffort's avatar
Rémi Duraffort committed
130
            msg_Err( p_demux, "Can't find camera with uid : 0x%"PRIx64".",
131
                     sys->selected_uid );
Rémi Duraffort's avatar
Rémi Duraffort committed
132
            goto end;
133 134 135 136 137 138
        }
    }
    else if( sys->selected_camera >= (int)list->num )
    {
        msg_Err( p_demux, "There are not this many cameras. (%d/%d)",
                 sys->selected_camera, sys->num_cameras );
Rémi Duraffort's avatar
Rémi Duraffort committed
139
        goto end;
140 141 142 143 144 145 146 147 148 149
    }
    else if( sys->selected_camera >= 0 )
    {
        sys->camera = dc1394_camera_new(sys->p_dccontext,
                    list->ids[sys->selected_camera].guid);
    }
    else
    {
        sys->camera = dc1394_camera_new(sys->p_dccontext,
                                          list->ids[0].guid);
150
    }
151

Rémi Duraffort's avatar
Rémi Duraffort committed
152 153 154
    i_ret = VLC_SUCCESS;

end:
155
    dc1394_camera_free_list (list);
Rémi Duraffort's avatar
Rémi Duraffort committed
156
    return i_ret;
157 158 159 160 161 162 163
}

/*****************************************************************************
 * Open:
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
164 165 166 167
    demux_t      *p_demux = (demux_t*)p_this;
    demux_sys_t  *p_sys;
    es_format_t   fmt;
    dc1394error_t res;
168

169 170 171
    if( strncmp(p_demux->psz_access, "dc1394", 6) != 0 )
        return VLC_EGENERIC;

172 173 174 175 176 177 178
    /* Set up p_demux */
    p_demux->pf_demux = Demux;
    p_demux->pf_control = Control;
    p_demux->info.i_update = 0;
    p_demux->info.i_title = 0;
    p_demux->info.i_seekpoint = 0;

179
    p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
180 181
    if( !p_sys )
        return VLC_ENOMEM;
182

183 184 185
    memset( &fmt, 0, sizeof( es_format_t ) );

    /* DEFAULTS */
186 187 188 189 190 191 192 193 194 195 196
    p_sys->video_mode      = DC1394_VIDEO_MODE_640x480_YUV422;
    p_sys->width           = 640;
    p_sys->height          = 480;
    p_sys->frame_rate      = DC1394_FRAMERATE_15;
    p_sys->brightness      = 200;
    p_sys->focus           = 0;
    p_sys->p_dccontext     = NULL;
    p_sys->camera          = NULL;
    p_sys->selected_camera = -1;
    p_sys->dma_buffers     = 1;
    p_sys->reset_bus       = 0;
197 198 199 200 201 202

    /* PROCESS INPUT OPTIONS */
    if( process_options(p_demux) != VLC_SUCCESS )
    {
        msg_Err( p_demux, "Bad MRL, please check the option line "
                          "(MRL was: %s)",
203
                          p_demux->psz_location );
204 205 206 207
        free( p_sys );
        return VLC_EGENERIC;
    }

208 209 210 211
    p_sys->p_dccontext = dc1394_new();
    if( !p_sys->p_dccontext )
    {
        msg_Err( p_demux, "Failed to initialise libdc1394");
212
        free( p_sys );
213 214 215 216
        return VLC_EGENERIC;
    }

    if( FindCamera( p_sys, p_demux ) != VLC_SUCCESS )
Rémi Duraffort's avatar
Rémi Duraffort committed
217 218 219
    {
        dc1394_free( p_sys->p_dccontext );
        free( p_sys );
220
        return VLC_EGENERIC;
Rémi Duraffort's avatar
Rémi Duraffort committed
221
    }
222

223
    if( !p_sys->camera )
224 225
    {
        msg_Err( p_demux, "No camera found !!" );
226
        dc1394_free( p_sys->p_dccontext );
227 228 229 230
        free( p_sys );
        return VLC_EGENERIC;
    }

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 237 238
            Close( p_this );
            return VLC_EGENERIC;
        }
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 246 247 248
        Close( p_this );
        return VLC_EGENERIC;
    }

249 250
    if( dc1394_camera_print_info( p_sys->camera,
                  stderr ) != DC1394_SUCCESS )
251
    {
252
        msg_Err( p_demux, "Unable to print camera info");
253 254 255 256
        Close( p_this );
        return VLC_EGENERIC;
    }

257 258
    if( dc1394_feature_get_all( p_sys->camera,
                &p_sys->features ) != DC1394_SUCCESS )
259
    {
260
        msg_Err( p_demux, "Unable to get feature set");
261 262 263
        Close( p_this );
        return VLC_EGENERIC;
    }
264 265
    // TODO: only print features if verbosity increased
    dc1394_feature_print_all(&p_sys->features, stderr);
266

267 268
#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/
    if( p_sys->video_device )
269
    {
270 271 272 273 274 275 276
        if( dc1394_capture_set_device_filename( p_sys->camera,
                        p_sys->video_device ) != DC1394_SUCCESS )
        {
            msg_Err( p_demux, "Unable to set video device");
            Close( p_this );
            return VLC_EGENERIC;
        }
277
    }
278
#endif
279 280 281

    if( p_sys->focus )
    {
282 283 284
        if( dc1394_feature_set_value( p_sys->camera,
                      DC1394_FEATURE_FOCUS,
                      p_sys->focus ) != DC1394_SUCCESS )
285
        {
286
            msg_Err( p_demux, "Unable to set initial focus to %u",
287 288
                     p_sys->focus );
        }
289 290
        else
            msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus );
291 292
    }

293 294 295
    if( dc1394_feature_set_value( p_sys->camera,
                  DC1394_FEATURE_FOCUS,
                  p_sys->brightness ) != DC1394_SUCCESS )
296
    {
297 298
        msg_Err( p_demux, "Unable to set initial brightness to %u",
                 p_sys->brightness );
299
    }
300 301
    else
        msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness );
302

303 304
    if( dc1394_video_set_framerate( p_sys->camera,
                    p_sys->frame_rate ) != DC1394_SUCCESS )
305
    {
306
        msg_Err( p_demux, "Unable to set framerate");
307 308 309 310
        Close( p_this );
        return VLC_EGENERIC;
    }

311 312
    if( dc1394_video_set_mode( p_sys->camera,
                   p_sys->video_mode ) != DC1394_SUCCESS )
313
    {
314
        msg_Err( p_demux, "Unable to set video mode");
315 316 317 318
        Close( p_this );
        return VLC_EGENERIC;
    }

319 320
    if( dc1394_video_set_iso_speed( p_sys->camera,
                    DC1394_ISO_SPEED_400 ) != DC1394_SUCCESS )
321
    {
322
        msg_Err( p_demux, "Unable to set iso speed");
323 324 325 326 327
        Close( p_this );
        return VLC_EGENERIC;
    }

    /* and setup capture */
328 329 330 331 332 333
    res = dc1394_capture_setup( p_sys->camera,
                    p_sys->dma_buffers,
                DC1394_CAPTURE_FLAGS_DEFAULT);
    if( res != DC1394_SUCCESS )
    {
        if( res == DC1394_NO_BANDWIDTH )
334
        {
335 336
            msg_Err( p_demux ,"No bandwidth: try adding the "
             "\"resetbus\" option" );
337
        }
338
        else
339
        {
340
            msg_Err( p_demux ,"Unable to setup capture" );
341
        }
342 343
        Close( p_this );
        return VLC_EGENERIC;
344 345 346 347 348
    }

    /* TODO - UYV444 chroma converter is missing, when it will be available
     * fourcc will become variable (and not just a fixed value for UYVY)
     */
349
    es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_UYVY );
350

351 352
    fmt.video.i_width = p_sys->width;
    fmt.video.i_height = p_sys->height;
353

354
    msg_Dbg( p_demux, "Added new video es %4.4s %dx%d",
355 356 357 358 359
             (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );

    p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );

    /* have the camera start sending us data */
360 361
    if( dc1394_video_set_transmission( p_sys->camera,
                       DC1394_ON ) != DC1394_SUCCESS )
362
    {
363 364
        msg_Err( p_demux, "Unable to start camera iso transmission" );
        dc1394_capture_stop( p_sys->camera );
365 366 367
        Close( p_this );
        return VLC_EGENERIC;
    }
368 369
    msg_Dbg( p_demux, "Set iso transmission" );
    // TODO: reread camera
370 371 372 373 374 375 376 377 378 379 380 381
    return VLC_SUCCESS;
}

/*****************************************************************************
 * Close:
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    demux_t     *p_demux = (demux_t*)p_this;
    demux_sys_t *p_sys = p_demux->p_sys;

    /* Stop data transmission */
382 383 384
    if( dc1394_video_set_transmission( p_sys->camera,
                       DC1394_OFF ) != DC1394_SUCCESS )
        msg_Err( p_demux, "Unable to stop camera iso transmission" );
385 386

    /* Close camera */
387
    dc1394_capture_stop( p_sys->camera );
388

389 390 391
    dc1394_camera_free(p_sys->camera);
    dc1394_free(p_sys->p_dccontext);

Rémi Duraffort's avatar
Rémi Duraffort committed
392
    free( p_sys->video_device );
393 394 395
    free( p_sys );
}

396
#if 0
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
static void MovePixelUYVY( void *src, int spos, void *dst, int dpos )
{
    char u,v,y;
    u_char  *sc;
    u_char  *dc;

    sc = (u_char *)src + (spos*2);
    if( spos % 2 )
    {
        v = sc[0];
        y = sc[1];
        u = *(sc -2);
    }
    else
    {
        u = sc[0];
        y = sc[1];
        v = sc[2];
    }
    dc = (u_char *)dst+(dpos*2);
    if( dpos % 2 )
    {
        dc[0] = v;
        dc[1] = y;
    }
    else
    {
        dc[0] = u;
        dc[1] = y;
    }
}
428
#endif
429 430 431 432 433 434 435 436 437

/*****************************************************************************
 * Demux:
 *****************************************************************************/
static block_t *GrabVideo( demux_t *p_demux )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    block_t     *p_block = NULL;

438 439 440
    if( dc1394_capture_dequeue( p_sys->camera,
                DC1394_CAPTURE_POLICY_WAIT,
                &p_sys->frame ) != DC1394_SUCCESS )
441
    {
442 443
        msg_Err( p_demux, "Unable to capture a frame" );
        return NULL;
444 445
    }

446 447
    p_block = block_New( p_demux, p_sys->frame->size[0] *
                                  p_sys->frame->size[1] * 2 );
448 449
    if( !p_block )
    {
450
        msg_Err( p_demux, "Can not get block" );
451 452 453
        return NULL;
    }

454
    if( !p_sys->frame->image )
455
    {
456
        msg_Err (p_demux, "Capture buffer empty");
457 458 459 460
        block_Release( p_block );
        return NULL;
    }

461 462
    memcpy( p_block->p_buffer, (const char *)p_sys->frame->image,
            p_sys->width * p_sys->height * 2 );
463 464

    p_block->i_pts = p_block->i_dts = mdate();
465
    dc1394_capture_enqueue( p_sys->camera, p_sys->frame );
466 467 468 469 470 471 472 473 474
    return p_block;
}

static int Demux( demux_t *p_demux )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    block_t *p_blockv = NULL;

    /* Try grabbing video frame */
475
    p_blockv = GrabVideo( p_demux );
476

477
    if( !p_blockv )
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
    {
        /* Sleep so we do not consume all the cpu, 10ms seems
         * like a good value (100fps)
         */
        msleep( 10000 );
        return 1;
    }

    if( p_blockv )
    {
        es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_blockv->i_pts );
        es_out_Send( p_demux->out, p_sys->p_es_video, p_blockv );
    }
    return 1;
}

/*****************************************************************************
 * Control:
 *****************************************************************************/
static int Control( demux_t *p_demux, int i_query, va_list args )
{
499
    VLC_UNUSED( p_demux );
500 501 502 503
    switch( i_query )
    {
        /* Special for access_demux */
        case DEMUX_CAN_PAUSE:
504
        case DEMUX_CAN_SEEK:
505 506
        case DEMUX_SET_PAUSE_STATE:
        case DEMUX_CAN_CONTROL_PACE:
507
            *va_arg( args, bool * ) = false;
508 509 510
            return VLC_SUCCESS;

        case DEMUX_GET_PTS_DELAY:
511
            *va_arg( args, int64_t * ) = (int64_t)DEFAULT_PTS_DELAY;
512 513 514
            return VLC_SUCCESS;

        case DEMUX_GET_TIME:
515
            *va_arg( args, int64_t * ) = mdate();
516 517 518 519 520 521 522 523 524 525 526 527
            return VLC_SUCCESS;

        /* TODO implement others */
        default:
            return VLC_EGENERIC;
    }
    return VLC_EGENERIC;
}

static int process_options( demux_t *p_demux )
{
    demux_sys_t *p_sys = p_demux->p_sys;
528
    char *psz_dup;
529 530 531
    char *psz_parser;
    char *token = NULL;
    char *state = NULL;
532 533
    const char *in_size = NULL;
    const char *in_fmt = NULL;
534 535
    float rate_f;

536
    psz_dup = strdup( p_demux->psz_location );
537 538 539 540 541 542 543 544 545 546 547 548 549
    psz_parser = psz_dup;
    for( token = strtok_r( psz_parser,":",&state); token;
         token = strtok_r( NULL, ":", &state ) )
    {
        if( strncmp( token, "size=", strlen("size=") ) == 0 )
        {
            token += strlen("size=");
            if( strncmp( token, "160x120", 7 ) == 0 )
            {
                /* TODO - UYV444 chroma converter is needed ...
                    * video size of 160x120 is temporarily disabled
                    */
                msg_Err( p_demux,
550 551 552 553
                    "video size of 160x120 is actually disabled for lack of"
                    "chroma support. It will relased ASAP, until then try "
                    "an higher size (320x240 and 640x480 are fully supported)" );
                free(psz_dup);
554 555
                return VLC_EGENERIC;
#if 0
556
                in_size = "160x120";
557 558 559 560 561 562
                p_sys->width = 160;
                p_sys->height = 120;
#endif
            }
            else if( strncmp( token, "320x240", 7 ) == 0 )
            {
563
                in_size = "320x240";
564 565 566 567 568
                p_sys->width = 320;
                p_sys->height = 240;
            }
            else if( strncmp( token, "640x480", 7 ) == 0 )
            {
569
                in_size = "640x480";
570 571 572 573 574 575 576 577 578 579
                p_sys->width = 640;
                p_sys->height = 480;
            }
            else
            {
                msg_Err( p_demux,
                    "This program currently suppots frame sizes of"
                    " 160x120, 320x240, and 640x480. "
                    "Please specify one of them. You have specified %s.",
                    token );
580
                free(psz_dup);
581 582 583 584
                return VLC_EGENERIC;
            }
            msg_Dbg( p_demux, "Requested video size : %s",token );
        }
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
        if( strncmp( token, "format=", strlen("format=") ) == 0 )
        {
            token += strlen("format=");
            if( strncmp( token, "YUV411", 6 ) == 0 )
            {
                in_fmt = "YUV411";
            }
            else if( strncmp( token, "YUV422", 6 ) == 0 )
            {
                in_fmt = "YUV422";
            }
            else if( strncmp( token, "YUV444", 6 ) == 0 )
            {
                in_fmt = "YUV444";
            }
            else if( strncmp( token, "RGB8", 4 ) == 0 )
            {
                in_fmt = "RGB8";
            }
            else if( strncmp( token, "MONO8", 5 ) == 0 )
            {
                in_fmt = "MONO8";
            }
            else if( strncmp( token, "MONO16", 6 ) == 0 )
            {
                in_fmt = "MONO16";
            }
            else
            {
                msg_Err( p_demux, "Invalid format %s.", token );
                free(psz_dup);
                return VLC_EGENERIC;
            }
            msg_Dbg( p_demux, "Requested video format : %s", token );
        }
620 621 622 623 624
        else if( strncmp( token, "fps=", strlen( "fps=" ) ) == 0 )
        {
            token += strlen("fps=");
            sscanf( token, "%g", &rate_f );
            if( rate_f == 1.875 )
625
                p_sys->frame_rate = DC1394_FRAMERATE_1_875;
626
            else if( rate_f == 3.75 )
627
                p_sys->frame_rate = DC1394_FRAMERATE_3_75;
628
            else if( rate_f == 7.5 )
629
                p_sys->frame_rate = DC1394_FRAMERATE_7_5;
630
            else if( rate_f == 15 )
631
                p_sys->frame_rate = DC1394_FRAMERATE_15;
632
            else if( rate_f == 30 )
633
                p_sys->frame_rate = DC1394_FRAMERATE_30;
634
            else if( rate_f == 60 )
635
                p_sys->frame_rate = DC1394_FRAMERATE_60;
636 637 638 639 640 641 642
            else
            {
                msg_Err( p_demux ,
                    "This program supports framerates of"
                    " 1.875, 3.75, 7.5, 15, 30, 60. "
                    "Please specify one of them. You have specified %s.",
                    token);
643
                free(psz_dup);
644 645 646 647
                return VLC_EGENERIC;
            }
            msg_Dbg( p_demux, "Requested frame rate : %s",token );
        }
648 649 650 651 652
        else if( strncmp( token, "resetbus", strlen( "resetbus" ) ) == 0 )
        {
            token += strlen("resetbus");
            p_sys->reset_bus = 1;
        }
653 654 655 656 657 658 659 660 661 662
        else if( strncmp( token, "brightness=", strlen( "brightness=" ) ) == 0 )
        {
            int nr = 0;
            token += strlen("brightness=");
            nr = sscanf( token, "%u", &p_sys->brightness);
            if( nr != 1 )
            {
                msg_Err( p_demux, "Bad brightness value '%s', "
                                  "must be an unsigned integer.",
                                  token );
663 664 665 666 667 668 669 670 671 672 673 674 675 676
                free(psz_dup);
                return VLC_EGENERIC;
            }
        }
        else if( strncmp( token, "buffers=", strlen( "buffers=" ) ) == 0 )
        {
            int nr = 0;
            int in_buf = 0;
            token += strlen("buffers=");
            nr = sscanf( token, "%d", &in_buf);
            if( nr != 1 || in_buf < 1 )
            {
                msg_Err( p_demux, "DMA buffers must be 1 or greater." );
                free(psz_dup);
677 678
                return VLC_EGENERIC;
            }
679
            else p_sys->dma_buffers = in_buf;
680 681
        }
#if 0
682 683
        // NOTE: If controller support is added back, more logic will needed to be added
        //       after the cameras are scanned.
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
        else if( strncmp( token, "controller=", strlen( "controller=" ) ) == 0 )
        {
            int nr = 0;
            token += strlen("controller=");
            nr = sscanf( token, "%u", &p_sys->controller );
            if( nr != 1)
            {
                msg_Err(p_demux, "Bad controller value '%s', "
                                 "must be an unsigned integer.",
                                 token );
                return VLC_EGENERIC;
            }
        }
#endif
        else if( strncmp( token, "camera=", strlen( "camera=" ) ) == 0 )
        {
            int nr = 0;
            token += strlen("camera=");
            nr = sscanf(token,"%u",&p_sys->selected_camera);
            if( nr != 1)
            {
                msg_Err( p_demux, "Bad camera number '%s', "
                                  "must be an unsigned integer.",
                                  token );
708
                free(psz_dup);
709 710 711
                return VLC_EGENERIC;
            }
        }
712
        else if( strncmp( token, "vdev=", strlen( "vdev=" ) ) == 0)
713
        {
714 715 716
            token += strlen("vdev=");
            p_sys->video_device = strdup(token);
            msg_Dbg( p_demux, "Using video device '%s'.", token );
717 718 719
        }
        else if( strncmp( token, "focus=", strlen("focus=" ) ) == 0)
        {
720
            int nr = 0;
721
            token += strlen("focus=");
722 723 724 725 726 727 728 729 730
            nr = sscanf( token, "%u", &p_sys->focus );
            if( nr != 1 )
            {
                msg_Err( p_demux, "Bad focus value '%s', "
                                  "must be an unsigned integer.",
                                  token );
                free(psz_dup);
                return VLC_EGENERIC;
            }
731 732 733 734
        }
        else if( strncmp( token, "uid=", strlen("uid=") ) == 0)
        {
            token += strlen("uid=");
735
            sscanf( token, "0x%"SCNx64, &p_sys->selected_uid );
736 737
        }
    }
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773

    // The mode is a combination of size and format and not every format
    // is supported by every size.
    if( in_size)
    {
        if( strcmp( in_size, "160x120") == 0)
        {
            if( in_fmt && (strcmp( in_fmt, "YUV444") != 0) )
                msg_Err(p_demux, "160x120 only supports YUV444 - forcing");
            p_sys->video_mode = DC1394_VIDEO_MODE_160x120_YUV444;
        }
        else if( strcmp( in_size, "320x240") == 0)
        {
            if( in_fmt && (strcmp( in_fmt, "YUV422") != 0) )
                msg_Err(p_demux, "320x240 only supports YUV422 - forcing");
            p_sys->video_mode = DC1394_VIDEO_MODE_320x240_YUV422;
        }
    }
    else
    { // 640x480 default
        if( in_fmt )
        {
            if( strcmp( in_fmt, "RGB8") == 0)
                p_sys->video_mode = DC1394_VIDEO_MODE_640x480_RGB8;
            else if( strcmp( in_fmt, "MONO8") == 0)
                p_sys->video_mode = DC1394_VIDEO_MODE_640x480_MONO8;
            else if( strcmp( in_fmt, "MONO16") == 0)
                p_sys->video_mode = DC1394_VIDEO_MODE_640x480_MONO16;
            else if( strcmp( in_fmt, "YUV411") == 0)
                p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV411;
            else // YUV422 default
                p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
        }
        else // YUV422 default
            p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
    }
Rémi Duraffort's avatar
Rémi Duraffort committed
774 775

    free( psz_dup );
776 777
    return VLC_SUCCESS;
}