Skip to content

Commit 751ef70

Browse files
committed
Add comments
1 parent 5667c5c commit 751ef70

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

virtio-snd.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,19 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
499499
uint32_t channels = props->pp.channels;
500500
uint32_t rate = pcm_rate_tbl[props->pp.rate];
501501

502-
// Calculate bps rate
502+
/* Rather use the period_bytes/buffer_bytes set by driver,
503+
* we calculate bps rate to achieve the strema's desired parameters
504+
* suggested by [1].
505+
*/
506+
/* Reference:
507+
* [1]
508+
* https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-sound/src/audio_backends/alsa.rs#L153
509+
*/
510+
/* Calculate bps rate. */
503511
uint32_t bps_rate = channels * VSND_CNFA_FRAME_SZ * rate;
504-
// Calculate period bytes for ~100ms interrupt period
512+
/* Calculate period bytes for ~100ms interrupt period. */
505513
uint32_t cnfa_period_bytes = bps_rate / 10;
506-
// Calculate the period size (in frames) for CNFA
514+
/* Calculate the period size (in frames) for CNFA . */
507515
uint32_t cnfa_period_frames = cnfa_period_bytes / VSND_CNFA_FRAME_SZ;
508516
uint32_t period_frames = period_bytes / VSND_CNFA_FRAME_SZ;
509517

@@ -774,8 +782,17 @@ static void __virtio_snd_frame_enqueue(void *payload,
774782
pthread_cond_wait(&props->lock.writable, &props->lock.lock);
775783

776784
/* Add a PCM frame to queue */
777-
/* TODO: add description of the speciality of Linux Kernel VirtIO sound
778-
* driver */
785+
/* As stated in Linux Kernel mailing list [1], we keep the pointer
786+
* points to the payload [2] so that we can always get up-to-date
787+
* contents of PCM frames.
788+
* References:
789+
* [1] https://lore.kernel.org/all/[email protected]/T/
790+
* [2]
791+
* https://github.com/rust-vmm/vhost-device/blob/eb2e2227e41d48a52e4e6346189b772c5363879d/staging/vhost-device-sound/src/device.rs#L554
792+
*/
793+
/* FIXME: locate the root case of repeating artifact even we
794+
* keep the pointer of the payload.
795+
*/
779796
vsnd_buf_queue_node_t *node = malloc(sizeof(*node));
780797
node->addr = payload;
781798
node->len = n;

0 commit comments

Comments
 (0)