]> git.alsa-project.org Git - alsa-lib.git/commitdiff
topology: Add element ID so we can look up references by name.
authorJin Yao <yao.jin@linux.intel.com>
Tue, 4 Aug 2015 17:09:12 +0000 (18:09 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 5 Aug 2015 06:05:56 +0000 (08:05 +0200)
Add support to lookup elements by name. This is in preparation for adding
some new API calls that will allow building topology data using a C API. This
will allow applications to build their own topology data directly.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Signed-off-by: Mengdong Lin <mengdong.lin@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/topology/ctl.c
src/topology/dapm.c
src/topology/data.c
src/topology/elem.c
src/topology/pcm.c
src/topology/text.c
src/topology/tplg_local.h

index 9c1333c1fc88ebc9f6b92814cef981c7a13f1c9b..aa06ff64bc48f4d90784b7c09bef64172c45fa27 100644 (file)
@@ -264,7 +264,7 @@ int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg,
        int err = 0;
        struct tplg_elem *elem;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_TLV);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_TLV);
        if (!elem)
                return -ENOMEM;
 
@@ -298,7 +298,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg,
        const char *id, *val = NULL;
        int err;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_BYTES);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_BYTES);
        if (!elem)
                return -ENOMEM;
 
@@ -403,11 +403,10 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg,
        const char *id, *val = NULL;
        int err, j;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_ENUM);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_ENUM);
        if (!elem)
                return -ENOMEM;
 
-       /* init new mixer */
        ec = elem->enum_ctrl;
        elem_copy_text(ec->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
        ec->hdr.type = SND_SOC_TPLG_TYPE_ENUM;
@@ -501,7 +500,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg,
        const char *id, *val = NULL;
        int err, j;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_MIXER);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_MIXER);
        if (!elem)
                return -ENOMEM;
 
index 1da82adea4703d867dce4d21e5781641e4921dd4..7e26ea0326ec67425504c922dc8c85da0f51ce62 100644 (file)
@@ -420,7 +420,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg,
        const char *id, *val = NULL;
        int widget_type, err;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_DAPM_WIDGET);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_DAPM_WIDGET);
        if (!elem)
                return -ENOMEM;
 
index 13e1e2bb60fb8185d90e54eff362811d9935afce..c768bc5b0b045e3ba358ab43fe12c5a03d6b610e 100644 (file)
@@ -268,7 +268,7 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg,
        int err = 0;
        struct tplg_elem *elem;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_DATA);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_DATA);
        if (!elem)
                return -ENOMEM;
 
index d7a1fd715d49652aabe352b93d46386b98bccc46..7fee6533212473beeae0b2b1be4b53c0adf4ae9c 100644 (file)
@@ -103,20 +103,27 @@ struct tplg_elem *tplg_elem_lookup(struct list_head *base, const char* id,
 
 /* create a new common element and object */
 struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
-       snd_config_t *cfg, enum object_type type)
+       snd_config_t *cfg, const char *name, enum object_type type)
 {
        struct tplg_elem *elem;
        const char *id;
        int obj_size = 0;
        void *obj;
 
+       if (!cfg && !name)
+               return NULL;
+
        elem = tplg_elem_new();
        if (!elem)
                return NULL;
 
-       snd_config_get_id(cfg, &id);
-       strncpy(elem->id, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
-       elem->id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0;
+       /* do we get name from cfg */
+       if (cfg) {
+               snd_config_get_id(cfg, &id);
+               elem_copy_text(elem->id, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
+               elem->id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0;
+       } else if (name != NULL)
+               elem_copy_text(elem->id, name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
 
        switch (type) {
        case OBJECT_TYPE_DATA:
index 8f23a6f12ec47202d79391ec78ffe6ed7dae9bc6..deae47b771be4ea6cdb8db4e15f9ec08aa64a78e 100644 (file)
@@ -228,7 +228,7 @@ int tplg_parse_pcm_config(snd_tplg_t *tplg,
        const char *id;
        int err;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_STREAM_CONFIG);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_STREAM_CONFIG);
        if (!elem)
                return -ENOMEM;
 
@@ -294,7 +294,7 @@ int tplg_parse_pcm_caps(snd_tplg_t *tplg,
        char *s;
        int err;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_STREAM_CAPS);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_STREAM_CAPS);
        if (!elem)
                return -ENOMEM;
 
@@ -461,7 +461,7 @@ int tplg_parse_pcm(snd_tplg_t *tplg,
        const char *id, *val = NULL;
        int err;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_PCM);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_PCM);
        if (!elem)
                return -ENOMEM;
 
@@ -524,7 +524,7 @@ int tplg_parse_be(snd_tplg_t *tplg,
        const char *id, *val = NULL;
        int err;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_BE);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_BE);
        if (!elem)
                return -ENOMEM;
 
@@ -587,7 +587,7 @@ int tplg_parse_cc(snd_tplg_t *tplg,
        const char *id, *val = NULL;
        int err;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_CC);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_CC);
        if (!elem)
                return -ENOMEM;
 
index ebb6e3840d6261730d11be4ea48486aee9171c4d..7128056d5d345eef079f8085b263e0a47f6ff16e 100644 (file)
@@ -64,7 +64,7 @@ int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg,
        int err = 0;
        struct tplg_elem *elem;
 
-       elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_TEXT);
+       elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_TEXT);
        if (!elem)
                return -ENOMEM;
 
index 688c78f3a6a48a967235179a98db7c52966cd7ac..62788e4b7ca10751474db19ea0f764109ba6e51b 100644 (file)
@@ -216,7 +216,7 @@ struct tplg_elem *tplg_elem_lookup(struct list_head *base,
                                const char* id,
                                unsigned int type);
 struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
-       snd_config_t *cfg, enum object_type type);
+       snd_config_t *cfg, const char *name, enum object_type type);
 
 static inline void elem_copy_text(char *dest, const char *src, int len)
 {