Add preliminary support for metadata.

This commit is contained in:
Mke Brady
2015-02-18 21:51:08 +00:00
parent 8947eefaef
commit 8bbc8d0f24
2 changed files with 48 additions and 28 deletions
+31 -9
View File
@@ -30,11 +30,20 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <openssl/md5.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "config.h"
#ifdef HAVE_LIBSSL
#include <openssl/md5.h>
#endif
#ifdef HAVE_LIBPOLARSSL
#include <polarssl/md5.h>
#endif
#include "common.h"
#include "metadata.h"
@@ -78,11 +87,12 @@ static void metadata_close(void) {
}
static void print_one(const char *name, const char *value) {
write(fd, name, strlen(name));
write(fd, "=", 1);
int ignore;
ignore = write(fd, name, strlen(name));
ignore = write(fd, "=", 1);
if (value)
write(fd, value, strlen(value));
write(fd, "\n", 1);
ignore = write(fd, value, strlen(value));
ignore = write(fd, "\n", 1);
}
#define write_one(name) \
@@ -119,17 +129,29 @@ void metadata_cover_image(const char *buf, int len, const char *ext) {
return;
if (buf) {
debug(1, "Cover Art set\n");
debug(2, "Cover Art set\n");
} else {
debug(1, "Cover Art cleared\n");
debug(2, "Cover Art cleared\n");
return;
}
uint8_t img_md5[16];
#ifdef HAVE_LIBSSL
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, buf, len);
MD5_Final(img_md5, &ctx);
#endif
#ifdef HAVE_LIBPOLARSSL
md5_context tctx;
md5_starts(&tctx);
md5_update(&tctx, buf, len);
md5_finish(&tctx, img_md5);
#endif
char img_md5_str[33];
int i;
@@ -144,7 +166,7 @@ void metadata_cover_image(const char *buf, int len, const char *ext) {
char *path = malloc(pl+1);
snprintf(path, pl+1, "%s/%s%s.%s", dir, prefix, img_md5_str, ext);
int cover_fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
int cover_fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP| S_IROTH | S_IWOTH);
if (cover_fd < 0) {
warn("Could not open file %s for writing cover art", path);
@@ -158,7 +180,7 @@ void metadata_cover_image(const char *buf, int len, const char *ext) {
}
close(cover_fd);
debug(1, "Cover Art file is %s\n", path);
debug(2, "Cover Art file is \"%s\".\n", path);
metadata_set(&player_meta.artwork, path+strlen(dir)+1);
free(path);
+17 -19
View File
@@ -569,13 +569,13 @@ static void handle_set_parameter_parameter(rtsp_conn_info *conn,
if (!strncmp(cp, "volume: ", 8)) {
float volume = atof(cp + 8);
debug(1, "volume: %f\n", volume);
debug(2, "volume: %f\n", volume);
player_volume(volume);
} else if(!strncmp(cp, "progress: ", 10)) {
char *progress = cp + 10;
debug(1, "progress: %s\n", progress);
debug(1, "progress: \"%s\"\n", progress);
} else {
debug(1, "unrecognised parameter: >>%s<< (%d)\n", cp, strlen(cp));
debug(1, "unrecognised parameter: \"%s\" (%d)\n", cp, strlen(cp));
}
cp = next;
}
@@ -606,19 +606,19 @@ static void handle_set_parameter_metadata(rtsp_conn_info *conn,
debug(2, "Tag: %s Content: %s\n", tag, val);
if (!strncmp(tag, "asal ", 4)) {
debug(1, "META Album: %s\n", val);
debug(2, "META Album: \"%s\".\n", val);
metadata_set(&player_meta.album, val);
} else if (!strncmp(tag, "asar ", 4)) {
debug(1, "META Artist: %s\n", val);
debug(2, "META Artist: \"%s\".\n", val);
metadata_set(&player_meta.artist, val);
} else if (!strncmp(tag, "ascm ", 4)) {
debug(1, "META Comment: %s\n", val);
debug(2, "META Comment: \"%s\".\n", val);
metadata_set(&player_meta.comment, val);
} else if (!strncmp(tag, "asgn ", 4)) {
debug(1, "META Genre: %s\n", val);
debug(2, "META Genre: \"%s\".\n", val);
metadata_set(&player_meta.genre, val);
} else if (!strncmp(tag, "minm ", 4)) {
debug(1, "META Title: %s\n", val);
debug(2, "META Title: \"%s\".\n", val);
metadata_set(&player_meta.title, val);
}
@@ -640,36 +640,34 @@ static void handle_set_parameter_coverart(rtsp_conn_info *conn,
} else if (!strncmp(ct, "image/png", 9)) {
metadata_cover_image(cp, cl, "png");
} else {
debug(1, "unrecognised image type received: \"%s\".\n",ct);
metadata_cover_image(NULL, 0, NULL);
}
}
static void handle_set_parameter(rtsp_conn_info *conn,
rtsp_message *req, rtsp_message *resp) {
if (!req->contentlength)
debug(1, "received empty SET_PARAMETER request\n");
if (!req->contentlength)
debug(1, "received empty SET_PARAMETER request\n");
char *ct = msg_get_header(req, "Content-Type");
if (ct) {
debug(2, "SET_PARAMETER Content-Type: %s\n", ct);
debug(2, "SET_PARAMETER Content-Type:\"%s\".\n", ct);
if (!strncmp(ct, "application/x-dmap-tagged", 25)) {
debug(1, "received metadata tags in SET_PARAMETER request\n");
debug(2, "received metadata tags in SET_PARAMETER request\n");
handle_set_parameter_metadata(conn, req, resp);
} else if (!strncmp(ct, "image/jpeg", 10) ||
!strncmp(ct, "image/png", 9) ||
!strncmp(ct, "image/none", 10)) {
debug(1, "received image in SET_PARAMETER request\n");
} else if (!strncmp(ct, "image", 5)) {
debug(2, "received image in SET_PARAMETER request\n");
handle_set_parameter_coverart(conn, req, resp);
} else if (!strncmp(ct, "text/parameters", 15)) {
debug(1, "received parameters in SET_PARAMETER request\n");
debug(2, "received parameters in SET_PARAMETER request\n");
handle_set_parameter_parameter(conn, req, resp);
} else {
debug(1, "received unknown Content-Type %s in SET_PARAMETER request\n", ct);
debug(1, "received unknown Content-Type \"%s\" in SET_PARAMETER request\n", ct);
}
} else {
debug(1, "missing Content-Type header in SET_PARAMETER request\n");