Skip to contentSkip to conversation

Add BIP for AVRCP covert art OBEX client

PATCH Superseded Frédéric Danis 3 participants 11 messages Sep 12, 2024 – Sep 13, 2024

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add BIP for AVRCP covert art OBEX client

If AVRCP Target supports Cover Art download its SDP record contains an additional access protocol for OBEX with an LCAP PSM on which the OBEX client session should connect to, with the specific OBEX target header 7163DD54-4A7E-11E2-B47C-0050C2490048.

Once the OBEX session is connected, the AVRCP track metadata will contain an Image Handle which can be used to get the associated image using GetImageThumbnail or GetImage with one of the description property found with GetImageProperties.

v1 -> v2: Parse integer properties as integer instead of string

          Return GetImageProperties values as aa{sv} instead of aa{ss}
          Get properties for GetImage as a{sv} instead of a{ss}
          Set new properties and interface as experimental

Frédéric Danis (7):
obexd: Add PSM support to session create
player: Add OBEX PSM port for cover art support
player: Add image handle support property
obexd: Add BIP client for AVRCP cover art download.
obexd: Add GetImageProperties to bip-avrcp
obexd: Add GetImage to bip-avrcp
doc: Add description of org.bluez.obex.BipAvrcp

 Makefile.am                     |   9 +-
 Makefile.obexd                  |   2 +
 doc/org.bluez.MediaPlayer.rst   |  11 +
 doc/org.bluez.obex.BipAvrcp.rst |  72 +++
 doc/org.bluez.obex.Client.rst   |   5 +
 doc/org.bluez.obex.Session.rst  |   5 +
 monitor/avctp.c                 |   3 +
 obexd/client/bip-avrcp.c        | 427 +++++++++++++++++
 obexd/client/bip-avrcp.h        |  12 +
 obexd/client/bip-common.c       | 800 ++++++++++++++++++++++++++++++++
 obexd/client/bip-common.h       |  24 +
 obexd/client/manager.c          |  16 +-
 obexd/client/session.c          |  27 +-
 obexd/client/session.h          |   1 +
 obexd/client/transfer.c         |  16 +
 obexd/client/transfer.h         |   2 +
 profiles/audio/avrcp.c          |  64 ++-
 profiles/audio/avrcp.h          |   3 +-
 profiles/audio/player.c         |  30 ++
 profiles/audio/player.h         |   1 +
 tools/parser/avrcp.c            |   3 +
 21 files changed, 1514 insertions(+), 19 deletions(-)
 create mode 100644 doc/org.bluez.obex.BipAvrcp.rst
 create mode 100644 obexd/client/bip-avrcp.c
 create mode 100644 obexd/client/bip-avrcp.h
 create mode 100644 obexd/client/bip-common.c
 create mode 100644 obexd/client/bip-common.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/7 obexd: Add PSM support to session create

An OBEX session can be connected to a RFCOMM channel or a L2CAP PSM.

---
 doc/org.bluez.obex.Client.rst  |  4 ++++
 doc/org.bluez.obex.Session.rst |  5 +++++
 obexd/client/manager.c         | 14 ++++++++++----
 obexd/client/session.c         | 27 ++++++++++++++++++++++++---
 obexd/client/session.h         |  1 +
 5 files changed, 44 insertions(+), 7 deletions(-)
doc/org.bluez.obex.Client.rst +4 -0
index 9f77a9abc..5ae7cc5e8 100644
@@ -52,6 +52,10 @@ object CreateSession(string destination, dict args)
 
 		Channel to be used.
 
+	:uint16 PSM:
+
+		L2CAP PSM to be used.
+
 	Possible errors:
 
 	:org.bluez.obex.Error.InvalidArguments:
doc/org.bluez.obex.Session.rst +5 -0
index 1cef9a53d..fc5f14e5d 100644
@@ -50,6 +50,11 @@ byte Channel [readonly]
 
 	Bluetooth channel
 
+uint16 PSM [readonly]
+```````````````````````
+
+	Bluetooth L2CAP PSM
+
 string Target [readonly]
 ````````````````````````
 
obexd/client/manager.c +10 -4
index ad1fbb04a..52c00fb0c 100644
@@ -107,7 +107,8 @@ done:
 }
 
 static int parse_device_dict(DBusMessageIter *iter,
-		const char **source, const char **target, uint8_t *channel)
+		const char **source, const char **target, uint8_t *channel,
+		uint16_t *psm)
 {
 	while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_DICT_ENTRY) {
 		DBusMessageIter entry, value;
@@ -130,6 +131,10 @@ static int parse_device_dict(DBusMessageIter *iter,
 			if (g_str_equal(key, "Channel") == TRUE)
 				dbus_message_iter_get_basic(&value, channel);
 			break;
+		case DBUS_TYPE_UINT16:
+			if (g_str_equal(key, "PSM") == TRUE)
+				dbus_message_iter_get_basic(&value, psm);
+			break;
 		}
 
 		dbus_message_iter_next(iter);
@@ -160,6 +165,7 @@ static DBusMessage *create_session(DBusConnection *connection,
 	struct send_data *data;
 	const char *source = NULL, *dest = NULL, *target = NULL;
 	uint8_t channel = 0;
+	uint16_t psm = 0;
 
 	dbus_message_iter_init(message, &iter);
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
@@ -175,8 +181,8 @@ static DBusMessage *create_session(DBusConnection *connection,
 
 	dbus_message_iter_recurse(&iter, &dict);
 
-	parse_device_dict(&dict, &source, &target, &channel);
-	if (dest == NULL || target == NULL)
+	parse_device_dict(&dict, &source, &target, &channel, &psm);
+	if (dest == NULL || target == NULL || (channel && psm))
 		return g_dbus_create_error(message,
 				ERROR_INTERFACE ".InvalidArguments", NULL);
 
@@ -188,7 +194,7 @@ static DBusMessage *create_session(DBusConnection *connection,
 	data->connection = dbus_connection_ref(connection);
 	data->message = dbus_message_ref(message);
 
-	session = obc_session_create(source, dest, target, channel,
+	session = obc_session_create(source, dest, target, channel, psm,
 					dbus_message_get_sender(message),
 					create_callback, data);
 	if (session != NULL) {
obexd/client/session.c +24 -3
index 7d8ebb04e..13a834e14 100644
@@ -88,6 +88,7 @@ struct obc_session {
 	char *source;
 	char *destination;
 	uint8_t channel;
+	uint16_t psm;
 	struct obc_transport *transport;
 	struct obc_driver *driver;
 	char *path;		/* Session path */
@@ -471,6 +472,7 @@ static struct obc_session *session_find(const char *source,
 						const char *destination,
 						const char *service,
 						uint8_t channel,
+						uint16_t psm,
 						const char *owner)
 {
 	GSList *l;
@@ -490,6 +492,9 @@ static struct obc_session *session_find(const char *source,
 		if (channel && session->channel != channel)
 			continue;
 
+		if (psm && session->psm != psm)
+			continue;
+
 		if (g_strcmp0(owner, session->owner))
 			continue;
 
@@ -541,8 +546,9 @@ static int session_connect(struct obc_session *session,
 	}
 
 	session->id = transport->connect(session->source, session->destination,
-					driver->uuid, session->channel,
-					transport_func, callback);
+			driver->uuid,
+			session->channel ? session->channel : session->psm,
+			transport_func, callback);
 	if (session->id == 0) {
 		obc_session_unref(callback->session);
 		g_free(callback);
@@ -558,6 +564,7 @@ struct obc_session *obc_session_create(const char *source,
 						const char *destination,
 						const char *service,
 						uint8_t channel,
+						uint16_t psm,
 						const char *owner,
 						session_callback_t function,
 						void *user_data)
@@ -570,7 +577,8 @@ struct obc_session *obc_session_create(const char *source,
 	if (destination == NULL)
 		return NULL;
 
-	session = session_find(source, destination, service, channel, owner);
+	session = session_find(source, destination, service, channel, psm,
+				owner);
 	if (session != NULL)
 		goto proceed;
 
@@ -598,6 +606,7 @@ struct obc_session *obc_session_create(const char *source,
 	session->source = g_strdup(source);
 	session->destination = g_strdup(destination);
 	session->channel = channel;
+	session->psm = psm;
 	session->queue = g_queue_new();
 	session->folder = g_strdup("/");
 
@@ -762,6 +771,17 @@ static gboolean get_channel(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static gboolean get_psm(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct obc_session *session = data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
+							&session->psm);
+
+	return TRUE;
+}
+
 static const GDBusMethodTable session_methods[] = {
 	{ GDBUS_ASYNC_METHOD("GetCapabilities",
 				NULL, GDBUS_ARGS({ "capabilities", "s" }),
@@ -794,6 +814,7 @@ static const GDBusPropertyTable session_properties[] = {
 	{ "Source", "s", get_source, NULL, source_exists },
 	{ "Destination", "s", get_destination },
 	{ "Channel", "y", get_channel },
+	{ "PSM", "q", get_psm },
 	{ "Target", "s", get_target, NULL, target_exists },
 	{ }
 };
obexd/client/session.h +1 -0
index 2c646df1a..19c3f3687 100644
@@ -22,6 +22,7 @@ struct obc_session *obc_session_create(const char *source,
 						const char *destination,
 						const char *service,
 						uint8_t channel,
+						uint16_t psm,
 						const char *owner,
 						session_callback_t function,
 						void *user_data);
Signature · 1 line
2.34.1
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=889869

---Test result---

Test Summary:

CheckPatch                    FAIL      4.87 seconds
GitLint                       FAIL      2.45 seconds
BuildEll                      PASS      25.39 seconds
BluezMake                     PASS      1704.84 seconds
MakeCheck                     PASS      21.99 seconds
MakeDistcheck                 PASS      193.14 seconds
CheckValgrind                 PASS      274.95 seconds
CheckSmatch                   PASS      356.90 seconds
bluezmakeextell               PASS      120.03 seconds
IncrementalBuild              PASS      11587.97 seconds
ScanBuild                     WARNING   1015.75 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v2,5/7] obexd: Add GetImageProperties to bip-avrcp
WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line) #78:
[2] https://github.com/enkait/Basic-Imaging-Profile-in-obexd/blob/gsoc_final/plugins/bip_util.c

WARNING:ONE_SEMICOLON: Statements terminations use 1 semicolon #366: FILE: obexd/client/bip-common.c:132:
+ return g_ascii_strtoll(size, NULL, 10);;

/github/workspace/src/src/13802399.patch total: 0 errors, 2 warnings, 926 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13802399.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[BlueZ,v2,4/7] obexd: Add BIP client for AVRCP cover art download.

WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
1: T3 Title has trailing punctuation (.): "[BlueZ,v2,4/7] obexd: Add BIP client for AVRCP cover art download."
[BlueZ,v2,5/7] obexd: Add GetImageProperties to bip-avrcp

WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
10: B1 Line exceeds max length (95>80): "[2] https://github.com/enkait/Basic-Imaging-Profile-in-obexd/blob/gsoc_final/plugins/bip_util.c"
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
obexd/client/bip-avrcp.c:119:3: warning: Value stored to 'reply' is never read
reply = g_dbus_create_error(message,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
obexd/client/bip-avrcp.c:141:9: warning: Access to field 'message' results in a dereference of a null pointer (loaded from variable 'err')

                                                                err->message);
                                                                ^~~~~~~~~~~~

obexd/client/bip-avrcp.c:162:3: warning: Value stored to 'reply' is never read
reply = g_dbus_create_error(message,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
obexd/client/bip-avrcp.c:181:9: warning: Access to field 'message' results in a dereference of a null pointer (loaded from variable 'err')

                                                                err->message);
                                                                ^~~~~~~~~~~~

obexd/client/bip-avrcp.c:322:10: warning: Potential leak of memory pointed to by 'encoding'
reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
^~~~~~~~~~~~~~~~~~~
obexd/client/bip-avrcp.c:322:10: warning: Potential leak of memory pointed to by 'pixel'
reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
^~~~~~~~~~~~~~~~~~~
6 warnings generated.
profiles/audio/avrcp.c:1942:2: warning: Value stored to 'operands' is never read

        operands += sizeof(*pdu);
        ^           ~~~~~~~~~~~~

1 warning generated.

---
Regards,
Linux Bluetooth

#3 lore raw

PATCH v2 2/7 player: Add OBEX PSM port for cover art support

In reply to Frédéric Danis

This parse the AVRCP Target SDP record for the L2CAP PSM to use with the OBEX session to get the cover art.
---
v1 -> v2: Set new propert as experimental

 doc/org.bluez.MediaPlayer.rst |  6 +++++
 profiles/audio/avrcp.c        | 51 +++++++++++++++++++++++++++++++----
 profiles/audio/player.c       | 30 +++++++++++++++++++++
 profiles/audio/player.h       |  1 +
 4 files changed, 83 insertions(+), 5 deletions(-)
doc/org.bluez.MediaPlayer.rst +6 -0
index 60bd679bb..858344b30 100644
@@ -313,3 +313,9 @@ object Playlist
 ```````````````
 
 	Playlist object path.
+
+uint16 ObexPort [readonly, experimental]
+````````````````````````````````````````
+
+	If present indicates the player can get cover art using BIP over OBEX
+	on this PSM port.
profiles/audio/avrcp.c +46 -5

100 lines not on this page · raw message

profiles/audio/player.c +30 -0
index c995697fe..b3a6920fc 100644
@@ -88,6 +88,7 @@ struct media_player {
 	struct player_callback	*cb;
 	GSList			*pending;
 	GSList			*folders;
+	uint16_t		obex_port;
 };
 
 static void append_track(void *key, void *value, void *user_data)
@@ -437,6 +438,28 @@ static gboolean get_playlist(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static gboolean obexport_exists(const GDBusPropertyTable *property,
+								void *data)
+{
+	struct media_player *mp = data;
+
+	return mp->obex_port != 0;
+}
+
+static gboolean get_obexport(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct media_player *mp = data;
+
+	if (mp->obex_port == 0)
+		return FALSE;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
+							&mp->obex_port);
+
+	return TRUE;
+}
+
 static DBusMessage *media_player_play(DBusConnection *conn, DBusMessage *msg,
 								void *data)
 {
@@ -778,6 +801,8 @@ static const GDBusPropertyTable media_player_properties[] = {
 	{ "Browsable", "b", get_browsable, NULL, browsable_exists },
 	{ "Searchable", "b", get_searchable, NULL, searchable_exists },
 	{ "Playlist", "o", get_playlist, NULL, playlist_exists },
+	{ "ObexPort", "q", get_obexport, NULL, obexport_exists,
+			G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
 	{ }
 };
 
@@ -1997,3 +2022,8 @@ struct media_item *media_player_set_playlist_item(struct media_player *mp,
 
 	return item;
 }
+
+void media_player_set_obex_port(struct media_player *mp, uint16_t port)
+{
+	mp->obex_port = port;
+}
profiles/audio/player.h +1 -0
index 74fb7d771..0076c4641 100644
@@ -86,6 +86,7 @@ void media_player_set_folder(struct media_player *mp, const char *path,
 void media_player_set_playlist(struct media_player *mp, const char *name);
 struct media_item *media_player_set_playlist_item(struct media_player *mp,
 								uint64_t uid);
+void media_player_set_obex_port(struct media_player *mp, uint16_t port);
 
 struct media_item *media_player_create_folder(struct media_player *mp,
 						const char *name,
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 3/7 player: Add image handle support property

In reply to Frédéric Danis

This is part of the metadata when the AVRCP target supports covert art download and a OBEX BIP session is connected.
The image handle references the cover art associated to the track, and is valid only during OBEX BIP session.
---
v1 -> v2: Set new property as experimental

 doc/org.bluez.MediaPlayer.rst | 5 +++++
 monitor/avctp.c               | 3 +++
 profiles/audio/avrcp.c        | 7 ++++++-
 profiles/audio/avrcp.h        | 3 ++-
 tools/parser/avrcp.c          | 3 +++
 5 files changed, 19 insertions(+), 2 deletions(-)
doc/org.bluez.MediaPlayer.rst +5 -0
index 858344b30..94f5b8472 100644
@@ -237,6 +237,11 @@ dict Track [readonly]
 
 		Track duration in milliseconds
 
+	:string ImgHandle: [experimental]
+
+		Track image handle, available and valid only during the lifetime of an
+		OBEX BIP connection to the ObexPort.
+
 object Device [readonly]
 ````````````````````````
 
monitor/avctp.c +3 -0
index c59e93b20..4da448750 100644
@@ -156,6 +156,7 @@
 #define AVRCP_MEDIA_ATTRIBUTE_TOTAL	0x05
 #define AVRCP_MEDIA_ATTRIBUTE_GENRE	0x06
 #define AVRCP_MEDIA_ATTRIBUTE_DURATION	0x07
+#define AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE	0x08
 
 /* play status */
 #define AVRCP_PLAY_STATUS_STOPPED	0x00
@@ -582,6 +583,8 @@ static const char *mediattr2str(uint32_t attr)
 		return "Genre";
 	case AVRCP_MEDIA_ATTRIBUTE_DURATION:
 		return "Track duration";
+	case AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE:
+		return "Imaging handle";
 	default:
 		return "Reserved";
 	}
profiles/audio/avrcp.c +6 -1
index 61558e492..fe24b5a92 100644
@@ -417,7 +417,8 @@ static sdp_record_t *avrcp_ct_record(bool browsing)
 	uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
 						AVRCP_FEATURE_CATEGORY_2 |
 						AVRCP_FEATURE_CATEGORY_3 |
-						AVRCP_FEATURE_CATEGORY_4);
+						AVRCP_FEATURE_CATEGORY_4 |
+						AVRCP_FEATURE_CT_GET_THUMBNAIL);
 
 	record = sdp_record_alloc();
 	if (!record)
@@ -883,6 +884,8 @@ static const char *metadata_to_str(uint32_t id)
 		return "NumberOfTracks";
 	case AVRCP_MEDIA_ATTRIBUTE_DURATION:
 		return "Duration";
+	case AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE:
+		return "ImgHandle";
 	}
 
 	return NULL;
@@ -1197,6 +1200,8 @@ static uint32_t str_to_metadata(const char *str)
 		return AVRCP_MEDIA_ATTRIBUTE_N_TRACKS;
 	else if (strcasecmp(str, "Duration") == 0)
 		return AVRCP_MEDIA_ATTRIBUTE_DURATION;
+	else if (strcasecmp(str, "ImgHandle") == 0)
+		return AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE;
 
 	return 0;
 }
profiles/audio/avrcp.h +2 -1
index dcc580e37..59117e946 100644
@@ -46,7 +46,8 @@
 #define AVRCP_MEDIA_ATTRIBUTE_N_TRACKS	0x05
 #define AVRCP_MEDIA_ATTRIBUTE_GENRE	0x06
 #define AVRCP_MEDIA_ATTRIBUTE_DURATION	0x07
-#define AVRCP_MEDIA_ATTRIBUTE_LAST	AVRCP_MEDIA_ATTRIBUTE_DURATION
+#define AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE	0x08
+#define AVRCP_MEDIA_ATTRIBUTE_LAST	AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE
 
 /* play status */
 #define AVRCP_PLAY_STATUS_STOPPED	0x00
tools/parser/avrcp.c +3 -0
index e73a6317e..d574c7ee3 100644
@@ -160,6 +160,7 @@
 #define AVRCP_MEDIA_ATTRIBUTE_TOTAL	0x5
 #define AVRCP_MEDIA_ATTRIBUTE_GENRE	0x6
 #define AVRCP_MEDIA_ATTRIBUTE_DURATION	0x7
+#define AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE	0x08
 
 /* play status */
 #define AVRCP_PLAY_STATUS_STOPPED	0x00
@@ -933,6 +934,8 @@ static const char *mediattr2str(uint32_t attr)
 		return "Genre";
 	case AVRCP_MEDIA_ATTRIBUTE_DURATION:
 		return "Track duration";
+	case AVRCP_MEDIA_ATTRIBUTE_IMG_HANDLE:
+		return "Imaging handle";
 	default:
 		return "Reserved";
 	}
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 4/7 obexd: Add BIP client for AVRCP cover art download.

In reply to Frédéric Danis

The cover art image handle is available in the metadata of the track when the OBEX BIP session is connected to the PSM port provided in AVRCP SDP record and available as org.bluez.MediaPlayer property.

This service allows to get the thumbnail.

---
 Makefile.obexd           |   1 +
 obexd/client/bip-avrcp.c | 171 +++++++++++++++++++++++++++++++++++++++
 obexd/client/bip-avrcp.h |  12 +++
 obexd/client/manager.c   |   2 +
 obexd/client/transfer.c  |  16 ++++
 obexd/client/transfer.h  |   2 +
 6 files changed, 204 insertions(+)
 create mode 100644 obexd/client/bip-avrcp.c
 create mode 100644 obexd/client/bip-avrcp.h
Makefile.obexd +1 -0
index 4cdce73af..8038d2327 100644
@@ -81,6 +81,7 @@ obexd_src_obexd_SOURCES = $(btio_sources) $(gobex_sources) \
 			obexd/client/ftp.h obexd/client/ftp.c \
 			obexd/client/opp.h obexd/client/opp.c \
 			obexd/client/map.h obexd/client/map.c \
+			obexd/client/bip-avrcp.h obexd/client/bip-avrcp.c \
 			obexd/client/map-event.h obexd/client/map-event.c \
 			obexd/client/transfer.h obexd/client/transfer.c \
 			obexd/client/transport.h obexd/client/transport.c \
obexd/client/bip-avrcp.c new file +171 -0

171 lines not on this page · raw message

obexd/client/bip-avrcp.h new file +12 -0
new file mode 100644
index 000000000..acd8068f2
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *
+ *  OBEX Client
+ *
+ *  Copyright (C) 2024  Collabora Ltd.
+ *
+ *
+ */
+
+int bip_avrcp_init(void);
+void bip_avrcp_exit(void);
obexd/client/manager.c +2 -0
index 52c00fb0c..5078f56da 100644
@@ -32,6 +32,7 @@
 #include "pbap.h"
 #include "sync.h"
 #include "map.h"
+#include "bip-avrcp.h"
 #include "manager.h"
 
 #define CLIENT_INTERFACE	"org.bluez.obex.Client1"
@@ -258,6 +259,7 @@ static const struct obc_module {
 	{ "pbap", pbap_init, pbap_exit },
 	{ "sync", sync_init, sync_exit },
 	{ "map", map_init, map_exit },
+	{ "bip-avrcp", bip_avrcp_init, bip_avrcp_exit },
 	{ }
 };
 
obexd/client/transfer.c +16 -0
index a7a85a0c0..fdf32a985 100644
@@ -57,6 +57,7 @@ struct obc_transfer {
 	GObex *obex;
 	uint8_t status;
 	GObexApparam *apparam;
+	GSList *headers;
 	guint8 op;
 	struct transfer_callback *callback;
 	DBusConnection *conn;
@@ -820,6 +821,16 @@ static gboolean transfer_start_get(struct obc_transfer *transfer, GError **err)
 		g_obex_packet_add_bytes(req, G_OBEX_HDR_TYPE, transfer->type,
 						strlen(transfer->type) + 1);
 
+	if (transfer->headers != NULL) {
+		GSList *l;
+
+		for (l = transfer->headers; l != NULL; l = g_slist_next(l)) {
+			GObexHeader *hdr = l->data;
+
+			g_obex_packet_add_header(req, hdr);
+		}
+	}
+
 	if (transfer->apparam != NULL) {
 		hdr = g_obex_header_new_apparam(transfer->apparam);
 		g_obex_packet_add_header(req, hdr);
@@ -974,3 +985,8 @@ gint64 obc_transfer_get_size(struct obc_transfer *transfer)
 {
 	return transfer->size;
 }
+
+void obc_transfer_add_header(struct obc_transfer *transfer, void *data)
+{
+	transfer->headers = g_slist_append(transfer->headers, data);
+}
obexd/client/transfer.h +2 -0
index 323332a62..1ed195984 100644
@@ -47,3 +47,5 @@ gint64 obc_transfer_get_size(struct obc_transfer *transfer);
 
 DBusMessage *obc_transfer_create_dbus_reply(struct obc_transfer *transfer,
 							DBusMessage *message);
+
+void obc_transfer_add_header(struct obc_transfer *transfer, void *data);
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH BlueZ v2 4/7] obexd: Add BIP client for AVRCP cover art download.

Hi Frédéric,

Quoted 10 lines · Frédéric Danis

The cover art image handle is available in the metadata of the track when the OBEX BIP session is connected to the PSM port provided in AVRCP SDP record and available as org.bluez.MediaPlayer property.

This service allows to get the thumbnail.

---
 Makefile.obexd           |   1 +
 obexd/client/bip-avrcp.c | 171 +++++++++++++++++++++++++++++++++++++++
 obexd/client/bip-avrcp.h |  12 +++

Id got with bit.{c,h} so we can reuse the implementation for BIP.

Quoted 154 lines
 obexd/client/manager.c   |   2 +
 obexd/client/transfer.c  |  16 ++++
 obexd/client/transfer.h  |   2 +
 6 files changed, 204 insertions(+)
 create mode 100644 obexd/client/bip-avrcp.c
 create mode 100644 obexd/client/bip-avrcp.h
Makefile.obexd +1 -0
index 4cdce73af..8038d2327 100644
@@ -81,6 +81,7 @@ obexd_src_obexd_SOURCES = $(btio_sources) $(gobex_sources) \
                        obexd/client/ftp.h obexd/client/ftp.c \
                        obexd/client/opp.h obexd/client/opp.c \
                        obexd/client/map.h obexd/client/map.c \
+                       obexd/client/bip-avrcp.h obexd/client/bip-avrcp.c \
                        obexd/client/map-event.h obexd/client/map-event.c \
                        obexd/client/transfer.h obexd/client/transfer.c \
                        obexd/client/transport.h obexd/client/transport.c \
obexd/client/bip-avrcp.c new file +129 -0
new file mode 100644
index 000000000..ca702be5a
@@ -0,0 +1,171 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *
+ *  OBEX Client
+ *
+ *  Copyright (C) 2024  Collabora Ltd.
+ *
+ *
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gdbus/gdbus.h"
+#include "gobex/gobex.h"
+
+#include "obexd/src/log.h"
+#include "transfer.h"
+#include "session.h"
+#include "driver.h"
+#include "bip-avrcp.h"
+
+#define OBEX_BIP_AVRCP_UUID \
+       "\x71\x63\xDD\x54\x4A\x7E\x11\xE2\xB4\x7C\x00\x50\xC2\x49\x00\x48"
+#define OBEX_BIP_AVRCP_UUID_LEN 16
+
+#define BIP_AVRCP_INTERFACE "org.bluez.obex.BipAvrcp1"
+#define ERROR_INTERFACE "org.bluez.obex.Error"
+#define BIP_AVRCP_UUID "0000111A-0000-1000-8000-00805f9b34fb"
+
+#define IMG_HANDLE_TAG  0x30
+
+static DBusConnection *conn;
+
+struct bip_avrcp_data {
+       struct obc_session *session;
+};
+
+static DBusMessage *get_image_thumbnail(DBusConnection *connection,
+                                       DBusMessage *message, void *user_data)
+{
+       struct bip_avrcp_data *bip_avrcp = user_data;
+       const char *handle = NULL, *image_path = NULL;
+       struct obc_transfer *transfer;
+       GObexHeader *header;
+       DBusMessage *reply = NULL;
+       GError *err = NULL;
+
+       DBG("");
+
+       if (dbus_message_get_args(message, NULL,
+                               DBUS_TYPE_STRING, &image_path,
+                               DBUS_TYPE_STRING, &handle,
+                               DBUS_TYPE_INVALID) == FALSE) {
+               reply = g_dbus_create_error(message,
+                               ERROR_INTERFACE ".InvalidArguments", NULL);
+               goto fail;
+       }
+
+       transfer = obc_transfer_get("x-bt/img-thm", NULL, image_path, &err);
+       if (transfer == NULL)
+               goto fail;
+
+       header = g_obex_header_new_unicode(IMG_HANDLE_TAG, handle);
+       obc_transfer_add_header(transfer, header);
+
+       if (!obc_session_queue(bip_avrcp->session, transfer, NULL, NULL, &err))
+               goto fail;
+
+       return obc_transfer_create_dbus_reply(transfer, message);
+
+fail:
+       reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+                                                               err->message);
+       g_error_free(err);
+       return reply;
+}
+
+static const GDBusMethodTable bip_avrcp_methods[] = {
+       { GDBUS_ASYNC_METHOD("GetImageThumbnail",
+               GDBUS_ARGS({ "file", "s" }, { "handle", "s"}),
+               GDBUS_ARGS({ "transfer", "o" }, { "properties", "a{sv}" }),
+               get_image_thumbnail) },
+       { }
+};
+
+static void bip_avrcp_free(void *data)
+{
+       struct bip_avrcp_data *bip_avrcp = data;
+
+       obc_session_unref(bip_avrcp->session);
+       g_free(bip_avrcp);
+}
+
+static int bip_avrcp_probe(struct obc_session *session)
+{
+       struct bip_avrcp_data *bip_avrcp;
+       const char *path;
+
+       path = obc_session_get_path(session);
+
+       DBG("%s", path);
+
+       bip_avrcp = g_try_new0(struct bip_avrcp_data, 1);
+       if (!bip_avrcp)
+               return -ENOMEM;
+
+       bip_avrcp->session = obc_session_ref(session);
+
+       if (!g_dbus_register_interface(conn, path, BIP_AVRCP_INTERFACE,
+                                       bip_avrcp_methods,
+                                       NULL, NULL,
+                                       bip_avrcp, bip_avrcp_free)) {
+               bip_avrcp_free(bip_avrcp);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+static void bip_avrcp_remove(struct obc_session *session)
+{
+       const char *path = obc_session_get_path(session);
+
+       DBG("%s", path);
+
+       g_dbus_unregister_interface(conn, path, BIP_AVRCP_INTERFACE);

obexd/client/bip-avrcp.c line 139

Quoted 10 lines
obexd/client/bip-avrcp.c new file +10 -0
+}
+
+static struct obc_driver bip_avrcp = {
+       .service = "BIP-AVRCP",
+       .uuid = BIP_AVRCP_UUID,
+       .target = OBEX_BIP_AVRCP_UUID,
+       .target_len = OBEX_BIP_AVRCP_UUID_LEN,
+       .probe = bip_avrcp_probe,
+       .remove = bip_avrcp_remove
+};

This can stay as bip_arvcp, since obc_driver is per-uuid, but in the future if someone wants to add BIP uuid it just registers another driver.

Quoted 62 lines
obexd/client/bip-avrcp.c new file +31 -0
+int bip_avrcp_init(void)
+{
+       int err;
+
+       DBG("");
+
+       conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
+       if (!conn)
+               return -EIO;
+
+       err = obc_driver_register(&bip_avrcp);
+       if (err < 0)
+               goto failed;
+
+       return 0;
+
+failed:
+       dbus_connection_unref(conn);
+       conn = NULL;
+       return err;
+}
+
+void bip_avrcp_exit(void)
+{
+       DBG("");
+
+       dbus_connection_unref(conn);
+       conn = NULL;
+
+       obc_driver_unregister(&bip_avrcp);
+}
obexd/client/bip-avrcp.h new file +12 -0
new file mode 100644
index 000000000..acd8068f2
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *
+ *  OBEX Client
+ *
+ *  Copyright (C) 2024  Collabora Ltd.
+ *
+ *
+ */
+
+int bip_avrcp_init(void);
+void bip_avrcp_exit(void);
obexd/client/manager.c +1 -0
index 52c00fb0c..5078f56da 100644
@@ -32,6 +32,7 @@
 #include "pbap.h"
 #include "sync.h"
 #include "map.h"
+#include "bip-avrcp.h"
 #include "manager.h"
 
 #define CLIENT_INTERFACE       "org.bluez.obex.Client1"

obexd/client/manager.c static const struct obc_module { · line 262

Quoted 4 lines
obexd/client/manager.c +1 -0
@@ -258,6 +259,7 @@ static const struct obc_module {
        { "pbap", pbap_init, pbap_exit },
        { "sync", sync_init, sync_exit },
        { "map", map_init, map_exit },
+       { "bip-avrcp", bip_avrcp_init, bip_avrcp_exit },

For the module it shall be just bip, avrcp specific UUID is handled by a dedicated driver.

Quoted 18 lines
obexd/client/manager.c +0 -0
        { }
 };
 
obexd/client/transfer.c +1 -0
index a7a85a0c0..fdf32a985 100644
@@ -57,6 +57,7 @@ struct obc_transfer {
        GObex *obex;
        uint8_t status;
        GObexApparam *apparam;
+       GSList *headers;
        guint8 op;
        struct transfer_callback *callback;
        DBusConnection *conn;
@@ -820,6 +821,16 @@ static gboolean transfer_start_get(struct obc_transfer *transfer, GError **err)
                g_obex_packet_add_bytes(req, G_OBEX_HDR_TYPE, transfer->type,
                                                strlen(transfer->type) + 1);

obexd/client/transfer.c static gboolean transfer_start_get(struct obc_transfer *transfer, GError **err) · line 832

Quoted 10 lines
obexd/client/transfer.c +9 -0
 
+       if (transfer->headers != NULL) {
+               GSList *l;
+
+               for (l = transfer->headers; l != NULL; l = g_slist_next(l)) {
+                       GObexHeader *hdr = l->data;
+
+                       g_obex_packet_add_header(req, hdr);
+               }
+       }

This one seems to be a different change, so Id put it in a different patch.

Quoted 27 lines
obexd/client/transfer.c +6 -0
+
        if (transfer->apparam != NULL) {
                hdr = g_obex_header_new_apparam(transfer->apparam);
                g_obex_packet_add_header(req, hdr);
@@ -974,3 +985,8 @@ gint64 obc_transfer_get_size(struct obc_transfer *transfer)
 {
        return transfer->size;
 }
+
+void obc_transfer_add_header(struct obc_transfer *transfer, void *data)
+{
+       transfer->headers = g_slist_append(transfer->headers, data);
+}
obexd/client/transfer.h +2 -1
index 323332a62..1ed195984 100644
@@ -47,3 +47,5 @@ gint64 obc_transfer_get_size(struct obc_transfer *transfer);
 
 DBusMessage *obc_transfer_create_dbus_reply(struct obc_transfer *transfer,
                                                        DBusMessage *message);
+
+void obc_transfer_add_header(struct obc_transfer *transfer, void *data);
--

2.34.1

Signature · 1 line
Luiz Augusto von Dentz
#7 lore raw

PATCH v2 5/7 obexd: Add GetImageProperties to bip-avrcp

In reply to Frédéric Danis

This allows to get the different version of the image provided by the remote device to chose the one to use with GetImage.

This bip-common.[ch] files are based on previous work done by Jakub Adamek for GSoC 2011, see [1] and [2].

[1] https://www.bluez.org/gsoc-basic-image-profilebip/
[2] https://github.com/enkait/Basic-Imaging-Profile-in-obexd/blob/gsoc_final/plugins/bip_util.c
---
v1 -> v2: Parse integer properties as integer instead of string

          Return GetImageProperties values as aa{sv} instead of aa{ss}
 Makefile.obexd            |   1 +
 obexd/client/bip-avrcp.c  | 101 +++++
 obexd/client/bip-common.c | 781 ++++++++++++++++++++++++++++++++++++++
 obexd/client/bip-common.h |  19 +
 4 files changed, 902 insertions(+)
 create mode 100644 obexd/client/bip-common.c
 create mode 100644 obexd/client/bip-common.h
Makefile.obexd +1 -0
index 8038d2327..2e9689dea 100644
@@ -82,6 +82,7 @@ obexd_src_obexd_SOURCES = $(btio_sources) $(gobex_sources) \
 			obexd/client/opp.h obexd/client/opp.c \
 			obexd/client/map.h obexd/client/map.c \
 			obexd/client/bip-avrcp.h obexd/client/bip-avrcp.c \
+			obexd/client/bip-common.h obexd/client/bip-common.c \
 			obexd/client/map-event.h obexd/client/map-event.c \
 			obexd/client/transfer.h obexd/client/transfer.c \
 			obexd/client/transport.h obexd/client/transport.c \
obexd/client/bip-avrcp.c +101 -0

119 lines not on this page · raw message

obexd/client/bip-common.c new file +781 -0

781 lines not on this page · raw message

obexd/client/bip-common.h new file +19 -0
new file mode 100644
index 000000000..0fee54636
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *
+ *  OBEX Client
+ *
+ *  Copyright (C) 2024  Collabora Ltd.
+ *
+ *
+ */
+
+#include <glib.h>
+#include "gdbus/gdbus.h"
+
+struct prop_object;
+
+struct prop_object *parse_properties(char *data, unsigned int length,
+							int *err);
+gboolean verify_properties(struct prop_object *obj);
+void append_properties(DBusMessageIter *args, struct prop_object *obj);
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 6/7 obexd: Add GetImage to bip-avrcp

In reply to Frédéric Danis

Retrieves the image corresponding to the handle and the description, as one of the descriptions retrieved by GetImageProperties, and store it in a local file.

If the "transform" property description exists it should be set to one of the value listed by GetImageProperties for this description.

---
 obexd/client/bip-avrcp.c  | 155 ++++++++++++++++++++++++++++++++++++++
 obexd/client/bip-common.c |  21 +++++-
 obexd/client/bip-common.h |   5 ++
 profiles/audio/avrcp.c    |  10 ++-
 4 files changed, 186 insertions(+), 5 deletions(-)
obexd/client/bip-avrcp.c +155 -0
index 272a288b4..8f00ddf8d 100644
@@ -32,6 +32,14 @@
 #define BIP_AVRCP_UUID "0000111A-0000-1000-8000-00805f9b34fb"
 
 #define IMG_HANDLE_TAG  0x30
+#define IMG_DESC_TAG    0x71
+
+#define EOL_CHARS "\n"
+#define IMG_DESC_BEGIN "<image-descriptor version=\"1.0\">" EOL_CHARS
+#define IMG_BEGIN "<image encoding=\"%s\" pixel=\"%s\""
+#define IMG_TRANSFORM " transformation=\"%s\""
+#define IMG_END "/>" EOL_CHARS
+#define IMG_DESC_END "</image-descriptor>" EOL_CHARS
 
 static DBusConnection *conn;
 
@@ -175,11 +183,158 @@ fail:
 	return reply;
 }
 
+static gboolean parse_get_image_dict(DBusMessage *msg, char **path,
+					char **handle, char **pixel,
+					char **encoding, uint64_t *maxsize,
+							char **transform)
+{
+	DBusMessageIter iter, array;
+
+	DBG("");
+
+	*path = NULL;
+	*handle = NULL;
+	*pixel = NULL;
+	*encoding = NULL;
+	*transform = NULL;
+
+	dbus_message_iter_init(msg, &iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		goto failed;
+	dbus_message_iter_get_basic(&iter, path);
+	*path = g_strdup(*path);
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		goto failed;
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, handle);
+	*handle = g_strdup(*handle);
+	dbus_message_iter_next(&iter);
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		goto failed;
+
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key, *val;
+
+		dbus_message_iter_recurse(&array, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			return FALSE;
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+		switch (dbus_message_iter_get_arg_type(&value)) {
+		case DBUS_TYPE_STRING:
+			dbus_message_iter_get_basic(&value, &val);
+			if (g_str_equal(key, "pixel")) {
+				if (!parse_pixel_range(val, NULL, NULL, NULL))
+					goto failed;
+				*pixel = g_strdup(val);
+			} else if (g_str_equal(key, "encoding")) {
+				if (!verify_encoding(val))
+					goto failed;
+				*encoding = g_strdup(val);
+				if (*encoding == NULL)
+					goto failed;
+			} else if (g_str_equal(key, "transformation")) {
+				*transform = parse_transform(val);
+				if (*transform == NULL)
+					goto failed;
+			}
+			break;
+		case DBUS_TYPE_UINT64:
+			if (g_str_equal(key, "maxsize") == TRUE) {
+				dbus_message_iter_get_basic(&value, maxsize);
+				if (*maxsize == 0)
+					goto failed;
+			}
+			break;
+		}
+		dbus_message_iter_next(&array);
+	}
+
+	if (*pixel == NULL)
+		*pixel = strdup("");
+	if (*encoding == NULL)
+		*encoding = strdup("");
+
+	DBG("pixel: '%s' encoding: '%s' maxsize: '%lu' transform: '%s'",
+			*pixel, *encoding, *maxsize, *transform
+	);
+
+	return TRUE;
+failed:
+	g_free(*path);
+	g_free(*handle);
+	g_free(*pixel);
+	g_free(*encoding);
+	g_free(*transform);
+	return FALSE;
+}
+
+static DBusMessage *get_image(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct bip_avrcp_data *bip_avrcp = user_data;
+	char *handle = NULL, *image_path = NULL, *transform = NULL,
+		*encoding = NULL, *pixel = NULL;
+	uint64_t maxsize;
+	struct obc_transfer *transfer;
+	GObexHeader *header;
+	DBusMessage *reply = NULL;
+	GString *descriptor = NULL;
+	GError *err = NULL;
+
+	DBG("");
+
+	if (!parse_get_image_dict(message, &image_path, &handle, &pixel,
+					&encoding, &maxsize, &transform))
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	transfer = obc_transfer_get("x-bt/img-img", NULL, image_path, &err);
+	if (transfer == NULL)
+		goto fail;
+
+	header = g_obex_header_new_unicode(IMG_HANDLE_TAG, handle);
+	obc_transfer_add_header(transfer, header);
+
+	descriptor = g_string_new(IMG_DESC_BEGIN);
+	g_string_append_printf(descriptor, IMG_BEGIN, encoding, pixel);
+	if (transform != NULL)
+		g_string_append_printf(descriptor, IMG_TRANSFORM, transform);
+	g_string_append(descriptor, IMG_END);
+	descriptor = g_string_append(descriptor, IMG_DESC_END);
+	header = g_obex_header_new_bytes(IMG_DESC_TAG, descriptor->str,
+						descriptor->len);
+	obc_transfer_add_header(transfer, header);
+	g_string_free(descriptor, TRUE);
+
+	if (!obc_session_queue(bip_avrcp->session, transfer, NULL, NULL, &err))
+		goto fail;
+
+	return obc_transfer_create_dbus_reply(transfer, message);
+
+fail:
+	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+								err->message);
+	g_error_free(err);
+	return reply;
+}
+
 static const GDBusMethodTable bip_avrcp_methods[] = {
 	{ GDBUS_ASYNC_METHOD("GetImageProperties",
 		GDBUS_ARGS({ "handle", "s"}),
 		GDBUS_ARGS({ "properties", "aa{sv}" }),
 		get_image_properties) },
+	{ GDBUS_ASYNC_METHOD("GetImage",
+		GDBUS_ARGS({ "file", "s" }, { "handle", "s"},
+				{"properties", "a{sv}"}),
+		GDBUS_ARGS({ "transfer", "o" }, { "properties", "a{sv}" }),
+		get_image) },
 	{ GDBUS_ASYNC_METHOD("GetImageThumbnail",
 		GDBUS_ARGS({ "file", "s" }, { "handle", "s"}),
 		GDBUS_ARGS({ "transfer", "o" }, { "properties", "a{sv}" }),
obexd/client/bip-common.c +20 -1
index b93921df5..16a199977 100644
@@ -49,7 +49,7 @@ static const gchar *convBIP2IM(const gchar *encoding)
 	return NULL;
 }
 
-static gboolean parse_pixel_range(const gchar *dim, unsigned int *lower_ret,
+gboolean parse_pixel_range(const gchar *dim, unsigned int *lower_ret,
 						unsigned int *upper_ret,
 						gboolean *fixed_ratio_ret)
 {
@@ -139,6 +139,18 @@ char *transforms[] = {
 	NULL
 };
 
+gboolean verify_encoding(const char *encoding)
+{
+	struct encconv_pair *et = encconv_table;
+
+	while (et->bip) {
+		if (g_strcmp0(encoding, et->bip) == 0)
+			return TRUE;
+		et++;
+	}
+	return FALSE;
+}
+
 static gboolean verify_transform(const char *transform)
 {
 	char **str = transforms;
@@ -151,6 +163,13 @@ static gboolean verify_transform(const char *transform)
 	return FALSE;
 }
 
+char *parse_transform(const char *transform)
+{
+	if (!verify_transform(transform))
+		return NULL;
+	return g_strdup(transform);
+}
+
 static char *parse_transform_list(const char *transform)
 {
 	char **args = NULL, **arg = NULL;
obexd/client/bip-common.h +5 -0
index 0fee54636..6e7aac375 100644
@@ -13,6 +13,11 @@
 
 struct prop_object;
 
+gboolean parse_pixel_range(const gchar *dim, unsigned int *lower_ret,
+						unsigned int *upper_ret,
+						gboolean *fixed_ratio_ret);
+gboolean verify_encoding(const char *encoding);
+char *parse_transform(const char *transform);
 struct prop_object *parse_properties(char *data, unsigned int length,
 							int *err);
 gboolean verify_properties(struct prop_object *obj);
profiles/audio/avrcp.c +6 -4
index fe24b5a92..ee750f50b 100644
@@ -415,10 +415,12 @@ static sdp_record_t *avrcp_ct_record(bool browsing)
 	uint16_t lp = AVCTP_CONTROL_PSM;
 	uint16_t avctp_ver = 0x0103;
 	uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
-						AVRCP_FEATURE_CATEGORY_2 |
-						AVRCP_FEATURE_CATEGORY_3 |
-						AVRCP_FEATURE_CATEGORY_4 |
-						AVRCP_FEATURE_CT_GET_THUMBNAIL);
+					AVRCP_FEATURE_CATEGORY_2 |
+					AVRCP_FEATURE_CATEGORY_3 |
+					AVRCP_FEATURE_CATEGORY_4 |
+					AVRCP_FEATURE_CT_GET_IMAGE_PROP |
+					AVRCP_FEATURE_CT_GET_IMAGE |
+					AVRCP_FEATURE_CT_GET_THUMBNAIL);
 
 	record = sdp_record_alloc();
 	if (!record)
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH BlueZ v2 6/7] obexd: Add GetImage to bip-avrcp

Hi Frédéric,

Quoted 263 lines · Frédéric Danis

Retrieves the image corresponding to the handle and the description, as one of the descriptions retrieved by GetImageProperties, and store it in a local file.

If the "transform" property description exists it should be set to one of the value listed by GetImageProperties for this description.

---
 obexd/client/bip-avrcp.c  | 155 ++++++++++++++++++++++++++++++++++++++
 obexd/client/bip-common.c |  21 +++++-
 obexd/client/bip-common.h |   5 ++
 profiles/audio/avrcp.c    |  10 ++-
 4 files changed, 186 insertions(+), 5 deletions(-)
obexd/client/bip-avrcp.c +155 -0
index 272a288b4..8f00ddf8d 100644
@@ -32,6 +32,14 @@
 #define BIP_AVRCP_UUID "0000111A-0000-1000-8000-00805f9b34fb"
 
 #define IMG_HANDLE_TAG  0x30
+#define IMG_DESC_TAG    0x71
+
+#define EOL_CHARS "\n"
+#define IMG_DESC_BEGIN "<image-descriptor version=\"1.0\">" EOL_CHARS
+#define IMG_BEGIN "<image encoding=\"%s\" pixel=\"%s\""
+#define IMG_TRANSFORM " transformation=\"%s\""
+#define IMG_END "/>" EOL_CHARS
+#define IMG_DESC_END "</image-descriptor>" EOL_CHARS
 
 static DBusConnection *conn;
 
@@ -175,11 +183,158 @@ fail:
        return reply;
 }
 
+static gboolean parse_get_image_dict(DBusMessage *msg, char **path,
+                                       char **handle, char **pixel,
+                                       char **encoding, uint64_t *maxsize,
+                                                       char **transform)
+{
+       DBusMessageIter iter, array;
+
+       DBG("");
+
+       *path = NULL;
+       *handle = NULL;
+       *pixel = NULL;
+       *encoding = NULL;
+       *transform = NULL;
+
+       dbus_message_iter_init(msg, &iter);
+
+       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+               goto failed;
+       dbus_message_iter_get_basic(&iter, path);
+       *path = g_strdup(*path);
+       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+               goto failed;
+       dbus_message_iter_next(&iter);
+       dbus_message_iter_get_basic(&iter, handle);
+       *handle = g_strdup(*handle);
+       dbus_message_iter_next(&iter);
+       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+               goto failed;
+
+       dbus_message_iter_recurse(&iter, &array);
+
+       while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+               DBusMessageIter entry, value;
+               const char *key, *val;
+
+               dbus_message_iter_recurse(&array, &entry);
+
+               if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+                       return FALSE;
+               dbus_message_iter_get_basic(&entry, &key);
+               dbus_message_iter_next(&entry);
+               dbus_message_iter_recurse(&entry, &value);
+               switch (dbus_message_iter_get_arg_type(&value)) {
+               case DBUS_TYPE_STRING:
+                       dbus_message_iter_get_basic(&value, &val);
+                       if (g_str_equal(key, "pixel")) {
+                               if (!parse_pixel_range(val, NULL, NULL, NULL))
+                                       goto failed;
+                               *pixel = g_strdup(val);
+                       } else if (g_str_equal(key, "encoding")) {
+                               if (!verify_encoding(val))
+                                       goto failed;
+                               *encoding = g_strdup(val);
+                               if (*encoding == NULL)
+                                       goto failed;
+                       } else if (g_str_equal(key, "transformation")) {
+                               *transform = parse_transform(val);
+                               if (*transform == NULL)
+                                       goto failed;
+                       }
+                       break;
+               case DBUS_TYPE_UINT64:
+                       if (g_str_equal(key, "maxsize") == TRUE) {
+                               dbus_message_iter_get_basic(&value, maxsize);
+                               if (*maxsize == 0)
+                                       goto failed;
+                       }
+                       break;
+               }
+               dbus_message_iter_next(&array);
+       }
+
+       if (*pixel == NULL)
+               *pixel = strdup("");
+       if (*encoding == NULL)
+               *encoding = strdup("");
+
+       DBG("pixel: '%s' encoding: '%s' maxsize: '%lu' transform: '%s'",
+                       *pixel, *encoding, *maxsize, *transform
+       );
+
+       return TRUE;
+failed:
+       g_free(*path);
+       g_free(*handle);
+       g_free(*pixel);
+       g_free(*encoding);
+       g_free(*transform);
+       return FALSE;
+}
+
+static DBusMessage *get_image(DBusConnection *connection,
+                                       DBusMessage *message, void *user_data)
+{
+       struct bip_avrcp_data *bip_avrcp = user_data;
+       char *handle = NULL, *image_path = NULL, *transform = NULL,
+               *encoding = NULL, *pixel = NULL;
+       uint64_t maxsize;
+       struct obc_transfer *transfer;
+       GObexHeader *header;
+       DBusMessage *reply = NULL;
+       GString *descriptor = NULL;
+       GError *err = NULL;
+
+       DBG("");
+
+       if (!parse_get_image_dict(message, &image_path, &handle, &pixel,
+                                       &encoding, &maxsize, &transform))
+               return g_dbus_create_error(message,
+                               ERROR_INTERFACE ".InvalidArguments", NULL);
+
+       transfer = obc_transfer_get("x-bt/img-img", NULL, image_path, &err);
+       if (transfer == NULL)
+               goto fail;
+
+       header = g_obex_header_new_unicode(IMG_HANDLE_TAG, handle);
+       obc_transfer_add_header(transfer, header);
+
+       descriptor = g_string_new(IMG_DESC_BEGIN);
+       g_string_append_printf(descriptor, IMG_BEGIN, encoding, pixel);
+       if (transform != NULL)
+               g_string_append_printf(descriptor, IMG_TRANSFORM, transform);
+       g_string_append(descriptor, IMG_END);
+       descriptor = g_string_append(descriptor, IMG_DESC_END);
+       header = g_obex_header_new_bytes(IMG_DESC_TAG, descriptor->str,
+                                               descriptor->len);
+       obc_transfer_add_header(transfer, header);
+       g_string_free(descriptor, TRUE);
+
+       if (!obc_session_queue(bip_avrcp->session, transfer, NULL, NULL, &err))
+               goto fail;
+
+       return obc_transfer_create_dbus_reply(transfer, message);
+
+fail:
+       reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+                                                               err->message);
+       g_error_free(err);
+       return reply;
+}
+
 static const GDBusMethodTable bip_avrcp_methods[] = {
        { GDBUS_ASYNC_METHOD("GetImageProperties",
                GDBUS_ARGS({ "handle", "s"}),
                GDBUS_ARGS({ "properties", "aa{sv}" }),
                get_image_properties) },
+       { GDBUS_ASYNC_METHOD("GetImage",
+               GDBUS_ARGS({ "file", "s" }, { "handle", "s"},
+                               {"properties", "a{sv}"}),
+               GDBUS_ARGS({ "transfer", "o" }, { "properties", "a{sv}" }),
+               get_image) },
        { GDBUS_ASYNC_METHOD("GetImageThumbnail",
                GDBUS_ARGS({ "file", "s" }, { "handle", "s"}),
                GDBUS_ARGS({ "transfer", "o" }, { "properties", "a{sv}" }),
obexd/client/bip-common.c +20 -1
index b93921df5..16a199977 100644
@@ -49,7 +49,7 @@ static const gchar *convBIP2IM(const gchar *encoding)
        return NULL;
 }
 
-static gboolean parse_pixel_range(const gchar *dim, unsigned int *lower_ret,
+gboolean parse_pixel_range(const gchar *dim, unsigned int *lower_ret,
                                                unsigned int *upper_ret,
                                                gboolean *fixed_ratio_ret)
 {
@@ -139,6 +139,18 @@ char *transforms[] = {
        NULL
 };
 
+gboolean verify_encoding(const char *encoding)
+{
+       struct encconv_pair *et = encconv_table;
+
+       while (et->bip) {
+               if (g_strcmp0(encoding, et->bip) == 0)
+                       return TRUE;
+               et++;
+       }
+       return FALSE;
+}
+
 static gboolean verify_transform(const char *transform)
 {
        char **str = transforms;
@@ -151,6 +163,13 @@ static gboolean verify_transform(const char *transform)
        return FALSE;
 }
 
+char *parse_transform(const char *transform)
+{
+       if (!verify_transform(transform))
+               return NULL;
+       return g_strdup(transform);
+}
+
 static char *parse_transform_list(const char *transform)
 {
        char **args = NULL, **arg = NULL;
obexd/client/bip-common.h +5 -0
index 0fee54636..6e7aac375 100644
@@ -13,6 +13,11 @@
 
 struct prop_object;
 
+gboolean parse_pixel_range(const gchar *dim, unsigned int *lower_ret,
+                                               unsigned int *upper_ret,
+                                               gboolean *fixed_ratio_ret);
+gboolean verify_encoding(const char *encoding);
+char *parse_transform(const char *transform);
 struct prop_object *parse_properties(char *data, unsigned int length,
                                                        int *err);
 gboolean verify_properties(struct prop_object *obj);
profiles/audio/avrcp.c +0 -0
index fe24b5a92..ee750f50b 100644
@@ -415,10 +415,12 @@ static sdp_record_t *avrcp_ct_record(bool browsing)
        uint16_t lp = AVCTP_CONTROL_PSM;
        uint16_t avctp_ver = 0x0103;
        uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |

profiles/audio/avrcp.c static sdp_record_t *avrcp_ct_record(bool browsing) · line 423

Quoted 10 lines
profiles/audio/avrcp.c +6 -4
-                                               AVRCP_FEATURE_CATEGORY_2 |
-                                               AVRCP_FEATURE_CATEGORY_3 |
-                                               AVRCP_FEATURE_CATEGORY_4 |
-                                               AVRCP_FEATURE_CT_GET_THUMBNAIL);
+                                       AVRCP_FEATURE_CATEGORY_2 |
+                                       AVRCP_FEATURE_CATEGORY_3 |
+                                       AVRCP_FEATURE_CATEGORY_4 |
+                                       AVRCP_FEATURE_CT_GET_IMAGE_PROP |
+                                       AVRCP_FEATURE_CT_GET_IMAGE |
+                                       AVRCP_FEATURE_CT_GET_THUMBNAIL);

Changes to obexd and avrcp shall probably be split, also make sure the versioning is proper, if I recall it correctly it was added on AVRCP 1.6 so we need to make sure that it is reflected correctly in the record.

Quoted 6 lines
profiles/audio/avrcp.c +0 -1
        record = sdp_record_alloc();
        if (!record)
--

2.34.1

Signature · 1 line
Luiz Augusto von Dentz
#10 lore raw

PATCH v2 7/7 doc: Add description of org.bluez.obex.BipAvrcp

In reply to Frédéric Danis

This new interface allows to get the image referenced in the audio metadata ImgHandle available in org.bluez.MediaPlayer track properties. The image handle is only available in track info if an OBEX session is connected to the ObexPort port provided in org.bluez.MediaPlayer properties.
---
v1 -> v2: Set new interface as experimental

 Makefile.am                     |  9 +++--
 doc/org.bluez.obex.BipAvrcp.rst | 72 +++++++++++++++++++++++++++++++++
 doc/org.bluez.obex.Client.rst   |  1 +
 3 files changed, 79 insertions(+), 3 deletions(-)
 create mode 100644 doc/org.bluez.obex.BipAvrcp.rst
Makefile.am +6 -3
index 88044aa05..3a9728782 100644
@@ -382,7 +382,8 @@ man_MANS += doc/org.bluez.obex.Client.5 doc/org.bluez.obex.Session.5 \
 		doc/org.bluez.obex.PhonebookAccess.5 \
 		doc/org.bluez.obex.MessageAccess.5 \
 		doc/org.bluez.obex.Message.5 \
-		doc/org.bluez.obex.AgentManager.5 doc/org.bluez.obex.Agent.5
+		doc/org.bluez.obex.AgentManager.5 doc/org.bluez.obex.Agent.5 \
+		doc/org.bluez.obex.BipAvrcp.5
 endif
 manual_pages += src/bluetoothd.8
 manual_pages += doc/l2cap.7 doc/rfcomm.7
@@ -415,7 +416,8 @@ manual_pages += doc/org.bluez.obex.Client.5 doc/org.bluez.obex.Session.5 \
 		doc/org.bluez.obex.PhonebookAccess.5 \
 		doc/org.bluez.obex.MessageAccess.5 \
 		doc/org.bluez.obex.Message.5 \
-		doc/org.bluez.obex.AgentManager.5 doc/org.bluez.obex.Agent.5
+		doc/org.bluez.obex.AgentManager.5 doc/org.bluez.obex.Agent.5 \
+		doc/org.bluez.obex.BipAvrcp.5
 
 EXTRA_DIST += src/genbuiltin src/bluetooth.conf \
 			src/main.conf profiles/network/network.conf \
@@ -497,7 +499,8 @@ EXTRA_DIST += doc/org.bluez.obex.Client.rst doc/org.bluez.obex.Session.rst \
 		doc/org.bluez.obex.PhonebookAccess.rst \
 		doc/org.bluez.obex.MessageAccess.rst \
 		doc/org.bluez.obex.Message.rst \
-		doc/org.bluez.obex.AgentManager.rst doc/org.bluez.obex.Agent.rst
+		doc/org.bluez.obex.AgentManager.rst doc/org.bluez.obex.Agent.rst \
+		doc/org.bluez.obex.BipAvrcp.rst
 
 EXTRA_DIST += doc/pics-opp.txt doc/pixit-opp.txt \
 		doc/pts-opp.txt
doc/org.bluez.obex.BipAvrcp.rst new file +72 -0

72 lines not on this page · raw message

doc/org.bluez.obex.Client.rst +1 -0
index 5ae7cc5e8..f20dd5baa 100644
@@ -43,6 +43,7 @@ object CreateSession(string destination, dict args)
 		:"opp":
 		:"pbap":
 		:"sync":
+		:"bip-avrcp":
 
 	:string Source:
 
Signature · 1 line
2.34.1