[pulseaudio-discuss] Releasing stream resources when the client receives SIGSTOP
Tanu Kaskinen
tanu.kaskinen at linux.intel.com
Mon Nov 24 03:04:32 PST 2014
On Mon, 2014-11-24 at 11:12 +0100, David Henningsson wrote:
>
> On 2014-11-20 04:44, Ricardo Salveti wrote:
> > Hey,
> >
> > When investigating the issue we had on Ubuntu Touch, described by bug
> > https://bugs.launchpad.net/ubuntu-rtm/+source/pulseaudio/+bug/1391230,
> > I noticed that PulseAudio never releases the resources used by an
> > active stream if the app gets a SIGSTOP, keeping pulse busy and
> > consuming cpu until the app resumes or is closed by the user.
> >
> > On Ubuntu Touch that happens when the application is active playing
> > audio/video, and the user moves back to the home scopes (Ubuntu Touch
> > lifecycle will automatically send a SIGSTOP after 5 seconds). When
> > checking that on my desktop, I also noticed that the same happens (by
> > forcing a SIGSTOP against mplayer, for example). Pulse only releases
> > the stream when the app pauses the stream, not necessarily when the
> > app stops after receiving the signal.
> >
> > I raised this first with David to understand if it was indeed a valid
> > use case, and he said that it was indeed something that it was
> > probably never really considered
> > (https://bugs.launchpad.net/ubuntu-rtm/+source/pulseaudio/+bug/1391230/comments/8).
> >
> > So before going and trying to deep dive and find a fix for the issue,
> > I first wanted to understand from you guys if this is indeed a valid
> > issue and what would be the best way to get this fixed. I know we're
> > still using Pulse 4.0 on Ubuntu, but wanted to make sure to get
> > something that would also be compatible with upstream.
>
> So when I discussed this with Ricardo, my suggestion was that we either
>
> 1) (ab)use the cork mechanism to stop/resume the client when we
> discover that the client is SIGSTOPped, or
This implies that we implement server-side corking, because currently
the cork status is controlled by the client, and this "stalled" corking
would be controlled by the server.
Even though I have mentioned the "server-side corking" feature before
(as something that we need and use in Tizen), I might not have explained
how I think it should be implemented (Tizen's current implementation is
less flexible than what I'd like). We should have a hashmap of "cork
requests" in sink inputs and source outputs. The stream would be corked
as long as the hashmap isn't empty, i.e. as long as someone thinks that
the stream should be corked. The hashmap keys would be strings
identifying the "corking reasons", so policy modules could easily add
new reasons. The normal client-initiated corking would be one corking
reason, and this stall detection would be another reason. Tizen's policy
module would implement a third reason.
> 2) introduce a new state for sink inputs and source outputs, like
> SINK_INPUT_STALLED or something.
>
> My gut feeling is that the second option is cleaner.
If we are going to expose the state to clients (it would be nice to see
the state with pactl), I'd prefer a separate boolean "stalled" variable.
I'm not confident that all existing applications would be able to cope
with a new value in the stream state enum.
> From PA's perspective, I think this is the same situation as if the
> client has hung, we keep on hoping that the client will come back the
> next millisecond, so we keep the sink/source open. In case of recording,
> we'll keep on buffering data until...I don't know what happens tbh.
> Probably the memblockq will start to complain after 64MB or so.
>
> Anyhow, this needs work on several levels to do properly. Some place,
> probably in the core, needs to detect that the client has hung by some
> timeout definition, and set sink state accordingly. But I'm not sure
> *where* in the core would be the place to detect this - probably the I/O
> thread should detect it, and notify the main thread? That would make it
> work across other protocols than the native protocol too.
I agree.
--
Tanu
More information about the pulseaudio-discuss
mailing list