[RFCv2 17/17] bluetooth: Postpone sink and source creation for BlueZ 5 HFP

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

 



On Mon, Apr 15, 2013 at 6:53 PM,  <jprvita at gmail.com> wrote:
> From: Jo?o Paulo Rechi Vita <jprvita at openbossa.org>
>
> CVSD and mSBC stream have different sample rates, and the CODEC of the
> Audio Connection is only on NewConnection(). Since the sample rate is
> needed to create the sink/source their creation is postponed to when the
> transport changes its state to 'playing'.

Ideally instead of postponing the sink/source creation what I want
here is to update their sample rate, otherwise I can't support (1)
subsequent calls with different sample rates and (2) HF-initiated call
transfer from the HF to the AG. For (1) a workaround would be
destroying the sink after the call ends (HUP on stream fd) but I
couldn't think of anything to cover (2).

I've played a bit with pa_sink_update_rate() but I always got a
message complaining that the attached monitor source was not idle,
even when the sink was idle. Can someone give me any help on that?

> ---
>  src/modules/bluetooth/module-bluetooth-device.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
> index 22880c6..1f5bcbc 100644
> --- a/src/modules/bluetooth/module-bluetooth-device.c
> +++ b/src/modules/bluetooth/module-bluetooth-device.c
> @@ -1579,6 +1579,11 @@ static pa_available_t get_port_availability(struct userdata *u, pa_direction_t d
>      return result;
>  }
>
> +static void bt_transport_config(struct userdata *u);
> +static int add_source(struct userdata *u);
> +static int add_sink(struct userdata *u);
> +static int start_thread(struct userdata *u);
> +
>  /* Run from main thread */
>  static void handle_transport_state_change(struct userdata *u, struct pa_bluetooth_transport *transport) {
>      bool acquire = false;
> @@ -1613,6 +1618,18 @@ static void handle_transport_state_change(struct userdata *u, struct pa_bluetoot
>
>      if (acquire)
>          if (bt_transport_acquire(u, true) >= 0) {
> +
> +            /* Create sink and source with the correct sample rate for PROFILE_HFGW && BLUEZ5 */
> +            if ((pa_bluetooth_discovery_get_bluez_version(u->discovery) == BLUEZ_VERSION_5) && profile == PROFILE_HFGW &&
> +                (!u->sink || !u->source)) {
> +
> +                bt_transport_config(u);
> +                add_sink(u);
> +                add_source(u);
> +                if (u->sink || u->source)
> +                    start_thread(u);
> +            }
> +
>              if (u->source) {
>                  pa_log_debug("Resuming source %s, because the bluetooth audio state changed to 'playing'.", u->source->name);
>                  pa_source_suspend(u->source, false, PA_SUSPEND_IDLE|PA_SUSPEND_USER);
> @@ -2194,13 +2211,13 @@ static int init_profile(struct userdata *u) {
>
>      if (u->profile == PROFILE_A2DP ||
>          u->profile == PROFILE_HSP ||
> -        u->profile == PROFILE_HFGW)
> +        (u->profile == PROFILE_HFGW && pa_bluetooth_discovery_get_bluez_version(u->discovery) == BLUEZ_VERSION_4))
>          if (add_sink(u) < 0)
>              r = -1;
>
>      if (u->profile == PROFILE_HSP ||
>          u->profile == PROFILE_A2DP_SOURCE ||
> -        u->profile == PROFILE_HFGW)
> +        (u->profile == PROFILE_HFGW && pa_bluetooth_discovery_get_bluez_version(u->discovery) == BLUEZ_VERSION_4))
>          if (add_source(u) < 0)
>              r = -1;
>
> --
> 1.7.11.7
>


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

  Powered by Linux