]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: Set default include path
authorTakashi Iwai <tiwai@suse.de>
Wed, 28 Nov 2018 15:25:41 +0000 (16:25 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 29 Nov 2018 08:40:10 +0000 (09:40 +0100)
Many UCM profiles include the UCM profile components under ucm/*
subdirectories and thusly put <searchdir:ucm> at each place.  This is
rather cumbersome.

This patch makes the UCM parser to set the default include path, so
that each profile no longer needs to set searchdir.  All the
<searchdir:ucm> lines currently found in the profiles are removed
gracefully, too.

For the needed implementation, a new helper,
_snd_config_load_with_include() is introduced.  It's not exported,
only for the use inside alsa-lib.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
23 files changed:
include/local.h
src/conf.c
src/conf/ucm/PIPO-W2S-Defaultstring-CherryTrailCR/HiFi.conf
src/conf/ucm/bytcr-rt5640-mono-spk-dmic1-mic/HiFi.conf
src/conf/ucm/bytcr-rt5640-mono-spk-in1-mic/HiFi.conf
src/conf/ucm/bytcr-rt5640-mono-spk-in3-mic/HiFi.conf
src/conf/ucm/bytcr-rt5640-stereo-spk-dmic1-mic/HiFi.conf
src/conf/ucm/bytcr-rt5640-stereo-spk-in1-mic/HiFi.conf
src/conf/ucm/bytcr-rt5640-stereo-spk-in3-mic/HiFi.conf
src/conf/ucm/bytcr-rt5640/HiFi.conf
src/conf/ucm/bytcr-rt5651-mono-spk-in1-mic/HiFi.conf
src/conf/ucm/bytcr-rt5651-mono-spk-in2-mic-hp-swapped/HiFi.conf
src/conf/ucm/bytcr-rt5651-mono-spk-in2-mic/HiFi.conf
src/conf/ucm/bytcr-rt5651-stereo-spk-in1-mic/HiFi.conf
src/conf/ucm/bytcr-rt5651-stereo-spk-in12-mic/HiFi.conf
src/conf/ucm/bytcr-rt5651-stereo-spk-in2-mic/HiFi.conf
src/conf/ucm/bytcr-rt5651/HiFi.conf
src/conf/ucm/chtnau8824/HiFi.conf
src/conf/ucm/chtrt5645/HiFi.conf
src/conf/ucm/cube-i1_TF-Defaultstring-CherryTrailCR/HiFi.conf
src/ucm/parser.c
src/ucm/ucm_local.h
src/ucm/utils.c

index b5e7b6f00ff5fa7d4ac1f70256f516c8547d4fc7..03d8f0ccdc5825452a72e83d555780195b5580ea 100644 (file)
@@ -354,6 +354,9 @@ int snd_config_search_alias_hooks(snd_config_t *config,
 
 int _snd_conf_generic_id(const char *id);
 
+int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in,
+                                 const char *default_include_path);
+
 /* convenience macros */
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 
index 254c485868b58342ec56fff995f003b188fc9b88..1f9bad7b3a9796272763d17949bea1680a9839a4 100644 (file)
@@ -1832,7 +1832,8 @@ int snd_config_top(snd_config_t **config)
        return _snd_config_make(config, 0, SND_CONFIG_TYPE_COMPOUND);
 }
 
-static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override)
+static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override,
+                           char *default_include_path)
 {
        int err;
        input_t input;
@@ -1847,6 +1848,11 @@ static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override)
        fd->column = 0;
        fd->next = NULL;
        INIT_LIST_HEAD(&fd->include_paths);
+       if (default_include_path) {
+               err = add_include_path(fd, default_include_path);
+               if (err < 0)
+                       goto _end;
+       }
        input.current = fd;
        input.unget = 0;
        err = parse_defs(config, &input, 0, override);
@@ -1915,9 +1921,29 @@ static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override)
  */
 int snd_config_load(snd_config_t *config, snd_input_t *in)
 {
-       return snd_config_load1(config, in, 0);
+       return snd_config_load1(config, in, 0, NULL);
 }
 
+#ifndef DOC_HIDDEN
+/* load config with the default include path; used internally for UCM parser */
+int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in,
+                                 const char *default_include_path)
+{
+       int err;
+       char *s = NULL;
+
+       if (default_include_path) {
+               s = strdup(default_include_path);
+               if (!s)
+                       return -ENOMEM;
+       }
+       err = snd_config_load1(config, in, 0, s);
+       if (err < 0)
+               free(s);
+       return err;
+}
+#endif
+
 /**
  * \brief Loads a configuration tree and overrides existing configuration nodes.
  * \param config Handle to a top level configuration node.
@@ -1930,7 +1956,7 @@ int snd_config_load(snd_config_t *config, snd_input_t *in)
  */
 int snd_config_load_override(snd_config_t *config, snd_input_t *in)
 {
-       return snd_config_load1(config, in, 1);
+       return snd_config_load1(config, in, 1, NULL);
 }
 
 /**
index facc73ac3b2bfa322091e1acc1501906b2e259d2..b931b7914ce7af6256c24bb5d7d2cd264b0180f7 100644 (file)
@@ -1,4 +1,3 @@
-<searchdir:ucm>
 
 SectionVerb {
 
index c78cdfb80a443b1d1721bd83e2af82eed1ef94b4..0e21d6e1abf95830430a9a1536e7db5cc0a14426 100644 (file)
@@ -1,6 +1,5 @@
 # Use case Configuration for bytcr-rt5640
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 34a5d53d363c6bd7bc0b9e2f501fbb1479d99320..d8ca499a5799fa56d7a8d76c276e2842eb09336b 100644 (file)
@@ -1,6 +1,5 @@
 # Use case Configuration for bytcr-rt5640
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 0aa0c0266412f4a883c4c2753ab122d384c6a5f2..e4fb28df546f588de732321cfd2aa1e42fd944fe 100644 (file)
@@ -1,6 +1,5 @@
 # Use case Configuration for bytcr-rt5640
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index e358d4f23f12b94c214071690ae84b5419f2ee5b..bb31bf5316335c3f8a546523aa94cb5c240e7366 100644 (file)
@@ -1,6 +1,5 @@
 # Use case Configuration for bytcr-rt5640
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 097560d02d120c468b3a4e32313049490e3225dc..9474a64e84fff10d9c1dd9da4d156f5950c90110 100644 (file)
@@ -1,6 +1,5 @@
 # Use case Configuration for bytcr-rt5640
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 8a018f63c9c6201fed8d6dcf228e620527b8852b..478130e67ae4c25c19474bb45db65e262c5d39f3 100644 (file)
@@ -1,6 +1,5 @@
 # Use case Configuration for bytcr-rt5640
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 20ebe2dd36e28dffe4efd8acfddc2b0e0b1248f9..54dd2517dbd7e38aa7a91d0f67c86c7d9430d5ff 100644 (file)
@@ -1,6 +1,5 @@
 # Use case Configuration for bytcr-rt5640
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index ca8a7d9078fb79c8613278b7774eceb70742a730..b93e0be33cbd7fd9df2a825dcd5def34bb978b1e 100644 (file)
@@ -1,6 +1,5 @@
 # Adapted from https://github.com/plbossart/UCM/tree/master/bytcr-rt5651
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 60ef6b332ea2ac34bd7a7a0c93641cdd4470cf76..ef048626732ec95cfcb2b1c9922f19f45458eb54 100644 (file)
@@ -1,6 +1,5 @@
 # Adapted from https://github.com/plbossart/UCM/tree/master/bytcr-rt5651
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index e75210d4aa7e6fbbc2bdeea96abb464bfb049cae..c324c14ad542333cd2b0bf907fb8975d046d6c7a 100644 (file)
@@ -1,6 +1,5 @@
 # Adapted from https://github.com/plbossart/UCM/tree/master/bytcr-rt5651
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 2b7675bce8315b979a857851ea28247010b917fa..aa1a1cde7856249f52845a6ef4f82b494ede5a2f 100644 (file)
@@ -1,6 +1,5 @@
 # Adapted from https://github.com/plbossart/UCM/tree/master/bytcr-rt5651
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 7a8c94bc5d6bc7112bb6273e8f9348cbe8c6fc50..343aed211bb452a45ca2025508cd8fac7958a3dc 100644 (file)
@@ -1,6 +1,5 @@
 # Adapted from https://github.com/plbossart/UCM/tree/master/bytcr-rt5651
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 45c7837c6fb97d8b33c4b33c36dd5eb6da8e2158..6f6d74cf2e68cd9846707f905e9e41622099aea7 100644 (file)
@@ -1,6 +1,5 @@
 # Adapted from https://github.com/plbossart/UCM/tree/master/bytcr-rt5651
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index d3928e9b9976053c9f38ec13907abdedaa7fda1f..fddd8a3ca19ab7c696855d1f86844d8587e8f945 100644 (file)
@@ -1,6 +1,5 @@
 # Adapted from https://github.com/plbossart/UCM/tree/master/bytcr-rt5651
 
-<searchdir:ucm>
 
 SectionVerb {
        EnableSequence [
index 97a7ac7ba366365f9f188fcdea8176666f7ebe5d..845cbcaffe5fd5d5ebe274c3423b7f3e41953db9 100644 (file)
@@ -1,4 +1,3 @@
-<searchdir:ucm>
 
 SectionVerb {
 
index 6a3c6875f301a16ec6720469ba7b1316bba501b5..422f3b7eef4f8515a0138d61eff222dadf82c491 100644 (file)
@@ -1,4 +1,3 @@
-<searchdir:ucm>
 
 SectionVerb {
        # ALSA PCM
index facc73ac3b2bfa322091e1acc1501906b2e259d2..b931b7914ce7af6256c24bb5d7d2cd264b0180f7 100644 (file)
@@ -1,4 +1,3 @@
-<searchdir:ucm>
 
 SectionVerb {
 
index 2b6f1159aa7df6211c36e2caa50da3d2d55be6dc..5e1a8862fac1e81443f4691f73ededde3cab768b 100644 (file)
@@ -34,9 +34,6 @@
 #include <dirent.h>
 #include <limits.h>
 
-/** The name of the environment variable containing the UCM directory */
-#define ALSA_CONFIG_UCM_VAR "ALSA_CONFIG_UCM"
-
 /* Directories to store UCM configuration files for components, like
  * off-soc codecs or embedded DSPs. Components can define their own
  * devices and sequences, to be reused by sound cards/machines. UCM
index ce2fc6ea18eb19ede708d39b4bb46329382662a8..8e7ac7ea48e96a64bca2675c6f75869594846940 100644 (file)
@@ -243,3 +243,6 @@ void uc_mgr_free_sequence_element(struct sequence_element *seq);
 void uc_mgr_free_transition_element(struct transition_sequence *seq);
 void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr);
 void uc_mgr_free(snd_use_case_mgr_t *uc_mgr);
+
+/** The name of the environment variable containing the UCM directory */
+#define ALSA_CONFIG_UCM_VAR "ALSA_CONFIG_UCM"
index 18785488db07d10eb1fca82b46dbab3ae1806c3d..ea5ac5dd1b013ed6328e87ff3fcd7b3708688c62 100644 (file)
@@ -54,6 +54,7 @@ int uc_mgr_config_load(const char *file, snd_config_t **cfg)
        FILE *fp;
        snd_input_t *in;
        snd_config_t *top;
+       const char *default_path;
        int err;
 
        fp = fopen(file, "r");
@@ -70,7 +71,11 @@ int uc_mgr_config_load(const char *file, snd_config_t **cfg)
        err = snd_config_top(&top);
        if (err < 0)
                return err;
-       err = snd_config_load(top, in);
+
+       default_path = getenv(ALSA_CONFIG_UCM_VAR);
+       if (!default_path || !*default_path)
+               default_path = ALSA_CONFIG_DIR "/ucm";
+       err = _snd_config_load_with_include(top, in, default_path);
        if (err < 0) {
                uc_error("could not load configuration file %s", file);
                snd_config_delete(top);