diff options
author | Nicolas Dato <nicolas.dato@gmail.com> | 2025-07-19 22:53:49 -0300 |
---|---|---|
committer | Nicolas Dato <nicolas.dato@gmail.com> | 2025-07-19 22:53:49 -0300 |
commit | 5c271cdae60c9711fb100a544d2b014a777c3408 (patch) | |
tree | a6757ade4f9f00ee7419f4a5d7479eba6a660b88 | |
parent | 7b71892626c8bcb034562deef274a5762bb1c014 (diff) | |
download | libtuberia-5c271cdae60c9711fb100a544d2b014a777c3408.tar.gz |
adding a simple example
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 66 | ||||
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | example/Makefile.am | 13 | ||||
-rw-r--r-- | example/simple.c | 57 | ||||
-rw-r--r-- | src/tuberia.h | 74 |
6 files changed, 207 insertions, 14 deletions
@@ -30,6 +30,7 @@ doc/Doxyfile doc/doxygen_man doc/doxygen_html doc/doxygen_html.tar +example/simple example/decode_resize_encode install-sh libtool @@ -15,19 +15,29 @@ pipeline ## Building, Compiling, Installing If you don't have a ./configure file, run: + - `autoreconf -fi` When you have the ./configure file, run: + - `./configure` - `make` - `make install` You can see some configuration options with: + - `./configure --help` +## Using this library + +Include tuberia.h, and link libtuberia.a and pthread: `-ltuberia -lpthread` + +You can also use: `pkg-config --cflags --libs --static tuberia` + ## Quick Guide -See the `example/decode_resize_encode.c` and the function `do_tuberia()` +See the files `example/simple.c` and `example/decode_resize_encode.c` +(function `do_tuberia()` in particular) Create a source with `tube_source_alloc()`. If you set fetch to something, there will be a thread running fetch to inject @@ -52,7 +62,59 @@ Free the pipeline with `tube_free()`. ### Quick example -```C +See `examples/simple.c` + +Compile with: `gcc -o simple simple.c -ltuberia -lpthread` + +Or with: ``gcc -o simple simple.c `pkg-config --cflags --libs --static tuberia``` + +```C +#include <stdio.h> +#include <stdlib.h> +#include <tuberia.h> + +void *stage_one(void *element, void *opaque) +{ + int *i = element; + *i += 5; + return i; +} + +void *stage_two(void *element, void *opaque) +{ + int *i = element; + *i *= 10; + return i; +} + +void sink(void *element, void *opaque) +{ + int *i = element; + printf("sink: %d\n", *i); + free(i); +} + +int main(void) +{ + tube *ctx; + tube_source *source; + int *element, n; + + source = tube_source_alloc(2, NULL, NULL, free); + tube_stage_append(source, tube_stage_alloc(2, stage_one, NULL, free)); + tube_stage_append(source, tube_stage_alloc(2, stage_two, NULL, free)); + ctx = tube_alloc(source, sink, NULL); + tube_source_and_stages_free(&source); + tube_start(ctx); + while (scanf("%d", &n) == 1) { + element = malloc(sizeof(*element)); + *element = n; + tube_inject(ctx, 1000, element); + } + tube_free(&ctx); + + return 0; +} ``` diff --git a/configure.ac b/configure.ac index 28b21db..b6259ed 100644 --- a/configure.ac +++ b/configure.ac @@ -49,14 +49,15 @@ AC_ARG_ENABLE([tuberia-test], AS_HELP_STRING([--disable-tuberia-test], [Disable AS_VAR_IF([has_doxygen], [no], [AS_VAR_SET([enable_doxygen], [no])], []) AS_VAR_IF([has_valgrind], [no], [AS_VAR_SET([enable_valgrind], [no])], []) -AS_VAR_IF([has_avcodec], [no], [AS_VAR_SET([enable_examples], [no])], []) -AS_VAR_IF([has_avformat], [no], [AS_VAR_SET([enable_examples], [no])], []) -AS_VAR_IF([has_avutil], [no], [AS_VAR_SET([enable_examples], [no])], []) -AS_VAR_IF([has_swscale], [no], [AS_VAR_SET([enable_examples], [no])], []) +AS_VAR_IF([has_avcodec], [no], [AS_VAR_SET([has_ffmpeg], [no])], []) +AS_VAR_IF([has_avformat], [no], [AS_VAR_SET([has_ffmpeg], [no])], []) +AS_VAR_IF([has_avutil], [no], [AS_VAR_SET([has_ffmpeg], [no])], []) +AS_VAR_IF([has_swscale], [no], [AS_VAR_SET([has_ffmpeg], [no])], []) AM_CONDITIONAL([DOXYGEN], [test x$enable_doxygen = xyes]) AM_CONDITIONAL([VALGRIND], [test x$enable_valgrind = xyes]) AM_CONDITIONAL([EXAMPLES], [test x$enable_examples = xyes]) +AM_CONDITIONAL([HAS_FFMPEG], [test x$has_ffmpeg = xyes]) AM_CONDITIONAL([TESTS], [test x$enable_tests = xyes]) AM_CONDITIONAL([ITCTEST], [test x$enable_itc_test = xyes]) AM_CONDITIONAL([TUBERIATEST], [test x$enable_tuberia_test = xyes]) @@ -76,6 +77,7 @@ AC_MSG_NOTICE([has avcodec: $has_avcodec]) AC_MSG_NOTICE([has avformat: $has_avformat]) AC_MSG_NOTICE([has avutil: $has_avutil]) AC_MSG_NOTICE([has swscale: $has_swscale]) +AC_MSG_NOTICE([has ffmpeg: $has_ffmpeg]) AC_MSG_NOTICE([enable doxygen: $enable_doxygen]) AC_MSG_NOTICE([enable valgrind: $enable_valgrind]) AC_MSG_NOTICE([enable examples: $enable_examples]) diff --git a/example/Makefile.am b/example/Makefile.am index a30c12e..fc520f7 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,12 +1,21 @@ if EXAMPLES -noinst_PROGRAMS = decode_resize_encode +noinst_PROGRAMS = simple +simple_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/../src +simple_LDADD = ../src/libtuberia.a +simple_LDFLAGS = -lpthread +simple_SOURCES = simple.c + +if HAS_FFMPEG +noinst_PROGRAMS += decode_resize_encode decode_resize_encode_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/../src decode_resize_encode_LDADD = ../src/libtuberia.a decode_resize_encode_LDFLAGS = -lpthread -lavcodec -lavformat -lavutil -lswscale decode_resize_encode_SOURCES = decode_resize_encode.c endif +endif + exampledir = $(docdir)/example -example_DATA = decode_resize_encode.c +example_DATA = simple.c decode_resize_encode.c diff --git a/example/simple.c b/example/simple.c new file mode 100644 index 0000000..3d4df1a --- /dev/null +++ b/example/simple.c @@ -0,0 +1,57 @@ +/* + * Compile with + * gcc -o simple simple.c -ltuberia -lpthread + * or + * gcc -o simple simple.c `pkg-config --cflags --libs --static tuberia` + */ + +#include <stdio.h> +#include <stdlib.h> +#include <tuberia.h> + +void *stage_one(void *element, void *opaque) +{ + (void)opaque; + int *i = element; + *i += 5; + return i; +} + +void *stage_two(void *element, void *opaque) +{ + (void)opaque; + int *i = element; + *i *= 10; + return i; +} + +void sink(void *element, void *opaque) +{ + (void)opaque; + int *i = element; + printf("sink: %d\n", *i); + free(i); +} + +int main(void) +{ + tube *ctx; + tube_source *source; + int *element, n; + + source = tube_source_alloc(2, NULL, NULL, free); + tube_stage_append(source, tube_stage_alloc(2, stage_one, NULL, free)); + tube_stage_append(source, tube_stage_alloc(2, stage_two, NULL, free)); + ctx = tube_alloc(source, sink, NULL); + tube_source_and_stages_free(&source); + tube_start(ctx); + while (scanf("%d", &n) == 1) { + element = malloc(sizeof(*element)); + *element = n; + tube_inject(ctx, 1000, element); + } + tube_free(&ctx); + + return 0; +} + diff --git a/src/tuberia.h b/src/tuberia.h index f9746b2..2a25287 100644 --- a/src/tuberia.h +++ b/src/tuberia.h @@ -22,19 +22,26 @@ * @section building Building * * If you don't have a ./configure file, run: - * - autoreconf -fi + * - `autoreconf -fi` * * When you have the ./configure file, run: - * - ./configure - * - make - * - make install + * - `./configure` + * - `make` + * - `make install` * * You can see some configure options with - * - ./configure --help + * - `./configure --help` + * + * @section using Using this library + * + * Include tuberia.h, and link libtuberia.a and pthread: `-ltuberia -lpthread` + * + * You can use: `pkg-config --cflags --libs --static tuberia` * * @section quick_guide Quick Guide * - * See the example/decode_resize_encode.c and the function do_tuberia() + * See the files example/simple.c and example/decode_resize_encode.c (function + * do_tuberia() in particular) * * Create a source with @ref tube_source_alloc(). * If you set fetch to something, there will be a thread running fetch to inject @@ -58,6 +65,61 @@ * Free the pipeline with @ref tube_free(). * * @subsection quick_example Example + * + * See example/simple.c + * + * Compile with: `gcc -o simple simple.c -ltuberia -lpthread` + * + * Or with: ``gcc -o simple simple.c `pkg-config --cflags --libs --static tuberia``` + * +@code {.c} +#include <stdio.h> +#include <stdlib.h> +#include <tuberia.h> + +void *stage_one(void *element, void *opaque) +{ + int *i = element; + *i += 5; + return i; +} + +void *stage_two(void *element, void *opaque) +{ + int *i = element; + *i *= 10; + return i; +} + +void sink(void *element, void *opaque) +{ + int *i = element; + printf("sink: %d\n", *i); + free(i); +} + +int main(void) +{ + tube *ctx; + tube_source *source; + int *element, n; + + source = tube_source_alloc(2, NULL, NULL, free); + tube_stage_append(source, tube_stage_alloc(2, stage_one, NULL, free)); + tube_stage_append(source, tube_stage_alloc(2, stage_two, NULL, free)); + ctx = tube_alloc(source, sink, NULL); + tube_source_and_stages_free(&source); + tube_start(ctx); + while (scanf("%d", &n) == 1) { + element = malloc(sizeof(*element)); + *element = n; + tube_inject(ctx, 1000, element); + } + tube_free(&ctx); + + return 0; +} +@endcode */ /** |