PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
PA_MODULE_DESCRIPTION("Playback stream expression matching module");
PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(TRUE);
-PA_MODULE_USAGE("table=<filename>");
+PA_MODULE_USAGE("table=<filename> "
+ "key=<property_key>");
#define WHITESPACE "\n\r \t"
static const char* const valid_modargs[] = {
"table",
+ "key",
NULL,
};
struct rule {
regex_t regex;
pa_volume_t volume;
+ pa_proplist *proplist;
struct rule *next;
};
struct userdata {
struct rule *rules;
+ char *property_key;
pa_subscription *subscription;
};
while (!feof(f)) {
char *d, *v;
- pa_volume_t volume;
+ pa_volume_t volume = PA_VOLUME_NORM;
uint32_t k;
regex_t regex;
char ln[256];
struct rule *rule;
+ pa_proplist *proplist = NULL;
if (!fgets(ln, sizeof(ln), f))
break;
}
*d = 0;
- if (pa_atou(v, &k) < 0) {
- pa_log("[%s:%u] failed to parse volume", filename, n);
- goto finish;
+ if (pa_atou(v, &k) >= 0) {
+ volume = (pa_volume_t) k;
+ } else if (*v == '"') {
+ char *e;
+
+ e = strchr(v+1, '"');
+ if (!e) {
+ pa_log(__FILE__ ": [%s:%u] failed to parse line - missing role closing quote", filename, n);
+ goto finish;
+ }
+
+ *e = '\0';
+ e = pa_sprintf_malloc("media.role=\"%s\"", v+1);
+ proplist = pa_proplist_from_string(e);
+ pa_xfree(e);
+ } else {
+ char *e;
+
+ e = v+strspn(v, WHITESPACE);
+ if (!*e) {
+ pa_log(__FILE__ ": [%s:%u] failed to parse line - missing end of property list", filename, n);
+ goto finish;
+ }
+ *e = '\0';
+ proplist = pa_proplist_from_string(v);
}
- volume = (pa_volume_t) k;
-
-
if (regcomp(®ex, ln, REG_EXTENDED|REG_NOSUB) != 0) {
pa_log("[%s:%u] invalid regular expression", filename, n);
goto finish;
rule = pa_xnew(struct rule, 1);
rule->regex = regex;
+ rule->proplist = proplist;
rule->volume = volume;
rule->next = NULL;
if (!(si = pa_idxset_get_by_index(c->sink_inputs, idx)))
return;
- if (!(n = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_NAME)))
+ if (!(n = pa_proplist_gets(si->proplist, u->property_key)))
return;
+ pa_log_debug("Matching with %s", n);
+
for (r = u->rules; r; r = r->next) {
if (!regexec(&r->regex, n, 0, NULL, 0)) {
- pa_cvolume cv;
- pa_log_debug("changing volume of sink input '%s' to 0x%03x", n, r->volume);
- pa_cvolume_set(&cv, si->sample_spec.channels, r->volume);
- pa_sink_input_set_volume(si, &cv);
+ if (r->proplist) {
+ pa_log_debug("updating proplist of sink input '%s'", n);
+ pa_proplist_update(si->proplist, PA_UPDATE_MERGE, r->proplist);
+ } else {
+ pa_cvolume cv;
+ pa_log_debug("changing volume of sink input '%s' to 0x%03x", n, r->volume);
+ pa_cvolume_set(&cv, si->sample_spec.channels, r->volume);
+ pa_sink_input_set_volume(si, &cv, TRUE, FALSE);
+ }
}
}
}
u->subscription = NULL;
m->userdata = u;
+ u->property_key = pa_xstrdup(pa_modargs_get_value(ma, "key", PA_PROP_MEDIA_NAME));
+
if (load_rules(u, pa_modargs_get_value(ma, "table", NULL)) < 0)
goto fail;
+ /* FIXME: Doing this asynchronously is just broken. This needs to
+ * use a hook! */
+
u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u);
pa_modargs_free(ma);
if (u->subscription)
pa_subscription_free(u->subscription);
+ if (u->property_key)
+ pa_xfree(u->property_key);
+
for (r = u->rules; r; r = n) {
n = r->next;
regfree(&r->regex);
+ if (r->proplist)
+ pa_proplist_free(r->proplist);
pa_xfree(r);
}