[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 evbuf the response event buffer
* @param mfi media information * @param mfi media information
* @param item_id queue-item id
* @param pos_pl position in the playqueue, if -1 the position is ignored * @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. * @return the number of bytes added if successful, or -1 if an error occurred.
*/ */
static int 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]; char modified[32];
int ret; int ret;
@ -516,10 +517,9 @@ mpd_add_mediainfo(struct evbuffer *evbuf, struct media_file_info *mfi, int pos_p
"Pos: %d\n", "Pos: %d\n",
pos_pl); 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, ret = evbuffer_add_printf(evbuf,
"Id: %d\n", "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 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; struct media_file_info *mfi;
int ret; int ret;
@ -539,7 +539,7 @@ mpd_add_mediainfo_byid(struct evbuffer *evbuf, int id, int pos_pl)
return -1; return -1;
} }
ret = mpd_add_mediainfo(evbuf, mfi, pos_pl); ret = mpd_add_mediainfo(evbuf, mfi, item_id, pos_pl);
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_MPD, "Error adding media info for file with id: %d\n", id); 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; 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) if (ret < 0)
{ {
ret = asprintf(errmsg, "Error adding media info for file with id: %d", status.id); 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" "nextsong: %d\n"
"nextsongid: %d\n", "nextsongid: %d\n",
status.pos_pl, status.pos_pl,
status.id, status.queueitem_id,
(status.pos_ms / 1000), (status.len_ms / 1000), (status.pos_ms / 1000), (status.len_ms / 1000),
(status.pos_ms / 1000.0), (status.pos_ms / 1000.0),
status.next_pos_pl, status.next_pos_pl,
status.next_id); status.next_queueitem_id);
} }
if (filescanner_scanning()) 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) 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) if (ret < 0)
{ {
ret = asprintf(errmsg, "Error adding media info for file with id: %d", queue->queue[i].dbmfi_id); 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; pos_pl = queue->start_pos;
for (i = 0; i < queue->count; i++) 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) if (ret < 0)
{ {
ret = asprintf(errmsg, "Error adding media info for file with id: %d", queue->queue[i].dbmfi_id); 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; pos_pl = queue->start_pos;
for (i = 0; i < queue->count; i++) 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) if (ret < 0)
{ {
ret = asprintf(errmsg, "Error adding media info for file with id: %d", queue->queue[i].dbmfi_id); 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); mfi = db_file_fetch_byvirtualpath(fi->virtual_path);
if (mfi) if (mfi)
{ {
ret = mpd_add_mediainfo(evbuf, mfi, -1); ret = mpd_add_mediainfo(evbuf, mfi, 0, -1);
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_MPD, "Could not add mediainfo for path '%s'\n", fi->virtual_path); 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 static int
source_read(uint8_t *buf, int len, uint64_t rtptime) source_read(uint8_t *buf, int len, uint64_t rtptime)
{ {
int new;
int ret; int ret;
int nbytes; int nbytes;
char *silence_buf; char *silence_buf;
@ -1504,7 +1503,6 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
return 0; return 0;
nbytes = 0; nbytes = 0;
new = 0;
while (nbytes < len) while (nbytes < len)
{ {
if (evbuffer_get_length(audio_buf) == 0) 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"); 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) if (ret < 0)
{ {
@ -2192,6 +2190,7 @@ get_status(struct player_command *cmd)
status->status = PLAY_PAUSED; status->status = PLAY_PAUSED;
status->id = cur_streaming->id; status->id = cur_streaming->id;
status->queueitem_id = cur_streaming->queueitem_id;
pos = last_rtptime + AIRTUNES_V2_PACKET_SAMPLES - cur_streaming->stream_start; pos = last_rtptime + AIRTUNES_V2_PACKET_SAMPLES - cur_streaming->stream_start;
status->pos_ms = (pos * 1000) / 44100; status->pos_ms = (pos * 1000) / 44100;
@ -2237,12 +2236,14 @@ get_status(struct player_command *cmd)
status->len_ms = ps->len_ms; status->len_ms = ps->len_ms;
status->id = ps->id; status->id = ps->id;
status->queueitem_id = ps->queueitem_id;
status->pos_pl = queue_index_byitemid(queue, ps->queueitem_id, 0); 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) if (item_next)
{ {
status->next_id = item_next->dbmfi_id; 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); status->next_pos_pl = queue_index_byitemid(queue, item_next->item_id, 0);
} }
else else
@ -2444,7 +2445,7 @@ playback_start_item(struct player_command *cmd, struct queue_item_info *qii)
{ {
if (shuffle) if (shuffle)
queue_shuffle(queue, 0); queue_shuffle(queue, 0);
item = queue_next(queue, 0, shuffle, repeat); item = queue_next(queue, 0, shuffle, repeat, 0);
} }
if (item) if (item)
@ -2668,7 +2669,7 @@ playback_next_bh(struct player_command *cmd)
if (cur_streaming->output_start > cur_streaming->stream_start) if (cur_streaming->output_start > cur_streaming->stream_start)
history_add(cur_streaming->id); 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) if (!item)
{ {
playback_abort(); playback_abort();

View File

@ -51,8 +51,10 @@ struct player_status {
uint32_t plversion; uint32_t plversion;
/* Playlist length */ /* Playlist length */
uint32_t playlistlength; uint32_t playlistlength;
/* Playing song id*/ /* Id of the playing file/item in the files database */
uint32_t id; uint32_t id;
/* Item-Id of the playing file/item in the queue */
uint32_t queueitem_id;
/* Elapsed time in ms of playing item */ /* Elapsed time in ms of playing item */
uint32_t pos_ms; uint32_t pos_ms;
/* Length in ms of playing item */ /* Length in ms of playing item */
@ -61,6 +63,8 @@ struct player_status {
int pos_pl; int pos_pl;
/* Item id of next item in playlist */ /* Item id of next item in playlist */
uint32_t next_id; uint32_t next_id;
/* Item-Id of the next file/item in the queue */
uint32_t next_queueitem_id;
/* Playlist position of next item */ /* Playlist position of next item */
int next_pos_pl; 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 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 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 r_mode Repeat mode
* @param reshuffle If 1 and repeat mode is "repeat all" reshuffles the queue on wrap around
* @return The next item * @return The next item
*/ */
struct queue_item_info * 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; 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) if (item == queue->head && r_mode == REPEAT_ALL)
{ {
// Repeat all and end of queue reached, return first item in the queue // 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); 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); queue_index_byitemid(struct queue *queue, unsigned int item_id, char shuffle);
struct queue_item_info * 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 * struct queue_item_info *
queue_prev(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode); queue_prev(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode);