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 || stream->next_track) { 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 if (stream->next_track) in snd_compr_set_params()
618 stream->metadata_set = false; in snd_compr_set_params()
619 stream->next_track = false; in snd_compr_set_params()
621 stream->runtime->state = SNDRV_PCM_STATE_SETUP; in snd_compr_set_params()
631 snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_params() argument
636 if (!stream->ops->get_params) in snd_compr_get_params()
642 retval = stream->ops->get_params(stream, params); in snd_compr_get_params()
654 snd_compr_get_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_metadata() argument
659 if (!stream->ops->get_metadata) in snd_compr_get_metadata()
665 retval = stream->ops->get_metadata(stream, &metadata); in snd_compr_get_metadata()
676 snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_set_metadata() argument
681 if (!stream->ops->set_metadata) in snd_compr_set_metadata()
690 retval = stream->ops->set_metadata(stream, &metadata); in snd_compr_set_metadata()
691 stream->metadata_set = true; in snd_compr_set_metadata()
697 snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_tstamp() argument
702 ret = snd_compr_update_tstamp(stream, &tstamp); in snd_compr_tstamp()
709 static int snd_compr_pause(struct snd_compr_stream *stream) in snd_compr_pause() argument
713 switch (stream->runtime->state) { in snd_compr_pause()
715 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); in snd_compr_pause()
717 stream->runtime->state = SNDRV_PCM_STATE_PAUSED; in snd_compr_pause()
720 if (!stream->device->use_pause_in_draining) in snd_compr_pause()
722 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); in snd_compr_pause()
724 stream->pause_in_draining = true; in snd_compr_pause()
732 static int snd_compr_resume(struct snd_compr_stream *stream) in snd_compr_resume() argument
736 switch (stream->runtime->state) { in snd_compr_resume()
738 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); in snd_compr_resume()
740 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_resume()
743 if (!stream->pause_in_draining) in snd_compr_resume()
745 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); in snd_compr_resume()
747 stream->pause_in_draining = false; in snd_compr_resume()
755 static int snd_compr_start(struct snd_compr_stream *stream) in snd_compr_start() argument
759 switch (stream->runtime->state) { in snd_compr_start()
761 if (stream->direction != SND_COMPRESS_CAPTURE) in snd_compr_start()
770 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_START); in snd_compr_start()
772 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_start()
776 static int snd_compr_stop(struct snd_compr_stream *stream) in snd_compr_stop() argument
780 switch (stream->runtime->state) { in snd_compr_stop()
789 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in snd_compr_stop()
792 stream->partial_drain = false; in snd_compr_stop()
793 stream->metadata_set = false; in snd_compr_stop()
794 stream->pause_in_draining = false; in snd_compr_stop()
795 snd_compr_drain_notify(stream); in snd_compr_stop()
796 stream->runtime->total_bytes_available = 0; in snd_compr_stop()
797 stream->runtime->total_bytes_transferred = 0; in snd_compr_stop()
804 struct snd_compr_stream *stream; in error_delayed_work() local
806 stream = container_of(work, struct snd_compr_stream, error_work.work); in error_delayed_work()
808 mutex_lock(&stream->device->lock); in error_delayed_work()
810 stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in error_delayed_work()
811 wake_up(&stream->runtime->sleep); in error_delayed_work()
813 mutex_unlock(&stream->device->lock); in error_delayed_work()
827 int snd_compr_stop_error(struct snd_compr_stream *stream, in snd_compr_stop_error() argument
830 if (stream->runtime->state == state) in snd_compr_stop_error()
833 stream->runtime->state = state; in snd_compr_stop_error()
837 queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0); in snd_compr_stop_error()
843 static int snd_compress_wait_for_drain(struct snd_compr_stream *stream) in snd_compress_wait_for_drain() argument
855 stream->runtime->state = SNDRV_PCM_STATE_DRAINING; in snd_compress_wait_for_drain()
856 mutex_unlock(&stream->device->lock); in snd_compress_wait_for_drain()
864 ret = wait_event_interruptible(stream->runtime->sleep, in snd_compress_wait_for_drain()
865 (stream->runtime->state != SNDRV_PCM_STATE_DRAINING)); in snd_compress_wait_for_drain()
872 wake_up(&stream->runtime->sleep); in snd_compress_wait_for_drain()
873 mutex_lock(&stream->device->lock); in snd_compress_wait_for_drain()
878 static int snd_compr_drain(struct snd_compr_stream *stream) in snd_compr_drain() argument
882 switch (stream->runtime->state) { in snd_compr_drain()
894 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); in snd_compr_drain()
897 wake_up(&stream->runtime->sleep); in snd_compr_drain()
901 return snd_compress_wait_for_drain(stream); in snd_compr_drain()
904 static int snd_compr_next_track(struct snd_compr_stream *stream) in snd_compr_next_track() argument
909 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) in snd_compr_next_track()
913 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_next_track()
919 if (stream->metadata_set == false) in snd_compr_next_track()
922 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_NEXT_TRACK); in snd_compr_next_track()
925 stream->metadata_set = false; in snd_compr_next_track()
926 stream->next_track = true; in snd_compr_next_track()
930 static int snd_compr_partial_drain(struct snd_compr_stream *stream) in snd_compr_partial_drain() argument
934 switch (stream->runtime->state) { in snd_compr_partial_drain()
947 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_partial_drain()
951 if (stream->next_track == false) in snd_compr_partial_drain()
954 stream->partial_drain = true; in snd_compr_partial_drain()
955 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); in snd_compr_partial_drain()
958 wake_up(&stream->runtime->sleep); in snd_compr_partial_drain()
962 stream->next_track = false; in snd_compr_partial_drain()
963 return snd_compress_wait_for_drain(stream); in snd_compr_partial_drain()
969 struct snd_compr_stream *stream; in snd_compr_ioctl() local
975 stream = &data->stream; in snd_compr_ioctl()
977 mutex_lock(&stream->device->lock); in snd_compr_ioctl()
984 retval = snd_compr_get_caps(stream, arg); in snd_compr_ioctl()
988 retval = snd_compr_get_codec_caps(stream, arg); in snd_compr_ioctl()
992 retval = snd_compr_set_params(stream, arg); in snd_compr_ioctl()
995 retval = snd_compr_get_params(stream, arg); in snd_compr_ioctl()
998 retval = snd_compr_set_metadata(stream, arg); in snd_compr_ioctl()
1001 retval = snd_compr_get_metadata(stream, arg); in snd_compr_ioctl()
1004 retval = snd_compr_tstamp(stream, arg); in snd_compr_ioctl()
1007 retval = snd_compr_ioctl_avail(stream, arg); in snd_compr_ioctl()
1010 retval = snd_compr_pause(stream); in snd_compr_ioctl()
1013 retval = snd_compr_resume(stream); in snd_compr_ioctl()
1016 retval = snd_compr_start(stream); in snd_compr_ioctl()
1019 retval = snd_compr_stop(stream); in snd_compr_ioctl()
1022 retval = snd_compr_drain(stream); in snd_compr_ioctl()
1025 retval = snd_compr_partial_drain(stream); in snd_compr_ioctl()
1028 retval = snd_compr_next_track(stream); in snd_compr_ioctl()
1032 mutex_unlock(&stream->device->lock); in snd_compr_ioctl()