From fafbe100b1b1116959590f84e98ee5e4fa2a3ac8 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 30 Dec 2001 05:38:44 +0000 Subject: [PATCH] * Put ErrorThread() in input_ext-dec.h because it was the same function in all decoders. Called it DecoderError() instead. * All decoders enter DecoderError() in case of error, even if they haven't allocated all their data. This prevents the input from getting stuck if a decoder has failed its initialization. * Namespace fixes through the decoder files. --- include/common.h | 3 +- include/input_ext-dec.h | 13 +++++- include/modules_export.h | 2 + plugins/ac3_adec/ac3_adec.c | 71 ++++++++++-------------------- plugins/ac3_spdif/ac3_spdif.c | 69 ++++++++++------------------- plugins/lpcm_adec/lpcm_adec.c | 75 +++++++++++--------------------- plugins/mad/mad_adec.c | 70 ++++++++++------------------- plugins/mpeg_adec/mpeg_adec.c | 68 ++++++++--------------------- plugins/mpeg_adec/mpeg_adec.h | 3 +- plugins/mpeg_vdec/video_parser.c | 73 ++++++++++--------------------- plugins/spudec/spu_decoder.c | 68 ++++++++--------------------- src/input/input_ext-dec.c | 25 ++++++++++- 12 files changed, 194 insertions(+), 346 deletions(-) diff --git a/include/common.h b/include/common.h index 25e10f65f5..bb92dd14aa 100644 --- a/include/common.h +++ b/include/common.h @@ -3,7 +3,7 @@ * Collection of useful common types and macros definitions ***************************************************************************** * Copyright (C) 1998, 1999, 2000 VideoLAN - * $Id: common.h,v 1.61 2001/12/27 01:49:34 massiot Exp $ + * $Id: common.h,v 1.62 2001/12/30 05:38:44 sam Exp $ * * Authors: Samuel Hocevar * Vincent Seguin @@ -499,6 +499,7 @@ typedef struct module_symbols_s void ( * ) ( struct bit_stream_s *, boolean_t ), void * ); + void ( * DecoderError ) ( struct decoder_fifo_s * p_fifo ); int ( * input_InitStream ) ( struct input_thread_s *, size_t ); void ( * input_EndStream ) ( struct input_thread_s * ); diff --git a/include/input_ext-dec.h b/include/input_ext-dec.h index f0eef86e28..093284416b 100644 --- a/include/input_ext-dec.h +++ b/include/input_ext-dec.h @@ -2,7 +2,7 @@ * input_ext-dec.h: structures exported to the VideoLAN decoders ***************************************************************************** * Copyright (C) 1999-2001 VideoLAN - * $Id: input_ext-dec.h,v 1.48 2001/12/29 03:07:51 massiot Exp $ + * $Id: input_ext-dec.h,v 1.49 2001/12/30 05:38:44 sam Exp $ * * Authors: Christophe Massiot * Michel Kaempf @@ -209,7 +209,7 @@ typedef struct bit_stream_s #endif /***************************************************************************** - * Protoypes from input_ext-dec.c + * Prototypes from input_ext-dec.c *****************************************************************************/ #ifndef PLUGIN u32 UnalignedShowBits( struct bit_stream_s *, unsigned int ); @@ -533,3 +533,12 @@ typedef struct decoder_config_s void * ); } decoder_config_t; +/***************************************************************************** + * Prototypes from input_dec.c + *****************************************************************************/ +#ifndef PLUGIN +void DecoderError ( struct decoder_fifo_s * p_fifo ); +#else +# define DecoderError p_symbols->DecoderError +#endif + diff --git a/include/modules_export.h b/include/modules_export.h index bfa7595f94..1b7e0633ef 100644 --- a/include/modules_export.h +++ b/include/modules_export.h @@ -65,6 +65,7 @@ (p_symbols)->input_AddArea = input_AddArea; \ (p_symbols)->input_DelArea = input_DelArea; \ (p_symbols)->InitBitstream = InitBitstream; \ + (p_symbols)->DecoderError = DecoderError; \ (p_symbols)->input_InitStream = input_InitStream; \ (p_symbols)->input_EndStream = input_EndStream; \ (p_symbols)->input_ParsePES = input_ParsePES; \ @@ -163,6 +164,7 @@ # define input_DelArea p_symbols->input_DelArea # define InitBitstream p_symbols->InitBitstream +# define DecoderError p_symbols->DecoderError # define input_InitStream p_symbols->input_InitStream # define input_EndStream p_symbols->input_EndStream diff --git a/plugins/ac3_adec/ac3_adec.c b/plugins/ac3_adec/ac3_adec.c index c795449aee..6029fb4912 100644 --- a/plugins/ac3_adec/ac3_adec.c +++ b/plugins/ac3_adec/ac3_adec.c @@ -2,7 +2,7 @@ * ac3_adec.c: ac3 decoder module main file ***************************************************************************** * Copyright (C) 1999-2001 VideoLAN - * $Id: ac3_adec.c,v 1.9 2001/12/27 01:49:34 massiot Exp $ + * $Id: ac3_adec.c,v 1.10 2001/12/30 05:38:44 sam Exp $ * * Authors: Michel Lespinasse * @@ -60,21 +60,20 @@ /***************************************************************************** * Local prototypes *****************************************************************************/ -static int ac3_adec_Probe ( probedata_t * ); -static int ac3_adec_Run ( decoder_config_t * ); -static int ac3_adec_Init (ac3dec_thread_t * p_adec); -static void ac3_adec_ErrorThread (ac3dec_thread_t * p_adec); -static void ac3_adec_EndThread (ac3dec_thread_t * p_adec); -static void BitstreamCallback ( bit_stream_t *p_bit_stream, - boolean_t b_new_pes ); +static int decoder_Probe ( probedata_t * ); +static int decoder_Run ( decoder_config_t * ); +static int InitThread ( ac3dec_thread_t * p_adec ); +static void EndThread ( ac3dec_thread_t * p_adec ); +static void BitstreamCallback ( bit_stream_t *p_bit_stream, + boolean_t b_new_pes ); /***************************************************************************** * Capabilities *****************************************************************************/ void _M( adec_getfunctions )( function_list_t * p_function_list ) { - p_function_list->pf_probe = ac3_adec_Probe; - p_function_list->functions.dec.pf_run = ac3_adec_Run; + p_function_list->pf_probe = decoder_Probe; + p_function_list->functions.dec.pf_run = decoder_Run; } /***************************************************************************** @@ -99,20 +98,20 @@ MODULE_DEACTIVATE_STOP /***************************************************************************** - * ac3_adec_Probe: probe the decoder and return score + * decoder_Probe: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ -static int ac3_adec_Probe( probedata_t *p_data ) +static int decoder_Probe( probedata_t *p_data ) { return ( p_data->i_type == AC3_AUDIO_ES ) ? 50 : 0; } /***************************************************************************** - * ac3_adec_Run: this function is called just after the thread is created + * decoder_Run: this function is called just after the thread is created *****************************************************************************/ -static int ac3_adec_Run ( decoder_config_t * p_config ) +static int decoder_Run ( decoder_config_t * p_config ) { ac3dec_thread_t * p_ac3thread; int sync; @@ -125,7 +124,8 @@ static int ac3_adec_Run ( decoder_config_t * p_config ) if( p_ac3thread == NULL ) { intf_ErrMsg ( "ac3_adec error: not enough memory " - "for ac3_adec_Run() to allocate p_ac3thread" ); + "for decoder_Run() to allocate p_ac3thread" ); + DecoderError( p_config->p_decoder_fifo ); return( -1 ); } @@ -133,9 +133,10 @@ static int ac3_adec_Run ( decoder_config_t * p_config ) * Initialize the thread properties */ p_ac3thread->p_config = p_config; - if( ac3_adec_Init( p_ac3thread ) ) + if( InitThread( p_ac3thread ) ) { intf_ErrMsg( "ac3_adec error: could not initialize thread" ); + DecoderError( p_config->p_decoder_fifo ); free( p_ac3thread ); return( -1 ); } @@ -211,11 +212,11 @@ static int ac3_adec_Run ( decoder_config_t * p_config ) /* If b_error is set, the ac3 decoder thread enters the error loop */ if (p_ac3thread->p_fifo->b_error) { - ac3_adec_ErrorThread (p_ac3thread); + DecoderError( p_ac3thread->p_fifo ); } /* End of the ac3 decoder thread */ - ac3_adec_EndThread (p_ac3thread); + EndThread (p_ac3thread); free( p_ac3thread ); @@ -224,9 +225,9 @@ static int ac3_adec_Run ( decoder_config_t * p_config ) /***************************************************************************** - * ac3_adec_Init: initialize data before entering main loop + * InitThread: initialize data before entering main loop *****************************************************************************/ -static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread ) +static int InitThread( ac3dec_thread_t * p_ac3thread ) { /* * Thread properties @@ -372,35 +373,9 @@ static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread ) /***************************************************************************** - * ac3_adec_ErrorThread : ac3 decoder's RunThread() error loop + * EndThread : ac3 decoder thread destruction *****************************************************************************/ -static void ac3_adec_ErrorThread (ac3dec_thread_t * p_ac3thread) -{ - /* We take the lock, because we are going to read/write the start/end - * indexes of the decoder fifo */ - vlc_mutex_lock (&p_ac3thread->p_fifo->data_lock); - - /* Wait until a `die' order is sent */ - while (!p_ac3thread->p_fifo->b_die) - { - /* Trash all received PES packets */ - p_ac3thread->p_fifo->pf_delete_pes( - p_ac3thread->p_fifo->p_packets_mgt, - p_ac3thread->p_fifo->p_first ); - - /* Waiting for the input thread to put new PES packets in the fifo */ - vlc_cond_wait (&p_ac3thread->p_fifo->data_wait, - &p_ac3thread->p_fifo->data_lock); - } - - /* We can release the lock before leaving */ - vlc_mutex_unlock (&p_ac3thread->p_fifo->data_lock); -} - -/***************************************************************************** - * ac3_adec_EndThread : ac3 decoder thread destruction - *****************************************************************************/ -static void ac3_adec_EndThread (ac3dec_thread_t * p_ac3thread) +static void EndThread (ac3dec_thread_t * p_ac3thread) { intf_DbgMsg ("ac3dec debug: destroying ac3 decoder thread %p", p_ac3thread); diff --git a/plugins/ac3_spdif/ac3_spdif.c b/plugins/ac3_spdif/ac3_spdif.c index 8e81ff9061..f8555db580 100644 --- a/plugins/ac3_spdif/ac3_spdif.c +++ b/plugins/ac3_spdif/ac3_spdif.c @@ -2,7 +2,7 @@ * ac3_spdif.c: ac3 pass-through to external decoder with enabled soundcard ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: ac3_spdif.c,v 1.8 2001/12/27 01:49:34 massiot Exp $ + * $Id: ac3_spdif.c,v 1.9 2001/12/30 05:38:44 sam Exp $ * * Authors: Stéphane Borel * Juha Yrjola @@ -61,20 +61,19 @@ /**************************************************************************** * Local Prototypes ****************************************************************************/ -static int ac3_spdif_Probe ( probedata_t * ); -static int ac3_spdif_Run ( decoder_config_t * ); -static int ac3_spdif_Init ( ac3_spdif_thread_t * ); -static void ac3_spdif_ErrorThread ( ac3_spdif_thread_t * ); -static void ac3_spdif_EndThread ( ac3_spdif_thread_t * ); -static void BitstreamCallback( bit_stream_t *, boolean_t ); +static int decoder_Probe ( probedata_t * ); +static int decoder_Run ( decoder_config_t * ); +static int InitThread ( ac3_spdif_thread_t * ); +static void EndThread ( ac3_spdif_thread_t * ); +static void BitstreamCallback ( bit_stream_t *, boolean_t ); /***************************************************************************** * Capabilities *****************************************************************************/ void _M( adec_getfunctions )( function_list_t * p_function_list ) { - p_function_list->pf_probe = ac3_spdif_Probe; - p_function_list->functions.dec.pf_run = ac3_spdif_Run; + p_function_list->pf_probe = decoder_Probe; + p_function_list->functions.dec.pf_run = decoder_Run; } /***************************************************************************** @@ -98,12 +97,12 @@ MODULE_DEACTIVATE_START MODULE_DEACTIVATE_STOP /***************************************************************************** - * ac3_spdif_Probe: probe the decoder and return score + * decoder_Probe: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ -static int ac3_spdif_Probe( probedata_t *p_data ) +static int decoder_Probe( probedata_t *p_data ) { if( main_GetIntVariable( AOUT_SPDIF_VAR, 0 ) && p_data->i_type == AC3_AUDIO_ES ) @@ -114,11 +113,11 @@ static int ac3_spdif_Probe( probedata_t *p_data ) /**************************************************************************** - * ac3_spdif_Run: the whole thing + * decoder_Run: the whole thing **************************************************************************** * This function is called just after the thread is launched. ****************************************************************************/ -static int ac3_spdif_Run( decoder_config_t * p_config ) +static int decoder_Run( decoder_config_t * p_config ) { ac3_spdif_thread_t * p_spdif; mtime_t i_frame_time; @@ -135,14 +134,17 @@ static int ac3_spdif_Run( decoder_config_t * p_config ) { intf_ErrMsg ( "spdif error: not enough memory " "for spdif_CreateThread() to create the new thread"); + DecoderError( p_config->p_decoder_fifo ); return( -1 ); } p_spdif->p_config = p_config; - if (ac3_spdif_Init( p_spdif ) ) + if (InitThread( p_spdif ) ) { intf_ErrMsg( "spdif error: could not initialize thread" ); + DecoderError( p_config->p_decoder_fifo ); + free( p_spdif ); return( -1 ); } @@ -213,19 +215,19 @@ static int ac3_spdif_Run( decoder_config_t * p_config ) /* If b_error is set, the ac3 spdif thread enters the error loop */ if( p_spdif->p_fifo->b_error ) { - ac3_spdif_ErrorThread( p_spdif ); + DecoderError( p_spdif->p_fifo ); } /* End of the ac3 decoder thread */ - ac3_spdif_EndThread( p_spdif ); + EndThread( p_spdif ); return( 0 ); } /**************************************************************************** - * ac3_spdif_Init: initialize thread data and create output fifo + * InitThread: initialize thread data and create output fifo ****************************************************************************/ -static int ac3_spdif_Init( ac3_spdif_thread_t * p_spdif ) +static int InitThread( ac3_spdif_thread_t * p_spdif ) { boolean_t b_sync = 0; @@ -301,37 +303,10 @@ static int ac3_spdif_Init( ac3_spdif_thread_t * p_spdif ) return( 0 ); } - -/***************************************************************************** - * ac3_spdif_ErrorThread : ac3 spdif's RunThread() error loop - *****************************************************************************/ -static void ac3_spdif_ErrorThread( ac3_spdif_thread_t * p_spdif ) -{ - /* We take the lock, because we are going to read/write the start/end - * indexes of the decoder fifo */ - vlc_mutex_lock (&p_spdif->p_fifo->data_lock); - - /* Wait until a `die' order is sent */ - while( !p_spdif->p_fifo->b_die ) - { - /* Trash all received PES packets */ - p_spdif->p_fifo->pf_delete_pes( - p_spdif->p_fifo->p_packets_mgt, - p_spdif->p_fifo->p_first ); - - /* Waiting for the input thread to put new PES packets in the fifo */ - vlc_cond_wait( &p_spdif->p_fifo->data_wait, - &p_spdif->p_fifo->data_lock ); - } - - /* We can release the lock before leaving */ - vlc_mutex_unlock( &p_spdif->p_fifo->data_lock ); -} - /***************************************************************************** - * ac3_spdif_EndThread : ac3 spdif thread destruction + * EndThread : ac3 spdif thread destruction *****************************************************************************/ -static void ac3_spdif_EndThread( ac3_spdif_thread_t * p_spdif ) +static void EndThread( ac3_spdif_thread_t * p_spdif ) { intf_DbgMsg( "spdif debug: destroying thread %p", p_spdif ); diff --git a/plugins/lpcm_adec/lpcm_adec.c b/plugins/lpcm_adec/lpcm_adec.c index ad24707f1a..21af5b31dc 100644 --- a/plugins/lpcm_adec/lpcm_adec.c +++ b/plugins/lpcm_adec/lpcm_adec.c @@ -2,7 +2,7 @@ * lpcm_decoder_thread.c: lpcm decoder thread ***************************************************************************** * Copyright (C) 1999-2001 VideoLAN - * $Id: lpcm_adec.c,v 1.6 2001/12/27 01:49:34 massiot Exp $ + * $Id: lpcm_adec.c,v 1.7 2001/12/30 05:38:44 sam Exp $ * * Authors: Samuel Hocevar * Henri Fallon @@ -56,12 +56,11 @@ /***************************************************************************** * Local prototypes *****************************************************************************/ -static int lpcm_adec_Probe ( probedata_t * ); -static int lpcm_adec_Run ( decoder_config_t * ); -void lpcm_adec_DecodeFrame ( lpcmdec_thread_t * ); -static int lpcm_adec_Init ( lpcmdec_thread_t * ); -static void lpcm_adec_ErrorThread ( lpcmdec_thread_t * ); -static void lpcm_adec_EndThread ( lpcmdec_thread_t * ); +static int decoder_Probe ( probedata_t * ); +static int decoder_Run ( decoder_config_t * ); + void DecodeFrame ( lpcmdec_thread_t * ); +static int InitThread ( lpcmdec_thread_t * ); +static void EndThread ( lpcmdec_thread_t * ); /***************************************************************************** @@ -69,8 +68,8 @@ static void lpcm_adec_EndThread ( lpcmdec_thread_t * ); *****************************************************************************/ void _M( adec_getfunctions )( function_list_t * p_function_list ) { - p_function_list->pf_probe = lpcm_adec_Probe; - p_function_list->functions.dec.pf_run = lpcm_adec_Run; + p_function_list->pf_probe = decoder_Probe; + p_function_list->functions.dec.pf_run = decoder_Run; } /***************************************************************************** @@ -94,9 +93,9 @@ MODULE_DEACTIVATE_START MODULE_DEACTIVATE_STOP /***************************************************************************** - * lpcm_adec_Probe: probe the decoder and return score + * decoder_Probe: probe the decoder and return score *****************************************************************************/ -static int lpcm_adec_Probe( probedata_t *p_data ) +static int decoder_Probe( probedata_t *p_data ) { if( p_data->i_type == LPCM_AUDIO_ES ) return( 100 ); @@ -105,9 +104,9 @@ static int lpcm_adec_Probe( probedata_t *p_data ) } /***************************************************************************** - * lpcm_adec_Run: the lpcm decoder + * decoder_Run: the lpcm decoder *****************************************************************************/ -static int lpcm_adec_Run( decoder_config_t * p_config ) +static int decoder_Run( decoder_config_t * p_config ) { lpcmdec_thread_t * p_lpcmdec; @@ -118,6 +117,7 @@ static int lpcm_adec_Run( decoder_config_t * p_config ) == NULL) { intf_ErrMsg( "LPCM : error : cannot create lpcmdec_thread_t" ); + DecoderError( p_config->p_decoder_fifo ); return( -1 ); } @@ -127,8 +127,10 @@ static int lpcm_adec_Run( decoder_config_t * p_config ) p_lpcmdec->p_config = p_config; p_lpcmdec->p_fifo = p_config->p_decoder_fifo; - if( lpcm_adec_Init( p_lpcmdec ) ) + if( InitThread( p_lpcmdec ) ) { + DecoderError( p_config->p_decoder_fifo ); + free( p_lpcmdec ); return( -1 ); } @@ -138,25 +140,25 @@ static int lpcm_adec_Run( decoder_config_t * p_config ) /* lpcm decoder thread's main loop */ while ((!p_lpcmdec->p_fifo->b_die) && (!p_lpcmdec->p_fifo->b_error)) { - lpcm_adec_DecodeFrame(p_lpcmdec); + DecodeFrame(p_lpcmdec); } /* If b_error is set, the lpcm decoder thread enters the error loop */ if (p_lpcmdec->p_fifo->b_error) { - lpcm_adec_ErrorThread (p_lpcmdec); + DecoderError( p_lpcmdec->p_fifo ); } /* End of the lpcm decoder thread */ - lpcm_adec_EndThread (p_lpcmdec); + EndThread (p_lpcmdec); return( 0 ); } /***************************************************************************** - * lpcm_adec_Init : initialize an lpcm decoder thread + * InitThread : initialize an lpcm decoder thread *****************************************************************************/ -static int lpcm_adec_Init (lpcmdec_thread_t * p_lpcmdec) +static int InitThread (lpcmdec_thread_t * p_lpcmdec) { /* Init the BitStream */ @@ -176,9 +178,9 @@ static int lpcm_adec_Init (lpcmdec_thread_t * p_lpcmdec) } /***************************************************************************** - * lpcm_adec_DecodeFrame: decodes a frame. + * DecodeFrame: decodes a frame. *****************************************************************************/ -void lpcm_adec_DecodeFrame( lpcmdec_thread_t * p_lpcmdec ) +void DecodeFrame( lpcmdec_thread_t * p_lpcmdec ) { byte_t * buffer,p_temp[LPCMDEC_FRAME_SIZE]; int i_loop; @@ -232,37 +234,10 @@ void lpcm_adec_DecodeFrame( lpcmdec_thread_t * p_lpcmdec ) } - -/***************************************************************************** - * lpcm_adec_ErrorThread : lpcm decoder's RunThread() error loop - *****************************************************************************/ -static void lpcm_adec_ErrorThread( lpcmdec_thread_t * p_lpcmdec ) -{ - /* We take the lock, because we are going to read/write the start/end - * indexes of the decoder fifo */ - vlc_mutex_lock( &p_lpcmdec->p_fifo->data_lock ); - - /* Wait until a `die' order is sent */ - while( !p_lpcmdec->p_fifo->b_die ) - { - /* Trash all received PES packets */ - p_lpcmdec->p_fifo->pf_delete_pes( - p_lpcmdec->p_fifo->p_packets_mgt, - p_lpcmdec->p_fifo->p_first ); - - /* Waiting for the input thread to put new PES packets in the fifo */ - vlc_cond_wait ( &p_lpcmdec->p_fifo->data_wait, - &p_lpcmdec->p_fifo->data_lock ); - } - - /* We can release the lock before leaving */ - vlc_mutex_unlock( &p_lpcmdec->p_fifo->data_lock ); -} - /***************************************************************************** - * lpcm_adec_EndThread : lpcm decoder thread destruction + * EndThread : lpcm decoder thread destruction *****************************************************************************/ -static void lpcm_adec_EndThread( lpcmdec_thread_t * p_lpcmdec ) +static void EndThread( lpcmdec_thread_t * p_lpcmdec ) { intf_DbgMsg( "LPCM Debug: destroying lpcm decoder thread %p", p_lpcmdec ); diff --git a/plugins/mad/mad_adec.c b/plugins/mad/mad_adec.c index 8cbf0ae5d4..9610db534d 100644 --- a/plugins/mad/mad_adec.c +++ b/plugins/mad/mad_adec.c @@ -57,19 +57,18 @@ /***************************************************************************** * Local prototypes *****************************************************************************/ -static int mad_adec_Probe ( probedata_t * ); -static int mad_adec_Run ( decoder_config_t * ); -static int mad_adec_Init (mad_adec_thread_t * p_mad_adec); -static void mad_adec_ErrorThread (mad_adec_thread_t * p_mad_adec); -static void mad_adec_EndThread (mad_adec_thread_t * p_mad_adec); +static int decoder_Probe ( probedata_t * ); +static int decoder_Run ( decoder_config_t * ); +static int InitThread ( mad_adec_thread_t * p_mad_adec ); +static void EndThread ( mad_adec_thread_t * p_mad_adec ); /***************************************************************************** * Capabilities *****************************************************************************/ void _M( adec_getfunctions )( function_list_t * p_function_list ) { - p_function_list->pf_probe = mad_adec_Probe; - p_function_list->functions.dec.pf_run = mad_adec_Run; + p_function_list->pf_probe = decoder_Probe; + p_function_list->functions.dec.pf_run = decoder_Run; } /***************************************************************************** @@ -93,12 +92,12 @@ MODULE_DEACTIVATE_START MODULE_DEACTIVATE_STOP /***************************************************************************** - * mad_adec_Probe: probe the decoder and return score + * decoder_Probe: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ -static int mad_adec_Probe( probedata_t *p_data ) +static int decoder_Probe( probedata_t *p_data ) { if( p_data->i_type == MPEG1_AUDIO_ES || p_data->i_type == MPEG2_AUDIO_ES ) { @@ -115,9 +114,9 @@ static int mad_adec_Probe( probedata_t *p_data ) } /***************************************************************************** - * mad_adec_Run: this function is called just after the thread is created + * decoder_Run: this function is called just after the thread is created *****************************************************************************/ -static int mad_adec_Run ( decoder_config_t * p_config ) +static int decoder_Run ( decoder_config_t * p_config ) { mad_adec_thread_t * p_mad_adec; @@ -129,7 +128,8 @@ static int mad_adec_Run ( decoder_config_t * p_config ) if (p_mad_adec == NULL) { intf_ErrMsg ( "mad_adec error: not enough memory " - "for mad_adec_Run() to allocate p_mad_adec" ); + "for decoder_Run() to allocate p_mad_adec" ); + DecoderError( p_config->p_decoder_fifo ); return( -1 ); } @@ -138,9 +138,11 @@ static int mad_adec_Run ( decoder_config_t * p_config ) */ p_mad_adec->p_config = p_config; p_mad_adec->p_fifo = p_mad_adec->p_config->p_decoder_fifo; - if( mad_adec_Init( p_mad_adec ) ) + if( InitThread( p_mad_adec ) ) { intf_ErrMsg( "mad_adec error: could not initialize thread" ); + DecoderError( p_config->p_decoder_fifo ); + free( p_mad_adec ); return( -1 ); } @@ -151,7 +153,8 @@ static int mad_adec_Run ( decoder_config_t * p_config ) if (mad_decoder_run(p_mad_adec->libmad_decoder, MAD_DECODER_MODE_SYNC)==-1) { intf_ErrMsg( "mad_adec error: libmad decoder returns abnormally"); - mad_adec_EndThread(p_mad_adec); + DecoderError( p_mad_adec->p_fifo ); + EndThread(p_mad_adec); return( -1 ); } } @@ -159,19 +162,19 @@ static int mad_adec_Run ( decoder_config_t * p_config ) /* If b_error is set, the mad decoder thread enters the error loop */ if (p_mad_adec->p_fifo->b_error) { - mad_adec_ErrorThread (p_mad_adec); + DecoderError( p_mad_adec->p_fifo ); } /* End of the ac3 decoder thread */ - mad_adec_EndThread (p_mad_adec); + EndThread (p_mad_adec); return( 0 ); } /***************************************************************************** - * mad_adec_Init: initialize data before entering main loop + * InitThread: initialize data before entering main loop *****************************************************************************/ -static int mad_adec_Init( mad_adec_thread_t * p_mad_adec ) +static int InitThread( mad_adec_thread_t * p_mad_adec ) { /* * Properties of audio for libmad @@ -223,37 +226,10 @@ static int mad_adec_Init( mad_adec_thread_t * p_mad_adec ) return( 0 ); } - -/***************************************************************************** - * mad_adec_ErrorThread : mad decoder's RunThread() error loop - *****************************************************************************/ -static void mad_adec_ErrorThread (mad_adec_thread_t * p_mad_adec) -{ - /* We take the lock, because we are going to read/write the start/end - * indexes of the decoder fifo */ - vlc_mutex_lock (&p_mad_adec->p_fifo->data_lock); - - /* Wait until a `die' order is sent */ - while (!p_mad_adec->p_fifo->b_die) - { - /* Trash all received PES packets */ - p_mad_adec->p_fifo->pf_delete_pes( - p_mad_adec->p_fifo->p_packets_mgt, - p_mad_adec->p_fifo->p_first ); - - /* Waiting for the input thread to put new PES packets in the fifo */ - vlc_cond_wait (&p_mad_adec->p_fifo->data_wait, - &p_mad_adec->p_fifo->data_lock); - } - - /* We can release the lock before leaving */ - vlc_mutex_unlock (&p_mad_adec->p_fifo->data_lock); -} - /***************************************************************************** - * mad_adec_EndThread : libmad decoder thread destruction + * EndThread : libmad decoder thread destruction *****************************************************************************/ -static void mad_adec_EndThread (mad_adec_thread_t * p_mad_adec) +static void EndThread (mad_adec_thread_t * p_mad_adec) { intf_ErrMsg ("mad_adec debug: destroying mad decoder thread %p", p_mad_adec); diff --git a/plugins/mpeg_adec/mpeg_adec.c b/plugins/mpeg_adec/mpeg_adec.c index 003b2a4c4f..6826e6efdb 100644 --- a/plugins/mpeg_adec/mpeg_adec.c +++ b/plugins/mpeg_adec/mpeg_adec.c @@ -2,7 +2,7 @@ * mpeg_adec.c: MPEG audio decoder thread ***************************************************************************** * Copyright (C) 1999-2001 VideoLAN - * $Id: mpeg_adec.c,v 1.8 2001/12/27 01:49:34 massiot Exp $ + * $Id: mpeg_adec.c,v 1.9 2001/12/30 05:38:44 sam Exp $ * * Authors: Michel Kaempf * Michel Lespinasse @@ -56,11 +56,10 @@ /***************************************************************************** * Local Prototypes *****************************************************************************/ -static int adec_Probe( probedata_t * ); -static int adec_RunThread ( decoder_config_t * ); -static void adec_EndThread ( adec_thread_t * ); -static void adec_ErrorThread ( adec_thread_t * ); -static void adec_Decode( adec_thread_t * ); +static int decoder_Probe ( probedata_t * ); +static int decoder_Run ( decoder_config_t * ); +static void EndThread ( adec_thread_t * ); +static void DecodeThread ( adec_thread_t * ); /***************************************************************************** @@ -68,8 +67,8 @@ static void adec_Decode( adec_thread_t * ); *****************************************************************************/ void _M( adec_getfunctions )( function_list_t * p_function_list ) { - p_function_list->pf_probe = adec_Probe; - p_function_list->functions.dec.pf_run = adec_RunThread; + p_function_list->pf_probe = decoder_Probe; + p_function_list->functions.dec.pf_run = decoder_Run; } /***************************************************************************** @@ -93,9 +92,9 @@ MODULE_DEACTIVATE_START MODULE_DEACTIVATE_STOP /***************************************************************************** - * adec_Probe: probe the decoder and return score + * decoder_Probe: probe the decoder and return score *****************************************************************************/ -static int adec_Probe( probedata_t *p_data ) +static int decoder_Probe( probedata_t *p_data ) { if( p_data->i_type == MPEG1_AUDIO_ES || p_data->i_type == MPEG2_AUDIO_ES ) { @@ -114,9 +113,9 @@ static int adec_Probe( probedata_t *p_data ) } /***************************************************************************** - * adec_RunThread: initialize, go inside main loop, detroy + * decoder_Run: initialize, go inside main loop, detroy *****************************************************************************/ -static int adec_RunThread ( decoder_config_t * p_config ) +static int decoder_Run ( decoder_config_t * p_config ) { adec_thread_t * p_adec; @@ -127,6 +126,7 @@ static int adec_RunThread ( decoder_config_t * p_config ) { intf_ErrMsg ( "adec error: not enough memory for" " adec_CreateThread() to create the new thread" ); + DecoderError( p_config->p_decoder_fifo ); return 0; } @@ -166,17 +166,17 @@ static int adec_RunThread ( decoder_config_t * p_config ) /* Audio decoder thread's main loop */ while( (!p_adec->p_fifo->b_die) && (!p_adec->p_fifo->b_error) ) { - adec_Decode( p_adec ); + DecodeThread( p_adec ); } /* If b_error is set, the audio decoder thread enters the error loop */ if( p_adec->p_fifo->b_error ) { - adec_ErrorThread( p_adec ); + DecoderError( p_adec->p_fifo ); } /* End of the audio decoder thread */ - adec_EndThread( p_adec ); + EndThread( p_adec ); return( 0 ); } @@ -186,9 +186,9 @@ static int adec_RunThread ( decoder_config_t * p_config ) */ /***************************************************************************** - * adec_Decode: decodes a mpeg frame + * DecodeThread: decodes a mpeg frame *****************************************************************************/ -static void adec_Decode( adec_thread_t * p_adec ) +static void DecodeThread( adec_thread_t * p_adec ) { s16 * buffer; adec_sync_info_t sync_info; @@ -232,42 +232,12 @@ static void adec_Decode( adec_thread_t * p_adec ) } /***************************************************************************** - * adec_ErrorThread : audio decoder's RunThread() error loop - ***************************************************************************** - * This function is called when an error occured during thread main's loop. The - * thread can still receive feed, but must be ready to terminate as soon as - * possible. - *****************************************************************************/ -static void adec_ErrorThread ( adec_thread_t *p_adec ) -{ - /* We take the lock, because we are going to read/write the start/end - * indexes of the decoder fifo */ - vlc_mutex_lock ( &p_adec->p_fifo->data_lock ); - - /* Wait until a `die' order is sent */ - while ( !p_adec->p_fifo->b_die ) - { - /* Trash all received PES packets */ - p_adec->p_fifo->pf_delete_pes( - p_adec->p_fifo->p_packets_mgt, - p_adec->p_fifo->p_first ); - - /* Waiting for the input thread to put new PES packets in the fifo */ - vlc_cond_wait ( &p_adec->p_fifo->data_wait, &p_adec->p_fifo->data_lock ); - } - - /* We can release the lock before leaving */ - vlc_mutex_unlock ( &p_adec->p_fifo->data_lock ); -} - - -/***************************************************************************** - * adec_EndThread : audio decoder thread destruction + * EndThread : audio decoder thread destruction ***************************************************************************** * This function is called when the thread ends after a sucessful * initialization. *****************************************************************************/ -static void adec_EndThread ( adec_thread_t *p_adec ) +static void EndThread ( adec_thread_t *p_adec ) { intf_DbgMsg ( "adec debug: destroying audio decoder thread %p", p_adec ); diff --git a/plugins/mpeg_adec/mpeg_adec.h b/plugins/mpeg_adec/mpeg_adec.h index 0f21100171..3034950989 100644 --- a/plugins/mpeg_adec/mpeg_adec.h +++ b/plugins/mpeg_adec/mpeg_adec.h @@ -2,7 +2,7 @@ * mpeg_adec.h : audio decoder thread interface ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN - * $Id: mpeg_adec.h,v 1.1 2001/11/13 12:09:18 henri Exp $ + * $Id: mpeg_adec.h,v 1.2 2001/12/30 05:38:44 sam Exp $ * * Authors: Michel Kaempf * @@ -63,3 +63,4 @@ typedef struct adec_thread_s */ int adec_SyncFrame( adec_thread_t *, adec_sync_info_t * ); int adec_DecodeFrame( adec_thread_t * , s16 * ); + diff --git a/plugins/mpeg_vdec/video_parser.c b/plugins/mpeg_vdec/video_parser.c index f6946f0697..7c4025894d 100644 --- a/plugins/mpeg_vdec/video_parser.c +++ b/plugins/mpeg_vdec/video_parser.c @@ -2,7 +2,7 @@ * video_parser.c : video parser thread ***************************************************************************** * Copyright (C) 1999-2001 VideoLAN - * $Id: video_parser.c,v 1.8 2001/12/27 01:49:34 massiot Exp $ + * $Id: video_parser.c,v 1.9 2001/12/30 05:38:44 sam Exp $ * * Authors: Christophe Massiot * Samuel Hocevar @@ -64,20 +64,19 @@ /* * Local prototypes */ -static int mpeg_vdec_Probe ( probedata_t * ); -static int mpeg_vdec_Run ( decoder_config_t * ); -static int mpeg_vdec_Init ( vpar_thread_t * ); -static void mpeg_vdec_ErrorThread ( vpar_thread_t * ); -static void mpeg_vdec_EndThread ( vpar_thread_t * ); -static void BitstreamCallback ( bit_stream_t *, boolean_t ); +static int decoder_Probe ( probedata_t * ); +static int decoder_Run ( decoder_config_t * ); +static int InitThread ( vpar_thread_t * ); +static void EndThread ( vpar_thread_t * ); +static void BitstreamCallback ( bit_stream_t *, boolean_t ); /***************************************************************************** * Capabilities *****************************************************************************/ void _M( vdec_getfunctions )( function_list_t * p_function_list ) { - p_function_list->pf_probe = mpeg_vdec_Probe; - p_function_list->functions.dec.pf_run = mpeg_vdec_Run; + p_function_list->pf_probe = decoder_Probe; + p_function_list->functions.dec.pf_run = decoder_Run; } /***************************************************************************** @@ -102,12 +101,12 @@ MODULE_DEACTIVATE_STOP /***************************************************************************** - * mpeg_vdec_Probe: probe the decoder and return score + * decoder_Probe: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ -static int mpeg_vdec_Probe( probedata_t *p_data ) +static int decoder_Probe( probedata_t *p_data ) { if( p_data->i_type == MPEG1_VIDEO_ES || p_data->i_type == MPEG2_VIDEO_ES ) return( 50 ); @@ -116,9 +115,9 @@ static int mpeg_vdec_Probe( probedata_t *p_data ) } /***************************************************************************** - * mpeg_vdec_Run: this function is called just after the thread is created + * decoder_Run: this function is called just after the thread is created *****************************************************************************/ -static int mpeg_vdec_Run ( decoder_config_t * p_config ) +static int decoder_Run ( decoder_config_t * p_config ) { vpar_thread_t * p_vpar; boolean_t b_error; @@ -130,6 +129,7 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config ) { intf_ErrMsg( "vpar error: not enough memory " "for vpar_CreateThread() to create the new thread"); + DecoderError( p_config->p_decoder_fifo ); return( -1 ); } @@ -143,7 +143,7 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config ) /* * Initialize thread */ - p_vpar->p_fifo->b_error = mpeg_vdec_Init( p_vpar ); + p_vpar->p_fifo->b_error = InitThread( p_vpar ); /* * Main loop - it is not executed if an error occured during @@ -172,11 +172,11 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config ) */ if( ( b_error = p_vpar->p_fifo->b_error ) ) { - mpeg_vdec_ErrorThread( p_vpar ); + DecoderError( p_vpar->p_fifo ); } /* End of thread */ - mpeg_vdec_EndThread( p_vpar ); + EndThread( p_vpar ); if( b_error ) { @@ -188,13 +188,13 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config ) } /***************************************************************************** - * mpeg_vdec_Init: initialize vpar output thread + * InitThread: initialize vpar output thread ***************************************************************************** - * This function is called from mpeg_vdec_Run and performs the second step + * This function is called from decoder_Run and performs the second step * of the initialization. It returns 0 on success. Note that the thread's * flag are not modified inside this function. *****************************************************************************/ -static int mpeg_vdec_Init( vpar_thread_t *p_vpar ) +static int InitThread( vpar_thread_t *p_vpar ) { /* * Choose the best motion compensation module @@ -277,46 +277,17 @@ static int mpeg_vdec_Init( vpar_thread_t *p_vpar ) vpar_InitPool( p_vpar ); /* Mark thread as running and return */ - intf_DbgMsg("vpar debug: mpeg_vdec_Init(%p) succeeded", p_vpar); + intf_DbgMsg("vpar debug: InitThread(%p) succeeded", p_vpar); return( 0 ); } /***************************************************************************** - * mpeg_vdec_ErrorThread: RunThread() error loop - ***************************************************************************** - * This function is called when an error occured during thread main's loop. The - * thread can still receive feed, but must be ready to terminate as soon as - * possible. - *****************************************************************************/ -static void mpeg_vdec_ErrorThread( vpar_thread_t *p_vpar ) -{ - /* We take the lock, because we are going to read/write the start/end - * indexes of the decoder fifo */ - vlc_mutex_lock( &p_vpar->p_fifo->data_lock ); - - /* Wait until a `die' order is sent */ - while( !p_vpar->p_fifo->b_die ) - { - /* Trash all received PES packets */ - p_vpar->p_fifo->pf_delete_pes( - p_vpar->p_fifo->p_packets_mgt, - p_vpar->p_fifo->p_first ); - - /* Waiting for the input thread to put new PES packets in the fifo */ - vlc_cond_wait( &p_vpar->p_fifo->data_wait, &p_vpar->p_fifo->data_lock ); - } - - /* We can release the lock before leaving */ - vlc_mutex_unlock( &p_vpar->p_fifo->data_lock ); -} - -/***************************************************************************** - * mpeg_vdec_EndThread: thread destruction + * EndThread: thread destruction ***************************************************************************** * This function is called when the thread ends after a sucessful * initialization. *****************************************************************************/ -static void mpeg_vdec_EndThread( vpar_thread_t *p_vpar ) +static void EndThread( vpar_thread_t *p_vpar ) { intf_DbgMsg("vpar debug: destroying video parser thread %p", p_vpar); diff --git a/plugins/spudec/spu_decoder.c b/plugins/spudec/spu_decoder.c index f5af620803..4869e21ea1 100644 --- a/plugins/spudec/spu_decoder.c +++ b/plugins/spudec/spu_decoder.c @@ -2,7 +2,7 @@ * spu_decoder.c : spu decoder thread ***************************************************************************** * Copyright (C) 2000-2001 VideoLAN - * $Id: spu_decoder.c,v 1.4 2001/12/27 01:49:34 massiot Exp $ + * $Id: spu_decoder.c,v 1.5 2001/12/30 05:38:44 sam Exp $ * * Authors: Samuel Hocevar * @@ -59,11 +59,10 @@ /***************************************************************************** * Local prototypes *****************************************************************************/ -static int spudec_Probe ( probedata_t * ); -static int spudec_Run ( decoder_config_t * ); -static int spudec_Init ( spudec_thread_t * ); -static void spudec_ErrorThread ( spudec_thread_t * ); -static void spudec_EndThread ( spudec_thread_t * ); +static int decoder_Probe ( probedata_t * ); +static int decoder_Run ( decoder_config_t * ); +static int InitThread ( spudec_thread_t * ); +static void EndThread ( spudec_thread_t * ); static int SyncPacket ( spudec_thread_t * ); static void ParsePacket ( spudec_thread_t * ); @@ -75,8 +74,8 @@ static int ParseRLE ( spudec_thread_t *, subpicture_t *, u8 * ); *****************************************************************************/ void _M( spudec_getfunctions )( function_list_t * p_function_list ) { - p_function_list->pf_probe = spudec_Probe; - p_function_list->functions.dec.pf_run = spudec_Run; + p_function_list->pf_probe = decoder_Probe; + p_function_list->functions.dec.pf_run = decoder_Run; } /***************************************************************************** @@ -100,12 +99,12 @@ MODULE_DEACTIVATE_START MODULE_DEACTIVATE_STOP /***************************************************************************** - * spudec_Probe: probe the decoder and return score + * decoder_Probe: probe the decoder and return score ***************************************************************************** * Tries to launch a decoder and return score so that the interface is able * to chose. *****************************************************************************/ -static int spudec_Probe( probedata_t *p_data ) +static int decoder_Probe( probedata_t *p_data ) { if( p_data->i_type == DVD_SPU_ES ) return( 50 ); @@ -114,9 +113,9 @@ static int spudec_Probe( probedata_t *p_data ) } /***************************************************************************** - * spudec_Run: this function is called just after the thread is created + * decoder_Run: this function is called just after the thread is created *****************************************************************************/ -static int spudec_Run( decoder_config_t * p_config ) +static int decoder_Run( decoder_config_t * p_config ) { spudec_thread_t * p_spudec; @@ -129,6 +128,7 @@ static int spudec_Run( decoder_config_t * p_config ) { intf_ErrMsg( "spudec error: not enough memory " "for spudec_CreateThread() to create the new thread" ); + DecoderError( p_config->p_decoder_fifo ); return( -1 ); } @@ -142,7 +142,7 @@ static int spudec_Run( decoder_config_t * p_config ) /* * Initialize thread and free configuration */ - p_spudec->p_fifo->b_error = spudec_Init( p_spudec ); + p_spudec->p_fifo->b_error = InitThread( p_spudec ); /* * Main loop - it is not executed if an error occured during @@ -161,11 +161,11 @@ static int spudec_Run( decoder_config_t * p_config ) */ if( p_spudec->p_fifo->b_error ) { - spudec_ErrorThread( p_spudec ); + DecoderError( p_spudec->p_fifo ); } /* End of thread */ - spudec_EndThread( p_spudec ); + EndThread( p_spudec ); if( p_spudec->p_fifo->b_error ) { @@ -179,13 +179,13 @@ static int spudec_Run( decoder_config_t * p_config ) /* following functions are local */ /***************************************************************************** - * spudec_Init: initialize spu decoder thread + * InitThread: initialize spu decoder thread ***************************************************************************** * This function is called from RunThread and performs the second step of the * initialization. It returns 0 on success. Note that the thread's flag are not * modified inside this function. *****************************************************************************/ -static int spudec_Init( spudec_thread_t *p_spudec ) +static int InitThread( spudec_thread_t *p_spudec ) { int i_retry = 0; @@ -220,42 +220,12 @@ static int spudec_Init( spudec_thread_t *p_spudec ) } /***************************************************************************** - * spudec_ErrorThread: spudec_Run() error loop - ***************************************************************************** - * This function is called when an error occured during thread main's loop. The - * thread can still receive feed, but must be ready to terminate as soon as - * possible. - *****************************************************************************/ -static void spudec_ErrorThread( spudec_thread_t *p_spudec ) -{ - /* We take the lock, because we are going to read/write the start/end - * indexes of the decoder fifo */ - vlc_mutex_lock( &p_spudec->p_fifo->data_lock ); - - /* Wait until a `die' order is sent */ - while( !p_spudec->p_fifo->b_die ) - { - /* Trash all received PES packets */ - p_spudec->p_fifo->pf_delete_pes( - p_spudec->p_fifo->p_packets_mgt, - p_spudec->p_fifo->p_first ); - - /* Waiting for the input thread to put new PES packets in the fifo */ - vlc_cond_wait( &p_spudec->p_fifo->data_wait, - &p_spudec->p_fifo->data_lock ); - } - - /* We can release the lock before leaving */ - vlc_mutex_unlock( &p_spudec->p_fifo->data_lock ); -} - -/***************************************************************************** - * spudec_EndThread: thread destruction + * EndThread: thread destruction ***************************************************************************** * This function is called when the thread ends after a sucessful * initialization. *****************************************************************************/ -static void spudec_EndThread( spudec_thread_t *p_spudec ) +static void EndThread( spudec_thread_t *p_spudec ) { free( p_spudec ); } diff --git a/src/input/input_ext-dec.c b/src/input/input_ext-dec.c index 57c684f74d..1ba58409ca 100644 --- a/src/input/input_ext-dec.c +++ b/src/input/input_ext-dec.c @@ -2,7 +2,7 @@ * input_ext-dec.c: services to the decoders ***************************************************************************** * Copyright (C) 1998-2001 VideoLAN - * $Id: input_ext-dec.c,v 1.23 2001/12/27 01:49:34 massiot Exp $ + * $Id: input_ext-dec.c,v 1.24 2001/12/30 05:38:44 sam Exp $ * * Authors: Christophe Massiot * @@ -86,6 +86,29 @@ void InitBitstream( bit_stream_t * p_bit_stream, decoder_fifo_t * p_fifo, } } +/***************************************************************************** + * EmptyFifo : an error occured, use this function to empty the fifo + *****************************************************************************/ +void EmptyFifo( decoder_fifo_t * p_fifo ) +{ + /* We take the lock, because we are going to read/write the start/end + * indexes of the decoder fifo */ + vlc_mutex_lock (&p_fifo->data_lock); + + /* Wait until a `die' order is sent */ + while (!p_fifo->b_die) + { + /* Trash all received PES packets */ + p_fifo->pf_delete_pes( p_fifo->p_packets_mgt, p_fifo->p_first ); + + /* Waiting for the input thread to put new PES packets in the fifo */ + vlc_cond_wait (&p_fifo->data_wait, &p_fifo->data_lock); + } + + /* We can release the lock before leaving */ + vlc_mutex_unlock (&p_fifo->data_lock); +} + /***************************************************************************** * NextDataPacket: go to the next data packet *****************************************************************************/ -- 2.39.2