mirror of
https://github.com/rustdesk/qemu-display.git
synced 2025-07-01 15:25:29 +00:00
rdw: try audio capture
This commit is contained in:
parent
fabfa85adc
commit
b6f12103e9
@ -16,3 +16,4 @@ zbus = { git = "https://gitlab.freedesktop.org/dbus/zbus.git" }
|
|||||||
zvariant = { git = "https://gitlab.freedesktop.org/dbus/zbus.git" }
|
zvariant = { git = "https://gitlab.freedesktop.org/dbus/zbus.git" }
|
||||||
#zbus = { path = "../zbus/zbus" }
|
#zbus = { path = "../zbus/zbus" }
|
||||||
#zvariant = { path = "../zbus/zvariant" }
|
#zvariant = { path = "../zbus/zvariant" }
|
||||||
|
rdw4 = { path = "../rdw/rdw4" }
|
||||||
|
@ -256,4 +256,27 @@ impl Audio {
|
|||||||
self.out_listener.replace(c);
|
self.out_listener.replace(c);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn register_in_listener<H: AudioInHandler>(&mut self, handler: H) -> Result<()> {
|
||||||
|
let (p0, p1) = UnixStream::pair()?;
|
||||||
|
self.proxy
|
||||||
|
.register_in_listener(p0.as_raw_fd().into())
|
||||||
|
.await?;
|
||||||
|
let c = zbus::ConnectionBuilder::unix_stream(p1)
|
||||||
|
.p2p()
|
||||||
|
.build()
|
||||||
|
.await?;
|
||||||
|
{
|
||||||
|
let mut server = c.object_server_mut().await;
|
||||||
|
server
|
||||||
|
.at(
|
||||||
|
"/org/qemu/Display1/AudioInListener",
|
||||||
|
AudioInListener { handler },
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
server.start_dispatch();
|
||||||
|
}
|
||||||
|
self.in_listener.replace(c);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ once_cell = "1.5"
|
|||||||
zbus = { version = "2.0.0-beta" }
|
zbus = { version = "2.0.0-beta" }
|
||||||
qemu-display = { path = "../qemu-display" }
|
qemu-display = { path = "../qemu-display" }
|
||||||
keycodemap = { path = "../keycodemap" }
|
keycodemap = { path = "../keycodemap" }
|
||||||
rdw = { package = "rdw4", git = "https://gitlab.gnome.org/malureau/rdw.git" }
|
rdw = { package = "rdw4", version = "0.1.0" }
|
||||||
futures-util = "0.3.13"
|
futures-util = "0.3.13"
|
||||||
futures = "0.3.13"
|
futures = "0.3.13"
|
||||||
async-trait = "0.1.48"
|
async-trait = "0.1.48"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{error::Error, result::Result};
|
use std::{error::Error, result::Result};
|
||||||
|
|
||||||
use qemu_display::{Audio, AudioOutHandler};
|
use qemu_display::{Audio, AudioInHandler, AudioOutHandler};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Handler {
|
pub struct Handler {
|
||||||
@ -9,7 +9,7 @@ pub struct Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct OutListener {
|
struct OutListener {
|
||||||
gst: rdw::GstAudio,
|
gst: rdw::GstAudio,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ pub struct OutListener {
|
|||||||
impl AudioOutHandler for OutListener {
|
impl AudioOutHandler for OutListener {
|
||||||
async fn init(&mut self, id: u64, info: qemu_display::PCMInfo) {
|
async fn init(&mut self, id: u64, info: qemu_display::PCMInfo) {
|
||||||
if let Err(e) = self.gst.init_out(id, &info.gst_caps()) {
|
if let Err(e) = self.gst.init_out(id, &info.gst_caps()) {
|
||||||
log::warn!("Failed to initialize audio stream: {}", e);
|
log::warn!("Failed to initialize audio output stream: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ impl AudioOutHandler for OutListener {
|
|||||||
|
|
||||||
async fn set_enabled(&mut self, id: u64, enabled: bool) {
|
async fn set_enabled(&mut self, id: u64, enabled: bool) {
|
||||||
if let Err(e) = self.gst.set_enabled_out(id, enabled) {
|
if let Err(e) = self.gst.set_enabled_out(id, enabled) {
|
||||||
log::warn!("Failed to set enabled audio stream: {}", e);
|
log::warn!("Failed to set enabled audio output stream: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ impl AudioOutHandler for OutListener {
|
|||||||
volume.mute,
|
volume.mute,
|
||||||
volume.volume.first().map(|v| *v as f64 / 255f64),
|
volume.volume.first().map(|v| *v as f64 / 255f64),
|
||||||
) {
|
) {
|
||||||
log::warn!("Failed to set volume: {}", e);
|
log::warn!("Failed to set output volume: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,10 +48,56 @@ impl AudioOutHandler for OutListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
struct InListener {
|
||||||
|
gst: rdw::GstAudio,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl AudioInHandler for InListener {
|
||||||
|
async fn init(&mut self, id: u64, info: qemu_display::PCMInfo) {
|
||||||
|
if let Err(e) = self.gst.init_in(id, &info.gst_caps()) {
|
||||||
|
log::warn!("Failed to initialize audio input stream: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fini(&mut self, id: u64) {
|
||||||
|
self.gst.fini_in(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_enabled(&mut self, id: u64, enabled: bool) {
|
||||||
|
if let Err(e) = self.gst.set_enabled_in(id, enabled) {
|
||||||
|
log::warn!("Failed to set enabled audio input stream: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_volume(&mut self, id: u64, volume: qemu_display::Volume) {
|
||||||
|
if let Err(e) = self.gst.set_volume_in(
|
||||||
|
id,
|
||||||
|
volume.mute,
|
||||||
|
volume.volume.first().map(|v| *v as f64 / 255f64),
|
||||||
|
) {
|
||||||
|
log::warn!("Failed to set audio input volume: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn read(&mut self, id: u64, size: u64) -> Vec<u8> {
|
||||||
|
match self.gst.read_in(id, size).await {
|
||||||
|
Ok(d) => d,
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("Failed to read from input stream: {}", e);
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Handler {
|
impl Handler {
|
||||||
pub async fn new(mut audio: Audio) -> Result<Handler, Box<dyn Error>> {
|
pub async fn new(mut audio: Audio) -> Result<Handler, Box<dyn Error>> {
|
||||||
let gst = rdw::GstAudio::new()?;
|
let gst = rdw::GstAudio::new()?;
|
||||||
audio.register_out_listener(OutListener { gst }).await?;
|
audio.register_out_listener(OutListener { gst }).await?;
|
||||||
|
let gst = rdw::GstAudio::new()?;
|
||||||
|
audio.register_in_listener(InListener { gst }).await?;
|
||||||
Ok(Handler { audio })
|
Ok(Handler { audio })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user