From 49cec1998af4c8806f4981d12daa28091ccb0425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Axelsson?= Date: Wed, 9 Apr 2008 11:35:16 +0000 Subject: [PATCH] =?UTF-8?q?Add=20a=20generic=20write=20function=20to=20av?= =?UTF-8?q?=5Ffifo.=20Patch=20by=20Bj=C3=B6rn=20Axelsson:=20bjorn=20axelss?= =?UTF-8?q?on=20intinor=20se=20Original=20thread:=20[FFmpeg-devel]=20[RFC]?= =?UTF-8?q?[PATCH]=20av=5Ffifo=5Fwrite=5Ffrom=5Fbytestream()=20Date:=2004/?= =?UTF-8?q?03/2008=2012:14=20PM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Originally committed as revision 12773 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavutil/fifo.c | 14 +++++++++++++- libavutil/fifo.h | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/libavutil/fifo.c b/libavutil/fifo.c index 8ac3a0cb55..08b5977a1a 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -73,15 +73,27 @@ void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) { 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; } diff --git a/libavutil/fifo.h b/libavutil/fifo.h index 817a8a6b61..fccb322dbf 100644 --- a/libavutil/fifo.h +++ b/libavutil/fifo.h @@ -76,7 +76,21 @@ int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void * @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)); /** * Resizes an AVFifoBuffer.