blob: 3b05dca38196f0b857b20064cf983517a1e275da [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
12#include "test/gtest.h"
Johannes Kron9ac3c912018-10-12 10:54:26 +020013
14namespace cricket {
15
16TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) {
17 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020018 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020019}
20
21TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) {
22 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020023 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 Kron9ac3c912018-10-12 10:54:26 +020026 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020027 video_desc.extmap_allow_mixed_enum());
28 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
Johannes Kron9ac3c912018-10-12 10:54:26 +020029 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020030 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020031
32 // Not allowed to downgrade from kSession to kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +020033 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020034 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020035 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020036
37 // Always okay to set not supported.
Johannes Kron9581bc42018-10-23 10:17:39 +020038 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 Kron9ac3c912018-10-12 10:54:26 +020041 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020042 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 Kron9ac3c912018-10-12 10:54:26 +020045}
46
47TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) {
48 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020049 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 Kron9ac3c912018-10-12 10:54:26 +020055}
56
57TEST(SessionDescriptionTest, SetExtmapAllowMixed) {
58 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +020059 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 Kron9ac3c912018-10-12 10:54:26 +020063}
64
65TEST(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 Kron9581bc42018-10-23 10:17:39 +020071 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +020072 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020073 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020074
75 // Don't downgrade from session level to media level
Johannes Kron9581bc42018-10-23 10:17:39 +020076 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020077 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +020078 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020079
80 // Setting false on session level propagates to media level if the current
81 // state is kSession.
Johannes Kron9581bc42018-10-23 10:17:39 +020082 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +020083 EXPECT_EQ(MediaContentDescription::kNo,
Johannes Kron9581bc42018-10-23 10:17:39 +020084 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020085
86 // Now possible to set at media level.
Johannes Kron9581bc42018-10-23 10:17:39 +020087 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +020088 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020089 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020090
91 // Setting false on session level does not override on media level if current
92 // state is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +020093 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +020094 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 10:17:39 +020095 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +020096
97 // Setting true on session level overrides setting on media level.
Johannes Kron9581bc42018-10-23 10:17:39 +020098 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +020099 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +0200100 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200101}
102
103TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
104 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 10:17:39 +0200105 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200106 MediaContentDescription* audio_desc = new AudioContentDescription();
Johannes Kron9581bc42018-10-23 10:17:39 +0200107 audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200108
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 Kron9581bc42018-10-23 10:17:39 +0200113 audio_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200114
115 // If session setting is true, it's transferred to media level when new
116 // content is added.
Johannes Kron9581bc42018-10-23 10:17:39 +0200117 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200118 MediaContentDescription* video_desc = new VideoContentDescription();
119 session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
120 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +0200121 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200122
123 // Session level setting overrides media level when new content is added.
Steve Anton46afbf92019-05-10 11:15:18 -0700124 MediaContentDescription* data_desc = new DataContentDescription;
Johannes Kron9581bc42018-10-23 10:17:39 +0200125 data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200126 session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc);
127 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 10:17:39 +0200128 data_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 10:54:26 +0200129}
130
Johannes Kron9ac3c912018-10-12 10:54:26 +0200131} // namespace cricket