From 017b8ebcde57cce0e9ab18fba4ed9457a8970156 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 21 Apr 2023 14:53:03 +0200 Subject: [PATCH] buffer: use an accessor to read struct audio_stream::frame_fmt This patch adds audio_stream_get_frm_fmt() to read struct audio_stream::frame_fmt and converts all users. Apart from hiding internals of the structure, it also enforces the use of the __sparse_cache annotation. Signed-off-by: Guennadi Liakhovetski --- src/audio/asrc/asrc.c | 6 +++--- src/audio/copier/copier.c | 2 +- src/audio/copier/copier_generic.c | 5 +++-- src/audio/copier/copier_hifi.c | 5 +++-- src/audio/crossover/crossover.c | 6 +++--- src/audio/dai-legacy.c | 10 +++++----- src/audio/dai-zephyr.c | 10 +++++----- src/audio/dcblock/dcblock.c | 4 ++-- src/audio/drc/drc.c | 6 +++--- src/audio/eq_fir/eq_fir.c | 4 ++-- src/audio/eq_iir/eq_iir.c | 12 ++++++------ src/audio/google/google_hotword_detect.c | 2 +- src/audio/google/google_rtc_audio_processing.c | 2 +- src/audio/host-legacy.c | 4 ++-- src/audio/host-zephyr.c | 10 ++++++---- src/audio/igo_nr/igo_nr.c | 2 +- src/audio/mfcc/mfcc.c | 4 ++-- src/audio/module_adapter/module/dts.c | 2 +- src/audio/module_adapter/module/waves.c | 10 +++++----- src/audio/multiband_drc/multiband_drc.c | 6 +++--- src/audio/mux/mux.c | 2 +- src/audio/mux/mux_generic.c | 4 ++-- src/audio/pipeline/pipeline-params.c | 2 +- src/audio/rtnr/rtnr.c | 4 ++-- src/audio/selector/selector.c | 8 ++++---- src/audio/smart_amp/smart_amp.c | 10 +++++++--- src/audio/smart_amp/smart_amp_maxim_dsm.c | 10 +++++----- src/audio/src/src.c | 8 ++++---- src/audio/tdfb/tdfb.c | 2 +- src/include/sof/audio/audio_stream.h | 6 ++++++ src/include/sof/audio/mixer.h | 2 +- src/include/sof/audio/volume.h | 2 +- src/ipc/ipc-helper.c | 2 +- src/probe/probe.c | 2 +- src/samples/audio/detect_test.c | 2 +- src/samples/audio/smart_amp_test.c | 4 ++-- 36 files changed, 98 insertions(+), 84 deletions(-) diff --git a/src/audio/asrc/asrc.c b/src/audio/asrc/asrc.c index b570a04f8..02feffbd7 100644 --- a/src/audio/asrc/asrc.c +++ b/src/audio/asrc/asrc.c @@ -754,12 +754,12 @@ static int asrc_prepare(struct comp_dev *dev) sink_c = buffer_acquire(sinkb); /* get source data format and period bytes */ - cd->source_format = source_c->stream.frame_fmt; + cd->source_format = audio_stream_get_frm_fmt(&source_c->stream); source_period_bytes = audio_stream_period_bytes(&source_c->stream, cd->source_frames); /* get sink data format and period bytes */ - cd->sink_format = sink_c->stream.frame_fmt; + cd->sink_format = audio_stream_get_frm_fmt(&sink_c->stream); sink_period_bytes = audio_stream_period_bytes(&sink_c->stream, cd->sink_frames); @@ -785,7 +785,7 @@ static int asrc_prepare(struct comp_dev *dev) } /* ASRC supports S16_LE, S24_4LE and S32_LE formats */ - switch (source_c->stream.frame_fmt) { + switch (audio_stream_get_frm_fmt(&source_c->stream)) { case SOF_IPC_FRAME_S16_LE: cd->asrc_func = src_copy_s16; break; diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index 92ce0d68b..ff1b8db0b 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -1410,7 +1410,7 @@ static void copier_dma_cb(void *arg, enum notify_id type, void *data) else sink = buffer_acquire(cd->hd->dma_buffer); - frames = bytes / get_sample_bytes(sink->stream.frame_fmt); + frames = bytes / get_sample_bytes(audio_stream_get_frm_fmt(&sink->stream)); frames = frames / sink->stream.channels; ret = apply_attenuation(dev, cd, sink, frames); diff --git a/src/audio/copier/copier_generic.c b/src/audio/copier/copier_generic.c index 77bf9a15f..817082b11 100644 --- a/src/audio/copier/copier_generic.c +++ b/src/audio/copier/copier_generic.c @@ -30,7 +30,7 @@ int apply_attenuation(struct comp_dev *dev, struct copier_data *cd, int32_t *dst = audio_stream_get_rptr(&sink->stream); /* only support attenuation in format of 32bit */ - switch (sink->stream.frame_fmt) { + switch (audio_stream_get_frm_fmt(&sink->stream)) { case SOF_IPC_FRAME_S16_LE: comp_err(dev, "16bit sample isn't supported by attenuation"); return -EINVAL; @@ -49,7 +49,8 @@ int apply_attenuation(struct comp_dev *dev, struct copier_data *cd, return 0; default: - comp_err(dev, "unsupported format %d for attenuation", sink->stream.frame_fmt); + comp_err(dev, "unsupported format %d for attenuation", + audio_stream_get_frm_fmt(&sink->stream)); return -EINVAL; } } diff --git a/src/audio/copier/copier_hifi.c b/src/audio/copier/copier_hifi.c index 16c85ba8e..f9f1b8a26 100644 --- a/src/audio/copier/copier_hifi.c +++ b/src/audio/copier/copier_hifi.c @@ -36,7 +36,7 @@ int apply_attenuation(struct comp_dev *dev, struct copier_data *cd, ae_int32x2 *out = (ae_int32x2 *)dst; /* only support attenuation in format of 32bit */ - switch (sink->stream.frame_fmt) { + switch (audio_stream_get_frm_fmt(&sink->stream)) { case SOF_IPC_FRAME_S16_LE: comp_err(dev, "16bit sample isn't supported by attenuation"); return -EINVAL; @@ -66,7 +66,8 @@ int apply_attenuation(struct comp_dev *dev, struct copier_data *cd, return 0; default: - comp_err(dev, "unsupported format %d for attenuation", sink->stream.frame_fmt); + comp_err(dev, "unsupported format %d for attenuation", + audio_stream_get_frm_fmt(&sink->stream)); return -EINVAL; } } diff --git a/src/audio/crossover/crossover.c b/src/audio/crossover/crossover.c index 2ae517b67..06f104a4d 100644 --- a/src/audio/crossover/crossover.c +++ b/src/audio/crossover/crossover.c @@ -716,16 +716,16 @@ static int crossover_prepare(struct comp_dev *dev) source_c = buffer_acquire(source); /* Get source data format */ - cd->source_format = source_c->stream.frame_fmt; + cd->source_format = audio_stream_get_frm_fmt(&source_c->stream); /* Validate frame format and buffer size of sinks */ list_for_item(sink_list, &dev->bsink_list) { sink = container_of(sink_list, struct comp_buffer, source_list); sink_c = buffer_acquire(sink); - if (cd->source_format != sink_c->stream.frame_fmt) { + if (cd->source_format != audio_stream_get_frm_fmt(&sink_c->stream)) { comp_err(dev, "crossover_prepare(): Source fmt %d and sink fmt %d are different for sink %d.", - cd->source_format, sink_c->stream.frame_fmt, + cd->source_format, audio_stream_get_frm_fmt(&sink_c->stream), sink_c->pipeline_id); ret = -EINVAL; } else { diff --git a/src/audio/dai-legacy.c b/src/audio/dai-legacy.c index 0c94ab7c0..aa26d3d0a 100644 --- a/src/audio/dai-legacy.c +++ b/src/audio/dai-legacy.c @@ -332,8 +332,8 @@ static int dai_playback_params(struct comp_dev *dev, uint32_t period_bytes, struct dma_sg_config *config = &dd->config; struct comp_buffer __sparse_cache *dma_buf = buffer_acquire(dd->dma_buffer), *local_buf = buffer_acquire(dd->local_buffer); - uint32_t local_fmt = local_buf->stream.frame_fmt; - uint32_t dma_fmt = dma_buf->stream.frame_fmt; + uint32_t local_fmt = audio_stream_get_frm_fmt(&local_buf->stream); + uint32_t dma_fmt = audio_stream_get_frm_fmt(&dma_buf->stream); uint32_t fifo; int err = 0; @@ -394,8 +394,8 @@ static int dai_capture_params(struct comp_dev *dev, uint32_t period_bytes, struct dma_sg_config *config = &dd->config; struct comp_buffer __sparse_cache *dma_buf = buffer_acquire(dd->dma_buffer), *local_buf = buffer_acquire(dd->local_buffer); - uint32_t local_fmt = local_buf->stream.frame_fmt; - uint32_t dma_fmt = dma_buf->stream.frame_fmt; + uint32_t local_fmt = audio_stream_get_frm_fmt(&local_buf->stream); + uint32_t dma_fmt = audio_stream_get_frm_fmt(&dma_buf->stream); uint32_t fifo; int err = 0; @@ -941,7 +941,7 @@ static int dai_copy(struct comp_dev *dev) buf_c = buffer_acquire(dd->dma_buffer); - dma_fmt = buf_c->stream.frame_fmt; + dma_fmt = audio_stream_get_frm_fmt(&buf_c->stream); sampling = get_sample_bytes(dma_fmt); buffer_release(buf_c); diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index cd064c202..38ee7cfc8 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -441,8 +441,8 @@ static int dai_playback_params(struct comp_dev *dev, uint32_t period_bytes, struct dma_block_config *prev = NULL; struct comp_buffer __sparse_cache *dma_buf = buffer_acquire(dd->dma_buffer), *local_buf = buffer_acquire(dd->local_buffer); - uint32_t local_fmt = local_buf->stream.frame_fmt; - uint32_t dma_fmt = dma_buf->stream.frame_fmt; + uint32_t local_fmt = audio_stream_get_frm_fmt(&local_buf->stream); + uint32_t dma_fmt = audio_stream_get_frm_fmt(&dma_buf->stream); uint32_t fifo, max_block_count, buf_size; int i, err = 0; @@ -579,8 +579,8 @@ static int dai_capture_params(struct comp_dev *dev, uint32_t period_bytes, struct dma_block_config *prev = NULL; struct comp_buffer __sparse_cache *dma_buf = buffer_acquire(dd->dma_buffer), *local_buf = buffer_acquire(dd->local_buffer); - uint32_t local_fmt = local_buf->stream.frame_fmt; - uint32_t dma_fmt = dma_buf->stream.frame_fmt; + uint32_t local_fmt = audio_stream_get_frm_fmt(&local_buf->stream); + uint32_t dma_fmt = audio_stream_get_frm_fmt(&dma_buf->stream); uint32_t fifo, max_block_count, buf_size; int i, err = 0; @@ -1241,7 +1241,7 @@ static int dai_copy(struct comp_dev *dev) buf_c = buffer_acquire(dd->dma_buffer); - dma_fmt = buf_c->stream.frame_fmt; + dma_fmt = audio_stream_get_frm_fmt(&buf_c->stream); sampling = get_sample_bytes(dma_fmt); buffer_release(buf_c); diff --git a/src/audio/dcblock/dcblock.c b/src/audio/dcblock/dcblock.c index b8db07037..1d33a389d 100644 --- a/src/audio/dcblock/dcblock.c +++ b/src/audio/dcblock/dcblock.c @@ -359,10 +359,10 @@ static int dcblock_prepare(struct comp_dev *dev) sink_c = buffer_acquire(sinkb); /* get source data format */ - cd->source_format = source_c->stream.frame_fmt; + cd->source_format = audio_stream_get_frm_fmt(&source_c->stream); /* get sink data format and period bytes */ - cd->sink_format = sink_c->stream.frame_fmt; + cd->sink_format = audio_stream_get_frm_fmt(&sink_c->stream); sink_period_bytes = audio_stream_period_bytes(&sink_c->stream, dev->frames); if (audio_stream_get_size(&sink_c->stream) < sink_period_bytes) { diff --git a/src/audio/drc/drc.c b/src/audio/drc/drc.c index 72a323aba..4720e1b86 100644 --- a/src/audio/drc/drc.c +++ b/src/audio/drc/drc.c @@ -391,7 +391,7 @@ static int drc_prepare(struct comp_dev *dev) source_c = buffer_acquire(sourceb); /* get source data format */ - cd->source_format = source_c->stream.frame_fmt; + cd->source_format = audio_stream_get_frm_fmt(&source_c->stream); /* Initialize DRC */ comp_info(dev, "drc_prepare(), source_format=%d, sink_format=%d", @@ -419,9 +419,9 @@ static int drc_prepare(struct comp_dev *dev) sink_c = buffer_acquire(sinkb); /* validate sink data format and period bytes */ - if (cd->source_format != sink_c->stream.frame_fmt) { + if (cd->source_format != audio_stream_get_frm_fmt(&sink_c->stream)) { comp_err(dev, "drc_prepare(): Source fmt %d and sink fmt %d are different.", - cd->source_format, sink_c->stream.frame_fmt); + cd->source_format, audio_stream_get_frm_fmt(&sink_c->stream)); ret = -EINVAL; goto out_sink; } diff --git a/src/audio/eq_fir/eq_fir.c b/src/audio/eq_fir/eq_fir.c index 45e6ca662..13d99a1a6 100644 --- a/src/audio/eq_fir/eq_fir.c +++ b/src/audio/eq_fir/eq_fir.c @@ -529,7 +529,7 @@ static int eq_fir_process(struct processing_module *mod, return ret; } else if (cd->fir_delay_size) { comp_dbg(mod->dev, "eq_fir_process(), active"); - ret = set_fir_func(mod, source->frame_fmt); + ret = set_fir_func(mod, audio_stream_get_frm_fmt(source)); if (ret < 0) return ret; } else { @@ -593,7 +593,7 @@ static int eq_fir_prepare(struct processing_module *mod) sink_c = buffer_acquire(sinkb); eq_fir_set_alignment(&source_c->stream, &sink_c->stream); channels = sink_c->stream.channels; - frame_fmt = source_c->stream.frame_fmt; + frame_fmt = audio_stream_get_frm_fmt(&source_c->stream); buffer_release(sink_c); buffer_release(source_c); diff --git a/src/audio/eq_iir/eq_iir.c b/src/audio/eq_iir/eq_iir.c index 29191f9ff..c42d555c5 100644 --- a/src/audio/eq_iir/eq_iir.c +++ b/src/audio/eq_iir/eq_iir.c @@ -720,8 +720,8 @@ static int eq_iir_verify_params(struct comp_dev *dev, * pcm frame_fmt and will not make any conversion (sink and source * frame_fmt will be equal). */ - buffer_flag = eq_iir_find_func(source_c->stream.frame_fmt, - sink_c->stream.frame_fmt, fm_configured, + buffer_flag = eq_iir_find_func(audio_stream_get_frm_fmt(&source_c->stream), + audio_stream_get_frm_fmt(&sink_c->stream), fm_configured, ARRAY_SIZE(fm_configured)) ? BUFF_PARAMS_FRAME_FMT : 0; @@ -808,8 +808,8 @@ static int eq_iir_process(struct processing_module *mod, /* Check for changed configuration */ if (comp_is_new_data_blob_available(cd->model_handler)) { cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); - ret = eq_iir_new_blob(mod, cd, source->frame_fmt, - sink->frame_fmt, source->channels); + ret = eq_iir_new_blob(mod, cd, audio_stream_get_frm_fmt(source), + audio_stream_get_frm_fmt(sink), source->channels); if (ret) return ret; } @@ -919,8 +919,8 @@ static int eq_iir_prepare(struct processing_module *mod) /* get source and sink data format */ channels = sink_c->stream.channels; - source_format = source_c->stream.frame_fmt; - sink_format = sink_c->stream.frame_fmt; + source_format = audio_stream_get_frm_fmt(&source_c->stream); + sink_format = audio_stream_get_frm_fmt(&sink_c->stream); buffer_release(sink_c); buffer_release(source_c); diff --git a/src/audio/google/google_hotword_detect.c b/src/audio/google/google_hotword_detect.c index ea6e717ef..8faad2180 100644 --- a/src/audio/google/google_hotword_detect.c +++ b/src/audio/google/google_hotword_detect.c @@ -181,7 +181,7 @@ static int ghd_params(struct comp_dev *dev, if (source_c->stream.channels != 1) { comp_err(dev, "ghd_params(): Only single-channel supported"); ret = -EINVAL; - } else if (source_c->stream.frame_fmt != SOF_IPC_FRAME_S16_LE) { + } else if (audio_stream_get_frm_fmt(&source_c->stream) != SOF_IPC_FRAME_S16_LE) { comp_err(dev, "ghd_params(): Only S16_LE supported"); ret = -EINVAL; } else if (source_c->stream.rate != KPB_SAMPLNG_FREQUENCY) { diff --git a/src/audio/google/google_rtc_audio_processing.c b/src/audio/google/google_rtc_audio_processing.c index 695a45d23..a60a0f814 100644 --- a/src/audio/google/google_rtc_audio_processing.c +++ b/src/audio/google/google_rtc_audio_processing.c @@ -555,7 +555,7 @@ static int google_rtc_audio_processing_prepare(struct comp_dev *dev) } output_c = buffer_acquire(cd->output); - frame_fmt = output_c->stream.frame_fmt; + frame_fmt = audio_stream_get_frm_fmt(&output_c->stream); rate = output_c->stream.rate; buffer_release(output_c); diff --git a/src/audio/host-legacy.c b/src/audio/host-legacy.c index 90427a7d1..919c74bd8 100644 --- a/src/audio/host-legacy.c +++ b/src/audio/host-legacy.c @@ -851,8 +851,8 @@ int host_zephyr_params(struct host_data *hd, struct comp_dev *dev, host_copy_normal; /* set processing function */ - hd->process = pcm_get_conversion_function(host_buf_c->stream.frame_fmt, - host_buf_c->stream.frame_fmt); + hd->process = pcm_get_conversion_function(audio_stream_get_frm_fmt(&host_buf_c->stream), + audio_stream_get_frm_fmt(&host_buf_c->stream)); out: buffer_release(host_buf_c); diff --git a/src/audio/host-zephyr.c b/src/audio/host-zephyr.c index 162ea2477..282b0df89 100644 --- a/src/audio/host-zephyr.c +++ b/src/audio/host-zephyr.c @@ -860,11 +860,13 @@ int host_zephyr_params(struct host_data *hd, struct comp_dev *dev, /* set processing function */ if (params->direction == SOF_IPC_STREAM_CAPTURE) - hd->process = pcm_get_conversion_function(host_buf_c->stream.frame_fmt, - dma_buf_c->stream.frame_fmt); + hd->process = pcm_get_conversion_function( + audio_stream_get_frm_fmt(&host_buf_c->stream), + audio_stream_get_frm_fmt(&dma_buf_c->stream)); else - hd->process = pcm_get_conversion_function(dma_buf_c->stream.frame_fmt, - host_buf_c->stream.frame_fmt); + hd->process = pcm_get_conversion_function( + audio_stream_get_frm_fmt(&dma_buf_c->stream), + audio_stream_get_frm_fmt(&host_buf_c->stream)); config->src_width = audio_stream_sample_bytes(&dma_buf_c->stream); config->dest_width = config->src_width; diff --git a/src/audio/igo_nr/igo_nr.c b/src/audio/igo_nr/igo_nr.c index 4fcc3f11f..1a27b6c97 100755 --- a/src/audio/igo_nr/igo_nr.c +++ b/src/audio/igo_nr/igo_nr.c @@ -249,7 +249,7 @@ static inline int32_t set_capture_func(struct comp_dev *dev) sink_list); /* The igo_nr supports S16_LE data. Format converter is needed. */ - switch (sourceb->stream.frame_fmt) { + switch (audio_stream_get_frm_fmt(&sourceb->stream)) { #if CONFIG_FORMAT_S16LE case SOF_IPC_FRAME_S16_LE: comp_info(dev, "set_capture_func(), SOF_IPC_FRAME_S16_LE"); diff --git a/src/audio/mfcc/mfcc.c b/src/audio/mfcc/mfcc.c index 23ef2d7f7..7463d6708 100644 --- a/src/audio/mfcc/mfcc.c +++ b/src/audio/mfcc/mfcc.c @@ -209,13 +209,13 @@ static int mfcc_prepare(struct processing_module *mod) sink_c = buffer_acquire(sinkb); /* get source data format */ - source_format = source_c->stream.frame_fmt; + source_format = audio_stream_get_frm_fmt(&source_c->stream); /* set align requirements */ mfcc_set_alignment(&source_c->stream, &sink_c->stream); /* get sink data format and period bytes */ - sink_format = sink_c->stream.frame_fmt; + sink_format = audio_stream_get_frm_fmt(&sink_c->stream); sink_period_bytes = audio_stream_period_bytes(&sink_c->stream, dev->frames); comp_info(dev, "mfcc_prepare(), source_format = %d, sink_format = %d", source_format, sink_format); diff --git a/src/audio/module_adapter/module/dts.c b/src/audio/module_adapter/module/dts.c index 28840c342..042ad6e37 100644 --- a/src/audio/module_adapter/module/dts.c +++ b/src/audio/module_adapter/module/dts.c @@ -93,7 +93,7 @@ static int dts_effect_populate_buffer_configuration(struct comp_dev *dev, buffer_fmt = source_c->buffer_fmt; stream = &source_c->stream; - frame_fmt = stream->frame_fmt; + frame_fmt = audio_stream_get_frm_fmt(stream); rate = stream->rate; channels = stream->channels; diff --git a/src/audio/module_adapter/module/waves.c b/src/audio/module_adapter/module/waves.c index bc86f5799..7118bf6ce 100644 --- a/src/audio/module_adapter/module/waves.c +++ b/src/audio/module_adapter/module/waves.c @@ -251,9 +251,9 @@ static int waves_effect_check(struct comp_dev *dev) } /* different frame format not supported */ - if (src_fmt->frame_fmt != snk_fmt->frame_fmt) { + if (src_fmt->frame_fmt != audio_stream_get_frm_fmt(snk_fmt)) { comp_err(dev, "waves_effect_check() source %d sink %d sample format mismatch", - src_fmt->frame_fmt, snk_fmt->frame_fmt); + audio_stream_get_frm_fmt(src_fmt), audio_stream_get_frm_fmt(snk_fmt)); ret = -EINVAL; goto out; } @@ -265,7 +265,7 @@ static int waves_effect_check(struct comp_dev *dev) goto out; } - if (!format_is_supported(src_fmt->frame_fmt)) { + if (!format_is_supported(audio_stream_get_frm_fmt(src_fmt))) { comp_err(dev, "waves_effect_check() float samples not supported"); ret = -EINVAL; goto out; @@ -318,10 +318,10 @@ static int waves_effect_init(struct processing_module *mod) comp_dbg(dev, "waves_effect_init() start"); - sample_format = format_convert_sof_to_me(src_fmt->frame_fmt); + sample_format = format_convert_sof_to_me(audio_stream_get_frm_fmt(src_fmt)); if (sample_format < 0) { comp_err(dev, "waves_effect_init() sof sample format %d not supported", - src_fmt->frame_fmt); + audio_stream_get_frm_fmt(src_fmt)); ret = -EINVAL; goto out; } diff --git a/src/audio/multiband_drc/multiband_drc.c b/src/audio/multiband_drc/multiband_drc.c index 1bc422039..6619197b6 100644 --- a/src/audio/multiband_drc/multiband_drc.c +++ b/src/audio/multiband_drc/multiband_drc.c @@ -534,7 +534,7 @@ static int multiband_drc_prepare(struct comp_dev *dev) source_c = buffer_acquire(sourceb); /* get source data format */ - cd->source_format = source_c->stream.frame_fmt; + cd->source_format = audio_stream_get_frm_fmt(&source_c->stream); /* Initialize DRC */ comp_dbg(dev, "multiband_drc_prepare(), source_format=%d, sink_format=%d", @@ -574,10 +574,10 @@ static int multiband_drc_prepare(struct comp_dev *dev) sink_c = buffer_acquire(sinkb); /* validate sink data format and period bytes */ - if (cd->source_format != sink_c->stream.frame_fmt) { + if (cd->source_format != audio_stream_get_frm_fmt(&sink_c->stream)) { comp_err(dev, "multiband_drc_prepare(): Source fmt %d and sink fmt %d are different.", - cd->source_format, sink_c->stream.frame_fmt); + cd->source_format, audio_stream_get_frm_fmt(&sink_c->stream)); ret = -EINVAL; goto out_sink; } diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index a36a10556..26a54628d 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -306,7 +306,7 @@ static void set_mux_params(struct processing_module *mod) sink_c->stream.valid_sample_fmt = valid_fmt; sink_c->buffer_fmt = out_fmt.interleaving_style; - params->frame_fmt = sink_c->stream.frame_fmt; + params->frame_fmt = audio_stream_get_frm_fmt(&sink_c->stream); for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++) sink_c->chmap[i] = (out_fmt.ch_map >> i * 4) & 0xf; diff --git a/src/audio/mux/mux_generic.c b/src/audio/mux/mux_generic.c index 8d92503e9..e30e20dcc 100644 --- a/src/audio/mux/mux_generic.c +++ b/src/audio/mux/mux_generic.c @@ -535,7 +535,7 @@ mux_func mux_get_processing_function(struct processing_module *mod) for (i = 0; i < ARRAY_SIZE(mux_func_map); i++) { struct comp_buffer __sparse_cache *sink_c = buffer_acquire(sinkb); - enum sof_ipc_frame fmt = sink_c->stream.frame_fmt; + enum sof_ipc_frame fmt = audio_stream_get_frm_fmt(&sink_c->stream); if (fmt == mux_func_map[i].frame_format) @@ -559,7 +559,7 @@ demux_func demux_get_processing_function(struct processing_module *mod) for (i = 0; i < ARRAY_SIZE(mux_func_map); i++) { struct comp_buffer __sparse_cache *source_c = buffer_acquire(sourceb); - enum sof_ipc_frame fmt = source_c->stream.frame_fmt; + enum sof_ipc_frame fmt = audio_stream_get_frm_fmt(&source_c->stream); buffer_release(source_c); diff --git a/src/audio/pipeline/pipeline-params.c b/src/audio/pipeline/pipeline-params.c index ecdac1249..cb7b8495b 100644 --- a/src/audio/pipeline/pipeline-params.c +++ b/src/audio/pipeline/pipeline-params.c @@ -138,7 +138,7 @@ static void pipeline_update_buffer_pcm_params(struct comp_buffer __sparse_cache int i; params->buffer_fmt = buffer->buffer_fmt; - params->frame_fmt = buffer->stream.frame_fmt; + params->frame_fmt = audio_stream_get_frm_fmt(&buffer->stream); params->rate = buffer->stream.rate; params->channels = buffer->stream.channels; for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++) diff --git a/src/audio/rtnr/rtnr.c b/src/audio/rtnr/rtnr.c index c286f0927..c44d4e9f3 100644 --- a/src/audio/rtnr/rtnr.c +++ b/src/audio/rtnr/rtnr.c @@ -873,8 +873,8 @@ static int rtnr_prepare(struct comp_dev *dev) /* Get sink data format */ sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, source_list); sink_c = buffer_acquire(sinkb); - cd->sink_format = sink_c->stream.frame_fmt; - cd->sink_stream.frame_fmt = sink_c->stream.frame_fmt; + cd->sink_format = audio_stream_get_frm_fmt(&sink_c->stream); + cd->sink_stream.frame_fmt = audio_stream_get_frm_fmt(&sink_c->stream); buffer_release(sink_c); /* Check source and sink PCM format and get processing function */ diff --git a/src/audio/selector/selector.c b/src/audio/selector/selector.c index 2c75a143e..ee0b5d295 100644 --- a/src/audio/selector/selector.c +++ b/src/audio/selector/selector.c @@ -463,11 +463,11 @@ static int selector_prepare(struct comp_dev *dev) sink_c = buffer_acquire(sinkb); /* get source data format and period bytes */ - cd->source_format = source_c->stream.frame_fmt; + cd->source_format = audio_stream_get_frm_fmt(&source_c->stream); cd->source_period_bytes = audio_stream_period_bytes(&source_c->stream, dev->frames); /* get sink data format and period bytes */ - cd->sink_format = sink_c->stream.frame_fmt; + cd->sink_format = audio_stream_get_frm_fmt(&sink_c->stream); cd->sink_period_bytes = audio_stream_period_bytes(&sink_c->stream, dev->frames); /* There is an assumption that sink component will report out @@ -920,11 +920,11 @@ static int selector_prepare(struct processing_module *mod) audio_stream_init_alignment_constants(4, 1, &sink_c->stream); /* get source data format and period bytes */ - cd->source_format = source_c->stream.frame_fmt; + cd->source_format = audio_stream_get_frm_fmt(&source_c->stream); cd->source_period_bytes = audio_stream_period_bytes(&source_c->stream, dev->frames); /* get sink data format and period bytes */ - cd->sink_format = sink_c->stream.frame_fmt; + cd->sink_format = audio_stream_get_frm_fmt(&sink_c->stream); cd->sink_period_bytes = audio_stream_period_bytes(&sink_c->stream, dev->frames); /* There is an assumption that sink component will report out diff --git a/src/audio/smart_amp/smart_amp.c b/src/audio/smart_amp/smart_amp.c index 0a4903d8e..673b3dd8a 100644 --- a/src/audio/smart_amp/smart_amp.c +++ b/src/audio/smart_amp/smart_amp.c @@ -558,8 +558,12 @@ static int smart_amp_process(struct comp_dev *dev, static smart_amp_proc get_smart_amp_process(struct comp_dev *dev) { struct smart_amp_data *sad = comp_get_drvdata(dev); + struct comp_buffer __sparse_cache *source_buf = buffer_acquire(sad->source_buf); + enum sof_ipc_frame fmt = audio_stream_get_frm_fmt(&source_buf->stream); - switch (sad->source_buf->stream.frame_fmt) { + buffer_release(source_buf); + + switch (fmt) { case SOF_IPC_FRAME_S16_LE: case SOF_IPC_FRAME_S24_4LE: case SOF_IPC_FRAME_S32_LE: @@ -710,7 +714,7 @@ static int smart_amp_prepare(struct comp_dev *dev) } } - switch (source_c->stream.frame_fmt) { + switch (audio_stream_get_frm_fmt(&source_c->stream)) { case SOF_IPC_FRAME_S16_LE: bitwidth = 16; break; @@ -722,7 +726,7 @@ static int smart_amp_prepare(struct comp_dev *dev) break; default: comp_err(dev, "[DSM] smart_amp_process() error: not supported frame format %d", - source_c->stream.frame_fmt); + audio_stream_get_frm_fmt(&source_c->stream)); goto error; } diff --git a/src/audio/smart_amp/smart_amp_maxim_dsm.c b/src/audio/smart_amp/smart_amp_maxim_dsm.c index b87775cc9..78ed78dea 100644 --- a/src/audio/smart_amp/smart_amp_maxim_dsm.c +++ b/src/audio/smart_amp/smart_amp_maxim_dsm.c @@ -592,7 +592,7 @@ static int smart_amp_get_buffer(int32_t *buf, uint32_t frames, output.buf16 = (int16_t *)buf; output.buf32 = (int32_t *)buf; - switch (stream->frame_fmt) { + switch (audio_stream_get_frm_fmt(stream)) { case SOF_IPC_FRAME_S16_LE: for (idx = 0 ; idx < frames ; idx++) { for (ch = 0 ; ch < num_ch; ch++) { @@ -642,7 +642,7 @@ static int smart_amp_put_buffer(int32_t *buf, uint32_t frames, output.buf16 = audio_stream_get_wptr(stream); output.buf32 = audio_stream_get_wptr(stream); - switch (stream->frame_fmt) { + switch (audio_stream_get_frm_fmt(stream)) { case SOF_IPC_FRAME_S16_LE: for (idx = 0 ; idx < frames ; idx++) { for (ch = 0 ; ch < num_ch_out; ch++) { @@ -708,7 +708,7 @@ int smart_amp_ff_copy(struct comp_dev *dev, uint32_t frames, if (ret) goto err; - switch (source->frame_fmt) { + switch (audio_stream_get_frm_fmt(source)) { case SOF_IPC_FRAME_S16_LE: maxim_dsm_ff_proc(hspk, dev, hspk->buf.frame_in, @@ -767,7 +767,7 @@ int smart_amp_fb_copy(struct comp_dev *dev, uint32_t frames, if (ret) goto err; - switch (source->frame_fmt) { + switch (audio_stream_get_frm_fmt(source)) { case SOF_IPC_FRAME_S16_LE: maxim_dsm_fb_proc(hspk, dev, hspk->buf.frame_iv, frames * num_ch, sizeof(int16_t)); @@ -784,6 +784,6 @@ int smart_amp_fb_copy(struct comp_dev *dev, uint32_t frames, return 0; err: comp_err(dev, "[DSM] Not supported frame format : %d", - source->frame_fmt); + audio_stream_get_frm_fmt(source)); return ret; } diff --git a/src/audio/src/src.c b/src/audio/src/src.c index af1e96a0a..6523a8989 100644 --- a/src/audio/src/src.c +++ b/src/audio/src/src.c @@ -467,7 +467,7 @@ static void src_copy_sxx(struct comp_dev *dev, struct comp_data *cd, { int frames = cd->param.blk_in; - switch (sink->frame_fmt) { + switch (audio_stream_get_frm_fmt(sink)) { case SOF_IPC_FRAME_S16_LE: case SOF_IPC_FRAME_S24_4LE: case SOF_IPC_FRAME_S32_LE: @@ -766,7 +766,7 @@ static int src_params_general(struct comp_dev *dev, struct comp_data *cd, /* Allocate needed memory for delay lines */ comp_info(dev, "src_params(), source_rate = %u, sink_rate = %u, format = %d", - cd->source_rate, cd->sink_rate, source_c->stream.frame_fmt); + cd->source_rate, cd->sink_rate, audio_stream_get_frm_fmt(&source_c->stream)); comp_info(dev, "src_params(), sourceb->channels = %u, sinkb->channels = %u, dev->frames = %u", source_c->stream.channels, sink_c->stream.channels, dev->frames); err = src_buffer_lengths(dev, cd, source_c->stream.channels); @@ -861,8 +861,8 @@ static int src_prepare_general(struct comp_dev *dev, struct comp_data *cd) #endif /* get source/sink data format */ - source_format = source_c->stream.frame_fmt; - sink_format = sink_c->stream.frame_fmt; + source_format = audio_stream_get_frm_fmt(&source_c->stream); + sink_format = audio_stream_get_frm_fmt(&sink_c->stream); ret = src_check_buffer_sizes(dev, cd, &source_c->stream, &sink_c->stream); if (ret < 0) diff --git a/src/audio/tdfb/tdfb.c b/src/audio/tdfb/tdfb.c index 8e710533a..b5e857e20 100644 --- a/src/audio/tdfb/tdfb.c +++ b/src/audio/tdfb/tdfb.c @@ -745,7 +745,7 @@ static int tdfb_prepare(struct processing_module *mod) sink_c = buffer_acquire(sinkb); tdfb_set_alignment(&source_c->stream, &sink_c->stream); - frame_fmt = source_c->stream.frame_fmt; + frame_fmt = audio_stream_get_frm_fmt(&source_c->stream); source_channels = source_c->stream.channels; sink_channels = sink_c->stream.channels; rate = source_c->stream.rate; diff --git a/src/include/sof/audio/audio_stream.h b/src/include/sof/audio/audio_stream.h index 8d2e53187..049825e47 100644 --- a/src/include/sof/audio/audio_stream.h +++ b/src/include/sof/audio/audio_stream.h @@ -112,6 +112,12 @@ static inline uint32_t audio_stream_get_free(const struct audio_stream __sparse_ return buf->free; } +static inline enum sof_ipc_frame audio_stream_get_frm_fmt( + const struct audio_stream __sparse_cache *buf) +{ + return buf->frame_fmt; +} + /** * Retrieves readable address of a sample at specified index (see versions of * this macro specialized for various sample types). diff --git a/src/include/sof/audio/mixer.h b/src/include/sof/audio/mixer.h index 8c4aeab7f..c5836ca89 100644 --- a/src/include/sof/audio/mixer.h +++ b/src/include/sof/audio/mixer.h @@ -68,7 +68,7 @@ static inline mixer_func mixer_get_processing_function(struct comp_dev *dev, /* map the volume function for source and sink buffers */ for (i = 0; i < mixer_func_count; i++) { - if (sinkb->stream.frame_fmt != mixer_func_map[i].frame_fmt) + if (audio_stream_get_frm_fmt(&sinkb->stream) != mixer_func_map[i].frame_fmt) continue; return mixer_func_map[i].func; diff --git a/src/include/sof/audio/volume.h b/src/include/sof/audio/volume.h index e72407a13..d13106fdb 100644 --- a/src/include/sof/audio/volume.h +++ b/src/include/sof/audio/volume.h @@ -190,7 +190,7 @@ static inline vol_scale_func vol_get_processing_function(struct comp_dev *dev, /* map the volume function for source and sink buffers */ for (i = 0; i < volume_func_count; i++) { - if (sinkb->stream.frame_fmt != volume_func_map[i].frame_fmt) + if (audio_stream_get_frm_fmt(&sinkb->stream) != volume_func_map[i].frame_fmt) continue; return volume_func_map[i].func; diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index 085346290..bf0bdb59a 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -87,7 +87,7 @@ static void comp_update_params(uint32_t flag, struct comp_buffer __sparse_cache *buffer) { if (flag & BUFF_PARAMS_FRAME_FMT) - params->frame_fmt = buffer->stream.frame_fmt; + params->frame_fmt = audio_stream_get_frm_fmt(&buffer->stream); if (flag & BUFF_PARAMS_BUFFER_FMT) params->buffer_fmt = buffer->buffer_fmt; diff --git a/src/probe/probe.c b/src/probe/probe.c index 98f349b78..14247fd1a 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -829,7 +829,7 @@ static void probe_cb_produce(void *arg, enum notify_id type, void *data) } if (_probe->probe_points[i].purpose == PROBE_PURPOSE_EXTRACTION) { - format = probe_gen_format(buffer->stream.frame_fmt, + format = probe_gen_format(audio_stream_get_frm_fmt(&buffer->stream), buffer->stream.rate, buffer->stream.channels); ret = probe_gen_header(buffer_id, diff --git a/src/samples/audio/detect_test.c b/src/samples/audio/detect_test.c index c81f23a29..6cfa9d43a 100644 --- a/src/samples/audio/detect_test.c +++ b/src/samples/audio/detect_test.c @@ -767,7 +767,7 @@ static int test_keyword_params(struct comp_dev *dev, sink_list); source_c = buffer_acquire(sourceb); channels = source_c->stream.channels; - frame_fmt = source_c->stream.frame_fmt; + frame_fmt = audio_stream_get_frm_fmt(&source_c->stream); rate = source_c->stream.rate; buffer_release(source_c); diff --git a/src/samples/audio/smart_amp_test.c b/src/samples/audio/smart_amp_test.c index 7187f12ee..ccf6ce43a 100644 --- a/src/samples/audio/smart_amp_test.c +++ b/src/samples/audio/smart_amp_test.c @@ -162,7 +162,7 @@ static void smart_amp_set_params(struct comp_dev *dev, sink_c->stream.valid_sample_fmt = valid_fmt; sink_c->buffer_fmt = out_fmt.interleaving_style; - params->frame_fmt = sink_c->stream.frame_fmt; + params->frame_fmt = audio_stream_get_frm_fmt(&sink_c->stream); sink_c->hw_params_configured = true; @@ -636,7 +636,7 @@ static int smart_amp_process_s32(struct comp_dev *dev, static smart_amp_proc get_smart_amp_process(struct comp_dev *dev, struct comp_buffer __sparse_cache *buf) { - switch (buf->stream.frame_fmt) { + switch (audio_stream_get_frm_fmt(&buf->stream)) { case SOF_IPC_FRAME_S16_LE: return smart_amp_process_s16; case SOF_IPC_FRAME_S24_4LE: