Lines Matching full:stream
36 static void virtio_snd_pcm_flush(VirtIOSoundPCMStream *stream);
123 * Get a specific stream from the virtio sound card device.
127 * @stream_id: stream id
137 * Get params for a specific stream.
140 * @stream_id: stream id
162 VirtIOSoundPCMStream *stream = NULL; in virtio_snd_handle_pcm_info() local
201 stream = virtio_snd_pcm_get_stream(s, stream_id); in virtio_snd_handle_pcm_info()
202 if (!stream) { in virtio_snd_handle_pcm_info()
203 error_report("Invalid stream id: %"PRIu32, stream_id); in virtio_snd_handle_pcm_info()
207 val = stream->info; in virtio_snd_handle_pcm_info()
213 * 5.14.6.6.2.1 Device Requirements: Stream Information The device MUST in virtio_snd_handle_pcm_info()
231 * Set the given stream params.
262 error_report("Stream format is not supported."); in virtio_snd_set_pcm_params()
267 error_report("Stream rate is not supported."); in virtio_snd_set_pcm_params()
372 * Get QEMU Audiosystem compatible audsettings from virtio based pcm stream
385 * Close a stream and free all its resources.
387 * @stream: VirtIOSoundPCMStream *stream
389 static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream) in virtio_snd_pcm_close() argument
391 if (stream) { in virtio_snd_pcm_close()
392 virtio_snd_pcm_flush(stream); in virtio_snd_pcm_close()
393 if (stream->info.direction == VIRTIO_SND_D_OUTPUT) { in virtio_snd_pcm_close()
394 AUD_close_out(&stream->pcm->snd->card, stream->voice.out); in virtio_snd_pcm_close()
395 stream->voice.out = NULL; in virtio_snd_pcm_close()
396 } else if (stream->info.direction == VIRTIO_SND_D_INPUT) { in virtio_snd_pcm_close()
397 AUD_close_in(&stream->pcm->snd->card, stream->voice.in); in virtio_snd_pcm_close()
398 stream->voice.in = NULL; in virtio_snd_pcm_close()
404 * Prepares a VirtIOSound card stream.
408 * @stream_id: stream id
414 VirtIOSoundPCMStream *stream; in virtio_snd_pcm_prepare() local
427 stream = virtio_snd_pcm_get_stream(s, stream_id); in virtio_snd_pcm_prepare()
428 if (stream == NULL) { in virtio_snd_pcm_prepare()
429 stream = g_new0(VirtIOSoundPCMStream, 1); in virtio_snd_pcm_prepare()
430 stream->active = false; in virtio_snd_pcm_prepare()
431 stream->id = stream_id; in virtio_snd_pcm_prepare()
432 stream->pcm = s->pcm; in virtio_snd_pcm_prepare()
433 stream->s = s; in virtio_snd_pcm_prepare()
434 qemu_mutex_init(&stream->queue_mutex); in virtio_snd_pcm_prepare()
435 QSIMPLEQ_INIT(&stream->queue); in virtio_snd_pcm_prepare()
441 s->pcm->streams[stream_id] = stream; in virtio_snd_pcm_prepare()
445 stream->info.direction = stream_id < s->snd_conf.streams / 2 + in virtio_snd_pcm_prepare()
447 stream->info.hdr.hda_fn_nid = VIRTIO_SOUND_HDA_FN_NID; in virtio_snd_pcm_prepare()
448 stream->info.features = 0; in virtio_snd_pcm_prepare()
449 stream->info.channels_min = 1; in virtio_snd_pcm_prepare()
450 stream->info.channels_max = as.nchannels; in virtio_snd_pcm_prepare()
451 stream->info.formats = supported_formats; in virtio_snd_pcm_prepare()
452 stream->info.rates = supported_rates; in virtio_snd_pcm_prepare()
453 stream->params = *params; in virtio_snd_pcm_prepare()
455 stream->positions[0] = VIRTIO_SND_CHMAP_FL; in virtio_snd_pcm_prepare()
456 stream->positions[1] = VIRTIO_SND_CHMAP_FR; in virtio_snd_pcm_prepare()
457 stream->as = as; in virtio_snd_pcm_prepare()
459 if (stream->info.direction == VIRTIO_SND_D_OUTPUT) { in virtio_snd_pcm_prepare()
460 stream->voice.out = AUD_open_out(&s->card, in virtio_snd_pcm_prepare()
461 stream->voice.out, in virtio_snd_pcm_prepare()
463 stream, in virtio_snd_pcm_prepare()
466 AUD_set_volume_out(stream->voice.out, 0, 255, 255); in virtio_snd_pcm_prepare()
468 stream->voice.in = AUD_open_in(&s->card, in virtio_snd_pcm_prepare()
469 stream->voice.in, in virtio_snd_pcm_prepare()
471 stream, in virtio_snd_pcm_prepare()
474 AUD_set_volume_in(stream->voice.in, 0, 255, 255); in virtio_snd_pcm_prepare()
536 VirtIOSoundPCMStream *stream; in virtio_snd_handle_pcm_start_stop() local
558 stream = virtio_snd_pcm_get_stream(s, stream_id); in virtio_snd_handle_pcm_start_stop()
559 if (stream) { in virtio_snd_handle_pcm_start_stop()
560 WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { in virtio_snd_handle_pcm_start_stop()
561 stream->active = start; in virtio_snd_handle_pcm_start_stop()
563 if (stream->info.direction == VIRTIO_SND_D_OUTPUT) { in virtio_snd_handle_pcm_start_stop()
564 AUD_set_active_out(stream->voice.out, start); in virtio_snd_handle_pcm_start_stop()
566 AUD_set_active_in(stream->voice.in, start); in virtio_snd_handle_pcm_start_stop()
569 error_report("Invalid stream id: %"PRIu32, stream_id); in virtio_snd_handle_pcm_start_stop()
573 stream->active = start; in virtio_snd_handle_pcm_start_stop()
579 * @stream: VirtIOSoundPCMStream
581 static size_t virtio_snd_pcm_get_io_msgs_count(VirtIOSoundPCMStream *stream) in virtio_snd_pcm_get_io_msgs_count() argument
586 WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { in virtio_snd_pcm_get_io_msgs_count()
587 QSIMPLEQ_FOREACH_SAFE(buffer, &stream->queue, entry, next) { in virtio_snd_pcm_get_io_msgs_count()
604 VirtIOSoundPCMStream *stream; in virtio_snd_handle_pcm_release() local
624 stream = virtio_snd_pcm_get_stream(s, stream_id); in virtio_snd_handle_pcm_release()
625 if (stream == NULL) { in virtio_snd_handle_pcm_release()
629 error_report("already released stream %"PRIu32, stream_id); in virtio_snd_handle_pcm_release()
631 "already released stream %"PRIu32, in virtio_snd_handle_pcm_release()
637 if (virtio_snd_pcm_get_io_msgs_count(stream)) { in virtio_snd_handle_pcm_release()
640 * Device Requirements: Stream Release in virtio_snd_handle_pcm_release()
643 * specified stream ID. in virtio_snd_handle_pcm_release()
645 * are pending I/O messages for the specified stream ID. in virtio_snd_handle_pcm_release()
648 virtio_snd_pcm_flush(stream); in virtio_snd_handle_pcm_release()
866 VirtIOSoundPCMStream *stream; in virtio_snd_handle_tx_xfer() local
888 stream = vsnd->pcm->streams[stream_id]; in virtio_snd_handle_tx_xfer()
889 if (stream->info.direction != VIRTIO_SND_D_OUTPUT) { in virtio_snd_handle_tx_xfer()
893 WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { in virtio_snd_handle_tx_xfer()
903 QSIMPLEQ_INSERT_TAIL(&stream->queue, buffer, entry); in virtio_snd_handle_tx_xfer()
947 VirtIOSoundPCMStream *stream; in virtio_snd_handle_rx_xfer() local
969 stream = vsnd->pcm->streams[stream_id]; in virtio_snd_handle_rx_xfer()
970 if (stream == NULL || stream->info.direction != VIRTIO_SND_D_INPUT) { in virtio_snd_handle_rx_xfer()
973 WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { in virtio_snd_handle_rx_xfer()
981 QSIMPLEQ_INSERT_TAIL(&stream->queue, buffer, entry); in virtio_snd_handle_rx_xfer()
1096 "Can't initialize stream params, device responded with %s.", in virtio_snd_realize()
1115 static inline void return_tx_buffer(VirtIOSoundPCMStream *stream, in return_tx_buffer() argument
1129 virtio_notify(VIRTIO_DEVICE(stream->s), buffer->vq); in return_tx_buffer()
1130 QSIMPLEQ_REMOVE(&stream->queue, in return_tx_buffer()
1140 * @data: VirtIOSoundPCMStream stream
1145 VirtIOSoundPCMStream *stream = data; in virtio_snd_pcm_out_cb() local
1149 WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { in virtio_snd_pcm_out_cb()
1150 while (!QSIMPLEQ_EMPTY(&stream->queue)) { in virtio_snd_pcm_out_cb()
1151 buffer = QSIMPLEQ_FIRST(&stream->queue); in virtio_snd_pcm_out_cb()
1155 if (!stream->active) { in virtio_snd_pcm_out_cb()
1156 /* Stream has stopped, so do not perform AUD_write. */ in virtio_snd_pcm_out_cb()
1157 return_tx_buffer(stream, buffer); in virtio_snd_pcm_out_cb()
1169 size = AUD_write(stream->voice.out, in virtio_snd_pcm_out_cb()
1182 return_tx_buffer(stream, buffer); in virtio_snd_pcm_out_cb()
1197 * Flush all buffer data from this input stream's queue into the driver's
1200 * @stream: VirtIOSoundPCMStream *stream
1202 static inline void return_rx_buffer(VirtIOSoundPCMStream *stream, in return_rx_buffer() argument
1222 virtio_notify(VIRTIO_DEVICE(stream->s), buffer->vq); in return_rx_buffer()
1223 QSIMPLEQ_REMOVE(&stream->queue, in return_rx_buffer()
1234 * @data: VirtIOSoundPCMStream stream
1239 VirtIOSoundPCMStream *stream = data; in virtio_snd_pcm_in_cb() local
1243 WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { in virtio_snd_pcm_in_cb()
1244 while (!QSIMPLEQ_EMPTY(&stream->queue)) { in virtio_snd_pcm_in_cb()
1245 buffer = QSIMPLEQ_FIRST(&stream->queue); in virtio_snd_pcm_in_cb()
1249 if (!stream->active) { in virtio_snd_pcm_in_cb()
1250 /* Stream has stopped, so do not perform AUD_read. */ in virtio_snd_pcm_in_cb()
1251 return_rx_buffer(stream, buffer); in virtio_snd_pcm_in_cb()
1258 return_rx_buffer(stream, buffer); in virtio_snd_pcm_in_cb()
1261 size = AUD_read(stream->voice.in, in virtio_snd_pcm_in_cb()
1263 MIN(available, (stream->params.period_bytes - in virtio_snd_pcm_in_cb()
1271 if (buffer->size >= stream->params.period_bytes) { in virtio_snd_pcm_in_cb()
1272 return_rx_buffer(stream, buffer); in virtio_snd_pcm_in_cb()
1287 * Flush all buffer data from this output stream's queue into the driver's
1290 * @stream: VirtIOSoundPCMStream *stream
1292 static inline void virtio_snd_pcm_flush(VirtIOSoundPCMStream *stream) in virtio_snd_pcm_flush() argument
1296 (stream->info.direction == VIRTIO_SND_D_OUTPUT) ? return_tx_buffer : in virtio_snd_pcm_flush()
1299 WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { in virtio_snd_pcm_flush()
1300 while (!QSIMPLEQ_EMPTY(&stream->queue)) { in virtio_snd_pcm_flush()
1301 buffer = QSIMPLEQ_FIRST(&stream->queue); in virtio_snd_pcm_flush()
1302 cb(stream, buffer); in virtio_snd_pcm_flush()
1311 VirtIOSoundPCMStream *stream; in virtio_snd_unrealize() local
1319 stream = vsnd->pcm->streams[i]; in virtio_snd_unrealize()
1320 if (stream) { in virtio_snd_unrealize()
1321 virtio_snd_process_cmdq(stream->s); in virtio_snd_unrealize()
1322 virtio_snd_pcm_close(stream); in virtio_snd_unrealize()
1323 qemu_mutex_destroy(&stream->queue_mutex); in virtio_snd_unrealize()
1324 g_free(stream); in virtio_snd_unrealize()