From e1488eca55aac4fb2397993faeff5d856594da6c Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 28 Feb 2024 00:07:15 +0100 Subject: [PATCH] pipewire: force re-negotiation when buffers change --- src/pipewire/pw_ifs/pw_client_node.rs | 21 ++++++++++++++++----- src/portal/ptl_screencast.rs | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pipewire/pw_ifs/pw_client_node.rs b/src/pipewire/pw_ifs/pw_client_node.rs index 11f47b18..ac139ac1 100644 --- a/src/pipewire/pw_ifs/pw_client_node.rs +++ b/src/pipewire/pw_ifs/pw_client_node.rs @@ -25,8 +25,9 @@ use { SPA_PARAM_Meta, SpaDataFlags, SpaDataType, SpaDirection, SpaIoType, SpaMediaSubtype, SpaMediaType, SpaMetaType, SpaNodeBuffersFlags, SpaNodeCommand, SpaParamType, SpaVideoFormat, SPA_DATA_FLAG_READABLE, SPA_DIRECTION_INPUT, - SPA_DIRECTION_OUTPUT, SPA_NODE_BUFFERS_FLAG_ALLOC, SPA_PARAM_INFO_READ, - SPA_PORT_FLAG, SPA_PORT_FLAG_CAN_ALLOC_BUFFERS, + SPA_DIRECTION_OUTPUT, SPA_NODE_BUFFERS_FLAG_ALLOC, SPA_PARAM_INFO, + SPA_PARAM_INFO_READ, SPA_PARAM_INFO_SERIAL, SPA_PORT_FLAG, + SPA_PORT_FLAG_CAN_ALLOC_BUFFERS, }, }, utils::{ @@ -120,6 +121,8 @@ pub struct PwClientNodePort { pub buffer_config: Cell>, pub io_buffers: CopyHashMap>>, + + pub serial: Cell, } #[derive(Copy, Clone, Debug, Default)] @@ -255,6 +258,7 @@ impl PwClientNode { buffers: RefCell::new(vec![]), buffer_config: Cell::new(None), io_buffers: Default::default(), + serial: Cell::new(false), }); self.ports.set((direction, port.id), port.clone()); port @@ -291,7 +295,14 @@ impl PwClientNode { }); } - pub fn send_port_update(&self, port: &PwClientNodePort) { + pub fn send_port_update(&self, port: &PwClientNodePort, re_init: bool) { + if re_init { + port.serial.set(!port.serial.get()); + } + let serial = match port.serial.get() { + true => SPA_PARAM_INFO_SERIAL, + false => SPA_PARAM_INFO::none(), + }; self.con.send(self, PwClientNodeMethods::PortUpdate, |f| { f.write_struct(|f| { // direction @@ -437,11 +448,11 @@ impl PwClientNode { f.write_uint(num_params); if sf.is_some() { f.write_id(SPA_PARAM_EnumFormat.0); - f.write_uint(SPA_PARAM_INFO_READ.0); + f.write_uint((SPA_PARAM_INFO_READ | serial).0); } if bc.is_some() { f.write_id(SPA_PARAM_Buffers.0); - f.write_uint(SPA_PARAM_INFO_READ.0); + f.write_uint((SPA_PARAM_INFO_READ | serial).0); } f.write_id(SPA_PARAM_Meta.0); f.write_uint(SPA_PARAM_INFO_READ.0); diff --git a/src/portal/ptl_screencast.rs b/src/portal/ptl_screencast.rs index 60502f52..e1aa2b5c 100644 --- a/src/portal/ptl_screencast.rs +++ b/src/portal/ptl_screencast.rs @@ -155,7 +155,7 @@ impl PwClientNodeOwner for StartingScreencast { impl PwClientNodeOwner for StartedScreencast { fn port_format_changed(&self, port: &Rc) { - self.node.send_port_update(port); + self.node.send_port_update(port, false); } fn use_buffers(&self, port: &Rc) { @@ -300,7 +300,7 @@ impl UsrJayScreencastOwner for StartedScreencast { data_type: SPA_DATA_DmaBuf, }; self.port.buffer_config.set(Some(bc)); - self.node.send_port_update(&self.port); + self.node.send_port_update(&self.port, true); self.node.send_active(true); *self.buffers.borrow_mut() = buffers; }