Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 123 additions & 3 deletions src/audio/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,61 @@
#include <sof/lock.h>
#include <sof/list.h>
#include <sof/stream.h>
#include <sof/ipc.h>
#include <sof/audio/component.h>

/* tracing */
#define trace_mux(__e) trace_event(TRACE_CLASS_MUX, __e)
#define trace_mux_error(__e) trace_error(TRACE_CLASS_MUX, __e)
#define tracev_mux(__e) tracev_event(TRACE_CLASS_MUX, __e)

struct mux_data {
uint32_t period_bytes;
uint32_t mux_value[SOF_IPC_MAX_CHANNELS];
};

static struct comp_dev *mux_new(struct sof_ipc_comp *comp)
{
struct comp_dev *dev;
struct sof_ipc_comp_mux *mux;
struct sof_ipc_comp_mux *ipc_mux =
(struct sof_ipc_comp_mux *)comp;
struct mux_data *md;

trace_mux("mux_new()");

return NULL;
if (IPC_IS_SIZE_INVALID(ipc_mux->config)) {
IPC_SIZE_ERROR_TRACE(TRACE_CLASS_MUX, ipc_mux->config);
return NULL;
}

dev = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM,
COMP_SIZE(struct sof_ipc_comp_mux));
if (!dev)
return NULL;

mux = (struct sof_ipc_comp_mux *)&dev->comp;
memcpy(mux, ipc_mux, sizeof(struct sof_ipc_comp_mux));

md = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(*md));
if (!md) {
rfree(dev);
return NULL;
}

comp_set_drvdata(dev, md);
dev->state = COMP_STATE_READY;
return dev;
}

static void mux_free(struct comp_dev *dev)
{
struct mux_data *md = comp_get_drvdata(dev);

trace_mux("mux_free()");

rfree(md);
rfree(dev);
}

/* set component audio stream parameters */
Expand All @@ -59,12 +97,94 @@ static int mux_params(struct comp_dev *dev)
return 0;
}

/**
* \brief Sets mux control command.
* \param[in,out] dev mux base component device.
* \param[in,out] cdata Control command data.
* \return Error code.
*/
static int mux_ctrl_set_cmd(struct comp_dev *dev,
struct sof_ipc_ctrl_data *cdata)
{
struct mux_data *cd = comp_get_drvdata(dev);
int j;

/* validate */
if (cdata->num_elems == 0 || cdata->num_elems > SOF_IPC_MAX_CHANNELS) {
trace_mux_error("mux_ctrl_set_cmd() error: "
"invalid cdata->num_elems");
return -EINVAL;
}

switch (cdata->cmd) {
case SOF_CTRL_CMD_ENUM:
/*FIXME: fix logger for mux */
trace_mux("mux_ctrl_set_cmd(), SOF_CTRL_CMD_ENUM, ");

/* save enum value state */
for (j = 0; j < cdata->num_elems; j++)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is stored in num_elements when for cmd == SOF_CMD_ENUM ? is it a number of parameters and each chanv[j].value represents enum value of parameter[0..num_elements] ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its the number of channel elements to be changed.

cd->mux_value[j] = cdata->chanv[j].value;

break;

default:
trace_mux_error("invalid cdata->cmd");
return -EINVAL;
}

return 0;
}

/**
* \brief Gets mux control command.
* \param[in,out] dev mux base component device.
* \param[in,out] cdata Control command data.
* \return Error code.
*/
static int mux_ctrl_get_cmd(struct comp_dev *dev,
struct sof_ipc_ctrl_data *cdata, int size)
{
struct mux_data *cd = comp_get_drvdata(dev);
int j;

/* validate */
if (cdata->num_elems == 0 || cdata->num_elems > SOF_IPC_MAX_CHANNELS) {
trace_mux_error("invalid cdata->num_elems");
return -EINVAL;
}

if (cdata->cmd == SOF_CTRL_CMD_ENUM) {
trace_mux("mux_ctrl_get_cmd(), SOF_CTRL_CMD_ENUM");

/* copy current enum value */
for (j = 0; j < cdata->num_elems; j++) {
cdata->chanv[j].channel = j;
cdata->chanv[j].value = cd->mux_value[j];
}
} else {
trace_mux_error("invalid cdata->cmd");
return -EINVAL;
}

return 0;
}

/* used to pass standard and bespoke commands (with data) to component */
static int mux_cmd(struct comp_dev *dev, int cmd, void *data,
int max_data_size)
{
/* mux will use buffer "connected" status */
return 0;
struct sof_ipc_ctrl_data *cdata = data;

trace_mux("mux_cmd()");

switch (cmd) {
case COMP_CMD_SET_VALUE:
return mux_ctrl_set_cmd(dev, cdata);
case COMP_CMD_GET_VALUE:
return mux_ctrl_get_cmd(dev, cdata, max_data_size);
default:
return -EINVAL;
}
}

/* copy and process stream data from source to sink buffers */
Expand Down