From 5b2b93f9158fded7a152ee8f1aea3430015e033a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 6 Sep 2022 20:16:29 +0200 Subject: [PATCH] alsa: add period-size, period-num and headroom in props Add the currently configured alsa hw_params in the properties for easier access. --- spa/plugins/alsa/alsa-pcm-sink.c | 10 ++++++++-- spa/plugins/alsa/alsa-pcm-source.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm-sink.c b/spa/plugins/alsa/alsa-pcm-sink.c index a0b5b4e68..73c421eec 100644 --- a/spa/plugins/alsa/alsa-pcm-sink.c +++ b/spa/plugins/alsa/alsa-pcm-sink.c @@ -56,9 +56,9 @@ static void emit_node_info(struct state *this, bool full) if (full) this->info.change_mask = this->info_all; if (this->info.change_mask) { - struct spa_dict_item items[4]; + struct spa_dict_item items[7]; uint32_t i, n_items = 0; - char latency[64]; + char latency[64], period[64], nperiods[64], headroom[64]; items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_API, "alsa"); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MEDIA_CLASS, "Audio/Sink"); @@ -66,6 +66,12 @@ static void emit_node_info(struct state *this, bool full) if (this->have_format) { snprintf(latency, sizeof(latency), "%lu/%d", this->buffer_frames / 2, this->rate); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency); + snprintf(period, sizeof(period), "%lu", this->period_frames); + items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-size", period); + snprintf(nperiods, sizeof(nperiods), "%lu", this->buffer_frames / this->period_frames); + items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-num", nperiods); + snprintf(headroom, sizeof(headroom), "%u", this->headroom); + items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom); } this->info.props = &SPA_DICT_INIT(items, n_items); diff --git a/spa/plugins/alsa/alsa-pcm-source.c b/spa/plugins/alsa/alsa-pcm-source.c index a1e9690cf..7f72d53ab 100644 --- a/spa/plugins/alsa/alsa-pcm-source.c +++ b/spa/plugins/alsa/alsa-pcm-source.c @@ -57,9 +57,9 @@ static void emit_node_info(struct state *this, bool full) if (full) this->info.change_mask = this->info_all; if (this->info.change_mask) { - struct spa_dict_item items[4]; + struct spa_dict_item items[7]; uint32_t i, n_items = 0; - char latency[64]; + char latency[64], period[64], nperiods[64], headroom[64]; items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_API, "alsa"); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MEDIA_CLASS, "Audio/Source"); @@ -67,6 +67,12 @@ static void emit_node_info(struct state *this, bool full) if (this->have_format) { snprintf(latency, sizeof(latency), "%lu/%d", this->buffer_frames / 2, this->rate); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency); + snprintf(period, sizeof(period), "%lu", this->period_frames); + items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-size", period); + snprintf(nperiods, sizeof(nperiods), "%lu", this->buffer_frames / this->period_frames); + items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-num", nperiods); + snprintf(headroom, sizeof(headroom), "%u", this->headroom); + items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom); } this->info.props = &SPA_DICT_INIT(items, n_items);