summaryrefslogtreecommitdiff
path: root/libavutil/fifo.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2009-03-08 14:16:55 +0000
committerMichael Niedermayer <michaelni@gmx.at>2009-03-08 14:16:55 +0000
commit41dd680dd80d93626e133c02b92e31cabb756eeb (patch)
treee21e3fdda1fab791bf322d167be5e02c414e4384 /libavutil/fifo.c
parent48d58e592aa258494beed72954fff74b5827acca (diff)
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. Originally committed as revision 17869 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil/fifo.c')
-rw-r--r--libavutil/fifo.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 8436b3b6a4..515b2d7f59 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -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 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
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;
}