mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-29 00:23:23 -05:00
[queue] Remove queue_info and queue_item_info structs
This commit is contained in:
parent
35df9455b9
commit
ba3385b0ec
@ -822,7 +822,7 @@ find_first_song_id(const char *query)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
make_queue_byquery(struct queue_item **head, const char *query, const char *queuefilter, const char *sort, int quirk)
|
dacp_queueitem_make(struct queue_item **head, const char *query, const char *queuefilter, const char *sort, int quirk)
|
||||||
{
|
{
|
||||||
struct media_file_info *mfi;
|
struct media_file_info *mfi;
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
@ -942,7 +942,7 @@ make_queue_byquery(struct queue_item **head, const char *query, const char *queu
|
|||||||
qp.sort = S_ARTIST;
|
qp.sort = S_ARTIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
items = queue_make(&qp);
|
items = queueitem_make_byquery(&qp);
|
||||||
|
|
||||||
if (qp.filter)
|
if (qp.filter)
|
||||||
free(qp.filter);
|
free(qp.filter);
|
||||||
@ -994,7 +994,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
{
|
{
|
||||||
sort = evhttp_find_header(query, "sort");
|
sort = evhttp_find_header(query, "sort");
|
||||||
|
|
||||||
ret = make_queue_byquery(&items, cuequery, NULL, sort, 0);
|
ret = dacp_queueitem_make(&items, cuequery, NULL, sort, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not build song queue\n");
|
DPRINTF(E_LOG, L_DACP, "Could not build song queue\n");
|
||||||
@ -1215,9 +1215,9 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
|
|
||||||
items = NULL;
|
items = NULL;
|
||||||
if (plid > 0)
|
if (plid > 0)
|
||||||
items = queue_make_pl(plid);
|
items = queueitem_make_byplid(plid);
|
||||||
else if (pos > 0)
|
else if (pos > 0)
|
||||||
items = queue_make_item(pos);
|
items = queueitem_make_byid(pos);
|
||||||
|
|
||||||
if (!items)
|
if (!items)
|
||||||
{
|
{
|
||||||
@ -1474,11 +1474,13 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
struct evbuffer *playlists;
|
struct evbuffer *playlists;
|
||||||
struct player_status status;
|
struct player_status status;
|
||||||
struct player_history *history;
|
struct player_history *history;
|
||||||
struct queue_info *queue;
|
struct queue *queue;
|
||||||
|
struct queue_item *item;
|
||||||
const char *param;
|
const char *param;
|
||||||
size_t songlist_length;
|
size_t songlist_length;
|
||||||
size_t playlist_length;
|
size_t playlist_length;
|
||||||
int span;
|
int span;
|
||||||
|
int count;
|
||||||
int i;
|
int i;
|
||||||
int n;
|
int n;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1549,10 +1551,12 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
queue = player_queue_get_bypos(abs(span));
|
queue = player_queue_get_bypos(abs(span));
|
||||||
if (queue)
|
if (queue)
|
||||||
{
|
{
|
||||||
i = queue->start_pos;
|
i = 0;
|
||||||
for (n = 0; (n < queue->count) && (n < abs(span)); n++)
|
count = queue_count(queue);
|
||||||
|
for (n = 0; (n < count) && (n < abs(span)); n++)
|
||||||
{
|
{
|
||||||
ret = playqueuecontents_add_source(songlist, queue->queue[n].dbmfi_id, (n + i + 1), status.plid);
|
item = queue_get_byindex(queue, n, 0);
|
||||||
|
ret = playqueuecontents_add_source(songlist, queueitem_id(item), (n + i + 1), status.plid);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not add song to songlist for playqueue-contents\n");
|
DPRINTF(E_LOG, L_DACP, "Could not add song to songlist for playqueue-contents\n");
|
||||||
@ -1561,7 +1565,7 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queue_info_free(queue);
|
queue_free(queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1730,7 +1734,7 @@ dacp_reply_playqueueedit_add(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
if (!querymodifier || (strcmp(querymodifier, "containers") != 0))
|
if (!querymodifier || (strcmp(querymodifier, "containers") != 0))
|
||||||
{
|
{
|
||||||
quirkyquery = (mode == 1) && strstr(editquery, "dmap.itemid:") && ((!queuefilter) || strstr(queuefilter, "(null)"));
|
quirkyquery = (mode == 1) && strstr(editquery, "dmap.itemid:") && ((!queuefilter) || strstr(queuefilter, "(null)"));
|
||||||
ret = make_queue_byquery(&items, editquery, queuefilter, sort, quirkyquery);
|
ret = dacp_queueitem_make(&items, editquery, queuefilter, sort, quirkyquery);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1745,7 +1749,7 @@ dacp_reply_playqueueedit_add(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
snprintf(modifiedquery, sizeof(modifiedquery), "playlist:%d", plid);
|
snprintf(modifiedquery, sizeof(modifiedquery), "playlist:%d", plid);
|
||||||
ret = make_queue_byquery(&items, NULL, modifiedquery, sort, 0);
|
ret = dacp_queueitem_make(&items, NULL, modifiedquery, sort, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
69
src/mpd.c
69
src/mpd.c
@ -1508,7 +1508,7 @@ mpd_command_stop(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct queue_item *
|
static struct queue_item *
|
||||||
make_queue_bypath(char *path, int recursive)
|
mpd_queueitem_make(char *path, int recursive)
|
||||||
{
|
{
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct queue_item *items;
|
struct queue_item *items;
|
||||||
@ -1532,7 +1532,7 @@ make_queue_bypath(char *path, int recursive)
|
|||||||
DPRINTF(E_DBG, L_PLAYER, "Out of memory\n");
|
DPRINTF(E_DBG, L_PLAYER, "Out of memory\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
items = queue_make(&qp);
|
items = queueitem_make_byquery(&qp);
|
||||||
|
|
||||||
sqlite3_free(qp.filter);
|
sqlite3_free(qp.filter);
|
||||||
return items;
|
return items;
|
||||||
@ -1557,7 +1557,7 @@ mpd_command_add(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
return ACK_ERROR_ARG;
|
return ACK_ERROR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
items = make_queue_bypath(argv[1], 1);
|
items = mpd_queueitem_make(argv[1], 1);
|
||||||
|
|
||||||
if (!items)
|
if (!items)
|
||||||
{
|
{
|
||||||
@ -1604,7 +1604,7 @@ mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
DPRINTF(E_LOG, L_MPD, "Adding at a specified position not supported for 'addid', adding songs at end of queue.\n");
|
DPRINTF(E_LOG, L_MPD, "Adding at a specified position not supported for 'addid', adding songs at end of queue.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
items = make_queue_bypath(argv[1], 0);
|
items = mpd_queueitem_make(argv[1], 0);
|
||||||
|
|
||||||
if (!items)
|
if (!items)
|
||||||
{
|
{
|
||||||
@ -1758,9 +1758,11 @@ mpd_command_deleteid(struct evbuffer *evbuf, int argc, char **argv, char **errms
|
|||||||
static int
|
static int
|
||||||
mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||||
{
|
{
|
||||||
struct queue_info *queue;
|
struct queue *queue;
|
||||||
|
struct queue_item *item;
|
||||||
uint32_t songid;
|
uint32_t songid;
|
||||||
int pos_pl;
|
int pos_pl;
|
||||||
|
int count;
|
||||||
int i;
|
int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -1787,17 +1789,19 @@ mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **err
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_pl = queue->start_pos;
|
pos_pl = 0;
|
||||||
for (i = 0; i < queue->count; i++)
|
count = queue_count(queue);
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if (songid == 0 || songid == queue->queue[i].item_id)
|
item = queue_get_byindex(queue, i, 0);
|
||||||
|
if (songid == 0 || songid == queueitem_item_id(item))
|
||||||
{
|
{
|
||||||
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, queue->queue[i].item_id, pos_pl);
|
ret = mpd_add_mediainfo_byid(evbuf, queueitem_id(item), queueitem_item_id(item), 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", queueitem_id(item));
|
||||||
|
|
||||||
queue_info_free(queue);
|
queue_free(queue);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||||
@ -1808,7 +1812,7 @@ mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **err
|
|||||||
pos_pl++;
|
pos_pl++;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_info_free(queue);
|
queue_free(queue);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1824,7 +1828,8 @@ mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **err
|
|||||||
static int
|
static int
|
||||||
mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||||
{
|
{
|
||||||
struct queue_info *queue;
|
struct queue *queue;
|
||||||
|
struct queue_item *item;
|
||||||
int start_pos;
|
int start_pos;
|
||||||
int end_pos;
|
int end_pos;
|
||||||
int count;
|
int count;
|
||||||
@ -1864,15 +1869,17 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_pl = queue->start_pos;
|
pos_pl = start_pos;
|
||||||
for (i = 0; i < queue->count; i++)
|
count = queue_count(queue);
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, queue->queue[i].item_id, pos_pl);
|
item = queue_get_byindex(queue, i, 0);
|
||||||
|
ret = mpd_add_mediainfo_byid(evbuf, queueitem_id(item), queueitem_item_id(item), 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", queueitem_id(item));
|
||||||
|
|
||||||
queue_info_free(queue);
|
queue_free(queue);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||||
@ -1882,7 +1889,7 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
|
|||||||
pos_pl++;
|
pos_pl++;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_info_free(queue);
|
queue_free(queue);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1894,8 +1901,10 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
|
|||||||
static int
|
static int
|
||||||
mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||||
{
|
{
|
||||||
struct queue_info *queue;
|
struct queue *queue;
|
||||||
|
struct queue_item *item;
|
||||||
int pos_pl;
|
int pos_pl;
|
||||||
|
int count;
|
||||||
int i;
|
int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -1911,15 +1920,17 @@ mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errm
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_pl = queue->start_pos;
|
pos_pl = 0;
|
||||||
for (i = 0; i < queue->count; i++)
|
count = queue_count(queue);
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i].dbmfi_id, queue->queue[i].item_id, pos_pl);
|
item = queue_get_byindex(queue, i, 0);
|
||||||
|
ret = mpd_add_mediainfo_byid(evbuf, queueitem_id(item), queueitem_item_id(item), 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", queueitem_id(item));
|
||||||
|
|
||||||
queue_info_free(queue);
|
queue_free(queue);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||||
@ -1929,7 +1940,7 @@ mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errm
|
|||||||
pos_pl++;
|
pos_pl++;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_info_free(queue);
|
queue_free(queue);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2174,7 +2185,7 @@ mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
|
|
||||||
//TODO If a second parameter is given only add the specified range of songs to the playqueue
|
//TODO If a second parameter is given only add the specified range of songs to the playqueue
|
||||||
|
|
||||||
items = queue_make_pl(pli->id);
|
items = queueitem_make_byplid(pli->id);
|
||||||
|
|
||||||
if (!items)
|
if (!items)
|
||||||
{
|
{
|
||||||
@ -2442,7 +2453,7 @@ mpd_command_findadd(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
|
|||||||
|
|
||||||
mpd_get_query_params_find(argc - 1, argv + 1, &qp);
|
mpd_get_query_params_find(argc - 1, argv + 1, &qp);
|
||||||
|
|
||||||
items = queue_make(&qp);
|
items = queueitem_make_byquery(&qp);
|
||||||
|
|
||||||
if (!items)
|
if (!items)
|
||||||
{
|
{
|
||||||
@ -2916,7 +2927,7 @@ mpd_command_searchadd(struct evbuffer *evbuf, int argc, char **argv, char **errm
|
|||||||
|
|
||||||
mpd_get_query_params_search(argc - 1, argv + 1, &qp);
|
mpd_get_query_params_search(argc - 1, argv + 1, &qp);
|
||||||
|
|
||||||
items = queue_make(&qp);
|
items = queueitem_make_byquery(&qp);
|
||||||
|
|
||||||
if (!items)
|
if (!items)
|
||||||
{
|
{
|
||||||
|
60
src/player.c
60
src/player.c
@ -155,7 +155,7 @@ struct playerqueue_get_param
|
|||||||
int pos;
|
int pos;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
struct queue_info *queue;
|
struct queue *queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct playerqueue_add_param
|
struct playerqueue_add_param
|
||||||
@ -1138,17 +1138,17 @@ source_now_playing()
|
|||||||
* Creates a new player source for the given queue item
|
* Creates a new player source for the given queue item
|
||||||
*/
|
*/
|
||||||
static struct player_source *
|
static struct player_source *
|
||||||
source_new(struct queue_item_info *item)
|
source_new(struct queue_item *item)
|
||||||
{
|
{
|
||||||
struct player_source *ps;
|
struct player_source *ps;
|
||||||
|
|
||||||
ps = (struct player_source *)calloc(1, sizeof(struct player_source));
|
ps = (struct player_source *)calloc(1, sizeof(struct player_source));
|
||||||
|
|
||||||
ps->id = item->dbmfi_id;
|
ps->id = queueitem_id(item);
|
||||||
ps->queueitem_id = item->item_id;
|
ps->queueitem_id = queueitem_item_id(item);
|
||||||
ps->data_kind = item->data_kind;
|
ps->data_kind = queueitem_data_kind(item);
|
||||||
ps->media_kind = item->media_kind;
|
ps->media_kind = queueitem_media_kind(item);
|
||||||
ps->len_ms = item->len_ms;
|
ps->len_ms = queueitem_len(item);
|
||||||
ps->play_next = NULL;
|
ps->play_next = NULL;
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
@ -1326,10 +1326,11 @@ source_play()
|
|||||||
* Stream-start and output-start values are set to the given start position.
|
* Stream-start and output-start values are set to the given start position.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
source_open(struct queue_item_info *qii, uint64_t start_pos, int seek)
|
source_open(struct queue_item *qii, uint64_t start_pos, int seek)
|
||||||
{
|
{
|
||||||
struct player_source *ps;
|
struct player_source *ps;
|
||||||
struct media_file_info *mfi;
|
struct media_file_info *mfi;
|
||||||
|
uint32_t id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (cur_streaming && cur_streaming->end == 0)
|
if (cur_streaming && cur_streaming->end == 0)
|
||||||
@ -1338,17 +1339,18 @@ source_open(struct queue_item_info *qii, uint64_t start_pos, int seek)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mfi = db_file_fetch_byid(qii->dbmfi_id);
|
id = queueitem_id(qii);
|
||||||
|
mfi = db_file_fetch_byid(id);
|
||||||
if (!mfi)
|
if (!mfi)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Couldn't fetch file id %d\n", qii->dbmfi_id);
|
DPRINTF(E_LOG, L_PLAYER, "Couldn't fetch file id %d\n", id);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mfi->disabled)
|
if (mfi->disabled)
|
||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_PLAYER, "File id %d is disabled, skipping\n", qii->dbmfi_id);
|
DPRINTF(E_DBG, L_PLAYER, "File id %d is disabled, skipping\n", id);
|
||||||
|
|
||||||
free_mfi(mfi, 0);
|
free_mfi(mfi, 0);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1490,7 +1492,7 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
|
|||||||
int ret;
|
int ret;
|
||||||
int nbytes;
|
int nbytes;
|
||||||
char *silence_buf;
|
char *silence_buf;
|
||||||
struct queue_item_info *item;
|
struct queue_item *item;
|
||||||
|
|
||||||
if (!cur_streaming)
|
if (!cur_streaming)
|
||||||
return 0;
|
return 0;
|
||||||
@ -2154,7 +2156,7 @@ get_status(struct player_command *cmd)
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
struct player_source *ps;
|
struct player_source *ps;
|
||||||
struct player_status *status;
|
struct player_status *status;
|
||||||
struct queue_item_info *item_next;
|
struct queue_item *item_next;
|
||||||
uint64_t pos;
|
uint64_t pos;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -2235,9 +2237,9 @@ get_status(struct player_command *cmd)
|
|||||||
item_next = queue_next(queue, ps->queueitem_id, shuffle, repeat, 0);
|
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 = queueitem_id(item_next);
|
||||||
status->next_queueitem_id = item_next->item_id;
|
status->next_queueitem_id = queueitem_item_id(item_next);
|
||||||
status->next_pos_pl = queue_index_byitemid(queue, item_next->item_id, 0);
|
status->next_pos_pl = queue_index_byitemid(queue, status->next_queueitem_id, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2397,12 +2399,12 @@ playback_start_bh(struct player_command *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
playback_start_item(struct player_command *cmd, struct queue_item_info *qii)
|
playback_start_item(struct player_command *cmd, struct queue_item *qii)
|
||||||
{
|
{
|
||||||
uint32_t *dbmfi_id;
|
uint32_t *dbmfi_id;
|
||||||
struct raop_device *rd;
|
struct raop_device *rd;
|
||||||
struct player_source *ps_playing;
|
struct player_source *ps_playing;
|
||||||
struct queue_item_info *item;
|
struct queue_item *item;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dbmfi_id = cmd->arg.playback_start_param.id_ptr;
|
dbmfi_id = cmd->arg.playback_start_param.id_ptr;
|
||||||
@ -2540,7 +2542,7 @@ static int
|
|||||||
playback_start_byitemid(struct player_command *cmd)
|
playback_start_byitemid(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
int item_id;
|
int item_id;
|
||||||
struct queue_item_info *qii;
|
struct queue_item *qii;
|
||||||
|
|
||||||
item_id = cmd->arg.playback_start_param.id;
|
item_id = cmd->arg.playback_start_param.id;
|
||||||
|
|
||||||
@ -2553,7 +2555,7 @@ static int
|
|||||||
playback_start_byindex(struct player_command *cmd)
|
playback_start_byindex(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
struct queue_item_info *qii;
|
struct queue_item *qii;
|
||||||
|
|
||||||
pos = cmd->arg.playback_start_param.pos;
|
pos = cmd->arg.playback_start_param.pos;
|
||||||
|
|
||||||
@ -2567,7 +2569,7 @@ playback_start_bypos(struct player_command *cmd)
|
|||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
struct player_source *ps_playing;
|
struct player_source *ps_playing;
|
||||||
struct queue_item_info *qii;
|
struct queue_item *qii;
|
||||||
|
|
||||||
offset = cmd->arg.playback_start_param.pos;
|
offset = cmd->arg.playback_start_param.pos;
|
||||||
|
|
||||||
@ -2590,7 +2592,7 @@ playback_prev_bh(struct player_command *cmd)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int pos_sec;
|
int pos_sec;
|
||||||
struct queue_item_info *item;
|
struct queue_item *item;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The upper half is playback_pause, therefor the current playing item is
|
* The upper half is playback_pause, therefor the current playing item is
|
||||||
@ -2661,7 +2663,7 @@ static int
|
|||||||
playback_next_bh(struct player_command *cmd)
|
playback_next_bh(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct queue_item_info *item;
|
struct queue_item *item;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The upper half is playback_pause, therefor the current playing item is
|
* The upper half is playback_pause, therefor the current playing item is
|
||||||
@ -3301,7 +3303,7 @@ static int
|
|||||||
playerqueue_get_bypos(struct player_command *cmd)
|
playerqueue_get_bypos(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
struct queue_info *qi;
|
struct queue *qi;
|
||||||
struct player_source *ps;
|
struct player_source *ps;
|
||||||
int item_id;
|
int item_id;
|
||||||
|
|
||||||
@ -3315,7 +3317,7 @@ playerqueue_get_bypos(struct player_command *cmd)
|
|||||||
item_id = ps->queueitem_id;
|
item_id = ps->queueitem_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
qi = queue_info_new_bypos(queue, item_id, count, shuffle);
|
qi = queue_new_bypos(queue, item_id, count, shuffle);
|
||||||
|
|
||||||
cmd->arg.queue_get_param.queue = qi;
|
cmd->arg.queue_get_param.queue = qi;
|
||||||
|
|
||||||
@ -3327,12 +3329,12 @@ playerqueue_get_byindex(struct player_command *cmd)
|
|||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
int count;
|
int count;
|
||||||
struct queue_info *qi;
|
struct queue *qi;
|
||||||
|
|
||||||
pos = cmd->arg.queue_get_param.pos;
|
pos = cmd->arg.queue_get_param.pos;
|
||||||
count = cmd->arg.queue_get_param.count;
|
count = cmd->arg.queue_get_param.count;
|
||||||
|
|
||||||
qi = queue_info_new_byindex(queue, pos, count, 0);
|
qi = queue_new_byindex(queue, pos, count, 0);
|
||||||
cmd->arg.queue_get_param.queue = qi;
|
cmd->arg.queue_get_param.queue = qi;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -4053,7 +4055,7 @@ player_shuffle_set(int enable)
|
|||||||
* @param count max number of media items to return
|
* @param count max number of media items to return
|
||||||
* @return queue info
|
* @return queue info
|
||||||
*/
|
*/
|
||||||
struct queue_info *
|
struct queue *
|
||||||
player_queue_get_bypos(int count)
|
player_queue_get_bypos(int count)
|
||||||
{
|
{
|
||||||
struct player_command cmd;
|
struct player_command cmd;
|
||||||
@ -4085,7 +4087,7 @@ player_queue_get_bypos(int count)
|
|||||||
* @param count max number of media items to return
|
* @param count max number of media items to return
|
||||||
* @return queue info
|
* @return queue info
|
||||||
*/
|
*/
|
||||||
struct queue_info *
|
struct queue *
|
||||||
player_queue_get_byindex(int index, int count)
|
player_queue_get_byindex(int index, int count)
|
||||||
{
|
{
|
||||||
struct player_command cmd;
|
struct player_command cmd;
|
||||||
|
@ -161,10 +161,10 @@ int
|
|||||||
player_shuffle_set(int enable);
|
player_shuffle_set(int enable);
|
||||||
|
|
||||||
|
|
||||||
struct queue_info *
|
struct queue *
|
||||||
player_queue_get_bypos(int count);
|
player_queue_get_bypos(int count);
|
||||||
|
|
||||||
struct queue_info *
|
struct queue *
|
||||||
player_queue_get_byindex(int pos, int count);
|
player_queue_get_byindex(int pos, int count);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
200
src/queue.c
200
src/queue.c
@ -31,12 +31,24 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal representation of an item in a queue. It links to the previous and the next item
|
* Internal representation of an item in a queue. It links to the previous and the next item
|
||||||
* in the queue for shuffle on/off. Only the queue_item_info can be exposed.
|
* in the queue for shuffle on/off. To access the properties use the queueitem_* functions.
|
||||||
*/
|
*/
|
||||||
struct queue_item
|
struct queue_item
|
||||||
{
|
{
|
||||||
/* Identifies the item in the db and the queue */
|
/* Item-Id is a unique id for this queue item. If the same item appears multiple
|
||||||
struct queue_item_info qii;
|
times in the queue each corresponding queue item has its own id. */
|
||||||
|
unsigned int item_id;
|
||||||
|
|
||||||
|
/* Id of the file/item in the files database */
|
||||||
|
uint32_t id;
|
||||||
|
|
||||||
|
/* Length of the item in ms */
|
||||||
|
unsigned int len_ms;
|
||||||
|
|
||||||
|
/* Data type of the item */
|
||||||
|
enum data_kind data_kind;
|
||||||
|
/* Media type of the item */
|
||||||
|
enum media_kind media_kind;
|
||||||
|
|
||||||
/* Link to the previous/next item in the queue */
|
/* Link to the previous/next item in the queue */
|
||||||
struct queue_item *next;
|
struct queue_item *next;
|
||||||
@ -183,29 +195,74 @@ item_prev(struct queue_item *item, char shuffle)
|
|||||||
* If no item is found for the given id, it returns -1.
|
* If no item is found for the given id, it returns -1.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
queueitem_pos(struct queue_item *item, uint32_t dbmfi_id)
|
queueitem_pos(struct queue_item *item, uint32_t id)
|
||||||
{
|
{
|
||||||
struct queue_item *temp;
|
struct queue_item *temp;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
if (dbmfi_id == 0 || item->qii.dbmfi_id == dbmfi_id)
|
if (id == 0 || item->id == id)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pos = 1;
|
pos = 1;
|
||||||
for (temp = item->next; (temp != item) && temp->qii.dbmfi_id != dbmfi_id; temp = temp->next)
|
for (temp = item->next; (temp != item) && temp->id != id; temp = temp->next)
|
||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp == item)
|
if (temp == item)
|
||||||
{
|
{
|
||||||
// Item with given dbmfi_id does not exists
|
// Item with given (database) id does not exists
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the id of the item/file in the files database table
|
||||||
|
*/
|
||||||
|
uint32_t
|
||||||
|
queueitem_id(struct queue_item *item)
|
||||||
|
{
|
||||||
|
return item->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the queue-item-id
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
queueitem_item_id(struct queue_item *item)
|
||||||
|
{
|
||||||
|
return item->item_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the length of the item in milliseconds
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
queueitem_len(struct queue_item *item)
|
||||||
|
{
|
||||||
|
return item->len_ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the data-kind
|
||||||
|
*/
|
||||||
|
enum data_kind
|
||||||
|
queueitem_data_kind(struct queue_item *item)
|
||||||
|
{
|
||||||
|
return item->data_kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the media-kind
|
||||||
|
*/
|
||||||
|
enum media_kind
|
||||||
|
queueitem_media_kind(struct queue_item *item)
|
||||||
|
{
|
||||||
|
return item->media_kind;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the item with the given item_id in the queue
|
* Returns the item with the given item_id in the queue
|
||||||
*
|
*
|
||||||
@ -218,7 +275,7 @@ queueitem_get_byitemid(struct queue *queue, int item_id)
|
|||||||
{
|
{
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
|
|
||||||
for (item = queue->head->next; item != queue->head && item->qii.item_id != item_id; item = item->next)
|
for (item = queue->head->next; item != queue->head && item->item_id != item_id; item = item->next)
|
||||||
{
|
{
|
||||||
// Iterate through the queue until the item with item_id is found
|
// Iterate through the queue until the item with item_id is found
|
||||||
}
|
}
|
||||||
@ -297,7 +354,7 @@ queueitem_get_bypos(struct queue *queue, unsigned int item_id, unsigned int pos,
|
|||||||
* @param item_id The unique id of the item in the queue
|
* @param item_id The unique id of the item in the queue
|
||||||
* @return Item with the given item_id or NULL if not found
|
* @return Item with the given item_id or NULL if not found
|
||||||
*/
|
*/
|
||||||
struct queue_item_info *
|
struct queue_item *
|
||||||
queue_get_byitemid(struct queue *queue, unsigned int item_id)
|
queue_get_byitemid(struct queue *queue, unsigned int item_id)
|
||||||
{
|
{
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
@ -307,7 +364,7 @@ queue_get_byitemid(struct queue *queue, unsigned int item_id)
|
|||||||
if (!item)
|
if (!item)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return &item->qii;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -318,7 +375,7 @@ queue_get_byitemid(struct queue *queue, unsigned int item_id)
|
|||||||
* @param shuffle Play queue (shuffle = 0) or shuffle queue (shuffle = 1)
|
* @param shuffle Play queue (shuffle = 0) or shuffle queue (shuffle = 1)
|
||||||
* @return Item at index in the queue or NULL if not found
|
* @return Item at index in the queue or NULL if not found
|
||||||
*/
|
*/
|
||||||
struct queue_item_info *
|
struct queue_item *
|
||||||
queue_get_byindex(struct queue *queue, unsigned int index, char shuffle)
|
queue_get_byindex(struct queue *queue, unsigned int index, char shuffle)
|
||||||
{
|
{
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
@ -328,7 +385,7 @@ queue_get_byindex(struct queue *queue, unsigned int index, char shuffle)
|
|||||||
if (!item)
|
if (!item)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return &item->qii;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -343,7 +400,7 @@ queue_get_byindex(struct queue *queue, unsigned int index, char shuffle)
|
|||||||
* @param shuffle If 0 the position in the play-queue, 1 the position in the shuffle-queue
|
* @param shuffle If 0 the position in the play-queue, 1 the position in the shuffle-queue
|
||||||
* @return Item at position in the queue or NULL if not found
|
* @return Item at position in the queue or NULL if not found
|
||||||
*/
|
*/
|
||||||
struct queue_item_info *
|
struct queue_item *
|
||||||
queue_get_bypos(struct queue *queue, unsigned int item_id, unsigned int pos, char shuffle)
|
queue_get_bypos(struct queue *queue, unsigned int item_id, unsigned int pos, char shuffle)
|
||||||
{
|
{
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
@ -353,7 +410,7 @@ queue_get_bypos(struct queue *queue, unsigned int item_id, unsigned int pos, cha
|
|||||||
if (!item)
|
if (!item)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return &item->qii;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -373,7 +430,7 @@ queue_index_byitemid(struct queue *queue, unsigned int item_id, char shuffle)
|
|||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for (item = item_next(queue->head, shuffle); item != queue->head && item->qii.item_id != item_id; item = item_next(item, shuffle))
|
for (item = item_next(queue->head, shuffle); item != queue->head && item->item_id != item_id; item = item_next(item, shuffle))
|
||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
@ -395,7 +452,7 @@ queue_index_byitemid(struct queue *queue, unsigned int item_id, char shuffle)
|
|||||||
* @param reshuffle If 1 and repeat mode is "repeat all" reshuffles the queue on wrap around
|
* @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 *
|
||||||
queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode, int reshuffle)
|
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;
|
||||||
@ -407,7 +464,7 @@ queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (r_mode == REPEAT_SONG && item != queue->head)
|
if (r_mode == REPEAT_SONG && item != queue->head)
|
||||||
return &item->qii;
|
return item;
|
||||||
|
|
||||||
item = item_next(item, shuffle);
|
item = item_next(item, shuffle);
|
||||||
|
|
||||||
@ -422,7 +479,7 @@ queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_
|
|||||||
if (item == queue->head)
|
if (item == queue->head)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return &item->qii;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -434,7 +491,7 @@ queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_
|
|||||||
* @param r_mode Repeat mode
|
* @param r_mode Repeat mode
|
||||||
* @return The previous item
|
* @return The previous item
|
||||||
*/
|
*/
|
||||||
struct queue_item_info *
|
struct queue_item *
|
||||||
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)
|
||||||
{
|
{
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
@ -446,7 +503,7 @@ queue_prev(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (r_mode == REPEAT_SONG && item != queue->head)
|
if (r_mode == REPEAT_SONG && item != queue->head)
|
||||||
return &item->qii;
|
return item;
|
||||||
|
|
||||||
item = item_prev(item, shuffle);
|
item = item_prev(item, shuffle);
|
||||||
|
|
||||||
@ -459,11 +516,11 @@ queue_prev(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_
|
|||||||
if (item == queue->head)
|
if (item == queue->head)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return &item->qii;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a new queue-info for the given queue.
|
* Creates a new queue with a copy of the items of the given queue.
|
||||||
*
|
*
|
||||||
* The given number of items (count) are copied from the play-queue (shuffle = 0) or shuffle-queue (shuffle = 1)
|
* The given number of items (count) are copied from the play-queue (shuffle = 0) or shuffle-queue (shuffle = 1)
|
||||||
* starting with the item at the given index (0-based).
|
* starting with the item at the given index (0-based).
|
||||||
@ -474,19 +531,20 @@ queue_prev(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_
|
|||||||
* @param index Index of the first item in the queue
|
* @param index Index of the first item in the queue
|
||||||
* @param count Maximum number of items to copy (if 0 all remaining items after index)
|
* @param count Maximum number of items to copy (if 0 all remaining items after index)
|
||||||
* @param shuffle If 0 the play-queue, if 1 the shuffle queue
|
* @param shuffle If 0 the play-queue, if 1 the shuffle queue
|
||||||
* @return A new queue-info with the specified items
|
* @return A new queue with the specified items
|
||||||
*/
|
*/
|
||||||
struct queue_info *
|
struct queue *
|
||||||
queue_info_new_byindex(struct queue *queue, unsigned int index, unsigned int count, char shuffle)
|
queue_new_byindex(struct queue *queue, unsigned int index, unsigned int count, char shuffle)
|
||||||
{
|
{
|
||||||
struct queue_info *qi;
|
struct queue *qi;
|
||||||
struct queue_item_info *qii;
|
struct queue_item *qii;
|
||||||
struct queue_item *item_base;
|
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
unsigned int i;
|
int i;
|
||||||
unsigned int qlength;
|
unsigned int qlength;
|
||||||
int qii_size;
|
int qii_size;
|
||||||
|
|
||||||
|
qi = queue_new();
|
||||||
|
|
||||||
qlength = queue_count(queue);
|
qlength = queue_count(queue);
|
||||||
|
|
||||||
qii_size = qlength - index;
|
qii_size = qlength - index;
|
||||||
@ -495,39 +553,37 @@ queue_info_new_byindex(struct queue *queue, unsigned int index, unsigned int cou
|
|||||||
|
|
||||||
if (qii_size <= 0)
|
if (qii_size <= 0)
|
||||||
{
|
{
|
||||||
return NULL;
|
return qi;
|
||||||
}
|
}
|
||||||
|
|
||||||
item_base = queueitem_get_byindex(queue, index, shuffle);
|
item = queueitem_get_byindex(queue, index, shuffle);
|
||||||
|
|
||||||
if (!item_base)
|
if (!item)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
qi = malloc(sizeof(struct queue_info));
|
|
||||||
qii = malloc(qii_size * sizeof(struct queue_item_info));
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (item = item_base; item != queue->head && i < qii_size; item = item_next(item, shuffle))
|
for (; item != queue->head && i < qii_size; item = item_next(item, shuffle))
|
||||||
{
|
{
|
||||||
qii[i].dbmfi_id = item->qii.dbmfi_id;
|
qii = malloc(sizeof(struct queue_item));
|
||||||
qii[i].item_id = item->qii.item_id;
|
qii->id = item->id;
|
||||||
qii[i].len_ms = item->qii.len_ms;
|
qii->item_id = item->item_id;
|
||||||
qii[i].data_kind = item->qii.data_kind;
|
qii->len_ms = item->len_ms;
|
||||||
qii[i].media_kind = item->qii.media_kind;
|
qii->data_kind = item->data_kind;
|
||||||
|
qii->media_kind = item->media_kind;
|
||||||
|
qii->next = qii;
|
||||||
|
qii->prev = qii;
|
||||||
|
qii->shuffle_next = qii;
|
||||||
|
qii->shuffle_prev = qii;
|
||||||
|
|
||||||
|
queue_add(qi, qii);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
qi->count = i;
|
|
||||||
qi->length = qlength;
|
|
||||||
qi->start_pos = index;
|
|
||||||
qi->queue = qii;
|
|
||||||
|
|
||||||
return qi;
|
return qi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a new queue-info for the given queue.
|
* Creates a new queue with a copy of the items of the given queue.
|
||||||
*
|
*
|
||||||
* The given number of items (count) are copied from the play-queue (shuffle = 0) or shuffle-queue (shuffle = 1)
|
* The given number of items (count) are copied from the play-queue (shuffle = 0) or shuffle-queue (shuffle = 1)
|
||||||
* starting after the item with the given item_id. The item with item_id is excluded, therefor the first item
|
* starting after the item with the given item_id. The item with item_id is excluded, therefor the first item
|
||||||
@ -539,13 +595,13 @@ queue_info_new_byindex(struct queue *queue, unsigned int index, unsigned int cou
|
|||||||
* @param item_id The unique id of the item in the queue
|
* @param item_id The unique id of the item in the queue
|
||||||
* @param count Maximum number of items to copy (if 0 all remaining items after index)
|
* @param count Maximum number of items to copy (if 0 all remaining items after index)
|
||||||
* @param shuffle If 0 the play-queue, if 1 the shuffle queue
|
* @param shuffle If 0 the play-queue, if 1 the shuffle queue
|
||||||
* @return A new queue-info with the specified items
|
* @return A new queue with the specified items
|
||||||
*/
|
*/
|
||||||
struct queue_info *
|
struct queue *
|
||||||
queue_info_new_bypos(struct queue *queue, unsigned int item_id, unsigned int count, char shuffle)
|
queue_new_bypos(struct queue *queue, unsigned int item_id, unsigned int count, char shuffle)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
struct queue_info *qi;
|
struct queue *qi;
|
||||||
|
|
||||||
pos = queue_index_byitemid(queue, item_id, shuffle);
|
pos = queue_index_byitemid(queue, item_id, shuffle);
|
||||||
|
|
||||||
@ -554,21 +610,11 @@ queue_info_new_bypos(struct queue *queue, unsigned int item_id, unsigned int cou
|
|||||||
else
|
else
|
||||||
pos = pos + 1; // exclude the item with the given item-id
|
pos = pos + 1; // exclude the item with the given item-id
|
||||||
|
|
||||||
qi = queue_info_new_byindex(queue, pos, count, shuffle);
|
qi = queue_new_byindex(queue, pos, count, shuffle);
|
||||||
|
|
||||||
return qi;
|
return qi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Frees the queue info
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
queue_info_free(struct queue_info *qi)
|
|
||||||
{
|
|
||||||
free(qi->queue);
|
|
||||||
free(qi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds items to the queue after the given item
|
* Adds items to the queue after the given item
|
||||||
*
|
*
|
||||||
@ -598,11 +644,11 @@ queue_add_afteritem(struct queue *queue, struct queue_item *item_new, struct que
|
|||||||
|
|
||||||
// Set item-id for all new items
|
// Set item-id for all new items
|
||||||
queue->last_inserted_item_id++;
|
queue->last_inserted_item_id++;
|
||||||
item_new->qii.item_id = queue->last_inserted_item_id;
|
item_new->item_id = queue->last_inserted_item_id;
|
||||||
for (item = item_new->next; item != item_new; item = item->next)
|
for (item = item_new->next; item != item_new; item = item->next)
|
||||||
{
|
{
|
||||||
queue->last_inserted_item_id++;
|
queue->last_inserted_item_id++;
|
||||||
item->qii.item_id = queue->last_inserted_item_id;
|
item->item_id = queue->last_inserted_item_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add items into the queue
|
// Add items into the queue
|
||||||
@ -872,7 +918,7 @@ queue_reset_and_find(struct queue *queue, unsigned int item_id)
|
|||||||
temp->shuffle_next = temp->next;
|
temp->shuffle_next = temp->next;
|
||||||
temp->shuffle_prev = temp->prev;
|
temp->shuffle_prev = temp->prev;
|
||||||
|
|
||||||
if (temp->qii.item_id == item_id)
|
if (temp->item_id == item_id)
|
||||||
item = temp;
|
item = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1006,16 +1052,16 @@ queue_item_new(struct db_media_file_info *dbmfi)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
item->qii.dbmfi_id = id;
|
item->id = id;
|
||||||
item->qii.len_ms = len_ms;
|
item->len_ms = len_ms;
|
||||||
item->qii.data_kind = data_kind;
|
item->data_kind = data_kind;
|
||||||
item->qii.media_kind = media_kind;
|
item->media_kind = media_kind;
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct queue_item *
|
struct queue_item *
|
||||||
queue_make(struct query_params *qp)
|
queueitem_make_byquery(struct query_params *qp)
|
||||||
{
|
{
|
||||||
struct db_media_file_info dbmfi;
|
struct db_media_file_info dbmfi;
|
||||||
struct queue_item *item_head;
|
struct queue_item *item_head;
|
||||||
@ -1082,7 +1128,7 @@ queue_make(struct query_params *qp)
|
|||||||
* @return List of items for all playlist items
|
* @return List of items for all playlist items
|
||||||
*/
|
*/
|
||||||
struct queue_item *
|
struct queue_item *
|
||||||
queue_make_pl(int plid)
|
queueitem_make_byplid(int plid)
|
||||||
{
|
{
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
@ -1096,19 +1142,19 @@ queue_make_pl(int plid)
|
|||||||
qp.sort = S_NONE;
|
qp.sort = S_NONE;
|
||||||
qp.idx_type = I_NONE;
|
qp.idx_type = I_NONE;
|
||||||
|
|
||||||
item = queue_make(&qp);
|
item = queueitem_make_byquery(&qp);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Makes a queue-item for the item/file with the given id (dbmfi_id)
|
* Makes a queue-item for the item/file with the given id
|
||||||
*
|
*
|
||||||
* @param dbmfi_id Id of the item/file
|
* @param id Id of the item/file in the db
|
||||||
* @return List of items containing only the item with the given id
|
* @return List of items containing only the item with the given id
|
||||||
*/
|
*/
|
||||||
struct queue_item *
|
struct queue_item *
|
||||||
queue_make_item(uint32_t dbmfi_id)
|
queueitem_make_byid(uint32_t id)
|
||||||
{
|
{
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct queue_item *item;
|
struct queue_item *item;
|
||||||
@ -1121,10 +1167,10 @@ queue_make_item(uint32_t dbmfi_id)
|
|||||||
qp.offset = 0;
|
qp.offset = 0;
|
||||||
qp.limit = 0;
|
qp.limit = 0;
|
||||||
qp.sort = S_NONE;
|
qp.sort = S_NONE;
|
||||||
snprintf(buf, sizeof(buf), "f.id = %" PRIu32, dbmfi_id);
|
snprintf(buf, sizeof(buf), "f.id = %" PRIu32, id);
|
||||||
qp.filter = buf;
|
qp.filter = buf;
|
||||||
|
|
||||||
item = queue_make(&qp);
|
item = queueitem_make_byquery(&qp);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
80
src/queue.h
80
src/queue.h
@ -22,42 +22,6 @@ struct queue;
|
|||||||
*/
|
*/
|
||||||
struct queue_item;
|
struct queue_item;
|
||||||
|
|
||||||
/*
|
|
||||||
* External representation of an item in a queue
|
|
||||||
*/
|
|
||||||
struct queue_item_info
|
|
||||||
{
|
|
||||||
/* Item-Id is a unique id for this queue item. If the same item appears multiple
|
|
||||||
times in the queue each corresponding queue item has its own id. */
|
|
||||||
unsigned int item_id;
|
|
||||||
|
|
||||||
/* Id of the file/item in the files database */
|
|
||||||
unsigned int dbmfi_id;
|
|
||||||
|
|
||||||
/* Length of the item in ms */
|
|
||||||
unsigned int len_ms;
|
|
||||||
|
|
||||||
/* Data type of the item */
|
|
||||||
enum data_kind data_kind;
|
|
||||||
/* Media type of the item */
|
|
||||||
enum media_kind media_kind;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* External representation of a queue
|
|
||||||
*/
|
|
||||||
struct queue_info
|
|
||||||
{
|
|
||||||
// The number of items in the queue
|
|
||||||
unsigned int length;
|
|
||||||
|
|
||||||
// The position (0-based) in the queue for the first item in the queue array
|
|
||||||
unsigned int start_pos;
|
|
||||||
// The number of items in the queue array
|
|
||||||
unsigned int count;
|
|
||||||
// The queue array (array of items infos)
|
|
||||||
struct queue_item_info *queue;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct queue *
|
struct queue *
|
||||||
queue_new();
|
queue_new();
|
||||||
@ -69,34 +33,46 @@ unsigned int
|
|||||||
queue_count(struct queue *queue);
|
queue_count(struct queue *queue);
|
||||||
|
|
||||||
int
|
int
|
||||||
queueitem_pos(struct queue_item *item, uint32_t dbmfi_id);
|
queueitem_pos(struct queue_item *item, uint32_t id);
|
||||||
|
|
||||||
struct queue_item_info *
|
uint32_t
|
||||||
|
queueitem_id(struct queue_item *item);
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
queueitem_item_id(struct queue_item *item);
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
queueitem_len(struct queue_item *item);
|
||||||
|
|
||||||
|
enum data_kind
|
||||||
|
queueitem_data_kind(struct queue_item *item);
|
||||||
|
|
||||||
|
enum media_kind
|
||||||
|
queueitem_media_kind(struct queue_item *item);
|
||||||
|
|
||||||
|
struct queue_item *
|
||||||
queue_get_byitemid(struct queue *queue, unsigned int item_id);
|
queue_get_byitemid(struct queue *queue, unsigned int item_id);
|
||||||
|
|
||||||
struct queue_item_info *
|
struct queue_item *
|
||||||
queue_get_byindex(struct queue *queue, unsigned int index, char shuffle);
|
queue_get_byindex(struct queue *queue, unsigned int index, char shuffle);
|
||||||
|
|
||||||
struct queue_item_info *
|
struct queue_item *
|
||||||
queue_get_bypos(struct queue *queue, unsigned int item_id, unsigned int pos, char shuffle);
|
queue_get_bypos(struct queue *queue, unsigned int item_id, unsigned int pos, char shuffle);
|
||||||
|
|
||||||
int
|
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 *
|
||||||
queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode, int reshuffle);
|
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 *
|
||||||
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);
|
||||||
|
|
||||||
struct queue_info *
|
struct queue *
|
||||||
queue_info_new_byindex(struct queue *queue, unsigned int index, unsigned int count, char shuffle);
|
queue_new_byindex(struct queue *queue, unsigned int index, unsigned int count, char shuffle);
|
||||||
|
|
||||||
struct queue_info *
|
struct queue *
|
||||||
queue_info_new_bypos(struct queue *queue, unsigned int item_id, unsigned int count, char shuffle);
|
queue_new_bypos(struct queue *queue, unsigned int item_id, unsigned int count, char shuffle);
|
||||||
|
|
||||||
void
|
|
||||||
queue_info_free(struct queue_info *qi);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
queue_add(struct queue *queue, struct queue_item *item);
|
queue_add(struct queue *queue, struct queue_item *item);
|
||||||
@ -123,12 +99,12 @@ void
|
|||||||
queue_shuffle(struct queue *queue, unsigned int item_id);
|
queue_shuffle(struct queue *queue, unsigned int item_id);
|
||||||
|
|
||||||
struct queue_item *
|
struct queue_item *
|
||||||
queue_make(struct query_params *qp);
|
queueitem_make_byquery(struct query_params *qp);
|
||||||
|
|
||||||
struct queue_item *
|
struct queue_item *
|
||||||
queue_make_pl(int plid);
|
queueitem_make_byplid(int plid);
|
||||||
|
|
||||||
struct queue_item *
|
struct queue_item *
|
||||||
queue_make_item(uint32_t dbmfi_id);
|
queueitem_make_byid(uint32_t id);
|
||||||
|
|
||||||
#endif /* SRC_QUEUE_H_ */
|
#endif /* SRC_QUEUE_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user