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