~ubuntu-branches/debian/squeeze/vlc/squeeze

« back to all changes in this revision

Viewing changes to modules/access/v4l2.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Mutricy
  • Date: 2009-09-20 01:08:41 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090920010841-vc6vme91a70r5w0t
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * v4l2.c : Video4Linux2 input module for vlc
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2002-2009 the VideoLAN team
5
 
 * $Id: 31dae6643f3445a6549b225e2e42f9e133a91ca5 $
 
5
 * $Id: 4b1c67c8f9256345a0b158257452bd6d6946591b $
6
6
 *
7
7
 * Authors: Benjamin Pracht <bigben at videolan dot org>
8
8
 *          Richard Hosking <richard at hovis dot net>
40
40
#include <vlc_common.h>
41
41
#include <vlc_plugin.h>
42
42
#include <vlc_access.h>
 
43
#include <vlc_charset.h>
43
44
#include <vlc_demux.h>
44
45
#include <vlc_input.h>
45
46
 
361
362
static int AccessControl( access_t *, int, va_list );
362
363
 
363
364
static int Demux( demux_t * );
364
 
static ssize_t AccessRead( access_t *, uint8_t *, size_t );
 
365
static block_t *AccessRead( access_t * );
365
366
 
366
 
static block_t* GrabVideo( demux_t *p_demux );
367
 
static block_t* ProcessVideoFrame( demux_t *p_demux, uint8_t *p_frame, size_t );
 
367
static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys );
 
368
static block_t* ProcessVideoFrame( vlc_object_t *p_demux, uint8_t *p_frame, size_t );
368
369
 
369
370
static bool IsPixelFormatSupported( demux_t *p_demux,
370
371
                                          unsigned int i_pixelformat );
429
430
 
430
431
    /* Compressed data types */
431
432
    { V4L2_PIX_FMT_MJPEG,   VLC_FOURCC('M','J','P','G'), 0, 0, 0 },
 
433
    { V4L2_PIX_FMT_JPEG,    VLC_FOURCC('J','P','E','G'), 0, 0, 0 },
432
434
#if 0
433
 
    { V4L2_PIX_FMT_JPEG,    VLC_FOURCC('J','P','E','G') },
434
435
    { V4L2_PIX_FMT_DV,      VLC_FOURCC('?','?','?','?') },
435
436
    { V4L2_PIX_FMT_MPEG,    VLC_FOURCC('?','?','?','?') },
436
437
#endif
446
447
static const __u32 p_chroma_fallbacks[] =
447
448
{ V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YVU420, V4L2_PIX_FMT_YUV422P,
448
449
  V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_BGR24,
449
 
  V4L2_PIX_FMT_BGR32, V4L2_PIX_FMT_MJPEG };
 
450
  V4L2_PIX_FMT_BGR32, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_JPEG };
450
451
 
451
452
static const struct
452
453
{
771
772
            }
772
773
            else if( !strncmp( psz_parser, "fps=", strlen( "fps=" ) ) )
773
774
            {
774
 
                p_sys->f_fps = strtof( psz_parser + strlen( "fps=" ),
775
 
                                       &psz_parser );
 
775
                p_sys->f_fps = us_strtof( psz_parser + strlen( "fps=" ),
 
776
                                          &psz_parser );
776
777
            }
777
778
            else if( !strncmp( psz_parser, "io=", strlen( "io=" ) ) )
778
779
            {
1055
1056
    if( *p_access->psz_access == '\0' ) return VLC_EGENERIC;
1056
1057
 
1057
1058
    access_InitFields( p_access );
1058
 
    ACCESS_SET_CALLBACKS( AccessRead, NULL, AccessControl, NULL );
 
1059
    ACCESS_SET_CALLBACKS( NULL, AccessRead, AccessControl, NULL );
1059
1060
    p_sys = calloc( 1, sizeof( demux_sys_t ));
1060
1061
    if( !p_sys ) return VLC_ENOMEM;
1061
1062
    p_access->p_sys = (access_sys_t*)p_sys;
1177
1178
/*****************************************************************************
1178
1179
 * AccessRead: access callback
1179
1180
 ******************************************************************************/
1180
 
static ssize_t AccessRead( access_t * p_access, uint8_t * p_buffer, size_t i_len )
 
1181
static block_t *AccessRead( access_t * p_access )
1181
1182
{
1182
 
    demux_sys_t *p_sys = (demux_sys_t *) p_access->p_sys;
1183
 
    struct pollfd ufd;
1184
 
    int i_ret;
1185
 
 
1186
 
    ufd.fd = p_sys->i_fd;
1187
 
    ufd.events = POLLIN;
1188
 
 
1189
 
    if( p_access->info.b_eof )
1190
 
        return 0;
1191
 
 
1192
 
    do
1193
 
    {
1194
 
        if( !vlc_object_alive (p_access) )
1195
 
            return 0;
1196
 
 
1197
 
        ufd.revents = 0;
1198
 
    }
1199
 
    while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 );
1200
 
 
1201
 
    if( i_ret < 0 )
1202
 
    {
1203
 
        msg_Err( p_access, "Polling error (%m)." );
1204
 
        return -1;
1205
 
    }
1206
 
 
1207
 
    i_ret = v4l2_read( p_sys->i_fd, p_buffer, i_len );
1208
 
    if( i_ret == 0 )
1209
 
    {
1210
 
        p_access->info.b_eof = true;
1211
 
    }
1212
 
    else if( i_ret > 0 )
1213
 
    {
1214
 
        p_access->info.i_pos += i_ret;
1215
 
    }
1216
 
 
1217
 
    return i_ret;
 
1183
    demux_sys_t *p_sys = (demux_sys_t *)p_access->p_sys;
 
1184
 
 
1185
    struct pollfd fd;
 
1186
    fd.fd = p_sys->i_fd;
 
1187
    fd.events = POLLIN|POLLPRI;
 
1188
    fd.revents = 0;
 
1189
 
 
1190
    /* Wait for data */
 
1191
    if( poll( &fd, 1, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
 
1192
    {
 
1193
        if( fd.revents & (POLLIN|POLLPRI) )
 
1194
        {
 
1195
            return GrabVideo( VLC_OBJECT(p_access), p_sys );
 
1196
        }
 
1197
    }
 
1198
 
 
1199
    return NULL;
1218
1200
}
1219
1201
 
1220
1202
/*****************************************************************************
1234
1216
    {
1235
1217
        if( fd.revents & (POLLIN|POLLPRI) )
1236
1218
        {
1237
 
            block_t *p_block = GrabVideo( p_demux );
 
1219
            block_t *p_block = GrabVideo( VLC_OBJECT(p_demux), p_sys );
1238
1220
            if( p_block )
1239
1221
            {
1240
1222
                es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
1249
1231
/*****************************************************************************
1250
1232
 * GrabVideo: Grab a video frame
1251
1233
 *****************************************************************************/
1252
 
static block_t* GrabVideo( demux_t *p_demux )
 
1234
static block_t* GrabVideo( vlc_object_t *p_demux, demux_sys_t *p_sys )
1253
1235
{
1254
 
    demux_sys_t *p_sys = p_demux->p_sys;
1255
 
 
1256
1236
    block_t *p_block = NULL;
1257
1237
    struct v4l2_buffer buf;
1258
1238
    ssize_t i_ret;
1389
1369
 * ProcessVideoFrame: Helper function to take a buffer and copy it into
1390
1370
 * a new block
1391
1371
 *****************************************************************************/
1392
 
static block_t* ProcessVideoFrame( demux_t *p_demux, uint8_t *p_frame, size_t i_size )
 
1372
static block_t* ProcessVideoFrame( vlc_object_t *p_demux, uint8_t *p_frame, size_t i_size )
1393
1373
{
1394
1374
    block_t *p_block;
1395
1375
 
1411
1391
/*****************************************************************************
1412
1392
 * Helper function to initalise video IO using the Read method
1413
1393
 *****************************************************************************/
1414
 
static int InitRead( demux_t *p_demux, unsigned int i_buffer_size )
 
1394
static int InitRead( vlc_object_t *p_demux, demux_sys_t *p_sys, unsigned int i_buffer_size )
1415
1395
{
1416
 
    demux_sys_t *p_sys = p_demux->p_sys;
 
1396
    (void)p_demux;
1417
1397
 
1418
1398
    p_sys->p_buffers = calloc( 1, sizeof( *p_sys->p_buffers ) );
1419
1399
    if( !p_sys->p_buffers )
1430
1410
/*****************************************************************************
1431
1411
 * Helper function to initalise video IO using the mmap method
1432
1412
 *****************************************************************************/
1433
 
static int InitMmap( demux_t *p_demux, int i_fd )
 
1413
static int InitMmap( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd )
1434
1414
{
1435
 
    demux_sys_t *p_sys = p_demux->p_sys;
1436
1415
    struct v4l2_requestbuffers req;
1437
1416
 
1438
1417
    memset( &req, 0, sizeof(req) );
1492
1471
/*****************************************************************************
1493
1472
 * Helper function to initalise video IO using the userbuf method
1494
1473
 *****************************************************************************/
1495
 
static int InitUserP( demux_t *p_demux, int i_fd, unsigned int i_buffer_size )
 
1474
static int InitUserP( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd, unsigned int i_buffer_size )
1496
1475
{
1497
 
    demux_sys_t *p_sys = p_demux->p_sys;
1498
1476
    struct v4l2_requestbuffers req;
1499
1477
    unsigned int i_page_size;
1500
1478
 
1856
1834
                  var_GetBool( p_obj, "v4l2-controls-reset" ), b_demux );
1857
1835
    SetAvailControlsByString( p_obj, p_sys, i_fd );
1858
1836
 
1859
 
    if( false == b_demux)
1860
 
    {
1861
 
        return i_fd;
1862
 
    }
1863
 
 
1864
 
    demux_t *p_demux = (demux_t *) p_obj;
1865
 
 
1866
1837
    /* Verify device support for the various IO methods */
1867
1838
    switch( p_sys->io )
1868
1839
    {
1918
1889
        /* Use current width and height settings */
1919
1890
        if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 )
1920
1891
        {
1921
 
            msg_Err( p_demux, "Cannot get default width and height." );
 
1892
            msg_Err( p_obj, "Cannot get default width and height." );
1922
1893
            goto open_failed;
1923
1894
        }
1924
1895
 
1932
1903
    }
1933
1904
    else if( p_sys->i_width < 0 || p_sys->i_height < 0 )
1934
1905
    {
1935
 
        msg_Dbg( p_demux, "will try to find optimal width and height." );
 
1906
        msg_Dbg( p_obj, "will try to find optimal width and height." );
1936
1907
    }
1937
1908
    else
1938
1909
    {
1939
1910
        /* Use user specified width and height */
1940
 
        msg_Dbg( p_demux, "trying specified size %dx%d", p_sys->i_width, p_sys->i_height );
 
1911
        msg_Dbg( p_obj, "trying specified size %dx%d", p_sys->i_width, p_sys->i_height );
1941
1912
    }
1942
1913
 
1943
1914
    fmt.fmt.pix.width = p_sys->i_width;
1944
1915
    fmt.fmt.pix.height = p_sys->i_height;
1945
1916
    fmt.fmt.pix.field = V4L2_FIELD_NONE;
1946
1917
 
1947
 
    /* Test and set Chroma */
1948
 
    fmt.fmt.pix.pixelformat = 0;
1949
 
    if( p_sys->psz_requested_chroma && strlen( p_sys->psz_requested_chroma ) > 0 )
 
1918
    if (b_demux)
1950
1919
    {
1951
 
        /* User specified chroma */
1952
 
        if( strlen( p_sys->psz_requested_chroma ) >= 4 )
 
1920
        demux_t *p_demux = (demux_t *) p_obj;
 
1921
 
 
1922
        /* Test and set Chroma */
 
1923
        fmt.fmt.pix.pixelformat = 0;
 
1924
        if( p_sys->psz_requested_chroma && *p_sys->psz_requested_chroma )
1953
1925
        {
 
1926
            /* User specified chroma */
1954
1927
            int i_requested_fourcc = VLC_FOURCC(
1955
1928
                p_sys->psz_requested_chroma[0], p_sys->psz_requested_chroma[1],
1956
1929
                p_sys->psz_requested_chroma[2], p_sys->psz_requested_chroma[3] );
 
1930
 
1957
1931
            for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
1958
1932
            {
1959
1933
                if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
1962
1936
                    break;
1963
1937
                }
1964
1938
            }
1965
 
        }
1966
 
        /* Try and set user chroma */
1967
 
        if( !IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) || ( fmt.fmt.pix.pixelformat && v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) )
1968
 
        {
1969
 
            msg_Warn( p_demux, "Driver is unable to use specified chroma %s. Trying defaults.", p_sys->psz_requested_chroma );
1970
 
            fmt.fmt.pix.pixelformat = 0;
1971
 
        }
1972
 
    }
1973
 
 
1974
 
    /* If no user specified chroma, find best */
1975
 
    /* This also decides if MPEG encoder card or not */
1976
 
    if( !fmt.fmt.pix.pixelformat )
1977
 
    {
1978
 
        unsigned int i;
1979
 
        for( i = 0; i < ARRAY_SIZE( p_chroma_fallbacks ); i++ )
1980
 
        {
1981
 
            fmt.fmt.pix.pixelformat = p_chroma_fallbacks[i];
1982
 
            if( IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat )
1983
 
             && v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
1984
 
                break;
1985
 
        }
1986
 
        if( i == ARRAY_SIZE( p_chroma_fallbacks ) )
1987
 
        {
1988
 
            msg_Warn( p_demux, "Could not select any of the default chromas; attempting to open as MPEG encoder card (access)" );
1989
 
            goto open_failed;
1990
 
        }
1991
 
    }
1992
 
 
1993
 
    if( p_sys->i_width < 0 || p_sys->i_height < 0 )
1994
 
    {
1995
 
        if( p_sys->f_fps <= 0 )
1996
 
        {
1997
 
            p_sys->f_fps = GetAbsoluteMaxFrameRate( p_demux, i_fd,
1998
 
                                                    fmt.fmt.pix.pixelformat );
1999
 
            msg_Dbg( p_demux, "Found maximum framerate of %f", p_sys->f_fps );
2000
 
        }
2001
 
        GetMaxDimensions( p_demux, i_fd,
2002
 
                          fmt.fmt.pix.pixelformat, p_sys->f_fps,
2003
 
                          &fmt.fmt.pix.width, &fmt.fmt.pix.height );
2004
 
        msg_Dbg( p_demux, "Found optimal dimensions for framerate %f of %dx%d",
2005
 
                 p_sys->f_fps, fmt.fmt.pix.width, fmt.fmt.pix.height );
2006
 
        if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) {;}
2007
 
    }
2008
 
 
2009
 
    /* Reassign width, height and chroma incase driver override */
2010
 
    p_sys->i_width = fmt.fmt.pix.width;
2011
 
    p_sys->i_height = fmt.fmt.pix.height;
2012
 
 
 
1939
            /* Try and set user chroma */
 
1940
            bool b_error = !IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat );
 
1941
            if( !b_error && fmt.fmt.pix.pixelformat )
 
1942
            {
 
1943
                if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
 
1944
                {
 
1945
                    fmt.fmt.pix.field = V4L2_FIELD_ANY;
 
1946
                    if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
 
1947
                    {
 
1948
                        fmt.fmt.pix.field = V4L2_FIELD_NONE;
 
1949
                        b_error = true;
 
1950
                    }
 
1951
                }
 
1952
            }
 
1953
            if( b_error )
 
1954
            {
 
1955
                msg_Warn( p_demux, "Driver is unable to use specified chroma %s. Trying defaults.", p_sys->psz_requested_chroma );
 
1956
                fmt.fmt.pix.pixelformat = 0;
 
1957
            }
 
1958
        }
 
1959
 
 
1960
        /* If no user specified chroma, find best */
 
1961
        /* This also decides if MPEG encoder card or not */
 
1962
        if( !fmt.fmt.pix.pixelformat )
 
1963
        {
 
1964
            unsigned int i;
 
1965
            for( i = 0; i < ARRAY_SIZE( p_chroma_fallbacks ); i++ )
 
1966
            {
 
1967
                fmt.fmt.pix.pixelformat = p_chroma_fallbacks[i];
 
1968
                if( IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) )
 
1969
                {
 
1970
                    if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
 
1971
                        break;
 
1972
                    fmt.fmt.pix.field = V4L2_FIELD_ANY;
 
1973
                    if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
 
1974
                        break;
 
1975
                    fmt.fmt.pix.field = V4L2_FIELD_NONE;
 
1976
                }
 
1977
            }
 
1978
            if( i == ARRAY_SIZE( p_chroma_fallbacks ) )
 
1979
            {
 
1980
                msg_Warn( p_demux, "Could not select any of the default chromas; attempting to open as MPEG encoder card (access)" );
 
1981
                goto open_failed;
 
1982
            }
 
1983
        }
 
1984
 
 
1985
        if( p_sys->i_width < 0 || p_sys->i_height < 0 )
 
1986
        {
 
1987
            if( p_sys->f_fps <= 0 )
 
1988
            {
 
1989
                p_sys->f_fps = GetAbsoluteMaxFrameRate( p_demux, i_fd,
 
1990
                                                        fmt.fmt.pix.pixelformat );
 
1991
                msg_Dbg( p_demux, "Found maximum framerate of %f", p_sys->f_fps );
 
1992
            }
 
1993
            uint32_t i_width, i_height;
 
1994
            GetMaxDimensions( p_demux, i_fd,
 
1995
                              fmt.fmt.pix.pixelformat, p_sys->f_fps,
 
1996
                              &i_width, &i_height );
 
1997
            if( i_width || i_height )
 
1998
            {
 
1999
                msg_Dbg( p_demux, "Found optimal dimensions for framerate %f of %dx%d",
 
2000
                         p_sys->f_fps, i_width, i_height );
 
2001
                fmt.fmt.pix.width = i_width;
 
2002
                fmt.fmt.pix.height = i_height;
 
2003
                if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) {;}
 
2004
            }
 
2005
            else
 
2006
            {
 
2007
                msg_Warn( p_obj, "Could not find optimal width and height." );
 
2008
            }
 
2009
        }
 
2010
 
 
2011
        /* Reassign width, height and chroma incase driver override */
 
2012
        p_sys->i_width = fmt.fmt.pix.width;
 
2013
        p_sys->i_height = fmt.fmt.pix.height;
 
2014
    }
 
2015
 
 
2016
    if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 ) {;}
 
2017
    /* Print extra info */
 
2018
    msg_Dbg( p_obj, "Driver requires at most %d bytes to store a complete image", fmt.fmt.pix.sizeimage );
2013
2019
    /* Check interlacing */
2014
 
    if( v4l2_ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 ) {;}
2015
2020
    switch( fmt.fmt.pix.field )
2016
2021
    {
2017
2022
        case V4L2_FIELD_NONE:
2018
 
            msg_Dbg( p_demux, "Interlacing setting: progressive" );
 
2023
            msg_Dbg( p_obj, "Interlacing setting: progressive" );
2019
2024
            break;
2020
2025
        case V4L2_FIELD_TOP:
2021
 
            msg_Dbg( p_demux, "Interlacing setting: top field only" );
 
2026
            msg_Dbg( p_obj, "Interlacing setting: top field only" );
2022
2027
            break;
2023
2028
        case V4L2_FIELD_BOTTOM:
2024
 
            msg_Dbg( p_demux, "Interlacing setting: bottom field only" );
 
2029
            msg_Dbg( p_obj, "Interlacing setting: bottom field only" );
2025
2030
            break;
2026
2031
        case V4L2_FIELD_INTERLACED:
2027
 
            msg_Dbg( p_demux, "Interlacing setting: interleaved (bottom top if M/NTSC, top bottom otherwise)" );
 
2032
            msg_Dbg( p_obj, "Interlacing setting: interleaved (bottom top if M/NTSC, top bottom otherwise)" );
2028
2033
            break;
2029
2034
        case V4L2_FIELD_SEQ_TB:
2030
 
            msg_Dbg( p_demux, "Interlacing setting: sequential top bottom" );
 
2035
            msg_Dbg( p_obj, "Interlacing setting: sequential top bottom" );
2031
2036
            break;
2032
2037
        case V4L2_FIELD_SEQ_BT:
2033
 
            msg_Dbg( p_demux, "Interlacing setting: sequential bottom top" );
 
2038
            msg_Dbg( p_obj, "Interlacing setting: sequential bottom top" );
2034
2039
            break;
2035
2040
        case V4L2_FIELD_ALTERNATE:
2036
 
            msg_Dbg( p_demux, "Interlacing setting: alternate fields" );
 
2041
            msg_Dbg( p_obj, "Interlacing setting: alternate fields" );
2037
2042
            break;
2038
2043
        case V4L2_FIELD_INTERLACED_TB:
2039
 
            msg_Dbg( p_demux, "Interlacing setting: interleaved top bottom" );
 
2044
            msg_Dbg( p_obj, "Interlacing setting: interleaved top bottom" );
2040
2045
            break;
2041
2046
        case V4L2_FIELD_INTERLACED_BT:
2042
 
            msg_Dbg( p_demux, "Interlacing setting: interleaved bottom top" );
 
2047
            msg_Dbg( p_obj, "Interlacing setting: interleaved bottom top" );
2043
2048
            break;
2044
2049
        default:
2045
 
            msg_Warn( p_demux, "Interlacing setting: unknown type (%d)",
 
2050
            msg_Warn( p_obj, "Interlacing setting: unknown type (%d)",
2046
2051
                      fmt.fmt.pix.field );
2047
2052
            break;
2048
2053
    }
2049
2054
    if( fmt.fmt.pix.field != V4L2_FIELD_NONE )
2050
 
        msg_Warn( p_demux, "Interlaced inputs haven't been tested. Please report any issue." );
 
2055
        msg_Warn( p_obj, "Interlaced inputs haven't been tested. Please report any issue." );
2051
2056
 
2052
2057
    /* Look up final fourcc */
2053
2058
    p_sys->i_fourcc = 0;
2085
2090
        char psz_fourcc[5];
2086
2091
        memset( &psz_fourcc, 0, sizeof( psz_fourcc ) );
2087
2092
        vlc_fourcc_to_char( p_sys->i_fourcc, &psz_fourcc );
2088
 
        msg_Dbg( p_demux, "supported frame intervals for %4s, %dx%d:",
 
2093
        msg_Dbg( p_obj, "supported frame intervals for %4s, %dx%d:",
2089
2094
                 psz_fourcc, frmival.width, frmival.height );
2090
2095
        switch( frmival.type )
2091
2096
        {
2092
2097
            case V4L2_FRMIVAL_TYPE_DISCRETE:
2093
2098
                do
2094
2099
                {
2095
 
                    msg_Dbg( p_demux, "    supported frame interval: %d/%d",
 
2100
                    msg_Dbg( p_obj, "    supported frame interval: %d/%d",
2096
2101
                             frmival.discrete.numerator,
2097
2102
                             frmival.discrete.denominator );
2098
2103
                    frmival.index++;
2099
2104
                } while( v4l2_ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 );
2100
2105
                break;
2101
2106
            case V4L2_FRMIVAL_TYPE_STEPWISE:
2102
 
                msg_Dbg( p_demux, "    supported frame intervals: %d/%d to "
 
2107
                msg_Dbg( p_obj, "    supported frame intervals: %d/%d to "
2103
2108
                         "%d/%d using %d/%d increments",
2104
2109
                         frmival.stepwise.min.numerator,
2105
2110
                         frmival.stepwise.min.denominator,
2109
2114
                         frmival.stepwise.step.denominator );
2110
2115
                break;
2111
2116
            case V4L2_FRMIVAL_TYPE_CONTINUOUS:
2112
 
                msg_Dbg( p_demux, "    supported frame intervals: %d/%d to %d/%d",
 
2117
                msg_Dbg( p_obj, "    supported frame intervals: %d/%d to %d/%d",
2113
2118
                         frmival.stepwise.min.numerator,
2114
2119
                         frmival.stepwise.min.denominator,
2115
2120
                         frmival.stepwise.max.numerator,
2124
2129
    switch( p_sys->io )
2125
2130
    {
2126
2131
    case IO_METHOD_READ:
2127
 
        if( InitRead( p_demux, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
 
2132
        if( InitRead( p_obj, p_sys, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
2128
2133
        break;
2129
2134
 
2130
2135
    case IO_METHOD_MMAP:
2131
 
        if( InitMmap( p_demux, i_fd ) != VLC_SUCCESS ) goto open_failed;
 
2136
        if( InitMmap( p_obj, p_sys, i_fd ) != VLC_SUCCESS ) goto open_failed;
2132
2137
        break;
2133
2138
 
2134
2139
    case IO_METHOD_USERPTR:
2135
 
        if( InitUserP( p_demux, i_fd, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
 
2140
        if( InitUserP( p_obj, p_sys, i_fd, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
2136
2141
        break;
2137
2142
 
2138
2143
    }
2142
2147
    es_fmt.video.i_height = p_sys->i_height;
2143
2148
    es_fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
2144
2149
 
2145
 
    msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
2146
 
        (char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
2147
 
    p_sys->p_es = es_out_Add( p_demux->out, &es_fmt );
 
2150
    if( b_demux )
 
2151
    {
 
2152
        demux_t *p_demux = (demux_t *) p_obj;
 
2153
        msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
 
2154
            (char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
 
2155
        p_sys->p_es = es_out_Add( p_demux->out, &es_fmt );
 
2156
    }
2148
2157
 
2149
2158
    /* Start Capture */
2150
2159
 
2166
2175
 
2167
2176
            if( v4l2_ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
2168
2177
            {
2169
 
                msg_Err( p_demux, "VIDIOC_QBUF failed" );
 
2178
                msg_Err( p_obj, "VIDIOC_QBUF failed" );
2170
2179
                goto open_failed;
2171
2180
            }
2172
2181
        }
2174
2183
        buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2175
2184
        if( v4l2_ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
2176
2185
        {
2177
 
            msg_Err( p_demux, "VIDIOC_STREAMON failed" );
 
2186
            msg_Err( p_obj, "VIDIOC_STREAMON failed" );
2178
2187
            goto open_failed;
2179
2188
        }
2180
2189
 
2194
2203
 
2195
2204
            if( v4l2_ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
2196
2205
            {
2197
 
                msg_Err( p_demux, "VIDIOC_QBUF failed" );
 
2206
                msg_Err( p_obj, "VIDIOC_QBUF failed" );
2198
2207
                goto open_failed;
2199
2208
            }
2200
2209
        }
2202
2211
        buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2203
2212
        if( v4l2_ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
2204
2213
        {
2205
 
            msg_Err( p_demux, "VIDIOC_STREAMON failed" );
 
2214
            msg_Err( p_obj, "VIDIOC_STREAMON failed" );
2206
2215
            goto open_failed;
2207
2216
        }
2208
2217
 
2212
2221
    /* report fps */
2213
2222
    if( p_sys->f_fps >= 0.1 )
2214
2223
    {
2215
 
        msg_Dbg( p_demux, "User set fps=%f", p_sys->f_fps );
 
2224
        msg_Dbg( p_obj, "User set fps=%f", p_sys->f_fps );
2216
2225
    }
2217
2226
 
2218
2227
    return i_fd;
2328
2337
    {
2329
2338
        struct v4l2_standard t_standards;
2330
2339
        t_standards.index = 0;
 
2340
        p_sys->i_standard = 0;
2331
2341
        while( v4l2_ioctl( i_fd, VIDIOC_ENUMSTD, &t_standards ) >=0 )
2332
2342
        {
2333
2343
            p_sys->i_standard++;
2391
2401
    {
2392
2402
        struct v4l2_tuner tuner;
2393
2403
        memset( &tuner, 0, sizeof(tuner) );
 
2404
        p_sys->i_tuner = 0;
2394
2405
        while( v4l2_ioctl( i_fd, VIDIOC_G_TUNER, &tuner ) >= 0 )
2395
2406
        {
2396
2407
            p_sys->i_tuner++;