Skip to contentSkip to conversation

AVCTP: Fix allways destroying browsing channel

PATCH New Luiz Augusto von Dentz 1 participant 4 messages Jan 31, 2013 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/4 AVCTP: Fix allways destroying browsing channel

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

This reverts commit 53d3fc3fad5152167458625ad2acf19070cdf26a that leads to always destroy the browsing channel because the callback changes the state.

To fix session_browsing_cb naw takes care of destroying the channel if it disconnects.

---
 profiles/audio/avctp.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
profiles/audio/avctp.c +7 -4
index 41e2f46..303427e 100644
@@ -490,10 +490,6 @@ static void avctp_set_state(struct avctp *session, avctp_state_t new_state)
 		break;
 	case AVCTP_STATE_CONNECTED:
 		DBG("AVCTP Connected");
-		if (session->browsing) {
-			avctp_channel_destroy(session->browsing);
-			session->browsing = NULL;
-		}
 		break;
 	case AVCTP_STATE_BROWSING_CONNECTING:
 		DBG("AVCTP Browsing Connecting");
@@ -817,6 +813,13 @@ send:
 
 failed:
 	DBG("AVCTP Browsing: disconnected");
+	avctp_set_state(session, AVCTP_STATE_CONNECTED);
+
+	if (session->browsing) {
+		avctp_channel_destroy(session->browsing);
+		session->browsing = NULL;
+	}
+
 	return FALSE;
 }
 
Signature · 1 line
1.8.1
author maintainer
#1 lore raw

PATCH 2/4 AVCTP: Fix memory leak

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

651 (280 direct, 371 indirect) bytes in 7 blocks are definitely lost in loss record 306 of 332
at 0x4A06B2F: calloc (vg_replace_malloc.c:593)
by 0x319724D706: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.3400.2)
by 0x418A54: avctp_send_browsing_req (avctp.c:1457)
by 0x41A330: avrcp_handle_event (avrcp.c:1998)
by 0x417810: session_cb (avctp.c:702)
by 0x3197247A74: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2) by 0x3197247DA7: ??? (in /usr/lib64/libglib-2.0.so.0.3400.2)
by 0x31972481A1: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
by 0x409D6E: main (main.c:583)

---
 profiles/audio/avctp.c | 1 +
 1 file changed, 1 insertion(+)
profiles/audio/avctp.c +1 -0
index 303427e..13dd4c3 100644
@@ -749,6 +749,7 @@ static void browsing_response(struct avctp_channel *browsing,
 			return;
 
 		browsing->processed = g_slist_remove(browsing->processed, p);
+		pending_destroy(p, NULL);
 
 		return;
 	}
Signature · 1 line
1.8.1
author maintainer
#2 lore raw

PATCH 3/4 A2DP: Fix not setting setup error to NULL

In reply to Luiz Augusto von Dentz

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

Once the error is informed to the callback it should be properly freed and set to NULL otherwise a subsequent operation may end up reusing the same error which might lead to crashes.

---
 profiles/audio/a2dp.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
profiles/audio/a2dp.c +6 -6
index efb4178..4b28465 100644
@@ -366,16 +366,13 @@ static void stream_state_changed(struct avdtp_stream *stream,
 static gboolean auto_config(gpointer data)
 {
 	struct a2dp_setup *setup = data;
-	struct avdtp_error *err = NULL;
 
 	/* Check if configuration was aborted */
 	if (setup->sep->stream == NULL)
 		return FALSE;
 
-	if (setup->err != NULL) {
-		err = setup->err;
+	if (setup->err != NULL)
 		goto done;
-	}
 
 	avdtp_stream_add_cb(setup->session, setup->stream,
 				stream_state_changed, setup->sep);
@@ -391,8 +388,10 @@ done:
 
 	finalize_config(setup);
 
-	if (err)
-		g_free(err);
+	if (setup->err) {
+		g_free(setup->err);
+		setup->err = NULL;
+	}
 
 	setup_unref(setup);
 
@@ -565,6 +564,7 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
 		if (setup) {
 			setup->err = err;
 			finalize_config(setup);
+			setup->err = NULL;
 		}
 		return;
 	}
Signature · 1 line
1.8.1
author maintainer
#3 lore raw

PATCH 4/4 AVRCP: Get track duration using GetPlayStatus command

In reply to Luiz Augusto von Dentz

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

Some stacks, notably broadcom, don't send track duration together with other metadata so it has to be set using GetPlayStatus.

---
 profiles/audio/avrcp.c  |  6 ++++--
 profiles/audio/player.c | 21 +++++++++++++++++++++
 profiles/audio/player.h |  1 +
 3 files changed, 26 insertions(+), 2 deletions(-)
profiles/audio/avrcp.c +4 -2
index f83c3db..728ba91 100644
@@ -1632,6 +1632,7 @@ static gboolean avrcp_get_play_status_rsp(struct avctp *conn,
 
 	memcpy(&duration, pdu->params, sizeof(uint32_t));
 	duration = ntohl(duration);
+	media_player_set_duration(mp, duration);
 
 	memcpy(&position, pdu->params + 4, sizeof(uint32_t));
 	position = ntohl(position);
@@ -1900,11 +1901,12 @@ static gboolean avrcp_handle_event(struct avctp *conn,
 		break;
 	case AVRCP_EVENT_TRACK_CHANGED:
 		mp = player->user_data;
-		if (code == AVC_CTYPE_CHANGED)
-			media_player_set_position(mp, 0);
 
 		avrcp_get_element_attributes(session);
 
+		if (code == AVC_CTYPE_CHANGED)
+			avrcp_get_play_status(session);
+
 		break;
 
 	case AVRCP_EVENT_SETTINGS_CHANGED:
profiles/audio/player.c +21 -0
index 841a577..fb750fd 100644
@@ -483,6 +483,27 @@ struct media_player *media_player_controller_create(const char *path)
 	return mp;
 }
 
+void media_player_set_duration(struct media_player *mp, uint32_t duration)
+{
+	char *value, *curval;
+
+	DBG("%u", duration);
+
+	value = g_strdup_printf("%u", duration);
+
+	curval = g_hash_table_lookup(mp->track, "Duration");
+	if (g_strcmp0(curval, value) == 0) {
+		g_free(value);
+		return;
+	}
+
+	g_hash_table_replace(mp->track, g_strdup("Duration"), value);
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(),
+					mp->path, MEDIA_PLAYER_INTERFACE,
+					"Track");
+}
+
 void media_player_set_position(struct media_player *mp, uint32_t position)
 {
 	DBG("%u", position);
profiles/audio/player.h +1 -0
index 212a5a6..fec1d06 100644
@@ -39,6 +39,7 @@ struct media_player_callback {
 
 struct media_player *media_player_controller_create(const char *path);
 void media_player_destroy(struct media_player *mp);
+void media_player_set_duration(struct media_player *mp, uint32_t duration);
 void media_player_set_position(struct media_player *mp, uint32_t position);
 void media_player_set_setting(struct media_player *mp, const char *key,
 							const char *value);
Signature · 1 line
1.8.1