summaryrefslogtreecommitdiff
path: root/chromium/third_party/webrtc/pc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/webrtc/pc')
-rw-r--r--chromium/third_party/webrtc/pc/mediasession.cc26
-rw-r--r--chromium/third_party/webrtc/pc/peerconnectioninterface_unittest.cc33
-rw-r--r--chromium/third_party/webrtc/pc/webrtcsession.cc48
3 files changed, 75 insertions, 32 deletions
diff --git a/chromium/third_party/webrtc/pc/mediasession.cc b/chromium/third_party/webrtc/pc/mediasession.cc
index 8079ae140cb..835f76d1cf0 100644
--- a/chromium/third_party/webrtc/pc/mediasession.cc
+++ b/chromium/third_party/webrtc/pc/mediasession.cc
@@ -1860,7 +1860,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer(
AudioCodecs filtered_codecs;
// Add the codecs from current content if exists.
if (current_content) {
- RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO));
+ RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO));
const AudioContentDescription* acd =
static_cast<const AudioContentDescription*>(
current_content->description);
@@ -1938,7 +1938,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer(
VideoCodecs filtered_codecs;
// Add the codecs from current content if exists.
if (current_content) {
- RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO));
+ RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO));
const VideoContentDescription* vcd =
static_cast<const VideoContentDescription*>(
current_content->description);
@@ -2002,6 +2002,7 @@ bool MediaSessionDescriptionFactory::AddDataContentForOffer(
// If the DataChannel type is not specified, use the DataChannel type in
// the current description.
if (session_options.data_channel_type == DCT_NONE && current_content) {
+ RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_DATA));
is_sctp = (static_cast<const DataContentDescription*>(
current_content->description)
->protocol() == kMediaProtocolSctp);
@@ -2077,6 +2078,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer(
const AudioCodecs& audio_codecs,
StreamParamsVec* current_streams,
SessionDescription* answer) const {
+ RTC_CHECK(IsMediaContentOfType(offer_content, MEDIA_TYPE_AUDIO));
const AudioContentDescription* offer_audio_description =
static_cast<const AudioContentDescription*>(offer_content->description);
@@ -2101,7 +2103,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer(
AudioCodecs filtered_codecs;
// Add the codecs from current content if exists.
if (current_content) {
- RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO));
+ RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO));
const AudioContentDescription* acd =
static_cast<const AudioContentDescription*>(
current_content->description);
@@ -2170,6 +2172,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer(
const VideoCodecs& video_codecs,
StreamParamsVec* current_streams,
SessionDescription* answer) const {
+ RTC_CHECK(IsMediaContentOfType(offer_content, MEDIA_TYPE_VIDEO));
const VideoContentDescription* offer_video_description =
static_cast<const VideoContentDescription*>(offer_content->description);
@@ -2184,7 +2187,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer(
VideoCodecs filtered_codecs;
// Add the codecs from current content if exists.
if (current_content) {
- RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO));
+ RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO));
const VideoContentDescription* vcd =
static_cast<const VideoContentDescription*>(
current_content->description);
@@ -2270,19 +2273,18 @@ bool MediaSessionDescriptionFactory::AddDataContentForAnswer(
data_transport->secure() ? cricket::SEC_DISABLED : secure();
bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) &&
session_options.bundle_enabled;
+ RTC_CHECK(IsMediaContentOfType(offer_content, MEDIA_TYPE_DATA));
+ const DataContentDescription* offer_data_description =
+ static_cast<const DataContentDescription*>(offer_content->description);
if (!CreateMediaContentAnswer(
- static_cast<const DataContentDescription*>(
- offer_content->description),
- media_description_options, session_options, data_codecs, sdes_policy,
- GetCryptos(current_content), RtpHeaderExtensions(),
- enable_encrypted_rtp_header_extensions_, current_streams,
- bundle_enabled, data_answer.get())) {
+ offer_data_description, media_description_options, session_options,
+ data_codecs, sdes_policy, GetCryptos(current_content),
+ RtpHeaderExtensions(), enable_encrypted_rtp_header_extensions_,
+ current_streams, bundle_enabled, data_answer.get())) {
return false; // Fails the session setup.
}
// Respond with sctpmap if the offer uses sctpmap.
- const DataContentDescription* offer_data_description =
- static_cast<const DataContentDescription*>(offer_content->description);
bool offer_uses_sctpmap = offer_data_description->use_sctpmap();
data_answer->set_use_sctpmap(offer_uses_sctpmap);
diff --git a/chromium/third_party/webrtc/pc/peerconnectioninterface_unittest.cc b/chromium/third_party/webrtc/pc/peerconnectioninterface_unittest.cc
index cc063b4f746..ac6c8b95667 100644
--- a/chromium/third_party/webrtc/pc/peerconnectioninterface_unittest.cc
+++ b/chromium/third_party/webrtc/pc/peerconnectioninterface_unittest.cc
@@ -3710,7 +3710,7 @@ TEST_F(PeerConnectionInterfaceTest, CreateAnswerWithoutRemoteDescription) {
EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
}
-// Test that an error is returned if a description is applied that doesn't
+// Tests that an error is returned if a description is applied that doesn't
// respect the order of existing media sections.
TEST_F(PeerConnectionInterfaceTest,
MediaSectionOrderEnforcedForSubsequentOffers) {
@@ -3743,6 +3743,37 @@ TEST_F(PeerConnectionInterfaceTest,
EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
}
+// Tests that an error is returned if a description is applied that has fewer
+// media sections than the existing description.
+TEST_F(PeerConnectionInterfaceTest,
+ MediaSectionCountEnforcedForSubsequentOffer) {
+ CreatePeerConnection();
+ FakeConstraints constraints;
+ constraints.SetMandatoryReceiveAudio(true);
+ constraints.SetMandatoryReceiveVideo(true);
+ std::unique_ptr<SessionDescriptionInterface> offer;
+ ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
+ EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
+
+ // A remote offer with fewer media sections should be rejected.
+ ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
+ offer->description()->contents().pop_back();
+ offer->description()->contents().pop_back();
+ ASSERT_TRUE(offer->description()->contents().empty());
+ EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
+
+ std::unique_ptr<SessionDescriptionInterface> answer;
+ ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
+ EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
+
+ // A subsequent local offer with fewer media sections should be rejected.
+ ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
+ offer->description()->contents().pop_back();
+ offer->description()->contents().pop_back();
+ ASSERT_TRUE(offer->description()->contents().empty());
+ EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
+}
+
class PeerConnectionMediaConfigTest : public testing::Test {
protected:
void SetUp() override {
diff --git a/chromium/third_party/webrtc/pc/webrtcsession.cc b/chromium/third_party/webrtc/pc/webrtcsession.cc
index f556204c6c9..55d029608cb 100644
--- a/chromium/third_party/webrtc/pc/webrtcsession.cc
+++ b/chromium/third_party/webrtc/pc/webrtcsession.cc
@@ -140,25 +140,30 @@ IceCandidatePairType GetIceCandidatePairCounter(
return kIceCandidatePairMax;
}
-// Verify that the order of media sections in |desc1| matches |desc2|. The
-// number of m= sections could be different.
-static bool MediaSectionsInSameOrder(const SessionDescription* desc1,
- const SessionDescription* desc2) {
- if (!desc1 || !desc2) {
+// Verify that the order of media sections in |new_desc| matches
+// |existing_desc|. The number of m= sections in |new_desc| should be no less
+// than |existing_desc|.
+static bool MediaSectionsInSameOrder(const SessionDescription* existing_desc,
+ const SessionDescription* new_desc) {
+ if (!existing_desc || !new_desc) {
+ return false;
+ }
+
+ if (existing_desc->contents().size() > new_desc->contents().size()) {
return false;
}
- for (size_t i = 0;
- i < desc1->contents().size() && i < desc2->contents().size(); ++i) {
- if ((desc2->contents()[i].name) != desc1->contents()[i].name) {
+
+ for (size_t i = 0; i < existing_desc->contents().size(); ++i) {
+ if (new_desc->contents()[i].name != existing_desc->contents()[i].name) {
return false;
}
- const MediaContentDescription* desc2_mdesc =
+ const MediaContentDescription* new_desc_mdesc =
static_cast<const MediaContentDescription*>(
- desc2->contents()[i].description);
- const MediaContentDescription* desc1_mdesc =
+ new_desc->contents()[i].description);
+ const MediaContentDescription* existing_desc_mdesc =
static_cast<const MediaContentDescription*>(
- desc1->contents()[i].description);
- if (desc2_mdesc->type() != desc1_mdesc->type()) {
+ existing_desc->contents()[i].description);
+ if (new_desc_mdesc->type() != existing_desc_mdesc->type()) {
return false;
}
}
@@ -2165,16 +2170,21 @@ bool WebRtcSession::ValidateSessionDescription(
const cricket::SessionDescription* offer_desc =
(source == cricket::CS_LOCAL) ? remote_description()->description()
: local_description()->description();
- if (!MediaSectionsHaveSameCount(sdesc->description(), offer_desc) ||
- !MediaSectionsInSameOrder(sdesc->description(), offer_desc)) {
+ if (!MediaSectionsHaveSameCount(offer_desc, sdesc->description()) ||
+ !MediaSectionsInSameOrder(offer_desc, sdesc->description())) {
return BadAnswerSdp(source, kMlineMismatchInAnswer, err_desc);
}
} else {
- // The re-offers should respect the order of m= sections in current local
+ const cricket::SessionDescription* current_desc = nullptr;
+ if (source == cricket::CS_LOCAL && local_description()) {
+ current_desc = local_description()->description();
+ } else if (source == cricket::CS_REMOTE && remote_description()) {
+ current_desc = remote_description()->description();
+ }
+ // The re-offers should respect the order of m= sections in current
// description. See RFC3264 Section 8 paragraph 4 for more details.
- if (local_description() &&
- !MediaSectionsInSameOrder(sdesc->description(),
- local_description()->description())) {
+ if (current_desc &&
+ !MediaSectionsInSameOrder(current_desc, sdesc->description())) {
return BadOfferSdp(source, kMlineMismatchInSubsequentOffer, err_desc);
}
}