Skip to contentSkip to conversation

AVRCP: Prefix folder name with /Filesystem

PATCH In review Luiz Augusto von Dentz 2 participants 8 messages Feb 15, 2013 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/7 AVRCP: Prefix folder name with /Filesystem

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

This separate the scopes of the folder as documented in doc/media-api.txt

---
 profiles/audio/avrcp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
profiles/audio/avrcp.c +3 -2
index 00eeea1..5967180 100644
@@ -1935,9 +1935,10 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
 
 	depth = operands[13];
 
-	folders = g_new0(char *, depth + 1);
+	folders = g_new0(char *, depth + 2);
+	folders[0] = g_strdup("/Filesystem");
 
-	for (i = 14, count = 0; count < depth; count++) {
+	for (i = 14, count = 1; count - 1 < depth; count++) {
 		char *part;
 		uint8_t len;
 
Signature · 1 line
1.8.1.2
author maintainer
#1 lore raw

PATCH 2/7 AVRCP: Parse browsing and searching features bits

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

This parses browsing and searching features bits and set the respective property.

---
 profiles/audio/avrcp.c  | 18 ++++++++----
 profiles/audio/player.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++-
 profiles/audio/player.h |  2 ++
 3 files changed, 87 insertions(+), 6 deletions(-)
profiles/audio/avrcp.c +13 -5
index 5967180..cabe2ee 100644
@@ -1976,6 +1976,18 @@ static void avrcp_set_browsed_player(struct avrcp *session,
 				avrcp_set_browsed_player_rsp, session);
 }
 
+static void avrcp_player_parse_features(struct avrcp_player *player,
+							uint8_t *features)
+{
+	struct media_player *mp = player->user_data;
+
+	if (features[7] & 0x08)
+		media_player_set_browsable(mp, true);
+
+	if (features[7] & 0x10)
+		media_player_set_searchable(mp, true);
+}
+
 static void avrcp_parse_media_player_item(struct avrcp *session,
 					uint8_t *operands, uint16_t len)
 {
@@ -1984,7 +1996,6 @@ static void avrcp_parse_media_player_item(struct avrcp *session,
 	uint16_t id;
 	uint32_t subtype;
 	const char *curval, *strval;
-	uint64_t features[2];
 	char name[255];
 
 	if (len < 28)
@@ -2009,10 +2020,7 @@ static void avrcp_parse_media_player_item(struct avrcp *session,
 		avrcp_get_play_status(session);
 	}
 
-	features[0] = bt_get_be64(&operands[8]);
-	features[1] = bt_get_be64(&operands[16]);
-
-	media_player_set_features(mp, features);
+	avrcp_player_parse_features(player, &operands[8]);
 
 	if (operands[26] != 0) {
 		memcpy(name, &operands[27], operands[26]);
profiles/audio/player.c +72 -1

97 lines not on this page · raw message

profiles/audio/player.h +2 -0
index 1ac9800..e9a7d1c 100644
@@ -51,6 +51,8 @@ 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_features(struct media_player *mp, uint64_t *features);
 void media_player_set_name(struct media_player *mp, const char *name);
+void media_player_set_browsable(struct media_player *mp, bool enabled);
+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);
 
Signature · 1 line
1.8.1.2
author maintainer
#2 lore raw

PATCH 3/7 media-api: Fix referencing to MediaLibrary instead of MediaFolder

In reply to Luiz Augusto von Dentz

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

MediaLibrary was replaced by MediaFolder so doesn't exist anymore.

---
 doc/media-api.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
doc/media-api.txt +2 -2
index db1575f..2656a9e 100644
@@ -233,7 +233,7 @@ Properties	string Equalizer [readwrite]
 		boolean Browsable [readonly]
 
 			If present indicates the player can be browsed using
-			MediaLibrary interface.
+			MediaFolder interface.
 
 			Possible values:
 
@@ -248,7 +248,7 @@ Properties	string Equalizer [readwrite]
 		boolean Searchable [readonly]
 
 			If present indicates the player can be searched using
-			MediaLibrary interface.
+			MediaFolder interface.
 
 			Possible values:
 
Signature · 1 line
1.8.1.2
author maintainer
#3 lore raw

PATCH 4/7 AVRCP: Move features to avrcp.c

In reply to Luiz Augusto von Dentz

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

avrcp.c should be responsible for specifics of AVRCP not player.c which is more high level abstraction.

---
 profiles/audio/avrcp.c  | 4 ++++
 profiles/audio/player.c | 8 --------
 profiles/audio/player.h | 1 -
 3 files changed, 4 insertions(+), 9 deletions(-)
profiles/audio/avrcp.c +4 -0
index cabe2ee..55887bc 100644
@@ -180,6 +180,7 @@ struct avrcp_player {
 	GSList *sessions;
 	uint16_t id;
 	uint16_t uid_counter;
+	uint8_t *features;
 
 	struct avrcp_player_cb *cb;
 	void *user_data;
@@ -1981,6 +1982,8 @@ static void avrcp_player_parse_features(struct avrcp_player *player,
 {
 	struct media_player *mp = player->user_data;
 
+	player->features = g_memdup(features, 16);
+
 	if (features[7] & 0x08)
 		media_player_set_browsable(mp, true);
 
@@ -2553,6 +2556,7 @@ static void player_destroy(gpointer data)
 		player->destroy(player->user_data);
 
 	g_slist_free(player->sessions);
+	g_free(player->features);
 	g_free(player);
 }
 
profiles/audio/player.c +0 -8
index 7879193..07fd457 100644
@@ -69,7 +69,6 @@ struct media_player {
 	char			*subtype;	/* Player subtype */
 	bool			browsable;	/* Player browsing feature */
 	bool			searchable;	/* Player searching feature */
-	uint8_t			*features;	/* Player features */
 	struct media_folder	*folder;	/* Player currenct folder */
 	char			*path;		/* Player object path */
 	GHashTable		*settings;	/* Player settings */
@@ -941,13 +940,6 @@ void media_player_set_folder(struct media_player *mp, const char *path,
 	}
 }
 
-void media_player_set_features(struct media_player *mp, uint64_t *features)
-{
-	DBG("0x%016" PRIx64 "%016" PRIx64, features[0], features[1]);
-
-	memcpy(features, mp->features, sizeof(mp->features));
-}
-
 void media_player_set_callbacks(struct media_player *mp,
 				const struct media_player_callback *cbs,
 				void *user_data)
profiles/audio/player.h +0 -1
index e9a7d1c..9109b1f 100644
@@ -49,7 +49,6 @@ void media_player_set_metadata(struct media_player *mp, 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_features(struct media_player *mp, uint64_t *features);
 void media_player_set_name(struct media_player *mp, const char *name);
 void media_player_set_browsable(struct media_player *mp, bool enabled);
 void media_player_set_searchable(struct media_player *mp, bool enabled);
Signature · 1 line
1.8.1.2
author maintainer
#4 lore raw

PATCH 5/7 AVRCP: Create folders for /Filesystem and /NowPlaying

In reply to Luiz Augusto von Dentz

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

If browsing is supported create objects representing /Filesystem and /NowPlaying, these object implement MediaItem interface and can be passed to ChangeFolder to change the scope.

---
 profiles/audio/avrcp.c  |   7 +-
 profiles/audio/player.c | 233 ++++++++++++++++++++++++++++++++++++++++++------
 profiles/audio/player.h |   2 +
 3 files changed, 216 insertions(+), 26 deletions(-)
profiles/audio/avrcp.c +6 -1
index 55887bc..3b9aad6 100644
@@ -1984,11 +1984,16 @@ static void avrcp_player_parse_features(struct avrcp_player *player,
 
 	player->features = g_memdup(features, 16);
 
-	if (features[7] & 0x08)
+	if (features[7] & 0x08) {
 		media_player_set_browsable(mp, true);
+		media_player_create_folder(mp, "/Filesystem");
+	}
 
 	if (features[7] & 0x10)
 		media_player_set_searchable(mp, true);
+
+	if (features[8] & 0x02)
+		media_player_create_folder(mp, "/NowPlaying");
 }
 
 static void avrcp_parse_media_player_item(struct avrcp *session,
profiles/audio/player.c +208 -25

314 lines not on this page · raw message

profiles/audio/player.h +2 -0
index 9109b1f..a59cc66 100644
@@ -55,6 +55,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);
 
+int media_player_create_folder(struct media_player *mp, const char *path);
+
 void media_player_set_callbacks(struct media_player *mp,
 				const struct media_player_callback *cbs,
 				void *user_data);
Signature · 1 line
1.8.1.2
author maintainer
#5 lore raw

PATCH 6/7 AVRCP: Add support for GetItemAttributes

In reply to Luiz Augusto von Dentz

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

GetItemAttributes should be used instead of GetElementAttributes if browsing is supported.

---
 profiles/audio/avrcp.c | 112 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 83 insertions(+), 29 deletions(-)
profiles/audio/avrcp.c +83 -29
index 3b9aad6..9833a3a 100644
@@ -100,6 +100,7 @@
 #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_GENERAL_REJECT		0xA0
 
@@ -1788,42 +1789,23 @@ static void avrcp_list_player_attributes(struct avrcp *session)
 					session);
 }
 
-static gboolean avrcp_get_attributes_rsp(struct avctp *conn,
-					uint8_t code, uint8_t subunit,
-					uint8_t *operands, size_t operand_count,
-					void *user_data)
+static void avrcp_parse_attribute_list(struct avrcp_player *player,
+					uint8_t *operands, uint8_t count)
 {
-	struct avrcp *session = user_data;
-	struct avrcp_player *player = session->player;
 	struct media_player *mp = player->user_data;
-	struct avrcp_header *pdu = (void *) operands;
-	uint8_t count;
 	int i;
 
-	if (code == AVC_CTYPE_REJECTED)
-		return FALSE;
-
-	count = pdu->params[0];
-
-	if (ntohs(pdu->params_len) - 1 < count * 8) {
-		error("Invalid parameters");
-		return FALSE;
-	}
-
-	for (i = 1; count > 0; count--) {
+	for (i = 0; count > 0; count--) {
 		uint32_t id;
 		uint16_t charset, len;
 
-		memcpy(&id, &pdu->params[i], sizeof(uint32_t));
-		id = ntohl(id);
+		id = bt_get_be32(&operands[i]);
 		i += sizeof(uint32_t);
 
-		memcpy(&charset, &pdu->params[i], sizeof(uint16_t));
-		charset = ntohs(charset);
+		charset = bt_get_be16(&operands[i]);
 		i += sizeof(uint16_t);
 
-		memcpy(&len, &pdu->params[i], sizeof(uint16_t));
-		len = ntohs(len);
+		len = bt_get_be16(&operands[i]);
 		i += sizeof(uint16_t);
 
 		if (charset == 106) {
@@ -1832,11 +1814,35 @@ static gboolean avrcp_get_attributes_rsp(struct avctp *conn,
 			if (key != NULL)
 				media_player_set_metadata(mp,
 							metadata_to_str(id),
-							&pdu->params[i], len);
+							&operands[i], len);
 		}
 
 		i += len;
 	}
+}
+
+static gboolean avrcp_get_element_attributes_rsp(struct avctp *conn,
+						uint8_t code, uint8_t subunit,
+						uint8_t *operands,
+						size_t operand_count,
+						void *user_data)
+{
+	struct avrcp *session = user_data;
+	struct avrcp_player *player = session->player;
+	struct avrcp_header *pdu = (void *) operands;
+	uint8_t count;
+
+	if (code == AVC_CTYPE_REJECTED)
+		return FALSE;
+
+	count = pdu->params[0];
+
+	if (ntohs(pdu->params_len) - 1 < count * 8) {
+		error("Invalid parameters");
+		return FALSE;
+	}
+
+	avrcp_parse_attribute_list(player, &pdu->params[1], count);
 
 	return FALSE;
 }
@@ -1858,7 +1864,7 @@ static void avrcp_get_element_attributes(struct avrcp *session)
 
 	avctp_send_vendordep_req(session->conn, AVC_CTYPE_STATUS,
 					AVC_SUBUNIT_PANEL, buf, length,
-					avrcp_get_attributes_rsp,
+					avrcp_get_element_attributes_rsp,
 					session);
 }
 
@@ -1977,6 +1983,48 @@ static void avrcp_set_browsed_player(struct avrcp *session,
 				avrcp_set_browsed_player_rsp, session);
 }
 
+static gboolean avrcp_get_item_attributes_rsp(struct avctp *conn,
+						uint8_t *operands,
+						size_t operand_count,
+						void *user_data)
+{
+	struct avrcp *session = user_data;
+	struct avrcp_player *player = session->player;
+	struct avrcp_browsing_header *pdu = (void *) operands;
+	uint8_t count;
+
+	if (pdu->params[0] != AVRCP_STATUS_SUCCESS || operand_count < 4)
+		return FALSE;
+
+	count = pdu->params[1];
+
+	if (ntohs(pdu->param_len) - 1 < count * 8) {
+		error("Invalid parameters");
+		return FALSE;
+	}
+
+	avrcp_parse_attribute_list(player, &pdu->params[2], count);
+
+	return FALSE;
+}
+
+static void avrcp_get_item_attributes(struct avrcp *session, uint64_t uid)
+{
+	uint8_t buf[AVRCP_BROWSING_HEADER_LENGTH + 12];
+	struct avrcp_browsing_header *pdu = (void *) buf;
+
+	memset(buf, 0, sizeof(buf));
+
+	pdu->pdu_id = AVRCP_GET_ITEM_ATTRIBUTES;
+	pdu->params[0] = 0x03;
+	bt_put_be64(uid, &pdu->params[1]);
+	bt_put_be16(session->player->uid_counter, &pdu->params[9]);
+	pdu->param_len = htons(12);
+
+	avctp_send_browsing_req(session->conn, buf, sizeof(buf),
+				avrcp_get_item_attributes_rsp, session);
+}
+
 static void avrcp_player_parse_features(struct avrcp_player *player,
 							uint8_t *features)
 {
@@ -2122,9 +2170,15 @@ static void avrcp_status_changed(struct avrcp *session,
 static void avrcp_track_changed(struct avrcp *session,
 						struct avrcp_header *pdu)
 {
-	avrcp_get_element_attributes(session);
-	avrcp_get_play_status(session);
+	uint64_t uid;
+
+	if (session->browsing_id) {
+		uid = bt_get_be64(&pdu->params[1]);
+		avrcp_get_item_attributes(session, uid);
+	} else
+		avrcp_get_element_attributes(session);
 
+	avrcp_get_play_status(session);
 }
 
 static void avrcp_setting_changed(struct avrcp *session,
Signature · 1 line
1.8.1.2
author maintainer
#6 lore raw

PATCH 7/7 AVRCP: Fix parsing of SetBrowsedPlayer response

In reply to Luiz Augusto von Dentz

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

Folder depth is actually the byte 13 not 14 of the response.

---
 profiles/audio/avrcp.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
profiles/audio/avrcp.c +8 -7
index 9833a3a..9be977e 100644
@@ -1928,29 +1928,30 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
 	struct avrcp *session = user_data;
 	struct avrcp_player *player = session->player;
 	struct media_player *mp = player->user_data;
+	struct avrcp_browsing_header *pdu = (void *) operands;
 	uint32_t items;
 	char **folders, *path;
 	uint8_t depth, count;
 	int i;
 
-	if (operands[3] != AVRCP_STATUS_SUCCESS || operand_count < 13)
+	if (pdu->params[0] != AVRCP_STATUS_SUCCESS || operand_count < 13)
 		return FALSE;
 
-	player->uid_counter = bt_get_be16(&operands[4]);
+	player->uid_counter = bt_get_be16(&pdu->params[1]);
 
-	items = bt_get_be32(&operands[6]);
+	items = bt_get_be32(&pdu->params[3]);
 
-	depth = operands[13];
+	depth = operands[9];
 
 	folders = g_new0(char *, depth + 2);
 	folders[0] = g_strdup("/Filesystem");
 
-	for (i = 14, count = 1; count - 1 < depth; count++) {
+	for (i = 10, count = 1; count - 1 < depth; count++) {
 		char *part;
 		uint8_t len;
 
-		len = operands[i++];
-		part = g_memdup(&operands[i], len);
+		len = pdu->params[i++];
+		part = g_memdup(&pdu->params[i], len);
 		i += len;
 		folders[count] = part;
 	}
Signature · 1 line
1.8.1.2
#7 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 4 lines · Luiz Augusto von Dentz

This separate the scopes of the folder as documented in doc/media-api.txt

---
 profiles/audio/avrcp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

All patches in this set have been applied. Thanks.

Johan