Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions tools/plugin/alsaplug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target_include_directories(asound_module_pcm_sof PRIVATE
${sof_source_directory}/src/audio)

target_compile_options(asound_module_pcm_sof PRIVATE -DPIC -g -O3 -Wmissing-prototypes
-Wimplicit-fallthrough -DCONFIG_LIBRARY -imacros${config_h})
-Wno-stringop-truncation -Wimplicit-fallthrough -DCONFIG_LIBRARY -imacros${config_h})

install(TARGETS asound_module_pcm_sof DESTINATION /usr/lib/x86_64-linux-gnu/alsa-lib)

Expand Down Expand Up @@ -49,7 +49,7 @@ target_include_directories(asound_module_ctl_sof PRIVATE
${sof_source_directory}/src/audio)

target_compile_options(asound_module_ctl_sof PRIVATE -DPIC -g -O3 -Wmissing-prototypes
-Wimplicit-fallthrough -Wall -Werror -DCONFIG_LIBRARY -imacros${config_h})
-Wimplicit-fallthrough -Wno-stringop-truncation -Wall -Werror -DCONFIG_LIBRARY -imacros${config_h})

install(TARGETS asound_module_ctl_sof DESTINATION /usr/lib/x86_64-linux-gnu/alsa-lib)

Expand Down
72 changes: 31 additions & 41 deletions tools/plugin/alsaplug/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
typedef struct snd_sof_ctl {
struct plug_shm_glb_state *glb;
snd_ctl_ext_t ext;
struct plug_mq_desc ipc_tx;
struct plug_mq_desc ipc_rx;
struct plug_socket_desc ipc;
struct plug_shm_desc shm_ctx;
int subscribed;
int updated[MAX_CTLS];
Expand Down Expand Up @@ -232,8 +231,7 @@ static int plug_ctl_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long

/* send the IPC message */
memcpy(msg, &config, sizeof(config));
err = plug_mq_cmd_tx_rx(&ctl->ipc_tx, &ctl->ipc_rx,
msg, size, reply_data, reply_data_size);
err = plug_ipc_cmd_tx_rx(&ctl->ipc, msg, size, reply_data, reply_data_size);
free(msg);
if (err < 0) {
SNDERR("failed to set volume for control %s\n", mixer_ctl->hdr.name);
Expand Down Expand Up @@ -325,8 +323,7 @@ static int plug_ctl_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, lon
memcpy(msg + sizeof(config), &volume, sizeof(volume));

/* send the message and check status */
err = plug_mq_cmd_tx_rx(&ctl->ipc_tx, &ctl->ipc_rx,
msg, size, &reply, sizeof(reply));
err = plug_ipc_cmd_tx_rx(&ctl->ipc, msg, size, &reply, sizeof(reply));
free(msg);
if (err < 0) {
SNDERR("failed to set volume control %s\n", mixer_ctl->hdr.name);
Expand Down Expand Up @@ -426,8 +423,7 @@ static int plug_ctl_read_enumerated(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,

/* send the IPC message */
memcpy(msg, &config, sizeof(config));
err = plug_mq_cmd_tx_rx(&ctl->ipc_tx, &ctl->ipc_rx,
msg, size, reply_data, reply_data_size);
err = plug_ipc_cmd_tx_rx(&ctl->ipc, msg, size, reply_data, reply_data_size);
free(msg);
if (err < 0) {
SNDERR("failed to get enum items for control %s\n", enum_ctl->hdr.name);
Expand Down Expand Up @@ -516,7 +512,7 @@ static int plug_ctl_write_enumerated(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
free(data);

/* send the message and check status */
err = plug_mq_cmd_tx_rx(&ctl->ipc_tx, &ctl->ipc_rx, msg, msg_size, &reply, sizeof(reply));
err = plug_ipc_cmd_tx_rx(&ctl->ipc, msg, msg_size, &reply, sizeof(reply));
free(msg);
if (err < 0) {
SNDERR("failed to set enum control %s\n", enum_ctl->hdr.name);
Expand Down Expand Up @@ -573,8 +569,7 @@ static int plug_ctl_get_bytes_data(snd_sof_ctl_t *ctl, snd_ctl_ext_key_t key,

/* send the IPC message */
memcpy(msg, &config, sizeof(config));
err = plug_mq_cmd_tx_rx(&ctl->ipc_tx, &ctl->ipc_rx,
msg, size, reply_data, reply_data_size);
err = plug_ipc_cmd_tx_rx(&ctl->ipc, msg, size, reply_data, reply_data_size);
free(msg);
if (err < 0) {
SNDERR("failed to get bytes data for control %s\n", bytes_ctl->hdr.name);
Expand Down Expand Up @@ -633,9 +628,8 @@ static int plug_ctl_write_bytes(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
int err;

/* send IPC with kcontrol data */
err = plug_send_bytes_data(&ctl->ipc_tx, &ctl->ipc_rx,
ctl->glb->ctl[key].module_id, ctl->glb->ctl[key].instance_id,
abi);
err = plug_send_bytes_data(&ctl->ipc, ctl->glb->ctl[key].module_id,
ctl->glb->ctl[key].instance_id, abi);
if (err < 0) {
SNDERR("failed to set bytes data for control %s\n", bytes_ctl->hdr.name);
return err;
Expand All @@ -644,6 +638,7 @@ static int plug_ctl_write_bytes(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
return 0;
}

/* TLV ops used for TLV bytes control callback */
/* TLV ops used for TLV bytes control callback */
static int plug_tlv_rw(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int op_flag,
unsigned int numid, unsigned int *tlv, unsigned int tlv_size)
Expand All @@ -653,12 +648,26 @@ static int plug_tlv_rw(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int op_flag,
struct sof_abi_hdr *abi = (struct sof_abi_hdr *)(tlv + 2); /* skip TLV header */
int data_size;

/* only bytes and volume controls have tlv callback set */
if (bytes_ctl->hdr.ops.info != SND_SOC_TPLG_CTL_BYTES) {
struct snd_soc_tplg_mixer_control *mixer_ctl = CTL_GET_TPLG_MIXER(ctl, key);
struct snd_soc_tplg_ctl_hdr *hdr = &mixer_ctl->hdr;
struct snd_soc_tplg_ctl_tlv *mixer_tlv = &hdr->tlv;

/* set the dbscale values */
tlv[0] = SND_CTL_TLVT_DB_SCALE;
tlv[1] = sizeof(int) * 2;
tlv[2] = mixer_tlv->scale.min;
tlv[3] = mixer_tlv->scale.mute << 16 | mixer_tlv->scale.step;

return 0;
}

/* send IPC with kcontrol data if op_flag is > 0 else send IPC to get kcontrol data */
if (op_flag) {
int err;

err = plug_send_bytes_data(&ctl->ipc_tx, &ctl->ipc_rx,
ctl->glb->ctl[key].module_id,
err = plug_send_bytes_data(&ctl->ipc, ctl->glb->ctl[key].module_id,
ctl->glb->ctl[key].instance_id, abi);
if (err < 0) {
SNDERR("failed to set bytes data for control %s\n", bytes_ctl->hdr.name);
Expand Down Expand Up @@ -731,6 +740,7 @@ static void plug_ctl_close(snd_ctl_ext_t *ext)
snd_sof_ctl_t *ctl = ext->private_data;

/* TODO: munmap */
close(ctl->ipc.socket_fd);
free(ctl);
}

Expand Down Expand Up @@ -777,34 +787,17 @@ SND_CTL_PLUGIN_DEFINE_FUNC(sof)
goto error;
}

/* init IPC tx message queue name */
err = plug_mq_init(&ctl->ipc_tx, "sof", "ipc-tx", 0);
/* init IPC socket name */
err = plug_socket_path_init(&ctl->ipc, "sof", "ipc", 0);
if (err < 0) {
SNDERR("error: invalid name for IPC tx mq %s\n", plug->tplg_file);
goto error;
}

/* open the sof-pipe IPC tx message queue */
err = plug_mq_open(&ctl->ipc_tx);
if (err < 0) {
SNDERR("error: failed to open sof-pipe IPC mq %s: %s",
ctl->ipc_tx.queue_name, strerror(err));
goto error;
}

/* init IPC rx message queue name */
err = plug_mq_init(&ctl->ipc_rx, "sof", "ipc-rx", 0);
if (err < 0) {
SNDERR("error: invalid name for IPC rx mq %s\n", plug->tplg_file);
goto error;
}

/* open the sof-pipe IPC rx message queue */
err = plug_mq_open(&ctl->ipc_rx);
err = plug_create_client_socket(&ctl->ipc);
if (err < 0) {
SNDERR("error: failed to open sof-pipe IPC mq %s: %s",
ctl->ipc_rx.queue_name, strerror(err));
goto error;
SNDERR("failed to connect to SOF pipe IPC socket : %s", strerror(err));
return -errno;
}

/* create a SHM mapping for low latency stream position */
Expand All @@ -831,9 +824,6 @@ SND_CTL_PLUGIN_DEFINE_FUNC(sof)
strncpy(ctl->ext.mixername, "SOF",
sizeof(ctl->ext.mixername) - 1);

/* polling on message queue - supported on Linux but not portable */
ctl->ext.poll_fd = ctl->ipc_tx.mq;

ctl->ext.callback = &sof_ext_callback;
ctl->ext.private_data = ctl;
ctl->ext.tlv.c = plug_tlv_rw;
Expand Down
79 changes: 12 additions & 67 deletions tools/plugin/alsaplug/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#include <sys/poll.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <semaphore.h>
Expand Down Expand Up @@ -42,10 +43,6 @@ typedef struct snd_sof_pcm {
/* PCM flow control */
struct plug_sem_desc ready[TPLG_MAX_PCM_PIPELINES];
struct plug_sem_desc done[TPLG_MAX_PCM_PIPELINES];
/* pipeline IPC tx queues */
struct plug_mq_desc pipeline_ipc_tx[TPLG_MAX_PCM_PIPELINES];
/* pipeline IPC response queues */
struct plug_mq_desc pipeline_ipc_rx[TPLG_MAX_PCM_PIPELINES];

struct plug_shm_desc shm_pcm;

Expand All @@ -55,15 +52,15 @@ typedef struct snd_sof_pcm {
static int plug_pipeline_set_state(snd_sof_plug_t *plug, int state,
struct ipc4_pipeline_set_state *pipe_state,
struct tplg_pipeline_info *pipe_info,
struct plug_mq_desc *ipc_tx, struct plug_mq_desc *ipc_rx)
struct plug_socket_desc *ipc)
{
struct ipc4_message_reply reply = {{ 0 }};
int ret;

pipe_state->primary.r.ppl_id = pipe_info->instance_id;

ret = plug_mq_cmd_tx_rx(ipc_tx, ipc_rx, pipe_state, sizeof(*pipe_state),
&reply, sizeof(reply));
ret = plug_ipc_cmd_tx_rx(ipc, pipe_state, sizeof(*pipe_state),
&reply, sizeof(reply));
if (ret < 0)
SNDERR("failed pipeline %d set state %d\n", pipe_info->instance_id, state);

Expand Down Expand Up @@ -97,8 +94,7 @@ static int plug_pipelines_set_state(snd_sof_plug_t *plug, int state)
int ret;

ret = plug_pipeline_set_state(plug, state, &pipe_state, pipe_info,
&pcm->pipeline_ipc_tx[i],
&pcm->pipeline_ipc_rx[i]);
&plug->ipc);
if (ret < 0)
return ret;
}
Expand All @@ -111,7 +107,7 @@ static int plug_pipelines_set_state(snd_sof_plug_t *plug, int state)
int ret;

ret = plug_pipeline_set_state(plug, state, &pipe_state, pipe_info,
&pcm->pipeline_ipc_tx[i], &pcm->pipeline_ipc_rx[i]);
&plug->ipc);
if (ret < 0)
return ret;
}
Expand Down Expand Up @@ -482,38 +478,6 @@ static int plug_pcm_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params)
for (i = 0; i < pipeline_list->count; i++) {
struct tplg_pipeline_info *pipe_info = pipeline_list->pipelines[i];

/* init IPC message queue name */
err = plug_mq_init(&pcm->pipeline_ipc_tx[i], plug->tplg_file, "pcm-tx",
pipe_info->instance_id);
if (err < 0) {
SNDERR("error: invalid name for pipeline IPC mq %s\n", plug->tplg_file);
return err;
}

/* open the sof-pipe IPC message queue */
err = plug_mq_open(&pcm->pipeline_ipc_tx[i]);
if (err < 0) {
SNDERR("error: failed to open sof-pipe IPC mq %s: %s",
pcm->pipeline_ipc_tx[i].queue_name, strerror(err));
return -errno;
}

/* init IPC message queue name */
err = plug_mq_init(&pcm->pipeline_ipc_rx[i], plug->tplg_file, "pcm-rx",
pipe_info->instance_id);
if (err < 0) {
SNDERR("error: invalid name for pipeline IPC mq %s\n", plug->tplg_file);
return err;
}

/* open the sof-pipe IPC message queue */
err = plug_mq_open(&pcm->pipeline_ipc_rx[i]);
if (err < 0) {
SNDERR("error: failed to open sof-pipe IPC mq %s: %s",
pcm->pipeline_ipc_tx[i].queue_name, strerror(err));
return -errno;
}

/* init name for pipeline ready lock */
err = plug_lock_init(&pcm->ready[i], plug->tplg_file, "ready",
pipe_info->instance_id);
Expand Down Expand Up @@ -671,20 +635,17 @@ static int plug_pcm_hw_free(snd_pcm_ioplug_t *io)
pipeline_list = &plug->pcm_info->playback_pipeline_list;

ret = plug_free_pipelines(plug, pipeline_list, pcm->capture);
if (ret < 0)
return ret;

close(pcm->shm_pcm.fd);
close(plug->glb_ctx.fd);

for (i = 0; i < pipeline_list->count; i++) {
struct tplg_pipeline_info *pipe_info = pipeline_list->pipelines[i];

mq_close(pcm->pipeline_ipc_tx[pipe_info->instance_id].mq);
mq_close(pcm->pipeline_ipc_rx[pipe_info->instance_id].mq);
sem_close(pcm->ready[pipe_info->instance_id].sem);
sem_close(pcm->done[pipe_info->instance_id].sem);
}
close(plug->ipc.socket_fd);

return 0;
}
Expand Down Expand Up @@ -957,31 +918,15 @@ static int plug_init_sof_pipe(snd_sof_plug_t *plug, snd_pcm_t **pcmp,
fprintf(stdout, "topology parsing complete\n");

/* init IPC message queue name */
err = plug_mq_init(&plug->ipc_tx, "sof", "ipc-tx", 0);
if (err < 0) {
SNDERR("error: invalid name for IPC mq %s\n", plug->tplg_file);
return err;
}

/* open the sof-pipe IPC message queue */
err = plug_mq_open(&plug->ipc_tx);
if (err < 0) {
SNDERR("error: failed to open sof-pipe IPC mq %s: %s",
plug->ipc_tx.queue_name, strerror(err));
return -errno;
}

err = plug_mq_init(&plug->ipc_rx, "sof", "ipc-rx", 0);
err = plug_socket_path_init(&plug->ipc, "sof", "ipc", 0);
if (err < 0) {
SNDERR("error: invalid name for IPC mq %s\n", plug->tplg_file);
SNDERR("error: invalid name for IPC socket %s\n", plug->tplg_file);
return err;
}

/* open the sof-pipe IPC message queue */
err = plug_mq_open(&plug->ipc_rx);
err = plug_create_client_socket(&plug->ipc);
if (err < 0) {
SNDERR("error: failed to open sof-pipe IPC mq %s: %s",
plug->ipc_rx.queue_name, strerror(err));
SNDERR("failed to connect to SOF pipe IPC socket : %s", strerror(err));
return -errno;
}

Expand Down
22 changes: 0 additions & 22 deletions tools/plugin/alsaplug/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <semaphore.h>
Expand All @@ -41,27 +40,6 @@
#include "plugin.h"
#include "common.h"

int plug_mq_cmd(struct plug_mq_desc *ipc, void *msg, size_t len, void *reply, size_t rlen)
{
return plug_mq_cmd_tx_rx(ipc, ipc, msg, len, reply, rlen);
}

/*
* Open an existing message queue using IPC object.
*/
int plug_mq_open(struct plug_mq_desc *ipc)
{
/* now open new queue for Tx and Rx */
ipc->mq = mq_open(ipc->queue_name, O_RDWR);
if (ipc->mq < 0) {
// SNDERR("failed to open IPC queue %s: %s\n",
// ipc->queue_name, strerror(errno));
return -errno;
}

return 0;
}

/*
* Open an existing semaphore using lock object.
*/
Expand Down
3 changes: 1 addition & 2 deletions tools/plugin/alsaplug/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ typedef struct snd_sof_plug {
struct list_item pcm_list;
struct list_item pipeline_list;
int instance_ids[SND_SOC_TPLG_DAPM_LAST];
struct plug_mq_desc ipc_tx;
struct plug_mq_desc ipc_rx;
struct plug_socket_desc ipc;

struct plug_shm_desc glb_ctx;

Expand Down
Loading