From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 7 Dec 2020 14:04:22 +0000 (+0000) Subject: Restore compatibility with AirPower on Android. X-Git-Tag: 3.3.8~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8f348d459e326997498c8895ae8d24dda620ddd;p=thirdparty%2Fshairport-sync.git Restore compatibility with AirPower on Android. --- diff --git a/dacp.c b/dacp.c index acb963b9..effbe5ec 100644 --- a/dacp.c +++ b/dacp.c @@ -445,9 +445,13 @@ void set_dacp_server_information(rtsp_conn_info *conn) { } if (dacp_server.active_remote_id) free(dacp_server.active_remote_id); - dacp_server.active_remote_id = - strdup(conn->dacp_active_remote); // even if the dacp_id remains the same, - // the active remote will change. + if (conn->dacp_active_remote) + dacp_server.active_remote_id = + strdup(conn->dacp_active_remote); // even if the dacp_id remains the same, + // the active remote will change. + else + dacp_server.active_remote_id = NULL; + debug(3, "set_dacp_server_information set active-remote id to %s.", dacp_server.active_remote_id); pthread_cond_signal(&dacp_server_information_cv); debug_mutex_unlock(&dacp_server_information_lock, 3); diff --git a/rtsp.c b/rtsp.c index 184b411e..f3524ae2 100644 --- a/rtsp.c +++ b/rtsp.c @@ -1652,41 +1652,41 @@ void *metadata_mqtt_thread_function(__attribute__((unused)) void *ignore) { #endif void metadata_init(void) { - - // create the metadata pipe, if necessary - size_t pl = strlen(config.metadata_pipename) + 1; - char *path = malloc(pl + 1); - snprintf(path, pl + 1, "%s", config.metadata_pipename); - - mode_t oldumask = umask(000); - if (mkfifo(path, 0666) && errno != EEXIST) - die("Could not create metadata pipe \"%s\".", path); - umask(oldumask); - debug(1, "metadata pipe name is \"%s\".", path); - - // try to open it - fd = try_to_open_pipe_for_writing(path); - // we check that it's not a "real" error. From the "man 2 open" page: - // "ENXIO O_NONBLOCK | O_WRONLY is set, the named file is a FIFO, and no process has the FIFO - // open for reading." Which is okay. - if ((fd == -1) && (errno != ENXIO)) { - char errorstring[1024]; - strerror_r(errno, (char *)errorstring, sizeof(errorstring)); - debug(1, "metadata_hub_thread_function -- error %d (\"%s\") opening pipe: \"%s\".", errno, - (char *)errorstring, path); - warn("can not open metadata pipe -- error %d (\"%s\") opening pipe: \"%s\".", errno, - (char *)errorstring, path); + int ret; + if (config.metadata_enabled) { + // create the metadata pipe, if necessary + size_t pl = strlen(config.metadata_pipename) + 1; + char *path = malloc(pl + 1); + snprintf(path, pl + 1, "%s", config.metadata_pipename); + mode_t oldumask = umask(000); + if (mkfifo(path, 0666) && errno != EEXIST) + die("Could not create metadata pipe \"%s\".", path); + umask(oldumask); + debug(1, "metadata pipe name is \"%s\".", path); + + // try to open it + fd = try_to_open_pipe_for_writing(path); + // we check that it's not a "real" error. From the "man 2 open" page: + // "ENXIO O_NONBLOCK | O_WRONLY is set, the named file is a FIFO, and no process has the FIFO + // open for reading." Which is okay. + if ((fd == -1) && (errno != ENXIO)) { + char errorstring[1024]; + strerror_r(errno, (char *)errorstring, sizeof(errorstring)); + debug(1, "metadata_hub_thread_function -- error %d (\"%s\") opening pipe: \"%s\".", errno, + (char *)errorstring, path); + warn("can not open metadata pipe -- error %d (\"%s\") opening pipe: \"%s\".", errno, + (char *)errorstring, path); + } + free(path); + int ret; + ret = pthread_create(&metadata_thread, NULL, metadata_thread_function, NULL); + if (ret) + debug(1, "Failed to create metadata thread!"); + + ret = pthread_create(&metadata_multicast_thread, NULL, metadata_multicast_thread_function, NULL); + if (ret) + debug(1, "Failed to create metadata multicast thread!"); } - free(path); - - int ret = pthread_create(&metadata_thread, NULL, metadata_thread_function, NULL); - if (ret) - debug(1, "Failed to create metadata thread!"); - - ret = pthread_create(&metadata_multicast_thread, NULL, metadata_multicast_thread_function, NULL); - if (ret) - debug(1, "Failed to create metadata multicast thread!"); - #ifdef CONFIG_METADATA_HUB ret = pthread_create(&metadata_hub_thread, NULL, metadata_hub_thread_function, NULL); if (ret) @@ -1715,15 +1715,20 @@ void metadata_stop(void) { pthread_join(metadata_hub_thread, NULL); // debug(2, "metadata stop hub done."); #endif - // debug(2, "metadata stop multicast thread."); - pthread_cancel(metadata_multicast_thread); - pthread_join(metadata_multicast_thread, NULL); - // debug(2, "metadata stop multicast done."); - - // debug(2, "metadata stop metadata_thread thread."); - pthread_cancel(metadata_thread); - pthread_join(metadata_thread, NULL); - // debug(2, "metadata_stop finished successfully."); + if (config.metadata_enabled) { + // debug(2, "metadata stop multicast thread."); + if (metadata_multicast_thread) { + pthread_cancel(metadata_multicast_thread); + pthread_join(metadata_multicast_thread, NULL); + // debug(2, "metadata stop multicast done."); + } + if (metadata_thread) { + // debug(2, "metadata stop metadata_thread thread."); + pthread_cancel(metadata_thread); + pthread_join(metadata_thread, NULL); + // debug(2, "metadata_stop finished successfully."); + } + } } } @@ -1793,8 +1798,10 @@ int send_metadata_to_queue(pc_queue *queue, uint32_t type, uint32_t code, char * int send_metadata(uint32_t type, uint32_t code, char *data, uint32_t length, rtsp_message *carrier, int block) { int rc; - if (config.metadata_enabled) + if (config.metadata_enabled) { rc = send_metadata_to_queue(&metadata_queue, type, code, data, length, carrier, block); + rc = send_metadata_to_queue(&metadata_multicast_queue, type, code, data, length, carrier, block); + } #ifdef CONFIG_METADATA_HUB rc = send_metadata_to_queue(&metadata_hub_queue, type, code, data, length, carrier, block); diff --git a/shairport.c b/shairport.c index 9cedc72d..db2c7531 100644 --- a/shairport.c +++ b/shairport.c @@ -1362,7 +1362,6 @@ void exit_function() { #endif #ifdef CONFIG_METADATA - if (config.metadata_enabled) metadata_stop(); // close down the metadata pipe #endif @@ -1953,8 +1952,7 @@ int main(int argc, char **argv) { #endif memcpy(config.hw_addr, ap_md5, sizeof(config.hw_addr)); #ifdef CONFIG_METADATA - if (config.metadata_enabled) - metadata_init(); // create the metadata pipe if necessary + metadata_init(); // create the metadata pipe if necessary #endif #ifdef CONFIG_METADATA_HUB