From 1eae3f1a2c0b5788b740c76db793af6a8890b91b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 22 Jun 2018 17:31:54 +0200 Subject: [PATCH] media-session: round buffer-size down to power of 2 use rate of the session to calculate the buffer size and round down to power of 2 --- src/modules/module-media-session.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/modules/module-media-session.c b/src/modules/module-media-session.c index 4f5c4e192..9d7627d6a 100644 --- a/src/modules/module-media-session.c +++ b/src/modules/module-media-session.c @@ -435,6 +435,16 @@ static int find_session(void *data, struct session *sess) return 0; } +static uint32_t flp2(uint32_t x) +{ + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >> 16); + return x - (x >> 1); +} + static int handle_autoconnect(struct impl *impl, struct pw_node *node, const struct pw_properties *props) { @@ -474,10 +484,14 @@ static int handle_autoconnect(struct impl *impl, struct pw_node *node, else exclusive = false; - if ((str = pw_properties_get(props, "node.latency")) != NULL) - buffer_size = atoi(str) * sizeof(float); - else - buffer_size = MAX_BUFFER_SIZE; + buffer_size = MAX_BUFFER_SIZE; + if ((str = pw_properties_get(props, "node.latency")) != NULL) { + uint32_t num, denom; + pw_log_info("module %p: '%s'", impl, str); + if (sscanf(str, "%u/%u", &num, &denom) == 2 && denom != 0) { + buffer_size = flp2((num * denom / sample_rate) * sizeof(float)); + } + } pw_log_info("module %p: '%s' '%s' '%s' exclusive:%d quantum:%d/%d", impl, media, category, role, exclusive,