Commit 0a71e78c authored by Michael Niedermayer's avatar Michael Niedermayer

Try to fix the 1 byte cannot be used issue.

Originally committed as revision 17865 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 5add54b4
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
int av_fifo_init(AVFifoBuffer *f, unsigned int size) int av_fifo_init(AVFifoBuffer *f, unsigned int size)
{ {
size= FFMAX(size, size+1);
f->wptr = f->rptr = f->wptr = f->rptr =
f->buffer = av_malloc(size); f->buffer = av_malloc(size);
f->end = f->buffer + size; f->end = f->buffer + size;
f->rndx = f->wndx = 0;
if (!f->buffer) if (!f->buffer)
return -1; return -1;
return 0; return 0;
...@@ -40,10 +40,7 @@ void av_fifo_free(AVFifoBuffer *f) ...@@ -40,10 +40,7 @@ void av_fifo_free(AVFifoBuffer *f)
int av_fifo_size(AVFifoBuffer *f) int av_fifo_size(AVFifoBuffer *f)
{ {
int size = f->wptr - f->rptr; return (uint32_t)(f->wndx - f->rndx);
if (size < 0)
size += f->end - f->buffer;
return size;
} }
int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size) int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size)
...@@ -60,7 +57,7 @@ void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) { ...@@ -60,7 +57,7 @@ void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) { int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
unsigned int old_size= f->end - f->buffer; unsigned int old_size= f->end - f->buffer;
if(old_size <= new_size){ if(old_size < new_size){
int len= av_fifo_size(f); int len= av_fifo_size(f);
AVFifoBuffer f2; AVFifoBuffer f2;
...@@ -68,6 +65,7 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) { ...@@ -68,6 +65,7 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
return -1; return -1;
av_fifo_read(f, f2.buffer, len); av_fifo_read(f, f2.buffer, len);
f2.wptr += len; f2.wptr += len;
f2.wndx += len;
av_free(f->buffer); av_free(f->buffer);
*f= f2; *f= f2;
} }
...@@ -96,6 +94,7 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void ...@@ -96,6 +94,7 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
f->wptr += len; f->wptr += len;
if (f->wptr >= f->end) if (f->wptr >= f->end)
f->wptr = f->buffer; f->wptr = f->buffer;
f->wndx += len;
size -= len; size -= len;
} while (size > 0); } while (size > 0);
return total - size; return total - size;
...@@ -123,4 +122,5 @@ void av_fifo_drain(AVFifoBuffer *f, int size) ...@@ -123,4 +122,5 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
f->rptr += size; f->rptr += size;
if (f->rptr >= f->end) if (f->rptr >= f->end)
f->rptr -= f->end - f->buffer; f->rptr -= f->end - f->buffer;
f->rndx += size;
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
typedef struct AVFifoBuffer { typedef struct AVFifoBuffer {
uint8_t *buffer; uint8_t *buffer;
uint8_t *rptr, *wptr, *end; uint8_t *rptr, *wptr, *end;
uint32_t rndx, wndx;
} AVFifoBuffer; } AVFifoBuffer;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment