[FFmpeg-devel] [libav-devel] [PATCH] fifo: add av_fifo_peek2()

Stefano Sabatini stefano.sabatini-lala at poste.it
Mon Jul 4 16:13:31 CEST 2011


On date Thursday 2011-06-30 14:56:37 +0200, Michael Niedermayer encoded:
> On Thu, Jun 30, 2011 at 12:41:55PM +0200, Stefano Sabatini wrote:
> > 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
> 
> >  fifo.h |   24 +++++++++++++++++++++---
> >  1 file changed, 21 insertions(+), 3 deletions(-)
> > 18713c5dbe8b3aa107e58aab73c828e5664cb307  0004-fifo-add-av_fifo_peek2.patch
> > From 8388c50d94084ca3a795b8f7e1cc364f47789010 Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > 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
> > + */
> 
> We also should say something about the validity of the returned ptr +1
> +2 ...

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

I'm also attaching a small test program, which I used for testing here
(not necessarily to be committed, just for showing the API usage). 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-fifo-add-av_fifo_peek2.patch
Type: text/x-diff
Size: 1419 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110704/b506bb2f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-fifo-add-fifo-API-test-program.patch
Type: text/x-diff
Size: 1785 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110704/b506bb2f/attachment-0001.bin>


More information about the ffmpeg-devel mailing list