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