add some mutex locking to the timestamp map updates to prevent concurrency bugs;

82-dvmbridge---implement-notch-filter-for-2175hz-trc-guard-tone
Bryan Biedenkapp 1 year ago
parent 132bec6eaa
commit 3f75869a92

@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms. * GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* Copyright (C) 2023,2024 Bryan Biedenkapp, N2PLL * Copyright (C) 2023,2024,2025 Bryan Biedenkapp, N2PLL
* *
*/ */
#include "Defines.h" #include "Defines.h"
@ -23,6 +23,12 @@ using namespace network::frame;
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
std::mutex FrameQueue::m_fqTimestampLock;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Public Class Members // Public Class Members
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -170,6 +176,7 @@ void FrameQueue::enqueueMessage(const uint8_t* message, uint32_t length, uint32_
void FrameQueue::clearTimestamps() void FrameQueue::clearTimestamps()
{ {
std::lock_guard<std::mutex> lock(m_fqTimestampLock);
m_streamTimestamps.clear(); m_streamTimestamps.clear();
} }
@ -187,6 +194,7 @@ uint8_t* FrameQueue::generateMessage(const uint8_t* message, uint32_t length, ui
uint32_t timestamp = INVALID_TS; uint32_t timestamp = INVALID_TS;
if (streamId != 0U) { if (streamId != 0U) {
std::lock_guard<std::mutex> lock(m_fqTimestampLock);
auto entry = m_streamTimestamps.find(streamId); auto entry = m_streamTimestamps.find(streamId);
if (entry != m_streamTimestamps.end()) { if (entry != m_streamTimestamps.end()) {
timestamp = entry->second; timestamp = entry->second;
@ -221,6 +229,7 @@ uint8_t* FrameQueue::generateMessage(const uint8_t* message, uint32_t length, ui
} }
if (streamId != 0U && rtpSeq == RTP_END_OF_CALL_SEQ) { if (streamId != 0U && rtpSeq == RTP_END_OF_CALL_SEQ) {
std::lock_guard<std::mutex> lock(m_fqTimestampLock);
auto entry = m_streamTimestamps.find(streamId); auto entry = m_streamTimestamps.find(streamId);
if (entry != m_streamTimestamps.end()) { if (entry != m_streamTimestamps.end()) {
if (m_debug) if (m_debug)

@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms. * GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* Copyright (C) 2023,2024 Bryan Biedenkapp, N2PLL * Copyright (C) 2023,2024,2025 Bryan Biedenkapp, N2PLL
* *
*/ */
/** /**
@ -21,6 +21,7 @@
#include "common/network/RTPFNEHeader.h" #include "common/network/RTPFNEHeader.h"
#include "common/network/RawFrameQueue.h" #include "common/network/RawFrameQueue.h"
#include <mutex>
#include <unordered_map> #include <unordered_map>
namespace network namespace network
@ -116,6 +117,7 @@ namespace network
private: private:
uint32_t m_peerId; uint32_t m_peerId;
std::unordered_map<uint32_t, uint32_t> m_streamTimestamps; std::unordered_map<uint32_t, uint32_t> m_streamTimestamps;
static std::mutex m_fqTimestampLock;
/** /**
* @brief Generate RTP message for the frame queue. * @brief Generate RTP message for the frame queue.

Loading…
Cancel
Save

Powered by TurnKey Linux.