* mpeg_system.c: TS, PS and PES management
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: mpeg_system.c,v 1.87 2002/03/20 17:44:15 sam Exp $
+ * $Id: mpeg_system.c,v 1.91 2002/04/23 14:16:20 sam Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
/* Read what we believe to be a packet header. */
PEEK( 4 );
- if( *p_peek || *(p_peek + 1) || *(p_peek + 2) != 1 )
+ if( p_peek[0] || p_peek[1] || p_peek[2] != 1 || p_peek[3] < 0xB9 )
{
- if( *p_peek || *(p_peek + 1) || *(p_peek + 2) )
+ if( p_peek[0] || p_peek[1] || p_peek[2] )
{
/* It is common for MPEG-1 streams to pad with zeros
* (although it is forbidden by the recommendation), so
* don't bother everybody in this case. */
intf_WarnMsg( 3, "input warning: garbage (0x%.2x%.2x%.2x%.2x)",
- *p_peek, *(p_peek + 1), *(p_peek + 2), *(p_peek + 3) );
+ p_peek[0], p_peek[1], p_peek[2], p_peek[3] );
}
/* This is not the startcode of a packet. Read the stream
* until we find one. */
- while( *p_peek || *(p_peek + 1) || *(p_peek + 2) != 1 )
+ while( p_peek[0] || p_peek[1] || p_peek[2] != 1 || p_peek[3] < 0xB9 )
{
p_input->p_current_data++;
PEEK( 4 );
p_es->i_cat = AUDIO_ES;
#ifdef AUTO_SPAWN
if( !p_input->stream.b_seekable )
- if( config_GetIntVariable( "input_channel" )
+ if( config_GetIntVariable( "audio-channel" )
== (p_es->i_id & 0x1F) ||
- ( config_GetIntVariable( "input_channel" ) < 0
+ ( config_GetIntVariable( "audio-channel" ) < 0
&& !(p_es->i_id & 0x1F) ) )
- switch( config_GetIntVariable( "input_audio" ) )
+ switch( config_GetIntVariable( "audio-type" ) )
{
case -1:
case REQUESTED_MPEG:
p_es->i_cat = AUDIO_ES;
#ifdef AUTO_SPAWN
if( !p_input->stream.b_seekable )
- if( config_GetIntVariable( "input_channel" )
+ if( config_GetIntVariable( "audio-channel" )
== ((p_es->i_id & 0xF00) >> 8) ||
- ( config_GetIntVariable( "input_channel" ) < 0
+ ( config_GetIntVariable( "audio-channel" ) < 0
&& !((p_es->i_id & 0xF00) >> 8)) )
- switch( config_GetIntVariable( "input_audio" ) )
+ switch( config_GetIntVariable( "audio-type" ) )
{
case -1:
case REQUESTED_AC3:
p_es->i_type = DVD_SPU_ES;
p_es->i_cat = SPU_ES;
#ifdef AUTO_SPAWN
- if( config_GetIntVariable( "input_subtitle" )
+ if( config_GetIntVariable( "spu-channel" )
== ((p_es->i_id & 0x1F00) >> 8) )
{
if( !p_input->stream.b_seekable )
p_stream_data->i_pat_version = p_psi->i_version_number;
}
-#undef p_psi
+#undef p_psi
- /* FIXME This has nothing to do here */
- if( !p_input->stream.p_selected_program )
- {
- input_SetProgram( p_input, p_input->stream.pp_programs[0] );
- }
}
/*****************************************************************************
int i_section_length,i_current_section;
int i_prog_info_length, i_loop;
int i_es_info_length, i_pid, i_stream_type;
- int i_audio_es, i_spu_es;
- int i_required_audio_es, i_required_spu_es;
p_current_section = p_psi->buffer;
p_current_data = p_psi->buffer;
p_pgrm_data->i_pcr_pid = ( ((u32)*(p_current_section + 8) & 0x1F) << 8 ) |
*(p_current_section + 9);
- i_audio_es = 0;
- i_spu_es = 0;
/* Lock stream information */
vlc_mutex_lock( &p_input->stream.stream_lock );
- /* Get the number of the required audio stream */
- if( p_main->b_audio )
- {
- /* Default is the first one */
- i_required_audio_es = config_GetIntVariable( "input_channel" );
- if( i_required_audio_es < 0 )
- {
- i_required_audio_es = 1;
- }
- }
- else
- {
- i_required_audio_es = 0;
- }
-
- /* Same thing for subtitles */
- if( p_main->b_video )
- {
- /* for spu, default is none */
- i_required_spu_es = config_GetIntVariable( "input_subtitle" );
- if( i_required_spu_es < 0 )
- {
- i_required_spu_es = 0;
- }
- }
- else
- {
- i_required_spu_es = 0;
- }
-
/* Delete all ES in this program except the PSI. We start from the
* end because i_es_number gets decremented after each deletion. */
for( i_loop = p_es->p_pgrm->i_es_number ; i_loop ; )
/* Tell the interface what kind of stream it is and select
* the required ones */
- if ( p_input->stream.p_selected_program == p_new_es->p_pgrm )
{
switch( i_stream_type )
{
case MPEG1_VIDEO_ES:
case MPEG2_VIDEO_ES:
p_new_es->i_cat = VIDEO_ES;
- input_SelectES( p_input, p_new_es );
break;
case MPEG1_AUDIO_ES:
case MPEG2_AUDIO_ES:
p_new_es->i_cat = AUDIO_ES;
- i_audio_es += 1;
- if( i_audio_es == i_required_audio_es )
- input_SelectES( p_input, p_new_es );
break;
case LPCM_AUDIO_ES :
case AC3_AUDIO_ES :
p_new_es->i_stream_id = 0xBD;
p_new_es->i_cat = AUDIO_ES;
- i_audio_es += 1;
- if( i_audio_es == i_required_audio_es )
- input_SelectES( p_input, p_new_es );
break;
/* Not sure this one is fully specification-compliant */
case DVD_SPU_ES :
p_new_es->i_stream_id = 0xBD;
p_new_es->i_cat = SPU_ES;
- i_spu_es += 1;
- if( i_spu_es == i_required_spu_es )
- input_SelectES( p_input, p_new_es );
break;
default :
p_new_es->i_cat = UNKNOWN_ES;
} while( i_current_section < p_psi->i_last_section_number );
- if( i_required_audio_es > i_audio_es )
- {
- intf_WarnMsg( 2, "input: non-existing audio ES required" );
- }
-
- if( i_required_spu_es > i_spu_es )
+ p_pgrm_data->i_pmt_version = p_psi->i_version_number;
+
+ /* if no program is selected :*/
+ if( !p_input->stream.p_selected_program )
{
- intf_WarnMsg( 2, "input: non-existing subtitles ES required" );
+ pgrm_descriptor_t * p_pgrm_to_select;
+ u16 i_id = (u16)config_GetIntVariable( "program" );
+
+ if( i_id != 0 ) /* if user specified a program */
+ {
+ p_pgrm_to_select = input_FindProgram( p_input, i_id );
+
+ if( p_pgrm_to_select || p_pgrm_to_select == p_es->p_pgrm )
+ p_input->pf_set_program( p_input, p_pgrm_to_select );
+ }
+ else
+ p_input->pf_set_program( p_input, p_es->p_pgrm );
}
- p_pgrm_data->i_pmt_version = p_psi->i_version_number;
-
/* inform interface that stream has changed */
p_input->stream.b_changed = 1;
/* Remove lock */