+/*****************************************************************************
+ * input_AddArea: add and init an area descriptor
+ *****************************************************************************
+ * This area descriptor will be referenced in the given stream descriptor
+ *****************************************************************************/
+input_area_t * input_AddArea( input_thread_t * p_input )
+{
+ /* Where to add the pgrm */
+ int i_area_index = p_input->stream.i_area_nb;
+
+ /* Add an entry to the list of program associated with the stream */
+ p_input->stream.i_area_nb++;
+ p_input->stream.pp_areas = realloc( p_input->stream.pp_areas,
+ p_input->stream.i_area_nb
+ * sizeof(input_area_t *) );
+ if( p_input->stream.pp_areas == NULL )
+ {
+ intf_ErrMsg( "Unable to realloc memory in input_AddArea" );
+ return( NULL );
+ }
+
+ /* Allocate the structure to store this description */
+ p_input->stream.pp_areas[i_area_index] =
+ malloc( sizeof(input_area_t) );
+ if( p_input->stream.pp_areas[i_area_index] == NULL )
+ {
+ intf_ErrMsg( "Unable to allocate memory in input_AddArea" );
+ return( NULL );
+ }
+
+ /* Init this entry */
+ p_input->stream.pp_areas[i_area_index]->i_id = 0;
+ p_input->stream.pp_areas[i_area_index]->i_start = 0;
+ p_input->stream.pp_areas[i_area_index]->i_size = 0;
+ p_input->stream.pp_areas[i_area_index]->i_tell = 0;
+ p_input->stream.pp_areas[i_area_index]->i_seek = NO_SEEK;
+ p_input->stream.pp_areas[i_area_index]->i_part_nb = 1;
+ p_input->stream.pp_areas[i_area_index]->i_part= 0;
+
+ return p_input->stream.pp_areas[i_area_index];
+}
+
+/*****************************************************************************
+ * input_SetProgram: changes the current program
+ *****************************************************************************/
+int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
+{
+ int i_es_index;
+
+ if ( p_input->stream.p_selected_program )
+ {
+ for ( i_es_index = 0 ;
+ i_es_index < p_input->stream.i_selected_es_number;
+ i_es_index ++ )
+ {
+ intf_WarnMsg( 4, "Unselecting ES %d",
+ p_input->stream.pp_selected_es[i_es_index]->i_id );
+ input_UnselectES( p_input ,
+ p_input->stream.pp_selected_es[i_es_index] );
+ }
+ }
+
+ for (i_es_index = 0 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
+ {
+ int i_required_audio_es;
+ int i_required_spu_es;
+ int i_audio_es = 0;
+ int i_spu_es = 0;
+
+ /* 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;
+ }
+ switch( p_new_prg->pp_es[i_es_index]->i_cat )
+ {
+ case MPEG1_VIDEO_ES:
+ case MPEG2_VIDEO_ES:
+ intf_WarnMsg( 4, "Selecting ES %x",
+ p_new_prg->pp_es[i_es_index]->i_id );
+ input_SelectES( p_input,
+ p_new_prg->pp_es[i_es_index] );
+ break;
+ case MPEG1_AUDIO_ES:
+ case MPEG2_AUDIO_ES:
+ i_audio_es += 1;
+ if( i_audio_es == i_required_audio_es )
+ {
+ intf_WarnMsg( 4, "Selecting ES %x",
+ p_new_prg->pp_es[i_es_index]->i_id );
+ input_SelectES( p_input,
+ p_new_prg->pp_es[i_es_index]);
+ }
+ break;
+ case LPCM_AUDIO_ES :
+ case AC3_AUDIO_ES :
+ i_audio_es += 1;
+ if( i_audio_es == i_required_audio_es )
+ {
+ intf_WarnMsg( 4, "Selecting ES %x",
+ p_new_prg->pp_es[i_es_index]->i_id );
+ input_SelectES( p_input,
+ p_new_prg->pp_es[i_es_index] );
+ }
+ break;
+ /* Not sure this one is fully specification-compliant */
+ case DVD_SPU_ES :
+ i_spu_es += 1;
+ if( i_spu_es == i_required_spu_es )
+ {
+ intf_WarnMsg( 4, "Selecting ES %x",
+ p_new_prg->pp_es[i_es_index]->i_id );
+ input_SelectES( p_input,
+ p_new_prg->pp_es[i_es_index] );
+ }
+ break;
+ default :
+ break;
+ }
+
+ }
+
+
+ p_input->stream.p_selected_program = p_new_prg;
+
+ return( 0 );
+}
+
+
+/*****************************************************************************
+ * input_DelArea: destroy a area descriptor
+ *****************************************************************************
+ * All ES descriptions referenced in the descriptor will be deleted.
+ *****************************************************************************/
+void input_DelArea( input_thread_t * p_input, input_area_t * p_area )
+{
+ int i_area_index;
+
+ ASSERT( p_area );
+
+ /* Find the area in the areas table */
+ for( i_area_index = 0; i_area_index < p_input->stream.i_area_nb;
+ i_area_index++ )
+ {
+ if( p_input->stream.pp_areas[i_area_index] == p_area )
+ break;
+ }
+
+ /* Remove this area from the stream's list of areas */
+ p_input->stream.i_area_nb--;
+
+ p_input->stream.pp_areas[i_area_index] =
+ p_input->stream.pp_areas[p_input->stream.i_area_nb];
+ p_input->stream.pp_areas = realloc( p_input->stream.pp_areas,
+ p_input->stream.i_area_nb
+ * sizeof(input_area_t *) );
+
+ if( p_input->stream.i_area_nb && p_input->stream.pp_areas == NULL)
+ {
+ intf_ErrMsg( "input error: unable to realloc area list"
+ " in input_DelArea" );
+ }
+
+ /* Free the description of this area */
+ free( p_area );
+}
+
+