alsa/0039-topology-parser-recode-tplg_parse_config.patch
Takashi Iwai 6ab9f38ea9 Accepting request 766329 from home:tiwai:branches:multimedia:libs
- Backport upstream fixes:
  more topology fixes, a memory leak fix in mixer API, alsactl
  string handling fix, UCM config fixes:
  0032-Update-the-attributes.m4-macro-file-from-xine.patch
  0033-topology-avoid-to-use-the-atoi-directly-when-expecte.patch
  0034-topology-use-snd_config_get_bool-instead-own-impleme.patch
  0035-topology-fix-tplg_get_integer-handle-errno-ERANGE.patch
  0036-topology-add-tplg_get_unsigned-function.patch
  0037-topology-convert-builder-to-use-the-mallocated-memor.patch
  0038-topology-add-binary-output-from-the-builder.patch
  0039-topology-parser-recode-tplg_parse_config.patch
  0040-topology-add-snd_tplg_load-remove-snd_tplg_build_bin.patch
  0041-topology-move-the-topology-element-table-from-builde.patch
  0042-topology-add-parser-to-the-tplg_table.patch
  0043-topology-add-snd_tplg_save.patch
  0044-topology-add-snd_tplg_create-with-flags.patch
  0045-topology-add-snd_tplg_version-function.patch
  0046-topology-cleanup-the-SNDERR-calls.patch
  0047-topology-dapm-fix-the-SNDERR-Undefined.patch
  0048-topology-fix-the-unitialized-tuples.patch
  0049-topology-implement-shorter-hexa-uuid-00-00-parser.patch
  0050-topology-fix-the-TPLG_DEBUG-compilation.patch
  0051-topology-fix-the-ops-parser-accept-integer-hexa-valu.patch
  0052-topology-fix-the-wrong-memory-access-object-realloc.patch
  0053-topology-implement-snd_tplg_decode.patch
  0054-topology-move-the-elem-list-delete-to-tplg_elem_free.patch
  0055-topology-unify-the-log-mechanism.patch
  0056-topology-tplg_dbg-cleanups.patch
  0057-topology-cosmetic-changes-functions.patch
  0058-mixer-Fix-memory-leak-for-more-than-16-file-descript.patch

OBS-URL: https://build.opensuse.org/request/show/766329
OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/alsa?expand=0&rev=265
2020-01-22 14:27:43 +00:00

347 lines
9.1 KiB
Diff

From 22b66731f3dc0eb5149a99ff547eeb84eaf8d54b Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sat, 14 Dec 2019 20:32:24 +0100
Subject: [PATCH 39/63] topology: parser - recode tplg_parse_config()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
src/topology/parser.c | 225 +++++++++++++++++++---------------------------
src/topology/tplg_local.h | 67 ++++----------
2 files changed, 108 insertions(+), 184 deletions(-)
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 861565b734ad..82af7cc518d8 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -142,9 +142,88 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg,
static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg)
{
+ static struct _parser {
+ const char *id;
+ int (*parser)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+ } *p, parsers[] = {
+ {
+ .id = "SectionTLV",
+ .parser = tplg_parse_tlv
+ },
+ {
+ .id = "SectionControlMixer",
+ .parser = tplg_parse_control_mixer
+ },
+ {
+ .id = "SectionControlEnum",
+ .parser = tplg_parse_control_enum
+ },
+ {
+ .id = "SectionControlBytes",
+ .parser = tplg_parse_control_bytes
+ },
+ {
+ .id = "SectionWidget",
+ .parser = tplg_parse_dapm_widget
+ },
+ {
+ .id = "SectionPCMCapabilities",
+ .parser = tplg_parse_stream_caps
+ },
+ {
+ .id = "SectionPCM",
+ .parser = tplg_parse_pcm
+ },
+ {
+ .id = "SectionDAI",
+ .parser = tplg_parse_dai
+ },
+ {
+ .id = "SectionHWConfig",
+ .parser = tplg_parse_hw_config
+ },
+ {
+ .id = "SectionLink",
+ .parser = tplg_parse_link
+ },
+ {
+ .id = "SectionBE",
+ .parser = tplg_parse_link
+ },
+ {
+ .id = "SectionCC",
+ .parser = tplg_parse_cc
+ },
+ {
+ .id = "SectionGraph",
+ .parser = tplg_parse_dapm_graph
+ },
+ {
+ .id = "SectionText",
+ .parser = tplg_parse_text
+ },
+ {
+ .id = "SectionData",
+ .parser = tplg_parse_data
+ },
+ {
+ .id = "SectionVendorTokens",
+ .parser = tplg_parse_tokens
+ },
+ {
+ .id = "SectionVendorTuples",
+ .parser = tplg_parse_tuples
+ },
+ {
+ .id = "SectionManifest",
+ .parser = tplg_parse_manifest_data
+ },
+ };
+ int (*parser)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
snd_config_iterator_t i, next;
snd_config_t *n;
const char *id;
+ unsigned int idx;
int err;
if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) {
@@ -159,145 +238,23 @@ static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg)
if (snd_config_get_id(n, &id) < 0)
continue;
- if (strcmp(id, "SectionTLV") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_tlv,
- NULL);
- if (err < 0)
- return err;
- continue;
+ parser = NULL;
+ for (idx = 0; idx < ARRAY_SIZE(parsers); idx++) {
+ p = &parsers[idx];
+ if (strcmp(id, p->id) == 0) {
+ parser = p->parser;
+ break;
+ }
}
- if (strcmp(id, "SectionControlMixer") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_control_mixer, NULL);
- if (err < 0)
- return err;
+ if (parser == NULL) {
+ SNDERR("error: unknown section %s\n", id);
continue;
}
- if (strcmp(id, "SectionControlEnum") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_control_enum, NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionControlBytes") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_control_bytes, NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionWidget") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_dapm_widget, NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionPCMCapabilities") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_stream_caps, NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionPCM") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_pcm, NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionDAI") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_dai, NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionHWConfig") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_hw_config,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionLink") == 0
- || strcmp(id, "SectionBE") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_link,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionCC") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_cc,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionGraph") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_dapm_graph, NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionText") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_text,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionData") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_data,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionVendorTokens") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_tokens,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionVendorTuples") == 0) {
- err = tplg_parse_compound(tplg, n, tplg_parse_tuples,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- if (strcmp(id, "SectionManifest") == 0) {
- err = tplg_parse_compound(tplg, n,
- tplg_parse_manifest_data,
- NULL);
- if (err < 0)
- return err;
- continue;
- }
-
- SNDERR("error: unknown section %s\n", id);
+ err = tplg_parse_compound(tplg, n, parser, NULL);
+ if (err < 0)
+ return err;
}
return 0;
}
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 87e6c9a517de..77a681897a85 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -202,59 +202,26 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg,
int tplg_write_data(snd_tplg_t *tplg);
-int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
+int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_control_bytes(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_control_mixer(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_dapm_widget(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_stream_caps(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_link(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_cc(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
void tplg_free_tuples(void *obj);
-int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_control_bytes(snd_tplg_t *tplg,
- snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_control_mixer(snd_tplg_t *tplg,
- snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_dapm_widget(snd_tplg_t *tplg,
- snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_stream_caps(snd_tplg_t *tplg,
- snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_pcm(snd_tplg_t *tplg,
- snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_link(snd_tplg_t *tplg,
- snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_cc(snd_tplg_t *tplg,
- snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
- void *private ATTRIBUTE_UNUSED);
-
int tplg_build_data(snd_tplg_t *tplg);
int tplg_build_manifest_data(snd_tplg_t *tplg);
int tplg_build_controls(snd_tplg_t *tplg);
--
2.16.4