return 0;
}
- // src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter)
- int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))
+int av_fifo_grow(AVFifoBuffer *f, unsigned int size)
+{
+ unsigned int old_size = f->end - f->buffer;
+ if(size + (unsigned)av_fifo_size(f) < size)
+ return AVERROR(EINVAL);
+
+ size += av_fifo_size(f);
+
+ if (old_size < size)
+ return av_fifo_realloc2(f, FFMAX(size, 2*size));
+ return 0;
+}
+
+ /* src must NOT be const as it can be a context for func that may need
+ * updating (like a pointer or byte counter) */
+ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size,
+ int (*func)(void *, void *, int))
{
int total = size;
+ uint32_t wndx= f->wndx;
+ uint8_t *wptr= f->wptr;
+
do {
- int len = FFMIN(f->end - f->wptr, size);
+ int len = FFMIN(f->end - wptr, size);
if (func) {
- if (func(src, f->wptr, len) <= 0)
+ if (func(src, wptr, len) <= 0)
break;
} else {
- memcpy(f->wptr, src, len);
+ memcpy(wptr, src, len);
- src = (uint8_t*)src + len;
+ src = (uint8_t *)src + len;
}
// Write memory barrier needed for SMP here in theory
- f->wptr += len;
- if (f->wptr >= f->end)
- f->wptr = f->buffer;
- f->wndx += len;
+ wptr += len;
+ if (wptr >= f->end)
+ wptr = f->buffer;
- wndx += len;
- size -= len;
++ wndx += len;
+ size -= len;
} while (size > 0);
+ f->wndx= wndx;
+ f->wptr= wptr;
return total - size;
}