Lines Matching refs:stream
54 struct snd_compr_stream stream; member
116 INIT_DELAYED_WORK(&data->stream.error_work, error_delayed_work); in snd_compr_open()
118 data->stream.ops = compr->ops; in snd_compr_open()
119 data->stream.direction = dirn; in snd_compr_open()
120 data->stream.private_data = compr->private_data; in snd_compr_open()
121 data->stream.device = compr; in snd_compr_open()
130 data->stream.runtime = runtime; in snd_compr_open()
133 ret = compr->ops->open(&data->stream); in snd_compr_open()
146 struct snd_compr_runtime *runtime = data->stream.runtime; in snd_compr_free()
148 cancel_delayed_work_sync(&data->stream.error_work); in snd_compr_free()
154 data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP); in snd_compr_free()
160 data->stream.ops->free(&data->stream); in snd_compr_free()
161 if (!data->stream.runtime->dma_buffer_p) in snd_compr_free()
162 kfree(data->stream.runtime->buffer); in snd_compr_free()
163 kfree(data->stream.runtime); in snd_compr_free()
168 static int snd_compr_update_tstamp(struct snd_compr_stream *stream, in snd_compr_update_tstamp() argument
171 if (!stream->ops->pointer) in snd_compr_update_tstamp()
173 stream->ops->pointer(stream, tstamp); in snd_compr_update_tstamp()
176 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_update_tstamp()
177 stream->runtime->total_bytes_transferred = tstamp->copied_total; in snd_compr_update_tstamp()
179 stream->runtime->total_bytes_available = tstamp->copied_total; in snd_compr_update_tstamp()
183 static size_t snd_compr_calc_avail(struct snd_compr_stream *stream, in snd_compr_calc_avail() argument
187 snd_compr_update_tstamp(stream, &avail->tstamp); in snd_compr_calc_avail()
190 if (stream->runtime->total_bytes_available == 0 && in snd_compr_calc_avail()
191 stream->runtime->state == SNDRV_PCM_STATE_SETUP && in snd_compr_calc_avail()
192 stream->direction == SND_COMPRESS_PLAYBACK) { in snd_compr_calc_avail()
194 return stream->runtime->buffer_size; in snd_compr_calc_avail()
197 stream->runtime->total_bytes_available, in snd_compr_calc_avail()
198 stream->runtime->total_bytes_transferred); in snd_compr_calc_avail()
199 if (stream->runtime->total_bytes_available == in snd_compr_calc_avail()
200 stream->runtime->total_bytes_transferred) { in snd_compr_calc_avail()
201 if (stream->direction == SND_COMPRESS_PLAYBACK) { in snd_compr_calc_avail()
203 return stream->runtime->buffer_size; in snd_compr_calc_avail()
210 avail->avail = stream->runtime->total_bytes_available - in snd_compr_calc_avail()
211 stream->runtime->total_bytes_transferred; in snd_compr_calc_avail()
212 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_calc_avail()
213 avail->avail = stream->runtime->buffer_size - avail->avail; in snd_compr_calc_avail()
219 static inline size_t snd_compr_get_avail(struct snd_compr_stream *stream) in snd_compr_get_avail() argument
223 return snd_compr_calc_avail(stream, &avail); in snd_compr_get_avail()
227 snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_ioctl_avail() argument
232 avail = snd_compr_calc_avail(stream, &ioctl_avail); in snd_compr_ioctl_avail()
235 switch (stream->runtime->state) { in snd_compr_ioctl_avail()
250 static int snd_compr_write_data(struct snd_compr_stream *stream, in snd_compr_write_data() argument
255 struct snd_compr_runtime *runtime = stream->runtime; in snd_compr_write_data()
276 if (stream->ops->ack) in snd_compr_write_data()
277 stream->ops->ack(stream, count); in snd_compr_write_data()
285 struct snd_compr_stream *stream; in snd_compr_write() local
292 stream = &data->stream; in snd_compr_write()
293 mutex_lock(&stream->device->lock); in snd_compr_write()
295 switch (stream->runtime->state) { in snd_compr_write()
301 mutex_unlock(&stream->device->lock); in snd_compr_write()
305 avail = snd_compr_get_avail(stream); in snd_compr_write()
311 if (stream->ops->copy) { in snd_compr_write()
313 retval = stream->ops->copy(stream, cbuf, avail); in snd_compr_write()
315 retval = snd_compr_write_data(stream, buf, avail); in snd_compr_write()
318 stream->runtime->total_bytes_available += retval; in snd_compr_write()
322 if (stream->runtime->state == SNDRV_PCM_STATE_SETUP) { in snd_compr_write()
323 stream->runtime->state = SNDRV_PCM_STATE_PREPARED; in snd_compr_write()
327 mutex_unlock(&stream->device->lock); in snd_compr_write()
336 struct snd_compr_stream *stream; in snd_compr_read() local
343 stream = &data->stream; in snd_compr_read()
344 mutex_lock(&stream->device->lock); in snd_compr_read()
350 switch (stream->runtime->state) { in snd_compr_read()
362 avail = snd_compr_get_avail(stream); in snd_compr_read()
368 if (stream->ops->copy) { in snd_compr_read()
369 retval = stream->ops->copy(stream, buf, avail); in snd_compr_read()
375 stream->runtime->total_bytes_transferred += retval; in snd_compr_read()
378 mutex_unlock(&stream->device->lock); in snd_compr_read()
387 static __poll_t snd_compr_get_poll(struct snd_compr_stream *stream) in snd_compr_get_poll() argument
389 if (stream->direction == SND_COMPRESS_PLAYBACK) in snd_compr_get_poll()
398 struct snd_compr_stream *stream; in snd_compr_poll() local
405 stream = &data->stream; in snd_compr_poll()
407 mutex_lock(&stream->device->lock); in snd_compr_poll()
409 switch (stream->runtime->state) { in snd_compr_poll()
412 retval = snd_compr_get_poll(stream) | EPOLLERR; in snd_compr_poll()
418 poll_wait(f, &stream->runtime->sleep, wait); in snd_compr_poll()
420 avail = snd_compr_get_avail(stream); in snd_compr_poll()
423 switch (stream->runtime->state) { in snd_compr_poll()
428 retval = snd_compr_get_poll(stream); in snd_compr_poll()
429 stream->runtime->state = SNDRV_PCM_STATE_SETUP; in snd_compr_poll()
434 if (avail >= stream->runtime->fragment_size) in snd_compr_poll()
435 retval = snd_compr_get_poll(stream); in snd_compr_poll()
438 retval = snd_compr_get_poll(stream) | EPOLLERR; in snd_compr_poll()
442 mutex_unlock(&stream->device->lock); in snd_compr_poll()
447 snd_compr_get_caps(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_caps() argument
452 if (!stream->ops->get_caps) in snd_compr_get_caps()
456 retval = stream->ops->get_caps(stream, &caps); in snd_compr_get_caps()
467 snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_codec_caps() argument
472 if (!stream->ops->get_codec_caps) in snd_compr_get_codec_caps()
479 retval = stream->ops->get_codec_caps(stream, caps); in snd_compr_get_codec_caps()
491 int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size) in snd_compr_malloc_pages() argument
496 if (snd_BUG_ON(!(stream) || !(stream)->runtime)) in snd_compr_malloc_pages()
501 dmab->dev = stream->dma_buffer.dev; in snd_compr_malloc_pages()
508 snd_compr_set_runtime_buffer(stream, dmab); in snd_compr_malloc_pages()
509 stream->runtime->dma_bytes = size; in snd_compr_malloc_pages()
514 int snd_compr_free_pages(struct snd_compr_stream *stream) in snd_compr_free_pages() argument
518 if (snd_BUG_ON(!(stream) || !(stream)->runtime)) in snd_compr_free_pages()
520 runtime = stream->runtime; in snd_compr_free_pages()
523 if (runtime->dma_buffer_p != &stream->dma_buffer) { in snd_compr_free_pages()
529 snd_compr_set_runtime_buffer(stream, NULL); in snd_compr_free_pages()
535 static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, in snd_compr_allocate_buffer() argument
542 if (stream->ops->copy) { in snd_compr_allocate_buffer()
548 if (stream->runtime->dma_buffer_p) { in snd_compr_allocate_buffer()
550 if (buffer_size > stream->runtime->dma_buffer_p->bytes) in snd_compr_allocate_buffer()
551 dev_err(&stream->device->dev, in snd_compr_allocate_buffer()
554 buffer = stream->runtime->dma_buffer_p->area; in snd_compr_allocate_buffer()
563 stream->runtime->fragment_size = params->buffer.fragment_size; in snd_compr_allocate_buffer()
564 stream->runtime->fragments = params->buffer.fragments; in snd_compr_allocate_buffer()
565 stream->runtime->buffer = buffer; in snd_compr_allocate_buffer()
566 stream->runtime->buffer_size = buffer_size; in snd_compr_allocate_buffer()
589 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_set_params() argument
594 if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) { in snd_compr_set_params()
607 retval = snd_compr_allocate_buffer(stream, params); in snd_compr_set_params()
613 retval = stream->ops->set_params(stream, params); in snd_compr_set_params()
617 stream->metadata_set = false; in snd_compr_set_params()
618 stream->next_track = false; in snd_compr_set_params()
620 stream->runtime->state = SNDRV_PCM_STATE_SETUP; in snd_compr_set_params()
630 snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_params() argument
635 if (!stream->ops->get_params) in snd_compr_get_params()
641 retval = stream->ops->get_params(stream, params); in snd_compr_get_params()
653 snd_compr_get_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_get_metadata() argument
658 if (!stream->ops->get_metadata) in snd_compr_get_metadata()
664 retval = stream->ops->get_metadata(stream, &metadata); in snd_compr_get_metadata()
675 snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_set_metadata() argument
680 if (!stream->ops->set_metadata) in snd_compr_set_metadata()
689 retval = stream->ops->set_metadata(stream, &metadata); in snd_compr_set_metadata()
690 stream->metadata_set = true; in snd_compr_set_metadata()
696 snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg) in snd_compr_tstamp() argument
701 ret = snd_compr_update_tstamp(stream, &tstamp); in snd_compr_tstamp()
708 static int snd_compr_pause(struct snd_compr_stream *stream) in snd_compr_pause() argument
712 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) in snd_compr_pause()
714 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); in snd_compr_pause()
716 stream->runtime->state = SNDRV_PCM_STATE_PAUSED; in snd_compr_pause()
720 static int snd_compr_resume(struct snd_compr_stream *stream) in snd_compr_resume() argument
724 if (stream->runtime->state != SNDRV_PCM_STATE_PAUSED) in snd_compr_resume()
726 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); in snd_compr_resume()
728 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_resume()
732 static int snd_compr_start(struct snd_compr_stream *stream) in snd_compr_start() argument
736 switch (stream->runtime->state) { in snd_compr_start()
738 if (stream->direction != SND_COMPRESS_CAPTURE) in snd_compr_start()
747 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_START); in snd_compr_start()
749 stream->runtime->state = SNDRV_PCM_STATE_RUNNING; in snd_compr_start()
753 static int snd_compr_stop(struct snd_compr_stream *stream) in snd_compr_stop() argument
757 switch (stream->runtime->state) { in snd_compr_stop()
766 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in snd_compr_stop()
769 stream->partial_drain = false; in snd_compr_stop()
770 stream->metadata_set = false; in snd_compr_stop()
771 snd_compr_drain_notify(stream); in snd_compr_stop()
772 stream->runtime->total_bytes_available = 0; in snd_compr_stop()
773 stream->runtime->total_bytes_transferred = 0; in snd_compr_stop()
780 struct snd_compr_stream *stream; in error_delayed_work() local
782 stream = container_of(work, struct snd_compr_stream, error_work.work); in error_delayed_work()
784 mutex_lock(&stream->device->lock); in error_delayed_work()
786 stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); in error_delayed_work()
787 wake_up(&stream->runtime->sleep); in error_delayed_work()
789 mutex_unlock(&stream->device->lock); in error_delayed_work()
801 int snd_compr_stop_error(struct snd_compr_stream *stream, in snd_compr_stop_error() argument
804 if (stream->runtime->state == state) in snd_compr_stop_error()
807 stream->runtime->state = state; in snd_compr_stop_error()
811 queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0); in snd_compr_stop_error()
817 static int snd_compress_wait_for_drain(struct snd_compr_stream *stream) in snd_compress_wait_for_drain() argument
829 stream->runtime->state = SNDRV_PCM_STATE_DRAINING; in snd_compress_wait_for_drain()
830 mutex_unlock(&stream->device->lock); in snd_compress_wait_for_drain()
838 ret = wait_event_interruptible(stream->runtime->sleep, in snd_compress_wait_for_drain()
839 (stream->runtime->state != SNDRV_PCM_STATE_DRAINING)); in snd_compress_wait_for_drain()
846 wake_up(&stream->runtime->sleep); in snd_compress_wait_for_drain()
847 mutex_lock(&stream->device->lock); in snd_compress_wait_for_drain()
852 static int snd_compr_drain(struct snd_compr_stream *stream) in snd_compr_drain() argument
856 switch (stream->runtime->state) { in snd_compr_drain()
868 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); in snd_compr_drain()
871 wake_up(&stream->runtime->sleep); in snd_compr_drain()
875 return snd_compress_wait_for_drain(stream); in snd_compr_drain()
878 static int snd_compr_next_track(struct snd_compr_stream *stream) in snd_compr_next_track() argument
883 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) in snd_compr_next_track()
887 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_next_track()
893 if (stream->metadata_set == false) in snd_compr_next_track()
896 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_NEXT_TRACK); in snd_compr_next_track()
899 stream->metadata_set = false; in snd_compr_next_track()
900 stream->next_track = true; in snd_compr_next_track()
904 static int snd_compr_partial_drain(struct snd_compr_stream *stream) in snd_compr_partial_drain() argument
908 switch (stream->runtime->state) { in snd_compr_partial_drain()
921 if (stream->direction == SND_COMPRESS_CAPTURE) in snd_compr_partial_drain()
925 if (stream->next_track == false) in snd_compr_partial_drain()
928 stream->partial_drain = true; in snd_compr_partial_drain()
929 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); in snd_compr_partial_drain()
932 wake_up(&stream->runtime->sleep); in snd_compr_partial_drain()
936 stream->next_track = false; in snd_compr_partial_drain()
937 return snd_compress_wait_for_drain(stream); in snd_compr_partial_drain()
943 struct snd_compr_stream *stream; in snd_compr_ioctl() local
949 stream = &data->stream; in snd_compr_ioctl()
951 mutex_lock(&stream->device->lock); in snd_compr_ioctl()
958 retval = snd_compr_get_caps(stream, arg); in snd_compr_ioctl()
962 retval = snd_compr_get_codec_caps(stream, arg); in snd_compr_ioctl()
966 retval = snd_compr_set_params(stream, arg); in snd_compr_ioctl()
969 retval = snd_compr_get_params(stream, arg); in snd_compr_ioctl()
972 retval = snd_compr_set_metadata(stream, arg); in snd_compr_ioctl()
975 retval = snd_compr_get_metadata(stream, arg); in snd_compr_ioctl()
978 retval = snd_compr_tstamp(stream, arg); in snd_compr_ioctl()
981 retval = snd_compr_ioctl_avail(stream, arg); in snd_compr_ioctl()
984 retval = snd_compr_pause(stream); in snd_compr_ioctl()
987 retval = snd_compr_resume(stream); in snd_compr_ioctl()
990 retval = snd_compr_start(stream); in snd_compr_ioctl()
993 retval = snd_compr_stop(stream); in snd_compr_ioctl()
996 retval = snd_compr_drain(stream); in snd_compr_ioctl()
999 retval = snd_compr_partial_drain(stream); in snd_compr_ioctl()
1002 retval = snd_compr_next_track(stream); in snd_compr_ioctl()
1006 mutex_unlock(&stream->device->lock); in snd_compr_ioctl()