
Attached is a patch for the packet cache (buffer allocator)
in input_ps. Two threads are accessing the cache so I added
a mutex.

-- 
Jon Johansen
nanocrew.net


-- Attached file included as plaintext by Listar --

diff -urN vlc.cvs/plugins/mpeg/input_ps.c vlc/plugins/mpeg/input_ps.c
--- vlc.cvs/plugins/mpeg/input_ps.c	Mon May  7 21:45:28 2001
+++ vlc/plugins/mpeg/input_ps.c	Mon May  7 22:01:35 2001
@@ -166,6 +166,9 @@
         return;
     }
     p_input->p_method_data = (void *)p_packet_cache;
+
+    /* init packet cache mutex */
+    vlc_mutex_init( &p_packet_cache->lock );
     
     /* allocates the data cache */
     p_packet_cache->data.p_stack = malloc( DATA_CACHE_SIZE * 
@@ -362,6 +365,7 @@
  *****************************************************************************/
 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 +575,8 @@
         return NULL;
     }
 
+    vlc_mutex_lock( &p_cache->lock );
+
     /* Checks whether the data cache is empty */
     if( p_cache->data.l_index == 0 )
     {
@@ -578,6 +584,7 @@
         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 +598,7 @@
             == NULL )
         {
             intf_ErrMsg( "NULL packet in the data cache" );
+            vlc_mutex_unlock( &p_cache->lock );
             return NULL;
         }
     }
@@ -607,6 +615,7 @@
             {
                 intf_DbgMsg( "Out of memory" );
                 free( p_data );
+                vlc_mutex_unlock( &p_cache->lock );
                 return NULL;
             }
 #ifdef TRACE_INPUT
@@ -623,6 +632,7 @@
             {
                 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 +660,7 @@
             {
                 intf_ErrMsg( "Out of memory" );
                 free( p_data );
+                vlc_mutex_unlock( &p_cache->lock );
                 return NULL;
             }
 #ifdef TRACE_INPUT
@@ -666,6 +677,7 @@
             {
                 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 +694,8 @@
         }
     }
 
+    vlc_mutex_unlock( &p_cache->lock );
+
     /* Initialize data */
     p_data->p_next = NULL;
     p_data->b_discard_payload = 0;
@@ -711,6 +725,8 @@
     }
 #endif
 
+    vlc_mutex_lock( &p_cache->lock );	
+
     /* Checks whether the PES cache is empty */
     if( p_cache->pes.l_index == 0 )
     {
@@ -718,6 +734,7 @@
         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 +748,13 @@
             == 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 +784,8 @@
 
     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 +841,7 @@
 #endif
     }
 
+    vlc_mutex_unlock( &p_cache->lock );
 }
 
 /*****************************************************************************
@@ -851,6 +874,8 @@
         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 +890,7 @@
         intf_DbgMsg( "PS input: PES packet freed" );
 #endif
     }
+
+    vlc_mutex_unlock( &p_cache->lock );
 }
 
diff -urN vlc.cvs/plugins/mpeg/input_ps.h vlc/plugins/mpeg/input_ps.h
--- vlc.cvs/plugins/mpeg/input_ps.h	Mon Apr 16 14:34:28 2001
+++ vlc/plugins/mpeg/input_ps.h	Mon May  7 21:58:07 2001
@@ -75,6 +75,7 @@
 
 typedef struct
 {
+    vlc_mutex_t             lock;
     data_packet_cache_t     data;
     pes_packet_cache_t      pes;
     small_buffer_cache_t    small;



