* [PATCH BlueZ 3/4] A2DP: Fix not setting setup error to NULL
2013-01-31 17:12 [PATCH BlueZ 1/4] AVCTP: Fix allways destroying browsing channel Luiz Augusto von Dentz
2013-01-31 17:12 ` [PATCH BlueZ 2/4] AVCTP: Fix memory leak Luiz Augusto von Dentz
@ 2013-01-31 17:12 ` Luiz Augusto von Dentz
2013-01-31 17:12 ` [PATCH BlueZ 4/4] AVRCP: Get track duration using GetPlayStatus command Luiz Augusto von Dentz
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2013-01-31 17:12 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index efb4178..4b28465 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -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;
}
--
1.8.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH BlueZ 4/4] AVRCP: Get track duration using GetPlayStatus command
2013-01-31 17:12 [PATCH BlueZ 1/4] AVCTP: Fix allways destroying browsing channel Luiz Augusto von Dentz
2013-01-31 17:12 ` [PATCH BlueZ 2/4] AVCTP: Fix memory leak Luiz Augusto von Dentz
2013-01-31 17:12 ` [PATCH BlueZ 3/4] A2DP: Fix not setting setup error to NULL Luiz Augusto von Dentz
@ 2013-01-31 17:12 ` Luiz Augusto von Dentz
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2013-01-31 17:12 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(-)
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index f83c3db..728ba91 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -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:
diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 841a577..fb750fd 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -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);
diff --git a/profiles/audio/player.h b/profiles/audio/player.h
index 212a5a6..fec1d06 100644
--- a/profiles/audio/player.h
+++ b/profiles/audio/player.h
@@ -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);
--
1.8.1
^ permalink raw reply related [flat|nested] 4+ messages in thread