]> git.sesse.net Git - vlc/commitdiff
* include/decoder_fifo.h :
authorMichel Kaempf <maxx@videolan.org>
Sat, 2 Oct 1999 21:32:21 +0000 (21:32 +0000)
committerMichel Kaempf <maxx@videolan.org>
Sat, 2 Oct 1999 21:32:21 +0000 (21:32 +0000)
- 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

include/decoder_fifo.h
src/audio_decoder/audio_decoder.c
src/generic_decoder/generic_decoder.c
src/input/input.c
src/input/input_psi.c
src/video_decoder/video_decoder.c

index 117bde1afc3653a0f291861cb854ab289ad72e81..0c0c4c6bd458ae0fc513fc3d757dfe30e9a449bd 100644 (file)
@@ -96,6 +96,12 @@ typedef struct bit_stream_s
  *****************************************************************************/
 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 ? */
     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 )
                 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 );
 
-                /* !! b_die !! */
                 while ( DECODER_FIFO_ISEMPTY(*p_bit_stream->p_decoder_fifo) )
                 {
                     pthread_cond_wait( &p_bit_stream->p_decoder_fifo->data_wait,
                                        &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 */
index 103010d7a3cac3cd6c3eede62be740a41bb19917..f7b0e6b16284cb86427dd9292b9260a238ac7225 100644 (file)
@@ -136,9 +136,14 @@ void adec_DestroyThread( adec_thread_t * p_adec )
 
     /* Ask thread to kill itself */
     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 */
-    pthread_join( p_adec->thread_id, NULL );         /* wait until it's done */
+    pthread_join( p_adec->thread_id, NULL );
 }
 
 /* Following functions are local */
@@ -157,14 +162,8 @@ static int FindHeader( adec_thread_t * p_adec )
         NeedBits( &p_adec->bit_stream, 32 );
         if ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_SYNCWORD_MASK) == ADEC_HEADER_SYNCWORD_MASK )
         {
-#ifdef DEBUG
-//            fprintf(stderr, "H");
-#endif
             return( 0 );
         }
-#ifdef DEBUG
-//        fprintf(stderr, "!");
-#endif
         DumpBits( &p_adec->bit_stream, 8 );
     }
 
@@ -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) );
            DECODER_FIFO_INCSTART( p_adec->fifo );
-#ifdef DEBUG
-//            fprintf(stderr, "*");
-#endif
         }
 
         /* Waiting for the input thread to put new PES packets in the fifo */
index a4e99f843a256db3886ef82738b1ba3c616ba452..89a74ac99fe7c9a3dc2d8633d718083989666b14 100644 (file)
@@ -144,6 +144,10 @@ void gdec_DestroyThread( gdec_thread_t *p_gdec, int *pi_status )
      
     /* Request thread destruction */
     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( pi_status )
@@ -154,7 +158,7 @@ void gdec_DestroyThread( gdec_thread_t *p_gdec, int *pi_status )
         }while( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR) 
                 && (i_status != THREAD_FATAL) );   
     }
-    
+
     intf_DbgMsg("%p -> succeeded\n", p_gdec);
 }
 
@@ -437,4 +441,3 @@ static void PrintPES( pes_packet_t *p_pes, int i_stream_id )
 #endif
     intf_Msg("gdec: PES %s\n", psz_pes );
 }
-
index c66ecc4cd073bae241b8d4aa1773e3a9acec7fae..e610539dd440b2542ee61bcdbfd277384e066354 100644 (file)
@@ -339,10 +339,12 @@ static void EndThread( input_thread_t *p_input )
                 case MPEG2_VIDEO_ES:
                     vdec_DestroyThread( (vdec_thread_t*)(p_input->pp_selected_es[i_es_loop]->p_dec) /*, NULL */ );
                     break;
+
                 case MPEG1_AUDIO_ES:
                 case MPEG2_AUDIO_ES:
                     adec_DestroyThread( (adec_thread_t*)(p_input->pp_selected_es[i_es_loop]->p_dec) );
                     break;
+
                 default:
                     break;
             }
index f7b3323d045ae010b5c1e0c6e6685b77f30ba50e..11bb02c0139ce3c6557800a741fbcde3f6e1c3e3 100644 (file)
@@ -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 Unset_known( byte_t* a_known_section, u8 i_section );
 
-
 /******************************************************************************
  * input_PsiInit: Initialize PSI decoder
  ******************************************************************************
@@ -110,7 +109,6 @@ int input_PsiInit( input_thread_t *p_input )
   return( 0 );
 }
 
-
 /******************************************************************************
  * input_PsiClean: Clean PSI structures before dying
  ******************************************************************************/
@@ -130,8 +128,6 @@ int input_PsiClean( input_thread_t *p_input )
   return( 0 );
 }
 
-
-
 /******************************************************************************
  * input_PsiRead: Read the table of programs
  ******************************************************************************
@@ -177,7 +173,6 @@ void input_PsiRead( input_thread_t *p_input /* ??? */ )
   //pthread_mutex_unlock()
 }
 
-
 /******************************************************************************
  * input_PsiDecode: Decode a PSI section
  ******************************************************************************
@@ -236,7 +231,6 @@ void input_PsiDecode( input_thread_t *p_input, psi_section_t* p_psi_section )
   }
 }
 
-
 /******************************************************************************
  * DecodeAssocSection: Decode a PAS
  ******************************************************************************
@@ -406,7 +400,6 @@ static void DecodePgrmAssocSection(u8* p_pas, input_thread_t *p_input )
 #undef p_descr
 }
 
-
 /******************************************************************************
  * DecodePgrmMapSection: Decode a PMS
  ******************************************************************************
@@ -620,8 +613,6 @@ static void DecodePgrmMapSection( u8* p_pms, input_thread_t* p_input )
 #undef p_descr
 }
 
-
-
 /******************************************************************************
  * DecodeSrvDescrSection
  ******************************************************************************
@@ -705,13 +696,7 @@ void DecodeSrvDescrSection( byte_t* p_sdt, input_thread_t *p_input )
      }
    }
 #undef p_stream
-};
-
-
-
-
-
-
+}
 
 /******************************************************************************
  * DecodePgrmDescr
@@ -768,9 +753,6 @@ static void DecodePgrmDescriptor( byte_t* p_descriptor, pgrm_descriptor_t* p_pgr
     }
 }
 
-
-
-
 /******************************************************************************
  * DecodeESDescriptor
  ******************************************************************************
@@ -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
  ******************************************************************************
@@ -880,7 +860,6 @@ static int input_AddPsiPID( input_thread_t *p_input, int i_pid )
   return( i_rc );
 }
 
-
 /******************************************************************************
  * 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 )
   return( 0 );
 }
 
-
-
 /******************************************************************************
  * Precalculate the 32-bit CRC table
  ******************************************************************************
@@ -955,7 +932,6 @@ void BuildCrc32Table( )
     }
 }
 
-
 /******************************************************************************
  * Test the validity of a checksum
  ******************************************************************************
@@ -976,8 +952,6 @@ int CheckCRC32(byte_t* p_data, int i_data_size)
   return i_crc;
 }
 
-
-
 /******************************************************************************
  * 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 )
   return b_is_known;
 }
 
-
 /******************************************************************************
  * 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 )
   a_known_section[i_byte_in_table] |= mask;
 }
 
-
 /******************************************************************************
  * 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 )
   a_known_section[i_byte_in_table] &= mask;
 }
 
-
 /******************************************************************************
  * 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
   return p_input->p_stream;
 }
 
-
 /******************************************************************************
  * DestroyStreamDescr: destroy the stream desciptor of the given input
  ******************************************************************************
@@ -1102,10 +1072,9 @@ static void DestroyStreamDescr(input_thread_t* p_input, u16 i_stream_id)
   /* 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++ )
   {
-    DestroyPgrmDescr( p_input, p_input->p_stream,
-                      p_input->p_stream->ap_programs[i_index]->i_number );
+    DestroyPgrmDescr( p_input, p_input->p_stream, p_input->p_stream->ap_programs[i_index]->i_number );
   }
-  
+
   /* Free the table of pgrm descriptors */
   free( p_input->p_stream->ap_programs );
 
@@ -1116,7 +1085,6 @@ static void DestroyStreamDescr(input_thread_t* p_input, u16 i_stream_id)
   p_input->p_stream = NULL;
 }
 
-
 /******************************************************************************
  * AddPgrmDescr: add and init a program descriptor
  ******************************************************************************
@@ -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];
 }
 
-
 /******************************************************************************
  * AddPgrmDescr: destroy a program descriptor
  ******************************************************************************
  * 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;
-  pgrm_descriptor_t* p_pgrm;
-  
-  ASSERT(p_stream);
+  int i_index, i_pgrm_index;
+  pgrm_descriptor_t * p_pgrm;
+
+  ASSERT( p_stream );
 
-  /* Find where is described this program */
-  for(i_index = 0; i_index < p_stream->i_pgrm_number; i_index++)
+  /* Find where this program is described */
+  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 )
     {
-      /* Here we are */
-      p_pgrm = p_stream->ap_programs[i_index];
+      i_pgrm_index = i_index;
+      p_pgrm = p_stream->ap_programs[ i_pgrm_index ];
       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++ )
-    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( p_pgrm->ap_es );
@@ -1183,13 +1152,12 @@ static void DestroyPgrmDescr(input_thread_t* p_input, stream_descriptor_t* p_str
   /* Free the description of this stream */
   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->ap_programs[i_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[ 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 * sizeof(pgrm_descriptor_t *) );
 }
 
-
 /******************************************************************************
  * AddESDescr:
  ******************************************************************************
@@ -1247,8 +1215,6 @@ static es_descriptor_t* AddESDescr(input_thread_t* p_input,
   return p_es;
 }
 
-
-
 /******************************************************************************
  * DestroyESDescr:
  ******************************************************************************
index 3c0c784deda9ccd544cac1250d50c45f4b3f9c4a..f7db898ad4895639e467b387672d98fa18126ef0 100644 (file)
@@ -108,9 +108,14 @@ void vdec_DestroyThread( vdec_thread_t *p_vdec /*, int *pi_status */ )
 
     /* Ask thread to kill itself */
     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 */
-    pthread_join( p_vdec->thread_id, NULL );         /* wait until it's done */
+    pthread_join( p_vdec->thread_id, NULL );
 }
 
 /* following functions are local */
@@ -281,5 +286,3 @@ static void EndThread( vdec_thread_t *p_vdec )
 
     intf_DbgMsg("vdec debug: EndThread(%p)\n", p_vdec);
 }
-
-