Commit 65468e37 authored by Michel Kaempf's avatar Michel Kaempf

* include/decoder_fifo.h :

- Rajout du support permettant de d�tecter la fin du thread input
correspondant au flux de bits pass� en argument � la fonction GetByte ;

* input/input.c :
- Changements cosm�tiques ;

* input/input_psi.c :
- Correction d'un bug de la fonction DestroyPgrmDescr qui faisait
segfaulter le vlc � sa terminaison ;

* audio_decoder/audio_decoder.c :
* generic_decoder/generic_decoder.c :
* video_decoder/video_decoder.c :
- Les fonctions xdec_DestroyThread envoient d�sormais un signal permettant
aux decoder threads de quitter la fonction GetByte meme s'ils sont en
attente dans la fonction pthread_cond_wait ;

--
MaXX
parent b0539b37
...@@ -96,6 +96,12 @@ typedef struct bit_stream_s ...@@ -96,6 +96,12 @@ typedef struct bit_stream_s
*****************************************************************************/ *****************************************************************************/
static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream ) static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream )
{ {
/* Is the input thread dying ? */
if ( p_bit_stream->p_input->b_die )
{
return( 0 );
}
/* Are there some bytes left in the current TS packet ? */ /* Are there some bytes left in the current TS packet ? */
if ( p_bit_stream->i_byte < p_bit_stream->p_ts->i_payload_end ) if ( p_bit_stream->i_byte < p_bit_stream->p_ts->i_payload_end )
{ {
...@@ -123,11 +129,15 @@ static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream ) ...@@ -123,11 +129,15 @@ static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream )
input_NetlistFreePES( p_bit_stream->p_input, DECODER_FIFO_START(*p_bit_stream->p_decoder_fifo) ); input_NetlistFreePES( p_bit_stream->p_input, DECODER_FIFO_START(*p_bit_stream->p_decoder_fifo) );
DECODER_FIFO_INCSTART( *p_bit_stream->p_decoder_fifo ); DECODER_FIFO_INCSTART( *p_bit_stream->p_decoder_fifo );
/* !! b_die !! */
while ( DECODER_FIFO_ISEMPTY(*p_bit_stream->p_decoder_fifo) ) while ( DECODER_FIFO_ISEMPTY(*p_bit_stream->p_decoder_fifo) )
{ {
pthread_cond_wait( &p_bit_stream->p_decoder_fifo->data_wait, pthread_cond_wait( &p_bit_stream->p_decoder_fifo->data_wait,
&p_bit_stream->p_decoder_fifo->data_lock ); &p_bit_stream->p_decoder_fifo->data_lock );
if ( p_bit_stream->p_input->b_die )
{
pthread_mutex_unlock( &(p_bit_stream->p_decoder_fifo->data_lock) );
return( 0 );
}
} }
/* The next byte could be found in the next PES packet */ /* The next byte could be found in the next PES packet */
......
...@@ -136,9 +136,14 @@ void adec_DestroyThread( adec_thread_t * p_adec ) ...@@ -136,9 +136,14 @@ void adec_DestroyThread( adec_thread_t * p_adec )
/* Ask thread to kill itself */ /* Ask thread to kill itself */
p_adec->b_die = 1; p_adec->b_die = 1;
/* Make sure the decoder thread leaves the GetByte() function */
pthread_mutex_lock( &(p_adec->fifo.data_lock) );
pthread_cond_signal( &(p_adec->fifo.data_wait) );
pthread_mutex_unlock( &(p_adec->fifo.data_lock) );
/* Waiting for the decoder thread to exit */
/* Remove this as soon as the "status" flag is implemented */ /* Remove this as soon as the "status" flag is implemented */
pthread_join( p_adec->thread_id, NULL ); /* wait until it's done */ pthread_join( p_adec->thread_id, NULL );
} }
/* Following functions are local */ /* Following functions are local */
...@@ -157,14 +162,8 @@ static int FindHeader( adec_thread_t * p_adec ) ...@@ -157,14 +162,8 @@ static int FindHeader( adec_thread_t * p_adec )
NeedBits( &p_adec->bit_stream, 32 ); NeedBits( &p_adec->bit_stream, 32 );
if ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_SYNCWORD_MASK) == ADEC_HEADER_SYNCWORD_MASK ) if ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_SYNCWORD_MASK) == ADEC_HEADER_SYNCWORD_MASK )
{ {
#ifdef DEBUG
// fprintf(stderr, "H");
#endif
return( 0 ); return( 0 );
} }
#ifdef DEBUG
// fprintf(stderr, "!");
#endif
DumpBits( &p_adec->bit_stream, 8 ); DumpBits( &p_adec->bit_stream, 8 );
} }
...@@ -971,9 +970,6 @@ static void ErrorThread( adec_thread_t *p_adec ) ...@@ -971,9 +970,6 @@ static void ErrorThread( adec_thread_t *p_adec )
{ {
input_NetlistFreePES( p_adec->bit_stream.p_input, DECODER_FIFO_START(p_adec->fifo) ); input_NetlistFreePES( p_adec->bit_stream.p_input, DECODER_FIFO_START(p_adec->fifo) );
DECODER_FIFO_INCSTART( p_adec->fifo ); DECODER_FIFO_INCSTART( p_adec->fifo );
#ifdef DEBUG
// fprintf(stderr, "*");
#endif
} }
/* Waiting for the input thread to put new PES packets in the fifo */ /* Waiting for the input thread to put new PES packets in the fifo */
......
...@@ -144,6 +144,10 @@ void gdec_DestroyThread( gdec_thread_t *p_gdec, int *pi_status ) ...@@ -144,6 +144,10 @@ void gdec_DestroyThread( gdec_thread_t *p_gdec, int *pi_status )
/* Request thread destruction */ /* Request thread destruction */
p_gdec->b_die = 1; p_gdec->b_die = 1;
/* Make sure the decoder thread leaves the GetByte() function */
pthread_mutex_lock( &(p_gdec->fifo.data_lock) );
pthread_cond_signal( &(p_gdec->fifo.data_wait) );
pthread_mutex_unlock( &(p_gdec->fifo.data_lock) );
/* If status is NULL, wait until thread has been destroyed */ /* If status is NULL, wait until thread has been destroyed */
if( pi_status ) if( pi_status )
...@@ -437,4 +441,3 @@ static void PrintPES( pes_packet_t *p_pes, int i_stream_id ) ...@@ -437,4 +441,3 @@ static void PrintPES( pes_packet_t *p_pes, int i_stream_id )
#endif #endif
intf_Msg("gdec: PES %s\n", psz_pes ); intf_Msg("gdec: PES %s\n", psz_pes );
} }
...@@ -339,10 +339,12 @@ static void EndThread( input_thread_t *p_input ) ...@@ -339,10 +339,12 @@ static void EndThread( input_thread_t *p_input )
case MPEG2_VIDEO_ES: case MPEG2_VIDEO_ES:
vdec_DestroyThread( (vdec_thread_t*)(p_input->pp_selected_es[i_es_loop]->p_dec) /*, NULL */ ); vdec_DestroyThread( (vdec_thread_t*)(p_input->pp_selected_es[i_es_loop]->p_dec) /*, NULL */ );
break; break;
case MPEG1_AUDIO_ES: case MPEG1_AUDIO_ES:
case MPEG2_AUDIO_ES: case MPEG2_AUDIO_ES:
adec_DestroyThread( (adec_thread_t*)(p_input->pp_selected_es[i_es_loop]->p_dec) ); adec_DestroyThread( (adec_thread_t*)(p_input->pp_selected_es[i_es_loop]->p_dec) );
break; break;
default: default:
break; break;
} }
......
...@@ -77,7 +77,6 @@ static boolean_t Is_known( byte_t* a_known_section, u8 i_section ); ...@@ -77,7 +77,6 @@ static boolean_t Is_known( byte_t* a_known_section, u8 i_section );
static void Set_known( byte_t* a_known_section, u8 i_section ); static void Set_known( byte_t* a_known_section, u8 i_section );
static void Unset_known( byte_t* a_known_section, u8 i_section ); static void Unset_known( byte_t* a_known_section, u8 i_section );
/****************************************************************************** /******************************************************************************
* input_PsiInit: Initialize PSI decoder * input_PsiInit: Initialize PSI decoder
****************************************************************************** ******************************************************************************
...@@ -110,7 +109,6 @@ int input_PsiInit( input_thread_t *p_input ) ...@@ -110,7 +109,6 @@ int input_PsiInit( input_thread_t *p_input )
return( 0 ); return( 0 );
} }
/****************************************************************************** /******************************************************************************
* input_PsiClean: Clean PSI structures before dying * input_PsiClean: Clean PSI structures before dying
******************************************************************************/ ******************************************************************************/
...@@ -130,8 +128,6 @@ int input_PsiClean( input_thread_t *p_input ) ...@@ -130,8 +128,6 @@ int input_PsiClean( input_thread_t *p_input )
return( 0 ); return( 0 );
} }
/****************************************************************************** /******************************************************************************
* input_PsiRead: Read the table of programs * input_PsiRead: Read the table of programs
****************************************************************************** ******************************************************************************
...@@ -177,7 +173,6 @@ void input_PsiRead( input_thread_t *p_input /* ??? */ ) ...@@ -177,7 +173,6 @@ void input_PsiRead( input_thread_t *p_input /* ??? */ )
//pthread_mutex_unlock() //pthread_mutex_unlock()
} }
/****************************************************************************** /******************************************************************************
* input_PsiDecode: Decode a PSI section * input_PsiDecode: Decode a PSI section
****************************************************************************** ******************************************************************************
...@@ -236,7 +231,6 @@ void input_PsiDecode( input_thread_t *p_input, psi_section_t* p_psi_section ) ...@@ -236,7 +231,6 @@ void input_PsiDecode( input_thread_t *p_input, psi_section_t* p_psi_section )
} }
} }
/****************************************************************************** /******************************************************************************
* DecodeAssocSection: Decode a PAS * DecodeAssocSection: Decode a PAS
****************************************************************************** ******************************************************************************
...@@ -406,7 +400,6 @@ static void DecodePgrmAssocSection(u8* p_pas, input_thread_t *p_input ) ...@@ -406,7 +400,6 @@ static void DecodePgrmAssocSection(u8* p_pas, input_thread_t *p_input )
#undef p_descr #undef p_descr
} }
/****************************************************************************** /******************************************************************************
* DecodePgrmMapSection: Decode a PMS * DecodePgrmMapSection: Decode a PMS
****************************************************************************** ******************************************************************************
...@@ -620,8 +613,6 @@ static void DecodePgrmMapSection( u8* p_pms, input_thread_t* p_input ) ...@@ -620,8 +613,6 @@ static void DecodePgrmMapSection( u8* p_pms, input_thread_t* p_input )
#undef p_descr #undef p_descr
} }
/****************************************************************************** /******************************************************************************
* DecodeSrvDescrSection * DecodeSrvDescrSection
****************************************************************************** ******************************************************************************
...@@ -705,13 +696,7 @@ void DecodeSrvDescrSection( byte_t* p_sdt, input_thread_t *p_input ) ...@@ -705,13 +696,7 @@ void DecodeSrvDescrSection( byte_t* p_sdt, input_thread_t *p_input )
} }
} }
#undef p_stream #undef p_stream
}; }
/****************************************************************************** /******************************************************************************
* DecodePgrmDescr * DecodePgrmDescr
...@@ -768,9 +753,6 @@ static void DecodePgrmDescriptor( byte_t* p_descriptor, pgrm_descriptor_t* p_pgr ...@@ -768,9 +753,6 @@ static void DecodePgrmDescriptor( byte_t* p_descriptor, pgrm_descriptor_t* p_pgr
} }
} }
/****************************************************************************** /******************************************************************************
* DecodeESDescriptor * DecodeESDescriptor
****************************************************************************** ******************************************************************************
...@@ -817,8 +799,6 @@ static void DecodeESDescriptor( byte_t* p_descriptor, es_descriptor_t* p_es ) ...@@ -817,8 +799,6 @@ static void DecodeESDescriptor( byte_t* p_descriptor, es_descriptor_t* p_es )
} }
} }
/****************************************************************************** /******************************************************************************
* input_AddPsiPID: Start to receive the PSI info contained in a PID * input_AddPsiPID: Start to receive the PSI info contained in a PID
****************************************************************************** ******************************************************************************
...@@ -880,7 +860,6 @@ static int input_AddPsiPID( input_thread_t *p_input, int i_pid ) ...@@ -880,7 +860,6 @@ static int input_AddPsiPID( input_thread_t *p_input, int i_pid )
return( i_rc ); return( i_rc );
} }
/****************************************************************************** /******************************************************************************
* input_DelPsiPID: Stop to receive the PSI info contained in a PID * input_DelPsiPID: Stop to receive the PSI info contained in a PID
****************************************************************************** ******************************************************************************
...@@ -935,8 +914,6 @@ static int input_DelPsiPID( input_thread_t *p_input, int i_pid ) ...@@ -935,8 +914,6 @@ static int input_DelPsiPID( input_thread_t *p_input, int i_pid )
return( 0 ); return( 0 );
} }
/****************************************************************************** /******************************************************************************
* Precalculate the 32-bit CRC table * Precalculate the 32-bit CRC table
****************************************************************************** ******************************************************************************
...@@ -955,7 +932,6 @@ void BuildCrc32Table( ) ...@@ -955,7 +932,6 @@ void BuildCrc32Table( )
} }
} }
/****************************************************************************** /******************************************************************************
* Test the validity of a checksum * Test the validity of a checksum
****************************************************************************** ******************************************************************************
...@@ -976,8 +952,6 @@ int CheckCRC32(byte_t* p_data, int i_data_size) ...@@ -976,8 +952,6 @@ int CheckCRC32(byte_t* p_data, int i_data_size)
return i_crc; return i_crc;
} }
/****************************************************************************** /******************************************************************************
* Is_known: check if a given section has already been received * Is_known: check if a given section has already been received
****************************************************************************** ******************************************************************************
...@@ -1003,7 +977,6 @@ boolean_t Is_known( byte_t* a_known_section, u8 i_section ) ...@@ -1003,7 +977,6 @@ boolean_t Is_known( byte_t* a_known_section, u8 i_section )
return b_is_known; return b_is_known;
} }
/****************************************************************************** /******************************************************************************
* Set_known: mark a given section has having been received * Set_known: mark a given section has having been received
****************************************************************************** ******************************************************************************
...@@ -1024,7 +997,6 @@ static void Set_known( byte_t* a_known_section, u8 i_section ) ...@@ -1024,7 +997,6 @@ static void Set_known( byte_t* a_known_section, u8 i_section )
a_known_section[i_byte_in_table] |= mask; a_known_section[i_byte_in_table] |= mask;
} }
/****************************************************************************** /******************************************************************************
* Unset_known: remove the 'received' mark for a given section * Unset_known: remove the 'received' mark for a given section
****************************************************************************** ******************************************************************************
...@@ -1046,7 +1018,6 @@ static void Unset_known( byte_t* a_known_section, u8 i_section ) ...@@ -1046,7 +1018,6 @@ static void Unset_known( byte_t* a_known_section, u8 i_section )
a_known_section[i_byte_in_table] &= mask; a_known_section[i_byte_in_table] &= mask;
} }
/****************************************************************************** /******************************************************************************
* AddStreamDescr: add and init the stream descriptor of the given input * AddStreamDescr: add and init the stream descriptor of the given input
****************************************************************************** ******************************************************************************
...@@ -1087,7 +1058,6 @@ static stream_descriptor_t* AddStreamDescr(input_thread_t* p_input, u16 i_stream ...@@ -1087,7 +1058,6 @@ static stream_descriptor_t* AddStreamDescr(input_thread_t* p_input, u16 i_stream
return p_input->p_stream; return p_input->p_stream;
} }
/****************************************************************************** /******************************************************************************
* DestroyStreamDescr: destroy the stream desciptor of the given input * DestroyStreamDescr: destroy the stream desciptor of the given input
****************************************************************************** ******************************************************************************
...@@ -1102,8 +1072,7 @@ static void DestroyStreamDescr(input_thread_t* p_input, u16 i_stream_id) ...@@ -1102,8 +1072,7 @@ static void DestroyStreamDescr(input_thread_t* p_input, u16 i_stream_id)
/* Free the structures that describes the programs of that stream */ /* Free the structures that describes the programs of that stream */
for( i_index = 0; i_index < p_input->p_stream->i_pgrm_number; i_index++ ) for( i_index = 0; i_index < p_input->p_stream->i_pgrm_number; i_index++ )
{ {
DestroyPgrmDescr( p_input, p_input->p_stream, DestroyPgrmDescr( p_input, p_input->p_stream, p_input->p_stream->ap_programs[i_index]->i_number );
p_input->p_stream->ap_programs[i_index]->i_number );
} }
/* Free the table of pgrm descriptors */ /* Free the table of pgrm descriptors */
...@@ -1116,7 +1085,6 @@ static void DestroyStreamDescr(input_thread_t* p_input, u16 i_stream_id) ...@@ -1116,7 +1085,6 @@ static void DestroyStreamDescr(input_thread_t* p_input, u16 i_stream_id)
p_input->p_stream = NULL; p_input->p_stream = NULL;
} }
/****************************************************************************** /******************************************************************************
* AddPgrmDescr: add and init a program descriptor * AddPgrmDescr: add and init a program descriptor
****************************************************************************** ******************************************************************************
...@@ -1149,33 +1117,34 @@ static pgrm_descriptor_t* AddPgrmDescr(stream_descriptor_t* p_stream, u16 i_pgrm ...@@ -1149,33 +1117,34 @@ static pgrm_descriptor_t* AddPgrmDescr(stream_descriptor_t* p_stream, u16 i_pgrm
return p_stream->ap_programs[p_stream->i_pgrm_number-1]; return p_stream->ap_programs[p_stream->i_pgrm_number-1];
} }
/****************************************************************************** /******************************************************************************
* AddPgrmDescr: destroy a program descriptor * AddPgrmDescr: destroy a program descriptor
****************************************************************************** ******************************************************************************
* All ES descriptions referenced in the descriptor will be deleted. * All ES descriptions referenced in the descriptor will be deleted.
******************************************************************************/ ******************************************************************************/
static void DestroyPgrmDescr(input_thread_t* p_input, stream_descriptor_t* p_stream, u16 i_pgrm_id) static void DestroyPgrmDescr( input_thread_t * p_input, stream_descriptor_t * p_stream, u16 i_pgrm_id )
{ {
int i_index; int i_index, i_pgrm_index;
pgrm_descriptor_t* p_pgrm; pgrm_descriptor_t * p_pgrm;
ASSERT(p_stream); ASSERT( p_stream );
/* Find where is described this program */ /* Find where this program is described */
for(i_index = 0; i_index < p_stream->i_pgrm_number; i_index++) for( i_index = 0; i_index < p_stream->i_pgrm_number; i_index++ )
{ {
if( p_stream->ap_programs[i_index]->i_number == i_pgrm_id ) if( p_stream->ap_programs[i_index]->i_number == i_pgrm_id )
{ {
/* Here we are */ i_pgrm_index = i_index;
p_pgrm = p_stream->ap_programs[i_index]; p_pgrm = p_stream->ap_programs[ i_pgrm_index ];
break; break;
} }
} }
/* Free the structures that describes the es that belongs to that program */ /* 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++ ) for( i_index = 0; i_index < p_pgrm->i_es_number; i_index++ )
DestroyESDescr(p_input, p_pgrm, p_pgrm->ap_es[i_index]->i_id); {
DestroyESDescr( p_input, p_pgrm, p_pgrm->ap_es[i_index]->i_id );
}
/* Free the table of es descriptors */ /* Free the table of es descriptors */
free( p_pgrm->ap_es ); free( p_pgrm->ap_es );
...@@ -1183,13 +1152,12 @@ static void DestroyPgrmDescr(input_thread_t* p_input, stream_descriptor_t* p_str ...@@ -1183,13 +1152,12 @@ static void DestroyPgrmDescr(input_thread_t* p_input, stream_descriptor_t* p_str
/* Free the description of this stream */ /* Free the description of this stream */
free( p_pgrm ); free( p_pgrm );
/* Remove this program from he list of programs of the stream */ /* Remove this program from the stream's list of programs */
p_stream->i_pgrm_number--; p_stream->i_pgrm_number--;
p_stream->ap_programs[i_index] = p_stream->ap_programs[p_stream->i_pgrm_number]; p_stream->ap_programs[ i_pgrm_index ] = p_stream->ap_programs[ p_stream->i_pgrm_number ];
p_stream->ap_programs = realloc(p_stream->ap_programs, p_stream->i_pgrm_number); p_stream->ap_programs = realloc( p_stream->ap_programs, p_stream->i_pgrm_number * sizeof(pgrm_descriptor_t *) );
} }
/****************************************************************************** /******************************************************************************
* AddESDescr: * AddESDescr:
****************************************************************************** ******************************************************************************
...@@ -1247,8 +1215,6 @@ static es_descriptor_t* AddESDescr(input_thread_t* p_input, ...@@ -1247,8 +1215,6 @@ static es_descriptor_t* AddESDescr(input_thread_t* p_input,
return p_es; return p_es;
} }
/****************************************************************************** /******************************************************************************
* DestroyESDescr: * DestroyESDescr:
****************************************************************************** ******************************************************************************
......
...@@ -108,9 +108,14 @@ void vdec_DestroyThread( vdec_thread_t *p_vdec /*, int *pi_status */ ) ...@@ -108,9 +108,14 @@ void vdec_DestroyThread( vdec_thread_t *p_vdec /*, int *pi_status */ )
/* Ask thread to kill itself */ /* Ask thread to kill itself */
p_vdec->b_die = 1; p_vdec->b_die = 1;
/* Make sure the decoder thread leaves the GetByte() function */
pthread_mutex_lock( &(p_vdec->fifo.data_lock) );
pthread_cond_signal( &(p_vdec->fifo.data_wait) );
pthread_mutex_unlock( &(p_vdec->fifo.data_lock) );
/* Waiting for the decoder thread to exit */
/* Remove this as soon as the "status" flag is implemented */ /* Remove this as soon as the "status" flag is implemented */
pthread_join( p_vdec->thread_id, NULL ); /* wait until it's done */ pthread_join( p_vdec->thread_id, NULL );
} }
/* following functions are local */ /* following functions are local */
...@@ -281,5 +286,3 @@ static void EndThread( vdec_thread_t *p_vdec ) ...@@ -281,5 +286,3 @@ static void EndThread( vdec_thread_t *p_vdec )
intf_DbgMsg("vdec debug: EndThread(%p)\n", p_vdec); intf_DbgMsg("vdec debug: EndThread(%p)\n", p_vdec);
} }
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