From e8fec7fa704950c10ddf5178a7941953ec508d7f Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 28 Feb 2022 17:58:15 +1100 Subject: [PATCH] Wait for two seconds for the NQPTP service to appear. --- shairport.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/shairport.c b/shairport.c index 3dcdcff5..dc8b5408 100644 --- a/shairport.c +++ b/shairport.c @@ -2211,13 +2211,23 @@ int main(int argc, char **argv) { #endif #ifdef CONFIG_AIRPLAY_2 - ptp_shm_interface_init(); - ptp_send_control_message_string("T"); // incidentally create the named SHM and remove all previous history - usleep(1000000); // wait for it to get done (?) - if (ptp_shm_interface_open() == 0) { - debug(1,"shm interface opened successfully!"); + ptp_send_control_message_string("T"); // get nqptp to create the named shm interface + int ptp_check_times = 0; + const int ptp_wait_interval_us = 5000; + // wait for up to two seconds for NQPTP to come online + do { + ptp_send_control_message_string("T"); // get nqptp to create the named shm interface + usleep(ptp_wait_interval_us); + ptp_check_times++; + } while ((ptp_shm_interface_open() != 0) && (ptp_check_times < (2000000 / ptp_wait_interval_us))); + + if (ptp_shm_interface_open() != 0) { + die("Can't access NQPTP! Is it installed and running?"); } else { - warn("Unable to open the shm interface at startup!"); + if (ptp_check_times == 1) + debug(1,"NQPTP is online."); + else + debug(1,"NQPTP is online after %u microseconds.",ptp_check_times * ptp_wait_interval_us); } #endif