Bracket metadata reception with prologs and epilogs, make metadat pipe and art directory writable by group and world

This commit is contained in:
Mike Brady
2018-01-23 11:13:19 +00:00
parent 86b72a981a
commit 564ff638e6
4 changed files with 59 additions and 22 deletions
+39 -4
View File
@@ -151,8 +151,9 @@ char *metadata_write_image_file(const char *buf, int len) {
debug(1, "Unidentified image type of cover art -- jpg extension used.");
ext = jpg;
}
int result = mkpath(config.cover_art_cache_dir, 0700);
mode_t oldumask = umask(000);
int result = mkpath(config.cover_art_cache_dir, 0777);
umask(oldumask);
if ((result == 0) || (result == -EEXIST)) {
// see if the file exists by opening it.
// if it exists, we're done
@@ -224,6 +225,10 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
// metadata coming in from the audio source or from Shairport Sync itself passes through here
// this has more information about tags, which might be relevant:
// https://code.google.com/p/ytrack/wiki/DMAP
// all the following items of metadata are contained in one metadata packet
// they are preseded by an 'ssnc' 'mdst' item and followed by an 'ssnc 'mden' item.
if (type == 'core') {
switch (code) {
case 'asal':
@@ -251,7 +256,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
case 'ascm':
if ((metadata_store.comment == NULL) ||
(strncmp(metadata_store.comment, data, length) != 0)) {
if (metadata_store.comment)
if (metadata_store.comment)
free(metadata_store.comment);
metadata_store.comment = strndup(data, length);
// debug(1, "MH Comment set to: \"%s\"", metadata_store.comment);
@@ -347,23 +352,53 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
}
} else if (type == 'ssnc') {
switch (code) {
// ignore the following
case 'pcst':
case 'pcen':
break;
case 'mdst':
debug(1, "MH Metadata stream processing start.");
metadata_hub_modify_prolog();
break;
case 'mden':
metadata_hub_modify_epilog();
debug(1, "MH Metadata stream processing end.");
break;
case 'PICT':
debug(1, "MH Picture received, length %u bytes.", length);
if (length > 16) {
metadata_hub_modify_prolog();
if (metadata_store.cover_art_pathname)
free(metadata_store.cover_art_pathname);
metadata_store.cover_art_pathname = metadata_write_image_file(data, length);
metadata_hub_modify_epilog();
}
break;
case 'clip':
if ((metadata_store.client_ip == NULL) ||
(strncmp(metadata_store.client_ip, data, length) != 0)) {
metadata_hub_modify_prolog();
if (metadata_store.client_ip)
free(metadata_store.client_ip);
metadata_store.client_ip = strndup(data, length);
// debug(1, "MH Client IP set to: \"%s\"", metadata_store.client_ip);
debug(1, "MH Client IP set to: \"%s\"", metadata_store.client_ip);
metadata_store.client_ip_changed = 1;
metadata_store.changed = 1;
metadata_hub_modify_epilog();
}
break;
case 'svip':
if ((metadata_store.server_ip == NULL) ||
(strncmp(metadata_store.server_ip, data, length) != 0)) {
metadata_hub_modify_prolog();
if (metadata_store.server_ip)
free(metadata_store.server_ip);
metadata_store.server_ip = strndup(data, length);
debug(1, "MH Server IP set to: \"%s\"", metadata_store.server_ip);
metadata_hub_modify_epilog();
}
break;
default: {
+3 -1
View File
@@ -63,9 +63,11 @@ typedef struct metadata_bundle {
char *sort_as; // a malloced string -- if non-zero, free it before replacing it
int sort_as_changed;
char *client_ip; // a malloced string -- if non-zero, free it before replacing it
char *client_ip; // IP number used by the audio source (i.e. the "client")
int client_ip_changed;
char *server_ip; // IP number used by Shairport Sync
uint32_t item_id; // seems to be a track ID -- see itemid in DACP.c
int item_id_changed;
+12 -16
View File
@@ -816,10 +816,9 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
// say we have started playing here
#ifdef HAVE_METADATA_HUB
if (metadata_store.player_state != PS_PLAYING) {
metadata_store.player_state = PS_PLAYING;
run_metadata_watchers();
}
metadata_hub_modify_prolog();
metadata_store.player_state = PS_PLAYING;
metadata_hub_modify_epilog();
#endif
if (reference_timestamp) { // if we have a reference time
// debug(1,"First frame seen with timestamp...");
@@ -2498,10 +2497,9 @@ void player_flush(int64_t timestamp, rtsp_conn_info *conn) {
#endif
#ifdef HAVE_METADATA_HUB
if (metadata_store.player_state != PS_PAUSED) {
metadata_store.player_state = PS_PAUSED;
run_metadata_watchers();
}
metadata_hub_modify_prolog();
metadata_store.player_state = PS_PAUSED;
metadata_hub_modify_epilog();
#endif
}
@@ -2529,10 +2527,9 @@ int player_play(rtsp_conn_info *conn) {
pthread_create(pt, &tattr, player_thread_func, (void *)conn);
pthread_attr_destroy(&tattr);
#ifdef HAVE_METADATA_HUB
if (metadata_store.player_state != PS_PLAYING) {
metadata_store.player_state = PS_PLAYING;
run_metadata_watchers();
}
metadata_hub_modify_prolog();
metadata_store.player_state = PS_PLAYING;
metadata_hub_modify_epilog();
#endif
return 0;
}
@@ -2550,10 +2547,9 @@ void player_stop(rtsp_conn_info *conn) {
free(conn->player_thread);
conn->player_thread = NULL;
#ifdef HAVE_METADATA_HUB
if (metadata_store.player_state != PS_STOPPED) {
metadata_store.player_state = PS_STOPPED;
run_metadata_watchers();
}
metadata_hub_modify_prolog();
metadata_store.player_state = PS_STOPPED;
metadata_hub_modify_epilog();
#endif
} else {
debug(3, "player thread of RTSP conversation %d is already deleted.", conn->connection_number);
+5 -1
View File
@@ -1047,10 +1047,14 @@ void metadata_create(void) {
char *path = malloc(pl + 1);
snprintf(path, pl + 1, "%s", config.metadata_pipename);
if (mkfifo(path, 0644) && errno != EEXIST)
mode_t oldumask = umask(000);
if (mkfifo(path, 0666) && errno != EEXIST)
die("Could not create metadata FIFO %s", path);
free(path);
umask(oldumask);
}
void metadata_open(void) {