[pulseaudio-discuss] [RFCv3 03/20] bluetooth: Register Handsfree Audio Agent with oFono

jprvita at gmail.com jprvita at gmail.com
Sun Apr 21 20:07:33 PDT 2013


From: João Paulo Rechi Vita <jprvita at openbossa.org>

---
 src/modules/bluetooth/bluetooth-util.c | 56 ++++++++++++++++++++++++++++++++--
 src/modules/bluetooth/bluetooth-util.h |  2 ++
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index b97841d..aca170f 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -116,12 +116,16 @@ struct pa_bluetooth_discovery {
     pa_core *core;
     pa_dbus_connection *connection;
     PA_LLIST_HEAD(pa_dbus_pending, pending);
+    bool filter_added;
+
     pa_bluez_version_t version;
     bool adapters_listed;
     pa_hashmap *devices;
     pa_hashmap *transports;
     pa_hook hooks[PA_BLUETOOTH_HOOK_MAX];
-    bool filter_added;
+
+    char *ofono_bus_id;
+    pa_hashmap *hf_cards;
 };
 
 static void get_properties_reply(DBusPendingCall *pending, void *userdata);
@@ -1125,6 +1129,51 @@ static void init_bluez(pa_bluetooth_discovery *y) {
     send_and_add_to_pending(y, m, get_managed_objects_reply, NULL);
 }
 
+static void hfagent_register_reply(DBusPendingCall *pending, void *userdata) {
+    DBusMessage *r;
+    pa_dbus_pending *p;
+    pa_bluetooth_discovery *y;
+
+    pa_assert_se(p = userdata);
+    pa_assert_se(y = p->context_data);
+    pa_assert_se(r = dbus_pending_call_steal_reply(pending));
+
+    if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
+        pa_log_error("Failed to register as a handsfree audio agent with ofono: %s: %s",
+                     dbus_message_get_error_name(r), pa_dbus_get_error_message(r));
+        goto finish;
+    }
+
+    y->ofono_bus_id = pa_xstrdup(dbus_message_get_sender(r));
+    y->hf_cards = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+
+finish:
+    dbus_message_unref(r);
+
+    PA_LLIST_REMOVE(pa_dbus_pending, y->pending, p);
+    pa_dbus_pending_free(p);
+}
+
+static void ofono_init(pa_bluetooth_discovery *y) {
+    DBusMessage *m;
+    unsigned char codecs[2];
+    const unsigned char *pcodecs = codecs;
+    int ncodecs = 0;
+    const char *path = HFP_AUDIO_AGENT_PATH;
+
+    pa_assert(y);
+
+    pa_assert_se(m = dbus_message_new_method_call("org.ofono", "/", "org.ofono.HandsfreeAudioManager", "Register"));
+
+    codecs[ncodecs++] = HFP_AUDIO_CODEC_CVSD;
+
+    pa_assert_se(dbus_message_append_args(m,
+                                          DBUS_TYPE_OBJECT_PATH, &path,
+                                          DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &pcodecs, ncodecs,
+                                          DBUS_TYPE_INVALID));
+    send_and_add_to_pending(y, m, hfagent_register_reply, NULL);
+}
+
 static int transport_parse_property(pa_bluetooth_transport *t, DBusMessageIter *i) {
     const char *key;
     DBusMessageIter variant_i;
@@ -1348,8 +1397,10 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
             if (old_owner && *old_owner)
                 pa_log_debug("oFono disappeared");
 
-            if (new_owner && *new_owner)
+            if (new_owner && *new_owner) {
                 pa_log_debug("oFono appeared");
+                ofono_init(y);
+            }
         }
 
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -2220,6 +2271,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
     pa_assert_se(dbus_connection_register_object_path(conn, HFP_AUDIO_AGENT_PATH, &vt, y));
 
     init_bluez(y);
+    ofono_init(y);
 
     return y;
 
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index 3361b0f..949521f 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -38,6 +38,8 @@
 #define HFP_HS_UUID             "0000111e-0000-1000-8000-00805f9b34fb"
 #define HFP_AG_UUID             "0000111f-0000-1000-8000-00805f9b34fb"
 
+#define HFP_AUDIO_CODEC_CVSD    0x01
+
 #define ADVANCED_AUDIO_UUID     "0000110d-0000-1000-8000-00805f9b34fb"
 
 #define A2DP_SOURCE_UUID        "0000110a-0000-1000-8000-00805f9b34fb"
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list