diff options
author | Roman Shaposhnik <roman@shaposhnik.org> | 2006-09-21 07:31:53 +0000 |
---|---|---|
committer | Roman Shaposhnik <roman@shaposhnik.org> | 2006-09-21 07:31:53 +0000 |
commit | f5a478f65d7262dbe194641d384f24fbbc03ed85 (patch) | |
tree | fbdda2fba8809f3e7a6c662017d812276da8d5c1 /libavformat/utils.c | |
parent | a1ef006823de991c546a89b3e9135617a3524582 (diff) | |
download | ffmpeg-f5a478f65d7262dbe194641d384f24fbbc03ed85.tar.gz |
* Moving FifoBuffer out of libavformat/avformat.h and
libavformat/utils.c into libavutil
Originally committed as revision 6310 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 77bc84aa10..425db9a28a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -263,146 +263,6 @@ int av_dup_packet(AVPacket *pkt) return 0; } -/* fifo handling */ - -int fifo_init(FifoBuffer *f, int size) -{ - f->buffer = av_malloc(size); - if (!f->buffer) - return -1; - f->end = f->buffer + size; - f->wptr = f->rptr = f->buffer; - return 0; -} - -void fifo_free(FifoBuffer *f) -{ - av_free(f->buffer); -} - -int fifo_size(FifoBuffer *f, uint8_t *rptr) -{ - int size; - - if(!rptr) - rptr= f->rptr; - - if (f->wptr >= rptr) { - size = f->wptr - rptr; - } else { - size = (f->end - rptr) + (f->wptr - f->buffer); - } - return size; -} - -/** - * Get data from the fifo (returns -1 if not enough data). - */ -int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **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 { - size = (f->end - rptr) + (f->wptr - f->buffer); - } - - if (size < buf_size) - return -1; - while (buf_size > 0) { - len = f->end - rptr; - if (len > buf_size) - len = buf_size; - memcpy(buf, rptr, len); - buf += len; - rptr += len; - if (rptr >= f->end) - rptr = f->buffer; - buf_size -= len; - } - *rptr_ptr = rptr; - return 0; -} - -/** - * Resizes a FIFO. - */ -void fifo_realloc(FifoBuffer *f, unsigned int new_size){ - unsigned 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, const 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) - len = size; - memcpy(wptr, buf, len); - wptr += len; - if (wptr >= f->end) - wptr = f->buffer; - buf += len; - size -= len; - } - *wptr_ptr = wptr; -} - -/* get data from the fifo (return -1 if not enough data) */ -int put_fifo(ByteIOContext *pb, FifoBuffer *f, int buf_size, uint8_t **rptr_ptr) -{ - uint8_t *rptr = *rptr_ptr; - int size, len; - - if (f->wptr >= rptr) { - size = f->wptr - rptr; - } else { - size = (f->end - rptr) + (f->wptr - f->buffer); - } - - if (size < buf_size) - return -1; - while (buf_size > 0) { - len = f->end - rptr; - if (len > buf_size) - len = buf_size; - put_buffer(pb, rptr, len); - rptr += len; - if (rptr >= f->end) - rptr = f->buffer; - buf_size -= len; - } - *rptr_ptr = rptr; - return 0; -} - /** * Allocate the payload of a packet and intialized its fields to default values. * |