[FFmpeg-devel] [PATCH 01/12] fifo: uninline av_fifo_peek2() on the next major bump

Anton Khirnov anton at khirnov.net
Mon Feb 24 14:37:28 EET 2020


Inline public functions should be avoided unless absolutely necessary,
and no such necessity exists in this code.
---
 libavutil/fifo.c | 13 +++++++++++++
 libavutil/fifo.h |  5 +++++
 2 files changed, 18 insertions(+)

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 1060aedf13..0baaadc521 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -23,6 +23,7 @@
 #include "avassert.h"
 #include "common.h"
 #include "fifo.h"
+#include "version.h"
 
 static AVFifoBuffer *fifo_alloc_common(void *buffer, size_t size)
 {
@@ -238,3 +239,15 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
         f->rptr -= f->end - f->buffer;
     f->rndx += size;
 }
+
+#if LIBAVUTIL_VERSION_MAJOR >= 57
+uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs);
+{
+    uint8_t *ptr = f->rptr + offs;
+    if (ptr >= f->end)
+        ptr = f->buffer + (ptr - f->end);
+    else if (ptr < f->buffer)
+        ptr = f->end - (f->buffer - ptr);
+    return ptr;
+}
+#endif
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index dc7bc6f0dd..8cd964ef45 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -27,6 +27,7 @@
 #include <stdint.h>
 #include "avutil.h"
 #include "attributes.h"
+#include "version.h"
 
 typedef struct AVFifoBuffer {
     uint8_t *buffer;
@@ -166,6 +167,7 @@ void av_fifo_drain(AVFifoBuffer *f, int size);
  *             point outside to the buffer data.
  *             The used buffer size can be checked with av_fifo_size().
  */
+#if LIBAVUTIL_VERSION_MAJOR < 57
 static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
 {
     uint8_t *ptr = f->rptr + offs;
@@ -175,5 +177,8 @@ static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
         ptr = f->end - (f->buffer - ptr);
     return ptr;
 }
+#else
+uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs);
+#endif
 
 #endif /* AVUTIL_FIFO_H */
-- 
2.24.1



More information about the ffmpeg-devel mailing list