/*****************************************************************************
* input_programs.c: es_descriptor_t, pgrm_descriptor_t management
*****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_programs.c,v 1.37 2001/02/23 12:37:31 massiot Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: input_programs.c,v 1.71 2002/02/19 00:50:19 sam Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include "defs.h"
-
#include <stdlib.h>
+#include <string.h> /* memcpy(), memset() */
+#include <sys/types.h> /* off_t */
-#include "config.h"
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
-#include "debug.h"
-
-#include "intf_msg.h"
+#include <videolan/vlc.h>
#include "stream_control.h"
#include "input_ext-intf.h"
#include "input_ext-dec.h"
-#include "input.h"
+#include "input_ext-plugins.h"
-#include "main.h" /* --noaudio --novideo */
+#include "debug.h"
/*
* NOTICE : all of these functions expect you to have taken the lock on
*****************************************************************************/
int input_InitStream( input_thread_t * p_input, size_t i_data_len )
{
+
p_input->stream.i_stream_id = 0;
+
+ /* initialized to 0 since we don't give the signal to the interface
+ * before the end of input initialization */
+ p_input->stream.b_changed = 0;
p_input->stream.pp_es = NULL;
p_input->stream.pp_selected_es = NULL;
+ p_input->stream.p_removed_es = NULL;
+ p_input->stream.p_newly_selected_es = NULL;
p_input->stream.pp_programs = NULL;
-
+ p_input->stream.p_selected_program = NULL;
+ p_input->stream.p_new_program = NULL;
+
if( i_data_len )
{
if ( (p_input->stream.p_demux_data = malloc( i_data_len )) == NULL )
}
memset( p_input->stream.p_demux_data, 0, i_data_len );
}
+ else
+ {
+ p_input->stream.p_demux_data = NULL;
+ }
return 0;
}
{
input_DelES( p_input, p_input->stream.pp_es[0] );
}
+
+ /* Free all areas */
+ while( p_input->stream.i_area_nb )
+ {
+ input_DelArea( p_input, p_input->stream.pp_areas[0] );
+ }
+
+ /* Free selected ES */
+ if( p_input->stream.pp_selected_es != NULL )
+ {
+ free( p_input->stream.pp_selected_es );
+ }
+
+ if( p_input->stream.p_demux_data != NULL )
+ {
+ free( p_input->stream.p_demux_data );
+ }
}
/*****************************************************************************
/* Where to add the pgrm */
int i_pgrm_index = p_input->stream.i_pgrm_number;
- intf_DbgMsg("Adding description for pgrm %d", i_pgrm_id);
-
/* Add an entry to the list of program associated with the stream */
p_input->stream.i_pgrm_number++;
p_input->stream.pp_programs = realloc( p_input->stream.pp_programs,
p_input->stream.pp_programs[i_pgrm_index]->i_synchro_state
= SYNCHRO_START;
- p_input->stream.pp_programs[i_pgrm_index]->p_vout
- = p_input->p_default_vout;
- p_input->stream.pp_programs[i_pgrm_index]->p_aout
- = p_input->p_default_aout;
-
if( i_data_len )
{
p_input->stream.pp_programs[i_pgrm_index]->p_demux_data =
memset( p_input->stream.pp_programs[i_pgrm_index]->p_demux_data, 0,
i_data_len );
}
+ else
+ {
+ p_input->stream.pp_programs[i_pgrm_index]->p_demux_data = NULL;
+ }
return p_input->stream.pp_programs[i_pgrm_index];
}
ASSERT( p_pgrm );
- intf_DbgMsg("Deleting description for pgrm %d", p_pgrm->i_number);
-
/* Free the structures that describe the es that belongs to that program */
while( p_pgrm->i_es_number )
{
/* Where to add the pgrm */
int i_area_index = p_input->stream.i_area_nb;
- intf_DbgMsg("Adding description for area %d", i_area_index );
-
/* 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.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 = 0;
+ p_input->stream.pp_areas[i_area_index]->i_part_nb = 1;
p_input->stream.pp_areas[i_area_index]->i_part= 0;
+ p_input->stream.pp_areas[i_area_index]->i_angle_nb = 1;
+ p_input->stream.pp_areas[i_area_index]->i_angle = 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;
+#define old_prg p_input->stream.p_selected_program
+ for ( i_es_index = 0 ; i_es_index < old_prg->i_es_number ; i_es_index ++ )
+ {
+ input_UnselectES( p_input , old_prg->pp_es[i_es_index] );
+ }
+#undef old_prg
+ for (i_es_index = 0 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
+ {
+ input_SelectES( p_input , p_new_prg->pp_es[i_es_index] );
+ }
+
+ p_input->stream.p_selected_program = p_new_prg;
+
+ return( 0 );
+}
+
+
/*****************************************************************************
* input_DelArea: destroy a area descriptor
*****************************************************************************
ASSERT( p_area );
- intf_DbgMsg("Deleting description for area %d", p_area->i_id );
-
/* Find the area in the areas table */
for( i_area_index = 0; i_area_index < p_input->stream.i_area_nb;
i_area_index++ )
{
es_descriptor_t * p_es;
- intf_DbgMsg("Adding description for ES 0x%x", i_es_id);
-
p_es = (es_descriptor_t *)malloc( sizeof(es_descriptor_t) );
if( p_es == NULL )
{
/* Init its values */
p_es->i_id = i_es_id;
+ p_es->psz_desc[0] = '\0';
p_es->p_pes = NULL;
p_es->p_decoder_fifo = NULL;
p_es->b_audio = 0;
+ p_es->i_cat = UNKNOWN_ES;
if( i_data_len )
{
}
-/*****************************************************************************
- * InitDecConfig: initializes a decoder_config_t
- *****************************************************************************/
-static int InitDecConfig( input_thread_t * p_input, es_descriptor_t * p_es,
- decoder_config_t * p_config )
-{
- p_config->i_id = p_es->i_id;
- p_config->i_type = p_es->i_type;
- p_config->p_stream_ctrl =
- &p_input->stream.control;
-
- /* Decoder FIFO */
- if( (p_config->p_decoder_fifo =
- (decoder_fifo_t *)malloc( sizeof(decoder_fifo_t) )) == NULL )
- {
- intf_ErrMsg( "Out of memory" );
- return( -1 );
- }
-
- vlc_mutex_init(&p_config->p_decoder_fifo->data_lock);
- vlc_cond_init(&p_config->p_decoder_fifo->data_wait);
- p_config->p_decoder_fifo->i_start = p_config->p_decoder_fifo->i_end = 0;
- p_config->p_decoder_fifo->b_die = p_config->p_decoder_fifo->b_error = 0;
- p_config->p_decoder_fifo->p_packets_mgt = p_input->p_method_data;
- p_config->p_decoder_fifo->pf_delete_pes = p_input->pf_delete_pes;
- p_es->p_decoder_fifo = p_config->p_decoder_fifo;
-
- p_config->pf_init_bit_stream = InitBitstream;
-
- return( 0 );
-}
-
-/*****************************************************************************
- * GetVdecConfig: returns a valid vdec_config_t
- *****************************************************************************/
-static vdec_config_t * GetVdecConfig( input_thread_t * p_input,
- es_descriptor_t * p_es )
-{
- vdec_config_t * p_config;
-
- p_config = (vdec_config_t *)malloc( sizeof(vdec_config_t) );
- if( p_config == NULL )
- {
- intf_ErrMsg( "Unable to allocate memory in GetVdecConfig" );
- return( NULL );
- }
- p_config->p_vout = p_input->p_default_vout;
- if( InitDecConfig( p_input, p_es, &p_config->decoder_config ) == -1 )
- {
- free( p_config );
- return( NULL );
- }
-
- return( p_config );
-}
-
-/*****************************************************************************
- * GetAdecConfig: returns a valid adec_config_t
- *****************************************************************************/
-static adec_config_t * GetAdecConfig( input_thread_t * p_input,
- es_descriptor_t * p_es )
-{
- adec_config_t * p_config;
-
- p_config = (adec_config_t *)malloc( sizeof(adec_config_t));
- if( p_config == NULL )
- {
- intf_ErrMsg( "Unable to allocate memory in GetAdecConfig" );
- return( NULL );
- }
- p_config->p_aout = p_input->p_default_aout;
- if( InitDecConfig( p_input, p_es, &p_config->decoder_config ) == -1 )
- {
- free( p_config );
- return( NULL );
- }
-
- return( p_config );
-}
-
/*****************************************************************************
* input_SelectES: selects an ES and spawns the associated decoder
+ *****************************************************************************
+ * Remember we are still supposed to have stream_lock when entering this
+ * function ?
*****************************************************************************/
-/* FIXME */
-vlc_thread_t adec_CreateThread( void * );
-vlc_thread_t ac3dec_CreateThread( void * );
-vlc_thread_t vpar_CreateThread( void * );
-vlc_thread_t spudec_CreateThread( void * );
-
int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
{
- /* FIXME ! */
- decoder_capabilities_t decoder;
+ if( p_es == NULL )
+ {
+ intf_ErrMsg( "input error: nothing to do in input_SelectES" );
+ return -1;
+ }
-#ifdef DEBUG_INPUT
- intf_DbgMsg( "Selecting ES 0x%x", p_es->i_id );
-#endif
+ intf_WarnMsg( 4, "input: selecting ES 0x%x", p_es->i_id );
if( p_es->p_decoder_fifo != NULL )
{
- intf_ErrMsg( "ES %d is already selected", p_es->i_id );
+ intf_ErrMsg( "ES 0x%x is already selected", p_es->i_id );
return( -1 );
}
switch( p_es->i_type )
{
+ case AC3_AUDIO_ES:
case MPEG1_AUDIO_ES:
case MPEG2_AUDIO_ES:
+ case LPCM_AUDIO_ES:
if( p_main->b_audio )
{
- decoder.pf_create_thread = adec_CreateThread;
- p_es->thread_id = input_RunDecoder( &decoder,
- (void *)GetAdecConfig( p_input, p_es ) );
+ /* This kludge should be removed */
+ p_main->b_ac3 = ( p_es->i_type == AC3_AUDIO_ES );
+
+ /* Release the lock, not to block the input thread during
+ * the creation of the thread. */
+ vlc_mutex_unlock( &p_input->stream.stream_lock );
+ p_es->thread_id = input_RunDecoder( p_input, p_es );
+ vlc_mutex_lock( &p_input->stream.stream_lock );
}
break;
case MPEG1_VIDEO_ES:
case MPEG2_VIDEO_ES:
- if( p_main->b_video )
- {
- decoder.pf_create_thread = vpar_CreateThread;
- p_es->thread_id = input_RunDecoder( &decoder,
- (void *)GetVdecConfig( p_input, p_es ) );
- }
- break;
-
- case AC3_AUDIO_ES:
- if( p_main->b_audio )
- {
- decoder.pf_create_thread = ac3dec_CreateThread;
- p_es->thread_id = input_RunDecoder( &decoder,
- (void *)GetAdecConfig( p_input, p_es ) );
- }
- break;
-
case DVD_SPU_ES:
if( p_main->b_video )
{
- decoder.pf_create_thread = spudec_CreateThread;
- p_es->thread_id = input_RunDecoder( &decoder,
- (void *)GetVdecConfig( p_input, p_es ) );
+ /* Release the lock, not to block the input thread during
+ * the creation of the thread. */
+ vlc_mutex_unlock( &p_input->stream.stream_lock );
+ p_es->thread_id = input_RunDecoder( p_input, p_es );
+ vlc_mutex_lock( &p_input->stream.stream_lock );
}
break;
default:
- intf_ErrMsg( "Unknown stream type %d", p_es->i_type );
+ intf_ErrMsg( "Unknown stream type 0x%x", p_es->i_type );
return( -1 );
break;
}
return( -1 );
}
- if( p_es->p_decoder_fifo != NULL )
- {
- p_input->stream.i_selected_es_number++;
- p_input->stream.pp_selected_es = realloc(
- p_input->stream.pp_selected_es,
- p_input->stream.i_selected_es_number
- * sizeof(es_descriptor_t *) );
- if( p_input->stream.pp_selected_es == NULL )
- {
- intf_ErrMsg( "Unable to realloc memory in input_SelectES" );
- return(-1);
- }
- p_input->stream.pp_selected_es[p_input->stream.i_selected_es_number - 1]
- = p_es;
- }
return( 0 );
}
/*****************************************************************************
- * input_UnSelectES: removes an ES from the list of selected ES
+ * input_UnselectES: removes an ES from the list of selected ES
*****************************************************************************/
-int input_UnSelectES( input_thread_t * p_input, es_descriptor_t * p_es )
+int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
{
int i_index = 0;
-#ifdef DEBUG_INPUT
- intf_DbgMsg( "UnSelecting ES 0x%x", p_es->i_id );
-#endif
+ if( p_es == NULL )
+ {
+ intf_ErrMsg( "Nothing to do in input_UnselectES" );
+ return -1;
+ }
+
+ intf_WarnMsg( 4, "input: unselecting ES 0x%x", p_es->i_id );
if( p_es->p_decoder_fifo == NULL )
{
- intf_ErrMsg( "ES %d is not selected", p_es->i_id );
+ intf_ErrMsg( "ES 0x%x is not selected", p_es->i_id );
return( -1 );
}
input_EndDecoder( p_input, p_es );
- if( p_es->p_decoder_fifo == NULL )
+ if( ( p_es->p_decoder_fifo == NULL ) &&
+ ( p_input->stream.i_selected_es_number > 0 ) )
{
p_input->stream.i_selected_es_number--;
p_input->stream.pp_selected_es,
p_input->stream.i_selected_es_number
* sizeof(es_descriptor_t *) );
+
if( p_input->stream.pp_selected_es == NULL )
{
- intf_ErrMsg( "Unable to realloc memory in input_SelectES" );
- return(-1);
+ intf_WarnMsg( 4, "input: no more selected ES in input_UnselectES" );
+ return( 1 );
}
}
+
return( 0 );
}