alsa/0038-topology-add-binary-output-from-the-builder.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

174 lines
4.3 KiB
Diff

From bee8d4fcaa52d00950d035ec561513c2b9e7cac7 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sat, 14 Dec 2019 19:20:02 +0100
Subject: [PATCH 38/63] topology: add binary output from the builder
- snd_tplg_build_bin()
- snd_tplg_build_bin_file()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
include/topology.h | 22 +++++++++++++-
src/topology/parser.c | 79 ++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 87 insertions(+), 14 deletions(-)
diff --git a/include/topology.h b/include/topology.h
index 27da7308dd62..c9ef554a610f 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -791,7 +791,18 @@ void snd_tplg_free(snd_tplg_t *tplg);
* \return Zero on success, otherwise a negative error code
*/
int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile,
- const char *outfile);
+ const char *outfile);
+
+/**
+ * \brief Parse and build topology text file into binary file.
+ * \param tplg Topology instance.
+ * \param infile Topology text input file to be parsed
+ * \param bin Binary topology output buffer (malloc).
+ * \param size Binary topology output buffer size in bytes.
+ * \return Zero on success, otherwise a negative error code
+ */
+int snd_tplg_build_bin_file(snd_tplg_t *tplg, const char *infile,
+ void **bin, size_t *size);
/**
* \brief Enable verbose reporting of binary file output
@@ -1089,6 +1100,15 @@ int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
*/
int snd_tplg_build(snd_tplg_t *tplg, const char *outfile);
+/**
+ * \brief Build all registered topology data into memory.
+ * \param tplg Topology instance.
+ * \param bin Binary topology output buffer (malloc).
+ * \param size Binary topology output buffer size in bytes.
+ * \return Zero on success, otherwise a negative error code
+ */
+int snd_tplg_build_bin(snd_tplg_t *tplg, void **bin, size_t *size);
+
/**
* \brief Attach private data to topology manifest.
* \param tplg Topology instance.
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 98a9f9e9deac..861565b734ad 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -393,9 +393,7 @@ static int tplg_build_integ(snd_tplg_t *tplg)
return err;
}
-int snd_tplg_build_file(snd_tplg_t *tplg,
- const char *infile,
- const char *outfile)
+static int tplg_load(snd_tplg_t *tplg, const char *infile)
{
snd_config_t *cfg = NULL;
int err = 0;
@@ -414,10 +412,53 @@ int snd_tplg_build_file(snd_tplg_t *tplg,
}
snd_config_delete(cfg);
+ return 0;
+}
+
+static int tplg_build(snd_tplg_t *tplg)
+{
+ int err;
+
+ err = tplg_build_integ(tplg);
+ if (err < 0) {
+ SNDERR("error: failed to check topology integrity\n");
+ return err;
+ }
+
+ err = tplg_write_data(tplg);
+ if (err < 0) {
+ SNDERR("error: failed to write data %d\n", err);
+ return err;
+ }
+ return 0;
+}
+
+int snd_tplg_build_file(snd_tplg_t *tplg,
+ const char *infile,
+ const char *outfile)
+{
+ int err;
+
+ err = tplg_load(tplg, infile);
+ if (err < 0)
+ return err;
return snd_tplg_build(tplg, outfile);
}
+int snd_tplg_build_bin_file(snd_tplg_t *tplg,
+ const char *infile,
+ void **bin, size_t *size)
+{
+ int err;
+
+ err = tplg_load(tplg, infile);
+ if (err < 0)
+ return err;
+
+ return snd_tplg_build_bin(tplg, bin, size);
+}
+
int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
{
switch (t->type) {
@@ -450,17 +491,9 @@ int snd_tplg_build(snd_tplg_t *tplg, const char *outfile)
int fd, err;
ssize_t r;
- err = tplg_build_integ(tplg);
- if (err < 0) {
- SNDERR("error: failed to check topology integrity\n");
- return err;
- }
-
- err = tplg_write_data(tplg);
- if (err < 0) {
- SNDERR("error: failed to write data %d\n", err);
+ err = tplg_build(tplg);
+ if (err < 0)
return err;
- }
fd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd < 0) {
@@ -481,6 +514,26 @@ int snd_tplg_build(snd_tplg_t *tplg, const char *outfile)
return 0;
}
+int snd_tplg_build_bin(snd_tplg_t *tplg,
+ void **bin, size_t *size)
+{
+ int err;
+
+ err = tplg_build(tplg);
+ if (err < 0)
+ return err;
+
+ err = tplg_build(tplg);
+ if (err < 0)
+ return err;
+
+ *bin = tplg->bin;
+ *size = tplg->bin_size;
+ tplg->bin = NULL;
+ tplg->bin_size = tplg->bin_pos = 0;
+ return 0;
+}
+
int snd_tplg_set_manifest_data(snd_tplg_t *tplg, const void *data, int len)
{
if (len <= 0)
--
2.16.4