]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Require NQPTP to be running and create the SHM interface at startup.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 27 Feb 2022 02:00:03 +0000 (13:00 +1100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 27 Feb 2022 02:00:03 +0000 (13:00 +1100)
ptp-utilities.c
ptp-utilities.h
rtsp.c
shairport.c

index 73fe70c14a32b010ed2302ee75064113cf449e6b..8b05101ec93e966f2f7b7a9bce98da623e51c8ab 100644 (file)
@@ -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!");
   }
index f18169d961c5626441141ded081c3cafe36f123d..86d2b4993e168e2bd9f8f578c344afad0164bace 100644 (file)
@@ -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 d277b7c05337b833e87bfb87054bfc75e0f03c64..29d1e4e08325f93e4d118d2f2b7ef9919b268282 100644 (file)
--- 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) {
index ea7b0b957c6aaf1b16380b3829cdd8111a68568e..c5dc81fda6725ab646dbfccd7efa35ec43b29786 100644 (file)
@@ -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