On date Thursday 2011-06-30 10:59:12 +0200, Diego Biurrun encoded:
> On Thu, Jun 30, 2011 at 10:11:04AM +0200, Stefano Sabatini wrote:
> > The new functions provides a more generic interface than
>
> s/functions/function/
>
> > av_fifo_peek2() for peeking data out of a fifo buffer.
>
> s/fifo/FIFO/
>
> > --- a/libavutil/fifo.h
> > +++ b/libavutil/fifo.h
> > @@ -113,4 +113,17 @@ static inline uint8_t av_fifo_peek(AVFifoBuffer *f,
> > int offs)
> > +
> > +/**
> > + * Return a pointer to the data offset by offs stored in the fifo,
> > + * without modifying the fifo itself.
> > + */
>
> FIFO
Fixed.
> Neither the parameters, nor the return value have (Doxygen) documentation.
The return value is documented in the brief.
> But there is interesting stuff that you could document there, namely
> that a NULL pointer will make this function crash.
Yes fixed.
>
> > +static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
>
> const AVFifoBuffer * const f, const int offs would be even more
> const-correct.
Don't know, offs should not necessarily be const as it is passed per
value, * const f looks a bit overkill, unless you have reasons for
keeping that (e.g. avoiding potential warnings).
> > + uint8_t *ptr = f->rptr + offs;
> > + if (ptr >= f->end)
> > + ptr -= f->end - f->buffer;
> > + return ptr;
>
> To me this looks like you can still end up outside the FIFO if the
> offset is larger than two times the FIFO size.
Indeed, fixed the logic (which was copypasted from av_fifo_peek()).
--
Neglect of duty does not cease, by repetition, to be neglect of duty.
-- Napoleon
>From 8388c50d94084ca3a795b8f7e1cc364f47789010 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.
---
libavutil/fifo.h | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 999d0bf..ed09e4e 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -106,11 +106,29 @@ 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 offset by offs stored in a FIFO
+ * buffer, without modifying the FIFO buffer itself.
+ *
+ * @param 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->end - f->buffer;
- return *ptr;
+ ptr = f->buffer + (ptr - f->end) % (f->end - f->buffer);
+ else if (ptr < f->buffer)
+ ptr = f->end - (f->buffer - ptr) % (f->end - f->buffer);
+ return ptr;
}
+
+/**
+ * @see av_fifo_peek2()
+ */
+static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
+{
+ return *(uint8_t *)av_fifo_peek2(f, offs);
+}
+
#endif /* AVUTIL_FIFO_H */
--
1.7.2.5
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel