/*****************************************************************************
* Preamble
*****************************************************************************/
+#include "defs.h"
+
+#include <stdlib.h>
+
+#include "config.h"
+#include "common.h"
+#include "threads.h"
+#include "mtime.h"
+#include "debug.h"
+
+#include "intf_msg.h"
+
+#include "stream_control.h"
+#include "input_ext-intf.h"
+#include "input_ext-dec.h"
+#include "input.h"
+
+/*
+ * NOTICE : all of these functions expect you to have taken the lock on
+ * p_input->stream.lock
+ */
/*****************************************************************************
* input_InitStream: init the stream descriptor of the given input
*****************************************************************************/
-void input_InitStream( input_thread_t * p_input )
+void input_InitStream( input_thread_t * p_input, size_t i_data_len )
{
- p_input->stream->i_pgrm_number = 0;
- p_input->stream->pp_programs = NULL;
+ p_input->stream.i_pgrm_number = 0;
+ p_input->stream.pp_programs = NULL;
+
+ if( i_data_len )
+ {
+ p_input->stream.p_demux_data = malloc( i_data_len );
+ memset( p_input->stream.p_demux_data, 0, i_data_len );
+ }
}
/*****************************************************************************
* This program descriptor will be referenced in the given stream descriptor
*****************************************************************************/
pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
- u16 i_pgrm_id)
+ u16 i_pgrm_id, size_t i_data_len )
{
- int i_pgrm_index = p_stream->i_pgrm_number; /* Where to add the pgrm */
+ /* 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);
p_input->stream.pp_programs[i_pgrm_index]->c_average_count = 0;
p_input->stream.pp_programs[i_pgrm_index]->i_synchro_state
= SYNCHRO_NOT_STARTED;
+ p_input->stream.pp_programs[i_pgrm_index]->b_discontinuity = 0;
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 =
+ malloc( i_data_len );
+ memset( p_input->stream.pp_programs[i_pgrm_index]->p_demux_data, 0,
+ i_data_len );
+ }
+
return p_input->stream.pp_programs[i_pgrm_index];
}
/* Free the structures that describe the es that belongs to that program */
for( i_index = 0; i_index < p_pgrm->i_es_number; i_index++ )
{
- DestroyESDescr( p_input, p_pgrm, p_pgrm->pp_es[i_index]->i_id );
+ input_DelES( p_input, p_pgrm->pp_es[i_index]->i_id );
}
/* Free the table of es descriptors */
free( p_pgrm->pp_es );
+ /* Free the demux data */
+ if( p_pgrm->p_demux_data != NULL )
+ {
+ free( p_pgrm->p_demux_data );
+ }
+
/* Free the description of this stream */
free( p_pgrm );
* alone (PSI ?)
*****************************************************************************/
es_descriptor_t * input_AddES( input_thread_t * p_input,
- pgrm_descriptor_t * p_pgrm, u16 i_es_id)
+ pgrm_descriptor_t * p_pgrm, u16 i_es_id,
+ size_t i_data_len )
{
int i_index;
es_descriptor_t * p_es = NULL;
/* Init its values */
p_es->b_discontinuity = 0;
- p_es->p_pes_packet = NULL;
+ p_es->p_pes = NULL;
p_es->p_decoder_fifo = NULL;
+ if( i_data_len )
+ {
+ p_es->p_demux_data = malloc( i_data_len );
+ memset( p_es->p_demux_data, 0, i_data_len );
+ }
+
/* Add this ES to the program definition if one is given */
if( p_pgrm )
{
/*****************************************************************************
* input_DelES:
*****************************************************************************/
-void input_DelES( input_thread_t * p_input, u16 i_id)
+void input_DelES( input_thread_t * p_input, u16 i_id )
{
int i_index;
- program_descriptor_t * p_pgrm;
- es_descriptor_t * p_es;
+ pgrm_descriptor_t * p_pgrm = NULL;
+ es_descriptor_t * p_es = NULL;
/* Look for the description of the ES */
for( i_index = 0; i_index < INPUT_MAX_ES; i_index++ )
{
for( i_index = 0; ; i_index++ )
{
- if( p_pgrm->p_es[i_index].i_id == i_id )
+ if( p_pgrm->pp_es[i_index]->i_id == i_id )
{
p_pgrm->i_es_number--;
- p_pgrm->pp_es[i_index] = p_pgrm->p_es[p_pgrm->i_es_number];
+ p_pgrm->pp_es[i_index] = p_pgrm->pp_es[p_pgrm->i_es_number];
p_pgrm->pp_es = realloc( p_pgrm->pp_es,
p_pgrm->i_es_number
- * sizeof(es_decriptor_t *));
+ * sizeof(es_descriptor_t *));
break;
}
}
/* The table of stream descriptors is static, so don't free memory
* but just mark the slot as unused */
p_es->i_id = EMPTY_ID;
+
+ /* Free the demux data */
+ if( p_es->p_demux_data != NULL )
+ {
+ free( p_es->p_demux_data );
+ }
+}
+
+/*****************************************************************************
+ * 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_stream_id = p_es->i_stream_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 = 0;
+ p_config->p_decoder_fifo->p_packets_mgt = p_input->p_method_data;
+ p_config->p_decoder_fifo->pf_delete_pes =
+ p_input->p_plugin->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) );
+ 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) );
+ 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
+ *****************************************************************************/
+int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
+{
+ int i;
+ es_descriptor_t ** p_spot = NULL;
+
+#ifdef DEBUG_INPUT
+ intf_DbgMsg( "Selecting ES %d", p_es->i_id );
+#endif
+
+ if( p_es->p_decoder_fifo != NULL )
+ {
+ intf_ErrMsg( "ES %d is already selected", p_es->i_id );
+ return( -1 );
+ }
+
+ /* Find a free spot in pp_selected_es. */
+ for( i = 0; i < INPUT_MAX_SELECTED_ES; i++ )
+ {
+ if( p_input->pp_selected_es[i] == NULL )
+ {
+ p_spot = &p_input->pp_selected_es[i];
+ break;
+ }
+ }
+
+ if( p_spot == NULL )
+ {
+ intf_ErrMsg( "Too many ES selected" );
+ return( -1 );
+ }
+
+ switch( p_es->i_type )
+ {
+ /* FIXME ! */
+ case AC3_AUDIO_ES:
+ p_es->thread_id = ac3dec_CreateThread( GetAdecConfig( p_input, p_es ) );
+ break;
+
+ case MPEG1_AUDIO_ES:
+ case MPEG2_AUDIO_ES:
+ p_es->thread_id = adec_CreateThread( GetAdecConfig( p_input, p_es ) );
+ break;
+
+ case MPEG1_VIDEO_ES:
+ case MPEG2_VIDEO_ES:
+ p_es->thread_id = vpar_CreateThread( GetVdecConfig( p_input, p_es ) );
+ break;
+
+ default:
+ intf_ErrMsg( "Unknown stream type %d", p_es->i_type );
+ return( -1 );
+ break;
+ }
+
+ *p_spot = p_es;
+ return( 0 );
}
i_id = p_data->p_buffer[3]; /* ID of the stream. */
vlc_mutex_lock( &p_input->stream.stream_lock );
- for( i_dummy = 0; i_dummy < INPUT_MAX_ES; i_dummy++ )
+ for( i_dummy = 0; i_dummy < INPUT_MAX_SELECTED_ES; i_dummy++ )
{
- if( p_input->p_es[i_dummy].i_id == i_id )
+ if( p_input->pp_selected_es[i_dummy] != NULL
+ && p_input->pp_selected_es[i_dummy]->i_id == i_id )
{
- p_es = &p_input->p_es[i_dummy];
+ p_es = p_input->pp_selected_es[i_dummy];
break;
}
}
/* FIXME ! */
if( (i_id & 0xC0L) == 0xC0L )
{
+ vlc_mutex_lock( &p_input->stream.stream_lock );
/* MPEG video and audio */
- for( i_dummy = 0; i_dummy < INPUT_MAX_ES; i_dummy++ )
- {
- if( p_input->p_es[i_dummy].i_id == EMPTY_ID )
- {
- p_es = &p_input->p_es[i_dummy];
- break;
- }
- }
+ p_es = input_AddES( p_input, p_input->stream.pp_programs[0],
+ i_id, 0 );
if( p_es != NULL && (i_id & 0xF0L) == 0xE0L )
{
/* MPEG video */
- vdec_config_t * p_config;
- p_es->i_id = p_es->i_stream_id = i_id;
+ p_es->i_stream_id = i_id;
p_es->i_type = MPEG2_VIDEO_ES;
- p_es->p_pgrm = p_input->stream.pp_programs[0];
- p_es->p_pes = NULL;
#ifdef AUTO_SPAWN
- p_config = (vdec_config_t *)malloc( sizeof(vdec_config_t) );
- p_config->p_vout = p_input->p_default_vout;
- /* FIXME ! */
- p_config->decoder_config.i_stream_id = i_id;
- p_config->decoder_config.i_type = MPEG2_VIDEO_ES;
- p_config->decoder_config.p_stream_ctrl =
- &p_input->stream.control;
- p_config->decoder_config.p_decoder_fifo =
- (decoder_fifo_t *)malloc( sizeof(decoder_fifo_t) );
- vlc_mutex_init(&p_config->decoder_config.p_decoder_fifo->data_lock);
- vlc_cond_init(&p_config->decoder_config.p_decoder_fifo->data_wait);
- p_config->decoder_config.p_decoder_fifo->i_start =
- p_config->decoder_config.p_decoder_fifo->i_end = 0;
- p_config->decoder_config.p_decoder_fifo->b_die = 0;
- p_config->decoder_config.p_decoder_fifo->p_packets_mgt =
- p_input->p_method_data;
- p_config->decoder_config.p_decoder_fifo->pf_delete_pes =
- p_input->p_plugin->pf_delete_pes;
- p_es->p_decoder_fifo = p_config->decoder_config.p_decoder_fifo;
- p_config->decoder_config.pf_init_bit_stream =
- InitBitstream;
- for( i_dummy = 0; i_dummy < INPUT_MAX_SELECTED_ES; i_dummy++ )
- {
- if( p_input->pp_selected_es[i_dummy] == NULL )
- {
- p_input->pp_selected_es[i_dummy] = p_es;
- break;
- }
- }
-
- p_es->thread_id = vpar_CreateThread( p_config );
+ input_SelectES( p_input, p_es );
#endif
}
else if( p_es != NULL && (i_id & 0xE0) == 0xC0 )
{
/* MPEG audio */
- adec_config_t * p_config;
- p_es->i_id = p_es->i_stream_id = i_id;
+ p_es->i_stream_id = i_id;
p_es->i_type = MPEG2_AUDIO_ES;
- p_es->p_pgrm = p_input->stream.pp_programs[0];
- p_es->p_pes = NULL;
#ifdef AUTO_SPAWN
- p_config = (adec_config_t *)malloc( sizeof(adec_config_t) );
- p_config->p_aout = p_input->p_default_aout;
- /* FIXME ! */
- p_config->decoder_config.i_stream_id = i_id;
- p_config->decoder_config.i_type = MPEG2_AUDIO_ES;
- p_config->decoder_config.p_stream_ctrl =
- &p_input->stream.control;
- p_config->decoder_config.p_decoder_fifo =
- (decoder_fifo_t *)malloc( sizeof(decoder_fifo_t) );
- vlc_mutex_init(&p_config->decoder_config.p_decoder_fifo->data_lock);
- vlc_cond_init(&p_config->decoder_config.p_decoder_fifo->data_wait);
- p_config->decoder_config.p_decoder_fifo->i_start =
- p_config->decoder_config.p_decoder_fifo->i_end = 0;
- p_config->decoder_config.p_decoder_fifo->b_die = 0;
- p_config->decoder_config.p_decoder_fifo->p_packets_mgt =
- p_input->p_method_data;
- p_config->decoder_config.p_decoder_fifo->pf_delete_pes =
- p_input->p_plugin->pf_delete_pes;
- p_es->p_decoder_fifo = p_config->decoder_config.p_decoder_fifo;
- p_config->decoder_config.pf_init_bit_stream =
- InitBitstream;
- for( i_dummy = 0; i_dummy < INPUT_MAX_SELECTED_ES; i_dummy++ )
- {
- if( p_input->pp_selected_es[i_dummy] == NULL )
- {
- p_input->pp_selected_es[i_dummy] = p_es;
- break;
- }
- }
-
- p_es->thread_id = adec_CreateThread( p_config );
+ input_SelectES( p_input, p_es );
#endif
}
else
{
b_trash = 1;
}
+ vlc_mutex_unlock( &p_input->stream.stream_lock );
}
else
b_trash = 1;