Mercurial > libavutil.hg
comparison fifo.c @ 679:58a5033060c3 libavutil
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.
author | michael |
---|---|
date | Sun, 08 Mar 2009 14:16:55 +0000 |
parents | 5dd1730abf98 |
children | cb5d78a798ac |
comparison
equal
deleted
inserted
replaced
678:bcd0e6fe83d8 | 679:58a5033060c3 |
---|---|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 */ | 21 */ |
22 #include "common.h" | 22 #include "common.h" |
23 #include "fifo.h" | 23 #include "fifo.h" |
24 | 24 |
25 int av_fifo_init(AVFifoBuffer *f, unsigned int size) | 25 AVFifoBuffer *av_fifo_alloc(unsigned int size) |
26 { | 26 { |
27 AVFifoBuffer *f= av_mallocz(sizeof(AVFifoBuffer)); | |
28 if(!f) | |
29 return NULL; | |
27 f->wptr = f->rptr = | 30 f->wptr = f->rptr = |
28 f->buffer = av_malloc(size); | 31 f->buffer = av_malloc(size); |
29 f->end = f->buffer + size; | 32 f->end = f->buffer + size; |
30 f->rndx = f->wndx = 0; | |
31 if (!f->buffer) | 33 if (!f->buffer) |
32 return -1; | 34 av_freep(&f); |
33 return 0; | 35 return f; |
34 } | 36 } |
35 | 37 |
36 void av_fifo_free(AVFifoBuffer *f) | 38 void av_fifo_free(AVFifoBuffer *f) |
37 { | 39 { |
40 if(f){ | |
38 av_free(f->buffer); | 41 av_free(f->buffer); |
42 av_free(f); | |
43 } | |
39 } | 44 } |
40 | 45 |
41 int av_fifo_size(AVFifoBuffer *f) | 46 int av_fifo_size(AVFifoBuffer *f) |
42 { | 47 { |
43 return (uint32_t)(f->wndx - f->rndx); | 48 return (uint32_t)(f->wndx - f->rndx); |
57 int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) { | 62 int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) { |
58 unsigned int old_size= f->end - f->buffer; | 63 unsigned int old_size= f->end - f->buffer; |
59 | 64 |
60 if(old_size < new_size){ | 65 if(old_size < new_size){ |
61 int len= av_fifo_size(f); | 66 int len= av_fifo_size(f); |
62 AVFifoBuffer f2; | 67 AVFifoBuffer *f2= av_fifo_alloc(new_size); |
63 | 68 |
64 if (av_fifo_init(&f2, new_size) < 0) | 69 if (!f2) |
65 return -1; | 70 return -1; |
66 av_fifo_read(f, f2.buffer, len); | 71 av_fifo_read(f, f2->buffer, len); |
67 f2.wptr += len; | 72 f2->wptr += len; |
68 f2.wndx += len; | 73 f2->wndx += len; |
69 av_free(f->buffer); | 74 av_free(f->buffer); |
70 *f= f2; | 75 *f= *f2; |
76 av_free(f2); | |
71 } | 77 } |
72 return 0; | 78 return 0; |
73 } | 79 } |
74 | 80 |
75 #if LIBAVUTIL_VERSION_MAJOR < 50 | 81 #if LIBAVUTIL_VERSION_MAJOR < 50 |