From 88e74b8c34648e4b1a2537dbd767f98276b7bc5e Mon Sep 17 00:00:00 2001 From: hbeni Date: Fri, 12 Feb 2021 17:14:14 +0100 Subject: [PATCH] UDP-server now handles PTT at the end to avoid deadlock with mumble-main-thread fix #76 --- client/mumble-plugin/fgcom-mumble.cpp | 7 +++++++ client/mumble-plugin/lib/io_UDPServer.cpp | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/client/mumble-plugin/fgcom-mumble.cpp b/client/mumble-plugin/fgcom-mumble.cpp index 8c9a41c7..f7b08e6f 100644 --- a/client/mumble-plugin/fgcom-mumble.cpp +++ b/client/mumble-plugin/fgcom-mumble.cpp @@ -156,6 +156,10 @@ void fgcom_handlePTT() { // see which radio was used and if its operational. bool radio_serviceable, radio_powered, radio_switchedOn, radio_ptt; bool radio_ptt_result = false; // if we should open or close the mic, default no + + pluginDbg("fgcom_localcfg_mtx.lock()"); + fgcom_localcfg_mtx.lock(); + for (const auto &lcl_idty : fgcom_local_client) { int iid = lcl_idty.first; fgcom_client lcl = lcl_idty.second; @@ -178,6 +182,9 @@ void fgcom_handlePTT() { } } } + + pluginDbg("fgcom_localcfg_mtx.unlock()"); + fgcom_localcfg_mtx.unlock(); if (radio_ptt_result) pluginDbg("final PTT/radio openmic state: "+std::to_string(radio_ptt_result)); mumAPI.requestMicrophoneActivationOvewrite(ownPluginID, radio_ptt_result); diff --git a/client/mumble-plugin/lib/io_UDPServer.cpp b/client/mumble-plugin/lib/io_UDPServer.cpp index c45e7611..831c9413 100644 --- a/client/mumble-plugin/lib/io_UDPServer.cpp +++ b/client/mumble-plugin/lib/io_UDPServer.cpp @@ -99,6 +99,9 @@ std::map fgcom_udp_parseMsg(char buffer[MAXLINE] std::map hgt_value; std::map alt_value; std::map> parsed_frq_valAndToken; // last parsed frequency per radio-id (,) + + // marker for PTT change + bool needToHandlePTT = false; // convert to stringstream so we can easily tokenize // TODO: why not simply refactor to strtok()? @@ -274,7 +277,7 @@ std::map fgcom_udp_parseMsg(char buffer[MAXLINE] bool oldValue = fgcom_local_client[iid].radios[radio_id].ptt; fgcom_local_client[iid].radios[radio_id].ptt = parsedPTT; if (fgcom_local_client[iid].radios[radio_id].ptt != oldValue ) parseResult[iid].radioData.insert(radio_id); - fgcom_handlePTT(); + needToHandlePTT = true; } } @@ -376,7 +379,7 @@ std::map fgcom_udp_parseMsg(char buffer[MAXLINE] } } } - fgcom_handlePTT(); + needToHandlePTT = true; } if (token_key == "OUTPUT_VOL") { // Set all radio instances to the selected volume @@ -497,6 +500,12 @@ std::map fgcom_udp_parseMsg(char buffer[MAXLINE] // All done fgcom_localcfg_mtx.unlock(); + + /** + * Handle PTT Change + */ + if (needToHandlePTT) fgcom_handlePTT(); + pluginDbg("[UDP-server] packet fully processed"); return parseResult; }