fix potential bridge memory leak when using USRP audio; add support for bridge to reset and start a new call when using UDP metadata *and* overriding the source ID;

4.11f_maint
Bryan Biedenkapp 11 months ago
parent 63e2a6a579
commit e38488f602

@ -87,6 +87,9 @@ network:
# Flag indicating the source "Radio ID" will be overridden from the received # Flag indicating the source "Radio ID" will be overridden from the received
# UDP SRC ID. # UDP SRC ID.
overrideSourceIdFromUDP: false overrideSourceIdFromUDP: false
# Flag indicating if the source "Radio ID" is being overriden, and changes mid-call, bridge should
# terminate previous call an initiate a new one. (This applies only when both udpMetadata and overrideSourceIdFromUDP is set.)
resetCallForSourceIdChange: false
# Talkgroup ID for transmitted/received audio frames. # Talkgroup ID for transmitted/received audio frames.
destinationId: 1 destinationId: 1
# Slot for received/transmitted audio frames. # Slot for received/transmitted audio frames.

@ -299,6 +299,7 @@ HostBridge::HostBridge(const std::string& confFile) :
m_srcIdOverride(0U), m_srcIdOverride(0U),
m_overrideSrcIdFromMDC(false), m_overrideSrcIdFromMDC(false),
m_overrideSrcIdFromUDP(false), m_overrideSrcIdFromUDP(false),
m_resetCallForSourceIdChange(false),
m_dstId(1U), m_dstId(1U),
m_slot(1U), m_slot(1U),
m_identity(), m_identity(),
@ -1045,9 +1046,15 @@ bool HostBridge::createNetwork()
m_srcId = (uint32_t)networkConf["sourceId"].as<uint32_t>(p25::defines::WUID_FNE); m_srcId = (uint32_t)networkConf["sourceId"].as<uint32_t>(p25::defines::WUID_FNE);
m_overrideSrcIdFromMDC = networkConf["overrideSourceIdFromMDC"].as<bool>(false); m_overrideSrcIdFromMDC = networkConf["overrideSourceIdFromMDC"].as<bool>(false);
m_overrideSrcIdFromUDP = networkConf["overrideSourceIdFromUDP"].as<bool>(false); m_overrideSrcIdFromUDP = networkConf["overrideSourceIdFromUDP"].as<bool>(false);
m_resetCallForSourceIdChange = networkConf["resetCallForSourceIdChange"].as<bool>(false);
m_dstId = (uint32_t)networkConf["destinationId"].as<uint32_t>(1U); m_dstId = (uint32_t)networkConf["destinationId"].as<uint32_t>(1U);
m_slot = (uint8_t)networkConf["slot"].as<uint32_t>(1U); m_slot = (uint8_t)networkConf["slot"].as<uint32_t>(1U);
if (!m_udpMetadata && m_resetCallForSourceIdChange)
m_resetCallForSourceIdChange = false; // only applies to UDP audio with metadata
if (!m_overrideSrcIdFromUDP && m_resetCallForSourceIdChange)
m_resetCallForSourceIdChange = false; // only applies to UDP audio when overriding source ID
bool encrypted = networkConf["encrypted"].as<bool>(false); bool encrypted = networkConf["encrypted"].as<bool>(false);
std::string key = networkConf["presharedKey"].as<std::string>(); std::string key = networkConf["presharedKey"].as<std::string>();
uint8_t presharedKey[AES_WRAPPED_PCKT_KEY_LEN]; uint8_t presharedKey[AES_WRAPPED_PCKT_KEY_LEN];
@ -1116,6 +1123,9 @@ bool HostBridge::createNetwork()
LogInfo(" DMR Slot: %u", m_slot); LogInfo(" DMR Slot: %u", m_slot);
LogInfo(" Override Source ID from MDC: %s", m_overrideSrcIdFromMDC ? "yes" : "no"); LogInfo(" Override Source ID from MDC: %s", m_overrideSrcIdFromMDC ? "yes" : "no");
LogInfo(" Override Source ID from UDP Audio: %s", m_overrideSrcIdFromUDP ? "yes" : "no"); LogInfo(" Override Source ID from UDP Audio: %s", m_overrideSrcIdFromUDP ? "yes" : "no");
if (m_resetCallForSourceIdChange) {
LogInfo(" Reset Call if Source ID Changes from UDP Audio: %s", m_resetCallForSourceIdChange ? "yes" : "no");
}
if (debug) { if (debug) {
LogInfo(" Debug: yes"); LogInfo(" Debug: yes");
@ -1224,17 +1234,27 @@ void HostBridge::processUDPAudio()
if (usrpHeader[15U] == 1U && length > USRP_HEADER_LENGTH) // PTT state true and ensure we did not just receive a USRP header if (usrpHeader[15U] == 1U && length > USRP_HEADER_LENGTH) // PTT state true and ensure we did not just receive a USRP header
::memcpy(pcm, buffer + USRP_HEADER_LENGTH, pcmLength); ::memcpy(pcm, buffer + USRP_HEADER_LENGTH, pcmLength);
delete[] usrpHeader;
} }
// Utils::dump(1U, "PCM RECV BYTE BUFFER", pcm, pcmLength); // Utils::dump(1U, "PCM RECV BYTE BUFFER", pcm, pcmLength);
m_udpSrcId = m_srcId; m_udpDstId = m_dstId;
if (m_udpMetadata) { if (m_udpMetadata) {
if (m_overrideSrcIdFromUDP) if (m_overrideSrcIdFromUDP) {
m_udpSrcId = __GET_UINT32(buffer, pcmLength + 8U); uint32_t udpSrcId = __GET_UINT32(buffer, pcmLength + 8U);
}
m_udpDstId = m_dstId; // if the UDP source ID now doesn't match the current call ID, reset call states
if (m_resetCallForSourceIdChange && (udpSrcId != m_udpSrcId))
callEnd(m_udpSrcId, m_dstId);
m_udpSrcId = udpSrcId;
}
} else {
m_udpSrcId = m_srcId;
}
std::lock_guard<std::mutex> lock(m_audioMutex); std::lock_guard<std::mutex> lock(m_audioMutex);

@ -170,6 +170,7 @@ private:
uint32_t m_srcIdOverride; uint32_t m_srcIdOverride;
bool m_overrideSrcIdFromMDC; bool m_overrideSrcIdFromMDC;
bool m_overrideSrcIdFromUDP; bool m_overrideSrcIdFromUDP;
bool m_resetCallForSourceIdChange;
uint32_t m_dstId; uint32_t m_dstId;
uint8_t m_slot; uint8_t m_slot;

Loading…
Cancel
Save

Powered by TurnKey Linux.