/* Watch for properties starting with droid.parameter. and translate them directly to
* HAL set_parameters() calls. */
static pa_hook_result_t sink_proplist_changed_hook_cb(pa_core *c, pa_sink *sink, struct userdata *u) {
bool changed = false;
const char *pkey;
const char *key;
const char *value;
char *tmp;
void *state = NULL;
droid_parameter_mapping *parameter = NULL;
pa_assert(sink);
pa_assert(u);
if (u->sink != sink)
return PA_HOOK_OK;
while ((key = pa_proplist_iterate(sink->proplist, &state))) {
if (!pa_startswith(key, PROP_DROID_PARAMETER_PREFIX))
continue;
pkey = key + strlen(PROP_DROID_PARAMETER_PREFIX);
if (pkey[0] == '\0')
continue;
changed = false;
if (!(parameter = pa_hashmap_get(u->parameters, pkey))) {
parameter = pa_xnew0(droid_parameter_mapping, 1);
parameter->key = pa_xstrdup(pkey);
parameter->value = pa_xstrdup(pa_proplist_gets(sink->proplist, key));
pa_hashmap_put(u->parameters, parameter->key, parameter);
changed = true;
} else {
value = pa_proplist_gets(sink->proplist, key);
if (!pa_streq(parameter->value, value)) {
pa_xfree(parameter->value);
parameter->value = pa_xstrdup(value);
changed = true;
}
}
if (changed) {
pa_assert(parameter);
tmp = pa_sprintf_malloc("%s=%s;", parameter->key, parameter->value);
pa_log_debug("sink proplist changed: set_parameters(): %s", tmp);
pa_droid_hw_module_lock(u->hw_module);
u->stream_out->common.set_parameters(&u->stream_out->common, tmp);
pa_droid_hw_module_unlock(u->hw_module);
pa_xfree(tmp);
}
}
return PA_HOOK_OK;
}