[Sound-open-firmware] [PATCH v2 5/5] host: integrate consume and produce to host_update_buffer

Keyon Jie yang.jie at linux.intel.com
Thu Feb 16 09:08:40 CET 2017


For capture, the read/write pointers are opposite, here we
integrate produce/consume to host_update_buffer(hd, produce).
We also change 'inline' to real function to save code size
at the same time.

Signed-off-by: Keyon Jie <yang.jie at linux.intel.com>
---
 src/audio/host.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/src/audio/host.c b/src/audio/host.c
index 419aca3..92b5cf3 100644
--- a/src/audio/host.c
+++ b/src/audio/host.c
@@ -89,23 +89,12 @@ struct host_data {
 	struct comp_position cp;
 };
 
-static void host_update_buffer_produce(struct host_data *hd)
+static void host_update_buffer(struct host_data *hd, uint32_t produce)
 {
 	if (hd->host_r_ptr < hd->host_w_ptr)
 		hd->host_avail = hd->host_w_ptr - hd->host_r_ptr;
 	else if (hd->host_r_ptr == hd->host_w_ptr)
-		hd->host_avail = hd->host_size;
-	else
-		hd->host_avail = hd->host_size -hd->host_r_ptr + hd->host_w_ptr;
-	hd->host_free = hd->host_size - hd->host_avail;
-}
-
-static void host_update_buffer_consume(struct host_data *hd)
-{
-	if (hd->host_r_ptr < hd->host_w_ptr)
-		hd->host_avail = hd->host_w_ptr - hd->host_r_ptr;
-	else if (hd->host_r_ptr == hd->host_w_ptr)
-		hd->host_avail = 0;
+		hd->host_avail = produce ? hd->host_size : 0;
 	else
 		hd->host_avail = hd->host_size -hd->host_r_ptr + hd->host_w_ptr;
 	hd->host_free = hd->host_size - hd->host_avail;
@@ -166,7 +155,7 @@ static void host_dma_cb_playback(struct comp_dev *dev,
 	/* buffer overlap ? */
 	if (hd->host_r_ptr >= hd->host_size)
 		hd->host_r_ptr = 0;
-	host_update_buffer_consume(hd);
+	host_update_buffer(hd, 0); /* consume */
 
 	/* send IPC message to driver if needed */
 	hd->host_period_pos += local_elem->size;
@@ -641,7 +630,7 @@ static int host_prepare(struct comp_dev *dev)
 		hd->params.period_frames * hd->params.frame_size;
 	hd->split_remaining = 0;
 
-	host_update_buffer_consume(hd);
+	host_update_buffer(hd, 0); /* consume */
 
 	dev->preload = PLAT_HOST_PERIODS;
 
@@ -680,7 +669,7 @@ static int host_pointer_reset(struct comp_dev *dev)
 	hd->host_w_ptr = 0;
 	hd->host_period_pos = 0;
 
-	host_update_buffer_consume(hd);
+	host_update_buffer(hd, 0); /* consume */
 
 	return 0;
 }
@@ -739,11 +728,11 @@ static int host_cmd(struct comp_dev *dev, int cmd, void *data)
 
 		if (hd->params.direction == STREAM_DIRECTION_PLAYBACK) {
 			hd->host_w_ptr = app_pos->position;
-			host_update_buffer_produce(hd);
+			host_update_buffer(hd, 1); /* produce */
 		}
 		else {
 			hd->host_r_ptr = app_pos->position;
-			host_update_buffer_consume(hd);
+			host_update_buffer(hd, 0); /* consume */
 		}
 		break;
 	case COMP_CMD_VOLUME:
@@ -772,7 +761,7 @@ static int host_buffer(struct comp_dev *dev, struct dma_sg_elem *elem,
 	*e = *elem;
 	hd->host_size = host_size;
 
-	host_update_buffer_consume(hd);
+	host_update_buffer(hd, 0); /* consume */
 
 	list_item_append(&e->list, &hd->host.elem_list);
 	return 0;
-- 
2.7.4



More information about the Sound-open-firmware mailing list