On date Thursday 2011-07-21 19:45:15 +0200, Stefano Sabatini encoded:
> On date Saturday 2011-07-16 17:15:27 +0200, Stefano Sabatini encoded:
> > 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.

Updated.
>From fb89e1bbcaeb2d979a299e2f7f558d930169ead4 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 09a12fe..9c620cd 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2011-08-xx - xxxxxx - lavu 52.x.0
+  Add av_fifo_peek2(), deprecate av_fifo_peek().
+
 2011-08-02 - 9d39cbf - lavc 53.7.1
   Add AV_PKT_FLAG_CORRUPT AVPacket flag.
 
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 15b659b..5c55338 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

>From 595917fe2a2e14613ce85d389a4792d09f7aa749 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini <[email protected]>
Date: Sat, 16 Jul 2011 09:49:42 +0200
Subject: [PATCH] fifo: add FIFO API test program, and fate test

---
 libavutil/Makefile       |    2 +-
 libavutil/fifo.c         |   36 ++++++++++++++++++++++++++++++++++++
 tests/fate/libavutil.mak |    4 ++++
 tests/ref/fate/fifo      |   27 +++++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 1 deletions(-)
 create mode 100644 tests/ref/fate/fifo

diff --git a/libavutil/Makefile b/libavutil/Makefile
index cfe7bae..bded2c6 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -75,7 +75,7 @@ OBJS-$(ARCH_ARM) += arm/cpu.o
 OBJS-$(ARCH_PPC) += ppc/cpu.o
 OBJS-$(ARCH_X86) += x86/cpu.o
 
-TESTPROGS = adler32 aes avstring base64 cpu crc des eval file lfg lls \
+TESTPROGS = adler32 aes avstring base64 cpu crc des eval file fifo lfg lls \
             md5 opt parseutils rational sha tree
 TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
 
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index f87a99d..5774d33 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -127,3 +127,39 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
         f->rptr -= f->end - f->buffer;
     f->rndx += size;
 }
+
+#ifdef TEST
+
+#undef printf
+
+int main(void)
+{
+    /* create a FIFO buffer */
+    AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
+    int i, j, n;
+
+    /* fill data */
+    for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
+        av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+
+    /* peek at FIFO */
+    n = av_fifo_size(fifo)/sizeof(int);
+    for (i = -n+1; i < n; i++) {
+        int *v = (int *)av_fifo_peek2(fifo, i*sizeof(int));
+        printf("%d: %d\n", i, *v);
+    }
+    printf("\n");
+
+    /* read data */
+    for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
+        av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
+        printf("%d ", j);
+    }
+    printf("\n");
+
+    av_fifo_free(fifo);
+
+    return 0;
+}
+
+#endif
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 4299f08..a65b724 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -25,6 +25,10 @@ FATE_TESTS += fate-eval
 fate-eval: libavutil/eval-test$(EXESUF)
 fate-eval: CMD = run libavutil/eval-test
 
+FATE_TESTS += fate-fifo
+fate-fifo: libavutil/fifo-test$(EXESUF)
+fate-fifo: CMD = run libavutil/fifo-test
+
 FATE_TESTS += fate-md5
 fate-md5: libavutil/md5-test$(EXESUF)
 fate-md5: CMD = run libavutil/md5-test
diff --git a/tests/ref/fate/fifo b/tests/ref/fate/fifo
new file mode 100644
index 0000000..2c076c1
--- /dev/null
+++ b/tests/ref/fate/fifo
@@ -0,0 +1,27 @@
+-12: 1
+-11: 2
+-10: 3
+-9: 4
+-8: 5
+-7: 6
+-6: 7
+-5: 8
+-4: 9
+-3: 10
+-2: 11
+-1: 12
+0: 0
+1: 1
+2: 2
+3: 3
+4: 4
+5: 5
+6: 6
+7: 7
+8: 8
+9: 9
+10: 10
+11: 11
+12: 12
+
+0 1 2 3 4 5 6 7 8 9 10 11 12 
-- 
1.7.2.5

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

Reply via email to