Changeset 7f4aba6183dab7a43b2d87ce8b73383aa5d79aa0

Show
Ignore:
Timestamp:
01/01/08 15:54:42 (6 months ago)
Author:
Antoine Cellerier <dionoea@videolan.org>
git-committer:
Antoine Cellerier <dionoea@videolan.org> 1199199282 +0000
git-parent:

[5ceb0f293b338279011f5aa7cafa8b86888e3768]

git-author:
Antoine Cellerier <dionoea@videolan.org> 1199199282 +0000
Message:

v4l2: Factorize code, fix the video controls init, add Dennis Lou's contributions to the v4l2 module in THANKS.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • THANKS

    r7b08761 r7f4aba6  
    6767Davor Orel <syntheticamac at yahoo.it> - Mac OS X icons 
    6868Dennis van Amerongen <Dennis dot vanAmerongen at nob dot nl> - x264 options unification 
    69 Dennis Lou <dlou99 at yahoo dot com> - ATSC support in the DVB module 
     69Dennis Lou <dlou99 at yahoo dot com> - ATSC support in the DVB module, MPEG2 support in the v4l2 module 
    7070Dermot McGahon <dermot at dspsrv dot com> - Bug fixes, RC interface loop and repeat 
    7171Diego Petteno <flameeyes at gentoo dot org> - remove usage of internal ffmpeg symbols, configure fixes 
  • modules/access/v4l2.c

    r7778719 r7f4aba6  
    77 * Authors: Benjamin Pracht <bigben at videolan dot org> 
    88 *          Richard Hosking <richard at hovis dot net> 
    9  *          Antoine Cellerier <dionoea at videolan d.t net> 
     9 *          Antoine Cellerier <dionoea at videolan d.t org> 
     10 *          Dennis Lou <dlou99 at yahoo dot com> 
    1011 * 
    1112 * This program is free software; you can redistribute it and/or modify 
     
    108109#define BRIGHTNESS_TEXT N_( "Brightness" ) 
    109110#define BRIGHTNESS_LONGTEXT N_( \ 
    110     "Brightness of the video input." ) 
     111    "Brightness of the video input (if supported by v4l2 driver)." ) 
    111112#define CONTRAST_TEXT N_( "Contrast" ) 
    112113#define CONTRAST_LONGTEXT N_( \ 
    113     "Contrast of the video input." ) 
     114    "Contrast of the video input (if supported by v4l2 driver)." ) 
    114115#define SATURATION_TEXT N_( "Saturation" ) 
    115116#define SATURATION_LONGTEXT N_( \ 
    116     "Saturation of the video input." ) 
     117    "Saturation of the video input (if supported by v4l2 driver)." ) 
    117118#define HUE_TEXT N_( "Hue" ) 
    118119#define HUE_LONGTEXT N_( \ 
    119     "Hue of the video input." ) 
     120    "Hue of the video input (if supported by v4l2 driver)." ) 
    120121#define GAMMA_TEXT N_( "Gamma" ) 
    121122#define GAMMA_LONGTEXT N_( \ 
    122     "Gamma of the video input." ) 
     123    "Gamma of the video input (if supported by v4l2 driver)." ) 
    123124 
    124125#define ADEV_TEXT N_("Audio device name") 
     
    184185    add_float( CFG_PREFIX "fps", 0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE ); 
    185186 
    186     set_section( N_( "Video controls" ), NULL ); 
    187     add_bool( CFG_PREFIX "controls-reset", VLC_FALSE, NULL, CTRL_RESET_TEXT, 
    188               CTRL_RESET_LONGTEXT, VLC_TRUE ); 
    189     add_integer( CFG_PREFIX "brightness", -1, NULL, BRIGHTNESS_TEXT, 
    190                 BRIGHTNESS_LONGTEXT, VLC_TRUE ); 
    191     add_integer( CFG_PREFIX "contrast", -1, NULL, CONTRAST_TEXT, 
    192                 CONTRAST_LONGTEXT, VLC_TRUE ); 
    193     add_integer( CFG_PREFIX "saturation", -1, NULL, SATURATION_TEXT, 
    194                 SATURATION_LONGTEXT, VLC_TRUE ); 
    195     add_integer( CFG_PREFIX "hue", -1, NULL, HUE_TEXT, 
    196                 HUE_LONGTEXT, VLC_TRUE ); 
    197     add_integer( CFG_PREFIX "gamma", -1, NULL, GAMMA_TEXT, 
    198                 GAMMA_LONGTEXT, VLC_TRUE ); 
    199  
    200187    set_section( N_( "Audio input" ), NULL ); 
    201188    add_string( CFG_PREFIX "adev", "/dev/dsp", 0, ADEV_TEXT, ADEV_LONGTEXT, 
     
    212199                CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE ); 
    213200 
     201    set_section( N_( "Controls" ), N_( "v4l2 driver controls" ) ); 
     202    add_bool( CFG_PREFIX "controls-reset", VLC_FALSE, NULL, CTRL_RESET_TEXT, 
     203              CTRL_RESET_LONGTEXT, VLC_TRUE ); 
     204    add_integer( CFG_PREFIX "brightness", -1, NULL, BRIGHTNESS_TEXT, 
     205                BRIGHTNESS_LONGTEXT, VLC_TRUE ); 
     206    add_integer( CFG_PREFIX "contrast", -1, NULL, CONTRAST_TEXT, 
     207                CONTRAST_LONGTEXT, VLC_TRUE ); 
     208    add_integer( CFG_PREFIX "saturation", -1, NULL, SATURATION_TEXT, 
     209                SATURATION_LONGTEXT, VLC_TRUE ); 
     210    add_integer( CFG_PREFIX "hue", -1, NULL, HUE_TEXT, 
     211                HUE_LONGTEXT, VLC_TRUE ); 
     212    add_integer( CFG_PREFIX "gamma", -1, NULL, GAMMA_TEXT, 
     213                GAMMA_LONGTEXT, VLC_TRUE ); 
     214 
     215 
    214216    add_shortcut( "v4l2" ); 
    215217    set_capability( "access_demux", 10 ); 
     
    230232static void CommonClose( vlc_object_t *, demux_sys_t * ); 
    231233static void ParseMRL( demux_sys_t *, char *, vlc_object_t * ); 
    232 static void GetV4L2Params( demux_sys_t * , vlc_object_t * ); 
     234static void GetV4L2Params( demux_sys_t *, vlc_object_t * ); 
    233235 
    234236static int DemuxControl( demux_t *, int, va_list ); 
     
    242244static block_t* GrabAudio( demux_t *p_demux ); 
    243245 
    244 vlc_bool_t IsPixelFormatSupported( demux_t *p_demux, unsigned int i_pixelformat ); 
    245  
    246 char* ResolveALSADeviceName( char *psz_device ); 
     246static vlc_bool_t IsPixelFormatSupported( demux_t *p_demux, 
     247                                          unsigned int i_pixelformat ); 
     248 
     249static char* ResolveALSADeviceName( char *psz_device ); 
    247250static int OpenVideoDev( vlc_object_t *, demux_sys_t *, vlc_bool_t ); 
    248 static int OpenAudioDev( demux_t *, char *psz_device ); 
    249 static vlc_bool_t ProbeVideoDev( vlc_object_t *, demux_sys_t *, char *psz_device ); 
    250 static vlc_bool_t ProbeAudioDev( demux_t *, char *psz_device ); 
     251static int OpenAudioDev( vlc_object_t *, demux_sys_t *, vlc_bool_t ); 
     252static vlc_bool_t ProbeVideoDev( vlc_object_t *, demux_sys_t *, 
     253                                 char *psz_device ); 
     254static vlc_bool_t ProbeAudioDev( vlc_object_t *, demux_sys_t *, 
     255                                 char *psz_device ); 
    251256 
    252257static int ControlList( vlc_object_t *, int , vlc_bool_t, vlc_bool_t ); 
    253258static int Control( vlc_object_t *, int i_fd, 
    254259                    const char *psz_name, int i_cid, int i_value ); 
    255 static int DemuxControlCallback( vlc_object_t *p_this, 
    256     const char *psz_var, vlc_value_t oldval, vlc_value_t newval, 
    257     void *p_data ); 
    258 static int DemuxControlResetCallback( vlc_object_t *p_this, 
    259     const char *psz_var, vlc_value_t oldval, vlc_value_t newval, 
    260     void *p_data ); 
    261 static int AccessControlCallback( vlc_object_t *p_this, 
    262     const char *psz_var, vlc_value_t oldval, vlc_value_t newval, 
    263     void *p_data ); 
     260 
     261static int DemuxControlCallback( vlc_object_t *p_this, const char *psz_var, 
     262                                 vlc_value_t oldval, vlc_value_t newval, 
     263                                 void *p_data ); 
     264static int DemuxControlResetCallback( vlc_object_t *p_this, const char *psz_var, 
     265                                      vlc_value_t oldval, vlc_value_t newval, 
     266                                      void *p_data ); 
     267static int AccessControlCallback( vlc_object_t *p_this, const char *psz_var, 
     268                                  vlc_value_t oldval, vlc_value_t newval, 
     269                                  void *p_data ); 
    264270static int AccessControlResetCallback( vlc_object_t *p_this, 
    265     const char *psz_var, vlc_value_t oldval, vlc_value_t newval, 
    266     void *p_data ); 
     271                                       const char *psz_var, vlc_value_t oldval, 
     272                                       vlc_value_t newval, void *p_data ); 
    267273 
    268274static struct 
     
    400406}; 
    401407 
     408#define FIND_VIDEO 1 
     409#define FIND_AUDIO 2 
     410 
     411static int FindMainDevice( vlc_object_t *p_this, demux_sys_t *p_sys, 
     412                           int i_flags, vlc_bool_t b_demux, 
     413                           vlc_bool_t b_forced ) 
     414{ 
     415    /* Find main device (video or audio) */ 
     416    if( p_sys->psz_device && *p_sys->psz_device ) 
     417    { 
     418        msg_Dbg( p_this, "main device='%s'", p_sys->psz_device ); 
     419 
     420        /* Try to open as video device */ 
     421        if( i_flags & FIND_VIDEO ) 
     422        { 
     423            msg_Dbg( p_this, "trying device '%s' as video", p_sys->psz_device ); 
     424            if( ProbeVideoDev( p_this, p_sys, p_sys->psz_device ) ) 
     425            { 
     426                msg_Dbg( p_this, "'%s' is a video device", p_sys->psz_device ); 
     427                /* Device was a video device */ 
     428                if( p_sys->psz_vdev ) free( p_sys->psz_vdev ); 
     429                p_sys->psz_vdev = p_sys->psz_device; 
     430                p_sys->psz_device = NULL; 
     431                p_sys->i_fd_video = OpenVideoDev( p_this, p_sys, b_demux ); 
     432                if( p_sys->i_fd_video < 0 ) 
     433                    return VLC_EGENERIC; 
     434                return VLC_SUCCESS; 
     435            } 
     436        } 
     437 
     438        if( i_flags & FIND_AUDIO ) 
     439        { 
     440            /* Try to open as audio device */ 
     441            msg_Dbg( p_this, "trying device '%s' as audio", p_sys->psz_device ); 
     442            if( ProbeAudioDev( p_this, p_sys, p_sys->psz_device ) ) 
     443            { 
     444                msg_Dbg( p_this, "'%s' is an audio device", p_sys->psz_device ); 
     445                /* Device was an audio device */ 
     446                if( p_sys->psz_adev ) free( p_sys->psz_adev ); 
     447                p_sys->psz_adev = p_sys->psz_device; 
     448                p_sys->psz_device = NULL; 
     449                p_sys->i_fd_audio = OpenAudioDev( p_this, p_sys, b_demux ); 
     450                if( p_sys->i_fd_audio < 0 ) 
     451                    return VLC_EGENERIC; 
     452                return VLC_SUCCESS; 
     453            } 
     454        } 
     455    } 
     456 
     457    /* If no device opened, only continue if the access was forced */ 
     458    if( b_forced == VLC_FALSE 
     459        && !( ( i_flags & FIND_VIDEO && p_sys->i_fd_video >= 0 ) 
     460           || ( i_flags & FIND_AUDIO && p_sys->i_fd_audio >= 0 ) ) ) 
     461    { 
     462        return VLC_EGENERIC; 
     463    } 
     464 
     465    /* Find video device */ 
     466    if( i_flags & FIND_VIDEO && p_sys->i_fd_video < 0 ) 
     467    { 
     468        if( !p_sys->psz_vdev || !*p_sys->psz_vdev ) 
     469        { 
     470            if( p_sys->psz_vdev ) free( p_sys->psz_vdev ); 
     471            p_sys->psz_vdev = var_CreateGetString( p_this, "v4l2-dev" ); 
     472        } 
     473 
     474        msg_Dbg( p_this, "opening '%s' as video", p_sys->psz_vdev ); 
     475        if( p_sys->psz_vdev && *p_sys->psz_vdev 
     476         && ProbeVideoDev( p_this, p_sys, p_sys->psz_vdev ) ) 
     477        { 
     478            p_sys->i_fd_video = OpenVideoDev( p_this, p_sys, b_demux ); 
     479        } 
     480    } 
     481 
     482    /* Find audio device */ 
     483    if( i_flags & FIND_AUDIO && p_sys->i_fd_audio < 0 ) 
     484    { 
     485        if( !p_sys->psz_adev || !*p_sys->psz_adev ) 
     486        { 
     487            if( p_sys->psz_adev ) free( p_sys->psz_adev ); 
     488            p_sys->psz_adev = var_CreateGetString( p_this, "v4l2-adev" ); 
     489        } 
     490 
     491        msg_Dbg( p_this, "opening '%s' as audio", p_sys->psz_adev ); 
     492        if( p_sys->psz_adev && *p_sys->psz_adev 
     493         && ProbeAudioDev( p_this, p_sys, p_sys->psz_adev ) ) 
     494        { 
     495            p_sys->i_fd_audio = OpenAudioDev( p_this, p_sys, b_demux ); 
     496        } 
     497    } 
     498 
     499    if( !( ( i_flags & FIND_VIDEO && p_sys->i_fd_video >= 0 ) 
     500        || ( i_flags & FIND_AUDIO && p_sys->i_fd_audio >= 0 ) ) ) 
     501    { 
     502        return VLC_EGENERIC; 
     503    } 
     504    return VLC_SUCCESS; 
     505} 
     506 
    402507/***************************************************************************** 
    403508 * DemuxOpen: opens v4l2 device, access_demux callback 
     
    434539#endif 
    435540 
    436     /* Find main device (video or audio) */ 
    437     if( p_sys->psz_device && *p_sys->psz_device ) 
    438     { 
    439         msg_Dbg( p_demux, "main device='%s'", p_sys->psz_device ); 
    440  
    441         /* Try to open as video device */ 
    442         msg_Dbg( p_demux, "trying device '%s' as video", p_sys->psz_device ); 
    443         if( ProbeVideoDev( (vlc_object_t *) p_demux, p_sys, p_sys->psz_device ) ) 
    444         { 
    445             msg_Dbg( p_demux, "'%s' is a video device", p_sys->psz_device ); 
    446             /* Device was a video device */ 
    447             if( p_sys->psz_vdev ) free( p_sys->psz_vdev ); 
    448             p_sys->psz_vdev = p_sys->psz_device; 
    449             p_sys->psz_device = NULL; 
    450             p_sys->i_fd_video = OpenVideoDev( (vlc_object_t *) p_demux, p_sys, VLC_TRUE ); 
    451             if( p_sys->i_fd_video < 0 ) 
    452             { 
    453                 DemuxClose( p_this ); 
    454                 return VLC_EGENERIC; 
    455             } 
    456         } 
    457         else 
    458         { 
    459             /* Try to open as audio device */ 
    460             msg_Dbg( p_demux, "trying device '%s' as audio", p_sys->psz_device ); 
    461             if( ProbeAudioDev( p_demux, p_sys->psz_device ) ) 
    462             { 
    463                 msg_Dbg( p_demux, "'%s' is an audio device", p_sys->psz_device ); 
    464                 /* Device was an audio device */ 
    465                 if( p_sys->psz_adev ) free( p_sys->psz_adev ); 
    466                 p_sys->psz_adev = p_sys->psz_device; 
    467                 p_sys->psz_device = NULL; 
    468                 p_sys->i_fd_audio = OpenAudioDev( p_demux, p_sys->psz_adev ); 
    469                 if( p_sys->i_fd_audio < 0 ) 
    470                 { 
    471                     DemuxClose( p_this ); 
    472                     return VLC_EGENERIC; 
    473                 } 
    474             } 
    475         } 
    476     } 
    477  
    478     /* If no device opened, only continue if the access was forced */ 
    479     if( p_sys->i_fd_video < 0 && p_sys->i_fd_audio < 0 ) 
    480     { 
    481         if( strcmp( p_demux->psz_access, "v4l2" ) ) 
    482         { 
    483             DemuxClose( p_this ); 
    484             return VLC_EGENERIC; 
    485         } 
    486     } 
    487  
    488     /* Find video device */ 
    489     if( p_sys->i_fd_video < 0 ) 
    490     { 
    491         if( !p_sys->psz_vdev || !*p_sys->psz_vdev ) 
    492         { 
    493             if( p_sys->psz_vdev ) free( p_sys->psz_vdev ); 
    494             p_sys->psz_vdev = var_CreateGetString( p_demux, "v4l2-dev" ); 
    495         } 
    496  
    497         msg_Dbg( p_demux, "opening '%s' as video", p_sys->psz_vdev ); 
    498         if( p_sys->psz_vdev && *p_sys->psz_vdev && ProbeVideoDev( (vlc_object_t *) p_demux, p_sys, p_sys->psz_vdev ) ) 
    499         { 
    500             p_sys->i_fd_video = OpenVideoDev( (vlc_object_t *) p_demux, p_sys, VLC_TRUE ); 
    501         } 
    502     } 
    503  
    504     /* Find audio device */ 
    505     if( p_sys->i_fd_audio < 0 ) 
    506     { 
    507         if( !p_sys->psz_adev || !*p_sys->psz_adev ) 
    508         { 
    509             if( p_sys->psz_adev ) free( p_sys->psz_adev ); 
    510             p_sys->psz_adev = var_CreateGetString( p_demux, "v4l2-adev" ); 
    511         } 
    512  
    513         msg_Dbg( p_demux, "opening '%s' as audio", p_sys->psz_adev ); 
    514         if( p_sys->psz_adev && *p_sys->psz_adev && ProbeAudioDev( p_demux, p_sys->psz_adev ) ) 
    515         { 
    516             p_sys->i_fd_audio = OpenAudioDev( p_demux, p_sys->psz_adev ); 
    517         } 
    518     } 
    519  
    520     if( p_sys->i_fd_video < 0 && p_sys->i_fd_audio < 0 ) 
     541    if( FindMainDevice( p_this, p_sys, FIND_VIDEO|FIND_AUDIO, 
     542        VLC_TRUE, !strcmp( p_demux->psz_access, "v4l2" ) ) != VLC_SUCCESS ) 
    521543    { 
    522544        DemuxClose( p_this ); 
     
    530552 * GetV4L2Params: fill in p_sys parameters (shared by DemuxOpen and AccessOpen) 
    531553 *****************************************************************************/ 
    532 void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj ) 
    533 
    534     vlc_value_t val; 
    535  
     554static void GetV4L2Params( demux_sys_t *p_sys, vlc_object_t *p_obj ) 
     555
    536556    p_sys->i_video_pts = -1; 
    537557 
    538     var_Create( p_obj, "v4l2-standard", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); 
    539     var_Get( p_obj, "v4l2-standard", &val ); 
    540     p_sys->i_selected_standard_id = i_standards_list[val.i_int]; 
     558    p_sys->i_selected_standard_id = 
     559        i_standards_list[var_CreateGetInteger( p_obj, "v4l2-standard" )]; 
    541560 
    542561    p_sys->i_selected_input = var_CreateGetInteger( p_obj, "v4l2-input" ); 
     
    549568    var_CreateGetBool( p_obj, "v4l2-controls-reset" ); 
    550569 
    551     var_Create( p_obj, "v4l2-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); 
    552     var_Get( p_obj, "v4l2-fps", &val ); 
    553     p_sys->f_fps = val.f_float; 
    554  
    555     var_Create( p_obj, "v4l2-samplerate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); 
    556     var_Get( p_obj, "v4l2-samplerate", &val ); 
    557     p_sys->i_sample_rate = val.i_int; 
    558  
     570    p_sys->f_fps = var_CreateGetFloat( p_obj, "v4l2-fps" ); 
     571    p_sys->i_sample_rate = var_CreateGetInteger( p_obj, "v4l2-samplerate" ); 
    559572    p_sys->psz_requested_chroma = var_CreateGetString( p_obj, "v4l2-chroma" ); 
    560573 
    561574#ifdef HAVE_ALSA 
    562     var_Create( p_obj, "v4l2-alsa", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); 
    563     var_Get( p_obj, "v4l2-alsa", &val ); 
    564     p_sys->b_use_alsa = val.b_bool; 
     575    p_sys->b_use_alsa = var_CreateGetBool( p_obj, "v4l2-alsa" ); 
    565576#endif 
    566577 
    567     var_Create( p_obj, "v4l2-stereo", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); 
    568     var_Get( p_obj, "v4l2-stereo", &val ); 
    569     p_sys->b_stereo = val.b_bool; 
     578    p_sys->b_stereo = var_CreateGetBool( p_obj, "v4l2-stereo" ); 
    570579 
    571580    p_sys->i_pts = var_CreateGetInteger( p_obj, "v4l2-caching" ); 
     
    947956    if( p_sys == NULL ) return VLC_ENOMEM; 
    948957 
    949     GetV4L2Params(p_sys, (vlc_object_t *) p_access); 
     958    GetV4L2Params( p_sys, (vlc_object_t *) p_access ); 
    950959 
    951960    ParseMRL( p_sys, p_access->psz_path, (vlc_object_t *) p_access ); 
    952961 
    953     /* Find main device (video) */ 
    954     if( p_sys->psz_device && *p_sys->psz_device ) 
    955     { 
    956         msg_Dbg( p_access, "main device='%s'", p_sys->psz_device ); 
    957  
    958         /* Try to open as video device */ 
    959         msg_Dbg( p_access, "trying device '%s' as video", p_sys->psz_device ); 
    960         if( ProbeVideoDev( (vlc_object_t *) p_access, p_sys, p_sys->psz_device ) ) 
    961         { 
    962             msg_Dbg( p_access, "'%s' is a video device", p_sys->psz_device ); 
    963             /* Device was a video device */ 
    964             if( p_sys->psz_vdev ) free( p_sys->psz_vdev ); 
    965             p_sys->psz_vdev = p_sys->psz_device; 
    966             p_sys->psz_device = NULL; 
    967             p_sys->i_fd_video = OpenVideoDev( (vlc_object_t *) p_access, p_sys, VLC_FALSE ); 
    968             if( p_sys->i_fd_video < 0 ) 
    969             { 
    970                 AccessClose( p_this ); 
    971                 return VLC_EGENERIC; 
    972             } 
    973         } 
    974     } 
    975  
    976     /* If no device opened, only continue if the access was forced */ 
    977     if( p_sys->i_fd_video < 0 ) 
    978     { 
    979         if( strcmp( p_access->psz_access, "v4l2" ) ) 
    980         { 
    981             AccessClose( p_this ); 
    982             return VLC_EGENERIC; 
    983         } 
    984     } 
    985  
    986     /* Find video device */ 
    987     if( p_sys->i_fd_video < 0 ) 
    988     { 
    989         if( !p_sys->psz_vdev || !*p_sys->psz_vdev ) 
    990         { 
    991             if( p_sys->psz_vdev ) free( p_sys->psz_vdev ); 
    992             p_sys->psz_vdev = var_CreateGetString( p_access, "v4l2-dev" ); 
    993         } 
    994  
    995         msg_Dbg( p_access, "opening '%s' as video", p_sys->psz_vdev ); 
    996         if( p_sys->psz_vdev && *p_sys->psz_vdev && ProbeVideoDev( (vlc_object_t *) p_access, p_sys, p_sys->psz_vdev ) ) 
    997         { 
    998             p_sys->i_fd_video = OpenVideoDev( (vlc_object_t *) p_access, p_sys, VLC_FALSE ); 
    999         } 
    1000     } 
    1001  
    1002  
    1003     if( p_sys->i_fd_video < 0 ) 
     962    if( FindMainDevice( p_this, p_sys, FIND_VIDEO, 
     963        VLC_FALSE, !strcmp( p_access->psz_access, "v4l2" ) ) != VLC_SUCCESS ) 
    1004964    { 
    1005965        AccessClose( p_this ); 
     
    16021562 * in the array of supported formats returned by the driver 
    16031563 *****************************************************************************/ 
    1604 vlc_bool_t IsPixelFormatSupported( demux_t *p_demux, unsigned int i_pixelformat ) 
     1564static vlc_bool_t IsPixelFormatSupported( demux_t *p_demux, unsigned int i_pixelformat ) 
    16051565{ 
    16061566    demux_sys_t *p_sys = p_demux->p_sys; 
     
    16171577 * OpenVideoDev: open and set up the video device and probe for capabilities 
    16181578 *****************************************************************************/ 
    1619 int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, vlc_bool_t b_demux ) 
     1579static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, vlc_bool_t b_demux ) 
    16201580{ 
    16211581    int i_fd; 
     
    16611621    /* TODO: Move the resolution stuff up here */ 
    16621622    /* if MPEG encoder card, no need to do anything else after this */ 
     1623    ControlList( p_obj, i_fd, 
     1624                  var_GetBool( p_obj, "v4l2-controls-reset" ), b_demux ); 
    16631625    if( VLC_FALSE == b_demux) 
    16641626    { 
    1665         ControlList( p_obj, i_fd, 
    1666                       var_GetBool( p_obj, "v4l2-controls-reset" ), b_demux ); 
    1667  
    16681627        return i_fd; 
    16691628    } 
     
    19811940 * ResolveALSADeviceName: Change any . to : in the ALSA device name 
    19821941 *****************************************************************************/ 
    1983 char* ResolveALSADeviceName( char *psz_device ) 
     1942static char *ResolveALSADeviceName( char *psz_device ) 
    19841943{ 
    19851944    char* psz_alsa_name = strdup( psz_device ); 
     
    19951954 * OpenAudioDev: open and set up the audio device and probe for capabilities 
    19961955 *****************************************************************************/ 
    1997 int OpenAudioDev( demux_t *p_demux, char *psz_device ) 
    1998 
    1999     demux_sys_t *p_sys = p_demux->p_sys; 
     1956static int OpenAudioDev( vlc_object_t *p_this, demux_sys_t *p_sys, 
     1957                         vlc_bool_t b_demux ) 
     1958
     1959    char *psz_device = p_sys->psz_adev; 
    20001960    int i_fd = 0; 
    20011961    int i_format; 
     
    20181978            SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK ) ) < 0) 
    20191979        { 
    2020             msg_Err( p_demux, "Cannot open ALSA audio device %s (%s)", 
    2021                 psz_alsa_device_name, 
    2022                 snd_strerror( i_err ) ); 
     1980            msg_Err( p_this, "Cannot open ALSA audio device %s (%s)", 
     1981                     psz_alsa_device_name, snd_strerror( i_err ) ); 
    20231982            goto adev_fail; 
    20241983        } 
     
    20261985        if( ( i_err = snd_pcm_nonblock( p_sys->p_alsa_pcm, 1 ) ) < 0) 
    20271986        { 
    2028             msg_Err( p_demux, "Cannot set ALSA nonblock (%s)",  
    2029                 snd_strerror( i_err ) ); 
     1987            msg_Err( p_this, "Cannot set ALSA nonblock (%s)", 
     1988                     snd_strerror( i_err ) ); 
    20301989            goto adev_fail; 
    20311990        } 
     
    20351994        if( ( i_err = snd_pcm_hw_params_malloc( &p_hw_params ) ) < 0 ) 
    20361995        { 
    2037             msg_Err( p_demux, "ALSA: cannot allocate hardware parameter structure (%s)", 
    2038                 snd_strerror( i_err ) ); 
     1996            msg_Err( p_this, 
     1997                     "ALSA: cannot allocate hardware parameter structure (%s)", 
     1998                     snd_strerror( i_err ) ); 
    20391999            goto adev_fail; 
    20402000        } 
     
    20422002        if( ( i_err = snd_pcm_hw_params_any( p_sys->p_alsa_pcm, p_hw_params ) ) < 0 ) 
    20432003        { 
    2044             msg_Err( p_demux, "ALSA: cannot initialize hardware parameter structure (%s)", 
    2045                 snd_strerror( i_err ) ); 
     2004            msg_Err( p_this, 
     2005                    "ALSA: cannot initialize hardware parameter structure (%s)", 
     2006                     snd_strerror( i_err ) ); 
    20462007            goto adev_fail; 
    20472008        } 
     
    20502011        if( ( i_err = snd_pcm_hw_params_set_access( p_sys->p_alsa_pcm, p_hw_params, SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 ) 
    20512012        { 
    2052             msg_Err( p_demux, "ALSA: cannot set access type (%s)", 
    2053                 snd_strerror( i_err ) ); 
     2013            msg_Err( p_this, "ALSA: cannot set access type (%s)", 
     2014                     snd_strerror( i_err ) ); 
    20542015            goto adev_fail; 
    20552016        } 
     
    20582019        if( ( i_err = snd_pcm_hw_params_set_format( p_sys->p_alsa_pcm, p_hw_params, SND_PCM_FORMAT_S16_LE ) ) < 0 ) 
    20592020        { 
    2060             msg_Err( p_demux, "ALSA: cannot set sample format (%s)", 
    2061                 snd_strerror( i_err ) ); 
     2021            msg_Err( p_this, "ALSA: cannot set sample format (%s)", 
     2022                     snd_strerror( i_err ) ); 
    20622023            goto adev_fail; 
    20632024        } 
     
    20712032        if( i_err < 0 ) 
    20722033        { 
    2073             msg_Err( p_demux, "ALSA: cannot set sample rate (%s)", 
    2074                 snd_strerror( i_err ) ); 
     2034            msg_Err( p_this, "ALSA: cannot set sample rate (%s)", 
     2035                     snd_strerror( i_err ) ); 
    20752036            goto adev_fail; 
    20762037        } 
     
    20812042        { 
    20822043            channels = ( channels==1 ) ? 2 : 1; 
    2083             msg_Warn( p_demux, "ALSA: cannot set channel count (%s). Trying with channels=%d", 
    2084                 snd_strerror( i_err ), 
    2085                 channels ); 
     2044            msg_Warn( p_this, "ALSA: cannot set channel count (%s). " 
     2045                      "Trying with channels=%d", 
     2046                      snd_strerror( i_err ), 
     2047                      channels ); 
    20862048            if( ( i_err = snd_pcm_hw_params_set_channels( p_sys->p_alsa_pcm, p_hw_params, channels ) ) < 0 ) 
    20872049            { 
    2088                 msg_Err( p_demux, "ALSA: cannot set channel count (%s)", 
    2089                     snd_strerror( i_err ) ); 
     2050                msg_Err( p_this, "ALSA: cannot set channel count (%s)", 
     2051                         snd_strerror( i_err ) ); 
    20902052                goto adev_fail; 
    20912053            } 
     
    20972059        if( ( i_err = snd_pcm_hw_params_get_buffer_time_max(p_hw_params, &buffer_time, 0) ) < 0 ) 
    20982060        { 
    2099             msg_Err( p_demux, "ALSA: cannot get buffer time max (%s)", 
    2100                 snd_strerror( i_err ) ); 
     2061            msg_Err( p_this, "ALSA: cannot get buffer time max (%s)", 
     2062                     snd_strerror( i_err ) ); 
    21012063            goto adev_fail; 
    21022064        } 
     
    21122074        if( i_err < 0 ) 
    21132075        { 
    2114             msg_Err( p_demux, "ALSA: cannot set period time (%s)", 
    2115                 snd_strerror( i_err ) ); 
     2076            msg_Err( p_this, "ALSA: cannot set period time (%s)", 
     2077                     snd_strerror( i_err ) ); 
    21162078            goto adev_fail; 
    21172079        } 
     
    21252087        if( i_err < 0 ) 
    21262088        { 
    2127             msg_Err( p_demux, "ALSA: cannot set buffer time (%s)", 
    2128                 snd_strerror( i_err ) ); 
     2089            msg_Err( p_this, "ALSA: cannot set buffer time (%s)", 
     2090                     snd_strerror( i_err ) ); 
    21292091            goto adev_fail; 
    21302092        } 
     
    21332095        if( ( i_err = snd_pcm_hw_params( p_sys->p_alsa_pcm, p_hw_params ) ) < 0 ) 
    21342096        { 
    2135             msg_Err( p_demux, "ALSA: cannot set hw parameters (%s)", 
    2136                 snd_strerror( i_err ) ); 
     2097            msg_Err( p_this, "ALSA: cannot set hw parameters (%s)", 
     2098                     snd_strerror( i_err ) ); 
    21372099            goto adev_fail; 
    21382100        } 
     
    21432105        if (chunk_size == buffer_size) 
    21442106        { 
    2145             msg_Err( p_demux, "ALSA: period cannot equal buffer size (%lu == %lu)", 
    2146                 chunk_size, buffer_size); 
     2107            msg_Err( p_this, 
     2108                     "ALSA: period cannot equal buffer size (%lu == %lu)", 
     2109                     chunk_size, buffer_size); 
    21472110            goto adev_fail; 
    21482111        } 
     
    21612124        if( ( i_err = snd_pcm_prepare( p_sys->p_alsa_pcm ) ) < 0 ) 
    21622125        { 
    2163             msg_Err( p_demux, "ALSA: cannot prepare audio interface for use (%s)", 
    2164                 snd_strerror( i_err ) ); 
     2126            msg_Err( p_this, 
     2127                     "ALSA: cannot prepare audio interface for use (%s)", 
     2128                     snd_strerror( i_err ) ); 
    21652129            goto adev_fail; 
    21662130        } 
     
    21772141        if( (i_fd = open( psz_device, O_RDONLY | O_NONBLOCK )) < 0 ) 
    21782142        { 
    2179             msg_Err( p_demux, "cannot open OSS audio device (%m)" ); 
     2143            msg_Err( p_this, "cannot open OSS audio device (%m)" ); 
    21802144            goto adev_fail; 
    21812145        } 
     
    21852149            || i_format != AFMT_S16_LE ) 
    21862150        { 
    2187             msg_Err( p_demux, "cannot set audio format (16b little endian) " 
    2188                      "(%m)" ); 
     2151            msg_Err( p_this, 
     2152                     "cannot set audio format (16b little endian) (%m)" ); 
    21892153            goto adev_fail; 
    21902154        } 
     
    21932157                   &p_sys->b_stereo ) < 0 ) 
    21942158        { 
    2195             msg_Err( p_demux, "cannot set audio channels count (%m)" ); 
     2159            msg_Err( p_this, "cannot set audio channels count (%m)" ); 
    21962160            goto adev_fail; 
    21972161        } 
     
    22002164                   &p_sys->i_sample_rate ) < 0 ) 
    22012165        { 
    2202             msg_Err( p_demux, "cannot set audio sample rate (%m)" ); 
     2166            msg_Err( p_this, "cannot set audio sample rate (%m)" ); 
    22032167            goto adev_fail; 
    22042168        } 
     
    22072171    } 
    22082172 
    2209     msg_Dbg( p_demux, "opened adev=`%s' %s %dHz", 
     2173    msg_Dbg( p_this, "opened adev=`%s' %s %dHz", 
    22102174             psz_device, p_sys->b_stereo ? "stereo" : "mono", 
    22112175             p_sys->i_sample_rate ); 
     
    22202184    fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate * fmt.audio.i_bitspersample; 
    22212185 
    2222     msg_Dbg( p_demux, "new audio es %d channels %dHz", 
    2223       fmt.audio.i_channels, fmt.audio.i_rate ); 
    2224  
    2225     p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt ); 
     2186    msg_Dbg( p_this, "new audio es %d channels %dHz", 
     2187             fmt.audio.i_channels, fmt.audio.i_rate ); 
     2188 
     2189    if( b_demux ) 
     2190    { 
     2191        demux_t *p_demux = (demux_t *)p_this; 
     2192        p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt ); 
     2193    } 
    22262194 
    22272195#ifdef HAVE_ALSA 
     
    22482216 * ProbeVideoDev: probe video for capabilities 
    22492217 *****************************************************************************/ 
    2250 vlc_bool_t ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, char *psz_device ) 
     2218static vlc_bool_t ProbeVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, 
     2219                                 char *psz_device ) 
    22512220{ 
    22522221    int i_index; 
     
    25382507 * ProbeAudioDev: probe audio for capabilities 
    25392508 *****************************************************************************/ 
    2540 vlc_bool_t ProbeAudioDev( demux_t *p_demux, char *psz_device ) 
     2509static vlc_bool_t ProbeAudioDev( vlc_object_t *p_this, demux_sys_t *p_sys, 
     2510                                 char *psz_device ) 
    25412511{ 
    25422512    int i_fd = 0; 
     
    25442514 
    25452515#ifdef HAVE_ALSA 
    2546     demux_sys_t *p_sys = p_demux->p_sys; 
    2547  
    25482516    if( p_sys->b_use_alsa ) 
    25492517    { 
     
    25562524        if( ( i_err = snd_pcm_open( &p_alsa_pcm, psz_alsa_device_name, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK ) ) < 0 ) 
    25572525        { 
    2558             msg_Err( p_demux, "cannot open device %s for ALSA audio (%s)", psz_alsa_device_name, snd_strerror( i_err ) ); 
     2526            msg_Err( p_this, "cannot open device %s for ALSA audio (%s)", psz_alsa_device_name, snd_strerror( i_err ) ); 
    25592527            free( psz_alsa_device_name ); 
    25602528            goto open_failed; 
     
    25712539        if( ( i_fd = open( psz_device, O_RDONLY | O_NONBLOCK ) ) < 0 ) 
    25722540        { 
    2573             msg_Err( p_demux, "cannot open device %s for OSS audio (%m)", psz_device ); 
     2541            msg_Err( p_this, "cannot open device %s for OSS audio (%m)", psz_device ); 
    25742542            goto open_failed; 
    25752543        } 
     
    25782546        if( ioctl( i_fd, SNDCTL_DSP_GETCAPS, &i_caps ) < 0 ) 
    25792547        { 
    2580             msg_Err( p_demux, "cannot get audio caps (%m)" ); 
     2548            msg_Err( p_this, "cannot get audio caps (%m)" ); 
    25812549            goto open_failed; 
    25822550        } 
     
    25902558    if( i_fd >= 0 ) close( i_fd ); 
    25912559    return VLC_FALSE; 
    2592  
    25932560} 
    25942561 
     
    27672734 * value and create the relevant variables to enable runtime changes 
    27682735 *****************************************************************************/ 
    2769 static int ControlList( vlc_object_t *p_obj, int i_fd, vlc_bool_t b_reset, vlc_bool_t b_demux ) 
     2736static int ControlList( vlc_object_t *p_obj, int i_fd, 
     2737                        vlc_bool_t b_reset, vlc_bool_t b_demux ) 
    27702738{ 
    27712739    struct v4l2_queryctrl queryctrl;