android/AVRCP: Add bt_avrcp_connect
Luiz Augusto von Dentz
maintainerPATCH 1/4 android/AVRCP: Add bt_avrcp_connect
From: Luiz Augusto von Dentz <[email protected]>
This adds bt_avrcp_connect function which can be used to request AVRCP connections.
--- android/avrcp.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- android/avrcp.h | 2 ++ 2 files changed, 57 insertions(+), 5 deletions(-)
android/avrcp.c +55 -5
@@ -54,6 +54,7 @@ static GIOChannel *server = NULL;struct avrcp_device {bdaddr_t dst;struct avctp *session; +GIOChannel *io; };static const struct ipc_handler cmd_handlers[] = {
@@ -197,17 +198,20 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data) }ba2str (&dst, address); -DBG ("Incoming connection from %s" , address); l =g_slist_find_custom (devices, &dst, device_cmp);if (l) { -error ("Unexpected connection" ); -return ; + dev = l->data; +if (dev->session) { +error ("Unexpected connection" ); +return ; + } + }else { +DBG ("Incoming connection from %s" , address); + dev =avrcp_device_new (&dst); } fd =g_io_channel_unix_get_fd (chan); - - dev =avrcp_device_new (&dst); dev->session =avctp_new (fd, imtu, omtu,0x0100 );if (!dev->session) {
@@ -222,6 +226,11 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)g_io_channel_set_close_on_unref (chan, FALSE); +if (dev->io) { +g_io_channel_unref (dev->io); + dev->io =NULL ; + } +DBG ("%s connected" , address); }
@@ -288,3 +297,44 @@ void bt_avrcp_unregister(void) server =NULL ; } } + +static bool avrcp_device_connect (struct avrcp_device *dev,BtIOConnect cb) +{ +GError *err =NULL ; + + dev->io =bt_io_connect (cb, dev,NULL , &err, +BT_IO_OPT_SOURCE_BDADDR , &adapter_addr, +BT_IO_OPT_DEST_BDADDR , &dev->dst, +BT_IO_OPT_PSM ,L2CAP_PSM_AVCTP , +BT_IO_OPT_SEC_LEVEL ,BT_IO_SEC_MEDIUM , +BT_IO_OPT_INVALID ); +if (err) { +error ("%s" , err->message); +g_error_free (err); +return false; + } + +return true; +} + +void bt_avrcp_connect (const bdaddr_t *dst) +{ +struct avrcp_device *dev; +char addr[18 ]; +GSList *l; + +DBG ("" ); + + l =g_slist_find_custom (devices, dst, device_cmp); +if (l) +return ; + + dev =avrcp_device_new (dst); +if (!avrcp_device_connect (dev, connect_cb)) { +avrcp_device_free (dev); +return ; + } + +ba2str (&dev->dst, addr); +DBG ("connecting to %s" , addr); +}
android/avrcp.h +2 -0
@@ -23,3 +23,5 @@bool bt_avrcp_register (const bdaddr_t *addr);void bt_avrcp_unregister (void ); + +void bt_avrcp_connect (const bdaddr_t *dst);
Signature · 1 line
1.8.5.3
Luiz Augusto von Dentz
maintainerPATCH 2/4 android/AVRCP: Add bt_avrcp_disconnect
From: Luiz Augusto von Dentz <[email protected]>
This adds bt_avrcp_disconnect function which can be used to disconnect AVRCP sessions.
--- android/avrcp.c | 26 ++++++++++++++++++++++++++ android/avrcp.h | 1 + 2 files changed, 27 insertions(+)
android/avrcp.c +26 -0
@@ -135,6 +135,11 @@ static void avrcp_device_free(void *data)if (dev->session)avctp_shutdown (dev->session); +if (dev->io) { +g_io_channel_shutdown (dev->io, FALSE,NULL ); +g_io_channel_unref (dev->io); + } + devices =g_slist_remove (devices, dev);g_free (dev); }
@@ -338,3 +343,24 @@ void bt_avrcp_connect(const bdaddr_t *dst)ba2str (&dev->dst, addr);DBG ("connecting to %s" , addr); } + +void bt_avrcp_disconnect (const bdaddr_t *dst) +{ +struct avrcp_device *dev; +GSList *l; + +DBG ("" ); + + l =g_slist_find_custom (devices, dst, device_cmp); +if (!l) +return ; + + dev = l->data; + +if (dev->session) { +avctp_shutdown (dev->session); +return ; + } + +avrcp_device_free (dev); +}
android/avrcp.h +1 -0
@@ -25,3 +25,4 @@ bool bt_avrcp_register(const bdaddr_t *addr);void bt_avrcp_unregister (void );void bt_avrcp_connect (const bdaddr_t *dst); +void bt_avrcp_disconnect (const bdaddr_t *dst);
Signature · 1 line
1.8.5.3
Luiz Augusto von Dentz
maintainerPATCH 3/4 android: Connect AVRCP once A2DP is connected
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
In case of being the initiator of the A2DP connection also attempt to connect AVRCP.
--- android/a2dp.c | 2 ++ 1 file changed, 2 insertions(+)
android/a2dp.c +2 -0
@@ -45,6 +45,7 @@#include "utils.h" #include "bluetooth.h" #include "avdtp.h" +#include "avrcp.h" #include "audio-msg.h" #include "audio-ipc.h"
@@ -544,6 +545,7 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err,error ("avdtp_discover: %s" ,strerror (-perr)); goto failed; } +bt_avrcp_connect (&dev->dst); }else /* Init idle timeout to discover */ dev->idle_id =g_timeout_add_seconds (IDLE_TIMEOUT , idle_timeout, dev);
Signature · 1 line
1.8.5.3
Luiz Augusto von Dentz
maintainerPATCH 4/4 android: Disconnect AVRCP once A2DP is disconnected
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
If A2DP is disconnected also disconnect AVRCP.
--- android/a2dp.c | 2 ++ 1 file changed, 2 insertions(+)
android/a2dp.c +2 -0
@@ -227,6 +227,8 @@ static void bt_a2dp_notify_state(struct a2dp_device *dev, uint8_t state)if (state !=HAL_A2DP_STATE_DISCONNECTED )return ; +bt_avrcp_disconnect (&dev->dst); +a2dp_device_free (dev); }
Signature · 1 line
1.8.5.3
Hi Luiz,
Quoted 110 lines · On Wednesday 05 of February 2014 12:26:57 Luiz Augusto von Dentz wrote:
From: Luiz Augusto von Dentz <[email protected]>
This adds
bt_avrcp_connectfunction which can be used to request AVRCP connections.--- android/avrcp.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- android/avrcp.h | 2 ++ 2 files changed, 57 insertions(+), 5 deletions(-)android/avrcp.c +55
-5@@ -54,6 +54,7 @@ static GIOChannel *server = NULL;struct avrcp_device {bdaddr_t dst;struct avctp *session; +GIOChannel *io; };static const struct ipc_handler cmd_handlers[] = {@@ -197,17 +198,20 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data) }ba2str (&dst, address); -DBG ("Incoming connection from %s" , address); l =g_slist_find_custom (devices, &dst, device_cmp);if (l) { -error ("Unexpected connection" ); -return ; + dev = l->data; +if (dev->session) { +error ("Unexpected connection" ); +return ; + } + }else { +DBG ("Incoming connection from %s" , address); + dev =avrcp_device_new (&dst); } fd =g_io_channel_unix_get_fd (chan); - - dev =avrcp_device_new (&dst); dev->session =avctp_new (fd, imtu, omtu,0x0100 );if (!dev->session) {@@ -222,6 +226,11 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)g_io_channel_set_close_on_unref (chan, FALSE); +if (dev->io) { +g_io_channel_unref (dev->io); + dev->io =NULL ; + } +DBG ("%s connected" , address); }@@ -288,3 +297,44 @@ void bt_avrcp_unregister(void) server =NULL ; } } + +static bool avrcp_device_connect (struct avrcp_device *dev,BtIOConnect cb) +{ +GError *err =NULL ; + + dev->io =bt_io_connect (cb, dev,NULL , &err, +BT_IO_OPT_SOURCE_BDADDR , &adapter_addr, +BT_IO_OPT_DEST_BDADDR , &dev->dst, +BT_IO_OPT_PSM ,L2CAP_PSM_AVCTP , +BT_IO_OPT_SEC_LEVEL ,BT_IO_SEC_MEDIUM , +BT_IO_OPT_INVALID ); +if (err) { +error ("%s" , err->message); +g_error_free (err); +return false; + } + +return true; +} + +void bt_avrcp_connect (const bdaddr_t *dst) +{ +struct avrcp_device *dev; +char addr[18 ]; +GSList *l; + +DBG ("" ); + + l =g_slist_find_custom (devices, dst, device_cmp); +if (l) +return ; + + dev =avrcp_device_new (dst); +if (!avrcp_device_connect (dev, connect_cb)) { +avrcp_device_free (dev); +return ; + } + +ba2str (&dev->dst, addr); +DBG ("connecting to %s" , addr); +}android/avrcp.h +0
-0
android/avrcp.h line 27
Quoted 5 lines
android/avrcp.h +2
-0@@ -23,3 +23,5 @@bool bt_avrcp_register (const bdaddr_t *addr);void bt_avrcp_unregister (void ); + +void bt_avrcp_connect (const bdaddr_t *dst);
All four patches applied, thanks.
Signature · 2 lines
Best regards, Szymon Janc