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 | |
| 12 | #include "test/gtest.h" |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 13 | |
| 14 | namespace cricket { |
| 15 | |
| 16 | TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) { |
| 17 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 18 | EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) { |
| 22 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 23 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 24 | EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum()); |
| 25 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 26 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 27 | video_desc.extmap_allow_mixed_enum()); |
| 28 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 29 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 30 | video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 31 | |
| 32 | // Not allowed to downgrade from kSession to kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 33 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 34 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 35 | video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 36 | |
| 37 | // Always okay to set not supported. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 38 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 39 | EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum()); |
| 40 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 41 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 42 | video_desc.extmap_allow_mixed_enum()); |
| 43 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 44 | EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) { |
| 48 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 49 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 50 | EXPECT_FALSE(video_desc.extmap_allow_mixed()); |
| 51 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
| 52 | EXPECT_TRUE(video_desc.extmap_allow_mixed()); |
| 53 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession); |
| 54 | EXPECT_TRUE(video_desc.extmap_allow_mixed()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | TEST(SessionDescriptionTest, SetExtmapAllowMixed) { |
| 58 | SessionDescription session_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 59 | session_desc.set_extmap_allow_mixed(true); |
| 60 | EXPECT_TRUE(session_desc.extmap_allow_mixed()); |
| 61 | session_desc.set_extmap_allow_mixed(false); |
| 62 | EXPECT_FALSE(session_desc.extmap_allow_mixed()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | TEST(SessionDescriptionTest, SetExtmapAllowMixedPropagatesToMediaLevel) { |
| 66 | SessionDescription session_desc; |
| 67 | MediaContentDescription* video_desc = new VideoContentDescription(); |
| 68 | session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc); |
| 69 | |
| 70 | // Setting true on session level propagates to media level. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 71 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 72 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 73 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 74 | |
| 75 | // Don't downgrade from session level to media level |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 76 | video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 77 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 78 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 79 | |
| 80 | // Setting false on session level propagates to media level if the current |
| 81 | // state is kSession. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 82 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 83 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 84 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 85 | |
| 86 | // Now possible to set at media level. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 87 | video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 88 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 89 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 90 | |
| 91 | // Setting false on session level does not override on media level if current |
| 92 | // state is kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 93 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 94 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 95 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 96 | |
| 97 | // Setting true on session level overrides setting on media level. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 98 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 99 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 100 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) { |
| 104 | SessionDescription session_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 105 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 106 | MediaContentDescription* audio_desc = new AudioContentDescription(); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 107 | audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 108 | |
| 109 | // If session setting is false, media level setting is preserved when new |
| 110 | // content is added. |
| 111 | session_desc.AddContent("audio", MediaProtocolType::kRtp, audio_desc); |
| 112 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 113 | audio_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 114 | |
| 115 | // If session setting is true, it's transferred to media level when new |
| 116 | // content is added. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 117 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 118 | MediaContentDescription* video_desc = new VideoContentDescription(); |
| 119 | session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc); |
| 120 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 121 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 122 | |
| 123 | // Session level setting overrides media level when new content is added. |
Steve Anton | 46afbf9 | 2019-05-10 11:15:18 -0700 | [diff] [blame] | 124 | MediaContentDescription* data_desc = new DataContentDescription; |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 125 | data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 126 | session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc); |
| 127 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 128 | data_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Johannes Kron | 9ac3c91 | 2018-10-12 10:54:26 +0200 | [diff] [blame] | 131 | } // namespace cricket |