Lines Matching refs:stream

52 	struct snd_compr_stream stream;  member
114 INIT_DELAYED_WORK(&data->stream.error_work, error_delayed_work); in snd_compr_open()
116 data->stream.ops = compr->ops; in snd_compr_open()
117 data->stream.direction = dirn; in snd_compr_open()
118 data->stream.private_data = compr->private_data; in snd_compr_open()
119 data->stream.device = compr; in snd_compr_open()
128 data->stream.runtime = runtime; in snd_compr_open()
131 ret = compr->ops->open(&data->stream); in snd_compr_open()
144 struct snd_compr_runtime *runtime = data->stream.runtime; in snd_compr_free()
146 cancel_delayed_work_sync(&data->stream.error_work); in snd_compr_free()
152 data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP); in snd_compr_free()
158 data->stream.ops->free(&data->stream); in snd_compr_free()
159 if (!data->stream.runtime->dma_buffer_p) in snd_compr_free()
160 kfree(data->stream.runtime->buffer); in snd_compr_free()
161 kfree(data->stream.runtime); in snd_compr_free()
166 static int snd_compr_update_tstamp(struct snd_compr_stream *stream, in snd_compr_update_tstamp() argument
169 if (!stream->ops->pointer) in snd_compr_update_tstamp()
171 stream->ops->pointer(stream, tstamp); in snd_compr_update_tstamp()
174 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_update_tstamp()
175 stream->runtime->total_bytes_transferred = tstamp->copied_total; in snd_compr_update_tstamp()
177 stream->runtime->total_bytes_available = tstamp->copied_total; in snd_compr_update_tstamp()
181 static size_t snd_compr_calc_avail(struct snd_compr_stream *stream, in snd_compr_calc_avail() argument
185 snd_compr_update_tstamp(stream, &avail->tstamp); in snd_compr_calc_avail()
188 if (stream->runtime->total_bytes_available == 0 && in snd_compr_calc_avail()
189 stream->runtime->state == SNDRV_PCM_STATE_SETUP && in snd_compr_calc_avail()
190 stream->direction == SND_COMPRESS_PLAYBACK) { in snd_compr_calc_avail()
192 return stream->runtime->buffer_size; in snd_compr_calc_avail()
195 stream->runtime->total_bytes_available, in snd_compr_calc_avail()
196 stream->runtime->total_bytes_transferred); in snd_compr_calc_avail()
197 if (stream->runtime->total_bytes_available == in snd_compr_calc_avail()
198 stream->runtime->total_bytes_transferred) { in snd_compr_calc_avail()
199 if (stream->direction == SND_COMPRESS_PLAYBACK) { in snd_compr_calc_avail()
201 return stream->runtime->buffer_size; in snd_compr_calc_avail()
208 avail->avail = stream->runtime->total_bytes_available - in snd_compr_calc_avail()
209 stream->runtime->total_bytes_transferred; in snd_compr_calc_avail()
210 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_calc_avail()
211 avail->avail = stream->runtime->buffer_size - avail->avail; in snd_compr_calc_avail()
217 static inline size_t snd_compr_get_avail(struct snd_compr_stream *stream) in snd_compr_get_avail() argument
221 return snd_compr_calc_avail(stream, &avail); in snd_compr_get_avail()
225 snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_ioctl_avail() argument
230 avail = snd_compr_calc_avail(stream, &ioctl_avail); in snd_compr_ioctl_avail()
233 switch (stream->runtime->state) { in snd_compr_ioctl_avail()
248 static int snd_compr_write_data(struct snd_compr_stream *stream, in snd_compr_write_data() argument
253 struct snd_compr_runtime *runtime = stream->runtime; in snd_compr_write_data()
274 if (stream->ops->ack) in snd_compr_write_data()
275 stream->ops->ack(stream, count); in snd_compr_write_data()
283 struct snd_compr_stream *stream; in snd_compr_write() local
290 stream = &data->stream; in snd_compr_write()
291 mutex_lock(&stream->device->lock); in snd_compr_write()
293 switch (stream->runtime->state) { in snd_compr_write()
299 mutex_unlock(&stream->device->lock); in snd_compr_write()
303 avail = snd_compr_get_avail(stream); in snd_compr_write()
309 if (stream->ops->copy) { in snd_compr_write()
311 retval = stream->ops->copy(stream, cbuf, avail); in snd_compr_write()
313 retval = snd_compr_write_data(stream, buf, avail); in snd_compr_write()
316 stream->runtime->total_bytes_available += retval; in snd_compr_write()
320 if (stream->runtime->state == SNDRV_PCM_STATE_SETUP) { in snd_compr_write()
321 stream->runtime->state = SNDRV_PCM_STATE_PREPARED; in snd_compr_write()
325 mutex_unlock(&stream->device->lock); in snd_compr_write()
334 struct snd_compr_stream *stream; in snd_compr_read() local
341 stream = &data->stream; in snd_compr_read()
342 mutex_lock(&stream->device->lock); in snd_compr_read()
348 switch (stream->runtime->state) { in snd_compr_read()
360 avail = snd_compr_get_avail(stream); in snd_compr_read()
366 if (stream->ops->copy) { in snd_compr_read()
367 retval = stream->ops->copy(stream, buf, avail); in snd_compr_read()
373 stream->runtime->total_bytes_transferred += retval; in snd_compr_read()
376 mutex_unlock(&stream->device->lock); in snd_compr_read()
385 static __poll_t snd_compr_get_poll(struct snd_compr_stream *stream) in snd_compr_get_poll() argument
387 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_get_poll()
396 struct snd_compr_stream *stream; in snd_compr_poll() local
403 stream = &data->stream; in snd_compr_poll()
405 mutex_lock(&stream->device->lock); in snd_compr_poll()
407 switch (stream->runtime->state) { in snd_compr_poll()
410 retval = snd_compr_get_poll(stream) | EPOLLERR; in snd_compr_poll()
416 poll_wait(f, &stream->runtime->sleep, wait); in snd_compr_poll()
418 avail = snd_compr_get_avail(stream); in snd_compr_poll()
421 switch (stream->runtime->state) { in snd_compr_poll()
426 retval = snd_compr_get_poll(stream); in snd_compr_poll()
427 stream->runtime->state = SNDRV_PCM_STATE_SETUP; in snd_compr_poll()
432 if (avail >= stream->runtime->fragment_size) in snd_compr_poll()
433 retval = snd_compr_get_poll(stream); in snd_compr_poll()
436 retval = snd_compr_get_poll(stream) | EPOLLERR; in snd_compr_poll()
440 mutex_unlock(&stream->device->lock); in snd_compr_poll()
445 snd_compr_get_caps(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_caps() argument
450 if (!stream->ops->get_caps) in snd_compr_get_caps()
454 retval = stream->ops->get_caps(stream, &caps); in snd_compr_get_caps()
465 snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_codec_caps() argument
470 if (!stream->ops->get_codec_caps) in snd_compr_get_codec_caps()
477 retval = stream->ops->get_codec_caps(stream, caps); in snd_compr_get_codec_caps()
489 int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size) in snd_compr_malloc_pages() argument
494 if (snd_BUG_ON(!(stream) || !(stream)->runtime)) in snd_compr_malloc_pages()
499 dmab->dev = stream->dma_buffer.dev; in snd_compr_malloc_pages()
506 snd_compr_set_runtime_buffer(stream, dmab); in snd_compr_malloc_pages()
507 stream->runtime->dma_bytes = size; in snd_compr_malloc_pages()
512 int snd_compr_free_pages(struct snd_compr_stream *stream) in snd_compr_free_pages() argument
516 if (snd_BUG_ON(!(stream) || !(stream)->runtime)) in snd_compr_free_pages()
518 runtime = stream->runtime; in snd_compr_free_pages()
521 if (runtime->dma_buffer_p != &stream->dma_buffer) { in snd_compr_free_pages()
527 snd_compr_set_runtime_buffer(stream, NULL); in snd_compr_free_pages()
533 static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, in snd_compr_allocate_buffer() argument
540 if (stream->ops->copy) { in snd_compr_allocate_buffer()
546 if (stream->runtime->dma_buffer_p) { in snd_compr_allocate_buffer()
548 if (buffer_size > stream->runtime->dma_buffer_p->bytes) in snd_compr_allocate_buffer()
549 dev_err(&stream->device->dev, in snd_compr_allocate_buffer()
552 buffer = stream->runtime->dma_buffer_p->area; in snd_compr_allocate_buffer()
561 stream->runtime->fragment_size = params->buffer.fragment_size; in snd_compr_allocate_buffer()
562 stream->runtime->fragments = params->buffer.fragments; in snd_compr_allocate_buffer()
563 stream->runtime->buffer = buffer; in snd_compr_allocate_buffer()
564 stream->runtime->buffer_size = buffer_size; in snd_compr_allocate_buffer()
587 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_set_params() argument
592 if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) { in snd_compr_set_params()
605 retval = snd_compr_allocate_buffer(stream, params); in snd_compr_set_params()
611 retval = stream->ops->set_params(stream, params); in snd_compr_set_params()
615 stream->metadata_set = false; in snd_compr_set_params()
616 stream->next_track = false; in snd_compr_set_params()
618 stream->runtime->state = SNDRV_PCM_STATE_SETUP; in snd_compr_set_params()
628 snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_params() argument
633 if (!stream->ops->get_params) in snd_compr_get_params()
639 retval = stream->ops->get_params(stream, params); in snd_compr_get_params()
651 snd_compr_get_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_metadata() argument
656 if (!stream->ops->get_metadata) in snd_compr_get_metadata()
662 retval = stream->ops->get_metadata(stream, &metadata); in snd_compr_get_metadata()
673 snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_set_metadata() argument
678 if (!stream->ops->set_metadata) in snd_compr_set_metadata()
687 retval = stream->ops->set_metadata(stream, &metadata); in snd_compr_set_metadata()
688 stream->metadata_set = true; in snd_compr_set_metadata()
694 snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_tstamp() argument
699 ret = snd_compr_update_tstamp(stream, &tstamp); in snd_compr_tstamp()
706 static int snd_compr_pause(struct snd_compr_stream *stream) in snd_compr_pause() argument
710 switch (stream->runtime->state) { in snd_compr_pause()
712 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); in snd_compr_pause()
714 stream->runtime->state = SNDRV_PCM_STATE_PAUSED; in snd_compr_pause()
717 if (!stream->device->use_pause_in_draining) in snd_compr_pause()
719 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); in snd_compr_pause()
721 stream->pause_in_draining = true; in snd_compr_pause()
729 static int snd_compr_resume(struct snd_compr_stream *stream) in snd_compr_resume() argument
733 switch (stream->runtime->state) { in snd_compr_resume()
735 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); in snd_compr_resume()
737 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_resume()
740 if (!stream->pause_in_draining) in snd_compr_resume()
742 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); in snd_compr_resume()
744 stream->pause_in_draining = false; in snd_compr_resume()
752 static int snd_compr_start(struct snd_compr_stream *stream) in snd_compr_start() argument
756 switch (stream->runtime->state) { in snd_compr_start()
758 if (stream->direction != SND_COMPRESS_CAPTURE) in snd_compr_start()
767 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_START); in snd_compr_start()
769 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_start()
773 static int snd_compr_stop(struct snd_compr_stream *stream) in snd_compr_stop() argument
777 switch (stream->runtime->state) { in snd_compr_stop()
786 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in snd_compr_stop()
789 stream->partial_drain = false; in snd_compr_stop()
790 stream->metadata_set = false; in snd_compr_stop()
791 stream->pause_in_draining = false; in snd_compr_stop()
792 snd_compr_drain_notify(stream); in snd_compr_stop()
793 stream->runtime->total_bytes_available = 0; in snd_compr_stop()
794 stream->runtime->total_bytes_transferred = 0; in snd_compr_stop()
801 struct snd_compr_stream *stream; in error_delayed_work() local
803 stream = container_of(work, struct snd_compr_stream, error_work.work); in error_delayed_work()
805 mutex_lock(&stream->device->lock); in error_delayed_work()
807 stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in error_delayed_work()
808 wake_up(&stream->runtime->sleep); in error_delayed_work()
810 mutex_unlock(&stream->device->lock); in error_delayed_work()
822 int snd_compr_stop_error(struct snd_compr_stream *stream, in snd_compr_stop_error() argument
825 if (stream->runtime->state == state) in snd_compr_stop_error()
828 stream->runtime->state = state; in snd_compr_stop_error()
832 queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0); in snd_compr_stop_error()
838 static int snd_compress_wait_for_drain(struct snd_compr_stream *stream) in snd_compress_wait_for_drain() argument
850 stream->runtime->state = SNDRV_PCM_STATE_DRAINING; in snd_compress_wait_for_drain()
851 mutex_unlock(&stream->device->lock); in snd_compress_wait_for_drain()
859 ret = wait_event_interruptible(stream->runtime->sleep, in snd_compress_wait_for_drain()
860 (stream->runtime->state != SNDRV_PCM_STATE_DRAINING)); in snd_compress_wait_for_drain()
867 wake_up(&stream->runtime->sleep); in snd_compress_wait_for_drain()
868 mutex_lock(&stream->device->lock); in snd_compress_wait_for_drain()
873 static int snd_compr_drain(struct snd_compr_stream *stream) in snd_compr_drain() argument
877 switch (stream->runtime->state) { in snd_compr_drain()
889 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); in snd_compr_drain()
892 wake_up(&stream->runtime->sleep); in snd_compr_drain()
896 return snd_compress_wait_for_drain(stream); in snd_compr_drain()
899 static int snd_compr_next_track(struct snd_compr_stream *stream) in snd_compr_next_track() argument
904 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) in snd_compr_next_track()
908 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_next_track()
914 if (stream->metadata_set == false) in snd_compr_next_track()
917 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_NEXT_TRACK); in snd_compr_next_track()
920 stream->metadata_set = false; in snd_compr_next_track()
921 stream->next_track = true; in snd_compr_next_track()
925 static int snd_compr_partial_drain(struct snd_compr_stream *stream) in snd_compr_partial_drain() argument
929 switch (stream->runtime->state) { in snd_compr_partial_drain()
942 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_partial_drain()
946 if (stream->next_track == false) in snd_compr_partial_drain()
949 stream->partial_drain = true; in snd_compr_partial_drain()
950 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); in snd_compr_partial_drain()
953 wake_up(&stream->runtime->sleep); in snd_compr_partial_drain()
957 stream->next_track = false; in snd_compr_partial_drain()
958 return snd_compress_wait_for_drain(stream); in snd_compr_partial_drain()
964 struct snd_compr_stream *stream; in snd_compr_ioctl() local
970 stream = &data->stream; in snd_compr_ioctl()
972 mutex_lock(&stream->device->lock); in snd_compr_ioctl()
979 retval = snd_compr_get_caps(stream, arg); in snd_compr_ioctl()
983 retval = snd_compr_get_codec_caps(stream, arg); in snd_compr_ioctl()
987 retval = snd_compr_set_params(stream, arg); in snd_compr_ioctl()
990 retval = snd_compr_get_params(stream, arg); in snd_compr_ioctl()
993 retval = snd_compr_set_metadata(stream, arg); in snd_compr_ioctl()
996 retval = snd_compr_get_metadata(stream, arg); in snd_compr_ioctl()
999 retval = snd_compr_tstamp(stream, arg); in snd_compr_ioctl()
1002 retval = snd_compr_ioctl_avail(stream, arg); in snd_compr_ioctl()
1005 retval = snd_compr_pause(stream); in snd_compr_ioctl()
1008 retval = snd_compr_resume(stream); in snd_compr_ioctl()
1011 retval = snd_compr_start(stream); in snd_compr_ioctl()
1014 retval = snd_compr_stop(stream); in snd_compr_ioctl()
1017 retval = snd_compr_drain(stream); in snd_compr_ioctl()
1020 retval = snd_compr_partial_drain(stream); in snd_compr_ioctl()
1023 retval = snd_compr_next_track(stream); in snd_compr_ioctl()
1027 mutex_unlock(&stream->device->lock); in snd_compr_ioctl()