Commit cb0b3752 by Andy Gatward

Add option to force PAL / SECAM / NTSC mode

parent 42f1f170
Showing with 142 additions and 13 deletions
......@@ -134,6 +134,11 @@ int ivtv_InitEncoder()
if( i_setup_rv < 0 )
return( i_setup_rv );
i_setup_rv = ivtv_SetStandard();
if( i_setup_rv < 0 )
return( i_setup_rv );
i_setup_rv = ivtv_SetFrequency();
if( i_setup_rv < 0 )
......@@ -188,6 +193,107 @@ int ivtv_InitEncoder()
return( 0 );
}
int ivtv_GetStandard( char *psz_standard )
{
v4l2_std_id std_id;
struct v4l2_standard standard;
if( ivtv_doIoctl( VIDIOC_G_STD, &std_id ) == -1 )
{
msg_Err( NULL, "Could not read current video standard: %s", strerror( errno ) );
return( -errno );
}
memset( &standard, 0, sizeof( standard ) );
standard.index = 0;
while( ivtv_doIoctl( VIDIOC_ENUMSTD, &standard ) == 0 )
{
if( standard.id & std_id )
{
memcpy( psz_standard, &standard.name, 24 );
return( 0 );
}
}
if( errno == EINVAL || standard.index == 0 )
msg_Warn( NULL, "Reached end of video standard enumeration without a match." );
return( -EINVAL );
}
int ivtv_PrintStandards()
{
struct v4l2_input input;
struct v4l2_standard standard;
memset( &input, 0, sizeof( input ));
if( ivtv_doIoctl( VIDIOC_G_INPUT, &input.index ) < 0 )
{
msg_Err( NULL, "Failed to read index of selected input: %s", strerror( errno ) );
return( -errno );
}
if( ivtv_doIoctl( VIDIOC_ENUMINPUT, &input ) < 0 )
{
msg_Err( NULL, "Failed to read supported video standards for input: %s", strerror( errno ) );
return( -errno );
}
msg_Raw( NULL, "" );
msg_Raw( NULL, "Selected input (%s) supports these video standards:", input.name );
memset( &standard, 0, sizeof( standard ) );
standard.index = 0;
while( ivtv_doIoctl( VIDIOC_ENUMSTD, &standard ) == 0 )
{
if( standard.id & input.std )
msg_Raw( NULL, " %s", standard.name );
standard.index++;
}
if( errno != EINVAL ) {
msg_Err( NULL, "Error while enumerating supported video standards: %s", strerror( errno ) );
return( -errno );
}
return( 0 );
}
int ivtv_SetStandard()
{
struct v4l2_input input;
memset( &input, 0, sizeof( input ) );
if( ivtv_doIoctl( VIDIOC_G_INPUT, &input.index ) < 0 )
{
msg_Err( NULL, "Failed to read index of selected input: %s", strerror( errno ) );
return( -errno );
}
if( ivtv_doIoctl( VIDIOC_ENUMINPUT, &input ) < 0 )
{
msg_Err( NULL, "Failed to enumerate input: %s", strerror( errno ) );
return( -errno );
}
if( ( p_pvr->i_vid_std & input.std ) == 0 )
{
msg_Err( NULL, "Requested video standard is not supported." );
return( -errno );
}
if( ivtv_doIoctl( VIDIOC_S_STD, &p_pvr->i_vid_std ) < 0 )
{
msg_Err( NULL, "Failed to set requested video standard: %s", strerror( errno ) );
return( -errno );
}
return( 0 );
}
int ivtv_GetFrequency()
{
if( p_pvr->i_fd < 0 )
......
......@@ -78,6 +78,8 @@ void usage()
msg_Raw( NULL, " -I List card inputs." );
msg_Raw( NULL, " -m Override network MTU size, using specified value." );
msg_Raw( NULL, " -p Set peak video bandwidth (VBR) in kb/s, default %d.", DEFAULT_VB_MAX );
msg_Raw( NULL, " -s Force video standard (PAL, NTSC, SECAM), default auto" );
msg_Raw( NULL, " -S Show supported video standards for selected input." );
msg_Raw( NULL, " -r Set aspect ratio, default is 4:3, valid values are: " );
msg_Raw( NULL, " 1:1, 4:3, 16:9, 2.21:1" );
msg_Raw( NULL, " -t Set TTL for multicast output, default %d.", DEFAULT_TTL );
......@@ -107,6 +109,7 @@ int main( int i_argc, char *p_argv[] )
p_pvr->i_gop_size = 0;
p_pvr->i_input = DEFAULT_INPUT;
p_pvr->i_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3;
p_pvr->i_vid_std = V4L2_STD_ALL;
// build output structure and populate with default data
......@@ -137,6 +140,8 @@ int main( int i_argc, char *p_argv[] )
{ "mtu", required_argument, NULL, 'm' },
{ "video-maxbw", required_argument, NULL, 'p' },
{ "aspect", required_argument, NULL, 'r' },
{ "standard", required_argument, NULL, 's' },
{ "list-std", no_argument, NULL, 'S' },
{ "ttl", required_argument, NULL, 't' },
{ "udp", no_argument, NULL, 'u' },
{ "version", no_argument, NULL, 'V' },
......@@ -144,9 +149,10 @@ int main( int i_argc, char *p_argv[] )
};
uint8_t b_lsinput = 0;
uint8_t b_lsstds = 0;
int c;
while( ( c = getopt_long(i_argc, p_argv, "v::a:b:cd:f:g:hi:Im:p:r:t:uV", long_options, NULL ) ) != -1 )
while( ( c = getopt_long(i_argc, p_argv, "v::a:b:cd:f:g:hi:Im:p:r:s:St:uV", long_options, NULL ) ) != -1 )
{
switch( c )
{
......@@ -249,26 +255,32 @@ int main( int i_argc, char *p_argv[] )
break;
case 'r':
if( strcmp( optarg, "1:1" ) == 0 )
{
p_pvr->i_aspect = V4L2_MPEG_VIDEO_ASPECT_1x1;
}
else if( strcmp( optarg, "4:3" ) == 0 )
{
p_pvr->i_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3;
}
else if( strcmp( optarg, "16:9" ) == 0 )
{
p_pvr->i_aspect = V4L2_MPEG_VIDEO_ASPECT_16x9;
}
else if( strcmp( optarg, "2.21:1" ) == 0 )
{
p_pvr->i_aspect = V4L2_MPEG_VIDEO_ASPECT_221x100;
}
else {
else
{
msg_Warn( NULL, "'%s' is not a valid aspect ratio, using default.", optarg );
p_pvr->i_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3;
}
break;
case 's':
if( strcmp( optarg, "NTSC" ) == 0 )
p_pvr->i_vid_std = V4L2_STD_NTSC;
else if( strcmp( optarg, "SECAM" ) == 0 )
p_pvr->i_vid_std = V4L2_STD_SECAM;
else if( strcmp( optarg, "PAL" ) == 0 )
p_pvr->i_vid_std = V4L2_STD_PAL;
else
msg_Warn( NULL, "'%s' is not a recognised video standard, auto-detecting.", optarg );
break;
case 'S':
b_lsstds = 1;
break;
case 't':
p_output->i_ttl = strtol( optarg, NULL, 10 );
if( p_output->i_ttl < 1 )
......@@ -294,9 +306,16 @@ int main( int i_argc, char *p_argv[] )
if( b_lsinput )
{
if( !ivtv_Open() )
{
ivtv_PrintInputList();
}
ivtv_Close();
exit( EXIT_SUCCESS );
}
if( b_lsstds )
{
if( !ivtv_Open() )
if( !ivtv_SetInput() )
ivtv_PrintStandards();
ivtv_Close();
exit( EXIT_SUCCESS );
}
......
......@@ -29,7 +29,7 @@
/*****************************************************************************
* System-level configuration
*****************************************************************************/
#define HAVE_CLOCK_NANOSLEEP
#undef HAVE_CLOCK_NANOSLEEP
/*****************************************************************************
* Application-wide defines and typedefs
......@@ -77,6 +77,7 @@ typedef struct pvr_t
/* v4l2 params */
int i_input;
int i_freq;
uint64_t i_vid_std;
/* MPEG encoder params */
int i_aspect;
......@@ -135,6 +136,9 @@ void ivtv_Close();
int ivtv_Read( unsigned char *p_data, uint16_t i_len );
int ivtv_InitEncoder();
int ivtv_SetInput();
int ivtv_GetStandard( char *psz_standard );
int ivtv_PrintStandards();
int ivtv_SetStandard();
int ivtv_GetFrequency();
int ivtv_SetFrequency();
int ivtv_GetAudioBw();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment