Originally committed as revision 12773 to svn://svn.ffmpeg.org/ffmpeg/trunk
Björn Axelsson authored on 2008/04/09 20:35:16... | ... |
@@ -73,15 +73,27 @@ void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) { |
73 | 73 |
|
74 | 74 |
void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size) |
75 | 75 |
{ |
76 |
+ av_fifo_generic_write(f, (void *)buf, size, NULL); |
|
77 |
+} |
|
78 |
+ |
|
79 |
+int av_fifo_generic_write(AVFifoBuffer *f, void *buf, int size, int (*func)(void*, void*, int)) |
|
80 |
+{ |
|
81 |
+ int total = size; |
|
76 | 82 |
do { |
77 | 83 |
int len = FFMIN(f->end - f->wptr, size); |
84 |
+ if(func) { |
|
85 |
+ if(func(buf, f->wptr, len) <= 0) |
|
86 |
+ break; |
|
87 |
+ } else { |
|
78 | 88 |
memcpy(f->wptr, buf, len); |
89 |
+ buf = (uint8_t*)buf + len; |
|
90 |
+ } |
|
79 | 91 |
f->wptr += len; |
80 | 92 |
if (f->wptr >= f->end) |
81 | 93 |
f->wptr = f->buffer; |
82 |
- buf += len; |
|
83 | 94 |
size -= len; |
84 | 95 |
} while (size > 0); |
96 |
+ return total - size; |
|
85 | 97 |
} |
86 | 98 |
|
87 | 99 |
|
... | ... |
@@ -76,7 +76,21 @@ int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void |
76 | 76 |
* @param *buf data source |
77 | 77 |
* @param size data size |
78 | 78 |
*/ |
79 |
-void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size); |
|
79 |
+attribute_deprecated void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size); |
|
80 |
+ |
|
81 |
+/** |
|
82 |
+ * Feeds data from a user supplied callback to an AVFifoBuffer. |
|
83 |
+ * @param *f AVFifoBuffer to write to |
|
84 |
+ * @param *buf data source |
|
85 |
+ * @param size number of bytes to write |
|
86 |
+ * @param *func generic write function. First parameter is buf, |
|
87 |
+ * second is dest_buf, third is dest_buf_size. |
|
88 |
+ * func must return the number of bytes written to dest_buf, or <= 0 to |
|
89 |
+ * indicate no more data available to write. |
|
90 |
+ * If func is NULL, buf is interpreted as a simple byte array for source data. |
|
91 |
+ * @return the number of bytes written to the fifo. |
|
92 |
+ */ |
|
93 |
+int av_fifo_generic_write(AVFifoBuffer *f, void *buf, int size, int (*func)(void*, void*, int)); |
|
80 | 94 |
|
81 | 95 |
/** |
82 | 96 |
* Resizes an AVFifoBuffer. |