Skip to content

Commit

Permalink
sound/pipewire: destroy pipewire streams not destroyed
Browse files Browse the repository at this point in the history
The PCM command transition prepare->prepare or set_param->prepare
is allowed by the specification. Pipewire, however, creates multiple
streams which are not destroyed when this type of transition happens.
By using this PR, we can ensure that when the prepare function in the
pipewire backend is called multiple times without the release function,
only one pipewire stream is created.

Close rust-vmm#490

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
  • Loading branch information
Dorinda Bassey committed Apr 2, 2024
1 parent 04998a9 commit 1809dae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vhost-device-sound/src/audio_backends/pipewire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ impl AudioBackend for PwBackend {

let params = &stream_params[stream_id as usize].params;

if let Some(stream) = stream_hash.get(&stream_id) {
if let Err(err) = stream.disconnect() {
log::error!("Stream {} disconnect {}", stream_id, err);
return Err(Error::CouldNotDisconnectStream);
}
stream_hash.remove(&stream_id);
stream_listener.remove(&stream_id);
}

let mut pos: [u32; 64] = [SPA_AUDIO_CHANNEL_UNKNOWN; 64];

match params.channels {
Expand Down
2 changes: 2 additions & 0 deletions vhost-device-sound/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ pub enum Error {
StreamWithIdNotFound(u32),
#[error("Channel number not supported: {0}")]
ChannelNotSupported(u8),
#[error("Could not disconnect stream")]
CouldNotDisconnectStream,
}

impl From<Error> for IoError {
Expand Down

0 comments on commit 1809dae

Please sign in to comment.