Refactoring profiles/audio code
v3 cover Refactoring profiles/audio code
From: Andrei Emeltchenko <[email protected]>
Refactoring code so that avdtp library can be easily reused inside profiles/
Andrei Emeltchenko (9):
android/avdtp: Refactor local SEP list handling unit/avdtp: Refactor context destroy
android/avdtp: Remove extra check
audio/avdtp: Use bitfield id generation
audio/avdtp: Refactor avdtp and a2dp code audio/avdtp: Replace GSList with queue for SEP list
audi: Refactor avdtp_get function
audio/avdtp: Move avdtp_server from avdtp SEP structures audio/avdtp: Use SEP queue instead of avdtp_server in avdtp code
android/Android.mk | 1 + android/Makefile.am | 1 + android/a2dp.c | 18 ++- android/avdtp.c | 91 +++++++++------ android/avdtp.h | 8 +- android/avdtptest.c | 10 +- profiles/audio/a2dp.c | 181 ++++++++++++++++++++++++++++- profiles/audio/a2dp.h | 1 + profiles/audio/avdtp.c | 283 +++++++++++++-------------------------------- profiles/audio/avdtp.h | 19 ++- profiles/audio/media.c | 1 + profiles/audio/sink.c | 3 +- profiles/audio/source.c | 3 +- profiles/audio/transport.c | 3 +- unit/test-avdtp.c | 117 ++++++++++--------- 15 files changed, 421 insertions(+), 319 deletions(-)
Signature · 1 line
2.1.0
RFC v3 1/9 android/avdtp: Refactor local SEP list handling
From: Andrei Emeltchenko <[email protected]>
In order to deduplicate similar code in android/ and profiles/ we need to handle local SEP queue outside of avdtp.c. GSList is transformed to queue.
--- android/Android.mk | 1 + android/Makefile.am | 1 + android/a2dp.c | 18 +++++++--- android/avdtp.c | 90 ++++++++++++++++++++++++++++++-------------------- android/avdtp.h | 8 +++-- android/avdtptest.c | 10 ++++-- unit/test-avdtp.c | 95 ++++++++++++++++++++++++++++++----------------------- 7 files changed, 137 insertions(+), 86 deletions(-)
android/Android.mk +1 -0
@@ -262,6 +262,7 @@ LOCAL_SRC_FILES := \ bluez/lib/bluetooth.c \ bluez/lib/hci.c \ bluez/src/shared/util.c \ + bluez/src/shared/queue.c \ LOCAL_C_INCLUDES += \ $(LOCAL_PATH)/bluez \
android/Makefile.am +1 -0
@@ -103,6 +103,7 @@ android_avdtptest_SOURCES = android/avdtptest.c \ src/log.h src/log.c \ btio/btio.h btio/btio.c \ src/shared/util.h src/shared/util.c \ + src/shared/queue.h src/shared/queue.c \ android/avdtp.h android/avdtp.c android_avdtptest_CFLAGS = $(AM_CFLAGS) android_avdtptest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
android/a2dp.c +14 -4
@@ -38,6 +38,7 @@#include "lib/sdp.h" #include "lib/sdp_lib.h" #include "profiles/audio/a2dp-codecs.h" +#include "src/shared/queue.h" #include "src/log.h" #include "hal-msg.h" #include "ipc-common.h"
@@ -65,6 +66,8 @@ static bool audio_retrying = false;static struct ipc *hal_ipc =NULL ;static struct ipc *audio_ipc =NULL ; +static struct queue *lseps =NULL ; +struct a2dp_preset {void *data;int8_t len;
@@ -115,7 +118,7 @@ static void unregister_endpoint(void *data)struct a2dp_endpoint *endpoint = data;if (endpoint->sep) -avdtp_unregister_sep (endpoint->sep); +avdtp_unregister_sep (lseps, endpoint->sep);if (endpoint->caps)preset_free (endpoint->caps);
@@ -620,6 +623,7 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err, gpointer user_data) {struct a2dp_device *dev = user_data; +struct avdtp *session;uint16_t imtu, omtu;GError *gerr =NULL ;int fd;
@@ -643,10 +647,12 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err, fd =g_io_channel_unix_get_fd (chan);/* FIXME: Add proper version */ - dev->session =avdtp_new (fd, imtu, omtu,0x0100 ); -if (!dev->session) + session =avdtp_new (fd, imtu, omtu,0x0100 , lseps); +if (!session) goto failed; + dev->session = session; +avdtp_add_disconnect_cb (dev->session, disconnect_cb, dev);/* Proceed to stream setup if initiator */
@@ -1327,7 +1333,7 @@ static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec, endpoint = g_new0(struct a2dp_endpoint, 1); endpoint->id =g_slist_length (endpoints) +1 ; endpoint->codec = codec; - endpoint->sep =avdtp_register_sep (AVDTP_SEP_TYPE_SOURCE , + endpoint->sep =avdtp_register_sep (lseps,AVDTP_SEP_TYPE_SOURCE ,AVDTP_MEDIA_TYPE_AUDIO , codec, FALSE, &sep_ind, &sep_cfm, endpoint);
@@ -1624,6 +1630,8 @@ static void bt_audio_unregister(void)ipc_cleanup (audio_ipc); audio_ipc =NULL ; + +queue_destroy (lseps,NULL ); }static bool bt_audio_register (ipc_disconnect_cb disconnect)
@@ -1691,6 +1699,8 @@ bool bt_a2dp_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)bacpy (&adapter_addr, addr); + lseps =queue_new (); + server = bt_io_listen(connect_cb, NULL, NULL, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, &adapter_addr, BT_IO_OPT_PSM, AVDTP_PSM,
android/avdtp.c +54 -36
246 lines not on this page · raw message
android/avdtp.h +5 -3
@@ -205,7 +205,8 @@ typedef void (*avdtp_discover_cb_t) (struct avdtp *session, GSList *seps, struct avdtp_error *err, void *user_data);typedef void (*avdtp_disconnect_cb_t ) (void *user_data); -struct avdtp *avdtp_new (int fd,size_t imtu,size_t omtu,uint16_t version); +struct avdtp *avdtp_new (int fd,size_t imtu,size_t omtu,uint16_t version, +struct queue *lseps); unsigned int avdtp_add_disconnect_cb(struct avdtp *session, avdtp_disconnect_cb_t cb,
@@ -265,7 +266,8 @@ int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);int avdtp_delay_report (struct avdtp *session,struct avdtp_stream *stream,uint16_t delay); -struct avdtp_local_sep *avdtp_register_sep(uint8_t type, uint8_t media_type, +struct avdtp_local_sep *avdtp_register_sep(struct queue *lseps, uint8_t type, + uint8_t media_type, uint8_t codec_type, gboolean delay_reporting, struct avdtp_sep_ind *ind,
@@ -278,7 +280,7 @@ void avdtp_sep_set_vendor_codec(struct avdtp_local_sep *sep, uint32_t vendor_id,struct avdtp_remote_sep *avdtp_find_remote_sep (struct avdtp *session,struct avdtp_local_sep *lsep); -int avdtp_unregister_sep (struct avdtp_local_sep *sep); +int avdtp_unregister_sep (struct queue *lseps,struct avdtp_local_sep *sep);avdtp_state_t avdtp_sep_get_state (struct avdtp_local_sep *sep);
android/avdtptest.c +8 -2
@@ -40,6 +40,7 @@#include "src/shared/util.h" #include "btio/btio.h" +#include "src/shared/queue.h" #include "avdtp.h" static GMainLoop *mainloop =NULL ;
@@ -57,6 +58,7 @@ static uint16_t version = 0x0103;static guint media_player =0 ;static guint media_recorder =0 ;static guint idle_id =0 ; +static struct queue *lseps =NULL ;static bool fragment = false;
@@ -411,7 +413,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)return ; } - avdtp =avdtp_new (fd, imtu, omtu, version); + avdtp =avdtp_new (fd, imtu, omtu, version, lseps);if (!avdtp) {printf ("Failed to create avdtp instance\n" );g_main_loop_quit (mainloop);
@@ -864,13 +866,15 @@ int main(int argc, char *argv[]) } } - local_sep =avdtp_register_sep (dev_role,AVDTP_MEDIA_TYPE_AUDIO , + local_sep =avdtp_register_sep (lseps, dev_role,AVDTP_MEDIA_TYPE_AUDIO ,0x00 , TRUE, &sep_ind, &sep_cfm,NULL );if (!local_sep) {printf ("Failed to register sep\n" );exit (0 ); } +queue_push_tail (lseps, local_sep); +if (!bacmp (&dst,BDADDR_ANY )) {printf ("Listening...\n" ); io =do_listen (&err);
@@ -889,6 +893,8 @@ int main(int argc, char *argv[])printf ("Done\n" ); +queue_destroy (lseps,NULL ); +avdtp_unref (avdtp); avdtp =NULL ;
unit/test-avdtp.c +54 -41
253 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC v3 2/9 unit/avdtp: Refactor context destroy
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
destroy_context() function will be used for dummy_tests without context_execute()
--- unit/test-avdtp.c | 58 +++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-)
unit/test-avdtp.c +22 -36
@@ -264,10 +264,16 @@ static struct context *create_context(uint16_t version, gconstpointer data)return context_new (version,672 ,672 , data); } -static void execute_context (struct context *context) +static void unregister_sep (void *data) { -g_main_loop_run (context->main_loop); +struct avdtp_local_sep *sep = data; + +/* Removed from the queue by caller */ +avdtp_unregister_sep (NULL , sep); +} +static void destroy_context (struct context *context) +{if (context->source >0 )g_source_remove (context->source);avdtp_unref (context->session);
@@ -275,9 +281,18 @@ static void execute_context(struct context *context)g_main_loop_unref (context->main_loop);test_free (context->data); +queue_destroy (context->lseps, unregister_sep); +g_free (context); } +static void execute_context (struct context *context) +{ +g_main_loop_run (context->main_loop); + +destroy_context (context); +} + static gboolean sep_getcap_ind(struct avdtp *session, struct avdtp_local_sep *sep, GSList **caps, uint8_t *err,
@@ -513,13 +528,11 @@ static void test_server(gconstpointer data)AVDTP_MEDIA_TYPE_AUDIO ,0x00 , FALSE, &sep_ind, &sep_cfm, context); +g_assert (sep);g_idle_add (send_pdu, context);execute_context (context); - -avdtp_unregister_sep (context->lseps, sep); -queue_destroy (context->lseps,NULL ); }static void test_server_1_3 (gconstpointer data)
@@ -530,13 +543,11 @@ static void test_server_1_3(gconstpointer data) sep =avdtp_register_sep (context->lseps,AVDTP_SEP_TYPE_SOURCE ,AVDTP_MEDIA_TYPE_AUDIO ,0x00 , TRUE, &sep_ind,NULL , context); +g_assert (sep);g_idle_add (send_pdu, context);execute_context (context); - -avdtp_unregister_sep (context->lseps, sep); -queue_destroy (context->lseps,NULL ); }static void test_server_1_3_sink (gconstpointer data)
@@ -547,13 +558,11 @@ static void test_server_1_3_sink(gconstpointer data) sep =avdtp_register_sep (context->lseps,AVDTP_SEP_TYPE_SINK ,AVDTP_MEDIA_TYPE_AUDIO ,0x00 , TRUE, &sep_ind,NULL , context); +g_assert (sep);g_idle_add (send_pdu, context);execute_context (context); - -avdtp_unregister_sep (context->lseps, sep); -queue_destroy (context->lseps,NULL ); }static void test_server_0_sep (gconstpointer data)
@@ -565,14 +574,6 @@ static void test_server_0_sep(gconstpointer data)execute_context (context); } -static void unregister_sep (void *data) -{ -struct avdtp_local_sep *sep = data; - -/* Removed from the queue by caller */ -avdtp_unregister_sep (NULL , sep); -} -static void test_server_seid (gconstpointer data) {struct context *context =create_context (0x0103 , data);
@@ -594,8 +595,7 @@ static void test_server_seid(gconstpointer data) context);g_assert (!sep); -/* Remove all SEPs */ -queue_destroy (context->lseps, unregister_sep); +destroy_context (context); }static void test_server_seid_duplicate (gconstpointer data)
@@ -630,9 +630,6 @@ static void test_server_seid_duplicate(gconstpointer data)g_idle_add (send_pdu, context);execute_context (context); - -/* Remove all SEPs */ -queue_destroy (context->lseps, unregister_sep); } static gboolean sep_getcap_ind_frg(struct avdtp *session,
@@ -684,13 +681,11 @@ static void test_server_frg(gconstpointer data)AVDTP_MEDIA_TYPE_AUDIO ,0x00 , TRUE, &sep_ind_frg, NULL, context); +g_assert (sep);g_idle_add (send_pdu, context);execute_context (context); - -avdtp_unregister_sep (context->lseps, sep); -queue_destroy (context->lseps,NULL ); } static void discover_cb(struct avdtp *session, GSList *seps,
@@ -774,9 +769,6 @@ static void test_client(gconstpointer data)avdtp_discover (context->session, discover_cb, context);execute_context (context); - -avdtp_unregister_sep (context->lseps, sep); -queue_destroy (context->lseps,NULL ); }static void test_client_1_3 (gconstpointer data)
@@ -793,9 +785,6 @@ static void test_client_1_3(gconstpointer data)avdtp_discover (context->session, discover_cb, context);execute_context (context); - -avdtp_unregister_sep (context->lseps, sep); -queue_destroy (context->lseps,NULL ); }static void test_client_frg (gconstpointer data)
@@ -812,9 +801,6 @@ static void test_client_frg(gconstpointer data)avdtp_discover (context->session, discover_cb, context);execute_context (context); - -avdtp_unregister_sep (context->lseps, sep); -queue_destroy (context->lseps,NULL ); }int main (int argc,char *argv[])
Signature · 1 line
2.1.0
RFC v3 3/9 android/avdtp: Remove extra check
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
--- android/avdtp.c | 3 --- 1 file changed, 3 deletions(-)
android/avdtp.c +0 -3
@@ -3372,9 +3372,6 @@ struct avdtp_local_sep *avdtp_register_sep(struct queue *lseps, uint8_t type,if (!seid)return NULL ; -if (queue_length (lseps) >MAX_SEID ) -return NULL ; - sep = g_new0(struct avdtp_local_sep, 1); sep->state =AVDTP_STATE_IDLE ;
Signature · 1 line
2.1.0
RFC v3 4/9 audio/avdtp: Use bitfield id generation
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
Use bitfield utils for assigning SEP id. This fixes duplicated id generation shown in unit/avdtp tests.
--- profiles/audio/avdtp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
profiles/audio/avdtp.c +8 -4
@@ -41,6 +41,7 @@#include <glib.h> #include "src/log.h" +#include "src/shared/util.h" #include "btio/btio.h" #include "lib/uuid.h"
@@ -54,6 +55,7 @@#define AVDTP_PSM 25#define MAX_SEID 0x3E +static unsigned int seids;#ifndef MAX # define MAX (x, y) ((x) > (y) ? (x) : (y))
@@ -3703,6 +3705,10 @@ struct avdtp_local_sep *avdtp_register_sep(struct btd_adapter *adapter, {struct avdtp_server *server;struct avdtp_local_sep *sep; +uint8_t seid =util_get_uid (&seids,MAX_SEID ); + +if (!seid) +return NULL ; server =find_server (servers, adapter);if (!server) {
@@ -3711,13 +3717,10 @@ struct avdtp_local_sep *avdtp_register_sep(struct btd_adapter *adapter,return NULL ; } -if (g_slist_length (server->seps) >MAX_SEID ) -return NULL ; - sep = g_new0(struct avdtp_local_sep, 1); sep->state =AVDTP_STATE_IDLE ; - sep->info.seid =g_slist_length (server->seps) +1 ; + sep->info.seid = seid; sep->info.type = type; sep->info.media_type = media_type; sep->codec = codec_type;
@@ -3762,6 +3765,7 @@ int avdtp_unregister_sep(struct avdtp_local_sep *sep)DBG ("SEP %p unregistered: type:%d codec:%d seid:%d" , sep, sep->info.type, sep->codec, sep->info.seid); +util_clear_uid (&seids, sep->info.seid);g_free (sep);if (server->seps)
Signature · 1 line
2.1.0
RFC v3 5/9 audio/avdtp: Refactor avdtp and a2dp code
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
Move connection-related code from avdtp to a2dp. This shall help to use same avdtp library in profiles/ and android/ code.
--- profiles/audio/a2dp.c | 163 +++++++++++++++++++++++++++++++++++++++++++++-- profiles/audio/avdtp.c | 168 ++++++++++++++----------------------------------- profiles/audio/avdtp.h | 14 ++++- 3 files changed, 219 insertions(+), 126 deletions(-)
profiles/audio/a2dp.c +159 -4
@@ -46,6 +46,8 @@#include "src/log.h" #include "src/sdpd.h" +#include "btio/btio.h" +#include "avdtp.h" #include "sink.h" #include "source.h"
@@ -58,6 +60,8 @@#define SUSPEND_TIMEOUT 5#define RECONFIGURE_TIMEOUT 500 +#define AVDTP_PSM 25 +struct a2dp_sep {struct a2dp_server *server;struct a2dp_endpoint *endpoint;
@@ -110,7 +114,15 @@ struct a2dp_server {gboolean source_enabled; }; +struct avdtp_server { +struct btd_adapter *adapter; +GIOChannel *io; +GSList *seps; +GSList *sessions; +}; +static GSList *servers =NULL ; +static GSList *avdtp_servers =NULL ;static GSList *setups =NULL ;static unsigned int cb_id =0 ;
@@ -1186,6 +1198,19 @@ static struct a2dp_server *find_server(GSList *list, struct btd_adapter *a)return NULL ; } +static struct avdtp_server *find_avdtp_server (GSList *list, +struct btd_adapter *a) +{ +for (; list; list = list->next) { +struct avdtp_server *server = list->data; + +if (server->adapter == a) +return server; + } + +return NULL ; +} +static struct a2dp_server *a2dp_server_register (struct btd_adapter *adapter) {struct a2dp_server *server;
@@ -1197,6 +1222,30 @@ static struct a2dp_server *a2dp_server_register(struct btd_adapter *adapter)return server; } +static void avdtp_server_destroy (struct avdtp_server *server) +{ +g_slist_free_full (server->sessions, avdtp_free); + + avdtp_servers =g_slist_remove (avdtp_servers, server); + +g_io_channel_shutdown (server->io, TRUE,NULL ); +g_io_channel_unref (server->io); +btd_adapter_unref (server->adapter); +g_free (server); +} + +static void a2dp_clean_lsep (struct avdtp_local_sep *lsep) +{ +struct avdtp_server *server =avdtp_get_server (lsep); + + + server->seps =g_slist_remove (server->seps, lsep); +if (!server->seps) +avdtp_server_destroy (server); + +avdtp_unregister_sep (lsep); +} +static void a2dp_unregister_sep (struct a2dp_sep *sep) {if (sep->destroy) {
@@ -1204,7 +1253,8 @@ static void a2dp_unregister_sep(struct a2dp_sep *sep) sep->endpoint =NULL ; } -avdtp_unregister_sep (sep->lsep); +a2dp_clean_lsep (sep->lsep); +g_free (sep); }
@@ -1215,6 +1265,103 @@ static void a2dp_server_unregister(struct a2dp_server *server)g_free (server); } +static void auth_cb (DBusError *derr,void *user_data) +{ +struct avdtp *session = user_data; + +if (derr &&dbus_error_is_set (derr)) { +error ("Access denied: %s" , derr->message); +connection_lost (session,EACCES ); +return ; + } + +avdtp_accept (session); +} + +static void avdtp_confirm_cb (GIOChannel *chan,gpointer data) +{ +struct avdtp *session; +char address[18 ]; +bdaddr_t src, dst; +GError *err =NULL ; +struct btd_device *device; +struct avdtp_server *avdtp_server; + +bt_io_get (chan, &err, +BT_IO_OPT_SOURCE_BDADDR , &src, +BT_IO_OPT_DEST_BDADDR , &dst, +BT_IO_OPT_DEST , address, +BT_IO_OPT_INVALID ); +if (err) { +error ("%s" , err->message); +g_error_free (err); + goto drop; + } + +DBG ("AVDTP: incoming connect from %s" , address); + + device =btd_adapter_find_device (adapter_find (&src), &dst, +BDADDR_BREDR ); +if (!device) + goto drop; + + avdtp_server =find_avdtp_server (avdtp_servers, +device_get_adapter (device)); +if (!avdtp_server) + goto drop; + + session =avdtp_new (avdtp_server, avdtp_server->sessions, chan, device); +if (!session) + goto drop; + +avdtp_request_authorization (session, &src, &dst, auth_cb); + +return ; + +drop: +g_io_channel_shutdown (chan, TRUE,NULL ); +} + +static GIOChannel *avdtp_server_socket (const bdaddr_t *src,gboolean master) +{ +GError *err =NULL ; +GIOChannel *io; + + io =bt_io_listen (NULL , avdtp_confirm_cb, +NULL ,NULL , &err, +BT_IO_OPT_SOURCE_BDADDR , src, +BT_IO_OPT_PSM ,AVDTP_PSM , +BT_IO_OPT_SEC_LEVEL ,BT_IO_SEC_MEDIUM , +BT_IO_OPT_MASTER , master, +BT_IO_OPT_INVALID ); +if (!io) { +error ("%s" , err->message); +g_error_free (err); + } + +return io; +} + +static struct avdtp_server *avdtp_server_init (struct btd_adapter *adapter) +{ +struct avdtp_server *server; + + server = g_new0(struct avdtp_server, 1); + + server->io =avdtp_server_socket (btd_adapter_get_address (adapter), + TRUE); +if (!server->io) { +g_free (server); +return NULL ; + } + + server->adapter =btd_adapter_ref (adapter); + + avdtp_servers =g_slist_append (avdtp_servers, server); + +return server; +} + struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type, uint8_t codec, gboolean delay_reporting, struct a2dp_endpoint *endpoint,
@@ -1222,6 +1369,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type, int *err) {struct a2dp_server *server; +struct avdtp_server *avdtp_server;struct a2dp_sep *sep;GSList **l;uint32_t *record_id;
@@ -1248,7 +1396,14 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type, sep = g_new0(struct a2dp_sep, 1); - sep->lsep =avdtp_register_sep (adapter, type, + avdtp_server =find_avdtp_server (avdtp_servers, adapter); +if (!avdtp_server) { + avdtp_server =avdtp_server_init (adapter); +if (!server) +return NULL ; + } + + sep->lsep =avdtp_register_sep (avdtp_server, type,AVDTP_MEDIA_TYPE_AUDIO , codec, delay_reporting, &endpoint_ind, &cfm, sep);
@@ -1282,7 +1437,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type, record =a2dp_record (type);if (!record) {error ("Unable to allocate new service record" ); -avdtp_unregister_sep (sep->lsep); +a2dp_clean_lsep (sep->lsep);g_free (sep);if (err) *err = -EINVAL ;
@@ -1292,7 +1447,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,if (adapter_service_add (server->adapter, record) <0 ) {error ("Unable to register A2DP service record" );sdp_record_free (record); -avdtp_unregister_sep (sep->lsep); +a2dp_clean_lsep (sep->lsep);g_free (sep);if (err) *err = -EINVAL ;
profiles/audio/avdtp.c +47 -121
261 lines not on this page · raw message
profiles/audio/avdtp.h +13 -1
@@ -29,6 +29,7 @@ typedef enum { } avdtp_session_state_t;struct avdtp ; +struct avdtp_server ;struct avdtp_stream ;struct avdtp_local_sep ;struct avdtp_remote_sep ;
@@ -268,7 +269,7 @@ int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);int avdtp_delay_report (struct avdtp *session,struct avdtp_stream *stream,uint16_t delay); -struct avdtp_local_sep *avdtp_register_sep(struct btd_adapter *adapter, +struct avdtp_local_sep *avdtp_register_sep(struct avdtp_server *server, uint8_t type, uint8_t media_type, uint8_t codec_type,
@@ -293,3 +294,14 @@ int avdtp_error_posix_errno(struct avdtp_error *err);struct btd_adapter *avdtp_get_adapter (struct avdtp *session);struct btd_device *avdtp_get_device (struct avdtp *session); +struct avdtp_server *avdtp_get_server (struct avdtp_local_sep *lsep); + +struct avdtp *avdtp_new (struct avdtp_server *server,GSList *sessions, +GIOChannel *chan, +struct btd_device *device); +void avdtp_free (void *data); +void connection_lost (struct avdtp *session,int err); +void avdtp_accept (struct avdtp *session); +bool avdtp_request_authorization (struct avdtp *session,const bdaddr_t *src, +const bdaddr_t *dst, +service_auth_cb cb);
Signature · 1 line
2.1.0
RFC v3 6/9 audio/avdtp: Replace GSList with queue for SEP list
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
--- profiles/audio/a2dp.c | 7 ++++--- profiles/audio/avdtp.c | 51 +++++++++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 24 deletions(-)
profiles/audio/a2dp.c +4 -3
@@ -45,6 +45,7 @@#include "src/service.h" #include "src/log.h" #include "src/sdpd.h" +#include "src/shared/queue.h" #include "btio/btio.h"
@@ -117,7 +118,7 @@ struct a2dp_server {struct avdtp_server {struct btd_adapter *adapter;GIOChannel *io; -GSList *seps; +struct queue *seps;GSList *sessions; };
@@ -1239,8 +1240,8 @@ static void a2dp_clean_lsep(struct avdtp_local_sep *lsep)struct avdtp_server *server =avdtp_get_server (lsep); - server->seps =g_slist_remove (server->seps, lsep); -if (!server->seps) +queue_remove (server->seps, lsep); +if (queue_isempty (server->seps))avdtp_server_destroy (server);avdtp_unregister_sep (lsep);
profiles/audio/avdtp.c +30 -21
96 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC v3 7/9 audi: Refactor avdtp_get function
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
Refactor avdtp_get() moving it from avdtp to a2dp and renaming to a2dp_avdtp_get().
--- profiles/audio/a2dp.c | 16 +++++++++++++ profiles/audio/a2dp.h | 1 + profiles/audio/avdtp.c | 57 +++------------------------------------------- profiles/audio/avdtp.h | 2 -- profiles/audio/sink.c | 2 +- profiles/audio/source.c | 2 +- profiles/audio/transport.c | 2 +- 7 files changed, 23 insertions(+), 59 deletions(-)
profiles/audio/a2dp.c +16 -0
@@ -1212,6 +1212,22 @@ static struct avdtp_server *find_avdtp_server(GSList *list,return NULL ; } +struct avdtp *a2dp_avdtp_get (struct btd_device *device) +{ +struct avdtp_server *server; +struct avdtp *session; + + server =find_avdtp_server (avdtp_servers,device_get_adapter (device)); +if (server ==NULL ) +return NULL ; + + session =avdtp_new (server, server->sessions,NULL , device); +if (!session) +return NULL ; + +return avdtp_ref (session); +} +static struct a2dp_server *a2dp_server_register (struct btd_adapter *adapter) {struct a2dp_server *server;
profiles/audio/a2dp.h +1 -0
@@ -87,3 +87,4 @@ gboolean a2dp_sep_lock(struct a2dp_sep *sep, struct avdtp *session);gboolean a2dp_sep_unlock (struct a2dp_sep *sep,struct avdtp *session);struct avdtp_stream *a2dp_sep_get_stream (struct a2dp_sep *sep);struct btd_device *a2dp_setup_get_device (struct a2dp_setup *setup); +struct avdtp *a2dp_avdtp_get (struct btd_device *device);
profiles/audio/avdtp.c +3 -54
81 lines not on this page · raw message
profiles/audio/avdtp.h +0 -2
@@ -214,8 +214,6 @@ struct avdtp_sep_ind {typedef void (*avdtp_discover_cb_t ) (struct avdtp *session,GSList *seps,struct avdtp_error *err,void *user_data); -struct avdtp *avdtp_get (struct btd_device *device); -void avdtp_unref (struct avdtp *session);struct avdtp *avdtp_ref (struct avdtp *session);
profiles/audio/sink.c +1 -1
@@ -282,7 +282,7 @@ int sink_connect(struct btd_service *service)struct sink *sink =btd_service_get_user_data (service);if (!sink->session) - sink->session =avdtp_get (btd_service_get_device (service)); + sink->session =a2dp_avdtp_get (btd_service_get_device (service));if (!sink->session) {DBG ("Unable to get a session" );
profiles/audio/source.c +1 -1
@@ -283,7 +283,7 @@ int source_connect(struct btd_service *service)struct source *source =btd_service_get_user_data (service);if (!source->session) - source->session =avdtp_get (btd_service_get_device (service)); + source->session =a2dp_avdtp_get (btd_service_get_device (service));if (!source->session) {DBG ("Unable to get a session" );
profiles/audio/transport.c +1 -1
@@ -333,7 +333,7 @@ static guint resume_a2dp(struct media_transport *transport,guint id;if (a2dp->session ==NULL ) { - a2dp->session =avdtp_get (transport->device); + a2dp->session =a2dp_avdtp_get (transport->device);if (a2dp->session ==NULL )return 0 ; }
Signature · 1 line
2.1.0
RFC v3 8/9 audio/avdtp: Move avdtp_server from avdtp SEP structures
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
a2dp_server and avdtp_server are handled inside a2dp_sep structure.
--- profiles/audio/a2dp.c | 14 ++++++++------ profiles/audio/avdtp.c | 7 ------- 2 files changed, 8 insertions(+), 13 deletions(-)
profiles/audio/a2dp.c +8 -6
@@ -65,6 +65,7 @@struct a2dp_sep {struct a2dp_server *server; +struct avdtp_server *avdtp_server;struct a2dp_endpoint *endpoint;uint8_t type;uint8_t codec;
@@ -1251,10 +1252,10 @@ static void avdtp_server_destroy(struct avdtp_server *server)g_free (server); } -static void a2dp_clean_lsep (struct avdtp_local_sep *lsep) +static void a2dp_clean_lsep (struct a2dp_sep *sep) { -struct avdtp_server *server =avdtp_get_server (lsep); - +struct avdtp_local_sep *lsep = sep->lsep; +struct avdtp_server *server = sep->avdtp_server;queue_remove (server->seps, lsep);if (queue_isempty (server->seps))
@@ -1270,7 +1271,7 @@ static void a2dp_unregister_sep(struct a2dp_sep *sep) sep->endpoint =NULL ; } -a2dp_clean_lsep (sep->lsep); +a2dp_clean_lsep (sep);g_free (sep); }
@@ -1433,6 +1434,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type, } sep->server = server; + sep->avdtp_server = avdtp_server; sep->endpoint = endpoint; sep->codec = codec; sep->type = type;
@@ -1454,7 +1456,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type, record =a2dp_record (type);if (!record) {error ("Unable to allocate new service record" ); -a2dp_clean_lsep (sep->lsep); +a2dp_clean_lsep (sep);g_free (sep);if (err) *err = -EINVAL ;
@@ -1464,7 +1466,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,if (adapter_service_add (server->adapter, record) <0 ) {error ("Unable to register A2DP service record" );sdp_record_free (record); -a2dp_clean_lsep (sep->lsep); +a2dp_clean_lsep (sep);g_free (sep);if (err) *err = -EINVAL ;
profiles/audio/avdtp.c +0 -7
@@ -341,7 +341,6 @@ struct avdtp_local_sep {struct avdtp_sep_ind *ind;struct avdtp_sep_cfm *cfm;void *user_data; -struct avdtp_server *server; };struct stream_callback {
@@ -3624,7 +3623,6 @@ struct avdtp_local_sep *avdtp_register_sep(struct avdtp_server *server, sep->ind = ind; sep->cfm = cfm; sep->user_data = user_data; - sep->server = server; sep->delay_reporting = delay_reporting; DBG("SEP %p registered: type:%d codec:%d seid:%d", sep,
@@ -3715,11 +3713,6 @@ struct btd_device *avdtp_get_device(struct avdtp *session)return session->device; } -struct avdtp_server *avdtp_get_server (struct avdtp_local_sep *lsep) -{ -return lsep->server; -} -gboolean avdtp_has_stream (struct avdtp *session,struct avdtp_stream *stream) {return g_slist_find (session->streams, stream) ? TRUE : FALSE;
Signature · 1 line
2.1.0
RFC v3 9/9 audio/avdtp: Use SEP queue instead of avdtp_server in avdtp code
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
This makes register/unregister sep code inside avdtp.c similar between profiles/ and android/
--- profiles/audio/a2dp.c | 7 +++---- profiles/audio/avdtp.c | 8 ++++---- profiles/audio/avdtp.h | 5 ++--- profiles/audio/media.c | 1 + profiles/audio/sink.c | 1 + profiles/audio/source.c | 1 + profiles/audio/transport.c | 1 + 7 files changed, 13 insertions(+), 11 deletions(-)
profiles/audio/a2dp.c +3 -4
@@ -1257,11 +1257,10 @@ static void a2dp_clean_lsep(struct a2dp_sep *sep)struct avdtp_local_sep *lsep = sep->lsep;struct avdtp_server *server = sep->avdtp_server; -queue_remove (server->seps, lsep); +avdtp_unregister_sep (server->seps, lsep); +if (queue_isempty (server->seps))avdtp_server_destroy (server); - -avdtp_unregister_sep (lsep); }static void a2dp_unregister_sep (struct a2dp_sep *sep)
@@ -1421,7 +1420,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,return NULL ; } - sep->lsep =avdtp_register_sep (avdtp_server, type, + sep->lsep =avdtp_register_sep (avdtp_server->seps, type,AVDTP_MEDIA_TYPE_AUDIO , codec, delay_reporting, &endpoint_ind, &cfm, sep);
profiles/audio/avdtp.c +4 -4
@@ -3598,8 +3598,7 @@ void avdtp_accept(struct avdtp *session) session->stream_setup = TRUE; } -struct avdtp_local_sep *avdtp_register_sep(struct avdtp_server *server, - uint8_t type, +struct avdtp_local_sep *avdtp_register_sep(struct queue *lseps, uint8_t type, uint8_t media_type, uint8_t codec_type, gboolean delay_reporting,
@@ -3628,7 +3627,7 @@ struct avdtp_local_sep *avdtp_register_sep(struct avdtp_server *server,DBG ("SEP %p registered: type:%d codec:%d seid:%d" , sep, sep->info.type, sep->codec, sep->info.seid); -if (!queue_push_tail (server->seps, sep)) { +if (!queue_push_tail (lseps, sep)) {g_free (sep);return NULL ; }
@@ -3636,7 +3635,7 @@ struct avdtp_local_sep *avdtp_register_sep(struct avdtp_server *server,return sep; } -int avdtp_unregister_sep (struct avdtp_local_sep *sep) +int avdtp_unregister_sep (struct queue *lseps,struct avdtp_local_sep *sep) {if (!sep)return -EINVAL ;
@@ -3648,6 +3647,7 @@ int avdtp_unregister_sep(struct avdtp_local_sep *sep) sep->info.type, sep->codec, sep->info.seid);util_clear_uid (&seids, sep->info.seid); +queue_remove (lseps, sep);g_free (sep);return 0 ;
profiles/audio/avdtp.h +2 -3
@@ -267,8 +267,7 @@ int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);int avdtp_delay_report (struct avdtp *session,struct avdtp_stream *stream,uint16_t delay); -struct avdtp_local_sep *avdtp_register_sep(struct avdtp_server *server, - uint8_t type, +struct avdtp_local_sep *avdtp_register_sep(struct queue *lseps, uint8_t type, uint8_t media_type, uint8_t codec_type, gboolean delay_reporting,
@@ -280,7 +279,7 @@ struct avdtp_local_sep *avdtp_register_sep(struct avdtp_server *server,struct avdtp_remote_sep *avdtp_find_remote_sep (struct avdtp *session,struct avdtp_local_sep *lsep); -int avdtp_unregister_sep (struct avdtp_local_sep *sep); +int avdtp_unregister_sep (struct queue *lseps,struct avdtp_local_sep *sep);avdtp_state_t avdtp_sep_get_state (struct avdtp_local_sep *sep);
profiles/audio/media.c +1 -0
@@ -44,6 +44,7 @@#include "src/uuid-helper.h" #include "src/log.h" #include "src/error.h" +#include "src/shared/queue.h" #include "avdtp.h" #include "media.h"
profiles/audio/sink.c +1 -0
@@ -44,6 +44,7 @@#include "src/service.h" #include "src/error.h" #include "src/dbus-common.h" +#include "src/shared/queue.h" #include "avdtp.h" #include "media.h"
profiles/audio/source.c +1 -0
@@ -45,6 +45,7 @@#include "src/service.h" #include "src/error.h" #include "src/dbus-common.h" +#include "src/shared/queue.h" #include "avdtp.h" #include "media.h"
profiles/audio/transport.c +1 -0
@@ -39,6 +39,7 @@#include "src/log.h" #include "src/error.h" +#include "src/shared/queue.h" #include "avdtp.h" #include "media.h"
Signature · 1 line
2.1.0
Hi Andrei,
Quoted 24 lines · On Friday 20 of February 2015 14:43:14 Andrei Emeltchenko wrote:
From: Andrei Emeltchenko <[email protected]>
Refactoring code so that avdtp library can be easily reused inside profiles/
Andrei Emeltchenko (9):
android/avdtp: Refactor local SEP list handling unit/avdtp: Refactor context destroy
android/avdtp: Remove extra check
audio/avdtp: Use bitfield id generation
audio/avdtp: Refactor avdtp and a2dp code audio/avdtp: Replace GSList with queue for SEP list
audi: Refactoravdtp_getfunction
audio/avdtp: Moveavdtp_serverfrom avdtp SEP structures audio/avdtp: Use SEP queue instead ofavdtp_serverin avdtp codeandroid/Android.mk | 1 + android/Makefile.am | 1 + android/a2dp.c | 18 ++- android/avdtp.c | 91 +++++++++------ android/avdtp.h | 8 +- android/avdtptest.c | 10 +- profiles/audio/a2dp.c | 181 ++++++++++++++++++++++++++++- profiles/audio/a2dp.h | 1 + profiles/audio/avdtp.c | 283
Quoted 8 lines
+++++++++++++--------------------------------
profiles/audio/avdtp.h|
19 ++-profiles/audio/media.c | 1 + profiles/audio/sink.c | 3 +- profiles/audio/source.c | 3 +- profiles/audio/transport.c | 3 +- unit/test-avdtp.c | 117 ++++++++++--------- 15 files changed, 421 insertions(+), 319 deletions(-)
All patches applied, thanks.
Signature · 2 lines
BR Szymon Janc