#include "ptp-utilities.h"
int shm_fd;
-void *mapped_addr = NULL;
+void *mapped_addr;
static pthread_mutex_t ptp_access_mutex = PTHREAD_MUTEX_INITIALIZER;
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) {
}
} 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!");
}
void ptp_send_control_message_string(const char *msg);
+void ptp_shm_interface_init();
int ptp_shm_interface_open();
int ptp_shm_interface_close();
// 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) {
#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