[FFmpeg-devel] [PATCH 04/35] lavu/fifo: add new functions for determinining reading/writing size
Anton Khirnov
anton at khirnov.net
Tue Jan 11 22:45:39 EET 2022
Consistently use size_t for sizes.
The new names should also be more clear - e.g. current av_fifo_size()
could be misinterpreted as meaning the allocated size.
---
doc/APIchanges | 2 +-
libavutil/fifo.c | 16 +++++++++++++---
libavutil/fifo.h | 10 ++++++++++
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 5646cf2278..9400c5147a 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -18,7 +18,7 @@ API changes, most recent first:
Add av_fifo_alloc2(), which allows setting a FIFO element size.
Operations on FIFOs created with this function on these elements
rather than bytes.
- Add av_fifo_elem_size().
+ Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write().
2022-01-xx - xxxxxxxxxx - lavu fifo.h
Access to all AVFifoBuffer members is deprecated. The struct will
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index fc7c93470f..8cde2c20e1 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -126,7 +126,7 @@ size_t av_fifo_elem_size(const AVFifoBuffer *f)
return fb->elem_size;
}
-int av_fifo_size(const AVFifoBuffer *f)
+size_t av_fifo_can_read(const AVFifoBuffer *f)
{
const FifoBuffer *fb = (const FifoBuffer*)f;
if (fb->offset_w <= fb->offset_r && !fb->is_empty)
@@ -134,10 +134,20 @@ int av_fifo_size(const AVFifoBuffer *f)
return fb->offset_w - fb->offset_r;
}
-int av_fifo_space(const AVFifoBuffer *f)
+size_t av_fifo_can_write(const AVFifoBuffer *f)
{
const FifoBuffer *fb = (const FifoBuffer*)f;
- return fb->nb_elems - av_fifo_size(f);
+ return fb->nb_elems - av_fifo_can_read(f);
+}
+
+int av_fifo_size(const AVFifoBuffer *f)
+{
+ return av_fifo_can_read(f);
+}
+
+int av_fifo_space(const AVFifoBuffer *f)
+{
+ return av_fifo_can_write(f);
}
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 22362c0239..9e78082b3b 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -119,6 +119,16 @@ int av_fifo_size(const AVFifoBuffer *f);
*/
int av_fifo_space(const AVFifoBuffer *f);
+/**
+ * @return number of elements available for reading from the given FIFO.
+ */
+size_t av_fifo_can_read(const AVFifoBuffer *f);
+
+/**
+ * @return number of elements that can be written into the given FIFO.
+ */
+size_t av_fifo_can_write(const AVFifoBuffer *f);
+
/**
* Feed data at specific position from an AVFifoBuffer to a user-supplied callback.
* Similar as av_fifo_gereric_read but without discarding data.
--
2.33.0
More information about the ffmpeg-devel
mailing list