OSDN Git Service

SunOS support fixed with new ffmpeg and x264
[handbrake-jp/handbrake-jp-git.git] / libhb / fifo.c
index 1bf2a9d..9441f71 100644 (file)
@@ -85,12 +85,12 @@ void hb_buffer_pool_free( void )
         }
         if ( count )
         {
-            hb_log("Freed %d buffers of size %d", count,
+            hb_deep_log( 2, "Freed %d buffers of size %d", count,
                     buffers.pool[i]->buffer_size);
         }
     }
 
-    hb_log("Allocated %lld bytes of buffers on this pass and Freed %lld bytes, "
+    hb_deep_log( 2, "Allocated %lld bytes of buffers on this pass and Freed %lld bytes, "
            "%lld bytes leaked", buffers.allocated, freed, buffers.allocated - freed);
     buffers.allocated = 0;
     hb_unlock(buffers.lock);
@@ -190,7 +190,7 @@ void hb_buffer_close( hb_buffer_t ** _b )
 
     if( buffer_pool && b->data && !hb_fifo_is_full( buffer_pool ) )
     {
-        hb_fifo_push( buffer_pool, b );
+        hb_fifo_push_head( buffer_pool, b );
         return;
     }
     /* either the pool is full or this size doesn't use a pool - free the buf */
@@ -334,12 +334,49 @@ void hb_fifo_push( hb_fifo_t * f, hb_buffer_t * b )
     hb_unlock( f->lock );
 }
 
+void hb_fifo_push_head( hb_fifo_t * f, hb_buffer_t * b )
+{
+    hb_buffer_t * tmp;
+    uint32_t      size = 0;
+
+    if( !b )
+    {
+        return;
+    }
+
+    hb_lock( f->lock );
+
+    /*
+     * If there are a chain of buffers prepend the lot
+     */
+    tmp = b;
+    while( tmp->next )
+    {
+        tmp = tmp->next;
+        size += 1;
+    }
+
+    if( f->size > 0 )
+    {
+        tmp->next = f->first;
+    } 
+    else
+    {
+        f->last = tmp;
+    }
+
+    f->first = b;
+    f->size += ( size + 1 );
+
+    hb_unlock( f->lock );
+}
+
 void hb_fifo_close( hb_fifo_t ** _f )
 {
     hb_fifo_t   * f = *_f;
     hb_buffer_t * b;
 
-    hb_log( "fifo_close: trashing %d buffer(s)", hb_fifo_size( f ) );
+    hb_deep_log( 2, "fifo_close: trashing %d buffer(s)", hb_fifo_size( f ) );
     while( ( b = hb_fifo_get( f ) ) )
     {
         hb_buffer_close( &b );