[raop/dmap] Build raop metadata from queue item

This commit is contained in:
chme 2016-12-03 20:40:54 +01:00
parent 6c6f02fdfa
commit fdd85ccf66
4 changed files with 98 additions and 55 deletions

View File

@ -559,3 +559,78 @@ dmap_encode_file_metadata(struct evbuffer *songlist, struct evbuffer *song, stru
return 0;
}
int
dmap_encode_queue_metadata(struct evbuffer *songlist, struct evbuffer *song, struct db_queue_item *queue_item)
{
int32_t val;
int want_mikd;
int want_asdk;
int want_ased;
int ret;
dmap_add_int(song, "miid", queue_item->file_id);
dmap_add_string(song, "minm", queue_item->title);
dmap_add_long(song, "mper", queue_item->file_id);
dmap_add_int(song, "mcti", queue_item->file_id);
dmap_add_string(song, "asal", queue_item->album);
dmap_add_long(song, "asai", queue_item->songalbumid);
dmap_add_string(song, "asaa", queue_item->album_artist);
dmap_add_string(song, "asar", queue_item->artist);
dmap_add_int(song, "asdm", queue_item->time_modified);
dmap_add_short(song, "asdn", queue_item->disc);
dmap_add_string(song, "asgn", queue_item->genre);
dmap_add_int(song, "astm", queue_item->song_length);
dmap_add_short(song, "astn", queue_item->track);
dmap_add_short(song, "asyr", queue_item->year);
dmap_add_int(song, "aeMK", queue_item->media_kind);
dmap_add_char(song, "aeMk", queue_item->media_kind);
dmap_add_string(song, "asfm", "wav");
dmap_add_short(song, "asbr", 1411);
dmap_add_string(song, "asdt", "wav audio file");
want_mikd = 1;/* Will be prepended to the list *//* item kind */
want_asdk = 1;/* Will be prepended to the list *//* data kind */
want_ased = 1;/* Extradata not in media_file_info but flag for reply */
/* Required for artwork in iTunes, set songartworkcount (asac) = 1 */
if (want_ased)
{
dmap_add_short(song, "ased", 1);
dmap_add_short(song, "asac", 1);
}
val = 0;
if (want_mikd)
val += 9;
if (want_asdk)
val += 9;
dmap_add_container(songlist, "mlit", evbuffer_get_length(song) + val);
/* Prepend mikd & asdk if needed */
if (want_mikd)
{
/* dmap.itemkind must come first */
val = 2; /* music by default */
dmap_add_char(songlist, "mikd", val);
}
if (want_asdk)
{
ret = queue_item->data_kind;
if (ret < 0)
val = 0;
dmap_add_char(songlist, "asdk", val);
}
ret = evbuffer_add_buffer(songlist, song);
if (ret < 0)
{
DPRINTF(E_LOG, L_DAAP, "Could not add song to song list\n");
return -1;
}
return 0;
}

View File

@ -84,4 +84,7 @@ dmap_send_error(struct evhttp_request *req, const char *container, const char *e
int
dmap_encode_file_metadata(struct evbuffer *songlist, struct evbuffer *song, struct db_media_file_info *dbmfi, const struct dmap_field **meta, int nmeta, int sort_tags, int force_wav);
int
dmap_encode_queue_metadata(struct evbuffer *songlist, struct evbuffer *song, struct db_queue_item *queue_item);
#endif /* !__DMAP_HELPERS_H__ */

View File

@ -821,12 +821,9 @@ raop_metadata_prune(uint64_t rtptime)
static void *
raop_metadata_prepare(int id)
{
struct query_params qp;
struct db_media_file_info dbmfi;
char filter[32];
struct db_queue_item *queue_item;
struct raop_metadata *rmd;
struct evbuffer *tmp;
uint64_t duration;
int ret;
rmd = (struct raop_metadata *)malloc(sizeof(struct raop_metadata));
@ -839,6 +836,14 @@ raop_metadata_prepare(int id)
memset(rmd, 0, sizeof(struct raop_metadata));
queue_item = db_queue_fetch_byitemid(id);
if (!queue_item)
{
DPRINTF(E_LOG, L_RAOP, "Out of memory for queue item\n");
goto out_rmd;
}
/* Get artwork */
rmd->artwork = evbuffer_new();
if (!rmd->artwork)
@ -848,7 +853,7 @@ raop_metadata_prepare(int id)
goto skip_artwork;
}
ret = artwork_get_item(rmd->artwork, id, 600, 600);
ret = artwork_get_item(rmd->artwork, queue_item->file_id, 600, 600);
if (ret < 0)
{
DPRINTF(E_INFO, L_RAOP, "Failed to retrieve artwork for file id %d; no artwork will be sent\n", id);
@ -861,44 +866,13 @@ raop_metadata_prepare(int id)
skip_artwork:
/* Get dbmfi */
memset(&qp, 0, sizeof(struct query_params));
qp.type = Q_ITEMS;
qp.idx_type = I_NONE;
qp.sort = S_NONE;
qp.filter = filter;
ret = snprintf(filter, sizeof(filter), "id = %d", id);
if ((ret < 0) || (ret >= sizeof(filter)))
{
DPRINTF(E_LOG, L_RAOP, "Could not build filter for file id %d; metadata will not be sent\n", id);
goto out_rmd;
}
ret = db_query_start(&qp);
if (ret < 0)
{
DPRINTF(E_LOG, L_RAOP, "Couldn't start query; no metadata will be sent\n");
goto out_rmd;
}
ret = db_query_fetch_file(&qp, &dbmfi);
if (ret < 0)
{
DPRINTF(E_LOG, L_RAOP, "Couldn't fetch file id %d; metadata will not be sent\n", id);
goto out_query;
}
/* Turn it into DAAP metadata */
tmp = evbuffer_new();
if (!tmp)
{
DPRINTF(E_LOG, L_RAOP, "Out of memory for temporary metadata evbuffer; metadata will not be sent\n");
goto out_query;
goto out_qi;
}
rmd->metadata = evbuffer_new();
@ -907,10 +881,10 @@ raop_metadata_prepare(int id)
DPRINTF(E_LOG, L_RAOP, "Out of memory for metadata evbuffer; metadata will not be sent\n");
evbuffer_free(tmp);
goto out_query;
goto out_qi;
}
ret = dmap_encode_file_metadata(rmd->metadata, tmp, &dbmfi, NULL, 0, 0, 1);
ret = dmap_encode_queue_metadata(rmd->metadata, tmp, queue_item);
evbuffer_free(tmp);
if (ret < 0)
{
@ -919,27 +893,18 @@ raop_metadata_prepare(int id)
goto out_metadata;
}
/* Progress */
ret = safe_atou64(dbmfi.song_length, &duration);
if (ret < 0)
{
DPRINTF(E_LOG, L_RAOP, "Failed to convert song_length to integer; no metadata will be sent\n");
goto out_metadata;
}
db_query_end(&qp);
/* raop_metadata_send() will add rtptime to these */
/* Progress - raop_metadata_send() will add rtptime to these */
rmd->start = 0;
rmd->end = (duration * 44100UL) / 1000UL;
rmd->end = (queue_item->song_length * 44100UL) / 1000UL;
free_queue_item(queue_item, 0);
return rmd;
out_metadata:
evbuffer_free(rmd->metadata);
out_query:
db_query_end(&qp);
out_qi:
free_queue_item(queue_item, 0);
out_rmd:
free(rmd);

View File

@ -502,7 +502,7 @@ metadata_trigger(int startup)
memset(&pmd, 0, sizeof(struct player_metadata));
pmd.id = cur_streaming->id;
pmd.id = cur_streaming->item_id;
pmd.startup = startup;
if (cur_streaming->stream_start && cur_streaming->output_start)