[PATCH] bluetooth: Add support for automatic switch between hsp and a2dp profiles

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 24 September 2014 21:36:50 Alexander E. Patrakov wrote:
> 24.09.2014 23:08, Pali Roh?r wrote:
> > With this patch module-bluetooth-policy automatically switch
> > from a2dp profile to hsp profile if some application want
> > to start recording.
> > 
> > By default a2dp profile is used for listening music, but for
> > VOIP calls is needed profile with microphone support (hsp).
> > So this patch will switch to hsp profile if some
> > application want to use microphone and after it release it
> > profile is switched back to a2dp. So this patch allows to
> > use bluetooth microphone automatically without need of user
> > interaction.
> 
> Summary from IRC:
> 
> This module switches the headset to the hsp profile when any
> application starts recording anything, except pavucontrol.
> While the need for ignoring pavucontrol is valid, the test
> should likely not be done via PA_PROP_APPLICATION_ID.
> 
> Unfortunately, I cannot suggest an exhaustive list of source
> outputs that should be ignored. The following candidates to
> ignore have been suggested so far:
> 
>   * pavucontrol (obviously), both when it is recording from
> the microphone and when it is recording from the monitor
> source
>   * all desktop-specific equivalents of pavucontrol -
> e.g. mate-volume-control. Maybe we can figure them out by
> resampler == peaks?
>   * anything that records from any monitor
> source
>   * virtual streams, like the one from module-echo-cancel, as
> long as nothing records from the corresponding virtual
> sources
> 

Pavucontrol always hides all streams which application name is
pavucontrol (via PA_PROP_APPLICATION_ID).

Then pavucontrol can show/hide virtual streams (depends on select
box). Pavucontrol mark source output as virtual stream if no
client is assigned to stream.

It looks like all desktop volume controllers which show progress
bar from microphone output using peaks resampler (also
pavucontrol).

So I'm sending small patch which modify code for ignoring
streams. It ignores all output streams without assigned client
(eg. module-loopback or module-echo-cancel) and all output
streams with resampler peaks (so applications pavucontrol, and
others).

diff --git a/src/modules/bluetooth/module-bluetooth-policy.c b/src/modules/bluetooth/module-bluetooth-
policy.c
index c98f372..dc3db78 100644
--- a/src/modules/bluetooth/module-bluetooth-policy.c
+++ b/src/modules/bluetooth/module-bluetooth-policy.c
@@ -207,13 +207,13 @@ static void switch_profile(pa_card *card, bool revert) {
     }
 }
 
-/* Return true if source output is pavucontrol peak */
-static bool is_pc_peak(pa_source_output *source_output) {
-    const char *s = pa_proplist_gets(source_output->proplist, PA_PROP_APPLICATION_ID);
-    if (!s || !pa_streq(s, "org.PulseAudio.pavucontrol"))
-        return false;
-    else
+/* Return true if we should ignore this source output (is virtual or using peaks resample method) */
+static bool ignore_output(pa_source_output *source_output) {
+    if (pa_source_output_get_resample_method(source_output) == PA_RESAMPLER_PEAKS)
         return true;
+    if (!source_output->client)
+        return true;
+    return false;
 }
 
 static unsigned source_output_count(pa_core *c) {
@@ -222,7 +222,7 @@ static unsigned source_output_count(pa_core *c) {
     unsigned count = 0;
 
     PA_IDXSET_FOREACH(source_output, c->source_outputs, idx)
-        if (!is_pc_peak(source_output))
+        if (!ignore_output(source_output))
             ++count;
 
     return count;
@@ -242,8 +242,7 @@ static pa_hook_result_t source_output_put_hook_callback(pa_core *c, pa_source_ou
     pa_assert(c);
     pa_assert(source_output);
 
-    /* Ignore pavucontrol */
-    if (is_pc_peak(source_output))
+    if (ignore_output(source_output))
         return PA_HOOK_OK;
 
     switch_profile_all(c->cards, false);
@@ -255,8 +254,7 @@ static pa_hook_result_t source_output_unlink_hook_callback(pa_core *c, pa_source
     pa_assert(c);
     pa_assert(source_output);
 
-    /* Ignore pavucontrol */
-    if (is_pc_peak(source_output))
+    if (ignore_output(source_output))
         return PA_HOOK_OK;
 
     /* If there are still some source outputs do nothing (count is with *this* source_output, so +1) 
*/


-- 
Pali Roh?r
pali.rohar at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20140925/f8dc9c44/attachment.sig>


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux