summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.c9
-rw-r--r--src/modules/rkt/rkt.c5
-rw-r--r--src/til_stream.c18
-rw-r--r--src/til_stream.h1
4 files changed, 31 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index daf1b24..f350a1f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -73,7 +73,7 @@ typedef struct rototiller_t {
til_fb_fragment_t *fragment;
pthread_t thread;
til_fb_t *fb;
- til_audio_context_t *audio;
+ til_audio_context_t *audio, *audio_control;
} rototiller_t;
static rototiller_t rototiller;
@@ -430,6 +430,10 @@ static void * rototiller_thread(void *_rt)
til_fb_fragment_submit(rt->fragment);
last_ticks = ticks;
+ /* if we're in audio control, ensure it's unpaused if something's queueing audio */
+ if (rt->audio_control && til_audio_n_queued(rt->audio_control))
+ til_audio_unpause(rt->audio_control);
+
if (rt->args.print_module_contexts || rt->args.print_pipes) {
/* render threads are idle at this point */
printf("\x1b[2J\x1b[;H"); /* ANSI codes for clear screen and move cursor to top left */
@@ -502,6 +506,9 @@ int main(int argc, const char *argv[])
&rototiller.module_context)) < 0,
"unable to create module context: %s", strerror(-r));
+ /* this determines if we need to "control" the audio (unpause it, really) */
+ rototiller.audio_control = til_stream_get_audio_context_control(rototiller.stream);
+
pexit_if(pthread_create(&rototiller.thread, NULL, rototiller_thread, &rototiller) != 0,
"unable to create dispatch thread");
diff --git a/src/modules/rkt/rkt.c b/src/modules/rkt/rkt.c
index 7460161..f5221f4 100644
--- a/src/modules/rkt/rkt.c
+++ b/src/modules/rkt/rkt.c
@@ -286,7 +286,10 @@ static til_module_context_t * rkt_create_context(const til_module_t *module, til
if (!ctxt->scene_track)
return til_module_context_free(&ctxt->til_module_context);
- ctxt->audio_context = til_stream_get_audio_context(stream);
+ ctxt->audio_context = til_stream_get_audio_context_control(stream);
+ if (!ctxt->audio_context)
+ return til_module_context_free(&ctxt->til_module_context);
+
/* set the stream hooks early so context creates can establish taps early */
til_stream_set_hooks(stream, &rkt_stream_hooks, ctxt);
diff --git a/src/til_stream.c b/src/til_stream.c
index 72dedb6..8fd4b07 100644
--- a/src/til_stream.c
+++ b/src/til_stream.c
@@ -97,6 +97,7 @@ typedef struct til_stream_t {
const til_stream_hooks_t *hooks;
void *hooks_context;
til_audio_context_t *audio_context;
+ unsigned audio_controlled:1;
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;
@@ -227,6 +228,23 @@ til_audio_context_t * til_stream_get_audio_context(til_stream_t *stream)
return stream->audio_context;
}
+
+/* identical to til_stream_get_audio_context() except taking control,
+ * returns NULL if control is already taken.
+ */
+til_audio_context_t * til_stream_get_audio_context_control(til_stream_t *stream)
+{
+ assert(stream);
+
+ if (stream->audio_controlled)
+ return NULL;
+
+ stream->audio_controlled = 1;
+
+ 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 d72b139..a0dde31 100644
--- a/src/til_stream.h
+++ b/src/til_stream.h
@@ -53,6 +53,7 @@ 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);
+til_audio_context_t * til_stream_get_audio_context_control(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);
© All Rights Reserved