diff --git a/alsactl/alsactl.1 b/alsactl/alsactl.1 index c515fdd..8423b82 100644 --- a/alsactl/alsactl.1 +++ b/alsactl/alsactl.1 @@ -142,6 +142,11 @@ Set the process priority (see 'man nice') \fI\-c, \-\-sched-idle\fP Set the process scheduling policy to idle (SCHED_IDLE). +.TP +\fI\-D, \-\-ucm-defaults\fP +Execute also the 'defaults' section from the UCM configuration. The standard +behaviour is to execute only 'once' section. + .SH FILES \fI/var/lib/alsa/asound.state\fP (or whatever file you specify with the \fB\-f\fP flag) is used to store current settings for your diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c index 92ce270..1971d4e 100644 --- a/alsactl/alsactl.c +++ b/alsactl/alsactl.c @@ -96,6 +96,7 @@ static struct arg args[] = { { 's', "syslog", "use syslog for messages" }, { INTARG | 'n', "nice", "set the process priority (see 'man nice')" }, { 'c', "sched-idle", "set the process scheduling policy to idle (SCHED_IDLE)" }, +{ 'D', "ucm-defaults", "execute also the UCM 'defaults' section" }, { HEADER, NULL, "Available commands:" }, { CARDCMD, "store", "save current driver setup for one or each soundcards" }, { EMPCMD, NULL, " to configuration file" }, @@ -191,6 +192,7 @@ int main(int argc, char *argv[]) int daemoncmd = 0; int use_nice = NO_NICE; int sched_idle = 0; + int initflags = 0; struct arg *a; struct option *o; int i, j, k, res; @@ -263,6 +265,9 @@ int main(int argc, char *argv[]) case 'I': init_fallback = 0; break; + case 'D': + initflags |= FLAG_UCM_DEFAULTS; + break; case 'r': statefile = optarg; break; @@ -357,7 +362,7 @@ int main(int argc, char *argv[]) snd_lib_error_set_handler(error_handler); if (!strcmp(cmd, "init")) { - res = init(initfile, cardname); + res = init(initfile, initflags, cardname); snd_config_update_free_global(); } else if (!strcmp(cmd, "store")) { res = save_state(cfgfile, cardname); @@ -366,7 +371,7 @@ int main(int argc, char *argv[]) !strcmp(cmd, "nrestore")) { if (removestate) remove(statefile); - res = load_state(cfgfile, initfile, cardname, init_fallback); + res = load_state(cfgfile, initfile, initflags, cardname, init_fallback); if (!strcmp(cmd, "rdaemon")) { do_nice(use_nice, sched_idle); res = state_daemon(cfgfile, cardname, period, pidfile); diff --git a/alsactl/alsactl.h b/alsactl/alsactl.h index 853a701..2352f4c 100644 --- a/alsactl/alsactl.h +++ b/alsactl/alsactl.h @@ -25,13 +25,15 @@ void error_handler(const char *file, int line, const char *function, int err, co #define dbg(args...) do { dbg_(__func__, __LINE__, ##args); } while (0) #endif -int init(const char *file, const char *cardname); -int init_ucm(int cardno); +#define FLAG_UCM_DEFAULTS (1<<0) + +int init(const char *file, int flags, const char *cardname); +int init_ucm(int flags, int cardno); int state_lock(const char *file, int timeout); int state_unlock(int fd, const char *file); int save_state(const char *file, const char *cardname); -int load_state(const char *file, const char *initfile, const char *cardname, - int do_init); +int load_state(const char *file, const char *initfile, int initflags, + const char *cardname, int do_init); int power(const char *argv[], int argc); int monitor(const char *name); int state_daemon(const char *file, const char *cardname, int period, diff --git a/alsactl/init_parse.c b/alsactl/init_parse.c index f176a7a..4ece067 100644 --- a/alsactl/init_parse.c +++ b/alsactl/init_parse.c @@ -1742,7 +1742,7 @@ static int parse(struct space *space, const char *filename) return err ? err : -abs(space->exit_code); } -int init(const char *filename, const char *cardname) +int init(const char *filename, int flags, const char *cardname) { struct space *space; int err = 0, lasterr = 0, card, first; @@ -1762,7 +1762,7 @@ int init(const char *filename, const char *cardname) break; } first = 0; - err = init_ucm(card); + err = init_ucm(flags, card); if (err == 0) continue; err = init_space(&space, card); @@ -1787,7 +1787,7 @@ int init(const char *filename, const char *cardname) error("Cannot find soundcard '%s'...", cardname); goto error; } - err = init_ucm(card); + err = init_ucm(flags, card); if (err == 0) return 0; memset(&space, 0, sizeof(space)); diff --git a/alsactl/init_ucm.c b/alsactl/init_ucm.c index 833a1f9..9c05300 100644 --- a/alsactl/init_ucm.c +++ b/alsactl/init_ucm.c @@ -19,12 +19,14 @@ * */ +#include +#include "alsactl.h" #include /* * Keep it as simple as possible. Execute commands from the SectionOnce only. */ -int init_ucm(int cardno) +int init_ucm(int flags, int cardno) { snd_use_case_mgr_t *uc_mgr; char id[32]; @@ -35,6 +37,14 @@ int init_ucm(int cardno) if (err < 0) return err; err = snd_use_case_set(uc_mgr, "_once", NULL); + if (err < 0) + goto _error; + if ((flags & FLAG_UCM_DEFAULTS) != 0) { + err = snd_use_case_set(uc_mgr, "_defaults", NULL); + if (err < 0) + goto _error; + } +_error: snd_use_case_mgr_close(uc_mgr); return err; } diff --git a/alsactl/state.c b/alsactl/state.c index 22e0269..ea1d3bc 100644 --- a/alsactl/state.c +++ b/alsactl/state.c @@ -1645,8 +1645,8 @@ out: return err; } -int load_state(const char *file, const char *initfile, const char *cardname, - int do_init) +int load_state(const char *file, const char *initfile, int initflags, + const char *cardname, int do_init) { int err, finalerr = 0; snd_config_t *config; @@ -1704,7 +1704,7 @@ single: if (!do_init) break; sprintf(cardname1, "%i", card); - err = init(initfile, cardname1); + err = init(initfile, initflags, cardname1); if (err < 0) { finalerr = err; initfailed(card, "init", err); @@ -1743,7 +1743,7 @@ single: /* do a check if controls matches state file */ if (do_init && set_controls(card, config, 0)) { sprintf(cardname1, "%i", card); - err = init(initfile, cardname1); + err = init(initfile, initflags, cardname1); if (err < 0) { initfailed(card, "init", err); finalerr = err; @@ -1766,7 +1766,7 @@ single: } /* do a check if controls matches state file */ if (do_init && set_controls(cardno, config, 0)) { - err = init(initfile, cardname); + err = init(initfile, initflags, cardname); if (err < 0) { initfailed(cardno, "init", err); finalerr = err;