From 8569aed5570e415a2d4361c521c0b511684e3b7e Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 4 Feb 2009 09:39:57 -0800 Subject: Delay AVRCP connection when remote device connects A2DP The audio profile coexistence whitepaper recommends that the initiator of the A2DP connection also initiates the AVRCP connection. This patch adds a two second delay before we attempt connecting AVRCP after the remote device has connected A2DP to us. --- audio/device.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 6f59746d..a5cfc880 100644 --- a/audio/device.c +++ b/audio/device.c @@ -54,15 +54,54 @@ #include "headset.h" #include "sink.h" +#define CONTROL_CONNECT_TIMEOUT 2 + static void device_free(struct audio_device *dev) { if (dev->conn) dbus_connection_unref(dev->conn); + if (dev->control_timer) + g_source_remove(dev->control_timer); + g_free(dev->path); g_free(dev); } +static gboolean control_connect_timeout(gpointer user_data) +{ + struct audio_device *dev = user_data; + + dev->control_timer = 0; + + if (dev->control) + avrcp_connect(dev); + + return FALSE; +} + +gboolean device_set_control_timer(struct audio_device *dev) +{ + if (!dev->control) + return FALSE; + + if (dev->control_timer) + return FALSE; + + dev->control_timer = g_timeout_add_seconds(CONTROL_CONNECT_TIMEOUT, + control_connect_timeout, + dev); + + return TRUE; +} + +void device_remove_control_timer(struct audio_device *dev) +{ + if (dev->control_timer) + g_source_remove(dev->control_timer); + dev->control_timer = 0; +} + struct audio_device *audio_device_register(DBusConnection *conn, const char *path, const bdaddr_t *src, const bdaddr_t *dst) -- cgit