+#endif /* HAVE_NEW_LINUX_VIDEODEV2_H */
+
+/*****************************************************************************
+ * Open: open the device
+ *****************************************************************************/
+static int Open( vlc_object_t * p_this )
+{
+ access_t *p_access = (access_t*) p_this;
+ access_sys_t * p_sys;
+ char * psz_tofree;
+ char * psz_parser;
+ struct v4l2_capability device_capability;
+ int result;
+
+ memset( &device_capability, 0, sizeof(struct v4l2_capability) );
+
+ access_InitFields( p_access );
+ ACCESS_SET_CALLBACKS( Read, NULL, Control, NULL );
+ p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ));
+ if( !p_sys ) return VLC_ENOMEM;
+
+ /* defaults values */
+ var_Create( p_access, "pvr-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+
+ p_sys->psz_videodev = var_InheritString( p_access, "pvr-device" );
+ p_sys->psz_radiodev = var_InheritString( p_access, "pvr-radio-device" );
+ p_sys->i_standard = var_InheritInteger( p_access, "pvr-norm" );
+ p_sys->i_width = var_InheritInteger( p_access, "pvr-width" );
+ p_sys->i_height = var_InheritInteger( p_access, "pvr-height" );
+ p_sys->i_frequency = var_InheritInteger( p_access, "pvr-frequency" );
+ p_sys->i_framerate = var_InheritInteger( p_access, "pvr-framerate" );
+ p_sys->i_keyint = var_InheritInteger( p_access, "pvr-keyint" );
+ p_sys->i_bframes = var_InheritInteger( p_access, "pvr-bframes" );
+ p_sys->i_bitrate = var_InheritInteger( p_access, "pvr-bitrate" );
+ p_sys->i_bitrate_peak = var_InheritInteger( p_access, "pvr-bitrate-peak" );
+ p_sys->i_bitrate_mode = var_InheritInteger( p_access, "pvr-bitrate-mode" );
+ p_sys->i_audio_bitmask = var_InheritInteger( p_access, "pvr-audio-bitmask" );
+ p_sys->i_volume = var_InheritInteger( p_access, "pvr-audio-volume" );
+ p_sys->i_input = var_InheritInteger( p_access, "pvr-channel" );
+
+ /* parse command line options */
+ psz_tofree = strdup( p_access->psz_location );
+ if( !psz_tofree )
+ {
+ free( p_sys->psz_radiodev );
+ free( p_sys->psz_videodev );
+ free( p_sys );
+ return VLC_ENOMEM;
+ }
+
+ psz_parser = psz_tofree;
+ while( *psz_parser )
+ {
+ /* Leading slash -> device path */
+ if( *psz_parser == '/' )
+ {
+ free( p_sys->psz_videodev );
+ p_sys->psz_videodev = decode_URI_duplicate( psz_parser );
+ break;
+ }
+
+ /* Extract option name */
+ const char *optname = psz_parser;
+ psz_parser = strchr( psz_parser, '=' );
+ if( psz_parser == NULL )
+ break;
+ *psz_parser++ = '\0';
+
+ /* Extract option value */
+ char *optval = psz_parser;
+ while( memchr( ":,", *psz_parser, 3 /* includes \0 */ ) == NULL )
+ psz_parser++;
+ if( *psz_parser ) /* more options to come */
+ *psz_parser++ = '\0'; /* skip , or : */
+
+ if ( !strcmp( optname, "norm" ) )
+ {
+ if ( !strcmp( optval, "secam" ) )
+ p_sys->i_standard = V4L2_STD_SECAM;
+ else if ( !strcmp( optval, "pal" ) )
+ p_sys->i_standard = V4L2_STD_PAL;
+ else if ( !strcmp( optval, "ntsc" ) )
+ p_sys->i_standard = V4L2_STD_NTSC;
+ else
+ p_sys->i_standard = atoi( optval );
+ }
+ else if( !strcmp( optname, "channel" ) )
+ p_sys->i_input = atoi( optval );
+ else if( !strcmp( optname, "device" ) )
+ {
+ free( p_sys->psz_videodev );
+ if( asprintf( &p_sys->psz_videodev, "/dev/video%s", optval ) == -1)
+ p_sys->psz_videodev = NULL;
+ }
+ else if( !strcmp( optname, "frequency" ) )
+ p_sys->i_frequency = atoi( optval );
+ else if( !strcmp( optname, "framerate" ) )
+ p_sys->i_framerate = atoi( optval );
+ else if( !strcmp( optname, "keyint" ) )
+ p_sys->i_keyint = atoi( optval );
+ else if( !strcmp( optname, "bframes" ) )
+ p_sys->i_bframes = atoi( optval );
+ else if( !strcmp( optname, "width" ) )
+ p_sys->i_width = atoi( optval );
+ else if( !strcmp( optname, "height" ) )
+ p_sys->i_height = atoi( optval );
+ else if( !strcmp( optname, "audio" ) )
+ p_sys->i_audio_bitmask = atoi( optval );
+ else if( !strcmp( optname, "bitrate" ) )
+ p_sys->i_bitrate = atoi( optval );
+ else if( !strcmp( optname, "maxbitrate" ) )
+ p_sys->i_bitrate_peak = atoi( optval );
+ else if( !strcmp( optname, "bitratemode" ) )
+ {
+ if( !strcmp( optval, "vbr" ) )
+ p_sys->i_bitrate_mode = 0;
+ else if( !strcmp( optval, "cbr" ) )
+ p_sys->i_bitrate_mode = 1;
+ }
+ else if( !strcmp( optname, "size" ) )
+ {
+ p_sys->i_width = strtol( optval, &optval, 0 );
+ p_sys->i_height = atoi( optval );
+ }
+ }