Skip to content

Commit

Permalink
Skip ice candidate if peer and stream objects are NULL (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpoddubchak authored Feb 17, 2020
1 parent 3f4faad commit a1bc273
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
19 changes: 12 additions & 7 deletions erizo/src/erizo/NicerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,25 @@ void NicerConnection::startGathering() {
bool NicerConnection::setRemoteCandidates(const std::vector<CandidateInfo> &candidates, bool is_bundle) {
std::vector<CandidateInfo> cands(candidates);
auto remote_candidates_promise = std::make_shared<std::promise<void>>();
nr_ice_peer_ctx *peer = peer_;
nr_ice_media_stream *stream = stream_;
std::shared_ptr<NicerInterface> nicer = nicer_;
async([cands, nicer, peer, stream, this, remote_candidates_promise]
async([cands, this, remote_candidates_promise]
(std::shared_ptr<NicerConnection> this_ptr) {
ELOG_DEBUG("%s message: adding remote candidates (%ld)", toLog(), cands.size());
nr_ice_peer_ctx *peer = this_ptr->peer_;
nr_ice_media_stream *stream = this_ptr->stream_;
std::shared_ptr<NicerInterface> nicer = this_ptr->nicer_;
for (const CandidateInfo &cand : cands) {
std::string sdp = cand.sdp;
std::size_t pos = sdp.find(",");
std::string candidate = sdp.substr(0, pos);
ELOG_DEBUG("%s message: New remote ICE candidate (%s)", toLog(), candidate.c_str());
UINT4 r = nicer->IcePeerContextParseTrickleCandidate(peer, stream, const_cast<char *>(candidate.c_str()));
if (r && r != R_ALREADY) {
ELOG_WARN("%s message: Couldn't add remote ICE candidate (%s) (%d)", toLog(), candidate.c_str(), r);
if (peer != nullptr) {
UINT4 r = nicer->IcePeerContextParseTrickleCandidate(peer, stream, const_cast<char *>(candidate.c_str()));
if (r && r != R_ALREADY) {
ELOG_WARN("%s message: Couldn't add remote ICE candidate (%s) (%d)", toLog(), candidate.c_str(), r);
}
} else {
ELOG_WARN("%s message: Couldn't add remote ICE candidate (%s) bacause peer is NULL",
toLog(), candidate.c_str());
}
}
remote_candidates_promise->set_value();
Expand Down
1 change: 1 addition & 0 deletions erizo/src/erizo/NicerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class NicerConnection : public IceConnection, public std::enable_shared_from_thi
nr_ice_handler* ice_handler_;
std::promise<void> close_promise_;
std::promise<void> start_promise_;
std::future<void> start_future_;
boost::mutex close_mutex_;
boost::mutex close_sync_mutex_;
};
Expand Down
3 changes: 2 additions & 1 deletion erizo/src/test/NicerConnectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ TEST_F(NicerConnectionTest, setRemoteCandidates_Success_WhenCalled) {
std::vector<erizo::CandidateInfo> candidate_list;
candidate_list.push_back(arbitrary_candidate);

EXPECT_CALL(*nicer, IcePeerContextParseTrickleCandidate(_, _, _)).Times(1);
EXPECT_CALL(*nicer, IcePeerContextParseTrickleCandidate(_, _, _)).Times(2);
nicer_connection->setRemoteCandidates(candidate_list, true);
nicer_connection->setRemoteCandidates(candidate_list, true);
}

Expand Down

0 comments on commit a1bc273

Please sign in to comment.