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 <stefano.sabatini-l...@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.

s/than the one by//

> --- 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.

> + * 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.

> + * @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;
  else if (ptr < f->buffer)
      ptr = f->end - ptr;
  return f->buffer + ptr % (f->end - f->buffer);

> --- 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.

> --- 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.

Diego
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to