1
0
Fork 0
forked from wry/wry

pipewire: fix signaling of consumers

This commit is contained in:
Julian Orth 2024-09-02 21:07:53 +02:00
parent a57126327c
commit 8d2bd6f660
3 changed files with 34 additions and 32 deletions

View file

@ -24,10 +24,11 @@ use {
SPA_PARAM_EnumFormat, SPA_PARAM_Format, SPA_PARAM_META_size, SPA_PARAM_META_type, SPA_PARAM_EnumFormat, SPA_PARAM_Format, SPA_PARAM_META_size, SPA_PARAM_META_type,
SPA_PARAM_Meta, SpaDataFlags, SpaDataType, SpaDirection, SpaIoType, SPA_PARAM_Meta, SpaDataFlags, SpaDataType, SpaDirection, SpaIoType,
SpaMediaSubtype, SpaMediaType, SpaMetaType, SpaNodeBuffersFlags, SpaNodeCommand, SpaMediaSubtype, SpaMediaType, SpaMetaType, SpaNodeBuffersFlags, SpaNodeCommand,
SpaParamType, SpaVideoFormat, SPA_DATA_FLAG_READABLE, SPA_DIRECTION_INPUT, SpaParamType, SpaVideoFormat, PW_NODE_ACTIVATION_FINISHED,
SPA_DIRECTION_OUTPUT, SPA_NODE_BUFFERS_FLAG_ALLOC, SPA_PARAM_INFO, PW_NODE_ACTIVATION_NOT_TRIGGERED, PW_NODE_ACTIVATION_TRIGGERED,
SPA_PARAM_INFO_READ, SPA_PARAM_INFO_SERIAL, SPA_PORT_FLAG, SPA_DATA_FLAG_READABLE, SPA_DIRECTION_INPUT, SPA_DIRECTION_OUTPUT,
SPA_PORT_FLAG_CAN_ALLOC_BUFFERS, 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::{ utils::{
@ -41,6 +42,7 @@ use {
mem, mem,
ops::Deref, ops::Deref,
rc::Rc, rc::Rc,
sync::atomic::Ordering::{Relaxed, Release},
}, },
thiserror::Error, thiserror::Error,
uapi::OwnedFd, uapi::OwnedFd,
@ -181,8 +183,8 @@ pub struct PwClientNode {
} }
pub struct PwNodeActivation { pub struct PwNodeActivation {
pub _activation: Rc<PwMemTyped<pw_node_activation>>, pub activation: Rc<PwMemTyped<pw_node_activation>>,
pub _fd: Rc<OwnedFd>, pub fd: Rc<OwnedFd>,
} }
// pub struct PwNodeBuffer { // pub struct PwNodeBuffer {
@ -766,8 +768,8 @@ impl PwClientNode {
self.activations.set( self.activations.set(
node, node,
Rc::new(PwNodeActivation { Rc::new(PwNodeActivation {
_activation: typed, activation: typed,
_fd: signalfd, fd: signalfd,
}), }),
); );
} else { } else {
@ -812,27 +814,29 @@ impl PwClientNode {
) { ) {
let mut buf = TypedBuf::<u64>::new(); let mut buf = TypedBuf::<u64>::new();
loop { loop {
// unsafe {
// log::info!("transport = {:#?}", activation.read());
// }
// log::info!("transport in");
// for port in self.ports.lock().values() {
// for io in port.io_buffers.lock().values() {
// unsafe {
// log::info!("status = {:?}", io.read().status);
// }
// }
// }
// unsafe {
// log::info!("state = {:#?}", activation.read().state[0]);
// }
if let Err(e) = self.con.ring.read(&fd, buf.buf()).await { if let Err(e) = self.con.ring.read(&fd, buf.buf()).await {
log::error!("Could not read from eventfd: {}", ErrorFmt(e)); log::error!("Could not read from eventfd: {}", ErrorFmt(e));
return; return;
} }
let n = buf.t(); if let Some(activation) = self.activation.get() {
if n > 1 { let activation = unsafe { activation.read() };
log::warn!("Missed {} transport changes", n - 1); activation
.status
.store(PW_NODE_ACTIVATION_FINISHED.0, Relaxed);
}
}
}
pub fn drive(&self) {
for activation in self.activations.lock().values() {
let a = unsafe { activation.activation.read() };
let required = a.state[0].required.load(Relaxed);
a.state[0].pending.store(required - 1, Relaxed);
if required == 1 {
a.status.store(PW_NODE_ACTIVATION_TRIGGERED.0, Release);
let _ = uapi::eventfd_write(activation.fd.raw(), 1);
} else {
a.status.store(PW_NODE_ACTIVATION_NOT_TRIGGERED.0, Release);
} }
} }
} }

View file

@ -7,7 +7,7 @@ use {
bstr::BStr, bstr::BStr,
std::{ std::{
fmt::{Debug, Formatter}, fmt::{Debug, Formatter},
sync::atomic::AtomicU32, sync::atomic::{AtomicI32, AtomicU32},
}, },
uapi::{c, Pod}, uapi::{c, Pod},
}; };
@ -1344,8 +1344,8 @@ pub struct spa_io_position {
#[derive(Debug)] #[derive(Debug)]
pub struct pw_node_activation_state { pub struct pw_node_activation_state {
pub status: c::c_int, pub status: c::c_int,
pub required: i32, pub required: AtomicI32,
pub pending: i32, pub pending: AtomicI32,
} }
ty! { ty! {
@ -1368,7 +1368,7 @@ ty! {
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct pw_node_activation { pub struct pw_node_activation {
pub status: PW_NODE_ACTIVATION, pub status: AtomicU32,
pub flags: c::c_uint, pub flags: c::c_uint,

View file

@ -454,9 +454,7 @@ impl UsrJayScreencastOwner for StartedScreencast {
} }
io.buffer_id.store(ev.idx, Relaxed); io.buffer_id.store(ev.idx, Relaxed);
io.status.store(SPA_STATUS_HAVE_DATA.0, Release); io.status.store(SPA_STATUS_HAVE_DATA.0, Release);
if let Some(wfd) = self.port.node.transport_out.get() { self.port.node.drive();
let _ = uapi::eventfd_write(wfd.raw(), 1);
}
} }
fn destroyed(&self) { fn destroyed(&self) {