From 603d9cb4332d2e53ab35b36494989761a729dac6 Mon Sep 17 00:00:00 2001 From: Adrian Bonislawski Date: Fri, 13 Dec 2019 13:32:26 +0100 Subject: [PATCH] mux: using channel map as mux configuration Previous sof_mux_config will be deleted along with global frame_format and num_channels for mux. Mux will obtain format data from buffer params. Signed-off-by: Adrian Bonislawski --- src/audio/mux/mux.c | 119 +++++++++++------------ src/audio/mux/mux_generic.c | 68 ++++++------- src/include/sof/audio/mux.h | 16 +-- test/cmocka/src/audio/mux/CMakeLists.txt | 1 + test/cmocka/src/audio/mux/demux_copy.c | 38 +++++--- test/cmocka/src/audio/mux/mux_copy.c | 38 +++++--- test/cmocka/src/audio/mux/mux_prepare.c | 25 ++++- test/cmocka/src/audio/mux/util.h | 17 ++++ 8 files changed, 175 insertions(+), 147 deletions(-) diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 23679b762a1c..90bf0520c1d6 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -9,6 +9,7 @@ #if CONFIG_COMP_MUX +#include #include #include #include @@ -28,54 +29,58 @@ #include #include -static int mux_set_values(struct comp_data *cd, struct sof_mux_config *cfg) +static int mux_set_values(struct comp_data *cd, struct sof_ipc_stream_map *cfg) { - uint8_t i; - uint8_t j; - - /* check if number of streams configured doesn't exceed maximum */ - if (cfg->num_streams > MUX_MAX_STREAMS) { - trace_mux_error("mux_set_values() error: configured number of " - "streams (%u) exceeds maximum = " - META_QUOTE(MUX_MAX_STREAMS), - cfg->num_streams); - return -EINVAL; + struct mux_stream_data streams[MUX_MAX_STREAMS]; + struct sof_ipc_channel_map *ch_map; + uint32_t used_streams = 0; + uint32_t i, j; + + memset(&streams, 0, sizeof(struct mux_stream_data) * MUX_MAX_STREAMS); + + for (i = 0; i < cfg->num_ch_map; i++) { + ch_map = chmap_get(cfg, i); + + /* check if there is already a stream for this ext_id */ + for (j = 0; j < used_streams; j++) + if (ch_map->ext_id == streams[j].pipeline_id) + break; + + if (j == used_streams) + used_streams++; + + if (used_streams > MUX_MAX_STREAMS) { + trace_mux_error("mux_set_values() error: configured number of streams (%u) exceeds maximum = " + META_QUOTE(MUX_MAX_STREAMS), + used_streams); + return -EINVAL; + } + + /* for each stream */ + streams[j].pipeline_id = ch_map->ext_id; + /* save channel mask for one in/out channel */ + streams[j].mask[ch_map->ch_index] = ch_map->ch_mask; } /* check if all streams configured have distinct IDs */ - for (i = 0; i < cfg->num_streams; i++) { - for (j = i + 1; j < cfg->num_streams; j++) { - if (cfg->streams[i].pipeline_id == - cfg->streams[j].pipeline_id) { + for (i = 0; i < used_streams; i++) { + for (j = i + 1; j < used_streams; j++) { + if (streams[i].pipeline_id == + streams[j].pipeline_id) { trace_mux_error("mux_set_values() error: " "multiple configured streams " "have same pipeline ID = %u", - cfg->streams[i].pipeline_id); + streams[i].pipeline_id); return -EINVAL; } } } - /* check if number of channels per stream doesn't exceed maximum */ - for (i = 0; i < cfg->num_streams; i++) { - if (cfg->streams[i].num_channels > PLATFORM_MAX_CHANNELS) { - trace_mux_error("mux_set_values() error: configured " - "number of channels for stream %u " - "exceeds platform maximum = " - META_QUOTE(PLATFORM_MAX_CHANNELS), - i); - return -EINVAL; - } - } - - cd->config.num_channels = cfg->num_channels; - cd->config.frame_format = cfg->frame_format; + for (i = 0; i < used_streams; i++) { + cd->streams[i].pipeline_id = streams[i].pipeline_id; - for (i = 0; i < cfg->num_streams; i++) { - cd->config.streams[i].num_channels = cfg->streams[i].num_channels; - cd->config.streams[i].pipeline_id = cfg->streams[i].pipeline_id; - for (j = 0; j < cfg->streams[i].num_channels; j++) - cd->config.streams[i].mask[j] = cfg->streams[i].mask[j]; + for (j = 0; j < PLATFORM_MAX_CHANNELS; j++) + cd->streams[i].mask[j] = streams[i].mask[j]; } return 0; @@ -103,9 +108,8 @@ static struct comp_dev *mux_new(struct sof_ipc_comp *comp) return NULL; memcpy(&dev->comp, comp, sizeof(struct sof_ipc_comp_process)); + cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, - sizeof(*cd) + MUX_MAX_STREAMS * sizeof(struct mux_stream_data)); if (!cd) { rfree(dev); return NULL; @@ -113,17 +117,15 @@ static struct comp_dev *mux_new(struct sof_ipc_comp *comp) comp_set_drvdata(dev, cd); - memcpy_s(&cd->config, sizeof(struct sof_mux_config) + - MUX_MAX_STREAMS * sizeof(struct mux_stream_data), - ipc_process->data, bs); - /* verification of initial parameters */ - ret = mux_set_values(cd, &cd->config); + if (bs >= sizeof(struct sof_ipc_stream_map)) { + ret = mux_set_values(cd, (struct sof_ipc_stream_map *)&ipc_process->data); - if (ret < 0) { - rfree(cd); - rfree(dev); - return NULL; + if (ret < 0) { + rfree(cd); + rfree(dev); + return NULL; + } } dev->state = COMP_STATE_READY; @@ -144,17 +146,8 @@ static void mux_free(struct comp_dev *dev) static int mux_params(struct comp_dev *dev, struct sof_ipc_stream_params *params) { - struct comp_data *cd = comp_get_drvdata(dev); - struct comp_buffer *sinkb; - trace_mux_with_ids(dev, "mux_params()"); - sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, - source_list); - - cd->config.num_channels = sinkb->channels; - cd->config.frame_format = sinkb->frame_fmt; - return 0; } @@ -162,7 +155,7 @@ static int mux_ctrl_set_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) { struct comp_data *cd = comp_get_drvdata(dev); - struct sof_mux_config *cfg; + struct sof_ipc_stream_map *cfg; int ret = 0; trace_mux_with_ids(dev, "mux_ctrl_set_cmd(), cdata->cmd = 0x%08x", @@ -170,8 +163,7 @@ static int mux_ctrl_set_cmd(struct comp_dev *dev, switch (cdata->cmd) { case SOF_CTRL_CMD_BINARY: - cfg = (struct sof_mux_config *)cdata->data->data; - + cfg = (struct sof_ipc_stream_map *)cdata->data->data; ret = mux_set_values(cd, cfg); break; default: @@ -188,7 +180,7 @@ static int mux_ctrl_get_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata, int size) { struct comp_data *cd = comp_get_drvdata(dev); - struct sof_mux_config *cfg = &cd->config; + struct mux_stream_data *cfg = &cd->streams[0]; uint32_t reply_size; int ret = 0; @@ -197,8 +189,7 @@ static int mux_ctrl_get_cmd(struct comp_dev *dev, switch (cdata->cmd) { case SOF_CTRL_CMD_BINARY: /* calculate config size */ - reply_size = sizeof(struct sof_mux_config) + cfg->num_streams * - sizeof(struct mux_stream_data); + reply_size = sizeof(struct mux_stream_data) * MUX_MAX_STREAMS; /* copy back to user space */ assert(!memcpy_s(cdata->data->data, ((struct sof_abi_hdr *) @@ -240,7 +231,7 @@ static uint8_t get_stream_index(struct comp_data *cd, uint32_t pipe_id) int i; for (i = 0; i < MUX_MAX_STREAMS; i++) { - if (cd->config.streams[i].pipeline_id == pipe_id) + if (cd->streams[i].pipeline_id == pipe_id) return i; } trace_mux_error("get_stream_index() error: couldn't find configuration " @@ -303,7 +294,7 @@ static int demux_copy(struct comp_dev *dev) if (!sinks[i]) continue; - cd->demux(dev, sinks[i], source, frames, &cd->config.streams[i]); + cd->demux(dev, sinks[i], source, frames, &cd->streams[i]); } /* update components */ @@ -369,7 +360,7 @@ static int mux_copy(struct comp_dev *dev) sink_bytes = frames * buffer_frame_bytes(sink); /* produce output */ - cd->mux(dev, sink, &sources[0], frames, &cd->config.streams[0]); + cd->mux(dev, sink, &sources[0], frames, &cd->streams[0]); /* update components */ comp_update_buffer_produce(sink, sink_bytes); diff --git a/src/audio/mux/mux_generic.c b/src/audio/mux/mux_generic.c index 9ba2a4efa35f..35aa75c51228 100644 --- a/src/audio/mux/mux_generic.c +++ b/src/audio/mux/mux_generic.c @@ -64,22 +64,21 @@ static void demux_s16le(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames, struct mux_stream_data *data) { - struct comp_data *cd = comp_get_drvdata(dev); int32_t sample; int16_t *dst; uint8_t i; uint8_t out_ch; for (i = 0; i < frames; i++) { - for (out_ch = 0; out_ch < data->num_channels; out_ch++) { + for (out_ch = 0; out_ch < sink->channels; out_ch++) { sample = calc_sample_s16le(source, - cd->config.num_channels, - i * cd->config.num_channels, + source->channels, + i * source->channels, data->mask[out_ch]); /* saturate to 16 bits */ dst = buffer_write_frag_s16(sink, - i * data->num_channels + out_ch); + i * sink->channels + out_ch); *dst = sat_int16(sample); } } @@ -103,7 +102,6 @@ static void mux_s16le(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer **sources, uint32_t frames, struct mux_stream_data *data) { - struct comp_data *cd = comp_get_drvdata(dev); struct comp_buffer *source; uint8_t i; uint8_t j; @@ -112,7 +110,7 @@ static void mux_s16le(struct comp_dev *dev, struct comp_buffer *sink, int32_t sample; for (i = 0; i < frames; i++) { - for (out_ch = 0; out_ch < cd->config.num_channels; out_ch++) { + for (out_ch = 0; out_ch < sink->channels; out_ch++) { sample = 0; for (j = 0; j < MUX_MAX_STREAMS; j++) { @@ -121,12 +119,12 @@ static void mux_s16le(struct comp_dev *dev, struct comp_buffer *sink, continue; sample += calc_sample_s16le(source, - data[j].num_channels, - i * data[j].num_channels, + source->channels, + i * source->channels, data[j].mask[out_ch]); } dst = buffer_write_frag_s16(sink, - i * data->num_channels + out_ch); + i * sink->channels + out_ch); *dst = sat_int16(sample); } } @@ -179,22 +177,21 @@ static void demux_s24le(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames, struct mux_stream_data *data) { - struct comp_data *cd = comp_get_drvdata(dev); int32_t sample; int32_t *dst; uint8_t i; uint8_t out_ch; for (i = 0; i < frames; i++) { - for (out_ch = 0; out_ch < data->num_channels; out_ch++) { + for (out_ch = 0; out_ch < sink->channels; out_ch++) { sample = calc_sample_s24le(source, - cd->config.num_channels, - i * cd->config.num_channels, + source->channels, + i * source->channels, data->mask[out_ch]); /* saturate to 24 bits */ dst = buffer_write_frag_s32(sink, - i * data->num_channels + out_ch); + i * sink->channels + out_ch); *dst = sat_int24(sample); } } @@ -218,7 +215,6 @@ static void mux_s24le(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer **sources, uint32_t frames, struct mux_stream_data *data) { - struct comp_data *cd = comp_get_drvdata(dev); struct comp_buffer *source; uint8_t i; uint8_t j; @@ -227,7 +223,7 @@ static void mux_s24le(struct comp_dev *dev, struct comp_buffer *sink, int32_t sample; for (i = 0; i < frames; i++) { - for (out_ch = 0; out_ch < cd->config.num_channels; out_ch++) { + for (out_ch = 0; out_ch < sink->channels; out_ch++) { sample = 0; for (j = 0; j < MUX_MAX_STREAMS; j++) { source = sources[j]; @@ -235,12 +231,12 @@ static void mux_s24le(struct comp_dev *dev, struct comp_buffer *sink, continue; sample += calc_sample_s24le(source, - data[j].num_channels, - i * data[j].num_channels, + source->channels, + i * source->channels, data[j].mask[out_ch]); } dst = buffer_write_frag_s32(sink, - i * data->num_channels + out_ch); + i * sink->channels + out_ch); *dst = sat_int24(sample); } } @@ -293,22 +289,21 @@ static void demux_s32le(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames, struct mux_stream_data *data) { - struct comp_data *cd = comp_get_drvdata(dev); int64_t sample; int32_t *dst; uint8_t i; uint8_t out_ch; for (i = 0; i < frames; i++) { - for (out_ch = 0; out_ch < data->num_channels; out_ch++) { + for (out_ch = 0; out_ch < sink->channels; out_ch++) { sample = calc_sample_s32le(source, - cd->config.num_channels, - i * cd->config.num_channels, + source->channels, + i * source->channels, data->mask[out_ch]); /* saturate to 32 bits */ dst = buffer_write_frag_s32(sink, - i * data->num_channels + out_ch); + i * sink->channels + out_ch); *dst = sat_int32(sample); } } @@ -332,7 +327,6 @@ static void mux_s32le(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer **sources, uint32_t frames, struct mux_stream_data *data) { - struct comp_data *cd = comp_get_drvdata(dev); struct comp_buffer *source; uint8_t i; uint8_t j; @@ -341,7 +335,7 @@ static void mux_s32le(struct comp_dev *dev, struct comp_buffer *sink, int64_t sample; for (i = 0; i < frames; i++) { - for (out_ch = 0; out_ch < cd->config.num_channels; out_ch++) { + for (out_ch = 0; out_ch < sink->channels; out_ch++) { sample = 0; for (j = 0; j < MUX_MAX_STREAMS; j++) { source = sources[j]; @@ -349,12 +343,12 @@ static void mux_s32le(struct comp_dev *dev, struct comp_buffer *sink, continue; sample += calc_sample_s32le(source, - data[j].num_channels, - i * data[j].num_channels, + source->channels, + i * source->channels, data[j].mask[out_ch]); } dst = buffer_write_frag_s32(sink, - i * data->num_channels + out_ch); + i * sink->channels + out_ch); *dst = sat_int32(sample); } } @@ -376,11 +370,14 @@ const struct comp_func_map mux_func_map[] = { mux_func mux_get_processing_function(struct comp_dev *dev) { - struct comp_data *cd = comp_get_drvdata(dev); + struct comp_buffer *sinkb; uint8_t i; + sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, + source_list); + for (i = 0; i < ARRAY_SIZE(mux_func_map); i++) { - if (cd->config.frame_format == mux_func_map[i].frame_format) + if (sinkb->frame_fmt == mux_func_map[i].frame_format) return mux_func_map[i].mux_proc_func; } @@ -389,11 +386,14 @@ mux_func mux_get_processing_function(struct comp_dev *dev) demux_func demux_get_processing_function(struct comp_dev *dev) { - struct comp_data *cd = comp_get_drvdata(dev); + struct comp_buffer *sinkb; uint8_t i; + sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, + source_list); + for (i = 0; i < ARRAY_SIZE(mux_func_map); i++) { - if (cd->config.frame_format == mux_func_map[i].frame_format) + if (sinkb->frame_fmt == mux_func_map[i].frame_format) return mux_func_map[i].demux_proc_func; } diff --git a/src/include/sof/audio/mux.h b/src/include/sof/audio/mux.h index a91a005e5cf8..b31ce9be8df4 100644 --- a/src/include/sof/audio/mux.h +++ b/src/include/sof/audio/mux.h @@ -18,6 +18,7 @@ #if CONFIG_COMP_MUX +#include #include #include #include @@ -55,10 +56,7 @@ STATIC_ASSERT(MUX_MAX_STREAMS < PLATFORM_MAX_STREAMS, struct mux_stream_data { uint32_t pipeline_id; - uint8_t num_channels; uint8_t mask[PLATFORM_MAX_CHANNELS]; - - uint8_t reserved[(20 - PLATFORM_MAX_CHANNELS - 1) % 4]; // padding to ensure proper alignment of following instances }; typedef void(*demux_func)(struct comp_dev *dev, struct comp_buffer *sink, @@ -68,23 +66,13 @@ typedef void(*mux_func)(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer **sources, uint32_t frames, struct mux_stream_data *data); -struct sof_mux_config { - uint16_t frame_format; - uint16_t num_channels; - uint16_t num_streams; - - uint16_t reserved; // padding to ensure proper alignment - - struct mux_stream_data streams[]; -}; - struct comp_data { union { mux_func mux; demux_func demux; }; - struct sof_mux_config config; + struct mux_stream_data streams[MUX_MAX_STREAMS]; }; struct comp_func_map { diff --git a/test/cmocka/src/audio/mux/CMakeLists.txt b/test/cmocka/src/audio/mux/CMakeLists.txt index 8ebe1baa9d84..020da44cc644 100644 --- a/test/cmocka/src/audio/mux/CMakeLists.txt +++ b/test/cmocka/src/audio/mux/CMakeLists.txt @@ -12,6 +12,7 @@ add_library( ${PROJECT_SOURCE_DIR}/src/audio/mux/mux.c ${PROJECT_SOURCE_DIR}/src/audio/mux/mux_generic.c ${PROJECT_SOURCE_DIR}/src/audio/component.c + ${PROJECT_SOURCE_DIR}/src/audio/channel_map.c ) sof_append_relative_path_definitions(audio_mux) diff --git a/test/cmocka/src/audio/mux/demux_copy.c b/test/cmocka/src/audio/mux/demux_copy.c index 5038be0e6db0..d5e6768ec31f 100644 --- a/test/cmocka/src/audio/mux/demux_copy.c +++ b/test/cmocka/src/audio/mux/demux_copy.c @@ -91,28 +91,36 @@ static int setup_group(void **state) static struct sof_ipc_comp_process *create_demux_comp_ipc(struct test_data *td) { size_t ipc_size = sizeof(struct sof_ipc_comp_process); - size_t mux_size = sizeof(struct sof_mux_config) - + MUX_MAX_STREAMS * sizeof(struct mux_stream_data); + size_t mux_size = get_stream_map_size(td->mask); struct sof_ipc_comp_process *ipc = calloc(1, ipc_size + mux_size); - struct sof_mux_config *mux = (struct sof_mux_config *)&ipc->data; + struct sof_ipc_stream_map *stream_map = (struct sof_ipc_stream_map *)&ipc->data; + struct sof_ipc_channel_map *chmap; + char *w_ptr = (char *)&stream_map->ch_map; int i, j; - ipc->comp.hdr.size = sizeof(struct sof_ipc_comp_process); - ipc->comp.type = SOF_COMP_DEMUX; - ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); - ipc->size = mux_size; - - mux->frame_format = td->format; - mux->num_channels = PLATFORM_MAX_CHANNELS; - mux->num_streams = MUX_MAX_STREAMS; + stream_map->num_ch_map = 0; + /* for all streams */ for (i = 0; i < MUX_MAX_STREAMS; ++i) { - mux->streams[i].pipeline_id = i; - mux->streams[i].num_channels = PLATFORM_MAX_CHANNELS; - for (j = 0; j < PLATFORM_MAX_CHANNELS; ++j) - mux->streams[i].mask[j] = td->mask[i][j]; + /* generate a channel map for each channel */ + for (j = 0; j < PLATFORM_MAX_CHANNELS; ++j) { + chmap = (struct sof_ipc_channel_map *)w_ptr; + + chmap->ch_index = j; + chmap->ext_id = i; + chmap->ch_mask = td->mask[i][j]; + + stream_map->num_ch_map++; + w_ptr += sizeof(*chmap) + (popcount(chmap->ch_mask) * + sizeof(*chmap->ch_coeffs)); + } } + ipc->comp.hdr.size = sizeof(struct sof_ipc_comp_process); + ipc->comp.type = SOF_COMP_DEMUX; + ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); + ipc->size = w_ptr - (char *)stream_map; + return ipc; } diff --git a/test/cmocka/src/audio/mux/mux_copy.c b/test/cmocka/src/audio/mux/mux_copy.c index d072409398c4..244bcf0ab1da 100644 --- a/test/cmocka/src/audio/mux/mux_copy.c +++ b/test/cmocka/src/audio/mux/mux_copy.c @@ -103,28 +103,36 @@ static int setup_group(void **state) static struct sof_ipc_comp_process *create_mux_comp_ipc(struct test_data *td) { size_t ipc_size = sizeof(struct sof_ipc_comp_process); - size_t mux_size = sizeof(struct sof_mux_config) - + MUX_MAX_STREAMS * sizeof(struct mux_stream_data); + size_t mux_size = get_stream_map_size(td->mask); struct sof_ipc_comp_process *ipc = calloc(1, ipc_size + mux_size); - struct sof_mux_config *mux = (struct sof_mux_config *)&ipc->data; + struct sof_ipc_stream_map *stream_map = (struct sof_ipc_stream_map *)&ipc->data; + struct sof_ipc_channel_map *chmap; + char *w_ptr = (char *)&stream_map->ch_map; int i, j; - ipc->comp.hdr.size = sizeof(struct sof_ipc_comp_process); - ipc->comp.type = SOF_COMP_MUX; - ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); - ipc->size = mux_size; - - mux->frame_format = td->format; - mux->num_channels = PLATFORM_MAX_CHANNELS; - mux->num_streams = MUX_MAX_STREAMS; + stream_map->num_ch_map = 0; + /* for all streams */ for (i = 0; i < MUX_MAX_STREAMS; ++i) { - mux->streams[i].pipeline_id = i; - mux->streams[i].num_channels = PLATFORM_MAX_CHANNELS; - for (j = 0; j < PLATFORM_MAX_CHANNELS; ++j) - mux->streams[i].mask[j] = td->mask[i][j]; + /* generate a channel map for each channel */ + for (j = 0; j < PLATFORM_MAX_CHANNELS; ++j) { + chmap = (struct sof_ipc_channel_map *)w_ptr; + + chmap->ch_index = j; + chmap->ext_id = i; + chmap->ch_mask = td->mask[i][j]; + + stream_map->num_ch_map++; + w_ptr += sizeof(*chmap) + (popcount(chmap->ch_mask) * + sizeof(*chmap->ch_coeffs)); + } } + ipc->comp.hdr.size = sizeof(struct sof_ipc_comp_process); + ipc->comp.type = SOF_COMP_MUX; + ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); + ipc->size = w_ptr - (char *)stream_map; + return ipc; } diff --git a/test/cmocka/src/audio/mux/mux_prepare.c b/test/cmocka/src/audio/mux/mux_prepare.c index 82bc071ec753..1656ec187377 100644 --- a/test/cmocka/src/audio/mux/mux_prepare.c +++ b/test/cmocka/src/audio/mux/mux_prepare.c @@ -5,6 +5,8 @@ // Author: Daniel Bogdzia // Janusz Jankowski +#include "util.h" + #include #include @@ -18,6 +20,7 @@ struct test_data { struct comp_dev *dev; struct comp_data *cd; + struct comp_buffer *sink; }; static int setup_group(void **state) @@ -60,6 +63,7 @@ static int teardown_test_case(void **state) { struct test_data *td = *state; + free_test_sink(td->sink); comp_free(td->dev); free(td); @@ -71,8 +75,10 @@ static void test_mux_prepare_invalid_float(void **state) { struct test_data *td = *state; - /* set frame format value to unsupported value */ - td->cd->config.frame_format = SOF_IPC_FRAME_FLOAT; + td->sink = create_test_sink(td->dev, + MUX_MAX_STREAMS + 1, + SOF_IPC_FRAME_FLOAT, + PLATFORM_MAX_CHANNELS); assert_int_equal(comp_prepare(td->dev), -EINVAL); } @@ -83,7 +89,10 @@ static void test_mux_prepare_valid_s16le(void **state) { struct test_data *td = *state; - td->cd->config.frame_format = SOF_IPC_FRAME_S16_LE; + td->sink = create_test_sink(td->dev, + MUX_MAX_STREAMS + 1, + SOF_IPC_FRAME_S16_LE, + PLATFORM_MAX_CHANNELS); assert_int_equal(comp_prepare(td->dev), 0); } @@ -94,7 +103,10 @@ static void test_mux_prepare_valid_s24_4le(void **state) { struct test_data *td = *state; - td->cd->config.frame_format = SOF_IPC_FRAME_S24_4LE; + td->sink = create_test_sink(td->dev, + MUX_MAX_STREAMS + 1, + SOF_IPC_FRAME_S24_4LE, + PLATFORM_MAX_CHANNELS); assert_int_equal(comp_prepare(td->dev), 0); } @@ -105,7 +117,10 @@ static void test_mux_prepare_valid_s32le(void **state) { struct test_data *td = *state; - td->cd->config.frame_format = SOF_IPC_FRAME_S32_LE; + td->sink = create_test_sink(td->dev, + MUX_MAX_STREAMS + 1, + SOF_IPC_FRAME_S32_LE, + PLATFORM_MAX_CHANNELS); assert_int_equal(comp_prepare(td->dev), 0); } diff --git a/test/cmocka/src/audio/mux/util.h b/test/cmocka/src/audio/mux/util.h index b46aeeb6f960..375859c3bfa5 100644 --- a/test/cmocka/src/audio/mux/util.h +++ b/test/cmocka/src/audio/mux/util.h @@ -67,3 +67,20 @@ static inline void free_test_source(struct comp_buffer *buffer) free(buffer->source); free(buffer); } + +static inline size_t get_stream_map_size(uint8_t mask[][PLATFORM_MAX_CHANNELS]) +{ + size_t size = 0; + int i, j; + + /* Stream map size depends on ch_coeffs flexible array */ + for (i = 0; i < MUX_MAX_STREAMS; ++i) { + for (j = 0; j < PLATFORM_MAX_CHANNELS; ++j) { + /* mask bit count describes flexible array size */ + size += sizeof(struct sof_ipc_channel_map) + + (popcount(mask[i][j]) * + sizeof(((struct sof_ipc_channel_map *)0)->ch_coeffs[0])); + } + } + return sizeof(struct sof_ipc_stream_map) + size; +}