What is the best way to know if there are clients actually playing to a sink?
In order to save cpu usage PulseEffects tries to detect if there are audio applications actually playing audio. If there is we put our pipeline in the playing state. If not we stop it. At this moment what I am doing is listening to Link events. When I get one I iterate over all the links that are connected to our virtual sink and if there is at least one active I put the pipeline in the playing state. This approach works but it feels dumb and inefficient because there are events that do not matter. And in the end many unnecessary calls to
gst_element_get_state are made in order to check the current pipeline state and deciding if we should change it or not.
A similar situation happens on Pulseaudio but I wonder if on PipeWire there is already a better way to do this and I am not seeing it. Initially I thought about the node
state property. But it does not help because even when no client is playing to the sink it stays active when something is recording from its monitors. And our pipeline has to record from it to apply effects.
As far as the output of
pw-cli info goes I could not see any property in the sink node or in its ports that would reflect the activity of clients playing to it. So maybe there isn't a way to get this information.
I know this is the kind of situation that would not happen in a 100% PipeWire implementation without relying on GStreamer. But we are still far from that in PulseEffects...