Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sound] add a comment to explain latency value #501

Open
MatiasVara opened this issue Oct 25, 2023 · 4 comments
Open

[sound] add a comment to explain latency value #501

MatiasVara opened this issue Oct 25, 2023 · 4 comments

Comments

@MatiasVara
Copy link
Contributor

Based on crosvm comment, the latency of an used buffer is the number of bytes before the current buffer is played:

/// It returns how many bytes need to be consumed
/// before the current playback buffer will be played.

My guess is that Crosvm is using "0" because it notifies the guest after the current period has been consumed. We could add a comment to explain that too at

@epilys
Copy link
Member

epilys commented Oct 25, 2023

The doc comment can be similar to the commit that introduced the field:

sound: add latency_bytes field to IOMessage

The latency field specifies how long it will take until the device
finishes playing the I/O message's buffers.

Source:

https://lists.oasis-open.org/archives/virtio-dev/201912/msg00123.html

@MatiasVara
Copy link
Contributor Author

Right, it is not clear to me yet how the virtio-sound driver uses latency_bytes value. AFAIU, it seems it is stored to runtime->delay during virtsnd_pcm_msg_complete() but I do not understand what the kernel does with that.

@epilys
Copy link
Member

epilys commented Oct 27, 2023

@MatiasVara I had the same thought when I first read the code. My interpretation ended up being that the sound card should not be "kicked" (interrupted) until delay more frames are added to the buffer. So, if you have latency 0 in the guest, queue 1024 bytes in the host sound card and return a latency of 1024 bytes to the guest right away, its runtime->delay value would be increased by 1024 bytes converted into frames. This way, it doesn't send all audio bytes to the card device as fast as possible.

I don't have strong doubts about this explanation to be honest but the best source for this would surely be the spec authors.

@MatiasVara
Copy link
Contributor Author

The doc comment can be similar to the commit that introduced the field:

sound: add latency_bytes field to IOMessage
The latency field specifies how long it will take until the device
finishes playing the I/O message's buffers.

Source:

https://lists.oasis-open.org/archives/virtio-dev/201912/msg00123.html

Do you think you could respond this also here https://lore.kernel.org/all/ZR6EzpQb6J1TxbM8@fedora/T/? I think that would be helpful for moving the discussion forward. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants