stream: add a method to check if driving or not

When the node is driving, we need to call trigger_process()
otherwise we don't and we simply need to wait for the process() to
be called, triggered by the driver node.

See #1484
This commit is contained in:
Wim Taymans 2021-08-06 15:35:11 +02:00
parent 3c97090ba0
commit b030a4e7da
5 changed files with 32 additions and 14 deletions

View file

@ -208,8 +208,9 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
interval.tv_sec = 0;
interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
data->timer, &timeout, &interval, false);
if (pw_stream_is_driving(data->stream))
pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
data->timer, &timeout, &interval, false);
break;
}
default:

View file

@ -214,8 +214,9 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
interval.tv_sec = 0;
interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
data->timer, &timeout, &interval, false);
if (pw_stream_is_driving(data->stream))
pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
data->timer, &timeout, &interval, false);
timeout.tv_sec = 1;
timeout.tv_nsec = 0;

View file

@ -208,8 +208,9 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
interval.tv_sec = 0;
interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
data->timer, &timeout, &interval, false);
if (pw_stream_is_driving(data->stream))
pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
data->timer, &timeout, &interval, false);
break;
}
default:

View file

@ -2106,6 +2106,13 @@ int pw_stream_flush(struct pw_stream *stream, bool drain)
return 0;
}
SPA_EXPORT
bool pw_stream_is_driving(struct pw_stream *stream)
{
struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
return impl->driving;
}
static int
do_trigger_process(struct spa_loop *loop,
bool async, uint32_t seq, const void *data, size_t size, void *user_data)
@ -2133,14 +2140,16 @@ int pw_stream_trigger_process(struct pw_stream *stream)
/* flag to check for old or new behaviour */
impl->using_drive = true;
if (impl->driving) {
if (impl->direction == SPA_DIRECTION_OUTPUT &&
!impl->process_rt) {
pw_loop_invoke(impl->context->main_loop,
do_call_process, 1, NULL, 0, false, impl);
}
res = pw_loop_invoke(impl->context->data_loop,
do_trigger_process, 1, NULL, 0, false, impl);
if (!impl->driving)
return -EINVAL;
if (impl->direction == SPA_DIRECTION_OUTPUT &&
!impl->process_rt) {
pw_loop_invoke(impl->context->main_loop,
do_call_process, 1, NULL, 0, false, impl);
}
res = pw_loop_invoke(impl->context->data_loop,
do_trigger_process, 1, NULL, 0, false, impl);
return res;
}

View file

@ -362,6 +362,12 @@ int pw_stream_set_active(struct pw_stream *stream, bool active);
* be called when all data is played or recorded */
int pw_stream_flush(struct pw_stream *stream, bool drain);
/** Check if the stream is driving. The stream needs to have the
* PW_STREAM_FLAG_DRIVER set. When the stream is driving,
* pw_stream_trigger_process() needs to be called when data is
* available (output) or needed (input). Since 0.3.34 */
bool pw_stream_is_driving(struct pw_stream *stream);
/** Trigger a push/pull on the stream. One iteration of the graph will
* scheduled and process() will be called. Since 0.3.34 */
int pw_stream_trigger_process(struct pw_stream *stream);