Remove audio_device and introduce policy plugin
Subsystems (2)
Luiz Augusto von Dentz
maintainerv2 cover Remove audio_device and introduce policy plugin
From: Luiz Augusto von Dentz <[email protected]>
audio_device is no longer needed as btd_service can be used to track connection states, in fact audio_device probably obscured direct access to some data types like btd_device and use btd_service_set_user_data to set profile private data instead of storing everything inside audio_device.
There are probably more cleanups to audio after this changes, some policies that should be moved to policy plugin and a much needed split of audio plugin into smaller plugins, but I decided to stop right here otherwise the patch-set will get too big to be properly reviewed.
Also since this refactore the audio policy quite extensively this may create some IOP issues, but I did test this with quite a few stacks including:
- iOS 6
- Android 4.2
- WP 8
- Blackberry 10
- MW600
- Nokia Purity Pro
- BlueZ 4
- BlueZ 5
They all seems to be working as before.
v2: Add patch 21/21 to enable initiating connections to CT role.
Luiz Augusto von Dentz (21):
audio/sink: Use service user_data for private data audio/source: Use service user_data for private data audio/control: Use service user_data for private data audio/sink: Reduce dependency on struct audio_device audio/source: Reduce dependency on struct audio_device audio/control: Reduce dependency on struct audio_device audio/AVCTP: Remove dependency on struct audio_device audio/AVDTP: Remove dependency on struct audio_device audio/AVRCP: Remove dependency on struct audio_device audio/control: Remove dependency on struct audio_device audio/A2DP: Remove dependency on struct audio_device audio/sink: Remove dependency on struct audio_device audio/source: Remove dependency on struct audio_device audio/media: Remove dependency on struct audio_device audio/transport: Remove dependency on struct audio_device audio/manager: Remove dependency on struct audio_device audio/main: Remove dependency on struct audio_device plugins/policy: Reword audio policy code in a simple plugin audio/source: Move stream retry logic to policy plugin audio/sink: Move stream retry logic to policy plugin audio/control: Enable initiate connection to CT role
Makefile.plugins | 4 +- plugins/policy.c | 426 +++++++++++++++++++++++++++++++++++++++++++++ profiles/audio/a2dp.c | 110 ++++++------ profiles/audio/a2dp.h | 4 +- profiles/audio/avctp.c | 69 +++----- profiles/audio/avctp.h | 12 +- profiles/audio/avdtp.c | 97 +++++------ profiles/audio/avdtp.h | 13 +- profiles/audio/avrcp.c | 89 ++++++---- profiles/audio/avrcp.h | 8 +- profiles/audio/control.c | 143 +++++++-------- profiles/audio/control.h | 19 +- profiles/audio/device.c | 261 --------------------------- profiles/audio/device.h | 43 ----- profiles/audio/main.c | 1 - profiles/audio/manager.c | 199 +++++---------------- profiles/audio/manager.h | 10 -- profiles/audio/media.c | 39 +++-- profiles/audio/sink.c | 157 +++++++---------- profiles/audio/sink.h | 18 +- profiles/audio/source.c | 158 +++++++---------- profiles/audio/source.h | 20 +-- profiles/audio/transport.c | 109 +++++++----- profiles/audio/transport.h | 8 +- 24 files changed, 993 insertions(+), 1024 deletions(-) create mode 100644 plugins/policy.c delete mode 100644 profiles/audio/device.c delete mode 100644 profiles/audio/device.h
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 1/21 audio/sink: Use service user_data for private data
From: Luiz Augusto von Dentz <[email protected]>
This remove the need of forward declaration of struct sink and prepare for a complete removal of struct audio_device.
--- profiles/audio/device.c | 54 +++++++++++++++++++++++++++++------------------- profiles/audio/device.h | 3 +-- profiles/audio/manager.c | 4 ++-- profiles/audio/sink.c | 28 ++++++++++++++----------- profiles/audio/sink.h | 4 ++-- 5 files changed, 54 insertions(+), 39 deletions(-)
profiles/audio/device.c +33 -21
@@ -42,10 +42,12 @@#include <dbus/dbus.h> #include <gdbus/gdbus.h> -#include "log.h" -#include "../src/adapter.h" -#include "../src/device.h" +#include "lib/uuid.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/service.h" +#include "log.h" #include "error.h" #include "dbus-common.h" #include "device.h"
@@ -61,7 +63,7 @@#define AVDTP_CONNECT_TIMEOUT_BOOST 1struct dev_priv { -sink_state_t sink_state; +btd_service_state_t sink_state;avctp_state_t avctp_state;guint control_timer;
@@ -69,9 +71,9 @@ struct dev_priv {gboolean disconnecting; +unsigned int service_cb_id;unsigned int avdtp_callback_id;unsigned int avctp_callback_id; -unsigned int sink_callback_id; };static void device_free (struct audio_device *dev)
@@ -87,7 +89,7 @@ static void device_free(struct audio_device *dev)avdtp_remove_state_cb (priv->avdtp_callback_id);avctp_remove_state_cb (priv->avctp_callback_id); -sink_remove_state_cb (priv->sink_callback_id); +btd_service_remove_state_cb (priv->service_cb_id);g_free (priv); }
@@ -138,6 +140,7 @@ static void disconnect_cb(struct btd_device *btd_dev, gboolean removal, {struct audio_device *dev = user_data;struct dev_priv *priv = dev->priv; +struct btd_service *sink;if (priv->disconnecting)return ;
@@ -149,7 +152,8 @@ static void disconnect_cb(struct btd_device *btd_dev, gboolean removal,if (dev->control && priv->avctp_state !=AVCTP_STATE_DISCONNECTED )avrcp_disconnect (dev); -if (dev->sink && priv->sink_state !=SINK_STATE_DISCONNECTED ) + sink =btd_device_get_service (btd_dev,A2DP_SINK_UUID ); +if (sink)sink_disconnect (dev, TRUE);else priv->disconnecting = FALSE;
@@ -171,30 +175,25 @@ static void device_avdtp_cb(struct audio_device *dev, struct avdtp *session, }static void device_sink_cb (struct audio_device *dev, -sink_state_t old_state, -sink_state_t new_state, -void *user_data) +btd_service_state_t old_state, +btd_service_state_t new_state) {struct dev_priv *priv = dev->priv; -if (!dev->sink) -return ; - priv->sink_state = new_state;switch (new_state) { -case SINK_STATE_DISCONNECTED : +case BTD_SERVICE_STATE_UNAVAILABLE : +case BTD_SERVICE_STATE_DISCONNECTED :if (dev->control) {device_remove_control_timer (dev);if (priv->avctp_state !=AVCTP_STATE_DISCONNECTED )avrcp_disconnect (dev); }break ; -case SINK_STATE_CONNECTING : -break ; -case SINK_STATE_CONNECTED : -break ; -case SINK_STATE_PLAYING : +case BTD_SERVICE_STATE_CONNECTING : +case BTD_SERVICE_STATE_CONNECTED : +case BTD_SERVICE_STATE_DISCONNECTING :break ; } }
@@ -222,6 +221,20 @@ static void device_avctp_cb(struct audio_device *dev, avctp_state_t old_state, } } +static void service_cb (struct btd_service *service, +btd_service_state_t old_state, +btd_service_state_t new_state, +void *user_data) +{ +struct audio_device *dev = user_data; + +if (dev->btd_dev !=btd_service_get_device (service)) +return ; + +if (service == dev->sink) +device_sink_cb (dev, old_state, new_state); +} +struct audio_device *audio_device_register (struct btd_device *device) {struct audio_device *dev;
@@ -236,8 +249,7 @@ struct audio_device *audio_device_register(struct btd_device *device) dev->priv->dc_id =device_add_disconnect_watch (dev->btd_dev, disconnect_cb, dev,NULL ); - dev->priv->sink_callback_id =sink_add_state_cb (dev, device_sink_cb, -NULL ); + dev->priv->service_cb_id =btd_service_add_state_cb (service_cb, dev); dev->priv->avdtp_callback_id =avdtp_add_state_cb (dev, device_avdtp_cb); dev->priv->avctp_callback_id =avctp_add_state_cb (dev, device_avctp_cb);
profiles/audio/device.h +1 -2
@@ -25,13 +25,12 @@struct audio_device ;struct source ;struct control ; -struct sink ;struct dev_priv ;struct audio_device {struct btd_device *btd_dev; -struct sink *sink; +struct btd_service *sink;struct source *source;struct control *control;
profiles/audio/manager.c +2 -2
@@ -130,9 +130,9 @@ static int a2dp_sink_probe(struct btd_service *service)return -1 ; } - audio_dev->sink =sink_init (audio_dev, service); + audio_dev->sink = service; -return 0 ; +return sink_init (audio_dev, service); }static int avrcp_target_probe (struct btd_service *service)
profiles/audio/sink.c +16 -12
@@ -87,7 +87,7 @@ static char *str_state[] = {static void sink_set_state (struct audio_device *dev,sink_state_t new_state) { -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);sink_state_t old_state = sink->state;GSList *l;
@@ -119,7 +119,7 @@ static void avdtp_state_callback(struct audio_device *dev, avdtp_session_state_t old_state, avdtp_session_state_t new_state) { -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);switch (new_state) {case AVDTP_SESSION_STATE_DISCONNECTED :
@@ -142,7 +142,7 @@ static void stream_state_changed(struct avdtp_stream *stream, void *user_data) {struct audio_device *dev = user_data; -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);if (err)return ;
@@ -283,8 +283,10 @@ failed: sink->session =NULL ; } -gboolean sink_setup_stream (struct sink *sink,struct avdtp *session) +gboolean sink_setup_stream (struct btd_service *service,struct avdtp *session) { +struct sink *sink =btd_service_get_user_data (service); +if (sink->connect_id >0 || sink->disconnect_id >0 )return FALSE;
@@ -302,7 +304,7 @@ gboolean sink_setup_stream(struct sink *sink, struct avdtp *session)int sink_connect (struct audio_device *dev) { -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);if (!sink->session) sink->session =avdtp_get (dev);
@@ -318,7 +320,7 @@ int sink_connect(struct audio_device *dev)if (sink->stream_state >=AVDTP_STATE_OPEN )return -EALREADY ; -if (!sink_setup_stream (sink,NULL )) { +if (!sink_setup_stream (sink->service,NULL )) {DBG ("Failed to create a stream" );return -EIO ; }
@@ -330,7 +332,7 @@ int sink_connect(struct audio_device *dev)static void sink_free (struct audio_device *dev) { -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);if (sink->cb_id) avdtp_stream_remove_cb(sink->session, sink->stream,
@@ -367,7 +369,7 @@ void sink_unregister(struct audio_device *dev)sink_free (dev); } -struct sink *sink_init (struct audio_device *dev,struct btd_service *service) +int sink_init (struct audio_device *dev,struct btd_service *service) {struct sink *sink;
@@ -380,12 +382,14 @@ struct sink *sink_init(struct audio_device *dev, struct btd_service *service) sink->avdtp_callback_id =avdtp_add_state_cb (dev, avdtp_state_callback); -return sink; +btd_service_set_user_data (service, sink); + +return 0 ; }gboolean sink_is_active (struct audio_device *dev) { -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);if (sink->session)return TRUE;
@@ -396,7 +400,7 @@ gboolean sink_is_active(struct audio_device *dev)gboolean sink_new_stream (struct audio_device *dev,struct avdtp *session,struct avdtp_stream *stream) { -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);if (sink->stream)return FALSE;
@@ -414,7 +418,7 @@ gboolean sink_new_stream(struct audio_device *dev, struct avdtp *session,int sink_disconnect (struct audio_device *dev,gboolean shutdown) { -struct sink *sink = dev->sink; +struct sink *sink =btd_service_get_user_data (dev->sink);if (!sink->session)return -ENOTCONN ;
profiles/audio/sink.h +2 -2
@@ -40,11 +40,11 @@ unsigned int sink_add_state_cb(struct audio_device *dev, sink_state_cb cb, void *user_data);gboolean sink_remove_state_cb (unsigned int id); -struct sink *sink_init (struct audio_device *dev,struct btd_service *service); +int sink_init (struct audio_device *dev,struct btd_service *service);void sink_unregister (struct audio_device *dev);gboolean sink_is_active (struct audio_device *dev);int sink_connect (struct audio_device *dev);gboolean sink_new_stream (struct audio_device *dev,struct avdtp *session,struct avdtp_stream *stream); -gboolean sink_setup_stream (struct sink *sink,struct avdtp *session); +gboolean sink_setup_stream (struct btd_service *service,struct avdtp *session);int sink_disconnect (struct audio_device *dev,gboolean shutdown);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 1/3 core/service: Rename service_shutdown to service_remove
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This rename service_shutdown to service_remove to make it more similar to other internal APIs such as device_remove which only do object cleanup/free and do not have any disconnect logic.
--- src/device.c | 3 +-- src/service.c | 3 ++- src/service.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
src/device.c +1 -2
@@ -967,9 +967,8 @@ static void remove_service(gpointer data)struct btd_service *service = data;struct btd_device *device =btd_service_get_device (service); -service_shutdown (service); device->pending =g_slist_remove (device->pending, service); -btd_service_unref (service); +service_remove (service); }static gboolean do_disconnect (gpointer user_data)
src/service.c +2 -1
@@ -168,12 +168,13 @@ int service_probe(struct btd_service *service)return err; } -void service_shutdown (struct btd_service *service) +void service_remove (struct btd_service *service) {change_state (service,BTD_SERVICE_STATE_UNAVAILABLE ,0 ); service->profile->device_remove (service); service->device =NULL ; service->profile =NULL ; +btd_service_unref (service); }int btd_service_connect (struct btd_service *service)
src/service.h +1 -1
@@ -46,7 +46,7 @@ struct btd_service *service_create(struct btd_device *device, struct btd_profile *profile);int service_probe (struct btd_service *service); -void service_shutdown (struct btd_service *service); +void service_remove (struct btd_service *service);/* Connection control API */ int btd_service_connect (struct btd_service *service);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 1/3 v2] core/service: Rename service_shutdown to service_remove
Hi,
Quoted 59 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This rename
service_shutdowntoservice_removeto make it more similar to other internal APIs such asdevice_removewhich only do object cleanup/free and do not have any disconnect logic.--- src/device.c | 3 +-- src/service.c | 3 ++- src/service.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)src/device.c +1
-2@@ -967,9 +967,8 @@ static void remove_service(gpointer data)struct btd_service *service = data;struct btd_device *device =btd_service_get_device (service); -service_shutdown (service); device->pending =g_slist_remove (device->pending, service); -btd_service_unref (service); +service_remove (service); }static gboolean do_disconnect (gpointer user_data)src/service.c +2
-1@@ -168,12 +168,13 @@ int service_probe(struct btd_service *service)return err; } -void service_shutdown (struct btd_service *service) +void service_remove (struct btd_service *service) {change_state (service,BTD_SERVICE_STATE_UNAVAILABLE ,0 ); service->profile->device_remove (service); service->device =NULL ; service->profile =NULL ; +btd_service_unref (service); }int btd_service_connect (struct btd_service *service)src/service.h +1
-2@@ -46,7 +46,7 @@ struct btd_service *service_create(struct btd_device *device, struct btd_profile *profile);int service_probe (struct btd_service *service); -void service_shutdown (struct btd_service *service); +void service_remove (struct btd_service *service);/* Connection control API */ int btd_service_connect (struct btd_service *service); --
Quoted 1 line
1.8.1.4
These 3 patches are now pushed.
--
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerPATCH v2 2/21 audio/source: Use service user_data for private data
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This remove the need of forward declaration of struct source and prepare for a complete removal of struct audio_device.
--- profiles/audio/device.h | 3 +-- profiles/audio/manager.c | 4 ++-- profiles/audio/source.c | 28 ++++++++++++++++------------ profiles/audio/source.h | 6 +++--- 4 files changed, 22 insertions(+), 19 deletions(-)
profiles/audio/device.h +1 -2
@@ -23,7 +23,6 @@*/ struct audio_device ; -struct source ;struct control ;struct dev_priv ;
@@ -31,7 +30,7 @@ struct audio_device {struct btd_device *btd_dev;struct btd_service *sink; -struct source *source; +struct btd_service *source;struct control *control;struct dev_priv *priv;
profiles/audio/manager.c +2 -2
@@ -114,9 +114,9 @@ static int a2dp_source_probe(struct btd_service *service)return -1 ; } - audio_dev->source =source_init (audio_dev, service); + audio_dev->source = service; -return 0 ; +return source_init (audio_dev, service); }static int a2dp_sink_probe (struct btd_service *service)
profiles/audio/source.c +16 -12
@@ -88,7 +88,7 @@ static char *str_state[] = {static void source_set_state (struct audio_device *dev,source_state_t new_state) { -struct source *source = dev->source; +struct source *source =btd_service_get_user_data (dev->source);source_state_t old_state = source->state;GSList *l;
@@ -120,7 +120,7 @@ static void avdtp_state_callback(struct audio_device *dev, avdtp_session_state_t old_state, avdtp_session_state_t new_state) { -struct source *source = dev->source; +struct source *source =btd_service_get_user_data (dev->source);switch (new_state) {case AVDTP_SESSION_STATE_DISCONNECTED :
@@ -143,7 +143,7 @@ static void stream_state_changed(struct avdtp_stream *stream, void *user_data) {struct audio_device *dev = user_data; -struct source *source = dev->source; +struct source *source =btd_service_get_user_data (dev->source);if (err)return ;
@@ -287,8 +287,11 @@ failed: source->session =NULL ; } -gboolean source_setup_stream (struct source *source,struct avdtp *session) +gboolean source_setup_stream (struct btd_service *service, +struct avdtp *session) { +struct source *source =btd_service_get_user_data (service); +if (source->connect_id >0 || source->disconnect_id >0 )return FALSE;
@@ -306,7 +309,7 @@ gboolean source_setup_stream(struct source *source, struct avdtp *session)int source_connect (struct audio_device *dev) { -struct source *source = dev->source; +struct source *source =btd_service_get_user_data (dev->source);if (!source->session) source->session =avdtp_get (dev);
@@ -322,7 +325,7 @@ int source_connect(struct audio_device *dev)if (source->stream_state >=AVDTP_STATE_OPEN )return -EALREADY ; -if (!source_setup_stream (source,NULL )) { +if (!source_setup_stream (source->service,NULL )) {DBG ("Failed to create a stream" );return -EIO ; }
@@ -334,7 +337,7 @@ int source_connect(struct audio_device *dev)static void source_free (struct audio_device *dev) { -struct source *source = dev->source; +struct source *source =btd_service_get_user_data (dev->source);if (source->cb_id) avdtp_stream_remove_cb(source->session, source->stream,
@@ -372,8 +375,7 @@ void source_unregister(struct audio_device *dev)source_free (dev); } -struct source *source_init (struct audio_device *dev, -struct btd_service *service) +int source_init (struct audio_device *dev,struct btd_service *service) {struct source *source;
@@ -387,13 +389,15 @@ struct source *source_init(struct audio_device *dev, source->avdtp_callback_id =avdtp_add_state_cb (dev, avdtp_state_callback); -return source; +btd_service_set_user_data (service, source); + +return 0 ; }gboolean source_new_stream (struct audio_device *dev,struct avdtp *session,struct avdtp_stream *stream) { -struct source *source = dev->source; +struct source *source =btd_service_get_user_data (dev->source);if (source->stream)return FALSE;
@@ -411,7 +415,7 @@ gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,int source_disconnect (struct audio_device *dev,gboolean shutdown) { -struct source *source = dev->source; +struct source *source =btd_service_get_user_data (dev->source);if (!source->session)return -ENOTCONN ;
profiles/audio/source.h +3 -3
@@ -41,11 +41,11 @@ unsigned int source_add_state_cb(struct audio_device *dev, source_state_cb cb, void *user_data);gboolean source_remove_state_cb (unsigned int id); -struct source *source_init (struct audio_device *dev, -struct btd_service *service); +int source_init (struct audio_device *dev,struct btd_service *service);void source_unregister (struct audio_device *dev);int source_connect (struct audio_device *dev);gboolean source_new_stream (struct audio_device *dev,struct avdtp *session,struct avdtp_stream *stream); -gboolean source_setup_stream (struct source *source,struct avdtp *session); +gboolean source_setup_stream (struct btd_service *service, +struct avdtp *session);int source_disconnect (struct audio_device *dev,gboolean shutdown);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 2/3 core/device: Fix crash while freeing services list
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
btd_service do alter its state on service_remove which can cause plugins to attempt to access services list which may have freed some services already.
To fix this the code now updates the list in place so the services are first removed from services list before calling service_remove.
---
v2: Fix applying unrelated changes
src/device.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
src/device.c +13 -6
@@ -993,8 +993,12 @@ int device_block(struct btd_device *device, gboolean update_only)if (device->connected)do_disconnect (device); -g_slist_free_full (device->services, remove_service); - device->services =NULL ; +while (device->services !=NULL ) { +struct btd_service *service = device->services->data; + + device->services =g_slist_remove (device->services, service); +service_remove (service); + }if (!update_only) err = btd_adapter_block_address(device->adapter,
@@ -2361,7 +2365,6 @@ static void device_remove_stored(struct btd_device *device)void device_remove (struct btd_device *device,gboolean remove_stored) { -DBG ("Removing device %s" , device->path);if (device->bonding) {
@@ -2380,6 +2383,13 @@ void device_remove(struct btd_device *device, gboolean remove_stored)g_slist_foreach (device->services, dev_disconn_service,NULL ); +while (device->services !=NULL ) { +struct btd_service *service = device->services->data; + + device->services =g_slist_remove (device->services, service); +service_remove (service); + } +g_slist_free (device->pending); device->pending =NULL ;
@@ -2397,9 +2407,6 @@ void device_remove(struct btd_device *device, gboolean remove_stored)if (remove_stored)device_remove_stored (device); -g_slist_free_full (device->services, remove_service); - device->services =NULL ; -btd_device_unref (device); }
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 3/21 audio/control: Use service user_data for private data
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This remove the need of forward declaration of struct control and prepare for a complete removal of struct audio_device.
--- profiles/audio/avrcp.c | 12 ++++++------ profiles/audio/control.c | 51 +++++++++++++++++++++++++++++------------------- profiles/audio/control.h | 14 ++++++------- profiles/audio/device.h | 3 +-- profiles/audio/manager.c | 14 +++++++++++-- 5 files changed, 56 insertions(+), 38 deletions(-)
profiles/audio/avrcp.c +6 -6
@@ -3314,7 +3314,7 @@ static void session_tg_init_control(struct avrcp *session)avrcp_register_notification (session,AVRCP_EVENT_VOLUME_CHANGED ); -control_remote_connected (session->dev->control,0 ); +control_remote_connected (session->dev,0 ); }static void session_ct_init_browsing (struct avrcp *session)
@@ -3340,7 +3340,7 @@ static void session_ct_init_control(struct avrcp *session)if (session->version >=0x0104 ) session->supported_events = (1 <<AVRCP_EVENT_VOLUME_CHANGED ); -control_target_connected (session->dev->control,0 ); +control_target_connected (session->dev,0 ); player =create_ct_player (session,0 );if (player ==NULL )
@@ -3380,9 +3380,9 @@ static void session_tg_destroy(struct avrcp *session) player->sessions =g_slist_remove (player->sessions, session);if (session->control_id ==0 ) -control_remote_connected (session->dev->control, -EIO ); +control_remote_connected (session->dev, -EIO );else -control_remote_disconnected (session->dev->control,0 ); +control_remote_disconnected (session->dev,0 );session_destroy (session); }
@@ -3394,9 +3394,9 @@ static void session_ct_destroy(struct avrcp *session)g_slist_free_full (session->players, player_destroy);if (session->control_id ==0 ) -control_target_connected (session->dev->control, -EIO ); +control_target_connected (session->dev, -EIO );else -control_target_disconnected (session->dev->control,0 ); +control_target_disconnected (session->dev,0 );session_destroy (session); }
profiles/audio/control.c +31 -20
140 lines not on this page · raw message
profiles/audio/control.h +6 -8
@@ -26,17 +26,15 @@struct btd_service ; -struct control *control_init_target (struct audio_device *dev, -struct btd_service *service); -struct control *control_init_remote (struct audio_device *dev, -struct btd_service *service); +int control_init_target (struct audio_device *dev,struct btd_service *service); +int control_init_remote (struct audio_device *dev,struct btd_service *service);void control_unregister (struct audio_device *dev);gboolean control_is_active (struct audio_device *dev);int control_connect (struct audio_device *dev);int control_disconnect (struct audio_device *dev); -void control_target_connected (struct control *control,int err); -void control_target_disconnected (struct control *control,int err); -void control_remote_connected (struct control *control,int err); -void control_remote_disconnected (struct control *control,int err); +void control_target_connected (struct audio_device *dev,int err); +void control_target_disconnected (struct audio_device *dev,int err); +void control_remote_connected (struct audio_device *dev,int err); +void control_remote_disconnected (struct audio_device *dev,int err);
profiles/audio/device.h +1 -2
@@ -23,7 +23,6 @@*/ struct audio_device ; -struct control ;struct dev_priv ;struct audio_device {
@@ -31,7 +30,7 @@ struct audio_device {struct btd_service *sink;struct btd_service *source; -struct control *control; +struct btd_service *control;struct dev_priv *priv; };
profiles/audio/manager.c +12 -2
@@ -139,6 +139,7 @@ static int avrcp_target_probe(struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);struct audio_device *audio_dev; +int err; audio_dev =get_audio_dev (device);if (!audio_dev) {
@@ -146,7 +147,11 @@ static int avrcp_target_probe(struct btd_service *service)return -1 ; } - audio_dev->control =control_init_target (audio_dev, service); + err =control_init_target (audio_dev, service); +if (err <0 ) +return 0 ; + + audio_dev->control = service;if (audio_dev->sink &&sink_is_active (audio_dev))avrcp_connect (audio_dev);
@@ -158,6 +163,7 @@ static int avrcp_remote_probe(struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);struct audio_device *audio_dev; +int err; audio_dev =get_audio_dev (device);if (!audio_dev) {
@@ -165,7 +171,11 @@ static int avrcp_remote_probe(struct btd_service *service)return -1 ; } - audio_dev->control =control_init_remote (audio_dev, service); + err =control_init_remote (audio_dev, service); +if (err <0 ) +return err; + + audio_dev->control = service;return 0 ; }
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 3/3 core/device: Don't call btd_service_disconnect on device_remove
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
device_remove is called to cleanup/free the device objects so the services should be disconnected before hand.
--- src/device.c | 2 -- 1 file changed, 2 deletions(-)
src/device.c +0 -2
@@ -2381,8 +2381,6 @@ void device_remove(struct btd_device *device, gboolean remove_stored)if (device->browse)browse_request_cancel (device->browse); -g_slist_foreach (device->services, dev_disconn_service,NULL ); -while (device->services !=NULL ) {struct btd_service *service = device->services->data;
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 4/21 audio/sink: Reduce dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/a2dp.c | 5 ++-- profiles/audio/avrcp.c | 2 +- profiles/audio/device.c | 4 +-- profiles/audio/manager.c | 20 ++------------ profiles/audio/sink.c | 68 +++++++++++++++++++++++++--------------------- profiles/audio/sink.h | 14 +++++----- profiles/audio/transport.c | 4 +-- 7 files changed, 55 insertions(+), 62 deletions(-)
profiles/audio/a2dp.c +3 -2
@@ -403,6 +403,7 @@ static void stream_state_changed(struct avdtp_stream *stream,static gboolean auto_config (gpointer data) {struct a2dp_setup *setup = data; +struct audio_device *dev = setup->dev;/* Check if configuration was aborted */ if (setup->sep->stream ==NULL )
@@ -415,7 +416,7 @@ static gboolean auto_config(gpointer data) stream_state_changed, setup->sep);if (setup->sep->type ==AVDTP_SEP_TYPE_SOURCE ) -sink_new_stream (setup->dev, setup->session, setup->stream); +sink_new_stream (dev->sink, setup->session, setup->stream);else source_new_stream (setup->dev, setup->session, setup->stream);
@@ -618,7 +619,7 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,/* Notify D-Bus interface of the new stream */ if (a2dp_sep->type ==AVDTP_SEP_TYPE_SOURCE ) -sink_new_stream (dev, session, setup->stream); +sink_new_stream (dev->sink, session, setup->stream);else source_new_stream (dev, session, setup->stream);
profiles/audio/avrcp.c +1 -1
@@ -3425,7 +3425,7 @@ static struct avrcp *session_create(struct avrcp_server *server, session->target = TRUE; else if (dev->source && !dev->sink) session->target = FALSE; - else if (dev->sink && sink_is_active(dev)) + else if (dev->sink && sink_is_active(dev->sink)) session->target = TRUE; else session->target = FALSE;
profiles/audio/device.c +2 -2
@@ -154,7 +154,7 @@ static void disconnect_cb(struct btd_device *btd_dev, gboolean removal, sink =btd_device_get_service (btd_dev,A2DP_SINK_UUID );if (sink) -sink_disconnect (dev, TRUE); +sink_disconnect (sink, TRUE);else priv->disconnecting = FALSE; }
@@ -261,7 +261,7 @@ void audio_device_unregister(struct audio_device *device)DBG ("%s" ,device_get_path (device->btd_dev));if (device->sink) -sink_unregister (device); +sink_unregister (device->sink);if (device->source)source_unregister (device);
profiles/audio/manager.c +3 -17
@@ -153,7 +153,7 @@ static int avrcp_target_probe(struct btd_service *service) audio_dev->control = service; -if (audio_dev->sink &&sink_is_active (audio_dev)) +if (audio_dev->sink &&sink_is_active (audio_dev->sink))avrcp_connect (audio_dev);return 0 ;
@@ -218,34 +218,20 @@ static int a2dp_sink_connect(struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev); -struct audio_device *audio_dev;DBG ("path %s" , path); - audio_dev =get_audio_dev (dev); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - -return sink_connect (audio_dev); +return sink_connect (service); }static int a2dp_sink_disconnect (struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev); -struct audio_device *audio_dev;DBG ("path %s" , path); - audio_dev =get_audio_dev (dev); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - -return sink_disconnect (audio_dev, FALSE); +return sink_disconnect (service, FALSE); }static int avrcp_target_connect (struct btd_service *service)
profiles/audio/sink.c +37 -31
188 lines not on this page · raw message
profiles/audio/sink.h +7 -7
@@ -29,22 +29,22 @@ typedef enum {SINK_STATE_PLAYING , } sink_state_t; -typedef void (*sink_state_cb ) (struct audio_device *dev, +typedef void (*sink_state_cb ) (struct btd_service *service,sink_state_t old_state,sink_state_t new_state,void *user_data);struct btd_service ; -unsigned int sink_add_state_cb (struct audio_device *dev,sink_state_cb cb, +unsigned int sink_add_state_cb (struct btd_service *service,sink_state_cb cb,void *user_data);gboolean sink_remove_state_cb (unsigned int id);int sink_init (struct audio_device *dev,struct btd_service *service); -void sink_unregister (struct audio_device *dev); -gboolean sink_is_active (struct audio_device *dev); -int sink_connect (struct audio_device *dev); -gboolean sink_new_stream (struct audio_device *dev,struct avdtp *session, +void sink_unregister (struct btd_service *service); +gboolean sink_is_active (struct btd_service *service); +int sink_connect (struct btd_service *service); +gboolean sink_new_stream (struct btd_service *service,struct avdtp *session,struct avdtp_stream *stream);gboolean sink_setup_stream (struct btd_service *service,struct avdtp *session); -int sink_disconnect (struct audio_device *dev,gboolean shutdown); +int sink_disconnect (struct btd_service *service,gboolean shutdown);
profiles/audio/transport.c +2 -2
@@ -744,7 +744,7 @@ static void transport_update_playing(struct media_transport *transport,transport_set_state (transport,TRANSPORT_STATE_PENDING ); } -static void sink_state_changed (struct audio_device *dev, +static void sink_state_changed (struct btd_service *service,sink_state_t old_state,sink_state_t new_state,void *user_data)
@@ -804,7 +804,7 @@ struct media_transport *media_transport_create(struct audio_device *device,if (strcasecmp (uuid,A2DP_SOURCE_UUID ) ==0 ) { a2dp->volume =-1 ; - transport->sink_watch =sink_add_state_cb (device, + transport->sink_watch =sink_add_state_cb (device->sink, sink_state_changed, transport); }else {
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 5/21 audio/source: Reduce dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/a2dp.c | 4 +-- profiles/audio/device.c | 2 +- profiles/audio/manager.c | 18 ++----------- profiles/audio/source.c | 65 +++++++++++++++++++++++++--------------------- profiles/audio/source.h | 14 +++++----- profiles/audio/transport.c | 5 ++-- 6 files changed, 50 insertions(+), 58 deletions(-)
profiles/audio/a2dp.c +2 -2
@@ -418,7 +418,7 @@ static gboolean auto_config(gpointer data)if (setup->sep->type ==AVDTP_SEP_TYPE_SOURCE )sink_new_stream (dev->sink, setup->session, setup->stream);else -source_new_stream (setup->dev, setup->session, setup->stream); +source_new_stream (dev->source, setup->session, setup->stream); done:if (setup->setconf_cb)
@@ -621,7 +621,7 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,if (a2dp_sep->type ==AVDTP_SEP_TYPE_SOURCE )sink_new_stream (dev->sink, session, setup->stream);else -source_new_stream (dev, session, setup->stream); +source_new_stream (dev->source, session, setup->stream);/* Notify Endpoint */ if (a2dp_sep->endpoint) {
profiles/audio/device.c +1 -1
@@ -264,7 +264,7 @@ void audio_device_unregister(struct audio_device *device)sink_unregister (device->sink);if (device->source) -source_unregister (device); +source_unregister (device->source);if (device->control)control_unregister (device);
profiles/audio/manager.c +2 -16
@@ -184,34 +184,20 @@ static int a2dp_source_connect(struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev); -struct audio_device *audio_dev;DBG ("path %s" , path); - audio_dev =get_audio_dev (dev); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - -return source_connect (audio_dev); +return source_connect (service); }static int a2dp_source_disconnect (struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev); -struct audio_device *audio_dev;DBG ("path %s" , path); - audio_dev =get_audio_dev (dev); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - -return source_disconnect (audio_dev, FALSE); +return source_disconnect (service, FALSE); }static int a2dp_sink_connect (struct btd_service *service)
profiles/audio/source.c +35 -30
181 lines not on this page · raw message
profiles/audio/source.h +7 -7
@@ -30,22 +30,22 @@ typedef enum {SOURCE_STATE_PLAYING , } source_state_t; -typedef void (*source_state_cb ) (struct audio_device *dev, +typedef void (*source_state_cb ) (struct btd_service *service,source_state_t old_state,source_state_t new_state,void *user_data);struct btd_service ; -unsigned int source_add_state_cb (struct audio_device *dev,source_state_cb cb, -void *user_data); +unsigned int source_add_state_cb (struct btd_service *service, +source_state_cb cb,void *user_data);gboolean source_remove_state_cb (unsigned int id);int source_init (struct audio_device *dev,struct btd_service *service); -void source_unregister (struct audio_device *dev); -int source_connect (struct audio_device *dev); -gboolean source_new_stream (struct audio_device *dev,struct avdtp *session, +void source_unregister (struct btd_service *service); +int source_connect (struct btd_service *service); +gboolean source_new_stream (struct btd_service *service,struct avdtp *session,struct avdtp_stream *stream);gboolean source_setup_stream (struct btd_service *service,struct avdtp *session); -int source_disconnect (struct audio_device *dev,gboolean shutdown); +int source_disconnect (struct btd_service *service,gboolean shutdown);
profiles/audio/transport.c +3 -2
@@ -757,7 +757,7 @@ static void sink_state_changed(struct btd_service *service,transport_update_playing (transport, FALSE); } -static void source_state_changed (struct audio_device *dev, +static void source_state_changed (struct btd_service *service,source_state_t old_state,source_state_t new_state,void *user_data)
@@ -810,7 +810,8 @@ struct media_transport *media_transport_create(struct audio_device *device, }else { a2dp->volume =127 ;avrcp_set_volume (device, a2dp->volume); - transport->source_watch =source_add_state_cb (device, + transport->source_watch =source_add_state_cb ( + device->source, source_state_changed, transport); }
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 6/21 audio/control: Reduce dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/avrcp.c | 39 +++++++++++++++++++++++++++++-------- profiles/audio/control.c | 50 +++++++++++++----------------------------------- profiles/audio/control.h | 13 ++++--------- profiles/audio/device.c | 2 +- profiles/audio/manager.c | 18 ++--------------- 5 files changed, 51 insertions(+), 71 deletions(-)
profiles/audio/avrcp.c +31 -8
@@ -47,8 +47,9 @@#include <gdbus/gdbus.h> #include "lib/uuid.h" -#include "../src/adapter.h" -#include "../src/device.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/service.h" #include "log.h" #include "error.h"
@@ -3282,6 +3283,7 @@ static void session_tg_init_control(struct avrcp *session) {struct avrcp_server *server = session->server;struct avrcp_player *player; +struct btd_service *service;if (session->version <0x0103 )return ;
@@ -3314,7 +3316,10 @@ static void session_tg_init_control(struct avrcp *session)avrcp_register_notification (session,AVRCP_EVENT_VOLUME_CHANGED ); -control_remote_connected (session->dev,0 ); + service =btd_device_get_service (session->dev->btd_dev, +AVRCP_REMOTE_UUID ); +if (service !=NULL ) +btd_service_connecting_complete (service,0 ); }static void session_ct_init_browsing (struct avrcp *session)
@@ -3329,6 +3334,7 @@ static void session_ct_init_browsing(struct avrcp *session)static void session_ct_init_control (struct avrcp *session) {struct avrcp_player *player; +struct btd_service *service;DBG ("%p version 0x%04x" , session, session->version);
@@ -3340,7 +3346,11 @@ static void session_ct_init_control(struct avrcp *session)if (session->version >=0x0104 ) session->supported_events = (1 <<AVRCP_EVENT_VOLUME_CHANGED ); -control_target_connected (session->dev,0 ); + + service =btd_device_get_service (session->dev->btd_dev, +AVRCP_TARGET_UUID ); +if (service !=NULL ) +btd_service_connecting_complete (service,0 ); player =create_ct_player (session,0 );if (player ==NULL )
@@ -3373,30 +3383,43 @@ static void session_destroy(struct avrcp *session)static void session_tg_destroy (struct avrcp *session) {struct avrcp_player *player = session->player; +struct btd_service *service;DBG ("%p" , session);if (player !=NULL ) player->sessions =g_slist_remove (player->sessions, session); + service =btd_device_get_service (session->dev->btd_dev, +AVRCP_REMOTE_UUID ); +if (service ==NULL ) +return session_destroy (session); +if (session->control_id ==0 ) -control_remote_connected (session->dev, -EIO ); +btd_service_connecting_complete (service, -EIO );else -control_remote_disconnected (session->dev,0 ); +btd_service_disconnecting_complete (service,0 );session_destroy (session); }static void session_ct_destroy (struct avrcp *session) { +struct btd_service *service; +DBG ("%p" , session);g_slist_free_full (session->players, player_destroy); + service =btd_device_get_service (session->dev->btd_dev, +AVRCP_TARGET_UUID ); +if (service ==NULL ) +return session_destroy (session); +if (session->control_id ==0 ) -control_target_connected (session->dev, -EIO ); +btd_service_connecting_complete (service, -EIO );else -control_target_disconnected (session->dev,0 ); +btd_service_disconnecting_complete (service,0 );session_destroy (session); }
profiles/audio/control.c +13 -37
103 lines not on this page · raw message
profiles/audio/control.h +4 -9
@@ -28,13 +28,8 @@ struct btd_service;int control_init_target (struct audio_device *dev,struct btd_service *service);int control_init_remote (struct audio_device *dev,struct btd_service *service); -void control_unregister (struct audio_device *dev); -gboolean control_is_active (struct audio_device *dev); +void control_unregister (struct btd_service *service); +gboolean control_is_active (struct btd_service *service); -int control_connect (struct audio_device *dev); -int control_disconnect (struct audio_device *dev); - -void control_target_connected (struct audio_device *dev,int err); -void control_target_disconnected (struct audio_device *dev,int err); -void control_remote_connected (struct audio_device *dev,int err); -void control_remote_disconnected (struct audio_device *dev,int err); +int control_connect (struct btd_service *service); +int control_disconnect (struct btd_service *service);
profiles/audio/device.c +1 -1
@@ -267,7 +267,7 @@ void audio_device_unregister(struct audio_device *device)source_unregister (device->source);if (device->control) -control_unregister (device); +control_unregister (device->control);device_free (device); }
profiles/audio/manager.c +2 -16
@@ -224,34 +224,20 @@ static int avrcp_target_connect(struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev); -struct audio_device *audio_dev;DBG ("path %s" , path); - audio_dev =get_audio_dev (dev); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - -return control_connect (audio_dev); +return control_connect (service); }static int avrcp_target_disconnect (struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev); -struct audio_device *audio_dev;DBG ("path %s" , path); - audio_dev =get_audio_dev (dev); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - -return control_disconnect (audio_dev); +return control_disconnect (service); } static int a2dp_source_server_probe(struct btd_profile *p,
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 7/21 audio/AVCTP: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/avctp.c | 69 +++++++++++++++++------------------------------- profiles/audio/avctp.h | 12 +++++---- profiles/audio/avrcp.c | 35 ++++++++++++------------ profiles/audio/control.c | 13 ++++----- profiles/audio/device.c | 9 ++++--- 5 files changed, 62 insertions(+), 76 deletions(-)
profiles/audio/avctp.c +24 -45
@@ -47,14 +47,13 @@#include <btio/btio.h> #include "lib/uuid.h" -#include "adapter.h" -#include "../src/device.h" +#include "src/adapter.h" +#include "src/device.h" #include "log.h" #include "error.h" #include "uinput.h" #include "manager.h" -#include "device.h" #include "avctp.h" #include "avrcp.h"
@@ -119,8 +118,9 @@ struct avc_header {struct avctp_state_callback {avctp_state_cb cb; -struct audio_device *dev; +struct btd_device *dev;unsigned int id; +void *user_data; };struct avctp_server {
@@ -530,24 +530,17 @@ static void avctp_disconnected(struct avctp *session)static void avctp_set_state (struct avctp *session,avctp_state_t new_state) {GSList *l; -struct audio_device *dev;avctp_state_t old_state = session->state; - dev =manager_get_audio_device (session->device, FALSE); -if (dev ==NULL ) { -error ("%s(): No matching audio device" , __func__); -return ; - } - session->state = new_state;for (l = callbacks; l !=NULL ; l = l->next) {struct avctp_state_callback *cb = l->data; -if (cb->dev && cb->dev != dev) +if (cb->dev && cb->dev != session->device)continue ; - cb->cb (dev, old_state, new_state); + cb->cb (session->device, old_state, new_state, cb->user_data); }switch (new_state) {
@@ -1059,12 +1052,9 @@ static int uinput_create(char *name)static void init_uinput (struct avctp *session) { -struct audio_device *dev;char address[18 ], name[248 +1 ]; - dev =manager_get_audio_device (session->device, FALSE); - -device_get_name (dev->btd_dev, name,sizeof (name)); +device_get_name (session->device, name,sizeof (name));if (g_str_equal (name,"Nokia CK-20W" )) { session->key_quirks[AVC_FORWARD ] |=QUIRK_NO_RELEASE ; session->key_quirks[AVC_BACKWARD ] |=QUIRK_NO_RELEASE ;
@@ -1296,7 +1286,7 @@ static struct avctp *avctp_get_internal(struct btd_device *device) }static void avctp_control_confirm (struct avctp *session,GIOChannel *chan, -struct audio_device *dev) +struct btd_device *dev) {const bdaddr_t *src;const bdaddr_t *dst;
@@ -1310,8 +1300,8 @@ static void avctp_control_confirm(struct avctp *session, GIOChannel *chan,avctp_set_state (session,AVCTP_STATE_CONNECTING ); session->control =avctp_channel_create (session, chan,NULL ); - src =adapter_get_address (device_get_adapter (dev->btd_dev)); - dst =device_get_address (dev->btd_dev); + src =adapter_get_address (device_get_adapter (dev)); + dst =device_get_address (dev); session->auth_id = btd_request_authorization(src, dst, AVRCP_TARGET_UUID,
@@ -1328,7 +1318,7 @@ drop: }static void avctp_browsing_confirm (struct avctp *session,GIOChannel *chan, -struct audio_device *dev) +struct btd_device *dev) {GError *err =NULL ;
@@ -1351,7 +1341,6 @@ static void avctp_browsing_confirm(struct avctp *session, GIOChannel *chan,static void avctp_confirm_cb (GIOChannel *chan,gpointer data) {struct avctp *session; -struct audio_device *dev;char address[18 ];bdaddr_t src, dst;GError *err =NULL ;
@@ -1381,34 +1370,22 @@ static void avctp_confirm_cb(GIOChannel *chan, gpointer data)if (session ==NULL )return ; - dev =manager_get_audio_device (device, TRUE); -if (!dev) { -error ("Unable to get audio device object for %s" , address); - goto drop; - } +if (btd_device_get_service (device,AVRCP_REMOTE_UUID ) ==NULL ) +btd_device_add_uuid (device,AVRCP_REMOTE_UUID ); -if (dev->control ==NULL ) { -btd_device_add_uuid (dev->btd_dev,AVRCP_REMOTE_UUID ); -btd_device_add_uuid (dev->btd_dev,AVRCP_TARGET_UUID ); - -if (dev->control ==NULL ) - goto drop; - } +if (btd_device_get_service (device,AVRCP_TARGET_UUID ) ==NULL ) +btd_device_add_uuid (device,AVRCP_TARGET_UUID );switch (psm) {case AVCTP_CONTROL_PSM : -avctp_control_confirm (session, chan, dev); +avctp_control_confirm (session, chan, device);break ;case AVCTP_BROWSING_PSM : -avctp_browsing_confirm (session, chan, dev); +avctp_browsing_confirm (session, chan, device);break ; }return ; - -drop: -if (psm ==AVCTP_CONTROL_PSM ) -avctp_set_state (session,AVCTP_STATE_DISCONNECTED ); } static GIOChannel *avctp_server_socket(const bdaddr_t *src, gboolean master,
@@ -1721,7 +1698,8 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code, func, user_data); } -unsigned int avctp_add_state_cb (struct audio_device *dev,avctp_state_cb cb) +unsigned int avctp_add_state_cb (struct btd_device *dev,avctp_state_cb cb, +void *user_data) {struct avctp_state_callback *state_cb;static unsigned int id =0 ;
@@ -1730,6 +1708,7 @@ unsigned int avctp_add_state_cb(struct audio_device *dev, avctp_state_cb cb) state_cb->cb = cb; state_cb->dev = dev; state_cb->id = ++id; + state_cb->user_data = user_data; callbacks =g_slist_append (callbacks, state_cb);
@@ -1919,13 +1898,13 @@ gboolean avctp_unregister_browsing_pdu_handler(unsigned int id)return FALSE; } -struct avctp *avctp_connect (struct audio_device *device) +struct avctp *avctp_connect (struct btd_device *device) {struct avctp *session;GError *err =NULL ;GIOChannel *io; - session =avctp_get_internal (device->btd_dev); + session =avctp_get_internal (device);if (!session)return NULL ;
@@ -1999,9 +1978,9 @@ void avctp_disconnect(struct avctp *session)avctp_set_state (session,AVCTP_STATE_DISCONNECTED ); } -struct avctp *avctp_get (struct audio_device *device) +struct avctp *avctp_get (struct btd_device *device) { -return avctp_get_internal (device->btd_dev); +return avctp_get_internal (device); }bool avctp_is_initiator (struct avctp *session)
profiles/audio/avctp.h +7 -5
@@ -90,9 +90,10 @@ typedef enum {AVCTP_STATE_BROWSING_CONNECTED } avctp_state_t; -typedef void (*avctp_state_cb ) (struct audio_device *dev, +typedef void (*avctp_state_cb ) (struct btd_device *dev,avctp_state_t old_state, -avctp_state_t new_state); +avctp_state_t new_state, +void *user_data); typedef bool (*avctp_passthrough_cb) (struct avctp *session, uint8_t op, bool pressed,
@@ -112,14 +113,15 @@ typedef size_t (*avctp_browsing_pdu_cb) (struct avctp *session, uint8_t *operands, size_t operand_count, void *user_data); -unsigned int avctp_add_state_cb (struct audio_device *dev,avctp_state_cb cb); +unsigned int avctp_add_state_cb (struct btd_device *dev,avctp_state_cb cb, +void *user_data);gboolean avctp_remove_state_cb (unsigned int id);int avctp_register (struct btd_adapter *adapter,gboolean master);void avctp_unregister (struct btd_adapter *adapter); -struct avctp *avctp_connect (struct audio_device *device); -struct avctp *avctp_get (struct audio_device *device); +struct avctp *avctp_connect (struct btd_device *device); +struct avctp *avctp_get (struct btd_device *device);bool avctp_is_initiator (struct avctp *session);int avctp_connect_browsing (struct avctp *session);void avctp_disconnect (struct avctp *session);
profiles/audio/avrcp.c +18 -17
@@ -3251,12 +3251,12 @@ static void avrcp_get_capabilities(struct avrcp *session) session); } -static struct avrcp *find_session (GSList *list,struct audio_device *dev) +static struct avrcp *find_session (GSList *list,struct btd_device *dev) {for (; list; list = list->next) {struct avrcp *session = list->data; -if (session->dev == dev) +if (session->dev->btd_dev == dev)return session; }
@@ -3425,16 +3425,17 @@ static void session_ct_destroy(struct avrcp *session) }static struct avrcp *session_create (struct avrcp_server *server, -struct audio_device *dev) +struct btd_device *device) {struct avrcp *session;const sdp_record_t *rec;sdp_list_t *list;sdp_profile_desc_t *desc; +struct audio_device *dev =manager_get_audio_device (device, FALSE); session = g_new0(struct avrcp, 1); session->server = server; - session->conn =avctp_connect (dev); + session->conn =avctp_connect (device); session->dev = dev; server->sessions =g_slist_append (server->sessions, session);
@@ -3458,16 +3459,16 @@ static struct avrcp *session_create(struct avrcp_server *server, session->init_browsing = session_tg_init_browsing; session->destroy = session_tg_destroy; - rec =btd_device_get_record (dev->btd_dev,AVRCP_REMOTE_UUID ); + rec =btd_device_get_record (device,AVRCP_REMOTE_UUID );if (rec ==NULL ) -btd_device_add_uuid (dev->btd_dev,AVRCP_REMOTE_UUID ); +btd_device_add_uuid (device,AVRCP_REMOTE_UUID ); }else { session->init_control = session_ct_init_control; session->init_browsing = session_ct_init_browsing; session->destroy = session_ct_destroy; - rec =btd_device_get_record (dev->btd_dev,AVRCP_TARGET_UUID ); + rec =btd_device_get_record (device,AVRCP_TARGET_UUID );if (rec ==NULL ) -btd_device_add_uuid (dev->btd_dev,AVRCP_TARGET_UUID ); +btd_device_add_uuid (device,AVRCP_TARGET_UUID ); }if (rec ==NULL )
@@ -3485,17 +3486,17 @@ static struct avrcp *session_create(struct avrcp_server *server,return session; } -static void state_changed (struct audio_device *dev,avctp_state_t old_state, -avctp_state_t new_state) +static void state_changed (struct btd_device *device,avctp_state_t old_state, +avctp_state_t new_state,void *user_data) {struct avrcp_server *server;struct avrcp *session; - server =find_server (servers,device_get_adapter (dev->btd_dev)); + server =find_server (servers,device_get_adapter (device));if (!server)return ; - session =find_session (server->sessions, dev); + session =find_session (server->sessions, device);switch (new_state) {case AVCTP_STATE_DISCONNECTED :
@@ -3509,7 +3510,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,if (session !=NULL )break ; -session_create (server, dev); +session_create (server, device);break ;case AVCTP_STATE_CONNECTED :
@@ -3538,7 +3539,7 @@ gboolean avrcp_connect(struct audio_device *dev) {struct avctp *session; - session =avctp_connect (dev); + session =avctp_connect (dev->btd_dev);if (session)return FALSE;
@@ -3549,7 +3550,7 @@ void avrcp_disconnect(struct audio_device *dev) {struct avctp *session; - session =avctp_get (dev); + session =avctp_get (dev->btd_dev);if (!session)return ;
@@ -3582,7 +3583,7 @@ static struct avrcp_server *avrcp_server_register(struct btd_adapter *adapter, servers =g_slist_append (servers, server);if (!avctp_id) - avctp_id =avctp_add_state_cb (NULL , state_changed); + avctp_id =avctp_add_state_cb (NULL , state_changed,NULL );return server; }
@@ -3791,7 +3792,7 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)if (server ==NULL )return -EINVAL ; - session =find_session (server->sessions, dev); + session =find_session (server->sessions, dev->btd_dev);if (session ==NULL )return -ENOTCONN ;
profiles/audio/control.c +7 -6
@@ -69,12 +69,12 @@ struct control {unsigned int avctp_id; }; -static void state_changed (struct audio_device *dev,avctp_state_t old_state, -avctp_state_t new_state) +static void state_changed (struct btd_device *dev,avctp_state_t old_state, +avctp_state_t new_state,void *user_data) { +struct control *control = user_data;DBusConnection *conn =btd_get_dbus_connection (); -struct control *control =btd_service_get_user_data (dev->control); -const char *path =device_get_path (dev->btd_dev); +const char *path =device_get_path (dev);switch (new_state) {case AVCTP_STATE_DISCONNECTED :
@@ -110,7 +110,7 @@ int control_connect(struct btd_service *service)if (!control->target)return -ENOTSUP ; - control->session =avctp_connect (control->dev); + control->session =avctp_connect (control->dev->btd_dev);if (!control->session)return -EIO ;
@@ -287,7 +287,8 @@ static struct control *control_init(struct audio_device *dev) control = g_new0(struct control, 1); control->dev = dev; - control->avctp_id =avctp_add_state_cb (dev, state_changed); + control->avctp_id =avctp_add_state_cb (dev->btd_dev, state_changed, + control);return control; }
profiles/audio/device.c +6 -3
@@ -198,9 +198,11 @@ static void device_sink_cb(struct audio_device *dev, } } -static void device_avctp_cb (struct audio_device *dev,avctp_state_t old_state, -avctp_state_t new_state) +static void device_avctp_cb (struct btd_device *device,avctp_state_t old_state, +avctp_state_t new_state,void *user_data) { +struct audio_device *dev = user_data; +if (!dev->control)return ;
@@ -251,7 +253,8 @@ struct audio_device *audio_device_register(struct btd_device *device) NULL); dev->priv->service_cb_id =btd_service_add_state_cb (service_cb, dev); dev->priv->avdtp_callback_id =avdtp_add_state_cb (dev, device_avdtp_cb); - dev->priv->avctp_callback_id =avctp_add_state_cb (dev, device_avctp_cb); + dev->priv->avctp_callback_id =avctp_add_state_cb (device, + device_avctp_cb, dev);return dev; }
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 8/21 audio/AVDTP: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/avdtp.c | 97 +++++++++++++++++++++------------------------- profiles/audio/avdtp.h | 13 ++++--- profiles/audio/device.c | 10 +++-- profiles/audio/sink.c | 24 ++++++------ profiles/audio/source.c | 31 +++++++-------- profiles/audio/transport.c | 2 +- 6 files changed, 87 insertions(+), 90 deletions(-)
profiles/audio/avdtp.c +44 -53
@@ -47,10 +47,9 @@#include "log.h" #include "lib/uuid.h" -#include "../src/adapter.h" -#include "../src/device.h" +#include "src/adapter.h" +#include "src/device.h" -#include "device.h" #include "manager.h" #include "control.h" #include "avdtp.h"
@@ -356,8 +355,9 @@ struct stream_callback {struct avdtp_state_callback {avdtp_session_state_cb cb; -struct audio_device *dev; +struct btd_device *dev;unsigned int id; +void *user_data; };struct avdtp_stream {
@@ -714,24 +714,17 @@ static void avdtp_set_state(struct avdtp *session, avdtp_session_state_t new_state) {GSList *l; -struct audio_device *dev;avdtp_session_state_t old_state = session->state; session->state = new_state; - dev =manager_get_audio_device (avdtp_get_device (session), FALSE); -if (dev ==NULL ) { -error ("%s(): No matching audio device" , __func__); -return ; - } -for (l = avdtp_callbacks; l !=NULL ; l = l->next) {struct avdtp_state_callback *cb = l->data; -if (dev != cb->dev) +if (session->device != cb->dev)continue ; - cb->cb (dev, session, old_state, new_state); + cb->cb (cb->dev, session, old_state, new_state, cb->user_data); } }
@@ -1155,21 +1148,27 @@ static void avdtp_free(void *data)static gboolean disconnect_timeout (gpointer user_data) {struct avdtp *session = user_data; -struct audio_device *dev; +struct btd_service *service;gboolean stream_setup; session->dc_timer =0 ; stream_setup = session->stream_setup; session->stream_setup = FALSE; - dev =manager_get_audio_device (session->device, FALSE); -if (dev && dev->sink && stream_setup) -sink_setup_stream (dev->sink, session); -else if (dev && dev->source && stream_setup) -source_setup_stream (dev->source, session); -else -connection_lost (session,ETIMEDOUT ); + service =btd_device_get_service (session->device,A2DP_SINK_UUID ); +if (service && stream_setup) { +sink_setup_stream (service, session); +return FALSE; + } + + service =btd_device_get_service (session->device,A2DP_SOURCE_UUID ); +if (service && stream_setup) { +source_setup_stream (service, session); +return FALSE; + } + +connection_lost (session,ETIMEDOUT );return FALSE; }
@@ -1458,7 +1457,7 @@ static gboolean avdtp_setconf_cmd(struct avdtp *session, uint8_t transaction,struct avdtp_local_sep *sep;struct avdtp_stream *stream;uint8_t err, category =0x00 ; -struct audio_device *dev; +struct btd_service *service;GSList *l;if (size <sizeof (struct setconf_req )) {
@@ -1477,18 +1476,15 @@ static gboolean avdtp_setconf_cmd(struct avdtp *session, uint8_t transaction, goto failed; } - dev =manager_get_audio_device (avdtp_get_device (session), FALSE); -if (!dev) { -error ("Unable to get a audio device object" ); - err =AVDTP_BAD_STATE ; - goto failed; - } -switch (sep->info.type) {case AVDTP_SEP_TYPE_SOURCE : -if (!dev->sink) { -btd_device_add_uuid (dev->btd_dev,A2DP_SINK_UUID ); -if (!dev->sink) { + service =btd_device_get_service (session->device, +A2DP_SINK_UUID ); +if (service ==NULL ) { +btd_device_add_uuid (session->device,A2DP_SINK_UUID ); + service =btd_device_get_service (session->device, +A2DP_SINK_UUID ); +if (service ==NULL ) {error ("Unable to get a audio sink object" ); err =AVDTP_BAD_STATE ; goto failed;
@@ -1496,9 +1492,13 @@ static gboolean avdtp_setconf_cmd(struct avdtp *session, uint8_t transaction, }break ;case AVDTP_SEP_TYPE_SINK : -if (!dev->source) { -btd_device_add_uuid (dev->btd_dev,A2DP_SOURCE_UUID ); -if (!dev->source) { + service =btd_device_get_service (session->device, +A2DP_SOURCE_UUID ); +if (service ==NULL ) { +btd_device_add_uuid (session->device,A2DP_SOURCE_UUID ); + service =btd_device_get_service (session->device, +A2DP_SOURCE_UUID ); +if (service ==NULL ) {error ("Unable to get a audio source object" ); err =AVDTP_BAD_STATE ; goto failed;
@@ -2348,11 +2348,11 @@ static struct avdtp *avdtp_get_internal(struct btd_device *device)return session; } -struct avdtp *avdtp_get (struct audio_device *device) +struct avdtp *avdtp_get (struct btd_device *device) {struct avdtp *session; - session =avdtp_get_internal (device->btd_dev); + session =avdtp_get_internal (device);if (!session)return NULL ;
@@ -2465,7 +2465,6 @@ static void auth_cb(DBusError *derr, void *user_data)static void avdtp_confirm_cb (GIOChannel *chan,gpointer data) {struct avdtp *session; -struct audio_device *dev;char address[18 ];bdaddr_t src, dst;GError *err =NULL ;
@@ -2514,16 +2513,7 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data) goto drop; } - dev =manager_get_audio_device (device, FALSE); -if (!dev) { - dev =manager_get_audio_device (device, TRUE); -if (!dev) { -error ("Unable to get audio device object for %s" , - address); - goto drop; - } -btd_device_add_uuid (dev->btd_dev,ADVANCED_AUDIO_UUID ); - } +btd_device_add_uuid (device,ADVANCED_AUDIO_UUID ); session->io =g_io_channel_ref (chan);avdtp_set_state (session,AVDTP_SESSION_STATE_CONNECTING );
@@ -3186,16 +3176,16 @@ static gboolean avdtp_parse_rej(struct avdtp *session, } } -gboolean avdtp_is_connected (struct audio_device *device) +gboolean avdtp_is_connected (struct btd_device *device) {struct avdtp_server *server;struct avdtp *session; - server =find_server (servers,device_get_adapter (device->btd_dev)); + server =find_server (servers,device_get_adapter (device));if (!server)return FALSE; - session =find_session (server->sessions, device->btd_dev); + session =find_session (server->sessions, device);if (!session)return FALSE;
@@ -3922,8 +3912,8 @@ void avdtp_set_device_disconnect(struct avdtp *session, gboolean dev_dc) session->device_disconnect = dev_dc; } -unsigned int avdtp_add_state_cb (struct audio_device *dev, -avdtp_session_state_cb cb) +unsigned int avdtp_add_state_cb (struct btd_device *dev, +avdtp_session_state_cb cb,void *user_data) {struct avdtp_state_callback *state_cb;static unsigned int id =0 ;
@@ -3932,6 +3922,7 @@ unsigned int avdtp_add_state_cb(struct audio_device *dev, state_cb->cb = cb; state_cb->dev = dev; state_cb->id = ++id; + state_cb->user_data = user_data; avdtp_callbacks =g_slist_append (avdtp_callbacks, state_cb);
profiles/audio/avdtp.h +7 -6
@@ -116,10 +116,11 @@ struct avdtp_media_codec_capability {#error "Unknown byte order"#endif -typedef void (*avdtp_session_state_cb ) (struct audio_device *dev, +typedef void (*avdtp_session_state_cb ) (struct btd_device *dev,struct avdtp *session,avdtp_session_state_t old_state, -avdtp_session_state_t new_state); +avdtp_session_state_t new_state, +void *user_data); typedef void (*avdtp_stream_state_cb) (struct avdtp_stream *stream, avdtp_state_t old_state,
@@ -212,12 +213,12 @@ 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 audio_device *device); +struct avdtp *avdtp_get (struct btd_device *device);void avdtp_unref (struct avdtp *session);struct avdtp *avdtp_ref (struct avdtp *session); -gboolean avdtp_is_connected (struct audio_device *device); +gboolean avdtp_is_connected (struct btd_device *device);struct avdtp_service_capability *avdtp_service_cap_new (uint8_t category,void *data,int size);
@@ -259,8 +260,8 @@ gboolean avdtp_stream_has_capabilities(struct avdtp_stream *stream,struct avdtp_remote_sep *avdtp_stream_get_remote_sep (struct avdtp_stream *stream); -unsigned int avdtp_add_state_cb (struct audio_device *dev, -avdtp_session_state_cb cb); +unsigned int avdtp_add_state_cb (struct btd_device *dev, +avdtp_session_state_cb cb,void *user_data);gboolean avdtp_remove_state_cb (unsigned int id);
profiles/audio/device.c +7 -3
@@ -159,10 +159,13 @@ static void disconnect_cb(struct btd_device *btd_dev, gboolean removal, priv->disconnecting = FALSE; } -static void device_avdtp_cb (struct audio_device *dev,struct avdtp *session, +static void device_avdtp_cb (struct btd_device *device,struct avdtp *session,avdtp_session_state_t old_state, -avdtp_session_state_t new_state) +avdtp_session_state_t new_state, +void *user_data) { +struct audio_device *dev = user_data; +if (!dev->control)return ;
@@ -252,7 +255,8 @@ struct audio_device *audio_device_register(struct btd_device *device) disconnect_cb, dev, NULL); dev->priv->service_cb_id =btd_service_add_state_cb (service_cb, dev); - dev->priv->avdtp_callback_id =avdtp_add_state_cb (dev, device_avdtp_cb); + dev->priv->avdtp_callback_id =avdtp_add_state_cb (device, + device_avdtp_cb, dev); dev->priv->avctp_callback_id =avctp_add_state_cb (device, device_avctp_cb, dev);
profiles/audio/sink.c +13 -11
@@ -85,9 +85,9 @@ static char *str_state[] = { "SINK_STATE_PLAYING", }; -static void sink_set_state (struct btd_service *service,sink_state_t new_state) +static void sink_set_state (struct sink *sink,sink_state_t new_state) { -struct sink *sink =btd_service_get_user_data (service); +struct btd_service *service = sink->service;struct btd_device *dev =btd_service_get_device (service);sink_state_t old_state = sink->state;GSList *l;
@@ -115,19 +115,20 @@ static void sink_set_state(struct btd_service *service, sink_state_t new_state) } } -static void avdtp_state_callback (struct audio_device *dev, +static void avdtp_state_callback (struct btd_device *dev,struct avdtp *session,avdtp_session_state_t old_state, -avdtp_session_state_t new_state) +avdtp_session_state_t new_state, +void *user_data) { -struct sink *sink =btd_service_get_user_data (dev->sink); +struct sink *sink = user_data;switch (new_state) {case AVDTP_SESSION_STATE_DISCONNECTED : -sink_set_state (dev->sink,SINK_STATE_DISCONNECTED ); +sink_set_state (sink,SINK_STATE_DISCONNECTED );break ;case AVDTP_SESSION_STATE_CONNECTING : -sink_set_state (dev->sink,SINK_STATE_CONNECTING ); +sink_set_state (sink,SINK_STATE_CONNECTING );break ;case AVDTP_SESSION_STATE_CONNECTED :break ;
@@ -166,10 +167,10 @@ static void stream_state_changed(struct avdtp_stream *stream,break ;case AVDTP_STATE_OPEN :btd_service_connecting_complete (sink->service,0 ); -sink_set_state (service,SINK_STATE_CONNECTED ); +sink_set_state (sink,SINK_STATE_CONNECTED );break ;case AVDTP_STATE_STREAMING : -sink_set_state (service,SINK_STATE_PLAYING ); +sink_set_state (sink,SINK_STATE_PLAYING );break ;case AVDTP_STATE_CONFIGURED :case AVDTP_STATE_CLOSING :
@@ -308,7 +309,7 @@ int sink_connect(struct btd_service *service)struct sink *sink =btd_service_get_user_data (service);if (!sink->session) - sink->session =avdtp_get (sink->dev); + sink->session =avdtp_get (btd_service_get_device (service));if (!sink->session) {DBG ("Unable to get a session" );
@@ -385,7 +386,8 @@ int sink_init(struct audio_device *dev, struct btd_service *service) sink->dev = dev; sink->service =btd_service_ref (service); - sink->avdtp_callback_id =avdtp_add_state_cb (dev, avdtp_state_callback); + sink->avdtp_callback_id =avdtp_add_state_cb (dev->btd_dev, + avdtp_state_callback, sink);btd_service_set_user_data (service, sink);
profiles/audio/source.c +15 -16
@@ -86,10 +86,8 @@ static char *str_state[] = { "SOURCE_STATE_PLAYING", }; -static void source_set_state (struct btd_service *service, -source_state_t new_state) +static void source_set_state (struct source *source,source_state_t new_state) { -struct source *source =btd_service_get_user_data (service);struct audio_device *dev = source->dev;source_state_t old_state = source->state;GSList *l;
@@ -102,10 +100,10 @@ static void source_set_state(struct btd_service *service,for (l = source_callbacks; l !=NULL ; l = l->next) {struct source_state_callback *cb = l->data; -if (cb->service != service) +if (cb->service != source->service)continue ; - cb->cb (service, old_state, new_state, cb->user_data); + cb->cb (source->service, old_state, new_state, cb->user_data); }if (new_state !=SOURCE_STATE_DISCONNECTED )
@@ -117,19 +115,19 @@ static void source_set_state(struct btd_service *service, } } -static void avdtp_state_callback (struct audio_device *dev, -struct avdtp *session, +static void avdtp_state_callback (struct btd_device *dev,struct avdtp *session,avdtp_session_state_t old_state, -avdtp_session_state_t new_state) +avdtp_session_state_t new_state, +void *user_data) { -struct source *source =btd_service_get_user_data (dev->source); +struct source *source = user_data;switch (new_state) {case AVDTP_SESSION_STATE_DISCONNECTED : -source_set_state (dev->source,SOURCE_STATE_DISCONNECTED ); +source_set_state (source,SOURCE_STATE_DISCONNECTED );break ;case AVDTP_SESSION_STATE_CONNECTING : -source_set_state (dev->source,SOURCE_STATE_CONNECTING ); +source_set_state (source,SOURCE_STATE_CONNECTING );break ;case AVDTP_SESSION_STATE_CONNECTED :break ;
@@ -168,10 +166,10 @@ static void stream_state_changed(struct avdtp_stream *stream,break ;case AVDTP_STATE_OPEN :btd_service_connecting_complete (source->service,0 ); -source_set_state (service,SOURCE_STATE_CONNECTED ); +source_set_state (source,SOURCE_STATE_CONNECTED );break ;case AVDTP_STATE_STREAMING : -source_set_state (service,SOURCE_STATE_PLAYING ); +source_set_state (source,SOURCE_STATE_PLAYING );break ;case AVDTP_STATE_CONFIGURED :case AVDTP_STATE_CLOSING :
@@ -314,7 +312,7 @@ int source_connect(struct btd_service *service)struct source *source =btd_service_get_user_data (service);if (!source->session) - source->session =avdtp_get (source->dev); + source->session =avdtp_get (btd_service_get_device (service));if (!source->session) {DBG ("Unable to get a session" );
@@ -391,8 +389,9 @@ int source_init(struct audio_device *dev, struct btd_service *service) source->dev = dev; source->service =btd_service_ref (service); - source->avdtp_callback_id =avdtp_add_state_cb (dev, - avdtp_state_callback); + source->avdtp_callback_id =avdtp_add_state_cb (dev->btd_dev, + avdtp_state_callback, + source);btd_service_set_user_data (service, source);
profiles/audio/transport.c +1 -1
@@ -332,7 +332,7 @@ static guint resume_a2dp(struct media_transport *transport,guint id;if (a2dp->session ==NULL ) { - a2dp->session =avdtp_get (transport->device); + a2dp->session =avdtp_get (transport->device->btd_dev);if (a2dp->session ==NULL )return 0 ; }
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 9/21 audio/AVRCP: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/avrcp.c | 51 ++++++++++++++++++++++------------------------ profiles/audio/avrcp.h | 8 ++++---- profiles/audio/device.c | 8 ++++---- profiles/audio/manager.c | 2 +- profiles/audio/media.c | 11 +++++----- profiles/audio/transport.c | 12 +++++------ profiles/audio/transport.h | 4 ++-- 7 files changed, 47 insertions(+), 49 deletions(-)
profiles/audio/avrcp.c +24 -27
@@ -53,7 +53,6 @@#include "log.h" #include "error.h" -#include "device.h" #include "manager.h" #include "avctp.h" #include "avrcp.h"
@@ -213,7 +212,7 @@ struct avrcp_player {struct avrcp {struct avrcp_server *server;struct avctp *conn; -struct audio_device *dev; +struct btd_device *dev;struct avrcp_player *player;gboolean target;uint16_t version;
@@ -1417,7 +1416,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp *session, uint8_t transaction) {struct avrcp_player *player = session->player; -struct audio_device *dev = session->dev; +struct btd_device *dev = session->dev;uint16_t len =ntohs (pdu->params_len);uint64_t uid;GList *settings;
@@ -2820,7 +2819,7 @@ static struct avrcp_player *create_ct_player(struct avrcp *session, player = g_new0(struct avrcp_player, 1); player->sessions =g_slist_prepend (player->sessions, session); - path =device_get_path (session->dev->btd_dev); + path =device_get_path (session->dev); mp =media_player_controller_create (path, id);if (mp ==NULL )
@@ -3256,7 +3255,7 @@ static struct avrcp *find_session(GSList *list, struct btd_device *dev)for (; list; list = list->next) {struct avrcp *session = list->data; -if (session->dev->btd_dev == dev) +if (session->dev == dev)return session; }
@@ -3316,8 +3315,7 @@ static void session_tg_init_control(struct avrcp *session)avrcp_register_notification (session,AVRCP_EVENT_VOLUME_CHANGED ); - service =btd_device_get_service (session->dev->btd_dev, -AVRCP_REMOTE_UUID ); + service =btd_device_get_service (session->dev,AVRCP_REMOTE_UUID );if (service !=NULL )btd_service_connecting_complete (service,0 ); }
@@ -3346,9 +3344,7 @@ static void session_ct_init_control(struct avrcp *session)if (session->version >=0x0104 ) session->supported_events = (1 <<AVRCP_EVENT_VOLUME_CHANGED ); - - service =btd_device_get_service (session->dev->btd_dev, -AVRCP_TARGET_UUID ); + service =btd_device_get_service (session->dev,AVRCP_TARGET_UUID );if (service !=NULL )btd_service_connecting_complete (service,0 );
@@ -3390,8 +3386,7 @@ static void session_tg_destroy(struct avrcp *session)if (player !=NULL ) player->sessions =g_slist_remove (player->sessions, session); - service =btd_device_get_service (session->dev->btd_dev, -AVRCP_REMOTE_UUID ); + service =btd_device_get_service (session->dev,AVRCP_REMOTE_UUID );if (service ==NULL )return session_destroy (session);
@@ -3411,8 +3406,7 @@ static void session_ct_destroy(struct avrcp *session)g_slist_free_full (session->players, player_destroy); - service =btd_device_get_service (session->dev->btd_dev, -AVRCP_TARGET_UUID ); + service =btd_device_get_service (session->dev,AVRCP_TARGET_UUID );if (service ==NULL )return session_destroy (session);
@@ -3431,25 +3425,28 @@ static struct avrcp *session_create(struct avrcp_server *server,const sdp_record_t *rec;sdp_list_t *list;sdp_profile_desc_t *desc; -struct audio_device *dev =manager_get_audio_device (device, FALSE); +struct btd_service *sink, *source; session = g_new0(struct avrcp, 1); session->server = server; session->conn =avctp_connect (device); - session->dev = dev; + session->dev = device; server->sessions =g_slist_append (server->sessions, session); + sink =btd_device_get_service (device,A2DP_SINK_UUID ); + source =btd_device_get_service (device,A2DP_SOURCE_UUID ); +/* If sink and source are not supported assume the controller must * be the initiator */ -if (dev->sink ==NULL && dev->source ==NULL ) +if (sink ==NULL && source ==NULL ) session->target = !avctp_is_initiator (session->conn); -else if (dev->sink && !dev->source) +else if (sink && !source) session->target = TRUE; -else if (dev->source && !dev->sink) +else if (source && !sink) session->target = FALSE; -else if (dev->sink &&sink_is_active (dev->sink)) +else if (sink &&sink_is_active (sink)) session->target = TRUE;else session->target = FALSE;
@@ -3535,22 +3532,22 @@ static void state_changed(struct btd_device *device, avctp_state_t old_state, } } -gboolean avrcp_connect (struct audio_device *dev) +gboolean avrcp_connect (struct btd_device *dev) {struct avctp *session; - session =avctp_connect (dev->btd_dev); + session =avctp_connect (dev);if (session)return FALSE;return TRUE; } -void avrcp_disconnect (struct audio_device *dev) +void avrcp_disconnect (struct btd_device *dev) {struct avctp *session; - session =avctp_get (dev->btd_dev); + session =avctp_get (dev);if (!session)return ;
@@ -3781,18 +3778,18 @@ static gboolean avrcp_handle_set_volume(struct avctp *conn,return FALSE; } -int avrcp_set_volume (struct audio_device *dev,uint8_t volume) +int avrcp_set_volume (struct btd_device *dev,uint8_t volume) {struct avrcp_server *server;struct avrcp *session;uint8_t buf[AVRCP_HEADER_LENGTH +2 ];struct avrcp_header *pdu = (void *) buf; - server =find_server (servers,device_get_adapter (dev->btd_dev)); + server =find_server (servers,device_get_adapter (dev));if (server ==NULL )return -EINVAL ; - session =find_session (server->sessions, dev->btd_dev); + session =find_session (server->sessions, dev);if (session ==NULL )return -ENOTCONN ;
profiles/audio/avrcp.h +4 -4
@@ -91,7 +91,7 @@ struct avrcp_player_cb {const char *(*get_status) (void *user_data);uint32_t (*get_position) (void *user_data);uint32_t (*get_duration) (void *user_data); -void (*set_volume) (uint8_t volume,struct audio_device *dev, +void (*set_volume) (uint8_t volume,struct btd_device *dev,void *user_data);bool (*play) (void *user_data);bool (*stop) (void *user_data);
@@ -105,9 +105,9 @@ void avrcp_target_unregister(struct btd_adapter *adapter);int avrcp_remote_register (struct btd_adapter *adapter,GKeyFile *config);void avrcp_remote_unregister (struct btd_adapter *adapter); -gboolean avrcp_connect (struct audio_device *dev); -void avrcp_disconnect (struct audio_device *dev); -int avrcp_set_volume (struct audio_device *dev,uint8_t volume); +gboolean avrcp_connect (struct btd_device *dev); +void avrcp_disconnect (struct btd_device *dev); +int avrcp_set_volume (struct btd_device *dev,uint8_t volume); struct avrcp_player *avrcp_register_player(struct btd_adapter *adapter, struct avrcp_player_cb *cb,
profiles/audio/device.c +4 -4
@@ -106,7 +106,7 @@ static gboolean control_connect_timeout(gpointer user_data) dev->priv->control_timer =0 ;if (dev->control) -avrcp_connect (dev); +avrcp_connect (dev->btd_dev);return FALSE; }
@@ -150,7 +150,7 @@ static void disconnect_cb(struct btd_device *btd_dev, gboolean removal,device_remove_control_timer (dev);if (dev->control && priv->avctp_state !=AVCTP_STATE_DISCONNECTED ) -avrcp_disconnect (dev); +avrcp_disconnect (dev->btd_dev); sink =btd_device_get_service (btd_dev,A2DP_SINK_UUID );if (sink)
@@ -173,7 +173,7 @@ static void device_avdtp_cb(struct btd_device *device, struct avdtp *session,if (avdtp_stream_setup_active (session))device_set_control_timer (dev);else -avrcp_connect (dev); +avrcp_connect (dev->btd_dev); } }
@@ -191,7 +191,7 @@ static void device_sink_cb(struct audio_device *dev,if (dev->control) {device_remove_control_timer (dev);if (priv->avctp_state !=AVCTP_STATE_DISCONNECTED ) -avrcp_disconnect (dev); +avrcp_disconnect (dev->btd_dev); }break ;case BTD_SERVICE_STATE_CONNECTING :
profiles/audio/manager.c +1 -1
@@ -154,7 +154,7 @@ static int avrcp_target_probe(struct btd_service *service) audio_dev->control = service;if (audio_dev->sink &&sink_is_active (audio_dev->sink)) -avrcp_connect (audio_dev); +avrcp_connect (audio_dev->btd_dev);return 0 ; }
profiles/audio/media.c +6 -5
@@ -379,9 +379,10 @@ static gboolean select_configuration(struct media_endpoint *endpoint,static int transport_device_cmp (gconstpointer data,gconstpointer user_data) {struct media_transport *transport = (struct media_transport *) data; -const struct audio_device *device = user_data; +const struct btd_device *device = user_data; +const struct audio_device *dev =media_transport_get_dev (transport); -if (device ==media_transport_get_dev (transport)) +if (device == dev->btd_dev)return 0 ;return -1 ;
@@ -389,7 +390,7 @@ static int transport_device_cmp(gconstpointer data, gconstpointer user_data)static struct media_transport *find_device_transport (struct media_endpoint *endpoint, -struct audio_device *device) +struct btd_device *device) {GSList *match;
@@ -414,7 +415,7 @@ static gboolean set_configuration(struct media_endpoint *endpoint,DBusMessageIter iter;struct media_transport *transport; - transport =find_device_transport (endpoint, device); + transport =find_device_transport (endpoint, device->btd_dev);if (transport !=NULL )return FALSE;
@@ -1148,7 +1149,7 @@ static uint32_t get_duration(void *user_data)return mp->duration; } -static void set_volume (uint8_t volume,struct audio_device *dev,void *user_data) +static void set_volume (uint8_t volume,struct btd_device *dev,void *user_data) {struct media_player *mp = user_data;GSList *l;
profiles/audio/transport.c +6 -6
@@ -666,7 +666,7 @@ static void set_volume(const GDBusPropertyTable *property, }if (a2dp->volume != volume) -avrcp_set_volume (transport->device, volume); +avrcp_set_volume (transport->device->btd_dev, volume); a2dp->volume = volume;
@@ -809,7 +809,7 @@ struct media_transport *media_transport_create(struct audio_device *device, transport); }else { a2dp->volume =127 ; -avrcp_set_volume (device, a2dp->volume); +avrcp_set_volume (device->btd_dev, a2dp->volume); transport->source_watch = source_add_state_cb( device->source, source_state_changed,
@@ -883,7 +883,7 @@ void media_transport_update_volume(struct media_transport *transport, MEDIA_TRANSPORT_INTERFACE, "Volume"); } -uint8_t media_transport_get_device_volume (struct audio_device *dev) +uint8_t media_transport_get_device_volume (struct btd_device *dev) {GSList *l;
@@ -892,7 +892,7 @@ uint8_t media_transport_get_device_volume(struct audio_device *dev)for (l = transports; l; l = l->next) {struct media_transport *transport = l->data; -if (transport->device != dev) +if (transport->device->btd_dev != dev)continue ;/* Volume is A2DP only */
@@ -903,7 +903,7 @@ uint8_t media_transport_get_device_volume(struct audio_device *dev)return 0 ; } -void media_transport_update_device_volume (struct audio_device *dev, +void media_transport_update_device_volume (struct btd_device *dev,uint8_t volume) {GSList *l;
@@ -913,7 +913,7 @@ void media_transport_update_device_volume(struct audio_device *dev,for (l = transports; l; l = l->next) {struct media_transport *transport = l->data; -if (transport->device != dev) +if (transport->device->btd_dev != dev)continue ;/* Volume is A2DP only */
profiles/audio/transport.h +2 -2
@@ -39,6 +39,6 @@ void media_transport_update_volume(struct media_transport *transport,void transport_get_properties (struct media_transport *transport,DBusMessageIter *iter); -uint8_t media_transport_get_device_volume (struct audio_device *dev); -void media_transport_update_device_volume (struct audio_device *dev, +uint8_t media_transport_get_device_volume (struct btd_device *dev); +void media_transport_update_device_volume (struct btd_device *dev,uint8_t volume);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 10/21 audio/control: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/control.c | 80 +++++++++++++++++++++++++++++------------------- profiles/audio/control.h | 4 +-- profiles/audio/manager.c | 4 +-- 3 files changed, 52 insertions(+), 36 deletions(-)
profiles/audio/control.c +48 -32
@@ -46,14 +46,13 @@#include <gdbus/gdbus.h> #include "lib/uuid.h" -#include "../src/adapter.h" -#include "../src/device.h" -#include "../src/profile.h" -#include "../src/service.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/profile.h" +#include "src/service.h" #include "log.h" #include "error.h" -#include "device.h" #include "manager.h" #include "avctp.h" #include "control.h"
@@ -61,8 +60,10 @@#include "glib-helper.h" #include "dbus-common.h" +static GSList *devices =NULL ; +struct control { -struct audio_device *dev; +struct btd_device *dev;struct avctp *session;struct btd_service *target;struct btd_service *remote;
@@ -110,7 +111,7 @@ int control_connect(struct btd_service *service)if (!control->target)return -ENOTSUP ; - control->session =avctp_connect (control->dev->btd_dev); + control->session =avctp_connect (control->dev);if (!control->session)return -EIO ;
@@ -132,8 +133,7 @@ int control_disconnect(struct btd_service *service)static DBusMessage *key_pressed (DBusConnection *conn,DBusMessage *msg,uint8_t op,void *data) { -struct audio_device *device = data; -struct control *control =btd_service_get_user_data (device->control); +struct control *control = data;int err;if (!control->session)
@@ -207,8 +207,7 @@ static gboolean control_property_get_connected(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) { - struct audio_device *device = data; -struct control *control =btd_service_get_user_data (device->control); + struct control *control = data;dbus_bool_t value = (control->session !=NULL );dbus_message_iter_append_basic (iter,DBUS_TYPE_BOOLEAN , &value);
@@ -236,11 +235,10 @@ static const GDBusPropertyTable control_properties[] = {static void path_unregister (void *data) { -struct audio_device *dev = data; -struct control *control =btd_service_get_user_data (dev->control); +struct control *control = data; -DBG ("Unregistered interface %s on path %s" , -AUDIO_CONTROL_INTERFACE ,device_get_path (dev->btd_dev)); +DBG ("Unregistered interface %s on path %s" ,AUDIO_CONTROL_INTERFACE , +device_get_path (control->dev));if (control->session)avctp_disconnect (control->session);
@@ -253,8 +251,8 @@ static void path_unregister(void *data)if (control->remote)btd_service_unref (control->remote); + devices =g_slist_remove (devices, control);g_free (control); - dev->control =NULL ; }void control_unregister (struct btd_service *service)
@@ -266,38 +264,56 @@ void control_unregister(struct btd_service *service) AUDIO_CONTROL_INTERFACE); } -static struct control *control_init (struct audio_device *dev) +static struct control *find_control (struct btd_device *dev) +{ +GSList *l; + +for (l = devices; l; l = l->next) { +struct control *control = l->data; + +if (control->dev == dev) +return control; + } + +return NULL ; +} + +static struct control *control_init (struct btd_service *service) {struct control *control; +struct btd_device *dev =btd_service_get_device (service); -if (dev->control !=NULL ) -return btd_service_get_user_data (dev->control); + control =find_control (dev); +if (control !=NULL ) +return control; + + control = g_new0(struct control, 1);if (!g_dbus_register_interface (btd_get_dbus_connection (), -device_get_path (dev->btd_dev), +device_get_path (dev),AUDIO_CONTROL_INTERFACE , control_methods,NULL , - control_properties, dev, - path_unregister)) + control_properties, control, + path_unregister)) { +g_free (control);return NULL ; + } -DBG ("Registered interface %s on path %s" , -AUDIO_CONTROL_INTERFACE ,device_get_path (dev->btd_dev)); - - control = g_new0(struct control, 1); +DBG ("Registered interface %s on path %s" ,AUDIO_CONTROL_INTERFACE , +device_get_path (dev)); control->dev = dev; - control->avctp_id =avctp_add_state_cb (dev->btd_dev, state_changed, - control); + control->avctp_id =avctp_add_state_cb (dev, state_changed, control); + devices =g_slist_prepend (devices, control);return control; } -int control_init_target (struct audio_device *dev,struct btd_service *service) +int control_init_target (struct btd_service *service) {struct control *control; - control =control_init (dev); + control =control_init (service);if (control ==NULL )return -EINVAL ;
@@ -308,11 +324,11 @@ int control_init_target(struct audio_device *dev, struct btd_service *service)return 0 ; } -int control_init_remote (struct audio_device *dev,struct btd_service *service) +int control_init_remote (struct btd_service *service) {struct control *control; - control =control_init (dev); + control =control_init (service);if (control ==NULL )return -EINVAL ;
profiles/audio/control.h +2 -2
@@ -26,8 +26,8 @@struct btd_service ; -int control_init_target (struct audio_device *dev,struct btd_service *service); -int control_init_remote (struct audio_device *dev,struct btd_service *service); +int control_init_target (struct btd_service *service); +int control_init_remote (struct btd_service *service);void control_unregister (struct btd_service *service);gboolean control_is_active (struct btd_service *service);
profiles/audio/manager.c +2 -2
@@ -147,7 +147,7 @@ static int avrcp_target_probe(struct btd_service *service)return -1 ; } - err =control_init_target (audio_dev, service); + err =control_init_target (service);if (err <0 )return 0 ;
@@ -171,7 +171,7 @@ static int avrcp_remote_probe(struct btd_service *service)return -1 ; } - err =control_init_remote (audio_dev, service); + err =control_init_remote (service);if (err <0 )return err;
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 11/21 audio/A2DP: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/a2dp.c | 111 ++++++++++++++++++++------------------------- profiles/audio/a2dp.h | 4 +- profiles/audio/media.c | 27 +++++------ profiles/audio/sink.c | 11 ++--- profiles/audio/source.c | 10 ++-- profiles/audio/transport.c | 109 ++++++++++++++++++++++++++++---------------- profiles/audio/transport.h | 4 +- 7 files changed, 148 insertions(+), 128 deletions(-)
profiles/audio/a2dp.c +50 -61
@@ -37,10 +37,12 @@#include <bluetooth/sdp.h> #include <bluetooth/sdp_lib.h> -#include "../src/adapter.h" +#include "lib/uuid.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/service.h" #include "log.h" -#include "device.h" #include "manager.h" #include "avdtp.h" #include "sink.h"
@@ -83,7 +85,6 @@ struct a2dp_setup_cb { };struct a2dp_setup { -struct audio_device *dev;struct avdtp *session;struct a2dp_sep *sep;struct avdtp_remote_sep *rsep;
@@ -120,25 +121,12 @@ static struct a2dp_setup *setup_ref(struct a2dp_setup *setup)return setup; } -static struct audio_device *a2dp_get_dev (struct avdtp *session) -{ -return manager_get_audio_device (avdtp_get_device (session), FALSE); -} -static struct a2dp_setup *setup_new (struct avdtp *session) { -struct audio_device *dev;struct a2dp_setup *setup; - dev =a2dp_get_dev (session); -if (!dev) { -error ("Unable to create setup" ); -return NULL ; - } - setup = g_new0(struct a2dp_setup, 1); setup->session =avdtp_ref (session); - setup->dev =a2dp_get_dev (session); setups =g_slist_append (setups, setup);return setup;
@@ -322,20 +310,6 @@ static struct a2dp_setup *a2dp_setup_get(struct avdtp *session)return setup_ref (setup); } -static struct a2dp_setup *find_setup_by_dev (struct audio_device *dev) -{ -GSList *l; - -for (l = setups; l !=NULL ; l = l->next) { -struct a2dp_setup *setup = l->data; - -if (setup->dev == dev) -return setup; - } - -return NULL ; -} -static struct a2dp_setup *find_setup_by_stream (struct avdtp_stream *stream) {GSList *l;
@@ -403,7 +377,8 @@ static void stream_state_changed(struct avdtp_stream *stream,static gboolean auto_config (gpointer data) {struct a2dp_setup *setup = data; -struct audio_device *dev = setup->dev; +struct btd_device *dev =avdtp_get_device (setup->session); +struct btd_service *service;/* Check if configuration was aborted */ if (setup->sep->stream ==NULL )
@@ -415,10 +390,13 @@ static gboolean auto_config(gpointer data)avdtp_stream_add_cb (setup->session, setup->stream, stream_state_changed, setup->sep); -if (setup->sep->type ==AVDTP_SEP_TYPE_SOURCE ) -sink_new_stream (dev->sink, setup->session, setup->stream); -else -source_new_stream (dev->source, setup->session, setup->stream); +if (setup->sep->type ==AVDTP_SEP_TYPE_SOURCE ) { + service =btd_device_get_service (dev,A2DP_SINK_UUID ); +sink_new_stream (service, setup->session, setup->stream); + }else { + service =btd_device_get_service (dev,A2DP_SOURCE_UUID ); +source_new_stream (service, setup->session, setup->stream); + } done:if (setup->setconf_cb)
@@ -497,7 +475,7 @@ static gboolean endpoint_setconf_ind(struct avdtp *session, } ret = a2dp_sep->endpoint->set_configuration(a2dp_sep, - setup->dev, codec->data, + codec->data, cap->length - sizeof(*codec), setup, endpoint_setconf_cb,
@@ -588,7 +566,8 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep, {struct a2dp_sep *a2dp_sep = user_data;struct a2dp_setup *setup; -struct audio_device *dev; +struct btd_device *dev; +struct btd_service *service;int ret;if (a2dp_sep->type ==AVDTP_SEP_TYPE_SINK )
@@ -615,13 +594,16 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,if (!setup)return ; - dev =a2dp_get_dev (session); + dev =avdtp_get_device (session);/* Notify D-Bus interface of the new stream */ -if (a2dp_sep->type ==AVDTP_SEP_TYPE_SOURCE ) -sink_new_stream (dev->sink, session, setup->stream); -else -source_new_stream (dev->source, session, setup->stream); +if (a2dp_sep->type ==AVDTP_SEP_TYPE_SOURCE ) { + service =btd_device_get_service (dev,A2DP_SINK_UUID ); +sink_new_stream (service, session, setup->stream); + }else { + service =btd_device_get_service (dev,A2DP_SOURCE_UUID ); +source_new_stream (service, session, setup->stream); + }/* Notify Endpoint */ if (a2dp_sep->endpoint) {
@@ -632,7 +614,7 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep, service =avdtp_stream_get_codec (stream); codec = (struct avdtp_media_codec_capability *) service->data; - err = a2dp_sep->endpoint->set_configuration(a2dp_sep, dev, + err = a2dp_sep->endpoint->set_configuration(a2dp_sep, codec->data, service->length - sizeof(*codec), setup,
@@ -1839,32 +1821,31 @@ failed:return 0 ; } -gboolean a2dp_cancel (struct audio_device *dev,unsigned int id) +gboolean a2dp_cancel (unsigned int id) { -struct a2dp_setup *setup; -GSList *l; +GSList *ls; - setup =find_setup_by_dev (dev); -if (!setup) -return FALSE; +for (ls = setups; ls !=NULL ; ls =g_slist_next (ls)) { +struct a2dp_setup *setup = ls->data; +GSList *l; +for (l = setup->cb; l !=NULL ; l =g_slist_next (l)) { +struct a2dp_setup_cb *cb = l->data; -for (l = setup->cb; l !=NULL ; l =g_slist_next (l)) { -struct a2dp_setup_cb *cb = l->data; +if (cb->id != id) +continue ; -if (cb->id != id) -continue ; +setup_ref (setup); +setup_cb_free (cb); -setup_ref (setup); -setup_cb_free (cb); +if (!setup->cb) { +DBG ("aborting setup %p" , setup); +avdtp_abort (setup->session, setup->stream); +return TRUE; + } -if (!setup->cb) { -DBG ("aborting setup %p" , setup); -avdtp_abort (setup->session, setup->stream); +setup_unref (setup);return TRUE; } - -setup_unref (setup); -return TRUE; }return FALSE;
@@ -1926,3 +1907,11 @@ struct avdtp_stream *a2dp_sep_get_stream(struct a2dp_sep *sep) {return sep->stream; } + +struct btd_device *a2dp_setup_get_device (struct a2dp_setup *setup) +{ +if (setup->session ==NULL ) +return NULL ; + +return avdtp_get_device (setup->session); +}
profiles/audio/a2dp.h +2 -2
@@ -42,7 +42,6 @@ struct a2dp_endpoint {a2dp_endpoint_select_t cb, void *user_data); int (*set_configuration) (struct a2dp_sep *sep, - struct audio_device *dev, uint8_t *configuration, size_t length, struct a2dp_setup *setup,
@@ -87,8 +86,9 @@ unsigned int a2dp_resume(struct avdtp *session, struct a2dp_sep *sep, a2dp_stream_cb_t cb, void *user_data);unsigned int a2dp_suspend (struct avdtp *session,struct a2dp_sep *sep,a2dp_stream_cb_t cb,void *user_data); -gboolean a2dp_cancel (struct audio_device *dev,unsigned int id); +gboolean a2dp_cancel (unsigned int id);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);
profiles/audio/media.c +14 -13
@@ -380,9 +380,9 @@ static int transport_device_cmp(gconstpointer data, gconstpointer user_data) {struct media_transport *transport = (struct media_transport *) data;const struct btd_device *device = user_data; -const struct audio_device *dev =media_transport_get_dev (transport); +const struct btd_device *dev =media_transport_get_dev (transport); -if (device == dev->btd_dev) +if (device == dev)return 0 ;return -1 ;
@@ -402,20 +402,26 @@ static struct media_transport *find_device_transport(return match->data; } +struct a2dp_config_data { +struct a2dp_setup *setup; +a2dp_endpoint_config_t cb; +}; +static gboolean set_configuration (struct media_endpoint *endpoint, -struct audio_device *device,uint8_t *configuration,size_t size,media_endpoint_cb_t cb,void *user_data,GDestroyNotify destroy) { +struct a2dp_config_data *data = user_data; +struct btd_device *device =a2dp_setup_get_device (data->setup);DBusConnection *conn =btd_get_dbus_connection ();DBusMessage *msg;const char *path;DBusMessageIter iter;struct media_transport *transport; - transport =find_device_transport (endpoint, device->btd_dev); + transport =find_device_transport (endpoint, device);if (transport !=NULL )return FALSE;
@@ -488,11 +494,6 @@ static size_t get_capabilities(struct a2dp_sep *sep, uint8_t **capabilities,return endpoint->size; } -struct a2dp_config_data { -struct a2dp_setup *setup; -a2dp_endpoint_config_t cb; -}; -struct a2dp_select_data {struct a2dp_setup *setup;a2dp_endpoint_select_t cb;
@@ -533,8 +534,8 @@ static void config_cb(struct media_endpoint *endpoint, void *ret, int size, data->cb (data->setup, ret ? TRUE : FALSE); } -static int set_config (struct a2dp_sep *sep,struct audio_device *dev, -uint8_t *configuration,size_t length, +static int set_config (struct a2dp_sep *sep,uint8_t *configuration, +size_t length,struct a2dp_setup *setup,a2dp_endpoint_config_t cb,void *user_data)
@@ -546,8 +547,8 @@ static int set_config(struct a2dp_sep *sep, struct audio_device *dev, data->setup = setup; data->cb = cb; -if (set_configuration (endpoint, dev, configuration, length, - config_cb, data, g_free) == TRUE) +if (set_configuration (endpoint, configuration, length, config_cb, data, + g_free) == TRUE)return 0 ;g_free (data);
profiles/audio/sink.c +5 -6
@@ -154,7 +154,7 @@ static void stream_state_changed(struct avdtp_stream *stream,btd_service_disconnecting_complete (sink->service,0 );if (sink->disconnect_id >0 ) { -a2dp_cancel (sink->dev, sink->disconnect_id); +a2dp_cancel (sink->disconnect_id); sink->disconnect_id =0 ; }
@@ -194,7 +194,7 @@ static gboolean stream_setup_retry(gpointer user_data) }if (sink->connect_id >0 ) { -a2dp_cancel (sink->dev, sink->connect_id); +a2dp_cancel (sink->connect_id); sink->connect_id =0 ; }
@@ -346,13 +346,13 @@ static void sink_free(struct btd_service *service)if (sink->connect_id >0 ) {btd_service_connecting_complete (sink->service, -ECANCELED ); -a2dp_cancel (dev, sink->connect_id); +a2dp_cancel (sink->connect_id); sink->connect_id =0 ; }if (sink->disconnect_id >0 ) {btd_service_disconnecting_complete (sink->service, -ECANCELED ); -a2dp_cancel (dev, sink->disconnect_id); +a2dp_cancel (sink->disconnect_id); sink->disconnect_id =0 ; }
@@ -426,7 +426,6 @@ gboolean sink_new_stream(struct btd_service *service, struct avdtp *session,int sink_disconnect (struct btd_service *service,gboolean shutdown) {struct sink *sink =btd_service_get_user_data (service); -struct audio_device *dev = sink->dev;if (!sink->session)return -ENOTCONN ;
@@ -436,7 +435,7 @@ int sink_disconnect(struct btd_service *service, gboolean shutdown)/* cancel pending connect */ if (sink->connect_id >0 ) { -a2dp_cancel (dev, sink->connect_id); +a2dp_cancel (sink->connect_id); sink->connect_id =0 ;btd_service_connecting_complete (sink->service, -ECANCELED );
profiles/audio/source.c +5 -5
@@ -153,7 +153,7 @@ static void stream_state_changed(struct avdtp_stream *stream,btd_service_disconnecting_complete (source->service,0 );if (source->disconnect_id >0 ) { -a2dp_cancel (source->dev, source->disconnect_id); +a2dp_cancel (source->disconnect_id); source->disconnect_id =0 ; }
@@ -193,7 +193,7 @@ static gboolean stream_setup_retry(gpointer user_data) }if (source->connect_id >0 ) { -a2dp_cancel (source->dev, source->connect_id); +a2dp_cancel (source->connect_id); source->connect_id =0 ; }
@@ -349,13 +349,13 @@ static void source_free(struct btd_service *service)if (source->connect_id >0 ) {btd_service_connecting_complete (source->service, -ECANCELED ); -a2dp_cancel (dev, source->connect_id); +a2dp_cancel (source->connect_id); source->connect_id =0 ; }if (source->disconnect_id >0 ) {btd_service_disconnecting_complete (source->service, -ECANCELED ); -a2dp_cancel (dev, source->disconnect_id); +a2dp_cancel (source->disconnect_id); source->disconnect_id =0 ; }
@@ -429,7 +429,7 @@ int source_disconnect(struct btd_service *service, gboolean shutdown)/* cancel pending connect */ if (source->connect_id >0 ) { -a2dp_cancel (source->dev, source->connect_id); +a2dp_cancel (source->connect_id); source->connect_id =0 ;btd_service_connecting_complete (source->service, -ECANCELED );
profiles/audio/transport.c +70 -39
178 lines not on this page · raw message
profiles/audio/transport.h +2 -2
@@ -24,13 +24,13 @@struct media_transport ; -struct media_transport *media_transport_create (struct audio_device *device, +struct media_transport *media_transport_create (struct btd_device *device,uint8_t *configuration,size_t size,void *data);void media_transport_destroy (struct media_transport *transport);const char *media_transport_get_path (struct media_transport *transport); -struct audio_device *media_transport_get_dev (struct media_transport *transport); +struct btd_device *media_transport_get_dev (struct media_transport *transport);uint16_t media_transport_get_volume (struct media_transport *transport);void media_transport_update_delay (struct media_transport *transport,uint16_t delay);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 12/21 audio/sink: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/manager.c | 2 +- profiles/audio/sink.c | 20 ++++++++------------ profiles/audio/sink.h | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-)
profiles/audio/manager.c +1 -1
@@ -132,7 +132,7 @@ static int a2dp_sink_probe(struct btd_service *service) audio_dev->sink = service; -return sink_init (audio_dev, service); +return sink_init (service); }static int avrcp_target_probe (struct btd_service *service)
profiles/audio/sink.c +8 -12
@@ -39,11 +39,10 @@#include "log.h" -#include "../src/adapter.h" -#include "../src/device.h" -#include "../src/service.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/service.h" -#include "device.h" #include "avdtp.h" #include "media.h" #include "a2dp.h"
@@ -55,7 +54,6 @@#define STREAM_SETUP_RETRY_TIMER 2struct sink { -struct audio_device *dev;struct btd_service *service;struct avdtp *session;struct avdtp_stream *stream;
@@ -335,7 +333,6 @@ int sink_connect(struct btd_service *service)static void sink_free (struct btd_service *service) {struct sink *sink =btd_service_get_user_data (service); -struct audio_device *dev = sink->dev;if (sink->cb_id) avdtp_stream_remove_cb(sink->session, sink->stream,
@@ -363,7 +360,6 @@ static void sink_free(struct btd_service *service)btd_service_unref (sink->service);g_free (sink); - dev->sink =NULL ; }void sink_unregister (struct btd_service *service)
@@ -375,19 +371,19 @@ void sink_unregister(struct btd_service *service)sink_free (service); } -int sink_init (struct audio_device *dev,struct btd_service *service) +int sink_init (struct btd_service *service) { +struct btd_device *dev =btd_service_get_device (service);struct sink *sink; -DBG ("%s" ,device_get_path (dev->btd_dev)); +DBG ("%s" ,device_get_path (dev)); sink = g_new0(struct sink, 1); - sink->dev = dev; sink->service =btd_service_ref (service); - sink->avdtp_callback_id =avdtp_add_state_cb (dev->btd_dev, - avdtp_state_callback, sink); + sink->avdtp_callback_id =avdtp_add_state_cb (dev, avdtp_state_callback, + sink);btd_service_set_user_data (service, sink);
profiles/audio/sink.h +1 -1
@@ -40,7 +40,7 @@ unsigned int sink_add_state_cb(struct btd_service *service, sink_state_cb cb, void *user_data);gboolean sink_remove_state_cb (unsigned int id); -int sink_init (struct audio_device *dev,struct btd_service *service); +int sink_init (struct btd_service *service);void sink_unregister (struct btd_service *service);gboolean sink_is_active (struct btd_service *service);int sink_connect (struct btd_service *service);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 13/21 audio/source: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/manager.c | 2 +- profiles/audio/source.c | 22 +++++++++------------- profiles/audio/source.h | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-)
profiles/audio/manager.c +1 -1
@@ -116,7 +116,7 @@ static int a2dp_source_probe(struct btd_service *service) audio_dev->source = service; -return source_init (audio_dev, service); +return source_init (service); }static int a2dp_sink_probe (struct btd_service *service)
profiles/audio/source.c +9 -13
@@ -40,11 +40,10 @@#include "log.h" -#include "../src/adapter.h" -#include "../src/device.h" -#include "../src/service.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/service.h" -#include "device.h" #include "avdtp.h" #include "media.h" #include "a2dp.h"
@@ -56,7 +55,6 @@#define STREAM_SETUP_RETRY_TIMER 2struct source { -struct audio_device *dev;struct btd_service *service;struct avdtp *session;struct avdtp_stream *stream;
@@ -88,13 +86,13 @@ static char *str_state[] = {static void source_set_state (struct source *source,source_state_t new_state) { -struct audio_device *dev = source->dev; +struct btd_device *dev =btd_service_get_device (source->service);source_state_t old_state = source->state;GSList *l; source->state = new_state; -DBG ("State changed %s: %s -> %s" ,device_get_path (dev->btd_dev), +DBG ("State changed %s: %s -> %s" ,device_get_path (dev), str_state[old_state], str_state[new_state]);for (l = source_callbacks; l !=NULL ; l = l->next) {
@@ -338,7 +336,6 @@ int source_connect(struct btd_service *service)static void source_free (struct btd_service *service) {struct source *source =btd_service_get_user_data (service); -struct audio_device *dev = source->dev;if (source->cb_id) avdtp_stream_remove_cb(source->session, source->stream,
@@ -366,7 +363,6 @@ static void source_free(struct btd_service *service)btd_service_unref (source->service);g_free (source); - dev->source =NULL ; }void source_unregister (struct btd_service *service)
@@ -378,18 +374,18 @@ void source_unregister(struct btd_service *service)source_free (service); } -int source_init (struct audio_device *dev,struct btd_service *service) +int source_init (struct btd_service *service) { +struct btd_device *dev =btd_service_get_device (service);struct source *source; -DBG ("%s" ,device_get_path (dev->btd_dev)); +DBG ("%s" ,device_get_path (dev)); source = g_new0(struct source, 1); - source->dev = dev; source->service =btd_service_ref (service); - source->avdtp_callback_id =avdtp_add_state_cb (dev->btd_dev, + source->avdtp_callback_id =avdtp_add_state_cb (dev, avdtp_state_callback, source);
profiles/audio/source.h +1 -1
@@ -41,7 +41,7 @@ unsigned int source_add_state_cb(struct btd_service *service, source_state_cb cb, void *user_data);gboolean source_remove_state_cb (unsigned int id); -int source_init (struct audio_device *dev,struct btd_service *service); +int source_init (struct btd_service *service);void source_unregister (struct btd_service *service);int source_connect (struct btd_service *service); gboolean source_new_stream(struct btd_service *service, struct avdtp *session,
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 14/21 audio/media: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/media.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
profiles/audio/media.c +4 -5
@@ -34,15 +34,14 @@#include <gdbus/gdbus.h> #include "lib/uuid.h" -#include "../src/adapter.h" -#include "../src/device.h" -#include "../src/dbus-common.h" -#include "../src/profile.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/dbus-common.h" +#include "src/profile.h" #include "glib-helper.h" #include "log.h" #include "error.h" -#include "device.h" #include "avdtp.h" #include "media.h" #include "transport.h"
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 15/21 audio/transport: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/transport.c | 1 - 1 file changed, 1 deletion(-)
profiles/audio/transport.c +0 -1
@@ -38,7 +38,6 @@#include "log.h" #include "error.h" -#include "device.h" #include "avdtp.h" #include "media.h" #include "transport.h"
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 16/21 audio/manager: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/manager.c | 144 ++++++++++++----------------------------------- profiles/audio/manager.h | 10 ---- 2 files changed, 35 insertions(+), 119 deletions(-)
profiles/audio/manager.c +35 -109
@@ -50,13 +50,12 @@#include "lib/uuid.h" #include "glib-helper.h" -#include "../src/adapter.h" -#include "../src/device.h" -#include "../src/profile.h" -#include "../src/service.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/profile.h" +#include "src/service.h" #include "log.h" -#include "device.h" #include "error.h" #include "avdtp.h" #include "media.h"
@@ -69,115 +68,63 @@#include "sdpd.h" static GKeyFile *config =NULL ; -static GSList *devices =NULL ; -static struct audio_device *get_audio_dev (struct btd_device *device) -{ -return manager_get_audio_device (device, TRUE); -} - -static struct audio_device *manager_find_device (struct btd_device *device) +static int a2dp_source_probe (struct btd_service *service) { -GSList *l; +struct btd_device *dev =btd_service_get_device (service); -for (l = devices; l !=NULL ; l = l->next) { -struct audio_device *dev = l->data; +DBG ("path %s" ,device_get_path (dev)); -if (dev->btd_dev == device) -return dev; - } +source_init (service); -return NULL ; +return 0 ; } -static void audio_remove (struct btd_service *service) +static void a2dp_source_remove (struct btd_service *service) { -struct btd_device *device =btd_service_get_device (service); -struct audio_device *dev; - - dev =manager_find_device (device); -if (dev ==NULL ) -return ; - - devices =g_slist_remove (devices, dev); -audio_device_unregister (dev); +source_unregister (service); } -static int a2dp_source_probe (struct btd_service *service) +static int a2dp_sink_probe (struct btd_service *service) { -struct btd_device *device =btd_service_get_device (service); -struct audio_device *audio_dev; - - audio_dev =get_audio_dev (device); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } +struct btd_device *dev =btd_service_get_device (service); - audio_dev->source = service; +DBG ("path %s" ,device_get_path (dev)); -return source_init (service); +return sink_init (service); } -static int a2dp_sink_probe (struct btd_service *service) +static void a2dp_sink_remove (struct btd_service *service) { -struct btd_device *device =btd_service_get_device (service); -struct audio_device *audio_dev; - - audio_dev =get_audio_dev (device); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - - audio_dev->sink = service; - -return sink_init (service); +sink_unregister (service); }static int avrcp_target_probe (struct btd_service *service) { -struct btd_device *device =btd_service_get_device (service); -struct audio_device *audio_dev; -int err; - - audio_dev =get_audio_dev (device); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } - - err =control_init_target (service); -if (err <0 ) -return 0 ; +struct btd_device *dev =btd_service_get_device (service); - audio_dev->control = service; +DBG ("path %s" ,device_get_path (dev)); -if (audio_dev->sink &&sink_is_active (audio_dev->sink)) -avrcp_connect (audio_dev->btd_dev); +return control_init_target (service); +} -return 0 ; +static void avrcp_target_remove (struct btd_service *service) +{ +control_unregister (service); }static int avrcp_remote_probe (struct btd_service *service) { -struct btd_device *device =btd_service_get_device (service); -struct audio_device *audio_dev; -int err; - - audio_dev =get_audio_dev (device); -if (!audio_dev) { -DBG ("unable to get a device object" ); -return -1 ; - } +struct btd_device *dev =btd_service_get_device (service); - err =control_init_remote (service); -if (err <0 ) -return err; +DBG ("path %s" ,device_get_path (dev)); - audio_dev->control = service; +return control_init_remote (service); +} -return 0 ; +static void avrcp_remote_remove (struct btd_service *service) +{ +control_unregister (service); }static int a2dp_source_connect (struct btd_service *service)
@@ -324,7 +271,7 @@ static struct btd_profile a2dp_source_profile = { .remote_uuid = A2DP_SOURCE_UUID, .device_probe = a2dp_source_probe, - .device_remove = audio_remove, + .device_remove = a2dp_source_remove, .auto_connect = true, .connect = a2dp_source_connect,
@@ -340,7 +287,7 @@ static struct btd_profile a2dp_sink_profile = { .remote_uuid = A2DP_SINK_UUID, .device_probe = a2dp_sink_probe, - .device_remove = audio_remove, + .device_remove = a2dp_sink_remove, .auto_connect = true, .connect = a2dp_sink_connect,
@@ -355,7 +302,7 @@ static struct btd_profile avrcp_target_profile = { .remote_uuid = AVRCP_TARGET_UUID, .device_probe = avrcp_target_probe, - .device_remove = audio_remove, + .device_remove = avrcp_target_remove, .connect = avrcp_target_connect, .disconnect = avrcp_target_disconnect,
@@ -369,7 +316,7 @@ static struct btd_profile avrcp_remote_profile = { .remote_uuid = AVRCP_REMOTE_UUID, .device_probe = avrcp_remote_probe, - .device_remove = audio_remove, + .device_remove = avrcp_remote_remove, .adapter_probe = avrcp_remote_server_probe, .adapter_remove = avrcp_remote_server_remove,
@@ -411,27 +358,6 @@ void audio_manager_exit(void)btd_unregister_adapter_driver (&media_driver); } -struct audio_device *manager_get_audio_device (struct btd_device *device, -gboolean create) -{ -struct audio_device *dev; - - dev =manager_find_device (device); -if (dev) -return dev; - -if (!create) -return NULL ; - - dev =audio_device_register (device); -if (!dev) -return NULL ; - - devices =g_slist_append (devices, dev); - -return dev; -} -static void set_fast_connectable (struct btd_adapter *adapter,gpointer user_data) {
profiles/audio/manager.h +0 -10
@@ -22,19 +22,9 @@* */ -struct enabled_interfaces { -gboolean sink; -gboolean source; -gboolean control; -gboolean media_player; -}; -int audio_manager_init (GKeyFile *config);void audio_manager_exit (void ); -struct audio_device *manager_get_audio_device (struct btd_device *device, -gboolean create); -/* TRUE to enable fast connectable and FALSE to disable fast connectable for all * audio adapters. */ void manager_set_fast_connectable (gboolean enable);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 17/21 audio/main: Remove dependency on struct audio_device
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is part of the work necessary to completely remove struct audio_device
--- profiles/audio/main.c | 1 - 1 file changed, 1 deletion(-)
profiles/audio/main.c +0 -1
@@ -41,7 +41,6 @@#include "glib-helper.h" #include "plugin.h" #include "log.h" -#include "device.h" #include "manager.h" static GKeyFile *load_config_file (const char *file)
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 18/21 plugins/policy: Reword audio policy code in a simple plugin
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This moves audio device policy to a plugin and removes any dependency of audio plugin to it.
--- Makefile.plugins | 4 +- plugins/policy.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++++ profiles/audio/device.c | 280 ---------------------------------------- profiles/audio/device.h | 40 ------ 4 files changed, 334 insertions(+), 321 deletions(-) create mode 100644 plugins/policy.c delete mode 100644 profiles/audio/device.c delete mode 100644 profiles/audio/device.h
Makefile.plugins +3 -1
@@ -8,6 +8,9 @@ builtin_sources += plugins/wiimote.c builtin_modules += autopair builtin_sources += plugins/autopair.c +builtin_modules += policy +builtin_sources += plugins/policy.c + if MAINTAINER_MODE builtin_modules += gatt_example builtin_sources += plugins/gatt-example.c
@@ -33,7 +36,6 @@ builtin_sources += profiles/audio/main.c \ profiles/audio/control.h profiles/audio/control.c \ profiles/audio/avctp.h profiles/audio/avctp.c \ profiles/audio/avrcp.h profiles/audio/avrcp.c \ - profiles/audio/device.h profiles/audio/device.c \ profiles/audio/source.h profiles/audio/source.c \ profiles/audio/sink.h profiles/audio/sink.c \ profiles/audio/a2dp.h profiles/audio/a2dp.c \
plugins/policy.c new file +331 -0
331 lines not on this page · raw message
profiles/audio/device.c deleted +0 -280
280 lines not on this page · raw message
profiles/audio/device.h deleted +0 -40
@@ -1,40 +0,0 @@ -/* -* -* BlueZ - Bluetooth protocol stack for Linux -* -* Copyright (C) 2006-2010 Nokia Corporation -* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -* -*/ - -struct audio_device ; -struct dev_priv ; - -struct audio_device { -struct btd_device *btd_dev; - -struct btd_service *sink; -struct btd_service *source; -struct btd_service *control; - -struct dev_priv *priv; -}; - -struct audio_device *audio_device_register (struct btd_device *device); - -void audio_device_unregister (struct audio_device *device);
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 19/21 audio/source: Move stream retry logic to policy plugin
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
policy plugin is a better place to have such a logic as it is already handling other connection policies related to such profiles.
--- plugins/policy.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-- profiles/audio/source.c | 54 ++++++++++--------------------------------------- 2 files changed, 61 insertions(+), 45 deletions(-)
plugins/policy.c +50 -2
@@ -41,6 +41,7 @@#include "src/profile.h" #define CONTROL_CONNECT_TIMEOUT 2 +#define SOURCE_RETRY_TIMEOUT 2static unsigned int service_id =0 ;static GSList *devices =NULL ;
@@ -48,6 +49,7 @@ static GSList *devices = NULL;struct policy_data {struct btd_device *dev; +guint source_timer;guint ct_timer;guint tg_timer; };
@@ -113,6 +115,9 @@ static void policy_remove(void *user_data) {struct policy_data *data = user_data; +if (data->source_timer >0 ) +g_source_remove (data->source_timer); +if (data->ct_timer >0 )g_source_remove (data->ct_timer);
@@ -201,9 +206,35 @@ static void policy_set_tg_timer(struct policy_data *data) data); } -static void source_cb (struct btd_device *dev,btd_service_state_t old_state, +static gboolean policy_connect_source (gpointer user_data) +{ +struct policy_data *data = user_data; +struct btd_service *service; + + data->source_timer =0 ; + + service =btd_device_get_service (data->dev,A2DP_SOURCE_UUID ); +if (service !=NULL ) +policy_connect (data, service); + +return FALSE; +} + +static void policy_set_source_timer (struct policy_data *data) +{ +if (data->source_timer >0 ) +g_source_remove (data->source_timer); + + data->source_timer =g_timeout_add_seconds (SOURCE_RETRY_TIMEOUT , + policy_connect_source, + data); +} + +static void source_cb (struct btd_service *service, +btd_service_state_t old_state,btd_service_state_t new_state) { +struct btd_device *dev =btd_service_get_device (service);struct policy_data *data;struct btd_service *target;
@@ -216,6 +247,18 @@ static void source_cb(struct btd_device *dev, btd_service_state_t old_state,switch (new_state) {case BTD_SERVICE_STATE_UNAVAILABLE :case BTD_SERVICE_STATE_DISCONNECTED : +if (old_state ==BTD_SERVICE_STATE_CONNECTING ) { +int err =btd_service_get_error (service); + +if (err == -EAGAIN ) { +policy_set_source_timer (data); +break ; + }else if (data->source_timer >0 ) { +g_source_remove (data->source_timer); + data->source_timer =0 ; + } + } +if (data->tg_timer >0 ) {g_source_remove (data->tg_timer); data->tg_timer =0 ;
@@ -226,6 +269,11 @@ static void source_cb(struct btd_device *dev, btd_service_state_t old_state,case BTD_SERVICE_STATE_CONNECTING :break ;case BTD_SERVICE_STATE_CONNECTED : +if (data->source_timer >0 ) { +g_source_remove (data->source_timer); + data->source_timer =0 ; + } +/* Check if service initiate the connection then proceed * immediatelly otherwise set timer */
@@ -306,7 +354,7 @@ static void service_cb(struct btd_service *service,if (g_str_equal (profile->remote_uuid,A2DP_SINK_UUID ))sink_cb (dev, old_state, new_state);else if (g_str_equal (profile->remote_uuid,A2DP_SOURCE_UUID )) -source_cb (dev, old_state, new_state); +source_cb (service, old_state, new_state);else if (g_str_equal (profile->remote_uuid,AVRCP_REMOTE_UUID ))controller_cb (service, old_state, new_state);else if (g_str_equal (profile->remote_uuid,AVRCP_TARGET_UUID ))
profiles/audio/source.c +11 -43
109 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 20/21 audio/sink: Move stream retry logic to policy plugin
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
policy plugin is a better place to have such a logic as it is already handling other connection policies related to such profiles.
--- plugins/policy.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-- profiles/audio/sink.c | 52 +++++++++++---------------------------------------- 2 files changed, 60 insertions(+), 43 deletions(-)
plugins/policy.c +49 -2
@@ -42,6 +42,7 @@#define CONTROL_CONNECT_TIMEOUT 2#define SOURCE_RETRY_TIMEOUT 2 +#define SINK_RETRY_TIMEOUT SOURCE_RETRY_TIMEOUTstatic unsigned int service_id =0 ;static GSList *devices =NULL ;
@@ -50,6 +51,7 @@ struct policy_data {struct btd_device *dev;guint source_timer; +guint sink_timer;guint ct_timer;guint tg_timer; };
@@ -118,6 +120,9 @@ static void policy_remove(void *user_data)if (data->source_timer >0 )g_source_remove (data->source_timer); +if (data->sink_timer >0 ) +g_source_remove (data->sink_timer); +if (data->ct_timer >0 )g_source_remove (data->ct_timer);
@@ -143,9 +148,34 @@ static struct policy_data *policy_get_data(struct btd_device *dev)return data; } -static void sink_cb (struct btd_device *dev,btd_service_state_t old_state, +static gboolean policy_connect_sink (gpointer user_data) +{ +struct policy_data *data = user_data; +struct btd_service *service; + + data->source_timer =0 ; + + service =btd_device_get_service (data->dev,A2DP_SINK_UUID ); +if (service !=NULL ) +policy_connect (data, service); + +return FALSE; +} + +static void policy_set_sink_timer (struct policy_data *data) +{ +if (data->sink_timer >0 ) +g_source_remove (data->sink_timer); + + data->sink_timer =g_timeout_add_seconds (SINK_RETRY_TIMEOUT , + policy_connect_sink, + data); +} + +static void sink_cb (struct btd_service *service,btd_service_state_t old_state,btd_service_state_t new_state) { +struct btd_device *dev =btd_service_get_device (service);struct policy_data *data;struct btd_service *controller;
@@ -158,6 +188,18 @@ static void sink_cb(struct btd_device *dev, btd_service_state_t old_state,switch (new_state) {case BTD_SERVICE_STATE_UNAVAILABLE :case BTD_SERVICE_STATE_DISCONNECTED : +if (old_state ==BTD_SERVICE_STATE_CONNECTING ) { +int err =btd_service_get_error (service); + +if (err == -EAGAIN ) { +policy_set_sink_timer (data); +break ; + }else if (data->sink_timer >0 ) { +g_source_remove (data->sink_timer); + data->sink_timer =0 ; + } + } +if (data->ct_timer >0 ) {g_source_remove (data->ct_timer); data->ct_timer =0 ;
@@ -168,6 +210,11 @@ static void sink_cb(struct btd_device *dev, btd_service_state_t old_state,case BTD_SERVICE_STATE_CONNECTING :break ;case BTD_SERVICE_STATE_CONNECTED : +if (data->sink_timer >0 ) { +g_source_remove (data->sink_timer); + data->sink_timer =0 ; + } +/* Check if service initiate the connection then proceed * immediatelly otherwise set timer */
@@ -352,7 +399,7 @@ static void service_cb(struct btd_service *service,struct btd_profile *profile =btd_service_get_profile (service);if (g_str_equal (profile->remote_uuid,A2DP_SINK_UUID )) -sink_cb (dev, old_state, new_state); +sink_cb (service, old_state, new_state);else if (g_str_equal (profile->remote_uuid,A2DP_SOURCE_UUID ))source_cb (service, old_state, new_state);else if (g_str_equal (profile->remote_uuid,AVRCP_REMOTE_UUID ))
profiles/audio/sink.c +11 -41
102 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerPATCH v2 21/21 audio/control: Enable initiate connection to CT role
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Since the policy uses service API to initiate the connections this needs to be enabled for both CT and TG roles.
--- profiles/audio/control.c | 3 --- profiles/audio/manager.c | 11 +++++++---- 2 files changed, 7 insertions(+), 7 deletions(-)
profiles/audio/control.c +0 -3
@@ -108,9 +108,6 @@ int control_connect(struct btd_service *service)if (control->session)return -EALREADY ; -if (!control->target) -return -ENOTSUP ; - control->session =avctp_connect (control->dev);if (!control->session)return -EIO ;
profiles/audio/manager.c +7 -4
@@ -167,7 +167,7 @@ static int a2dp_sink_disconnect(struct btd_service *service)return sink_disconnect (service, FALSE); } -static int avrcp_target_connect (struct btd_service *service) +static int avrcp_control_connect (struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev);
@@ -177,7 +177,7 @@ static int avrcp_target_connect(struct btd_service *service)return control_connect (service); } -static int avrcp_target_disconnect (struct btd_service *service) +static int avrcp_control_disconnect (struct btd_service *service) {struct btd_device *dev =btd_service_get_device (service);const char *path =device_get_path (dev);
@@ -304,8 +304,8 @@ static struct btd_profile avrcp_target_profile = { .device_probe = avrcp_target_probe, .device_remove = avrcp_target_remove, - .connect = avrcp_target_connect, - .disconnect = avrcp_target_disconnect, + .connect = avrcp_control_connect, + .disconnect = avrcp_control_disconnect, .adapter_probe = avrcp_target_server_probe, .adapter_remove = avrcp_target_server_remove,
@@ -318,6 +318,9 @@ static struct btd_profile avrcp_remote_profile = { .device_probe = avrcp_remote_probe, .device_remove = avrcp_remote_remove, + .connect = avrcp_control_connect, + .disconnect = avrcp_control_disconnect, + .adapter_probe = avrcp_remote_server_probe, .adapter_remove = avrcp_remote_server_remove, };
Signature · 1 line
1.8.1.4
Luiz Augusto von Dentz
maintainerHi,
Quoted 82 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
audio_deviceis no longer needed asbtd_servicecan be used to track connection states, in factaudio_deviceprobably obscured direct access to some data types likebtd_deviceand usebtd_service_set_user_datato set profile private data instead of storing everything insideaudio_device.There are probably more cleanups to audio after this changes, some policies that should be moved to policy plugin and a much needed split of audio plugin into smaller plugins, but I decided to stop right here otherwise the patch-set will get too big to be properly reviewed.
Also since this refactore the audio policy quite extensively this may create some IOP issues, but I did test this with quite a few stacks including:
- iOS 6
- Android 4.2
- WP 8
- Blackberry 10
- MW600
- Nokia Purity Pro
- BlueZ 4
- BlueZ 5They all seems to be working as before.
v2: Add patch 21/21 to enable initiating connections to CT role.
Luiz Augusto von Dentz (21):
audio/sink: Use serviceuser_datafor private data audio/source: Use serviceuser_datafor private data audio/control: Use serviceuser_datafor private data audio/sink: Reduce dependency on structaudio_deviceaudio/source: Reduce dependency on structaudio_deviceaudio/control: Reduce dependency on structaudio_deviceaudio/AVCTP: Remove dependency on structaudio_deviceaudio/AVDTP: Remove dependency on structaudio_deviceaudio/AVRCP: Remove dependency on structaudio_deviceaudio/control: Remove dependency on structaudio_deviceaudio/A2DP: Remove dependency on structaudio_deviceaudio/sink: Remove dependency on structaudio_deviceaudio/source: Remove dependency on structaudio_deviceaudio/media: Remove dependency on structaudio_deviceaudio/transport: Remove dependency on structaudio_deviceaudio/manager: Remove dependency on structaudio_deviceaudio/main: Remove dependency on structaudio_deviceplugins/policy: Reword audio policy code in a simple plugin audio/source: Move stream retry logic to policy plugin audio/sink: Move stream retry logic to policy plugin audio/control: Enable initiate connection to CT roleMakefile.plugins | 4 +- plugins/policy.c | 426 +++++++++++++++++++++++++++++++++++++++++++++ profiles/audio/a2dp.c | 110 ++++++------ profiles/audio/a2dp.h | 4 +- profiles/audio/avctp.c | 69 +++----- profiles/audio/avctp.h | 12 +- profiles/audio/avdtp.c | 97 +++++------ profiles/audio/avdtp.h | 13 +- profiles/audio/avrcp.c | 89 ++++++---- profiles/audio/avrcp.h | 8 +- profiles/audio/control.c | 143 +++++++-------- profiles/audio/control.h | 19 +- profiles/audio/device.c | 261 --------------------------- profiles/audio/device.h | 43 ----- profiles/audio/main.c | 1 - profiles/audio/manager.c | 199 +++++---------------- profiles/audio/manager.h | 10 -- profiles/audio/media.c | 39 +++-- profiles/audio/sink.c | 157 +++++++---------- profiles/audio/sink.h | 18 +- profiles/audio/source.c | 158 +++++++---------- profiles/audio/source.h | 20 +-- profiles/audio/transport.c | 109 +++++++----- profiles/audio/transport.h | 8 +- 24 files changed, 993 insertions(+), 1024 deletions(-) create mode 100644 plugins/policy.c delete mode 100644 profiles/audio/device.c delete mode 100644 profiles/audio/device.h
Quoted 2 lines
--
1.8.1.4
This patch-set is now pushed.
--
Luiz Augusto von Dentz