diff --git a/src/examples/video-src-alloc.c b/src/examples/video-src-alloc.c index 8b005a651..166828e1e 100644 --- a/src/examples/video-src-alloc.c +++ b/src/examples/video-src-alloc.c @@ -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: diff --git a/src/examples/video-src-reneg.c b/src/examples/video-src-reneg.c index 673001690..eda664de2 100644 --- a/src/examples/video-src-reneg.c +++ b/src/examples/video-src-reneg.c @@ -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; diff --git a/src/examples/video-src.c b/src/examples/video-src.c index 6528341e8..403dc66f5 100644 --- a/src/examples/video-src.c +++ b/src/examples/video-src.c @@ -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: diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 68506246a..806b168b6 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -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; } diff --git a/src/pipewire/stream.h b/src/pipewire/stream.h index a25ca1938..4e54be62a 100644 --- a/src/pipewire/stream.h +++ b/src/pipewire/stream.h @@ -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);