@@ -19,7 +19,7 @@ API changes, most recent first:
Operations on FIFOs created with this function on these elements
rather than bytes.
Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write(),
- av_fifo_grow2().
+ av_fifo_grow2(), av_fifo_drain2().
2022-01-xx - xxxxxxxxxx - lavu fifo.h
Access to all AVFifoBuffer members is deprecated. The struct will
@@ -187,6 +187,26 @@ int av_fifo_grow2(AVFifoBuffer *f, size_t inc)
return 0;
}
+void av_fifo_drain2(AVFifoBuffer *f, size_t size)
+{
+ FifoBuffer *fb = (FifoBuffer*)f;
+ const size_t cur_size = av_fifo_can_read(f);
+
+ av_assert0(cur_size >= size);
+ if (cur_size == size)
+ fb->is_empty = 1;
+
+ if (fb->offset_r >= fb->nb_elems - size)
+ fb->offset_r -= fb->nb_elems - size;
+ else
+ fb->offset_r += size;
+
+#if FF_API_FIFO_PUBLIC
+ f->rptr = f->buffer + fb->offset_r * fb->elem_size;
+ f->rndx += size;
+#endif
+}
+
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
{
FifoBuffer *fb = (FifoBuffer*)f;
@@ -343,19 +363,5 @@ int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size,
/** Discard data from the FIFO. */
void av_fifo_drain(AVFifoBuffer *f, int size)
{
- FifoBuffer *fb = (FifoBuffer*)f;
- const size_t cur_size = av_fifo_size(f);
-
- av_assert2(cur_size >= size);
- if (cur_size == size)
- fb->is_empty = 1;
-
- if (fb->offset_r >= fb->nb_elems - size)
- fb->offset_r -= fb->nb_elems - size;
- else
- fb->offset_r += size;
-#if FF_API_FIFO_PUBLIC
- f->rptr = f->buffer + fb->offset_r * fb->elem_size;
- f->rndx += size;
-#endif
+ return av_fifo_drain2(f, size);
}
@@ -143,6 +143,13 @@ size_t av_fifo_can_write(const AVFifoBuffer *f);
*/
int av_fifo_grow2(AVFifoBuffer *f, size_t inc);
+/**
+ * Discard the specified amount of data from an AVFifoBuffer.
+ * @param size number of elements to discard, MUST NOT be larger than
+ * av_fifo_can_read(f)
+ */
+void av_fifo_drain2(AVFifoBuffer *f, size_t size);
+
/**
* Feed data at specific position from an AVFifoBuffer to a user-supplied callback.
* Similar as av_fifo_gereric_read but without discarding data.