Skip to content
Closed
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
71 changes: 71 additions & 0 deletions src/audio/codec_adapter/codec/cadence.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,75 @@ int cadence_codec_init(struct comp_dev *dev)
obj_size);
}

/* Assign stream params IDs */
switch (api_id) {
#ifdef CONFIG_CADENCE_CODEC_AAC_DEC
case CADENCE_CODEC_AAC_DEC_ID:
cd->sample_rate_id = XA_AACDEC_CONFIG_PARAM_AAC_SAMPLERATE;
cd->sample_width_id = XA_AACDEC_CONFIG_PARAM_PCM_WDSZ;
cd->channels_id = XA_AACDEC_CONFIG_PARAM_NUM_CHANNELS;
break;
#endif
#ifdef CONFIG_CADENCE_CODEC_MP3_DEC
case CADENCE_CODEC_MP3_DEC_ID:
cd->sample_rate_id = XA_MP3DEC_CONFIG_PARAM_SAMP_FREQ;
cd->sample_width_id = XA_MP3DEC_CONFIG_PARAM_PCM_WDSZ;
cd->channels_id = XA_MP3DEC_CONFIG_PARAM_NUM_CHANNELS;
break;
#endif
default:
cd->sample_rate_id = CADENCE_SAMPLE_RATE_ID;
cd->sample_width_id = CADENCE_SAMPLE_WIDTH_ID;
cd->channels_id = CADENCE_CHANNELS_COUNT_ID;
break;
}

comp_dbg(dev, "cadence_codec_init() done");
out:
return ret;
}

Comment thread
dbaluta marked this conversation as resolved.
Outdated
static int update_stream_params(struct comp_dev *dev)
{
int ret = 0;

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.

IIRC API_CALL() was ret = ... in which case this initialisation is superfluous

struct comp_data *ca_data = comp_get_drvdata(dev);
struct codec_data *codec = comp_get_codec(dev);
struct cadence_codec_data *cd = codec->private;
struct sof_ipc_stream_params *stream = &ca_data->stream_params;
/* copy stream params localy to ensure container size is correct */
uint32_t sample_width = (stream->frame_fmt == SOF_IPC_FRAME_S16_LE) ? 0x10 : 0x20;
Comment thread
mrajwa marked this conversation as resolved.
Outdated
uint32_t sample_rate = stream->rate;
uint32_t channels = stream->channels;

comp_err(dev, "update_stream_params() start");

Comment thread
mrajwa marked this conversation as resolved.
Outdated
/* update stream parameters */
/* sample rate */
API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, cd->sample_rate_id,
&sample_rate, ret);
Comment thread
paulstelian97 marked this conversation as resolved.
Outdated
if (LIB_IS_FATAL_ERROR(ret)) {
comp_err(dev, "update_stream_params(): failed to set sample rate.");
goto err;
}
/* sample width */
API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, cd->sample_width_id,
&sample_width, ret);
if (LIB_IS_FATAL_ERROR(ret)) {
comp_err(dev, "update_stream_params(): failed to set sample width.");
goto err;
}

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.

Here only print a warning if there is an error but do not return err from this function.

/* number of channels */
API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, cd->channels_id,
&channels, ret);
if (LIB_IS_FATAL_ERROR(ret)) {
comp_err(dev, "update_stream_params(): failed to set channel count.");
goto err;
}
err:
comp_err(dev, "update_stream_params() done, returned %d", ret);
return ret;
}

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.

If we get here I think we should return 0. For example setting channels or sample rate for MP3 is a non fatal error. MP3 decoder only needs the sample width the rest it will find by itself parsing the mp3 header.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dbaluta, I have just updated, I think this new way of handling update_stream_params() will cover fatal & non-fatal cases.

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.

@dbaluta is this resolved, sorry I cant tell from the diff.


static int apply_config(struct comp_dev *dev, enum codec_cfg_type type)
{
int ret = 0;
Expand Down Expand Up @@ -405,6 +469,13 @@ int cadence_codec_prepare(struct comp_dev *dev)
*/
codec->s_cfg.avail = false;

/* Update codec config with stream parameters */
ret = update_stream_params(dev);
if (ret) {
comp_err(dev, "cadence_codec_prepare() error %x: failed to update stream params",
ret);
goto err;
}
/* Allocate memory for the codec */
API_CALL(cd, XA_API_CMD_GET_MEMTABS_SIZE, 0, &mem_tabs_size, ret);
if (ret != LIB_NO_ERROR) {
Expand Down
11 changes: 11 additions & 0 deletions src/include/sof/audio/codec_adapter/codec/cadence.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@ struct cadence_api {
xa_codec_func_t *api;
};

enum default_stream_params_ids {
CADENCE_SAMPLE_RATE_ID = 0x01,
CADENCE_SAMPLE_WIDTH_ID = 0x02,
CADENCE_CHANNELS_COUNT_ID = 0x04
Comment thread
dbaluta marked this conversation as resolved.
Outdated
}

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.

Here we need a semicolon:

        CADENCE_SAMPLE_WIDTH_ID = 0x02,
        CADENCE_CHANNELS_COUNT_ID = 0x04
-}
+};

struct cadence_codec_data {
char name[LIB_NAME_MAX_LEN];
void *self;
xa_codec_func_t *api;
void *mem_tabs;
uint32_t sample_width_id;
uint32_t sample_rate_id;
uint32_t channels_id;
};



/*****************************************************************************/

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.

remove the new lines from here. Also, add the following changes:

--- a/src/audio/codec_adapter/CMakeLists.txt
+++ b/src/audio/codec_adapter/CMakeLists.txt
@@ -4,6 +4,7 @@ add_local_sources(sof codec_adapter.c codec/generic.c)
 
 if(CONFIG_CADENCE_CODEC)
 add_local_sources(sof codec/cadence.c)
+target_include_directories(sof PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../../include/sof/audio/cadence)
--- a/src/include/sof/audio/codec_adapter/codec/cadence.h
+++ b/src/include/sof/audio/codec_adapter/codec/cadence.h
@@ -13,6 +13,9 @@
#include <sof/audio/cadence/xa_error_standards.h>
#include <sof/audio/cadence/xa_memory_standards.h>

+#include <sof/audio/cadence/mp3_dec/xa_mp3_dec_api.h>
+#include <sof/audio/cadence/aac_dec/xa_aac_dec_api.h>

I will add a PR with these changes later if you want.

/* Cadence interfaces */
/*****************************************************************************/
Expand Down