diff options
author | Anton Khirnov <anton@khirnov.net> | 2022-01-11 21:38:49 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-02-07 00:31:23 +0100 |
commit | 93ed3755746227dee13f71605d9a9d2fab6d524c (patch) | |
tree | 25bd656ac801c328262a6b76a57e198daa55a174 /libavutil | |
parent | 14429f8fec231e1d6e0bfdb3f646e7461d11c736 (diff) |
lavu/tests/fifo: switch to the new API
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/tests/fifo.c | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c index a17d913233..579602ccf3 100644 --- a/libavutil/tests/fifo.c +++ b/libavutil/tests/fifo.c @@ -23,78 +23,73 @@ int main(void) { /* create a FIFO buffer */ - AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int)); + AVFifo *fifo = av_fifo_alloc2(13, sizeof(int), 0); int i, j, n, *p; /* fill data */ - for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++) - av_fifo_generic_write(fifo, &i, sizeof(int), NULL); + for (i = 0; av_fifo_can_write(fifo); i++) + av_fifo_write(fifo, &i, 1); /* peek_at at FIFO */ - n = av_fifo_size(fifo) / sizeof(int); + n = av_fifo_can_read(fifo); for (i = 0; i < n; i++) { - av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL); + av_fifo_peek(fifo, &j, 1, i); printf("%d: %d\n", i, j); } printf("\n"); /* generic peek at FIFO */ - n = av_fifo_size(fifo); - p = malloc(n); + n = av_fifo_can_read(fifo); + p = malloc(n * av_fifo_elem_size(fifo)); if (p == NULL) { fprintf(stderr, "failed to allocate memory.\n"); exit(1); } - (void) av_fifo_generic_peek(fifo, p, n, NULL); + (void) av_fifo_peek(fifo, p, n, 0); /* read data at p */ - n /= sizeof(int); for(i = 0; i < n; ++i) printf("%d: %d\n", i, p[i]); putchar('\n'); /* read data */ - for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) { - av_fifo_generic_read(fifo, &j, sizeof(int), NULL); + for (i = 0; av_fifo_can_read(fifo); i++) { + av_fifo_read(fifo, &j, 1); printf("%d ", j); } printf("\n"); - /* test *ndx overflow */ - av_fifo_reset(fifo); - fifo->rndx = fifo->wndx = ~(uint32_t)0 - 5; - /* fill data */ - for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++) - av_fifo_generic_write(fifo, &i, sizeof(int), NULL); + for (i = 0; av_fifo_can_write(fifo); i++) + av_fifo_write(fifo, &i, 1); /* peek_at at FIFO */ - n = av_fifo_size(fifo) / sizeof(int); + n = av_fifo_can_read(fifo); for (i = 0; i < n; i++) { - av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL); + av_fifo_peek(fifo, &j, 1, i); printf("%d: %d\n", i, j); } putchar('\n'); /* test fifo_grow */ - (void) av_fifo_grow(fifo, 15 * sizeof(int)); + (void) av_fifo_grow2(fifo, 15); /* fill data */ - n = av_fifo_size(fifo) / sizeof(int); - for (i = n; av_fifo_space(fifo) >= sizeof(int); ++i) - av_fifo_generic_write(fifo, &i, sizeof(int), NULL); + n = av_fifo_can_read(fifo); + for (i = n; av_fifo_can_write(fifo); ++i) + av_fifo_write(fifo, &i, 1); /* peek_at at FIFO */ - n = av_fifo_size(fifo) / sizeof(int); + n = av_fifo_can_read(fifo); for (i = 0; i < n; i++) { - av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL); + av_fifo_peek(fifo, &j, 1, i); printf("%d: %d\n", i, j); } - av_fifo_free(fifo); + av_fifo_freep2(&fifo); free(p); return 0; |