@@ -296,7 +296,41 @@ static ssize_t snd_compr_write(struct file *f, const char __user *buf,
296
296
static ssize_t snd_compr_read (struct file * f , char __user * buf ,
297
297
size_t count , loff_t * offset )
298
298
{
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 ;
300
334
}
301
335
302
336
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)
481
515
retval = stream -> ops -> set_params (stream , params );
482
516
if (retval )
483
517
goto out ;
484
- stream -> runtime -> state = SNDRV_PCM_STATE_SETUP ;
518
+
485
519
stream -> metadata_set = false;
486
520
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 ;
487
526
} else {
488
527
return - EPERM ;
489
528
}
0 commit comments