2018-10-12 10:54:26 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "pc/session_description.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
|
2019-05-13 13:36:16 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) {
|
|
|
|
|
VideoContentDescription video_desc;
|
2018-10-23 10:17:39 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) {
|
|
|
|
|
VideoContentDescription video_desc;
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
|
|
|
|
|
EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
|
|
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kMedia,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.extmap_allow_mixed_enum());
|
|
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kSession,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Not allowed to downgrade from kSession to kMedia.
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kSession,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Always okay to set not supported.
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
|
|
|
|
|
EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
|
|
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kMedia,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.extmap_allow_mixed_enum());
|
|
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
|
|
|
|
|
EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) {
|
|
|
|
|
VideoContentDescription video_desc;
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
|
|
|
|
|
EXPECT_FALSE(video_desc.extmap_allow_mixed());
|
|
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
|
|
|
|
EXPECT_TRUE(video_desc.extmap_allow_mixed());
|
|
|
|
|
video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
|
|
|
|
|
EXPECT_TRUE(video_desc.extmap_allow_mixed());
|
2018-10-12 10:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest, SetExtmapAllowMixed) {
|
|
|
|
|
SessionDescription session_desc;
|
2018-10-23 10:17:39 +02:00
|
|
|
session_desc.set_extmap_allow_mixed(true);
|
|
|
|
|
EXPECT_TRUE(session_desc.extmap_allow_mixed());
|
|
|
|
|
session_desc.set_extmap_allow_mixed(false);
|
|
|
|
|
EXPECT_FALSE(session_desc.extmap_allow_mixed());
|
2018-10-12 10:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest, SetExtmapAllowMixedPropagatesToMediaLevel) {
|
|
|
|
|
SessionDescription session_desc;
|
|
|
|
|
MediaContentDescription* video_desc = new VideoContentDescription();
|
|
|
|
|
session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
|
|
|
|
|
|
|
|
|
|
// Setting true on session level propagates to media level.
|
2018-10-23 10:17:39 +02:00
|
|
|
session_desc.set_extmap_allow_mixed(true);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kSession,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Don't downgrade from session level to media level
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kSession,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Setting false on session level propagates to media level if the current
|
|
|
|
|
// state is kSession.
|
2018-10-23 10:17:39 +02:00
|
|
|
session_desc.set_extmap_allow_mixed(false);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kNo,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Now possible to set at media level.
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kMedia,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Setting false on session level does not override on media level if current
|
|
|
|
|
// state is kMedia.
|
2018-10-23 10:17:39 +02:00
|
|
|
session_desc.set_extmap_allow_mixed(false);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kMedia,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Setting true on session level overrides setting on media level.
|
2018-10-23 10:17:39 +02:00
|
|
|
session_desc.set_extmap_allow_mixed(true);
|
2018-10-12 10:54:26 +02:00
|
|
|
EXPECT_EQ(MediaContentDescription::kSession,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
|
|
|
|
|
SessionDescription session_desc;
|
2018-10-23 10:17:39 +02:00
|
|
|
session_desc.set_extmap_allow_mixed(false);
|
2018-10-12 10:54:26 +02:00
|
|
|
MediaContentDescription* audio_desc = new AudioContentDescription();
|
2018-10-23 10:17:39 +02:00
|
|
|
audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// If session setting is false, media level setting is preserved when new
|
|
|
|
|
// content is added.
|
|
|
|
|
session_desc.AddContent("audio", MediaProtocolType::kRtp, audio_desc);
|
|
|
|
|
EXPECT_EQ(MediaContentDescription::kMedia,
|
2018-10-23 10:17:39 +02:00
|
|
|
audio_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// If session setting is true, it's transferred to media level when new
|
|
|
|
|
// content is added.
|
2018-10-23 10:17:39 +02:00
|
|
|
session_desc.set_extmap_allow_mixed(true);
|
2018-10-12 10:54:26 +02:00
|
|
|
MediaContentDescription* video_desc = new VideoContentDescription();
|
|
|
|
|
session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
|
|
|
|
|
EXPECT_EQ(MediaContentDescription::kSession,
|
2018-10-23 10:17:39 +02:00
|
|
|
video_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
|
|
|
|
|
// Session level setting overrides media level when new content is added.
|
2019-05-13 13:36:16 +02:00
|
|
|
MediaContentDescription* data_desc = new RtpDataContentDescription;
|
2018-10-23 10:17:39 +02:00
|
|
|
data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
|
2018-10-12 10:54:26 +02:00
|
|
|
session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc);
|
|
|
|
|
EXPECT_EQ(MediaContentDescription::kSession,
|
2018-10-23 10:17:39 +02:00
|
|
|
data_desc->extmap_allow_mixed_enum());
|
2018-10-12 10:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 11:33:50 +02:00
|
|
|
// The tests for DataContentDescription will be deleted soon.
|
|
|
|
|
// TODO(bugs.webrtc.org/10597): Declare this class obsolete and remove it
|
|
|
|
|
|
2019-05-13 13:36:16 +02:00
|
|
|
TEST(SessionDescriptionTest, DataContentDescriptionCanAddStream) {
|
|
|
|
|
auto description = absl::make_unique<DataContentDescription>();
|
|
|
|
|
// Adding a stream without setting protocol first should work.
|
|
|
|
|
description->AddLegacyStream(1234);
|
|
|
|
|
EXPECT_EQ(1UL, description->streams().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest, DataContentDescriptionCopyWorks) {
|
|
|
|
|
auto description = absl::make_unique<RtpDataContentDescription>();
|
2019-05-28 11:33:50 +02:00
|
|
|
auto shim_description = description->deprecated_as_data();
|
2019-05-13 13:36:16 +02:00
|
|
|
auto shim_copy = shim_description->Copy();
|
|
|
|
|
delete shim_copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest, DataContentDescriptionCodecsCallableOnNull) {
|
|
|
|
|
auto shim_description = absl::make_unique<DataContentDescription>();
|
|
|
|
|
auto codec_list = shim_description->codecs();
|
|
|
|
|
EXPECT_EQ(0UL, codec_list.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest, DataContentDescriptionSctpConferenceMode) {
|
|
|
|
|
auto description = absl::make_unique<SctpDataContentDescription>();
|
2019-05-28 11:33:50 +02:00
|
|
|
auto shim_description = description->deprecated_as_data();
|
2019-05-13 13:36:16 +02:00
|
|
|
EXPECT_FALSE(shim_description->conference_mode());
|
|
|
|
|
shim_description->set_conference_mode(true);
|
|
|
|
|
EXPECT_TRUE(shim_description->conference_mode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest, DataContentDesriptionInSessionIsUnwrapped) {
|
|
|
|
|
auto description = absl::make_unique<DataContentDescription>();
|
|
|
|
|
// Create a DTLS object behind the shim.
|
|
|
|
|
description->set_protocol(kMediaProtocolUdpDtlsSctp);
|
|
|
|
|
SessionDescription session;
|
|
|
|
|
session.AddContent("name", MediaProtocolType::kSctp, description.release());
|
|
|
|
|
ContentInfo* content = &(session.contents()[0]);
|
|
|
|
|
ASSERT_TRUE(content);
|
|
|
|
|
ASSERT_TRUE(content->media_description()->type() == MEDIA_TYPE_DATA);
|
|
|
|
|
ASSERT_TRUE(content->media_description()->as_sctp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest,
|
|
|
|
|
DataContentDescriptionInfoSurvivesInstantiationAsSctp) {
|
|
|
|
|
auto description = absl::make_unique<DataContentDescription>();
|
|
|
|
|
description->set_rtcp_mux(true);
|
|
|
|
|
description->set_protocol(kMediaProtocolUdpDtlsSctp);
|
|
|
|
|
EXPECT_TRUE(description->rtcp_mux());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SessionDescriptionTest,
|
|
|
|
|
DataContentDescriptionStreamInfoSurvivesInstantiationAsRtp) {
|
|
|
|
|
auto description = absl::make_unique<DataContentDescription>();
|
|
|
|
|
StreamParams stream;
|
|
|
|
|
description->AddLegacyStream(1234);
|
|
|
|
|
EXPECT_EQ(1UL, description->streams().size());
|
|
|
|
|
description->set_protocol(kMediaProtocolDtlsSavpf);
|
|
|
|
|
EXPECT_EQ(1UL, description->streams().size());
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 10:54:26 +02:00
|
|
|
} // namespace cricket
|