hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 11 | #include "sdk/media_constraints.h" |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include "test/gtest.h" |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | namespace { |
| 18 | |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 19 | // Checks all settings touched by CopyConstraintsIntoRtcConfiguration, |
| 20 | // plus audio_jitter_buffer_max_packets. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 21 | bool Matches(const PeerConnectionInterface::RTCConfiguration& a, |
| 22 | const PeerConnectionInterface::RTCConfiguration& b) { |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 23 | return a.disable_ipv6 == b.disable_ipv6 && |
| 24 | a.audio_jitter_buffer_max_packets == |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 25 | b.audio_jitter_buffer_max_packets && |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 26 | a.enable_rtp_data_channel == b.enable_rtp_data_channel && |
| 27 | a.screencast_min_bitrate == b.screencast_min_bitrate && |
| 28 | a.combined_audio_video_bwe == b.combined_audio_video_bwe && |
| 29 | a.enable_dtls_srtp == b.enable_dtls_srtp && |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 30 | a.media_config == b.media_config; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 31 | } |
| 32 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 33 | TEST(MediaConstraints, CopyConstraintsIntoRtcConfiguration) { |
| 34 | const MediaConstraints constraints_empty; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 35 | PeerConnectionInterface::RTCConfiguration old_configuration; |
| 36 | PeerConnectionInterface::RTCConfiguration configuration; |
| 37 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 38 | CopyConstraintsIntoRtcConfiguration(&constraints_empty, &configuration); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 39 | EXPECT_TRUE(Matches(old_configuration, configuration)); |
| 40 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 41 | const MediaConstraints constraits_enable_ipv6( |
| 42 | {MediaConstraints::Constraint(MediaConstraints::kEnableIPv6, "true")}, |
| 43 | {}); |
| 44 | CopyConstraintsIntoRtcConfiguration(&constraits_enable_ipv6, &configuration); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 45 | EXPECT_FALSE(configuration.disable_ipv6); |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 46 | const MediaConstraints constraints_disable_ipv6( |
| 47 | {MediaConstraints::Constraint(MediaConstraints::kEnableIPv6, "false")}, |
| 48 | {}); |
| 49 | CopyConstraintsIntoRtcConfiguration(&constraints_disable_ipv6, |
| 50 | &configuration); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 51 | EXPECT_TRUE(configuration.disable_ipv6); |
| 52 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 53 | const MediaConstraints constraints_screencast( |
| 54 | {MediaConstraints::Constraint(MediaConstraints::kScreencastMinBitrate, |
| 55 | "27")}, |
| 56 | {}); |
| 57 | CopyConstraintsIntoRtcConfiguration(&constraints_screencast, &configuration); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 58 | EXPECT_TRUE(configuration.screencast_min_bitrate); |
| 59 | EXPECT_EQ(27, *(configuration.screencast_min_bitrate)); |
| 60 | |
| 61 | // An empty set of constraints will not overwrite |
| 62 | // values that are already present. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 63 | configuration = old_configuration; |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 64 | configuration.enable_dtls_srtp = true; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 65 | configuration.audio_jitter_buffer_max_packets = 34; |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 66 | CopyConstraintsIntoRtcConfiguration(&constraints_empty, &configuration); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 67 | EXPECT_EQ(34, configuration.audio_jitter_buffer_max_packets); |
| 68 | ASSERT_TRUE(configuration.enable_dtls_srtp); |
| 69 | EXPECT_TRUE(*(configuration.enable_dtls_srtp)); |
| 70 | } |
| 71 | |
| 72 | } // namespace |
| 73 | |
| 74 | } // namespace webrtc |