topology: Parse vendor private data for manifest

In text conf file, user can define a manifest section and let it refer
to private data sections, in the same syntax as other element types.

The text conf file can have at most 1 manifest section.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Mengdong Lin 2016-07-15 20:19:41 +08:00 committed by Takashi Iwai
parent 62c180981b
commit a3683a2ba0
5 changed files with 153 additions and 2 deletions

View file

@ -26,6 +26,10 @@ struct snd_soc_tplg_private *get_priv_data(struct tplg_elem *elem)
struct snd_soc_tplg_private *priv = NULL;
switch (elem->type) {
case SND_TPLG_TYPE_MANIFEST:
priv = &elem->manifest->priv;
break;
case SND_TPLG_TYPE_MIXER:
priv = &elem->mixer_ctrl->priv;
break;
@ -834,6 +838,103 @@ void tplg_free_tuples(void *obj)
free(tuples->set);
}
/* Parse manifest's data references
*/
int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg,
void *private ATTRIBUTE_UNUSED)
{
struct snd_soc_tplg_manifest *manifest;
struct tplg_elem *elem;
snd_config_iterator_t i, next;
snd_config_t *n;
const char *id;
int err;
if (!list_empty(&tplg->manifest_list)) {
SNDERR("error: already has manifest data\n");
return -EINVAL;
}
elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_MANIFEST);
if (!elem)
return -ENOMEM;
manifest = elem->manifest;
manifest->size = elem->size;
tplg_dbg(" Manifest: %s\n", elem->id);
snd_config_for_each(i, next, cfg) {
n = snd_config_iterator_entry(i);
if (snd_config_get_id(n, &id) < 0)
continue;
/* skip comments */
if (strcmp(id, "comment") == 0)
continue;
if (id[0] == '#')
continue;
if (strcmp(id, "data") == 0) {
err = tplg_parse_data_refs(n, elem);
if (err < 0)
return err;
continue;
}
}
return 0;
}
/* merge private data of manifest */
int tplg_build_manifest_data(snd_tplg_t *tplg)
{
struct list_head *base, *pos;
struct tplg_elem *elem = NULL;
struct tplg_ref *ref;
struct snd_soc_tplg_manifest *manifest;
int err = 0;
base = &tplg->manifest_list;
list_for_each(pos, base) {
elem = list_entry(pos, struct tplg_elem, list);
break;
}
if (!elem) /* no manifest data */
return 0;
base = &elem->ref_list;
/* for each ref in this manifest elem */
list_for_each(pos, base) {
ref = list_entry(pos, struct tplg_ref, list);
if (ref->id == NULL || ref->elem)
continue;
if (ref->type == SND_TPLG_TYPE_DATA) {
err = tplg_copy_data(tplg, elem, ref);
if (err < 0)
return err;
}
}
manifest = elem->manifest;
if (!manifest->priv.size) /* no manifest data */
return 0;
tplg->manifest_pdata = malloc(manifest->priv.size);
if (!tplg->manifest_pdata)
return -ENOMEM;
tplg->manifest.priv.size = manifest->priv.size;
memcpy(tplg->manifest_pdata, manifest->priv.data, manifest->priv.size);
return 0;
}
/* Parse Private data.
*
* Object private data can either be from file or defined as bytes, shorts,