diff --git a/include/rtc/rtcpnackresponder.hpp b/include/rtc/rtcpnackresponder.hpp index a3f1cc1a8..b33c46a6f 100644 --- a/include/rtc/rtcpnackresponder.hpp +++ b/include/rtc/rtcpnackresponder.hpp @@ -37,9 +37,9 @@ class RTC_CPP_EXPORT RtcpNackResponder final : public MediaHandlerElement { shared_ptr oldest = nullptr; /// Newest packet in storage shared_ptr newest = nullptr; - /// Inner storage std::unordered_map> storage{}; + std::mutex mutex; /// Maximum storage size const unsigned maximumSize; diff --git a/src/rtcpnackresponder.cpp b/src/rtcpnackresponder.cpp index c9e1b5a29..efae6d94a 100644 --- a/src/rtcpnackresponder.cpp +++ b/src/rtcpnackresponder.cpp @@ -28,6 +28,7 @@ RtcpNackResponder::Storage::Storage(unsigned _maximumSize) : maximumSize(_maximu } optional RtcpNackResponder::Storage::get(uint16_t sequenceNumber) { + std::lock_guard lock(mutex); auto position = storage.find(sequenceNumber); return position != storage.end() ? std::make_optional(storage.at(sequenceNumber)->packet) : nullopt; @@ -40,6 +41,7 @@ void RtcpNackResponder::Storage::store(binary_ptr packet) { auto rtp = reinterpret_cast(packet->data()); auto sequenceNumber = rtp->seqNumber(); + std::lock_guard lock(mutex); assert((storage.empty() && !oldest && !newest) || (!storage.empty() && oldest && newest)); if (size() == 0) {