Add CreateIceCandidate overload which takes a cricket::Candidate

This gives clients a clear way to create an IceCandidateInterface
instance for use with PeerConnection from a parsed
cricket::Candidate structure.

Previously, the only way was with the JsepIceCandidate constructor,
but this CL will allow us to move that class out of the API.

Bug: webrtc:9544
Change-Id: Idfc1f1e0f5ee4c68d94599aae3fb824b23189a7c
Reviewed-on: https://webrtc-review.googlesource.com/90121
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24074}
This commit is contained in:
Steve Anton 2018-07-23 15:11:53 -07:00
parent 4206a0a849
commit 27ab0e5ee5
4 changed files with 36 additions and 15 deletions

View File

@ -78,6 +78,12 @@ IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid,
const std::string& sdp,
SdpParseError* error);
// Creates an IceCandidateInterface based on a parsed candidate structure.
std::unique_ptr<IceCandidateInterface> CreateIceCandidate(
const std::string& sdp_mid,
int sdp_mline_index,
const cricket::Candidate& candidate);
// This class represents a collection of candidates for a specific m= section.
// Used in SessionDescriptionInterface.
class IceCandidateCollection {

View File

@ -29,6 +29,14 @@ IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid,
return jsep_ice;
}
std::unique_ptr<IceCandidateInterface> CreateIceCandidate(
const std::string& sdp_mid,
int sdp_mline_index,
const cricket::Candidate& candidate) {
return absl::make_unique<JsepIceCandidate>(sdp_mid, sdp_mline_index,
candidate);
}
JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid,
int sdp_mline_index)
: sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {}

View File

@ -61,8 +61,9 @@ class PeerConnectionWrapperForBundleTest : public PeerConnectionWrapper {
const auto& content = desc->contents()[i];
if (content.media_description()->type() == media_type) {
candidate->set_transport_name(content.name);
JsepIceCandidate jsep_candidate(content.name, i, *candidate);
return pc()->AddIceCandidate(&jsep_candidate);
std::unique_ptr<IceCandidateInterface> jsep_candidate =
CreateIceCandidate(content.name, i, *candidate);
return pc()->AddIceCandidate(jsep_candidate.get());
}
}
RTC_NOTREACHED();

View File

@ -51,8 +51,9 @@ class PeerConnectionWrapperForIceTest : public PeerConnectionWrapper {
RTC_DCHECK(desc->contents().size() > 0);
const auto& first_content = desc->contents()[0];
candidate->set_transport_name(first_content.name);
JsepIceCandidate jsep_candidate(first_content.name, 0, *candidate);
return pc()->AddIceCandidate(&jsep_candidate);
std::unique_ptr<IceCandidateInterface> jsep_candidate =
CreateIceCandidate(first_content.name, 0, *candidate);
return pc()->AddIceCandidate(jsep_candidate.get());
}
// Returns ICE candidates from the remote session description.
@ -221,8 +222,9 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
RTC_DCHECK(desc->contents().size() > 0);
const auto& first_content = desc->contents()[0];
candidate->set_transport_name(first_content.name);
JsepIceCandidate jsep_candidate(first_content.name, 0, *candidate);
return sdesc->AddCandidate(&jsep_candidate);
std::unique_ptr<IceCandidateInterface> jsep_candidate =
CreateIceCandidate(first_content.name, 0, *candidate);
return sdesc->AddCandidate(jsep_candidate.get());
}
rtc::FakeNetworkManager* NewFakeNetwork() {
@ -411,13 +413,14 @@ TEST_P(PeerConnectionIceTest, CannotAddCandidateWhenRemoteDescriptionNotSet) {
auto caller = CreatePeerConnectionWithAudioVideo();
cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress);
JsepIceCandidate jsep_candidate(cricket::CN_AUDIO, 0, candidate);
std::unique_ptr<IceCandidateInterface> jsep_candidate =
CreateIceCandidate(cricket::CN_AUDIO, 0, candidate);
EXPECT_FALSE(caller->pc()->AddIceCandidate(&jsep_candidate));
EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get()));
caller->CreateOfferAndSetAsLocal();
EXPECT_FALSE(caller->pc()->AddIceCandidate(&jsep_candidate));
EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get()));
EXPECT_EQ(
2, webrtc::metrics::NumSamples("WebRTC.PeerConnection.AddIceCandidate"));
EXPECT_EQ(
@ -436,11 +439,12 @@ TEST_P(PeerConnectionIceTest, CannotAddCandidateWhenPeerConnectionClosed) {
cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress);
auto* audio_content = cricket::GetFirstAudioContent(
caller->pc()->local_description()->description());
JsepIceCandidate jsep_candidate(audio_content->name, 0, candidate);
std::unique_ptr<IceCandidateInterface> jsep_candidate =
CreateIceCandidate(audio_content->name, 0, candidate);
caller->pc()->Close();
EXPECT_FALSE(caller->pc()->AddIceCandidate(&jsep_candidate));
EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get()));
}
TEST_P(PeerConnectionIceTest, DuplicateIceCandidateIgnoredWhenAdded) {
@ -471,9 +475,10 @@ TEST_P(PeerConnectionIceTest,
cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress);
auto* audio_content = cricket::GetFirstAudioContent(
caller->pc()->local_description()->description());
JsepIceCandidate ice_candidate(audio_content->name, 0, candidate);
std::unique_ptr<IceCandidateInterface> ice_candidate =
CreateIceCandidate(audio_content->name, 0, candidate);
ASSERT_TRUE(caller->pc()->AddIceCandidate(&ice_candidate));
ASSERT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get()));
caller->pc()->Close();
@ -495,8 +500,9 @@ TEST_P(PeerConnectionIceTest,
cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress);
auto* audio_content = cricket::GetFirstAudioContent(
caller->pc()->local_description()->description());
JsepIceCandidate ice_candidate(audio_content->name, 0, candidate);
EXPECT_TRUE(caller->pc()->AddIceCandidate(&ice_candidate));
std::unique_ptr<IceCandidateInterface> ice_candidate =
CreateIceCandidate(audio_content->name, 0, candidate);
EXPECT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get()));
EXPECT_TRUE(caller->pc()->RemoveIceCandidates({candidate}));
}