<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - module-bluetooth-device unsuspends sinks and sources unreliably"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=57167">57167</a>
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>lennart@poettering.net
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>pulseaudio-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>module-bluetooth-device unsuspends sinks and sources unreliably
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>pulseaudio-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tanuk@iki.fi
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>modules
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>PulseAudio
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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).</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>