blob: 9797ed562786eb39d9187cf56c436fdcf14c4f55 [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 Alvestrand5fc28b12019-05-13 13:36:16 +0200132TEST(SessionDescriptionTest, DataContentDescriptionCanAddStream) {
133 auto description = absl::make_unique<DataContentDescription>();
134 // Adding a stream without setting protocol first should work.
135 description->AddLegacyStream(1234);
136 EXPECT_EQ(1UL, description->streams().size());
137}
138
139TEST(SessionDescriptionTest, DataContentDescriptionCopyWorks) {
140 auto description = absl::make_unique<RtpDataContentDescription>();
141 auto shim_description = description->as_data();
142 auto shim_copy = shim_description->Copy();
143 delete shim_copy;
144}
145
146TEST(SessionDescriptionTest, DataContentDescriptionCodecsCallableOnNull) {
147 auto shim_description = absl::make_unique<DataContentDescription>();
148 auto codec_list = shim_description->codecs();
149 EXPECT_EQ(0UL, codec_list.size());
150}
151
152TEST(SessionDescriptionTest, DataContentDescriptionSctpConferenceMode) {
153 auto description = absl::make_unique<SctpDataContentDescription>();
154 auto shim_description = description->as_data();
155 EXPECT_FALSE(shim_description->conference_mode());
156 shim_description->set_conference_mode(true);
157 EXPECT_TRUE(shim_description->conference_mode());
158}
159
160TEST(SessionDescriptionTest, DataContentDesriptionInSessionIsUnwrapped) {
161 auto description = absl::make_unique<DataContentDescription>();
162 // Create a DTLS object behind the shim.
163 description->set_protocol(kMediaProtocolUdpDtlsSctp);
164 SessionDescription session;
165 session.AddContent("name", MediaProtocolType::kSctp, description.release());
166 ContentInfo* content = &(session.contents()[0]);
167 ASSERT_TRUE(content);
168 ASSERT_TRUE(content->media_description()->type() == MEDIA_TYPE_DATA);
169 ASSERT_TRUE(content->media_description()->as_sctp());
170}
171
172TEST(SessionDescriptionTest,
173 DataContentDescriptionInfoSurvivesInstantiationAsSctp) {
174 auto description = absl::make_unique<DataContentDescription>();
175 description->set_rtcp_mux(true);
176 description->set_protocol(kMediaProtocolUdpDtlsSctp);
177 EXPECT_TRUE(description->rtcp_mux());
178}
179
180TEST(SessionDescriptionTest,
181 DataContentDescriptionStreamInfoSurvivesInstantiationAsRtp) {
182 auto description = absl::make_unique<DataContentDescription>();
183 StreamParams stream;
184 description->AddLegacyStream(1234);
185 EXPECT_EQ(1UL, description->streams().size());
186 description->set_protocol(kMediaProtocolDtlsSavpf);
187 EXPECT_EQ(1UL, description->streams().size());
188}
189
Johannes Kron9ac3c912018-10-12 10:54:26 +0200190} // namespace cricket