Skip to content

Commit 7a75c0d

Browse files
committed
Merge branch 'topic/compress' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into asoc-adsp
2 parents 546ad3d + a4f2d87 commit 7a75c0d

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

include/sound/compress_driver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct snd_compr_runtime {
6868
* @ops: pointer to DSP callbacks
6969
* @runtime: pointer to runtime structure
7070
* @device: device pointer
71+
* @error_work: delayed work used when closing the stream due to an error
7172
* @direction: stream direction, playback/recording
7273
* @metadata_set: metadata set flag, true when set
7374
* @next_track: has userspace signal next track transition, true when set
@@ -78,6 +79,7 @@ struct snd_compr_stream {
7879
struct snd_compr_ops *ops;
7980
struct snd_compr_runtime *runtime;
8081
struct snd_compr *device;
82+
struct delayed_work error_work;
8183
enum snd_compr_direction direction;
8284
bool metadata_set;
8385
bool next_track;
@@ -187,4 +189,7 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
187189
wake_up(&stream->runtime->sleep);
188190
}
189191

192+
int snd_compr_stop_error(struct snd_compr_stream *stream,
193+
snd_pcm_state_t state);
194+
190195
#endif

sound/core/compress_offload.c

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct snd_compr_file {
6767
struct snd_compr_stream stream;
6868
};
6969

70+
static void error_delayed_work(struct work_struct *work);
71+
7072
/*
7173
* a note on stream states used:
7274
* we use following states in the compressed core
@@ -123,6 +125,9 @@ static int snd_compr_open(struct inode *inode, struct file *f)
123125
snd_card_unref(compr->card);
124126
return -ENOMEM;
125127
}
128+
129+
INIT_DELAYED_WORK(&data->stream.error_work, error_delayed_work);
130+
126131
data->stream.ops = compr->ops;
127132
data->stream.direction = dirn;
128133
data->stream.private_data = compr->private_data;
@@ -153,6 +158,8 @@ static int snd_compr_free(struct inode *inode, struct file *f)
153158
struct snd_compr_file *data = f->private_data;
154159
struct snd_compr_runtime *runtime = data->stream.runtime;
155160

161+
cancel_delayed_work_sync(&data->stream.error_work);
162+
156163
switch (runtime->state) {
157164
case SNDRV_PCM_STATE_RUNNING:
158165
case SNDRV_PCM_STATE_DRAINING:
@@ -237,6 +244,15 @@ snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg)
237244
avail = snd_compr_calc_avail(stream, &ioctl_avail);
238245
ioctl_avail.avail = avail;
239246

247+
switch (stream->runtime->state) {
248+
case SNDRV_PCM_STATE_OPEN:
249+
return -EBADFD;
250+
case SNDRV_PCM_STATE_XRUN:
251+
return -EPIPE;
252+
default:
253+
break;
254+
}
255+
240256
if (copy_to_user((__u64 __user *)arg,
241257
&ioctl_avail, sizeof(ioctl_avail)))
242258
return -EFAULT;
@@ -346,11 +362,13 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
346362
switch (stream->runtime->state) {
347363
case SNDRV_PCM_STATE_OPEN:
348364
case SNDRV_PCM_STATE_PREPARED:
349-
case SNDRV_PCM_STATE_XRUN:
350365
case SNDRV_PCM_STATE_SUSPENDED:
351366
case SNDRV_PCM_STATE_DISCONNECTED:
352367
retval = -EBADFD;
353368
goto out;
369+
case SNDRV_PCM_STATE_XRUN:
370+
retval = -EPIPE;
371+
goto out;
354372
}
355373

356374
avail = snd_compr_get_avail(stream);
@@ -399,10 +417,16 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
399417
stream = &data->stream;
400418

401419
mutex_lock(&stream->device->lock);
402-
if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
420+
421+
switch (stream->runtime->state) {
422+
case SNDRV_PCM_STATE_OPEN:
423+
case SNDRV_PCM_STATE_XRUN:
403424
retval = snd_compr_get_poll(stream) | POLLERR;
404425
goto out;
426+
default:
427+
break;
405428
}
429+
406430
poll_wait(f, &stream->runtime->sleep, wait);
407431

408432
avail = snd_compr_get_avail(stream);
@@ -697,6 +721,45 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
697721
return retval;
698722
}
699723

724+
static void error_delayed_work(struct work_struct *work)
725+
{
726+
struct snd_compr_stream *stream;
727+
728+
stream = container_of(work, struct snd_compr_stream, error_work.work);
729+
730+
mutex_lock(&stream->device->lock);
731+
732+
stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
733+
wake_up(&stream->runtime->sleep);
734+
735+
mutex_unlock(&stream->device->lock);
736+
}
737+
738+
/*
739+
* snd_compr_stop_error: Report a fatal error on a stream
740+
* @stream: pointer to stream
741+
* @state: state to transition the stream to
742+
*
743+
* Stop the stream and set its state.
744+
*
745+
* Should be called with compressed device lock held.
746+
*/
747+
int snd_compr_stop_error(struct snd_compr_stream *stream,
748+
snd_pcm_state_t state)
749+
{
750+
if (stream->runtime->state == state)
751+
return 0;
752+
753+
stream->runtime->state = state;
754+
755+
pr_debug("Changing state to: %d\n", state);
756+
757+
queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0);
758+
759+
return 0;
760+
}
761+
EXPORT_SYMBOL_GPL(snd_compr_stop_error);
762+
700763
static int snd_compress_wait_for_drain(struct snd_compr_stream *stream)
701764
{
702765
int ret;

0 commit comments

Comments
 (0)