]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/fifo.h
mp3: Make the extrasize explicit
[ffmpeg] / libavutil / fifo.h
index 92319616b96d5f37037e6c04534876493a46b9ad..ea30f5d2bdd0f0fd944e652a434f6dd14cb799c6 100644 (file)
@@ -25,6 +25,8 @@
 #define AVUTIL_FIFO_H
 
 #include <stdint.h>
+#include "avutil.h"
+#include "attributes.h"
 
 typedef struct AVFifoBuffer {
     uint8_t *buffer;
@@ -106,11 +108,24 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
  */
 void av_fifo_drain(AVFifoBuffer *f, int size);
 
-static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
+/**
+ * Return a pointer to the data stored in a FIFO buffer at a certain offset.
+ * The FIFO buffer is not modified.
+ *
+ * @param f    AVFifoBuffer to peek at, f must be non-NULL
+ * @param offs an offset in bytes, its absolute value must be less
+ *             than the used buffer size or the returned pointer will
+ *             point outside to the buffer data.
+ *             The used buffer size can be checked with av_fifo_size().
+ */
+static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
 {
     uint8_t *ptr = f->rptr + offs;
     if (ptr >= f->end)
-        ptr -= f->end - f->buffer;
-    return *ptr;
+        ptr = f->buffer + (ptr - f->end);
+    else if (ptr < f->buffer)
+        ptr = f->end - (f->buffer - ptr);
+    return ptr;
 }
+
 #endif /* AVUTIL_FIFO_H */