Bug 57167 - module-bluetooth-device unsuspends sinks and sources unreliably
Summary: module-bluetooth-device unsuspends sinks and sources unreliably
Status: RESOLVED MOVED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: modules (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-15 19:31 UTC by Tanu Kaskinen
Modified: 2018-07-30 10:19 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tanu Kaskinen 2012-11-15 19:31:15 UTC
In module-bluetooth-device.c in filter_cb() there's this piece of code:

    if (acquire)
        if (bt_transport_acquire(u, FALSE) >= 0) {
            if (u->source)
                pa_source_suspend(u->source, FALSE, PA_SUSPEND_IDLE|PA_SUSPEND_USER);

            if (u->sink)
                pa_sink_suspend(u->sink, FALSE, PA_SUSPEND_IDLE|PA_SUSPEND_USER);
        }

The acquire variable is set to true if the bluetooth audio state changed to "playing". This can happen without pulseaudio requesting it, so if we want to have strict equivalence "sink/source suspended" == "audio state is 'playing'" (and I think we want that), then it makes sense that module-bluetooth-device unsuspends the sink/source. The problem here is that there's no clean "force unsuspend" mechanism in pulseaudio. pa_sink_suspend(u->sink, FALSE, PA_SUSPEND_IDLE|PA_SUSPEND_USER) may not actually unsuspend the sink, because there are also other suspend reasons than just IDLE and USER. So, depending on the situation, the sink may or may not get unsuspended.

module-bluetooth-device could list all possible reasons in the pa_sink_suspend() call, but that would be ugly. When adding new suspend reasons, it would be very easy to forget to update the pa_sink_suspend() call in module-bluetooth-device, and besides, if those suspend reasons are originally set by some other code, the original reasons to suspend don't really disappear when module-bluetooth-device unsuspends the sink, the old reasons are just overridden.

I think there should be a function for forcing unsuspending. The semantics would be such that the sink gets unsuspended regardless of any standing suspend reasons, but all standing suspend reasons would be remembered, and once a new suspend request would be made, the forced unsuspend would cease to have effect, the sink would suspend and things would return to normal.

A related thing is that I would like to replace the single suspend reason bitfield in pa_sink with an individual suspend request object for each suspend request. The single suspend reason bitfield is prone to conflicts if multiple places use the same reason (for example, module-bluetooth-device uses the USER reason which is also used for other purposes).
Comment 1 Tanu Kaskinen 2012-11-15 20:44:28 UTC
(In reply to comment #0)
> The problem here is that
> there's no clean "force unsuspend" mechanism in pulseaudio.
> pa_sink_suspend(u->sink, FALSE, PA_SUSPEND_IDLE|PA_SUSPEND_USER) may not
> actually unsuspend the sink, because there are also other suspend reasons
> than just IDLE and USER. So, depending on the situation, the sink may or may
> not get unsuspended.
> 
> module-bluetooth-device could list all possible reasons in the
> pa_sink_suspend() call, but that would be ugly. When adding new suspend
> reasons, it would be very easy to forget to update the pa_sink_suspend()
> call in module-bluetooth-device, and besides, if those suspend reasons are
> originally set by some other code, the original reasons to suspend don't
> really disappear when module-bluetooth-device unsuspends the sink, the old
> reasons are just overridden.

Correction: there is the PA_SUSPEND_ALL suspend cause. That looks like a good simple solution to this bug, even though it doesn't solve all the described problems. But at least it will reliably unsuspend the sink.
Comment 2 GitLab Migration User 2018-07-30 10:19:12 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/340.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.