1 /* $Id: fifo.c,v 1.17 2005/10/15 18:05:03 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
13 hb_buffer_t * hb_buffer_init( int size )
17 if( !( b = calloc( sizeof( hb_buffer_t ), 1 ) ) )
19 hb_log( "out of memory" );
27 #if defined( SYS_DARWIN ) || defined( SYS_FREEBSD )
28 b->data = malloc( size );
29 #elif defined( SYS_CYGWIN )
31 b->data = malloc( size + 17 );
33 b->data = memalign( 16, size );
38 hb_log( "out of memory" );
45 void hb_buffer_realloc( hb_buffer_t * b, int size )
47 /* No more alignment, but we don't care */
48 b->data = realloc( b->data, size );
52 void hb_buffer_close( hb_buffer_t ** _b )
54 hb_buffer_t * b = *_b;
65 void hb_buffer_copy_settings( hb_buffer_t * dst, const hb_buffer_t * src )
67 dst->start = src->start;
68 dst->stop = src->stop;
69 dst->new_chap = src->new_chap;
70 dst->frametype = src->frametype;
71 dst->flags = src->flags;
84 hb_fifo_t * hb_fifo_init( int capacity )
87 f = calloc( sizeof( hb_fifo_t ), 1 );
88 f->lock = hb_lock_init();
89 f->capacity = capacity;
93 int hb_fifo_size( hb_fifo_t * f )
104 int hb_fifo_is_full( hb_fifo_t * f )
109 ret = ( f->size >= f->capacity );
110 hb_unlock( f->lock );
115 float hb_fifo_percent_full( hb_fifo_t * f )
120 ret = f->size / f->capacity;
121 hb_unlock( f->lock );
126 hb_buffer_t * hb_fifo_get( hb_fifo_t * f )
133 hb_unlock( f->lock );
140 hb_unlock( f->lock );
145 hb_buffer_t * hb_fifo_see( hb_fifo_t * f )
152 hb_unlock( f->lock );
156 hb_unlock( f->lock );
161 hb_buffer_t * hb_fifo_see2( hb_fifo_t * f )
168 hb_unlock( f->lock );
172 hb_unlock( f->lock );
177 void hb_fifo_push( hb_fifo_t * f, hb_buffer_t * b )
195 while( f->last->next )
198 f->last = f->last->next;
200 hb_unlock( f->lock );
203 void hb_fifo_close( hb_fifo_t ** _f )
208 hb_log( "fifo_close: trashing %d buffer(s)", hb_fifo_size( f ) );
209 while( ( b = hb_fifo_get( f ) ) )
211 hb_buffer_close( &b );
214 hb_lock_close( &f->lock );