1933
1904
else if( p_sys->i_width < 0 || p_sys->i_height < 0 )
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." );
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 );
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;
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 )
1951
/* User specified chroma */
1952
if( strlen( p_sys->psz_requested_chroma ) >= 4 )
1920
demux_t *p_demux = (demux_t *) p_obj;
1922
/* Test and set Chroma */
1923
fmt.fmt.pix.pixelformat = 0;
1924
if( p_sys->psz_requested_chroma && *p_sys->psz_requested_chroma )
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] );
1957
1931
for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
1959
1933
if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
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 ) )
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;
1974
/* If no user specified chroma, find best */
1975
/* This also decides if MPEG encoder card or not */
1976
if( !fmt.fmt.pix.pixelformat )
1979
for( i = 0; i < ARRAY_SIZE( p_chroma_fallbacks ); i++ )
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 )
1986
if( i == ARRAY_SIZE( p_chroma_fallbacks ) )
1988
msg_Warn( p_demux, "Could not select any of the default chromas; attempting to open as MPEG encoder card (access)" );
1993
if( p_sys->i_width < 0 || p_sys->i_height < 0 )
1995
if( p_sys->f_fps <= 0 )
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 );
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 ) {;}
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;
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 )
1943
if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1945
fmt.fmt.pix.field = V4L2_FIELD_ANY;
1946
if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
1948
fmt.fmt.pix.field = V4L2_FIELD_NONE;
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;
1960
/* If no user specified chroma, find best */
1961
/* This also decides if MPEG encoder card or not */
1962
if( !fmt.fmt.pix.pixelformat )
1965
for( i = 0; i < ARRAY_SIZE( p_chroma_fallbacks ); i++ )
1967
fmt.fmt.pix.pixelformat = p_chroma_fallbacks[i];
1968
if( IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) )
1970
if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
1972
fmt.fmt.pix.field = V4L2_FIELD_ANY;
1973
if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) >= 0 )
1975
fmt.fmt.pix.field = V4L2_FIELD_NONE;
1978
if( i == ARRAY_SIZE( p_chroma_fallbacks ) )
1980
msg_Warn( p_demux, "Could not select any of the default chromas; attempting to open as MPEG encoder card (access)" );
1985
if( p_sys->i_width < 0 || p_sys->i_height < 0 )
1987
if( p_sys->f_fps <= 0 )
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 );
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 )
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 ) {;}
2007
msg_Warn( p_obj, "Could not find optimal width and height." );
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;
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 )
2017
2022
case V4L2_FIELD_NONE:
2018
msg_Dbg( p_demux, "Interlacing setting: progressive" );
2023
msg_Dbg( p_obj, "Interlacing setting: progressive" );
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" );
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" );
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)" );
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" );
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" );
2035
2040
case V4L2_FIELD_ALTERNATE:
2036
msg_Dbg( p_demux, "Interlacing setting: alternate fields" );
2041
msg_Dbg( p_obj, "Interlacing setting: alternate fields" );
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" );
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" );
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 );
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." );
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 )
2092
2097
case V4L2_FRMIVAL_TYPE_DISCRETE:
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 );
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,