[Sound-open-firmware] [PATCH] component: params: removed unused host params arg in params() config API

Liam Girdwood liam.r.girdwood at linux.intel.com
Mon Aug 21 21:34:37 CEST 2017


Remove the unused pointer to host parameters in params(). This was only
useful to the host component. Provide some component frame configuration
variables to give more flaxability than host params.

Signed-off-by: Liam Girdwood <liam.r.girdwood at linux.intel.com>
---
 src/audio/dai.c                    | 21 ++++++----------
 src/audio/eq_fir.c                 | 12 ++++------
 src/audio/eq_iir.c                 | 12 ++++------
 src/audio/host.c                   | 25 +++++++++----------
 src/audio/mixer.c                  | 17 ++++---------
 src/audio/mux.c                    |  2 +-
 src/audio/pipeline.c               | 11 ++++-----
 src/audio/src.c                    | 21 +++++++---------
 src/audio/switch.c                 |  2 +-
 src/audio/tone.c                   | 12 ++++------
 src/audio/volume.c                 | 49 ++++++++++++++++++++++----------------
 src/include/reef/audio/component.h | 28 +++++++++++++++++-----
 src/include/reef/audio/pipeline.h  |  2 +-
 src/ipc/intel-ipc.c                | 13 ++++++----
 14 files changed, 111 insertions(+), 116 deletions(-)

diff --git a/src/audio/dai.c b/src/audio/dai.c
index c89103d..bacb0d9 100644
--- a/src/audio/dai.c
+++ b/src/audio/dai.c
@@ -62,7 +62,6 @@ struct dai_data {
 	struct dai *dai;
 	struct dma *dma;
 	uint32_t period_bytes;
-	uint32_t sample_width;
 
 	uint32_t last_bytes;    /* the last bytes(<period size) it copies. */
 	uint32_t dai_pos_blks;	/* position in bytes (nearest block) */
@@ -228,8 +227,7 @@ static void dai_free(struct comp_dev *dev)
 }
 
 /* set component audio SSP and DMA configuration */
-static int dai_playback_params(struct comp_dev *dev,
-	struct stream_params *params)
+static int dai_playback_params(struct comp_dev *dev)
 {
 	struct dai_data *dd = comp_get_drvdata(dev);
 	struct dma_sg_config *config = &dd->config;
@@ -293,8 +291,7 @@ err_unwind:
 	return -ENOMEM;
 }
 
-static int dai_capture_params(struct comp_dev *dev,
-	struct stream_params *params)
+static int dai_capture_params(struct comp_dev *dev)
 {
 	struct dai_data *dd = comp_get_drvdata(dev);
 	struct dma_sg_config *config = &dd->config;
@@ -356,12 +353,10 @@ err_unwind:
 	return -ENOMEM;
 }
 
-static int dai_params(struct comp_dev *dev,
-	struct stream_params *host_params)
+static int dai_params(struct comp_dev *dev)
 {
 	struct dai_data *dd = comp_get_drvdata(dev);
 	struct comp_buffer *dma_buffer;
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 
 	trace_dai("par");
 
@@ -371,24 +366,22 @@ static int dai_params(struct comp_dev *dev,
 		return -EINVAL;
 	}
 
-	comp_install_params(dev, host_params);
-
 	/* calculate period size based on config */
-	config->frame_size = dd->sample_width * dev->params.channels;
-	dd->period_bytes = config->frames * config->frame_size;
+	dev->frame_bytes = comp_frame_bytes(dev);
+	dd->period_bytes = dev->frames * dev->frame_bytes;
 
 	if (dev->params.direction == SOF_IPC_STREAM_PLAYBACK) {
 		dma_buffer = list_first_item(&dev->bsource_list,
 			struct comp_buffer, sink_list);
 		dma_buffer->r_ptr = dma_buffer->addr;
 
-		return dai_playback_params(dev, host_params);
+		return dai_playback_params(dev);
 	} else {
 		dma_buffer = list_first_item(&dev->bsink_list,
 			struct comp_buffer, source_list);
 		dma_buffer->w_ptr = dma_buffer->addr;
 
-		return dai_capture_params(dev, host_params);
+		return dai_capture_params(dev);
 	}
 }
 
diff --git a/src/audio/eq_fir.c b/src/audio/eq_fir.c
index 9532b63..534a4a1 100644
--- a/src/audio/eq_fir.c
+++ b/src/audio/eq_fir.c
@@ -282,18 +282,15 @@ static void eq_fir_free(struct comp_dev *dev)
 }
 
 /* set component audio stream parameters */
-static int eq_fir_params(struct comp_dev *dev,
-	struct stream_params *host_params)
+static int eq_fir_params(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
 	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 
 	trace_src("par");
 
-	comp_install_params(dev, host_params);
-
 	/* calculate period size based on config */
-	cd->period_bytes = config->frames * config->frame_size;
+	cd->period_bytes = dev->frames * dev->frame_bytes;
 
 	/* EQ supports only S32_LE PCM format */
 	if (config->frame_fmt != SOF_IPC_FRAME_S32_LE)
@@ -401,7 +398,6 @@ static int eq_fir_cmd(struct comp_dev *dev, int cmd, void *data)
 static int eq_fir_copy(struct comp_dev *dev)
 {
 	struct comp_data *sd = comp_get_drvdata(dev);
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 	struct comp_buffer *source, *sink;
 	uint32_t copy_bytes;
 
@@ -422,13 +418,13 @@ static int eq_fir_copy(struct comp_dev *dev)
 	if (copy_bytes < sd->period_bytes)
 		return 0;
 
-	sd->eq_fir_func(dev, source, sink, config->frames);
+	sd->eq_fir_func(dev, source, sink, dev->frames);
 
 	/* calc new free and available */
 	comp_update_buffer_consume(source, copy_bytes);
 	comp_update_buffer_produce(sink, copy_bytes);
 
-	return config->frames;
+	return dev->frames;
 }
 
 static int eq_fir_prepare(struct comp_dev *dev)
diff --git a/src/audio/eq_iir.c b/src/audio/eq_iir.c
index e819903..0ac2ef9 100644
--- a/src/audio/eq_iir.c
+++ b/src/audio/eq_iir.c
@@ -286,18 +286,15 @@ static void eq_iir_free(struct comp_dev *dev)
 }
 
 /* set component audio stream parameters */
-static int eq_iir_params(struct comp_dev *dev,
-	struct stream_params *host_params)
+static int eq_iir_params(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
 	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 
 	trace_eq_iir("par");
 
-	comp_install_params(dev, host_params);
-
 	/* calculate period size based on config */
-	cd->period_bytes = config->frames * config->frame_size;
+	cd->period_bytes = dev->frames * dev->frame_bytes;
 
 	/* EQ supports only S32_LE PCM format */
 	if (config->frame_fmt != SOF_IPC_FRAME_S32_LE)
@@ -411,7 +408,6 @@ static int eq_iir_cmd(struct comp_dev *dev, int cmd, void *data)
 static int eq_iir_copy(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 	struct comp_buffer *source, *sink;
 	uint32_t copy_bytes;
 
@@ -432,13 +428,13 @@ static int eq_iir_copy(struct comp_dev *dev)
 	if (copy_bytes < cd->period_bytes)
 		return 0;
 
-	cd->eq_iir_func(dev, source, sink, config->frames);
+	cd->eq_iir_func(dev, source, sink, dev->frames);
 
 	/* calc new free and available */
 	comp_update_buffer_consume(source, copy_bytes);
 	comp_update_buffer_produce(sink, copy_bytes);
 
-	return config->frames;
+	return dev->frames;
 }
 
 static int eq_iir_prepare(struct comp_dev *dev)
diff --git a/src/audio/host.c b/src/audio/host.c
index 27b5418..c95a957 100644
--- a/src/audio/host.c
+++ b/src/audio/host.c
@@ -304,8 +304,7 @@ static void host_free(struct comp_dev *dev)
 	rfree(dev);
 }
 
-static int create_local_elems(struct comp_dev *dev,
-	struct stream_params *params)
+static int create_local_elems(struct comp_dev *dev)
 {
 	struct host_data *hd = comp_get_drvdata(dev);
 	struct dma_sg_elem *e;
@@ -320,13 +319,13 @@ static int create_local_elems(struct comp_dev *dev,
 
 		if (dev->params.direction == SOF_IPC_STREAM_PLAYBACK)
 			e->dest = (uint32_t)(hd->dma_buffer->addr) +
-				i *  hd->period_bytes;
+				i * hd->period_bytes;
 		else
 			e->src = (uint32_t)(hd->dma_buffer->addr) +
-				i *  hd->period_bytes;
+				i * hd->period_bytes;
 
 		e->size = hd->period_bytes;
-;
+
 		list_item_append(&e->list, &hd->local.elem_list);
 	}
 
@@ -371,12 +370,12 @@ static int host_elements_reset(struct comp_dev *dev)
 }
 
 /* configure the DMA params and descriptors for host buffer IO */
-static int host_params(struct comp_dev *dev, struct stream_params *params)
+static int host_params(struct comp_dev *dev)
 {
 	struct host_data *hd = comp_get_drvdata(dev);
 	struct sof_ipc_comp_config *cconfig = COMP_GET_CONFIG(dev);
 	struct dma_sg_config *config = &hd->config;
-	uint32_t buffer_size ;
+	uint32_t buffer_size;
 	int err;
 
 	trace_host("par");
@@ -405,8 +404,11 @@ static int host_params(struct comp_dev *dev, struct stream_params *params)
 	}
 
 	/* calculate period size based on config */
-	hd->period_bytes = cconfig->frames * dev->params.sample_size *
-		dev->params.channels;
+	hd->period_bytes = dev->frames * comp_frame_bytes(dev);
+	if (hd->period_bytes == 0) {
+		trace_host_error("eS1");
+		return -EINVAL;
+	}
 
 	/* resize the buffer if space is available to align with period size */
 	buffer_size = hd->period_count * hd->period_bytes;
@@ -426,7 +428,7 @@ static int host_params(struct comp_dev *dev, struct stream_params *params)
 	}
 
 	/* create SG DMA elems for local DMA buffer */
-	err = create_local_elems(dev, params);
+	err = create_local_elems(dev);
 	if (err < 0)
 		return err;
 
@@ -634,7 +636,6 @@ static int host_reset(struct comp_dev *dev)
 static int host_copy(struct comp_dev *dev)
 {
 	struct host_data *hd = comp_get_drvdata(dev);
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 
 	tracev_host("cpy");
 
@@ -645,7 +646,7 @@ static int host_copy(struct comp_dev *dev)
 	dma_set_config(hd->dma, hd->chan, &hd->config);
 	dma_start(hd->dma, hd->chan);
 
-	return config->frames;
+	return dev->frames;
 }
 
 struct comp_driver comp_host = {
diff --git a/src/audio/mixer.c b/src/audio/mixer.c
index 74c0ffb..372d59f 100644
--- a/src/audio/mixer.c
+++ b/src/audio/mixer.c
@@ -121,22 +121,14 @@ static void mixer_free(struct comp_dev *dev)
 }
 
 /* set component audio stream parameters */
-static int mixer_params(struct comp_dev *dev,
-	struct stream_params *host_params)
+static int mixer_params(struct comp_dev *dev)
 {
 	struct mixer_data *md = comp_get_drvdata(dev);
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 
 	trace_mixer("par");
 
-	/* dont do any params downstream setting for running mixer stream */
-	if (dev->state == COMP_STATE_RUNNING)
-		return 1;
-
-	comp_install_params(dev, host_params);
-
 	/* calculate period size based on config */
-	md->period_bytes = config->frames * config->frame_size;
+	md->period_bytes = dev->frames * dev->frame_bytes;
 
 	return 0;
 }
@@ -199,7 +191,6 @@ static int mixer_copy(struct comp_dev *dev)
 {
 	struct mixer_data *md = comp_get_drvdata(dev);
 	struct comp_buffer *sink, *sources[PLATFORM_MAX_STREAMS], *source;
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 	struct list_item *blist;
 	int32_t i = 0, num_mix_sources = 0;
 
@@ -236,7 +227,7 @@ static int mixer_copy(struct comp_dev *dev)
 	}
 
 	/* mix streams */
-	md->mix_func(dev, sink, sources, i, config->frames);
+	md->mix_func(dev, sink, sources, i, dev->frames);
 
 	/* update source buffer pointers for overflow */
 	for (i = --num_mix_sources; i >= 0; i--)
@@ -246,7 +237,7 @@ static int mixer_copy(struct comp_dev *dev)
 	comp_update_buffer_produce(sink, md->period_bytes);
 
 	/* number of frames sent downstream */
-	return config->frames;
+	return dev->frames;
 }
 
 static int mixer_reset(struct comp_dev *dev)
diff --git a/src/audio/mux.c b/src/audio/mux.c
index 63e3035..f420bd3 100644
--- a/src/audio/mux.c
+++ b/src/audio/mux.c
@@ -53,7 +53,7 @@ static void mux_free(struct comp_dev *dev)
 }
 
 /* set component audio stream paramters */
-static int mux_params(struct comp_dev *dev, struct stream_params *params)
+static int mux_params(struct comp_dev *dev)
 {
 
 	return 0;
diff --git a/src/audio/pipeline.c b/src/audio/pipeline.c
index 817ff08..3bc1f68 100644
--- a/src/audio/pipeline.c
+++ b/src/audio/pipeline.c
@@ -65,13 +65,12 @@ static void connect_upstream(struct pipeline *p, struct comp_dev *start,
 	struct comp_dev *current)
 {
 	struct list_item *clist;
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(current);
 
 	tracev_value(current->comp.id);
 
 	/* complete component init */
 	current->pipeline = p;
-	config->frames = p->ipc_pipe.frames_per_sched;
+	current->frames = p->ipc_pipe.frames_per_sched;
 
 	/* we are an endpoint if we have 0 source components */
 	if (list_is_empty(&current->bsource_list)) {
@@ -98,13 +97,12 @@ static void connect_downstream(struct pipeline *p, struct comp_dev *start,
 	struct comp_dev *current)
 {
 	struct list_item *clist;
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(current);
 
 	tracev_value(current->comp.id);
 
 	/* complete component init */
 	current->pipeline = p;
-	config->frames = p->ipc_pipe.frames_per_sched;
+	current->frames = p->ipc_pipe.frames_per_sched;
 
 	/* we are an endpoint if we have 0 sink components */
 	if (list_is_empty(&current->bsink_list)) {
@@ -547,7 +545,7 @@ int pipeline_cmd(struct pipeline *p, struct comp_dev *host, int cmd,
  * Params are always modified in the direction of host PCM to DAI.
  */
 int pipeline_params(struct pipeline *p, struct comp_dev *host,
-	struct stream_params *params)
+	struct sof_ipc_pcm_params *params)
 {
 	struct op_data op_data;
 	int ret;
@@ -556,10 +554,11 @@ int pipeline_params(struct pipeline *p, struct comp_dev *host,
 
 	op_data.p = p;
 	op_data.op = COMP_OPS_PARAMS;
-	op_data.params = params;
 
 	spin_lock(&p->lock);
 
+	host->params = params->params;
+
 	if (host->params.direction == SOF_IPC_STREAM_PLAYBACK) {
 		/* send params downstream from host to DAI */
 		ret = component_op_downstream(&op_data, host, host);
diff --git a/src/audio/src.c b/src/audio/src.c
index 1b5d1c9..074c041 100644
--- a/src/audio/src.c
+++ b/src/audio/src.c
@@ -298,7 +298,7 @@ static void src_free(struct comp_dev *dev)
 }
 
 /* set component audio stream parameters */
-static int src_params(struct comp_dev *dev, struct stream_params *host_params)
+static int src_params(struct comp_dev *dev)
 {
 	struct sof_ipc_stream_params *params = &dev->params;
 	struct sof_ipc_comp_src *src = COMP_GET_IPC(dev, sof_ipc_comp_src);
@@ -312,8 +312,6 @@ static int src_params(struct comp_dev *dev, struct stream_params *host_params)
 
 	trace_src("par");
 
-	comp_install_params(dev, host_params);
-
 	/* EQ supports only S32_LE PCM format */
 	if (config->frame_fmt != SOF_IPC_FRAME_S32_LE)
 		return -EINVAL;
@@ -377,10 +375,10 @@ static int src_params(struct comp_dev *dev, struct stream_params *host_params)
 	/* Check that src blk_in and blk_out are less than params.period_frames.
 	 * Return an error if the period is too short.
 	 */
-	if (src_polyphase_get_blk_in(&cd->src[0]) > config->frames)
+	if (src_polyphase_get_blk_in(&cd->src[0]) > dev->frames)
 		return -EINVAL;
 
-	if (src_polyphase_get_blk_out(&cd->src[0]) > config->frames)
+	if (src_polyphase_get_blk_out(&cd->src[0]) > dev->frames)
 		return -EINVAL;
 
 	return 0;
@@ -449,7 +447,6 @@ static int src_cmd(struct comp_dev *dev, int cmd, void *data)
 static int src_copy(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 	struct comp_buffer *source;
 	struct comp_buffer *sink;
 	uint32_t frames_source;
@@ -467,23 +464,23 @@ static int src_copy(struct comp_dev *dev)
 	/* Check that source has enough frames available and sink enough
 	 * frames free.
 	 */
-	frames_source = config->frames;
-	frames_sink = config->frames;
+	frames_source = dev->frames;
+	frames_sink = dev->frames;
 
 	min_frames = src_polyphase_get_blk_in(&cd->src[0]);
 	if (frames_source > min_frames)
-		need_source = frames_source * config->frame_size;
+		need_source = frames_source * dev->frame_bytes;
 	else {
 		frames_source = min_frames;
-		need_source = min_frames * config->frame_size;
+		need_source = min_frames * dev->frame_bytes;
 	}
 
 	min_frames = src_polyphase_get_blk_out(&cd->src[0]);
 	if (frames_sink > min_frames)
-		need_sink = frames_sink * config->frame_size;
+		need_sink = frames_sink * dev->frame_bytes;
 	else {
 		frames_sink = min_frames;
-		need_sink = min_frames * config->frame_size;
+		need_sink = min_frames * dev->frame_bytes;
 	}
 
 	/* Run as many times as buffers allow */
diff --git a/src/audio/switch.c b/src/audio/switch.c
index 63a0d68..7149b61 100644
--- a/src/audio/switch.c
+++ b/src/audio/switch.c
@@ -53,7 +53,7 @@ static void switch_free(struct comp_dev *dev)
 }
 
 /* set component audio stream paramters */
-static int switch_params(struct comp_dev *dev, struct stream_params *params)
+static int switch_params(struct comp_dev *dev)
 {
 
 	return 0;
diff --git a/src/audio/tone.c b/src/audio/tone.c
index 11f63dc..777846b 100644
--- a/src/audio/tone.c
+++ b/src/audio/tone.c
@@ -403,18 +403,15 @@ static void tone_free(struct comp_dev *dev)
 }
 
 /* set component audio stream parameters */
-static int tone_params(struct comp_dev *dev, struct stream_params *host_params)
+static int tone_params(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
 	struct sof_ipc_stream_params *params = &dev->params;
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 
 	trace_tone("par");
 
-	comp_install_params(dev, host_params);
-
 	/* calculate period size based on config */
-	cd->period_bytes = config->frames * config->frame_size;
+	cd->period_bytes = dev->frames * dev->frame_bytes;
 
 	/* EQ supports only S32_LE PCM format */
 	if (params->frame_fmt != SOF_IPC_FRAME_S32_LE)
@@ -489,7 +486,6 @@ static int tone_copy(struct comp_dev *dev)
 	struct comp_buffer *sink;
 	struct comp_buffer *source = NULL;
 	struct comp_data *cd = comp_get_drvdata(dev);
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 
 	trace_comp("cpy");
 
@@ -502,12 +498,12 @@ static int tone_copy(struct comp_dev *dev)
 	 */
 	if (sink->free >= cd->period_bytes) {
 		/* create tone */
-		cd->tone_func(dev, sink, source, config->frames);
+		cd->tone_func(dev, sink, source, dev->frames);
 	}
 
 	comp_update_buffer_produce(sink, cd->period_bytes);
 
-	return config->frames;
+	return dev->frames;
 }
 
 static int tone_prepare(struct comp_dev *dev)
diff --git a/src/audio/volume.c b/src/audio/volume.c
index 33ac07d..c770e70 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -370,14 +370,13 @@ static void volume_free(struct comp_dev *dev)
 }
 
 /*
- * Set volume component audio stream paramters.
+ * Set volume component audio stream paramters - All done in prepare() since
+ * wee need to know source and sink component params.
  */
-static int volume_params(struct comp_dev *dev, struct stream_params *host_params)
+static int volume_params(struct comp_dev *dev)
 {
 	trace_volume("par");
 
-	comp_install_params(dev, host_params);
-
 	return 0;
 }
 
@@ -480,7 +479,6 @@ static int volume_copy(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
 	struct comp_buffer *sink, *source;
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 	uint32_t copy_bytes;
 
 	tracev_volume("cpy");
@@ -505,13 +503,13 @@ static int volume_copy(struct comp_dev *dev)
 	}
 
 	/* copy and scale volume */
-	cd->scale_vol(dev, sink, source, config->frames);
+	cd->scale_vol(dev, sink, source, dev->frames);
 
 	/* calc new free and available */
 	comp_update_buffer_produce(sink, cd->sink_period_bytes);
 	comp_update_buffer_consume(source, cd->source_period_bytes);
 
-	return config->frames;
+	return dev->frames;
 }
 
 /*
@@ -522,7 +520,6 @@ static int volume_prepare(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
 	struct comp_buffer *sinkb, *sourceb;
-	struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
 	struct sof_ipc_comp_config *sconfig;
 	int i;
 
@@ -533,14 +530,13 @@ static int volume_prepare(struct comp_dev *dev)
 	sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, source_list);
 
 	/* get source data format */
-	switch (sourceb->source->comp.id) {
+	switch (sourceb->source->comp.type) {
 	case SOF_COMP_HOST:
 	case SOF_COMP_SG_HOST:
-		/* source format come from IPC params */
+		/* source format comes from IPC params */
 		cd->source_format = sourceb->source->params.frame_fmt;
-		cd->source_period_bytes = config->frames *
-			sourceb->source->params.channels *
-			sourceb->source->params.sample_size;
+		cd->source_period_bytes = dev->frames *
+			comp_frame_bytes(sourceb->source);
 		break;
 	case SOF_COMP_DAI:
 	case SOF_COMP_SG_DAI:
@@ -548,20 +544,19 @@ static int volume_prepare(struct comp_dev *dev)
 		/* source format comes from DAI/comp config */
 		sconfig = COMP_GET_CONFIG(sourceb->source);
 		cd->source_format = sconfig->frame_fmt;
-		cd->source_period_bytes = config->frames *
-			sconfig->channels * sconfig->frame_size;
+		cd->source_period_bytes = dev->frames *
+			sourceb->source->frame_bytes;
 		break;
 	}
 
 	/* get sink data format */
-	switch (sinkb->sink->comp.id) {
+	switch (sinkb->sink->comp.type) {
 	case SOF_COMP_HOST:
 	case SOF_COMP_SG_HOST:
 		/* sink format come from IPC params */
 		cd->sink_format = sinkb->sink->params.frame_fmt;
-		cd->sink_period_bytes = config->frames *
-			sinkb->sink->params.channels *
-			sinkb->sink->params.sample_size;
+		cd->sink_period_bytes = dev->frames *
+			comp_frame_bytes(sinkb->sink);
 		break;
 	case SOF_COMP_DAI:
 	case SOF_COMP_SG_DAI:
@@ -569,11 +564,23 @@ static int volume_prepare(struct comp_dev *dev)
 		/* sink format comes from DAI/comp config */
 		sconfig = COMP_GET_CONFIG(sinkb->sink);
 		cd->sink_format = sconfig->frame_fmt;
-		cd->sink_period_bytes = config->frames *
-			sconfig->channels * sconfig->frame_size;
+		cd->sink_period_bytes = dev->frames *
+			sinkb->sink->frame_bytes;
 		break;
 	}
 
+	dev->frame_bytes = cd->sink_period_bytes;
+
+	/* validate */
+	if (cd->sink_period_bytes == 0) {
+		trace_volume_error("vp1");
+		return -EINVAL;
+	}
+	if (cd->source_period_bytes == 0) {
+		trace_volume_error("vp2");
+		return -EINVAL;
+	}
+
 	/* map the volume function for source and sink buffers */
 	for (i = 0; i < ARRAY_SIZE(func_map); i++) {
 
diff --git a/src/include/reef/audio/component.h b/src/include/reef/audio/component.h
index 260fbda..a8db2ec 100644
--- a/src/include/reef/audio/component.h
+++ b/src/include/reef/audio/component.h
@@ -116,7 +116,7 @@ struct comp_ops {
 	void (*free)(struct comp_dev *dev);
 
 	/* set component audio stream paramters */
-	int (*params)(struct comp_dev *dev, struct stream_params *host_params);
+	int (*params)(struct comp_dev *dev);
 
 	/* preload buffers */
 	int (*preload)(struct comp_dev *dev);
@@ -165,6 +165,8 @@ struct comp_dev {
 	uint16_t is_endpoint;	/* component is end point in pipeline */
 	spinlock_t lock;	/* lock for this component */
 	uint64_t position;	/* component rendering position */
+	uint32_t frames;	/* number of frames we copy to sink */
+	uint32_t frame_bytes;	/* frames size copied to sink in bytes */
 	struct pipeline *pipeline;	/* pipeline we belong to */
 
 	/* common runtime configuration for downstream/upstream */
@@ -213,10 +215,9 @@ static inline void comp_free(struct comp_dev *dev)
 }
 
 /* component parameter init - mandatory */
-static inline int comp_params(struct comp_dev *dev,
-	struct stream_params *params)
+static inline int comp_params(struct comp_dev *dev)
 {
-	return dev->drv->ops.params(dev, params);
+	return dev->drv->ops.params(dev);
 }
 
 /* component host buffer config
@@ -325,11 +326,11 @@ static inline int comp_buffer_reset(struct comp_dev *dev)
  * playback and upstream on capture.
  */
 static inline void comp_install_params(struct comp_dev *dev,
-	struct stream_params *host_params)
+	enum sof_ipc_stream_direction direction)
 {
 	struct comp_buffer *buffer;
 
-	if (host_params->pcm->params.direction == SOF_IPC_STREAM_PLAYBACK) {
+	if (direction == SOF_IPC_STREAM_PLAYBACK) {
 		buffer = list_first_item(&dev->bsource_list,
 			struct comp_buffer, sink_list);
 		dev->params = buffer->source->params;
@@ -340,4 +341,19 @@ static inline void comp_install_params(struct comp_dev *dev,
 	}
 }
 
+static inline uint32_t comp_frame_bytes(struct comp_dev *dev)
+{
+	/* calculate period size based on params */
+	switch (dev->params.frame_fmt) {
+	case SOF_IPC_FRAME_S16_LE:
+		return 2 * dev->params.channels;
+	case SOF_IPC_FRAME_S24_4LE:
+	case SOF_IPC_FRAME_S32_LE:
+	case SOF_IPC_FRAME_FLOAT:
+		return 4 * dev->params.channels;
+	default:
+		return 0;
+	}
+}
+
 #endif
diff --git a/src/include/reef/audio/pipeline.h b/src/include/reef/audio/pipeline.h
index ca1947a..17e8a34 100644
--- a/src/include/reef/audio/pipeline.h
+++ b/src/include/reef/audio/pipeline.h
@@ -87,7 +87,7 @@ void pipeline_complete(struct pipeline *p);
 
 /* pipeline parameters */
 int pipeline_params(struct pipeline *p, struct comp_dev *cd,
-	struct stream_params *params);
+	struct sof_ipc_pcm_params *params);
 
 /* prepare the pipeline for usage */
 int pipeline_prepare(struct pipeline *p, struct comp_dev *cd);
diff --git a/src/ipc/intel-ipc.c b/src/ipc/intel-ipc.c
index 81b30b5..bd3b21d 100644
--- a/src/ipc/intel-ipc.c
+++ b/src/ipc/intel-ipc.c
@@ -200,16 +200,12 @@ static int ipc_stream_pcm_params(uint32_t stream)
 {
 	struct intel_ipc_data *iipc = ipc_get_drvdata(_ipc);
 	struct sof_ipc_pcm_params *pcm_params = _ipc->comp_data;
-	struct stream_params params;
 	struct ipc_comp_dev *pcm_dev;
 	struct comp_dev *cd;
 	int err;
 
 	trace_ipc("SAl");
 
-	params.type = STREAM_TYPE_PCM;
-	params.pcm = pcm_params;
-
 	/* get the pcm_dev */
 	pcm_dev = ipc_get_comp(_ipc, pcm_params->comp_id);
 	if (pcm_dev == NULL) {
@@ -218,6 +214,13 @@ static int ipc_stream_pcm_params(uint32_t stream)
 		return -EINVAL;
 	}
 
+	/* sanity check comp */
+	if (pcm_dev->cd->pipeline == NULL) {
+		trace_ipc_error("eA1");
+		trace_value(pcm_params->comp_id);
+		return -EINVAL;
+	}
+
 	/* set params component params */
 	cd = pcm_dev->cd;
 	cd->params = pcm_params->params;
@@ -238,7 +241,7 @@ static int ipc_stream_pcm_params(uint32_t stream)
 	}
 
 	/* configure pipeline audio params */
-	err = pipeline_params(pcm_dev->cd->pipeline, pcm_dev->cd, &params);
+	err = pipeline_params(pcm_dev->cd->pipeline, pcm_dev->cd, pcm_params);
 	if (err < 0) {
 		trace_ipc_error("eAa");
 		goto error;
-- 
2.11.0



More information about the Sound-open-firmware mailing list