From 1a3d320f122b696792dcda0389031ace1dd55b28 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 7 May 2015 16:55:19 +0300 Subject: audio/player: Resync if Position property is read Request position to be resync if status is playing and position is supported. --- profiles/audio/avrcp.c | 18 ++++++++++++++++++ profiles/audio/player.c | 5 +++++ profiles/audio/player.h | 1 + 3 files changed, 24 insertions(+) diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c index f9980b37e..136f4a463 100644 --- a/profiles/audio/avrcp.c +++ b/profiles/audio/avrcp.c @@ -2790,6 +2790,23 @@ static void avrcp_set_player_value(struct avrcp *session, uint8_t attr, avrcp_player_value_rsp, session); } +static bool ct_get_position(struct media_player *mp, void *user_data) +{ + struct avrcp_player *player = user_data; + struct avrcp *session; + + session = player->sessions->data; + if (session == NULL) + return false; + + if (session->controller->version < 0x0103) + return false; + + avrcp_get_play_status(session); + + return true; +} + static bool ct_set_setting(struct media_player *mp, const char *key, const char *value, void *user_data) { @@ -3175,6 +3192,7 @@ static int ct_get_total_numberofitems(struct media_player *mp, const char *name, } static const struct media_player_callback ct_cbs = { + .get_position = ct_get_position, .set_setting = ct_set_setting, .play = ct_play, .pause = ct_pause, diff --git a/profiles/audio/player.c b/profiles/audio/player.c index 4736396d1..8f3d8def2 100644 --- a/profiles/audio/player.c +++ b/profiles/audio/player.c @@ -169,12 +169,17 @@ static gboolean get_position(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) { struct media_player *mp = data; + struct player_callback *cb = mp->cb; uint32_t position; position = media_player_get_position(mp); dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &position); + /* Trigger a resync if position has drifted more than a sec */ + if (abs(position - mp->position) > 1000) + cb->cbs->get_position(mp, cb->user_data); + return TRUE; } diff --git a/profiles/audio/player.h b/profiles/audio/player.h index 4ad8bfebc..376bad9c1 100644 --- a/profiles/audio/player.h +++ b/profiles/audio/player.h @@ -45,6 +45,7 @@ struct media_player; struct media_item; struct media_player_callback { + bool (*get_position) (struct media_player *mp, void *user_data); bool (*set_setting) (struct media_player *mp, const char *key, const char *value, void *user_data); int (*play) (struct media_player *mp, void *user_data); -- cgit v1.2.1