瀏覽代碼

Lock remote description only when necessary

Paul-Louis Ageneau 5 年之前
父節點
當前提交
b68ccb4d71
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      src/peerconnection.cpp

+ 3 - 3
src/peerconnection.cpp

@@ -134,14 +134,11 @@ void PeerConnection::setRemoteDescription(Description description) {
 }
 
 void PeerConnection::addRemoteCandidate(Candidate candidate) {
-	std::lock_guard lock(mRemoteDescriptionMutex);
 
 	auto iceTransport = std::atomic_load(&mIceTransport);
 	if (!mRemoteDescription || !iceTransport)
 		throw std::logic_error("Remote candidate set without remote description");
 
-	mRemoteDescription->addCandidate(candidate);
-
 	if (candidate.resolve(Candidate::ResolveMode::Simple)) {
 		iceTransport->addRemoteCandidate(candidate);
 	} else {
@@ -154,6 +151,9 @@ void PeerConnection::addRemoteCandidate(Candidate candidate) {
 		});
 		t.detach();
 	}
+
+	std::lock_guard lock(mRemoteDescriptionMutex);
+	mRemoteDescription->addCandidate(candidate);
 }
 
 std::optional<string> PeerConnection::localAddress() const {