blob: eda83a5a716f62e235381cc9b40bff7ff2a9a256 [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;
Harald Alvestrand1716d392019-06-03 20:35:45 +020068 session_desc.AddContent("video", MediaProtocolType::kRtp,
69 absl::make_unique<VideoContentDescription>());
70 MediaContentDescription* video_desc =
71 session_desc.GetContentDescriptionByName("video");
Johannes Kron9ac3c912018-10-12 10:54:26 +020072
73 // Setting true on session level propagates to media level.
Johannes Kron9581bc42018-10-23 10:17:39 +020074 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +020075 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020076 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020077
78 // Don't downgrade from session level to media level
Johannes Kron9581bc42018-10-23 10:17:39 +020079 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020080 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020081 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020082
83 // Setting false on session level propagates to media level if the current
84 // state is kSession.
Johannes Kron9581bc42018-10-23 10:17:39 +020085 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +020086 EXPECT_EQ(MediaContentDescription::kNo,
Johannes Kron9581bc42018-10-23 10:17:39 +020087 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020088
89 // Now possible to set at media level.
Johannes Kron9581bc42018-10-23 10:17:39 +020090 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020091 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020092 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020093
94 // Setting false on session level does not override on media level if current
95 // state is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +020096 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +020097 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020098 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020099
100 // Setting true on session level overrides setting on media level.
Johannes Kron9581bc42018-10-23 10:17:39 +0200101 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200102 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +0200103 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200104}
105
106TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
107 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +0200108 session_desc.set_extmap_allow_mixed(false);
Harald Alvestrand1716d392019-06-03 20:35:45 +0200109 std::unique_ptr<MediaContentDescription> audio_desc =
110 absl::make_unique<AudioContentDescription>();
Johannes Kron9581bc42018-10-23 10:17:39 +0200111 audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200112
113 // If session setting is false, media level setting is preserved when new
114 // content is added.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200115 session_desc.AddContent("audio", MediaProtocolType::kRtp,
116 std::move(audio_desc));
Johannes Kron9ac3c912018-10-12 10:54:26 +0200117 EXPECT_EQ(MediaContentDescription::kMedia,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200118 session_desc.GetContentDescriptionByName("audio")
119 ->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200120
121 // If session setting is true, it's transferred to media level when new
122 // content is added.
Johannes Kron9581bc42018-10-23 10:17:39 +0200123 session_desc.set_extmap_allow_mixed(true);
Harald Alvestrand1716d392019-06-03 20:35:45 +0200124 std::unique_ptr<MediaContentDescription> video_desc =
125 absl::make_unique<VideoContentDescription>();
126 session_desc.AddContent("video", MediaProtocolType::kRtp,
127 std::move(video_desc));
Johannes Kron9ac3c912018-10-12 10:54:26 +0200128 EXPECT_EQ(MediaContentDescription::kSession,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200129 session_desc.GetContentDescriptionByName("video")
130 ->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200131
132 // Session level setting overrides media level when new content is added.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200133 std::unique_ptr<MediaContentDescription> data_desc =
134 absl::make_unique<RtpDataContentDescription>();
Johannes Kron9581bc42018-10-23 10:17:39 +0200135 data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Harald Alvestrand1716d392019-06-03 20:35:45 +0200136 session_desc.AddContent("data", MediaProtocolType::kRtp,
137 std::move(data_desc));
Johannes Kron9ac3c912018-10-12 10:54:26 +0200138 EXPECT_EQ(MediaContentDescription::kSession,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200139 session_desc.GetContentDescriptionByName("data")
140 ->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200141}
142
Harald Alvestranda33a8602019-05-28 11:33:50 +0200143// The tests for DataContentDescription will be deleted soon.
144// TODO(bugs.webrtc.org/10597): Declare this class obsolete and remove it
145
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200146TEST(SessionDescriptionTest, DataContentDescriptionCanAddStream) {
147 auto description = absl::make_unique<DataContentDescription>();
148 // Adding a stream without setting protocol first should work.
149 description->AddLegacyStream(1234);
150 EXPECT_EQ(1UL, description->streams().size());
151}
152
153TEST(SessionDescriptionTest, DataContentDescriptionCopyWorks) {
154 auto description = absl::make_unique<RtpDataContentDescription>();
Harald Alvestranda33a8602019-05-28 11:33:50 +0200155 auto shim_description = description->deprecated_as_data();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200156 auto shim_copy = shim_description->Copy();
157 delete shim_copy;
158}
159
160TEST(SessionDescriptionTest, DataContentDescriptionCodecsCallableOnNull) {
161 auto shim_description = absl::make_unique<DataContentDescription>();
162 auto codec_list = shim_description->codecs();
163 EXPECT_EQ(0UL, codec_list.size());
164}
165
166TEST(SessionDescriptionTest, DataContentDescriptionSctpConferenceMode) {
167 auto description = absl::make_unique<SctpDataContentDescription>();
Harald Alvestranda33a8602019-05-28 11:33:50 +0200168 auto shim_description = description->deprecated_as_data();
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200169 EXPECT_FALSE(shim_description->conference_mode());
170 shim_description->set_conference_mode(true);
171 EXPECT_TRUE(shim_description->conference_mode());
172}
173
174TEST(SessionDescriptionTest, DataContentDesriptionInSessionIsUnwrapped) {
175 auto description = absl::make_unique<DataContentDescription>();
176 // Create a DTLS object behind the shim.
177 description->set_protocol(kMediaProtocolUdpDtlsSctp);
178 SessionDescription session;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200179 session.AddContent("name", MediaProtocolType::kSctp, std::move(description));
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200180 ContentInfo* content = &(session.contents()[0]);
181 ASSERT_TRUE(content);
182 ASSERT_TRUE(content->media_description()->type() == MEDIA_TYPE_DATA);
183 ASSERT_TRUE(content->media_description()->as_sctp());
184}
185
186TEST(SessionDescriptionTest,
187 DataContentDescriptionInfoSurvivesInstantiationAsSctp) {
188 auto description = absl::make_unique<DataContentDescription>();
189 description->set_rtcp_mux(true);
190 description->set_protocol(kMediaProtocolUdpDtlsSctp);
191 EXPECT_TRUE(description->rtcp_mux());
192}
193
194TEST(SessionDescriptionTest,
195 DataContentDescriptionStreamInfoSurvivesInstantiationAsRtp) {
196 auto description = absl::make_unique<DataContentDescription>();
197 StreamParams stream;
198 description->AddLegacyStream(1234);
199 EXPECT_EQ(1UL, description->streams().size());
200 description->set_protocol(kMediaProtocolDtlsSavpf);
201 EXPECT_EQ(1UL, description->streams().size());
202}
203
Johannes Kron9ac3c912018-10-12 10:54:26 +0200204} // namespace cricket