Skip to content

Commit

Permalink
UDP-server now handles PTT at the end to avoid deadlock with mumble-m…
Browse files Browse the repository at this point in the history
…ain-thread

fix #76
  • Loading branch information
hbeni committed Feb 12, 2021
1 parent e1ae34e commit 88e74b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions client/mumble-plugin/fgcom-mumble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions client/mumble-plugin/lib/io_UDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ std::map<int, fgcom_udp_parseMsg_result> fgcom_udp_parseMsg(char buffer[MAXLINE]
std::map<int, float> hgt_value;
std::map<int, float> alt_value;
std::map<int, std::pair<std::string, std::string>> parsed_frq_valAndToken; // last parsed frequency per radio-id (<value>,<token>)

// marker for PTT change
bool needToHandlePTT = false;

// convert to stringstream so we can easily tokenize
// TODO: why not simply refactor to strtok()?
Expand Down Expand Up @@ -274,7 +277,7 @@ std::map<int, fgcom_udp_parseMsg_result> 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;
}

}
Expand Down Expand Up @@ -376,7 +379,7 @@ std::map<int, fgcom_udp_parseMsg_result> fgcom_udp_parseMsg(char buffer[MAXLINE]
}
}
}
fgcom_handlePTT();
needToHandlePTT = true;
}
if (token_key == "OUTPUT_VOL") {
// Set all radio instances to the selected volume
Expand Down Expand Up @@ -497,6 +500,12 @@ std::map<int, fgcom_udp_parseMsg_result> 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;
}
Expand Down

0 comments on commit 88e74b8

Please sign in to comment.