virtio-snd: add virtio sound device specification
PATCH v3 1/1 virtio-snd: add virtio sound device specification
This patch proposes virtio specification for new virtio sound device, that may be useful in case, when having audio is required but a device passthrough or emulation is not an option.
---
v2 -> v3 changes:
1. Define 4 mandatory queues: control, event, tx and rx.
2. Define feature bits for shared memory transport.
Make a message-based transport default.
3. Replace device features with stream features.
4. Rework device configuration space, now it contains only the total number of available PCM streams.
5. Add the get stream capabilities control request and define the stream capabilities structure.
6. Replace the set format with the set parameters control request.
7. Add the PCM notifications section.
8. Rework the PCM I/O messages section.
conformance.tex | 22 ++ content.tex | 1 + virtio-sound.tex | 561 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 584 insertions(+) create mode 100644 virtio-sound.tex
conformance.tex +22 -0
@@ -191,6 +191,17 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets} \item \ref{drivernormative:Device Types / RPMB Device / Device Operation} \end{itemize} +\conformance{\subsection}{Sound Driver Conformance}\label{sec:Conformance / Driver Conformance / Sound Driver Conformance} + +A sound driver MUST conform to the following normative statements: + +\begin{itemize} +\item \ref{drivernormative:Device Types / Sound Device / Device Operation / PCM Stream Parameters} +\item \ref{drivernormative:Device Types / Sound Device / Device Operation / PCM Notifications} +\item \ref{drivernormative:Device Types / Sound Device / Device Operation / PCM Output Stream} +\item \ref{drivernormative:Device Types / Sound Device / Device Operation / PCM Input Stream} +\end{itemize} + \conformance{\section}{Device Conformance}\label{sec:Conformance / Device Conformance} A device MUST conform to the following normative statements:
@@ -360,6 +371,17 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets} \item \ref{devicenormative:Device Types / RPMB Device / Device Operation} \end{itemize} +\conformance{\subsection}{Sound Device Conformance}\label{sec:Conformance / Device Conformance / Sound Device Conformance} + +A sound device MUST conform to the following normative statements: + +\begin{itemize} +\item \ref{devicenormative:Device Types / Sound Device / Device Initialization} +\item \ref{devicenormative:Device Types / Sound Device / Device Operation / PCM Stream Capabilities} +\item \ref{devicenormative:Device Types / Sound Device / Device Operation / PCM Stream Parameters} +\item \ref{devicenormative:Device Types / Sound Device / Device Operation / PCM Input Stream} +\end{itemize} + \conformance{\section}{Legacy Interface: Transitional Device and Transitional Driver Conformance}\label{sec:Conformance / Legacy Interface: Transitional Device and Transitional Driver Conformance} A conformant implementation MUST be either transitional or non-transitional, see \ref{intro:Legacy
content.tex +1 -0
@@ -5739,6 +5739,7 @@ \subsubsection{Legacy Interface: Framing Requirements}\label{sec:Device \input{virtio-vsock.tex} \input{virtio-fs.tex} \input{virtio-rpmb.tex} +\input{virtio-sound.tex} \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
virtio-sound.tex new file +561 -0
561 lines not on this page · raw message
Signature · 6 lines
2.24.0 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi,
Review
Quoted 3 lines
+\subsection{Feature bits}\label{sec:Device Types / Sound Device / Feature bits}
(quoted diff) +2
-0+ +None currently defined.
Flags for hostmem & guestmem here?
This could be an information the driver might want to know before initializing the virtqueues.
Quoted 4 lines
+\item START
+\item PAUSE
+\item UNPAUSE
+\item STOP
Why pause/unpause?
I don't see a reason compelling for this given the driver can restart a stream (i.e. set-params -> prepare -> start -> stop -> start -> stop -> release). Would a device handle stop and pause in a different way?
virtio-sound.tex line 232
Quoted 4 lines
virtio-sound.tex new file +4
-0+/* supported PCM stream features */ +enum { + VIRTIO_SND_PCM_F_HOST_MEM = 0, + VIRTIO_SND_PCM_F_GUEST_MEM,
Is this useful as stream property? I would expect when supported by a device it would work for all streams.
Quoted 1 line
+
VIRTIO_SND_PCM_F_EVT_PERIOD,
I think this is only useful for hostmem/guestmem.
Quoted 8 lines
virtio-sound.tex new file +8
-0+struct virtio_snd_pcm_set_params { + struct virtio_snd_pcm_hdr hdr; /* .code = VIRTIO_SND_R_PCM_SET_PARAMS */ + u8 features; + u8 channels; + u8 format; + u8 rate; + le32 buffer_bytes; + le32 period_bytes;
virtio-sound.tex line 403
Quoted 10 lines
virtio-sound.tex new file +10
-0+}; +\end{lstlisting} + +The request contains the following fields: + +\begin{description} +\item[\field{features}] (device-readable) is a selected feature bit map: +\begin{itemize*} +\item VIRTIO_SND_PCM_F_HOST_MEM: use shared memory allocated by the host (TBD), +\item VIRTIO_SND_PCM_F_GUEST_MEM: use shared memory allocated by the guest (TBD),
I'd suggest to drop those bits here. For hostmem + guestmem we probably need a virtio_snd_pcm_set_params_{hostmem,guestmem} struct (and command) with additional parameters anyway.
Quoted 1 line
+\item
VIRTIO_SND_PCM_F_EVT_PERIOD: enable elapsed period notifications,
Same comment as above ;)
Quoted 3 lines
+\begin{itemize*}
+\itemVIRTIO_SND_EVT_PCM_PERIOD: send notifications about each elapsed period, +the size of the period is specified in the \field{period_bytes} field.
Same comment as above ;)
virtio-sound.tex line 505
Quoted 4 lines
+\subsubsection{PCM I/O Messages}\label{sec:Device Types / Sound Device / Device Operation / PCM IO Messages}
virtio-sound.tex new file +3
-0+ +An I/O message consists of the header part, followed by the buffer, and then +the status part.
Each buffer MUST (or SHOULD?) be period_bytes in size.
The driver SHOULD queue (buffer_bytes / period_bytes) virtio buffers, so the device has buffer_bytes total buffer space available.
cheers,
Gerd
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi,
Quoted 10 lines · Gerd Hoffmann
Hi,Review
Quoted 3 lines
+\subsection{Feature bits}\label{sec:Device Types / Sound Device / Feature bits}
(quoted diff) +2
-0+ +None currently defined.Flags for hostmem & guestmem here?
This could be an information the driver might want to know before initializing the virtqueues.
Yes, it might be. Yet this means that there will be two sets of features. And current draft makes things more consistent (or at least looks so). Like, the choice of transport looks more natural (just usual "feature negotiation").
Quoted 10 lines
Quoted 4 lines
+\item START
+\item PAUSE
+\item UNPAUSE
+\item STOPWhy pause/unpause?
I don't see a reason compelling for this given the driver can restart a stream (i.e. set-params -> prepare -> start -> stop -> start -> stop -> release). Would a device handle stop and pause in a different way?
Well, usually restarting a paused stream means a lower start delay. But you have a point here. I think it's worth asking other people's opinions on this.
Quoted 7 lines
virtio-sound.tex line 232
Quoted 4 lines
virtio-sound.tex new file +4
-0+/* supported PCM stream features */ +enum { + VIRTIO_SND_PCM_F_HOST_MEM = 0, + VIRTIO_SND_PCM_F_GUEST_MEM,Is this useful as stream property? I would expect when supported by a device it would work for all streams.
Since we allowed different capabilities for different streams, now it's possible to have different backends for them. I’m not sure how much this can be a real scenario, but it is theoretically possible to have one backend that is able to work with shared memory, and the other is not. The same can be said for other stream feature bits.
Quoted 3 lines
Quoted 1 line
+
VIRTIO_SND_PCM_F_EVT_PERIOD,I think this is only useful for hostmem/guestmem.
Using message-based transport, an application can send the entire playback buffer at the beginning, and then send period-sized parts on each period notification.
Quoted 14 lines
Quoted 14 lines
virtio-sound.tex new file +14
-0+struct virtio_snd_pcm_set_params { + struct virtio_snd_pcm_hdr hdr; /* .code = VIRTIO_SND_R_PCM_SET_PARAMS */ + u8 features; + u8 channels; + u8 format; + u8 rate; + le32 buffer_bytes; + le32 period_bytes; +}; +\end{lstlisting} + +The request contains the following fields: + +\begin{description}
Quoted 8 lines
Quoted 4 lines
+\item[\field{features}] (device-readable) is a selected feature bit map:
+\begin{itemize*}
+\itemVIRTIO_SND_PCM_F_HOST_MEM: use shared memory allocated by the host (TBD), +\itemVIRTIO_SND_PCM_F_GUEST_MEM: use shared memory allocated by the guest (TBD),I'd suggest to drop those bits here. For hostmem + guestmem we probably need a virtio_snd_pcm_set_params_{hostmem,guestmem} struct (and command) with additional parameters anyway.
See comment at the beginning.
Quoted 9 lines
virtio-sound.tex line 505
Quoted 4 lines
+\subsubsection{PCM I/O Messages}\label{sec:Device Types / Sound Device / Device Operation / PCM IO Messages}
virtio-sound.tex new file +3
-0+ +An I/O message consists of the header part, followed by the buffer, and then +the status part.Each buffer MUST (or SHOULD?) be
period_bytesin size.The driver SHOULD queue (
buffer_bytes/period_bytes) virtio buffers, so the device hasbuffer_bytestotal buffer space available.
I think, it's better not to set queued buffer size restrictions. Periods are an optional feature. If the driver is not interested in period notifications, it's unclear what period_bytes means here.
Although, for the input stream we could say, that the total size of buffers in the rx queue should be buffer_bytes.
Quoted 4 lines
cheers,
Gerd
Signature · 12 lines
Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin Phone: +49 30 60 98 54 0 E-Mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 8 lines
Quoted 7 lines
virtio-sound.tex line 232
Quoted 4 lines
virtio-sound.tex new file +4
-0+/* supported PCM stream features */ +enum { + VIRTIO_SND_PCM_F_HOST_MEM = 0, + VIRTIO_SND_PCM_F_GUEST_MEM,Is this useful as stream property? I would expect when supported by a device it would work for all streams.
Quoted 5 lines
Since we allowed different capabilities for different streams, now it's possible to have different backends for them. I’m not sure how much this can be a real scenario, but it is theoretically possible to have one backend that is able to work with shared memory, and the other is not. The same can be said for other stream feature bits.
Hmm, ok. Point.
Independant from that they should either be a note that these two are nor (yet) specified and are just placeholders. Or simply be deleted and re-added with the actual specification for guestmem + hostmem.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+
VIRTIO_SND_PCM_F_EVT_PERIOD,I think this is only useful for hostmem/guestmem.
Using message-based transport, an application can send the entire playback buffer at the beginning, and then send period-sized parts on each period notification.
The driver can still split the data from the application into a set of smaller virtio buffers. And this is how I would write a driver. Create a bunch of buffers, period_bytes each, enough to cover buffer_bytes. Then go submit them, re-use them robin-round (each time the device completes a buffer re-fill and re-submit it), without a special case with one big buffer for the (playback) stream start.
I still think this is not needed for message-based transport.
Maybe this is not needed for hostmem/guestmem either. The point of using shared memory is to avoid system calls and vmexits for buffer management, so VIRTIO_SND_PCM_F_EVT_PERIOD doesn't look that useful here too. But maybe it is nice to have that as option.
Quoted 11 lines
Quoted 9 lines
virtio-sound.tex line 505
Quoted 4 lines
+\subsubsection{PCM I/O Messages}\label{sec:Device Types / Sound Device / Device Operation / PCM IO Messages}
virtio-sound.tex new file +3
-0+ +An I/O message consists of the header part, followed by the buffer, and then +the status part.Each buffer MUST (or SHOULD?) be
period_bytesin size.The driver SHOULD queue (
buffer_bytes/period_bytes) virtio buffers, so the device hasbuffer_bytestotal buffer space available.I think, it's better not to set queued buffer size restrictions.
Lets make it SHOULD then.
Quoted 2 lines
Periods are an optional feature. If the driver is not interested in period notifications, it's unclear what
period_bytesmeans here.
Well, the driver has to manage buffers, so I can't see how a driver is not interested in completion notifications. If the driver isn't interested in keeping the latency low by using lots of small buffers it still needs to queue at least two (larger) buffers, so the device still has data to continue playback when it completed a buffer. And the driver needs to know when the device is done with a buffer so it can either recycle the buffer or free the pages.
Quoted 2 lines
Although, for the input stream we could say, that the total size of buffers in the rx queue should be
buffer_bytes.
Yes.
cheers,
Gerd
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 14 lines · Gerd Hoffmann
Quoted 8 lines
Quoted 7 lines
virtio-sound.tex line 232
Quoted 4 lines
virtio-sound.tex new file +4
-0+/* supported PCM stream features */ +enum { + VIRTIO_SND_PCM_F_HOST_MEM = 0, + VIRTIO_SND_PCM_F_GUEST_MEM,Is this useful as stream property? I would expect when supported by a device it would work for all streams.
Quoted 5 lines
Since we allowed different capabilities for different streams, now it's possible to have different backends for them. I’m not sure how much this can be a real scenario, but it is theoretically possible to have one backend that is able to work with shared memory, and the other is not. The same can be said for other stream feature bits.
Quoted 5 lines
Hmm, ok. Point.
Independant from that they should either be a note that these two are nor (yet) specified and are just placeholders. Or simply be deleted and re-added with the actual specification for guestmem + hostmem.
I think having a note is better.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+
VIRTIO_SND_PCM_F_EVT_PERIOD,I think this is only useful for hostmem/guestmem.
Using message-based transport, an application can send the entire playback buffer at the beginning, and then send period-sized parts on each period notification.
Quoted 6 lines
The driver can still split the data from the application into a set of smaller virtio buffers. And this is how I would write a driver. Create a bunch of buffers,
period_byteseach, enough to coverbuffer_bytes. Then go submit them, re-use them robin-round (each time the device completes a buffer re-fill and re-submit it), without a special case with one big buffer for the (playback) stream start.
Yes, but what about device side? Most likely, it will copy the contents of the buffer to another location and immediately complete the request (otherwise it is not clear when to complete). In addition, the driver must advance the hardware position, and completing the request is the only possible place to do this. In most cases, all this will not coincide with the period notification. This means that the notification itself is an optional feature that may or may not be enabled for message-based transport.
Of course, the benefits of such notifications largely depend on the implementation of the driver. But at least people here claimed that they could be useful.
Quoted 6 lines
I still think this is not needed for message-based transport.
Maybe this is not needed for hostmem/guestmem either. The point of using shared memory is to avoid system calls and vmexits for buffer management, so
VIRTIO_SND_PCM_F_EVT_PERIODdoesn't look that useful here too. But maybe it is nice to have that as option.
Earlier there was a big discussion on this topic, which resulted in having this feature. The main point was it reflects the state of the hardware device, not the virtual device itself. But they may not always be useful or necessary, so this feature is optional.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
virtio-sound.tex line 505
Quoted 4 lines
+\subsubsection{PCM I/O Messages}\label{sec:Device Types / Sound Device / Device Operation / PCM IO Messages}
virtio-sound.tex new file +3
-0+ +An I/O message consists of the header part, followed by the buffer, and then +the status part.Each buffer MUST (or SHOULD?) be
period_bytesin size.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The driver SHOULD queue (
buffer_bytes/period_bytes) virtio buffers, so the device hasbuffer_bytestotal buffer space available.I think, it's better not to set queued buffer size restrictions.
Lets make it SHOULD then.
Again, if periods are not used, then there's no period_bytes. And they are not used, for example, in most low-latency applications.
(Well, technically speaking, low-latency applications in Linux must configure period size for ALSA. But then they usually suppress period notifications and send very small chunks of data, which usually do not correspond to the size of the period at all.)
Quoted 10 lines
Quoted 2 lines
Periods are an optional feature. If the driver is not interested in period notifications, it's unclear what
period_bytesmeans here.Well, the driver has to manage buffers, so I can't see how a driver is not interested in completion notifications. If the driver isn't interested in keeping the latency low by using lots of small buffers it still needs to queue at least two (larger) buffers, so the device still has data to continue playback when it completed a buffer. And the driver needs to know when the device is done with a buffer so it can either recycle the buffer or free the pages.
It seems that you have mixed up two different things: sending/completing a request containing a buffer, and period notifications. They are not the same.
Signature · 13 lines
Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin Phone: +49 30 60 98 54 0 E-Mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi,
Quoted 10 lines
Quoted 6 lines
The driver can still split the data from the application into a set of smaller virtio buffers. And this is how I would write a driver. Create a bunch of buffers,
period_byteseach, enough to coverbuffer_bytes. Then go submit them, re-use them robin-round (each time the device completes a buffer re-fill and re-submit it), without a special case with one big buffer for the (playback) stream start.Yes, but what about device side? Most likely, it will copy the contents of the buffer to another location and immediately complete the request (otherwise it is not clear when to complete).
qemu has rather small buffers backend buffers, to keep latencies low. So, yes it would copy data to backend buffers. No, it would most likely not copy over everything immediately. It will most likely leave buffers in the virtqueue, reading the data piecewise in the audio backend timer callback, complete the virtio request when it has read all data. So there wouldn't be a huge gap between completing the request and feeding the data to the host hardware.
Another reason for this (beside keeping latencies low) is that it is a good idea to avoid or at least limit guest-triggered allocations on the host for security reasons.
While talking about latencies: What happened to the idea to signal additional device latencies (backend buffering and processing ...) to the driver?
Quoted 3 lines
In addition, the driver must advance the
hardware position, and completing the request is the only possible place to do this. In most cases, all this will not coincide with the period notification.
So, period notification should be triggered when the device has actually completed processing the data (i.e. host playback finished)? I can see that this can be useful. I think qemu wouldn't be able to support that with the current audio backend design, but that isn't a blocker given this is an optional feature. Also I think the spec should to clarify how period notification is supposed to work, how that relates to buffer completion and latencies.
Quoted 2 lines
This means that the notification itself is an optional feature that may or may not be enabled for message-based transport.
Which transports are expected to support that?
If multiple transports: Can a device signal it supports these notifications for one transport but not for another?
Quoted 11 lines
Quoted 3 lines
Quoted 1 line
I think, it's better not to set queued buffer size restrictions.
Lets make it SHOULD then.
Again, if periods are not used, then there's no
period_bytes. And they are not used, for example, in most low-latency applications.(Well, technically speaking, low-latency applications in Linux must configure period size for ALSA. But then they usually suppress period notifications and send very small chunks of data, which usually do not correspond to the size of the period at all.)
So you want pass the data on to the device in whatever chunks the userspace application hands them to the driver? Ok, reasonable.
Should we define period_bytes as upper limit then, i.e. virtio buffers should be period_bytes or smaller?
Completely different topic: I think we should consider adding tags to streams. Some background: In qemu we have two almost identical hda codecs: hda-duplex and hda-micro. The only difference is that
hda-duplex has the input stream tagged as "line-in" and the output stream as "line-out", whereas hda-micro has the input channel tagged as "microphone" and the output channel as "speaker". hda-micro was created because some windows application refused to accept "line-in" as audio source. So applications clearly do care, and in case you have two input streams it would help applications pick a reasonable default.
cheers,
Gerd
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 13 lines · Gerd Hoffmann
Hi,Quoted 10 lines
Quoted 6 lines
The driver can still split the data from the application into a set of smaller virtio buffers. And this is how I would write a driver. Create a bunch of buffers,
period_byteseach, enough to coverbuffer_bytes. Then go submit them, re-use them robin-round (each time the device completes a buffer re-fill and re-submit it), without a special case with one big buffer for the (playback) stream start.Yes, but what about device side? Most likely, it will copy the contents of the buffer to another location and immediately complete the request (otherwise it is not clear when to complete).
Quoted 7 lines
qemu has rather small buffers backend buffers, to keep latencies low. So, yes it would copy data to backend buffers. No, it would most likely not copy over everything immediately. It will most likely leave buffers in the virtqueue, reading the data piecewise in the audio backend timer callback, complete the virtio request when it has read all data. So there wouldn't be a huge gap between completing the request and feeding the data to the host hardware.
Yes, there is a gap, and this causes the following two concerns:
1. An application can rewind its pointer and rewrite part of this buffer. The worst case is if the application rewrites the part currently being read by the device.
2. This approach looks like shared memory on a smaller scale, and the whole meaning of the messages is lost. Because sending a message assumes that what's gone is gone.
Quoted 3 lines
Another reason for this (beside keeping latencies low) is that it is a good idea to avoid or at least limit guest-triggered allocations on the host for security reasons.
Yes, that makes sense.
Quoted 3 lines
While talking about latencies: What happened to the idea to signal additional device latencies (backend buffering and processing ...) to the driver?
Yeah, such an additional latency has a runtime nature, and we could report it as part of an I/O request completion. We only need to choose units (time or bytes).
Quoted 12 lines
Quoted 3 lines
In addition, the driver must advance the
hardware position, and completing the request is the only possible place to do this. In most cases, all this will not coincide with the period notification.So, period notification should be triggered when the device has actually completed processing the data (i.e. host playback finished)? I can see that this can be useful. I think qemu wouldn't be able to support that with the current audio backend design, but that isn't a blocker given this is an optional feature. Also I think the spec should to clarify how period notification is supposed to work, how that relates to buffer completion and latencies.
Quoted 6 lines
Quoted 2 lines
This means that the notification itself is an optional feature that may or may not be enabled for message-based transport.
Which transports are expected to support that?
If multiple transports: Can a device signal it supports these notifications for one transport but not for another?
I think this does not depend on transport, but take a look at the comment below.
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line
I think, it's better not to set queued buffer size restrictions.
Lets make it SHOULD then.
Again, if periods are not used, then there's no
period_bytes. And they are not used, for example, in most low-latency applications.(Well, technically speaking, low-latency applications in Linux must configure period size for ALSA. But then they usually suppress period notifications and send very small chunks of data, which usually do not correspond to the size of the period at all.)
Quoted 5 lines
So you want pass the data on to the device in whatever chunks the userspace application hands them to the driver? Ok, reasonable.
Should we define
period_bytesas upper limit then, i.e. virtio buffers should beperiod_bytesor smaller?
I think, it's becoming more and more complicated and we should revise everything.
Now we have only optional notifications (periods and xrun). But let's say, that the device MAY send the xrun notifications and MUST send the period notifications, and remove them from feature bits.
Then we define requirements for message-based transport:
1. the tx and rx queues are filled in with buffers having period_bytes size,
2. buffer_bytes % period_bytes == 0,
3. total buffers size in the queue is buffer_bytes.
It is still not clear, when to complete playback buffers, but at least such approach makes the driver being interrupt-driven.
Basically, it is what you said but with little changes.
Quoted 9 lines
Completely different topic: I think we should consider adding tags to streams. Some background: In qemu we have two almost identical hda codecs: hda-duplex and hda-micro. The only difference is thathda-duplex has the input stream tagged as "line-in" and the output stream as "line-out", whereas hda-micro has the input channel tagged as "microphone" and the output channel as "speaker". hda-micro was created because some windows application refused to accept "line-in" as audio source. So applications clearly do care, and in case you have two input streams it would help applications pick a reasonable default.
Should it be a fixed-size field in the capabilities structure?
Quoted 5 lines
cheers,
Gerd
Signature · 17 lines
Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin Phone: +49 30 60 98 54 0 E-Mail: [email protected] www.opensynergy.com Handelsregister/Commercial Registry: Amtsgericht Charlottenburg, HRB 108616B Geschäftsführer/Managing Director: Regis Adjamah --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi,
Quoted 8 lines
Quoted 7 lines
qemu has rather small buffers backend buffers, to keep latencies low. So, yes it would copy data to backend buffers. No, it would most likely not copy over everything immediately. It will most likely leave buffers in the virtqueue, reading the data piecewise in the audio backend timer callback, complete the virtio request when it has read all data. So there wouldn't be a huge gap between completing the request and feeding the data to the host hardware.
Quoted 5 lines
Yes, there is a gap, and this causes the following two concerns:
1. An application can rewind its pointer and rewrite part of this buffer. The worst case is if the application rewrites the part currently being read by the device.
Depends on the driver implementation. If the driver will copy over the data to a buffer not visible to the userspace application this can't happen. If the driver allows userspace mmap the buffer, then queues virtio requests with pointers to those buffers, then yes, the application could modify buffers which are sitting in the queue waiting to be processed by the device.
Quoted 7 lines
Quoted 3 lines
While talking about latencies: What happened to the idea to signal additional device latencies (backend buffering and processing ...) to the driver?
Yeah, such an additional latency has a runtime nature, and we could report it as part of an I/O request completion. We only need to choose units (time or bytes).
I'd stick to bytes, for consistency with period and buffer sizes.
Quoted 11 lines
Now we have only optional notifications (periods and xrun). But let's say, that the device MAY send the xrun notifications and MUST send the period notifications, and remove them from feature bits.
Then we define requirements for message-based transport:
1. the tx and rx queues are filled in with buffers havingperiod_bytessize,
2.buffer_bytes%period_bytes== 0,
3. total buffers size in the queue isbuffer_bytes.It is still not clear, when to complete playback buffers, but at least such approach makes the driver being interrupt-driven.
Period notification would be implicit (playback buffer completion) or explicit event queue message?
On playback buffer completion: adding a latency field to the completion field could solve that nicely I think. The latency field would specify how long it will take until the device finishes playing that buffer. So in case the device completes the buffer when playback is finished it would fill in "0" there. In case the device completes the buffer after copying over the data to the internal buffer it would fill in the internal buffer size there (or maybe even the number of bytes which are currently used in the internal buffer).
Quoted 11 lines
Quoted 9 lines
Completely different topic: I think we should consider adding tags to streams. Some background: In qemu we have two almost identical hda codecs: hda-duplex and hda-micro. The only difference is thathda-duplex has the input stream tagged as "line-in" and the output stream as "line-out", whereas hda-micro has the input channel tagged as "microphone" and the output channel as "speaker". hda-micro was created because some windows application refused to accept "line-in" as audio source. So applications clearly do care, and in case you have two input streams it would help applications pick a reasonable default.
Should it be a fixed-size field in the capabilities structure?
Yes, a simple enum would do the trick I think.
Not sure if we want add more properties. hda codecs can also specify the color coding of physical jacks (line-in is red, ...) for example. Probably not useful for most use cases (i.e. when sound data lands @ pulseaudio where the user can re-route things as he wants), but it might be useful when a fixed physical host output is assigned to the guest.
cheers,
Gerd
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi,
Quoted 16 lines · Gerd Hoffmann
Hi,Quoted 8 lines
Quoted 7 lines
qemu has rather small buffers backend buffers, to keep latencies low. So, yes it would copy data to backend buffers. No, it would most likely not copy over everything immediately. It will most likely leave buffers in the virtqueue, reading the data piecewise in the audio backend timer callback, complete the virtio request when it has read all data. So there wouldn't be a huge gap between completing the request and feeding the data to the host hardware.
Quoted 5 lines
Yes, there is a gap, and this causes the following two concerns:
1. An application can rewind its pointer and rewrite part of this buffer. The worst case is if the application rewrites the part currently being read by the device.
Quoted 6 lines
Depends on the driver implementation. If the driver will copy over the data to a buffer not visible to the userspace application this can't happen. If the driver allows userspace mmap the buffer, then queues virtio requests with pointers to those buffers, then yes, the application could modify buffers which are sitting in the queue waiting to be processed by the device.
Yes, it seems that the protocol cannot protect against all possible problems. Let's delegate this to the device / driver implementation then.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
While talking about latencies: What happened to the idea to signal additional device latencies (backend buffering and processing ...) to the driver?
Yeah, such an additional latency has a runtime nature, and we could report it as part of an I/O request completion. We only need to choose units (time or bytes).
I'd stick to bytes, for consistency with period and buffer sizes.
Great!
Quoted 9 lines
Quoted 9 lines
Now we have only optional notifications (periods and xrun). But let's say, that the device MAY send the xrun notifications and MUST send the period notifications, and remove them from feature bits.
Then we define requirements for message-based transport:
1. the tx and rx queues are filled in with buffers havingperiod_bytessize,
2.buffer_bytes%period_bytes== 0,
3. total buffers size in the queue isbuffer_bytes.
Quoted 5 lines
Quoted 2 lines
It is still not clear, when to complete playback buffers, but at least such approach makes the driver being interrupt-driven.
Period notification would be implicit (playback buffer completion) or explicit event queue message?
Good question. I think, for message-base transport they would be implicit, since we will require to enqueue period_size length buffers. The only exception here will be the end of the stream for playback.
As for shared memory, I think that they could work as an optional notification (as suggested earlier), and the driver should enable them using the set params request (setting the feature bit).
Quoted 8 lines
On playback buffer completion: adding a latency field to the completion field could solve that nicely I think. The latency field would specify how long it will take until the device finishes playing that buffer. So in case the device completes the buffer when playback is finished it would fill in "0" there. In case the device completes the buffer after copying over the data to the internal buffer it would fill in the internal buffer size there (or maybe even the number of bytes which are currently used in the internal buffer).
Yes, nice idea. Then let's put it into the spec.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Completely different topic: I think we should consider adding tags to streams. Some background: In qemu we have two almost identical hda codecs: hda-duplex and hda-micro. The only difference is thathda-duplex has the input stream tagged as "line-in" and the output stream as "line-out", whereas hda-micro has the input channel tagged as "microphone" and the output channel as "speaker". hda-micro was created because some windows application refused to accept "line-in" as audio source. So applications clearly do care, and in case you have two input streams it would help applications pick a reasonable default.
Quoted 3 lines
Quoted 1 line
Should it be a fixed-size field in the capabilities structure?
Yes, a simple enum would do the trick I think.
And just reuse existing values from the HDA spec, right?
Quoted 5 lines
Not sure if we want add more properties. hda codecs can also specify the color coding of physical jacks (line-in is red, ...) for example. Probably not useful for most use cases (i.e. when sound data lands @ pulseaudio where the user can re-route things as he wants), but it might be useful when a fixed physical host output is assigned to the guest.
Well, if we are gonna introduce jacks colors, then we should introduce a jack entity itself. Like, define some kind of jack descriptor, enumerate all available jacks for the stream, putting into the descriptor its color and other properties, maybe allow jack hotplug/unplug, etc.
Quoted 9 lines
cheers,
Gerd---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Signature · 17 lines
Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin Phone: +49 30 60 98 54 0 E-Mail: [email protected] www.opensynergy.com Handelsregister/Commercial Registry: Amtsgericht Charlottenburg, HRB 108616B Geschäftsführer/Managing Director: Regis Adjamah --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi,
Quoted 6 lines
Quoted 2 lines
Period notification would be implicit (playback buffer completion) or explicit event queue message?
Good question. I think, for message-base transport they would be implicit, since we will require to enqueue
period_sizelength buffers. The only exception here will be the end of the stream for playback.
Why is the end-of-stream different?
Quoted 3 lines
As for shared memory, I think that they could work as an optional notification (as suggested earlier), and the driver should enable them using the set params request (setting the feature bit).
Sounds good.
Quoted 3 lines
Quoted 1 line
Yes, a simple enum would do the trick I think.
And just reuse existing values from the HDA spec, right?
Looks useful, simplifies things.
Quoted 10 lines
Quoted 5 lines
Not sure if we want add more properties. hda codecs can also specify the color coding of physical jacks (line-in is red, ...) for example. Probably not useful for most use cases (i.e. when sound data lands @ pulseaudio where the user can re-route things as he wants), but it might be useful when a fixed physical host output is assigned to the guest.
Well, if we are gonna introduce jacks colors, then we should introduce a jack entity itself. Like, define some kind of jack descriptor, enumerate all available jacks for the stream, putting into the descriptor its color and other properties, maybe allow jack hotplug/unplug, etc.
We also need routing then (enable/disable jacks per stream), and link detection (is something plugged into the jack?) could be useful too.
Should we make that an optional extension (and possibly hash out these details later)? If you assign host machine jacks to your guest all this is useful. If your guests's sound is routed to pulseaudio for playback not so much.
Note: I'll be offline for xmas and new year until january.
cheers,
Gerd
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 10 lines · Gerd Hoffmann
Hi,Quoted 6 lines
Quoted 2 lines
Period notification would be implicit (playback buffer completion) or explicit event queue message?
Good question. I think, for message-base transport they would be implicit, since we will require to enqueue
period_sizelength buffers. The only exception here will be the end of the stream for playback.Why is the end-of-stream different?
Since, as in the case of the input stream, the last buffer may contain less than period_bytes of data.
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Not sure if we want add more properties. hda codecs can also specify the color coding of physical jacks (line-in is red, ...) for example. Probably not useful for most use cases (i.e. when sound data lands @ pulseaudio where the user can re-route things as he wants), but it might be useful when a fixed physical host output is assigned to the guest.
Well, if we are gonna introduce jacks colors, then we should introduce a jack entity itself. Like, define some kind of jack descriptor, enumerate all available jacks for the stream, putting into the descriptor its color and other properties, maybe allow jack hotplug/unplug, etc.
Quoted 7 lines
We also need routing then (enable/disable jacks per stream), and link detection (is something plugged into the jack?) could be useful too.
Should we make that an optional extension (and possibly hash out these details later)? If you assign host machine jacks to your guest all this is useful. If your guests's sound is routed to pulseaudio for playback not so much.
Yeah, we can put it off for later. In addition, in the case of PA, sinks and sources can be moved, added and removed dynamically, so some logic with jacks might be useful there as well.
Quoted 1 line
Note: I'll be offline for xmas and new year until january.
Happy holidays!
Signature · 13 lines
Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin Phone: +49 30 60 98 54 0 E-Mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · Mark Brown
Quoted 9 lines · Anton Yakovlev
Quoted 7 lines · Gerd Hoffmann
Well, the driver has to manage buffers, so I can't see how a driver is not interested in completion notifications. If the driver isn't interested in keeping the latency low by using lots of small buffers it still needs to queue at least two (larger) buffers, so the device still has data to continue playback when it completed a buffer. And the driver needs to know when the device is done with a buffer so it can either recycle the buffer or free the pages.
Quoted 6 lines
Quoted 2 lines
It seems that you have mixed up two different things: sending/completing a request containing a buffer, and period notifications. They are not the same.
What do you expect a period notification to be? The default expecation would very much be that they're tied to what's going on with the buffers.
Elapsed period notification was initially proposed as an optional feature. But then the discussion switched on to define the entire period-based operational sequence built in protocol. Well, we can go this way and make periods not an optional notification, but a full optional mode of operation. Then we can add all the requirements that Gerd spoke of.
Signature · 12 lines
Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin Phone: +49 30 60 98 54 0 E-Mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]