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