# HG changeset patch # User michael # Date 1236521815 0 # Node ID 58a5033060c38377b81c5335d5db955e25138184 # Parent bcd0e6fe83d8e42afb2257763ea7b9fa7844624c Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues. Yes this breaks ABI/API but ive already broken it and will bump avutil major soon. diff -r bcd0e6fe83d8 -r 58a5033060c3 fifo.c --- a/fifo.c Sun Mar 08 01:28:14 2009 +0000 +++ b/fifo.c Sun Mar 08 14:16:55 2009 +0000 @@ -22,20 +22,25 @@ #include "common.h" #include "fifo.h" -int av_fifo_init(AVFifoBuffer *f, unsigned int size) +AVFifoBuffer *av_fifo_alloc(unsigned int size) { + AVFifoBuffer *f= av_mallocz(sizeof(AVFifoBuffer)); + if(!f) + return NULL; f->wptr = f->rptr = f->buffer = av_malloc(size); f->end = f->buffer + size; - f->rndx = f->wndx = 0; if (!f->buffer) - return -1; - return 0; + av_freep(&f); + return f; } void av_fifo_free(AVFifoBuffer *f) { + if(f){ av_free(f->buffer); + av_free(f); + } } int av_fifo_size(AVFifoBuffer *f) @@ -59,15 +64,16 @@ if(old_size < new_size){ int len= av_fifo_size(f); - AVFifoBuffer f2; + AVFifoBuffer *f2= av_fifo_alloc(new_size); - if (av_fifo_init(&f2, new_size) < 0) + if (!f2) return -1; - av_fifo_read(f, f2.buffer, len); - f2.wptr += len; - f2.wndx += len; + av_fifo_read(f, f2->buffer, len); + f2->wptr += len; + f2->wndx += len; av_free(f->buffer); - *f= f2; + *f= *f2; + av_free(f2); } return 0; } diff -r bcd0e6fe83d8 -r 58a5033060c3 fifo.h --- a/fifo.h Sun Mar 08 01:28:14 2009 +0000 +++ b/fifo.h Sun Mar 08 14:16:55 2009 +0000 @@ -36,11 +36,10 @@ /** * Initializes an AVFifoBuffer. - * @param *f AVFifoBuffer to initialize * @param size of FIFO - * @return <0 for failure >=0 otherwise + * @return AVFifoBuffer or NULL if mem allocation failure */ -int av_fifo_init(AVFifoBuffer *f, unsigned int size); +AVFifoBuffer *av_fifo_alloc(unsigned int size); /** * Frees an AVFifoBuffer.