From: Luiz Augusto von Dentz Date: Thu, 31 Jan 2013 17:12:43 +0000 (-0600) Subject: AVRCP: Get track duration using GetPlayStatus command X-Git-Tag: android-x86-4.4-r3~8565 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b926af1c4f4b58fbddd846db4b0b5fb1070cab92;p=android-x86%2Fexternal-bluetooth-bluez.git AVRCP: Get track duration using GetPlayStatus command Some stacks, notably broadcom, don't send track duration together with other metadata so it has to be set using GetPlayStatus. --- diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c index f83c3db5c..728ba915f 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 841a57702..fb750fd41 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 212a5a60b..fec1d06fc 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);