Skip to content

Commit 49bb640

Browse files
charleskeepaxtiwai
authored andcommitted
ALSA: compress_core: Add support for capture streams
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Acked-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 4daf891 commit 49bb640

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

sound/core/compress_offload.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,41 @@ static ssize_t snd_compr_write(struct file *f, const char __user *buf,
296296
static ssize_t snd_compr_read(struct file *f, char __user *buf,
297297
size_t count, loff_t *offset)
298298
{
299-
return -ENXIO;
299+
struct snd_compr_file *data = f->private_data;
300+
struct snd_compr_stream *stream;
301+
size_t avail;
302+
int retval;
303+
304+
if (snd_BUG_ON(!data))
305+
return -EFAULT;
306+
307+
stream = &data->stream;
308+
mutex_lock(&stream->device->lock);
309+
310+
/* read is allowed when stream is running */
311+
if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
312+
retval = -EBADFD;
313+
goto out;
314+
}
315+
316+
avail = snd_compr_get_avail(stream);
317+
pr_debug("avail returned %ld\n", (unsigned long)avail);
318+
/* calculate how much we can read from buffer */
319+
if (avail > count)
320+
avail = count;
321+
322+
if (stream->ops->copy) {
323+
retval = stream->ops->copy(stream, buf, avail);
324+
} else {
325+
retval = -ENXIO;
326+
goto out;
327+
}
328+
if (retval > 0)
329+
stream->runtime->total_bytes_transferred += retval;
330+
331+
out:
332+
mutex_unlock(&stream->device->lock);
333+
return retval;
300334
}
301335

302336
static int snd_compr_mmap(struct file *f, struct vm_area_struct *vma)
@@ -481,9 +515,14 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
481515
retval = stream->ops->set_params(stream, params);
482516
if (retval)
483517
goto out;
484-
stream->runtime->state = SNDRV_PCM_STATE_SETUP;
518+
485519
stream->metadata_set = false;
486520
stream->next_track = false;
521+
522+
if (stream->direction == SND_COMPRESS_PLAYBACK)
523+
stream->runtime->state = SNDRV_PCM_STATE_SETUP;
524+
else
525+
stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
487526
} else {
488527
return -EPERM;
489528
}

0 commit comments

Comments
 (0)