/*****************************************************************************
* input_programs.c: es_descriptor_t, pgrm_descriptor_t management
*****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_programs.c,v 1.56 2001/05/19 00:39:30 stef Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: input_programs.c,v 1.77 2002/03/28 03:53:15 jobi 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_method = INPUT_METHOD_NONE;
p_input->stream.i_stream_id = 0;
/* initialized to 0 since we don't give the signal to the interface
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_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,
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_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;
- 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;
+
+ 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
*****************************************************************************
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 )
{
p_es->p_decoder_fifo = NULL;
p_es->b_audio = 0;
p_es->i_cat = UNKNOWN_ES;
+#ifdef HAVE_SATELLITE
+ p_es->i_dmx_fd = 0;
+#endif
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;
-
- 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 );
-}
-
-/*****************************************************************************
- * 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 );
- }
- 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 );
- }
-
- 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 ac3spdif_CreateThread( void * );
-vlc_thread_t spdif_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;
- void * p_config;
-
if( p_es == NULL )
{
- intf_ErrMsg( "Nothing to do in input_SelectES" );
+ intf_ErrMsg( "input error: nothing to do in input_SelectES" );
return -1;
}
-#ifdef TRACE_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 )
{
return( -1 );
}
+ p_es->thread_id = 0;
+
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_config = (void *)GetAdecConfig( 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( &decoder, p_config );
+ 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_config = (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( &decoder, p_config );
- vlc_mutex_lock( &p_input->stream.stream_lock );
- }
- break;
-
- case AC3_AUDIO_ES:
- if( p_main->b_audio )
- {
- if( main_GetIntVariable( AOUT_SPDIF_VAR, 0 ) )
- {
- decoder.pf_create_thread = spdif_CreateThread;
- }
- else
- {
- decoder.pf_create_thread = ac3dec_CreateThread;
- }
-
- p_config = (void *)GetAdecConfig( 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( &decoder, p_config );
- vlc_mutex_lock( &p_input->stream.stream_lock );
- }
- break;
- case LPCM_AUDIO_ES:
- if( p_main->b_audio )
- {
- intf_ErrMsg( "input error: LPCM audio not handled yet" );
- break;
-
- p_config = (void *)GetAdecConfig( 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( &decoder, p_config );
- vlc_mutex_lock( &p_input->stream.stream_lock );
- }
- break;
case DVD_SPU_ES:
if( p_main->b_video )
{
- decoder.pf_create_thread = spudec_CreateThread;
- p_config = (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( &decoder, p_config );
+ p_es->thread_id = input_RunDecoder( p_input, p_es );
vlc_mutex_lock( &p_input->stream.stream_lock );
}
break;
return -1;
}
-#ifdef TRACE_INPUT
- intf_DbgMsg( "Unselecting ES 0x%x", p_es->i_id );
-#endif
+ intf_WarnMsg( 4, "input: unselecting ES 0x%x", p_es->i_id );
if( p_es->p_decoder_fifo == NULL )
{
}
input_EndDecoder( p_input, p_es );
+ free( p_es->p_pes );
if( ( p_es->p_decoder_fifo == NULL ) &&
( p_input->stream.i_selected_es_number > 0 ) )
if( p_input->stream.pp_selected_es == NULL )
{
-#ifdef TRACE_INPUT
- intf_DbgMsg( "No more selected ES in input_UnselectES" );
-#endif
+ intf_WarnMsg( 4, "input: no more selected ES in input_UnselectES" );
return( 1 );
}
}