[pulseaudio-discuss] [RFC 06/24] bluetooth: Register Handsfree Audio Agent with oFono
jprvita at gmail.com
jprvita at gmail.com
Tue Mar 26 22:16:45 PDT 2013
From: João Paulo Rechi Vita <jprvita at openbossa.org>
---
src/modules/bluetooth/bluetooth-util.c | 55 +++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 84e0760..38bf58c 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,53 @@ 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"));
+
+ /* TODO: check available CODECs */
+ codecs[ncodecs++] = 1; /* HFP_AUDIO_CVSD */
+ codecs[ncodecs++] = 2; /* HFP_AUDIO_MSBC */
+
+ 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;
@@ -1351,6 +1402,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
if (new_owner && *new_owner) {
pa_log_debug("oFono appeared");
+ ofono_init(y);
}
}
@@ -2222,6 +2274,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;
--
1.7.11.7
More information about the pulseaudio-discuss
mailing list