|
@@ -751,6 +751,8 @@ void PeerConnection::remoteCloseDataChannels() {
|
|
}
|
|
}
|
|
|
|
|
|
shared_ptr<Track> PeerConnection::emplaceTrack(Description::Media description) {
|
|
shared_ptr<Track> PeerConnection::emplaceTrack(Description::Media description) {
|
|
|
|
+ std::unique_lock lock(mTracksMutex); // we are going to emplace
|
|
|
|
+
|
|
#if !RTC_ENABLE_MEDIA
|
|
#if !RTC_ENABLE_MEDIA
|
|
// No media support, mark as removed
|
|
// No media support, mark as removed
|
|
PLOG_WARNING << "Tracks are disabled (not compiled with media support)";
|
|
PLOG_WARNING << "Tracks are disabled (not compiled with media support)";
|
|
@@ -759,10 +761,12 @@ shared_ptr<Track> PeerConnection::emplaceTrack(Description::Media description) {
|
|
|
|
|
|
shared_ptr<Track> track;
|
|
shared_ptr<Track> track;
|
|
if (auto it = mTracks.find(description.mid()); it != mTracks.end())
|
|
if (auto it = mTracks.find(description.mid()); it != mTracks.end())
|
|
- if (track = it->second.lock(); track)
|
|
|
|
- track->setDescription(std::move(description));
|
|
|
|
|
|
+ if (auto t = it->second.lock(); t && !t->isClosed())
|
|
|
|
+ track = std::move(t);
|
|
|
|
|
|
- if (!track) {
|
|
|
|
|
|
+ if (track) {
|
|
|
|
+ track->setDescription(std::move(description));
|
|
|
|
+ } else {
|
|
track = std::make_shared<Track>(weak_from_this(), std::move(description));
|
|
track = std::make_shared<Track>(weak_from_this(), std::move(description));
|
|
mTracks.emplace(std::make_pair(track->mid(), track));
|
|
mTracks.emplace(std::make_pair(track->mid(), track));
|
|
mTrackLines.emplace_back(track);
|
|
mTrackLines.emplace_back(track);
|
|
@@ -896,7 +900,7 @@ void PeerConnection::processLocalDescription(Description description) {
|
|
description.addMedia(std::move(reciprocated));
|
|
description.addMedia(std::move(reciprocated));
|
|
},
|
|
},
|
|
[&](Description::Media *remoteMedia) {
|
|
[&](Description::Media *remoteMedia) {
|
|
- std::shared_lock lock(mTracksMutex);
|
|
|
|
|
|
+ std::unique_lock lock(mTracksMutex); // we may emplace a track
|
|
if (auto it = mTracks.find(remoteMedia->mid()); it != mTracks.end()) {
|
|
if (auto it = mTracks.find(remoteMedia->mid()); it != mTracks.end()) {
|
|
// Prefer local description
|
|
// Prefer local description
|
|
if (auto track = it->second.lock()) {
|
|
if (auto track = it->second.lock()) {
|