In this commit, the buffers are only read from the available ring when
the audio backend will consume them. The guest driver moves buffers from
the used to the avail ring without knowing if the user application has
updated the content. As a result, when a request is enqueued into the
available ring, the device only reads the buffer from guest memory when
it is required by the audio engine. By doing this, we add enough delay
so that we can read the updated buffer.
Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
Inserting a new stream into stream_hash can potentially move out of
context a stream previously stored in the hash with the same id,
triggering pw::stream::Stream::Drop, which calls pw_stream_destroy.
As calls to the pipewire library must happen either in the pipewire
thread or under thread_loop lock protection, move the insert into
stream_hash under the latter.
Signed-off-by: Sergio Lopez <slp@redhat.com>
Make Null backend compiled unconditionally,
removing the null-backend feature. That
allows having the other backend choices in
the BackendType enum to be conditional, and
make them not available if their features is
opted out at compile time.
For example, compiled with no backend features,
there is only choice (i.e., null) for --backend:
```
$ target/debug/vhost-user-sound --help
Usage: vhost-user-sound --socket <SOCKET> --backend <BACKEND>
Options:
--socket <SOCKET> vhost-user Unix domain socket path
--backend <BACKEND> audio backend to be used [possible values: null]
-h, --help Print help
-V, --version Print version
```
Fixes: #26
Signed-off-by: Albert Esteve <aesteve@redhat.com>
When compiled with no features, the `streams`
parameter of the alloc_audio_backend() function
is not used. Mark it as allowed to avoid the
compilation warning.
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Change the CLI backend option to receive values
listed in a ValueEnum.
Current '--help' output:
```
A virtio-sound device using the vhost-user protocol.
Usage: vhost-user-sound --socket <SOCKET> --backend <BACKEND>
Options:
--socket <SOCKET> vhost-user Unix domain socket path
--backend <BACKEND> audio backend to be used [possible values:
null, pipewire, alsa]
-h, --help Print help
-V, --version Print version
```
If a wrong backend is given, it give hints:
```
$ cargo run -- --socket /tmp/sound.sock --backend nul
error: invalid value 'nul' for '<BACKEND>'
[possible values: null, pipewire, alsa]
tip: a similar value exists: 'null'
```
Signed-off-by: Albert Esteve <aesteve@redhat.com>
This commit adds the set_param() method. This method can only be called
if the stream is in the "set parameters", "prepare" or "release" state.
For the pw backend, this method only updates the internal values for the
given stream.
Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
This commit adds a vector named StreamInfo that contains the supported
configuration for the audio backends, e.g., rate, format. This
information is stored in the context of VhostUserSoundBackend. The
device reponses this information when getting the VIRTIO_SND_R_PCM_INFO
msg. The number of streams that are exposed in the device configuration
is got from this table.
Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
This commit handles the pcm i/o messages to the tx transmission queue.
These msgs contains three descriptors: hdr, data and status. The data
descriptor shall be processed by the audio backend. The data may be
split in multiples descriptors.
Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>