summaryrefslogtreecommitdiff
path: root/libavutil/fifo.h
diff options
context:
space:
mode:
authorStefano Sabatini <stefano.sabatini-lala@poste.it>2011-06-29 17:30:23 +0200
committerAnton Khirnov <anton@khirnov.net>2011-08-26 20:53:02 +0200
commitf2011ed234f580de01768257f3da6e73fbf8ac7b (patch)
tree86ea1bac14e765c42e82cda13f0c43ee5fcfc462 /libavutil/fifo.h
parentf4f3300c09bb13eb7922e60888b55e3e0fb325e7 (diff)
fifo: add av_fifo_peek2(), and deprecate av_fifo_peek()
The new function provides a more generic interface than av_fifo_peek() for peeking at a FIFO buffer data. Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavutil/fifo.h')
-rw-r--r--libavutil/fifo.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 92319616b9..961463a2a4 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -25,6 +25,7 @@
#define AVUTIL_FIFO_H
#include <stdint.h>
+#include "avutil.h"
typedef struct AVFifoBuffer {
uint8_t *buffer;
@@ -106,11 +107,35 @@ 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;
}
+
+#if FF_API_AV_FIFO_PEEK
+/**
+ * @deprecated Use av_fifo_peek2() instead.
+ */
+attribute_deprecated
+static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
+{
+ return *av_fifo_peek2(f, offs);
+}
+#endif
+
#endif /* AVUTIL_FIFO_H */