mirror of
https://github.com/rustdesk/qemu-display.git
synced 2026-10-26 22:20:02 +00:00
rdw: try audio capture
This commit is contained in:
1 parent
fabfa85adc
commit
b6f12103e9
4 files changed
+76
-6
No files matched your search
+1
-1
@@ -13,7 +13,7 @@ once_cell = "1.5"
|
||||
zbus = { version = "2.0.0-beta" }
|
||||
qemu-display = { path = "../qemu-display" }
|
||||
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 = "0.3.13"
|
||||
async-trait = "0.1.48"
|
||||
+51
-5
@@ -1,6 +1,6 @@
|
||||
use std::{error::Error, result::Result};
|
||||
|
||||
use qemu_display::{Audio, AudioOutHandler};
|
||||
use qemu_display::{Audio, AudioInHandler, AudioOutHandler};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Handler {
|
||||
@@ -9,7 +9,7 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct OutListener {
|
||||
struct OutListener {
|
||||
gst: rdw::GstAudio,
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ pub struct OutListener {
|
||||
impl AudioOutHandler for OutListener {
|
||||
async fn init(&mut self, id: u64, info: qemu_display::PCMInfo) {
|
||||
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) {
|
||||
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.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 {
|
||||
pub async fn new(mut audio: Audio) -> Result<Handler, Box<dyn Error>> {
|
||||
let gst = rdw::GstAudio::new()?;
|
||||
audio.register_out_listener(OutListener { gst }).await?;
|
||||
let gst = rdw::GstAudio::new()?;
|
||||
audio.register_in_listener(InListener { gst }).await?;
|
||||
Ok(Handler { audio })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user