diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 3a41588fc..4f70f9bad 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -2595,3 +2595,23 @@ int pw_stream_trigger_process(struct pw_stream *stream) } return res; } + +SPA_EXPORT +int pw_stream_set_rate(struct pw_stream *stream, double rate) +{ + struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this); + bool enable; + + if (impl->rate_match == NULL) + return -ENOTSUP; + + if (rate <= 0.0) { + rate = 1.0; + enable = false; + } else { + enable = true; + } + impl->rate_match->rate = rate; + SPA_FLAG_UPDATE(impl->rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE, enable); + return 0; +} diff --git a/src/pipewire/stream.h b/src/pipewire/stream.h index f4c421e7b..bd9da1381 100644 --- a/src/pipewire/stream.h +++ b/src/pipewire/stream.h @@ -662,6 +662,15 @@ int pw_stream_trigger_process(struct pw_stream *stream); * Since 1.2.6 */ int pw_stream_emit_event(struct pw_stream *stream, const struct spa_event *event); +/** Adjust the rate of the stream. + * When the stream is using an adaptive resampler, adjust the resampler rate. + * When there is no resampler, -ENOTSUP is returned. Activating the adaptive + * resampler will add a small amount of delay to the samples, you can deactivate + * it again by setting a value <= 0.0. + * Since 1.4.0 */ +int pw_stream_set_rate(struct pw_stream *stream, double rate); + + /** * \} */