[FFmpeg-devel] [RFC][PATCH] av_fifo_write_from_bytestream()
Benoit Fouet
benoit.fouet
Wed Apr 9 08:40:14 CEST 2008
Hi,
Bj?rn Axelsson wrote:
> Index: libavutil/fifo.h
> ===================================================================
> --- libavutil/fifo.h.orig 2008-04-03 13:25:00.000000000 +0200
> +++ libavutil/fifo.h 2008-04-07 13:31:26.837042804 +0200
> @@ -76,7 +76,21 @@
> * @param *buf data source
> * @param size data size
> */
> -void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size);
> +attribute_deprecated void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size);
> +
> +/**
> + * Feeds data from a user supplied callback to an AVFifoBuffer.
> + * @param *f AVFifoBuffer to write to
> + * @param *buf data source
> + * @param size number of bytes to write
> + * @param *func generic write function. First parameter is buf,
> + * second is dest_buf, third is dest_buf_size.
> + * func must return the number of bytes written to dest_buf, or <= 0 to
> + * indicate no more data available to write.
> + * If func is NULL, buf is interpreted as a simple byte array for source data.
> + * @return the number of bytes written to the fifo.
> + */
> +int av_fifo_generic_write(AVFifoBuffer *f, void *buf, int size, int (*func)(void*, void*, int));
>
why is buf not const ? (same applies for the first argument of func)
> /**
> * Resizes an AVFifoBuffer.
> Index: libavutil/fifo.c
> ===================================================================
> --- libavutil/fifo.c.orig 2008-04-03 13:24:58.000000000 +0200
> +++ libavutil/fifo.c 2008-04-07 13:31:26.840042135 +0200
> @@ -73,15 +73,27 @@
>
> void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
> {
> + av_fifo_generic_write(f, (void *)buf, size, NULL);
> +}
> +
> +int av_fifo_generic_write(AVFifoBuffer *f, void *buf, int size, int (*func)(void*, void*, int))
> +{
> + int total = size;
> do {
> int len = FFMIN(f->end - f->wptr, size);
> + if(func) {
> + if(func(buf, f->wptr, len) <= 0)
> + break;
> + } else {
> memcpy(f->wptr, buf, len);
> + buf = (uint8_t*)buf + len;
> + }
> f->wptr += len;
> if (f->wptr >= f->end)
> f->wptr = f->buffer;
> - buf += len;
> size -= len;
> } while (size > 0);
> + return total - size;
> }
>
--
Benoit Fouet
Purple Labs S.A.
www.purplelabs.com
More information about the ffmpeg-devel
mailing list