Skip to content

Commit ca88c8b

Browse files
committed
vhost-device-sound: Add GStreamer audio backend support
Add gstreamer backend. Add gstreamer-related crates used in the vhost-device-sound module This affects only the vhost-device-sound module, and updates the following dependencies: - dependency-name: gstreamer dependency-version: 0.24.2 - dependency-name: gstreamer-app dependency-version: 0.24.2 - dependency-name: gstreamer-audio dependency-version: 0.24.2 Signed-off-by: nicholasdezai <[email protected]>
1 parent b6fd16f commit ca88c8b

File tree

10 files changed

+1683
-227
lines changed

10 files changed

+1683
-227
lines changed

Cargo.lock

Lines changed: 404 additions & 224 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vhost-device-sound/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
### Added
55

6+
- [[#876]](https://github.com/rust-vmm/vhost-device/pull/876) Add GStreamer audio backend support
67
- [[#806]](https://github.com/rust-vmm/vhost-device/pull/806) Add controls field in VirtioSoundConfig
78
- [[#746]](https://github.com/rust-vmm/vhost-device/pull/746) Add new sampling rates 12000Hz and 24000Hz
89

@@ -14,6 +15,10 @@
1415
- [[#808]](https://github.com/rust-vmm/vhost-device/pull/808) pipewire: Fix rand module imports
1516
- [[#884]](https://github.com/rust-vmm/vhost-device/pull/884) vhost-device-sound/pipewire: fix wrong format
1617

18+
### Limitations
19+
20+
- GStreamer backend: 20-bit PCM formats (VIRTIO_SND_PCM_FMT_S20/U20) are not directly supported by GStreamer and are automatically converted to 24/32-bit formats
21+
1722
### Deprecated
1823

1924
## v0.2.0

vhost-device-sound/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ edition = "2021"
1212

1313
[features]
1414
xen = ["vm-memory/xen", "vhost/xen", "vhost-user-backend/xen"]
15-
default = ["alsa-backend", "pw-backend"]
15+
default = ["alsa-backend", "pw-backend", "gst-backend"]
1616
alsa-backend = ["dep:alsa"]
1717
pw-backend = ["pw"]
18+
gst-backend = ["dep:gst", "dep:gst-app", "dep:gst-audio"]
1819

1920
[dependencies]
2021
clap = { version = "4.5", features = ["derive"] }
@@ -32,6 +33,9 @@ vmm-sys-util = "0.14"
3233
[target.'cfg(target_env = "gnu")'.dependencies]
3334
alsa = { version = "0.10", optional = true }
3435
pw = { package = "pipewire", version = "0.9.2", optional = true }
36+
gst = { package = "gstreamer", version = "0.24.2", optional = true, features = ["v1_24"] }
37+
gst-app = { package = "gstreamer-app", version = "0.24.2", optional = true, features = ["v1_24"] }
38+
gst-audio = {package = "gstreamer-audio", version = "0.24.2", optional = true, features = ["v1_24"] }
3539

3640
[dev-dependencies]
3741
rstest = "0.26.1"

vhost-device-sound/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ generated with help2man target/debug/vhost-device-sound |mandoc
1616
vhost-user Unix domain socket path
1717
1818
--backend <BACKEND>
19-
audio backend to be used [possible values: null, pipewire, alsa]
19+
audio backend to be used [possible values: null, pipewire, alsa, gstreamer]
2020
2121
-h, --help
2222
Print help

vhost-device-sound/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ pub enum BackendType {
2525
Pipewire,
2626
#[cfg(all(feature = "alsa-backend", target_env = "gnu"))]
2727
Alsa,
28+
#[cfg(all(feature = "gst-backend", target_env = "gnu"))]
29+
#[value(name = "gstreamer")]
30+
GStreamer,
2831
}

vhost-device-sound/src/audio_backends.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ mod null;
88
#[cfg(all(feature = "pw-backend", target_env = "gnu"))]
99
mod pipewire;
1010

11+
#[cfg(all(feature = "gst-backend", target_env = "gnu"))]
12+
mod gstreamer;
13+
1114
use std::sync::{Arc, RwLock};
1215

1316
#[cfg(all(feature = "alsa-backend", target_env = "gnu"))]
1417
use self::alsa::AlsaBackend;
18+
#[cfg(all(feature = "gst-backend", target_env = "gnu"))]
19+
use self::gstreamer::GStreamerBackend;
1520
use self::null::NullBackend;
1621
#[cfg(all(feature = "pw-backend", target_env = "gnu"))]
1722
use self::pipewire::PwBackend;
@@ -61,6 +66,12 @@ pub fn alloc_audio_backend(
6166
}
6267
#[cfg(all(feature = "alsa-backend", target_env = "gnu"))]
6368
BackendType::Alsa => Ok(Box::new(AlsaBackend::new(streams))),
69+
#[cfg(all(feature = "gst-backend", target_env = "gnu"))]
70+
BackendType::GStreamer => {
71+
Ok(Box::new(GStreamerBackend::new(streams).map_err(|err| {
72+
crate::Error::UnexpectedAudioBackendError(err.into())
73+
})?))
74+
}
6475
}
6576
}
6677

0 commit comments

Comments
 (0)