Add a generic write function to av_fifo.
Patch by Björn Axelsson: bjorn axelsson intinor se Original thread: [FFmpeg-devel] [RFC][PATCH] av_fifo_write_from_bytestream() Date: 04/03/2008 12:14 PM Originally committed as revision 12773 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
96275520a3
commit
49cec1998a
@ -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)
|
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 {
|
do {
|
||||||
int len = FFMIN(f->end - f->wptr, size);
|
int len = FFMIN(f->end - f->wptr, size);
|
||||||
|
if(func) {
|
||||||
|
if(func(buf, f->wptr, len) <= 0)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
memcpy(f->wptr, buf, len);
|
memcpy(f->wptr, buf, len);
|
||||||
|
buf = (uint8_t*)buf + len;
|
||||||
|
}
|
||||||
f->wptr += len;
|
f->wptr += len;
|
||||||
if (f->wptr >= f->end)
|
if (f->wptr >= f->end)
|
||||||
f->wptr = f->buffer;
|
f->wptr = f->buffer;
|
||||||
buf += len;
|
|
||||||
size -= len;
|
size -= len;
|
||||||
} while (size > 0);
|
} while (size > 0);
|
||||||
|
return total - size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +76,21 @@ int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void
|
|||||||
* @param *buf data source
|
* @param *buf data source
|
||||||
* @param size data size
|
* @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.
|
* Resizes an AVFifoBuffer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user