stream: add TRIGGER stream flag

The trigger flag adds an extra dependency on the node so that it does
not automatically get scheduled. A manual scheduling is required with,
for example pw_stream_trigger_process().

This can be used to create an artificial dependency between a sink
stream and a source stream, like when using loopback or filter-chain.
Normally those streams are not linked in the graph but they have an
internal dependency. Without any such dependency, the source part of the
chain will be scheduled first and then the sink part and we get a
cycle of delay (with possible quantum change etc).

With this patch, the sink part will be scheduled first and its process
function will trigger the 'downstream' source stream explicitly. The
sink and source stream will stay in sync and will use the same quantum.
This reduces the latency and glitches because of quantum changes.

Fixes #1873
This commit is contained in:
Wim Taymans 2021-12-08 20:29:15 +01:00
parent 53dbfa79c3
commit db77f6d37d
6 changed files with 26 additions and 3 deletions

View file

@ -166,6 +166,8 @@ static void capture_process(void *d)
pw_stream_queue_buffer(impl->capture, in);
if (out != NULL)
pw_stream_queue_buffer(impl->playback, out);
pw_stream_trigger_process(impl->playback);
}
static void param_latency_changed(struct impl *impl, const struct spa_pod *param,
@ -294,7 +296,8 @@ static int setup_streams(struct impl *impl)
PW_ID_ANY,
PW_STREAM_FLAG_AUTOCONNECT |
PW_STREAM_FLAG_MAP_BUFFERS |
PW_STREAM_FLAG_RT_PROCESS,
PW_STREAM_FLAG_RT_PROCESS |
PW_STREAM_FLAG_TRIGGER,
params, n_params)) < 0)
return res;