Skip to contentSkip to conversation

MediaFolder and MediaItem implementation

PATCH In review Luiz Augusto von Dentz 1 participant 18 messages Jun 14, 2013 – Jun 17, 2013 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

v3 cover MediaFolder and MediaItem implementation

From: Luiz Augusto von Dentz <[email protected]>

v2: Fixes ChangeFolder not working for subfolders past /Filesystem
v3: Add Search implementation, fix not forwarding errors properly and add patch to create current item if it doesn't exist.

This set of patches implements most of the functionality of MediaFolder and MediaItem interfaces.

Some remarks:

- ChangeFolder can only change one level at time, this perhaps gonna be changed in the future but for now this matches the limitation of AVRCP itself.
- ListItems returns the items in the correct order but GetManagedObjects does the reverse order due to use of g_slist_prepend.
- PlayItem and AddToNowPlaying works fine with iPhone but with WP8 is not working probably because the UIDCounter changes more frequently which needs some new notifications that are currently not implemented.

This can be tested using tools/mpris-player which will browse the NowPlaying list and show which item is currently being played, but the gnome extention itself needs patching which can be found here:

https://github.com/Vudentz/gnome-shell-extensions-mediaplayer

Or use the command line tool: tools/bluetooth-player

Luiz Augusto von Dentz (16):
audio/player: Split item creation
audio/AVRCP: Add browsed flag to player audio/AVRCP: Add support for GetFolderItems command audio/player: Add implementation of MediaFolder.ListItems audio/player: Add support for setting current Item object audio/player: Add function media_item_set_playable audio/player: Add support for MediaItem.Metadata property audio/AVRCP: Add support for ChangePath command audio/player: Add implementation of MediaFolder.ChangeFolder audio/AVRCP: Add support for PlayItem command audio/player: Add implementation of MediaItem.Play audio/AVRCP: Add support for AddToNowPlaying command audio/player: Add implementation of MediaItem.AddToNowPlaying audio/AVRCP: Add support for Search command audio/player: Add implementation of MediaFolder.Search audio/player: Create item on media_player_set_playlist_item

 profiles/audio/avrcp.c  | 488 ++++++++++++++++++++++++++++-
 profiles/audio/player.c | 804 ++++++++++++++++++++++++++++++++++++++++--------
 profiles/audio/player.h |  35 ++-
 3 files changed, 1187 insertions(+), 140 deletions(-)
Signature · 1 line
1.8.1.4
author maintainer
#1 lore raw

PATCH v3 1/16 audio/player: Split item creation

From: Luiz Augusto von Dentz <[email protected]>

This split item creation into two functions, media_player_create_folder for folders and media_player_create_item for regular items.

---
 profiles/audio/avrcp.c  |   4 +-
 profiles/audio/player.c | 343 +++++++++++++++++++++++++++++++++---------------
 profiles/audio/player.h |  11 +-
 3 files changed, 250 insertions(+), 108 deletions(-)
profiles/audio/avrcp.c +2 -2
index e6d0e72..3d54fbe 100644
@@ -2207,7 +2207,7 @@ static void avrcp_player_parse_features(struct avrcp_player *player,
 	if (features[7] & 0x08) {
 		media_player_set_browsable(mp, true);
 		media_player_create_folder(mp, "/Filesystem",
-						PLAYER_FOLDER_TYPE_MIXED);
+						PLAYER_FOLDER_TYPE_MIXED, 0);
 	}
 
 	if (features[7] & 0x10)
@@ -2215,7 +2215,7 @@ static void avrcp_player_parse_features(struct avrcp_player *player,
 
 	if (features[8] & 0x02) {
 		media_player_create_folder(mp, "/NowPlaying",
-						PLAYER_FOLDER_TYPE_MIXED);
+						PLAYER_FOLDER_TYPE_MIXED, 0);
 		media_player_set_playlist(mp, "/NowPlaying");
 	}
 }
profiles/audio/player.c +239 -104

511 lines not on this page · raw message

profiles/audio/player.h +9 -2
index 852042e..6e44308 100644
@@ -42,6 +42,7 @@ typedef enum {
 } player_folder_type_t;
 
 struct media_player;
+struct media_item;
 
 struct media_player_callback {
 	bool (*set_setting) (struct media_player *mp, const char *key,
@@ -75,8 +76,14 @@ void media_player_set_folder(struct media_player *mp, const char *path,
 								uint32_t items);
 void media_player_set_playlist(struct media_player *mp, const char *name);
 
-int media_player_create_folder(struct media_player *mp, const char *name,
-						player_folder_type_t type);
+struct media_item *media_player_create_folder(struct media_player *mp,
+						const char *name,
+						player_folder_type_t type,
+						uint64_t uid);
+struct media_item *media_player_create_item(struct media_player *mp,
+						const char *name,
+						player_item_type_t type,
+						uint64_t uid);
 
 void media_player_set_callbacks(struct media_player *mp,
 				const struct media_player_callback *cbs,
Signature · 1 line
1.8.1.4
author maintainer
#2 lore raw

PATCH v3 2/16 audio/AVRCP: Add browsed flag to player

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This flag indicates if the player is browsed and are checked to avoid setting the same player as browsed multiple times.

---
 profiles/audio/avrcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
profiles/audio/avrcp.c +3 -1
index 3d54fbe..90c80c3 100644
@@ -182,6 +182,7 @@ struct avrcp_player {
 	GSList *sessions;
 	uint16_t id;
 	uint16_t uid_counter;
+	bool browsed;
 	uint8_t *features;
 
 	struct avrcp_player_cb *cb;
@@ -2095,6 +2096,7 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
 		return FALSE;
 
 	player->uid_counter = bt_get_be16(&pdu->params[1]);
+	player->browsed = true;
 
 	items = bt_get_be32(&pdu->params[3]);
 
@@ -2444,7 +2446,7 @@ avrcp_parse_media_player_item(struct avrcp *session, uint8_t *operands,
 		media_player_set_name(mp, name);
 	}
 
-	if (session->player == player)
+	if (session->player == player && !player->browsed)
 		avrcp_set_browsed_player(session, player);
 
 	return player;
Signature · 1 line
1.8.1.4
author maintainer
#3 lore raw

PATCH v3 3/16 audio/AVRCP: Add support for GetFolderItems command

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds support for GetFolderItems command via player callback.

---
 profiles/audio/avrcp.c  | 197 +++++++++++++++++++++++++++++++++++++++++++++++-
 profiles/audio/player.h |   2 +
 2 files changed, 195 insertions(+), 4 deletions(-)
profiles/audio/avrcp.c +193 -4
index 90c80c3..1da9541 100644
@@ -177,14 +177,24 @@ struct pending_pdu {
 	uint16_t offset;
 };
 
+struct pending_list_items {
+	GSList *items;
+	uint32_t start;
+	uint32_t end;
+};
+
 struct avrcp_player {
 	struct avrcp_server *server;
 	GSList *sessions;
 	uint16_t id;
+	uint8_t scope;
+	uint64_t uid;
 	uint16_t uid_counter;
 	bool browsed;
 	uint8_t *features;
 
+	struct pending_list_items *p;
+
 	struct avrcp_player_cb *cb;
 	void *user_data;
 	GDestroyNotify destroy;
@@ -2077,6 +2087,158 @@ static const char *subtype_to_string(uint32_t subtype)
 	return "None";
 }
 
+static struct media_item *parse_media_element(struct avrcp *session,
+					uint8_t *operands, uint16_t len)
+{
+	struct avrcp_player *player;
+	struct media_player *mp;
+	uint16_t namelen;
+	char name[255];
+	uint64_t uid;
+
+	if (len < 13)
+		return NULL;
+
+	uid = bt_get_be64(&operands[0]);
+
+	namelen = MIN(bt_get_be16(&operands[11]), sizeof(name) - 1);
+	if (namelen > 0) {
+		memcpy(name, &operands[13], namelen);
+		name[namelen] = '\0';
+	}
+
+	player = session->player;
+	mp = player->user_data;
+
+	return media_player_create_item(mp, name, PLAYER_ITEM_TYPE_AUDIO, uid);
+}
+
+static struct media_item *parse_media_folder(struct avrcp *session,
+					uint8_t *operands, uint16_t len)
+{
+	struct avrcp_player *player = session->player;
+	struct media_player *mp = player->user_data;
+	uint16_t namelen;
+	char name[255];
+	uint64_t uid;
+	uint8_t type;
+
+	if (len < 12)
+		return NULL;
+
+	uid = bt_get_be64(&operands[0]);
+	type = operands[9];
+
+	namelen = MIN(bt_get_be16(&operands[12]), sizeof(name) - 1);
+	if (namelen > 0) {
+		memcpy(name, &operands[14], namelen);
+		name[namelen] = '\0';
+	}
+
+	return media_player_create_folder(mp, name, type, uid);
+}
+
+static void avrcp_list_items(struct avrcp *session, uint32_t start,
+								uint32_t end);
+static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands,
+					size_t operand_count, void *user_data)
+{
+	struct avrcp_browsing_header *pdu = (void *) operands;
+	struct avrcp *session = user_data;
+	struct avrcp_player *player = session->player;
+	struct pending_list_items *p = player->p;
+	uint16_t count;
+	uint32_t items, total;
+	size_t i;
+
+	if (pdu->params[0] != AVRCP_STATUS_SUCCESS || operand_count < 5)
+		goto done;
+
+	count = bt_get_be16(&operands[6]);
+	if (count == 0)
+		goto done;
+
+	for (i = 8; count && i + 3 < operand_count; count--) {
+		struct media_item *item;
+		uint8_t type;
+		uint16_t len;
+
+		type = operands[i++];
+		len = bt_get_be16(&operands[i]);
+		i += 2;
+
+		if (type != 0x03 && type != 0x02) {
+			i += len;
+			continue;
+		}
+
+		if (i + len > operand_count) {
+			error("Invalid item length");
+			break;
+		}
+
+		if (type == 0x03)
+			item = parse_media_element(session, &operands[i], len);
+		else if (type == 0x02)
+			item = parse_media_folder(session, &operands[i], len);
+
+		if (item) {
+			if (g_slist_find(p->items, item))
+				goto done;
+			p->items = g_slist_append(p->items, item);
+		}
+
+		i += len;
+	}
+
+	items = g_slist_length(p->items);
+	total = p->end - p->start;
+	if (items < total) {
+		avrcp_list_items(session, p->start + items + 1, p->end);
+		return FALSE;
+	}
+
+done:
+	g_slist_free(p->items);
+	g_free(p);
+	player->p = NULL;
+
+	return FALSE;
+}
+
+static void avrcp_list_items(struct avrcp *session, uint32_t start,
+								uint32_t end)
+{
+	uint8_t buf[AVRCP_BROWSING_HEADER_LENGTH + 10 +
+			AVRCP_MEDIA_ATTRIBUTE_LAST * sizeof(uint32_t)];
+	struct avrcp_player *player = session->player;
+	struct avrcp_browsing_header *pdu = (void *) buf;
+	uint16_t length = AVRCP_BROWSING_HEADER_LENGTH + 10;
+	uint32_t attribute;
+
+	memset(buf, 0, sizeof(buf));
+
+	pdu->pdu_id = AVRCP_GET_FOLDER_ITEMS;
+	pdu->param_len = htons(10 + sizeof(uint32_t));
+
+	pdu->params[0] = player->scope;
+
+	bt_put_be32(start, &pdu->params[1]);
+	bt_put_be32(end, &pdu->params[5]);
+
+	pdu->params[9] = 1;
+
+	/* Only the title (0x01) is mandatory. This can be extended to
+	 * support AVRCP_MEDIA_ATTRIBUTE_* attributes */
+	attribute = htonl(AVRCP_MEDIA_ATTRIBUTE_TITLE);
+	memcpy(&pdu->params[10], &attribute, sizeof(uint32_t));
+
+	length += sizeof(uint32_t);
+
+	avctp_send_browsing_req(session->conn, buf, length,
+					avrcp_list_items_rsp, session);
+}
+
 static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
 						uint8_t *operands,
 						size_t operand_count,
@@ -2339,6 +2501,33 @@ static int ct_rewind(struct media_player *mp, void *user_data)
 	return ct_press(player, AVC_REWIND);
 }
 
+static int ct_list_items(struct media_player *mp, const char *name,
+				uint32_t start, uint32_t end, void *user_data)
+{
+	struct avrcp_player *player = user_data;
+	struct avrcp *session;
+	struct pending_list_items *p;
+
+	if (player->p != NULL)
+		return -EBUSY;
+
+	session = player->sessions->data;
+
+	if (g_str_has_prefix(name, "/NowPlaying"))
+		player->scope = 0x03;
+	else
+		player->scope = 0x01;
+
+	avrcp_list_items(session, start, end);
+
+	p = g_new0(struct pending_list_items, 1);
+	p->start = start;
+	p->end = end;
+	player->p = p;
+
+	return 0;
+}
+
 static const struct media_player_callback ct_cbs = {
 	.set_setting	= ct_set_setting,
 	.play		= ct_play,
@@ -2348,6 +2537,7 @@ static const struct media_player_callback ct_cbs = {
 	.previous	= ct_previous,
 	.fast_forward	= ct_fast_forward,
 	.rewind		= ct_rewind,
+	.list_items	= ct_list_items,
 };
 
 static struct avrcp_player *create_ct_player(struct avrcp *session,
@@ -2582,11 +2772,10 @@ static void avrcp_status_changed(struct avrcp *session,
 static void avrcp_track_changed(struct avrcp *session,
 						struct avrcp_header *pdu)
 {
-	uint64_t uid;
-
 	if (session->browsing_id) {
-		uid = bt_get_be64(&pdu->params[1]);
-		avrcp_get_item_attributes(session, uid);
+		struct avrcp_player *player = session->player;
+		player->uid = bt_get_be64(&pdu->params[1]);
+		avrcp_get_item_attributes(session, player->uid);
 	} else
 		avrcp_get_element_attributes(session);
 }
profiles/audio/player.h +2 -0
index 6e44308..e7a885e 100644
@@ -54,6 +54,8 @@ struct media_player_callback {
 	int (*previous) (struct media_player *mp, void *user_data);
 	int (*fast_forward) (struct media_player *mp, void *user_data);
 	int (*rewind) (struct media_player *mp, void *user_data);
+	int (*list_items) (struct media_player *mp, const char *name,
+				uint32_t start, uint32_t end, void *user_data);
 };
 
 struct media_player *media_player_controller_create(const char *path,
Signature · 1 line
1.8.1.4
author maintainer
#4 lore raw

PATCH v3 4/16 audio/player: Add implementation of MediaFolder.ListItems

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/avrcp.c  |  21 ++++++-
 profiles/audio/player.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++-
 profiles/audio/player.h |   3 +
 3 files changed, 164 insertions(+), 3 deletions(-)
profiles/audio/avrcp.c +20 -1
index 1da9541..cbac603 100644
@@ -73,6 +73,7 @@
 #define AVRCP_STATUS_PARAM_NOT_FOUND		0x02
 #define AVRCP_STATUS_INTERNAL_ERROR		0x03
 #define AVRCP_STATUS_SUCCESS			0x04
+#define AVRCP_STATUS_OUT_OF_BOUNDS		0x0b
 #define AVRCP_STATUS_INVALID_PLAYER_ID		0x11
 #define AVRCP_STATUS_PLAYER_NOT_BROWSABLE	0x12
 #define AVRCP_STATUS_NO_AVAILABLE_PLAYERS	0x15
@@ -2150,10 +2151,26 @@ static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands,
 	uint16_t count;
 	uint32_t items, total;
 	size_t i;
+	int err = 0;
 
-	if (pdu->params[0] != AVRCP_STATUS_SUCCESS || operand_count < 5)
+	if (pdu == NULL) {
+		err = -ETIMEDOUT;
+		goto done;
+	}
+
+	/* AVRCP 1.5 - Page 76:
+	 * If the TG receives a GetFolderItems command for an empty folder then
+	 * the TG shall return the error (= Range Out of Bounds) in the status
+	 * field of the GetFolderItems response.
+	 */
+	if (pdu->params[0] == AVRCP_STATUS_OUT_OF_BOUNDS)
 		goto done;
 
+	if (pdu->params[0] != AVRCP_STATUS_SUCCESS || operand_count < 5) {
+		err = -EINVAL;
+		goto done;
+	}
+
 	count = bt_get_be16(&operands[6]);
 	if (count == 0)
 		goto done;
@@ -2199,6 +2216,8 @@ static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands,
 	}
 
 done:
+	media_player_list_complete(player->user_data, p->items, err);
+
 	g_slist_free(p->items);
 	g_free(p);
 	player->p = NULL;
profiles/audio/player.c +141 -2

176 lines not on this page · raw message

profiles/audio/player.h +3 -0
index e7a885e..4626a24 100644
@@ -87,6 +87,9 @@ struct media_item *media_player_create_item(struct media_player *mp,
 						player_item_type_t type,
 						uint64_t uid);
 
+void media_player_list_complete(struct media_player *mp, GSList *items,
+								int err);
+
 void media_player_set_callbacks(struct media_player *mp,
 				const struct media_player_callback *cbs,
 				void *user_data);
Signature · 1 line
1.8.1.4
author maintainer
#5 lore raw

PATCH v3 5/16 audio/player: Add support for setting current Item object

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This introduces media_player_set_playlist_item which is used when the current item UID is known, with this the application can tell what is the current item in the playlist.

---
 profiles/audio/avrcp.c  |  3 +++
 profiles/audio/player.c | 42 ++++++++++++++++++++++++++++++++++++------
 profiles/audio/player.h |  1 +
 3 files changed, 40 insertions(+), 6 deletions(-)
profiles/audio/avrcp.c +3 -0
index cbac603..539684d 100644
@@ -1961,6 +1961,9 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
 	struct media_player *mp = player->user_data;
 	int i;
 
+	if (player->uid > 0)
+		media_player_set_playlist_item(mp, player->uid);
+
 	for (i = 0; count > 0; count--) {
 		uint32_t id;
 		uint16_t charset, len;
profiles/audio/player.c +36 -6

58 lines not on this page · raw message

profiles/audio/player.h +1 -0
index 4626a24..3a388d2 100644
@@ -77,6 +77,7 @@ void media_player_set_searchable(struct media_player *mp, bool enabled);
 void media_player_set_folder(struct media_player *mp, const char *path,
 								uint32_t items);
 void media_player_set_playlist(struct media_player *mp, const char *name);
+void media_player_set_playlist_item(struct media_player *mp, uint64_t uid);
 
 struct media_item *media_player_create_folder(struct media_player *mp,
 						const char *name,
Signature · 1 line
1.8.1.4
author maintainer
#6 lore raw

PATCH v3 6/16 audio/player: Add function media_item_set_playable

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/avrcp.c  |  9 ++++++++-
 profiles/audio/player.c | 11 +++++++++++
 profiles/audio/player.h |  1 +
 3 files changed, 20 insertions(+), 1 deletion(-)
profiles/audio/avrcp.c +8 -1
index 539684d..d46e598 100644
@@ -2096,6 +2096,7 @@ static struct media_item *parse_media_element(struct avrcp *session,
 {
 	struct avrcp_player *player;
 	struct media_player *mp;
+	struct media_item *item;
 	uint16_t namelen;
 	char name[255];
 	uint64_t uid;
@@ -2114,7 +2115,13 @@ static struct media_item *parse_media_element(struct avrcp *session,
 	player = session->player;
 	mp = player->user_data;
 
-	return media_player_create_item(mp, name, PLAYER_ITEM_TYPE_AUDIO, uid);
+	item = media_player_create_item(mp, name, PLAYER_ITEM_TYPE_AUDIO, uid);
+	if (item == NULL)
+		return NULL;
+
+	media_item_set_playable(item, true);
+
+	return item;
 }
 
 static struct media_item *parse_media_folder(struct avrcp *session,
profiles/audio/player.c +11 -0
index c151560..69e8cd5 100644
@@ -1466,6 +1466,17 @@ static const GDBusPropertyTable media_item_properties[] = {
 	{ }
 };
 
+void media_item_set_playable(struct media_item *item, bool value)
+{
+	if (item->playable == value)
+		return;
+
+	item->playable = value;
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), item->path,
+					MEDIA_ITEM_INTERFACE, "Playable");
+}
+
 struct media_item *media_player_create_item(struct media_player *mp,
 						const char *name,
 						player_item_type_t type,
profiles/audio/player.h +1 -0
index 3a388d2..20de0b8 100644
@@ -88,6 +88,7 @@ struct media_item *media_player_create_item(struct media_player *mp,
 						player_item_type_t type,
 						uint64_t uid);
 
+void media_item_set_playable(struct media_item *item, bool value);
 void media_player_list_complete(struct media_player *mp, GSList *items,
 								int err);
 
Signature · 1 line
1.8.1.4
author maintainer
#7 lore raw

PATCH v3 7/16 audio/player: Add support for MediaItem.Metadata property

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/player.c | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
profiles/audio/player.c +41 -1
index 69e8cd5..d56640f 100644
@@ -66,6 +66,7 @@ struct media_item {
 	player_folder_type_t	folder_type;	/* Folder type */
 	bool			playable;	/* Item playable flag */
 	uint64_t		uid;		/* Item uid */
+	GHashTable		*metadata;	/* Item metadata */
 };
 
 struct media_folder {
@@ -771,6 +772,9 @@ static DBusMessage *media_folder_list_items(DBusConnection *conn,
 
 static void media_item_free(struct media_item *item)
 {
+	if (item->metadata != NULL)
+		g_hash_table_unref(item->metadata);
+
 	g_free(item->path);
 	g_free(item->name);
 	g_free(item);
@@ -1446,6 +1450,37 @@ static gboolean get_folder_type(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static gboolean metadata_exists(const GDBusPropertyTable *property, void *data)
+{
+	struct media_item *item = data;
+
+	return item->metadata != NULL;
+}
+
+static gboolean get_metadata(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct media_item *item = data;
+	DBusMessageIter dict;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&dict);
+
+	if (g_hash_table_size(item->metadata) > 0)
+		g_hash_table_foreach(item->metadata, append_metadata, &dict);
+	else if (item->name != NULL)
+		dict_append_entry(&dict, "Title", DBUS_TYPE_STRING,
+								&item->name);
+
+	dbus_message_iter_close_container(iter, &dict);
+
+	return TRUE;
+}
+
 static const GDBusMethodTable media_item_methods[] = {
 	{ GDBUS_EXPERIMENTAL_METHOD("Play", NULL, NULL,
 					media_item_play) },
@@ -1463,6 +1498,8 @@ static const GDBusPropertyTable media_item_properties[] = {
 					G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
 	{ "Playable", "b", get_playable, NULL, NULL,
 					G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
+	{ "Metadata", "a{sv}", get_metadata, NULL, metadata_exists,
+					G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
 	{ }
 };
 
@@ -1521,8 +1558,11 @@ struct media_item *media_player_create_item(struct media_player *mp,
 		return NULL;
 	}
 
-	if (type != PLAYER_ITEM_TYPE_FOLDER)
+	if (type != PLAYER_ITEM_TYPE_FOLDER) {
 		folder->items = g_slist_prepend(folder->items, item);
+		item->metadata = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, g_free);
+	}
 
 	DBG("%s", item->path);
 
Signature · 1 line
1.8.1.4
author maintainer
#8 lore raw

PATCH v3 8/16 audio/AVRCP: Add support for ChangePath command

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds support for ChangePath command via player callback.

---
 profiles/audio/avrcp.c  | 77 +++++++++++++++++++++++++++++++++++++++++++++----
 profiles/audio/player.h |  2 ++
 2 files changed, 73 insertions(+), 6 deletions(-)
profiles/audio/avrcp.c +71 -6
index d46e598..6135d78 100644
@@ -102,8 +102,9 @@
 #define AVRCP_ABORT_CONTINUING		0x41
 #define AVRCP_SET_ABSOLUTE_VOLUME	0x50
 #define AVRCP_SET_BROWSED_PLAYER	0x70
-#define AVRCP_GET_ITEM_ATTRIBUTES	0x73
 #define AVRCP_GET_FOLDER_ITEMS		0x71
+#define AVRCP_CHANGE_PATH		0x72
+#define AVRCP_GET_ITEM_ATTRIBUTES	0x73
 #define AVRCP_GENERAL_REJECT		0xA0
 
 /* Capabilities for AVRCP_GET_CAPABILITIES pdu */
@@ -193,8 +194,10 @@ struct avrcp_player {
 	uint16_t uid_counter;
 	bool browsed;
 	uint8_t *features;
+	char *path;
 
 	struct pending_list_items *p;
+	char *change_path;
 
 	struct avrcp_player_cb *cb;
 	void *user_data;
@@ -2268,6 +2271,32 @@ static void avrcp_list_items(struct avrcp *session, uint32_t start,
 					avrcp_list_items_rsp, session);
 }
 
+static gboolean avrcp_change_path_rsp(struct avctp *conn,
+					uint8_t *operands, size_t operand_count,
+					void *user_data)
+{
+	struct avrcp_browsing_header *pdu = (void *) operands;
+	struct avrcp *session = user_data;
+	struct avrcp_player *player = session->player;
+	struct media_player *mp = player->user_data;
+	uint8_t status;
+	uint32_t num_of_items;
+
+	status = pdu->params[0];
+	if (status != AVRCP_STATUS_SUCCESS)
+		return FALSE;
+
+	num_of_items = bt_get_be32(&pdu->params[1]);
+
+	g_free(player->path);
+	player->path = player->change_path;
+	player->change_path = NULL;
+
+	media_player_set_folder(mp, player->path, num_of_items);
+
+	return FALSE;
+}
+
 static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
 						uint8_t *operands,
 						size_t operand_count,
@@ -2278,7 +2307,7 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
 	struct media_player *mp = player->user_data;
 	struct avrcp_browsing_header *pdu = (void *) operands;
 	uint32_t items;
-	char **folders, *path;
+	char **folders;
 	uint8_t depth, count;
 	size_t i;
 
@@ -2311,12 +2340,10 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
 		i += len;
 	}
 
-	path = g_build_pathv("/", folders);
+	player->path = g_build_pathv("/", folders);
 	g_strfreev(folders);
 
-	media_player_set_folder(mp, path, items);
-
-	g_free(path);
+	media_player_set_folder(mp, player->path, items);
 
 	return FALSE;
 }
@@ -2557,6 +2584,41 @@ static int ct_list_items(struct media_player *mp, const char *name,
 	return 0;
 }
 
+static void avrcp_change_path(struct avrcp *session, uint8_t direction,
+								uint64_t uid)
+{
+	struct avrcp_player *player = session->player;
+	uint8_t buf[AVRCP_BROWSING_HEADER_LENGTH + 11];
+	struct avrcp_browsing_header *pdu = (void *) buf;
+
+	memset(buf, 0, sizeof(buf));
+	bt_put_be16(player->uid_counter, &pdu->params[0]);
+	pdu->params[2] = direction;
+	bt_put_be64(uid, &pdu->params[3]);
+	pdu->pdu_id = AVRCP_CHANGE_PATH;
+	pdu->param_len = htons(11);
+
+	avctp_send_browsing_req(session->conn, buf, sizeof(buf),
+					avrcp_change_path_rsp, session);
+}
+
+static int ct_change_folder(struct media_player *mp, const char *path,
+					uint64_t uid, void *user_data)
+{
+	struct avrcp_player *player = user_data;
+	struct avrcp *session;
+	uint8_t direction;
+
+	session = player->sessions->data;
+	player->change_path = g_strdup(path);
+
+	direction = g_str_has_prefix(path, player->path) ? 0x01 : 0x00;
+
+	avrcp_change_path(session, direction, uid);
+
+	return 0;
+}
+
 static const struct media_player_callback ct_cbs = {
 	.set_setting	= ct_set_setting,
 	.play		= ct_play,
@@ -2567,6 +2629,7 @@ static const struct media_player_callback ct_cbs = {
 	.fast_forward	= ct_fast_forward,
 	.rewind		= ct_rewind,
 	.list_items	= ct_list_items,
+	.change_folder	= ct_change_folder,
 };
 
 static struct avrcp_player *create_ct_player(struct avrcp *session,
@@ -2679,6 +2742,8 @@ static void player_destroy(gpointer data)
 		player->destroy(player->user_data);
 
 	g_slist_free(player->sessions);
+	g_free(player->path);
+	g_free(player->change_path);
 	g_free(player->features);
 	g_free(player);
 }
profiles/audio/player.h +2 -0
index 20de0b8..4103742 100644
@@ -56,6 +56,8 @@ struct media_player_callback {
 	int (*rewind) (struct media_player *mp, void *user_data);
 	int (*list_items) (struct media_player *mp, const char *name,
 				uint32_t start, uint32_t end, void *user_data);
+	int (*change_folder) (struct media_player *mp, const char *path,
+						uint64_t uid, void *user_data);
 };
 
 struct media_player *media_player_controller_create(const char *path,
Signature · 1 line
1.8.1.4
author maintainer
#9 lore raw

PATCH v3 9/16 audio/player: Add implementation of MediaFolder.ChangeFolder

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/avrcp.c  | 31 ++++++++++++++++--------
 profiles/audio/player.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++--
 profiles/audio/player.h |  2 ++
 3 files changed, 85 insertions(+), 12 deletions(-)
profiles/audio/avrcp.c +21 -10
index 6135d78..a35477e 100644
@@ -2279,20 +2279,31 @@ static gboolean avrcp_change_path_rsp(struct avctp *conn,
 	struct avrcp *session = user_data;
 	struct avrcp_player *player = session->player;
 	struct media_player *mp = player->user_data;
-	uint8_t status;
-	uint32_t num_of_items;
+	int ret;
 
-	status = pdu->params[0];
-	if (status != AVRCP_STATUS_SUCCESS)
-		return FALSE;
+	if (pdu == NULL) {
+		ret = -ETIMEDOUT;
+		goto done;
+	}
 
-	num_of_items = bt_get_be32(&pdu->params[1]);
+	if (pdu->params[0] != AVRCP_STATUS_SUCCESS) {
+		ret = -EINVAL;
+		goto done;
+	}
 
-	g_free(player->path);
-	player->path = player->change_path;
-	player->change_path = NULL;
+	ret = bt_get_be32(&pdu->params[1]);
+
+done:
+	if (ret < 0) {
+		g_free(player->change_path);
+		player->change_path = NULL;
+	} else {
+		g_free(player->path);
+		player->path = player->change_path;
+		player->change_path = NULL;
+	}
 
-	media_player_set_folder(mp, player->path, num_of_items);
+	media_player_change_folder_complete(mp, player->path, ret);
 
 	return FALSE;
 }
profiles/audio/player.c +62 -2

82 lines not on this page · raw message

profiles/audio/player.h +2 -0
index 4103742..151cabd 100644
@@ -93,6 +93,8 @@ struct media_item *media_player_create_item(struct media_player *mp,
 void media_item_set_playable(struct media_item *item, bool value);
 void media_player_list_complete(struct media_player *mp, GSList *items,
 								int err);
+void media_player_change_folder_complete(struct media_player *player,
+						const char *path, int ret);
 
 void media_player_set_callbacks(struct media_player *mp,
 				const struct media_player_callback *cbs,
Signature · 1 line
1.8.1.4
author maintainer
#10 lore raw

PATCH v3 10/16 audio/AVRCP: Add support for PlayItem command

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds support for PlayItem command via player callback.

---
 profiles/audio/avrcp.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 profiles/audio/player.h |  2 ++
 2 files changed, 50 insertions(+)
profiles/audio/avrcp.c +48 -0
index a35477e..632cd64 100644
@@ -105,6 +105,7 @@
 #define AVRCP_GET_FOLDER_ITEMS		0x71
 #define AVRCP_CHANGE_PATH		0x72
 #define AVRCP_GET_ITEM_ATTRIBUTES	0x73
+#define AVRCP_PLAY_ITEM			0x74
 #define AVRCP_GENERAL_REJECT		0xA0
 
 /* Capabilities for AVRCP_GET_CAPABILITIES pdu */
@@ -2630,6 +2631,52 @@ static int ct_change_folder(struct media_player *mp, const char *path,
 	return 0;
 }
 
+static void avrcp_play_item(struct avrcp *session, uint64_t uid)
+{
+	uint8_t buf[AVRCP_HEADER_LENGTH + 11];
+	struct avrcp_player *player = session->player;
+	struct avrcp_header *pdu = (void *) buf;
+	uint16_t length;
+
+	memset(buf, 0, sizeof(buf));
+
+	set_company_id(pdu->company_id, IEEEID_BTSIG);
+	pdu->pdu_id = AVRCP_PLAY_ITEM;
+	pdu->params_len = htons(11);
+	pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;
+
+	pdu->params[0] = player->scope;
+	bt_put_be64(uid, &pdu->params[1]);
+	bt_put_be16(player->uid_counter, &pdu->params[9]);
+
+	length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
+
+	avctp_send_vendordep_req(session->conn, AVC_CTYPE_STATUS,
+					AVC_SUBUNIT_PANEL, buf, length,
+					NULL, session);
+}
+
+static int ct_play_item(struct media_player *mp, const char *name,
+						uint64_t uid, void *user_data)
+{
+	struct avrcp_player *player = user_data;
+	struct avrcp *session;
+
+	if (player->p != NULL)
+		return -EBUSY;
+
+	session = player->sessions->data;
+
+	if (g_strrstr(name, "/NowPlaying"))
+		player->scope = 0x03;
+	else
+		player->scope = 0x01;
+
+	avrcp_play_item(session, uid);
+
+	return 0;
+}
+
 static const struct media_player_callback ct_cbs = {
 	.set_setting	= ct_set_setting,
 	.play		= ct_play,
@@ -2641,6 +2688,7 @@ static const struct media_player_callback ct_cbs = {
 	.rewind		= ct_rewind,
 	.list_items	= ct_list_items,
 	.change_folder	= ct_change_folder,
+	.play_item	= ct_play_item,
 };
 
 static struct avrcp_player *create_ct_player(struct avrcp *session,
profiles/audio/player.h +2 -0
index 151cabd..7d4344c 100644
@@ -58,6 +58,8 @@ struct media_player_callback {
 				uint32_t start, uint32_t end, void *user_data);
 	int (*change_folder) (struct media_player *mp, const char *path,
 						uint64_t uid, void *user_data);
+	int (*play_item) (struct media_player *mp, const char *name,
+					uint64_t uid, void *user_data);
 };
 
 struct media_player *media_player_controller_create(const char *path,
Signature · 1 line
1.8.1.4
author maintainer
#11 lore raw

PATCH v3 11/16 audio/player: Add implementation of MediaItem.Play

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/player.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
profiles/audio/player.c +16 -1
index 0ef0ac3..d0ecc6c 100644
@@ -1387,7 +1387,22 @@ void media_player_set_playlist_item(struct media_player *mp, uint64_t uid)
 static DBusMessage *media_item_play(DBusConnection *conn, DBusMessage *msg,
 								void *data)
 {
-	return btd_error_failed(msg, strerror(ENOTSUP));
+	struct media_item *item = data;
+	struct media_player *mp = item->player;
+	struct player_callback *cb = mp->cb;
+	int err;
+
+	if (!item->playable)
+		return btd_error_failed(msg, strerror(ENOTSUP));
+
+	if (cb->cbs->play_item == NULL)
+		return btd_error_failed(msg, strerror(ENOTSUP));
+
+	err = cb->cbs->play_item(mp, item->path, item->uid, cb->user_data);
+	if (err < 0)
+		return btd_error_failed(msg, strerror(-err));
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
 static DBusMessage *media_item_add_to_nowplaying(DBusConnection *conn,
Signature · 1 line
1.8.1.4
author maintainer
#12 lore raw

PATCH v3 12/16 audio/AVRCP: Add support for AddToNowPlaying command

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds support for AddToNowPlaying command via player callback.

---
 profiles/audio/avrcp.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 profiles/audio/player.h |  2 ++
 2 files changed, 50 insertions(+)
profiles/audio/avrcp.c +48 -0
index 632cd64..31fcaad 100644
@@ -106,6 +106,7 @@
 #define AVRCP_CHANGE_PATH		0x72
 #define AVRCP_GET_ITEM_ATTRIBUTES	0x73
 #define AVRCP_PLAY_ITEM			0x74
+#define AVRCP_ADD_TO_NOW_PLAYING	0x90
 #define AVRCP_GENERAL_REJECT		0xA0
 
 /* Capabilities for AVRCP_GET_CAPABILITIES pdu */
@@ -2677,6 +2678,52 @@ static int ct_play_item(struct media_player *mp, const char *name,
 	return 0;
 }
 
+static void avrcp_add_to_nowplaying(struct avrcp *session, uint64_t uid)
+{
+	uint8_t buf[AVRCP_HEADER_LENGTH + 11];
+	struct avrcp_player *player = session->player;
+	struct avrcp_header *pdu = (void *) buf;
+	uint16_t length;
+
+	memset(buf, 0, sizeof(buf));
+
+	set_company_id(pdu->company_id, IEEEID_BTSIG);
+	pdu->pdu_id = AVRCP_ADD_TO_NOW_PLAYING;
+	pdu->params_len = htons(11);
+	pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;
+
+	pdu->params[0] = player->scope;
+	bt_put_be64(uid, &pdu->params[1]);
+	bt_put_be16(player->uid_counter, &pdu->params[9]);
+
+	length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
+
+	avctp_send_vendordep_req(session->conn, AVC_CTYPE_STATUS,
+					AVC_SUBUNIT_PANEL, buf, length,
+					NULL, session);
+}
+
+static int ct_add_to_nowplaying(struct media_player *mp, const char *name,
+						uint64_t uid, void *user_data)
+{
+	struct avrcp_player *player = user_data;
+	struct avrcp *session;
+
+	if (player->p != NULL)
+		return -EBUSY;
+
+	session = player->sessions->data;
+
+	if (g_strrstr(name, "/NowPlaying"))
+		player->scope = 0x03;
+	else
+		player->scope = 0x01;
+
+	avrcp_add_to_nowplaying(session, uid);
+
+	return 0;
+}
+
 static const struct media_player_callback ct_cbs = {
 	.set_setting	= ct_set_setting,
 	.play		= ct_play,
@@ -2689,6 +2736,7 @@ static const struct media_player_callback ct_cbs = {
 	.list_items	= ct_list_items,
 	.change_folder	= ct_change_folder,
 	.play_item	= ct_play_item,
+	.add_to_nowplaying = ct_add_to_nowplaying,
 };
 
 static struct avrcp_player *create_ct_player(struct avrcp *session,
profiles/audio/player.h +2 -0
index 7d4344c..150b38a 100644
@@ -60,6 +60,8 @@ struct media_player_callback {
 						uint64_t uid, void *user_data);
 	int (*play_item) (struct media_player *mp, const char *name,
 					uint64_t uid, void *user_data);
+	int (*add_to_nowplaying) (struct media_player *mp, const char *name,
+					uint64_t uid, void *user_data);
 };
 
 struct media_player *media_player_controller_create(const char *path,
Signature · 1 line
1.8.1.4
author maintainer
#13 lore raw

PATCH v3 13/16 audio/player: Add implementation of MediaItem.AddToNowPlaying

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/player.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
profiles/audio/player.c +17 -1
index d0ecc6c..701d366 100644
@@ -1408,7 +1408,23 @@ static DBusMessage *media_item_play(DBusConnection *conn, DBusMessage *msg,
 static DBusMessage *media_item_add_to_nowplaying(DBusConnection *conn,
 						DBusMessage *msg, void *data)
 {
-	return btd_error_failed(msg, strerror(ENOTSUP));
+	struct media_item *item = data;
+	struct media_player *mp = item->player;
+	struct player_callback *cb = mp->cb;
+	int err;
+
+	if (!item->playable)
+		return btd_error_failed(msg, strerror(ENOTSUP));
+
+	if (cb->cbs->play_item == NULL)
+		return btd_error_failed(msg, strerror(ENOTSUP));
+
+	err = cb->cbs->add_to_nowplaying(mp, item->path, item->uid,
+							cb->user_data);
+	if (err < 0)
+		return btd_error_failed(msg, strerror(-err));
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
 static gboolean item_name_exists(const GDBusPropertyTable *property,
Signature · 1 line
1.8.1.4
author maintainer
#14 lore raw

PATCH v3 14/16 audio/AVRCP: Add support for Search command

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds support for Search command via player callback.

---
 profiles/audio/avrcp.c  | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 profiles/audio/player.h |  2 ++
 2 files changed, 56 insertions(+)
profiles/audio/avrcp.c +54 -0
index 31fcaad..4dce600 100644
@@ -106,6 +106,7 @@
 #define AVRCP_CHANGE_PATH		0x72
 #define AVRCP_GET_ITEM_ATTRIBUTES	0x73
 #define AVRCP_PLAY_ITEM			0x74
+#define AVRCP_SEARCH			0x80
 #define AVRCP_ADD_TO_NOW_PLAYING	0x90
 #define AVRCP_GENERAL_REJECT		0xA0
 
@@ -2632,6 +2633,58 @@ static int ct_change_folder(struct media_player *mp, const char *path,
 	return 0;
 }
 
+static gboolean avrcp_search_rsp(struct avctp *conn, uint8_t *operands,
+					size_t operand_count, void *user_data)
+{
+	struct avrcp_browsing_header *pdu = (void *) operands;
+	struct avrcp *session = (void *) user_data;
+	struct avrcp_player *player = session->player;
+
+	if (pdu == NULL || pdu->params[0] != AVRCP_STATUS_SUCCESS ||
+							operand_count < 7)
+		return FALSE;
+
+	player->uid_counter = bt_get_be16(&pdu->params[1]);
+
+	return FALSE;
+}
+
+static void avrcp_search(struct avrcp *session, const char *string)
+{
+	uint8_t buf[AVRCP_BROWSING_HEADER_LENGTH + 255];
+	struct avrcp_browsing_header *pdu = (void *) buf;
+	uint16_t len;
+
+	len = strlen(string);
+	if (len > 251)
+		len = 251;
+
+	memset(buf, 0, sizeof(buf));
+	bt_put_be16(0x6A, &pdu->params[0]);
+	bt_put_be16(len, &pdu->params[2]);
+	memcpy(&pdu->params[4], string, len);
+	pdu->pdu_id = AVRCP_SEARCH;
+	pdu->param_len = htons(len + 4);
+
+	len = AVRCP_BROWSING_HEADER_LENGTH + len + 4;
+
+	avctp_send_browsing_req(session->conn, buf, len, avrcp_search_rsp,
+								session);
+}
+
+static int ct_search(struct media_player *mp, const char *string,
+							void *user_data)
+{
+	struct avrcp_player *player = user_data;
+	struct avrcp *session;
+
+	session = player->sessions->data;
+
+	avrcp_search(session, string);
+
+	return 0;
+}
+
 static void avrcp_play_item(struct avrcp *session, uint64_t uid)
 {
 	uint8_t buf[AVRCP_HEADER_LENGTH + 11];
@@ -2735,6 +2788,7 @@ static const struct media_player_callback ct_cbs = {
 	.rewind		= ct_rewind,
 	.list_items	= ct_list_items,
 	.change_folder	= ct_change_folder,
+	.search		= ct_search,
 	.play_item	= ct_play_item,
 	.add_to_nowplaying = ct_add_to_nowplaying,
 };
profiles/audio/player.h +2 -0
index 150b38a..eecab1b 100644
@@ -58,6 +58,8 @@ struct media_player_callback {
 				uint32_t start, uint32_t end, void *user_data);
 	int (*change_folder) (struct media_player *mp, const char *path,
 						uint64_t uid, void *user_data);
+	int (*search) (struct media_player *mp, const char *string,
+						void *user_data);
 	int (*play_item) (struct media_player *mp, const char *name,
 					uint64_t uid, void *user_data);
 	int (*add_to_nowplaying) (struct media_player *mp, const char *name,
Signature · 1 line
1.8.1.4
author maintainer
#15 lore raw

PATCH v3 15/16 audio/player: Add implementation of MediaFolder.Search

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/avrcp.c  |  20 +++++++--
 profiles/audio/player.c | 113 +++++++++++++++++++++++++++++++++++++++---------
 profiles/audio/player.h |   1 +
 3 files changed, 110 insertions(+), 24 deletions(-)
profiles/audio/avrcp.c +17 -3
index 4dce600..135dcc7 100644
@@ -2585,6 +2585,8 @@ static int ct_list_items(struct media_player *mp, const char *name,
 
 	if (g_str_has_prefix(name, "/NowPlaying"))
 		player->scope = 0x03;
+	else if (g_str_has_suffix(name, "/search"))
+		player->scope = 0x02;
 	else
 		player->scope = 0x01;
 
@@ -2639,12 +2641,24 @@ static gboolean avrcp_search_rsp(struct avctp *conn, uint8_t *operands,
 	struct avrcp_browsing_header *pdu = (void *) operands;
 	struct avrcp *session = (void *) user_data;
 	struct avrcp_player *player = session->player;
+	struct media_player *mp = player->user_data;
+	int ret;
 
-	if (pdu == NULL || pdu->params[0] != AVRCP_STATUS_SUCCESS ||
-							operand_count < 7)
-		return FALSE;
+	if (pdu == NULL) {
+		ret = -ETIMEDOUT;
+		goto done;
+	}
+
+	if (pdu->params[0] != AVRCP_STATUS_SUCCESS || operand_count < 7) {
+		ret = -EINVAL;
+		goto done;
+	}
 
 	player->uid_counter = bt_get_be16(&pdu->params[1]);
+	ret = bt_get_be32(&pdu->params[3]);
+
+done:
+	media_player_search_complete(mp, ret);
 
 	return FALSE;
 }
profiles/audio/player.c +92 -21

155 lines not on this page · raw message

profiles/audio/player.h +1 -0
index eecab1b..9edc51b 100644
@@ -101,6 +101,7 @@ void media_player_list_complete(struct media_player *mp, GSList *items,
 								int err);
 void media_player_change_folder_complete(struct media_player *player,
 						const char *path, int ret);
+void media_player_search_complete(struct media_player *mp, int ret);
 
 void media_player_set_callbacks(struct media_player *mp,
 				const struct media_player_callback *cbs,
Signature · 1 line
1.8.1.4
author maintainer
#16 lore raw

PATCH v3 16/16 audio/player: Create item on media_player_set_playlist_item

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This makes sure that even if /NowPlaying folder has not been listed the current item is available and its metadata is updated.

---
 profiles/audio/avrcp.c  |   6 +--
 profiles/audio/player.c | 111 +++++++++++++++++++++++++++++++++---------------
 profiles/audio/player.h |   8 ++--
 3 files changed, 85 insertions(+), 40 deletions(-)
profiles/audio/avrcp.c +3 -3
index 135dcc7..92d4527 100644
@@ -1965,10 +1965,10 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
 					uint8_t *operands, uint8_t count)
 {
 	struct media_player *mp = player->user_data;
+	struct media_item *item;
 	int i;
 
-	if (player->uid > 0)
-		media_player_set_playlist_item(mp, player->uid);
+	item = media_player_set_playlist_item(mp, player->uid);
 
 	for (i = 0; count > 0; count--) {
 		uint32_t id;
@@ -1987,7 +1987,7 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
 			const char *key = metadata_to_str(id);
 
 			if (key != NULL)
-				media_player_set_metadata(mp,
+				media_player_set_metadata(mp, item,
 							metadata_to_str(id),
 							&operands[i], len);
 		}
profiles/audio/player.c +77 -34

169 lines not on this page · raw message

profiles/audio/player.h +5 -3
index 9edc51b..ac2a3da 100644
@@ -75,8 +75,9 @@ void media_player_set_setting(struct media_player *mp, const char *key,
 							const char *value);
 const char *media_player_get_status(struct media_player *mp);
 void media_player_set_status(struct media_player *mp, const char *status);
-void media_player_set_metadata(struct media_player *mp, const char *key,
-						void *data, size_t len);
+void media_player_set_metadata(struct media_player *mp,
+				struct media_item *item, const char *key,
+				void *data, size_t len);
 void media_player_set_type(struct media_player *mp, const char *type);
 void media_player_set_subtype(struct media_player *mp, const char *subtype);
 void media_player_set_name(struct media_player *mp, const char *name);
@@ -85,7 +86,8 @@ void media_player_set_searchable(struct media_player *mp, bool enabled);
 void media_player_set_folder(struct media_player *mp, const char *path,
 								uint32_t items);
 void media_player_set_playlist(struct media_player *mp, const char *name);
-void media_player_set_playlist_item(struct media_player *mp, uint64_t uid);
+struct media_item *media_player_set_playlist_item(struct media_player *mp,
+								uint64_t uid);
 
 struct media_item *media_player_create_folder(struct media_player *mp,
 						const char *name,
Signature · 1 line
1.8.1.4
author maintainer
#17 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 46 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

v2: Fixes ChangeFolder not working for subfolders past /Filesystem
v3: Add Search implementation, fix not forwarding errors properly and add patch to create current item if it doesn't exist.

This set of patches implements most of the functionality of MediaFolder and MediaItem interfaces.

Some remarks:

- ChangeFolder can only change one level at time, this perhaps gonna be changed in the future but for now this matches the limitation of AVRCP itself.
- ListItems returns the items in the correct order but GetManagedObjects does the reverse order due to use of g_slist_prepend.
- PlayItem and AddToNowPlaying works fine with iPhone but with WP8 is not working probably because the UIDCounter changes more frequently which needs some new notifications that are currently not implemented.

This can be tested using tools/mpris-player which will browse the NowPlaying list and show which item is currently being played, but the gnome extention itself needs patching which can be found here:

https://github.com/Vudentz/gnome-shell-extensions-mediaplayer

Or use the command line tool: tools/bluetooth-player

Luiz Augusto von Dentz (16):
audio/player: Split item creation
audio/AVRCP: Add browsed flag to player audio/AVRCP: Add support for GetFolderItems command audio/player: Add implementation of MediaFolder.ListItems audio/player: Add support for setting current Item object audio/player: Add function media_item_set_playable audio/player: Add support for MediaItem.Metadata property audio/AVRCP: Add support for ChangePath command audio/player: Add implementation of MediaFolder.ChangeFolder audio/AVRCP: Add support for PlayItem command audio/player: Add implementation of MediaItem.Play audio/AVRCP: Add support for AddToNowPlaying command audio/player: Add implementation of MediaItem.AddToNowPlaying audio/AVRCP: Add support for Search command audio/player: Add implementation of MediaFolder.Search audio/player: Create item on media_player_set_playlist_item

Quoted 7 lines
 profiles/audio/avrcp.c  | 488 ++++++++++++++++++++++++++++-
 profiles/audio/player.c | 804 ++++++++++++++++++++++++++++++++++++++++--------
 profiles/audio/player.h |  35 ++-
 3 files changed, 1187 insertions(+), 140 deletions(-)

--
1.8.1.4

This patch-set has been applied.

--
Luiz Augusto von Dentz