Move v4l and pvr into the main access directory.
authorClément Stenac <zorglub@videolan.org>
Wed, 19 Jul 2006 09:45:02 +0000 (09:45 +0000)
committerClément Stenac <zorglub@videolan.org>
Wed, 19 Jul 2006 09:45:02 +0000 (09:45 +0000)
No need for a separate directory for 1 file

12 files changed:
configure.ac
modules/access/Modules.am
modules/access/pvr.c [new file with mode: 0644]
modules/access/pvr/Modules.am [deleted file]
modules/access/pvr/pvr.c [deleted file]
modules/access/pvr/videodev2.h [deleted file]
modules/access/v4l.c [new file with mode: 0644]
modules/access/v4l/Modules.am [deleted file]
modules/access/v4l/v4l.c [deleted file]
modules/access/v4l/videodev_mjpeg.h [deleted file]
modules/access/videodev2.h [new file with mode: 0644]
modules/access/videodev_mjpeg.h [new file with mode: 0644]

index 42129eb..5addd65 100644 (file)
@@ -5489,8 +5489,6 @@ AC_CONFIG_FILES([
   modules/access/dshow/Makefile
   modules/access/dvb/Makefile
   modules/access/mms/Makefile
-  modules/access/pvr/Makefile
-  modules/access/v4l/Makefile
   modules/access/cdda/Makefile
   modules/access/rtsp/Makefile
   modules/access/vcd/Makefile
index 09f3457..948a1be 100644 (file)
@@ -10,6 +10,8 @@ SOURCES_access_gnomevfs = gnomevfs.c
 SOURCES_dvdnav = dvdnav.c
 SOURCES_dvdread = dvdread.c
 SOURCES_access_fake = fake.c
+SOURCES_pvr = pvr.c videodev2.h
+SOURCES_v4l = v4l.c videodev_mjpeg.h
 SOURCES_cdda = \
         cdda.c \
         vcd/cdrom.c \
diff --git a/modules/access/pvr.c b/modules/access/pvr.c
new file mode 100644 (file)
index 0000000..a3409e7
--- /dev/null
@@ -0,0 +1,847 @@
+/*****************************************************************************
+ * pvr.c
+ *****************************************************************************
+ * Copyright (C) 2001, 2002 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Eric Petit <titer@videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <vlc/vlc.h>
+#include <vlc/input.h>
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <linux/types.h>
+#include <sys/ioctl.h>
+#include <sys/poll.h>
+#include "videodev2.h"
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int  Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
+#define CACHING_TEXT N_("Caching value in ms")
+#define CACHING_LONGTEXT N_( \
+    "Default caching value for PVR streams. This " \
+    "value should be set in milliseconds." )
+
+#define DEVICE_TEXT N_( "Device" )
+#define DEVICE_LONGTEXT N_( "PVR video device" )
+
+#define RADIO_DEVICE_TEXT N_( "Radio device" )
+#define RADIO_DEVICE_LONGTEXT N_( "PVR radio device" )
+
+#define NORM_TEXT N_( "Norm" )
+#define NORM_LONGTEXT N_( "Norm of the stream " \
+    "(Automatic, SECAM, PAL, or NTSC)." )
+
+#define WIDTH_TEXT N_( "Width" )
+#define WIDTH_LONGTEXT N_( "Width of the stream to capture " \
+    "(-1 for autodetection)." )
+
+#define HEIGHT_TEXT N_( "Height" )
+#define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \
+    "(-1 for autodetection)." )
+
+#define FREQUENCY_TEXT N_( "Frequency" )
+#define FREQUENCY_LONGTEXT N_( "Frequency to capture (in kHz), if applicable." )
+
+#define FRAMERATE_TEXT N_( "Framerate" )
+#define FRAMERATE_LONGTEXT N_( "Framerate to capture, if applicable " \
+    "(-1 for autodetect)." )
+
+#define KEYINT_TEXT N_( "Key interval" )
+#define KEYINT_LONGTEXT N_( "Interval between keyframes (-1 for autodetect)." )
+
+#define BFRAMES_TEXT N_( "B Frames" )
+#define BFRAMES_LONGTEXT N_("If this option is set, B-Frames will be used. " \
+    "Use this option to set the number of B-Frames.")
+
+#define BITRATE_TEXT N_( "Bitrate" )
+#define BITRATE_LONGTEXT N_( "Bitrate to use (-1 for default)." )
+
+#define BITRATE_PEAK_TEXT N_( "Bitrate peak" )
+#define BITRATE_PEAK_LONGTEXT N_( "Peak bitrate in VBR mode." )
+
+/// \bug extra parenthesis
+#define BITRATE_MODE_TEXT N_( "Bitrate mode)" )
+#define BITRATE_MODE_LONGTEXT N_( "Bitrate mode to use (VBR or CBR)." )
+
+#define BITMASK_TEXT N_( "Audio bitmask" )
+#define BITMASK_LONGTEXT N_("Bitmask that will "\
+    "get used by the audio part of the card." )
+
+#define VOLUME_TEXT N_( "Volume" )
+#define VOLUME_LONGTEXT N_("Audio volume (0-65535)." )
+
+#define CHAN_TEXT N_( "Channel" )
+#define CHAN_LONGTEXT N_( "Channel of the card to use (Usually, 0 = tuner, " \
+    "1 = composite, 2 = svideo)" )
+
+static int i_norm_list[] =
+    { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC };
+static char *psz_norm_list_text[] =
+    { N_("Automatic"), N_("SECAM"), N_("PAL"),  N_("NTSC") };
+
+static int i_bitrates[] = { 0, 1 };
+static char *psz_bitrates_list_text[] = { N_("vbr"), N_("cbr") };
+
+static int pi_radio_range[2] = { 65000, 108000 };
+
+vlc_module_begin();
+    set_shortname( _("PVR") );
+    set_description( _("IVTV MPEG Encoding cards input") );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_ACCESS );
+    set_capability( "access2", 0 );
+    add_shortcut( "pvr" );
+
+    add_integer( "pvr-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
+    add_string( "pvr-device", "/dev/video0", NULL, DEVICE_TEXT,
+                 DEVICE_LONGTEXT, VLC_FALSE );
+    add_string( "pvr-radio-device", "/dev/radio0", NULL, RADIO_DEVICE_TEXT,
+                 RADIO_DEVICE_LONGTEXT, VLC_FALSE );
+    add_integer( "pvr-norm", V4L2_STD_UNKNOWN , NULL, NORM_TEXT,
+                 NORM_LONGTEXT, VLC_FALSE );
+       change_integer_list( i_norm_list, psz_norm_list_text, 0 );
+    add_integer( "pvr-width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_TRUE );
+    add_integer( "pvr-height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "pvr-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
+                 VLC_FALSE );
+    add_integer( "pvr-framerate", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "pvr-keyint", -1, NULL, KEYINT_TEXT, KEYINT_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "pvr-bframes", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "pvr-bitrate", -1, NULL, BITRATE_TEXT, BITRATE_LONGTEXT,
+                 VLC_FALSE );
+    add_integer( "pvr-bitrate-peak", -1, NULL, BITRATE_PEAK_TEXT,
+                 BITRATE_PEAK_LONGTEXT, VLC_TRUE );
+    add_integer( "pvr-bitrate-mode", -1, NULL, BITRATE_MODE_TEXT,
+                 BITRATE_MODE_LONGTEXT, VLC_TRUE );
+        change_integer_list( i_bitrates, psz_bitrates_list_text, 0 );
+    add_integer( "pvr-audio-bitmask", -1, NULL, BITMASK_TEXT,
+                 BITMASK_LONGTEXT, VLC_TRUE );
+    add_integer( "pvr-audio-volume", -1, NULL, VOLUME_TEXT,
+                 VOLUME_LONGTEXT, VLC_TRUE );
+    add_integer( "pvr-channel", -1, NULL, CHAN_TEXT, CHAN_LONGTEXT, VLC_TRUE );
+
+    set_callbacks( Open, Close );
+vlc_module_end();
+
+/*****************************************************************************
+ * Prototypes
+ *****************************************************************************/
+static int Read   ( access_t *, uint8_t *, int );
+static int Control( access_t *, int, va_list );
+
+/* ivtv specific ioctls */
+#define IVTV_IOC_G_CODEC    0xFFEE7703
+#define IVTV_IOC_S_CODEC    0xFFEE7704
+
+/* for use with IVTV_IOC_G_CODEC and IVTV_IOC_S_CODEC */
+
+struct ivtv_ioctl_codec {
+        uint32_t aspect;
+        uint32_t audio_bitmask;
+        uint32_t bframes;
+        uint32_t bitrate_mode;
+        uint32_t bitrate;
+        uint32_t bitrate_peak;
+        uint32_t dnr_mode;
+        uint32_t dnr_spatial;
+        uint32_t dnr_temporal;
+        uint32_t dnr_type;
+        uint32_t framerate;
+        uint32_t framespergop;
+        uint32_t gop_closure;
+        uint32_t pulldown;
+        uint32_t stream_type;
+};
+
+struct access_sys_t
+{
+    /* file descriptor */
+    int i_fd;
+    int i_radio_fd;
+
+    /* options */
+    int i_standard;
+    int i_width;
+    int i_height;
+    int i_frequency;
+    int i_framerate;
+    int i_keyint;
+    int i_bframes;
+    int i_bitrate;
+    int i_bitrate_peak;
+    int i_bitrate_mode;
+    int i_audio_bitmask;
+    int i_input;
+    int i_volume;
+};
+
+/*****************************************************************************
+ * 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, * psz_parser, * psz_device, * psz_radio_device;
+    vlc_value_t val;
+
+    //psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
+
+    p_access->pf_read = Read;
+    p_access->pf_block = NULL;
+    p_access->pf_seek = NULL;
+    p_access->pf_control = Control;
+    p_access->info.i_update = 0;
+    p_access->info.i_size = 0;
+    p_access->info.i_pos = 0;
+    p_access->info.b_eof = VLC_FALSE;
+    p_access->info.i_title = 0;
+    p_access->info.i_seekpoint = 0;
+
+    /* create private access data */
+    p_sys = calloc( sizeof( access_sys_t ), 1 );
+    p_access->p_sys = p_sys;
+
+    /* defaults values */
+    var_Create( p_access, "pvr-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+
+    var_Create( p_access, "pvr-device", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-device" , &val);
+    psz_device = val.psz_string;
+
+    var_Create( p_access, "pvr-radio-device", VLC_VAR_STRING |
+                                              VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-radio-device" , &val);
+    psz_radio_device = val.psz_string;
+
+    var_Create( p_access, "pvr-norm", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-norm" , &val);
+    p_sys->i_standard = val.i_int;
+
+    var_Create( p_access, "pvr-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-width" , &val);
+    p_sys->i_width = val.i_int;
+
+    var_Create( p_access, "pvr-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-height" , &val);
+    p_sys->i_height = val.i_int;
+
+    var_Create( p_access, "pvr-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-frequency" , &val);
+    p_sys->i_frequency = val.i_int;
+
+    var_Create( p_access, "pvr-framerate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-framerate" , &val);
+    p_sys->i_framerate = val.i_int;
+
+    var_Create( p_access, "pvr-keyint", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-keyint" , &val);
+    p_sys->i_keyint = val.i_int;
+
+    var_Create( p_access, "pvr-bframes", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-bframes" , &val);
+    p_sys->i_bframes = val.b_bool;
+
+    var_Create( p_access, "pvr-bitrate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-bitrate" , &val);
+    p_sys->i_bitrate = val.i_int;
+
+    var_Create( p_access, "pvr-bitrate-peak", VLC_VAR_INTEGER |
+                                              VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-bitrate-peak" , &val);
+    p_sys->i_bitrate_peak = val.i_int;
+
+    var_Create( p_access, "pvr-bitrate-mode", VLC_VAR_INTEGER |
+                                              VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-bitrate-mode" , &val);
+    p_sys->i_bitrate_mode = val.i_int;
+
+    var_Create( p_access, "pvr-audio-bitmask", VLC_VAR_INTEGER |
+                                              VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-audio-bitmask" , &val);
+    p_sys->i_audio_bitmask = val.i_int;
+
+    var_Create( p_access, "pvr-audio-volume", VLC_VAR_INTEGER |
+                                              VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-audio-volume" , &val);
+    p_sys->i_volume = val.i_int;
+
+    var_Create( p_access, "pvr-channel", VLC_VAR_INTEGER |
+                                              VLC_VAR_DOINHERIT );
+    var_Get( p_access, "pvr-channel" , &val);
+    p_sys->i_input = val.i_int;
+
+    /* parse command line options */
+    psz_tofree = strdup( p_access->psz_path );
+    psz_parser = psz_tofree;
+
+    if( *psz_parser )
+    {
+        for( ;; )
+        {
+            if ( !strncmp( psz_parser, "norm=", strlen( "norm=" ) ) )
+            {
+                char *psz_parser_init;
+                psz_parser += strlen( "norm=" );
+                psz_parser_init = psz_parser;
+                while ( *psz_parser != ':' && *psz_parser != ','
+                                                    && *psz_parser != '\0' )
+                {
+                    psz_parser++;
+                }
+
+                if ( !strncmp( psz_parser_init, "secam" ,
+                               psz_parser - psz_parser_init ) )
+                {
+                    p_sys->i_standard = V4L2_STD_SECAM;
+                }
+                else if ( !strncmp( psz_parser_init, "pal" ,
+                                    psz_parser - psz_parser_init ) )
+                {
+                    p_sys->i_standard = V4L2_STD_PAL;
+                }
+                else if ( !strncmp( psz_parser_init, "ntsc" ,
+                                    psz_parser - psz_parser_init ) )
+                {
+                    p_sys->i_standard = V4L2_STD_NTSC;
+                }
+                else
+                {
+                    p_sys->i_standard = strtol( psz_parser_init ,
+                                                &psz_parser, 0 );
+                }
+            }
+            else if( !strncmp( psz_parser, "channel=",
+                               strlen( "channel=" ) ) )
+            {
+                p_sys->i_input =
+                    strtol( psz_parser + strlen( "channel=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "device=", strlen( "device=" ) ) )
+            {
+                psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
+                sprintf( psz_device, "/dev/video%ld",
+                            strtol( psz_parser + strlen( "device=" ),
+                            &psz_parser, 0 ) );
+            }
+            else if( !strncmp( psz_parser, "frequency=",
+                               strlen( "frequency=" ) ) )
+            {
+                p_sys->i_frequency =
+                    strtol( psz_parser + strlen( "frequency=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "framerate=",
+                               strlen( "framerate=" ) ) )
+            {
+                p_sys->i_framerate =
+                    strtol( psz_parser + strlen( "framerate=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "keyint=",
+                               strlen( "keyint=" ) ) )
+            {
+                p_sys->i_keyint =
+                    strtol( psz_parser + strlen( "keyint=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "bframes=",
+                               strlen( "bframes=" ) ) )
+            {
+                p_sys->i_bframes =
+                    strtol( psz_parser + strlen( "bframes=" ),
+                            &psz_parser, 0 );
+            }
+
+            else if( !strncmp( psz_parser, "width=",
+                               strlen( "width=" ) ) )
+            {
+                p_sys->i_width =
+                    strtol( psz_parser + strlen( "width=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "height=",
+                               strlen( "height=" ) ) )
+            {
+                p_sys->i_height =
+                    strtol( psz_parser + strlen( "height=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "audio=",
+                               strlen( "audio=" ) ) )
+            {
+                p_sys->i_audio_bitmask =
+                    strtol( psz_parser + strlen( "audio=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "bitrate=",
+                               strlen( "bitrate=" ) ) )
+            {
+                p_sys->i_bitrate =
+                    strtol( psz_parser + strlen( "bitrate=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "maxbitrate=",
+                               strlen( "maxbitrate=" ) ) )
+            {
+                p_sys->i_bitrate_peak =
+                    strtol( psz_parser + strlen( "maxbitrate=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "bitratemode=",
+                               strlen( "bitratemode=" ) ) )
+            {
+                char *psz_parser_init;
+                psz_parser += strlen( "bitratemode=" );
+                psz_parser_init = psz_parser;
+                while ( *psz_parser != ':' && *psz_parser != ','
+                         && *psz_parser != '\0' )
+                {
+                    psz_parser++;
+                }
+
+                if ( !strncmp( psz_parser_init, "vbr" ,
+                               psz_parser - psz_parser_init ) )
+                {
+                     p_sys->i_bitrate_mode = 0;
+                }
+                else if ( !strncmp( psz_parser_init, "cbr" ,
+                                    psz_parser - psz_parser_init ) )
+                {
+                    p_sys->i_bitrate_mode = 1;
+                }
+            }
+            else if( !strncmp( psz_parser, "size=",
+                               strlen( "size=" ) ) )
+            {
+                p_sys->i_width =
+                    strtol( psz_parser + strlen( "size=" ),
+                            &psz_parser, 0 );
+                p_sys->i_height =
+                    strtol( psz_parser + 1 ,
+                            &psz_parser, 0 );
+            }
+            else
+            {
+                char *psz_parser_init;
+                psz_parser_init = psz_parser;
+                while ( *psz_parser != ':' && *psz_parser != ',' && *psz_parser != '\0' )
+                {
+                    psz_parser++;
+                }
+                psz_device = calloc( psz_parser - psz_parser_init + 1, 1 );
+                strncpy( psz_device, psz_parser_init,
+                         psz_parser - psz_parser_init );
+            }
+            if( *psz_parser )
+                psz_parser++;
+            else
+                break;
+        }
+    }
+
+    //give a default value to psz_device if none has been specified
+
+    if ( psz_device == NULL )
+    {
+        psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
+        strcpy( psz_device, "/dev/video0" );
+    }
+
+    free( psz_tofree );
+
+    /* open the device */
+    if( ( p_sys->i_fd = open( psz_device, O_RDWR ) ) < 0 )
+    {
+        msg_Err( p_access, "cannot open device (%s)", strerror( errno ) );
+        free( p_sys );
+        return VLC_EGENERIC;
+    }
+    else
+    {
+        msg_Dbg( p_access, "using video device: %s",psz_device);
+    }
+
+    free( psz_device );
+
+    /* set the input */
+    if ( p_sys->i_input != -1 )
+    {
+        if ( ioctl( p_sys->i_fd, VIDIOC_S_INPUT, &p_sys->i_input ) < 0 )
+        {
+            msg_Warn( p_access, "VIDIOC_S_INPUT failed" );
+        }
+        else
+        {
+            msg_Dbg( p_access, "input set to: %d", p_sys->i_input);
+        }
+    }
+
+    /* set the video standard */
+    if ( p_sys->i_standard != V4L2_STD_UNKNOWN )
+    {
+        if ( ioctl( p_sys->i_fd, VIDIOC_S_STD, &p_sys->i_standard ) < 0 )
+        {
+            msg_Warn( p_access, "VIDIOC_S_STD failed" );
+        }
+        else
+        {
+            msg_Dbg( p_access, "video standard set to: %x", p_sys->i_standard);
+        }
+    }
+
+    /* set the picture size */
+    if ( p_sys->i_width != -1 || p_sys->i_height != -1 )
+    {
+        struct v4l2_format vfmt;
+
+        vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+        if ( ioctl( p_sys->i_fd, VIDIOC_G_FMT, &vfmt ) < 0 )
+        {
+            msg_Warn( p_access, "VIDIOC_G_FMT failed" );
+        }
+        else
+        {
+            if ( p_sys->i_width != -1 )
+            {
+                vfmt.fmt.pix.width = p_sys->i_width;
+            }
+
+            if ( p_sys->i_height != -1 )
+            {
+                vfmt.fmt.pix.height = p_sys->i_height;
+            }
+
+            if ( ioctl( p_sys->i_fd, VIDIOC_S_FMT, &vfmt ) < 0 )
+            {
+                msg_Warn( p_access, "VIDIOC_S_FMT failed" );
+            }
+            else
+            {
+                msg_Dbg( p_access, "picture size set to: %dx%d",
+                         vfmt.fmt.pix.width, vfmt.fmt.pix.height );
+            }
+        }
+    }
+
+    /* set the frequency */
+    if ( p_sys->i_frequency != -1 )
+    {
+        int i_fd;
+        struct v4l2_tuner vt;
+        vt.index = 0; /* TODO: let the user choose the tuner */
+        memset( &vt.reserved, 0, sizeof(vt.reserved) );
+
+        if ( p_sys->i_frequency >= pi_radio_range[0]
+              && p_sys->i_frequency <= pi_radio_range[1] )
+        {
+            if( ( p_sys->i_radio_fd = open( psz_radio_device, O_RDWR ) ) < 0 )
+            {
+                msg_Err( p_access, "cannot open radio device (%s)",
+                         strerror( errno ) );
+                close( p_sys->i_fd );
+                free( p_sys );
+                return VLC_EGENERIC;
+            }
+            else
+            {
+                msg_Dbg( p_access, "using radio device: %s", psz_radio_device );
+            }
+            i_fd = p_sys->i_radio_fd;
+        }
+        else
+        {
+            i_fd = p_sys->i_fd;
+            p_sys->i_radio_fd = -1;
+        }
+
+        if ( ioctl( i_fd, VIDIOC_G_TUNER, &vt ) < 0 )
+        {
+            msg_Warn( p_access, "VIDIOC_G_TUNER failed (%s)",
+                      strerror( errno ) );
+        }
+        else
+        {
+            struct v4l2_frequency vf;
+            vf.tuner = vt.index;
+
+            if ( ioctl( i_fd, VIDIOC_G_FREQUENCY, &vf ) < 0 )
+            {
+                msg_Warn( p_access, "VIDIOC_G_FREQUENCY failed (%s)",
+                          strerror( errno ) );
+            }
+            else
+            {
+                if( vt.capability & V4L2_TUNER_CAP_LOW )
+                    vf.frequency = p_sys->i_frequency * 16;
+                else
+                    vf.frequency = (p_sys->i_frequency * 16 + 500) / 1000;
+
+                if( ioctl( i_fd, VIDIOC_S_FREQUENCY, &vf ) < 0 )
+                {
+                    msg_Warn( p_access, "VIDIOC_S_FREQUENCY failed (%s)",
+                              strerror( errno ) );
+                }
+                else
+                {
+                    msg_Dbg( p_access, "tuner frequency set to: %d",
+                             p_sys->i_frequency );
+                }
+            }
+        }
+    }
+
+    /* control parameters */
+    if ( p_sys->i_volume != -1 )
+    {
+        struct v4l2_control ctrl;
+
+        ctrl.id = V4L2_CID_AUDIO_VOLUME;
+        ctrl.value = p_sys->i_volume;
+
+        if ( ioctl( p_sys->i_fd, VIDIOC_S_CTRL, &ctrl ) < 0 )
+        {
+            msg_Warn( p_access, "VIDIOC_S_CTRL failed" );
+        }
+    }
+
+    /* codec parameters */
+    if ( p_sys->i_framerate != -1
+            || p_sys->i_bitrate_mode != -1
+            || p_sys->i_bitrate_peak != -1
+            || p_sys->i_keyint != -1
+            || p_sys->i_bframes != -1
+            || p_sys->i_bitrate != -1
+            || p_sys->i_audio_bitmask != -1 )
+    {
+        struct ivtv_ioctl_codec codec;
+
+        if ( ioctl( p_sys->i_fd, IVTV_IOC_G_CODEC, &codec ) < 0 )
+        {
+            msg_Warn( p_access, "IVTV_IOC_G_CODEC failed" );
+        }
+        else
+        {
+            if ( p_sys->i_framerate != -1 )
+            {
+                switch ( p_sys->i_framerate )
+                {
+                    case 30:
+                        codec.framerate = 0;
+                        break;
+
+                    case 25:
+                        codec.framerate = 1;
+                        break;
+
+                    default:
+                        msg_Warn( p_access, "invalid framerate, reverting to 25" );
+                        codec.framerate = 1;
+                        break;
+                }
+            }
+
+            if ( p_sys->i_bitrate != -1 )
+            {
+                codec.bitrate = p_sys->i_bitrate;
+            }
+
+            if ( p_sys->i_bitrate_peak != -1 )
+            {
+                codec.bitrate_peak = p_sys->i_bitrate_peak;
+            }
+
+            if ( p_sys->i_bitrate_mode != -1 )
+            {
+                codec.bitrate_mode = p_sys->i_bitrate_mode;
+            }
+
+            if ( p_sys->i_audio_bitmask != -1 )
+            {
+                codec.audio_bitmask = p_sys->i_audio_bitmask;
+            }
+            if ( p_sys->i_keyint != -1 )
+            {
+                codec.framespergop = p_sys->i_keyint;
+            }
+
+            if ( p_sys->i_bframes != -1 )
+            {
+                codec.bframes = p_sys->i_bframes;
+            }
+            if( ioctl( p_sys->i_fd, IVTV_IOC_S_CODEC, &codec ) < 0 )
+            {
+                msg_Warn( p_access, "IVTV_IOC_S_CODEC failed" );
+            }
+            else
+            {
+                msg_Dbg( p_access, "Setting codec parameters to:  framerate: %d, bitrate: %d/%d/%d",
+               codec.framerate, codec.bitrate, codec.bitrate_peak, codec.bitrate_mode );
+            }
+        }
+    }
+
+    /* do a quick read */
+#if 0
+    if ( p_sys->i_fd )
+    {
+        if ( read( p_sys->i_fd, psz_tmp, 1 ) )
+        {
+            msg_Dbg(p_input, "Could read byte from device");
+        }
+        else
+        {
+            msg_Warn(p_input, "Could not read byte from device");
+        }
+    }
+#endif
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close: close the device
+ *****************************************************************************/
+static void Close( vlc_object_t * p_this )
+{
+    access_t *p_access = (access_t*) p_this;
+    access_sys_t * p_sys = p_access->p_sys;
+
+    close( p_sys->i_fd );
+    if ( p_sys->i_radio_fd != -1 )
+        close( p_sys->i_radio_fd );
+    free( p_sys );
+}
+
+/*****************************************************************************
+ * Read
+ *****************************************************************************/
+static int Read( access_t * p_access, uint8_t * p_buffer, int i_len )
+{
+    access_sys_t * p_sys = p_access->p_sys;
+
+    int i_ret;
+    struct pollfd ufd;
+
+    ufd.fd = p_sys->i_fd;
+    ufd.events = POLLIN;
+
+    if( p_access->info.b_eof )
+        return 0;
+
+    do
+    {
+        if( p_access->b_die )
+            return 0;
+
+        ufd.revents = 0;
+    }
+    while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 );
+
+    if( i_ret < 0 )
+    {
+        msg_Err( p_access, "select error (%s)", strerror( errno ) );
+        return -1;
+    }
+
+    i_ret = read( p_sys->i_fd, p_buffer, i_len );
+    if( i_ret == 0 )
+    {
+        p_access->info.b_eof = VLC_TRUE;
+    }
+    else if( i_ret > 0 )
+    {
+        p_access->info.i_pos += i_ret;
+    }
+
+    return i_ret;
+}
+
+/*****************************************************************************
+ * Control
+ *****************************************************************************/
+static int Control( access_t *p_access, int i_query, va_list args )
+{
+    vlc_bool_t   *pb_bool;
+    int          *pi_int;
+    int64_t      *pi_64;
+
+    switch( i_query )
+    {
+        /* */
+        case ACCESS_CAN_SEEK:
+        case ACCESS_CAN_FASTSEEK:
+            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
+            *pb_bool = VLC_FALSE;
+            break;
+        case ACCESS_CAN_PAUSE:
+            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
+            *pb_bool = VLC_FALSE;
+            break;
+        case ACCESS_CAN_CONTROL_PACE:
+            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
+            *pb_bool = VLC_FALSE;
+            break;
+
+        /* */
+        case ACCESS_GET_MTU:
+            pi_int = (int*)va_arg( args, int * );
+            *pi_int = 0;
+            break;
+
+        case ACCESS_GET_PTS_DELAY:
+            pi_64 = (int64_t*)va_arg( args, int64_t * );
+            *pi_64 = (int64_t)var_GetInteger( p_access, "pvr-caching" ) * 1000;
+            break;
+
+        /* */
+        case ACCESS_SET_PAUSE_STATE:
+            /* Nothing to do */
+            break;
+
+        case ACCESS_GET_TITLE_INFO:
+        case ACCESS_SET_TITLE:
+        case ACCESS_SET_SEEKPOINT:
+        case ACCESS_SET_PRIVATE_ID_STATE:
+            return VLC_EGENERIC;
+
+        default:
+            msg_Warn( p_access, "unimplemented query in control" );
+            return VLC_EGENERIC;
+
+    }
+    return VLC_SUCCESS;
+}
diff --git a/modules/access/pvr/Modules.am b/modules/access/pvr/Modules.am
deleted file mode 100644 (file)
index a9b1591..0000000
+++ /dev/null
@@ -1 +0,0 @@
-SOURCES_pvr = pvr.c videodev2.h
diff --git a/modules/access/pvr/pvr.c b/modules/access/pvr/pvr.c
deleted file mode 100644 (file)
index a3409e7..0000000
+++ /dev/null
@@ -1,847 +0,0 @@
-/*****************************************************************************
- * pvr.c
- *****************************************************************************
- * Copyright (C) 2001, 2002 the VideoLAN team
- * $Id$
- *
- * Authors: Eric Petit <titer@videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/input.h>
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <linux/types.h>
-#include <sys/ioctl.h>
-#include <sys/poll.h>
-#include "videodev2.h"
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-static int  Open ( vlc_object_t * );
-static void Close( vlc_object_t * );
-
-#define CACHING_TEXT N_("Caching value in ms")
-#define CACHING_LONGTEXT N_( \
-    "Default caching value for PVR streams. This " \
-    "value should be set in milliseconds." )
-
-#define DEVICE_TEXT N_( "Device" )
-#define DEVICE_LONGTEXT N_( "PVR video device" )
-
-#define RADIO_DEVICE_TEXT N_( "Radio device" )
-#define RADIO_DEVICE_LONGTEXT N_( "PVR radio device" )
-
-#define NORM_TEXT N_( "Norm" )
-#define NORM_LONGTEXT N_( "Norm of the stream " \
-    "(Automatic, SECAM, PAL, or NTSC)." )
-
-#define WIDTH_TEXT N_( "Width" )
-#define WIDTH_LONGTEXT N_( "Width of the stream to capture " \
-    "(-1 for autodetection)." )
-
-#define HEIGHT_TEXT N_( "Height" )
-#define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \
-    "(-1 for autodetection)." )
-
-#define FREQUENCY_TEXT N_( "Frequency" )
-#define FREQUENCY_LONGTEXT N_( "Frequency to capture (in kHz), if applicable." )
-
-#define FRAMERATE_TEXT N_( "Framerate" )
-#define FRAMERATE_LONGTEXT N_( "Framerate to capture, if applicable " \
-    "(-1 for autodetect)." )
-
-#define KEYINT_TEXT N_( "Key interval" )
-#define KEYINT_LONGTEXT N_( "Interval between keyframes (-1 for autodetect)." )
-
-#define BFRAMES_TEXT N_( "B Frames" )
-#define BFRAMES_LONGTEXT N_("If this option is set, B-Frames will be used. " \
-    "Use this option to set the number of B-Frames.")
-
-#define BITRATE_TEXT N_( "Bitrate" )
-#define BITRATE_LONGTEXT N_( "Bitrate to use (-1 for default)." )
-
-#define BITRATE_PEAK_TEXT N_( "Bitrate peak" )
-#define BITRATE_PEAK_LONGTEXT N_( "Peak bitrate in VBR mode." )
-
-/// \bug extra parenthesis
-#define BITRATE_MODE_TEXT N_( "Bitrate mode)" )
-#define BITRATE_MODE_LONGTEXT N_( "Bitrate mode to use (VBR or CBR)." )
-
-#define BITMASK_TEXT N_( "Audio bitmask" )
-#define BITMASK_LONGTEXT N_("Bitmask that will "\
-    "get used by the audio part of the card." )
-
-#define VOLUME_TEXT N_( "Volume" )
-#define VOLUME_LONGTEXT N_("Audio volume (0-65535)." )
-
-#define CHAN_TEXT N_( "Channel" )
-#define CHAN_LONGTEXT N_( "Channel of the card to use (Usually, 0 = tuner, " \
-    "1 = composite, 2 = svideo)" )
-
-static int i_norm_list[] =
-    { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC };
-static char *psz_norm_list_text[] =
-    { N_("Automatic"), N_("SECAM"), N_("PAL"),  N_("NTSC") };
-
-static int i_bitrates[] = { 0, 1 };
-static char *psz_bitrates_list_text[] = { N_("vbr"), N_("cbr") };
-
-static int pi_radio_range[2] = { 65000, 108000 };
-
-vlc_module_begin();
-    set_shortname( _("PVR") );
-    set_description( _("IVTV MPEG Encoding cards input") );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_ACCESS );
-    set_capability( "access2", 0 );
-    add_shortcut( "pvr" );
-
-    add_integer( "pvr-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
-    add_string( "pvr-device", "/dev/video0", NULL, DEVICE_TEXT,
-                 DEVICE_LONGTEXT, VLC_FALSE );
-    add_string( "pvr-radio-device", "/dev/radio0", NULL, RADIO_DEVICE_TEXT,
-                 RADIO_DEVICE_LONGTEXT, VLC_FALSE );
-    add_integer( "pvr-norm", V4L2_STD_UNKNOWN , NULL, NORM_TEXT,
-                 NORM_LONGTEXT, VLC_FALSE );
-       change_integer_list( i_norm_list, psz_norm_list_text, 0 );
-    add_integer( "pvr-width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_TRUE );
-    add_integer( "pvr-height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
-                 VLC_TRUE );
-    add_integer( "pvr-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
-                 VLC_FALSE );
-    add_integer( "pvr-framerate", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
-                 VLC_TRUE );
-    add_integer( "pvr-keyint", -1, NULL, KEYINT_TEXT, KEYINT_LONGTEXT,
-                 VLC_TRUE );
-    add_integer( "pvr-bframes", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
-                 VLC_TRUE );
-    add_integer( "pvr-bitrate", -1, NULL, BITRATE_TEXT, BITRATE_LONGTEXT,
-                 VLC_FALSE );
-    add_integer( "pvr-bitrate-peak", -1, NULL, BITRATE_PEAK_TEXT,
-                 BITRATE_PEAK_LONGTEXT, VLC_TRUE );
-    add_integer( "pvr-bitrate-mode", -1, NULL, BITRATE_MODE_TEXT,
-                 BITRATE_MODE_LONGTEXT, VLC_TRUE );
-        change_integer_list( i_bitrates, psz_bitrates_list_text, 0 );
-    add_integer( "pvr-audio-bitmask", -1, NULL, BITMASK_TEXT,
-                 BITMASK_LONGTEXT, VLC_TRUE );
-    add_integer( "pvr-audio-volume", -1, NULL, VOLUME_TEXT,
-                 VOLUME_LONGTEXT, VLC_TRUE );
-    add_integer( "pvr-channel", -1, NULL, CHAN_TEXT, CHAN_LONGTEXT, VLC_TRUE );
-
-    set_callbacks( Open, Close );
-vlc_module_end();
-
-/*****************************************************************************
- * Prototypes
- *****************************************************************************/
-static int Read   ( access_t *, uint8_t *, int );
-static int Control( access_t *, int, va_list );
-
-/* ivtv specific ioctls */
-#define IVTV_IOC_G_CODEC    0xFFEE7703
-#define IVTV_IOC_S_CODEC    0xFFEE7704
-
-/* for use with IVTV_IOC_G_CODEC and IVTV_IOC_S_CODEC */
-
-struct ivtv_ioctl_codec {
-        uint32_t aspect;
-        uint32_t audio_bitmask;
-        uint32_t bframes;
-        uint32_t bitrate_mode;
-        uint32_t bitrate;
-        uint32_t bitrate_peak;
-        uint32_t dnr_mode;
-        uint32_t dnr_spatial;
-        uint32_t dnr_temporal;
-        uint32_t dnr_type;
-        uint32_t framerate;
-        uint32_t framespergop;
-        uint32_t gop_closure;
-        uint32_t pulldown;
-        uint32_t stream_type;
-};
-
-struct access_sys_t
-{
-    /* file descriptor */
-    int i_fd;
-    int i_radio_fd;
-
-    /* options */
-    int i_standard;
-    int i_width;
-    int i_height;
-    int i_frequency;
-    int i_framerate;
-    int i_keyint;
-    int i_bframes;
-    int i_bitrate;
-    int i_bitrate_peak;
-    int i_bitrate_mode;
-    int i_audio_bitmask;
-    int i_input;
-    int i_volume;
-};
-
-/*****************************************************************************
- * 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, * psz_parser, * psz_device, * psz_radio_device;
-    vlc_value_t val;
-
-    //psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
-
-    p_access->pf_read = Read;
-    p_access->pf_block = NULL;
-    p_access->pf_seek = NULL;
-    p_access->pf_control = Control;
-    p_access->info.i_update = 0;
-    p_access->info.i_size = 0;
-    p_access->info.i_pos = 0;
-    p_access->info.b_eof = VLC_FALSE;
-    p_access->info.i_title = 0;
-    p_access->info.i_seekpoint = 0;
-
-    /* create private access data */
-    p_sys = calloc( sizeof( access_sys_t ), 1 );
-    p_access->p_sys = p_sys;
-
-    /* defaults values */
-    var_Create( p_access, "pvr-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-
-    var_Create( p_access, "pvr-device", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-device" , &val);
-    psz_device = val.psz_string;
-
-    var_Create( p_access, "pvr-radio-device", VLC_VAR_STRING |
-                                              VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-radio-device" , &val);
-    psz_radio_device = val.psz_string;
-
-    var_Create( p_access, "pvr-norm", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-norm" , &val);
-    p_sys->i_standard = val.i_int;
-
-    var_Create( p_access, "pvr-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-width" , &val);
-    p_sys->i_width = val.i_int;
-
-    var_Create( p_access, "pvr-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-height" , &val);
-    p_sys->i_height = val.i_int;
-
-    var_Create( p_access, "pvr-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-frequency" , &val);
-    p_sys->i_frequency = val.i_int;
-
-    var_Create( p_access, "pvr-framerate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-framerate" , &val);
-    p_sys->i_framerate = val.i_int;
-
-    var_Create( p_access, "pvr-keyint", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-keyint" , &val);
-    p_sys->i_keyint = val.i_int;
-
-    var_Create( p_access, "pvr-bframes", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-bframes" , &val);
-    p_sys->i_bframes = val.b_bool;
-
-    var_Create( p_access, "pvr-bitrate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-bitrate" , &val);
-    p_sys->i_bitrate = val.i_int;
-
-    var_Create( p_access, "pvr-bitrate-peak", VLC_VAR_INTEGER |
-                                              VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-bitrate-peak" , &val);
-    p_sys->i_bitrate_peak = val.i_int;
-
-    var_Create( p_access, "pvr-bitrate-mode", VLC_VAR_INTEGER |
-                                              VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-bitrate-mode" , &val);
-    p_sys->i_bitrate_mode = val.i_int;
-
-    var_Create( p_access, "pvr-audio-bitmask", VLC_VAR_INTEGER |
-                                              VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-audio-bitmask" , &val);
-    p_sys->i_audio_bitmask = val.i_int;
-
-    var_Create( p_access, "pvr-audio-volume", VLC_VAR_INTEGER |
-                                              VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-audio-volume" , &val);
-    p_sys->i_volume = val.i_int;
-
-    var_Create( p_access, "pvr-channel", VLC_VAR_INTEGER |
-                                              VLC_VAR_DOINHERIT );
-    var_Get( p_access, "pvr-channel" , &val);
-    p_sys->i_input = val.i_int;
-
-    /* parse command line options */
-    psz_tofree = strdup( p_access->psz_path );
-    psz_parser = psz_tofree;
-
-    if( *psz_parser )
-    {
-        for( ;; )
-        {
-            if ( !strncmp( psz_parser, "norm=", strlen( "norm=" ) ) )
-            {
-                char *psz_parser_init;
-                psz_parser += strlen( "norm=" );
-                psz_parser_init = psz_parser;
-                while ( *psz_parser != ':' && *psz_parser != ','
-                                                    && *psz_parser != '\0' )
-                {
-                    psz_parser++;
-                }
-
-                if ( !strncmp( psz_parser_init, "secam" ,
-                               psz_parser - psz_parser_init ) )
-                {
-                    p_sys->i_standard = V4L2_STD_SECAM;
-                }
-                else if ( !strncmp( psz_parser_init, "pal" ,
-                                    psz_parser - psz_parser_init ) )
-                {
-                    p_sys->i_standard = V4L2_STD_PAL;
-                }
-                else if ( !strncmp( psz_parser_init, "ntsc" ,
-                                    psz_parser - psz_parser_init ) )
-                {
-                    p_sys->i_standard = V4L2_STD_NTSC;
-                }
-                else
-                {
-                    p_sys->i_standard = strtol( psz_parser_init ,
-                                                &psz_parser, 0 );
-                }
-            }
-            else if( !strncmp( psz_parser, "channel=",
-                               strlen( "channel=" ) ) )
-            {
-                p_sys->i_input =
-                    strtol( psz_parser + strlen( "channel=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "device=", strlen( "device=" ) ) )
-            {
-                psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
-                sprintf( psz_device, "/dev/video%ld",
-                            strtol( psz_parser + strlen( "device=" ),
-                            &psz_parser, 0 ) );
-            }
-            else if( !strncmp( psz_parser, "frequency=",
-                               strlen( "frequency=" ) ) )
-            {
-                p_sys->i_frequency =
-                    strtol( psz_parser + strlen( "frequency=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "framerate=",
-                               strlen( "framerate=" ) ) )
-            {
-                p_sys->i_framerate =
-                    strtol( psz_parser + strlen( "framerate=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "keyint=",
-                               strlen( "keyint=" ) ) )
-            {
-                p_sys->i_keyint =
-                    strtol( psz_parser + strlen( "keyint=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "bframes=",
-                               strlen( "bframes=" ) ) )
-            {
-                p_sys->i_bframes =
-                    strtol( psz_parser + strlen( "bframes=" ),
-                            &psz_parser, 0 );
-            }
-
-            else if( !strncmp( psz_parser, "width=",
-                               strlen( "width=" ) ) )
-            {
-                p_sys->i_width =
-                    strtol( psz_parser + strlen( "width=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "height=",
-                               strlen( "height=" ) ) )
-            {
-                p_sys->i_height =
-                    strtol( psz_parser + strlen( "height=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "audio=",
-                               strlen( "audio=" ) ) )
-            {
-                p_sys->i_audio_bitmask =
-                    strtol( psz_parser + strlen( "audio=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "bitrate=",
-                               strlen( "bitrate=" ) ) )
-            {
-                p_sys->i_bitrate =
-                    strtol( psz_parser + strlen( "bitrate=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "maxbitrate=",
-                               strlen( "maxbitrate=" ) ) )
-            {
-                p_sys->i_bitrate_peak =
-                    strtol( psz_parser + strlen( "maxbitrate=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "bitratemode=",
-                               strlen( "bitratemode=" ) ) )
-            {
-                char *psz_parser_init;
-                psz_parser += strlen( "bitratemode=" );
-                psz_parser_init = psz_parser;
-                while ( *psz_parser != ':' && *psz_parser != ','
-                         && *psz_parser != '\0' )
-                {
-                    psz_parser++;
-                }
-
-                if ( !strncmp( psz_parser_init, "vbr" ,
-                               psz_parser - psz_parser_init ) )
-                {
-                     p_sys->i_bitrate_mode = 0;
-                }
-                else if ( !strncmp( psz_parser_init, "cbr" ,
-                                    psz_parser - psz_parser_init ) )
-                {
-                    p_sys->i_bitrate_mode = 1;
-                }
-            }
-            else if( !strncmp( psz_parser, "size=",
-                               strlen( "size=" ) ) )
-            {
-                p_sys->i_width =
-                    strtol( psz_parser + strlen( "size=" ),
-                            &psz_parser, 0 );
-                p_sys->i_height =
-                    strtol( psz_parser + 1 ,
-                            &psz_parser, 0 );
-            }
-            else
-            {
-                char *psz_parser_init;
-                psz_parser_init = psz_parser;
-                while ( *psz_parser != ':' && *psz_parser != ',' && *psz_parser != '\0' )
-                {
-                    psz_parser++;
-                }
-                psz_device = calloc( psz_parser - psz_parser_init + 1, 1 );
-                strncpy( psz_device, psz_parser_init,
-                         psz_parser - psz_parser_init );
-            }
-            if( *psz_parser )
-                psz_parser++;
-            else
-                break;
-        }
-    }
-
-    //give a default value to psz_device if none has been specified
-
-    if ( psz_device == NULL )
-    {
-        psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
-        strcpy( psz_device, "/dev/video0" );
-    }
-
-    free( psz_tofree );
-
-    /* open the device */
-    if( ( p_sys->i_fd = open( psz_device, O_RDWR ) ) < 0 )
-    {
-        msg_Err( p_access, "cannot open device (%s)", strerror( errno ) );
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
-    else
-    {
-        msg_Dbg( p_access, "using video device: %s",psz_device);
-    }
-
-    free( psz_device );
-
-    /* set the input */
-    if ( p_sys->i_input != -1 )
-    {
-        if ( ioctl( p_sys->i_fd, VIDIOC_S_INPUT, &p_sys->i_input ) < 0 )
-        {
-            msg_Warn( p_access, "VIDIOC_S_INPUT failed" );
-        }
-        else
-        {
-            msg_Dbg( p_access, "input set to: %d", p_sys->i_input);
-        }
-    }
-
-    /* set the video standard */
-    if ( p_sys->i_standard != V4L2_STD_UNKNOWN )
-    {
-        if ( ioctl( p_sys->i_fd, VIDIOC_S_STD, &p_sys->i_standard ) < 0 )
-        {
-            msg_Warn( p_access, "VIDIOC_S_STD failed" );
-        }
-        else
-        {
-            msg_Dbg( p_access, "video standard set to: %x", p_sys->i_standard);
-        }
-    }
-
-    /* set the picture size */
-    if ( p_sys->i_width != -1 || p_sys->i_height != -1 )
-    {
-        struct v4l2_format vfmt;
-
-        vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-        if ( ioctl( p_sys->i_fd, VIDIOC_G_FMT, &vfmt ) < 0 )
-        {
-            msg_Warn( p_access, "VIDIOC_G_FMT failed" );
-        }
-        else
-        {
-            if ( p_sys->i_width != -1 )
-            {
-                vfmt.fmt.pix.width = p_sys->i_width;
-            }
-
-            if ( p_sys->i_height != -1 )
-            {
-                vfmt.fmt.pix.height = p_sys->i_height;
-            }
-
-            if ( ioctl( p_sys->i_fd, VIDIOC_S_FMT, &vfmt ) < 0 )
-            {
-                msg_Warn( p_access, "VIDIOC_S_FMT failed" );
-            }
-            else
-            {
-                msg_Dbg( p_access, "picture size set to: %dx%d",
-                         vfmt.fmt.pix.width, vfmt.fmt.pix.height );
-            }
-        }
-    }
-
-    /* set the frequency */
-    if ( p_sys->i_frequency != -1 )
-    {
-        int i_fd;
-        struct v4l2_tuner vt;
-        vt.index = 0; /* TODO: let the user choose the tuner */
-        memset( &vt.reserved, 0, sizeof(vt.reserved) );
-
-        if ( p_sys->i_frequency >= pi_radio_range[0]
-              && p_sys->i_frequency <= pi_radio_range[1] )
-        {
-            if( ( p_sys->i_radio_fd = open( psz_radio_device, O_RDWR ) ) < 0 )
-            {
-                msg_Err( p_access, "cannot open radio device (%s)",
-                         strerror( errno ) );
-                close( p_sys->i_fd );
-                free( p_sys );
-                return VLC_EGENERIC;
-            }
-            else
-            {
-                msg_Dbg( p_access, "using radio device: %s", psz_radio_device );
-            }
-            i_fd = p_sys->i_radio_fd;
-        }
-        else
-        {
-            i_fd = p_sys->i_fd;
-            p_sys->i_radio_fd = -1;
-        }
-
-        if ( ioctl( i_fd, VIDIOC_G_TUNER, &vt ) < 0 )
-        {
-            msg_Warn( p_access, "VIDIOC_G_TUNER failed (%s)",
-                      strerror( errno ) );
-        }
-        else
-        {
-            struct v4l2_frequency vf;
-            vf.tuner = vt.index;
-
-            if ( ioctl( i_fd, VIDIOC_G_FREQUENCY, &vf ) < 0 )
-            {
-                msg_Warn( p_access, "VIDIOC_G_FREQUENCY failed (%s)",
-                          strerror( errno ) );
-            }
-            else
-            {
-                if( vt.capability & V4L2_TUNER_CAP_LOW )
-                    vf.frequency = p_sys->i_frequency * 16;
-                else
-                    vf.frequency = (p_sys->i_frequency * 16 + 500) / 1000;
-
-                if( ioctl( i_fd, VIDIOC_S_FREQUENCY, &vf ) < 0 )
-                {
-                    msg_Warn( p_access, "VIDIOC_S_FREQUENCY failed (%s)",
-                              strerror( errno ) );
-                }
-                else
-                {
-                    msg_Dbg( p_access, "tuner frequency set to: %d",
-                             p_sys->i_frequency );
-                }
-            }
-        }
-    }
-
-    /* control parameters */
-    if ( p_sys->i_volume != -1 )
-    {
-        struct v4l2_control ctrl;
-
-        ctrl.id = V4L2_CID_AUDIO_VOLUME;
-        ctrl.value = p_sys->i_volume;
-
-        if ( ioctl( p_sys->i_fd, VIDIOC_S_CTRL, &ctrl ) < 0 )
-        {
-            msg_Warn( p_access, "VIDIOC_S_CTRL failed" );
-        }
-    }
-
-    /* codec parameters */
-    if ( p_sys->i_framerate != -1
-            || p_sys->i_bitrate_mode != -1
-            || p_sys->i_bitrate_peak != -1
-            || p_sys->i_keyint != -1
-            || p_sys->i_bframes != -1
-            || p_sys->i_bitrate != -1
-            || p_sys->i_audio_bitmask != -1 )
-    {
-        struct ivtv_ioctl_codec codec;
-
-        if ( ioctl( p_sys->i_fd, IVTV_IOC_G_CODEC, &codec ) < 0 )
-        {
-            msg_Warn( p_access, "IVTV_IOC_G_CODEC failed" );
-        }
-        else
-        {
-            if ( p_sys->i_framerate != -1 )
-            {
-                switch ( p_sys->i_framerate )
-                {
-                    case 30:
-                        codec.framerate = 0;
-                        break;
-
-                    case 25:
-                        codec.framerate = 1;
-                        break;
-
-                    default:
-                        msg_Warn( p_access, "invalid framerate, reverting to 25" );
-                        codec.framerate = 1;
-                        break;
-                }
-            }
-
-            if ( p_sys->i_bitrate != -1 )
-            {
-                codec.bitrate = p_sys->i_bitrate;
-            }
-
-            if ( p_sys->i_bitrate_peak != -1 )
-            {
-                codec.bitrate_peak = p_sys->i_bitrate_peak;
-            }
-
-            if ( p_sys->i_bitrate_mode != -1 )
-            {
-                codec.bitrate_mode = p_sys->i_bitrate_mode;
-            }
-
-            if ( p_sys->i_audio_bitmask != -1 )
-            {
-                codec.audio_bitmask = p_sys->i_audio_bitmask;
-            }
-            if ( p_sys->i_keyint != -1 )
-            {
-                codec.framespergop = p_sys->i_keyint;
-            }
-
-            if ( p_sys->i_bframes != -1 )
-            {
-                codec.bframes = p_sys->i_bframes;
-            }
-            if( ioctl( p_sys->i_fd, IVTV_IOC_S_CODEC, &codec ) < 0 )
-            {
-                msg_Warn( p_access, "IVTV_IOC_S_CODEC failed" );
-            }
-            else
-            {
-                msg_Dbg( p_access, "Setting codec parameters to:  framerate: %d, bitrate: %d/%d/%d",
-               codec.framerate, codec.bitrate, codec.bitrate_peak, codec.bitrate_mode );
-            }
-        }
-    }
-
-    /* do a quick read */
-#if 0
-    if ( p_sys->i_fd )
-    {
-        if ( read( p_sys->i_fd, psz_tmp, 1 ) )
-        {
-            msg_Dbg(p_input, "Could read byte from device");
-        }
-        else
-        {
-            msg_Warn(p_input, "Could not read byte from device");
-        }
-    }
-#endif
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Close: close the device
- *****************************************************************************/
-static void Close( vlc_object_t * p_this )
-{
-    access_t *p_access = (access_t*) p_this;
-    access_sys_t * p_sys = p_access->p_sys;
-
-    close( p_sys->i_fd );
-    if ( p_sys->i_radio_fd != -1 )
-        close( p_sys->i_radio_fd );
-    free( p_sys );
-}
-
-/*****************************************************************************
- * Read
- *****************************************************************************/
-static int Read( access_t * p_access, uint8_t * p_buffer, int i_len )
-{
-    access_sys_t * p_sys = p_access->p_sys;
-
-    int i_ret;
-    struct pollfd ufd;
-
-    ufd.fd = p_sys->i_fd;
-    ufd.events = POLLIN;
-
-    if( p_access->info.b_eof )
-        return 0;
-
-    do
-    {
-        if( p_access->b_die )
-            return 0;
-
-        ufd.revents = 0;
-    }
-    while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 );
-
-    if( i_ret < 0 )
-    {
-        msg_Err( p_access, "select error (%s)", strerror( errno ) );
-        return -1;
-    }
-
-    i_ret = read( p_sys->i_fd, p_buffer, i_len );
-    if( i_ret == 0 )
-    {
-        p_access->info.b_eof = VLC_TRUE;
-    }
-    else if( i_ret > 0 )
-    {
-        p_access->info.i_pos += i_ret;
-    }
-
-    return i_ret;
-}
-
-/*****************************************************************************
- * Control
- *****************************************************************************/
-static int Control( access_t *p_access, int i_query, va_list args )
-{
-    vlc_bool_t   *pb_bool;
-    int          *pi_int;
-    int64_t      *pi_64;
-
-    switch( i_query )
-    {
-        /* */
-        case ACCESS_CAN_SEEK:
-        case ACCESS_CAN_FASTSEEK:
-            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
-            *pb_bool = VLC_FALSE;
-            break;
-        case ACCESS_CAN_PAUSE:
-            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
-            *pb_bool = VLC_FALSE;
-            break;
-        case ACCESS_CAN_CONTROL_PACE:
-            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
-            *pb_bool = VLC_FALSE;
-            break;
-
-        /* */
-        case ACCESS_GET_MTU:
-            pi_int = (int*)va_arg( args, int * );
-            *pi_int = 0;
-            break;
-
-        case ACCESS_GET_PTS_DELAY:
-            pi_64 = (int64_t*)va_arg( args, int64_t * );
-            *pi_64 = (int64_t)var_GetInteger( p_access, "pvr-caching" ) * 1000;
-            break;
-
-        /* */
-        case ACCESS_SET_PAUSE_STATE:
-            /* Nothing to do */
-            break;
-
-        case ACCESS_GET_TITLE_INFO:
-        case ACCESS_SET_TITLE:
-        case ACCESS_SET_SEEKPOINT:
-        case ACCESS_SET_PRIVATE_ID_STATE:
-            return VLC_EGENERIC;
-
-        default:
-            msg_Warn( p_access, "unimplemented query in control" );
-            return VLC_EGENERIC;
-
-    }
-    return VLC_SUCCESS;
-}
diff --git a/modules/access/pvr/videodev2.h b/modules/access/pvr/videodev2.h
deleted file mode 100644 (file)
index a358497..0000000
+++ /dev/null
@@ -1,858 +0,0 @@
-#ifndef __LINUX_VIDEODEV2_H
-#define __LINUX_VIDEODEV2_H
-/*
- *     Video for Linux Two
- *
- *     Header file for v4l or V4L2 drivers and applications, for
- *     Linux kernels 2.2.x or 2.4.x.
- *
- *     See http://bytesex.org/v4l/ for API specs and other
- *     v4l2 documentation.
- *
- *     Author: Bill Dirks <bdirks@pacbell.net>
- *             Justin Schoeman
- *             et al.
- */
-
-/*
- *     M I S C E L L A N E O U S
- */
-
-/*  Four-character-code (FOURCC) */
-#define v4l2_fourcc(a,b,c,d)\
-        (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))
-
-/*
- *     E N U M S
- */
-enum v4l2_field {
-       V4L2_FIELD_ANY        = 0, /* driver can choose from none,
-                                     top, bottom, interlaced
-                                     depending on whatever it thinks
-                                     is approximate ... */
-       V4L2_FIELD_NONE       = 1, /* this device has no fields ... */
-       V4L2_FIELD_TOP        = 2, /* top field only */
-       V4L2_FIELD_BOTTOM     = 3, /* bottom field only */
-       V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */
-       V4L2_FIELD_SEQ_TB     = 5, /* both fields sequential into one
-                                     buffer, top-bottom order */
-       V4L2_FIELD_SEQ_BT     = 6, /* same as above + bottom-top order */
-       V4L2_FIELD_ALTERNATE  = 7, /* both fields alternating into
-                                     separate buffers */
-};
-#define V4L2_FIELD_HAS_TOP(field)      \
-       ((field) == V4L2_FIELD_TOP      ||\
-        (field) == V4L2_FIELD_INTERLACED ||\
-        (field) == V4L2_FIELD_SEQ_TB   ||\
-        (field) == V4L2_FIELD_SEQ_BT)
-#define V4L2_FIELD_HAS_BOTTOM(field)   \
-       ((field) == V4L2_FIELD_BOTTOM   ||\
-        (field) == V4L2_FIELD_INTERLACED ||\
-        (field) == V4L2_FIELD_SEQ_TB   ||\
-        (field) == V4L2_FIELD_SEQ_BT)
-#define V4L2_FIELD_HAS_BOTH(field)     \
-       ((field) == V4L2_FIELD_INTERLACED ||\
-        (field) == V4L2_FIELD_SEQ_TB   ||\
-        (field) == V4L2_FIELD_SEQ_BT)
-
-enum v4l2_buf_type {
-       V4L2_BUF_TYPE_VIDEO_CAPTURE  = 1,
-       V4L2_BUF_TYPE_VIDEO_OUTPUT   = 2,
-       V4L2_BUF_TYPE_VIDEO_OVERLAY  = 3,
-       V4L2_BUF_TYPE_VBI_CAPTURE    = 4,
-       V4L2_BUF_TYPE_VBI_OUTPUT     = 5,
-       V4L2_BUF_TYPE_PRIVATE        = 0x80,
-};
-
-enum v4l2_ctrl_type {
-       V4L2_CTRL_TYPE_INTEGER       = 1,
-       V4L2_CTRL_TYPE_BOOLEAN       = 2,
-       V4L2_CTRL_TYPE_MENU          = 3,
-       V4L2_CTRL_TYPE_BUTTON        = 4,
-};
-
-enum v4l2_tuner_type {
-       V4L2_TUNER_RADIO             = 1,
-       V4L2_TUNER_ANALOG_TV         = 2,
-};
-
-enum v4l2_memory {
-       V4L2_MEMORY_MMAP             = 1,
-       V4L2_MEMORY_USERPTR          = 2,
-       V4L2_MEMORY_OVERLAY          = 3,
-};
-
-/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
-enum v4l2_colorspace {
-       /* ITU-R 601 -- broadcast NTSC/PAL */
-       V4L2_COLORSPACE_SMPTE170M     = 1,
-
-       /* 1125-Line (US) HDTV */
-       V4L2_COLORSPACE_SMPTE240M     = 2,
-
-       /* HD and modern captures. */
-       V4L2_COLORSPACE_REC709        = 3,
-       
-       /* broken BT878 extents (601, luma range 16-253 instead of 16-235) */
-       V4L2_COLORSPACE_BT878         = 4,
-       
-       /* These should be useful.  Assume 601 extents. */
-       V4L2_COLORSPACE_470_SYSTEM_M  = 5,
-       V4L2_COLORSPACE_470_SYSTEM_BG = 6,
-       
-       /* I know there will be cameras that send this.  So, this is
-        * unspecified chromaticities and full 0-255 on each of the
-        * Y'CbCr components
-        */
-       V4L2_COLORSPACE_JPEG          = 7,
-       
-       /* For RGB colourspaces, this is probably a good start. */
-       V4L2_COLORSPACE_SRGB          = 8,
-};
-
-struct v4l2_rect {
-       __s32   left;
-       __s32   top;
-       __s32   width;
-       __s32   height;
-};
-
-struct v4l2_fract {
-       __u32   numerator;
-       __u32   denominator;
-};
-
-/*
- *     D R I V E R   C A P A B I L I T I E S
- */
-struct v4l2_capability
-{
-       __u8    driver[16];     /* i.e. "bttv" */
-       __u8    card[32];       /* i.e. "Hauppauge WinTV" */
-       __u8    bus_info[32];   /* "PCI:" + pci_dev->slot_name */
-       __u32   version;        /* should use KERNEL_VERSION() */
-       __u32   capabilities;   /* Device capabilities */
-       __u32   reserved[4];
-};
-
-/* Values for 'capabilities' field */
-#define V4L2_CAP_VIDEO_CAPTURE 0x00000001  /* Is a video capture device */
-#define V4L2_CAP_VIDEO_OUTPUT  0x00000002  /* Is a video output device */
-#define V4L2_CAP_VIDEO_OVERLAY 0x00000004  /* Can do video overlay */
-#define V4L2_CAP_VBI_CAPTURE   0x00000010  /* Is a VBI capture device */
-#define V4L2_CAP_VBI_OUTPUT    0x00000020  /* Is a VBI output device */
-#define V4L2_CAP_RDS_CAPTURE   0x00000100  /* RDS data capture */
-
-#define V4L2_CAP_TUNER         0x00010000  /* Has a tuner */
-#define V4L2_CAP_AUDIO         0x00020000  /* has audio support */
-
-#define V4L2_CAP_READWRITE      0x01000000  /* read/write systemcalls */
-#define V4L2_CAP_ASYNCIO        0x02000000  /* async I/O */
-#define V4L2_CAP_STREAMING      0x04000000  /* streaming I/O ioctls */
-
-/*
- *     V I D E O   I M A G E   F O R M A T
- */
-
-struct v4l2_pix_format
-{
-       __u32                   width;
-       __u32                   height;
-       __u32                   pixelformat;
-       enum v4l2_field         field;
-       __u32                   bytesperline;   /* for padding, zero if unused */
-       __u32                   sizeimage;
-        enum v4l2_colorspace   colorspace;
-       __u32                   priv;           /* private data, depends on pixelformat */
-};
-
-/*           Pixel format    FOURCC                  depth  Description   */
-#define V4L2_PIX_FMT_RGB332  v4l2_fourcc('R','G','B','1') /*  8  RGB-3-3-2     */
-#define V4L2_PIX_FMT_RGB555  v4l2_fourcc('R','G','B','O') /* 16  RGB-5-5-5     */
-#define V4L2_PIX_FMT_RGB565  v4l2_fourcc('R','G','B','P') /* 16  RGB-5-6-5     */
-#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16  RGB-5-5-5 BE  */
-#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R','G','B','R') /* 16  RGB-5-6-5 BE  */
-#define V4L2_PIX_FMT_BGR24   v4l2_fourcc('B','G','R','3') /* 24  BGR-8-8-8     */
-#define V4L2_PIX_FMT_RGB24   v4l2_fourcc('R','G','B','3') /* 24  RGB-8-8-8     */
-#define V4L2_PIX_FMT_BGR32   v4l2_fourcc('B','G','R','4') /* 32  BGR-8-8-8-8   */
-#define V4L2_PIX_FMT_RGB32   v4l2_fourcc('R','G','B','4') /* 32  RGB-8-8-8-8   */
-#define V4L2_PIX_FMT_GREY    v4l2_fourcc('G','R','E','Y') /*  8  Greyscale     */
-#define V4L2_PIX_FMT_YVU410  v4l2_fourcc('Y','V','U','9') /*  9  YVU 4:1:0     */
-#define V4L2_PIX_FMT_YVU420  v4l2_fourcc('Y','V','1','2') /* 12  YVU 4:2:0     */
-#define V4L2_PIX_FMT_YUYV    v4l2_fourcc('Y','U','Y','V') /* 16  YUV 4:2:2     */
-#define V4L2_PIX_FMT_UYVY    v4l2_fourcc('U','Y','V','Y') /* 16  YUV 4:2:2     */
-#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16  YVU422 planar */
-#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16  YVU411 planar */
-#define V4L2_PIX_FMT_Y41P    v4l2_fourcc('Y','4','1','P') /* 12  YUV 4:1:1     */
-
-/* two planes -- one Y, one Cr + Cb interleaved  */
-#define V4L2_PIX_FMT_NV12    v4l2_fourcc('N','V','1','2') /* 12  Y/CbCr 4:2:0  */
-#define V4L2_PIX_FMT_NV21    v4l2_fourcc('N','V','2','1') /* 12  Y/CrCb 4:2:0  */
-
-/*  The following formats are not defined in the V4L2 specification */
-#define V4L2_PIX_FMT_YUV410  v4l2_fourcc('Y','U','V','9') /*  9  YUV 4:1:0     */
-#define V4L2_PIX_FMT_YUV420  v4l2_fourcc('Y','U','1','2') /* 12  YUV 4:2:0     */
-#define V4L2_PIX_FMT_YYUV    v4l2_fourcc('Y','Y','U','V') /* 16  YUV 4:2:2     */
-#define V4L2_PIX_FMT_HI240   v4l2_fourcc('H','I','2','4') /*  8  8-bit color   */
-
-/* compressed formats */
-#define V4L2_PIX_FMT_MJPEG    v4l2_fourcc('M','J','P','G') /* Motion-JPEG   */
-#define V4L2_PIX_FMT_JPEG     v4l2_fourcc('J','P','E','G') /* JFIF JPEG     */
-#define V4L2_PIX_FMT_DV       v4l2_fourcc('d','v','s','d') /* 1394          */
-#define V4L2_PIX_FMT_MPEG     v4l2_fourcc('M','P','E','G') /* MPEG          */
-
-/*  Vendor-specific formats   */
-#define V4L2_PIX_FMT_WNVA    v4l2_fourcc('W','N','V','A') /* Winnov hw compres */
-
-/*
- *     F O R M A T   E N U M E R A T I O N
- */
-struct v4l2_fmtdesc
-{
-       __u32               index;             /* Format number      */
-       enum v4l2_buf_type  type;              /* buffer type        */
-       __u32               flags;
-       __u8                description[32];   /* Description string */
-       __u32               pixelformat;       /* Format fourcc      */
-       __u32               reserved[4];
-};
-
-#define V4L2_FMT_FLAG_COMPRESSED 0x0001
-
-
-/*
- *     T I M E C O D E
- */
-struct v4l2_timecode
-{
-       __u32   type;
-       __u32   flags;
-       __u8    frames;
-       __u8    seconds;
-       __u8    minutes;
-       __u8    hours;
-       __u8    userbits[4];
-};
-
-/*  Type  */
-#define V4L2_TC_TYPE_24FPS             1
-#define V4L2_TC_TYPE_25FPS             2
-#define V4L2_TC_TYPE_30FPS             3
-#define V4L2_TC_TYPE_50FPS             4
-#define V4L2_TC_TYPE_60FPS             5
-
-/*  Flags  */
-#define V4L2_TC_FLAG_DROPFRAME         0x0001 /* "drop-frame" mode */
-#define V4L2_TC_FLAG_COLORFRAME                0x0002
-#define V4L2_TC_USERBITS_field         0x000C
-#define V4L2_TC_USERBITS_USERDEFINED   0x0000
-#define V4L2_TC_USERBITS_8BITCHARS     0x0008
-/* The above is based on SMPTE timecodes */
-
-
-/*
- *     C O M P R E S S I O N   P A R A M E T E R S
- */
-#if 0
-/* ### generic compression settings don't work, there is too much
- * ### codec-specific stuff.  Maybe reuse that for MPEG codec settings
- * ### later ... */
-struct v4l2_compression
-{
-       __u32   quality;
-       __u32   keyframerate;
-       __u32   pframerate;
-       __u32   reserved[5];
-};
-#endif
-
-struct v4l2_jpegcompression
-{
-       int quality;
-
-       int  APPn;              /* Number of APP segment to be written,
-                                * must be 0..15 */
-       int  APP_len;           /* Length of data in JPEG APPn segment */
-       char APP_data[60];      /* Data in the JPEG APPn segment. */
-       
-       int  COM_len;           /* Length of data in JPEG COM segment */
-       char COM_data[60];      /* Data in JPEG COM segment */
-       
-       __u32 jpeg_markers;     /* Which markers should go into the JPEG
-                                * output. Unless you exactly know what
-                                * you do, leave them untouched.
-                                * Inluding less markers will make the
-                                * resulting code smaller, but there will
-                                * be fewer aplications which can read it.
-                                * The presence of the APP and COM marker
-                                * is influenced by APP_len and COM_len
-                                * ONLY, not by this property! */
-       
-#define V4L2_JPEG_MARKER_DHT (1<<3)    /* Define Huffman Tables */
-#define V4L2_JPEG_MARKER_DQT (1<<4)    /* Define Quantization Tables */
-#define V4L2_JPEG_MARKER_DRI (1<<5)    /* Define Restart Interval */
-#define V4L2_JPEG_MARKER_COM (1<<6)    /* Comment segment */
-#define V4L2_JPEG_MARKER_APP (1<<7)    /* App segment, driver will
-                                        * allways use APP0 */
-};
-
-
-/*
- *     M E M O R Y - M A P P I N G   B U F F E R S
- */
-struct v4l2_requestbuffers
-{
-       __u32                   count;
-       enum v4l2_buf_type      type;
-       enum v4l2_memory        memory;
-       __u32                   reserved[2];
-};
-
-struct v4l2_buffer
-{
-       __u32                   index;
-       enum v4l2_buf_type      type;
-       __u32                   bytesused;
-       __u32                   flags;
-       enum v4l2_field         field;
-       struct timeval          timestamp;
-       struct v4l2_timecode    timecode;
-       __u32                   sequence;
-
-       /* memory location */
-       enum v4l2_memory        memory;
-       union {
-               __u32           offset;
-               unsigned long   userptr;
-       } m;
-       __u32                   length;
-
-       __u32                   reserved[2];
-};
-
-/*  Flags for 'flags' field */
-#define V4L2_BUF_FLAG_MAPPED   0x0001  /* Buffer is mapped (flag) */
-#define V4L2_BUF_FLAG_QUEUED   0x0002  /* Buffer is queued for processing */
-#define V4L2_BUF_FLAG_DONE     0x0004  /* Buffer is ready */
-#define V4L2_BUF_FLAG_KEYFRAME 0x0008  /* Image is a keyframe (I-frame) */
-#define V4L2_BUF_FLAG_PFRAME   0x0010  /* Image is a P-frame */
-#define V4L2_BUF_FLAG_BFRAME   0x0020  /* Image is a B-frame */
-#define V4L2_BUF_FLAG_TIMECODE 0x0100  /* timecode field is valid */
-
-/*
- *     O V E R L A Y   P R E V I E W
- */
-struct v4l2_framebuffer
-{
-       __u32                   capability;
-       __u32                   flags;
-/* FIXME: in theory we should pass something like PCI device + memory
- * region + offset instead of some physical address */
-       void*                   base;
-       struct v4l2_pix_format  fmt;
-};
-/*  Flags for the 'capability' field. Read only */
-#define V4L2_FBUF_CAP_EXTERNOVERLAY    0x0001
-#define V4L2_FBUF_CAP_CHROMAKEY                0x0002
-#define V4L2_FBUF_CAP_LIST_CLIPPING     0x0004
-#define V4L2_FBUF_CAP_BITMAP_CLIPPING  0x0008
-/*  Flags for the 'flags' field. */
-#define V4L2_FBUF_FLAG_PRIMARY         0x0001
-#define V4L2_FBUF_FLAG_OVERLAY         0x0002
-#define V4L2_FBUF_FLAG_CHROMAKEY       0x0004
-
-struct v4l2_clip
-{
-       struct v4l2_rect        c;
-       struct v4l2_clip        *next;
-};
-
-struct v4l2_window
-{
-       struct v4l2_rect        w;
-       enum v4l2_field         field;
-       __u32                   chromakey;
-       struct v4l2_clip        *clips;
-       __u32                   clipcount;
-       void                    *bitmap;
-};
-
-
-/*
- *     C A P T U R E   P A R A M E T E R S
- */
-struct v4l2_captureparm
-{
-       __u32              capability;    /*  Supported modes */
-       __u32              capturemode;   /*  Current mode */
-       struct v4l2_fract  timeperframe;  /*  Time per frame in .1us units */
-       __u32              extendedmode;  /*  Driver-specific extensions */
-       __u32              readbuffers;   /*  # of buffers for read */
-       __u32              reserved[4];
-};
-/*  Flags for 'capability' and 'capturemode' fields */
-#define V4L2_MODE_HIGHQUALITY  0x0001  /*  High quality imaging mode */
-#define V4L2_CAP_TIMEPERFRAME  0x1000  /*  timeperframe field is supported */
-
-struct v4l2_outputparm
-{
-       __u32              capability;   /*  Supported modes */
-       __u32              outputmode;   /*  Current mode */
-       struct v4l2_fract  timeperframe; /*  Time per frame in seconds */
-       __u32              extendedmode; /*  Driver-specific extensions */
-       __u32              writebuffers; /*  # of buffers for write */
-       __u32              reserved[4];
-};
-
-/*
- *     I N P U T   I M A G E   C R O P P I N G
- */
-
-struct v4l2_cropcap {
-       enum v4l2_buf_type      type;   
-        struct v4l2_rect        bounds;
-        struct v4l2_rect        defrect;
-        struct v4l2_fract       pixelaspect;
-};
-
-struct v4l2_crop {
-       enum v4l2_buf_type      type;
-       struct v4l2_rect        c;
-};
-
-/*
- *      A N A L O G   V I D E O   S T A N D A R D
- */
-
-typedef __u64 v4l2_std_id;
-
-/* one bit for each */
-#define V4L2_STD_PAL_B          ((v4l2_std_id)0x00000001)
-#define V4L2_STD_PAL_B1         ((v4l2_std_id)0x00000002)
-#define V4L2_STD_PAL_G          ((v4l2_std_id)0x00000004)
-#define V4L2_STD_PAL_H          ((v4l2_std_id)0x00000008)
-#define V4L2_STD_PAL_I          ((v4l2_std_id)0x00000010)
-#define V4L2_STD_PAL_D          ((v4l2_std_id)0x00000020)
-#define V4L2_STD_PAL_D1         ((v4l2_std_id)0x00000040)
-#define V4L2_STD_PAL_K          ((v4l2_std_id)0x00000080)
-
-#define V4L2_STD_PAL_M          ((v4l2_std_id)0x00000100)
-#define V4L2_STD_PAL_N          ((v4l2_std_id)0x00000200)
-#define V4L2_STD_PAL_Nc         ((v4l2_std_id)0x00000400)
-#define V4L2_STD_PAL_60         ((v4l2_std_id)0x00000800)
-
-#define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)
-#define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)
-
-#define V4L2_STD_SECAM_B        ((v4l2_std_id)0x00010000)
-#define V4L2_STD_SECAM_D        ((v4l2_std_id)0x00020000)
-#define V4L2_STD_SECAM_G        ((v4l2_std_id)0x00040000)
-#define V4L2_STD_SECAM_H        ((v4l2_std_id)0x00080000)
-#define V4L2_STD_SECAM_K        ((v4l2_std_id)0x00100000)
-#define V4L2_STD_SECAM_K1       ((v4l2_std_id)0x00200000)
-#define V4L2_STD_SECAM_L        ((v4l2_std_id)0x00400000)
-
-/* ATSC/HDTV */
-#define V4L2_STD_ATSC_8_VSB     ((v4l2_std_id)0x01000000)
-#define V4L2_STD_ATSC_16_VSB    ((v4l2_std_id)0x02000000)
-
-/* some common needed stuff */
-#define V4L2_STD_PAL_BG                (V4L2_STD_PAL_B         |\
-                                V4L2_STD_PAL_B1        |\
-                                V4L2_STD_PAL_G)
-#define V4L2_STD_PAL_DK                (V4L2_STD_PAL_D         |\
-                                V4L2_STD_PAL_D1        |\
-                                V4L2_STD_PAL_K)
-#define V4L2_STD_PAL           (V4L2_STD_PAL_BG        |\
-                                V4L2_STD_PAL_DK        |\
-                                V4L2_STD_PAL_H         |\
-                                V4L2_STD_PAL_I)
-#define V4L2_STD_NTSC           (V4L2_STD_NTSC_M       |\
-                                V4L2_STD_NTSC_M_JP)
-#define V4L2_STD_SECAM         (V4L2_STD_SECAM_B       |\
-                                V4L2_STD_SECAM_D       |\
-                                V4L2_STD_SECAM_G       |\
-                                V4L2_STD_SECAM_H       |\
-                                V4L2_STD_SECAM_K       |\
-                                V4L2_STD_SECAM_K1      |\
-                                V4L2_STD_SECAM_L)
-
-#define V4L2_STD_525_60                (V4L2_STD_PAL_M         |\
-                                V4L2_STD_PAL_60        |\
-                                V4L2_STD_NTSC)
-#define V4L2_STD_625_50                (V4L2_STD_PAL           |\
-                                V4L2_STD_PAL_N         |\
-                                V4L2_STD_PAL_Nc        |\
-                                V4L2_STD_SECAM)
-
-#define V4L2_STD_UNKNOWN        0
-#define V4L2_STD_ALL            (V4L2_STD_525_60       |\
-                                V4L2_STD_625_50)
-
-struct v4l2_standard
-{
-       __u32                index;
-       v4l2_std_id          id;
-       __u8                 name[24];
-       struct v4l2_fract    frameperiod; /* Frames, not fields */
-       __u32                framelines;
-       __u32                reserved[4];
-};
-
-
-/*
- *     V I D E O   I N P U T S
- */
-struct v4l2_input
-{
-       __u32        index;             /*  Which input */
-       __u8         name[32];          /*  Label */
-       __u32        type;              /*  Type of input */
-       __u32        audioset;          /*  Associated audios (bitfield) */
-       __u32        tuner;             /*  Associated tuner */
-       v4l2_std_id  std;
-       __u32        status;
-       __u32        reserved[4];
-};
-/*  Values for the 'type' field */
-#define V4L2_INPUT_TYPE_TUNER          1
-#define V4L2_INPUT_TYPE_CAMERA         2
-
-/* field 'status' - general */
-#define V4L2_IN_ST_NO_POWER    0x00000001  /* Attached device is off */
-#define V4L2_IN_ST_NO_SIGNAL   0x00000002
-#define V4L2_IN_ST_NO_COLOR    0x00000004
-
-/* field 'status' - analog */
-#define V4L2_IN_ST_NO_H_LOCK   0x00000100  /* No horizontal sync lock */
-#define V4L2_IN_ST_COLOR_KILL  0x00000200  /* Color killer is active */
-
-/* field 'status' - digital */
-#define V4L2_IN_ST_NO_SYNC     0x00010000  /* No synchronization lock */
-#define V4L2_IN_ST_NO_EQU      0x00020000  /* No equalizer lock */
-#define V4L2_IN_ST_NO_CARRIER  0x00040000  /* Carrier recovery failed */
-
-/* field 'status' - VCR and set-top box */
-#define V4L2_IN_ST_MACROVISION 0x01000000  /* Macrovision detected */
-#define V4L2_IN_ST_NO_ACCESS   0x02000000  /* Conditional access denied */
-#define V4L2_IN_ST_VTR         0x04000000  /* VTR time constant */
-
-/*
- *     V I D E O   O U T P U T S
- */
-struct v4l2_output
-{
-       __u32        index;             /*  Which output */
-       __u8         name[32];          /*  Label */
-       __u32        type;              /*  Type of output */
-       __u32        audioset;          /*  Associated audios (bitfield) */
-       __u32        modulator;         /*  Associated modulator */
-       v4l2_std_id  std;
-       __u32        reserved[4];
-};
-/*  Values for the 'type' field */
-#define V4L2_OUTPUT_TYPE_MODULATOR             1
-#define V4L2_OUTPUT_TYPE_ANALOG                        2
-#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY      3
-
-/*
- *     C O N T R O L S
- */
-struct v4l2_control
-{
-       __u32                id;
-       __s32                value;
-};
-
-/*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
-struct v4l2_queryctrl
-{
-       __u32                id;
-       enum v4l2_ctrl_type  type;
-       __u8                 name[32];  /* Whatever */
-       __s32                minimum;   /* Note signedness */
-       __s32                maximum;
-       __s32                step;
-       __s32                default_value;
-       __u32                flags;
-       __u32                reserved[2];
-};
-
-/*  Used in the VIDIOC_QUERYMENU ioctl for querying menu items */
-struct v4l2_querymenu
-{
-       __u32           id;
-       __u32           index;
-       __u8            name[32];       /* Whatever */
-       __u32           reserved;
-};
-
-/*  Control flags  */
-#define V4L2_CTRL_FLAG_DISABLED                0x0001
-#define V4L2_CTRL_FLAG_GRABBED         0x0002
-
-/*  Control IDs defined by V4L2 */
-#define V4L2_CID_BASE                  0x00980900
-/*  IDs reserved for driver specific controls */
-#define V4L2_CID_PRIVATE_BASE          0x08000000
-
-#define V4L2_CID_BRIGHTNESS            (V4L2_CID_BASE+0)
-#define V4L2_CID_CONTRAST              (V4L2_CID_BASE+1)
-#define V4L2_CID_SATURATION            (V4L2_CID_BASE+2)
-#define V4L2_CID_HUE                   (V4L2_CID_BASE+3)
-#define V4L2_CID_AUDIO_VOLUME          (V4L2_CID_BASE+5)
-#define V4L2_CID_AUDIO_BALANCE         (V4L2_CID_BASE+6)
-#define V4L2_CID_AUDIO_BASS            (V4L2_CID_BASE+7)
-#define V4L2_CID_AUDIO_TREBLE          (V4L2_CID_BASE+8)
-#define V4L2_CID_AUDIO_MUTE            (V4L2_CID_BASE+9)
-#define V4L2_CID_AUDIO_LOUDNESS                (V4L2_CID_BASE+10)
-#define V4L2_CID_BLACK_LEVEL           (V4L2_CID_BASE+11)
-#define V4L2_CID_AUTO_WHITE_BALANCE    (V4L2_CID_BASE+12)
-#define V4L2_CID_DO_WHITE_BALANCE      (V4L2_CID_BASE+13)
-#define V4L2_CID_RED_BALANCE           (V4L2_CID_BASE+14)
-#define V4L2_CID_BLUE_BALANCE          (V4L2_CID_BASE+15)
-#define V4L2_CID_GAMMA                 (V4L2_CID_BASE+16)
-#define V4L2_CID_WHITENESS             (V4L2_CID_GAMMA) /* ? Not sure */
-#define V4L2_CID_EXPOSURE              (V4L2_CID_BASE+17)
-#define V4L2_CID_AUTOGAIN              (V4L2_CID_BASE+18)
-#define V4L2_CID_GAIN                  (V4L2_CID_BASE+19)
-#define V4L2_CID_HFLIP                 (V4L2_CID_BASE+20)
-#define V4L2_CID_VFLIP                 (V4L2_CID_BASE+21)
-#define V4L2_CID_HCENTER               (V4L2_CID_BASE+22)
-#define V4L2_CID_VCENTER               (V4L2_CID_BASE+23)
-#define V4L2_CID_LASTP1                        (V4L2_CID_BASE+24) /* last CID + 1 */
-
-/*
- *     T U N I N G
- */
-struct v4l2_tuner
-{
-       __u32                   index;
-       __u8                    name[32];
-       enum v4l2_tuner_type    type;
-       __u32                   capability;
-       __u32                   rangelow;
-       __u32                   rangehigh;
-       __u32                   rxsubchans;
-       __u32                   audmode;
-       __s32                   signal;
-       __s32                   afc;
-       __u32                   reserved[4];
-};
-
-struct v4l2_modulator
-{
-       __u32                   index;
-       __u8                    name[32];
-       __u32                   capability;
-       __u32                   rangelow;
-       __u32                   rangehigh;
-       __u32                   txsubchans;
-       __u32                   reserved[4];
-};
-
-/*  Flags for the 'capability' field */
-#define V4L2_TUNER_CAP_LOW             0x0001
-#define V4L2_TUNER_CAP_NORM            0x0002
-#define V4L2_TUNER_CAP_STEREO          0x0010
-#define V4L2_TUNER_CAP_LANG2           0x0020
-#define V4L2_TUNER_CAP_SAP             0x0020
-#define V4L2_TUNER_CAP_LANG1           0x0040
-
-/*  Flags for the 'rxsubchans' field */
-#define V4L2_TUNER_SUB_MONO            0x0001
-#define V4L2_TUNER_SUB_STEREO          0x0002
-#define V4L2_TUNER_SUB_LANG2           0x0004
-#define V4L2_TUNER_SUB_SAP             0x0004
-#define V4L2_TUNER_SUB_LANG1           0x0008
-
-/*  Values for the 'audmode' field */
-#define V4L2_TUNER_MODE_MONO           0x0000
-#define V4L2_TUNER_MODE_STEREO         0x0001
-#define V4L2_TUNER_MODE_LANG2          0x0002
-#define V4L2_TUNER_MODE_SAP            0x0002
-#define V4L2_TUNER_MODE_LANG1          0x0003
-
-struct v4l2_frequency
-{
-       __u32                 tuner;
-       enum v4l2_tuner_type  type;
-        __u32                frequency;
-       __u32                 reserved[8];
-};
-
-/*
- *     A U D I O
- */
-struct v4l2_audio
-{
-       __u32   index;
-       __u8    name[32];
-       __u32   capability;
-       __u32   mode;
-       __u32   reserved[2];
-};
-/*  Flags for the 'capability' field */
-#define V4L2_AUDCAP_STEREO             0x00001
-#define V4L2_AUDCAP_AVL                        0x00002
-
-/*  Flags for the 'mode' field */
-#define V4L2_AUDMODE_AVL               0x00001
-
-struct v4l2_audioout
-{
-       __u32   index;
-       __u8    name[32];
-       __u32   capability;
-       __u32   mode;
-       __u32   reserved[2];
-};
-
-/*
- *     D A T A   S E R V I C E S   ( V B I )
- *
- *     Data services API by Michael Schimek
- */
-
-struct v4l2_vbi_format
-{
-       __u32   sampling_rate;          /* in 1 Hz */
-       __u32   offset;
-       __u32   samples_per_line;
-       __u32   sample_format;          /* V4L2_PIX_FMT_* */
-       __s32   start[2];
-       __u32   count[2];
-       __u32   flags;                  /* V4L2_VBI_* */
-       __u32   reserved[2];            /* must be zero */
-};
-
-/*  VBI flags  */
-#define V4L2_VBI_UNSYNC                (1<< 0)
-#define V4L2_VBI_INTERLACED    (1<< 1)
-
-
-/*
- *     A G G R E G A T E   S T R U C T U R E S
- */
-
-/*     Stream data format
- */
-struct v4l2_format
-{
-       enum v4l2_buf_type type;
-       union
-       {
-               struct v4l2_pix_format  pix;  // V4L2_BUF_TYPE_VIDEO_CAPTURE
-               struct v4l2_window      win;  // V4L2_BUF_TYPE_VIDEO_OVERLAY
-               struct v4l2_vbi_format  vbi;  // V4L2_BUF_TYPE_VBI_CAPTURE
-               __u8    raw_data[200];        // user-defined
-       } fmt;
-};
-
-
-/*     Stream type-dependent parameters
- */
-struct v4l2_streamparm
-{
-       enum v4l2_buf_type type;
-       union
-       {
-               struct v4l2_captureparm capture;
-               struct v4l2_outputparm  output;
-               __u8    raw_data[200];  /* user-defined */
-       } parm;
-};
-
-
-
-/*
- *     I O C T L   C O D E S   F O R   V I D E O   D E V I C E S
- *
- */
-#define VIDIOC_QUERYCAP                _IOR  ('V',  0, struct v4l2_capability)
-#define VIDIOC_RESERVED                _IO   ('V',  1)
-#define VIDIOC_ENUM_FMT         _IOWR ('V',  2, struct v4l2_fmtdesc)
-#define VIDIOC_G_FMT           _IOWR ('V',  4, struct v4l2_format)
-#define VIDIOC_S_FMT           _IOWR ('V',  5, struct v4l2_format)
-#if 0
-#define VIDIOC_G_COMP          _IOR  ('V',  6, struct v4l2_compression)
-#define VIDIOC_S_COMP          _IOW  ('V',  7, struct v4l2_compression)
-#endif
-#define VIDIOC_REQBUFS         _IOWR ('V',  8, struct v4l2_requestbuffers)
-#define VIDIOC_QUERYBUF                _IOWR ('V',  9, struct v4l2_buffer)
-#define VIDIOC_G_FBUF          _IOR  ('V', 10, struct v4l2_framebuffer)
-#define VIDIOC_S_FBUF          _IOW  ('V', 11, struct v4l2_framebuffer)
-#define VIDIOC_OVERLAY         _IOWR ('V', 14, int)
-#define VIDIOC_QBUF            _IOWR ('V', 15, struct v4l2_buffer)
-#define VIDIOC_DQBUF           _IOWR ('V', 17, struct v4l2_buffer)
-#define VIDIOC_STREAMON                _IOW  ('V', 18, int)
-#define VIDIOC_STREAMOFF       _IOW  ('V', 19, int)
-#define VIDIOC_G_PARM          _IOWR ('V', 21, struct v4l2_streamparm)
-#define VIDIOC_S_PARM          _IOW  ('V', 22, struct v4l2_streamparm)
-#define VIDIOC_G_STD           _IOR  ('V', 23, v4l2_std_id)
-#define VIDIOC_S_STD           _IOW  ('V', 24, v4l2_std_id)
-#define VIDIOC_ENUMSTD         _IOWR ('V', 25, struct v4l2_standard)
-#define VIDIOC_ENUMINPUT       _IOWR ('V', 26, struct v4l2_input)
-#define VIDIOC_G_CTRL          _IOWR ('V', 27, struct v4l2_control)
-#define VIDIOC_S_CTRL          _IOW  ('V', 28, struct v4l2_control)
-#define VIDIOC_G_TUNER         _IOWR ('V', 29, struct v4l2_tuner)
-#define VIDIOC_S_TUNER         _IOW  ('V', 30, struct v4l2_tuner)
-#define VIDIOC_G_AUDIO         _IOWR ('V', 33, struct v4l2_audio)
-#define VIDIOC_S_AUDIO         _IOW  ('V', 34, struct v4l2_audio)
-#define VIDIOC_QUERYCTRL       _IOWR ('V', 36, struct v4l2_queryctrl)
-#define VIDIOC_QUERYMENU       _IOWR ('V', 37, struct v4l2_querymenu)
-#define VIDIOC_G_INPUT         _IOR  ('V', 38, int)
-#define VIDIOC_S_INPUT         _IOWR ('V', 39, int)
-#define VIDIOC_G_OUTPUT                _IOR  ('V', 46, int)
-#define VIDIOC_S_OUTPUT                _IOWR ('V', 47, int)
-#define VIDIOC_ENUMOUTPUT      _IOWR ('V', 48, struct v4l2_output)
-#define VIDIOC_G_AUDOUT                _IOWR ('V', 49, struct v4l2_audioout)
-#define VIDIOC_S_AUDOUT                _IOW  ('V', 50, struct v4l2_audioout)
-#define VIDIOC_G_MODULATOR     _IOWR ('V', 54, struct v4l2_modulator)
-#define VIDIOC_S_MODULATOR     _IOW  ('V', 55, struct v4l2_modulator)
-#define VIDIOC_G_FREQUENCY     _IOWR ('V', 56, struct v4l2_frequency)
-#define VIDIOC_S_FREQUENCY     _IOW  ('V', 57, struct v4l2_frequency)
-#define VIDIOC_CROPCAP         _IOR  ('V', 58, struct v4l2_cropcap)
-#define VIDIOC_G_CROP          _IOWR ('V', 59, struct v4l2_crop)
-#define VIDIOC_S_CROP          _IOW  ('V', 60, struct v4l2_crop)
-#define VIDIOC_G_JPEGCOMP      _IOR  ('V', 61, struct v4l2_jpegcompression)
-#define VIDIOC_S_JPEGCOMP      _IOW  ('V', 62, struct v4l2_jpegcompression)
-#define VIDIOC_QUERYSTD        _IOR  ('V', 63, v4l2_std_id)
-#define VIDIOC_TRY_FMT         _IOWR ('V', 64, struct v4l2_format)
-
-#define BASE_VIDIOC_PRIVATE    192             /* 192-255 are private */
-
-
-#ifdef __KERNEL__
-/*
- *
- *     V 4 L 2   D R I V E R   H E L P E R   A P I
- *
- *     Some commonly needed functions for drivers (v4l2-common.o module)
- */
-#include <linux/fs.h>
-
-/*  Video standard functions  */
-extern unsigned int v4l2_video_std_fps(struct v4l2_standard *vs);
-extern int v4l2_video_std_construct(struct v4l2_standard *vs,
-                                   int id, char *name);
-
-/*  Compatibility layer interface  */
-typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
-                          unsigned int cmd, void *arg);
-int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
-                              int cmd, void *arg, v4l2_kioctl driver_ioctl);
-
-/* names for fancy debug output */
-extern char *v4l2_field_names[];
-extern char *v4l2_type_names[];
-extern char *v4l2_ioctl_names[];
-
-#endif /* __KERNEL__ */
-#endif /* __LINUX_VIDEODEV2_H */
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
diff --git a/modules/access/v4l.c b/modules/access/v4l.c
new file mode 100644 (file)
index 0000000..6ea1bc4
--- /dev/null
@@ -0,0 +1,1595 @@
+/*****************************************************************************
+ * v4l.c : Video4Linux input module for vlc
+ *****************************************************************************
+ * Copyright (C) 2002-2004 the VideoLAN team
+ * $Id$
+ *
+ * Author: Laurent Aimar <fenrir@via.ecp.fr>
+ *         Paul Forgey <paulf at aphrodite dot com>
+ *         Gildas Bazin <gbazin@videolan.org>
+ *         Benjamin Pracht <bigben at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <vlc/vlc.h>
+#include <vlc/input.h>
+#include <vlc/vout.h>
+#include <codecs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <fcntl.h>
+
+/* From GStreamer's v4l plugin:
+ * Because of some really cool feature in video4linux1, also known as
+ * 'not including sys/types.h and sys/time.h', we had to include it
+ * ourselves. In all their intelligence, these people decided to fix
+ * this in the next version (video4linux2) in such a cool way that it
+ * breaks all compilations of old stuff...
+ * The real problem is actually that linux/time.h doesn't use proper
+ * macro checks before defining types like struct timeval. The proper
+ * fix here is to either fuck the kernel header (which is what we do
+ * by defining _LINUX_TIME_H, an innocent little hack) or by fixing it
+ * upstream, which I'll consider doing later on. If you get compiler
+ * errors here, check your linux/time.h && sys/time.h header setup.
+*/
+#define _LINUX_TIME_H
+
+#include <linux/videodev.h>
+#include "videodev_mjpeg.h"
+
+#include <sys/soundcard.h>
+
+/*****************************************************************************
+ * Module descriptior
+ *****************************************************************************/
+static int  Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
+#define CACHING_TEXT N_("Caching value in ms")
+#define CACHING_LONGTEXT N_( \
+    "Caching value for V4L captures. This " \
+    "value should be set in milliseconds." )
+#define VDEV_TEXT N_("Video device name")
+#define VDEV_LONGTEXT N_( \
+    "Name of the video device to use. " \
+    "If you don't specify anything, no video device will be used.")
+#define ADEV_TEXT N_("Audio device name")
+#define ADEV_LONGTEXT N_( \
+    "Name of the audio device to use. " \
+    "If you don't specify anything, no audio device will be used.")
+#define CHROMA_TEXT N_("Video input chroma format")
+#define CHROMA_LONGTEXT N_( \
+    "Force the Video4Linux video device to use a specific chroma format " \
+    "(eg. I420 (default), RV24, etc.)")
+#define FREQUENCY_TEXT N_( "Frequency" )
+#define FREQUENCY_LONGTEXT N_( \
+    "Frequency to capture (in kHz), if applicable." )
+#define CHANNEL_TEXT N_( "Channel" )
+#define CHANNEL_LONGTEXT N_( \
+    "Channel of the card to use (Usually, 0 = tuner, " \
+    "1 = composite, 2 = svideo)." )
+#define NORM_TEXT N_( "Norm" )
+#define NORM_LONGTEXT N_( \
+    "Norm of the stream (Automatic, SECAM, PAL, or NTSC)." )
+#define AUDIO_TEXT N_( "Audio Channel" )
+#define AUDIO_LONGTEXT N_( \
+    "Audio Channel to use, if there are several audio inputs." )
+#define WIDTH_TEXT N_( "Width" )
+#define WIDTH_LONGTEXT N_( "Width of the stream to capture " \
+    "(-1 for autodetect)." )
+#define HEIGHT_TEXT N_( "Height" )
+#define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \
+    "(-1 for autodetect)." )
+#define BRIGHTNESS_TEXT N_( "Brightness" )
+#define BRIGHTNESS_LONGTEXT N_( \
+    "Brightness of the video input." )
+#define HUE_TEXT N_( "Hue" )
+#define HUE_LONGTEXT N_( \
+    "Hue of the video input." )
+#define COLOUR_TEXT N_( "Color" )
+#define COLOUR_LONGTEXT N_( \
+    "Color of the video input." )
+#define CONTRAST_TEXT N_( "Contrast" )
+#define CONTRAST_LONGTEXT N_( \
+    "Contrast of the video input." )
+#define TUNER_TEXT N_( "Tuner" )
+#define TUNER_LONGTEXT N_( "Tuner to use, if there are several ones." )
+#define SAMPLERATE_TEXT N_( "Samplerate" )
+#define SAMPLERATE_LONGTEXT N_( \
+    "Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100)" )
+#define STEREO_TEXT N_( "Stereo" )
+#define STEREO_LONGTEXT N_( \
+    "Capture the audio stream in stereo." )
+#define MJPEG_TEXT N_( "MJPEG" )
+#define MJPEG_LONGTEXT N_(  \
+    "Set this option if the capture device outputs MJPEG" )
+#define DECIMATION_TEXT N_( "Decimation" )
+#define DECIMATION_LONGTEXT N_( \
+    "Decimation level for MJPEG streams" )
+#define QUALITY_TEXT N_( "Quality" )
+#define QUALITY_LONGTEXT N_( "Quality of the stream." )
+#define FPS_TEXT N_( "Framerate" )
+#define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \
+    "(-1 for autodetect)." )
+
+static int i_norm_list[] =
+    { VIDEO_MODE_AUTO, VIDEO_MODE_SECAM, VIDEO_MODE_PAL, VIDEO_MODE_NTSC };
+static char *psz_norm_list_text[] =
+    { N_("Automatic"), N_("SECAM"), N_("PAL"),  N_("NTSC") };
+
+vlc_module_begin();
+    set_shortname( _("Video4Linux") );
+    set_description( _("Video4Linux input") );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_ACCESS );
+
+    add_integer( "v4l-caching", DEFAULT_PTS_DELAY / 1000, NULL,
+                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
+    add_string( "v4l-vdev", "/dev/video", 0, VDEV_TEXT, VDEV_LONGTEXT,
+                VLC_FALSE );
+    add_string( "v4l-adev", "/dev/dsp", 0, ADEV_TEXT, ADEV_LONGTEXT,
+                VLC_FALSE );
+    add_string( "v4l-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
+                VLC_TRUE );
+    add_float( "v4l-fps", -1.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
+    add_integer( "v4l-samplerate", 44100, NULL, SAMPLERATE_TEXT,
+                SAMPLERATE_LONGTEXT, VLC_TRUE );
+    add_integer( "v4l-channel", 0, NULL, CHANNEL_TEXT, CHANNEL_LONGTEXT,
+                VLC_TRUE );
+    add_integer( "v4l-tuner", -1, NULL, TUNER_TEXT, TUNER_LONGTEXT, VLC_TRUE );
+    add_integer( "v4l-norm", VIDEO_MODE_AUTO, NULL, NORM_TEXT, NORM_LONGTEXT,
+                VLC_FALSE );
+        change_integer_list( i_norm_list, psz_norm_list_text, 0 );
+    add_integer( "v4l-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
+                VLC_FALSE );
+    add_integer( "v4l-audio", -1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT, VLC_TRUE );
+    add_bool( "v4l-stereo", VLC_TRUE, NULL, STEREO_TEXT, STEREO_LONGTEXT,
+            VLC_TRUE );
+    add_integer( "v4l-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_TRUE );
+    add_integer( "v4l-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
+                VLC_TRUE );
+    add_integer( "v4l-brightness", -1, NULL, BRIGHTNESS_TEXT,
+                BRIGHTNESS_LONGTEXT, VLC_TRUE );
+    add_integer( "v4l-colour", -1, NULL, COLOUR_TEXT, COLOUR_LONGTEXT,
+                VLC_TRUE );
+    add_integer( "v4l-hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, VLC_TRUE );
+    add_integer( "v4l-contrast", -1, NULL, CONTRAST_TEXT, CONTRAST_LONGTEXT,
+                VLC_TRUE );
+    add_bool( "v4l-mjpeg", VLC_FALSE, NULL, MJPEG_TEXT, MJPEG_LONGTEXT,
+            VLC_TRUE );
+    add_integer( "v4l-decimation", 1, NULL, DECIMATION_TEXT,
+            DECIMATION_LONGTEXT, VLC_TRUE );
+    add_integer( "v4l-quality", 100, NULL, QUALITY_TEXT, QUALITY_LONGTEXT,
+            VLC_TRUE );
+
+    add_shortcut( "v4l" );
+    set_capability( "access_demux", 10 );
+    set_callbacks( Open, Close );
+vlc_module_end();
+
+/*****************************************************************************
+ * Access: local prototypes
+ *****************************************************************************/
+static int Demux  ( demux_t * );
+static int Control( demux_t *, int, va_list );
+
+static void ParseMRL    ( demux_t * );
+static int  OpenVideoDev( demux_t *, char * );
+static int  OpenAudioDev( demux_t *, char * );
+
+static block_t *GrabAudio( demux_t * );
+static block_t *GrabVideo( demux_t * );
+
+#define MJPEG_BUFFER_SIZE (256*1024)
+
+struct quicktime_mjpeg_app1
+{
+    uint32_t    i_reserved;             /* set to 0 */
+    uint32_t    i_tag;                  /* 'mjpg' */
+    uint32_t    i_field_size;           /* offset following EOI */
+    uint32_t    i_padded_field_size;    /* offset following EOI+pad */
+    uint32_t    i_next_field;           /* offset to next field */
+    uint32_t    i_DQT_offset;
+    uint32_t    i_DHT_offset;
+    uint32_t    i_SOF_offset;
+    uint32_t    i_SOS_offset;
+    uint32_t    i_data_offset;          /* following SOS marker data */
+};
+
+static struct
+{
+    int i_v4l;
+    int i_fourcc;
+
+} v4lchroma_to_fourcc[] =
+{
+    { VIDEO_PALETTE_GREY, VLC_FOURCC( 'G', 'R', 'E', 'Y' ) },
+    { VIDEO_PALETTE_HI240, VLC_FOURCC( 'I', '2', '4', '0' ) },
+    { VIDEO_PALETTE_RGB565, VLC_FOURCC( 'R', 'V', '1', '6' ) },
+    { VIDEO_PALETTE_RGB555, VLC_FOURCC( 'R', 'V', '1', '5' ) },
+    { VIDEO_PALETTE_RGB24, VLC_FOURCC( 'R', 'V', '2', '4' ) },
+    { VIDEO_PALETTE_RGB32, VLC_FOURCC( 'R', 'V', '3', '2' ) },
+    { VIDEO_PALETTE_YUV422, VLC_FOURCC( 'I', '4', '2', '2' ) },
+    { VIDEO_PALETTE_YUYV, VLC_FOURCC( 'Y', 'U', 'Y', 'V' ) },
+    { VIDEO_PALETTE_UYVY, VLC_FOURCC( 'U', 'Y', 'V', 'Y' ) },
+    { VIDEO_PALETTE_YUV420, VLC_FOURCC( 'I', '4', '2', 'N' ) },
+    { VIDEO_PALETTE_YUV411, VLC_FOURCC( 'I', '4', '1', 'N' ) },
+    { VIDEO_PALETTE_RAW, VLC_FOURCC( 'G', 'R', 'A', 'W' ) },
+    { VIDEO_PALETTE_YUV422P, VLC_FOURCC( 'I', '4', '2', '2' ) },
+    { VIDEO_PALETTE_YUV420P, VLC_FOURCC( 'I', '4', '2', '0' ) },
+    { VIDEO_PALETTE_YUV411P, VLC_FOURCC( 'I', '4', '1', '1' ) },
+    { 0, 0 }
+};
+
+struct demux_sys_t
+{
+    /* Devices */
+    char *psz_device;         /* Main device from MRL, can be video or audio */
+
+    char *psz_vdev;
+    int  fd_video;
+
+    char *psz_adev;
+    int  fd_audio;
+
+    /* Video properties */
+    picture_t pic;
+
+    int i_fourcc;
+    int i_channel;
+    int i_audio;
+    int i_norm;
+    int i_tuner;
+    int i_frequency;
+    int i_width;
+    int i_height;
+
+    int i_brightness;
+    int i_hue;
+    int i_colour;
+    int i_contrast;
+
+    float f_fps;            /* <= 0.0 mean to grab at full rate */
+    mtime_t i_video_pts;    /* only used when f_fps > 0 */
+
+    vlc_bool_t b_mjpeg;
+    int i_decimation;
+    int i_quality;
+
+    struct video_capability vid_cap;
+    struct video_mbuf       vid_mbuf;
+    struct mjpeg_requestbuffers mjpeg_buffers;
+
+    uint8_t *p_video_mmap;
+    int     i_frame_pos;
+
+    struct video_mmap   vid_mmap;
+    struct video_picture vid_picture;
+
+    int          i_video_frame_size;
+    es_out_id_t  *p_es_video;
+
+    /* Audio properties */
+    vlc_fourcc_t i_acodec_raw;
+    int          i_sample_rate;
+    vlc_bool_t   b_stereo;
+    int          i_audio_max_frame_size;
+    block_t      *p_block_audio;
+    es_out_id_t  *p_es_audio;
+};
+
+/*****************************************************************************
+ * Open: opens v4l device
+ *****************************************************************************
+ *
+ * url: <video device>::::
+ *
+ *****************************************************************************/
+static int Open( vlc_object_t *p_this )
+{
+    demux_t     *p_demux = (demux_t*)p_this;
+    demux_sys_t *p_sys;
+    vlc_value_t val;
+
+    /* Only when selected */
+    if( *p_demux->psz_access == '\0' )
+        return VLC_EGENERIC;
+
+    /* 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;
+    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+    memset( p_sys, 0, sizeof( demux_sys_t ) );
+
+    var_Create( p_demux, "v4l-audio", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-audio", &val );
+    p_sys->i_audio          = val.i_int;
+
+    var_Create( p_demux, "v4l-channel", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-channel", &val );
+    p_sys->i_channel        = val.i_int;
+
+    var_Create( p_demux, "v4l-norm", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-norm", &val );
+    p_sys->i_norm           = val.i_int;
+
+    var_Create( p_demux, "v4l-tuner", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-tuner", &val );
+    p_sys->i_tuner          = val.i_int;
+
+    var_Create( p_demux, "v4l-frequency",
+                                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-frequency", &val );
+    p_sys->i_frequency      = val.i_int;
+
+    var_Create( p_demux, "v4l-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-fps", &val );
+    p_sys->f_fps            = val.f_float;
+
+    var_Create( p_demux, "v4l-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-width", &val );
+    p_sys->i_width          = val.i_int;
+
+    var_Create( p_demux, "v4l-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-height", &val );
+    p_sys->i_height         = val.i_int;
+
+    p_sys->i_video_pts      = -1;
+
+    var_Create( p_demux, "v4l-brightness", VLC_VAR_INTEGER |
+                                                        VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-brightness", &val );
+    p_sys->i_brightness     = val.i_int;
+
+    var_Create( p_demux, "v4l-hue", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-hue", &val );
+    p_sys->i_hue            = -1;
+
+    var_Create( p_demux, "v4l-colour", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-colour", &val );
+    p_sys->i_colour         = val.i_int;
+
+    var_Create( p_demux, "v4l-contrast", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-contrast", &val );
+    p_sys->i_contrast       = val.i_int;
+
+    var_Create( p_demux, "v4l-mjpeg", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-mjpeg", &val );
+    p_sys->b_mjpeg     = val.b_bool;
+
+    var_Create( p_demux, "v4l-decimation", VLC_VAR_INTEGER |
+                                                            VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-decimation", &val );
+    p_sys->i_decimation = val.i_int;
+
+    var_Create( p_demux, "v4l-quality", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-quality", &val );
+    p_sys->i_quality = val.i_int;
+
+    var_Create( p_demux, "v4l-samplerate",
+                                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-samplerate", &val );
+    p_sys->i_sample_rate  = val.i_int;
+
+    var_Create( p_demux, "v4l-stereo", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "v4l-stereo", &val );
+    p_sys->b_stereo       = val.b_bool;
+
+    p_sys->psz_device = p_sys->psz_vdev = p_sys->psz_adev = NULL;
+    p_sys->fd_video = -1;
+    p_sys->fd_audio = -1;
+
+    p_sys->p_es_video = p_sys->p_es_audio = 0;
+    p_sys->p_block_audio = 0;
+
+    ParseMRL( p_demux );
+
+    /* Find main device (video or audio) */
+    if( p_sys->psz_device && *p_sys->psz_device )
+    {
+        msg_Dbg( p_demux, "main device=`%s'", p_sys->psz_device );
+
+        /* Try to open as video device */
+        p_sys->fd_video = OpenVideoDev( p_demux, p_sys->psz_device );
+
+        if( p_sys->fd_video < 0 )
+        {
+            /* Try to open as audio device */
+            p_sys->fd_audio = OpenAudioDev( p_demux, p_sys->psz_device );
+            if( p_sys->fd_audio >= 0 )
+            {
+                if( p_sys->psz_adev ) free( p_sys->psz_adev );
+                p_sys->psz_adev = p_sys->psz_device;
+                p_sys->psz_device = NULL;
+            }
+        }
+        else
+        {
+            if( p_sys->psz_vdev ) free( p_sys->psz_vdev );
+            p_sys->psz_vdev = p_sys->psz_device;
+            p_sys->psz_device = NULL;
+        }
+    }
+
+    /* If no device opened, only continue if the access was forced */
+    if( p_sys->fd_video < 0 && p_sys->fd_audio < 0 )
+    {
+        if( strcmp( p_demux->psz_access, "v4l" ) )
+        {
+            Close( p_this );
+            return VLC_EGENERIC;
+        }
+    }
+
+    /* Find video device */
+    if( p_sys->fd_video < 0 )
+    {
+        if( !p_sys->psz_vdev || !*p_sys->psz_vdev )
+        {
+            if( p_sys->psz_vdev ) free( p_sys->psz_vdev );
+            p_sys->psz_vdev = var_CreateGetString( p_demux, "v4l-vdev" );;
+        }
+
+        if( p_sys->psz_vdev && *p_sys->psz_vdev )
+        {
+            p_sys->fd_video = OpenVideoDev( p_demux, p_sys->psz_vdev );
+        }
+    }
+
+    /* Find audio device */
+    if( p_sys->fd_audio < 0 )
+    {
+        if( !p_sys->psz_adev || !*p_sys->psz_adev )
+        {
+            if( p_sys->psz_adev ) free( p_sys->psz_adev );
+            p_sys->psz_adev = var_CreateGetString( p_demux, "v4l-adev" );;
+        }
+
+        if( p_sys->psz_adev && *p_sys->psz_adev )
+        {
+            p_sys->fd_audio = OpenAudioDev( p_demux, p_sys->psz_adev );
+        }
+    }
+
+    if( p_sys->fd_video < 0 && p_sys->fd_audio < 0 )
+    {
+        Close( p_this );
+        return VLC_EGENERIC;
+    }
+
+    msg_Dbg( p_demux, "v4l grabbing started" );
+
+    /* Declare elementary streams */
+    if( p_sys->fd_video >= 0 )
+    {
+        es_format_t fmt;
+        es_format_Init( &fmt, VIDEO_ES, p_sys->i_fourcc );
+        fmt.video.i_width  = p_sys->i_width;
+        fmt.video.i_height = p_sys->i_height;
+        fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
+
+        /* Setup rgb mask for RGB formats */
+        if( p_sys->i_fourcc == VLC_FOURCC('R','V','2','4') )
+        {
+            /* This is in BGR format */
+            fmt.video.i_bmask = 0x00ff0000;
+            fmt.video.i_gmask = 0x0000ff00;
+            fmt.video.i_rmask = 0x000000ff;
+        }
+
+        msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
+                 (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
+        p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
+    }
+
+    if( p_sys->fd_audio >= 0 )
+    {
+        es_format_t fmt;
+        es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC('a','r','a','w') );
+
+        fmt.audio.i_channels = p_sys->b_stereo ? 2 : 1;
+        fmt.audio.i_rate = p_sys->i_sample_rate;
+        fmt.audio.i_bitspersample = 16; // FIXME ?
+        fmt.audio.i_blockalign = fmt.audio.i_channels *
+            fmt.audio.i_bitspersample / 8;
+        fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
+            fmt.audio.i_bitspersample;
+
+        msg_Dbg( p_demux, "new audio es %d channels %dHz",
+                 fmt.audio.i_channels, fmt.audio.i_rate );
+
+        p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt );
+    }
+
+    /* Update default_pts to a suitable value for access */
+    var_Create( p_demux, "v4l-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close: close device, free resources
+ *****************************************************************************/
+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;
+
+    if( p_sys->psz_device ) free( p_sys->psz_device );
+    if( p_sys->psz_vdev )   free( p_sys->psz_vdev );
+    if( p_sys->psz_adev )   free( p_sys->psz_adev );
+    if( p_sys->fd_video >= 0 ) close( p_sys->fd_video );
+    if( p_sys->fd_audio >= 0 ) close( p_sys->fd_audio );
+    if( p_sys->p_block_audio ) block_Release( p_sys->p_block_audio );
+
+    if( p_sys->b_mjpeg )
+    {
+        int i_noframe = -1;
+        ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT, &i_noframe );
+    }
+
+    if( p_sys->p_video_mmap && p_sys->p_video_mmap != MAP_FAILED )
+    {
+        if( p_sys->b_mjpeg )
+            munmap( p_sys->p_video_mmap, p_sys->mjpeg_buffers.size *
+                    p_sys->mjpeg_buffers.count );
+        else
+            munmap( p_sys->p_video_mmap, p_sys->vid_mbuf.size );
+    }
+
+    free( p_sys );
+}
+
+/*****************************************************************************
+ * Control:
+ *****************************************************************************/
+static int Control( demux_t *p_demux, int i_query, va_list args )
+{
+    vlc_bool_t *pb;
+    int64_t    *pi64;
+
+    switch( i_query )
+    {
+        /* Special for access_demux */
+        case DEMUX_CAN_PAUSE:
+        case DEMUX_SET_PAUSE_STATE:
+        case DEMUX_CAN_CONTROL_PACE:
+            pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
+            *pb = VLC_FALSE;
+            return VLC_SUCCESS;
+
+        case DEMUX_GET_PTS_DELAY:
+            pi64 = (int64_t*)va_arg( args, int64_t * );
+            *pi64 = (int64_t)var_GetInteger( p_demux, "v4l-caching" ) * 1000;
+            return VLC_SUCCESS;
+
+        case DEMUX_GET_TIME:
+            pi64 = (int64_t*)va_arg( args, int64_t * );
+            *pi64 = mdate();
+            return VLC_SUCCESS;
+
+        /* TODO implement others */
+        default:
+            return VLC_EGENERIC;
+    }
+
+    return VLC_EGENERIC;
+}
+
+/*****************************************************************************
+ * Demux:
+ *****************************************************************************/
+static int Demux( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    es_out_id_t  *p_es = p_sys->p_es_audio;
+    block_t *p_block = NULL;
+
+    /* Try grabbing audio frames first */
+    if( p_sys->fd_audio < 0 || !( p_block = GrabAudio( p_demux ) ) )
+    {
+        /* Try grabbing video frame */
+        p_es = p_sys->p_es_video;
+        if( p_sys->fd_video > 0 ) p_block = GrabVideo( p_demux );
+    }
+
+    if( !p_block )
+    {
+        /* Sleep so we do not consume all the cpu, 10ms seems
+         * like a good value (100fps) */
+        msleep( 10000 );
+        return 1;
+    }
+
+    es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
+    es_out_Send( p_demux->out, p_es, p_block );
+
+    return 1;
+}
+
+/*****************************************************************************
+ * ParseMRL: parse the options contained in the MRL
+ *****************************************************************************/
+static void ParseMRL( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+
+    char *psz_dup = strdup( p_demux->psz_path );
+    char *psz_parser = psz_dup;
+
+    while( *psz_parser && *psz_parser != ':' )
+    {
+        psz_parser++;
+    }
+
+    if( *psz_parser == ':' )
+    {
+        /* read options */
+        for( ;; )
+        {
+            *psz_parser++ = '\0';
+            if( !strncmp( psz_parser, "channel=", strlen( "channel=" ) ) )
+            {
+                p_sys->i_channel = strtol( psz_parser + strlen( "channel=" ),
+                                           &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "norm=", strlen( "norm=" ) ) )
+            {
+                psz_parser += strlen( "norm=" );
+                if( !strncmp( psz_parser, "pal", strlen( "pal" ) ) )
+                {
+                    p_sys->i_norm = VIDEO_MODE_PAL;
+                    psz_parser += strlen( "pal" );
+                }
+                else if( !strncmp( psz_parser, "ntsc", strlen( "ntsc" ) ) )
+                {
+                    p_sys->i_norm = VIDEO_MODE_NTSC;
+                    psz_parser += strlen( "ntsc" );
+                }
+                else if( !strncmp( psz_parser, "secam", strlen( "secam" ) ) )
+                {
+                    p_sys->i_norm = VIDEO_MODE_SECAM;
+                    psz_parser += strlen( "secam" );
+                }
+                else if( !strncmp( psz_parser, "auto", strlen( "auto" ) ) )
+                {
+                    p_sys->i_norm = VIDEO_MODE_AUTO;
+                    psz_parser += strlen( "auto" );
+                }
+                else
+                {
+                    p_sys->i_norm = strtol( psz_parser, &psz_parser, 0 );
+                }
+            }
+            else if( !strncmp( psz_parser, "frequency=",
+                               strlen( "frequency=" ) ) )
+            {
+                p_sys->i_frequency =
+                    strtol( psz_parser + strlen( "frequency=" ),
+                            &psz_parser, 0 );
+                if( p_sys->i_frequency < 30000 )
+                {
+                    msg_Warn( p_demux, "v4l syntax has changed : "
+                              "'frequency' is now channel frequency in kHz");
+                }
+            }
+            else if( !strncmp( psz_parser, "audio=", strlen( "audio=" ) ) )
+            {
+                p_sys->i_audio = strtol( psz_parser + strlen( "audio=" ),
+                                         &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "size=", strlen( "size=" ) ) )
+            {
+                psz_parser += strlen( "size=" );
+                if( !strncmp( psz_parser, "subqcif", strlen( "subqcif" ) ) )
+                {
+                    p_sys->i_width  = 128;
+                    p_sys->i_height = 96;
+                }
+                else if( !strncmp( psz_parser, "qsif", strlen( "qsif" ) ) )
+                {
+                    p_sys->i_width  = 160;
+                    p_sys->i_height = 120;
+                }
+                else if( !strncmp( psz_parser, "qcif", strlen( "qcif" ) ) )
+                {
+                    p_sys->i_width  = 176;
+                    p_sys->i_height = 144;
+                }
+                else if( !strncmp( psz_parser, "sif", strlen( "sif" ) ) )
+                {
+                    p_sys->i_width  = 320;
+                    p_sys->i_height = 244;
+                }
+                else if( !strncmp( psz_parser, "cif", strlen( "cif" ) ) )
+                {
+                    p_sys->i_width  = 352;
+                    p_sys->i_height = 288;
+                }
+                else if( !strncmp( psz_parser, "vga", strlen( "vga" ) ) )
+                {
+                    p_sys->i_width  = 640;
+                    p_sys->i_height = 480;
+                }
+                else
+                {
+                    /* widthxheight */
+                    p_sys->i_width = strtol( psz_parser, &psz_parser, 0 );
+                    if( *psz_parser == 'x' || *psz_parser == 'X')
+                    {
+                        p_sys->i_height = strtol( psz_parser + 1,
+                                                  &psz_parser, 0 );
+                    }
+                    msg_Dbg( p_demux, "WxH %dx%d", p_sys->i_width,
+                             p_sys->i_height );
+                }
+            }
+            else if( !strncmp( psz_parser, "brightness=", strlen( "brightness=" ) ) )
+            {
+                p_sys->i_brightness = strtol( psz_parser + strlen( "brightness=" ),
+                                              &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "colour=", strlen( "colour=" ) ) )
+            {
+                p_sys->i_colour = strtol( psz_parser + strlen( "colour=" ),
+                                          &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "hue=", strlen( "hue=" ) ) )
+            {
+                p_sys->i_hue = strtol( psz_parser + strlen( "hue=" ), 
+                                       &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "contrast=", strlen( "contrast=" ) ) )
+            {
+                p_sys->i_contrast = strtol( psz_parser + strlen( "contrast=" ),
+                                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "tuner=", strlen( "tuner=" ) ) )
+            {
+                p_sys->i_tuner = strtol( psz_parser + strlen( "tuner=" ),
+                                         &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "adev=", strlen( "adev=" ) ) )
+            {
+                int  i_len;
+
+                psz_parser += strlen( "adev=" );
+                if( strchr( psz_parser, ':' ) )
+                {
+                    i_len = strchr( psz_parser, ':' ) - psz_parser;
+                }
+                else
+                {
+                    i_len = strlen( psz_parser );
+                }
+
+                p_sys->psz_adev = strndup( psz_parser, i_len );
+
+                psz_parser += i_len;
+            }
+            else if( !strncmp( psz_parser, "samplerate=",
+                               strlen( "samplerate=" ) ) )
+            {
+                p_sys->i_sample_rate =
+                    strtol( psz_parser + strlen( "samplerate=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "stereo", strlen( "stereo" ) ) )
+            {
+                psz_parser += strlen( "stereo" );
+
+                p_sys->b_stereo = VLC_TRUE;
+            }
+            else if( !strncmp( psz_parser, "mono", strlen( "mono" ) ) )
+            {
+                psz_parser += strlen( "mono" );
+
+                p_sys->b_stereo = VLC_FALSE;
+            }
+            else if( !strncmp( psz_parser, "mjpeg", strlen( "mjpeg" ) ) )
+            {
+                psz_parser += strlen( "mjpeg" );
+
+                p_sys->b_mjpeg = VLC_TRUE;
+            }
+            else if( !strncmp( psz_parser, "decimation=",
+                        strlen( "decimation=" ) ) )
+            {
+                p_sys->i_decimation =
+                    strtol( psz_parser + strlen( "decimation=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "quality=",
+                        strlen( "quality=" ) ) )
+            {
+                p_sys->i_quality =
+                    strtol( psz_parser + strlen( "quality=" ),
+                            &psz_parser, 0 );
+            }
+            else if( !strncmp( psz_parser, "fps=", strlen( "fps=" ) ) )
+            {
+                p_sys->f_fps = strtof( psz_parser + strlen( "fps=" ),
+                                       &psz_parser );
+            }
+            else
+            {
+                msg_Warn( p_demux, "unknown option" );
+            }
+
+            while( *psz_parser && *psz_parser != ':' )
+            {
+                psz_parser++;
+            }
+
+            if( *psz_parser == '\0' )
+            {
+                break;
+            }
+        }
+    }
+
+    if( *psz_dup )
+    {
+        p_sys->psz_device = strdup( psz_dup );
+    }
+    if( psz_dup ) free( psz_dup );
+}
+
+/*****************************************************************************
+ * OpenVideoDev:
+ *****************************************************************************/
+static int OpenVideoDev( demux_t *p_demux, char *psz_device )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    int i_fd;
+
+    struct video_channel vid_channel;
+    struct mjpeg_params mjpeg;
+    int i;
+
+    if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 )
+    {
+        msg_Err( p_demux, "cannot open device (%s)", strerror( errno ) );
+        goto vdev_failed;
+    }
+
+    if( ioctl( i_fd, VIDIOCGCAP, &p_sys->vid_cap ) < 0 )
+    {
+        msg_Err( p_demux, "cannot get capabilities (%s)", strerror( errno ) );
+        goto vdev_failed;
+    }
+
+    msg_Dbg( p_demux,
+             "V4L device %s %d channels %d audios %d < w < %d %d < h < %d",
+             p_sys->vid_cap.name,
+             p_sys->vid_cap.channels,
+             p_sys->vid_cap.audios,
+             p_sys->vid_cap.minwidth,  p_sys->vid_cap.maxwidth,
+             p_sys->vid_cap.minheight, p_sys->vid_cap.maxheight );
+
+    if( p_sys->i_channel < 0 || p_sys->i_channel >= p_sys->vid_cap.channels )
+    {
+        msg_Dbg( p_demux, "invalid channel, falling back on channel 0" );
+        p_sys->i_channel = 0;
+    }
+    if( p_sys->vid_cap.audios && p_sys->i_audio >= p_sys->vid_cap.audios )
+    {
+        msg_Dbg( p_demux, "invalid audio, falling back with no audio" );
+        p_sys->i_audio = -1;
+    }
+
+    if( p_sys->i_width < p_sys->vid_cap.minwidth ||
+        p_sys->i_width > p_sys->vid_cap.maxwidth )
+    {
+        msg_Dbg( p_demux, "invalid width %i", p_sys->i_width );
+        p_sys->i_width = 0;
+    }
+    if( p_sys->i_height < p_sys->vid_cap.minheight ||
+        p_sys->i_height > p_sys->vid_cap.maxheight )
+    {
+        msg_Dbg( p_demux, "invalid height %i", p_sys->i_height );
+        p_sys->i_height = 0;
+    }
+
+    if( !( p_sys->vid_cap.type & VID_TYPE_CAPTURE ) )
+    {
+        msg_Err( p_demux, "cannot grab" );
+        goto vdev_failed;
+    }
+
+    vid_channel.channel = p_sys->i_channel;
+    if( ioctl( i_fd, VIDIOCGCHAN, &vid_channel ) < 0 )
+    {
+        msg_Err( p_demux, "cannot get channel infos (%s)",
+                          strerror( errno ) );
+        goto vdev_failed;
+    }
+    msg_Dbg( p_demux,
+             "setting channel %s(%d) %d tuners flags=0x%x type=0x%x norm=0x%x",
+             vid_channel.name, vid_channel.channel, vid_channel.tuners,
+             vid_channel.flags, vid_channel.type, vid_channel.norm );
+
+    if( p_sys->i_tuner >= vid_channel.tuners )
+    {
+        msg_Dbg( p_demux, "invalid tuner, falling back on tuner 0" );
+        p_sys->i_tuner = 0;
+    }
+
+    vid_channel.norm = p_sys->i_norm;
+    if( ioctl( i_fd, VIDIOCSCHAN, &vid_channel ) < 0 )
+    {
+        msg_Err( p_demux, "cannot set channel (%s)", strerror( errno ) );
+        goto vdev_failed;
+    }
+
+    if( vid_channel.flags & VIDEO_VC_TUNER )
+    {
+
+        /* set tuner */
+#if 0
+        struct video_tuner vid_tuner;
+        if( p_sys->i_tuner >= 0 )
+        {
+            vid_tuner.tuner = p_sys->i_tuner;
+            if( ioctl( i_fd, VIDIOCGTUNER, &vid_tuner ) < 0 )
+            {
+                msg_Err( p_demux, "cannot get tuner (%s)", strerror( errno ) );
+                goto vdev_failed;
+            }
+            msg_Dbg( p_demux, "tuner %s low=%d high=%d, flags=0x%x "
+                     "mode=0x%x signal=0x%x",
+                     vid_tuner.name, vid_tuner.rangelow, vid_tuner.rangehigh,
+                     vid_tuner.flags, vid_tuner.mode, vid_tuner.signal );
+
+            msg_Dbg( p_demux, "setting tuner %s (%d)",
+                     vid_tuner.name, vid_tuner.tuner );
+
+            /* FIXME FIXME to be checked FIXME FIXME */
+            //vid_tuner.mode = p_sys->i_norm;
+            if( ioctl( i_fd, VIDIOCSTUNER, &vid_tuner ) < 0 )
+            {
+                msg_Err( p_demux, "cannot set tuner (%s)", strerror( errno ) );
+                goto vdev_failed;
+            }
+        }
+#endif
+
+        /* Show a warning if frequency is < than 30000.
+         * User is certainly usint old syntax. */
+
+
+        /* set frequency */
+        if( p_sys->i_frequency >= 0 )
+        {
+            int driver_frequency = p_sys->i_frequency * 16 /1000;
+            if( ioctl( i_fd, VIDIOCSFREQ, &driver_frequency ) < 0 )
+            {
+                msg_Err( p_demux, "cannot set frequency (%s)",
+                                  strerror( errno ) );
+                goto vdev_failed;
+            }
+            msg_Dbg( p_demux, "frequency %d (%d)", p_sys->i_frequency,
+                                                   driver_frequency );
+        }
+    }
+
+    /* set audio */
+    if( vid_channel.flags & VIDEO_VC_AUDIO )
+    {
+        struct video_audio      vid_audio;
+
+        /* XXX TODO volume, balance, ... */
+        if( p_sys->i_audio >= 0 )
+        {
+            vid_audio.audio = p_sys->i_audio;
+            if( ioctl( i_fd, VIDIOCGAUDIO, &vid_audio ) < 0 )
+            {
+                msg_Err( p_demux, "cannot get audio (%s)", strerror( errno ) );
+                goto vdev_failed;
+            }
+
+            /* unmute audio */
+            vid_audio.flags &= ~VIDEO_AUDIO_MUTE;
+
+            if( ioctl( i_fd, VIDIOCSAUDIO, &vid_audio ) < 0 )
+            {
+                msg_Err( p_demux, "cannot set audio (%s)", strerror( errno ) );
+                goto vdev_failed;
+            }
+        }
+
+    }
+
+    /* establish basic params with input and norm before feeling width
+     * or height */
+    if( p_sys->b_mjpeg )
+    {
+        struct quicktime_mjpeg_app1 *p_app1;
+        int32_t i_offset;
+
+        if( ioctl( i_fd, MJPIOC_G_PARAMS, &mjpeg ) < 0 )
+        {
+            msg_Err( p_demux, "cannot get mjpeg params (%s)",
+                              strerror( errno ) );
+            goto vdev_failed;
+        }
+        mjpeg.input = p_sys->i_channel;
+        mjpeg.norm  = p_sys->i_norm;
+        mjpeg.decimation = p_sys->i_decimation;
+
+        if( p_sys->i_width )
+            mjpeg.img_width = p_sys->i_width / p_sys->i_decimation;
+        if( p_sys->i_height )
+            mjpeg.img_height = p_sys->i_height / p_sys->i_decimation;
+
+        /* establish Quicktime APP1 marker while we are here */
+        mjpeg.APPn = 1;
+        mjpeg.APP_len = 40;
+
+        /* aligned */
+        p_app1 = (struct quicktime_mjpeg_app1 *)mjpeg.APP_data;
+        p_app1->i_reserved = 0;
+        p_app1->i_tag = VLC_FOURCC( 'm','j','p','g' );
+        p_app1->i_field_size = 0;
+        p_app1->i_padded_field_size = 0;
+        p_app1->i_next_field = 0;
+        /* XXX WARNING XXX */
+        /* these's nothing magic about these values.  We are dangerously
+         * assuming the encoder card is encoding mjpeg-a and is not throwing
+         * in marker tags we aren't expecting.  It's bad enough we have to
+         * search through the jpeg output for every frame we grab just to
+         * find the first field's end marker, so we take this risk to boost
+         * performance.
+         * This is really something the driver could do for us because this
+         * does conform to standards outside of Apple Quicktime.
+         */
+        i_offset = 0x2e;
+        p_app1->i_DQT_offset = hton32( i_offset );
+        i_offset = 0xb4;
+        p_app1->i_DHT_offset = hton32( i_offset );
+        i_offset = 0x258;
+        p_app1->i_SOF_offset = hton32( i_offset );
+        i_offset = 0x26b;
+        p_app1->i_SOS_offset = hton32( i_offset );
+        i_offset = 0x279;
+        p_app1->i_data_offset = hton32( i_offset );
+
+        /* SOF and SOS aren't specified by the mjpeg API because they aren't
+         * optional.  They will be present in the output. */
+        mjpeg.jpeg_markers = JPEG_MARKER_DHT | JPEG_MARKER_DQT;
+
+        if( ioctl( i_fd, MJPIOC_S_PARAMS, &mjpeg ) < 0 )
+        {
+            msg_Err( p_demux, "cannot set mjpeg params (%s)",
+                              strerror( errno ) );
+            goto vdev_failed;
+        }
+
+        p_sys->i_width = mjpeg.img_width * mjpeg.HorDcm;
+        p_sys->i_height = mjpeg.img_height * mjpeg.VerDcm *
+            mjpeg.field_per_buff;
+    }
+
+    /* fix width/height */
+    if( !p_sys->b_mjpeg && ( p_sys->i_width == 0 || p_sys->i_height == 0 ) )
+    {
+        struct video_window vid_win;
+
+        if( ioctl( i_fd, VIDIOCGWIN, &vid_win ) < 0 )
+        {
+            msg_Err( p_demux, "cannot get win (%s)", strerror( errno ) );
+            goto vdev_failed;
+        }
+        p_sys->i_width  = vid_win.width;
+        p_sys->i_height = vid_win.height;
+
+        if( !p_sys->i_width || !p_sys->i_height )
+        {
+            p_sys->i_width = p_sys->vid_cap.maxwidth;
+            p_sys->i_height = p_sys->vid_cap.maxheight;
+        }
+
+        if( !p_sys->i_width || !p_sys->i_height )
+        {
+            msg_Err( p_demux, "invalid video size (%ix%i)",
+                     p_sys->i_width, p_sys->i_height );
+            goto vdev_failed;
+        }
+
+        msg_Dbg( p_demux, "will use %dx%d", p_sys->i_width, p_sys->i_height );
+    }
+
+    if( !p_sys->b_mjpeg )
+    {
+        /* set hue/color/.. */
+        if( ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
+        {
+            struct video_picture vid_picture = p_sys->vid_picture;
+
+            if( p_sys->i_brightness >= 0 && p_sys->i_brightness < 65536 )
+            {
+                vid_picture.brightness = p_sys->i_brightness;
+            }
+            if( p_sys->i_colour >= 0 && p_sys->i_colour < 65536 )
+            {
+                vid_picture.colour = p_sys->i_colour;
+            }
+            if( p_sys->i_hue >= 0 && p_sys->i_hue < 65536 )
+            {
+                vid_picture.hue = p_sys->i_hue;
+            }
+            if( p_sys->i_contrast  >= 0 && p_sys->i_contrast < 65536 )
+            {
+                vid_picture.contrast = p_sys->i_contrast;
+            }
+            if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
+            {
+                msg_Dbg( p_demux, "v4l device uses brightness: %d",
+                         vid_picture.brightness );
+                msg_Dbg( p_demux, "v4l device uses colour: %d",
+                         vid_picture.colour );
+                msg_Dbg( p_demux, "v4l device uses hue: %d", vid_picture.hue );
+                msg_Dbg( p_demux, "v4l device uses contrast: %d",
+                         vid_picture.contrast );
+                p_sys->vid_picture = vid_picture;
+            }
+        }
+
+        /* Find out video format used by device */
+        if( ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
+        {
+            struct video_picture vid_picture = p_sys->vid_picture;
+            char *psz;
+            int i;
+
+            vid_picture.palette = 0;
+            p_sys->i_fourcc = 0;
+
+            psz = var_CreateGetString( p_demux, "v4l-chroma" );
+            if( strlen( psz ) >= 4 )
+            {
+                int i_chroma = VLC_FOURCC( psz[0], psz[1], psz[2], psz[3] );
+
+                /* Find out v4l chroma code */
+                for( i = 0; v4lchroma_to_fourcc[i].i_v4l != 0; i++ )
+                {
+                    if( v4lchroma_to_fourcc[i].i_fourcc == i_chroma )
+                    {
+                        vid_picture.palette = v4lchroma_to_fourcc[i].i_v4l;
+                        break;
+                    }
+                }
+            }
+            free( psz );
+
+            if( vid_picture.palette &&
+                !ioctl( i_fd, VIDIOCSPICT, &vid_picture ) )
+            {
+                p_sys->vid_picture = vid_picture;
+            }
+            else
+            {
+                /* Try to set the format to something easy to encode */
+                vid_picture.palette = VIDEO_PALETTE_YUV420P;
+                if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
+                {
+                    p_sys->vid_picture = vid_picture;
+                }
+                else
+                {
+                    vid_picture.palette = VIDEO_PALETTE_YUV422P;
+                    if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
+                    {
+                        p_sys->vid_picture = vid_picture;
+                    }
+                }
+            }
+
+            /* Find out final format */
+            for( i = 0; v4lchroma_to_fourcc[i].i_v4l != 0; i++ )
+            {
+                if( v4lchroma_to_fourcc[i].i_v4l == p_sys->vid_picture.palette)
+                {
+                    p_sys->i_fourcc = v4lchroma_to_fourcc[i].i_fourcc;
+                    break;
+                }
+            }
+        }
+        else
+        {
+            msg_Err( p_demux, "ioctl VIDIOCGPICT failed" );
+            goto vdev_failed;
+        }
+    }
+
+    if( p_sys->b_mjpeg )
+    {
+        int i;
+
+        p_sys->mjpeg_buffers.count = 8;
+        p_sys->mjpeg_buffers.size = MJPEG_BUFFER_SIZE;
+
+        if( ioctl( i_fd, MJPIOC_REQBUFS, &p_sys->mjpeg_buffers ) < 0 )
+        {
+            msg_Err( p_demux, "mmap unsupported" );
+            goto vdev_failed;
+        }
+
+        p_sys->p_video_mmap = mmap( 0,
+                p_sys->mjpeg_buffers.size * p_sys->mjpeg_buffers.count,
+                PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, 0 );
+        if( p_sys->p_video_mmap == MAP_FAILED )
+        {
+            msg_Err( p_demux, "mmap failed" );
+            goto vdev_failed;
+        }
+
+        p_sys->i_fourcc  = VLC_FOURCC( 'm','j','p','g' );
+        p_sys->i_frame_pos = -1;
+
+        /* queue up all the frames */
+        for( i = 0; i < (int)p_sys->mjpeg_buffers.count; i++ )
+        {
+            if( ioctl( i_fd, MJPIOC_QBUF_CAPT, &i ) < 0 )
+            {
+                msg_Err( p_demux, "unable to queue frame" );
+                goto vdev_failed;
+            }
+        }
+    }
+    else
+    {
+        /* Fill in picture_t fields */
+        vout_InitPicture( VLC_OBJECT(p_demux), &p_sys->pic, p_sys->i_fourcc,
+                          p_sys->i_width, p_sys->i_height, p_sys->i_width *
+                          VOUT_ASPECT_FACTOR / p_sys->i_height );
+        if( !p_sys->pic.i_planes )
+        {
+            msg_Err( p_demux, "unsupported chroma" );
+            goto vdev_failed;
+        }
+        p_sys->i_video_frame_size = 0;
+        for( i = 0; i < p_sys->pic.i_planes; i++ )
+        {
+            p_sys->i_video_frame_size += p_sys->pic.p[i].i_visible_lines *
+              p_sys->pic.p[i].i_visible_pitch;
+        }
+
+        msg_Dbg( p_demux, "v4l device uses frame size: %i",
+                 p_sys->i_video_frame_size );
+        msg_Dbg( p_demux, "v4l device uses chroma: %4.4s",
+                (char*)&p_sys->i_fourcc );
+
+        /* Allocate mmap buffer */
+        if( ioctl( i_fd, VIDIOCGMBUF, &p_sys->vid_mbuf ) < 0 )
+        {
+            msg_Err( p_demux, "mmap unsupported" );
+            goto vdev_failed;
+        }
+
+        p_sys->p_video_mmap = mmap( 0, p_sys->vid_mbuf.size,
+                                    PROT_READ|PROT_WRITE, MAP_SHARED,
+                                    i_fd, 0 );
+        if( p_sys->p_video_mmap == MAP_FAILED )
+        {
+            /* FIXME -> normal read */
+            msg_Err( p_demux, "mmap failed" );
+            goto vdev_failed;
+        }
+
+        /* init grabbing */
+        p_sys->vid_mmap.frame  = 0;
+        p_sys->vid_mmap.width  = p_sys->i_width;
+        p_sys->vid_mmap.height = p_sys->i_height;
+        p_sys->vid_mmap.format = p_sys->vid_picture.palette;
+        if( ioctl( i_fd, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
+        {
+            msg_Warn( p_demux, "%4.4s refused", (char*)&p_sys->i_fourcc );
+            msg_Err( p_demux, "chroma selection failed" );
+            goto vdev_failed;
+        }
+    }
+    return i_fd;
+
+vdev_failed:
+
+    if( i_fd >= 0 ) close( i_fd );
+    return -1;
+}
+
+/*****************************************************************************
+ * OpenAudioDev:
+ *****************************************************************************/
+static int OpenAudioDev( demux_t *p_demux, char *psz_device )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    int i_fd, i_format;
+
+    if( (i_fd = open( psz_device, O_RDONLY | O_NONBLOCK )) < 0 )
+    {
+        msg_Err( p_demux, "cannot open audio device (%s)", strerror( errno ) );
+        goto adev_fail;
+    }
+
+    i_format = AFMT_S16_LE;
+    if( ioctl( i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0
+        || i_format != AFMT_S16_LE )
+    {
+        msg_Err( p_demux, "cannot set audio format (16b little endian) "
+                 "(%s)", strerror( errno ) );
+        goto adev_fail;
+    }
+
+    if( ioctl( i_fd, SNDCTL_DSP_STEREO,
+               &p_sys->b_stereo ) < 0 )
+    {
+        msg_Err( p_demux, "cannot set audio channels count (%s)",
+                 strerror( errno ) );
+        goto adev_fail;
+    }
+
+    if( ioctl( i_fd, SNDCTL_DSP_SPEED,
+               &p_sys->i_sample_rate ) < 0 )
+    {
+        msg_Err( p_demux, "cannot set audio sample rate (%s)",
+                 strerror( errno ) );
+        goto adev_fail;
+    }
+
+    msg_Dbg( p_demux, "openened adev=`%s' %s %dHz",
+             psz_device, p_sys->b_stereo ? "stereo" : "mono",
+             p_sys->i_sample_rate );
+
+    p_sys->i_audio_max_frame_size = 6 * 1024;
+
+    return i_fd;
+
+ adev_fail:
+
+    if( i_fd >= 0 ) close( i_fd );
+    return -1;
+}
+
+/*****************************************************************************
+ * GrabAudio: grab audio
+ *****************************************************************************/
+static block_t *GrabAudio( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    struct audio_buf_info buf_info;
+    int i_read, i_correct;
+    block_t *p_block;
+
+    if( p_sys->p_block_audio ) p_block = p_sys->p_block_audio;
+    else p_block = block_New( p_demux, p_sys->i_audio_max_frame_size );
+
+    if( !p_block )
+    {
+        msg_Warn( p_demux, "cannot get block" );
+        return 0;
+    }
+
+    p_sys->p_block_audio = p_block;
+
+    i_read = read( p_sys->fd_audio, p_block->p_buffer,
+                   p_sys->i_audio_max_frame_size );
+
+    if( i_read <= 0 ) return 0;
+
+    p_block->i_buffer = i_read;
+    p_sys->p_block_audio = 0;
+
+    /* Correct the date because of kernel buffering */
+    i_correct = i_read;
+    if( ioctl( p_sys->fd_audio, SNDCTL_DSP_GETISPACE, &buf_info ) == 0 )
+    {
+        i_correct += buf_info.bytes;
+    }
+
+    p_block->i_pts = p_block->i_dts =
+        mdate() - I64C(1000000) * (mtime_t)i_correct /
+        2 / ( p_sys->b_stereo ? 2 : 1) / p_sys->i_sample_rate;
+
+    return p_block;
+}
+
+/*****************************************************************************
+ * GrabVideo:
+ *****************************************************************************/
+static uint8_t *GrabCapture( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    int i_captured_frame = p_sys->i_frame_pos;
+
+    p_sys->vid_mmap.frame = (p_sys->i_frame_pos + 1) % p_sys->vid_mbuf.frames;
+
+    while( ioctl( p_sys->fd_video, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
+    {
+        if( errno != EAGAIN )
+        {
+            msg_Err( p_demux, "failed capturing new frame" );
+            return NULL;
+        }
+
+        if( p_demux->b_die )
+        {
+            return NULL;
+        }
+
+        msg_Dbg( p_demux, "grab failed, trying again" );
+    }
+
+    while( ioctl(p_sys->fd_video, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
+    {
+        if( errno != EAGAIN && errno != EINTR )    
+        {
+            msg_Err( p_demux, "failed syncing new frame" );
+            return NULL;
+        }
+    }
+
+    p_sys->i_frame_pos = p_sys->vid_mmap.frame;
+    /* leave i_video_frame_size alone */
+    return p_sys->p_video_mmap + p_sys->vid_mbuf.offsets[i_captured_frame];
+}
+
+static uint8_t *GrabMJPEG( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    struct mjpeg_sync sync;
+    uint8_t *p_frame, *p_field, *p;
+    uint16_t tag;
+    uint32_t i_size;
+    struct quicktime_mjpeg_app1 *p_app1 = NULL;
+
+    /* re-queue the last frame we sync'd */
+    if( p_sys->i_frame_pos != -1 )
+    {
+        while( ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT,
+                                       &p_sys->i_frame_pos ) < 0 )
+        {
+            if( errno != EAGAIN && errno != EINTR )
+            {
+                msg_Err( p_demux, "failed capturing new frame" );
+                return NULL;
+            }
+        }
+    }
+
+    /* sync on the next frame */
+    while( ioctl( p_sys->fd_video, MJPIOC_SYNC, &sync ) < 0 )
+    {
+        if( errno != EAGAIN && errno != EINTR )    
+        {
+            msg_Err( p_demux, "failed syncing new frame" );
+            return NULL;
+        }
+    }
+
+    p_sys->i_frame_pos = sync.frame;
+    p_frame = p_sys->p_video_mmap + p_sys->mjpeg_buffers.size * sync.frame;
+
+    /* p_frame now points to the data.  fix up the Quicktime APP1 marker */
+    tag = 0xffd9;
+    tag = hton16( tag );
+    p_field = p_frame;
+
+    /* look for EOI */
+    p = memmem( p_field, sync.length, &tag, 2 );
+
+    if( p )
+    {
+        p += 2; /* data immediately following EOI */
+        /* UNALIGNED! */
+        p_app1 = (struct quicktime_mjpeg_app1 *)(p_field + 6);
+
+        i_size = ((uint32_t)(p - p_field));
+        i_size = hton32( i_size );
+        memcpy( &p_app1->i_field_size, &i_size, 4 );
+
+        while( *p == 0xff && *(p+1) == 0xff )
+            p++;
+
+        i_size = ((uint32_t)(p - p_field));
+        i_size = hton32( i_size );
+        memcpy( &p_app1->i_padded_field_size, &i_size, 4 );
+    }
+
+    tag = 0xffd8;
+    tag = hton16( tag );
+    p_field = memmem( p, sync.length - (size_t)(p - p_frame), &tag, 2 );
+
+    if( p_field )
+    {
+        i_size = (uint32_t)(p_field - p_frame);
+        i_size = hton32( i_size );
+        memcpy( &p_app1->i_next_field, &i_size, 4 );
+
+        /* UNALIGNED! */
+        p_app1 = (struct quicktime_mjpeg_app1 *)(p_field + 6);
+        tag = 0xffd9;
+        tag = hton16( tag );
+        p = memmem( p_field, sync.length - (size_t)(p_field - p_frame),
+                &tag, 2 );
+
+        if( !p )
+        {
+            /* sometimes the second field doesn't have the EOI.  just put it
+             * there
+             */
+            p = p_frame + sync.length;
+            memcpy( p, &tag, 2 );
+            sync.length += 2;
+        }
+
+        p += 2;
+        i_size = (uint32_t)(p - p_field);
+        i_size = hton32( i_size );
+        memcpy( &p_app1->i_field_size, &i_size, 4 );
+        i_size = (uint32_t)(sync.length - (uint32_t)(p_field - p_frame));
+        i_size = hton32( i_size );
+        memcpy( &p_app1->i_padded_field_size, &i_size, 4 );
+    }
+
+    p_sys->i_video_frame_size = sync.length;
+    return p_frame;
+}
+
+static block_t *GrabVideo( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    uint8_t     *p_frame;
+    block_t     *p_block;
+
+    if( p_sys->f_fps >= 0.1 && p_sys->i_video_pts > 0 )
+    {
+        mtime_t i_dur = (mtime_t)((double)1000000 / (double)p_sys->f_fps);
+
+        /* Did we wait long enough ? (frame rate reduction) */
+        if( p_sys->i_video_pts + i_dur > mdate() ) return 0;
+    }
+
+    if( p_sys->b_mjpeg ) p_frame = GrabMJPEG( p_demux );
+    else p_frame = GrabCapture( p_demux );
+
+    if( !p_frame ) return 0;
+
+    if( !( p_block = block_New( p_demux, p_sys->i_video_frame_size ) ) )
+    {
+        msg_Warn( p_demux, "cannot get block" );
+        return 0;
+    }
+
+    memcpy( p_block->p_buffer, p_frame, p_sys->i_video_frame_size );
+    p_sys->i_video_pts = p_block->i_pts = p_block->i_dts = mdate();
+
+    return p_block;
+}
diff --git a/modules/access/v4l/Modules.am b/modules/access/v4l/Modules.am
deleted file mode 100644 (file)
index bfdd854..0000000
+++ /dev/null
@@ -1 +0,0 @@
-SOURCES_v4l = v4l.c videodev_mjpeg.h
diff --git a/modules/access/v4l/v4l.c b/modules/access/v4l/v4l.c
deleted file mode 100644 (file)
index 6ea1bc4..0000000
+++ /dev/null
@@ -1,1595 +0,0 @@
-/*****************************************************************************
- * v4l.c : Video4Linux input module for vlc
- *****************************************************************************
- * Copyright (C) 2002-2004 the VideoLAN team
- * $Id$
- *
- * Author: Laurent Aimar <fenrir@via.ecp.fr>
- *         Paul Forgey <paulf at aphrodite dot com>
- *         Gildas Bazin <gbazin@videolan.org>
- *         Benjamin Pracht <bigben at videolan dot org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/vout.h>
-#include <codecs.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <fcntl.h>
-
-/* From GStreamer's v4l plugin:
- * Because of some really cool feature in video4linux1, also known as
- * 'not including sys/types.h and sys/time.h', we had to include it
- * ourselves. In all their intelligence, these people decided to fix
- * this in the next version (video4linux2) in such a cool way that it
- * breaks all compilations of old stuff...
- * The real problem is actually that linux/time.h doesn't use proper
- * macro checks before defining types like struct timeval. The proper
- * fix here is to either fuck the kernel header (which is what we do
- * by defining _LINUX_TIME_H, an innocent little hack) or by fixing it
- * upstream, which I'll consider doing later on. If you get compiler
- * errors here, check your linux/time.h && sys/time.h header setup.
-*/
-#define _LINUX_TIME_H
-
-#include <linux/videodev.h>
-#include "videodev_mjpeg.h"
-
-#include <sys/soundcard.h>
-
-/*****************************************************************************
- * Module descriptior
- *****************************************************************************/
-static int  Open ( vlc_object_t * );
-static void Close( vlc_object_t * );
-
-#define CACHING_TEXT N_("Caching value in ms")
-#define CACHING_LONGTEXT N_( \
-    "Caching value for V4L captures. This " \
-    "value should be set in milliseconds." )
-#define VDEV_TEXT N_("Video device name")
-#define VDEV_LONGTEXT N_( \
-    "Name of the video device to use. " \
-    "If you don't specify anything, no video device will be used.")
-#define ADEV_TEXT N_("Audio device name")
-#define ADEV_LONGTEXT N_( \
-    "Name of the audio device to use. " \
-    "If you don't specify anything, no audio device will be used.")
-#define CHROMA_TEXT N_("Video input chroma format")
-#define CHROMA_LONGTEXT N_( \
-    "Force the Video4Linux video device to use a specific chroma format " \
-    "(eg. I420 (default), RV24, etc.)")
-#define FREQUENCY_TEXT N_( "Frequency" )
-#define FREQUENCY_LONGTEXT N_( \
-    "Frequency to capture (in kHz), if applicable." )
-#define CHANNEL_TEXT N_( "Channel" )
-#define CHANNEL_LONGTEXT N_( \
-    "Channel of the card to use (Usually, 0 = tuner, " \
-    "1 = composite, 2 = svideo)." )
-#define NORM_TEXT N_( "Norm" )
-#define NORM_LONGTEXT N_( \
-    "Norm of the stream (Automatic, SECAM, PAL, or NTSC)." )
-#define AUDIO_TEXT N_( "Audio Channel" )
-#define AUDIO_LONGTEXT N_( \
-    "Audio Channel to use, if there are several audio inputs." )
-#define WIDTH_TEXT N_( "Width" )
-#define WIDTH_LONGTEXT N_( "Width of the stream to capture " \
-    "(-1 for autodetect)." )
-#define HEIGHT_TEXT N_( "Height" )
-#define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \
-    "(-1 for autodetect)." )
-#define BRIGHTNESS_TEXT N_( "Brightness" )
-#define BRIGHTNESS_LONGTEXT N_( \
-    "Brightness of the video input." )
-#define HUE_TEXT N_( "Hue" )
-#define HUE_LONGTEXT N_( \
-    "Hue of the video input." )
-#define COLOUR_TEXT N_( "Color" )
-#define COLOUR_LONGTEXT N_( \
-    "Color of the video input." )
-#define CONTRAST_TEXT N_( "Contrast" )
-#define CONTRAST_LONGTEXT N_( \
-    "Contrast of the video input." )
-#define TUNER_TEXT N_( "Tuner" )
-#define TUNER_LONGTEXT N_( "Tuner to use, if there are several ones." )
-#define SAMPLERATE_TEXT N_( "Samplerate" )
-#define SAMPLERATE_LONGTEXT N_( \
-    "Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100)" )
-#define STEREO_TEXT N_( "Stereo" )
-#define STEREO_LONGTEXT N_( \
-    "Capture the audio stream in stereo." )
-#define MJPEG_TEXT N_( "MJPEG" )
-#define MJPEG_LONGTEXT N_(  \
-    "Set this option if the capture device outputs MJPEG" )
-#define DECIMATION_TEXT N_( "Decimation" )
-#define DECIMATION_LONGTEXT N_( \
-    "Decimation level for MJPEG streams" )
-#define QUALITY_TEXT N_( "Quality" )
-#define QUALITY_LONGTEXT N_( "Quality of the stream." )
-#define FPS_TEXT N_( "Framerate" )
-#define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \
-    "(-1 for autodetect)." )
-
-static int i_norm_list[] =
-    { VIDEO_MODE_AUTO, VIDEO_MODE_SECAM, VIDEO_MODE_PAL, VIDEO_MODE_NTSC };
-static char *psz_norm_list_text[] =
-    { N_("Automatic"), N_("SECAM"), N_("PAL"),  N_("NTSC") };
-
-vlc_module_begin();
-    set_shortname( _("Video4Linux") );
-    set_description( _("Video4Linux input") );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_ACCESS );
-
-    add_integer( "v4l-caching", DEFAULT_PTS_DELAY / 1000, NULL,
-                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
-    add_string( "v4l-vdev", "/dev/video", 0, VDEV_TEXT, VDEV_LONGTEXT,
-                VLC_FALSE );
-    add_string( "v4l-adev", "/dev/dsp", 0, ADEV_TEXT, ADEV_LONGTEXT,
-                VLC_FALSE );
-    add_string( "v4l-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
-                VLC_TRUE );
-    add_float( "v4l-fps", -1.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
-    add_integer( "v4l-samplerate", 44100, NULL, SAMPLERATE_TEXT,
-                SAMPLERATE_LONGTEXT, VLC_TRUE );
-    add_integer( "v4l-channel", 0, NULL, CHANNEL_TEXT, CHANNEL_LONGTEXT,
-                VLC_TRUE );
-    add_integer( "v4l-tuner", -1, NULL, TUNER_TEXT, TUNER_LONGTEXT, VLC_TRUE );
-    add_integer( "v4l-norm", VIDEO_MODE_AUTO, NULL, NORM_TEXT, NORM_LONGTEXT,
-                VLC_FALSE );
-        change_integer_list( i_norm_list, psz_norm_list_text, 0 );
-    add_integer( "v4l-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
-                VLC_FALSE );
-    add_integer( "v4l-audio", -1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT, VLC_TRUE );
-    add_bool( "v4l-stereo", VLC_TRUE, NULL, STEREO_TEXT, STEREO_LONGTEXT,
-            VLC_TRUE );
-    add_integer( "v4l-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_TRUE );
-    add_integer( "v4l-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
-                VLC_TRUE );
-    add_integer( "v4l-brightness", -1, NULL, BRIGHTNESS_TEXT,
-                BRIGHTNESS_LONGTEXT, VLC_TRUE );
-    add_integer( "v4l-colour", -1, NULL, COLOUR_TEXT, COLOUR_LONGTEXT,
-                VLC_TRUE );
-    add_integer( "v4l-hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, VLC_TRUE );
-    add_integer( "v4l-contrast", -1, NULL, CONTRAST_TEXT, CONTRAST_LONGTEXT,
-                VLC_TRUE );
-    add_bool( "v4l-mjpeg", VLC_FALSE, NULL, MJPEG_TEXT, MJPEG_LONGTEXT,
-            VLC_TRUE );
-    add_integer( "v4l-decimation", 1, NULL, DECIMATION_TEXT,
-            DECIMATION_LONGTEXT, VLC_TRUE );
-    add_integer( "v4l-quality", 100, NULL, QUALITY_TEXT, QUALITY_LONGTEXT,
-            VLC_TRUE );
-
-    add_shortcut( "v4l" );
-    set_capability( "access_demux", 10 );
-    set_callbacks( Open, Close );
-vlc_module_end();
-
-/*****************************************************************************
- * Access: local prototypes
- *****************************************************************************/
-static int Demux  ( demux_t * );
-static int Control( demux_t *, int, va_list );
-
-static void ParseMRL    ( demux_t * );
-static int  OpenVideoDev( demux_t *, char * );
-static int  OpenAudioDev( demux_t *, char * );
-
-static block_t *GrabAudio( demux_t * );
-static block_t *GrabVideo( demux_t * );
-
-#define MJPEG_BUFFER_SIZE (256*1024)
-
-struct quicktime_mjpeg_app1
-{
-    uint32_t    i_reserved;             /* set to 0 */
-    uint32_t    i_tag;                  /* 'mjpg' */
-    uint32_t    i_field_size;           /* offset following EOI */
-    uint32_t    i_padded_field_size;    /* offset following EOI+pad */
-    uint32_t    i_next_field;           /* offset to next field */
-    uint32_t    i_DQT_offset;
-    uint32_t    i_DHT_offset;
-    uint32_t    i_SOF_offset;
-    uint32_t    i_SOS_offset;
-    uint32_t    i_data_offset;          /* following SOS marker data */
-};
-
-static struct
-{
-    int i_v4l;
-    int i_fourcc;
-
-} v4lchroma_to_fourcc[] =
-{
-    { VIDEO_PALETTE_GREY, VLC_FOURCC( 'G', 'R', 'E', 'Y' ) },
-    { VIDEO_PALETTE_HI240, VLC_FOURCC( 'I', '2', '4', '0' ) },
-    { VIDEO_PALETTE_RGB565, VLC_FOURCC( 'R', 'V', '1', '6' ) },
-    { VIDEO_PALETTE_RGB555, VLC_FOURCC( 'R', 'V', '1', '5' ) },
-    { VIDEO_PALETTE_RGB24, VLC_FOURCC( 'R', 'V', '2', '4' ) },
-    { VIDEO_PALETTE_RGB32, VLC_FOURCC( 'R', 'V', '3', '2' ) },
-    { VIDEO_PALETTE_YUV422, VLC_FOURCC( 'I', '4', '2', '2' ) },
-    { VIDEO_PALETTE_YUYV, VLC_FOURCC( 'Y', 'U', 'Y', 'V' ) },
-    { VIDEO_PALETTE_UYVY, VLC_FOURCC( 'U', 'Y', 'V', 'Y' ) },
-    { VIDEO_PALETTE_YUV420, VLC_FOURCC( 'I', '4', '2', 'N' ) },
-    { VIDEO_PALETTE_YUV411, VLC_FOURCC( 'I', '4', '1', 'N' ) },
-    { VIDEO_PALETTE_RAW, VLC_FOURCC( 'G', 'R', 'A', 'W' ) },
-    { VIDEO_PALETTE_YUV422P, VLC_FOURCC( 'I', '4', '2', '2' ) },
-    { VIDEO_PALETTE_YUV420P, VLC_FOURCC( 'I', '4', '2', '0' ) },
-    { VIDEO_PALETTE_YUV411P, VLC_FOURCC( 'I', '4', '1', '1' ) },
-    { 0, 0 }
-};
-
-struct demux_sys_t
-{
-    /* Devices */
-    char *psz_device;         /* Main device from MRL, can be video or audio */
-
-    char *psz_vdev;
-    int  fd_video;
-
-    char *psz_adev;
-    int  fd_audio;
-
-    /* Video properties */
-    picture_t pic;
-
-    int i_fourcc;
-    int i_channel;
-    int i_audio;
-    int i_norm;
-    int i_tuner;
-    int i_frequency;
-    int i_width;
-    int i_height;
-
-    int i_brightness;
-    int i_hue;
-    int i_colour;
-    int i_contrast;
-
-    float f_fps;            /* <= 0.0 mean to grab at full rate */
-    mtime_t i_video_pts;    /* only used when f_fps > 0 */
-
-    vlc_bool_t b_mjpeg;
-    int i_decimation;
-    int i_quality;
-
-    struct video_capability vid_cap;
-    struct video_mbuf       vid_mbuf;
-    struct mjpeg_requestbuffers mjpeg_buffers;
-
-    uint8_t *p_video_mmap;
-    int     i_frame_pos;
-
-    struct video_mmap   vid_mmap;
-    struct video_picture vid_picture;
-
-    int          i_video_frame_size;
-    es_out_id_t  *p_es_video;
-
-    /* Audio properties */
-    vlc_fourcc_t i_acodec_raw;
-    int          i_sample_rate;
-    vlc_bool_t   b_stereo;
-    int          i_audio_max_frame_size;
-    block_t      *p_block_audio;
-    es_out_id_t  *p_es_audio;
-};
-
-/*****************************************************************************
- * Open: opens v4l device
- *****************************************************************************
- *
- * url: <video device>::::
- *
- *****************************************************************************/
-static int Open( vlc_object_t *p_this )
-{
-    demux_t     *p_demux = (demux_t*)p_this;
-    demux_sys_t *p_sys;
-    vlc_value_t val;
-
-    /* Only when selected */
-    if( *p_demux->psz_access == '\0' )
-        return VLC_EGENERIC;
-
-    /* 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;
-    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
-    memset( p_sys, 0, sizeof( demux_sys_t ) );
-
-    var_Create( p_demux, "v4l-audio", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-audio", &val );
-    p_sys->i_audio          = val.i_int;
-
-    var_Create( p_demux, "v4l-channel", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-channel", &val );
-    p_sys->i_channel        = val.i_int;
-
-    var_Create( p_demux, "v4l-norm", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-norm", &val );
-    p_sys->i_norm           = val.i_int;
-
-    var_Create( p_demux, "v4l-tuner", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-tuner", &val );
-    p_sys->i_tuner          = val.i_int;
-
-    var_Create( p_demux, "v4l-frequency",
-                                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-frequency", &val );
-    p_sys->i_frequency      = val.i_int;
-
-    var_Create( p_demux, "v4l-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-fps", &val );
-    p_sys->f_fps            = val.f_float;
-
-    var_Create( p_demux, "v4l-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-width", &val );
-    p_sys->i_width          = val.i_int;
-
-    var_Create( p_demux, "v4l-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-height", &val );
-    p_sys->i_height         = val.i_int;
-
-    p_sys->i_video_pts      = -1;
-
-    var_Create( p_demux, "v4l-brightness", VLC_VAR_INTEGER |
-                                                        VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-brightness", &val );
-    p_sys->i_brightness     = val.i_int;
-
-    var_Create( p_demux, "v4l-hue", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-hue", &val );
-    p_sys->i_hue            = -1;
-
-    var_Create( p_demux, "v4l-colour", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-colour", &val );
-    p_sys->i_colour         = val.i_int;
-
-    var_Create( p_demux, "v4l-contrast", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-contrast", &val );
-    p_sys->i_contrast       = val.i_int;
-
-    var_Create( p_demux, "v4l-mjpeg", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-mjpeg", &val );
-    p_sys->b_mjpeg     = val.b_bool;
-
-    var_Create( p_demux, "v4l-decimation", VLC_VAR_INTEGER |
-                                                            VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-decimation", &val );
-    p_sys->i_decimation = val.i_int;
-
-    var_Create( p_demux, "v4l-quality", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-quality", &val );
-    p_sys->i_quality = val.i_int;
-
-    var_Create( p_demux, "v4l-samplerate",
-                                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-samplerate", &val );
-    p_sys->i_sample_rate  = val.i_int;
-
-    var_Create( p_demux, "v4l-stereo", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "v4l-stereo", &val );
-    p_sys->b_stereo       = val.b_bool;
-
-    p_sys->psz_device = p_sys->psz_vdev = p_sys->psz_adev = NULL;
-    p_sys->fd_video = -1;
-    p_sys->fd_audio = -1;
-
-    p_sys->p_es_video = p_sys->p_es_audio = 0;
-    p_sys->p_block_audio = 0;
-
-    ParseMRL( p_demux );
-
-    /* Find main device (video or audio) */
-    if( p_sys->psz_device && *p_sys->psz_device )
-    {
-        msg_Dbg( p_demux, "main device=`%s'", p_sys->psz_device );
-
-        /* Try to open as video device */
-        p_sys->fd_video = OpenVideoDev( p_demux, p_sys->psz_device );
-
-        if( p_sys->fd_video < 0 )
-        {
-            /* Try to open as audio device */
-            p_sys->fd_audio = OpenAudioDev( p_demux, p_sys->psz_device );
-            if( p_sys->fd_audio >= 0 )
-            {
-                if( p_sys->psz_adev ) free( p_sys->psz_adev );
-                p_sys->psz_adev = p_sys->psz_device;
-                p_sys->psz_device = NULL;
-            }
-        }
-        else
-        {
-            if( p_sys->psz_vdev ) free( p_sys->psz_vdev );
-            p_sys->psz_vdev = p_sys->psz_device;
-            p_sys->psz_device = NULL;
-        }
-    }
-
-    /* If no device opened, only continue if the access was forced */
-    if( p_sys->fd_video < 0 && p_sys->fd_audio < 0 )
-    {
-        if( strcmp( p_demux->psz_access, "v4l" ) )
-        {
-            Close( p_this );
-            return VLC_EGENERIC;
-        }
-    }
-
-    /* Find video device */
-    if( p_sys->fd_video < 0 )
-    {
-        if( !p_sys->psz_vdev || !*p_sys->psz_vdev )
-        {
-            if( p_sys->psz_vdev ) free( p_sys->psz_vdev );
-            p_sys->psz_vdev = var_CreateGetString( p_demux, "v4l-vdev" );;
-        }
-
-        if( p_sys->psz_vdev && *p_sys->psz_vdev )
-        {
-            p_sys->fd_video = OpenVideoDev( p_demux, p_sys->psz_vdev );
-        }
-    }
-
-    /* Find audio device */
-    if( p_sys->fd_audio < 0 )
-    {
-        if( !p_sys->psz_adev || !*p_sys->psz_adev )
-        {
-            if( p_sys->psz_adev ) free( p_sys->psz_adev );
-            p_sys->psz_adev = var_CreateGetString( p_demux, "v4l-adev" );;
-        }
-
-        if( p_sys->psz_adev && *p_sys->psz_adev )
-        {
-            p_sys->fd_audio = OpenAudioDev( p_demux, p_sys->psz_adev );
-        }
-    }
-
-    if( p_sys->fd_video < 0 && p_sys->fd_audio < 0 )
-    {
-        Close( p_this );
-        return VLC_EGENERIC;
-    }
-
-    msg_Dbg( p_demux, "v4l grabbing started" );
-
-    /* Declare elementary streams */
-    if( p_sys->fd_video >= 0 )
-    {
-        es_format_t fmt;
-        es_format_Init( &fmt, VIDEO_ES, p_sys->i_fourcc );
-        fmt.video.i_width  = p_sys->i_width;
-        fmt.video.i_height = p_sys->i_height;
-        fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
-
-        /* Setup rgb mask for RGB formats */
-        if( p_sys->i_fourcc == VLC_FOURCC('R','V','2','4') )
-        {
-            /* This is in BGR format */
-            fmt.video.i_bmask = 0x00ff0000;
-            fmt.video.i_gmask = 0x0000ff00;
-            fmt.video.i_rmask = 0x000000ff;
-        }
-
-        msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
-                 (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
-        p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
-    }
-
-    if( p_sys->fd_audio >= 0 )
-    {
-        es_format_t fmt;
-        es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC('a','r','a','w') );
-
-        fmt.audio.i_channels = p_sys->b_stereo ? 2 : 1;
-        fmt.audio.i_rate = p_sys->i_sample_rate;
-        fmt.audio.i_bitspersample = 16; // FIXME ?
-        fmt.audio.i_blockalign = fmt.audio.i_channels *
-            fmt.audio.i_bitspersample / 8;
-        fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
-            fmt.audio.i_bitspersample;
-
-        msg_Dbg( p_demux, "new audio es %d channels %dHz",
-                 fmt.audio.i_channels, fmt.audio.i_rate );
-
-        p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt );
-    }
-
-    /* Update default_pts to a suitable value for access */
-    var_Create( p_demux, "v4l-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Close: close device, free resources
- *****************************************************************************/
-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;
-
-    if( p_sys->psz_device ) free( p_sys->psz_device );
-    if( p_sys->psz_vdev )   free( p_sys->psz_vdev );
-    if( p_sys->psz_adev )   free( p_sys->psz_adev );
-    if( p_sys->fd_video >= 0 ) close( p_sys->fd_video );
-    if( p_sys->fd_audio >= 0 ) close( p_sys->fd_audio );
-    if( p_sys->p_block_audio ) block_Release( p_sys->p_block_audio );
-
-    if( p_sys->b_mjpeg )
-    {
-        int i_noframe = -1;
-        ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT, &i_noframe );
-    }
-
-    if( p_sys->p_video_mmap && p_sys->p_video_mmap != MAP_FAILED )
-    {
-        if( p_sys->b_mjpeg )
-            munmap( p_sys->p_video_mmap, p_sys->mjpeg_buffers.size *
-                    p_sys->mjpeg_buffers.count );
-        else
-            munmap( p_sys->p_video_mmap, p_sys->vid_mbuf.size );
-    }
-
-    free( p_sys );
-}
-
-/*****************************************************************************
- * Control:
- *****************************************************************************/
-static int Control( demux_t *p_demux, int i_query, va_list args )
-{
-    vlc_bool_t *pb;
-    int64_t    *pi64;
-
-    switch( i_query )
-    {
-        /* Special for access_demux */
-        case DEMUX_CAN_PAUSE:
-        case DEMUX_SET_PAUSE_STATE:
-        case DEMUX_CAN_CONTROL_PACE:
-            pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
-            *pb = VLC_FALSE;
-            return VLC_SUCCESS;
-
-        case DEMUX_GET_PTS_DELAY:
-            pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = (int64_t)var_GetInteger( p_demux, "v4l-caching" ) * 1000;
-            return VLC_SUCCESS;
-
-        case DEMUX_GET_TIME:
-            pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = mdate();
-            return VLC_SUCCESS;
-
-        /* TODO implement others */
-        default:
-            return VLC_EGENERIC;
-    }
-
-    return VLC_EGENERIC;
-}
-
-/*****************************************************************************
- * Demux:
- *****************************************************************************/
-static int Demux( demux_t *p_demux )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    es_out_id_t  *p_es = p_sys->p_es_audio;
-    block_t *p_block = NULL;
-
-    /* Try grabbing audio frames first */
-    if( p_sys->fd_audio < 0 || !( p_block = GrabAudio( p_demux ) ) )
-    {
-        /* Try grabbing video frame */
-        p_es = p_sys->p_es_video;
-        if( p_sys->fd_video > 0 ) p_block = GrabVideo( p_demux );
-    }
-
-    if( !p_block )
-    {
-        /* Sleep so we do not consume all the cpu, 10ms seems
-         * like a good value (100fps) */
-        msleep( 10000 );
-        return 1;
-    }
-
-    es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
-    es_out_Send( p_demux->out, p_es, p_block );
-
-    return 1;
-}
-
-/*****************************************************************************
- * ParseMRL: parse the options contained in the MRL
- *****************************************************************************/
-static void ParseMRL( demux_t *p_demux )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-
-    char *psz_dup = strdup( p_demux->psz_path );
-    char *psz_parser = psz_dup;
-
-    while( *psz_parser && *psz_parser != ':' )
-    {
-        psz_parser++;
-    }
-
-    if( *psz_parser == ':' )
-    {
-        /* read options */
-        for( ;; )
-        {
-            *psz_parser++ = '\0';
-            if( !strncmp( psz_parser, "channel=", strlen( "channel=" ) ) )
-            {
-                p_sys->i_channel = strtol( psz_parser + strlen( "channel=" ),
-                                           &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "norm=", strlen( "norm=" ) ) )
-            {
-                psz_parser += strlen( "norm=" );
-                if( !strncmp( psz_parser, "pal", strlen( "pal" ) ) )
-                {
-                    p_sys->i_norm = VIDEO_MODE_PAL;
-                    psz_parser += strlen( "pal" );
-                }
-                else if( !strncmp( psz_parser, "ntsc", strlen( "ntsc" ) ) )
-                {
-                    p_sys->i_norm = VIDEO_MODE_NTSC;
-                    psz_parser += strlen( "ntsc" );
-                }
-                else if( !strncmp( psz_parser, "secam", strlen( "secam" ) ) )
-                {
-                    p_sys->i_norm = VIDEO_MODE_SECAM;
-                    psz_parser += strlen( "secam" );
-                }
-                else if( !strncmp( psz_parser, "auto", strlen( "auto" ) ) )
-                {
-                    p_sys->i_norm = VIDEO_MODE_AUTO;
-                    psz_parser += strlen( "auto" );
-                }
-                else
-                {
-                    p_sys->i_norm = strtol( psz_parser, &psz_parser, 0 );
-                }
-            }
-            else if( !strncmp( psz_parser, "frequency=",
-                               strlen( "frequency=" ) ) )
-            {
-                p_sys->i_frequency =
-                    strtol( psz_parser + strlen( "frequency=" ),
-                            &psz_parser, 0 );
-                if( p_sys->i_frequency < 30000 )
-                {
-                    msg_Warn( p_demux, "v4l syntax has changed : "
-                              "'frequency' is now channel frequency in kHz");
-                }
-            }
-            else if( !strncmp( psz_parser, "audio=", strlen( "audio=" ) ) )
-            {
-                p_sys->i_audio = strtol( psz_parser + strlen( "audio=" ),
-                                         &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "size=", strlen( "size=" ) ) )
-            {
-                psz_parser += strlen( "size=" );
-                if( !strncmp( psz_parser, "subqcif", strlen( "subqcif" ) ) )
-                {
-                    p_sys->i_width  = 128;
-                    p_sys->i_height = 96;
-                }
-                else if( !strncmp( psz_parser, "qsif", strlen( "qsif" ) ) )
-                {
-                    p_sys->i_width  = 160;
-                    p_sys->i_height = 120;
-                }
-                else if( !strncmp( psz_parser, "qcif", strlen( "qcif" ) ) )
-                {
-                    p_sys->i_width  = 176;
-                    p_sys->i_height = 144;
-                }
-                else if( !strncmp( psz_parser, "sif", strlen( "sif" ) ) )
-                {
-                    p_sys->i_width  = 320;
-                    p_sys->i_height = 244;
-                }
-                else if( !strncmp( psz_parser, "cif", strlen( "cif" ) ) )
-                {
-                    p_sys->i_width  = 352;
-                    p_sys->i_height = 288;
-                }
-                else if( !strncmp( psz_parser, "vga", strlen( "vga" ) ) )
-                {
-                    p_sys->i_width  = 640;
-                    p_sys->i_height = 480;
-                }
-                else
-                {
-                    /* widthxheight */
-                    p_sys->i_width = strtol( psz_parser, &psz_parser, 0 );
-                    if( *psz_parser == 'x' || *psz_parser == 'X')
-                    {
-                        p_sys->i_height = strtol( psz_parser + 1,
-                                                  &psz_parser, 0 );
-                    }
-                    msg_Dbg( p_demux, "WxH %dx%d", p_sys->i_width,
-                             p_sys->i_height );
-                }
-            }
-            else if( !strncmp( psz_parser, "brightness=", strlen( "brightness=" ) ) )
-            {
-                p_sys->i_brightness = strtol( psz_parser + strlen( "brightness=" ),
-                                              &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "colour=", strlen( "colour=" ) ) )
-            {
-                p_sys->i_colour = strtol( psz_parser + strlen( "colour=" ),
-                                          &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "hue=", strlen( "hue=" ) ) )
-            {
-                p_sys->i_hue = strtol( psz_parser + strlen( "hue=" ), 
-                                       &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "contrast=", strlen( "contrast=" ) ) )
-            {
-                p_sys->i_contrast = strtol( psz_parser + strlen( "contrast=" ),
-                                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "tuner=", strlen( "tuner=" ) ) )
-            {
-                p_sys->i_tuner = strtol( psz_parser + strlen( "tuner=" ),
-                                         &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "adev=", strlen( "adev=" ) ) )
-            {
-                int  i_len;
-
-                psz_parser += strlen( "adev=" );
-                if( strchr( psz_parser, ':' ) )
-                {
-                    i_len = strchr( psz_parser, ':' ) - psz_parser;
-                }
-                else
-                {
-                    i_len = strlen( psz_parser );
-                }
-
-                p_sys->psz_adev = strndup( psz_parser, i_len );
-
-                psz_parser += i_len;
-            }
-            else if( !strncmp( psz_parser, "samplerate=",
-                               strlen( "samplerate=" ) ) )
-            {
-                p_sys->i_sample_rate =
-                    strtol( psz_parser + strlen( "samplerate=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "stereo", strlen( "stereo" ) ) )
-            {
-                psz_parser += strlen( "stereo" );
-
-                p_sys->b_stereo = VLC_TRUE;
-            }
-            else if( !strncmp( psz_parser, "mono", strlen( "mono" ) ) )
-            {
-                psz_parser += strlen( "mono" );
-
-                p_sys->b_stereo = VLC_FALSE;
-            }
-            else if( !strncmp( psz_parser, "mjpeg", strlen( "mjpeg" ) ) )
-            {
-                psz_parser += strlen( "mjpeg" );
-
-                p_sys->b_mjpeg = VLC_TRUE;
-            }
-            else if( !strncmp( psz_parser, "decimation=",
-                        strlen( "decimation=" ) ) )
-            {
-                p_sys->i_decimation =
-                    strtol( psz_parser + strlen( "decimation=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "quality=",
-                        strlen( "quality=" ) ) )
-            {
-                p_sys->i_quality =
-                    strtol( psz_parser + strlen( "quality=" ),
-                            &psz_parser, 0 );
-            }
-            else if( !strncmp( psz_parser, "fps=", strlen( "fps=" ) ) )
-            {
-                p_sys->f_fps = strtof( psz_parser + strlen( "fps=" ),
-                                       &psz_parser );
-            }
-            else
-            {
-                msg_Warn( p_demux, "unknown option" );
-            }
-
-            while( *psz_parser && *psz_parser != ':' )
-            {
-                psz_parser++;
-            }
-
-            if( *psz_parser == '\0' )
-            {
-                break;
-            }
-        }
-    }
-
-    if( *psz_dup )
-    {
-        p_sys->psz_device = strdup( psz_dup );
-    }
-    if( psz_dup ) free( psz_dup );
-}
-
-/*****************************************************************************
- * OpenVideoDev:
- *****************************************************************************/
-static int OpenVideoDev( demux_t *p_demux, char *psz_device )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    int i_fd;
-
-    struct video_channel vid_channel;
-    struct mjpeg_params mjpeg;
-    int i;
-
-    if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 )
-    {
-        msg_Err( p_demux, "cannot open device (%s)", strerror( errno ) );
-        goto vdev_failed;
-    }
-
-    if( ioctl( i_fd, VIDIOCGCAP, &p_sys->vid_cap ) < 0 )
-    {
-        msg_Err( p_demux, "cannot get capabilities (%s)", strerror( errno ) );
-        goto vdev_failed;
-    }
-
-    msg_Dbg( p_demux,
-             "V4L device %s %d channels %d audios %d < w < %d %d < h < %d",
-             p_sys->vid_cap.name,
-             p_sys->vid_cap.channels,
-             p_sys->vid_cap.audios,
-             p_sys->vid_cap.minwidth,  p_sys->vid_cap.maxwidth,
-             p_sys->vid_cap.minheight, p_sys->vid_cap.maxheight );
-
-    if( p_sys->i_channel < 0 || p_sys->i_channel >= p_sys->vid_cap.channels )
-    {
-        msg_Dbg( p_demux, "invalid channel, falling back on channel 0" );
-        p_sys->i_channel = 0;
-    }
-    if( p_sys->vid_cap.audios && p_sys->i_audio >= p_sys->vid_cap.audios )
-    {
-        msg_Dbg( p_demux, "invalid audio, falling back with no audio" );
-        p_sys->i_audio = -1;
-    }
-
-    if( p_sys->i_width < p_sys->vid_cap.minwidth ||
-        p_sys->i_width > p_sys->vid_cap.maxwidth )
-    {
-        msg_Dbg( p_demux, "invalid width %i", p_sys->i_width );
-        p_sys->i_width = 0;
-    }
-    if( p_sys->i_height < p_sys->vid_cap.minheight ||
-        p_sys->i_height > p_sys->vid_cap.maxheight )
-    {
-        msg_Dbg( p_demux, "invalid height %i", p_sys->i_height );
-        p_sys->i_height = 0;
-    }
-
-    if( !( p_sys->vid_cap.type & VID_TYPE_CAPTURE ) )
-    {
-        msg_Err( p_demux, "cannot grab" );
-        goto vdev_failed;
-    }
-
-    vid_channel.channel = p_sys->i_channel;
-    if( ioctl( i_fd, VIDIOCGCHAN, &vid_channel ) < 0 )
-    {
-        msg_Err( p_demux, "cannot get channel infos (%s)",
-                          strerror( errno ) );
-        goto vdev_failed;
-    }
-    msg_Dbg( p_demux,
-             "setting channel %s(%d) %d tuners flags=0x%x type=0x%x norm=0x%x",
-             vid_channel.name, vid_channel.channel, vid_channel.tuners,
-             vid_channel.flags, vid_channel.type, vid_channel.norm );
-
-    if( p_sys->i_tuner >= vid_channel.tuners )
-    {
-        msg_Dbg( p_demux, "invalid tuner, falling back on tuner 0" );
-        p_sys->i_tuner = 0;
-    }
-
-    vid_channel.norm = p_sys->i_norm;
-    if( ioctl( i_fd, VIDIOCSCHAN, &vid_channel ) < 0 )
-    {
-        msg_Err( p_demux, "cannot set channel (%s)", strerror( errno ) );
-        goto vdev_failed;
-    }
-
-    if( vid_channel.flags & VIDEO_VC_TUNER )
-    {
-
-        /* set tuner */
-#if 0
-        struct video_tuner vid_tuner;
-        if( p_sys->i_tuner >= 0 )
-        {
-            vid_tuner.tuner = p_sys->i_tuner;
-            if( ioctl( i_fd, VIDIOCGTUNER, &vid_tuner ) < 0 )
-            {
-                msg_Err( p_demux, "cannot get tuner (%s)", strerror( errno ) );
-                goto vdev_failed;
-            }
-            msg_Dbg( p_demux, "tuner %s low=%d high=%d, flags=0x%x "
-                     "mode=0x%x signal=0x%x",
-                     vid_tuner.name, vid_tuner.rangelow, vid_tuner.rangehigh,
-                     vid_tuner.flags, vid_tuner.mode, vid_tuner.signal );
-
-            msg_Dbg( p_demux, "setting tuner %s (%d)",
-                     vid_tuner.name, vid_tuner.tuner );
-
-            /* FIXME FIXME to be checked FIXME FIXME */
-            //vid_tuner.mode = p_sys->i_norm;
-            if( ioctl( i_fd, VIDIOCSTUNER, &vid_tuner ) < 0 )
-            {
-                msg_Err( p_demux, "cannot set tuner (%s)", strerror( errno ) );
-                goto vdev_failed;
-            }
-        }
-#endif
-
-        /* Show a warning if frequency is < than 30000.
-         * User is certainly usint old syntax. */
-
-
-        /* set frequency */
-        if( p_sys->i_frequency >= 0 )
-        {
-            int driver_frequency = p_sys->i_frequency * 16 /1000;
-            if( ioctl( i_fd, VIDIOCSFREQ, &driver_frequency ) < 0 )
-            {
-                msg_Err( p_demux, "cannot set frequency (%s)",
-                                  strerror( errno ) );
-                goto vdev_failed;
-            }
-            msg_Dbg( p_demux, "frequency %d (%d)", p_sys->i_frequency,
-                                                   driver_frequency );
-        }
-    }
-
-    /* set audio */
-    if( vid_channel.flags & VIDEO_VC_AUDIO )
-    {
-        struct video_audio      vid_audio;
-
-        /* XXX TODO volume, balance, ... */
-        if( p_sys->i_audio >= 0 )
-        {
-            vid_audio.audio = p_sys->i_audio;
-            if( ioctl( i_fd, VIDIOCGAUDIO, &vid_audio ) < 0 )
-            {
-                msg_Err( p_demux, "cannot get audio (%s)", strerror( errno ) );
-                goto vdev_failed;
-            }
-
-            /* unmute audio */
-            vid_audio.flags &= ~VIDEO_AUDIO_MUTE;
-
-            if( ioctl( i_fd, VIDIOCSAUDIO, &vid_audio ) < 0 )
-            {
-                msg_Err( p_demux, "cannot set audio (%s)", strerror( errno ) );
-                goto vdev_failed;
-            }
-        }
-
-    }
-
-    /* establish basic params with input and norm before feeling width
-     * or height */
-    if( p_sys->b_mjpeg )
-    {
-        struct quicktime_mjpeg_app1 *p_app1;
-        int32_t i_offset;
-
-        if( ioctl( i_fd, MJPIOC_G_PARAMS, &mjpeg ) < 0 )
-        {
-            msg_Err( p_demux, "cannot get mjpeg params (%s)",
-                              strerror( errno ) );
-            goto vdev_failed;
-        }
-        mjpeg.input = p_sys->i_channel;
-        mjpeg.norm  = p_sys->i_norm;
-        mjpeg.decimation = p_sys->i_decimation;
-
-        if( p_sys->i_width )
-            mjpeg.img_width = p_sys->i_width / p_sys->i_decimation;
-        if( p_sys->i_height )
-            mjpeg.img_height = p_sys->i_height / p_sys->i_decimation;
-
-        /* establish Quicktime APP1 marker while we are here */
-        mjpeg.APPn = 1;
-        mjpeg.APP_len = 40;
-
-        /* aligned */
-        p_app1 = (struct quicktime_mjpeg_app1 *)mjpeg.APP_data;
-        p_app1->i_reserved = 0;
-        p_app1->i_tag = VLC_FOURCC( 'm','j','p','g' );
-        p_app1->i_field_size = 0;
-        p_app1->i_padded_field_size = 0;
-        p_app1->i_next_field = 0;
-        /* XXX WARNING XXX */
-        /* these's nothing magic about these values.  We are dangerously
-         * assuming the encoder card is encoding mjpeg-a and is not throwing
-         * in marker tags we aren't expecting.  It's bad enough we have to
-         * search through the jpeg output for every frame we grab just to
-         * find the first field's end marker, so we take this risk to boost
-         * performance.
-         * This is really something the driver could do for us because this
-         * does conform to standards outside of Apple Quicktime.
-         */
-        i_offset = 0x2e;
-        p_app1->i_DQT_offset = hton32( i_offset );
-        i_offset = 0xb4;
-        p_app1->i_DHT_offset = hton32( i_offset );
-        i_offset = 0x258;
-        p_app1->i_SOF_offset = hton32( i_offset );
-        i_offset = 0x26b;
-        p_app1->i_SOS_offset = hton32( i_offset );
-        i_offset = 0x279;
-        p_app1->i_data_offset = hton32( i_offset );
-
-        /* SOF and SOS aren't specified by the mjpeg API because they aren't
-         * optional.  They will be present in the output. */
-        mjpeg.jpeg_markers = JPEG_MARKER_DHT | JPEG_MARKER_DQT;
-
-        if( ioctl( i_fd, MJPIOC_S_PARAMS, &mjpeg ) < 0 )
-        {
-            msg_Err( p_demux, "cannot set mjpeg params (%s)",
-                              strerror( errno ) );
-            goto vdev_failed;
-        }
-
-        p_sys->i_width = mjpeg.img_width * mjpeg.HorDcm;
-        p_sys->i_height = mjpeg.img_height * mjpeg.VerDcm *
-            mjpeg.field_per_buff;
-    }
-
-    /* fix width/height */
-    if( !p_sys->b_mjpeg && ( p_sys->i_width == 0 || p_sys->i_height == 0 ) )
-    {
-        struct video_window vid_win;
-
-        if( ioctl( i_fd, VIDIOCGWIN, &vid_win ) < 0 )
-        {
-            msg_Err( p_demux, "cannot get win (%s)", strerror( errno ) );
-            goto vdev_failed;
-        }
-        p_sys->i_width  = vid_win.width;
-        p_sys->i_height = vid_win.height;
-
-        if( !p_sys->i_width || !p_sys->i_height )
-        {
-            p_sys->i_width = p_sys->vid_cap.maxwidth;
-            p_sys->i_height = p_sys->vid_cap.maxheight;
-        }
-
-        if( !p_sys->i_width || !p_sys->i_height )
-        {
-            msg_Err( p_demux, "invalid video size (%ix%i)",
-                     p_sys->i_width, p_sys->i_height );
-            goto vdev_failed;
-        }
-
-        msg_Dbg( p_demux, "will use %dx%d", p_sys->i_width, p_sys->i_height );
-    }
-
-    if( !p_sys->b_mjpeg )
-    {
-        /* set hue/color/.. */
-        if( ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
-        {
-            struct video_picture vid_picture = p_sys->vid_picture;
-
-            if( p_sys->i_brightness >= 0 && p_sys->i_brightness < 65536 )
-            {
-                vid_picture.brightness = p_sys->i_brightness;
-            }
-            if( p_sys->i_colour >= 0 && p_sys->i_colour < 65536 )
-            {
-                vid_picture.colour = p_sys->i_colour;
-            }
-            if( p_sys->i_hue >= 0 && p_sys->i_hue < 65536 )
-            {
-                vid_picture.hue = p_sys->i_hue;
-            }
-            if( p_sys->i_contrast  >= 0 && p_sys->i_contrast < 65536 )
-            {
-                vid_picture.contrast = p_sys->i_contrast;
-            }
-            if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
-            {
-                msg_Dbg( p_demux, "v4l device uses brightness: %d",
-                         vid_picture.brightness );
-                msg_Dbg( p_demux, "v4l device uses colour: %d",
-                         vid_picture.colour );
-                msg_Dbg( p_demux, "v4l device uses hue: %d", vid_picture.hue );
-                msg_Dbg( p_demux, "v4l device uses contrast: %d",
-                         vid_picture.contrast );
-                p_sys->vid_picture = vid_picture;
-            }
-        }
-
-        /* Find out video format used by device */
-        if( ioctl( i_fd, VIDIOCGPICT, &p_sys->vid_picture ) == 0 )
-        {
-            struct video_picture vid_picture = p_sys->vid_picture;
-            char *psz;
-            int i;
-
-            vid_picture.palette = 0;
-            p_sys->i_fourcc = 0;
-
-            psz = var_CreateGetString( p_demux, "v4l-chroma" );
-            if( strlen( psz ) >= 4 )
-            {
-                int i_chroma = VLC_FOURCC( psz[0], psz[1], psz[2], psz[3] );
-
-                /* Find out v4l chroma code */
-                for( i = 0; v4lchroma_to_fourcc[i].i_v4l != 0; i++ )
-                {
-                    if( v4lchroma_to_fourcc[i].i_fourcc == i_chroma )
-                    {
-                        vid_picture.palette = v4lchroma_to_fourcc[i].i_v4l;
-                        break;
-                    }
-                }
-            }
-            free( psz );
-
-            if( vid_picture.palette &&
-                !ioctl( i_fd, VIDIOCSPICT, &vid_picture ) )
-            {
-                p_sys->vid_picture = vid_picture;
-            }
-            else
-            {
-                /* Try to set the format to something easy to encode */
-                vid_picture.palette = VIDEO_PALETTE_YUV420P;
-                if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
-                {
-                    p_sys->vid_picture = vid_picture;
-                }
-                else
-                {
-                    vid_picture.palette = VIDEO_PALETTE_YUV422P;
-                    if( ioctl( i_fd, VIDIOCSPICT, &vid_picture ) == 0 )
-                    {
-                        p_sys->vid_picture = vid_picture;
-                    }
-                }
-            }
-
-            /* Find out final format */
-            for( i = 0; v4lchroma_to_fourcc[i].i_v4l != 0; i++ )
-            {
-                if( v4lchroma_to_fourcc[i].i_v4l == p_sys->vid_picture.palette)
-                {
-                    p_sys->i_fourcc = v4lchroma_to_fourcc[i].i_fourcc;
-                    break;
-                }
-            }
-        }
-        else
-        {
-            msg_Err( p_demux, "ioctl VIDIOCGPICT failed" );
-            goto vdev_failed;
-        }
-    }
-
-    if( p_sys->b_mjpeg )
-    {
-        int i;
-
-        p_sys->mjpeg_buffers.count = 8;
-        p_sys->mjpeg_buffers.size = MJPEG_BUFFER_SIZE;
-
-        if( ioctl( i_fd, MJPIOC_REQBUFS, &p_sys->mjpeg_buffers ) < 0 )
-        {
-            msg_Err( p_demux, "mmap unsupported" );
-            goto vdev_failed;
-        }
-
-        p_sys->p_video_mmap = mmap( 0,
-                p_sys->mjpeg_buffers.size * p_sys->mjpeg_buffers.count,
-                PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, 0 );
-        if( p_sys->p_video_mmap == MAP_FAILED )
-        {
-            msg_Err( p_demux, "mmap failed" );
-            goto vdev_failed;
-        }
-
-        p_sys->i_fourcc  = VLC_FOURCC( 'm','j','p','g' );
-        p_sys->i_frame_pos = -1;
-
-        /* queue up all the frames */
-        for( i = 0; i < (int)p_sys->mjpeg_buffers.count; i++ )
-        {
-            if( ioctl( i_fd, MJPIOC_QBUF_CAPT, &i ) < 0 )
-            {
-                msg_Err( p_demux, "unable to queue frame" );
-                goto vdev_failed;
-            }
-        }
-    }
-    else
-    {
-        /* Fill in picture_t fields */
-        vout_InitPicture( VLC_OBJECT(p_demux), &p_sys->pic, p_sys->i_fourcc,
-                          p_sys->i_width, p_sys->i_height, p_sys->i_width *
-                          VOUT_ASPECT_FACTOR / p_sys->i_height );
-        if( !p_sys->pic.i_planes )
-        {
-            msg_Err( p_demux, "unsupported chroma" );
-            goto vdev_failed;
-        }
-        p_sys->i_video_frame_size = 0;
-        for( i = 0; i < p_sys->pic.i_planes; i++ )
-        {
-            p_sys->i_video_frame_size += p_sys->pic.p[i].i_visible_lines *
-              p_sys->pic.p[i].i_visible_pitch;
-        }
-
-        msg_Dbg( p_demux, "v4l device uses frame size: %i",
-                 p_sys->i_video_frame_size );
-        msg_Dbg( p_demux, "v4l device uses chroma: %4.4s",
-                (char*)&p_sys->i_fourcc );
-
-        /* Allocate mmap buffer */
-        if( ioctl( i_fd, VIDIOCGMBUF, &p_sys->vid_mbuf ) < 0 )
-        {
-            msg_Err( p_demux, "mmap unsupported" );
-            goto vdev_failed;
-        }
-
-        p_sys->p_video_mmap = mmap( 0, p_sys->vid_mbuf.size,
-                                    PROT_READ|PROT_WRITE, MAP_SHARED,
-                                    i_fd, 0 );
-        if( p_sys->p_video_mmap == MAP_FAILED )
-        {
-            /* FIXME -> normal read */
-            msg_Err( p_demux, "mmap failed" );
-            goto vdev_failed;
-        }
-
-        /* init grabbing */
-        p_sys->vid_mmap.frame  = 0;
-        p_sys->vid_mmap.width  = p_sys->i_width;
-        p_sys->vid_mmap.height = p_sys->i_height;
-        p_sys->vid_mmap.format = p_sys->vid_picture.palette;
-        if( ioctl( i_fd, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
-        {
-            msg_Warn( p_demux, "%4.4s refused", (char*)&p_sys->i_fourcc );
-            msg_Err( p_demux, "chroma selection failed" );
-            goto vdev_failed;
-        }
-    }
-    return i_fd;
-
-vdev_failed:
-
-    if( i_fd >= 0 ) close( i_fd );
-    return -1;
-}
-
-/*****************************************************************************
- * OpenAudioDev:
- *****************************************************************************/
-static int OpenAudioDev( demux_t *p_demux, char *psz_device )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    int i_fd, i_format;
-
-    if( (i_fd = open( psz_device, O_RDONLY | O_NONBLOCK )) < 0 )
-    {
-        msg_Err( p_demux, "cannot open audio device (%s)", strerror( errno ) );
-        goto adev_fail;
-    }
-
-    i_format = AFMT_S16_LE;
-    if( ioctl( i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0
-        || i_format != AFMT_S16_LE )
-    {
-        msg_Err( p_demux, "cannot set audio format (16b little endian) "
-                 "(%s)", strerror( errno ) );
-        goto adev_fail;
-    }
-
-    if( ioctl( i_fd, SNDCTL_DSP_STEREO,
-               &p_sys->b_stereo ) < 0 )
-    {
-        msg_Err( p_demux, "cannot set audio channels count (%s)",
-                 strerror( errno ) );
-        goto adev_fail;
-    }
-
-    if( ioctl( i_fd, SNDCTL_DSP_SPEED,
-               &p_sys->i_sample_rate ) < 0 )
-    {
-        msg_Err( p_demux, "cannot set audio sample rate (%s)",
-                 strerror( errno ) );
-        goto adev_fail;
-    }
-
-    msg_Dbg( p_demux, "openened adev=`%s' %s %dHz",
-             psz_device, p_sys->b_stereo ? "stereo" : "mono",
-             p_sys->i_sample_rate );
-
-    p_sys->i_audio_max_frame_size = 6 * 1024;
-
-    return i_fd;
-
- adev_fail:
-
-    if( i_fd >= 0 ) close( i_fd );
-    return -1;
-}
-
-/*****************************************************************************
- * GrabAudio: grab audio
- *****************************************************************************/
-static block_t *GrabAudio( demux_t *p_demux )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    struct audio_buf_info buf_info;
-    int i_read, i_correct;
-    block_t *p_block;
-
-    if( p_sys->p_block_audio ) p_block = p_sys->p_block_audio;
-    else p_block = block_New( p_demux, p_sys->i_audio_max_frame_size );
-
-    if( !p_block )
-    {
-        msg_Warn( p_demux, "cannot get block" );
-        return 0;
-    }
-
-    p_sys->p_block_audio = p_block;
-
-    i_read = read( p_sys->fd_audio, p_block->p_buffer,
-                   p_sys->i_audio_max_frame_size );
-
-    if( i_read <= 0 ) return 0;
-
-    p_block->i_buffer = i_read;
-    p_sys->p_block_audio = 0;
-
-    /* Correct the date because of kernel buffering */
-    i_correct = i_read;
-    if( ioctl( p_sys->fd_audio, SNDCTL_DSP_GETISPACE, &buf_info ) == 0 )
-    {
-        i_correct += buf_info.bytes;
-    }
-
-    p_block->i_pts = p_block->i_dts =
-        mdate() - I64C(1000000) * (mtime_t)i_correct /
-        2 / ( p_sys->b_stereo ? 2 : 1) / p_sys->i_sample_rate;
-
-    return p_block;
-}
-
-/*****************************************************************************
- * GrabVideo:
- *****************************************************************************/
-static uint8_t *GrabCapture( demux_t *p_demux )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    int i_captured_frame = p_sys->i_frame_pos;
-
-    p_sys->vid_mmap.frame = (p_sys->i_frame_pos + 1) % p_sys->vid_mbuf.frames;
-
-    while( ioctl( p_sys->fd_video, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
-    {
-        if( errno != EAGAIN )
-        {
-            msg_Err( p_demux, "failed capturing new frame" );
-            return NULL;
-        }
-
-        if( p_demux->b_die )
-        {
-            return NULL;
-        }
-
-        msg_Dbg( p_demux, "grab failed, trying again" );
-    }
-
-    while( ioctl(p_sys->fd_video, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
-    {
-        if( errno != EAGAIN && errno != EINTR )    
-        {
-            msg_Err( p_demux, "failed syncing new frame" );
-            return NULL;
-        }
-    }
-
-    p_sys->i_frame_pos = p_sys->vid_mmap.frame;
-    /* leave i_video_frame_size alone */
-    return p_sys->p_video_mmap + p_sys->vid_mbuf.offsets[i_captured_frame];
-}
-
-static uint8_t *GrabMJPEG( demux_t *p_demux )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    struct mjpeg_sync sync;
-    uint8_t *p_frame, *p_field, *p;
-    uint16_t tag;
-    uint32_t i_size;
-    struct quicktime_mjpeg_app1 *p_app1 = NULL;
-
-    /* re-queue the last frame we sync'd */
-    if( p_sys->i_frame_pos != -1 )
-    {
-        while( ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT,
-                                       &p_sys->i_frame_pos ) < 0 )
-        {
-            if( errno != EAGAIN && errno != EINTR )
-            {
-                msg_Err( p_demux, "failed capturing new frame" );
-                return NULL;
-            }
-        }
-    }
-
-    /* sync on the next frame */
-    while( ioctl( p_sys->fd_video, MJPIOC_SYNC, &sync ) < 0 )
-    {
-        if( errno != EAGAIN && errno != EINTR )    
-        {
-            msg_Err( p_demux, "failed syncing new frame" );
-            return NULL;
-        }
-    }
-
-    p_sys->i_frame_pos = sync.frame;
-    p_frame = p_sys->p_video_mmap + p_sys->mjpeg_buffers.size * sync.frame;
-
-    /* p_frame now points to the data.  fix up the Quicktime APP1 marker */
-    tag = 0xffd9;
-    tag = hton16( tag );
-    p_field = p_frame;
-
-    /* look for EOI */
-    p = memmem( p_field, sync.length, &tag, 2 );
-
-    if( p )
-    {
-        p += 2; /* data immediately following EOI */
-        /* UNALIGNED! */
-        p_app1 = (struct quicktime_mjpeg_app1 *)(p_field + 6);
-
-        i_size = ((uint32_t)(p - p_field));
-        i_size = hton32( i_size );
-        memcpy( &p_app1->i_field_size, &i_size, 4 );
-
-        while( *p == 0xff && *(p+1) == 0xff )
-            p++;
-
-        i_size = ((uint32_t)(p - p_field));
-        i_size = hton32( i_size );
-        memcpy( &p_app1->i_padded_field_size, &i_size, 4 );
-    }
-
-    tag = 0xffd8;
-    tag = hton16( tag );
-    p_field = memmem( p, sync.length - (size_t)(p - p_frame), &tag, 2 );
-
-    if( p_field )
-    {
-        i_size = (uint32_t)(p_field - p_frame);
-        i_size = hton32( i_size );
-        memcpy( &p_app1->i_next_field, &i_size, 4 );
-
-        /* UNALIGNED! */
-        p_app1 = (struct quicktime_mjpeg_app1 *)(p_field + 6);
-        tag = 0xffd9;
-        tag = hton16( tag );
-        p = memmem( p_field, sync.length - (size_t)(p_field - p_frame),
-                &tag, 2 );
-
-        if( !p )
-        {
-            /* sometimes the second field doesn't have the EOI.  just put it
-             * there
-             */
-            p = p_frame + sync.length;
-            memcpy( p, &tag, 2 );
-            sync.length += 2;
-        }
-
-        p += 2;
-        i_size = (uint32_t)(p - p_field);
-        i_size = hton32( i_size );
-        memcpy( &p_app1->i_field_size, &i_size, 4 );
-        i_size = (uint32_t)(sync.length - (uint32_t)(p_field - p_frame));
-        i_size = hton32( i_size );
-        memcpy( &p_app1->i_padded_field_size, &i_size, 4 );
-    }
-
-    p_sys->i_video_frame_size = sync.length;
-    return p_frame;
-}
-
-static block_t *GrabVideo( demux_t *p_demux )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    uint8_t     *p_frame;
-    block_t     *p_block;
-
-    if( p_sys->f_fps >= 0.1 && p_sys->i_video_pts > 0 )
-    {
-        mtime_t i_dur = (mtime_t)((double)1000000 / (double)p_sys->f_fps);
-
-        /* Did we wait long enough ? (frame rate reduction) */
-        if( p_sys->i_video_pts + i_dur > mdate() ) return 0;
-    }
-
-    if( p_sys->b_mjpeg ) p_frame = GrabMJPEG( p_demux );
-    else p_frame = GrabCapture( p_demux );
-
-    if( !p_frame ) return 0;
-
-    if( !( p_block = block_New( p_demux, p_sys->i_video_frame_size ) ) )
-    {
-        msg_Warn( p_demux, "cannot get block" );
-        return 0;
-    }
-
-    memcpy( p_block->p_buffer, p_frame, p_sys->i_video_frame_size );
-    p_sys->i_video_pts = p_block->i_pts = p_block->i_dts = mdate();
-
-    return p_block;
-}
diff --git a/modules/access/v4l/videodev_mjpeg.h b/modules/access/v4l/videodev_mjpeg.h
deleted file mode 100644 (file)
index 116a0c0..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*****************************************************************************
- * Copyright (C) lavrec (see http://mjpeg.sourceforge.net)
- * ( XXX This file was get from the driver-zoran package and it is under GPL)
- *
- * $Id$
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- *****************************************************************************/
-
-/* These are the MJPEG API extensions for the Video4Linux API,
-   first introduced by the Iomega Buz driver by Rainer Johanni
-   <rainer@johanni.de>
-*/
-
-/* This is identical with the mgavideo internal params struct,
-   please tell me if you change this struct here ! <gz@lysator.liu.se) */
-struct mjpeg_params
-{
-
-   /* The following parameters can only be queried */
-
-   int major_version;            /* Major version number of driver */
-   int minor_version;            /* Minor version number of driver */
-
-   /* Main control parameters */
-
-   int input;                    /* Input channel: 0 = Composite, 1 = S-VHS */
-   int norm;                     /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
-   int decimation;               /* decimation of captured video,
-                                    enlargement of video played back.
-                                    Valid values are 1, 2, 4 or 0.
-                                    0 is a special value where the user
-                                    has full control over video scaling */
-
-   /* The following parameters only have to be set if decimation==0,
-      for other values of decimation they provide the data how the image is captured */
-
-   int HorDcm;                    /* Horizontal decimation: 1, 2 or 4 */
-   int VerDcm;                    /* Vertical decimation: 1 or 2 */
-   int TmpDcm;                    /* Temporal decimation: 1 or 2,
-                                     if TmpDcm==2 in capture every second frame is dropped,
-                                     in playback every frame is played twice */
-   int field_per_buff;            /* Number of fields per buffer: 1 or 2 */
-   int img_x;                     /* start of image in x direction */
-   int img_y;                     /* start of image in y direction */
-   int img_width;                 /* image width BEFORE decimation,
-                                     must be a multiple of HorDcm*16 */
-   int img_height;                /* image height BEFORE decimation,
-                                     must be a multiple of VerDcm*8 */
-
-   /* --- End of parameters for decimation==0 only --- */
-
-   /* JPEG control parameters */
-
-   int  quality;                  /* Measure for quality of compressed images.
-                                     Scales linearly with the size of the compressed images.
-                                     Must be beetween 0 and 100, 100 is a compression
-                                     ratio of 1:4 */
-
-   int  odd_even;                 /* Which field should come first ???
-                                     This is more aptly named "top_first",
-                                     i.e. (odd_even==1) --> top-field-first */
-
-   int  APPn;                     /* Number of APP segment to be written, must be 0..15 */
-   int  APP_len;                  /* Length of data in JPEG APPn segment */
-   char APP_data[60];             /* Data in the JPEG APPn segment. */
-
-   int  COM_len;                  /* Length of data in JPEG COM segment */
-   char COM_data[60];             /* Data in JPEG COM segment */
-
-   unsigned long jpeg_markers;    /* Which markers should go into the JPEG output.
-                                     Unless you exactly know what you do, leave them untouched.
-                                     Inluding less markers will make the resulting code
-                                     smaller, but there will be fewer aplications
-                                     which can read it.
-                                     The presence of the APP and COM marker is
-                                     influenced by APP0_len and COM_len ONLY! */
-#define JPEG_MARKER_DHT (1<<3)    /* Define Huffman Tables */
-#define JPEG_MARKER_DQT (1<<4)    /* Define Quantization Tables */
-#define JPEG_MARKER_DRI (1<<5)    /* Define Restart Interval */
-#define JPEG_MARKER_COM (1<<6)    /* Comment segment */
-#define JPEG_MARKER_APP (1<<7)    /* App segment, driver will allways use APP0 */
-
-   int  VFIFO_FB;        /* Flag for enabling Video Fifo Feedback.
-                            If this flag is turned on and JPEG decompressing
-                            is going to the screen, the decompress process
-                            is stopped every time the Video Fifo is full.
-                            This enables a smooth decompress to the screen
-                            but the video output signal will get scrambled */
-
-   /* Misc */
-
-    char reserved[312];  /* Makes 512 bytes for this structure */
-};
-
-struct mjpeg_requestbuffers
-{
-   unsigned long count;      /* Number of buffers for MJPEG grabbing */
-   unsigned long size;       /* Size PER BUFFER in bytes */
-};
-
-struct mjpeg_sync
-{
-   unsigned long frame;      /* Frame (0 - n) for double buffer */
-   unsigned long length;     /* number of code bytes in buffer (capture only) */
-   unsigned long seq;        /* frame sequence number */
-   struct timeval timestamp; /* timestamp */
-};
-
-struct mjpeg_status
-{
-   int input;                /* Input channel, has to be set prior to BUZIOC_G_STATUS */
-   int signal;               /* Returned: 1 if valid video signal detected */
-   int norm;                 /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
-   int color;                /* Returned: 1 if color signal detected */
-};
-
-/*
-Private IOCTL to set up for displaying MJPEG
-*/
-#define MJPIOC_G_PARAMS       _IOR ('v', BASE_VIDIOCPRIVATE+0,  struct mjpeg_params)
-#define MJPIOC_S_PARAMS       _IOWR('v', BASE_VIDIOCPRIVATE+1,  struct mjpeg_params)
-#define MJPIOC_REQBUFS        _IOWR('v', BASE_VIDIOCPRIVATE+2,  struct mjpeg_requestbuffers)
-#define MJPIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOCPRIVATE+3,  int)
-#define MJPIOC_QBUF_PLAY      _IOW ('v', BASE_VIDIOCPRIVATE+4,  int)
-#define MJPIOC_SYNC           _IOR ('v', BASE_VIDIOCPRIVATE+5,  struct mjpeg_sync)
-#define MJPIOC_G_STATUS       _IOWR('v', BASE_VIDIOCPRIVATE+6,  struct mjpeg_status)
diff --git a/modules/access/videodev2.h b/modules/access/videodev2.h
new file mode 100644 (file)
index 0000000..a358497
--- /dev/null
@@ -0,0 +1,858 @@
+#ifndef __LINUX_VIDEODEV2_H
+#define __LINUX_VIDEODEV2_H
+/*
+ *     Video for Linux Two
+ *
+ *     Header file for v4l or V4L2 drivers and applications, for
+ *     Linux kernels 2.2.x or 2.4.x.
+ *
+ *     See http://bytesex.org/v4l/ for API specs and other
+ *     v4l2 documentation.
+ *
+ *     Author: Bill Dirks <bdirks@pacbell.net>
+ *             Justin Schoeman
+ *             et al.
+ */
+
+/*
+ *     M I S C E L L A N E O U S
+ */
+
+/*  Four-character-code (FOURCC) */
+#define v4l2_fourcc(a,b,c,d)\
+        (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))
+
+/*
+ *     E N U M S
+ */
+enum v4l2_field {
+       V4L2_FIELD_ANY        = 0, /* driver can choose from none,
+                                     top, bottom, interlaced
+                                     depending on whatever it thinks
+                                     is approximate ... */
+       V4L2_FIELD_NONE       = 1, /* this device has no fields ... */
+       V4L2_FIELD_TOP        = 2, /* top field only */
+       V4L2_FIELD_BOTTOM     = 3, /* bottom field only */
+       V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */
+       V4L2_FIELD_SEQ_TB     = 5, /* both fields sequential into one
+                                     buffer, top-bottom order */
+       V4L2_FIELD_SEQ_BT     = 6, /* same as above + bottom-top order */
+       V4L2_FIELD_ALTERNATE  = 7, /* both fields alternating into
+                                     separate buffers */
+};
+#define V4L2_FIELD_HAS_TOP(field)      \
+       ((field) == V4L2_FIELD_TOP      ||\
+        (field) == V4L2_FIELD_INTERLACED ||\
+        (field) == V4L2_FIELD_SEQ_TB   ||\
+        (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTTOM(field)   \
+       ((field) == V4L2_FIELD_BOTTOM   ||\
+        (field) == V4L2_FIELD_INTERLACED ||\
+        (field) == V4L2_FIELD_SEQ_TB   ||\
+        (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTH(field)     \
+       ((field) == V4L2_FIELD_INTERLACED ||\
+        (field) == V4L2_FIELD_SEQ_TB   ||\
+        (field) == V4L2_FIELD_SEQ_BT)
+
+enum v4l2_buf_type {
+       V4L2_BUF_TYPE_VIDEO_CAPTURE  = 1,
+       V4L2_BUF_TYPE_VIDEO_OUTPUT   = 2,
+       V4L2_BUF_TYPE_VIDEO_OVERLAY  = 3,
+       V4L2_BUF_TYPE_VBI_CAPTURE    = 4,
+       V4L2_BUF_TYPE_VBI_OUTPUT     = 5,
+       V4L2_BUF_TYPE_PRIVATE        = 0x80,
+};
+
+enum v4l2_ctrl_type {
+       V4L2_CTRL_TYPE_INTEGER       = 1,
+       V4L2_CTRL_TYPE_BOOLEAN       = 2,
+       V4L2_CTRL_TYPE_MENU          = 3,
+       V4L2_CTRL_TYPE_BUTTON        = 4,
+};
+
+enum v4l2_tuner_type {
+       V4L2_TUNER_RADIO             = 1,
+       V4L2_TUNER_ANALOG_TV         = 2,
+};
+
+enum v4l2_memory {
+       V4L2_MEMORY_MMAP             = 1,
+       V4L2_MEMORY_USERPTR          = 2,
+       V4L2_MEMORY_OVERLAY          = 3,
+};
+
+/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
+enum v4l2_colorspace {
+       /* ITU-R 601 -- broadcast NTSC/PAL */
+       V4L2_COLORSPACE_SMPTE170M     = 1,
+
+       /* 1125-Line (US) HDTV */
+       V4L2_COLORSPACE_SMPTE240M     = 2,
+
+       /* HD and modern captures. */
+       V4L2_COLORSPACE_REC709        = 3,
+       
+       /* broken BT878 extents (601, luma range 16-253 instead of 16-235) */
+       V4L2_COLORSPACE_BT878         = 4,
+       
+       /* These should be useful.  Assume 601 extents. */
+       V4L2_COLORSPACE_470_SYSTEM_M  = 5,
+       V4L2_COLORSPACE_470_SYSTEM_BG = 6,
+       
+       /* I know there will be cameras that send this.  So, this is
+        * unspecified chromaticities and full 0-255 on each of the
+        * Y'CbCr components
+        */
+       V4L2_COLORSPACE_JPEG          = 7,
+       
+       /* For RGB colourspaces, this is probably a good start. */
+       V4L2_COLORSPACE_SRGB          = 8,
+};
+
+struct v4l2_rect {
+       __s32   left;
+       __s32   top;
+       __s32   width;
+       __s32   height;
+};
+
+struct v4l2_fract {
+       __u32   numerator;
+       __u32   denominator;
+};
+
+/*
+ *     D R I V E R   C A P A B I L I T I E S
+ */
+struct v4l2_capability
+{
+       __u8    driver[16];     /* i.e. "bttv" */
+       __u8    card[32];       /* i.e. "Hauppauge WinTV" */
+       __u8    bus_info[32];   /* "PCI:" + pci_dev->slot_name */
+       __u32   version;        /* should use KERNEL_VERSION() */
+       __u32   capabilities;   /* Device capabilities */
+       __u32   reserved[4];
+};
+
+/* Values for 'capabilities' field */
+#define V4L2_CAP_VIDEO_CAPTURE 0x00000001  /* Is a video capture device */
+#define V4L2_CAP_VIDEO_OUTPUT  0x00000002  /* Is a video output device */
+#define V4L2_CAP_VIDEO_OVERLAY 0x00000004  /* Can do video overlay */
+#define V4L2_CAP_VBI_CAPTURE   0x00000010  /* Is a VBI capture device */
+#define V4L2_CAP_VBI_OUTPUT    0x00000020  /* Is a VBI output device */
+#define V4L2_CAP_RDS_CAPTURE   0x00000100  /* RDS data capture */
+
+#define V4L2_CAP_TUNER         0x00010000  /* Has a tuner */
+#define V4L2_CAP_AUDIO         0x00020000  /* has audio support */
+
+#define V4L2_CAP_READWRITE      0x01000000  /* read/write systemcalls */
+#define V4L2_CAP_ASYNCIO        0x02000000  /* async I/O */
+#define V4L2_CAP_STREAMING      0x04000000  /* streaming I/O ioctls */
+
+/*
+ *     V I D E O   I M A G E   F O R M A T
+ */
+
+struct v4l2_pix_format
+{
+       __u32                   width;
+       __u32                   height;
+       __u32                   pixelformat;
+       enum v4l2_field         field;
+       __u32                   bytesperline;   /* for padding, zero if unused */
+       __u32                   sizeimage;
+        enum v4l2_colorspace   colorspace;
+       __u32                   priv;           /* private data, depends on pixelformat */
+};
+
+/*           Pixel format    FOURCC                  depth  Description   */
+#define V4L2_PIX_FMT_RGB332  v4l2_fourcc('R','G','B','1') /*  8  RGB-3-3-2     */
+#define V4L2_PIX_FMT_RGB555  v4l2_fourcc('R','G','B','O') /* 16  RGB-5-5-5     */
+#define V4L2_PIX_FMT_RGB565  v4l2_fourcc('R','G','B','P') /* 16  RGB-5-6-5     */
+#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16  RGB-5-5-5 BE  */
+#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R','G','B','R') /* 16  RGB-5-6-5 BE  */
+#define V4L2_PIX_FMT_BGR24   v4l2_fourcc('B','G','R','3') /* 24  BGR-8-8-8     */
+#define V4L2_PIX_FMT_RGB24   v4l2_fourcc('R','G','B','3') /* 24  RGB-8-8-8     */
+#define V4L2_PIX_FMT_BGR32   v4l2_fourcc('B','G','R','4') /* 32  BGR-8-8-8-8   */
+#define V4L2_PIX_FMT_RGB32   v4l2_fourcc('R','G','B','4') /* 32  RGB-8-8-8-8   */
+#define V4L2_PIX_FMT_GREY    v4l2_fourcc('G','R','E','Y') /*  8  Greyscale     */
+#define V4L2_PIX_FMT_YVU410  v4l2_fourcc('Y','V','U','9') /*  9  YVU 4:1:0     */
+#define V4L2_PIX_FMT_YVU420  v4l2_fourcc('Y','V','1','2') /* 12  YVU 4:2:0     */
+#define V4L2_PIX_FMT_YUYV    v4l2_fourcc('Y','U','Y','V') /* 16  YUV 4:2:2     */
+#define V4L2_PIX_FMT_UYVY    v4l2_fourcc('U','Y','V','Y') /* 16  YUV 4:2:2     */
+#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16  YVU422 planar */
+#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16  YVU411 planar */
+#define V4L2_PIX_FMT_Y41P    v4l2_fourcc('Y','4','1','P') /* 12  YUV 4:1:1     */
+
+/* two planes -- one Y, one Cr + Cb interleaved  */
+#define V4L2_PIX_FMT_NV12    v4l2_fourcc('N','V','1','2') /* 12  Y/CbCr 4:2:0  */
+#define V4L2_PIX_FMT_NV21    v4l2_fourcc('N','V','2','1') /* 12  Y/CrCb 4:2:0  */
+
+/*  The following formats are not defined in the V4L2 specification */
+#define V4L2_PIX_FMT_YUV410  v4l2_fourcc('Y','U','V','9') /*  9  YUV 4:1:0     */
+#define V4L2_PIX_FMT_YUV420  v4l2_fourcc('Y','U','1','2') /* 12  YUV 4:2:0     */
+#define V4L2_PIX_FMT_YYUV    v4l2_fourcc('Y','Y','U','V') /* 16  YUV 4:2:2     */
+#define V4L2_PIX_FMT_HI240   v4l2_fourcc('H','I','2','4') /*  8  8-bit color   */
+
+/* compressed formats */
+#define V4L2_PIX_FMT_MJPEG    v4l2_fourcc('M','J','P','G') /* Motion-JPEG   */
+#define V4L2_PIX_FMT_JPEG     v4l2_fourcc('J','P','E','G') /* JFIF JPEG     */
+#define V4L2_PIX_FMT_DV       v4l2_fourcc('d','v','s','d') /* 1394          */
+#define V4L2_PIX_FMT_MPEG     v4l2_fourcc('M','P','E','G') /* MPEG          */
+
+/*  Vendor-specific formats   */
+#define V4L2_PIX_FMT_WNVA    v4l2_fourcc('W','N','V','A') /* Winnov hw compres */
+
+/*
+ *     F O R M A T   E N U M E R A T I O N
+ */
+struct v4l2_fmtdesc
+{
+       __u32               index;             /* Format number      */
+       enum v4l2_buf_type  type;              /* buffer type        */
+       __u32               flags;
+       __u8                description[32];   /* Description string */
+       __u32               pixelformat;       /* Format fourcc      */
+       __u32               reserved[4];
+};
+
+#define V4L2_FMT_FLAG_COMPRESSED 0x0001
+
+
+/*
+ *     T I M E C O D E
+ */
+struct v4l2_timecode
+{
+       __u32   type;
+       __u32   flags;
+       __u8    frames;
+       __u8    seconds;
+       __u8    minutes;
+       __u8    hours;
+       __u8    userbits[4];
+};
+
+/*  Type  */
+#define V4L2_TC_TYPE_24FPS             1
+#define V4L2_TC_TYPE_25FPS             2
+#define V4L2_TC_TYPE_30FPS             3
+#define V4L2_TC_TYPE_50FPS             4
+#define V4L2_TC_TYPE_60FPS             5
+
+/*  Flags  */
+#define V4L2_TC_FLAG_DROPFRAME         0x0001 /* "drop-frame" mode */
+#define V4L2_TC_FLAG_COLORFRAME                0x0002
+#define V4L2_TC_USERBITS_field         0x000C
+#define V4L2_TC_USERBITS_USERDEFINED   0x0000
+#define V4L2_TC_USERBITS_8BITCHARS     0x0008
+/* The above is based on SMPTE timecodes */
+
+
+/*
+ *     C O M P R E S S I O N   P A R A M E T E R S
+ */
+#if 0
+/* ### generic compression settings don't work, there is too much
+ * ### codec-specific stuff.  Maybe reuse that for MPEG codec settings
+ * ### later ... */
+struct v4l2_compression
+{
+       __u32   quality;
+       __u32   keyframerate;
+       __u32   pframerate;
+       __u32   reserved[5];
+};
+#endif
+
+struct v4l2_jpegcompression
+{
+       int quality;
+
+       int  APPn;              /* Number of APP segment to be written,
+                                * must be 0..15 */
+       int  APP_len;           /* Length of data in JPEG APPn segment */
+       char APP_data[60];      /* Data in the JPEG APPn segment. */
+       
+       int  COM_len;           /* Length of data in JPEG COM segment */
+       char COM_data[60];      /* Data in JPEG COM segment */
+       
+       __u32 jpeg_markers;     /* Which markers should go into the JPEG
+                                * output. Unless you exactly know what
+                                * you do, leave them untouched.
+                                * Inluding less markers will make the
+                                * resulting code smaller, but there will
+                                * be fewer aplications which can read it.
+                                * The presence of the APP and COM marker
+                                * is influenced by APP_len and COM_len
+                                * ONLY, not by this property! */
+       
+#define V4L2_JPEG_MARKER_DHT (1<<3)    /* Define Huffman Tables */
+#define V4L2_JPEG_MARKER_DQT (1<<4)    /* Define Quantization Tables */
+#define V4L2_JPEG_MARKER_DRI (1<<5)    /* Define Restart Interval */
+#define V4L2_JPEG_MARKER_COM (1<<6)    /* Comment segment */
+#define V4L2_JPEG_MARKER_APP (1<<7)    /* App segment, driver will
+                                        * allways use APP0 */
+};
+
+
+/*
+ *     M E M O R Y - M A P P I N G   B U F F E R S
+ */
+struct v4l2_requestbuffers
+{
+       __u32                   count;
+       enum v4l2_buf_type      type;
+       enum v4l2_memory        memory;
+       __u32                   reserved[2];
+};
+
+struct v4l2_buffer
+{
+       __u32                   index;
+       enum v4l2_buf_type      type;
+       __u32                   bytesused;
+       __u32                   flags;
+       enum v4l2_field         field;
+       struct timeval          timestamp;
+       struct v4l2_timecode    timecode;
+       __u32                   sequence;
+
+       /* memory location */
+       enum v4l2_memory        memory;
+       union {
+               __u32           offset;
+               unsigned long   userptr;
+       } m;
+       __u32                   length;
+
+       __u32                   reserved[2];
+};
+
+/*  Flags for 'flags' field */
+#define V4L2_BUF_FLAG_MAPPED   0x0001  /* Buffer is mapped (flag) */
+#define V4L2_BUF_FLAG_QUEUED   0x0002  /* Buffer is queued for processing */
+#define V4L2_BUF_FLAG_DONE     0x0004  /* Buffer is ready */
+#define V4L2_BUF_FLAG_KEYFRAME 0x0008  /* Image is a keyframe (I-frame) */
+#define V4L2_BUF_FLAG_PFRAME   0x0010  /* Image is a P-frame */
+#define V4L2_BUF_FLAG_BFRAME   0x0020  /* Image is a B-frame */
+#define V4L2_BUF_FLAG_TIMECODE 0x0100  /* timecode field is valid */
+
+/*
+ *     O V E R L A Y   P R E V I E W
+ */
+struct v4l2_framebuffer
+{
+       __u32                   capability;
+       __u32                   flags;
+/* FIXME: in theory we should pass something like PCI device + memory
+ * region + offset instead of some physical address */
+       void*                   base;
+       struct v4l2_pix_format  fmt;
+};
+/*  Flags for the 'capability' field. Read only */
+#define V4L2_FBUF_CAP_EXTERNOVERLAY    0x0001
+#define V4L2_FBUF_CAP_CHROMAKEY                0x0002
+#define V4L2_FBUF_CAP_LIST_CLIPPING     0x0004
+#define V4L2_FBUF_CAP_BITMAP_CLIPPING  0x0008
+/*  Flags for the 'flags' field. */
+#define V4L2_FBUF_FLAG_PRIMARY         0x0001
+#define V4L2_FBUF_FLAG_OVERLAY         0x0002
+#define V4L2_FBUF_FLAG_CHROMAKEY       0x0004
+
+struct v4l2_clip
+{
+       struct v4l2_rect        c;
+       struct v4l2_clip        *next;
+};
+
+struct v4l2_window
+{
+       struct v4l2_rect        w;
+       enum v4l2_field         field;
+       __u32                   chromakey;
+       struct v4l2_clip        *clips;
+       __u32                   clipcount;
+       void                    *bitmap;
+};
+
+
+/*
+ *     C A P T U R E   P A R A M E T E R S
+ */
+struct v4l2_captureparm
+{
+       __u32              capability;    /*  Supported modes */
+       __u32              capturemode;   /*  Current mode */
+       struct v4l2_fract  timeperframe;  /*  Time per frame in .1us units */
+       __u32              extendedmode;  /*  Driver-specific extensions */
+       __u32              readbuffers;   /*  # of buffers for read */
+       __u32              reserved[4];
+};
+/*  Flags for 'capability' and 'capturemode' fields */
+#define V4L2_MODE_HIGHQUALITY  0x0001  /*  High quality imaging mode */
+#define V4L2_CAP_TIMEPERFRAME  0x1000  /*  timeperframe field is supported */
+
+struct v4l2_outputparm
+{
+       __u32              capability;   /*  Supported modes */
+       __u32              outputmode;   /*  Current mode */
+       struct v4l2_fract  timeperframe; /*  Time per frame in seconds */
+       __u32              extendedmode; /*  Driver-specific extensions */
+       __u32              writebuffers; /*  # of buffers for write */
+       __u32              reserved[4];
+};
+
+/*
+ *     I N P U T   I M A G E   C R O P P I N G
+ */
+
+struct v4l2_cropcap {
+       enum v4l2_buf_type      type;   
+        struct v4l2_rect        bounds;
+        struct v4l2_rect        defrect;
+        struct v4l2_fract       pixelaspect;
+};
+
+struct v4l2_crop {
+       enum v4l2_buf_type      type;
+       struct v4l2_rect        c;
+};
+
+/*
+ *      A N A L O G   V I D E O   S T A N D A R D
+ */
+
+typedef __u64 v4l2_std_id;
+
+/* one bit for each */
+#define V4L2_STD_PAL_B          ((v4l2_std_id)0x00000001)
+#define V4L2_STD_PAL_B1         ((v4l2_std_id)0x00000002)
+#define V4L2_STD_PAL_G          ((v4l2_std_id)0x00000004)
+#define V4L2_STD_PAL_H          ((v4l2_std_id)0x00000008)
+#define V4L2_STD_PAL_I          ((v4l2_std_id)0x00000010)
+#define V4L2_STD_PAL_D          ((v4l2_std_id)0x00000020)
+#define V4L2_STD_PAL_D1         ((v4l2_std_id)0x00000040)
+#define V4L2_STD_PAL_K          ((v4l2_std_id)0x00000080)
+
+#define V4L2_STD_PAL_M          ((v4l2_std_id)0x00000100)
+#define V4L2_STD_PAL_N          ((v4l2_std_id)0x00000200)
+#define V4L2_STD_PAL_Nc         ((v4l2_std_id)0x00000400)
+#define V4L2_STD_PAL_60         ((v4l2_std_id)0x00000800)
+
+#define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)
+#define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)
+
+#define V4L2_STD_SECAM_B        ((v4l2_std_id)0x00010000)
+#define V4L2_STD_SECAM_D        ((v4l2_std_id)0x00020000)
+#define V4L2_STD_SECAM_G        ((v4l2_std_id)0x00040000)
+#define V4L2_STD_SECAM_H        ((v4l2_std_id)0x00080000)
+#define V4L2_STD_SECAM_K        ((v4l2_std_id)0x00100000)
+#define V4L2_STD_SECAM_K1       ((v4l2_std_id)0x00200000)
+#define V4L2_STD_SECAM_L        ((v4l2_std_id)0x00400000)
+
+/* ATSC/HDTV */
+#define V4L2_STD_ATSC_8_VSB     ((v4l2_std_id)0x01000000)
+#define V4L2_STD_ATSC_16_VSB    ((v4l2_std_id)0x02000000)
+
+/* some common needed stuff */
+#define V4L2_STD_PAL_BG                (V4L2_STD_PAL_B         |\
+                                V4L2_STD_PAL_B1        |\
+                                V4L2_STD_PAL_G)
+#define V4L2_STD_PAL_DK                (V4L2_STD_PAL_D         |\
+                                V4L2_STD_PAL_D1        |\
+                                V4L2_STD_PAL_K)
+#define V4L2_STD_PAL           (V4L2_STD_PAL_BG        |\
+                                V4L2_STD_PAL_DK        |\
+                                V4L2_STD_PAL_H         |\
+                                V4L2_STD_PAL_I)
+#define V4L2_STD_NTSC           (V4L2_STD_NTSC_M       |\
+                                V4L2_STD_NTSC_M_JP)
+#define V4L2_STD_SECAM         (V4L2_STD_SECAM_B       |\
+                                V4L2_STD_SECAM_D       |\
+                                V4L2_STD_SECAM_G       |\
+                                V4L2_STD_SECAM_H       |\
+                                V4L2_STD_SECAM_K       |\
+                                V4L2_STD_SECAM_K1      |\
+                                V4L2_STD_SECAM_L)
+
+#define V4L2_STD_525_60                (V4L2_STD_PAL_M         |\
+                                V4L2_STD_PAL_60        |\
+                                V4L2_STD_NTSC)
+#define V4L2_STD_625_50                (V4L2_STD_PAL           |\
+                                V4L2_STD_PAL_N         |\
+                                V4L2_STD_PAL_Nc        |\
+                                V4L2_STD_SECAM)
+
+#define V4L2_STD_UNKNOWN        0
+#define V4L2_STD_ALL            (V4L2_STD_525_60       |\
+                                V4L2_STD_625_50)
+
+struct v4l2_standard
+{
+       __u32                index;
+       v4l2_std_id          id;
+       __u8                 name[24];
+       struct v4l2_fract    frameperiod; /* Frames, not fields */
+       __u32                framelines;
+       __u32                reserved[4];
+};
+
+
+/*
+ *     V I D E O   I N P U T S
+ */
+struct v4l2_input
+{
+       __u32        index;             /*  Which input */
+       __u8         name[32];          /*  Label */
+       __u32        type;              /*  Type of input */
+       __u32        audioset;          /*  Associated audios (bitfield) */
+       __u32        tuner;             /*  Associated tuner */
+       v4l2_std_id  std;
+       __u32        status;
+       __u32        reserved[4];
+};
+/*  Values for the 'type' field */
+#define V4L2_INPUT_TYPE_TUNER          1
+#define V4L2_INPUT_TYPE_CAMERA         2
+
+/* field 'status' - general */
+#define V4L2_IN_ST_NO_POWER    0x00000001  /* Attached device is off */
+#define V4L2_IN_ST_NO_SIGNAL   0x00000002
+#define V4L2_IN_ST_NO_COLOR    0x00000004
+
+/* field 'status' - analog */
+#define V4L2_IN_ST_NO_H_LOCK   0x00000100  /* No horizontal sync lock */
+#define V4L2_IN_ST_COLOR_KILL  0x00000200  /* Color killer is active */
+
+/* field 'status' - digital */
+#define V4L2_IN_ST_NO_SYNC     0x00010000  /* No synchronization lock */
+#define V4L2_IN_ST_NO_EQU      0x00020000  /* No equalizer lock */
+#define V4L2_IN_ST_NO_CARRIER  0x00040000  /* Carrier recovery failed */
+
+/* field 'status' - VCR and set-top box */
+#define V4L2_IN_ST_MACROVISION 0x01000000  /* Macrovision detected */
+#define V4L2_IN_ST_NO_ACCESS   0x02000000  /* Conditional access denied */
+#define V4L2_IN_ST_VTR         0x04000000  /* VTR time constant */
+
+/*
+ *     V I D E O   O U T P U T S
+ */
+struct v4l2_output
+{
+       __u32        index;             /*  Which output */
+       __u8         name[32];          /*  Label */
+       __u32        type;              /*  Type of output */
+       __u32        audioset;          /*  Associated audios (bitfield) */
+       __u32        modulator;         /*  Associated modulator */
+       v4l2_std_id  std;
+       __u32        reserved[4];
+};
+/*  Values for the 'type' field */
+#define V4L2_OUTPUT_TYPE_MODULATOR             1
+#define V4L2_OUTPUT_TYPE_ANALOG                        2
+#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY      3
+
+/*
+ *     C O N T R O L S
+ */
+struct v4l2_control
+{
+       __u32                id;
+       __s32                value;
+};
+
+/*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
+struct v4l2_queryctrl
+{
+       __u32                id;
+       enum v4l2_ctrl_type  type;
+       __u8                 name[32];  /* Whatever */
+       __s32                minimum;   /* Note signedness */
+       __s32                maximum;
+       __s32                step;
+       __s32                default_value;
+       __u32                flags;
+       __u32                reserved[2];
+};
+
+/*  Used in the VIDIOC_QUERYMENU ioctl for querying menu items */
+struct v4l2_querymenu
+{
+       __u32           id;
+       __u32           index;
+       __u8            name[32];       /* Whatever */
+       __u32           reserved;
+};
+
+/*  Control flags  */
+#define V4L2_CTRL_FLAG_DISABLED                0x0001
+#define V4L2_CTRL_FLAG_GRABBED         0x0002
+
+/*  Control IDs defined by V4L2 */
+#define V4L2_CID_BASE                  0x00980900
+/*  IDs reserved for driver specific controls */
+#define V4L2_CID_PRIVATE_BASE          0x08000000
+
+#define V4L2_CID_BRIGHTNESS            (V4L2_CID_BASE+0)
+#define V4L2_CID_CONTRAST              (V4L2_CID_BASE+1)
+#define V4L2_CID_SATURATION            (V4L2_CID_BASE+2)
+#define V4L2_CID_HUE                   (V4L2_CID_BASE+3)
+#define V4L2_CID_AUDIO_VOLUME          (V4L2_CID_BASE+5)
+#define V4L2_CID_AUDIO_BALANCE         (V4L2_CID_BASE+6)
+#define V4L2_CID_AUDIO_BASS            (V4L2_CID_BASE+7)
+#define V4L2_CID_AUDIO_TREBLE          (V4L2_CID_BASE+8)
+#define V4L2_CID_AUDIO_MUTE            (V4L2_CID_BASE+9)
+#define V4L2_CID_AUDIO_LOUDNESS                (V4L2_CID_BASE+10)
+#define V4L2_CID_BLACK_LEVEL           (V4L2_CID_BASE+11)
+#define V4L2_CID_AUTO_WHITE_BALANCE    (V4L2_CID_BASE+12)
+#define V4L2_CID_DO_WHITE_BALANCE      (V4L2_CID_BASE+13)
+#define V4L2_CID_RED_BALANCE           (V4L2_CID_BASE+14)
+#define V4L2_CID_BLUE_BALANCE          (V4L2_CID_BASE+15)
+#define V4L2_CID_GAMMA                 (V4L2_CID_BASE+16)
+#define V4L2_CID_WHITENESS             (V4L2_CID_GAMMA) /* ? Not sure */
+#define V4L2_CID_EXPOSURE              (V4L2_CID_BASE+17)
+#define V4L2_CID_AUTOGAIN              (V4L2_CID_BASE+18)
+#define V4L2_CID_GAIN                  (V4L2_CID_BASE+19)
+#define V4L2_CID_HFLIP                 (V4L2_CID_BASE+20)
+#define V4L2_CID_VFLIP                 (V4L2_CID_BASE+21)
+#define V4L2_CID_HCENTER               (V4L2_CID_BASE+22)
+#define V4L2_CID_VCENTER               (V4L2_CID_BASE+23)
+#define V4L2_CID_LASTP1                        (V4L2_CID_BASE+24) /* last CID + 1 */
+
+/*
+ *     T U N I N G
+ */
+struct v4l2_tuner
+{
+       __u32                   index;
+       __u8                    name[32];
+       enum v4l2_tuner_type    type;
+       __u32                   capability;
+       __u32                   rangelow;
+       __u32                   rangehigh;
+       __u32                   rxsubchans;
+       __u32                   audmode;
+       __s32                   signal;
+       __s32                   afc;
+       __u32                   reserved[4];
+};
+
+struct v4l2_modulator
+{
+       __u32                   index;
+       __u8                    name[32];
+       __u32                   capability;
+       __u32                   rangelow;
+       __u32                   rangehigh;
+       __u32                   txsubchans;
+       __u32                   reserved[4];
+};
+
+/*  Flags for the 'capability' field */
+#define V4L2_TUNER_CAP_LOW             0x0001
+#define V4L2_TUNER_CAP_NORM            0x0002
+#define V4L2_TUNER_CAP_STEREO          0x0010
+#define V4L2_TUNER_CAP_LANG2           0x0020
+#define V4L2_TUNER_CAP_SAP             0x0020
+#define V4L2_TUNER_CAP_LANG1           0x0040
+
+/*  Flags for the 'rxsubchans' field */
+#define V4L2_TUNER_SUB_MONO            0x0001
+#define V4L2_TUNER_SUB_STEREO          0x0002
+#define V4L2_TUNER_SUB_LANG2           0x0004
+#define V4L2_TUNER_SUB_SAP             0x0004
+#define V4L2_TUNER_SUB_LANG1           0x0008
+
+/*  Values for the 'audmode' field */
+#define V4L2_TUNER_MODE_MONO           0x0000
+#define V4L2_TUNER_MODE_STEREO         0x0001
+#define V4L2_TUNER_MODE_LANG2          0x0002
+#define V4L2_TUNER_MODE_SAP            0x0002
+#define V4L2_TUNER_MODE_LANG1          0x0003
+
+struct v4l2_frequency
+{
+       __u32                 tuner;
+       enum v4l2_tuner_type  type;
+        __u32                frequency;
+       __u32                 reserved[8];
+};
+
+/*
+ *     A U D I O
+ */
+struct v4l2_audio
+{
+       __u32   index;
+       __u8    name[32];
+       __u32   capability;
+       __u32   mode;
+       __u32   reserved[2];
+};
+/*  Flags for the 'capability' field */
+#define V4L2_AUDCAP_STEREO             0x00001
+#define V4L2_AUDCAP_AVL                        0x00002
+
+/*  Flags for the 'mode' field */
+#define V4L2_AUDMODE_AVL               0x00001
+
+struct v4l2_audioout
+{
+       __u32   index;
+       __u8    name[32];
+       __u32   capability;
+       __u32   mode;
+       __u32   reserved[2];
+};
+
+/*
+ *     D A T A   S E R V I C E S   ( V B I )
+ *
+ *     Data services API by Michael Schimek
+ */
+
+struct v4l2_vbi_format
+{
+       __u32   sampling_rate;          /* in 1 Hz */
+       __u32   offset;
+       __u32   samples_per_line;
+       __u32   sample_format;          /* V4L2_PIX_FMT_* */
+       __s32   start[2];
+       __u32   count[2];
+       __u32   flags;                  /* V4L2_VBI_* */
+       __u32   reserved[2];            /* must be zero */
+};
+
+/*  VBI flags  */
+#define V4L2_VBI_UNSYNC                (1<< 0)
+#define V4L2_VBI_INTERLACED    (1<< 1)
+
+
+/*
+ *     A G G R E G A T E   S T R U C T U R E S
+ */
+
+/*     Stream data format
+ */
+struct v4l2_format
+{
+       enum v4l2_buf_type type;
+       union
+       {
+               struct v4l2_pix_format  pix;  // V4L2_BUF_TYPE_VIDEO_CAPTURE
+               struct v4l2_window      win;  // V4L2_BUF_TYPE_VIDEO_OVERLAY
+               struct v4l2_vbi_format  vbi;  // V4L2_BUF_TYPE_VBI_CAPTURE
+               __u8    raw_data[200];        // user-defined
+       } fmt;
+};
+
+
+/*     Stream type-dependent parameters
+ */
+struct v4l2_streamparm
+{
+       enum v4l2_buf_type type;
+       union
+       {
+               struct v4l2_captureparm capture;
+               struct v4l2_outputparm  output;
+               __u8    raw_data[200];  /* user-defined */
+       } parm;
+};
+
+
+
+/*
+ *     I O C T L   C O D E S   F O R   V I D E O   D E V I C E S
+ *
+ */
+#define VIDIOC_QUERYCAP                _IOR  ('V',  0, struct v4l2_capability)
+#define VIDIOC_RESERVED                _IO   ('V',  1)
+#define VIDIOC_ENUM_FMT         _IOWR ('V',  2, struct v4l2_fmtdesc)
+#define VIDIOC_G_FMT           _IOWR ('V',  4, struct v4l2_format)
+#define VIDIOC_S_FMT           _IOWR ('V',  5, struct v4l2_format)
+#if 0
+#define VIDIOC_G_COMP          _IOR  ('V',  6, struct v4l2_compression)
+#define VIDIOC_S_COMP          _IOW  ('V',  7, struct v4l2_compression)
+#endif
+#define VIDIOC_REQBUFS         _IOWR ('V',  8, struct v4l2_requestbuffers)
+#define VIDIOC_QUERYBUF                _IOWR ('V',  9, struct v4l2_buffer)
+#define VIDIOC_G_FBUF          _IOR  ('V', 10, struct v4l2_framebuffer)
+#define VIDIOC_S_FBUF          _IOW  ('V', 11, struct v4l2_framebuffer)
+#define VIDIOC_OVERLAY         _IOWR ('V', 14, int)
+#define VIDIOC_QBUF            _IOWR ('V', 15, struct v4l2_buffer)
+#define VIDIOC_DQBUF           _IOWR ('V', 17, struct v4l2_buffer)
+#define VIDIOC_STREAMON                _IOW  ('V', 18, int)
+#define VIDIOC_STREAMOFF       _IOW  ('V', 19, int)
+#define VIDIOC_G_PARM          _IOWR ('V', 21, struct v4l2_streamparm)
+#define VIDIOC_S_PARM          _IOW  ('V', 22, struct v4l2_streamparm)
+#define VIDIOC_G_STD           _IOR  ('V', 23, v4l2_std_id)
+#define VIDIOC_S_STD           _IOW  ('V', 24, v4l2_std_id)
+#define VIDIOC_ENUMSTD         _IOWR ('V', 25, struct v4l2_standard)
+#define VIDIOC_ENUMINPUT       _IOWR ('V', 26, struct v4l2_input)
+#define VIDIOC_G_CTRL          _IOWR ('V', 27, struct v4l2_control)
+#define VIDIOC_S_CTRL          _IOW  ('V', 28, struct v4l2_control)
+#define VIDIOC_G_TUNER         _IOWR ('V', 29, struct v4l2_tuner)
+#define VIDIOC_S_TUNER         _IOW  ('V', 30, struct v4l2_tuner)
+#define VIDIOC_G_AUDIO         _IOWR ('V', 33, struct v4l2_audio)
+#define VIDIOC_S_AUDIO         _IOW  ('V', 34, struct v4l2_audio)
+#define VIDIOC_QUERYCTRL       _IOWR ('V', 36, struct v4l2_queryctrl)
+#define VIDIOC_QUERYMENU       _IOWR ('V', 37, struct v4l2_querymenu)
+#define VIDIOC_G_INPUT         _IOR  ('V', 38, int)
+#define VIDIOC_S_INPUT         _IOWR ('V', 39, int)
+#define VIDIOC_G_OUTPUT                _IOR  ('V', 46, int)
+#define VIDIOC_S_OUTPUT                _IOWR ('V', 47, int)
+#define VIDIOC_ENUMOUTPUT      _IOWR ('V', 48, struct v4l2_output)
+#define VIDIOC_G_AUDOUT                _IOWR ('V', 49, struct v4l2_audioout)
+#define VIDIOC_S_AUDOUT                _IOW  ('V', 50, struct v4l2_audioout)
+#define VIDIOC_G_MODULATOR     _IOWR ('V', 54, struct v4l2_modulator)
+#define VIDIOC_S_MODULATOR     _IOW  ('V', 55, struct v4l2_modulator)
+#define VIDIOC_G_FREQUENCY     _IOWR ('V', 56, struct v4l2_frequency)
+#define VIDIOC_S_FREQUENCY     _IOW  ('V', 57, struct v4l2_frequency)
+#define VIDIOC_CROPCAP         _IOR  ('V', 58, struct v4l2_cropcap)
+#define VIDIOC_G_CROP          _IOWR ('V', 59, struct v4l2_crop)
+#define VIDIOC_S_CROP          _IOW  ('V', 60, struct v4l2_crop)
+#define VIDIOC_G_JPEGCOMP      _IOR  ('V', 61, struct v4l2_jpegcompression)
+#define VIDIOC_S_JPEGCOMP      _IOW  ('V', 62, struct v4l2_jpegcompression)
+#define VIDIOC_QUERYSTD        _IOR  ('V', 63, v4l2_std_id)
+#define VIDIOC_TRY_FMT         _IOWR ('V', 64, struct v4l2_format)
+
+#define BASE_VIDIOC_PRIVATE    192             /* 192-255 are private */
+
+
+#ifdef __KERNEL__
+/*
+ *
+ *     V 4 L 2   D R I V E R   H E L P E R   A P I
+ *
+ *     Some commonly needed functions for drivers (v4l2-common.o module)
+ */
+#include <linux/fs.h>
+
+/*  Video standard functions  */
+extern unsigned int v4l2_video_std_fps(struct v4l2_standard *vs);
+extern int v4l2_video_std_construct(struct v4l2_standard *vs,
+                                   int id, char *name);
+
+/*  Compatibility layer interface  */
+typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
+                          unsigned int cmd, void *arg);
+int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
+                              int cmd, void *arg, v4l2_kioctl driver_ioctl);
+
+/* names for fancy debug output */
+extern char *v4l2_field_names[];
+extern char *v4l2_type_names[];
+extern char *v4l2_ioctl_names[];
+
+#endif /* __KERNEL__ */
+#endif /* __LINUX_VIDEODEV2_H */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/modules/access/videodev_mjpeg.h b/modules/access/videodev_mjpeg.h
new file mode 100644 (file)
index 0000000..116a0c0
--- /dev/null
@@ -0,0 +1,139 @@
+/*****************************************************************************
+ * Copyright (C) lavrec (see http://mjpeg.sourceforge.net)
+ * ( XXX This file was get from the driver-zoran package and it is under GPL)
+ *
+ * $Id$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *****************************************************************************/
+
+/* These are the MJPEG API extensions for the Video4Linux API,
+   first introduced by the Iomega Buz driver by Rainer Johanni
+   <rainer@johanni.de>
+*/
+
+/* This is identical with the mgavideo internal params struct,
+   please tell me if you change this struct here ! <gz@lysator.liu.se) */
+struct mjpeg_params
+{
+
+   /* The following parameters can only be queried */
+
+   int major_version;            /* Major version number of driver */
+   int minor_version;            /* Minor version number of driver */
+
+   /* Main control parameters */
+
+   int input;                    /* Input channel: 0 = Composite, 1 = S-VHS */
+   int norm;                     /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
+   int decimation;               /* decimation of captured video,
+                                    enlargement of video played back.
+                                    Valid values are 1, 2, 4 or 0.
+                                    0 is a special value where the user
+                                    has full control over video scaling */
+
+   /* The following parameters only have to be set if decimation==0,
+      for other values of decimation they provide the data how the image is captured */
+
+   int HorDcm;                    /* Horizontal decimation: 1, 2 or 4 */
+   int VerDcm;                    /* Vertical decimation: 1 or 2 */
+   int TmpDcm;                    /* Temporal decimation: 1 or 2,
+                                     if TmpDcm==2 in capture every second frame is dropped,
+                                     in playback every frame is played twice */
+   int field_per_buff;            /* Number of fields per buffer: 1 or 2 */
+   int img_x;                     /* start of image in x direction */
+   int img_y;                     /* start of image in y direction */
+   int img_width;                 /* image width BEFORE decimation,
+                                     must be a multiple of HorDcm*16 */
+   int img_height;                /* image height BEFORE decimation,
+                                     must be a multiple of VerDcm*8 */
+
+   /* --- End of parameters for decimation==0 only --- */
+
+   /* JPEG control parameters */
+
+   int  quality;                  /* Measure for quality of compressed images.
+                                     Scales linearly with the size of the compressed images.
+                                     Must be beetween 0 and 100, 100 is a compression
+                                     ratio of 1:4 */
+
+   int  odd_even;                 /* Which field should come first ???
+                                     This is more aptly named "top_first",
+                                     i.e. (odd_even==1) --> top-field-first */
+
+   int  APPn;                     /* Number of APP segment to be written, must be 0..15 */
+   int  APP_len;                  /* Length of data in JPEG APPn segment */
+   char APP_data[60];             /* Data in the JPEG APPn segment. */
+
+   int  COM_len;                  /* Length of data in JPEG COM segment */
+   char COM_data[60];             /* Data in JPEG COM segment */
+
+   unsigned long jpeg_markers;    /* Which markers should go into the JPEG output.
+                                     Unless you exactly know what you do, leave them untouched.
+                                     Inluding less markers will make the resulting code
+                                     smaller, but there will be fewer aplications
+                                     which can read it.
+                                     The presence of the APP and COM marker is
+                                     influenced by APP0_len and COM_len ONLY! */
+#define JPEG_MARKER_DHT (1<<3)    /* Define Huffman Tables */
+#define JPEG_MARKER_DQT (1<<4)    /* Define Quantization Tables */
+#define JPEG_MARKER_DRI (1<<5)    /* Define Restart Interval */
+#define JPEG_MARKER_COM (1<<6)    /* Comment segment */
+#define JPEG_MARKER_APP (1<<7)    /* App segment, driver will allways use APP0 */
+
+   int  VFIFO_FB;        /* Flag for enabling Video Fifo Feedback.
+                            If this flag is turned on and JPEG decompressing
+                            is going to the screen, the decompress process
+                            is stopped every time the Video Fifo is full.
+                            This enables a smooth decompress to the screen
+                            but the video output signal will get scrambled */
+
+   /* Misc */
+
+    char reserved[312];  /* Makes 512 bytes for this structure */
+};
+
+struct mjpeg_requestbuffers
+{
+   unsigned long count;      /* Number of buffers for MJPEG grabbing */
+   unsigned long size;       /* Size PER BUFFER in bytes */
+};
+
+struct mjpeg_sync
+{
+   unsigned long frame;      /* Frame (0 - n) for double buffer */
+   unsigned long length;     /* number of code bytes in buffer (capture only) */
+   unsigned long seq;        /* frame sequence number */
+   struct timeval timestamp; /* timestamp */
+};
+
+struct mjpeg_status
+{
+   int input;                /* Input channel, has to be set prior to BUZIOC_G_STATUS */
+   int signal;               /* Returned: 1 if valid video signal detected */
+   int norm;                 /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
+   int color;                /* Returned: 1 if color signal detected */
+};
+
+/*
+Private IOCTL to set up for displaying MJPEG
+*/
+#define MJPIOC_G_PARAMS       _IOR ('v', BASE_VIDIOCPRIVATE+0,  struct mjpeg_params)
+#define MJPIOC_S_PARAMS       _IOWR('v', BASE_VIDIOCPRIVATE+1,  struct mjpeg_params)
+#define MJPIOC_REQBUFS        _IOWR('v', BASE_VIDIOCPRIVATE+2,  struct mjpeg_requestbuffers)
+#define MJPIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOCPRIVATE+3,  int)
+#define MJPIOC_QBUF_PLAY      _IOW ('v', BASE_VIDIOCPRIVATE+4,  int)
+#define MJPIOC_SYNC           _IOR ('v', BASE_VIDIOCPRIVATE+5,  struct mjpeg_sync)
+#define MJPIOC_G_STATUS       _IOWR('v', BASE_VIDIOCPRIVATE+6,  struct mjpeg_status)