--- libavutil/fifo.c | 37 +++++++++++++++++++++++++++++++++++++ libavutil/fifo.h | 11 +++++++++++ tests/ref/fate/fifo | 14 ++++++++++++++ 3 files changed, 62 insertions(+)
diff --git a/libavutil/fifo.c b/libavutil/fifo.c index 07fb4ec..cabb009 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -148,6 +148,35 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, return total - size; } +int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, int offset, int buf_size, void (*func)(void*, void*, int)) +{ + uint8_t *rptr = f->rptr + offset; + uint32_t rndx = f->rndx + offset; + + av_assert2(offset >= 0); + while (buf_size > 0) { + int len; + + if (rptr >= f->end) + rptr -= f->end - f->buffer; + + av_assert2(rndx < f->wndx); + len = FFMIN(f->end - rptr, buf_size); + if (func) + func(dest, rptr, len); + else { + memcpy(dest, rptr, len); + dest = (uint8_t *)dest + len; + } + + buf_size -= len; + rptr += len; + rndx += len; + } + + return 0; +} + int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void *, void *, int)) { @@ -223,6 +252,14 @@ int main(void) } printf("\n"); + /* peek_at at FIFO */ + n = av_fifo_size(fifo) / sizeof(int); + for (i = 0; i < n; i++) { + av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL); + printf("%d: %d\n", i, j); + } + printf("\n"); + /* read data */ for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) { av_fifo_generic_read(fifo, &j, sizeof(int), NULL); diff --git a/libavutil/fifo.h b/libavutil/fifo.h index 0e4070b..dc7bc6f 100644 --- a/libavutil/fifo.h +++ b/libavutil/fifo.h @@ -84,6 +84,17 @@ int av_fifo_size(const AVFifoBuffer *f); int av_fifo_space(const AVFifoBuffer *f); /** + * Feed data at specific position from an AVFifoBuffer to a user-supplied callback. + * Similar as av_fifo_gereric_read but without discarding data. + * @param f AVFifoBuffer to read from + * @param offset offset from current read position + * @param buf_size number of bytes to read + * @param func generic read function + * @param dest data destination + */ +int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, int offset, int buf_size, void (*func)(void*, void*, int)); + +/** * Feed data from an AVFifoBuffer to a user-supplied callback. * Similar as av_fifo_gereric_read but without discarding data. * @param f AVFifoBuffer to read from diff --git a/tests/ref/fate/fifo b/tests/ref/fate/fifo index 18a5691..5a59c5a 100644 --- a/tests/ref/fate/fifo +++ b/tests/ref/fate/fifo @@ -24,4 +24,18 @@ 11: 11 12: 12 +0: 0 +1: 1 +2: 2 +3: 3 +4: 4 +5: 5 +6: 6 +7: 7 +8: 8 +9: 9 +10: 10 +11: 11 +12: 12 + 0 1 2 3 4 5 6 7 8 9 10 11 12 -- 2.5.3 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel