From 4c629d77d9bd67e9861f578d89957b3cf1472aa8 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 5 Nov 2023 15:31:59 -0800 Subject: til_stream: add til_audio_context_t to til_stream_t Preliminary means of making the audio context available to modules. --- src/main.c | 2 +- src/til_stream.c | 22 +++++++++++++++++++++- src/til_stream.h | 4 +++- 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 70f83e2..daf1b24 100644 --- a/src/main.c +++ b/src/main.c @@ -487,7 +487,7 @@ int main(int argc, const char *argv[]) exit_if((r = til_audio_open(audio_ops, setup.audio_setup, &rototiller.audio)) < 0, "unable to open audio: %s", strerror(-r)); - exit_if(!(rototiller.stream = til_stream_new()), + exit_if(!(rototiller.stream = til_stream_new(rototiller.audio)), "unable to create root stream"); exit_if(!fps_setup(), diff --git a/src/til_stream.c b/src/til_stream.c index 5b9b59c..72dedb6 100644 --- a/src/til_stream.c +++ b/src/til_stream.c @@ -96,12 +96,14 @@ typedef struct til_stream_t { unsigned frame; const til_stream_hooks_t *hooks; void *hooks_context; + til_audio_context_t *audio_context; til_stream_pipe_t *pipe_buckets[TIL_STREAM_PIPE_BUCKETS_COUNT]; til_stream_module_context_t *module_context_buckets[TIL_STREAM_CTXT_BUCKETS_COUNT]; } til_stream_t; -til_stream_t * til_stream_new(void) +/* the caller must ensure audio_context persists, til_stream_free() will not free it */ +til_stream_t * til_stream_new(til_audio_context_t *audio_context) { til_stream_t *stream; @@ -110,6 +112,7 @@ til_stream_t * til_stream_new(void) return NULL; pthread_mutex_init(&stream->mutex, NULL); + stream->audio_context = audio_context; return stream; } @@ -207,6 +210,23 @@ int til_stream_unset_hooks(til_stream_t *stream, const til_stream_hooks_t *hooks } +/* An audio context is just a simple singleton per stream, nothing fancy currently. + * Any module that wants to produce audio just calls til_stream_get_audio_context() + * on the stream, and til_audio_queue() against that context if non-NULL. When + * the context is NULL audio-producing code should just not do anything. + * + * Nothing is done currently to prevent multiple modules from queueing audio and + * making an awful mess, this will probably get improved in the future. It's just + * up to the user/setup to not arrange multiple audio-generating modules on the + * same stream. + */ +til_audio_context_t * til_stream_get_audio_context(til_stream_t *stream) +{ + assert(stream); + + return stream->audio_context; +} + /* Taps the key-named type-typed pipe on the supplied stream. * If this is the first use of the pipe on this stream, new pipe will be created. * If the pipe exists on this stream, and the type/n_elems match, existing pipe will be used as-is. diff --git a/src/til_stream.h b/src/til_stream.h index e7b92e6..d72b139 100644 --- a/src/til_stream.h +++ b/src/til_stream.h @@ -24,6 +24,7 @@ #include "til_module_context.h" #include "til_setup.h" +typedef struct til_audio_context_t til_audio_context_t; typedef struct til_stream_t til_stream_t; typedef struct til_stream_module_context_t til_stream_module_context_t; typedef struct til_stream_pipe_t til_stream_pipe_t; @@ -44,13 +45,14 @@ typedef struct til_stream_hooks_t { void (*pipe_dtor)(void *context, til_stream_t *stream, const void *owner, const void *owner_foo, const char *parent_path, const til_tap_t *tap); /* called immediately *after* pipe "destroyed" (withdrawn from stream) */ } til_stream_hooks_t; -til_stream_t * til_stream_new(void); +til_stream_t * til_stream_new(til_audio_context_t *audio_context); til_stream_t * til_stream_free(til_stream_t *stream); void til_stream_end(til_stream_t *stream); int til_stream_active(til_stream_t *stream); void til_stream_start_frame(til_stream_t *stream); int til_stream_set_hooks(til_stream_t *stream, const til_stream_hooks_t *hooks, void *context); int til_stream_unset_hooks(til_stream_t *stream, const til_stream_hooks_t *hooks); +til_audio_context_t * til_stream_get_audio_context(til_stream_t *stream); /* bare interface for non-module-context owned taps */ int til_stream_tap(til_stream_t *stream, const void *owner, const void *owner_foo, const char *parent_path, uint32_t parent_hash, const til_tap_t *tap); -- cgit v1.2.1