[FFmpeg-devel] [RFC] add av_fifo_reset

Reimar Döffinger Reimar.Doeffinger
Sun Mar 8 18:20:15 CET 2009


Hello,
As said previously, av_fifo_drain(f, av_fifo_size(f)) is a bit
complicated when you just want to reuse the buffer and thread-safety is
not an issue at that place.
Attached patch would add a av_fifo_reset specifically for that purpose.
-------------- next part --------------
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 57b229a..f2c00a0 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -27,9 +27,9 @@ AVFifoBuffer *av_fifo_alloc(unsigned int size)
     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_free(AVFifoBuffer *f)
     }
 }
 
+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 --git a/libavutil/fifo.h b/libavutil/fifo.h
index 9ba7e70..f64914f 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -48,6 +48,12 @@ AVFifoBuffer *av_fifo_alloc(unsigned int size);
 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



More information about the ffmpeg-devel mailing list