mirror of
https://gitlab.com/marcandre.lureau/qemu-display.git
synced 2025-04-14 08:44:46 +00:00
gtk: detect if Audio is availble
This commit is contained in:
parent
865aec3f31
commit
be6e05d788
@ -8,7 +8,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
derivative = "2.2.0"
|
||||
zbus = "2.0.0-beta"
|
||||
zbus = { version = "2.0.0-beta", features = ["xml"] }
|
||||
zvariant = { version = "2.4.0", features = ["serde_bytes"] }
|
||||
libc = "0.2.86"
|
||||
glib = { git = "https://github.com/gtk-rs/gtk-rs", optional = true }
|
||||
|
@ -3,6 +3,7 @@ use std::os::unix::net::UnixStream;
|
||||
use std::sync::mpsc::{self, Receiver, SendError};
|
||||
use std::sync::Arc;
|
||||
use std::{os::unix::io::AsRawFd, thread};
|
||||
use std::str::FromStr;
|
||||
|
||||
use zbus::{dbus_interface, dbus_proxy, export::zvariant::Fd};
|
||||
|
||||
@ -234,6 +235,14 @@ impl Audio {
|
||||
Ok(Self { proxy })
|
||||
}
|
||||
|
||||
pub fn available(conn: &zbus::Connection) -> bool {
|
||||
// TODO: we may want to generalize interface detection
|
||||
let ip = zbus::fdo::IntrospectableProxy::new_for(&conn, "org.qemu", "/org/qemu/Display1").unwrap();
|
||||
let introspect = zbus::xml::Node::from_str(&ip.introspect().unwrap()).unwrap();
|
||||
let has_audio = introspect.nodes().iter().any(|n| n.name().map(|n| n == "Audio").unwrap_or(false));
|
||||
has_audio
|
||||
}
|
||||
|
||||
pub fn listen_out(&self) -> Result<Receiver<AudioOutEvent>> {
|
||||
let (p0, p1) = UnixStream::pair()?;
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
@ -96,11 +96,14 @@ mod imp {
|
||||
}
|
||||
.expect("Failed to connect to DBus");
|
||||
|
||||
if let Ok(audio) = Audio::new(&conn) {
|
||||
self.audio
|
||||
.set(GstAudio::new(audio).expect("Failed to setup audio"))
|
||||
.expect("Audio already set");
|
||||
if Audio::available(&conn) {
|
||||
if let Ok(audio) = Audio::new(&conn) {
|
||||
self.audio
|
||||
.set(GstAudio::new(audio).expect("Failed to setup audio"))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let console = Console::new(&conn, 0).expect("Failed to get the console");
|
||||
self.conn.set(conn).expect("Connection already set.");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user