Commit 67bc00c9 authored by Christophe Massiot's avatar Christophe Massiot

* Cleaned up program and ES management by using input_programs.c whenever

necessary.
* Cleaned up decoder spawning.
parent 4d26594b
......@@ -188,6 +188,7 @@ INTERFACE = src/interface/main.o \
INPUT = src/input/input_ps.o \
src/input/mpeg_system.o \
src/input/input_ext-dec.o \
src/input/input_programs.o \
src/input/input.o
AUDIO_OUTPUT = src/audio_output/audio_output.o
......
......@@ -46,3 +46,17 @@ typedef struct input_capabilities_s
*****************************************************************************/
void InitBitstream ( struct bit_stream_s *, struct decoder_fifo_s * );
void NextDataPacket ( struct bit_stream_s * );
/*****************************************************************************
* Prototypes from input_programs.c
*****************************************************************************/
void input_InitStream( struct input_thread_s *, size_t );
struct pgrm_descriptor_s * input_AddProgram( struct input_thread_s *,
u16, size_t );
void input_DelProgram( struct input_thread_s *, u16 );
struct es_descriptor_s * input_AddES( struct input_thread_s *,
struct pgrm_descriptor_s *, u16,
size_t );
void input_DelES( struct input_thread_s *, u16 );
int input_SelectES( struct input_thread_s *, struct es_descriptor_s * );
......@@ -23,14 +23,41 @@
/*****************************************************************************
* 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 );
}
}
/*****************************************************************************
......@@ -39,9 +66,10 @@ void input_InitStream( input_thread_t * p_input )
* 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);
......@@ -68,12 +96,21 @@ pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
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];
}
......@@ -107,12 +144,18 @@ void input_DelProgram( input_thread_t * p_input, u16 i_pgrm_id )
/* 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 );
......@@ -133,7 +176,8 @@ void input_DelProgram( input_thread_t * p_input, u16 i_pgrm_id )
* 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;
......@@ -159,9 +203,15 @@ es_descriptor_t * input_AddES( input_thread_t * p_input,
/* 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 )
{
......@@ -184,11 +234,11 @@ es_descriptor_t * input_AddES( input_thread_t * p_input,
/*****************************************************************************
* 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++ )
......@@ -209,13 +259,13 @@ void input_DelES( input_thread_t * p_input, u16 i_id)
{
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;
}
}
......@@ -224,4 +274,142 @@ void input_DelES( input_thread_t * p_input, u16 i_id)
/* 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 );
}
......@@ -80,7 +80,6 @@ static int PSProbe( input_thread_t * p_input )
static void PSInit( input_thread_t * p_input )
{
thread_ps_data_t * p_method;
stream_ps_data_t * p_demux;
if( (p_method =
(thread_ps_data_t *)malloc( sizeof(thread_ps_data_t) )) == NULL )
......@@ -103,19 +102,8 @@ static void PSInit( input_thread_t * p_input )
/* Pre-parse the stream to gather stream_descriptor_t. */
/* FIXME */
p_input->stream.pp_programs =
(pgrm_descriptor_t **)malloc( sizeof(pgrm_descriptor_t *) );
p_input->stream.pp_programs[0] =
(pgrm_descriptor_t *)malloc( sizeof(pgrm_descriptor_t) );
p_input->stream.pp_programs[0]->i_synchro_state = SYNCHRO_START;
p_input->stream.pp_programs[0]->delta_cr = 0;
p_input->stream.pp_programs[0]->last_cr = 0;
p_input->stream.pp_programs[0]->c_average_count = 0;
p_demux = (stream_ps_data_t *)malloc( sizeof( stream_ps_data_t) );
p_input->stream.p_demux_data = (void *)p_demux;
p_demux->b_is_PSM_complete = 0;
input_InitStream( p_input, 0 );
input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) );
}
/*****************************************************************************
......
......@@ -806,11 +806,12 @@ void input_DemuxPS( input_thread_t * p_input, data_packet_t * p_data )
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;
}
}
......@@ -822,106 +823,36 @@ void input_DemuxPS( input_thread_t * p_input, data_packet_t * p_data )
/* 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;
......
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 to comment