module-pulse-tunnel: rate limit some messages

This commit is contained in:
Wim Taymans 2022-10-20 09:24:54 +02:00
parent 500a5a689e
commit e5881e9afb

View file

@ -183,6 +183,8 @@ struct impl {
pa_context *pa_context; pa_context *pa_context;
pa_stream *pa_stream; pa_stream *pa_stream;
struct ratelimit rate_limit;
uint32_t target_latency; uint32_t target_latency;
uint32_t current_latency; uint32_t current_latency;
uint32_t target_buffer; uint32_t target_buffer;
@ -577,13 +579,20 @@ static void stream_write_request_cb(pa_stream *s, size_t length, void *userdata)
static void stream_underflow_cb(pa_stream *s, void *userdata) static void stream_underflow_cb(pa_stream *s, void *userdata)
{ {
struct impl *impl = userdata; struct impl *impl = userdata;
pw_log_warn("underflow"); struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
if (ratelimit_test(&impl->rate_limit, SPA_TIMESPEC_TO_NSEC(&ts), SPA_LOG_LEVEL_WARN))
pw_log_warn("underflow");
impl->resync = true; impl->resync = true;
} }
static void stream_overflow_cb(pa_stream *s, void *userdata) static void stream_overflow_cb(pa_stream *s, void *userdata)
{ {
struct impl *impl = userdata; struct impl *impl = userdata;
pw_log_warn("overflow"); struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
if (ratelimit_test(&impl->rate_limit, SPA_TIMESPEC_TO_NSEC(&ts), SPA_LOG_LEVEL_WARN))
pw_log_warn("overflow");
impl->resync = true; impl->resync = true;
} }
@ -963,6 +972,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
spa_ringbuffer_init(&impl->ring); spa_ringbuffer_init(&impl->ring);
impl->buffer = calloc(1, RINGBUFFER_SIZE); impl->buffer = calloc(1, RINGBUFFER_SIZE);
spa_dll_init(&impl->dll); spa_dll_init(&impl->dll);
impl->rate_limit.interval = 2 * SPA_NSEC_PER_SEC;
impl->rate_limit.burst = 1;
if ((str = pw_properties_get(props, "tunnel.mode")) != NULL) { if ((str = pw_properties_get(props, "tunnel.mode")) != NULL) {
if (spa_streq(str, "source")) { if (spa_streq(str, "source")) {