diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index bb23c9d5c..85d16a6b1 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -1986,7 +1986,8 @@ int pw_filter_get_time(struct pw_filter *filter, struct pw_time *time) pw_log_trace("%p: %"PRIi64" %"PRIi64" %"PRIu64" %d/%d ", filter, time->now, time->delay, time->ticks, time->rate.num, time->rate.denom); - return 0; + + return filter->state == PW_FILTER_STATE_STREAMING ? 0 : -EIO; } SPA_EXPORT diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 477861f61..4ee2138bc 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -2504,7 +2504,8 @@ int pw_stream_get_time_n(struct pw_stream *stream, struct pw_time *time, size_t impl->dequeued.outcount, impl->dequeued.incount, impl->queued.outcount, impl->queued.incount, avail_buffers, impl->n_buffers); - return 0; + + return stream->state == PW_STREAM_STATE_STREAMING ? 0 : -EIO; } SPA_EXPORT diff --git a/src/pipewire/stream.h b/src/pipewire/stream.h index 28b4eba1f..d5cd87188 100644 --- a/src/pipewire/stream.h +++ b/src/pipewire/stream.h @@ -293,7 +293,8 @@ struct pw_stream_control { * Use pw_stream_get_time_n() to get an updated time snapshot of the stream. * The time snapshot can give information about the time in the driver of the * graph, the delay to the edge of the graph and the internal queuing in the - * stream. + * stream. This function should only be called in the STREAMING state and will + * return an error when called in any other state. * * pw_time.ticks gives a monotonic increasing counter of the time in the graph * driver. I can be used to generate a timeline to schedule samples as well @@ -594,7 +595,7 @@ const struct pw_stream_control *pw_stream_get_control(struct pw_stream *stream, /** Set control values */ int pw_stream_set_control(struct pw_stream *stream, uint32_t id, uint32_t n_values, float *values, ...); -/** Query the time on the stream, RT safe */ +/** Query the time on the stream. Returns an error when the stream is not running. RT safe */ int pw_stream_get_time_n(struct pw_stream *stream, struct pw_time *time, size_t size); /** Get the current time in nanoseconds. This value can be compared with diff --git a/src/tests/test-stream.c b/src/tests/test-stream.c index d56b6c85b..b5061e927 100644 --- a/src/tests/test-stream.c +++ b/src/tests/test-stream.c @@ -151,7 +151,7 @@ static void test_create(void) /* check id, only when connected */ spa_assert_se(pw_stream_get_node_id(stream) == SPA_ID_INVALID); - spa_assert_se(pw_stream_get_time_n(stream, &tm, sizeof(tm)) == 0); + spa_assert_se(pw_stream_get_time_n(stream, &tm, sizeof(tm)) == -EIO); spa_assert_se(tm.now == 0); spa_assert_se(tm.rate.num == 0); spa_assert_se(tm.rate.denom == 0);