# HG changeset patch # User reimar # Date 1236590792 0 # Node ID 91216685a7aeeade994184cef9a13a86b55efaaa # Parent bc81990848aa836ed1b90ddaca5dfd052d7e6e01 Add av_fifo_reset function to completely reset fifo state, which makes it easier to reuse the fifo. diff -r bc81990848aa -r 91216685a7ae fifo.c --- a/fifo.c Mon Mar 09 03:39:58 2009 +0000 +++ b/fifo.c Mon Mar 09 09:26:32 2009 +0000 @@ -27,9 +27,9 @@ AVFifoBuffer *f= av_mallocz(sizeof(AVFifoBuffer)); if(!f) return NULL; - f->wptr = f->rptr = f->buffer = av_malloc(size); f->end = f->buffer + size; + av_fifo_reset(f); if (!f->buffer) av_freep(&f); return f; @@ -43,6 +43,12 @@ } } +void av_fifo_reset(AVFifoBuffer *f) +{ + f->wptr = f->rptr = f->buffer; + f->wndx = f->rndx = 0; +} + int av_fifo_size(AVFifoBuffer *f) { return (uint32_t)(f->wndx - f->rndx); diff -r bc81990848aa -r 91216685a7ae fifo.h --- a/fifo.h Mon Mar 09 03:39:58 2009 +0000 +++ b/fifo.h Mon Mar 09 09:26:32 2009 +0000 @@ -48,6 +48,12 @@ void av_fifo_free(AVFifoBuffer *f); /** + * Resets the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied. + * @param *f AVFifoBuffer to reset + */ +void av_fifo_reset(AVFifoBuffer *f); + +/** * Returns the amount of data in bytes in the AVFifoBuffer, that is the * amount of data you can read from it. * @param *f AVFifoBuffer to read from