comparison fifo.c @ 511:5accd0bccc76 libavutil

Ensure that one can store X bytes in a fifo of size X. Fixed issue417.
author michael
date Sun, 25 May 2008 23:04:09 +0000
parents b7593ce78422
children a1ac1cb9a91b
comparison
equal deleted inserted replaced
510:b7593ce78422 511:5accd0bccc76
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, int size) 25 int av_fifo_init(AVFifoBuffer *f, unsigned int size)
26 { 26 {
27 size= FFMAX(size, size+1);
27 f->wptr = f->rptr = 28 f->wptr = f->rptr =
28 f->buffer = av_malloc(size); 29 f->buffer = av_malloc(size);
29 f->end = f->buffer + size; 30 f->end = f->buffer + size;
30 if (!f->buffer) 31 if (!f->buffer)
31 return -1; 32 return -1;
54 * Resizes a FIFO. 55 * Resizes a FIFO.
55 */ 56 */
56 void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) { 57 void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
57 unsigned int old_size= f->end - f->buffer; 58 unsigned int old_size= f->end - f->buffer;
58 59
59 if(old_size < new_size){ 60 if(old_size <= new_size){
60 int len= av_fifo_size(f); 61 int len= av_fifo_size(f);
61 AVFifoBuffer f2; 62 AVFifoBuffer f2;
62 63
63 av_fifo_init(&f2, new_size); 64 av_fifo_init(&f2, new_size);
64 av_fifo_read(f, f2.buffer, len); 65 av_fifo_read(f, f2.buffer, len);