mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
match: can now change properties also
This commit is contained in:
parent
6ec0162686
commit
e97ed21892
1 changed files with 42 additions and 11 deletions
|
|
@ -63,6 +63,7 @@ static const char* const valid_modargs[] = {
|
||||||
struct rule {
|
struct rule {
|
||||||
regex_t regex;
|
regex_t regex;
|
||||||
pa_volume_t volume;
|
pa_volume_t volume;
|
||||||
|
pa_proplist *proplist;
|
||||||
struct rule *next;
|
struct rule *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -95,11 +96,12 @@ static int load_rules(struct userdata *u, const char *filename) {
|
||||||
|
|
||||||
while (!feof(f)) {
|
while (!feof(f)) {
|
||||||
char *d, *v;
|
char *d, *v;
|
||||||
pa_volume_t volume;
|
pa_volume_t volume = PA_VOLUME_NORM;
|
||||||
uint32_t k;
|
uint32_t k;
|
||||||
regex_t regex;
|
regex_t regex;
|
||||||
char ln[256];
|
char ln[256];
|
||||||
struct rule *rule;
|
struct rule *rule;
|
||||||
|
pa_proplist *proplist = NULL;
|
||||||
|
|
||||||
if (!fgets(ln, sizeof(ln), f))
|
if (!fgets(ln, sizeof(ln), f))
|
||||||
break;
|
break;
|
||||||
|
|
@ -121,14 +123,33 @@ static int load_rules(struct userdata *u, const char *filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
*d = 0;
|
*d = 0;
|
||||||
if (pa_atou(v, &k) < 0) {
|
if (pa_atou(v, &k) >= 0) {
|
||||||
pa_log("[%s:%u] failed to parse volume", filename, n);
|
volume = (pa_volume_t) k;
|
||||||
goto finish;
|
} 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) {
|
if (regcomp(®ex, ln, REG_EXTENDED|REG_NOSUB) != 0) {
|
||||||
pa_log("[%s:%u] invalid regular expression", filename, n);
|
pa_log("[%s:%u] invalid regular expression", filename, n);
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
@ -136,6 +157,7 @@ static int load_rules(struct userdata *u, const char *filename) {
|
||||||
|
|
||||||
rule = pa_xnew(struct rule, 1);
|
rule = pa_xnew(struct rule, 1);
|
||||||
rule->regex = regex;
|
rule->regex = regex;
|
||||||
|
rule->proplist = proplist;
|
||||||
rule->volume = volume;
|
rule->volume = volume;
|
||||||
rule->next = NULL;
|
rule->next = NULL;
|
||||||
|
|
||||||
|
|
@ -180,12 +202,19 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v
|
||||||
if (!(n = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_NAME)))
|
if (!(n = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_NAME)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
pa_log_debug("Matching with %s", n);
|
||||||
|
|
||||||
for (r = u->rules; r; r = r->next) {
|
for (r = u->rules; r; r = r->next) {
|
||||||
if (!regexec(&r->regex, n, 0, NULL, 0)) {
|
if (!regexec(&r->regex, n, 0, NULL, 0)) {
|
||||||
pa_cvolume cv;
|
if (r->proplist) {
|
||||||
pa_log_debug("changing volume of sink input '%s' to 0x%03x", n, r->volume);
|
pa_log_debug("updating proplist of sink input '%s'", n);
|
||||||
pa_cvolume_set(&cv, si->sample_spec.channels, r->volume);
|
pa_proplist_update(si->proplist, PA_UPDATE_MERGE, r->proplist);
|
||||||
pa_sink_input_set_volume(si, &cv);
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -238,6 +267,8 @@ void pa__done(pa_module*m) {
|
||||||
n = r->next;
|
n = r->next;
|
||||||
|
|
||||||
regfree(&r->regex);
|
regfree(&r->regex);
|
||||||
|
if (r->proplist)
|
||||||
|
pa_proplist_free(r->proplist);
|
||||||
pa_xfree(r);
|
pa_xfree(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue