On date Saturday 2011-07-16 17:00:59 +0200, Diego Biurrun encoded:
> On Sat, Jul 16, 2011 at 10:25:58AM +0200, Stefano Sabatini wrote:
> > 
> > --- a/libavutil/fifo.h
> > +++ b/libavutil/fifo.h
> > @@ -106,11 +107,34 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int 
> > size);
> >  
> > +/**
> > + * Return a pointer to the data stored in a FIFO buffer at a certain 
> > offset.
> > + * The FIFO buffer is not modified.
> > + *
> > + * @param f pointer to the FIFO buffer to peek at, must be non-NULL
> 
> So every caller must check for NULL?

Yes, this is consistent with the rest of the av_fifo_* API, and most
part of libav*, so I don't know if it is a good idea to add a NULL
check here.

> > + * @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
> 
> How would the caller know the used buffer size?

Added a note about av_fifo_size().
 
> Vertical alignment would help make this more readable.

Updated.
>From d5b9a012308a766de5ef27ec1c7f4a431bd50f13 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini <[email protected]>
Date: Wed, 29 Jun 2011 17:30:23 +0200
Subject: [PATCH] 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.
---
 doc/APIchanges      |    3 +++
 libavformat/dvenc.c |    4 ++--
 libavutil/avutil.h  |    3 +++
 libavutil/fifo.h    |   31 ++++++++++++++++++++++++++++---
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c533818..f7f604b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2011-07-XX - xxxxxx - lavu 52.X.0
+  Add av_fifo_peek2(), deprecate av_fifo_peek().
+
 2011-07-10 - a67c061 - lavf 53.3.0
   Add avformat_find_stream_info(), deprecate av_find_stream_info().
 
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 5aab683..d1cca9e 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -192,8 +192,8 @@ static void dv_inject_audio(DVMuxContext *c, int channel, uint8_t* frame_ptr)
                 if (of*2 >= size)
                     continue;
 
-                frame_ptr[d]   = av_fifo_peek(c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit
-                frame_ptr[d+1] = av_fifo_peek(c->audio_data[channel], of*2);   //        that DV is a big-endian PCM
+                frame_ptr[d]   = *av_fifo_peek2(c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit
+                frame_ptr[d+1] = *av_fifo_peek2(c->audio_data[channel], of*2);   //        that DV is a big-endian PCM
             }
             frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
         }
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 01e4e2f..dd75b8d 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -63,6 +63,9 @@
 #ifndef FF_API_FIND_OPT
 #define FF_API_FIND_OPT                 (LIBAVUTIL_VERSION_MAJOR < 52)
 #endif
+#ifndef FF_API_AV_FIFO_PEEK
+#define FF_API_AV_FIFO_PEEK             (LIBAVUTIL_VERSION_MAJOR < 52)
+#endif
 
 /**
  * Return the LIBAVUTIL_VERSION_INT constant.
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index cd361b0..771ce3e 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 */
-- 
1.7.2.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to