Skip to content

Commit 485c939

Browse files
committed
src: codec_adapter: Add process passthrough path
If the passthrough flag is enabled, on process() the data in the input buffer should be directly copied to the output buffer. The passthrough flag is implemented to be set/get by topology enum control. Signed-off-by: Pin-chih Lin <johnylin@google.com>
1 parent ebe28dd commit 485c939

5 files changed

Lines changed: 137 additions & 2 deletions

File tree

src/audio/codec_adapter/codec/generic.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ int codec_prepare(struct comp_dev *dev)
245245
return ret;
246246
}
247247

248+
static int process_passthrough(struct comp_dev *dev)
249+
{
250+
int ret;
251+
struct codec_data *codec = comp_get_codec(dev);
252+
253+
ret = memcpy_s(codec->cpd.out_buff, codec->cpd.avail, codec->cpd.in_buff, codec->cpd.avail);
254+
if (ret) {
255+
comp_err(dev, "process_through() error %d: failed to copy data from in to out",
256+
ret);
257+
codec->cpd.produced = 0;
258+
return ret;
259+
}
260+
codec->cpd.produced = codec->cpd.avail;
261+
return 0;
262+
}
263+
248264
int codec_process(struct comp_dev *dev)
249265
{
250266
int ret;
@@ -260,7 +276,12 @@ int codec_process(struct comp_dev *dev)
260276
return -EPERM;
261277
}
262278

263-
ret = codec->ops->process(dev);
279+
// TODO: how to set cd->passthrough flag?
280+
if (cd->passthrough) {
281+
ret = process_passthrough(dev);
282+
} else {
283+
ret = codec->ops->process(dev);
284+
}
264285
if (ret) {
265286
comp_err(dev, "codec_prepare() error %d: codec process failed for codec_id %x",
266287
ret, codec_id);

src/audio/codec_adapter/codec_adapter.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ DECLARE_SOF_RT_UUID("codec_adapter", ca_uuid, 0xd8218443, 0x5ff3, 0x4a4c,
3030

3131
DECLARE_TR_CTX(ca_tr, SOF_UUID(ca_uuid), LOG_LEVEL_INFO);
3232

33+
#define ENUM_CTRL_PASSTHROUGH 0
34+
3335
/**
3436
* \brief Create a codec adapter component.
3537
* \param[in] drv - component driver pointer.
@@ -91,6 +93,7 @@ static struct comp_dev *codec_adapter_new(const struct comp_driver *drv,
9193

9294
dev->state = COMP_STATE_READY;
9395
cd->state = PP_STATE_CREATED;
96+
cd->passthrough = 0;
9497

9598
comp_cl_info(&comp_codec_adapter, "codec_adapter_new() done");
9699
return dev;
@@ -620,6 +623,89 @@ static int codec_adapter_ctrl_set_data(struct comp_dev *dev,
620623
return ret;
621624
}
622625

626+
static int codec_adapter_ctrl_enum_set(struct sof_ipc_ctrl_data *cdata, struct comp_data *cd)
627+
{
628+
int ret;
629+
630+
switch (cdata->index) {
631+
case ENUM_CTRL_PASSTHROUGH:
632+
if (cdata->num_elems)
633+
cd->passthrough = cdata->chanv[0].value;
634+
break;
635+
default:
636+
comp_cl_err(&comp_codec_adapter,
637+
"codec_adapter_ctrl_enum_set() error: invalid index=%d",
638+
cdata->index);
639+
ret = -EINVAL;
640+
break;
641+
}
642+
643+
return ret;
644+
}
645+
646+
static int codec_adapter_set_value(struct comp_dev *dev,
647+
struct sof_ipc_ctrl_data *cdata)
648+
{
649+
int ret;
650+
struct comp_data *cd = comp_get_drvdata(dev);
651+
652+
switch (cdata->cmd) {
653+
case SOF_CTRL_CMD_ENUM:
654+
comp_dbg(dev, "codec_adapter_set_value(): SOF_CTRL_CMD_ENUM index=%d",
655+
cdata->index);
656+
ret = codec_adapter_ctrl_enum_set(cdata, cd);
657+
break;
658+
default:
659+
comp_err(dev, "codec_adapter_set_value() error: invalid cdata->cmd");
660+
ret = -EINVAL;
661+
break;
662+
}
663+
664+
return ret;
665+
}
666+
667+
static int codec_adapter_ctrl_enum_get(struct sof_ipc_ctrl_data *cdata, struct comp_data *cd)
668+
{
669+
int ret;
670+
int j;
671+
672+
switch (cdata->index) {
673+
case ENUM_CTRL_PASSTHROUGH:
674+
for (j = 0; j < cdata->num_elems; j++)
675+
cdata->chanv[j].value = cd->passthrough;
676+
break;
677+
default:
678+
comp_cl_err(&comp_codec_adapter,
679+
"codec_adapter_ctrl_enum_get() error: invalid index=%d",
680+
cdata->index);
681+
ret = -EINVAL;
682+
break;
683+
}
684+
685+
return ret;
686+
}
687+
688+
static int codec_adapter_get_value(struct comp_dev *dev,
689+
struct sof_ipc_ctrl_data *cdata)
690+
{
691+
int ret;
692+
struct comp_data *cd = comp_get_drvdata(dev);
693+
694+
switch (cdata->cmd) {
695+
case SOF_CTRL_CMD_ENUM:
696+
comp_dbg(dev, "codec_adapter_get_value(): SOF_CTRL_CMD_ENUM index=%d",
697+
cdata->index);
698+
ret = codec_adapter_ctrl_enum_get(cdata, cd);
699+
break;
700+
default:
701+
comp_err(dev, "codec_adapter_get_value() error: invalid cdata->cmd");
702+
ret = -EINVAL;
703+
break;
704+
}
705+
706+
return ret;
707+
}
708+
623709
/* Used to pass standard and bespoke commands (with data) to component */
624710
static int codec_adapter_cmd(struct comp_dev *dev, int cmd, void *data,
625711
int max_data_size)
@@ -637,6 +723,12 @@ static int codec_adapter_cmd(struct comp_dev *dev, int cmd, void *data,
637723
comp_err(dev, "codec_adapter_cmd() get_data not implemented yet.");
638724
ret = -ENODATA;
639725
break;
726+
case COMP_CMD_SET_VALUE:
727+
ret = codec_adapter_set_value(dev, cdata);
728+
break;
729+
case COMP_CMD_GET_VALUE:
730+
ret = codec_adapter_get_value(dev, cdata);
731+
break;
640732
default:
641733
comp_err(dev, "codec_adapter_cmd() error: unknown command");
642734
ret = -EINVAL;

src/include/sof/audio/codec_adapter/codec/generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ struct comp_data {
188188
struct sof_ipc_stream_params stream_params;
189189
uint32_t period_bytes; /** pipeline period bytes */
190190
uint32_t deep_buff_bytes; /**< copy start threshold */
191+
int passthrough:1; /**< data passthrough mode */
191192
};
192193

193194
/*****************************************************************************/

tools/topology/m4/codec_adapter.m4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ define(`W_CODEC_ADAPTER',
5050
` bytes ['
5151
$6
5252
` ]'
53+
` enum ['
54+
$7
55+
` ]'
5356

5457
`}')
5558

tools/topology/sof/pipe-codec-adapter-playback.m4

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ include(`dai.m4')
1212
include(`pipeline.m4')
1313
include(`codec_adapter.m4')
1414
include(`bytecontrol.m4')
15+
include(`enumcontrol.m4')
1516

1617
#
1718
# Controls
@@ -99,6 +100,20 @@ C_CONTROLBYTES(CA_RUNTIME_CONTROLBYTES_NAME_PIPE, PIPELINE_ID,
99100
,
100101
CA_RUNTIME_PARAMS)
101102

103+
define(CA_PASSTHRU_ENUM, concat(`ca_passthru_enum_', PIPELINE_ID))
104+
define(CA_PASSTHRU_CONTROL, concat(`CA PassThrough', PIPELINE_ID))
105+
106+
# Codec adapter passthrough enum list
107+
CONTROLENUM_LIST(CA_PASSTHRU_ENUM, LIST(` ', `"passthru off"', `"passthru on"'))
108+
109+
# Codec adapter passthrough enum control
110+
C_CONTROLENUM(CA_PASSTHRU_CONTROL, PIPELINE_ID,
111+
CA_PASSTHRU_ENUM,
112+
LIST(` ', ENUM_CHANNEL(FC, 3, 0)),
113+
CONTROLENUM_OPS(enum,
114+
257 binds the mixer control to enum get/put handlers,
115+
257, 257))
116+
102117
#
103118
# Components and Buffers
104119
#
@@ -112,7 +127,8 @@ ifdef(`CA_SCHEDULE_CORE',`', `define(`CA_SCHEDULE_CORE', `SCHEDULE_CORE')')
112127
W_PCM_PLAYBACK(PCM_ID, Passthrough Playback, DAI_PERIODS, 0, SCHEDULE_CORE)
113128

114129
W_CODEC_ADAPTER(0, PIPELINE_FORMAT, DAI_PERIODS, DAI_PERIODS, CA_SCHEDULE_CORE,
115-
LIST(` ', "CA_SETUP_CONTROLBYTES_NAME_PIPE", "CA_RUNTIME_CONTROLBYTES_NAME_PIPE"))
130+
LIST(` ', "CA_SETUP_CONTROLBYTES_NAME_PIPE", "CA_RUNTIME_CONTROLBYTES_NAME_PIPE"),
131+
LIST(` ', "CA_PASSTHRU_CONTROL"))
116132

117133
# Playback Buffers
118134
W_BUFFER(0, COMP_BUFFER_SIZE(DAI_PERIODS,
@@ -145,6 +161,8 @@ indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Playback PCM_I
145161

146162
PCM_CAPABILITIES(Passthrough Playback PCM_ID, CAPABILITY_FORMAT_NAME(PIPELINE_FORMAT), PCM_MIN_RATE, PCM_MAX_RATE, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536)
147163

164+
undefine(`CA_PASSTHRU_CONTROL')
165+
undefine(`CA_PASSTHRU_ENUM')
148166
undefine(`CA_RUNTIME_CONTROLBYTES_NAME_PIPE')
149167
undefine(`CA_RUNTIME_PARAMS')
150168
undefine(`CA_SETUP_CONTROLBYTES_NAME_PIPE')

0 commit comments

Comments
 (0)