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