aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2004-12-01 02:28:28 +0000
committerMichael Niedermayer <michaelni@gmx.at>2004-12-01 02:28:28 +0000
commit0d71240921397c98af9b42616be2fe4796df8912 (patch)
tree4ac76cd0564551ed74359eb51d9229cf153b61a9 /libavformat/utils.c
parent61f4aa96bad7fcca334df1aab5d5236a60bedaca (diff)
downloadffmpeg-0d71240921397c98af9b42616be2fe4796df8912.tar.gz
fifo_realloc()
Originally committed as revision 3726 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index a861c97c33..ddfaddeefe 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -232,6 +232,9 @@ void fifo_free(FifoBuffer *f)
int fifo_size(FifoBuffer *f, uint8_t *rptr)
{
int size;
+
+ if(!rptr)
+ rptr= f->rptr;
if (f->wptr >= rptr) {
size = f->wptr - rptr;
@@ -244,9 +247,13 @@ int fifo_size(FifoBuffer *f, uint8_t *rptr)
/* get data from the fifo (return -1 if not enough data) */
int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr)
{
- uint8_t *rptr = *rptr_ptr;
+ uint8_t *rptr;
int size, len;
+ if(!rptr_ptr)
+ rptr_ptr= &f->rptr;
+ rptr = *rptr_ptr;
+
if (f->wptr >= rptr) {
size = f->wptr - rptr;
} else {
@@ -270,11 +277,34 @@ int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr)
return 0;
}
+void fifo_realloc(FifoBuffer *f, int new_size){
+ int old_size= f->end - f->buffer;
+
+ if(old_size < new_size){
+ uint8_t *old= f->buffer;
+
+ f->buffer= av_realloc(f->buffer, new_size);
+
+ f->rptr += f->buffer - old;
+ f->wptr += f->buffer - old;
+
+ if(f->wptr < f->rptr){
+ memmove(f->rptr + new_size - old_size, f->rptr, f->buffer + old_size - f->rptr);
+ f->rptr += new_size - old_size;
+ }
+ f->end= f->buffer + new_size;
+ }
+}
+
void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr)
{
int len;
uint8_t *wptr;
+
+ if(!wptr_ptr)
+ wptr_ptr= &f->wptr;
wptr = *wptr_ptr;
+
while (size > 0) {
len = f->end - wptr;
if (len > size)