OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / libhb / fifo.c
index 781c940..a29e846 100644 (file)
@@ -202,14 +202,19 @@ void hb_buffer_close( hb_buffer_t ** _b )
         return;
     }
     /* either the pool is full or this size doesn't use a pool - free the buf */
-    if( b->data )
+    while( b )
     {
-        free( b->data );
-        hb_lock(buffers.lock);
-        buffers.allocated -= b->alloc;
-        hb_unlock(buffers.lock);
+        hb_buffer_t * next = b->next;
+        if( b->data )
+        {
+            free( b->data );
+            hb_lock(buffers.lock);
+            buffers.allocated -= b->alloc;
+            hb_unlock(buffers.lock);
+        }
+        free( b );
+        b = next;
     }
-    free( b );
     *_b = NULL;
 }
 
@@ -235,6 +240,23 @@ hb_fifo_t * hb_fifo_init( int capacity, int thresh )
     return f;
 }
 
+int hb_fifo_size_bytes( hb_fifo_t * f )
+{
+    int ret = 0;
+    hb_buffer_t * link;
+
+    hb_lock( f->lock );
+    link = f->first;
+    while ( link )
+    {
+        ret += link->size;
+        link = link->next;
+    }
+    hb_unlock( f->lock );
+
+    return ret;
+}
+
 int hb_fifo_size( hb_fifo_t * f )
 {
     int ret;
@@ -374,6 +396,21 @@ hb_buffer_t * hb_fifo_see2( hb_fifo_t * f )
     return b;
 }
 
+int hb_fifo_full_wait( hb_fifo_t * f )
+{
+    int result;
+
+    hb_lock( f->lock );
+    if( f->size >= f->capacity )
+    {
+        f->wait_full = 1;
+        hb_cond_timedwait( f->cond_full, f->lock, FIFO_TIMEOUT );
+    }
+    result = ( f->size < f->capacity );
+    hb_unlock( f->lock );
+    return result;
+}
+
 void hb_fifo_push_wait( hb_fifo_t * f, hb_buffer_t * b )
 {
     if( !b )