]> git.sesse.net Git - vlc/blobdiff - plugins/mpeg/input_ps.c
* Fixed the BeOS compile typo.
[vlc] / plugins / mpeg / input_ps.c
index be1f7356599d862710ce6f2e9bbc0d2dc6cb5539..856856c723f61ca56ab35a7e85f1ffb8ebb383d5 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.c: PS demux and packet management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ps.c,v 1.22 2001/05/07 04:42:42 sam Exp $
+ * $Id: input_ps.c,v 1.25 2001/05/30 17:03:12 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
@@ -88,8 +88,8 @@ void _M( input_getfunctions )( function_list_t * p_function_list )
 #define input p_function_list->functions.input
     p_function_list->pf_probe = PSProbe;
     input.pf_init             = PSInit;
-    input.pf_open             = input_FileOpen;
-    input.pf_close            = input_FileClose;
+    input.pf_open             = NULL; /* Set in PSInit */
+    input.pf_close            = NULL;
     input.pf_end              = PSEnd;
     input.pf_set_area         = NULL;
     input.pf_read             = PSRead;
@@ -166,6 +166,13 @@ static void PSInit( input_thread_t * p_input )
         return;
     }
     p_input->p_method_data = (void *)p_packet_cache;
+
+    /* Set callback */
+    p_input->pf_open  = p_input->pf_file_open;
+    p_input->pf_close = p_input->pf_file_close;
+
+    /* Initialize packet cache mutex */
+    vlc_mutex_init( &p_packet_cache->lock );
     
     /* allocates the data cache */
     p_packet_cache->data.p_stack = malloc( DATA_CACHE_SIZE * 
@@ -335,7 +342,16 @@ static void PSInit( input_thread_t * p_input )
                         break;
 
                     case LPCM_AUDIO_ES:
-                        /* FIXME ! */
+                        if( main_GetIntVariable( INPUT_CHANNEL_VAR, 0 )
+                                == ((p_es->i_id & 0x1F00) >> 8) )
+                        switch( main_GetIntVariable( INPUT_AUDIO_VAR, 0 ) )
+                        {
+                        case 0:
+                            main_PutIntVariable( INPUT_AUDIO_VAR,
+                                                 REQUESTED_LPCM );
+                        case REQUESTED_LPCM:
+                            input_SelectES( p_input, p_es );
+                        }
                         break;
                 }
             }
@@ -362,6 +378,7 @@ static void PSInit( input_thread_t * p_input )
  *****************************************************************************/
 static void PSEnd( input_thread_t * p_input )
 {
+    vlc_mutex_destroy( &((packet_cache_t *)p_input->p_plugin_data)->lock );
     free( p_input->p_plugin_data );
 }
 
@@ -571,6 +588,8 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
         return NULL;
     }
 
+    vlc_mutex_lock( &p_cache->lock );
+
     /* Checks whether the data cache is empty */
     if( p_cache->data.l_index == 0 )
     {
@@ -578,6 +597,7 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
         if ( (p_data = malloc( sizeof(data_packet_t) )) == NULL )
         {
             intf_ErrMsg( "Out of memory" );
+            vlc_mutex_unlock( &p_cache->lock );
             return NULL;
         }
 #ifdef TRACE_INPUT
@@ -591,6 +611,7 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
             == NULL )
         {
             intf_ErrMsg( "NULL packet in the data cache" );
+            vlc_mutex_unlock( &p_cache->lock );
             return NULL;
         }
     }
@@ -607,6 +628,7 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
             {
                 intf_DbgMsg( "Out of memory" );
                 free( p_data );
+                vlc_mutex_unlock( &p_cache->lock );
                 return NULL;
             }
 #ifdef TRACE_INPUT
@@ -623,6 +645,7 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
             {
                 intf_ErrMsg( "NULL packet in the small buffer cache" );
                 free( p_data );
+                vlc_mutex_unlock( &p_cache->lock );
                 return NULL;
             }
             /* Reallocates the packet if it is too small or too large */
@@ -650,6 +673,7 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
             {
                 intf_ErrMsg( "Out of memory" );
                 free( p_data );
+                vlc_mutex_unlock( &p_cache->lock );
                 return NULL;
             }
 #ifdef TRACE_INPUT
@@ -666,6 +690,7 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
             {
                 intf_ErrMsg( "NULL packet in the small buffer cache" );
                 free( p_data );
+                vlc_mutex_unlock( &p_cache->lock );
                 return NULL;
             }
             /* Reallocates the packet if it is too small or too large */
@@ -682,6 +707,8 @@ static struct data_packet_s * NewPacket( void * p_packet_cache,
         }
     }
 
+    vlc_mutex_unlock( &p_cache->lock );
+
     /* Initialize data */
     p_data->p_next = NULL;
     p_data->b_discard_payload = 0;
@@ -711,6 +738,8 @@ static pes_packet_t * NewPES( void * p_packet_cache )
     }
 #endif
 
+    vlc_mutex_lock( &p_cache->lock );  
+
     /* Checks whether the PES cache is empty */
     if( p_cache->pes.l_index == 0 )
     {
@@ -718,6 +747,7 @@ static pes_packet_t * NewPES( void * p_packet_cache )
         if ( (p_pes = malloc( sizeof(pes_packet_t) )) == NULL )
         {
             intf_DbgMsg( "Out of memory" );
+            vlc_mutex_unlock( &p_cache->lock );        
             return NULL;
         }
 #ifdef TRACE_INPUT
@@ -731,10 +761,13 @@ static pes_packet_t * NewPES( void * p_packet_cache )
             == NULL )
         {
             intf_ErrMsg( "NULL packet in the data cache" );
+            vlc_mutex_unlock( &p_cache->lock );
             return NULL;
         }
     }
 
+    vlc_mutex_unlock( &p_cache->lock );
+
     p_pes->b_data_alignment = p_pes->b_discontinuity =
         p_pes->i_pts = p_pes->i_dts = 0;
     p_pes->i_pes_size = 0;
@@ -764,6 +797,8 @@ static void DeletePacket( void * p_packet_cache,
 
     ASSERT( p_data );
 
+    vlc_mutex_lock( &p_cache->lock );
+
     /* Checks whether the data cache is full */
     if ( p_cache->data.l_index < DATA_CACHE_SIZE )
     {
@@ -819,6 +854,7 @@ static void DeletePacket( void * p_packet_cache,
 #endif
     }
 
+    vlc_mutex_unlock( &p_cache->lock );
 }
 
 /*****************************************************************************
@@ -851,6 +887,8 @@ static void DeletePES( void * p_packet_cache, pes_packet_t * p_pes )
         p_data = p_next;
     }
 
+    vlc_mutex_lock( &p_cache->lock );
+
     /* Checks whether the PES cache is full */
     if ( p_cache->pes.l_index < PES_CACHE_SIZE )
     {
@@ -865,5 +903,7 @@ static void DeletePES( void * p_packet_cache, pes_packet_t * p_pes )
         intf_DbgMsg( "PS input: PES packet freed" );
 #endif
     }
+
+    vlc_mutex_unlock( &p_cache->lock );
 }