henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 11 | #include <algorithm> |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 12 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | #include <string> |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 14 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 17 | #include "absl/algorithm/container.h" |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 18 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "media/base/test_utils.h" |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 21 | #include "media/sctp/sctp_transport_internal.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "p2p/base/p2p_constants.h" |
| 23 | #include "p2p/base/transport_description.h" |
| 24 | #include "p2p/base/transport_info.h" |
| 25 | #include "pc/media_session.h" |
| 26 | #include "pc/rtp_media_utils.h" |
| 27 | #include "pc/srtp_filter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 29 | #include "rtc_base/fake_ssl_identity.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "rtc_base/message_digest.h" |
| 32 | #include "rtc_base/ssl_adapter.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 33 | #include "rtc_base/strings/string_builder.h" |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 34 | #include "rtc_base/unique_id_generator.h" |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 35 | #include "test/gmock.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 37 | #define ASSERT_CRYPTO(cd, s, cs) \ |
| 38 | ASSERT_EQ(s, cd->cryptos().size()); \ |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 39 | ASSERT_EQ(cs, cd->cryptos()[0].cipher_suite) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
| 41 | typedef std::vector<cricket::Candidate> Candidates; |
| 42 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 43 | using cricket::AudioCodec; |
| 44 | using cricket::AudioContentDescription; |
| 45 | using cricket::ContentInfo; |
| 46 | using cricket::CryptoParamsVec; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 47 | using cricket::GetFirstAudioContent; |
| 48 | using cricket::GetFirstAudioContentDescription; |
| 49 | using cricket::GetFirstDataContent; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 50 | using cricket::GetFirstRtpDataContentDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 51 | using cricket::GetFirstVideoContent; |
| 52 | using cricket::GetFirstVideoContentDescription; |
| 53 | using cricket::kAutoBandwidth; |
| 54 | using cricket::MEDIA_TYPE_AUDIO; |
| 55 | using cricket::MEDIA_TYPE_DATA; |
| 56 | using cricket::MEDIA_TYPE_VIDEO; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | using cricket::MediaContentDescription; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 58 | using cricket::MediaDescriptionOptions; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 59 | using cricket::MediaProtocolType; |
| 60 | using cricket::MediaSessionDescriptionFactory; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | using cricket::MediaSessionOptions; |
| 62 | using cricket::MediaType; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 63 | using cricket::RidDescription; |
| 64 | using cricket::RidDirection; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 65 | using cricket::RtpDataCodec; |
| 66 | using cricket::RtpDataContentDescription; |
| 67 | using cricket::SctpDataContentDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 68 | using cricket::SEC_DISABLED; |
| 69 | using cricket::SEC_ENABLED; |
| 70 | using cricket::SEC_REQUIRED; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | using cricket::SessionDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 72 | using cricket::SimulcastDescription; |
| 73 | using cricket::SimulcastLayer; |
| 74 | using cricket::SimulcastLayerList; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | using cricket::SsrcGroup; |
| 76 | using cricket::StreamParams; |
| 77 | using cricket::StreamParamsVec; |
| 78 | using cricket::TransportDescription; |
| 79 | using cricket::TransportDescriptionFactory; |
| 80 | using cricket::TransportInfo; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | using cricket::VideoCodec; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 82 | using cricket::VideoContentDescription; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 83 | using rtc::CS_AEAD_AES_128_GCM; |
| 84 | using rtc::CS_AEAD_AES_256_GCM; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 85 | using rtc::CS_AES_CM_128_HMAC_SHA1_32; |
| 86 | using rtc::CS_AES_CM_128_HMAC_SHA1_80; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 87 | using rtc::UniqueRandomIdGenerator; |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 88 | using ::testing::Contains; |
| 89 | using ::testing::Each; |
| 90 | using ::testing::ElementsAreArray; |
| 91 | using ::testing::Eq; |
| 92 | using ::testing::Field; |
| 93 | using ::testing::IsEmpty; |
| 94 | using ::testing::IsFalse; |
| 95 | using ::testing::Ne; |
| 96 | using ::testing::Not; |
| 97 | using ::testing::Pointwise; |
| 98 | using ::testing::SizeIs; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 99 | using webrtc::RtpExtension; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 100 | using webrtc::RtpTransceiverDirection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | |
| 102 | static const AudioCodec kAudioCodecs1[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 103 | AudioCodec(103, "ISAC", 16000, -1, 1), |
| 104 | AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 105 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
| 106 | AudioCodec(8, "PCMA", 8000, 64000, 1), |
| 107 | AudioCodec(117, "red", 8000, 0, 1), |
| 108 | AudioCodec(107, "CN", 48000, 0, 1)}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | |
| 110 | static const AudioCodec kAudioCodecs2[] = { |
Henrik Lundin | f8ed561 | 2018-05-07 12:05:57 +0200 | [diff] [blame] | 111 | AudioCodec(126, "foo", 16000, 22000, 1), |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 112 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
| 113 | AudioCodec(127, "iLBC", 8000, 13300, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static const AudioCodec kAudioCodecsAnswer[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 117 | AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 118 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 121 | static const VideoCodec kVideoCodecs1[] = {VideoCodec(96, "H264-SVC"), |
| 122 | VideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 124 | static const VideoCodec kVideoCodecs1Reverse[] = {VideoCodec(97, "H264"), |
| 125 | VideoCodec(96, "H264-SVC")}; |
| 126 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 127 | static const VideoCodec kVideoCodecs2[] = {VideoCodec(126, "H264"), |
| 128 | VideoCodec(127, "H263")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 130 | static const VideoCodec kVideoCodecsAnswer[] = {VideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 132 | static const RtpDataCodec kDataCodecs1[] = {RtpDataCodec(98, "binary-data"), |
| 133 | RtpDataCodec(99, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 134 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 135 | static const RtpDataCodec kDataCodecs2[] = {RtpDataCodec(126, "binary-data"), |
| 136 | RtpDataCodec(127, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 138 | static const RtpDataCodec kDataCodecsAnswer[] = { |
| 139 | RtpDataCodec(98, "binary-data"), RtpDataCodec(99, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 141 | static const RtpExtension kAudioRtpExtension1[] = { |
| 142 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 143 | RtpExtension("http://google.com/testing/audio_something", 10), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 146 | static const RtpExtension kAudioRtpExtensionEncrypted1[] = { |
| 147 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 148 | RtpExtension("http://google.com/testing/audio_something", 10), |
| 149 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
| 150 | }; |
| 151 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 152 | static const RtpExtension kAudioRtpExtension2[] = { |
| 153 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 2), |
| 154 | RtpExtension("http://google.com/testing/audio_something_else", 8), |
| 155 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 158 | static const RtpExtension kAudioRtpExtension3[] = { |
| 159 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 160 | RtpExtension("http://google.com/testing/both_audio_and_video", 3), |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 163 | static const RtpExtension kAudioRtpExtension3ForEncryption[] = { |
| 164 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 165 | // Use RTP extension that supports encryption. |
| 166 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 167 | }; |
| 168 | |
| 169 | static const RtpExtension kAudioRtpExtension3ForEncryptionOffer[] = { |
| 170 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 171 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 172 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14, true), |
| 173 | }; |
| 174 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 175 | static const RtpExtension kAudioRtpExtensionAnswer[] = { |
| 176 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 179 | static const RtpExtension kAudioRtpExtensionEncryptedAnswer[] = { |
| 180 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
| 181 | }; |
| 182 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 183 | static const RtpExtension kVideoRtpExtension1[] = { |
| 184 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 185 | RtpExtension("http://google.com/testing/video_something", 13), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 188 | static const RtpExtension kVideoRtpExtensionEncrypted1[] = { |
| 189 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 190 | RtpExtension("http://google.com/testing/video_something", 13), |
| 191 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 11, true), |
| 192 | }; |
| 193 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 194 | static const RtpExtension kVideoRtpExtension2[] = { |
| 195 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 2), |
| 196 | RtpExtension("http://google.com/testing/video_something_else", 14), |
| 197 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 198 | }; |
| 199 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 200 | static const RtpExtension kVideoRtpExtension3[] = { |
| 201 | RtpExtension("http://google.com/testing/video_something", 4), |
| 202 | RtpExtension("http://google.com/testing/both_audio_and_video", 5), |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 205 | static const RtpExtension kVideoRtpExtension3ForEncryption[] = { |
| 206 | RtpExtension("http://google.com/testing/video_something", 4), |
| 207 | // Use RTP extension that supports encryption. |
| 208 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 5), |
| 209 | }; |
| 210 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 211 | static const RtpExtension kVideoRtpExtensionAnswer[] = { |
| 212 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 215 | static const RtpExtension kVideoRtpExtensionEncryptedAnswer[] = { |
| 216 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 11, true), |
| 217 | }; |
| 218 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 219 | static const RtpExtension kRtpExtensionTransportSequenceNumber01[] = { |
| 220 | RtpExtension("http://www.ietf.org/id/" |
| 221 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 222 | 1), |
| 223 | }; |
| 224 | |
| 225 | static const RtpExtension kRtpExtensionTransportSequenceNumber01And02[] = { |
| 226 | RtpExtension("http://www.ietf.org/id/" |
| 227 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 228 | 1), |
Johannes Kron | 8cc711a | 2019-03-07 22:36:35 +0100 | [diff] [blame] | 229 | RtpExtension( |
| 230 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 231 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | static const RtpExtension kRtpExtensionTransportSequenceNumber02[] = { |
Johannes Kron | 8cc711a | 2019-03-07 22:36:35 +0100 | [diff] [blame] | 235 | RtpExtension( |
| 236 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 237 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 238 | }; |
| 239 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 240 | static const uint32_t kSimulcastParamsSsrc[] = {10, 11, 20, 21, 30, 31}; |
| 241 | static const uint32_t kSimSsrc[] = {10, 20, 30}; |
| 242 | static const uint32_t kFec1Ssrc[] = {10, 11}; |
| 243 | static const uint32_t kFec2Ssrc[] = {20, 21}; |
| 244 | static const uint32_t kFec3Ssrc[] = {30, 31}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | |
| 246 | static const char kMediaStream1[] = "stream_1"; |
| 247 | static const char kMediaStream2[] = "stream_2"; |
| 248 | static const char kVideoTrack1[] = "video_1"; |
| 249 | static const char kVideoTrack2[] = "video_2"; |
| 250 | static const char kAudioTrack1[] = "audio_1"; |
| 251 | static const char kAudioTrack2[] = "audio_2"; |
| 252 | static const char kAudioTrack3[] = "audio_3"; |
| 253 | static const char kDataTrack1[] = "data_1"; |
| 254 | static const char kDataTrack2[] = "data_2"; |
| 255 | static const char kDataTrack3[] = "data_3"; |
| 256 | |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 257 | static const char* kMediaProtocols[] = {"RTP/AVP", "RTP/SAVP", "RTP/AVPF", |
| 258 | "RTP/SAVPF"}; |
| 259 | static const char* kMediaProtocolsDtls[] = { |
| 260 | "TCP/TLS/RTP/SAVPF", "TCP/TLS/RTP/SAVP", "UDP/TLS/RTP/SAVPF", |
| 261 | "UDP/TLS/RTP/SAVP"}; |
| 262 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 263 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 264 | // default changes. |
| 265 | static const char* kDefaultSrtpCryptoSuite = CS_AES_CM_128_HMAC_SHA1_80; |
| 266 | static const char* kDefaultSrtpCryptoSuiteGcm = CS_AEAD_AES_256_GCM; |
| 267 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 268 | // These constants are used to make the code using "AddMediaDescriptionOptions" |
| 269 | // more readable. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 270 | static constexpr bool kStopped = true; |
| 271 | static constexpr bool kActive = false; |
| 272 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 273 | static bool IsMediaContentOfType(const ContentInfo* content, |
| 274 | MediaType media_type) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 275 | RTC_DCHECK(content); |
| 276 | return content->media_description()->type() == media_type; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 279 | static RtpTransceiverDirection GetMediaDirection(const ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 280 | RTC_DCHECK(content); |
| 281 | return content->media_description()->direction(); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 282 | } |
| 283 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 284 | static void AddRtxCodec(const VideoCodec& rtx_codec, |
| 285 | std::vector<VideoCodec>* codecs) { |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 286 | ASSERT_FALSE(cricket::FindCodecById(*codecs, rtx_codec.id)); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 287 | codecs->push_back(rtx_codec); |
| 288 | } |
| 289 | |
| 290 | template <class T> |
| 291 | static std::vector<std::string> GetCodecNames(const std::vector<T>& codecs) { |
| 292 | std::vector<std::string> codec_names; |
Mirko Bonadei | 649a4c2 | 2019-01-29 10:11:53 +0100 | [diff] [blame] | 293 | codec_names.reserve(codecs.size()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 294 | for (const auto& codec : codecs) { |
| 295 | codec_names.push_back(codec.name); |
| 296 | } |
| 297 | return codec_names; |
| 298 | } |
| 299 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 300 | // This is used for test only. MIDs are not the identification of the |
| 301 | // MediaDescriptionOptions since some end points may not support MID and the SDP |
| 302 | // may not contain 'mid'. |
| 303 | std::vector<MediaDescriptionOptions>::iterator FindFirstMediaDescriptionByMid( |
| 304 | const std::string& mid, |
| 305 | MediaSessionOptions* opts) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 306 | return absl::c_find_if( |
| 307 | opts->media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 308 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
| 309 | } |
| 310 | |
| 311 | std::vector<MediaDescriptionOptions>::const_iterator |
| 312 | FindFirstMediaDescriptionByMid(const std::string& mid, |
| 313 | const MediaSessionOptions& opts) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 314 | return absl::c_find_if( |
| 315 | opts.media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 316 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // Add a media section to the |session_options|. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 320 | static void AddMediaDescriptionOptions(MediaType type, |
| 321 | const std::string& mid, |
| 322 | RtpTransceiverDirection direction, |
| 323 | bool stopped, |
| 324 | MediaSessionOptions* opts) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 325 | opts->media_description_options.push_back( |
| 326 | MediaDescriptionOptions(type, mid, direction, stopped)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 329 | static void AddAudioVideoSections(RtpTransceiverDirection direction, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 330 | MediaSessionOptions* opts) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 331 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 332 | opts); |
| 333 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", direction, kActive, |
| 334 | opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static void AddDataSection(cricket::DataChannelType dct, |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 338 | RtpTransceiverDirection direction, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 339 | MediaSessionOptions* opts) { |
| 340 | opts->data_channel_type = dct; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 341 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", direction, kActive, opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 344 | static void AttachSenderToMediaDescriptionOptions( |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 345 | const std::string& mid, |
| 346 | MediaType type, |
| 347 | const std::string& track_id, |
| 348 | const std::vector<std::string>& stream_ids, |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 349 | const std::vector<RidDescription>& rids, |
| 350 | const SimulcastLayerList& simulcast_layers, |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 351 | int num_sim_layer, |
| 352 | MediaSessionOptions* session_options) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 353 | auto it = FindFirstMediaDescriptionByMid(mid, session_options); |
| 354 | switch (type) { |
| 355 | case MEDIA_TYPE_AUDIO: |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 356 | it->AddAudioSender(track_id, stream_ids); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 357 | break; |
| 358 | case MEDIA_TYPE_VIDEO: |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 359 | it->AddVideoSender(track_id, stream_ids, rids, simulcast_layers, |
| 360 | num_sim_layer); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 361 | break; |
| 362 | case MEDIA_TYPE_DATA: |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 363 | RTC_CHECK(stream_ids.size() == 1U); |
| 364 | it->AddRtpDataChannel(track_id, stream_ids[0]); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 365 | break; |
| 366 | default: |
| 367 | RTC_NOTREACHED(); |
| 368 | } |
| 369 | } |
| 370 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 371 | static void AttachSenderToMediaDescriptionOptions( |
| 372 | const std::string& mid, |
| 373 | MediaType type, |
| 374 | const std::string& track_id, |
| 375 | const std::vector<std::string>& stream_ids, |
| 376 | int num_sim_layer, |
| 377 | MediaSessionOptions* session_options) { |
| 378 | AttachSenderToMediaDescriptionOptions(mid, type, track_id, stream_ids, {}, |
| 379 | SimulcastLayerList(), num_sim_layer, |
| 380 | session_options); |
| 381 | } |
| 382 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 383 | static void DetachSenderFromMediaSection(const std::string& mid, |
| 384 | const std::string& track_id, |
| 385 | MediaSessionOptions* session_options) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 386 | std::vector<cricket::SenderOptions>& sender_options_list = |
| 387 | FindFirstMediaDescriptionByMid(mid, session_options)->sender_options; |
| 388 | auto sender_it = |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 389 | absl::c_find_if(sender_options_list, |
| 390 | [track_id](const cricket::SenderOptions& sender_options) { |
| 391 | return sender_options.track_id == track_id; |
| 392 | }); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 393 | RTC_DCHECK(sender_it != sender_options_list.end()); |
| 394 | sender_options_list.erase(sender_it); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | // Helper function used to create a default MediaSessionOptions for Plan B SDP. |
| 398 | // (https://tools.ietf.org/html/draft-uberti-rtcweb-plan-00). |
| 399 | static MediaSessionOptions CreatePlanBMediaSessionOptions() { |
| 400 | MediaSessionOptions session_options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 401 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 402 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 403 | &session_options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 404 | return session_options; |
| 405 | } |
| 406 | |
| 407 | // TODO(zhihuang): Most of these tests were written while MediaSessionOptions |
| 408 | // was designed for Plan B SDP, where only one audio "m=" section and one video |
| 409 | // "m=" section could be generated, and ordering couldn't be controlled. Many of |
| 410 | // these tests may be obsolete as a result, and should be refactored or removed. |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 411 | class MediaSessionDescriptionFactoryTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 412 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 413 | MediaSessionDescriptionFactoryTest() |
| 414 | : f1_(&tdf1_, &ssrc_generator1), f2_(&tdf2_, &ssrc_generator2) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 415 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 416 | MAKE_VECTOR(kAudioCodecs1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 417 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 418 | f1_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 419 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 420 | MAKE_VECTOR(kAudioCodecs2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 421 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 422 | f2_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
Henrik Boström | 3a14bf3 | 2015-08-31 09:27:58 +0200 | [diff] [blame] | 423 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 424 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
Henrik Boström | 3a14bf3 | 2015-08-31 09:27:58 +0200 | [diff] [blame] | 425 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 426 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 427 | } |
| 428 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 429 | // Create a video StreamParamsVec object with: |
| 430 | // - one video stream with 3 simulcast streams and FEC, |
| 431 | StreamParamsVec CreateComplexVideoStreamParamsVec() { |
| 432 | SsrcGroup sim_group("SIM", MAKE_VECTOR(kSimSsrc)); |
| 433 | SsrcGroup fec_group1("FEC", MAKE_VECTOR(kFec1Ssrc)); |
| 434 | SsrcGroup fec_group2("FEC", MAKE_VECTOR(kFec2Ssrc)); |
| 435 | SsrcGroup fec_group3("FEC", MAKE_VECTOR(kFec3Ssrc)); |
| 436 | |
| 437 | std::vector<SsrcGroup> ssrc_groups; |
| 438 | ssrc_groups.push_back(sim_group); |
| 439 | ssrc_groups.push_back(fec_group1); |
| 440 | ssrc_groups.push_back(fec_group2); |
| 441 | ssrc_groups.push_back(fec_group3); |
| 442 | |
| 443 | StreamParams simulcast_params; |
| 444 | simulcast_params.id = kVideoTrack1; |
| 445 | simulcast_params.ssrcs = MAKE_VECTOR(kSimulcastParamsSsrc); |
| 446 | simulcast_params.ssrc_groups = ssrc_groups; |
| 447 | simulcast_params.cname = "Video_SIM_FEC"; |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 448 | simulcast_params.set_stream_ids({kMediaStream1}); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 449 | |
| 450 | StreamParamsVec video_streams; |
| 451 | video_streams.push_back(simulcast_params); |
| 452 | |
| 453 | return video_streams; |
| 454 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 455 | |
| 456 | bool CompareCryptoParams(const CryptoParamsVec& c1, |
| 457 | const CryptoParamsVec& c2) { |
| 458 | if (c1.size() != c2.size()) |
| 459 | return false; |
| 460 | for (size_t i = 0; i < c1.size(); ++i) |
| 461 | if (c1[i].tag != c2[i].tag || c1[i].cipher_suite != c2[i].cipher_suite || |
| 462 | c1[i].key_params != c2[i].key_params || |
| 463 | c1[i].session_params != c2[i].session_params) |
| 464 | return false; |
| 465 | return true; |
| 466 | } |
| 467 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 468 | // Returns true if the transport info contains "renomination" as an |
| 469 | // ICE option. |
| 470 | bool GetIceRenomination(const TransportInfo* transport_info) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 471 | return absl::c_linear_search(transport_info->description.transport_options, |
| 472 | "renomination"); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 473 | } |
| 474 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 475 | void TestTransportInfo(bool offer, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 476 | const MediaSessionOptions& options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 477 | bool has_current_desc) { |
| 478 | const std::string current_audio_ufrag = "current_audio_ufrag"; |
| 479 | const std::string current_audio_pwd = "current_audio_pwd"; |
| 480 | const std::string current_video_ufrag = "current_video_ufrag"; |
| 481 | const std::string current_video_pwd = "current_video_pwd"; |
| 482 | const std::string current_data_ufrag = "current_data_ufrag"; |
| 483 | const std::string current_data_pwd = "current_data_pwd"; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 484 | std::unique_ptr<SessionDescription> current_desc; |
| 485 | std::unique_ptr<SessionDescription> desc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 486 | if (has_current_desc) { |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 487 | current_desc = absl::make_unique<SessionDescription>(); |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 488 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 489 | "audio", |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 490 | TransportDescription(current_audio_ufrag, current_audio_pwd))); |
| 491 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 492 | "video", |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 493 | TransportDescription(current_video_ufrag, current_video_pwd))); |
| 494 | current_desc->AddTransportInfo(TransportInfo( |
| 495 | "data", TransportDescription(current_data_ufrag, current_data_pwd))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 496 | } |
| 497 | if (offer) { |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 498 | desc = f1_.CreateOffer(options, current_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 499 | } else { |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 500 | std::unique_ptr<SessionDescription> offer; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 501 | offer = f1_.CreateOffer(options, NULL); |
| 502 | desc = f1_.CreateAnswer(offer.get(), options, current_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 503 | } |
| 504 | ASSERT_TRUE(desc.get() != NULL); |
| 505 | const TransportInfo* ti_audio = desc->GetTransportInfoByName("audio"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 506 | if (options.has_audio()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 507 | EXPECT_TRUE(ti_audio != NULL); |
| 508 | if (has_current_desc) { |
| 509 | EXPECT_EQ(current_audio_ufrag, ti_audio->description.ice_ufrag); |
| 510 | EXPECT_EQ(current_audio_pwd, ti_audio->description.ice_pwd); |
| 511 | } else { |
| 512 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 513 | ti_audio->description.ice_ufrag.size()); |
| 514 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 515 | ti_audio->description.ice_pwd.size()); |
| 516 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 517 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 518 | FindFirstMediaDescriptionByMid("audio", options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 519 | EXPECT_EQ( |
| 520 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 521 | GetIceRenomination(ti_audio)); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 522 | EXPECT_EQ(media_desc_options_it->transport_options.opaque_parameters, |
| 523 | ti_audio->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 524 | |
| 525 | } else { |
| 526 | EXPECT_TRUE(ti_audio == NULL); |
| 527 | } |
| 528 | const TransportInfo* ti_video = desc->GetTransportInfoByName("video"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 529 | if (options.has_video()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 530 | EXPECT_TRUE(ti_video != NULL); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 531 | auto media_desc_options_it = |
| 532 | FindFirstMediaDescriptionByMid("video", options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 533 | if (options.bundle_enabled) { |
| 534 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 535 | ti_video->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 536 | EXPECT_EQ(ti_audio->description.ice_pwd, ti_video->description.ice_pwd); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 537 | EXPECT_EQ(ti_audio->description.opaque_parameters, |
| 538 | ti_video->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 539 | } else { |
| 540 | if (has_current_desc) { |
| 541 | EXPECT_EQ(current_video_ufrag, ti_video->description.ice_ufrag); |
| 542 | EXPECT_EQ(current_video_pwd, ti_video->description.ice_pwd); |
| 543 | } else { |
| 544 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 545 | ti_video->description.ice_ufrag.size()); |
| 546 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 547 | ti_video->description.ice_pwd.size()); |
| 548 | } |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 549 | EXPECT_EQ(media_desc_options_it->transport_options.opaque_parameters, |
| 550 | ti_video->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 551 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 552 | EXPECT_EQ( |
| 553 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 554 | GetIceRenomination(ti_video)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | } else { |
| 556 | EXPECT_TRUE(ti_video == NULL); |
| 557 | } |
| 558 | const TransportInfo* ti_data = desc->GetTransportInfoByName("data"); |
| 559 | if (options.has_data()) { |
| 560 | EXPECT_TRUE(ti_data != NULL); |
| 561 | if (options.bundle_enabled) { |
| 562 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 563 | ti_data->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 564 | EXPECT_EQ(ti_audio->description.ice_pwd, ti_data->description.ice_pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 565 | } else { |
| 566 | if (has_current_desc) { |
| 567 | EXPECT_EQ(current_data_ufrag, ti_data->description.ice_ufrag); |
| 568 | EXPECT_EQ(current_data_pwd, ti_data->description.ice_pwd); |
| 569 | } else { |
| 570 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 571 | ti_data->description.ice_ufrag.size()); |
| 572 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 573 | ti_data->description.ice_pwd.size()); |
| 574 | } |
| 575 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 576 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 577 | FindFirstMediaDescriptionByMid("data", options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 578 | EXPECT_EQ( |
| 579 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 580 | GetIceRenomination(ti_data)); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 581 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 582 | } else { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 583 | EXPECT_TRUE(ti_data == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
| 587 | void TestCryptoWithBundle(bool offer) { |
| 588 | f1_.set_secure(SEC_ENABLED); |
| 589 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 590 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 591 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 592 | &options); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 593 | std::unique_ptr<SessionDescription> ref_desc; |
| 594 | std::unique_ptr<SessionDescription> desc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 595 | if (offer) { |
| 596 | options.bundle_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 597 | ref_desc = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 598 | options.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 599 | desc = f1_.CreateOffer(options, ref_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 600 | } else { |
| 601 | options.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 602 | ref_desc = f1_.CreateOffer(options, NULL); |
| 603 | desc = f1_.CreateAnswer(ref_desc.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 604 | } |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 605 | ASSERT_TRUE(desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | const cricket::MediaContentDescription* audio_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 607 | desc->GetContentDescriptionByName("audio"); |
| 608 | ASSERT_TRUE(audio_media_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 609 | const cricket::MediaContentDescription* video_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 610 | desc->GetContentDescriptionByName("video"); |
| 611 | ASSERT_TRUE(video_media_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 612 | EXPECT_TRUE(CompareCryptoParams(audio_media_desc->cryptos(), |
| 613 | video_media_desc->cryptos())); |
| 614 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 615 | EXPECT_EQ(kDefaultSrtpCryptoSuite, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 616 | audio_media_desc->cryptos()[0].cipher_suite); |
| 617 | |
| 618 | // Verify the selected crypto is one from the reference audio |
| 619 | // media content. |
| 620 | const cricket::MediaContentDescription* ref_audio_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 621 | ref_desc->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | bool found = false; |
| 623 | for (size_t i = 0; i < ref_audio_media_desc->cryptos().size(); ++i) { |
| 624 | if (ref_audio_media_desc->cryptos()[i].Matches( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 625 | audio_media_desc->cryptos()[0])) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 626 | found = true; |
| 627 | break; |
| 628 | } |
| 629 | } |
| 630 | EXPECT_TRUE(found); |
| 631 | } |
| 632 | |
| 633 | // This test that the audio and video media direction is set to |
| 634 | // |expected_direction_in_answer| in an answer if the offer direction is set |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 635 | // to |direction_in_offer| and the answer is willing to both send and receive. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 636 | void TestMediaDirectionInAnswer( |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 637 | RtpTransceiverDirection direction_in_offer, |
| 638 | RtpTransceiverDirection expected_direction_in_answer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 639 | MediaSessionOptions offer_opts; |
| 640 | AddAudioVideoSections(direction_in_offer, &offer_opts); |
| 641 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 642 | std::unique_ptr<SessionDescription> offer = |
| 643 | f1_.CreateOffer(offer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 644 | ASSERT_TRUE(offer.get() != NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 645 | ContentInfo* ac_offer = offer->GetContentByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 646 | ASSERT_TRUE(ac_offer != NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 647 | ContentInfo* vc_offer = offer->GetContentByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 648 | ASSERT_TRUE(vc_offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 649 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 650 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 651 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 652 | std::unique_ptr<SessionDescription> answer = |
| 653 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | const AudioContentDescription* acd_answer = |
| 655 | GetFirstAudioContentDescription(answer.get()); |
| 656 | EXPECT_EQ(expected_direction_in_answer, acd_answer->direction()); |
| 657 | const VideoContentDescription* vcd_answer = |
| 658 | GetFirstVideoContentDescription(answer.get()); |
| 659 | EXPECT_EQ(expected_direction_in_answer, vcd_answer->direction()); |
| 660 | } |
| 661 | |
| 662 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 663 | RTC_DCHECK(content); |
| 664 | RTC_CHECK(content->media_description()); |
| 665 | const cricket::AudioContentDescription* audio_desc = |
| 666 | content->media_description()->as_audio(); |
| 667 | RTC_CHECK(audio_desc); |
| 668 | for (const cricket::AudioCodec& codec : audio_desc->codecs()) { |
| 669 | if (codec.name == "CN") { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 670 | return false; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 671 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 672 | } |
| 673 | return true; |
| 674 | } |
| 675 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 676 | void TestVideoGcmCipher(bool gcm_offer, bool gcm_answer) { |
| 677 | MediaSessionOptions offer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 678 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &offer_opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 679 | offer_opts.crypto_options.srtp.enable_gcm_crypto_suites = gcm_offer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 680 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 681 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 682 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &answer_opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 683 | answer_opts.crypto_options.srtp.enable_gcm_crypto_suites = gcm_answer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 684 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 685 | f1_.set_secure(SEC_ENABLED); |
| 686 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 687 | std::unique_ptr<SessionDescription> offer = |
| 688 | f1_.CreateOffer(offer_opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 689 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 690 | std::unique_ptr<SessionDescription> answer = |
| 691 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 692 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 693 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 694 | ASSERT_TRUE(ac != NULL); |
| 695 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 696 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 697 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 698 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 699 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 700 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 701 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 702 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 703 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 704 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 705 | if (gcm_offer && gcm_answer) { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 706 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 707 | } else { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 708 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 709 | } |
| 710 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 711 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 712 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 713 | EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 714 | if (gcm_offer && gcm_answer) { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 715 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuiteGcm); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 716 | } else { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 717 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 718 | } |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 719 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 722 | void TestTransportSequenceNumberNegotiation( |
| 723 | const cricket::RtpHeaderExtensions& local, |
| 724 | const cricket::RtpHeaderExtensions& offered, |
| 725 | const cricket::RtpHeaderExtensions& expectedAnswer) { |
| 726 | MediaSessionOptions opts; |
| 727 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 728 | f1_.set_audio_rtp_header_extensions(offered); |
| 729 | f1_.set_video_rtp_header_extensions(offered); |
| 730 | f2_.set_audio_rtp_header_extensions(local); |
| 731 | f2_.set_video_rtp_header_extensions(local); |
| 732 | |
| 733 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 734 | ASSERT_TRUE(offer.get() != NULL); |
| 735 | std::unique_ptr<SessionDescription> answer = |
| 736 | f2_.CreateAnswer(offer.get(), opts, NULL); |
| 737 | |
| 738 | EXPECT_EQ( |
| 739 | expectedAnswer, |
| 740 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 741 | EXPECT_EQ( |
| 742 | expectedAnswer, |
| 743 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
| 744 | } |
| 745 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 746 | protected: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 747 | UniqueRandomIdGenerator ssrc_generator1; |
| 748 | UniqueRandomIdGenerator ssrc_generator2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | MediaSessionDescriptionFactory f1_; |
| 750 | MediaSessionDescriptionFactory f2_; |
| 751 | TransportDescriptionFactory tdf1_; |
| 752 | TransportDescriptionFactory tdf2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 753 | }; |
| 754 | |
| 755 | // Create a typical audio offer, and ensure it matches what we expect. |
| 756 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { |
| 757 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 758 | std::unique_ptr<SessionDescription> offer = |
| 759 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 760 | ASSERT_TRUE(offer.get() != NULL); |
| 761 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 762 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 763 | ASSERT_TRUE(ac != NULL); |
| 764 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 765 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 766 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 767 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 768 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 769 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 770 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 771 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 772 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 773 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | // Create a typical video offer, and ensure it matches what we expect. |
| 777 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoOffer) { |
| 778 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 779 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 780 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 781 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 782 | ASSERT_TRUE(offer.get() != NULL); |
| 783 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 784 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 785 | ASSERT_TRUE(ac != NULL); |
| 786 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 787 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 788 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 789 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 790 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 791 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 792 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 793 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 794 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 795 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 796 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 797 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 798 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 799 | EXPECT_EQ(f1_.video_codecs(), vcd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 800 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 801 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 802 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 803 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 804 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | // Test creating an offer with bundle where the Codecs have the same dynamic |
| 808 | // RTP playlod type. The test verifies that the offer don't contain the |
| 809 | // duplicate RTP payload types. |
| 810 | TEST_F(MediaSessionDescriptionFactoryTest, TestBundleOfferWithSameCodecPlType) { |
| 811 | const VideoCodec& offered_video_codec = f2_.video_codecs()[0]; |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 812 | const AudioCodec& offered_audio_codec = f2_.audio_sendrecv_codecs()[0]; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 813 | const RtpDataCodec& offered_data_codec = f2_.rtp_data_codecs()[0]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 814 | ASSERT_EQ(offered_video_codec.id, offered_audio_codec.id); |
| 815 | ASSERT_EQ(offered_video_codec.id, offered_data_codec.id); |
| 816 | |
| 817 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 818 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 819 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 820 | opts.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 821 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 822 | const VideoContentDescription* vcd = |
| 823 | GetFirstVideoContentDescription(offer.get()); |
| 824 | const AudioContentDescription* acd = |
| 825 | GetFirstAudioContentDescription(offer.get()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 826 | const RtpDataContentDescription* dcd = |
| 827 | GetFirstRtpDataContentDescription(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | ASSERT_TRUE(NULL != vcd); |
| 829 | ASSERT_TRUE(NULL != acd); |
| 830 | ASSERT_TRUE(NULL != dcd); |
| 831 | EXPECT_NE(vcd->codecs()[0].id, acd->codecs()[0].id); |
| 832 | EXPECT_NE(vcd->codecs()[0].id, dcd->codecs()[0].id); |
| 833 | EXPECT_NE(acd->codecs()[0].id, dcd->codecs()[0].id); |
| 834 | EXPECT_EQ(vcd->codecs()[0].name, offered_video_codec.name); |
| 835 | EXPECT_EQ(acd->codecs()[0].name, offered_audio_codec.name); |
| 836 | EXPECT_EQ(dcd->codecs()[0].name, offered_data_codec.name); |
| 837 | } |
| 838 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 839 | // Test creating an updated offer with bundle, audio, video and data |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 840 | // after an audio only session has been negotiated. |
| 841 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 842 | TestCreateUpdatedVideoOfferWithBundle) { |
| 843 | f1_.set_secure(SEC_ENABLED); |
| 844 | f2_.set_secure(SEC_ENABLED); |
| 845 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 846 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 847 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 848 | &opts); |
| 849 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 850 | RtpTransceiverDirection::kInactive, kStopped, |
| 851 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 852 | opts.data_channel_type = cricket::DCT_NONE; |
| 853 | opts.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 854 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 855 | std::unique_ptr<SessionDescription> answer = |
| 856 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 857 | |
| 858 | MediaSessionOptions updated_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 859 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &updated_opts); |
| 860 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 861 | &updated_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 862 | updated_opts.bundle_enabled = true; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 863 | std::unique_ptr<SessionDescription> updated_offer( |
| 864 | f1_.CreateOffer(updated_opts, answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 865 | |
| 866 | const AudioContentDescription* acd = |
| 867 | GetFirstAudioContentDescription(updated_offer.get()); |
| 868 | const VideoContentDescription* vcd = |
| 869 | GetFirstVideoContentDescription(updated_offer.get()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 870 | const RtpDataContentDescription* dcd = |
| 871 | GetFirstRtpDataContentDescription(updated_offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 872 | EXPECT_TRUE(NULL != vcd); |
| 873 | EXPECT_TRUE(NULL != acd); |
| 874 | EXPECT_TRUE(NULL != dcd); |
| 875 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 876 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 877 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 878 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 879 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 880 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 881 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 883 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 884 | // Create a RTP data offer, and ensure it matches what we expect. |
| 885 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateRtpDataOffer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 887 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 888 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 889 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 890 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 891 | ASSERT_TRUE(offer.get() != NULL); |
| 892 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 893 | const ContentInfo* dc = offer->GetContentByName("data"); |
| 894 | ASSERT_TRUE(ac != NULL); |
| 895 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 896 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 897 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 898 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 899 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 900 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 901 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 902 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attched. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 903 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 904 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 905 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 906 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 907 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 908 | EXPECT_EQ(f1_.rtp_data_codecs(), dcd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 909 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 910 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 911 | dcd->bandwidth()); // default bandwidth (auto) |
| 912 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 913 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 914 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 915 | } |
| 916 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 917 | // Create an SCTP data offer with bundle without error. |
| 918 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { |
| 919 | MediaSessionOptions opts; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 920 | opts.bundle_enabled = true; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 921 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 922 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 923 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 924 | EXPECT_TRUE(offer.get() != NULL); |
| 925 | EXPECT_TRUE(offer->GetContentByName("data") != NULL); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 +0000 | [diff] [blame] | 926 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 927 | ASSERT_TRUE(dcd); |
| 928 | // Since this transport is insecure, the protocol should be "SCTP". |
| 929 | EXPECT_EQ(cricket::kMediaProtocolSctp, dcd->protocol()); |
| 930 | } |
| 931 | |
| 932 | // Create an SCTP data offer with bundle without error. |
| 933 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSecureSctpDataOffer) { |
| 934 | MediaSessionOptions opts; |
| 935 | opts.bundle_enabled = true; |
| 936 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 937 | f1_.set_secure(SEC_ENABLED); |
| 938 | tdf1_.set_secure(SEC_ENABLED); |
| 939 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 940 | EXPECT_TRUE(offer.get() != NULL); |
| 941 | EXPECT_TRUE(offer->GetContentByName("data") != NULL); |
| 942 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 943 | ASSERT_TRUE(dcd); |
| 944 | // The protocol should now be "UDP/DTLS/SCTP" |
| 945 | EXPECT_EQ(cricket::kMediaProtocolUdpDtlsSctp, dcd->protocol()); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 946 | } |
| 947 | |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 948 | // Test creating an sctp data channel from an already generated offer. |
| 949 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { |
| 950 | MediaSessionOptions opts; |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 951 | opts.bundle_enabled = true; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 952 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 953 | f1_.set_secure(SEC_ENABLED); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 954 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 955 | ASSERT_TRUE(offer1.get() != NULL); |
| 956 | const ContentInfo* data = offer1->GetContentByName("data"); |
| 957 | ASSERT_TRUE(data != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 958 | ASSERT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 959 | |
| 960 | // Now set data_channel_type to 'none' (default) and make sure that the |
| 961 | // datachannel type that gets generated from the previous offer, is of the |
| 962 | // same type. |
| 963 | opts.data_channel_type = cricket::DCT_NONE; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 964 | std::unique_ptr<SessionDescription> offer2( |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 965 | f1_.CreateOffer(opts, offer1.get())); |
| 966 | data = offer2->GetContentByName("data"); |
| 967 | ASSERT_TRUE(data != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 968 | EXPECT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 971 | // Test that if BUNDLE is enabled and all media sections are rejected then the |
| 972 | // BUNDLE group is not present in the re-offer. |
| 973 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferNoBundleGroupIfAllRejected) { |
| 974 | MediaSessionOptions opts; |
| 975 | opts.bundle_enabled = true; |
| 976 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 977 | RtpTransceiverDirection::kSendRecv, kActive, |
| 978 | &opts); |
| 979 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 980 | |
| 981 | opts.media_description_options[0].stopped = true; |
| 982 | std::unique_ptr<SessionDescription> reoffer = |
| 983 | f1_.CreateOffer(opts, offer.get()); |
| 984 | |
| 985 | EXPECT_FALSE(reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); |
| 986 | } |
| 987 | |
| 988 | // Test that if BUNDLE is enabled and the remote re-offer does not include a |
| 989 | // BUNDLE group since all media sections are rejected, then the re-answer also |
| 990 | // does not include a BUNDLE group. |
| 991 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerNoBundleGroupIfAllRejected) { |
| 992 | MediaSessionOptions opts; |
| 993 | opts.bundle_enabled = true; |
| 994 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 995 | RtpTransceiverDirection::kSendRecv, kActive, |
| 996 | &opts); |
| 997 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 998 | std::unique_ptr<SessionDescription> answer = |
| 999 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1000 | |
| 1001 | opts.media_description_options[0].stopped = true; |
| 1002 | std::unique_ptr<SessionDescription> reoffer = |
| 1003 | f1_.CreateOffer(opts, offer.get()); |
| 1004 | std::unique_ptr<SessionDescription> reanswer = |
| 1005 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1006 | |
| 1007 | EXPECT_FALSE(reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); |
| 1008 | } |
| 1009 | |
| 1010 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 1011 | // was rejected then the new offerer-tagged media section is the non-rejected |
| 1012 | // media section. |
| 1013 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferChangeBundleOffererTagged) { |
| 1014 | MediaSessionOptions opts; |
| 1015 | opts.bundle_enabled = true; |
| 1016 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1017 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1018 | &opts); |
| 1019 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1020 | |
| 1021 | // Reject the audio m= section and add a video m= section. |
| 1022 | opts.media_description_options[0].stopped = true; |
| 1023 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1024 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1025 | &opts); |
| 1026 | std::unique_ptr<SessionDescription> reoffer = |
| 1027 | f1_.CreateOffer(opts, offer.get()); |
| 1028 | |
| 1029 | const cricket::ContentGroup* bundle_group = |
| 1030 | reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1031 | ASSERT_TRUE(bundle_group); |
| 1032 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 1033 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 1034 | } |
| 1035 | |
| 1036 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 1037 | // was rejected and a new media section is added, then the re-answer BUNDLE |
| 1038 | // group will contain only the non-rejected media section. |
| 1039 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerChangedBundleOffererTagged) { |
| 1040 | MediaSessionOptions opts; |
| 1041 | opts.bundle_enabled = true; |
| 1042 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1043 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1044 | &opts); |
| 1045 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1046 | std::unique_ptr<SessionDescription> answer = |
| 1047 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1048 | |
| 1049 | // Reject the audio m= section and add a video m= section. |
| 1050 | opts.media_description_options[0].stopped = true; |
| 1051 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1052 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1053 | &opts); |
| 1054 | std::unique_ptr<SessionDescription> reoffer = |
| 1055 | f1_.CreateOffer(opts, offer.get()); |
| 1056 | std::unique_ptr<SessionDescription> reanswer = |
| 1057 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1058 | |
| 1059 | const cricket::ContentGroup* bundle_group = |
| 1060 | reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1061 | ASSERT_TRUE(bundle_group); |
| 1062 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 1063 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 1064 | } |
| 1065 | |
| 1066 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1067 | // and there is still a non-rejected media section that was in the initial |
| 1068 | // offer, then the ICE credentials do not change in the reoffer offerer-tagged |
| 1069 | // media section. |
| 1070 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1071 | ReOfferChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1072 | MediaSessionOptions opts; |
| 1073 | opts.bundle_enabled = true; |
| 1074 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 1075 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1076 | std::unique_ptr<SessionDescription> answer = |
| 1077 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1078 | |
| 1079 | // Reject the audio m= section. |
| 1080 | opts.media_description_options[0].stopped = true; |
| 1081 | std::unique_ptr<SessionDescription> reoffer = |
| 1082 | f1_.CreateOffer(opts, offer.get()); |
| 1083 | |
| 1084 | const TransportDescription* offer_tagged = |
| 1085 | offer->GetTransportDescriptionByName("audio"); |
| 1086 | ASSERT_TRUE(offer_tagged); |
| 1087 | const TransportDescription* reoffer_tagged = |
| 1088 | reoffer->GetTransportDescriptionByName("video"); |
| 1089 | ASSERT_TRUE(reoffer_tagged); |
| 1090 | EXPECT_EQ(offer_tagged->ice_ufrag, reoffer_tagged->ice_ufrag); |
| 1091 | EXPECT_EQ(offer_tagged->ice_pwd, reoffer_tagged->ice_pwd); |
| 1092 | } |
| 1093 | |
| 1094 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1095 | // and there is still a non-rejected media section that was in the initial |
| 1096 | // offer, then the ICE credentials do not change in the reanswer answerer-tagged |
| 1097 | // media section. |
| 1098 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1099 | ReAnswerChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1100 | MediaSessionOptions opts; |
| 1101 | opts.bundle_enabled = true; |
| 1102 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 1103 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1104 | std::unique_ptr<SessionDescription> answer = |
| 1105 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1106 | |
| 1107 | // Reject the audio m= section. |
| 1108 | opts.media_description_options[0].stopped = true; |
| 1109 | std::unique_ptr<SessionDescription> reoffer = |
| 1110 | f1_.CreateOffer(opts, offer.get()); |
| 1111 | std::unique_ptr<SessionDescription> reanswer = |
| 1112 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1113 | |
| 1114 | const TransportDescription* answer_tagged = |
| 1115 | answer->GetTransportDescriptionByName("audio"); |
| 1116 | ASSERT_TRUE(answer_tagged); |
| 1117 | const TransportDescription* reanswer_tagged = |
| 1118 | reanswer->GetTransportDescriptionByName("video"); |
| 1119 | ASSERT_TRUE(reanswer_tagged); |
| 1120 | EXPECT_EQ(answer_tagged->ice_ufrag, reanswer_tagged->ice_ufrag); |
| 1121 | EXPECT_EQ(answer_tagged->ice_pwd, reanswer_tagged->ice_pwd); |
| 1122 | } |
| 1123 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1124 | // Create an audio, video offer without legacy StreamParams. |
| 1125 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1126 | TestCreateOfferWithoutLegacyStreams) { |
| 1127 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1128 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1129 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1130 | ASSERT_TRUE(offer.get() != NULL); |
| 1131 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 1132 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 1133 | ASSERT_TRUE(ac != NULL); |
| 1134 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1135 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1136 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1137 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1138 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1139 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1142 | // Creates an audio+video sendonly offer. |
| 1143 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSendOnlyOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1144 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1145 | AddAudioVideoSections(RtpTransceiverDirection::kSendOnly, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1146 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 1147 | {kMediaStream1}, 1, &opts); |
| 1148 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 1149 | {kMediaStream1}, 1, &opts); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1150 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1151 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1152 | ASSERT_TRUE(offer.get() != NULL); |
| 1153 | EXPECT_EQ(2u, offer->contents().size()); |
| 1154 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[0], MEDIA_TYPE_AUDIO)); |
| 1155 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1156 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1157 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1158 | GetMediaDirection(&offer->contents()[0])); |
| 1159 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1160 | GetMediaDirection(&offer->contents()[1])); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1163 | // Verifies that the order of the media contents in the current |
| 1164 | // SessionDescription is preserved in the new SessionDescription. |
| 1165 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { |
| 1166 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1167 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1168 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1169 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1170 | ASSERT_TRUE(offer1.get() != NULL); |
| 1171 | EXPECT_EQ(1u, offer1->contents().size()); |
| 1172 | EXPECT_TRUE(IsMediaContentOfType(&offer1->contents()[0], MEDIA_TYPE_DATA)); |
| 1173 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1174 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1175 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1176 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1177 | std::unique_ptr<SessionDescription> offer2( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1178 | f1_.CreateOffer(opts, offer1.get())); |
| 1179 | ASSERT_TRUE(offer2.get() != NULL); |
| 1180 | EXPECT_EQ(2u, offer2->contents().size()); |
| 1181 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[0], MEDIA_TYPE_DATA)); |
| 1182 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1183 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1184 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1185 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1186 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1187 | std::unique_ptr<SessionDescription> offer3( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1188 | f1_.CreateOffer(opts, offer2.get())); |
| 1189 | ASSERT_TRUE(offer3.get() != NULL); |
| 1190 | EXPECT_EQ(3u, offer3->contents().size()); |
| 1191 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[0], MEDIA_TYPE_DATA)); |
| 1192 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1193 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[2], MEDIA_TYPE_AUDIO)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1196 | // Create a typical audio answer, and ensure it matches what we expect. |
| 1197 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswer) { |
| 1198 | f1_.set_secure(SEC_ENABLED); |
| 1199 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1200 | std::unique_ptr<SessionDescription> offer = |
| 1201 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1202 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1203 | std::unique_ptr<SessionDescription> answer = |
| 1204 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1205 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1206 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1207 | ASSERT_TRUE(ac != NULL); |
| 1208 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1209 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1210 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1211 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1212 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1213 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1214 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1215 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1216 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1217 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1220 | // Create a typical audio answer with GCM ciphers enabled, and ensure it |
| 1221 | // matches what we expect. |
| 1222 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { |
| 1223 | f1_.set_secure(SEC_ENABLED); |
| 1224 | f2_.set_secure(SEC_ENABLED); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1225 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1226 | opts.crypto_options.srtp.enable_gcm_crypto_suites = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1227 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1228 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1229 | std::unique_ptr<SessionDescription> answer = |
| 1230 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1231 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1232 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1233 | ASSERT_TRUE(ac != NULL); |
| 1234 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1235 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1236 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1237 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1238 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1239 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1240 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1241 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1242 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1243 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1246 | // Create a typical video answer, and ensure it matches what we expect. |
| 1247 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { |
| 1248 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1249 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1250 | f1_.set_secure(SEC_ENABLED); |
| 1251 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1252 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1253 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1254 | std::unique_ptr<SessionDescription> answer = |
| 1255 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1256 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1257 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1258 | ASSERT_TRUE(ac != NULL); |
| 1259 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1260 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1261 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1262 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1263 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1264 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1265 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1266 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1267 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1268 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1269 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1270 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1271 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1272 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 1273 | EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1274 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1275 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1278 | // Create a typical video answer with GCM ciphers enabled, and ensure it |
| 1279 | // matches what we expect. |
| 1280 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcm) { |
| 1281 | TestVideoGcmCipher(true, true); |
| 1282 | } |
| 1283 | |
| 1284 | // Create a typical video answer with GCM ciphers enabled for the offer only, |
| 1285 | // and ensure it matches what we expect. |
| 1286 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmOffer) { |
| 1287 | TestVideoGcmCipher(true, false); |
| 1288 | } |
| 1289 | |
| 1290 | // Create a typical video answer with GCM ciphers enabled for the answer only, |
| 1291 | // and ensure it matches what we expect. |
| 1292 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmAnswer) { |
| 1293 | TestVideoGcmCipher(false, true); |
| 1294 | } |
| 1295 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1296 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1297 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1298 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1299 | f1_.set_secure(SEC_ENABLED); |
| 1300 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1301 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1302 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1303 | std::unique_ptr<SessionDescription> answer = |
| 1304 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1305 | const ContentInfo* ac = answer->GetContentByName("audio"); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1306 | const ContentInfo* dc = answer->GetContentByName("data"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1307 | ASSERT_TRUE(ac != NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1308 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1309 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1310 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1311 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1312 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1313 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1314 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1315 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1316 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1317 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1318 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1319 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1320 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1321 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1322 | EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1323 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1324 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1327 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1328 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1329 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1330 | opts.crypto_options.srtp.enable_gcm_crypto_suites = true; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1331 | f1_.set_secure(SEC_ENABLED); |
| 1332 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1333 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1334 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1335 | std::unique_ptr<SessionDescription> answer = |
| 1336 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1337 | const ContentInfo* ac = answer->GetContentByName("audio"); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1338 | const ContentInfo* dc = answer->GetContentByName("data"); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1339 | ASSERT_TRUE(ac != NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1340 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1341 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1342 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1343 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1344 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1345 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1346 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1347 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1348 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1349 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1350 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1351 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1352 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1353 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1354 | EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1355 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuiteGcm); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1356 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | // The use_sctpmap flag should be set in a DataContentDescription by default. |
| 1360 | // The answer's use_sctpmap flag should match the offer's. |
| 1361 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { |
| 1362 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1363 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1364 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1365 | ASSERT_TRUE(offer.get() != NULL); |
| 1366 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1367 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1368 | SctpDataContentDescription* dcd_offer = |
| 1369 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1370 | EXPECT_TRUE(dcd_offer->use_sctpmap()); |
| 1371 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1372 | std::unique_ptr<SessionDescription> answer = |
| 1373 | f2_.CreateAnswer(offer.get(), opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1374 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1375 | ASSERT_TRUE(dc_answer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1376 | const SctpDataContentDescription* dcd_answer = |
| 1377 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1378 | EXPECT_TRUE(dcd_answer->use_sctpmap()); |
| 1379 | } |
| 1380 | |
| 1381 | // The answer's use_sctpmap flag should match the offer's. |
| 1382 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerWithoutSctpmap) { |
| 1383 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1384 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1385 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1386 | ASSERT_TRUE(offer.get() != NULL); |
| 1387 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1388 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1389 | SctpDataContentDescription* dcd_offer = |
| 1390 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1391 | dcd_offer->set_use_sctpmap(false); |
| 1392 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1393 | std::unique_ptr<SessionDescription> answer = |
| 1394 | f2_.CreateAnswer(offer.get(), opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1395 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1396 | ASSERT_TRUE(dc_answer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1397 | const SctpDataContentDescription* dcd_answer = |
| 1398 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1399 | EXPECT_FALSE(dcd_answer->use_sctpmap()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1402 | // Test that a valid answer will be created for "DTLS/SCTP", "UDP/DTLS/SCTP" |
| 1403 | // and "TCP/DTLS/SCTP" offers. |
| 1404 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1405 | TestCreateDataAnswerToDifferentOfferedProtos) { |
| 1406 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1407 | // test). |
| 1408 | f1_.set_secure(SEC_ENABLED); |
| 1409 | f2_.set_secure(SEC_ENABLED); |
| 1410 | tdf1_.set_secure(SEC_ENABLED); |
| 1411 | tdf2_.set_secure(SEC_ENABLED); |
| 1412 | |
| 1413 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1414 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1415 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1416 | ASSERT_TRUE(offer.get() != nullptr); |
| 1417 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1418 | ASSERT_TRUE(dc_offer != nullptr); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1419 | SctpDataContentDescription* dcd_offer = |
| 1420 | dc_offer->media_description()->as_sctp(); |
| 1421 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1422 | |
| 1423 | std::vector<std::string> protos = {"DTLS/SCTP", "UDP/DTLS/SCTP", |
| 1424 | "TCP/DTLS/SCTP"}; |
| 1425 | for (const std::string& proto : protos) { |
| 1426 | dcd_offer->set_protocol(proto); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1427 | std::unique_ptr<SessionDescription> answer = |
| 1428 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1429 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1430 | ASSERT_TRUE(dc_answer != nullptr); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1431 | const SctpDataContentDescription* dcd_answer = |
| 1432 | dc_answer->media_description()->as_sctp(); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1433 | EXPECT_FALSE(dc_answer->rejected); |
| 1434 | EXPECT_EQ(proto, dcd_answer->protocol()); |
| 1435 | } |
| 1436 | } |
| 1437 | |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 1438 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1439 | TestCreateDataAnswerToOfferWithDefinedMessageSize) { |
| 1440 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1441 | // test). |
| 1442 | f1_.set_secure(SEC_ENABLED); |
| 1443 | f2_.set_secure(SEC_ENABLED); |
| 1444 | tdf1_.set_secure(SEC_ENABLED); |
| 1445 | tdf2_.set_secure(SEC_ENABLED); |
| 1446 | |
| 1447 | MediaSessionOptions opts; |
| 1448 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 1449 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1450 | ASSERT_TRUE(offer.get() != nullptr); |
| 1451 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1452 | ASSERT_TRUE(dc_offer != nullptr); |
| 1453 | SctpDataContentDescription* dcd_offer = |
| 1454 | dc_offer->media_description()->as_sctp(); |
| 1455 | ASSERT_TRUE(dcd_offer); |
| 1456 | dcd_offer->set_max_message_size(1234); |
| 1457 | std::unique_ptr<SessionDescription> answer = |
| 1458 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1459 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1460 | ASSERT_TRUE(dc_answer != nullptr); |
| 1461 | const SctpDataContentDescription* dcd_answer = |
| 1462 | dc_answer->media_description()->as_sctp(); |
| 1463 | EXPECT_FALSE(dc_answer->rejected); |
| 1464 | EXPECT_EQ(1234, dcd_answer->max_message_size()); |
| 1465 | } |
| 1466 | |
| 1467 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1468 | TestCreateDataAnswerToOfferWithZeroMessageSize) { |
| 1469 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1470 | // test). |
| 1471 | f1_.set_secure(SEC_ENABLED); |
| 1472 | f2_.set_secure(SEC_ENABLED); |
| 1473 | tdf1_.set_secure(SEC_ENABLED); |
| 1474 | tdf2_.set_secure(SEC_ENABLED); |
| 1475 | |
| 1476 | MediaSessionOptions opts; |
| 1477 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 1478 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1479 | ASSERT_TRUE(offer.get() != nullptr); |
| 1480 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1481 | ASSERT_TRUE(dc_offer != nullptr); |
| 1482 | SctpDataContentDescription* dcd_offer = |
| 1483 | dc_offer->media_description()->as_sctp(); |
| 1484 | ASSERT_TRUE(dcd_offer); |
| 1485 | dcd_offer->set_max_message_size(0); |
| 1486 | std::unique_ptr<SessionDescription> answer = |
| 1487 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1488 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1489 | ASSERT_TRUE(dc_answer != nullptr); |
| 1490 | const SctpDataContentDescription* dcd_answer = |
| 1491 | dc_answer->media_description()->as_sctp(); |
| 1492 | EXPECT_FALSE(dc_answer->rejected); |
| 1493 | EXPECT_EQ(cricket::kSctpSendBufferSize, dcd_answer->max_message_size()); |
| 1494 | } |
| 1495 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1496 | // Verifies that the order of the media contents in the offer is preserved in |
| 1497 | // the answer. |
| 1498 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { |
| 1499 | MediaSessionOptions opts; |
| 1500 | |
| 1501 | // Creates a data only offer. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1502 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1503 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1504 | ASSERT_TRUE(offer1.get() != NULL); |
| 1505 | |
| 1506 | // Appends audio to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1507 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1508 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1509 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1510 | std::unique_ptr<SessionDescription> offer2( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1511 | f1_.CreateOffer(opts, offer1.get())); |
| 1512 | ASSERT_TRUE(offer2.get() != NULL); |
| 1513 | |
| 1514 | // Appends video to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1515 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1516 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1517 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1518 | std::unique_ptr<SessionDescription> offer3( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1519 | f1_.CreateOffer(opts, offer2.get())); |
| 1520 | ASSERT_TRUE(offer3.get() != NULL); |
| 1521 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1522 | std::unique_ptr<SessionDescription> answer = |
| 1523 | f2_.CreateAnswer(offer3.get(), opts, NULL); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1524 | ASSERT_TRUE(answer.get() != NULL); |
| 1525 | EXPECT_EQ(3u, answer->contents().size()); |
| 1526 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[0], MEDIA_TYPE_DATA)); |
| 1527 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[1], MEDIA_TYPE_AUDIO)); |
| 1528 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[2], MEDIA_TYPE_VIDEO)); |
| 1529 | } |
| 1530 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1531 | // TODO(deadbeef): Extend these tests to ensure the correct direction with other |
| 1532 | // answerer settings. |
| 1533 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1534 | // This test that the media direction is set to send/receive in an answer if |
| 1535 | // the offer is send receive. |
| 1536 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendReceiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1537 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendRecv, |
| 1538 | RtpTransceiverDirection::kSendRecv); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | // This test that the media direction is set to receive only in an answer if |
| 1542 | // the offer is send only. |
| 1543 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1544 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendOnly, |
| 1545 | RtpTransceiverDirection::kRecvOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | // This test that the media direction is set to send only in an answer if |
| 1549 | // the offer is recv only. |
| 1550 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToRecvOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1551 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kRecvOnly, |
| 1552 | RtpTransceiverDirection::kSendOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | // This test that the media direction is set to inactive in an answer if |
| 1556 | // the offer is inactive. |
| 1557 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToInactiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1558 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kInactive, |
| 1559 | RtpTransceiverDirection::kInactive); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | // Test that a data content with an unknown protocol is rejected in an answer. |
| 1563 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1564 | CreateDataAnswerToOfferWithUnknownProtocol) { |
| 1565 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1566 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1567 | f1_.set_secure(SEC_ENABLED); |
| 1568 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1569 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 1570 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1571 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1572 | RtpDataContentDescription* dcd_offer = |
| 1573 | dc_offer->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1574 | ASSERT_TRUE(dcd_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1575 | // Offer must be acceptable as an RTP protocol in order to be set. |
| 1576 | std::string protocol = "RTP/a weird unknown protocol"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1577 | dcd_offer->set_protocol(protocol); |
| 1578 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1579 | std::unique_ptr<SessionDescription> answer = |
| 1580 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1581 | |
| 1582 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1583 | ASSERT_TRUE(dc_answer != NULL); |
| 1584 | EXPECT_TRUE(dc_answer->rejected); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1585 | const RtpDataContentDescription* dcd_answer = |
| 1586 | dc_answer->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1587 | ASSERT_TRUE(dcd_answer != NULL); |
| 1588 | EXPECT_EQ(protocol, dcd_answer->protocol()); |
| 1589 | } |
| 1590 | |
| 1591 | // Test that the media protocol is RTP/AVPF if DTLS and SDES are disabled. |
| 1592 | TEST_F(MediaSessionDescriptionFactoryTest, AudioOfferAnswerWithCryptoDisabled) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1593 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1594 | f1_.set_secure(SEC_DISABLED); |
| 1595 | f2_.set_secure(SEC_DISABLED); |
| 1596 | tdf1_.set_secure(SEC_DISABLED); |
| 1597 | tdf2_.set_secure(SEC_DISABLED); |
| 1598 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1599 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1600 | const AudioContentDescription* offer_acd = |
| 1601 | GetFirstAudioContentDescription(offer.get()); |
| 1602 | ASSERT_TRUE(offer_acd != NULL); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1603 | EXPECT_EQ(cricket::kMediaProtocolAvpf, offer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1604 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1605 | std::unique_ptr<SessionDescription> answer = |
| 1606 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1607 | |
| 1608 | const ContentInfo* ac_answer = answer->GetContentByName("audio"); |
| 1609 | ASSERT_TRUE(ac_answer != NULL); |
| 1610 | EXPECT_FALSE(ac_answer->rejected); |
| 1611 | |
| 1612 | const AudioContentDescription* answer_acd = |
| 1613 | GetFirstAudioContentDescription(answer.get()); |
| 1614 | ASSERT_TRUE(answer_acd != NULL); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1615 | EXPECT_EQ(cricket::kMediaProtocolAvpf, answer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | // Create a video offer and answer and ensure the RTP header extensions |
| 1619 | // matches what we expect. |
| 1620 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferAnswerWithRtpExtensions) { |
| 1621 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1622 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1623 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1624 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1625 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1626 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 1627 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1628 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1629 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1630 | std::unique_ptr<SessionDescription> answer = |
| 1631 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1632 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1633 | EXPECT_EQ( |
| 1634 | MAKE_VECTOR(kAudioRtpExtension1), |
| 1635 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1636 | EXPECT_EQ( |
| 1637 | MAKE_VECTOR(kVideoRtpExtension1), |
| 1638 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1639 | EXPECT_EQ( |
| 1640 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1641 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1642 | EXPECT_EQ( |
| 1643 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1644 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 1647 | // Create a audio/video offer and answer and ensure that the |
| 1648 | // TransportSequenceNumber RTP header extensions are handled correctly. 02 is |
| 1649 | // supported and should take precedence even though not listed among locally |
| 1650 | // supported extensions. |
| 1651 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1652 | TestOfferAnswerWithTransportSequenceNumberInOffer) { |
| 1653 | TestTransportSequenceNumberNegotiation( |
| 1654 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1655 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Offer. |
| 1656 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01)); // Expected answer. |
| 1657 | } |
| 1658 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1659 | TestOfferAnswerWithTransportSequenceNumber01And02InOffer) { |
| 1660 | TestTransportSequenceNumberNegotiation( |
| 1661 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1662 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Offer. |
| 1663 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1664 | } |
| 1665 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1666 | TestOfferAnswerWithTransportSequenceNumber02InOffer) { |
| 1667 | TestTransportSequenceNumberNegotiation( |
| 1668 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1669 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Offer. |
| 1670 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1671 | } |
| 1672 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1673 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1674 | TestOfferAnswerWithEncryptedRtpExtensionsBoth) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1675 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1676 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1677 | |
| 1678 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1679 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1680 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1681 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1682 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1683 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1684 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1685 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1686 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1687 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1688 | std::unique_ptr<SessionDescription> answer = |
| 1689 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1690 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1691 | EXPECT_EQ( |
| 1692 | MAKE_VECTOR(kAudioRtpExtensionEncrypted1), |
| 1693 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1694 | EXPECT_EQ( |
| 1695 | MAKE_VECTOR(kVideoRtpExtensionEncrypted1), |
| 1696 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1697 | EXPECT_EQ( |
| 1698 | MAKE_VECTOR(kAudioRtpExtensionEncryptedAnswer), |
| 1699 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1700 | EXPECT_EQ( |
| 1701 | MAKE_VECTOR(kVideoRtpExtensionEncryptedAnswer), |
| 1702 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1706 | TestOfferAnswerWithEncryptedRtpExtensionsOffer) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1707 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1708 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1709 | |
| 1710 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1711 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1712 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1713 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1714 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1715 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1716 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1717 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1718 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1719 | std::unique_ptr<SessionDescription> answer = |
| 1720 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1721 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1722 | EXPECT_EQ( |
| 1723 | MAKE_VECTOR(kAudioRtpExtensionEncrypted1), |
| 1724 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1725 | EXPECT_EQ( |
| 1726 | MAKE_VECTOR(kVideoRtpExtensionEncrypted1), |
| 1727 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1728 | EXPECT_EQ( |
| 1729 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1730 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1731 | EXPECT_EQ( |
| 1732 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1733 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1737 | TestOfferAnswerWithEncryptedRtpExtensionsAnswer) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1738 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1739 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1740 | |
| 1741 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1742 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1743 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1744 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1745 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1746 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1747 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1748 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1749 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1750 | std::unique_ptr<SessionDescription> answer = |
| 1751 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1752 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1753 | EXPECT_EQ( |
| 1754 | MAKE_VECTOR(kAudioRtpExtension1), |
| 1755 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1756 | EXPECT_EQ( |
| 1757 | MAKE_VECTOR(kVideoRtpExtension1), |
| 1758 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1759 | EXPECT_EQ( |
| 1760 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1761 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1762 | EXPECT_EQ( |
| 1763 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1764 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1767 | // Create an audio, video, data answer without legacy StreamParams. |
| 1768 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1769 | TestCreateAnswerWithoutLegacyStreams) { |
| 1770 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1771 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1772 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1773 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1774 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1775 | std::unique_ptr<SessionDescription> answer = |
| 1776 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1777 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1778 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1779 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 1780 | ASSERT_TRUE(ac != NULL); |
| 1781 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1782 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1783 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1784 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1785 | |
| 1786 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
| 1787 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1788 | EXPECT_FALSE(dcd->has_ssrcs()); // No StreamParams. |
| 1789 | } |
| 1790 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1791 | // Create a typical video answer, and ensure it matches what we expect. |
| 1792 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { |
| 1793 | MediaSessionOptions offer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1794 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &offer_opts); |
| 1795 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, |
| 1796 | &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1797 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1798 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1799 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
| 1800 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, |
| 1801 | &answer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1802 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1803 | std::unique_ptr<SessionDescription> offer; |
| 1804 | std::unique_ptr<SessionDescription> answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1805 | |
| 1806 | offer_opts.rtcp_mux_enabled = true; |
| 1807 | answer_opts.rtcp_mux_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1808 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 1809 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1810 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1811 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1812 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1813 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1814 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1815 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1816 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1817 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1818 | EXPECT_TRUE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1819 | EXPECT_TRUE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1820 | EXPECT_TRUE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1821 | EXPECT_TRUE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1822 | |
| 1823 | offer_opts.rtcp_mux_enabled = true; |
| 1824 | answer_opts.rtcp_mux_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1825 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 1826 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1827 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1828 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1829 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1830 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1831 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1832 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1833 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1834 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1835 | EXPECT_TRUE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1836 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1837 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1838 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1839 | |
| 1840 | offer_opts.rtcp_mux_enabled = false; |
| 1841 | answer_opts.rtcp_mux_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1842 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 1843 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1844 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1845 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1846 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1847 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1848 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1849 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1850 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1851 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1852 | EXPECT_FALSE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1853 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1854 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1855 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1856 | |
| 1857 | offer_opts.rtcp_mux_enabled = false; |
| 1858 | answer_opts.rtcp_mux_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1859 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 1860 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1861 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1862 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1863 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1864 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1865 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1866 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1867 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1868 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1869 | EXPECT_FALSE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1870 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1871 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1872 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | // Create an audio-only answer to a video offer. |
| 1876 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerToVideo) { |
| 1877 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1878 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1879 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1880 | &opts); |
| 1881 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1882 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1883 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1884 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1885 | ASSERT_TRUE(offer.get() != NULL); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1886 | |
| 1887 | opts.media_description_options[1].stopped = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1888 | std::unique_ptr<SessionDescription> answer = |
| 1889 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1890 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1891 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1892 | ASSERT_TRUE(ac != NULL); |
| 1893 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1894 | ASSERT_TRUE(vc->media_description() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1895 | EXPECT_TRUE(vc->rejected); |
| 1896 | } |
| 1897 | |
| 1898 | // Create an audio-only answer to an offer with data. |
| 1899 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateNoDataAnswerToDataOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1900 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1901 | opts.data_channel_type = cricket::DCT_RTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1902 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 1903 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1904 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1905 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1906 | ASSERT_TRUE(offer.get() != NULL); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1907 | |
| 1908 | opts.media_description_options[1].stopped = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1909 | std::unique_ptr<SessionDescription> answer = |
| 1910 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1911 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1912 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 1913 | ASSERT_TRUE(ac != NULL); |
| 1914 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1915 | ASSERT_TRUE(dc->media_description() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1916 | EXPECT_TRUE(dc->rejected); |
| 1917 | } |
| 1918 | |
| 1919 | // Create an answer that rejects the contents which are rejected in the offer. |
| 1920 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1921 | CreateAnswerToOfferWithRejectedMedia) { |
| 1922 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1923 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1924 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1925 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1926 | ASSERT_TRUE(offer.get() != NULL); |
| 1927 | ContentInfo* ac = offer->GetContentByName("audio"); |
| 1928 | ContentInfo* vc = offer->GetContentByName("video"); |
| 1929 | ContentInfo* dc = offer->GetContentByName("data"); |
| 1930 | ASSERT_TRUE(ac != NULL); |
| 1931 | ASSERT_TRUE(vc != NULL); |
| 1932 | ASSERT_TRUE(dc != NULL); |
| 1933 | ac->rejected = true; |
| 1934 | vc->rejected = true; |
| 1935 | dc->rejected = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1936 | std::unique_ptr<SessionDescription> answer = |
| 1937 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1938 | ac = answer->GetContentByName("audio"); |
| 1939 | vc = answer->GetContentByName("video"); |
| 1940 | dc = answer->GetContentByName("data"); |
| 1941 | ASSERT_TRUE(ac != NULL); |
| 1942 | ASSERT_TRUE(vc != NULL); |
| 1943 | ASSERT_TRUE(dc != NULL); |
| 1944 | EXPECT_TRUE(ac->rejected); |
| 1945 | EXPECT_TRUE(vc->rejected); |
| 1946 | EXPECT_TRUE(dc->rejected); |
| 1947 | } |
| 1948 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1949 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1950 | CreateAnswerSupportsMixedOneAndTwoByteHeaderExtensions) { |
| 1951 | MediaSessionOptions opts; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1952 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1953 | // Offer without request of mixed one- and two-byte header extensions. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1954 | offer->set_extmap_allow_mixed(false); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1955 | ASSERT_TRUE(offer.get() != NULL); |
| 1956 | std::unique_ptr<SessionDescription> answer_no_support( |
| 1957 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1958 | EXPECT_FALSE(answer_no_support->extmap_allow_mixed()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1959 | |
| 1960 | // Offer with request of mixed one- and two-byte header extensions. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1961 | offer->set_extmap_allow_mixed(true); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1962 | ASSERT_TRUE(offer.get() != NULL); |
| 1963 | std::unique_ptr<SessionDescription> answer_support( |
| 1964 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1965 | EXPECT_TRUE(answer_support->extmap_allow_mixed()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1969 | CreateAnswerSupportsMixedOneAndTwoByteHeaderExtensionsOnMediaLevel) { |
| 1970 | MediaSessionOptions opts; |
| 1971 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1972 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1973 | MediaContentDescription* video_offer = |
| 1974 | offer->GetContentDescriptionByName("video"); |
| 1975 | ASSERT_TRUE(video_offer); |
| 1976 | MediaContentDescription* audio_offer = |
| 1977 | offer->GetContentDescriptionByName("audio"); |
| 1978 | ASSERT_TRUE(audio_offer); |
| 1979 | |
| 1980 | // Explicit disable of mixed one-two byte header support in offer. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1981 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 1982 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1983 | |
| 1984 | ASSERT_TRUE(offer.get() != NULL); |
| 1985 | std::unique_ptr<SessionDescription> answer_no_support( |
| 1986 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1987 | MediaContentDescription* video_answer = |
| 1988 | answer_no_support->GetContentDescriptionByName("video"); |
| 1989 | MediaContentDescription* audio_answer = |
| 1990 | answer_no_support->GetContentDescriptionByName("audio"); |
| 1991 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1992 | video_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1993 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1994 | audio_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1995 | |
| 1996 | // Enable mixed one-two byte header support in offer. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1997 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
| 1998 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1999 | ASSERT_TRUE(offer.get() != NULL); |
| 2000 | std::unique_ptr<SessionDescription> answer_support( |
| 2001 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 2002 | video_answer = answer_support->GetContentDescriptionByName("video"); |
| 2003 | audio_answer = answer_support->GetContentDescriptionByName("audio"); |
| 2004 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2005 | video_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2006 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2007 | audio_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2008 | } |
| 2009 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2010 | // Create an audio and video offer with: |
| 2011 | // - one video track |
| 2012 | // - two audio tracks |
| 2013 | // - two data tracks |
| 2014 | // and ensure it matches what we expect. Also updates the initial offer by |
| 2015 | // adding a new video track and replaces one of the audio tracks. |
| 2016 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { |
| 2017 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2018 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2019 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2020 | {kMediaStream1}, 1, &opts); |
| 2021 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2022 | {kMediaStream1}, 1, &opts); |
| 2023 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2024 | {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2025 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2026 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2027 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack1, |
| 2028 | {kMediaStream1}, 1, &opts); |
| 2029 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack2, |
| 2030 | {kMediaStream1}, 1, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2031 | |
| 2032 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2033 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2034 | |
| 2035 | ASSERT_TRUE(offer.get() != NULL); |
| 2036 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 2037 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 2038 | const ContentInfo* dc = offer->GetContentByName("data"); |
| 2039 | ASSERT_TRUE(ac != NULL); |
| 2040 | ASSERT_TRUE(vc != NULL); |
| 2041 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2042 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 2043 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2044 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2045 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 2046 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2047 | |
| 2048 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2049 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2050 | EXPECT_EQ(audio_streams[0].cname, audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2051 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2052 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2053 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2054 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2055 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2056 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2057 | |
| 2058 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2059 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2060 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2061 | |
| 2062 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 2063 | EXPECT_EQ(f1_.video_codecs(), vcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2064 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2065 | |
| 2066 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2067 | ASSERT_EQ(1U, video_streams.size()); |
| 2068 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2069 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2070 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2071 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2072 | |
| 2073 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2074 | EXPECT_EQ(f1_.rtp_data_codecs(), dcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2075 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2076 | |
| 2077 | const StreamParamsVec& data_streams = dcd->streams(); |
| 2078 | ASSERT_EQ(2U, data_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2079 | EXPECT_EQ(data_streams[0].cname, data_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2080 | EXPECT_EQ(kDataTrack1, data_streams[0].id); |
| 2081 | ASSERT_EQ(1U, data_streams[0].ssrcs.size()); |
| 2082 | EXPECT_NE(0U, data_streams[0].ssrcs[0]); |
| 2083 | EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 2084 | ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 2085 | EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 2086 | |
| 2087 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2088 | dcd->bandwidth()); // default bandwidth (auto) |
| 2089 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2090 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2091 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2092 | // Update the offer. Add a new video track that is not synched to the |
| 2093 | // other tracks and replace audio track 2 with audio track 3. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2094 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2095 | {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2096 | DetachSenderFromMediaSection("audio", kAudioTrack2, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2097 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack3, |
| 2098 | {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2099 | DetachSenderFromMediaSection("data", kDataTrack2, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2100 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack3, |
| 2101 | {kMediaStream1}, 1, &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2102 | std::unique_ptr<SessionDescription> updated_offer( |
| 2103 | f1_.CreateOffer(opts, offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2104 | |
| 2105 | ASSERT_TRUE(updated_offer.get() != NULL); |
| 2106 | ac = updated_offer->GetContentByName("audio"); |
| 2107 | vc = updated_offer->GetContentByName("video"); |
| 2108 | dc = updated_offer->GetContentByName("data"); |
| 2109 | ASSERT_TRUE(ac != NULL); |
| 2110 | ASSERT_TRUE(vc != NULL); |
| 2111 | ASSERT_TRUE(dc != NULL); |
| 2112 | const AudioContentDescription* updated_acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2113 | ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2114 | const VideoContentDescription* updated_vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2115 | vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2116 | const RtpDataContentDescription* updated_dcd = |
| 2117 | dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2118 | |
| 2119 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2120 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2121 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2122 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
| 2123 | EXPECT_EQ(dcd->type(), updated_dcd->type()); |
| 2124 | EXPECT_EQ(dcd->codecs(), updated_dcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2125 | ASSERT_CRYPTO(updated_acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2126 | EXPECT_TRUE(CompareCryptoParams(acd->cryptos(), updated_acd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2127 | ASSERT_CRYPTO(updated_vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2128 | EXPECT_TRUE(CompareCryptoParams(vcd->cryptos(), updated_vcd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2129 | ASSERT_CRYPTO(updated_dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2130 | EXPECT_TRUE(CompareCryptoParams(dcd->cryptos(), updated_dcd->cryptos())); |
| 2131 | |
| 2132 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2133 | ASSERT_EQ(2U, updated_audio_streams.size()); |
| 2134 | EXPECT_EQ(audio_streams[0], updated_audio_streams[0]); |
| 2135 | EXPECT_EQ(kAudioTrack3, updated_audio_streams[1].id); // New audio track. |
| 2136 | ASSERT_EQ(1U, updated_audio_streams[1].ssrcs.size()); |
| 2137 | EXPECT_NE(0U, updated_audio_streams[1].ssrcs[0]); |
| 2138 | EXPECT_EQ(updated_audio_streams[0].cname, updated_audio_streams[1].cname); |
| 2139 | |
| 2140 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2141 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2142 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2143 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2144 | // All the media streams in one PeerConnection share one RTCP CNAME. |
| 2145 | EXPECT_EQ(updated_video_streams[1].cname, updated_video_streams[0].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2146 | |
| 2147 | const StreamParamsVec& updated_data_streams = updated_dcd->streams(); |
| 2148 | ASSERT_EQ(2U, updated_data_streams.size()); |
| 2149 | EXPECT_EQ(data_streams[0], updated_data_streams[0]); |
| 2150 | EXPECT_EQ(kDataTrack3, updated_data_streams[1].id); // New data track. |
| 2151 | ASSERT_EQ(1U, updated_data_streams[1].ssrcs.size()); |
| 2152 | EXPECT_NE(0U, updated_data_streams[1].ssrcs[0]); |
| 2153 | EXPECT_EQ(updated_data_streams[0].cname, updated_data_streams[1].cname); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2154 | // The stream correctly got the CNAME from the MediaSessionOptions. |
| 2155 | // The Expected RTCP CNAME is the default one as we are using the default |
| 2156 | // MediaSessionOptions. |
| 2157 | EXPECT_EQ(updated_data_streams[0].cname, cricket::kDefaultRtcpCname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2160 | // Create an offer with simulcast video stream. |
| 2161 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { |
| 2162 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2163 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2164 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2165 | &opts); |
| 2166 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2167 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2168 | &opts); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2169 | const int num_sim_layers = 3; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2170 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2171 | {kMediaStream1}, num_sim_layers, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2172 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2173 | |
| 2174 | ASSERT_TRUE(offer.get() != NULL); |
| 2175 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 2176 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2177 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2178 | |
| 2179 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2180 | ASSERT_EQ(1U, video_streams.size()); |
| 2181 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2182 | const SsrcGroup* sim_ssrc_group = |
| 2183 | video_streams[0].get_ssrc_group(cricket::kSimSsrcGroupSemantics); |
| 2184 | ASSERT_TRUE(sim_ssrc_group != NULL); |
| 2185 | EXPECT_EQ(static_cast<size_t>(num_sim_layers), sim_ssrc_group->ssrcs.size()); |
| 2186 | } |
| 2187 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2188 | MATCHER(RidDescriptionEquals, "Verifies that two RidDescriptions are equal.") { |
| 2189 | const RidDescription& rid1 = ::testing::get<0>(arg); |
| 2190 | const RidDescription& rid2 = ::testing::get<1>(arg); |
| 2191 | return rid1.rid == rid2.rid && rid1.direction == rid2.direction; |
| 2192 | } |
| 2193 | |
| 2194 | static void CheckSimulcastInSessionDescription( |
| 2195 | const SessionDescription* description, |
| 2196 | const std::string& content_name, |
| 2197 | const std::vector<RidDescription>& send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2198 | const SimulcastLayerList& send_layers) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2199 | ASSERT_NE(description, nullptr); |
| 2200 | const ContentInfo* content = description->GetContentByName(content_name); |
| 2201 | ASSERT_NE(content, nullptr); |
| 2202 | const MediaContentDescription* cd = content->media_description(); |
| 2203 | ASSERT_NE(cd, nullptr); |
| 2204 | const StreamParamsVec& streams = cd->streams(); |
| 2205 | ASSERT_THAT(streams, SizeIs(1)); |
| 2206 | const StreamParams& stream = streams[0]; |
| 2207 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2208 | EXPECT_TRUE(stream.has_rids()); |
| 2209 | const std::vector<RidDescription> rids = stream.rids(); |
| 2210 | |
| 2211 | EXPECT_THAT(rids, Pointwise(RidDescriptionEquals(), send_rids)); |
| 2212 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2213 | EXPECT_TRUE(cd->HasSimulcast()); |
| 2214 | const SimulcastDescription& simulcast = cd->simulcast_description(); |
| 2215 | EXPECT_THAT(simulcast.send_layers(), SizeIs(send_layers.size())); |
| 2216 | EXPECT_THAT(simulcast.send_layers(), Pointwise(Eq(), send_layers)); |
| 2217 | |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2218 | ASSERT_THAT(simulcast.receive_layers().GetAllLayers(), SizeIs(0)); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | // Create an offer with spec-compliant simulcast video stream. |
| 2222 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastOffer) { |
| 2223 | MediaSessionOptions opts; |
| 2224 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2225 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2226 | &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2227 | std::vector<RidDescription> send_rids; |
| 2228 | send_rids.push_back(RidDescription("f", RidDirection::kSend)); |
| 2229 | send_rids.push_back(RidDescription("h", RidDirection::kSend)); |
| 2230 | send_rids.push_back(RidDescription("q", RidDirection::kSend)); |
| 2231 | SimulcastLayerList simulcast_layers; |
| 2232 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[0].rid, false)); |
| 2233 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[1].rid, true)); |
| 2234 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[2].rid, false)); |
| 2235 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2236 | {kMediaStream1}, send_rids, |
| 2237 | simulcast_layers, 0, &opts); |
| 2238 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2239 | |
| 2240 | CheckSimulcastInSessionDescription(offer.get(), "video", send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2241 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | // Create an offer that signals RIDs (not SSRCs) without Simulcast. |
| 2245 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2246 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferWithRidsNoSimulcast) { |
| 2247 | MediaSessionOptions opts; |
| 2248 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2249 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2250 | &opts); |
| 2251 | RidDescription rid("f", RidDirection::kSend); |
| 2252 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2253 | {kMediaStream1}, {rid}, |
| 2254 | SimulcastLayerList(), 0, &opts); |
| 2255 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2256 | |
| 2257 | ASSERT_NE(offer.get(), nullptr); |
| 2258 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2259 | ASSERT_NE(content, nullptr); |
| 2260 | const MediaContentDescription* cd = content->media_description(); |
| 2261 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2262 | const StreamParamsVec& streams = cd->streams(); |
| 2263 | ASSERT_THAT(streams, SizeIs(1)); |
| 2264 | const StreamParams& stream = streams[0]; |
| 2265 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2266 | EXPECT_FALSE(stream.has_rids()); |
| 2267 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2268 | } |
| 2269 | |
| 2270 | // Create an answer with spec-compliant simulcast video stream. |
| 2271 | // In this scenario, the SFU is the caller requesting that we send Simulcast. |
| 2272 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastAnswer) { |
| 2273 | MediaSessionOptions offer_opts; |
| 2274 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2275 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2276 | &offer_opts); |
| 2277 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2278 | {kMediaStream1}, 1, &offer_opts); |
| 2279 | std::unique_ptr<SessionDescription> offer = |
| 2280 | f1_.CreateOffer(offer_opts, nullptr); |
| 2281 | |
| 2282 | MediaSessionOptions answer_opts; |
| 2283 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2284 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2285 | &answer_opts); |
| 2286 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2287 | std::vector<RidDescription> rid_descriptions{ |
| 2288 | RidDescription("f", RidDirection::kSend), |
| 2289 | RidDescription("h", RidDirection::kSend), |
| 2290 | RidDescription("q", RidDirection::kSend), |
| 2291 | }; |
| 2292 | SimulcastLayerList simulcast_layers; |
| 2293 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[0].rid, false)); |
| 2294 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[1].rid, true)); |
| 2295 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[2].rid, false)); |
| 2296 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2297 | {kMediaStream1}, rid_descriptions, |
| 2298 | simulcast_layers, 0, &answer_opts); |
| 2299 | std::unique_ptr<SessionDescription> answer = |
| 2300 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
| 2301 | |
| 2302 | CheckSimulcastInSessionDescription(answer.get(), "video", rid_descriptions, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2303 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | // Create an answer that signals RIDs (not SSRCs) without Simulcast. |
| 2307 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2308 | // Note that RID Direction is not the same as the transceiver direction. |
| 2309 | TEST_F(MediaSessionDescriptionFactoryTest, TestAnswerWithRidsNoSimulcast) { |
| 2310 | MediaSessionOptions offer_opts; |
| 2311 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2312 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2313 | &offer_opts); |
| 2314 | RidDescription rid_offer("f", RidDirection::kSend); |
| 2315 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2316 | {kMediaStream1}, {rid_offer}, |
| 2317 | SimulcastLayerList(), 0, &offer_opts); |
| 2318 | std::unique_ptr<SessionDescription> offer = |
| 2319 | f1_.CreateOffer(offer_opts, nullptr); |
| 2320 | |
| 2321 | MediaSessionOptions answer_opts; |
| 2322 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2323 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2324 | &answer_opts); |
| 2325 | |
| 2326 | RidDescription rid_answer("f", RidDirection::kReceive); |
| 2327 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2328 | {kMediaStream1}, {rid_answer}, |
| 2329 | SimulcastLayerList(), 0, &answer_opts); |
| 2330 | std::unique_ptr<SessionDescription> answer = |
| 2331 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
| 2332 | |
| 2333 | ASSERT_NE(answer.get(), nullptr); |
| 2334 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2335 | ASSERT_NE(content, nullptr); |
| 2336 | const MediaContentDescription* cd = content->media_description(); |
| 2337 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2338 | const StreamParamsVec& streams = cd->streams(); |
| 2339 | ASSERT_THAT(streams, SizeIs(1)); |
| 2340 | const StreamParams& stream = streams[0]; |
| 2341 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2342 | EXPECT_FALSE(stream.has_rids()); |
| 2343 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2344 | } |
| 2345 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2346 | // Create an audio and video answer to a standard video offer with: |
| 2347 | // - one video track |
| 2348 | // - two audio tracks |
| 2349 | // - two data tracks |
| 2350 | // and ensure it matches what we expect. Also updates the initial answer by |
| 2351 | // adding a new video track and removes one of the audio tracks. |
| 2352 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { |
| 2353 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2354 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2355 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2356 | &offer_opts); |
| 2357 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2358 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2359 | &offer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2360 | offer_opts.data_channel_type = cricket::DCT_RTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2361 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2362 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2363 | &offer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2364 | f1_.set_secure(SEC_ENABLED); |
| 2365 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2366 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(offer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2367 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2368 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2369 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2370 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2371 | &answer_opts); |
| 2372 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2373 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2374 | &answer_opts); |
| 2375 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2376 | {kMediaStream1}, 1, &answer_opts); |
| 2377 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2378 | {kMediaStream1}, 1, &answer_opts); |
| 2379 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2380 | {kMediaStream1}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2381 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2382 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2383 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2384 | &answer_opts); |
| 2385 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack1, |
| 2386 | {kMediaStream1}, 1, &answer_opts); |
| 2387 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack2, |
| 2388 | {kMediaStream1}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2389 | answer_opts.data_channel_type = cricket::DCT_RTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2390 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2391 | std::unique_ptr<SessionDescription> answer = |
| 2392 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2393 | |
| 2394 | ASSERT_TRUE(answer.get() != NULL); |
| 2395 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2396 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 2397 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 2398 | ASSERT_TRUE(ac != NULL); |
| 2399 | ASSERT_TRUE(vc != NULL); |
| 2400 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2401 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 2402 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2403 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2404 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
| 2405 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
| 2406 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2407 | |
| 2408 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2409 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2410 | |
| 2411 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2412 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2413 | EXPECT_TRUE(audio_streams[0].cname == audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2414 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2415 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2416 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2417 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2418 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2419 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2420 | |
| 2421 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2422 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
| 2423 | |
| 2424 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2425 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2426 | |
| 2427 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2428 | ASSERT_EQ(1U, video_streams.size()); |
| 2429 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2430 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2431 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2432 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2433 | |
| 2434 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2435 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2436 | |
| 2437 | const StreamParamsVec& data_streams = dcd->streams(); |
| 2438 | ASSERT_EQ(2U, data_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2439 | EXPECT_TRUE(data_streams[0].cname == data_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2440 | EXPECT_EQ(kDataTrack1, data_streams[0].id); |
| 2441 | ASSERT_EQ(1U, data_streams[0].ssrcs.size()); |
| 2442 | EXPECT_NE(0U, data_streams[0].ssrcs[0]); |
| 2443 | EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 2444 | ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 2445 | EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 2446 | |
| 2447 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2448 | dcd->bandwidth()); // default bandwidth (auto) |
| 2449 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2450 | |
| 2451 | // Update the answer. Add a new video track that is not synched to the |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2452 | // other tracks and remove 1 audio track. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2453 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2454 | {kMediaStream2}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2455 | DetachSenderFromMediaSection("audio", kAudioTrack2, &answer_opts); |
| 2456 | DetachSenderFromMediaSection("data", kDataTrack2, &answer_opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2457 | std::unique_ptr<SessionDescription> updated_answer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2458 | f2_.CreateAnswer(offer.get(), answer_opts, answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2459 | |
| 2460 | ASSERT_TRUE(updated_answer.get() != NULL); |
| 2461 | ac = updated_answer->GetContentByName("audio"); |
| 2462 | vc = updated_answer->GetContentByName("video"); |
| 2463 | dc = updated_answer->GetContentByName("data"); |
| 2464 | ASSERT_TRUE(ac != NULL); |
| 2465 | ASSERT_TRUE(vc != NULL); |
| 2466 | ASSERT_TRUE(dc != NULL); |
| 2467 | const AudioContentDescription* updated_acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2468 | ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2469 | const VideoContentDescription* updated_vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2470 | vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2471 | const RtpDataContentDescription* updated_dcd = |
| 2472 | dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2473 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2474 | ASSERT_CRYPTO(updated_acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2475 | EXPECT_TRUE(CompareCryptoParams(acd->cryptos(), updated_acd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2476 | ASSERT_CRYPTO(updated_vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2477 | EXPECT_TRUE(CompareCryptoParams(vcd->cryptos(), updated_vcd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2478 | ASSERT_CRYPTO(updated_dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2479 | EXPECT_TRUE(CompareCryptoParams(dcd->cryptos(), updated_dcd->cryptos())); |
| 2480 | |
| 2481 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2482 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2483 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2484 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
| 2485 | EXPECT_EQ(dcd->type(), updated_dcd->type()); |
| 2486 | EXPECT_EQ(dcd->codecs(), updated_dcd->codecs()); |
| 2487 | |
| 2488 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2489 | ASSERT_EQ(1U, updated_audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2490 | EXPECT_TRUE(audio_streams[0] == updated_audio_streams[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2491 | |
| 2492 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2493 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2494 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2495 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2496 | // All media streams in one PeerConnection share one CNAME. |
| 2497 | EXPECT_EQ(updated_video_streams[1].cname, updated_video_streams[0].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2498 | |
| 2499 | const StreamParamsVec& updated_data_streams = updated_dcd->streams(); |
| 2500 | ASSERT_EQ(1U, updated_data_streams.size()); |
| 2501 | EXPECT_TRUE(data_streams[0] == updated_data_streams[0]); |
| 2502 | } |
| 2503 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2504 | // Create an updated offer after creating an answer to the original offer and |
| 2505 | // verify that the codecs that were part of the original answer are not changed |
| 2506 | // in the updated offer. |
| 2507 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2508 | RespondentCreatesOfferAfterCreatingAnswer) { |
| 2509 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2510 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2511 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2512 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 2513 | std::unique_ptr<SessionDescription> answer = |
| 2514 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2515 | |
| 2516 | const AudioContentDescription* acd = |
| 2517 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2518 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2519 | |
| 2520 | const VideoContentDescription* vcd = |
| 2521 | GetFirstVideoContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2522 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2523 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2524 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2525 | f2_.CreateOffer(opts, answer.get())); |
| 2526 | |
| 2527 | // The expected audio codecs are the common audio codecs from the first |
| 2528 | // offer/answer exchange plus the audio codecs only |f2_| offer, sorted in |
| 2529 | // preference order. |
wu@webrtc.org | ff1b1bf | 2014-06-20 20:57:42 +0000 | [diff] [blame] | 2530 | // TODO(wu): |updated_offer| should not include the codec |
| 2531 | // (i.e. |kAudioCodecs2[0]|) the other side doesn't support. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2532 | const AudioCodec kUpdatedAudioCodecOffer[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2533 | kAudioCodecsAnswer[0], kAudioCodecsAnswer[1], kAudioCodecs2[0], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2534 | }; |
| 2535 | |
| 2536 | // The expected video codecs are the common video codecs from the first |
| 2537 | // offer/answer exchange plus the video codecs only |f2_| offer, sorted in |
| 2538 | // preference order. |
| 2539 | const VideoCodec kUpdatedVideoCodecOffer[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2540 | kVideoCodecsAnswer[0], kVideoCodecs2[1], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2541 | }; |
| 2542 | |
| 2543 | const AudioContentDescription* updated_acd = |
| 2544 | GetFirstAudioContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2545 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kUpdatedAudioCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2546 | |
| 2547 | const VideoContentDescription* updated_vcd = |
| 2548 | GetFirstVideoContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2549 | EXPECT_THAT(updated_vcd->codecs(), ElementsAreArray(kUpdatedVideoCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2552 | // Test that a reoffer does not reuse audio codecs from a previous media section |
| 2553 | // that is being recycled. |
| 2554 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2555 | ReOfferDoesNotReUseRecycledAudioCodecs) { |
| 2556 | f1_.set_video_codecs({}); |
| 2557 | f2_.set_video_codecs({}); |
| 2558 | |
| 2559 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2560 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2561 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2562 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2563 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2564 | std::unique_ptr<SessionDescription> answer = |
| 2565 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2566 | |
| 2567 | // Recycle the media section by changing its mid. |
| 2568 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2569 | std::unique_ptr<SessionDescription> reoffer = |
| 2570 | f2_.CreateOffer(opts, answer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2571 | |
| 2572 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2573 | // section was not recycled the payload types would match the initial offerer. |
| 2574 | const AudioContentDescription* acd = |
| 2575 | GetFirstAudioContentDescription(reoffer.get()); |
| 2576 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecs2)); |
| 2577 | } |
| 2578 | |
| 2579 | // Test that a reoffer does not reuse video codecs from a previous media section |
| 2580 | // that is being recycled. |
| 2581 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2582 | ReOfferDoesNotReUseRecycledVideoCodecs) { |
| 2583 | f1_.set_audio_codecs({}, {}); |
| 2584 | f2_.set_audio_codecs({}, {}); |
| 2585 | |
| 2586 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2587 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2588 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2589 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2590 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2591 | auto answer = f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2592 | |
| 2593 | // Recycle the media section by changing its mid. |
| 2594 | opts.media_description_options[0].mid = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2595 | std::unique_ptr<SessionDescription> reoffer = |
| 2596 | f2_.CreateOffer(opts, answer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2597 | |
| 2598 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2599 | // section was not recycled the payload types would match the initial offerer. |
| 2600 | const VideoContentDescription* vcd = |
| 2601 | GetFirstVideoContentDescription(reoffer.get()); |
| 2602 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecs2)); |
| 2603 | } |
| 2604 | |
| 2605 | // Test that a reanswer does not reuse audio codecs from a previous media |
| 2606 | // section that is being recycled. |
| 2607 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2608 | ReAnswerDoesNotReUseRecycledAudioCodecs) { |
| 2609 | f1_.set_video_codecs({}); |
| 2610 | f2_.set_video_codecs({}); |
| 2611 | |
| 2612 | // Perform initial offer/answer in reverse (|f2_| as offerer) so that the |
| 2613 | // second offer/answer is forward (|f1_| as offerer). |
| 2614 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2615 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2616 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2617 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2618 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, nullptr); |
| 2619 | std::unique_ptr<SessionDescription> answer = |
| 2620 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2621 | |
| 2622 | // Recycle the media section by changing its mid. |
| 2623 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2624 | std::unique_ptr<SessionDescription> reoffer = |
| 2625 | f1_.CreateOffer(opts, answer.get()); |
| 2626 | std::unique_ptr<SessionDescription> reanswer = |
| 2627 | f2_.CreateAnswer(reoffer.get(), opts, offer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2628 | |
| 2629 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2630 | // section was not recycled the payload types would match the initial offerer. |
| 2631 | const AudioContentDescription* acd = |
| 2632 | GetFirstAudioContentDescription(reanswer.get()); |
| 2633 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
| 2634 | } |
| 2635 | |
| 2636 | // Test that a reanswer does not reuse video codecs from a previous media |
| 2637 | // section that is being recycled. |
| 2638 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2639 | ReAnswerDoesNotReUseRecycledVideoCodecs) { |
| 2640 | f1_.set_audio_codecs({}, {}); |
| 2641 | f2_.set_audio_codecs({}, {}); |
| 2642 | |
| 2643 | // Perform initial offer/answer in reverse (|f2_| as offerer) so that the |
| 2644 | // second offer/answer is forward (|f1_| as offerer). |
| 2645 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2646 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2647 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2648 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2649 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, nullptr); |
| 2650 | std::unique_ptr<SessionDescription> answer = |
| 2651 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2652 | |
| 2653 | // Recycle the media section by changing its mid. |
| 2654 | opts.media_description_options[0].mid = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2655 | std::unique_ptr<SessionDescription> reoffer = |
| 2656 | f1_.CreateOffer(opts, answer.get()); |
| 2657 | std::unique_ptr<SessionDescription> reanswer = |
| 2658 | f2_.CreateAnswer(reoffer.get(), opts, offer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2659 | |
| 2660 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2661 | // section was not recycled the payload types would match the initial offerer. |
| 2662 | const VideoContentDescription* vcd = |
| 2663 | GetFirstVideoContentDescription(reanswer.get()); |
| 2664 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
| 2665 | } |
| 2666 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2667 | // Create an updated offer after creating an answer to the original offer and |
| 2668 | // verify that the codecs that were part of the original answer are not changed |
| 2669 | // in the updated offer. In this test Rtx is enabled. |
| 2670 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2671 | RespondentCreatesOfferAfterCreatingAnswerWithRtx) { |
| 2672 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2673 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2674 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2675 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2676 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2677 | // This creates rtx for H264 with the payload type |f1_| uses. |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2678 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2679 | f1_.set_video_codecs(f1_codecs); |
| 2680 | |
| 2681 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2682 | // This creates rtx for H264 with the payload type |f2_| uses. |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2683 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2684 | f2_.set_video_codecs(f2_codecs); |
| 2685 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2686 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2687 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2688 | std::unique_ptr<SessionDescription> answer = |
| 2689 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2690 | |
| 2691 | const VideoContentDescription* vcd = |
| 2692 | GetFirstVideoContentDescription(answer.get()); |
| 2693 | |
| 2694 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2695 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 2696 | &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2697 | |
| 2698 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2699 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 2700 | // Now, make sure we get same result (except for the order) if |f2_| creates |
| 2701 | // an updated offer even though the default payload types between |f1_| and |
| 2702 | // |f2_| are different. |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2703 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2704 | f2_.CreateOffer(opts, answer.get())); |
| 2705 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2706 | std::unique_ptr<SessionDescription> updated_answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2707 | f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); |
| 2708 | |
| 2709 | const VideoContentDescription* updated_vcd = |
| 2710 | GetFirstVideoContentDescription(updated_answer.get()); |
| 2711 | |
| 2712 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 2713 | } |
| 2714 | |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2715 | // Regression test for: |
| 2716 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8332 |
| 2717 | // Existing codecs should always appear before new codecs in re-offers. But |
| 2718 | // under a specific set of circumstances, the existing RTX codec was ending up |
| 2719 | // added to the end of the list. |
| 2720 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2721 | RespondentCreatesOfferAfterCreatingAnswerWithRemappedRtxPayloadType) { |
| 2722 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2723 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2724 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2725 | &opts); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2726 | // We specifically choose different preferred payload types for VP8 to |
| 2727 | // trigger the issue. |
| 2728 | cricket::VideoCodec vp8_offerer(100, "VP8"); |
| 2729 | cricket::VideoCodec vp8_offerer_rtx = |
| 2730 | VideoCodec::CreateRtxCodec(101, vp8_offerer.id); |
| 2731 | cricket::VideoCodec vp8_answerer(110, "VP8"); |
| 2732 | cricket::VideoCodec vp8_answerer_rtx = |
| 2733 | VideoCodec::CreateRtxCodec(111, vp8_answerer.id); |
| 2734 | cricket::VideoCodec vp9(120, "VP9"); |
| 2735 | cricket::VideoCodec vp9_rtx = VideoCodec::CreateRtxCodec(121, vp9.id); |
| 2736 | |
| 2737 | std::vector<VideoCodec> f1_codecs = {vp8_offerer, vp8_offerer_rtx}; |
| 2738 | // We also specifically cause the answerer to prefer VP9, such that if it |
| 2739 | // *doesn't* honor the existing preferred codec (VP8) we'll notice. |
| 2740 | std::vector<VideoCodec> f2_codecs = {vp9, vp9_rtx, vp8_answerer, |
| 2741 | vp8_answerer_rtx}; |
| 2742 | |
| 2743 | f1_.set_video_codecs(f1_codecs); |
| 2744 | f2_.set_video_codecs(f2_codecs); |
| 2745 | std::vector<AudioCodec> audio_codecs; |
| 2746 | f1_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2747 | f2_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2748 | |
| 2749 | // Offer will be {VP8, RTX for VP8}. Answer will be the same. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2750 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2751 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2752 | std::unique_ptr<SessionDescription> answer = |
| 2753 | f2_.CreateAnswer(offer.get(), opts, NULL); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2754 | |
| 2755 | // Updated offer *should* be {VP8, RTX for VP8, VP9, RTX for VP9}. |
| 2756 | // But if the bug is triggered, RTX for VP8 ends up last. |
| 2757 | std::unique_ptr<SessionDescription> updated_offer( |
| 2758 | f2_.CreateOffer(opts, answer.get())); |
| 2759 | |
| 2760 | const VideoContentDescription* vcd = |
| 2761 | GetFirstVideoContentDescription(updated_offer.get()); |
| 2762 | std::vector<cricket::VideoCodec> codecs = vcd->codecs(); |
| 2763 | ASSERT_EQ(4u, codecs.size()); |
| 2764 | EXPECT_EQ(vp8_offerer, codecs[0]); |
| 2765 | EXPECT_EQ(vp8_offerer_rtx, codecs[1]); |
| 2766 | EXPECT_EQ(vp9, codecs[2]); |
| 2767 | EXPECT_EQ(vp9_rtx, codecs[3]); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2770 | // Create an updated offer that adds video after creating an audio only answer |
| 2771 | // to the original offer. This test verifies that if a video codec and the RTX |
| 2772 | // codec have the same default payload type as an audio codec that is already in |
| 2773 | // use, the added codecs payload types are changed. |
| 2774 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2775 | RespondentCreatesOfferWithVideoAndRtxAfterCreatingAudioAnswer) { |
| 2776 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2777 | // This creates rtx for H264 with the payload type |f1_| uses. |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2778 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2779 | f1_.set_video_codecs(f1_codecs); |
| 2780 | |
| 2781 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2782 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2783 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2784 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2785 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2786 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 2787 | std::unique_ptr<SessionDescription> answer = |
| 2788 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2789 | |
| 2790 | const AudioContentDescription* acd = |
| 2791 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2792 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2793 | |
| 2794 | // Now - let |f2_| add video with RTX and let the payload type the RTX codec |
| 2795 | // reference be the same as an audio codec that was negotiated in the |
| 2796 | // first offer/answer exchange. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2797 | opts.media_description_options.clear(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2798 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2799 | |
| 2800 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2801 | int used_pl_type = acd->codecs()[0].id; |
| 2802 | f2_codecs[0].id = used_pl_type; // Set the payload type for H264. |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2803 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, used_pl_type), &f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2804 | f2_.set_video_codecs(f2_codecs); |
| 2805 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2806 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2807 | f2_.CreateOffer(opts, answer.get())); |
| 2808 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2809 | std::unique_ptr<SessionDescription> updated_answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2810 | f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); |
| 2811 | |
| 2812 | const AudioContentDescription* updated_acd = |
| 2813 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2814 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2815 | |
| 2816 | const VideoContentDescription* updated_vcd = |
| 2817 | GetFirstVideoContentDescription(updated_answer.get()); |
| 2818 | |
| 2819 | ASSERT_EQ("H264", updated_vcd->codecs()[0].name); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2820 | ASSERT_EQ(cricket::kRtxCodecName, updated_vcd->codecs()[1].name); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2821 | int new_h264_pl_type = updated_vcd->codecs()[0].id; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2822 | EXPECT_NE(used_pl_type, new_h264_pl_type); |
| 2823 | VideoCodec rtx = updated_vcd->codecs()[1]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2824 | int pt_referenced_by_rtx = rtc::FromString<int>( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2825 | rtx.params[cricket::kCodecParamAssociatedPayloadType]); |
| 2826 | EXPECT_EQ(new_h264_pl_type, pt_referenced_by_rtx); |
| 2827 | } |
| 2828 | |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2829 | // Create an updated offer with RTX after creating an answer to an offer |
| 2830 | // without RTX, and with different default payload types. |
| 2831 | // Verify that the added RTX codec references the correct payload type. |
| 2832 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2833 | RespondentCreatesOfferWithRtxAfterCreatingAnswerWithoutRtx) { |
| 2834 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2835 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2836 | |
| 2837 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2838 | // This creates rtx for H264 with the payload type |f2_| uses. |
| 2839 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
| 2840 | f2_.set_video_codecs(f2_codecs); |
| 2841 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2842 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2843 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2844 | std::unique_ptr<SessionDescription> answer = |
| 2845 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2846 | |
| 2847 | const VideoContentDescription* vcd = |
| 2848 | GetFirstVideoContentDescription(answer.get()); |
| 2849 | |
| 2850 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
| 2851 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2852 | |
| 2853 | // Now, ensure that the RTX codec is created correctly when |f2_| creates an |
| 2854 | // updated offer, even though the default payload types are different from |
| 2855 | // those of |f1_|. |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2856 | std::unique_ptr<SessionDescription> updated_offer( |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2857 | f2_.CreateOffer(opts, answer.get())); |
| 2858 | ASSERT_TRUE(updated_offer); |
| 2859 | |
| 2860 | const VideoContentDescription* updated_vcd = |
| 2861 | GetFirstVideoContentDescription(updated_offer.get()); |
| 2862 | |
| 2863 | // New offer should attempt to add H263, and RTX for H264. |
| 2864 | expected_codecs.push_back(kVideoCodecs2[1]); |
| 2865 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[1].id), |
| 2866 | &expected_codecs); |
| 2867 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 2868 | } |
| 2869 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2870 | // Test that RTX is ignored when there is no associated payload type parameter. |
| 2871 | TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { |
| 2872 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2873 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2874 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2875 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2876 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2877 | // This creates RTX without associated payload type parameter. |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 2878 | AddRtxCodec(VideoCodec(126, cricket::kRtxCodecName), &f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2879 | f1_.set_video_codecs(f1_codecs); |
| 2880 | |
| 2881 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2882 | // This creates RTX for H264 with the payload type |f2_| uses. |
| 2883 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2884 | f2_.set_video_codecs(f2_codecs); |
| 2885 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2886 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2887 | ASSERT_TRUE(offer.get() != NULL); |
| 2888 | // kCodecParamAssociatedPayloadType will always be added to the offer when RTX |
| 2889 | // is selected. Manually remove kCodecParamAssociatedPayloadType so that it |
| 2890 | // is possible to test that that RTX is dropped when |
| 2891 | // kCodecParamAssociatedPayloadType is missing in the offer. |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2892 | MediaContentDescription* media_desc = |
| 2893 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 2894 | ASSERT_TRUE(media_desc); |
| 2895 | VideoContentDescription* desc = media_desc->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2896 | std::vector<VideoCodec> codecs = desc->codecs(); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 2897 | for (VideoCodec& codec : codecs) { |
| 2898 | if (codec.name.find(cricket::kRtxCodecName) == 0) { |
| 2899 | codec.params.clear(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2900 | } |
| 2901 | } |
| 2902 | desc->set_codecs(codecs); |
| 2903 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2904 | std::unique_ptr<SessionDescription> answer = |
| 2905 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2906 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 2907 | EXPECT_THAT( |
| 2908 | GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), |
| 2909 | Not(Contains(cricket::kRtxCodecName))); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | // Test that RTX will be filtered out in the answer if its associated payload |
| 2913 | // type doesn't match the local value. |
| 2914 | TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { |
| 2915 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2916 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2917 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2918 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2919 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2920 | // This creates RTX for H264 in sender. |
| 2921 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 2922 | f1_.set_video_codecs(f1_codecs); |
| 2923 | |
| 2924 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2925 | // This creates RTX for H263 in receiver. |
| 2926 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[1].id), &f2_codecs); |
| 2927 | f2_.set_video_codecs(f2_codecs); |
| 2928 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2929 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2930 | ASSERT_TRUE(offer.get() != NULL); |
| 2931 | // Associated payload type doesn't match, therefore, RTX codec is removed in |
| 2932 | // the answer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2933 | std::unique_ptr<SessionDescription> answer = |
| 2934 | f2_.CreateAnswer(offer.get(), opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2935 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 2936 | EXPECT_THAT( |
| 2937 | GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), |
| 2938 | Not(Contains(cricket::kRtxCodecName))); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | // Test that when multiple RTX codecs are offered, only the matched RTX codec |
| 2942 | // is added in the answer, and the unsupported RTX codec is filtered out. |
| 2943 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2944 | FilterOutUnsupportedRtxWhenCreatingAnswer) { |
| 2945 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2946 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2947 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2948 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2949 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2950 | // This creates RTX for H264-SVC in sender. |
| 2951 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
| 2952 | f1_.set_video_codecs(f1_codecs); |
| 2953 | |
| 2954 | // This creates RTX for H264 in sender. |
| 2955 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 2956 | f1_.set_video_codecs(f1_codecs); |
| 2957 | |
| 2958 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2959 | // This creates RTX for H264 in receiver. |
| 2960 | AddRtxCodec(VideoCodec::CreateRtxCodec(124, kVideoCodecs2[0].id), &f2_codecs); |
| 2961 | f2_.set_video_codecs(f2_codecs); |
| 2962 | |
| 2963 | // H264-SVC codec is removed in the answer, therefore, associated RTX codec |
| 2964 | // for H264-SVC should also be removed. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2965 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2966 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2967 | std::unique_ptr<SessionDescription> answer = |
| 2968 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2969 | const VideoContentDescription* vcd = |
| 2970 | GetFirstVideoContentDescription(answer.get()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2971 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
| 2972 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 2973 | &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2974 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2975 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2976 | } |
| 2977 | |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2978 | // Test that after one RTX codec has been negotiated, a new offer can attempt |
| 2979 | // to add another. |
| 2980 | TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { |
| 2981 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2982 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2983 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2984 | &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2985 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2986 | // This creates RTX for H264 for the offerer. |
| 2987 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 2988 | f1_.set_video_codecs(f1_codecs); |
| 2989 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2990 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2991 | ASSERT_TRUE(offer); |
| 2992 | const VideoContentDescription* vcd = |
| 2993 | GetFirstVideoContentDescription(offer.get()); |
| 2994 | |
| 2995 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2996 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 2997 | &expected_codecs); |
| 2998 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2999 | |
| 3000 | // Now, attempt to add RTX for H264-SVC. |
| 3001 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
| 3002 | f1_.set_video_codecs(f1_codecs); |
| 3003 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3004 | std::unique_ptr<SessionDescription> updated_offer( |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3005 | f1_.CreateOffer(opts, offer.get())); |
| 3006 | ASSERT_TRUE(updated_offer); |
| 3007 | vcd = GetFirstVideoContentDescription(updated_offer.get()); |
| 3008 | |
| 3009 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), |
| 3010 | &expected_codecs); |
| 3011 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3012 | } |
| 3013 | |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3014 | // Test that when RTX is used in conjunction with simulcast, an RTX ssrc is |
| 3015 | // generated for each simulcast ssrc and correctly grouped. |
| 3016 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { |
| 3017 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3018 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3019 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3020 | &opts); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3021 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3022 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3023 | {"stream1label"}, 3, &opts); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3024 | |
| 3025 | // Use a single real codec, and then add RTX for it. |
| 3026 | std::vector<VideoCodec> f1_codecs; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3027 | f1_codecs.push_back(VideoCodec(97, "H264")); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3028 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, 97), &f1_codecs); |
| 3029 | f1_.set_video_codecs(f1_codecs); |
| 3030 | |
| 3031 | // Ensure that the offer has an RTX ssrc for each regular ssrc, and that there |
| 3032 | // is a FID ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3033 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3034 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3035 | MediaContentDescription* media_desc = |
| 3036 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3037 | ASSERT_TRUE(media_desc); |
| 3038 | VideoContentDescription* desc = media_desc->as_video(); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3039 | const StreamParamsVec& streams = desc->streams(); |
| 3040 | // Single stream. |
| 3041 | ASSERT_EQ(1u, streams.size()); |
| 3042 | // Stream should have 6 ssrcs: 3 for video, 3 for RTX. |
| 3043 | EXPECT_EQ(6u, streams[0].ssrcs.size()); |
| 3044 | // And should have a SIM group for the simulcast. |
| 3045 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3046 | // And a FID group for RTX. |
| 3047 | EXPECT_TRUE(streams[0].has_ssrc_group("FID")); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3048 | std::vector<uint32_t> primary_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3049 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3050 | EXPECT_EQ(3u, primary_ssrcs.size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3051 | std::vector<uint32_t> fid_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3052 | streams[0].GetFidSsrcs(primary_ssrcs, &fid_ssrcs); |
| 3053 | EXPECT_EQ(3u, fid_ssrcs.size()); |
| 3054 | } |
| 3055 | |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3056 | // Test that, when the FlexFEC codec is added, a FlexFEC ssrc is created |
| 3057 | // together with a FEC-FR grouping. |
| 3058 | TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { |
| 3059 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3060 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3061 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3062 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3063 | // Add single stream. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3064 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3065 | {"stream1label"}, 1, &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3066 | |
| 3067 | // Use a single real codec, and then add FlexFEC for it. |
| 3068 | std::vector<VideoCodec> f1_codecs; |
| 3069 | f1_codecs.push_back(VideoCodec(97, "H264")); |
| 3070 | f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
| 3071 | f1_.set_video_codecs(f1_codecs); |
| 3072 | |
| 3073 | // Ensure that the offer has a single FlexFEC ssrc and that |
| 3074 | // there is no FEC-FR ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3075 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3076 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3077 | MediaContentDescription* media_desc = |
| 3078 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3079 | ASSERT_TRUE(media_desc); |
| 3080 | VideoContentDescription* desc = media_desc->as_video(); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3081 | const StreamParamsVec& streams = desc->streams(); |
| 3082 | // Single stream. |
| 3083 | ASSERT_EQ(1u, streams.size()); |
| 3084 | // Stream should have 2 ssrcs: 1 for video, 1 for FlexFEC. |
| 3085 | EXPECT_EQ(2u, streams[0].ssrcs.size()); |
| 3086 | // And should have a FEC-FR group for FlexFEC. |
| 3087 | EXPECT_TRUE(streams[0].has_ssrc_group("FEC-FR")); |
| 3088 | std::vector<uint32_t> primary_ssrcs; |
| 3089 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3090 | ASSERT_EQ(1u, primary_ssrcs.size()); |
| 3091 | uint32_t flexfec_ssrc; |
| 3092 | EXPECT_TRUE(streams[0].GetFecFrSsrc(primary_ssrcs[0], &flexfec_ssrc)); |
| 3093 | EXPECT_NE(flexfec_ssrc, 0u); |
| 3094 | } |
| 3095 | |
| 3096 | // Test that FlexFEC is disabled for simulcast. |
| 3097 | // TODO(brandtr): Remove this test when we support simulcast, either through |
| 3098 | // multiple FlexfecSenders, or through multistream protection. |
| 3099 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { |
| 3100 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3101 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3102 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3103 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3104 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3105 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3106 | {"stream1label"}, 3, &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3107 | |
| 3108 | // Use a single real codec, and then add FlexFEC for it. |
| 3109 | std::vector<VideoCodec> f1_codecs; |
| 3110 | f1_codecs.push_back(VideoCodec(97, "H264")); |
| 3111 | f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
| 3112 | f1_.set_video_codecs(f1_codecs); |
| 3113 | |
| 3114 | // Ensure that the offer has no FlexFEC ssrcs for each regular ssrc, and that |
| 3115 | // there is no FEC-FR ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3116 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3117 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3118 | MediaContentDescription* media_desc = |
| 3119 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3120 | ASSERT_TRUE(media_desc); |
| 3121 | VideoContentDescription* desc = media_desc->as_video(); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3122 | const StreamParamsVec& streams = desc->streams(); |
| 3123 | // Single stream. |
| 3124 | ASSERT_EQ(1u, streams.size()); |
| 3125 | // Stream should have 3 ssrcs: 3 for video, 0 for FlexFEC. |
| 3126 | EXPECT_EQ(3u, streams[0].ssrcs.size()); |
| 3127 | // And should have a SIM group for the simulcast. |
| 3128 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3129 | // And not a FEC-FR group for FlexFEC. |
| 3130 | EXPECT_FALSE(streams[0].has_ssrc_group("FEC-FR")); |
| 3131 | std::vector<uint32_t> primary_ssrcs; |
| 3132 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3133 | EXPECT_EQ(3u, primary_ssrcs.size()); |
| 3134 | for (uint32_t primary_ssrc : primary_ssrcs) { |
| 3135 | uint32_t flexfec_ssrc; |
| 3136 | EXPECT_FALSE(streams[0].GetFecFrSsrc(primary_ssrc, &flexfec_ssrc)); |
| 3137 | } |
| 3138 | } |
| 3139 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3140 | // Create an updated offer after creating an answer to the original offer and |
| 3141 | // verify that the RTP header extensions that were part of the original answer |
| 3142 | // are not changed in the updated offer. |
| 3143 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3144 | RespondentCreatesOfferAfterCreatingAnswerWithRtpExtensions) { |
| 3145 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3146 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3147 | |
| 3148 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 3149 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 3150 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 3151 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 3152 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3153 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 3154 | std::unique_ptr<SessionDescription> answer = |
| 3155 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3156 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3157 | EXPECT_EQ( |
| 3158 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 3159 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 3160 | EXPECT_EQ( |
| 3161 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 3162 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3163 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3164 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3165 | f2_.CreateOffer(opts, answer.get())); |
| 3166 | |
| 3167 | // The expected RTP header extensions in the new offer are the resulting |
| 3168 | // extensions from the first offer/answer exchange plus the extensions only |
| 3169 | // |f2_| offer. |
| 3170 | // Since the default local extension id |f2_| uses has already been used by |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 3171 | // |f1_| for another extensions, it is changed to 13. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3172 | const RtpExtension kUpdatedAudioRtpExtensions[] = { |
| 3173 | kAudioRtpExtensionAnswer[0], RtpExtension(kAudioRtpExtension2[1].uri, 13), |
| 3174 | kAudioRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3175 | }; |
| 3176 | |
| 3177 | // Since the default local extension id |f2_| uses has already been used by |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 3178 | // |f1_| for another extensions, is is changed to 12. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3179 | const RtpExtension kUpdatedVideoRtpExtensions[] = { |
| 3180 | kVideoRtpExtensionAnswer[0], RtpExtension(kVideoRtpExtension2[1].uri, 12), |
| 3181 | kVideoRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3182 | }; |
| 3183 | |
| 3184 | const AudioContentDescription* updated_acd = |
| 3185 | GetFirstAudioContentDescription(updated_offer.get()); |
| 3186 | EXPECT_EQ(MAKE_VECTOR(kUpdatedAudioRtpExtensions), |
| 3187 | updated_acd->rtp_header_extensions()); |
| 3188 | |
| 3189 | const VideoContentDescription* updated_vcd = |
| 3190 | GetFirstVideoContentDescription(updated_offer.get()); |
| 3191 | EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoRtpExtensions), |
| 3192 | updated_vcd->rtp_header_extensions()); |
| 3193 | } |
| 3194 | |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3195 | // Verify that if the same RTP extension URI is used for audio and video, the |
| 3196 | // same ID is used. Also verify that the ID isn't changed when creating an |
| 3197 | // updated offer (this was previously a bug). |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3198 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3199 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3200 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3201 | |
| 3202 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension3)); |
| 3203 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension3)); |
| 3204 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3205 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3206 | |
| 3207 | // Since the audio extensions used ID 3 for "both_audio_and_video", so should |
| 3208 | // the video extensions. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3209 | const RtpExtension kExpectedVideoRtpExtension[] = { |
| 3210 | kVideoRtpExtension3[0], kAudioRtpExtension3[1], |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3211 | }; |
| 3212 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3213 | EXPECT_EQ( |
| 3214 | MAKE_VECTOR(kAudioRtpExtension3), |
| 3215 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3216 | EXPECT_EQ( |
| 3217 | MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 3218 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3219 | |
| 3220 | // Nothing should change when creating a new offer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3221 | std::unique_ptr<SessionDescription> updated_offer( |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3222 | f1_.CreateOffer(opts, offer.get())); |
| 3223 | |
| 3224 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3225 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3226 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3227 | EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3228 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3229 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3232 | // Same as "RtpExtensionIdReused" above for encrypted RTP extensions. |
| 3233 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { |
| 3234 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3235 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3236 | |
| 3237 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 3238 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 3239 | |
| 3240 | f1_.set_audio_rtp_header_extensions( |
| 3241 | MAKE_VECTOR(kAudioRtpExtension3ForEncryption)); |
| 3242 | f1_.set_video_rtp_header_extensions( |
| 3243 | MAKE_VECTOR(kVideoRtpExtension3ForEncryption)); |
| 3244 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3245 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3246 | |
| 3247 | // The extensions that are shared between audio and video should use the same |
| 3248 | // id. |
| 3249 | const RtpExtension kExpectedVideoRtpExtension[] = { |
| 3250 | kVideoRtpExtension3ForEncryption[0], |
| 3251 | kAudioRtpExtension3ForEncryptionOffer[1], |
| 3252 | kAudioRtpExtension3ForEncryptionOffer[2], |
| 3253 | }; |
| 3254 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3255 | EXPECT_EQ( |
| 3256 | MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
| 3257 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3258 | EXPECT_EQ( |
| 3259 | MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 3260 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3261 | |
| 3262 | // Nothing should change when creating a new offer |
| 3263 | std::unique_ptr<SessionDescription> updated_offer( |
| 3264 | f1_.CreateOffer(opts, offer.get())); |
| 3265 | |
| 3266 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3267 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3268 | ->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3269 | EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3270 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3271 | ->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3274 | TEST(MediaSessionDescription, CopySessionDescription) { |
| 3275 | SessionDescription source; |
| 3276 | cricket::ContentGroup group(cricket::CN_AUDIO); |
| 3277 | source.AddGroup(group); |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 3278 | std::unique_ptr<AudioContentDescription> acd = |
| 3279 | absl::make_unique<AudioContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3280 | acd->set_codecs(MAKE_VECTOR(kAudioCodecs1)); |
| 3281 | acd->AddLegacyStream(1); |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 3282 | std::unique_ptr<AudioContentDescription> acd_passed = |
| 3283 | absl::WrapUnique(acd->Copy()); |
| 3284 | source.AddContent(cricket::CN_AUDIO, MediaProtocolType::kRtp, |
| 3285 | std::move(acd_passed)); |
| 3286 | std::unique_ptr<VideoContentDescription> vcd = |
| 3287 | absl::make_unique<VideoContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3288 | vcd->set_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 3289 | vcd->AddLegacyStream(2); |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 3290 | std::unique_ptr<VideoContentDescription> vcd_passed = |
| 3291 | absl::WrapUnique(vcd->Copy()); |
| 3292 | source.AddContent(cricket::CN_VIDEO, MediaProtocolType::kRtp, |
| 3293 | std::move(vcd_passed)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3294 | |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 3295 | std::unique_ptr<SessionDescription> copy = source.Clone(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3296 | ASSERT_TRUE(copy.get() != NULL); |
| 3297 | EXPECT_TRUE(copy->HasGroup(cricket::CN_AUDIO)); |
| 3298 | const ContentInfo* ac = copy->GetContentByName("audio"); |
| 3299 | const ContentInfo* vc = copy->GetContentByName("video"); |
| 3300 | ASSERT_TRUE(ac != NULL); |
| 3301 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 3302 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3303 | const AudioContentDescription* acd_copy = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3304 | EXPECT_EQ(acd->codecs(), acd_copy->codecs()); |
| 3305 | EXPECT_EQ(1u, acd->first_ssrc()); |
| 3306 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 3307 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3308 | const VideoContentDescription* vcd_copy = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3309 | EXPECT_EQ(vcd->codecs(), vcd_copy->codecs()); |
| 3310 | EXPECT_EQ(2u, vcd->first_ssrc()); |
| 3311 | } |
| 3312 | |
| 3313 | // The below TestTransportInfoXXX tests create different offers/answers, and |
| 3314 | // ensure the TransportInfo in the SessionDescription matches what we expect. |
| 3315 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudio) { |
| 3316 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3317 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3318 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3319 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3320 | TestTransportInfo(true, options, false); |
| 3321 | } |
| 3322 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3323 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3324 | TestTransportInfoOfferIceRenomination) { |
| 3325 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3326 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3327 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3328 | &options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3329 | options.media_description_options[0] |
| 3330 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3331 | TestTransportInfo(true, options, false); |
| 3332 | } |
| 3333 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3334 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudioCurrent) { |
| 3335 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3336 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3337 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3338 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3339 | TestTransportInfo(true, options, true); |
| 3340 | } |
| 3341 | |
| 3342 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferMultimedia) { |
| 3343 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3344 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3345 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3346 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3347 | TestTransportInfo(true, options, false); |
| 3348 | } |
| 3349 | |
| 3350 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3351 | TestTransportInfoOfferMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3352 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3353 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3354 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3355 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3356 | TestTransportInfo(true, options, true); |
| 3357 | } |
| 3358 | |
| 3359 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferBundle) { |
| 3360 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3361 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3362 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3363 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3364 | options.bundle_enabled = true; |
| 3365 | TestTransportInfo(true, options, false); |
| 3366 | } |
| 3367 | |
| 3368 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3369 | TestTransportInfoOfferBundleCurrent) { |
| 3370 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3371 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3372 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3373 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3374 | options.bundle_enabled = true; |
| 3375 | TestTransportInfo(true, options, true); |
| 3376 | } |
| 3377 | |
| 3378 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerAudio) { |
| 3379 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3380 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3381 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3382 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3383 | TestTransportInfo(false, options, false); |
| 3384 | } |
| 3385 | |
| 3386 | TEST_F(MediaSessionDescriptionFactoryTest, |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3387 | TestTransportInfoAnswerIceRenomination) { |
| 3388 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3389 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3390 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3391 | &options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3392 | options.media_description_options[0] |
| 3393 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3394 | TestTransportInfo(false, options, false); |
| 3395 | } |
| 3396 | |
| 3397 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3398 | TestTransportInfoAnswerAudioCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3399 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3400 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3401 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3402 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3403 | TestTransportInfo(false, options, true); |
| 3404 | } |
| 3405 | |
| 3406 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerMultimedia) { |
| 3407 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3408 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3409 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3410 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3411 | TestTransportInfo(false, options, false); |
| 3412 | } |
| 3413 | |
| 3414 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3415 | TestTransportInfoAnswerMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3416 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3417 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3418 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3419 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3420 | TestTransportInfo(false, options, true); |
| 3421 | } |
| 3422 | |
| 3423 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerBundle) { |
| 3424 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3425 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3426 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3427 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3428 | options.bundle_enabled = true; |
| 3429 | TestTransportInfo(false, options, false); |
| 3430 | } |
| 3431 | |
| 3432 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3433 | TestTransportInfoAnswerBundleCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3434 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3435 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3436 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3437 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3438 | options.bundle_enabled = true; |
| 3439 | TestTransportInfo(false, options, true); |
| 3440 | } |
| 3441 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 3442 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3443 | TestTransportInfoOfferBundlesTransportOptions) { |
| 3444 | MediaSessionOptions options; |
| 3445 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3446 | |
| 3447 | cricket::OpaqueTransportParameters audio_params; |
| 3448 | audio_params.protocol = "audio-transport"; |
| 3449 | audio_params.parameters = "audio-params"; |
| 3450 | FindFirstMediaDescriptionByMid("audio", &options) |
| 3451 | ->transport_options.opaque_parameters = audio_params; |
| 3452 | |
| 3453 | cricket::OpaqueTransportParameters video_params; |
| 3454 | video_params.protocol = "video-transport"; |
| 3455 | video_params.parameters = "video-params"; |
| 3456 | FindFirstMediaDescriptionByMid("video", &options) |
| 3457 | ->transport_options.opaque_parameters = video_params; |
| 3458 | |
| 3459 | TestTransportInfo(/*offer=*/true, options, /*has_current_desc=*/false); |
| 3460 | } |
| 3461 | |
| 3462 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3463 | TestTransportInfoAnswerBundlesTransportOptions) { |
| 3464 | MediaSessionOptions options; |
| 3465 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3466 | |
| 3467 | cricket::OpaqueTransportParameters audio_params; |
| 3468 | audio_params.protocol = "audio-transport"; |
| 3469 | audio_params.parameters = "audio-params"; |
| 3470 | FindFirstMediaDescriptionByMid("audio", &options) |
| 3471 | ->transport_options.opaque_parameters = audio_params; |
| 3472 | |
| 3473 | cricket::OpaqueTransportParameters video_params; |
| 3474 | video_params.protocol = "video-transport"; |
| 3475 | video_params.parameters = "video-params"; |
| 3476 | FindFirstMediaDescriptionByMid("video", &options) |
| 3477 | ->transport_options.opaque_parameters = video_params; |
| 3478 | |
| 3479 | TestTransportInfo(/*offer=*/false, options, /*has_current_desc=*/false); |
| 3480 | } |
| 3481 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3482 | // Create an offer with bundle enabled and verify the crypto parameters are |
| 3483 | // the common set of the available cryptos. |
| 3484 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithOfferBundle) { |
| 3485 | TestCryptoWithBundle(true); |
| 3486 | } |
| 3487 | |
| 3488 | // Create an answer with bundle enabled and verify the crypto parameters are |
| 3489 | // the common set of the available cryptos. |
| 3490 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithAnswerBundle) { |
| 3491 | TestCryptoWithBundle(false); |
| 3492 | } |
| 3493 | |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3494 | // Verifies that creating answer fails if the offer has UDP/TLS/RTP/SAVPF but |
| 3495 | // DTLS is not enabled locally. |
| 3496 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3497 | TestOfferDtlsSavpfWithoutDtlsFailed) { |
| 3498 | f1_.set_secure(SEC_ENABLED); |
| 3499 | f2_.set_secure(SEC_ENABLED); |
| 3500 | tdf1_.set_secure(SEC_DISABLED); |
| 3501 | tdf2_.set_secure(SEC_DISABLED); |
| 3502 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3503 | std::unique_ptr<SessionDescription> offer = |
| 3504 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3505 | ASSERT_TRUE(offer.get() != NULL); |
| 3506 | ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 3507 | ASSERT_TRUE(offer_content != NULL); |
| 3508 | AudioContentDescription* offer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3509 | offer_content->media_description()->as_audio(); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3510 | offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 3511 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3512 | std::unique_ptr<SessionDescription> answer = |
| 3513 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3514 | ASSERT_TRUE(answer != NULL); |
| 3515 | ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 3516 | ASSERT_TRUE(answer_content != NULL); |
| 3517 | |
| 3518 | ASSERT_TRUE(answer_content->rejected); |
| 3519 | } |
| 3520 | |
| 3521 | // Offers UDP/TLS/RTP/SAVPF and verifies the answer can be created and contains |
| 3522 | // UDP/TLS/RTP/SAVPF. |
| 3523 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferDtlsSavpfCreateAnswer) { |
| 3524 | f1_.set_secure(SEC_ENABLED); |
| 3525 | f2_.set_secure(SEC_ENABLED); |
| 3526 | tdf1_.set_secure(SEC_ENABLED); |
| 3527 | tdf2_.set_secure(SEC_ENABLED); |
| 3528 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3529 | std::unique_ptr<SessionDescription> offer = |
| 3530 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3531 | ASSERT_TRUE(offer.get() != NULL); |
| 3532 | ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 3533 | ASSERT_TRUE(offer_content != NULL); |
| 3534 | AudioContentDescription* offer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3535 | offer_content->media_description()->as_audio(); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3536 | offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 3537 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3538 | std::unique_ptr<SessionDescription> answer = |
| 3539 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3540 | ASSERT_TRUE(answer != NULL); |
| 3541 | |
| 3542 | const ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 3543 | ASSERT_TRUE(answer_content != NULL); |
| 3544 | ASSERT_FALSE(answer_content->rejected); |
| 3545 | |
| 3546 | const AudioContentDescription* answer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3547 | answer_content->media_description()->as_audio(); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3548 | EXPECT_EQ(cricket::kMediaProtocolDtlsSavpf, answer_audio_desc->protocol()); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3551 | // Test that we include both SDES and DTLS in the offer, but only include SDES |
| 3552 | // in the answer if DTLS isn't negotiated. |
| 3553 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoDtls) { |
| 3554 | f1_.set_secure(SEC_ENABLED); |
| 3555 | f2_.set_secure(SEC_ENABLED); |
| 3556 | tdf1_.set_secure(SEC_ENABLED); |
| 3557 | tdf2_.set_secure(SEC_DISABLED); |
| 3558 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3559 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3560 | std::unique_ptr<SessionDescription> offer, answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3561 | const cricket::MediaContentDescription* audio_media_desc; |
| 3562 | const cricket::MediaContentDescription* video_media_desc; |
| 3563 | const cricket::TransportDescription* audio_trans_desc; |
| 3564 | const cricket::TransportDescription* video_trans_desc; |
| 3565 | |
| 3566 | // Generate an offer with SDES and DTLS support. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3567 | offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3568 | ASSERT_TRUE(offer.get() != NULL); |
| 3569 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3570 | audio_media_desc = offer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3571 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3572 | video_media_desc = offer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3573 | ASSERT_TRUE(video_media_desc != NULL); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 3574 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3575 | EXPECT_EQ(1u, video_media_desc->cryptos().size()); |
| 3576 | |
| 3577 | audio_trans_desc = offer->GetTransportDescriptionByName("audio"); |
| 3578 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3579 | video_trans_desc = offer->GetTransportDescriptionByName("video"); |
| 3580 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3581 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3582 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
| 3583 | |
| 3584 | // Generate an answer with only SDES support, since tdf2 has crypto disabled. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3585 | answer = f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3586 | ASSERT_TRUE(answer.get() != NULL); |
| 3587 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3588 | audio_media_desc = answer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3589 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3590 | video_media_desc = answer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3591 | ASSERT_TRUE(video_media_desc != NULL); |
| 3592 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
| 3593 | EXPECT_EQ(1u, video_media_desc->cryptos().size()); |
| 3594 | |
| 3595 | audio_trans_desc = answer->GetTransportDescriptionByName("audio"); |
| 3596 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3597 | video_trans_desc = answer->GetTransportDescriptionByName("video"); |
| 3598 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3599 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() == NULL); |
| 3600 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() == NULL); |
| 3601 | |
| 3602 | // Enable DTLS; the answer should now only have DTLS support. |
| 3603 | tdf2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3604 | answer = f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3605 | ASSERT_TRUE(answer.get() != NULL); |
| 3606 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3607 | audio_media_desc = answer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3608 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3609 | video_media_desc = answer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3610 | ASSERT_TRUE(video_media_desc != NULL); |
| 3611 | EXPECT_TRUE(audio_media_desc->cryptos().empty()); |
| 3612 | EXPECT_TRUE(video_media_desc->cryptos().empty()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3613 | EXPECT_EQ(cricket::kMediaProtocolSavpf, audio_media_desc->protocol()); |
| 3614 | EXPECT_EQ(cricket::kMediaProtocolSavpf, video_media_desc->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3615 | |
| 3616 | audio_trans_desc = answer->GetTransportDescriptionByName("audio"); |
| 3617 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3618 | video_trans_desc = answer->GetTransportDescriptionByName("video"); |
| 3619 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3620 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3621 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3622 | |
| 3623 | // Try creating offer again. DTLS enabled now, crypto's should be empty |
| 3624 | // in new offer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3625 | offer = f1_.CreateOffer(options, offer.get()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3626 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3627 | audio_media_desc = offer->GetContentDescriptionByName("audio"); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3628 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3629 | video_media_desc = offer->GetContentDescriptionByName("video"); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3630 | ASSERT_TRUE(video_media_desc != NULL); |
| 3631 | EXPECT_TRUE(audio_media_desc->cryptos().empty()); |
| 3632 | EXPECT_TRUE(video_media_desc->cryptos().empty()); |
| 3633 | |
| 3634 | audio_trans_desc = offer->GetTransportDescriptionByName("audio"); |
| 3635 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3636 | video_trans_desc = offer->GetTransportDescriptionByName("video"); |
| 3637 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3638 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3639 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | // Test that an answer can't be created if cryptos are required but the offer is |
| 3643 | // unsecure. |
| 3644 | TEST_F(MediaSessionDescriptionFactoryTest, TestSecureAnswerToUnsecureOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3645 | MediaSessionOptions options = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3646 | f1_.set_secure(SEC_DISABLED); |
| 3647 | tdf1_.set_secure(SEC_DISABLED); |
| 3648 | f2_.set_secure(SEC_REQUIRED); |
| 3649 | tdf1_.set_secure(SEC_ENABLED); |
| 3650 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3651 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3652 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3653 | std::unique_ptr<SessionDescription> answer = |
| 3654 | f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3655 | EXPECT_TRUE(answer.get() == NULL); |
| 3656 | } |
| 3657 | |
| 3658 | // Test that we accept a DTLS offer without SDES and create an appropriate |
| 3659 | // answer. |
| 3660 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { |
| 3661 | f1_.set_secure(SEC_DISABLED); |
| 3662 | f2_.set_secure(SEC_ENABLED); |
| 3663 | tdf1_.set_secure(SEC_ENABLED); |
| 3664 | tdf2_.set_secure(SEC_ENABLED); |
| 3665 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3666 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3667 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3668 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3669 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3670 | // Generate an offer with DTLS but without SDES. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3671 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3672 | ASSERT_TRUE(offer.get() != NULL); |
| 3673 | |
| 3674 | const AudioContentDescription* audio_offer = |
| 3675 | GetFirstAudioContentDescription(offer.get()); |
| 3676 | ASSERT_TRUE(audio_offer->cryptos().empty()); |
| 3677 | const VideoContentDescription* video_offer = |
| 3678 | GetFirstVideoContentDescription(offer.get()); |
| 3679 | ASSERT_TRUE(video_offer->cryptos().empty()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 3680 | const RtpDataContentDescription* data_offer = |
| 3681 | GetFirstRtpDataContentDescription(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3682 | ASSERT_TRUE(data_offer->cryptos().empty()); |
| 3683 | |
| 3684 | const cricket::TransportDescription* audio_offer_trans_desc = |
| 3685 | offer->GetTransportDescriptionByName("audio"); |
| 3686 | ASSERT_TRUE(audio_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 3687 | const cricket::TransportDescription* video_offer_trans_desc = |
| 3688 | offer->GetTransportDescriptionByName("video"); |
| 3689 | ASSERT_TRUE(video_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 3690 | const cricket::TransportDescription* data_offer_trans_desc = |
| 3691 | offer->GetTransportDescriptionByName("data"); |
| 3692 | ASSERT_TRUE(data_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 3693 | |
| 3694 | // Generate an answer with DTLS. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3695 | std::unique_ptr<SessionDescription> answer = |
| 3696 | f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3697 | ASSERT_TRUE(answer.get() != NULL); |
| 3698 | |
| 3699 | const cricket::TransportDescription* audio_answer_trans_desc = |
| 3700 | answer->GetTransportDescriptionByName("audio"); |
| 3701 | EXPECT_TRUE(audio_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 3702 | const cricket::TransportDescription* video_answer_trans_desc = |
| 3703 | answer->GetTransportDescriptionByName("video"); |
| 3704 | EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 3705 | const cricket::TransportDescription* data_answer_trans_desc = |
| 3706 | answer->GetTransportDescriptionByName("data"); |
| 3707 | EXPECT_TRUE(data_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 3708 | } |
| 3709 | |
| 3710 | // Verifies if vad_enabled option is set to false, CN codecs are not present in |
| 3711 | // offer or answer. |
| 3712 | TEST_F(MediaSessionDescriptionFactoryTest, TestVADEnableOption) { |
| 3713 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3714 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3715 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3716 | ASSERT_TRUE(offer.get() != NULL); |
| 3717 | const ContentInfo* audio_content = offer->GetContentByName("audio"); |
| 3718 | EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); |
| 3719 | |
| 3720 | options.vad_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3721 | offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3722 | ASSERT_TRUE(offer.get() != NULL); |
| 3723 | audio_content = offer->GetContentByName("audio"); |
| 3724 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3725 | std::unique_ptr<SessionDescription> answer = |
| 3726 | f1_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3727 | ASSERT_TRUE(answer.get() != NULL); |
| 3728 | audio_content = answer->GetContentByName("audio"); |
| 3729 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
| 3730 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 3731 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3732 | // Test that the generated MIDs match the existing offer. |
| 3733 | TEST_F(MediaSessionDescriptionFactoryTest, TestMIDsMatchesExistingOffer) { |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 3734 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3735 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_modified", |
| 3736 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3737 | &opts); |
| 3738 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_modified", |
| 3739 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3740 | &opts); |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 3741 | opts.data_channel_type = cricket::DCT_SCTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3742 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data_modified", |
| 3743 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3744 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3745 | // Create offer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3746 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3747 | std::unique_ptr<SessionDescription> updated_offer( |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 3748 | f1_.CreateOffer(opts, offer.get())); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3749 | |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 3750 | const ContentInfo* audio_content = GetFirstAudioContent(updated_offer.get()); |
| 3751 | const ContentInfo* video_content = GetFirstVideoContent(updated_offer.get()); |
| 3752 | const ContentInfo* data_content = GetFirstDataContent(updated_offer.get()); |
| 3753 | ASSERT_TRUE(audio_content != nullptr); |
| 3754 | ASSERT_TRUE(video_content != nullptr); |
| 3755 | ASSERT_TRUE(data_content != nullptr); |
| 3756 | EXPECT_EQ("audio_modified", audio_content->name); |
| 3757 | EXPECT_EQ("video_modified", video_content->name); |
| 3758 | EXPECT_EQ("data_modified", data_content->name); |
| 3759 | } |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 3760 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3761 | // The following tests verify that the unified plan SDP is supported. |
| 3762 | // Test that we can create an offer with multiple media sections of same media |
| 3763 | // type. |
| 3764 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3765 | CreateOfferWithMultipleAVMediaSections) { |
| 3766 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3767 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 3768 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3769 | &opts); |
| 3770 | AttachSenderToMediaDescriptionOptions( |
| 3771 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3772 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3773 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 3774 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3775 | &opts); |
| 3776 | AttachSenderToMediaDescriptionOptions( |
| 3777 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3778 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3779 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 3780 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3781 | &opts); |
| 3782 | AttachSenderToMediaDescriptionOptions( |
| 3783 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3784 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3785 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 3786 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3787 | &opts); |
| 3788 | AttachSenderToMediaDescriptionOptions( |
| 3789 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3790 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3791 | ASSERT_TRUE(offer); |
| 3792 | |
| 3793 | ASSERT_EQ(4u, offer->contents().size()); |
| 3794 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 3795 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3796 | offer->contents()[0].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3797 | ASSERT_EQ(1u, acd->streams().size()); |
| 3798 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3799 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3800 | |
| 3801 | EXPECT_FALSE(offer->contents()[1].rejected); |
| 3802 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3803 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3804 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3805 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3806 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3807 | |
| 3808 | EXPECT_FALSE(offer->contents()[2].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3809 | acd = offer->contents()[2].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3810 | ASSERT_EQ(1u, acd->streams().size()); |
| 3811 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3812 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3813 | |
| 3814 | EXPECT_FALSE(offer->contents()[3].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3815 | vcd = offer->contents()[3].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3816 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3817 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3818 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | // Test that we can create an answer with multiple media sections of same media |
| 3822 | // type. |
| 3823 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3824 | CreateAnswerWithMultipleAVMediaSections) { |
| 3825 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3826 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 3827 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3828 | &opts); |
| 3829 | AttachSenderToMediaDescriptionOptions( |
| 3830 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3831 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3832 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 3833 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3834 | &opts); |
| 3835 | AttachSenderToMediaDescriptionOptions( |
| 3836 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3837 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3838 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 3839 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3840 | &opts); |
| 3841 | AttachSenderToMediaDescriptionOptions( |
| 3842 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3843 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3844 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 3845 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3846 | &opts); |
| 3847 | AttachSenderToMediaDescriptionOptions( |
| 3848 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3849 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3850 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3851 | ASSERT_TRUE(offer); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3852 | std::unique_ptr<SessionDescription> answer = |
| 3853 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3854 | |
| 3855 | ASSERT_EQ(4u, answer->contents().size()); |
| 3856 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 3857 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3858 | answer->contents()[0].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3859 | ASSERT_EQ(1u, acd->streams().size()); |
| 3860 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3861 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3862 | |
| 3863 | EXPECT_FALSE(answer->contents()[1].rejected); |
| 3864 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3865 | answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3866 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3867 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3868 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3869 | |
| 3870 | EXPECT_FALSE(answer->contents()[2].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3871 | acd = answer->contents()[2].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3872 | ASSERT_EQ(1u, acd->streams().size()); |
| 3873 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3874 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3875 | |
| 3876 | EXPECT_FALSE(answer->contents()[3].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3877 | vcd = answer->contents()[3].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3878 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3879 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3880 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | // Test that the media section will be rejected in offer if the corresponding |
| 3884 | // MediaDescriptionOptions is stopped by the offerer. |
| 3885 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3886 | CreateOfferWithMediaSectionStoppedByOfferer) { |
| 3887 | // Create an offer with two audio sections and one of them is stopped. |
| 3888 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3889 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3890 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3891 | &offer_opts); |
| 3892 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3893 | RtpTransceiverDirection::kInactive, kStopped, |
| 3894 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3895 | std::unique_ptr<SessionDescription> offer = |
| 3896 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3897 | ASSERT_TRUE(offer); |
| 3898 | ASSERT_EQ(2u, offer->contents().size()); |
| 3899 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 3900 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 3901 | } |
| 3902 | |
| 3903 | // Test that the media section will be rejected in answer if the corresponding |
| 3904 | // MediaDescriptionOptions is stopped by the offerer. |
| 3905 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3906 | CreateAnswerWithMediaSectionStoppedByOfferer) { |
| 3907 | // Create an offer with two audio sections and one of them is stopped. |
| 3908 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3909 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3910 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3911 | &offer_opts); |
| 3912 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3913 | RtpTransceiverDirection::kInactive, kStopped, |
| 3914 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3915 | std::unique_ptr<SessionDescription> offer = |
| 3916 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3917 | ASSERT_TRUE(offer); |
| 3918 | ASSERT_EQ(2u, offer->contents().size()); |
| 3919 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 3920 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 3921 | |
| 3922 | // Create an answer based on the offer. |
| 3923 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3924 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3925 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3926 | &answer_opts); |
| 3927 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3928 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3929 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3930 | std::unique_ptr<SessionDescription> answer = |
| 3931 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3932 | ASSERT_EQ(2u, answer->contents().size()); |
| 3933 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 3934 | EXPECT_TRUE(answer->contents()[1].rejected); |
| 3935 | } |
| 3936 | |
| 3937 | // Test that the media section will be rejected in answer if the corresponding |
| 3938 | // MediaDescriptionOptions is stopped by the answerer. |
| 3939 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3940 | CreateAnswerWithMediaSectionRejectedByAnswerer) { |
| 3941 | // Create an offer with two audio sections. |
| 3942 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3943 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3944 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3945 | &offer_opts); |
| 3946 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3947 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3948 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3949 | std::unique_ptr<SessionDescription> offer = |
| 3950 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3951 | ASSERT_TRUE(offer); |
| 3952 | ASSERT_EQ(2u, offer->contents().size()); |
| 3953 | ASSERT_FALSE(offer->contents()[0].rejected); |
| 3954 | ASSERT_FALSE(offer->contents()[1].rejected); |
| 3955 | |
| 3956 | // The answerer rejects one of the audio sections. |
| 3957 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3958 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3959 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3960 | &answer_opts); |
| 3961 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3962 | RtpTransceiverDirection::kInactive, kStopped, |
| 3963 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3964 | std::unique_ptr<SessionDescription> answer = |
| 3965 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3966 | ASSERT_EQ(2u, answer->contents().size()); |
| 3967 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 3968 | EXPECT_TRUE(answer->contents()[1].rejected); |
Zhi Huang | 3518e7b | 2018-01-30 13:20:35 -0800 | [diff] [blame] | 3969 | |
| 3970 | // The TransportInfo of the rejected m= section is expected to be added in the |
| 3971 | // answer. |
| 3972 | EXPECT_EQ(offer->transport_infos().size(), answer->transport_infos().size()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | // Test the generated media sections has the same order of the |
| 3976 | // corresponding MediaDescriptionOptions. |
| 3977 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3978 | CreateOfferRespectsMediaDescriptionOptionsOrder) { |
| 3979 | MediaSessionOptions opts; |
| 3980 | // This tests put video section first because normally audio comes first by |
| 3981 | // default. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3982 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3983 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3984 | &opts); |
| 3985 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3986 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3987 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3988 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3989 | |
| 3990 | ASSERT_TRUE(offer); |
| 3991 | ASSERT_EQ(2u, offer->contents().size()); |
| 3992 | EXPECT_EQ("video", offer->contents()[0].name); |
| 3993 | EXPECT_EQ("audio", offer->contents()[1].name); |
| 3994 | } |
| 3995 | |
| 3996 | // Test that different media sections using the same codec have same payload |
| 3997 | // type. |
| 3998 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3999 | PayloadTypesSharedByMediaSectionsOfSameType) { |
| 4000 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4001 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4002 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4003 | &opts); |
| 4004 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4005 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4006 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4007 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4008 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4009 | ASSERT_TRUE(offer); |
| 4010 | ASSERT_EQ(2u, offer->contents().size()); |
| 4011 | const VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4012 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4013 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4014 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4015 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 4016 | ASSERT_EQ(2u, vcd1->codecs().size()); |
| 4017 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 4018 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 4019 | EXPECT_EQ(vcd1->codecs()[1].name, vcd2->codecs()[1].name); |
| 4020 | EXPECT_EQ(vcd1->codecs()[1].id, vcd2->codecs()[1].id); |
| 4021 | |
| 4022 | // Create answer and negotiate the codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4023 | std::unique_ptr<SessionDescription> answer = |
| 4024 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4025 | ASSERT_TRUE(answer); |
| 4026 | ASSERT_EQ(2u, answer->contents().size()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4027 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4028 | vcd2 = answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4029 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 4030 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4031 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 4032 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 4033 | } |
| 4034 | |
| 4035 | // Test that the codec preference order per media section is respected in |
| 4036 | // subsequent offer. |
| 4037 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4038 | CreateOfferRespectsCodecPreferenceOrder) { |
| 4039 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4040 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4041 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4042 | &opts); |
| 4043 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4044 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4045 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4046 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4047 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4048 | ASSERT_TRUE(offer); |
| 4049 | ASSERT_EQ(2u, offer->contents().size()); |
| 4050 | VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4051 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4052 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4053 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4054 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4055 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4056 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4057 | |
| 4058 | // Change the codec preference of the first video section and create a |
| 4059 | // follow-up offer. |
| 4060 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4061 | vcd1->set_codecs(video_codecs_reverse); |
| 4062 | std::unique_ptr<SessionDescription> updated_offer( |
| 4063 | f1_.CreateOffer(opts, offer.get())); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4064 | vcd1 = updated_offer->contents()[0].media_description()->as_video(); |
| 4065 | vcd2 = updated_offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4066 | // The video codec preference order should be respected. |
| 4067 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4068 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4069 | } |
| 4070 | |
| 4071 | // Test that the codec preference order per media section is respected in |
| 4072 | // the answer. |
| 4073 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4074 | CreateAnswerRespectsCodecPreferenceOrder) { |
| 4075 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4076 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4077 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4078 | &opts); |
| 4079 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4080 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4081 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4082 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4083 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4084 | ASSERT_TRUE(offer); |
| 4085 | ASSERT_EQ(2u, offer->contents().size()); |
| 4086 | VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4087 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4088 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4089 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4090 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4091 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4092 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4093 | |
| 4094 | // Change the codec preference of the first video section and create an |
| 4095 | // answer. |
| 4096 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4097 | vcd1->set_codecs(video_codecs_reverse); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4098 | std::unique_ptr<SessionDescription> answer = |
| 4099 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4100 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4101 | vcd2 = answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4102 | // The video codec preference order should be respected. |
| 4103 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4104 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4105 | } |
| 4106 | |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4107 | // Test that when creating an answer, the codecs use local parameters instead of |
| 4108 | // the remote ones. |
| 4109 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerWithLocalCodecParams) { |
| 4110 | const std::string audio_param_name = "audio_param"; |
| 4111 | const std::string audio_value1 = "audio_v1"; |
| 4112 | const std::string audio_value2 = "audio_v2"; |
| 4113 | const std::string video_param_name = "video_param"; |
| 4114 | const std::string video_value1 = "video_v1"; |
| 4115 | const std::string video_value2 = "video_v2"; |
| 4116 | |
| 4117 | auto audio_codecs1 = MAKE_VECTOR(kAudioCodecs1); |
| 4118 | auto audio_codecs2 = MAKE_VECTOR(kAudioCodecs1); |
| 4119 | auto video_codecs1 = MAKE_VECTOR(kVideoCodecs1); |
| 4120 | auto video_codecs2 = MAKE_VECTOR(kVideoCodecs1); |
| 4121 | |
| 4122 | // Set the parameters for codecs. |
| 4123 | audio_codecs1[0].SetParam(audio_param_name, audio_value1); |
| 4124 | video_codecs1[0].SetParam(video_param_name, video_value1); |
| 4125 | audio_codecs2[0].SetParam(audio_param_name, audio_value2); |
| 4126 | video_codecs2[0].SetParam(video_param_name, video_value2); |
| 4127 | |
| 4128 | f1_.set_audio_codecs(audio_codecs1, audio_codecs1); |
| 4129 | f1_.set_video_codecs(video_codecs1); |
| 4130 | f2_.set_audio_codecs(audio_codecs2, audio_codecs2); |
| 4131 | f2_.set_video_codecs(video_codecs2); |
| 4132 | |
| 4133 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4134 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 4135 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4136 | &opts); |
| 4137 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4138 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4139 | &opts); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4140 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4141 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4142 | ASSERT_TRUE(offer); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4143 | auto offer_acd = offer->contents()[0].media_description()->as_audio(); |
| 4144 | auto offer_vcd = offer->contents()[1].media_description()->as_video(); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4145 | std::string value; |
| 4146 | EXPECT_TRUE(offer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4147 | EXPECT_EQ(audio_value1, value); |
| 4148 | EXPECT_TRUE(offer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4149 | EXPECT_EQ(video_value1, value); |
| 4150 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4151 | std::unique_ptr<SessionDescription> answer = |
| 4152 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4153 | ASSERT_TRUE(answer); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4154 | auto answer_acd = answer->contents()[0].media_description()->as_audio(); |
| 4155 | auto answer_vcd = answer->contents()[1].media_description()->as_video(); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4156 | // Use the parameters from the local codecs. |
| 4157 | EXPECT_TRUE(answer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4158 | EXPECT_EQ(audio_value2, value); |
| 4159 | EXPECT_TRUE(answer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4160 | EXPECT_EQ(video_value2, value); |
| 4161 | } |
| 4162 | |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4163 | // Test that matching packetization-mode is part of the criteria for matching |
| 4164 | // H264 codecs (in addition to profile-level-id). Previously, this was not the |
| 4165 | // case, so the first H264 codec with the same profile-level-id would match and |
| 4166 | // the payload type in the answer would be incorrect. |
| 4167 | // This is a regression test for bugs.webrtc.org/8808 |
| 4168 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4169 | H264MatchCriteriaIncludesPacketizationMode) { |
| 4170 | // Create two H264 codecs with the same profile level ID and different |
| 4171 | // packetization modes. |
| 4172 | VideoCodec h264_pm0(96, "H264"); |
| 4173 | h264_pm0.params[cricket::kH264FmtpProfileLevelId] = "42c01f"; |
| 4174 | h264_pm0.params[cricket::kH264FmtpPacketizationMode] = "0"; |
| 4175 | VideoCodec h264_pm1(97, "H264"); |
| 4176 | h264_pm1.params[cricket::kH264FmtpProfileLevelId] = "42c01f"; |
| 4177 | h264_pm1.params[cricket::kH264FmtpPacketizationMode] = "1"; |
| 4178 | |
| 4179 | // Offerer will send both codecs, answerer should choose the one with matching |
| 4180 | // packetization mode (and not the first one it sees). |
| 4181 | f1_.set_video_codecs({h264_pm0, h264_pm1}); |
| 4182 | f2_.set_video_codecs({h264_pm1}); |
| 4183 | |
| 4184 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4185 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4186 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4187 | &opts); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4188 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4189 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4190 | ASSERT_TRUE(offer); |
| 4191 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4192 | std::unique_ptr<SessionDescription> answer = |
| 4193 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4194 | ASSERT_TRUE(answer); |
| 4195 | |
| 4196 | // Answer should have one negotiated codec with packetization-mode=1 using the |
| 4197 | // offered payload type. |
| 4198 | ASSERT_EQ(1u, answer->contents().size()); |
| 4199 | auto answer_vcd = answer->contents()[0].media_description()->as_video(); |
| 4200 | ASSERT_EQ(1u, answer_vcd->codecs().size()); |
| 4201 | auto answer_codec = answer_vcd->codecs()[0]; |
| 4202 | EXPECT_EQ(h264_pm1.id, answer_codec.id); |
| 4203 | } |
| 4204 | |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4205 | class MediaProtocolTest : public ::testing::TestWithParam<const char*> { |
| 4206 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4207 | MediaProtocolTest() |
| 4208 | : f1_(&tdf1_, &ssrc_generator1), f2_(&tdf2_, &ssrc_generator2) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4209 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 4210 | MAKE_VECTOR(kAudioCodecs1)); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4211 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 4212 | f1_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4213 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 4214 | MAKE_VECTOR(kAudioCodecs2)); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4215 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 4216 | f2_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4217 | f1_.set_secure(SEC_ENABLED); |
| 4218 | f2_.set_secure(SEC_ENABLED); |
| 4219 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 4220 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4221 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 4222 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4223 | tdf1_.set_secure(SEC_ENABLED); |
| 4224 | tdf2_.set_secure(SEC_ENABLED); |
| 4225 | } |
| 4226 | |
| 4227 | protected: |
| 4228 | MediaSessionDescriptionFactory f1_; |
| 4229 | MediaSessionDescriptionFactory f2_; |
| 4230 | TransportDescriptionFactory tdf1_; |
| 4231 | TransportDescriptionFactory tdf2_; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4232 | UniqueRandomIdGenerator ssrc_generator1; |
| 4233 | UniqueRandomIdGenerator ssrc_generator2; |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4234 | }; |
| 4235 | |
| 4236 | TEST_P(MediaProtocolTest, TestAudioVideoAcceptance) { |
| 4237 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4238 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4239 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4240 | ASSERT_TRUE(offer.get() != nullptr); |
| 4241 | // Set the protocol for all the contents. |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 4242 | for (auto& content : offer.get()->contents()) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4243 | content.media_description()->set_protocol(GetParam()); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4244 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4245 | std::unique_ptr<SessionDescription> answer = |
| 4246 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4247 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4248 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 4249 | ASSERT_TRUE(ac != nullptr); |
| 4250 | ASSERT_TRUE(vc != nullptr); |
| 4251 | EXPECT_FALSE(ac->rejected); // the offer is accepted |
| 4252 | EXPECT_FALSE(vc->rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4253 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 4254 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4255 | EXPECT_EQ(GetParam(), acd->protocol()); |
| 4256 | EXPECT_EQ(GetParam(), vcd->protocol()); |
| 4257 | } |
| 4258 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4259 | INSTANTIATE_TEST_SUITE_P(MediaProtocolPatternTest, |
| 4260 | MediaProtocolTest, |
| 4261 | ::testing::ValuesIn(kMediaProtocols)); |
| 4262 | INSTANTIATE_TEST_SUITE_P(MediaProtocolDtlsPatternTest, |
| 4263 | MediaProtocolTest, |
| 4264 | ::testing::ValuesIn(kMediaProtocolsDtls)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4265 | |
| 4266 | TEST_F(MediaSessionDescriptionFactoryTest, TestSetAudioCodecs) { |
| 4267 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4268 | UniqueRandomIdGenerator ssrc_generator; |
| 4269 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4270 | std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4271 | std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4272 | |
| 4273 | // The merged list of codecs should contain any send codecs that are also |
| 4274 | // nominally in the recieve codecs list. Payload types should be picked from |
| 4275 | // the send codecs and a number-of-channels of 0 and 1 should be equivalent |
| 4276 | // (set to 1). This equals what happens when the send codecs are used in an |
| 4277 | // offer and the receive codecs are used in the following answer. |
| 4278 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4279 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4280 | const std::vector<AudioCodec> no_codecs; |
| 4281 | |
| 4282 | RTC_CHECK_EQ(send_codecs[1].name, "iLBC") |
| 4283 | << "Please don't change shared test data!"; |
| 4284 | RTC_CHECK_EQ(recv_codecs[2].name, "iLBC") |
| 4285 | << "Please don't change shared test data!"; |
| 4286 | // Alter iLBC send codec to have zero channels, to test that that is handled |
| 4287 | // properly. |
| 4288 | send_codecs[1].channels = 0; |
| 4289 | |
| 4290 | // Alther iLBC receive codec to be lowercase, to test that case conversions |
| 4291 | // are handled properly. |
| 4292 | recv_codecs[2].name = "ilbc"; |
| 4293 | |
| 4294 | // Test proper merge |
| 4295 | sf.set_audio_codecs(send_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4296 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4297 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4298 | EXPECT_EQ(sendrecv_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4299 | |
| 4300 | // Test empty send codecs list |
| 4301 | sf.set_audio_codecs(no_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4302 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4303 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4304 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4305 | |
| 4306 | // Test empty recv codecs list |
| 4307 | sf.set_audio_codecs(send_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4308 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4309 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4310 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4311 | |
| 4312 | // Test all empty codec lists |
| 4313 | sf.set_audio_codecs(no_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4314 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4315 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4316 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4317 | } |
| 4318 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 4319 | // Checks that the RID extensions are added to the video RTP header extensions. |
| 4320 | // Note: This test somewhat shows that |set_video_rtp_header_extensions()| is |
| 4321 | // not very well defined, as calling set() and immediately get() will yield |
| 4322 | // an object that is not semantically equivalent to the set object. |
| 4323 | TEST_F(MediaSessionDescriptionFactoryTest, VideoHasRidExtensionsInUnifiedPlan) { |
| 4324 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4325 | UniqueRandomIdGenerator ssrc_generator; |
| 4326 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 4327 | sf.set_is_unified_plan(true); |
| 4328 | cricket::RtpHeaderExtensions extensions; |
| 4329 | sf.set_video_rtp_header_extensions(extensions); |
| 4330 | cricket::RtpHeaderExtensions result = sf.video_rtp_header_extensions(); |
| 4331 | // Check to see that RID extensions were added to the extension list |
| 4332 | EXPECT_GE(result.size(), 2u); |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4333 | EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, |
Elad Alon | 157540a | 2019-02-08 23:37:52 +0100 | [diff] [blame] | 4334 | RtpExtension::kMidUri))); |
| 4335 | EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4336 | RtpExtension::kRidUri))); |
| 4337 | EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, |
| 4338 | RtpExtension::kRepairedRidUri))); |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | // Checks that the RID extensions are added to the audio RTP header extensions. |
| 4342 | // Note: This test somewhat shows that |set_audio_rtp_header_extensions()| is |
| 4343 | // not very well defined, as calling set() and immediately get() will yield |
| 4344 | // an object that is not semantically equivalent to the set object. |
| 4345 | TEST_F(MediaSessionDescriptionFactoryTest, AudioHasRidExtensionsInUnifiedPlan) { |
| 4346 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4347 | UniqueRandomIdGenerator ssrc_generator; |
| 4348 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 4349 | sf.set_is_unified_plan(true); |
| 4350 | cricket::RtpHeaderExtensions extensions; |
| 4351 | sf.set_audio_rtp_header_extensions(extensions); |
| 4352 | cricket::RtpHeaderExtensions result = sf.audio_rtp_header_extensions(); |
| 4353 | // Check to see that RID extensions were added to the extension list |
| 4354 | EXPECT_GE(result.size(), 2u); |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4355 | EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, |
Elad Alon | 157540a | 2019-02-08 23:37:52 +0100 | [diff] [blame] | 4356 | RtpExtension::kMidUri))); |
| 4357 | EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4358 | RtpExtension::kRidUri))); |
| 4359 | EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, |
| 4360 | RtpExtension::kRepairedRidUri))); |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 4361 | } |
| 4362 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4363 | namespace { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4364 | // Compare the two vectors of codecs ignoring the payload type. |
| 4365 | template <class Codec> |
| 4366 | bool CodecsMatch(const std::vector<Codec>& codecs1, |
| 4367 | const std::vector<Codec>& codecs2) { |
| 4368 | if (codecs1.size() != codecs2.size()) { |
| 4369 | return false; |
| 4370 | } |
| 4371 | |
| 4372 | for (size_t i = 0; i < codecs1.size(); ++i) { |
| 4373 | if (!codecs1[i].Matches(codecs2[i])) { |
| 4374 | return false; |
| 4375 | } |
| 4376 | } |
| 4377 | return true; |
| 4378 | } |
| 4379 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4380 | void TestAudioCodecsOffer(RtpTransceiverDirection direction) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4381 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4382 | UniqueRandomIdGenerator ssrc_generator; |
| 4383 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4384 | const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4385 | const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4386 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4387 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4388 | sf.set_audio_codecs(send_codecs, recv_codecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4389 | |
| 4390 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4391 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 4392 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4393 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4394 | if (direction == RtpTransceiverDirection::kSendRecv || |
| 4395 | direction == RtpTransceiverDirection::kSendOnly) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4396 | AttachSenderToMediaDescriptionOptions( |
| 4397 | "audio", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4398 | } |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4399 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4400 | std::unique_ptr<SessionDescription> offer = sf.CreateOffer(opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4401 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4402 | ContentInfo* ac = offer->GetContentByName("audio"); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4403 | |
| 4404 | // If the factory didn't add any audio content to the offer, we cannot check |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4405 | // that the codecs put in are right. This happens when we neither want to |
| 4406 | // send nor receive audio. The checks are still in place if at some point |
| 4407 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4408 | if (ac) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4409 | AudioContentDescription* acd = ac->media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4410 | // sendrecv and inactive should both present lists as if the channel was |
| 4411 | // to be used for sending and receiving. Inactive essentially means it |
| 4412 | // might eventually be used anything, but we don't know more at this |
| 4413 | // moment. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4414 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4415 | EXPECT_TRUE(CodecsMatch<AudioCodec>(send_codecs, acd->codecs())); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4416 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4417 | EXPECT_TRUE(CodecsMatch<AudioCodec>(recv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4418 | } else { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4419 | EXPECT_TRUE(CodecsMatch<AudioCodec>(sendrecv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4420 | } |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | static const AudioCodec kOfferAnswerCodecs[] = { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4425 | AudioCodec(0, "codec0", 16000, -1, 1), |
| 4426 | AudioCodec(1, "codec1", 8000, 13300, 1), |
| 4427 | AudioCodec(2, "codec2", 8000, 64000, 1), |
| 4428 | AudioCodec(3, "codec3", 8000, 64000, 1), |
| 4429 | AudioCodec(4, "codec4", 8000, 0, 2), |
| 4430 | AudioCodec(5, "codec5", 32000, 0, 1), |
| 4431 | AudioCodec(6, "codec6", 48000, 0, 1)}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4432 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4433 | /* The codecs groups below are chosen as per the matrix below. The objective |
| 4434 | * is to have different sets of codecs in the inputs, to get unique sets of |
| 4435 | * codecs after negotiation, depending on offer and answer communication |
| 4436 | * directions. One-way directions in the offer should either result in the |
| 4437 | * opposite direction in the answer, or an inactive answer. Regardless, the |
| 4438 | * choice of codecs should be as if the answer contained the opposite |
| 4439 | * direction. Inactive offers should be treated as sendrecv/sendrecv. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4440 | * |
| 4441 | * | Offer | Answer | Result |
| 4442 | * codec|send recv sr | send recv sr | s/r r/s sr/s sr/r sr/sr |
| 4443 | * 0 | x - - | - x - | x - - - - |
| 4444 | * 1 | x x x | - x - | x - - x - |
| 4445 | * 2 | - x - | x - - | - x - - - |
| 4446 | * 3 | x x x | x - - | - x x - - |
| 4447 | * 4 | - x - | x x x | - x - - - |
| 4448 | * 5 | x - - | x x x | x - - - - |
| 4449 | * 6 | x x x | x x x | x x x x x |
| 4450 | */ |
| 4451 | // Codecs used by offerer in the AudioCodecsAnswerTest |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4452 | static const int kOfferSendCodecs[] = {0, 1, 3, 5, 6}; |
| 4453 | static const int kOfferRecvCodecs[] = {1, 2, 3, 4, 6}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4454 | // Codecs used in the answerer in the AudioCodecsAnswerTest. The order is |
| 4455 | // jumbled to catch the answer not following the order in the offer. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4456 | static const int kAnswerSendCodecs[] = {6, 5, 2, 3, 4}; |
| 4457 | static const int kAnswerRecvCodecs[] = {6, 5, 4, 1, 0}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4458 | // The resulting sets of codecs in the answer in the AudioCodecsAnswerTest |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4459 | static const int kResultSend_RecvCodecs[] = {0, 1, 5, 6}; |
| 4460 | static const int kResultRecv_SendCodecs[] = {2, 3, 4, 6}; |
| 4461 | static const int kResultSendrecv_SendCodecs[] = {3, 6}; |
| 4462 | static const int kResultSendrecv_RecvCodecs[] = {1, 6}; |
| 4463 | static const int kResultSendrecv_SendrecvCodecs[] = {6}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4464 | |
| 4465 | template <typename T, int IDXS> |
| 4466 | std::vector<T> VectorFromIndices(const T* array, const int (&indices)[IDXS]) { |
| 4467 | std::vector<T> out; |
| 4468 | out.reserve(IDXS); |
| 4469 | for (int idx : indices) |
| 4470 | out.push_back(array[idx]); |
| 4471 | |
| 4472 | return out; |
| 4473 | } |
| 4474 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4475 | void TestAudioCodecsAnswer(RtpTransceiverDirection offer_direction, |
| 4476 | RtpTransceiverDirection answer_direction, |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4477 | bool add_legacy_stream) { |
| 4478 | TransportDescriptionFactory offer_tdf; |
| 4479 | TransportDescriptionFactory answer_tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4480 | UniqueRandomIdGenerator ssrc_generator1, ssrc_generator2; |
| 4481 | MediaSessionDescriptionFactory offer_factory(&offer_tdf, &ssrc_generator1); |
| 4482 | MediaSessionDescriptionFactory answer_factory(&answer_tdf, &ssrc_generator2); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4483 | offer_factory.set_audio_codecs( |
| 4484 | VectorFromIndices(kOfferAnswerCodecs, kOfferSendCodecs), |
| 4485 | VectorFromIndices(kOfferAnswerCodecs, kOfferRecvCodecs)); |
| 4486 | answer_factory.set_audio_codecs( |
| 4487 | VectorFromIndices(kOfferAnswerCodecs, kAnswerSendCodecs), |
| 4488 | VectorFromIndices(kOfferAnswerCodecs, kAnswerRecvCodecs)); |
| 4489 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4490 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4491 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", offer_direction, |
| 4492 | kActive, &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4493 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4494 | if (webrtc::RtpTransceiverDirectionHasSend(offer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4495 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4496 | kAudioTrack1, {kMediaStream1}, 1, |
| 4497 | &offer_opts); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4500 | std::unique_ptr<SessionDescription> offer = |
| 4501 | offer_factory.CreateOffer(offer_opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4502 | ASSERT_TRUE(offer.get() != NULL); |
| 4503 | |
| 4504 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4505 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", answer_direction, |
| 4506 | kActive, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4507 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4508 | if (webrtc::RtpTransceiverDirectionHasSend(answer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4509 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4510 | kAudioTrack1, {kMediaStream1}, 1, |
| 4511 | &answer_opts); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4512 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4513 | std::unique_ptr<SessionDescription> answer = |
| 4514 | answer_factory.CreateAnswer(offer.get(), answer_opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4515 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4516 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4517 | // If the factory didn't add any audio content to the answer, we cannot |
| 4518 | // check that the codecs put in are right. This happens when we neither want |
| 4519 | // to send nor receive audio. The checks are still in place if at some point |
| 4520 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4521 | if (ac) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4522 | ASSERT_EQ(MEDIA_TYPE_AUDIO, ac->media_description()->type()); |
| 4523 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4524 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4525 | std::vector<AudioCodec> target_codecs; |
| 4526 | // For offers with sendrecv or inactive, we should never reply with more |
| 4527 | // codecs than offered, with these codec sets. |
| 4528 | switch (offer_direction) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4529 | case RtpTransceiverDirection::kInactive: |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4530 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4531 | kResultSendrecv_SendrecvCodecs); |
| 4532 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4533 | case RtpTransceiverDirection::kSendOnly: |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4534 | target_codecs = |
| 4535 | VectorFromIndices(kOfferAnswerCodecs, kResultSend_RecvCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4536 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4537 | case RtpTransceiverDirection::kRecvOnly: |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4538 | target_codecs = |
| 4539 | VectorFromIndices(kOfferAnswerCodecs, kResultRecv_SendCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4540 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4541 | case RtpTransceiverDirection::kSendRecv: |
| 4542 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4543 | target_codecs = |
| 4544 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_SendCodecs); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4545 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4546 | target_codecs = |
| 4547 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_RecvCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4548 | } else { |
| 4549 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4550 | kResultSendrecv_SendrecvCodecs); |
| 4551 | } |
| 4552 | break; |
| 4553 | } |
| 4554 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4555 | auto format_codecs = [](const std::vector<AudioCodec>& codecs) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 4556 | rtc::StringBuilder os; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4557 | bool first = true; |
| 4558 | os << "{"; |
| 4559 | for (const auto& c : codecs) { |
| 4560 | os << (first ? " " : ", ") << c.id; |
| 4561 | first = false; |
| 4562 | } |
| 4563 | os << " }"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 4564 | return os.Release(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4565 | }; |
| 4566 | |
| 4567 | EXPECT_TRUE(acd->codecs() == target_codecs) |
| 4568 | << "Expected: " << format_codecs(target_codecs) |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4569 | << ", got: " << format_codecs(acd->codecs()) << "; Offered: " |
| 4570 | << webrtc::RtpTransceiverDirectionToString(offer_direction) |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4571 | << ", answerer wants: " |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4572 | << webrtc::RtpTransceiverDirectionToString(answer_direction) |
| 4573 | << "; got: " |
| 4574 | << webrtc::RtpTransceiverDirectionToString(acd->direction()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4575 | } else { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4576 | EXPECT_EQ(offer_direction, RtpTransceiverDirection::kInactive) |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4577 | << "Only inactive offers are allowed to not generate any audio " |
| 4578 | "content"; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4579 | } |
| 4580 | } |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 4581 | |
| 4582 | } // namespace |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4583 | |
| 4584 | class AudioCodecsOfferTest |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4585 | : public ::testing::TestWithParam<RtpTransceiverDirection> {}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4586 | |
| 4587 | TEST_P(AudioCodecsOfferTest, TestCodecsInOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4588 | TestAudioCodecsOffer(GetParam()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4589 | } |
| 4590 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4591 | INSTANTIATE_TEST_SUITE_P(MediaSessionDescriptionFactoryTest, |
| 4592 | AudioCodecsOfferTest, |
| 4593 | ::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4594 | RtpTransceiverDirection::kRecvOnly, |
| 4595 | RtpTransceiverDirection::kSendRecv, |
| 4596 | RtpTransceiverDirection::kInactive)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4597 | |
| 4598 | class AudioCodecsAnswerTest |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4599 | : public ::testing::TestWithParam<::testing::tuple<RtpTransceiverDirection, |
| 4600 | RtpTransceiverDirection, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4601 | bool>> {}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4602 | |
| 4603 | TEST_P(AudioCodecsAnswerTest, TestCodecsInAnswer) { |
ehmaldonado | abcef5d | 2017-02-08 04:07:11 -0800 | [diff] [blame] | 4604 | TestAudioCodecsAnswer(::testing::get<0>(GetParam()), |
| 4605 | ::testing::get<1>(GetParam()), |
| 4606 | ::testing::get<2>(GetParam())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4607 | } |
| 4608 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4609 | INSTANTIATE_TEST_SUITE_P( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4610 | MediaSessionDescriptionFactoryTest, |
| 4611 | AudioCodecsAnswerTest, |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4612 | ::testing::Combine(::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4613 | RtpTransceiverDirection::kRecvOnly, |
| 4614 | RtpTransceiverDirection::kSendRecv, |
| 4615 | RtpTransceiverDirection::kInactive), |
| 4616 | ::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4617 | RtpTransceiverDirection::kRecvOnly, |
| 4618 | RtpTransceiverDirection::kSendRecv, |
| 4619 | RtpTransceiverDirection::kInactive), |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4620 | ::testing::Bool())); |