On date Monday 2011-07-04 16:42:04 +0200, Diego Biurrun encoded:
> On Mon, Jul 04, 2011 at 04:13:31PM +0200, Stefano Sabatini wrote:
> >
> > Updated with changes:
> >
> > * extended documentation, clarify the meaning of offs and of the returned
> > pointer
> > * fix a bug (tested this time)
> > * keep unchanged the av_fifo_peek() code for avoiding performance
> > regressions
> >
> > >From 0e9763f0dc6f0ca5de4de3f055a37c566c755cb4 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()
> >
> > The new function provides a more generic interface than the one of by
> > av_fifo_peek() for peeking at a FIFO buffer data.
>
> s/than the one by//
Fixed (at least I hope).
> > --- a/libavutil/fifo.h
> > +++ b/libavutil/fifo.h
> > @@ -113,4 +113,25 @@ static inline uint8_t av_fifo_peek(AVFifoBuffer *f,
> > int offs)
> > +
> > +/**
> > + * Return a pointer to the data offset by offs stored in a FIFO
> > + * buffer. The FIFO buffer is not modified.
>
> Return a pointer to the data stored in a FIFO buffer at a certain offset.
> The FIFO buffer is not modified.
Changed.
> > + * The FIFO buffer is treated like a circular buffer, so the returned
> > + * value always points to the allocated buffer area.
> > + *
> > + * @param pointer to the the FIFO buffer to peek at, must be non-NULL
>
> f
>
> This should have generated a new doxygen warning.
Fixed.
> > + * @param offs an offset in bytes
> > + */
> > +static inline 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) % (f->end - f->buffer);
> > + else if (ptr < f->buffer)
> > + ptr = f->buffer + (f->end - ptr) % (f->end - f->buffer);
> > + return ptr;
>
> alternative:
>
> uint8_t *ptr = f->rptr + offs;
> if (ptr >= f->end)
> ptr = ptr - f->end;
uhm this requires a cast (ptr - ptr => int)
> else if (ptr < f->buffer)
> ptr = f->end - ptr;
> return f->buffer + ptr % (f->end - f->buffer);
I kept the old version here for avoiding ugly casts and avoid
obfuscating temporaries.
>
> > --- a/libavutil/Makefile
> > +++ b/libavutil/Makefile
> > @@ -77,7 +77,7 @@ OBJS-$(ARCH_ARM) += arm/cpu.o
> >
> > -TESTPROGS = adler32 aes base64 cpu crc des eval lls md5 pca sha tree
> > +TESTPROGS = adler32 aes base64 cpu crc des eval fifo lls md5 pca sha tree
> > TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
>
> Nowadays making FATE tests out of these is all the rage.
Uh.. fate test added.
> > --- a/libavutil/fifo.c
> > +++ b/libavutil/fifo.c
> > @@ -127,3 +127,35 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
> > +
> > +#ifdef TEST
> > +
> > +#undef printf
> > +
> > +int main(void)
> > +{
> > + /* create a fifo buffer */
>
> FIFO
>
> > + /* peek at fifo */
>
> FIFO
>
> > + for (i = -50; i < 50; i++) {
> > + int *v = (int *)av_fifo_peek2(fifo, i*sizeof(int *));
> > + printf("%d: %d\n", i, *v);
>
> This can be done without an ugly cast.
Uhm, this fixes a warning here.
--
Sir, it's very possible this asteroid is not stable.
-- C3P0
>From 2ec24f2f0c79414edfd558f3c55b7d7969018912 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()
The new function provides a more generic interface than av_fifo_peek()
for peeking at a FIFO buffer data.
---
libavutil/fifo.h | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 999d0bf..0df841c 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -113,4 +113,25 @@ static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
ptr -= f->end - f->buffer;
return *ptr;
}
+
+/**
+ * Return a pointer to the data stored in a FIFO buffer at a certain offset.
+ * The FIFO buffer is not modified.
+ *
+ * The FIFO buffer is treated like a circular buffer, so the returned
+ * value always points to the buffer area.
+ *
+ * @param f pointer to the the FIFO buffer to peek at, must be non-NULL
+ * @param offs an offset in bytes
+ */
+static inline 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) % (f->end - f->buffer);
+ else if (ptr < f->buffer)
+ ptr = f->buffer + (f->end - ptr) % (f->end - f->buffer);
+ return ptr;
+}
+
#endif /* AVUTIL_FIFO_H */
--
1.7.2.5
>From 6d84c9eeed8727ad6a16f4190607fc0f780db0e0 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini <[email protected]>
Date: Mon, 4 Jul 2011 15:37:01 +0200
Subject: [PATCH] fifo: add fifo API test program, and fate test
---
libavutil/Makefile | 2 +-
libavutil/fifo.c | 32 ++++++++++++++
tests/fate/libavutil.mak | 4 ++
tests/ref/fate/fifo | 101 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 138 insertions(+), 1 deletions(-)
create mode 100644 tests/ref/fate/fifo
diff --git a/libavutil/Makefile b/libavutil/Makefile
index ad2a3ee..fd60eb2 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -77,7 +77,7 @@ OBJS-$(ARCH_ARM) += arm/cpu.o
OBJS-$(ARCH_PPC) += ppc/cpu.o
OBJS-$(ARCH_X86) += x86/cpu.o
-TESTPROGS = adler32 aes base64 cpu crc des eval lls md5 pca sha tree
+TESTPROGS = adler32 aes base64 cpu crc des eval fifo lls md5 pca sha tree
TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
DIRS = arm bfin sh4 x86
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index d101989..dc29436 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -127,3 +127,35 @@ 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;
+
+ /* fill data */
+ for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
+ av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+
+ /* peek at FIFO */
+ for (i = -50; i < 50; i++) {
+ int *v = (int *)av_fifo_peek2(fifo, i*sizeof(int *));
+ printf("%d: %d\n", i, *v);
+ }
+
+ /* 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");
+
+ return 0;
+}
+
+#endif
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index d83ced8..61ebbaa 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -21,6 +21,10 @@ fate-des: libavutil/des-test$(EXESUF)
fate-des: CMD = run libavutil/des-test
fate-des: REF = /dev/null
+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..5767884
--- /dev/null
+++ b/tests/ref/fate/fifo
@@ -0,0 +1,101 @@
+-50: 11
+-49: 10
+-48: 9
+-47: 8
+-46: 7
+-45: 6
+-44: 5
+-43: 4
+-42: 3
+-41: 2
+-40: 1
+-39: 0
+-38: 12
+-37: 11
+-36: 10
+-35: 9
+-34: 8
+-33: 7
+-32: 6
+-31: 5
+-30: 4
+-29: 3
+-28: 2
+-27: 1
+-26: 0
+-25: 12
+-24: 11
+-23: 10
+-22: 9
+-21: 8
+-20: 7
+-19: 6
+-18: 5
+-17: 4
+-16: 3
+-15: 2
+-14: 1
+-13: 0
+-12: 12
+-11: 11
+-10: 10
+-9: 9
+-8: 8
+-7: 7
+-6: 6
+-5: 5
+-4: 4
+-3: 3
+-2: 2
+-1: 1
+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
+13: 0
+14: 1
+15: 2
+16: 3
+17: 4
+18: 5
+19: 6
+20: 7
+21: 8
+22: 9
+23: 10
+24: 11
+25: 12
+26: 0
+27: 1
+28: 2
+29: 3
+30: 4
+31: 5
+32: 6
+33: 7
+34: 8
+35: 9
+36: 10
+37: 11
+38: 12
+39: 0
+40: 1
+41: 2
+42: 3
+43: 4
+44: 5
+45: 6
+46: 7
+47: 8
+48: 9
+49: 10
+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