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