|
|
|
@ -17,14 +17,14 @@ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include "libavutil/fifo.h" |
|
|
|
|
|
|
|
|
|
int main(void) |
|
|
|
|
{ |
|
|
|
|
/* create a FIFO buffer */ |
|
|
|
|
AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int)); |
|
|
|
|
int i, j, n; |
|
|
|
|
int i, j, n, *p; |
|
|
|
|
|
|
|
|
|
/* fill data */ |
|
|
|
|
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++) |
|
|
|
@ -46,6 +46,24 @@ int main(void) |
|
|
|
|
} |
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
/* generic peek at FIFO */ |
|
|
|
|
|
|
|
|
|
n = av_fifo_size(fifo); |
|
|
|
|
p = malloc(n); |
|
|
|
|
if (p == NULL) { |
|
|
|
|
fprintf(stderr, "failed to allocate memory.\n"); |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
(void) av_fifo_generic_peek(fifo, p, n, NULL); |
|
|
|
|
|
|
|
|
|
/* 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); |
|
|
|
@ -61,6 +79,22 @@ int main(void) |
|
|
|
|
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++) |
|
|
|
|
av_fifo_generic_write(fifo, &i, sizeof(int), NULL); |
|
|
|
|
|
|
|
|
|
/* 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); |
|
|
|
|
} |
|
|
|
|
putchar('\n'); |
|
|
|
|
|
|
|
|
|
/* test fifo_grow */ |
|
|
|
|
(void) av_fifo_grow(fifo, 15 * sizeof(int)); |
|
|
|
|
|
|
|
|
|
/* 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); |
|
|
|
|
|
|
|
|
|
/* peek_at at FIFO */ |
|
|
|
|
n = av_fifo_size(fifo) / sizeof(int); |
|
|
|
|
for (i = 0; i < n; i++) { |
|
|
|
@ -69,6 +103,7 @@ int main(void) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
av_fifo_free(fifo); |
|
|
|
|
free(p); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|