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()
143 struct snd_compr_runtime *runtime = data->stream.runtime; in snd_compr_free()
145 cancel_delayed_work_sync(&data->stream.error_work); in snd_compr_free()
151 data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP); in snd_compr_free()
157 data->stream.ops->free(&data->stream); in snd_compr_free()
158 if (!data->stream.runtime->dma_buffer_p) in snd_compr_free()
159 kfree(data->stream.runtime->buffer); in snd_compr_free()
160 kfree(data->stream.runtime); in snd_compr_free()
165 static int snd_compr_update_tstamp(struct snd_compr_stream *stream, in snd_compr_update_tstamp() argument
168 if (!stream->ops->pointer) in snd_compr_update_tstamp()
170 stream->ops->pointer(stream, tstamp); in snd_compr_update_tstamp()
173 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_update_tstamp()
174 stream->runtime->total_bytes_transferred = tstamp->copied_total; in snd_compr_update_tstamp()
176 stream->runtime->total_bytes_available = tstamp->copied_total; in snd_compr_update_tstamp()
180 static size_t snd_compr_calc_avail(struct snd_compr_stream *stream, in snd_compr_calc_avail() argument
184 snd_compr_update_tstamp(stream, &avail->tstamp); in snd_compr_calc_avail()
187 if (stream->runtime->total_bytes_available == 0 && in snd_compr_calc_avail()
188 stream->runtime->state == SNDRV_PCM_STATE_SETUP && in snd_compr_calc_avail()
189 stream->direction == SND_COMPRESS_PLAYBACK) { in snd_compr_calc_avail()
191 return stream->runtime->buffer_size; in snd_compr_calc_avail()
194 stream->runtime->total_bytes_available, in snd_compr_calc_avail()
195 stream->runtime->total_bytes_transferred); in snd_compr_calc_avail()
196 if (stream->runtime->total_bytes_available == in snd_compr_calc_avail()
197 stream->runtime->total_bytes_transferred) { in snd_compr_calc_avail()
198 if (stream->direction == SND_COMPRESS_PLAYBACK) { in snd_compr_calc_avail()
200 return stream->runtime->buffer_size; in snd_compr_calc_avail()
207 avail->avail = stream->runtime->total_bytes_available - in snd_compr_calc_avail()
208 stream->runtime->total_bytes_transferred; in snd_compr_calc_avail()
209 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_calc_avail()
210 avail->avail = stream->runtime->buffer_size - avail->avail; in snd_compr_calc_avail()
216 static inline size_t snd_compr_get_avail(struct snd_compr_stream *stream) in snd_compr_get_avail() argument
220 return snd_compr_calc_avail(stream, &avail); in snd_compr_get_avail()
224 snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_ioctl_avail() argument
229 avail = snd_compr_calc_avail(stream, &ioctl_avail); in snd_compr_ioctl_avail()
232 switch (stream->runtime->state) { in snd_compr_ioctl_avail()
247 static int snd_compr_write_data(struct snd_compr_stream *stream, in snd_compr_write_data() argument
252 struct snd_compr_runtime *runtime = stream->runtime; in snd_compr_write_data()
273 if (stream->ops->ack) in snd_compr_write_data()
274 stream->ops->ack(stream, count); in snd_compr_write_data()
282 struct snd_compr_stream *stream; in snd_compr_write() local
289 stream = &data->stream; in snd_compr_write()
290 guard(mutex)(&stream->device->lock); in snd_compr_write()
292 switch (stream->runtime->state) { in snd_compr_write()
301 avail = snd_compr_get_avail(stream); in snd_compr_write()
307 if (stream->ops->copy) { in snd_compr_write()
309 retval = stream->ops->copy(stream, cbuf, avail); in snd_compr_write()
311 retval = snd_compr_write_data(stream, buf, avail); in snd_compr_write()
314 stream->runtime->total_bytes_available += retval; in snd_compr_write()
318 if (stream->runtime->state == SNDRV_PCM_STATE_SETUP) { in snd_compr_write()
319 stream->runtime->state = SNDRV_PCM_STATE_PREPARED; in snd_compr_write()
331 struct snd_compr_stream *stream; in snd_compr_read() local
338 stream = &data->stream; in snd_compr_read()
339 guard(mutex)(&stream->device->lock); in snd_compr_read()
345 switch (stream->runtime->state) { in snd_compr_read()
355 avail = snd_compr_get_avail(stream); in snd_compr_read()
361 if (stream->ops->copy) in snd_compr_read()
362 retval = stream->ops->copy(stream, buf, avail); in snd_compr_read()
366 stream->runtime->total_bytes_transferred += retval; in snd_compr_read()
376 static __poll_t snd_compr_get_poll(struct snd_compr_stream *stream) in snd_compr_get_poll() argument
378 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_get_poll()
387 struct snd_compr_stream *stream; in snd_compr_poll() local
394 stream = &data->stream; in snd_compr_poll()
396 guard(mutex)(&stream->device->lock); in snd_compr_poll()
398 switch (stream->runtime->state) { in snd_compr_poll()
401 return snd_compr_get_poll(stream) | EPOLLERR; in snd_compr_poll()
406 poll_wait(f, &stream->runtime->sleep, wait); in snd_compr_poll()
408 avail = snd_compr_get_avail(stream); in snd_compr_poll()
411 switch (stream->runtime->state) { in snd_compr_poll()
416 retval = snd_compr_get_poll(stream); in snd_compr_poll()
417 stream->runtime->state = SNDRV_PCM_STATE_SETUP; in snd_compr_poll()
422 if (avail >= stream->runtime->fragment_size) in snd_compr_poll()
423 retval = snd_compr_get_poll(stream); in snd_compr_poll()
426 return snd_compr_get_poll(stream) | EPOLLERR; in snd_compr_poll()
433 snd_compr_get_caps(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_caps() argument
438 if (!stream->ops->get_caps) in snd_compr_get_caps()
442 retval = stream->ops->get_caps(stream, &caps); in snd_compr_get_caps()
453 snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_codec_caps() argument
458 if (!stream->ops->get_codec_caps) in snd_compr_get_codec_caps()
465 retval = stream->ops->get_codec_caps(stream, caps); in snd_compr_get_codec_caps()
474 int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size) in snd_compr_malloc_pages() argument
479 if (snd_BUG_ON(!(stream) || !(stream)->runtime)) in snd_compr_malloc_pages()
484 dmab->dev = stream->dma_buffer.dev; in snd_compr_malloc_pages()
491 snd_compr_set_runtime_buffer(stream, dmab); in snd_compr_malloc_pages()
492 stream->runtime->dma_bytes = size; in snd_compr_malloc_pages()
497 int snd_compr_free_pages(struct snd_compr_stream *stream) in snd_compr_free_pages() argument
501 if (snd_BUG_ON(!(stream) || !(stream)->runtime)) in snd_compr_free_pages()
503 runtime = stream->runtime; in snd_compr_free_pages()
506 if (runtime->dma_buffer_p != &stream->dma_buffer) { in snd_compr_free_pages()
512 snd_compr_set_runtime_buffer(stream, NULL); in snd_compr_free_pages()
518 static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, in snd_compr_allocate_buffer() argument
525 if (stream->ops->copy) { in snd_compr_allocate_buffer()
531 if (stream->runtime->dma_buffer_p) { in snd_compr_allocate_buffer()
533 if (buffer_size > stream->runtime->dma_buffer_p->bytes) in snd_compr_allocate_buffer()
534 dev_err(stream->device->dev, in snd_compr_allocate_buffer()
537 buffer = stream->runtime->dma_buffer_p->area; in snd_compr_allocate_buffer()
546 stream->runtime->fragment_size = params->buffer.fragment_size; in snd_compr_allocate_buffer()
547 stream->runtime->fragments = params->buffer.fragments; in snd_compr_allocate_buffer()
548 stream->runtime->buffer = buffer; in snd_compr_allocate_buffer()
549 stream->runtime->buffer_size = buffer_size; in snd_compr_allocate_buffer()
572 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_set_params() argument
577 if (stream->runtime->state == SNDRV_PCM_STATE_OPEN || stream->next_track) { in snd_compr_set_params()
590 retval = snd_compr_allocate_buffer(stream, params); in snd_compr_set_params()
594 retval = stream->ops->set_params(stream, params); in snd_compr_set_params()
598 if (stream->next_track) in snd_compr_set_params()
601 stream->metadata_set = false; in snd_compr_set_params()
602 stream->next_track = false; in snd_compr_set_params()
604 stream->runtime->state = SNDRV_PCM_STATE_SETUP; in snd_compr_set_params()
612 snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_params() argument
617 if (!stream->ops->get_params) in snd_compr_get_params()
623 retval = stream->ops->get_params(stream, params); in snd_compr_get_params()
632 snd_compr_get_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_metadata() argument
637 if (!stream->ops->get_metadata) in snd_compr_get_metadata()
643 retval = stream->ops->get_metadata(stream, &metadata); in snd_compr_get_metadata()
654 snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_set_metadata() argument
659 if (!stream->ops->set_metadata) in snd_compr_set_metadata()
668 retval = stream->ops->set_metadata(stream, &metadata); in snd_compr_set_metadata()
669 stream->metadata_set = true; in snd_compr_set_metadata()
675 snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_tstamp() argument
680 ret = snd_compr_update_tstamp(stream, &tstamp); in snd_compr_tstamp()
687 static int snd_compr_pause(struct snd_compr_stream *stream) in snd_compr_pause() argument
691 switch (stream->runtime->state) { in snd_compr_pause()
693 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); in snd_compr_pause()
695 stream->runtime->state = SNDRV_PCM_STATE_PAUSED; in snd_compr_pause()
698 if (!stream->device->use_pause_in_draining) in snd_compr_pause()
700 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); in snd_compr_pause()
702 stream->pause_in_draining = true; in snd_compr_pause()
710 static int snd_compr_resume(struct snd_compr_stream *stream) in snd_compr_resume() argument
714 switch (stream->runtime->state) { in snd_compr_resume()
716 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); in snd_compr_resume()
718 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_resume()
721 if (!stream->pause_in_draining) in snd_compr_resume()
723 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); in snd_compr_resume()
725 stream->pause_in_draining = false; in snd_compr_resume()
733 static int snd_compr_start(struct snd_compr_stream *stream) in snd_compr_start() argument
737 switch (stream->runtime->state) { in snd_compr_start()
739 if (stream->direction != SND_COMPRESS_CAPTURE) in snd_compr_start()
748 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_START); in snd_compr_start()
750 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_start()
754 static int snd_compr_stop(struct snd_compr_stream *stream) in snd_compr_stop() argument
758 switch (stream->runtime->state) { in snd_compr_stop()
767 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in snd_compr_stop()
770 stream->partial_drain = false; in snd_compr_stop()
771 stream->metadata_set = false; in snd_compr_stop()
772 stream->pause_in_draining = false; in snd_compr_stop()
773 snd_compr_drain_notify(stream); in snd_compr_stop()
774 stream->runtime->total_bytes_available = 0; in snd_compr_stop()
775 stream->runtime->total_bytes_transferred = 0; in snd_compr_stop()
782 struct snd_compr_stream *stream; in error_delayed_work() local
784 stream = container_of(work, struct snd_compr_stream, error_work.work); in error_delayed_work()
786 guard(mutex)(&stream->device->lock); in error_delayed_work()
788 stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in error_delayed_work()
789 wake_up(&stream->runtime->sleep); in error_delayed_work()
803 int snd_compr_stop_error(struct snd_compr_stream *stream, in snd_compr_stop_error() argument
806 if (stream->runtime->state == state) in snd_compr_stop_error()
809 stream->runtime->state = state; in snd_compr_stop_error()
813 queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0); in snd_compr_stop_error()
819 static int snd_compress_wait_for_drain(struct snd_compr_stream *stream) in snd_compress_wait_for_drain() argument
831 stream->runtime->state = SNDRV_PCM_STATE_DRAINING; in snd_compress_wait_for_drain()
832 mutex_unlock(&stream->device->lock); in snd_compress_wait_for_drain()
840 ret = wait_event_interruptible(stream->runtime->sleep, in snd_compress_wait_for_drain()
841 (stream->runtime->state != SNDRV_PCM_STATE_DRAINING)); in snd_compress_wait_for_drain()
848 wake_up(&stream->runtime->sleep); in snd_compress_wait_for_drain()
849 mutex_lock(&stream->device->lock); in snd_compress_wait_for_drain()
854 static int snd_compr_drain(struct snd_compr_stream *stream) in snd_compr_drain() argument
858 switch (stream->runtime->state) { in snd_compr_drain()
870 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); in snd_compr_drain()
873 wake_up(&stream->runtime->sleep); in snd_compr_drain()
877 return snd_compress_wait_for_drain(stream); in snd_compr_drain()
880 static int snd_compr_next_track(struct snd_compr_stream *stream) in snd_compr_next_track() argument
885 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) in snd_compr_next_track()
889 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_next_track()
895 if (stream->metadata_set == false) in snd_compr_next_track()
898 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_NEXT_TRACK); in snd_compr_next_track()
901 stream->metadata_set = false; in snd_compr_next_track()
902 stream->next_track = true; in snd_compr_next_track()
906 static int snd_compr_partial_drain(struct snd_compr_stream *stream) in snd_compr_partial_drain() argument
910 switch (stream->runtime->state) { in snd_compr_partial_drain()
923 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_partial_drain()
927 if (stream->next_track == false) in snd_compr_partial_drain()
930 stream->partial_drain = true; in snd_compr_partial_drain()
931 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); in snd_compr_partial_drain()
934 wake_up(&stream->runtime->sleep); in snd_compr_partial_drain()
938 stream->next_track = false; in snd_compr_partial_drain()
939 return snd_compress_wait_for_drain(stream); in snd_compr_partial_drain()
945 struct snd_compr_stream *stream; in snd_compr_ioctl() local
950 stream = &data->stream; in snd_compr_ioctl()
952 guard(mutex)(&stream->device->lock); in snd_compr_ioctl()
958 return snd_compr_get_caps(stream, arg); in snd_compr_ioctl()
961 return snd_compr_get_codec_caps(stream, arg); in snd_compr_ioctl()
964 return snd_compr_set_params(stream, arg); in snd_compr_ioctl()
966 return snd_compr_get_params(stream, arg); in snd_compr_ioctl()
968 return snd_compr_set_metadata(stream, arg); in snd_compr_ioctl()
970 return snd_compr_get_metadata(stream, arg); in snd_compr_ioctl()
972 return snd_compr_tstamp(stream, arg); in snd_compr_ioctl()
974 return snd_compr_ioctl_avail(stream, arg); in snd_compr_ioctl()
976 return snd_compr_pause(stream); in snd_compr_ioctl()
978 return snd_compr_resume(stream); in snd_compr_ioctl()
980 return snd_compr_start(stream); in snd_compr_ioctl()
982 return snd_compr_stop(stream); in snd_compr_ioctl()
984 return snd_compr_drain(stream); in snd_compr_ioctl()
986 return snd_compr_partial_drain(stream); in snd_compr_ioctl()
988 return snd_compr_next_track(stream); in snd_compr_ioctl()