mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-15 16:53:18 -05:00
[player] Store item-ids in history to allow start of playback from the
previously played items in dacp
This commit is contained in:
parent
b19a7280b9
commit
199b765a7d
@ -967,6 +967,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
const char *cuequery;
|
const char *cuequery;
|
||||||
const char *param;
|
const char *param;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
uint32_t item_id;
|
||||||
uint32_t pos;
|
uint32_t pos;
|
||||||
int clear;
|
int clear;
|
||||||
struct player_history *history;
|
struct player_history *history;
|
||||||
@ -1018,6 +1019,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
dacp_propset_shufflestate(param, NULL);
|
dacp_propset_shufflestate(param, NULL);
|
||||||
|
|
||||||
id = 0;
|
id = 0;
|
||||||
|
item_id = 0;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
param = evhttp_find_header(query, "index");
|
param = evhttp_find_header(query, "index");
|
||||||
if (param)
|
if (param)
|
||||||
@ -1041,7 +1043,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
if (history->count > pos)
|
if (history->count > pos)
|
||||||
{
|
{
|
||||||
pos = (history->start_index + history->count - pos - 1) % MAX_HISTORY_COUNT;
|
pos = (history->start_index + history->count - pos - 1) % MAX_HISTORY_COUNT;
|
||||||
id = history->id[pos];
|
item_id = history->item_id[pos];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1060,7 +1062,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
|
|
||||||
/* If playing from history queue, the pos holds the id of the item to play */
|
/* If playing from history queue, the pos holds the id of the item to play */
|
||||||
if (hist)
|
if (hist)
|
||||||
ret = player_playback_start_byitemid(id, &id); //TODO [queue/history] id does not hold the queueitemid but the dbmfiid
|
ret = player_playback_start_byitemid(item_id, &id);
|
||||||
else
|
else
|
||||||
ret = player_playback_start_bypos(pos, &id);
|
ret = player_playback_start_bypos(pos, &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.queueitem_id, status.pos_pl);
|
ret = mpd_add_mediainfo_byid(evbuf, status.id, status.item_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.queueitem_id,
|
status.item_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_queueitem_id);
|
status.next_item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filescanner_scanning())
|
if (filescanner_scanning())
|
||||||
|
51
src/player.c
51
src/player.c
@ -87,7 +87,7 @@ struct player_source
|
|||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
|
||||||
/* Item-Id of the file/item in the queue */
|
/* Item-Id of the file/item in the queue */
|
||||||
uint32_t queueitem_id;
|
uint32_t item_id;
|
||||||
|
|
||||||
/* Length of the file/item in milliseconds */
|
/* Length of the file/item in milliseconds */
|
||||||
uint32_t len_ms;
|
uint32_t len_ms;
|
||||||
@ -794,7 +794,7 @@ player_history_get(void)
|
|||||||
* Add the song with the given id to the list of previously played songs
|
* Add the song with the given id to the list of previously played songs
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
history_add(uint32_t id)
|
history_add(uint32_t id, uint32_t item_id)
|
||||||
{
|
{
|
||||||
unsigned int cur_index;
|
unsigned int cur_index;
|
||||||
unsigned int next_index;
|
unsigned int next_index;
|
||||||
@ -813,6 +813,7 @@ history_add(uint32_t id)
|
|||||||
history->start_index = (history->start_index + 1) % MAX_HISTORY_COUNT;
|
history->start_index = (history->start_index + 1) % MAX_HISTORY_COUNT;
|
||||||
|
|
||||||
history->id[next_index] = id;
|
history->id[next_index] = id;
|
||||||
|
history->item_id[next_index] = item_id;
|
||||||
|
|
||||||
if (history->count < MAX_HISTORY_COUNT)
|
if (history->count < MAX_HISTORY_COUNT)
|
||||||
history->count++;
|
history->count++;
|
||||||
@ -1145,7 +1146,7 @@ source_new(struct queue_item *item)
|
|||||||
ps = (struct player_source *)calloc(1, sizeof(struct player_source));
|
ps = (struct player_source *)calloc(1, sizeof(struct player_source));
|
||||||
|
|
||||||
ps->id = queueitem_id(item);
|
ps->id = queueitem_id(item);
|
||||||
ps->queueitem_id = queueitem_item_id(item);
|
ps->item_id = queueitem_item_id(item);
|
||||||
ps->data_kind = queueitem_data_kind(item);
|
ps->data_kind = queueitem_data_kind(item);
|
||||||
ps->media_kind = queueitem_media_kind(item);
|
ps->media_kind = queueitem_media_kind(item);
|
||||||
ps->len_ms = queueitem_len(item);
|
ps->len_ms = queueitem_len(item);
|
||||||
@ -1458,7 +1459,7 @@ source_check(void)
|
|||||||
#ifdef LASTFM
|
#ifdef LASTFM
|
||||||
worker_execute(scrobble_cb, &id, sizeof(int), 8);
|
worker_execute(scrobble_cb, &id, sizeof(int), 8);
|
||||||
#endif
|
#endif
|
||||||
history_add(cur_playing->id);
|
history_add(cur_playing->id, cur_playing->item_id);
|
||||||
|
|
||||||
/* Stop playback */
|
/* Stop playback */
|
||||||
if (!cur_playing->play_next)
|
if (!cur_playing->play_next)
|
||||||
@ -1523,12 +1524,12 @@ 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, 1);
|
item = queue_next(queue, cur_streaming->item_id, shuffle, repeat, 1);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Error reading source %d\n", cur_streaming->id);
|
DPRINTF(E_LOG, L_PLAYER, "Error reading source %d\n", cur_streaming->id);
|
||||||
queue_remove_byitemid(queue, cur_streaming->queueitem_id);
|
queue_remove_byitemid(queue, cur_streaming->item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item)
|
if (item)
|
||||||
@ -2185,13 +2186,13 @@ 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;
|
status->item_id = cur_streaming->item_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;
|
||||||
status->len_ms = cur_streaming->len_ms;
|
status->len_ms = cur_streaming->len_ms;
|
||||||
|
|
||||||
status->pos_pl = queue_index_byitemid(queue, cur_streaming->queueitem_id, 0);
|
status->pos_pl = queue_index_byitemid(queue, cur_streaming->item_id, 0);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2231,15 +2232,15 @@ 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->item_id = ps->item_id;
|
||||||
status->pos_pl = queue_index_byitemid(queue, ps->queueitem_id, 0);
|
status->pos_pl = queue_index_byitemid(queue, ps->item_id, 0);
|
||||||
|
|
||||||
item_next = queue_next(queue, ps->queueitem_id, shuffle, repeat, 0);
|
item_next = queue_next(queue, ps->item_id, shuffle, repeat, 0);
|
||||||
if (item_next)
|
if (item_next)
|
||||||
{
|
{
|
||||||
status->next_id = queueitem_id(item_next);
|
status->next_id = queueitem_id(item_next);
|
||||||
status->next_queueitem_id = queueitem_item_id(item_next);
|
status->next_item_id = queueitem_item_id(item_next);
|
||||||
status->next_pos_pl = queue_index_byitemid(queue, status->next_queueitem_id, 0);
|
status->next_pos_pl = queue_index_byitemid(queue, status->next_item_id, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2315,7 +2316,7 @@ playback_stop(struct player_command *cmd)
|
|||||||
ps_playing = source_now_playing();
|
ps_playing = source_now_playing();
|
||||||
if (ps_playing)
|
if (ps_playing)
|
||||||
{
|
{
|
||||||
history_add(ps_playing->id);
|
history_add(ps_playing->id, ps_playing->item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
source_stop();
|
source_stop();
|
||||||
@ -2577,7 +2578,7 @@ playback_start_bypos(struct player_command *cmd)
|
|||||||
|
|
||||||
if (ps_playing)
|
if (ps_playing)
|
||||||
{
|
{
|
||||||
qii = queue_get_bypos(queue, ps_playing->queueitem_id, offset, shuffle);
|
qii = queue_get_bypos(queue, ps_playing->item_id, offset, shuffle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2606,7 +2607,7 @@ playback_prev_bh(struct player_command *cmd)
|
|||||||
|
|
||||||
/* Only add to history if playback started. */
|
/* Only add to history if playback started. */
|
||||||
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, cur_streaming->item_id);
|
||||||
|
|
||||||
/* Compute the playing time in seconds for the current song. */
|
/* Compute the playing time in seconds for the current song. */
|
||||||
if (cur_streaming->output_start > cur_streaming->stream_start)
|
if (cur_streaming->output_start > cur_streaming->stream_start)
|
||||||
@ -2619,7 +2620,7 @@ playback_prev_bh(struct player_command *cmd)
|
|||||||
DPRINTF(E_DBG, L_PLAYER, "Skipping song played %d sec\n", pos_sec);
|
DPRINTF(E_DBG, L_PLAYER, "Skipping song played %d sec\n", pos_sec);
|
||||||
if (pos_sec < 3)
|
if (pos_sec < 3)
|
||||||
{
|
{
|
||||||
item = queue_prev(queue, cur_streaming->queueitem_id, shuffle, repeat);
|
item = queue_prev(queue, cur_streaming->item_id, shuffle, repeat);
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
playback_abort();
|
playback_abort();
|
||||||
@ -2677,9 +2678,9 @@ playback_next_bh(struct player_command *cmd)
|
|||||||
|
|
||||||
/* Only add to history if playback started. */
|
/* Only add to history if playback started. */
|
||||||
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, cur_streaming->item_id);
|
||||||
|
|
||||||
item = queue_next(queue, cur_streaming->queueitem_id, shuffle, repeat, 0);
|
item = queue_next(queue, cur_streaming->item_id, shuffle, repeat, 0);
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
playback_abort();
|
playback_abort();
|
||||||
@ -3281,7 +3282,7 @@ shuffle_set(struct player_command *cmd)
|
|||||||
case 1:
|
case 1:
|
||||||
if (!shuffle)
|
if (!shuffle)
|
||||||
{
|
{
|
||||||
cur_id = cur_streaming ? cur_streaming->queueitem_id : 0;
|
cur_id = cur_streaming ? cur_streaming->item_id : 0;
|
||||||
queue_shuffle(queue, cur_id);
|
queue_shuffle(queue, cur_id);
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH*/
|
/* FALLTHROUGH*/
|
||||||
@ -3314,7 +3315,7 @@ playerqueue_get_bypos(struct player_command *cmd)
|
|||||||
item_id = 0;
|
item_id = 0;
|
||||||
if (ps)
|
if (ps)
|
||||||
{
|
{
|
||||||
item_id = ps->queueitem_id;
|
item_id = ps->item_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
qi = queue_new_bypos(queue, item_id, count, shuffle);
|
qi = queue_new_bypos(queue, item_id, count, shuffle);
|
||||||
@ -3352,7 +3353,7 @@ playerqueue_add(struct player_command *cmd)
|
|||||||
|
|
||||||
if (shuffle)
|
if (shuffle)
|
||||||
{
|
{
|
||||||
cur_id = cur_streaming ? cur_streaming->queueitem_id : 0;
|
cur_id = cur_streaming ? cur_streaming->item_id : 0;
|
||||||
queue_shuffle(queue, cur_id);
|
queue_shuffle(queue, cur_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3374,7 +3375,7 @@ playerqueue_add_next(struct player_command *cmd)
|
|||||||
|
|
||||||
items = cmd->arg.queue_add_param.items;
|
items = cmd->arg.queue_add_param.items;
|
||||||
|
|
||||||
cur_id = cur_streaming ? cur_streaming->queueitem_id : 0;
|
cur_id = cur_streaming ? cur_streaming->item_id : 0;
|
||||||
|
|
||||||
queue_add_after(queue, items, cur_id);
|
queue_add_after(queue, items, cur_id);
|
||||||
|
|
||||||
@ -3407,7 +3408,7 @@ playerqueue_move_bypos(struct player_command *cmd)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_move_bypos(queue, ps_playing->queueitem_id, cmd->arg.ps_pos[0], cmd->arg.ps_pos[1], shuffle);
|
queue_move_bypos(queue, ps_playing->item_id, cmd->arg.ps_pos[0], cmd->arg.ps_pos[1], shuffle);
|
||||||
|
|
||||||
cur_plversion++;
|
cur_plversion++;
|
||||||
|
|
||||||
@ -3438,7 +3439,7 @@ playerqueue_remove_bypos(struct player_command *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_PLAYER, "Removing item from position %d\n", pos);
|
DPRINTF(E_DBG, L_PLAYER, "Removing item from position %d\n", pos);
|
||||||
queue_remove_bypos(queue, ps_playing->queueitem_id, pos, shuffle);
|
queue_remove_bypos(queue, ps_playing->item_id, pos, shuffle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ struct player_status {
|
|||||||
/* Id of the playing file/item in the files database */
|
/* 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 */
|
/* Item-Id of the playing file/item in the queue */
|
||||||
uint32_t queueitem_id;
|
uint32_t item_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 */
|
||||||
@ -64,7 +64,7 @@ struct player_status {
|
|||||||
/* 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 */
|
/* Item-Id of the next file/item in the queue */
|
||||||
uint32_t next_queueitem_id;
|
uint32_t next_item_id;
|
||||||
/* Playlist position of next item */
|
/* Playlist position of next item */
|
||||||
int next_pos_pl;
|
int next_pos_pl;
|
||||||
};
|
};
|
||||||
@ -81,6 +81,7 @@ struct player_history
|
|||||||
|
|
||||||
/* Circular buffer of song ids previously played by forked-daapd */
|
/* Circular buffer of song ids previously played by forked-daapd */
|
||||||
uint32_t id[MAX_HISTORY_COUNT];
|
uint32_t id[MAX_HISTORY_COUNT];
|
||||||
|
uint32_t item_id[MAX_HISTORY_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user