[pulseaudio-discuss] [PATCH 2/4] bluez 5: Load the native headset backend if the oFono one is unavailable
David Henningsson
david.henningsson at canonical.com
Fri Nov 7 03:39:39 PST 2014
On 2014-11-07 12:20, Luiz Augusto von Dentz wrote:
> Hi David,
>
> On Mon, Nov 3, 2014 at 1:38 PM, David Henningsson
> <david.henningsson at canonical.com> wrote:
>> This implements some autodetect if both headset backends are compiled in:
>> First we try to contact the oFono service, if that's not working,
>> then we start the native backend instead.
>>
>> Likewise if the oFono service is going offline/online, we load/unload
>> the native backend accordingly.
>>
>> Signed-off-by: David Henningsson <david.henningsson at canonical.com>
>> ---
>
> This might actually work
Sounds like a good start :-)
> but we just need to be careful once the
> native backend support listening on SCO that needs to use BDADDR_ANY
> (00:00:00:00:00:00) as address so it does not block oFono to register
> for HFP since it also needs to listen on SCO.
Hmm, okay. I wonder if there's any way around that, i e, if we can get
our native headset to give up SCO listening before oFono starts doing that?
Like, we have a device reservation protocol for speaking to the JACK
audio server, would something similar be useful here?
Also I'm thinking whether there could be a startup race here. Would the
ofono implementation try to autostart ofono via d-Bus? If so, there's
less of a problem. Otherwise, we might have a startup race between
PulseAudio and ofono, and if PulseAudio is first, it'll grab the SCO
listening resource before ofono?
Anyhow, worst case is still same as without the patch; you can always
compile without one of the headset backends.
Also, do I understand correctly that this probably won't be a problem
for 6.0 since the native headset backend does not support SCO listening yet?
>
>> src/modules/bluetooth/backend-ofono.c | 26 +++++++++++++++-----------
>> src/modules/bluetooth/bluez5-util.c | 12 ++++++++++++
>> src/modules/bluetooth/bluez5-util.h | 1 +
>> 3 files changed, 28 insertions(+), 11 deletions(-)
>>
>> diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
>> index 797d35c..1f0c80f 100644
>> --- a/src/modules/bluetooth/backend-ofono.c
>> +++ b/src/modules/bluetooth/backend-ofono.c
>> @@ -336,6 +336,16 @@ static void hf_audio_agent_get_cards(pa_bluetooth_backend *hf) {
>> hf_dbus_send_and_add_to_pending(hf, m, hf_audio_agent_get_cards_reply, NULL);
>> }
>>
>> +static void ofono_bus_id_destroy(pa_bluetooth_backend *backend) {
>> + pa_hashmap_remove_all(backend->cards);
>> +
>> + if (backend->ofono_bus_id) {
>> + pa_xfree(backend->ofono_bus_id);
>> + backend->ofono_bus_id = NULL;
>> + pa_bluetooth_discovery_set_ofono_running(backend->discovery, false);
>> + }
>> +}
>> +
>> static void hf_audio_agent_register_reply(DBusPendingCall *pending, void *userdata) {
>> DBusMessage *r;
>> pa_dbus_pending *p;
>> @@ -360,6 +370,8 @@ finish:
>>
>> PA_LLIST_REMOVE(pa_dbus_pending, backend->pending, p);
>> pa_dbus_pending_free(p);
>> +
>> + pa_bluetooth_discovery_set_ofono_running(backend->discovery, backend->ofono_bus_id != NULL);
>> }
>>
>> static void hf_audio_agent_register(pa_bluetooth_backend *hf) {
>> @@ -393,8 +405,7 @@ static void hf_audio_agent_unregister(pa_bluetooth_backend *backend) {
>> pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID));
>> pa_assert_se(dbus_connection_send(pa_dbus_connection_get(backend->connection), m, NULL));
>>
>> - pa_xfree(backend->ofono_bus_id);
>> - backend->ofono_bus_id = NULL;
>> + ofono_bus_id_destroy(backend);
>> }
>> }
>>
>> @@ -429,11 +440,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da
>>
>> if (old_owner && *old_owner) {
>> pa_log_debug("oFono disappeared");
>> -
>> - pa_hashmap_remove_all(backend->cards);
>> -
>> - pa_xfree(backend->ofono_bus_id);
>> - backend->ofono_bus_id = NULL;
>> + ofono_bus_id_destroy(backend);
>> }
>>
>> if (new_owner && *new_owner) {
>> @@ -490,10 +497,7 @@ static DBusMessage *hf_audio_agent_release(DBusConnection *c, DBusMessage *m, vo
>>
>> pa_log_debug("HF audio agent has been unregistered by oFono (%s)", backend->ofono_bus_id);
>>
>> - pa_hashmap_remove_all(backend->cards);
>> -
>> - pa_xfree(backend->ofono_bus_id);
>> - backend->ofono_bus_id = NULL;
>> + ofono_bus_id_destroy(backend);
>>
>> pa_assert_se(r = dbus_message_new_method_return(m));
>>
>> diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
>> index f7bf654..4121b76 100644
>> --- a/src/modules/bluetooth/bluez5-util.c
>> +++ b/src/modules/bluetooth/bluez5-util.c
>> @@ -861,6 +861,18 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa
>> return;
>> }
>>
>> +void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running) {
>> + pa_assert(y);
>> +
>> + pa_log_debug("oFono is running: %s", pa_yes_no(is_running));
>> + if (is_running && y->native_backend) {
>> + pa_bluetooth_native_backend_free(y->native_backend);
>> + y->native_backend = NULL;
>> + }
>> + else if (!is_running && !y->native_backend)
>> + y->native_backend = pa_bluetooth_native_backend_new(y->core, y);
>> +}
>> +
>> static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata) {
>> pa_dbus_pending *p;
>> pa_bluetooth_discovery *y;
>> diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
>> index d1abd39..21f56b2 100644
>> --- a/src/modules/bluetooth/bluez5-util.h
>> +++ b/src/modules/bluetooth/bluez5-util.h
>> @@ -157,4 +157,5 @@ const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
>> pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
>> pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
>> void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
>> +void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running);
>> #endif
>> --
>> 1.9.1
>>
>
>
>
--
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
More information about the pulseaudio-discuss
mailing list