blob: 75e0974ecd3580f41e48a590925ddb4598de12c9 [file] [log] [blame]
Johannes Kron9ac3c912018-10-12 08:54:261/*
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 17:11:0010#include "pc/session_description.h"
Yves Gerey3e707812018-11-28 15:47:4911
Mirko Bonadei317a1f02019-09-17 15:06:1812#include <memory>
13
Yves Gerey3e707812018-11-28 15:47:4914#include "test/gtest.h"
Johannes Kron9ac3c912018-10-12 08:54:2615
16namespace cricket {
17
18TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) {
19 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 08:17:3920 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2621}
22
23TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) {
24 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 08:17:3925 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);
Johannes Kron9ac3c912018-10-12 08:54:2628 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3929 video_desc.extmap_allow_mixed_enum());
30 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
Johannes Kron9ac3c912018-10-12 08:54:2631 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3932 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2633
34 // Not allowed to downgrade from kSession to kMedia.
Johannes Kron9581bc42018-10-23 08:17:3935 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2636 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3937 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2638
39 // Always okay to set not supported.
Johannes Kron9581bc42018-10-23 08:17:3940 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);
Johannes Kron9ac3c912018-10-12 08:54:2643 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3944 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());
Johannes Kron9ac3c912018-10-12 08:54:2647}
48
49TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) {
50 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 08:17:3951 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());
Johannes Kron9ac3c912018-10-12 08:54:2657}
58
59TEST(SessionDescriptionTest, SetExtmapAllowMixed) {
60 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 08:17:3961 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());
Johannes Kron9ac3c912018-10-12 08:54:2665}
66
67TEST(SessionDescriptionTest, SetExtmapAllowMixedPropagatesToMediaLevel) {
68 SessionDescription session_desc;
Harald Alvestrand1716d392019-06-03 18:35:4569 session_desc.AddContent("video", MediaProtocolType::kRtp,
Mirko Bonadei317a1f02019-09-17 15:06:1870 std::make_unique<VideoContentDescription>());
Harald Alvestrand1716d392019-06-03 18:35:4571 MediaContentDescription* video_desc =
72 session_desc.GetContentDescriptionByName("video");
Johannes Kron9ac3c912018-10-12 08:54:2673
74 // Setting true on session level propagates to media level.
Johannes Kron9581bc42018-10-23 08:17:3975 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 08:54:2676 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3977 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2678
79 // Don't downgrade from session level to media level
Johannes Kron9581bc42018-10-23 08:17:3980 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2681 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3982 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2683
84 // Setting false on session level propagates to media level if the current
85 // state is kSession.
Johannes Kron9581bc42018-10-23 08:17:3986 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 08:54:2687 EXPECT_EQ(MediaContentDescription::kNo,
Johannes Kron9581bc42018-10-23 08:17:3988 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2689
90 // Now possible to set at media level.
Johannes Kron9581bc42018-10-23 08:17:3991 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2692 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3993 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2694
95 // Setting false on session level does not override on media level if current
96 // state is kMedia.
Johannes Kron9581bc42018-10-23 08:17:3997 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 08:54:2698 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3999 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26100
101 // Setting true on session level overrides setting on media level.
Johannes Kron9581bc42018-10-23 08:17:39102 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 08:54:26103 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:39104 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26105}
106
107TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
108 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 08:17:39109 session_desc.set_extmap_allow_mixed(false);
Harald Alvestrand1716d392019-06-03 18:35:45110 std::unique_ptr<MediaContentDescription> audio_desc =
Mirko Bonadei317a1f02019-09-17 15:06:18111 std::make_unique<AudioContentDescription>();
Johannes Kron9581bc42018-10-23 08:17:39112 audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:26113
114 // If session setting is false, media level setting is preserved when new
115 // content is added.
Harald Alvestrand1716d392019-06-03 18:35:45116 session_desc.AddContent("audio", MediaProtocolType::kRtp,
117 std::move(audio_desc));
Johannes Kron9ac3c912018-10-12 08:54:26118 EXPECT_EQ(MediaContentDescription::kMedia,
Harald Alvestrand1716d392019-06-03 18:35:45119 session_desc.GetContentDescriptionByName("audio")
120 ->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26121
122 // If session setting is true, it's transferred to media level when new
123 // content is added.
Johannes Kron9581bc42018-10-23 08:17:39124 session_desc.set_extmap_allow_mixed(true);
Harald Alvestrand1716d392019-06-03 18:35:45125 std::unique_ptr<MediaContentDescription> video_desc =
Mirko Bonadei317a1f02019-09-17 15:06:18126 std::make_unique<VideoContentDescription>();
Harald Alvestrand1716d392019-06-03 18:35:45127 session_desc.AddContent("video", MediaProtocolType::kRtp,
128 std::move(video_desc));
Johannes Kron9ac3c912018-10-12 08:54:26129 EXPECT_EQ(MediaContentDescription::kSession,
Harald Alvestrand1716d392019-06-03 18:35:45130 session_desc.GetContentDescriptionByName("video")
131 ->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26132
133 // Session level setting overrides media level when new content is added.
Harald Alvestrand1716d392019-06-03 18:35:45134 std::unique_ptr<MediaContentDescription> data_desc =
Mirko Bonadei317a1f02019-09-17 15:06:18135 std::make_unique<RtpDataContentDescription>();
Johannes Kron9581bc42018-10-23 08:17:39136 data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Harald Alvestrand1716d392019-06-03 18:35:45137 session_desc.AddContent("data", MediaProtocolType::kRtp,
138 std::move(data_desc));
Johannes Kron9ac3c912018-10-12 08:54:26139 EXPECT_EQ(MediaContentDescription::kSession,
Harald Alvestrand1716d392019-06-03 18:35:45140 session_desc.GetContentDescriptionByName("data")
141 ->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26142}
143
Johannes Kron9ac3c912018-10-12 08:54:26144} // namespace cricket