From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sun, 27 Feb 2022 02:00:03 +0000 (+1100) Subject: Require NQPTP to be running and create the SHM interface at startup. X-Git-Tag: 4.1-rc1~24^2~277 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=322f07720afe0fa104561bc16629fa9a3e38d689;p=thirdparty%2Fshairport-sync.git Require NQPTP to be running and create the SHM interface at startup. --- diff --git a/ptp-utilities.c b/ptp-utilities.c index 73fe70c1..8b05101e 100644 --- a/ptp-utilities.c +++ b/ptp-utilities.c @@ -46,7 +46,7 @@ #include "ptp-utilities.h" int shm_fd; -void *mapped_addr = NULL; +void *mapped_addr; static pthread_mutex_t ptp_access_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -115,9 +115,13 @@ int ptp_get_clock_info(uint64_t *actual_clock_id, uint64_t *time_of_sample, uint return response; } +void ptp_shm_interface_init() { + mapped_addr = NULL; +} + int ptp_shm_interface_open() { int response = 0; - if (mapped_addr == NULL) { + if ((mapped_addr == NULL) || (mapped_addr == MAP_FAILED)) { response = -1; debug(1, "ptp_shm_interface_open"); if (strcmp(config.nqptp_shared_memory_interface_name, "") != 0) { @@ -138,12 +142,15 @@ int ptp_shm_interface_open() { } } else { response = -1; + } + if (response == 0) + debug(1, "ptp_shm_interface_open successful"); + else + debug(1, "ptp_shm_interface_open failed"); } else { debug(1, "No config.nqptp_shared_memory_interface_name"); } - if (response != 0) - mapped_addr = NULL; // in case we try again later... } else { debug(1, "ptp_shm_interface_open -- already open!"); } diff --git a/ptp-utilities.h b/ptp-utilities.h index f18169d9..86d2b499 100644 --- a/ptp-utilities.h +++ b/ptp-utilities.h @@ -34,6 +34,7 @@ int ptp_get_clock_info(uint64_t *actual_clock_id, uint64_t *time_of_sample, uint void ptp_send_control_message_string(const char *msg); +void ptp_shm_interface_init(); int ptp_shm_interface_open(); int ptp_shm_interface_close(); diff --git a/rtsp.c b/rtsp.c index d277b7c0..29d1e4e0 100644 --- a/rtsp.c +++ b/rtsp.c @@ -2686,8 +2686,7 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) // if it's a full service PTP stream, we get groupUUID, groupContainsGroupLeader and // timingPeerList if (conn->airplay_stream_category == ptp_stream) { - ptp_shm_interface_open(); // it should be open already, but just in case it isn't... - ptp_send_control_message_string("T"); // remove all previous history + ptp_send_control_message_string("T"); // incidentally create the named SHM if necessary and remove all previous history debug_log_rtsp_message(2, "SETUP \"PTP\" message", req); plist_t groupUUID = plist_dict_get_item(messagePlist, "groupUUID"); if (groupUUID) { diff --git a/shairport.c b/shairport.c index ea7b0b95..c5dc81fd 100644 --- a/shairport.c +++ b/shairport.c @@ -2211,7 +2211,12 @@ int main(int argc, char **argv) { #endif #ifdef CONFIG_AIRPLAY_2 - ptp_shm_interface_open(); + ptp_shm_interface_init(); + ptp_send_control_message_string("T"); // incidentally create the named SHM and remove all previous history + usleep(100000); // wait for it to get done (?) + if (ptp_shm_interface_open() != 0) { + debug(1,"unable to open the shm interface at startup!"); + } #endif activity_monitor_start(); // not yet for AP2