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