Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 1 | /* |
| 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 Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 10 | #include "pc/session_description.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 11 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 12 | #include "absl/memory/memory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include "test/gtest.h" |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 14 | |
| 15 | namespace cricket { |
| 16 | |
| 17 | TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) { |
| 18 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 19 | EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) { |
| 23 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 24 | 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 Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 27 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 28 | video_desc.extmap_allow_mixed_enum()); |
| 29 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 30 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 31 | video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 32 | |
| 33 | // Not allowed to downgrade from kSession to kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 34 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 35 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 36 | video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 37 | |
| 38 | // Always okay to set not supported. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 39 | 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 Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 42 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 43 | 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 Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) { |
| 49 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 50 | 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 Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | TEST(SessionDescriptionTest, SetExtmapAllowMixed) { |
| 59 | SessionDescription session_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 60 | 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 Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | TEST(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 Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 72 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 73 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 74 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 75 | |
| 76 | // Don't downgrade from session level to media level |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 77 | video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 78 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 79 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 80 | |
| 81 | // Setting false on session level propagates to media level if the current |
| 82 | // state is kSession. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 83 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 84 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 85 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 86 | |
| 87 | // Now possible to set at media level. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 88 | video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 89 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 90 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 91 | |
| 92 | // Setting false on session level does not override on media level if current |
| 93 | // state is kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 94 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 95 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 96 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 97 | |
| 98 | // Setting true on session level overrides setting on media level. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 99 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 100 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 101 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) { |
| 105 | SessionDescription session_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 106 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 107 | MediaContentDescription* audio_desc = new AudioContentDescription(); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 108 | audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 109 | |
| 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 Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 114 | audio_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 115 | |
| 116 | // If session setting is true, it's transferred to media level when new |
| 117 | // content is added. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 118 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 119 | MediaContentDescription* video_desc = new VideoContentDescription(); |
| 120 | session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc); |
| 121 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 122 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 123 | |
| 124 | // Session level setting overrides media level when new content is added. |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 125 | MediaContentDescription* data_desc = new RtpDataContentDescription; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 126 | data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 127 | session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc); |
| 128 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 129 | data_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Harald Alvestrand | a33a860 | 2019-05-28 11:33:50 +0200 | [diff] [blame] | 132 | // The tests for DataContentDescription will be deleted soon. |
| 133 | // TODO(bugs.webrtc.org/10597): Declare this class obsolete and remove it |
| 134 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 135 | TEST(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 | |
| 142 | TEST(SessionDescriptionTest, DataContentDescriptionCopyWorks) { |
| 143 | auto description = absl::make_unique<RtpDataContentDescription>(); |
Harald Alvestrand | a33a860 | 2019-05-28 11:33:50 +0200 | [diff] [blame] | 144 | auto shim_description = description->deprecated_as_data(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 145 | auto shim_copy = shim_description->Copy(); |
| 146 | delete shim_copy; |
| 147 | } |
| 148 | |
| 149 | TEST(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 | |
| 155 | TEST(SessionDescriptionTest, DataContentDescriptionSctpConferenceMode) { |
| 156 | auto description = absl::make_unique<SctpDataContentDescription>(); |
Harald Alvestrand | a33a860 | 2019-05-28 11:33:50 +0200 | [diff] [blame] | 157 | auto shim_description = description->deprecated_as_data(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 158 | EXPECT_FALSE(shim_description->conference_mode()); |
| 159 | shim_description->set_conference_mode(true); |
| 160 | EXPECT_TRUE(shim_description->conference_mode()); |
| 161 | } |
| 162 | |
| 163 | TEST(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 | |
| 175 | TEST(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 | |
| 183 | TEST(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 Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 193 | } // namespace cricket |