From 94b4cd2459822150f7a33cdc3389445ae60871ec Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sat, 31 Jul 2010 12:07:51 +0200 Subject: [PATCH] Add support for shuffle in DACP playspec request --- src/httpd_dacp.c | 58 +++++++++++++++++++++++++++++------------------- src/player.c | 4 ++++ 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index c5a32ad1..f37ac092 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -819,6 +819,7 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u struct player_source *ps; struct daap_session *s; const char *param; + const char *shuffle; uint32_t plid; uint32_t id; int ret; @@ -831,6 +832,9 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u if (!s) return; + /* Check for shuffle */ + shuffle = evhttp_find_header(query, "dacp.shufflestate"); + /* Playlist ID */ param = evhttp_find_header(query, "container-spec"); if (!param) @@ -857,33 +861,38 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u goto out_fail; } - /* Start song ID */ - param = evhttp_find_header(query, "container-item-spec"); - if (!param) + if (!shuffle) { - DPRINTF(E_LOG, L_DACP, "No container-item-spec in playspec request\n"); + /* Start song ID */ + param = evhttp_find_header(query, "container-item-spec"); + if (!param) + { + DPRINTF(E_LOG, L_DACP, "No container-item-spec in playspec request\n"); - goto out_fail; + goto out_fail; + } + + param = strchr(param, ':'); + if (!param) + { + DPRINTF(E_LOG, L_DACP, "Malformed container-item-spec parameter in playspec request\n"); + + goto out_fail; + } + param++; + + ret = safe_hextou32(param, &id); + if (ret < 0) + { + DPRINTF(E_LOG, L_DACP, "Couldn't convert container-item-spec to an integer in playspec (%s)\n", param); + + goto out_fail; + } } + else + id = 0; - param = strchr(param, ':'); - if (!param) - { - DPRINTF(E_LOG, L_DACP, "Malformed container-item-spec parameter in playspec request\n"); - - goto out_fail; - } - param++; - - ret = safe_hextou32(param, &id); - if (ret < 0) - { - DPRINTF(E_LOG, L_DACP, "Couldn't convert container-item-spec to an integer in playspec (%s)\n", param); - - goto out_fail; - } - - DPRINTF(E_DBG, L_DACP, "Playspec request for playlist %d, start song id %d\n", plid, id); + DPRINTF(E_DBG, L_DACP, "Playspec request for playlist %d, start song id %d%s\n", plid, id, (shuffle) ? ", shuffle" : ""); ps = player_queue_make_pl(plid, &id); if (!ps) @@ -903,6 +912,9 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u player_queue_clear(); player_queue_add(ps); + if (shuffle) + dacp_propset_shufflestate(shuffle, NULL); + ret = player_playback_start(&id); if (ret < 0) { diff --git a/src/player.c b/src/player.c index 5d729d5b..61569fdb 100644 --- a/src/player.c +++ b/src/player.c @@ -474,6 +474,10 @@ player_queue_make_pl(int plid, uint32_t *id) ps = player_queue_make(&qp, NULL); + /* Shortcut for shuffled playlist */ + if (*id == 0) + return ps; + p = ps; i = 0; do