host: set up shared library table

Update testbench with a table containing the shared library handles
for all components. Currently, we support only volume and src
components. More component support will be added in future.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
This commit is contained in:
Ranjani Sridharan 2018-06-27 15:09:25 -07:00
parent 2757a2ccd6
commit 03067c6c77
5 changed files with 160 additions and 79 deletions

View File

@ -193,6 +193,34 @@ int tb_pipeline_params(struct ipc *ipc, int nch, char *bits_in,
return ret; return ret;
} }
/* getindex of shared library from table */
int get_index_by_name(char *comp_type,
struct shared_lib_table *lib_table)
{
int i;
for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {
if (!strcmp(comp_type, lib_table[i].comp_name))
return i;
}
return -EINVAL;
}
/* getindex of shared library from table by widget type*/
int get_index_by_type(uint32_t comp_type,
struct shared_lib_table *lib_table)
{
int i;
for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {
if (comp_type == lib_table[i].widget_type)
return i;
}
return -EINVAL;
}
/* The following definitions are to satisfy libsof linker errors */ /* The following definitions are to satisfy libsof linker errors */
struct dai *dai_get(uint32_t type, uint32_t index) struct dai *dai_get(uint32_t type, uint32_t index)

View File

@ -40,6 +40,14 @@
#define TESTBENCH_NCH 2 /* Stereo */ #define TESTBENCH_NCH 2 /* Stereo */
/* shared library look up table */
struct shared_lib_table lib_table[NUM_WIDGETS_SUPPORTED] = {
{"file", "", SND_SOC_TPLG_DAPM_AIF_IN, "", 0, NULL},
{"vol", "libsof_volume.so", SND_SOC_TPLG_DAPM_PGA, "sys_comp_volume_init", 0,
NULL},
{"src", "libsof_src.so", SND_SOC_TPLG_DAPM_SRC, "sys_comp_src_init", 0, NULL},
};
/* main firmware context */ /* main firmware context */
static struct sof sof; static struct sof sof;
static int fr_id; /* comp id for fileread */ static int fr_id; /* comp id for fileread */
@ -50,41 +58,53 @@ int debug;
/* /*
* Parse shared library from user input * Parse shared library from user input
* Currently only handles volume comp * Currently only handles volume and src comp
* This function takes in the libraries to be used as an input in the format:
* "vol=libsof_volume.so,src=libsof_src.so,..."
* The function parses the above string to identify the following:
* component type and the library name and sets up the library handle
* for the component and stores it in the shared library table
*/ */
static void parse_libraries(char *libs, void *handle) static void parse_libraries(char *libs)
{ {
char *lib_token, *comp_token; char *lib_token, *comp_token;
char *token = strtok_r(libs, ",", &lib_token); char *token = strtok_r(libs, ",", &lib_token);
char message[DEBUG_MSG_LEN]; char message[DEBUG_MSG_LEN];
int index;
while (token) { while (token) {
/* get component type */
char *token1 = strtok_r(token, "=", &comp_token); char *token1 = strtok_r(token, "=", &comp_token);
/* parse shared library for volume component */ /* get shared library index from library table */
if (strcmp(token1, "vol") == 0) { index = get_index_by_name(token1, lib_table);
while (token1) {
token1 = strtok_r(NULL, "=", &comp_token);
if (!token1)
return;
/* close shared library object */ if (index < 0) {
if (handle) fprintf(stderr, "error: unsupported comp type\n");
dlclose(handle); break;
/* open volume shared library object */
handle = dlopen(token1, RTLD_LAZY);
if (!handle) {
fprintf(stderr, "error: %s\n",
dlerror());
exit(EXIT_FAILURE);
}
sprintf(message, "opening vol shared lib %s\n",
token1);
debug_print(message);
}
} }
/* get shared library name */
token1 = strtok_r(NULL, "=", &comp_token);
if (!token1)
break;
/* close default shared library object */
if (lib_table[index].handle)
dlclose(lib_table[index].handle);
/* open volume shared library object */
lib_table[index].handle = dlopen(token1, RTLD_LAZY);
if (!lib_table[index].handle) {
fprintf(stderr, "error: %s\n", dlerror());
exit(EXIT_FAILURE);
}
sprintf(message, "opening shared lib %s\n", token1);
debug_print(message);
/* next library */
token = strtok_r(NULL, ",", &lib_token); token = strtok_r(NULL, ",", &lib_token);
} }
} }
@ -131,6 +151,25 @@ static void free_comps(void)
} }
} }
static int set_up_library_table(void)
{
int i;
/* set up default shared libraries */
for (i = 1; i < NUM_WIDGETS_SUPPORTED; i++) {
/* open default shared library */
lib_table[i].handle =
dlopen(lib_table[i].library_name, RTLD_LAZY);
if (!lib_table[i].handle) {
fprintf(stderr, "error: %s\n", dlerror());
return -EINVAL;
}
}
return 0;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct ipc_comp_dev *pcm_dev; struct ipc_comp_dev *pcm_dev;
@ -144,19 +183,14 @@ int main(int argc, char **argv)
clock_t tic, toc; clock_t tic, toc;
double c_realtime, t_exec; double c_realtime, t_exec;
int fs, n_in, n_out, ret; int fs, n_in, n_out, ret;
int option = 0; int i, option = 0;
/* volume component share library handle */
void *vol_handle = NULL;
/* TODO: create a shared library table for all components */ /* set up shared library look up table */
/*set up default volume shared library */ ret = set_up_library_table();
if (!vol_handle) { if (ret < 0) {
vol_handle = dlopen("libsof_volume.so", RTLD_LAZY); fprintf(stderr, "error: setting up shared libraried\n");
if (!vol_handle) { exit(EXIT_FAILURE);
fprintf(stderr, "error: %s\n", dlerror());
exit(EXIT_FAILURE);
}
} }
/* set up trace class definition table from trace header */ /* set up trace class definition table from trace header */
@ -187,7 +221,7 @@ int main(int argc, char **argv)
/* override default libraries */ /* override default libraries */
case 'a': case 'a':
parse_libraries(optarg, vol_handle); parse_libraries(optarg);
break; break;
/* enable debug prints */ /* enable debug prints */
@ -217,7 +251,7 @@ int main(int argc, char **argv)
/* parse topology file and create pipeline */ /* parse topology file and create pipeline */
if (parse_topology(tplg_file, &sof, &fr_id, &fw_id, &sched_id, bits_in, if (parse_topology(tplg_file, &sof, &fr_id, &fw_id, &sched_id, bits_in,
input_file, output_file, vol_handle, pipeline) < 0) { input_file, output_file, lib_table, pipeline) < 0) {
fprintf(stderr, "error: parsing topology\n"); fprintf(stderr, "error: parsing topology\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -290,9 +324,11 @@ int main(int argc, char **argv)
free(tplg_file); free(tplg_file);
free(output_file); free(output_file);
/* close shared library object */ /* close shared library objects */
if (vol_handle) for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {
dlclose(vol_handle); if (lib_table[i].handle)
dlclose(lib_table[i].handle);
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -44,9 +44,10 @@
char *input_file; char *input_file;
char *output_file; char *output_file;
void *volume_lib;
FILE *file; FILE *file;
char pipeline_string[DEBUG_MSG_LEN]; char pipeline_string[DEBUG_MSG_LEN];
struct shared_lib_table *lib_table;
/* /*
* Register component driver * Register component driver
@ -54,37 +55,39 @@ char pipeline_string[DEBUG_MSG_LEN];
*/ */
static void register_comp(int comp_type) static void register_comp(int comp_type)
{ {
static int pga_reg; int index;
static int file_reg; char message[DEBUG_MSG_LEN];
switch (comp_type) { /* register file comp driver (no shared library needed) */
case SND_SOC_TPLG_DAPM_PGA: if (comp_type == SND_SOC_TPLG_DAPM_DAI_IN ||
/* register comp driver if not already registered */ comp_type == SND_SOC_TPLG_DAPM_AIF_IN) {
if (!pga_reg) { if (!lib_table[0].register_drv) {
debug_print("register pga comp driver\n");
/* register volume driver */
void (*sys_comp_volume_init)() =
(void (*)(void))dlsym(volume_lib,
"sys_comp_volume_init");
sys_comp_volume_init();
pga_reg = 1;
}
break;
case SND_SOC_TPLG_DAPM_DAI_IN:
case SND_SOC_TPLG_DAPM_AIF_IN:
/* register comp driver if not already registered */
if (!file_reg) {
debug_print("register file comp driver\n");
/* register file driver */
sys_comp_file_init(); sys_comp_file_init();
file_reg = 1; lib_table[0].register_drv = 1;
debug_print("registered file comp driver\n");
} }
break; return;
default:
break;
} }
/* get index of comp in shared library table */
index = get_index_by_type(comp_type, lib_table);
if (index < 0)
return;
/* register comp driver if not already registered */
if (!lib_table[index].register_drv) {
sprintf(message, "registered comp driver for %s\n",
lib_table[index].comp_name);
debug_print(message);
/* register comp driver */
void (*comp_init)() =
(void (*)(void))dlsym(lib_table[index].handle,
lib_table[index].comp_init);
comp_init();
lib_table[index].register_drv = 1;
}
} }
/* read vendor tuples array from topology */ /* read vendor tuples array from topology */
@ -680,8 +683,9 @@ static int load_widget(struct sof *sof, int *fr_id, int *fw_id,
/* parse topology file and set up pipeline */ /* parse topology file and set up pipeline */
int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id, int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
int *sched_id, char *bits_in, char *in_file, int *sched_id, char *bits_in, char *in_file,
char *out_file, void *volume_library, char *pipeline_msg) char *out_file, struct shared_lib_table *library_table,
char *pipeline_msg)
{ {
struct snd_soc_tplg_hdr *hdr; struct snd_soc_tplg_hdr *hdr;
@ -692,9 +696,6 @@ int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
int i, ret = 0; int i, ret = 0;
size_t file_size, size; size_t file_size, size;
/* set volume library */
volume_lib = volume_library;
/* open topology file */ /* open topology file */
file = fopen(filename, "rb"); file = fopen(filename, "rb");
if (!file) { if (!file) {
@ -702,9 +703,7 @@ int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
return -EINVAL; return -EINVAL;
} }
/* set up fileread and filewrite file names */ lib_table = library_table;
input_file = strdup(in_file);
output_file = strdup(out_file);
/* file size */ /* file size */
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);

View File

@ -43,6 +43,19 @@
#include <sof/audio/format.h> #include <sof/audio/format.h>
#define DEBUG_MSG_LEN 256 #define DEBUG_MSG_LEN 256
#define MAX_LIB_NAME_LEN 256
/* number of widgets types supported in testbench */
#define NUM_WIDGETS_SUPPORTED 3
struct shared_lib_table {
char *comp_name;
char library_name[MAX_LIB_NAME_LEN];
uint32_t widget_type;
const char *comp_init;
int register_drv;
void *handle;
};
extern int debug; extern int debug;
@ -62,4 +75,9 @@ int tb_pipeline_params(struct ipc *ipc, int nch, char *bits_in,
void debug_print(char *message); void debug_print(char *message);
int get_index_by_name(char *comp_name,
struct shared_lib_table *lib_table);
int get_index_by_type(uint32_t comp_type,
struct shared_lib_table *lib_table);
#endif #endif

View File

@ -195,8 +195,8 @@ void sof_parse_word_tokens(void *object,
struct snd_soc_tplg_vendor_array *array); struct snd_soc_tplg_vendor_array *array);
int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id, int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
int *sched_id, char *bits_in, int *sched_id, char *bits_in, char *in_file,
char *in_file, char *out_file, void *volume_library, char *out_file, struct shared_lib_table *library_table,
char *pipeline); char *pipeline_msg);
#endif #endif