Skip to content

Commit 3c9c17b

Browse files
committed
vhost-device-sound: Add GStreamer audio backend support
This pr adds a new audio backend implementation based on GStreamer. Signed-off-by: nicholasdezai <[email protected]>
1 parent 1a4b5ec commit 3c9c17b

File tree

11 files changed

+1879
-293
lines changed

11 files changed

+1879
-293
lines changed

Cargo.lock

Lines changed: 584 additions & 291 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: 1 addition & 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

vhost-device-sound/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ edition = "2018"
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.9", optional = true }
3435
pw = { package = "pipewire", version = "0.8", optional = true }
36+
gst = { package = "gstreamer", version = "0.22", optional = true, features = ["v1_24"] }
37+
gst-app = { package = "gstreamer-app", version = "0.22", optional = true, features = ["v1_24"] }
38+
gst-audio = {package = "gstreamer-audio", version = "0.22", optional = true, features = ["v1_24"] }
3539

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

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: 7 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,8 @@ 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 => Ok(Box::new(GStreamerBackend::new(streams))),
6471
}
6572
}
6673

0 commit comments

Comments
 (0)