diff mbox series

[FFmpeg-devel,v2,05/31] lavu/tests/fifo: switch to the new API

Message ID AM7PR03MB6660842B30E6A90A3C4113418F5E9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 93ed3755746227dee13f71605d9a9d2fab6d524c
Headers show
Series New FIFO API | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 24, 2022, 2:45 p.m. UTC
From: Anton Khirnov <anton@khirnov.net>

---
 libavutil/tests/fifo.c | 47 +++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 26 deletions(-)
diff mbox series

Patch

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;