From 385246f5a1b46b5543df7d85e2111d369d61fad7 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 2 Dec 2021 10:55:50 +0100 Subject: [PATCH] audioconvert: only update the arrays when valid Only update our internal channelmap/volumes array when we actually parsed something. --- spa/plugins/audioconvert/channelmix.c | 19 +++++--- spa/plugins/audioconvert/merger.c | 65 +++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index 0e57fc8fc..2cca07473 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -524,6 +524,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param) int changed = 0; bool have_channel_volume = false; bool have_soft_volume = false; + uint32_t n; if (param == NULL) return 0; @@ -541,16 +542,19 @@ static int apply_props(struct impl *this, const struct spa_pod *param) } break; case SPA_PROP_channelVolumes: - if ((p->channel.n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, p->channel.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->channel.n_volumes = n; changed++; have_channel_volume = true; } break; case SPA_PROP_channelMap: - if ((p->n_channels = spa_pod_copy_array(&prop->value, SPA_TYPE_Id, - p->channel_map, SPA_AUDIO_MAX_CHANNELS)) > 0) + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Id, + p->channel_map, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->n_channels = n; changed++; + } break; case SPA_PROP_softMute: if (spa_pod_get_bool(&prop->value, &p->soft.mute) == 0) { @@ -559,8 +563,9 @@ static int apply_props(struct impl *this, const struct spa_pod *param) } break; case SPA_PROP_softVolumes: - if ((p->soft.n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, p->soft.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->soft.n_volumes = n; changed++; have_soft_volume = true; } @@ -570,9 +575,11 @@ static int apply_props(struct impl *this, const struct spa_pod *param) changed++; break; case SPA_PROP_monitorVolumes: - if ((p->monitor.n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, - p->monitor.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, + p->monitor.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->monitor.n_volumes = n; changed++; + } break; default: break; diff --git a/spa/plugins/audioconvert/merger.c b/spa/plugins/audioconvert/merger.c index d04d92e08..b79d52895 100644 --- a/spa/plugins/audioconvert/merger.c +++ b/spa/plugins/audioconvert/merger.c @@ -430,12 +430,53 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) return 0; } +static int merger_set_param(struct impl *this, const char *k, const char *s) +{ + if (spa_streq(k, "monitor.channel-volumes")) + this->monitor_channel_volumes = spa_atob(s); + return 0; +} + +static int parse_prop_params(struct impl *this, struct spa_pod *params) +{ + struct spa_pod_parser prs; + struct spa_pod_frame f; + + spa_pod_parser_pod(&prs, params); + if (spa_pod_parser_push_struct(&prs, &f) < 0) + return 0; + + while (true) { + const char *name; + struct spa_pod *pod; + char value[512]; + + if (spa_pod_parser_get_string(&prs, &name) < 0) + break; + + if (spa_pod_parser_get_pod(&prs, &pod) < 0) + break; + + if (spa_pod_is_bool(pod)) { + snprintf(value, sizeof(value), "%s", + SPA_POD_VALUE(struct spa_pod_bool, pod) ? + "true" : "false"); + } else + continue; + + spa_log_info(this->log, "key:'%s' val:'%s'", name, value); + merger_set_param(this, name, value); + } + return 0; +} + static int apply_props(struct impl *this, const struct spa_pod *param) { struct spa_pod_prop *prop; struct spa_pod_object *obj = (struct spa_pod_object *) param; struct props *p = &this->props; int changed = 0; + uint32_t n; SPA_POD_OBJECT_FOREACH(obj, prop) { switch (prop->key) { @@ -448,32 +489,40 @@ static int apply_props(struct impl *this, const struct spa_pod *param) changed++; break; case SPA_PROP_channelVolumes: - if ((p->channel.n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, - p->channel.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, + p->channel.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->channel.n_volumes = n; changed++; + } break; case SPA_PROP_channelMap: - if ((p->n_channels = spa_pod_copy_array(&prop->value, SPA_TYPE_Id, - p->channel_map, SPA_AUDIO_MAX_CHANNELS)) > 0) + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Id, + p->channel_map, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->n_channels = n; changed++; + } break; case SPA_PROP_softMute: if (spa_pod_get_bool(&prop->value, &p->soft.mute) == 0) changed++; break; case SPA_PROP_softVolumes: - if ((p->soft.n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, - p->soft.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, + p->soft.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->soft.n_volumes = n; changed++; + } break; case SPA_PROP_monitorMute: if (spa_pod_get_bool(&prop->value, &p->monitor.mute) == 0) changed++; break; case SPA_PROP_monitorVolumes: - if ((p->monitor.n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, - p->monitor.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) + if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, + p->monitor.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { + p->monitor.n_volumes = n; changed++; + } break; default: break;