[mpd] Expose queue-item-id instead of dbmfi-id in mpd commands

[player] Reshuffle on end of playlist and repeat mode is "repeat all"
This commit is contained in:
chme 2015-09-19 08:23:41 +02:00
parent cb2805800b
commit a06424a701
5 changed files with 29 additions and 21 deletions

View File

@ -471,11 +471,12 @@ mpd_parse_args(char *args, int *argc, char **argv)
*
* @param evbuf the response event buffer
* @param mfi media information
* @param item_id queue-item id
* @param pos_pl position in the playqueue, if -1 the position is ignored
* @return the number of bytes added if successful, or -1 if an error occurred.
*/
static int
mpd_add_mediainfo(struct evbuffer *evbuf, struct media_file_info *mfi, int pos_pl)
mpd_add_mediainfo(struct evbuffer *evbuf, struct media_file_info *mfi, unsigned int item_id, int pos_pl)
{
char modified[32];
int ret;
@ -516,10 +517,9 @@ mpd_add_mediainfo(struct evbuffer *evbuf, struct media_file_info *mfi, int pos_p
"Pos: %d\n",
pos_pl);
//TODO mpd does not return the persistent id of a file but instead a unique id in the current playlist
ret = evbuffer_add_printf(evbuf,
"Id: %d\n",
mfi->id);
item_id);
}
@ -527,7 +527,7 @@ mpd_add_mediainfo(struct evbuffer *evbuf, struct media_file_info *mfi, int pos_p
}
static int
mpd_add_mediainfo_byid(struct evbuffer *evbuf, int id, int pos_pl)
mpd_add_mediainfo_byid(struct evbuffer *evbuf, int id, unsigned int item_id, int pos_pl)
{
struct media_file_info *mfi;
int ret;
@ -539,7 +539,7 @@ mpd_add_mediainfo_byid(struct evbuffer *evbuf, int id, int pos_pl)
return -1;
}
ret = mpd_add_mediainfo(evbuf, mfi, pos_pl);
ret = mpd_add_mediainfo(evbuf, mfi, item_id, pos_pl);
if (ret < 0)
{
DPRINTF(E_LOG, L_MPD, "Error adding media info for file with id: %d\n", id);
@ -650,7 +650,7 @@ mpd_command_currentsong(struct evbuffer *evbuf, int argc, char **argv, char **er
return 0;
}
ret = mpd_add_mediainfo_byid(evbuf, status.id, status.pos_pl);
ret = mpd_add_mediainfo_byid(evbuf, status.id, status.queueitem_id, status.pos_pl);
if (ret < 0)
{
ret = asprintf(errmsg, "Error adding media info for file with id: %d", status.id);
@ -839,11 +839,11 @@ mpd_command_status(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
"nextsong: %d\n"
"nextsongid: %d\n",
status.pos_pl,
status.id,
status.queueitem_id,
(status.pos_ms / 1000), (status.len_ms / 1000),
(status.pos_ms / 1000.0),
status.next_pos_pl,
status.next_id);
status.next_queueitem_id);
}
if (filescanner_scanning())
@ -1792,7 +1792,7 @@ mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **err
{
if (songid == 0 || songid == queue->queue[i].item_id)
{
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, pos_pl);
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, queue->queue[i].item_id, pos_pl);
if (ret < 0)
{
ret = asprintf(errmsg, "Error adding media info for file with id: %d", queue->queue[i].dbmfi_id);
@ -1867,7 +1867,7 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
pos_pl = queue->start_pos;
for (i = 0; i < queue->count; i++)
{
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, pos_pl);
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, queue->queue[i].item_id, pos_pl);
if (ret < 0)
{
ret = asprintf(errmsg, "Error adding media info for file with id: %d", queue->queue[i].dbmfi_id);
@ -1914,7 +1914,7 @@ mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errm
pos_pl = queue->start_pos;
for (i = 0; i < queue->count; i++)
{
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, pos_pl);
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, queue->queue[i].item_id, pos_pl);
if (ret < 0)
{
ret = asprintf(errmsg, "Error adding media info for file with id: %d", queue->queue[i].dbmfi_id);
@ -2691,7 +2691,7 @@ mpd_command_lsinfo(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
mfi = db_file_fetch_byvirtualpath(fi->virtual_path);
if (mfi)
{
ret = mpd_add_mediainfo(evbuf, mfi, -1);
ret = mpd_add_mediainfo(evbuf, mfi, 0, -1);
if (ret < 0)
{
DPRINTF(E_LOG, L_MPD, "Could not add mediainfo for path '%s'\n", fi->virtual_path);

View File

@ -1494,7 +1494,6 @@ source_check(void)
static int
source_read(uint8_t *buf, int len, uint64_t rtptime)
{
int new;
int ret;
int nbytes;
char *silence_buf;
@ -1504,7 +1503,6 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
return 0;
nbytes = 0;
new = 0;
while (nbytes < len)
{
if (evbuffer_get_length(audio_buf) == 0)
@ -1530,7 +1528,7 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
DPRINTF(E_DBG, L_PLAYER, "New file\n");
item = queue_next(queue, cur_streaming->queueitem_id, shuffle, repeat);
item = queue_next(queue, cur_streaming->queueitem_id, shuffle, repeat, 1);
if (ret < 0)
{
@ -2192,6 +2190,7 @@ get_status(struct player_command *cmd)
status->status = PLAY_PAUSED;
status->id = cur_streaming->id;
status->queueitem_id = cur_streaming->queueitem_id;
pos = last_rtptime + AIRTUNES_V2_PACKET_SAMPLES - cur_streaming->stream_start;
status->pos_ms = (pos * 1000) / 44100;
@ -2237,12 +2236,14 @@ get_status(struct player_command *cmd)
status->len_ms = ps->len_ms;
status->id = ps->id;
status->queueitem_id = ps->queueitem_id;
status->pos_pl = queue_index_byitemid(queue, ps->queueitem_id, 0);
item_next = queue_next(queue, ps->queueitem_id, shuffle, repeat);
item_next = queue_next(queue, ps->queueitem_id, shuffle, repeat, 0);
if (item_next)
{
status->next_id = item_next->dbmfi_id;
status->next_queueitem_id = item_next->item_id;
status->next_pos_pl = queue_index_byitemid(queue, item_next->item_id, 0);
}
else
@ -2444,7 +2445,7 @@ playback_start_item(struct player_command *cmd, struct queue_item_info *qii)
{
if (shuffle)
queue_shuffle(queue, 0);
item = queue_next(queue, 0, shuffle, repeat);
item = queue_next(queue, 0, shuffle, repeat, 0);
}
if (item)
@ -2668,7 +2669,7 @@ playback_next_bh(struct player_command *cmd)
if (cur_streaming->output_start > cur_streaming->stream_start)
history_add(cur_streaming->id);
item = queue_next(queue, cur_streaming->queueitem_id, shuffle, repeat);
item = queue_next(queue, cur_streaming->queueitem_id, shuffle, repeat, 0);
if (!item)
{
playback_abort();

View File

@ -51,8 +51,10 @@ struct player_status {
uint32_t plversion;
/* Playlist length */
uint32_t playlistlength;
/* Playing song id*/
/* Id of the playing file/item in the files database */
uint32_t id;
/* Item-Id of the playing file/item in the queue */
uint32_t queueitem_id;
/* Elapsed time in ms of playing item */
uint32_t pos_ms;
/* Length in ms of playing item */
@ -61,6 +63,8 @@ struct player_status {
int pos_pl;
/* Item id of next item in playlist */
uint32_t next_id;
/* Item-Id of the next file/item in the queue */
uint32_t next_queueitem_id;
/* Playlist position of next item */
int next_pos_pl;
};

View File

@ -392,10 +392,11 @@ queue_index_byitemid(struct queue *queue, unsigned int item_id, char shuffle)
* @param item_id The id of the item in the queue
* @param shuffle If 0 return the next item in the play-queue, if 1 the next item in the shuffle-queue
* @param r_mode Repeat mode
* @param reshuffle If 1 and repeat mode is "repeat all" reshuffles the queue on wrap around
* @return The next item
*/
struct queue_item_info *
queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode)
queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode, int reshuffle)
{
struct queue_item *item;
@ -413,6 +414,8 @@ queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_
if (item == queue->head && r_mode == REPEAT_ALL)
{
// Repeat all and end of queue reached, return first item in the queue
if (reshuffle)
queue_shuffle(queue, 0);
item = item_next(queue->head, shuffle);
}

View File

@ -84,7 +84,7 @@ int
queue_index_byitemid(struct queue *queue, unsigned int item_id, char shuffle);
struct queue_item_info *
queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode);
queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode, int reshuffle);
struct queue_item_info *
queue_prev(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode);