[alsa-devel] [PATCH 2/3] ALSA: compress_core: Split copy into seperate read and write callbacks

Charles Keepax ckeepax at opensource.wolfsonmicro.com
Wed Apr 3 14:13:28 CEST 2013


The compress API for non-memory mapped DSPs shares a copy callback for
both read and write, however the file operation of write passes a const
buffer. Thus we can't maintain const correctness for the copy callback
and support both read and write.

This patch seperates the read and write callbacks in the compressed API.

Signed-off-by: Charles Keepax <ckeepax at opensource.wolfsonmicro.com>
---
 include/sound/compress_driver.h |    8 ++++++--
 sound/core/compress_offload.c   |    6 +++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
index ff6c741..4c64dd1 100644
--- a/include/sound/compress_driver.h
+++ b/include/sound/compress_driver.h
@@ -99,7 +99,9 @@ struct snd_compr_stream {
  * @trigger: Trigger operations like start, pause, resume, drain, stop.
  * This callback is mandatory
  * @pointer: Retrieve current h/w pointer information. Mandatory
- * @copy: Copy the compressed data to/from userspace, Optional
+ * @write: Copy the compressed data from userspace, Optional
+ * Can't be implemented if DSP supports mmap
+ * @read: Copy the compressed data to userspace, Optional
  * Can't be implemented if DSP supports mmap
  * @mmap: DSP mmap method to mmap DSP memory
  * @ack: Ack for DSP when data is written to audio buffer, Optional
@@ -121,7 +123,9 @@ struct snd_compr_ops {
 	int (*trigger)(struct snd_compr_stream *stream, int cmd);
 	int (*pointer)(struct snd_compr_stream *stream,
 			struct snd_compr_tstamp *tstamp);
-	int (*copy)(struct snd_compr_stream *stream, const char __user *buf,
+	int (*write)(struct snd_compr_stream *stream, const char __user *buf,
+		       size_t count);
+	int (*read)(struct snd_compr_stream *stream, char __user *buf,
 		       size_t count);
 	int (*mmap)(struct snd_compr_stream *stream,
 			struct vm_area_struct *vma);
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 27bd81a..78c6f97 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -265,8 +265,8 @@ static ssize_t snd_compr_write(struct file *f, const char __user *buf,
 	if (avail > count)
 		avail = count;
 
-	if (stream->ops->copy)
-		retval = stream->ops->copy(stream, buf, avail);
+	if (stream->ops->write)
+		retval = stream->ops->write(stream, buf, avail);
 	else
 		retval = snd_compr_write_data(stream, buf, avail);
 	if (retval > 0)
@@ -403,7 +403,7 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
 	void *buffer;
 
 	buffer_size = params->buffer.fragment_size * params->buffer.fragments;
-	if (stream->ops->copy) {
+	if (stream->ops->write) {
 		buffer = NULL;
 		/* if copy is defined the driver will be required to copy
 		 * the data from core
-- 
1.7.2.5



More information about the Alsa-devel mailing list