diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp index 5a22fbcc27676394df2809b2b5773cf0e846b902..2e22f42935fac8fcc916be0a706ac7595d17c9df 100644 --- a/src/sip/sipcall.cpp +++ b/src/sip/sipcall.cpp @@ -162,12 +162,16 @@ SIPCall::createCallAVStream(const StreamData& StreamData, const std::shared_ptr<MediaStreamSubject>& mediaStreamSubject) { const std::string AVStreamId = StreamData.id + std::to_string(StreamData.direction); - callAVStreams[AVStreamId] = mediaStreamSubject; - streamSource.attachPriorityObserver(callAVStreams[AVStreamId]); + std::lock_guard<std::mutex> lk(avStreamsMtx_); + auto it = callAVStreams.find(AVStreamId); + if (it != callAVStreams.end()) + return; + it = callAVStreams.insert(it, {AVStreamId, mediaStreamSubject}); + streamSource.attachPriorityObserver(it->second); jami::Manager::instance() .getJamiPluginManager() .getCallServicesManager() - .createAVSubject(StreamData, callAVStreams[AVStreamId]); + .createAVSubject(StreamData, it->second); } #endif // ENABLE_PLUGIN @@ -1251,8 +1255,11 @@ SIPCall::stopAllMedia() videortp_->stop(); #endif #ifdef ENABLE_PLUGIN - callAVStreams.erase(getCallId() + "0"); - callAVStreams.erase(getCallId() + "1"); + { + std::lock_guard<std::mutex> lk(avStreamsMtx_); + callAVStreams.erase(getCallId() + "0"); + callAVStreams.erase(getCallId() + "1"); + } jami::Manager::instance().getJamiPluginManager().getCallServicesManager().clearAVSubject( getCallId()); #endif diff --git a/src/sip/sipcall.h b/src/sip/sipcall.h index 3365299a498a221e13b14d128653a0d2f45fc2c4..652e06d2c0ca856c52180a3b7e8ff969124bcc02 100644 --- a/src/sip/sipcall.h +++ b/src/sip/sipcall.h @@ -279,6 +279,7 @@ private: void createCallAVStreams(); #endif // ENABLE_PLUGIN + std::mutex avStreamsMtx_ {}; std::map<std::string, std::shared_ptr<MediaStreamSubject>> callAVStreams; void setCallMediaLocal();