blob: d9426c8348d702e44cfaf847866ef384d7589dc5 [file] [log] [blame]
Johannes Kron9ac3c912018-10-12 10:54:26 +02001/*
2 * Copyright 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Steve Anton10542f22019-01-11 09:11:00 -080010#include "pc/session_description.h"
Yves Gerey3e707812018-11-28 16:47:49 +010011
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020012#include "absl/memory/memory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010013#include "test/gtest.h"
Johannes Kron9ac3c912018-10-12 10:54:26 +020014
15namespace cricket {
16
17TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) {
18 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020019 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020020}
21
22TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) {
23 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020024 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
25 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
26 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020027 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020028 video_desc.extmap_allow_mixed_enum());
29 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
Johannes Kron9ac3c912018-10-12 10:54:26 +020030 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020031 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020032
33 // Not allowed to downgrade from kSession to kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +020034 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020035 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020036 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020037
38 // Always okay to set not supported.
Johannes Kron9581bc42018-10-23 10:17:39 +020039 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
40 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
41 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020042 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020043 video_desc.extmap_allow_mixed_enum());
44 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
45 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020046}
47
48TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) {
49 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020050 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
51 EXPECT_FALSE(video_desc.extmap_allow_mixed());
52 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
53 EXPECT_TRUE(video_desc.extmap_allow_mixed());
54 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
55 EXPECT_TRUE(video_desc.extmap_allow_mixed());
Johannes Kron9ac3c912018-10-12 10:54:26 +020056}
57
58TEST(SessionDescriptionTest, SetExtmapAllowMixed) {
59 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020060 session_desc.set_extmap_allow_mixed(true);
61 EXPECT_TRUE(session_desc.extmap_allow_mixed());
62 session_desc.set_extmap_allow_mixed(false);
63 EXPECT_FALSE(session_desc.extmap_allow_mixed());
Johannes Kron9ac3c912018-10-12 10:54:26 +020064}
65
66TEST(SessionDescriptionTest, SetExtmapAllowMixedPropagatesToMediaLevel) {
67 SessionDescription session_desc;
68 MediaContentDescription* video_desc = new VideoContentDescription();
69 session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
70
71 // Setting true on session level propagates to media level.
Johannes Kron9581bc42018-10-23 10:17:39 +020072 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +020073 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020074 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020075
76 // Don't downgrade from session level to media level
Johannes Kron9581bc42018-10-23 10:17:39 +020077 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020078 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020079 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020080
81 // Setting false on session level propagates to media level if the current
82 // state is kSession.
Johannes Kron9581bc42018-10-23 10:17:39 +020083 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +020084 EXPECT_EQ(MediaContentDescription::kNo,
Johannes Kron9581bc42018-10-23 10:17:39 +020085 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020086
87 // Now possible to set at media level.
Johannes Kron9581bc42018-10-23 10:17:39 +020088 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020089 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020090 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020091
92 // Setting false on session level does not override on media level if current
93 // state is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +020094 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +020095 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020096 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020097
98 // Setting true on session level overrides setting on media level.
Johannes Kron9581bc42018-10-23 10:17:39 +020099 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200100 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +0200101 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200102}
103
104TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
105 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +0200106 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200107 MediaContentDescription* audio_desc = new AudioContentDescription();
Johannes Kron9581bc42018-10-23 10:17:39 +0200108 audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200109
110 // If session setting is false, media level setting is preserved when new
111 // content is added.
112 session_desc.AddContent("audio", MediaProtocolType::kRtp, audio_desc);
113 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +0200114 audio_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200115
116 // If session setting is true, it's transferred to media level when new
117 // content is added.
Johannes Kron9581bc42018-10-23 10:17:39 +0200118 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200119 MediaContentDescription* video_desc = new VideoContentDescription();
120 session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
121 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +0200122 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200123
124 // Session level setting overrides media level when new content is added.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200125 MediaContentDescription* data_desc = new RtpDataContentDescription;
Johannes Kron9581bc42018-10-23 10:17:39 +0200126 data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200127 session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc);
128 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +0200129 data_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200130}
131
Harald Alvestranda33a8602019-05-28 11:33:50 +0200132// The tests for DataContentDescription will be deleted soon.
133// TODO(bugs.webrtc.org/10597): Declare this class obsolete and remove it
134
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200135TEST(SessionDescriptionTest, DataContentDescriptionCanAddStream) {
136 auto description = absl::make_unique<DataContentDescription>();
137 // Adding a stream without setting protocol first should work.
138 description->AddLegacyStream(1234);
139 EXPECT_EQ(1UL, description->streams().size());
140}
141
142TEST(SessionDescriptionTest, DataContentDescriptionCopyWorks) {
143 auto description = absl::make_unique<RtpDataContentDescription>();
Harald Alvestranda33a8602019-05-28 11:33:50 +0200144 auto shim_description = description->deprecated_as_data();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200145 auto shim_copy = shim_description->Copy();
146 delete shim_copy;
147}
148
149TEST(SessionDescriptionTest, DataContentDescriptionCodecsCallableOnNull) {
150 auto shim_description = absl::make_unique<DataContentDescription>();
151 auto codec_list = shim_description->codecs();
152 EXPECT_EQ(0UL, codec_list.size());
153}
154
155TEST(SessionDescriptionTest, DataContentDescriptionSctpConferenceMode) {
156 auto description = absl::make_unique<SctpDataContentDescription>();
Harald Alvestranda33a8602019-05-28 11:33:50 +0200157 auto shim_description = description->deprecated_as_data();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200158 EXPECT_FALSE(shim_description->conference_mode());
159 shim_description->set_conference_mode(true);
160 EXPECT_TRUE(shim_description->conference_mode());
161}
162
163TEST(SessionDescriptionTest, DataContentDesriptionInSessionIsUnwrapped) {
164 auto description = absl::make_unique<DataContentDescription>();
165 // Create a DTLS object behind the shim.
166 description->set_protocol(kMediaProtocolUdpDtlsSctp);
167 SessionDescription session;
168 session.AddContent("name", MediaProtocolType::kSctp, description.release());
169 ContentInfo* content = &(session.contents()[0]);
170 ASSERT_TRUE(content);
171 ASSERT_TRUE(content->media_description()->type() == MEDIA_TYPE_DATA);
172 ASSERT_TRUE(content->media_description()->as_sctp());
173}
174
175TEST(SessionDescriptionTest,
176 DataContentDescriptionInfoSurvivesInstantiationAsSctp) {
177 auto description = absl::make_unique<DataContentDescription>();
178 description->set_rtcp_mux(true);
179 description->set_protocol(kMediaProtocolUdpDtlsSctp);
180 EXPECT_TRUE(description->rtcp_mux());
181}
182
183TEST(SessionDescriptionTest,
184 DataContentDescriptionStreamInfoSurvivesInstantiationAsRtp) {
185 auto description = absl::make_unique<DataContentDescription>();
186 StreamParams stream;
187 description->AddLegacyStream(1234);
188 EXPECT_EQ(1UL, description->streams().size());
189 description->set_protocol(kMediaProtocolDtlsSavpf);
190 EXPECT_EQ(1UL, description->streams().size());
191}
192
Johannes Kron9ac3c912018-10-12 10:54:26 +0200193} // namespace cricket