mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
topology: add snd_tplg_load() remove snd_tplg_build_bin_file()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
22b66731f3
commit
d52eaba63d
2 changed files with 47 additions and 77 deletions
|
|
@ -783,6 +783,15 @@ snd_tplg_t *snd_tplg_new(void);
|
||||||
*/
|
*/
|
||||||
void snd_tplg_free(snd_tplg_t *tplg);
|
void snd_tplg_free(snd_tplg_t *tplg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Load topology from the text buffer.
|
||||||
|
* \param tplg Topology instance.
|
||||||
|
* \param buf Text buffer.
|
||||||
|
* \param size Text buffer size in bytes.
|
||||||
|
* \return Zero on success, otherwise a negative error code
|
||||||
|
*/
|
||||||
|
int snd_tplg_load(snd_tplg_t *tplg, const char *buf, size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Parse and build topology text file into binary file.
|
* \brief Parse and build topology text file into binary file.
|
||||||
* \param tplg Topology instance.
|
* \param tplg Topology instance.
|
||||||
|
|
@ -793,17 +802,6 @@ void snd_tplg_free(snd_tplg_t *tplg);
|
||||||
int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile,
|
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
|
* \brief Enable verbose reporting of binary file output
|
||||||
* \param tplg Topology Instance
|
* \param tplg Topology Instance
|
||||||
|
|
|
||||||
|
|
@ -259,54 +259,32 @@ static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tplg_load_config(const char *file, snd_config_t **cfg)
|
static int tplg_load_config(snd_tplg_t *tplg, snd_input_t *in)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
|
||||||
snd_input_t *in;
|
|
||||||
snd_config_t *top;
|
snd_config_t *top;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fp = fopen(file, "r");
|
|
||||||
if (fp == NULL) {
|
|
||||||
SNDERR("error: could not open configuration file %s",
|
|
||||||
file);
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = snd_input_stdio_attach(&in, fp, 1);
|
|
||||||
if (ret < 0) {
|
|
||||||
fclose(fp);
|
|
||||||
SNDERR("error: could not attach stdio %s", file);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ret = snd_config_top(&top);
|
ret = snd_config_top(&top);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err;
|
return ret;
|
||||||
|
|
||||||
ret = snd_config_load(top, in);
|
ret = snd_config_load(top, in);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
SNDERR("error: could not load configuration file %s",
|
SNDERR("error: could not load configuration");
|
||||||
file);
|
|
||||||
goto err_load;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = snd_input_close(in);
|
|
||||||
if (ret < 0) {
|
|
||||||
in = NULL;
|
|
||||||
goto err_load;
|
|
||||||
}
|
|
||||||
|
|
||||||
*cfg = top;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err_load:
|
|
||||||
snd_config_delete(top);
|
snd_config_delete(top);
|
||||||
err:
|
|
||||||
if (in)
|
|
||||||
snd_input_close(in);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = tplg_parse_config(tplg, top);
|
||||||
|
snd_config_delete(top);
|
||||||
|
if (ret < 0) {
|
||||||
|
SNDERR("error: failed to parse topology");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int tplg_build_integ(snd_tplg_t *tplg)
|
static int tplg_build_integ(snd_tplg_t *tplg)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
@ -350,28 +328,22 @@ static int tplg_build_integ(snd_tplg_t *tplg)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tplg_load(snd_tplg_t *tplg, const char *infile)
|
int snd_tplg_load(snd_tplg_t *tplg, const char *buf, size_t size)
|
||||||
{
|
{
|
||||||
snd_config_t *cfg = NULL;
|
snd_input_t *in;
|
||||||
int err = 0;
|
int err;
|
||||||
|
|
||||||
err = tplg_load_config(infile, &cfg);
|
err = snd_input_buffer_open(&in, buf, size);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("error: failed to load topology file %s\n",
|
SNDERR("error: could not create input buffer");
|
||||||
infile);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tplg_parse_config(tplg, cfg);
|
err = tplg_load_config(tplg, in);
|
||||||
if (err < 0) {
|
snd_input_close(in);
|
||||||
SNDERR("error: failed to parse topology\n");
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_config_delete(cfg);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tplg_build(snd_tplg_t *tplg)
|
static int tplg_build(snd_tplg_t *tplg)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
@ -394,28 +366,32 @@ int snd_tplg_build_file(snd_tplg_t *tplg,
|
||||||
const char *infile,
|
const char *infile,
|
||||||
const char *outfile)
|
const char *outfile)
|
||||||
{
|
{
|
||||||
|
FILE *fp;
|
||||||
|
snd_input_t *in;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = tplg_load(tplg, infile);
|
fp = fopen(infile, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
SNDERR("error: could not open configuration file %s",
|
||||||
|
infile);
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = snd_input_stdio_attach(&in, fp, 1);
|
||||||
|
if (err < 0) {
|
||||||
|
fclose(fp);
|
||||||
|
SNDERR("error: could not attach stdio %s", infile);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tplg_load_config(tplg, in);
|
||||||
|
snd_input_close(in);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
return snd_tplg_build(tplg, outfile);
|
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)
|
int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
|
||||||
{
|
{
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
|
|
@ -476,10 +452,6 @@ int snd_tplg_build_bin(snd_tplg_t *tplg,
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = tplg_build(tplg);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
err = tplg_build(tplg);
|
err = tplg_build(tplg);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue