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 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "pc/media_session.h" |
| 12 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 13 | #include <algorithm> |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 14 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | #include <string> |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 16 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 19 | #include "absl/algorithm/container.h" |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 20 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "media/base/test_utils.h" |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 23 | #include "media/sctp/sctp_transport_internal.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "p2p/base/p2p_constants.h" |
| 25 | #include "p2p/base/transport_description.h" |
| 26 | #include "p2p/base/transport_info.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 27 | #include "pc/rtp_media_utils.h" |
| 28 | #include "pc/srtp_filter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "rtc_base/fake_ssl_identity.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "rtc_base/message_digest.h" |
| 33 | #include "rtc_base/ssl_adapter.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 34 | #include "rtc_base/strings/string_builder.h" |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 35 | #include "rtc_base/unique_id_generator.h" |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 36 | #include "test/gmock.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 38 | #define ASSERT_CRYPTO(cd, s, cs) \ |
| 39 | ASSERT_EQ(s, cd->cryptos().size()); \ |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 40 | ASSERT_EQ(cs, cd->cryptos()[0].cipher_suite) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | |
| 42 | typedef std::vector<cricket::Candidate> Candidates; |
| 43 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 44 | using cricket::AudioCodec; |
| 45 | using cricket::AudioContentDescription; |
| 46 | using cricket::ContentInfo; |
| 47 | using cricket::CryptoParamsVec; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 48 | using cricket::GetFirstAudioContent; |
| 49 | using cricket::GetFirstAudioContentDescription; |
| 50 | using cricket::GetFirstDataContent; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 51 | using cricket::GetFirstRtpDataContentDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 52 | using cricket::GetFirstVideoContent; |
| 53 | using cricket::GetFirstVideoContentDescription; |
| 54 | using cricket::kAutoBandwidth; |
| 55 | using cricket::MEDIA_TYPE_AUDIO; |
| 56 | using cricket::MEDIA_TYPE_DATA; |
| 57 | using cricket::MEDIA_TYPE_VIDEO; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | using cricket::MediaContentDescription; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 59 | using cricket::MediaDescriptionOptions; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 60 | using cricket::MediaProtocolType; |
| 61 | using cricket::MediaSessionDescriptionFactory; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | using cricket::MediaSessionOptions; |
| 63 | using cricket::MediaType; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 64 | using cricket::RidDescription; |
| 65 | using cricket::RidDirection; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 66 | using cricket::RtpDataCodec; |
| 67 | using cricket::RtpDataContentDescription; |
| 68 | using cricket::SctpDataContentDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 69 | using cricket::SEC_DISABLED; |
| 70 | using cricket::SEC_ENABLED; |
| 71 | using cricket::SEC_REQUIRED; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | using cricket::SessionDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 73 | using cricket::SimulcastDescription; |
| 74 | using cricket::SimulcastLayer; |
| 75 | using cricket::SimulcastLayerList; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | using cricket::SsrcGroup; |
| 77 | using cricket::StreamParams; |
| 78 | using cricket::StreamParamsVec; |
| 79 | using cricket::TransportDescription; |
| 80 | using cricket::TransportDescriptionFactory; |
| 81 | using cricket::TransportInfo; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | using cricket::VideoCodec; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 83 | using cricket::VideoContentDescription; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 84 | using rtc::CS_AEAD_AES_128_GCM; |
| 85 | using rtc::CS_AEAD_AES_256_GCM; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 86 | using rtc::CS_AES_CM_128_HMAC_SHA1_32; |
| 87 | using rtc::CS_AES_CM_128_HMAC_SHA1_80; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 88 | using rtc::UniqueRandomIdGenerator; |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 89 | using ::testing::Contains; |
| 90 | using ::testing::Each; |
Danil Chapovalov | 5f999a7 | 2020-02-20 16:39:05 +0100 | [diff] [blame] | 91 | using ::testing::ElementsAre; |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 92 | using ::testing::ElementsAreArray; |
| 93 | using ::testing::Eq; |
| 94 | using ::testing::Field; |
| 95 | using ::testing::IsEmpty; |
| 96 | using ::testing::IsFalse; |
| 97 | using ::testing::Ne; |
| 98 | using ::testing::Not; |
| 99 | using ::testing::Pointwise; |
| 100 | using ::testing::SizeIs; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 101 | using webrtc::RtpExtension; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 102 | using webrtc::RtpTransceiverDirection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | |
| 104 | static const AudioCodec kAudioCodecs1[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 105 | AudioCodec(103, "ISAC", 16000, -1, 1), |
| 106 | AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 107 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
| 108 | AudioCodec(8, "PCMA", 8000, 64000, 1), |
| 109 | AudioCodec(117, "red", 8000, 0, 1), |
| 110 | AudioCodec(107, "CN", 48000, 0, 1)}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | |
| 112 | static const AudioCodec kAudioCodecs2[] = { |
Henrik Lundin | f8ed561 | 2018-05-07 12:05:57 +0200 | [diff] [blame] | 113 | AudioCodec(126, "foo", 16000, 22000, 1), |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 114 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
| 115 | AudioCodec(127, "iLBC", 8000, 13300, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static const AudioCodec kAudioCodecsAnswer[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 119 | AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 120 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 123 | static const VideoCodec kVideoCodecs1[] = {VideoCodec(96, "H264-SVC"), |
| 124 | VideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 126 | static const VideoCodec kVideoCodecs1Reverse[] = {VideoCodec(97, "H264"), |
| 127 | VideoCodec(96, "H264-SVC")}; |
| 128 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 129 | static const VideoCodec kVideoCodecs2[] = {VideoCodec(126, "H264"), |
| 130 | VideoCodec(127, "H263")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 132 | static const VideoCodec kVideoCodecsAnswer[] = {VideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 133 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 134 | static const RtpDataCodec kDataCodecs1[] = {RtpDataCodec(98, "binary-data"), |
| 135 | RtpDataCodec(99, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 137 | static const RtpDataCodec kDataCodecs2[] = {RtpDataCodec(126, "binary-data"), |
| 138 | RtpDataCodec(127, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 139 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 140 | static const RtpDataCodec kDataCodecsAnswer[] = { |
| 141 | RtpDataCodec(98, "binary-data"), RtpDataCodec(99, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 143 | static const RtpExtension kAudioRtpExtension1[] = { |
| 144 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 145 | RtpExtension("http://google.com/testing/audio_something", 10), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 148 | static const RtpExtension kAudioRtpExtensionEncrypted1[] = { |
| 149 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 150 | RtpExtension("http://google.com/testing/audio_something", 10), |
| 151 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
| 152 | }; |
| 153 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 154 | static const RtpExtension kAudioRtpExtension2[] = { |
| 155 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 2), |
| 156 | RtpExtension("http://google.com/testing/audio_something_else", 8), |
| 157 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 158 | }; |
| 159 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 160 | static const RtpExtension kAudioRtpExtension3[] = { |
| 161 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 162 | RtpExtension("http://google.com/testing/both_audio_and_video", 3), |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 165 | static const RtpExtension kAudioRtpExtension3ForEncryption[] = { |
| 166 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 167 | // Use RTP extension that supports encryption. |
| 168 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 169 | }; |
| 170 | |
| 171 | static const RtpExtension kAudioRtpExtension3ForEncryptionOffer[] = { |
| 172 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 173 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 174 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14, true), |
| 175 | }; |
| 176 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 177 | static const RtpExtension kAudioRtpExtensionAnswer[] = { |
| 178 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 181 | static const RtpExtension kAudioRtpExtensionEncryptedAnswer[] = { |
| 182 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
| 183 | }; |
| 184 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 185 | static const RtpExtension kVideoRtpExtension1[] = { |
| 186 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 187 | RtpExtension("http://google.com/testing/video_something", 13), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 190 | static const RtpExtension kVideoRtpExtensionEncrypted1[] = { |
| 191 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 192 | RtpExtension("http://google.com/testing/video_something", 13), |
| 193 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 11, true), |
| 194 | }; |
| 195 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 196 | static const RtpExtension kVideoRtpExtension2[] = { |
| 197 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 2), |
| 198 | RtpExtension("http://google.com/testing/video_something_else", 14), |
| 199 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 202 | static const RtpExtension kVideoRtpExtension3[] = { |
| 203 | RtpExtension("http://google.com/testing/video_something", 4), |
| 204 | RtpExtension("http://google.com/testing/both_audio_and_video", 5), |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 207 | static const RtpExtension kVideoRtpExtension3ForEncryption[] = { |
| 208 | RtpExtension("http://google.com/testing/video_something", 4), |
| 209 | // Use RTP extension that supports encryption. |
| 210 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 5), |
| 211 | }; |
| 212 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 213 | static const RtpExtension kVideoRtpExtensionAnswer[] = { |
| 214 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 217 | static const RtpExtension kVideoRtpExtensionEncryptedAnswer[] = { |
| 218 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 11, true), |
| 219 | }; |
| 220 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 221 | static const RtpExtension kRtpExtensionTransportSequenceNumber01[] = { |
| 222 | RtpExtension("http://www.ietf.org/id/" |
| 223 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 224 | 1), |
| 225 | }; |
| 226 | |
| 227 | static const RtpExtension kRtpExtensionTransportSequenceNumber01And02[] = { |
| 228 | RtpExtension("http://www.ietf.org/id/" |
| 229 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 230 | 1), |
Johannes Kron | 8cc711a | 2019-03-07 22:36:35 +0100 | [diff] [blame] | 231 | RtpExtension( |
| 232 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 233 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | static const RtpExtension kRtpExtensionTransportSequenceNumber02[] = { |
Johannes Kron | 8cc711a | 2019-03-07 22:36:35 +0100 | [diff] [blame] | 237 | RtpExtension( |
| 238 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 239 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 240 | }; |
| 241 | |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 242 | static const RtpExtension kRtpExtensionGenericFrameDescriptorUri00[] = { |
| 243 | RtpExtension("http://www.webrtc.org/experiments/rtp-hdrext/" |
| 244 | "generic-frame-descriptor-00", |
| 245 | 3), |
| 246 | }; |
| 247 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 248 | static const uint32_t kSimulcastParamsSsrc[] = {10, 11, 20, 21, 30, 31}; |
| 249 | static const uint32_t kSimSsrc[] = {10, 20, 30}; |
| 250 | static const uint32_t kFec1Ssrc[] = {10, 11}; |
| 251 | static const uint32_t kFec2Ssrc[] = {20, 21}; |
| 252 | static const uint32_t kFec3Ssrc[] = {30, 31}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | |
| 254 | static const char kMediaStream1[] = "stream_1"; |
| 255 | static const char kMediaStream2[] = "stream_2"; |
| 256 | static const char kVideoTrack1[] = "video_1"; |
| 257 | static const char kVideoTrack2[] = "video_2"; |
| 258 | static const char kAudioTrack1[] = "audio_1"; |
| 259 | static const char kAudioTrack2[] = "audio_2"; |
| 260 | static const char kAudioTrack3[] = "audio_3"; |
| 261 | static const char kDataTrack1[] = "data_1"; |
| 262 | static const char kDataTrack2[] = "data_2"; |
| 263 | static const char kDataTrack3[] = "data_3"; |
| 264 | |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 265 | static const char* kMediaProtocols[] = {"RTP/AVP", "RTP/SAVP", "RTP/AVPF", |
| 266 | "RTP/SAVPF"}; |
| 267 | static const char* kMediaProtocolsDtls[] = { |
| 268 | "TCP/TLS/RTP/SAVPF", "TCP/TLS/RTP/SAVP", "UDP/TLS/RTP/SAVPF", |
| 269 | "UDP/TLS/RTP/SAVP"}; |
| 270 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 271 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 272 | // default changes. |
| 273 | static const char* kDefaultSrtpCryptoSuite = CS_AES_CM_128_HMAC_SHA1_80; |
| 274 | static const char* kDefaultSrtpCryptoSuiteGcm = CS_AEAD_AES_256_GCM; |
| 275 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 276 | // These constants are used to make the code using "AddMediaDescriptionOptions" |
| 277 | // more readable. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 278 | static constexpr bool kStopped = true; |
| 279 | static constexpr bool kActive = false; |
| 280 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 281 | static bool IsMediaContentOfType(const ContentInfo* content, |
| 282 | MediaType media_type) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 283 | RTC_DCHECK(content); |
| 284 | return content->media_description()->type() == media_type; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 287 | static RtpTransceiverDirection GetMediaDirection(const ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 288 | RTC_DCHECK(content); |
| 289 | return content->media_description()->direction(); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 290 | } |
| 291 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 292 | static void AddRtxCodec(const VideoCodec& rtx_codec, |
| 293 | std::vector<VideoCodec>* codecs) { |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 294 | ASSERT_FALSE(cricket::FindCodecById(*codecs, rtx_codec.id)); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 295 | codecs->push_back(rtx_codec); |
| 296 | } |
| 297 | |
| 298 | template <class T> |
| 299 | static std::vector<std::string> GetCodecNames(const std::vector<T>& codecs) { |
| 300 | std::vector<std::string> codec_names; |
Mirko Bonadei | 649a4c2 | 2019-01-29 10:11:53 +0100 | [diff] [blame] | 301 | codec_names.reserve(codecs.size()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 302 | for (const auto& codec : codecs) { |
| 303 | codec_names.push_back(codec.name); |
| 304 | } |
| 305 | return codec_names; |
| 306 | } |
| 307 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 308 | // This is used for test only. MIDs are not the identification of the |
| 309 | // MediaDescriptionOptions since some end points may not support MID and the SDP |
| 310 | // may not contain 'mid'. |
| 311 | std::vector<MediaDescriptionOptions>::iterator FindFirstMediaDescriptionByMid( |
| 312 | const std::string& mid, |
| 313 | MediaSessionOptions* opts) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 314 | return absl::c_find_if( |
| 315 | opts->media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 316 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
| 317 | } |
| 318 | |
| 319 | std::vector<MediaDescriptionOptions>::const_iterator |
| 320 | FindFirstMediaDescriptionByMid(const std::string& mid, |
| 321 | const MediaSessionOptions& opts) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 322 | return absl::c_find_if( |
| 323 | opts.media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 324 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // Add a media section to the |session_options|. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 328 | static void AddMediaDescriptionOptions(MediaType type, |
| 329 | const std::string& mid, |
| 330 | RtpTransceiverDirection direction, |
| 331 | bool stopped, |
| 332 | MediaSessionOptions* opts) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 333 | opts->media_description_options.push_back( |
| 334 | MediaDescriptionOptions(type, mid, direction, stopped)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 337 | static void AddAudioVideoSections(RtpTransceiverDirection direction, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 338 | MediaSessionOptions* opts) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 339 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 340 | opts); |
| 341 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", direction, kActive, |
| 342 | opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static void AddDataSection(cricket::DataChannelType dct, |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 346 | RtpTransceiverDirection direction, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 347 | MediaSessionOptions* opts) { |
| 348 | opts->data_channel_type = dct; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 349 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", direction, kActive, opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 352 | static void AttachSenderToMediaDescriptionOptions( |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 353 | const std::string& mid, |
| 354 | MediaType type, |
| 355 | const std::string& track_id, |
| 356 | const std::vector<std::string>& stream_ids, |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 357 | const std::vector<RidDescription>& rids, |
| 358 | const SimulcastLayerList& simulcast_layers, |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 359 | int num_sim_layer, |
| 360 | MediaSessionOptions* session_options) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 361 | auto it = FindFirstMediaDescriptionByMid(mid, session_options); |
| 362 | switch (type) { |
| 363 | case MEDIA_TYPE_AUDIO: |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 364 | it->AddAudioSender(track_id, stream_ids); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 365 | break; |
| 366 | case MEDIA_TYPE_VIDEO: |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 367 | it->AddVideoSender(track_id, stream_ids, rids, simulcast_layers, |
| 368 | num_sim_layer); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 369 | break; |
| 370 | case MEDIA_TYPE_DATA: |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 371 | RTC_CHECK(stream_ids.size() == 1U); |
| 372 | it->AddRtpDataChannel(track_id, stream_ids[0]); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 373 | break; |
| 374 | default: |
| 375 | RTC_NOTREACHED(); |
| 376 | } |
| 377 | } |
| 378 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 379 | static void AttachSenderToMediaDescriptionOptions( |
| 380 | const std::string& mid, |
| 381 | MediaType type, |
| 382 | const std::string& track_id, |
| 383 | const std::vector<std::string>& stream_ids, |
| 384 | int num_sim_layer, |
| 385 | MediaSessionOptions* session_options) { |
| 386 | AttachSenderToMediaDescriptionOptions(mid, type, track_id, stream_ids, {}, |
| 387 | SimulcastLayerList(), num_sim_layer, |
| 388 | session_options); |
| 389 | } |
| 390 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 391 | static void DetachSenderFromMediaSection(const std::string& mid, |
| 392 | const std::string& track_id, |
| 393 | MediaSessionOptions* session_options) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 394 | std::vector<cricket::SenderOptions>& sender_options_list = |
| 395 | FindFirstMediaDescriptionByMid(mid, session_options)->sender_options; |
| 396 | auto sender_it = |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 397 | absl::c_find_if(sender_options_list, |
| 398 | [track_id](const cricket::SenderOptions& sender_options) { |
| 399 | return sender_options.track_id == track_id; |
| 400 | }); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 401 | RTC_DCHECK(sender_it != sender_options_list.end()); |
| 402 | sender_options_list.erase(sender_it); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | // Helper function used to create a default MediaSessionOptions for Plan B SDP. |
| 406 | // (https://tools.ietf.org/html/draft-uberti-rtcweb-plan-00). |
| 407 | static MediaSessionOptions CreatePlanBMediaSessionOptions() { |
| 408 | MediaSessionOptions session_options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 409 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 410 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 411 | &session_options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 412 | return session_options; |
| 413 | } |
| 414 | |
| 415 | // TODO(zhihuang): Most of these tests were written while MediaSessionOptions |
| 416 | // was designed for Plan B SDP, where only one audio "m=" section and one video |
| 417 | // "m=" section could be generated, and ordering couldn't be controlled. Many of |
| 418 | // these tests may be obsolete as a result, and should be refactored or removed. |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 419 | class MediaSessionDescriptionFactoryTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 420 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 421 | MediaSessionDescriptionFactoryTest() |
| 422 | : f1_(&tdf1_, &ssrc_generator1), f2_(&tdf2_, &ssrc_generator2) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 423 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 424 | MAKE_VECTOR(kAudioCodecs1)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 425 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1), |
| 426 | MAKE_VECTOR(kVideoCodecs1)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 427 | f1_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 428 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 429 | MAKE_VECTOR(kAudioCodecs2)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 430 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2), |
| 431 | MAKE_VECTOR(kVideoCodecs2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 432 | f2_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
Henrik Boström | 3a14bf3 | 2015-08-31 09:27:58 +0200 | [diff] [blame] | 433 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 434 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
Henrik Boström | 3a14bf3 | 2015-08-31 09:27:58 +0200 | [diff] [blame] | 435 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 436 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | } |
| 438 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 439 | // Create a video StreamParamsVec object with: |
| 440 | // - one video stream with 3 simulcast streams and FEC, |
| 441 | StreamParamsVec CreateComplexVideoStreamParamsVec() { |
| 442 | SsrcGroup sim_group("SIM", MAKE_VECTOR(kSimSsrc)); |
| 443 | SsrcGroup fec_group1("FEC", MAKE_VECTOR(kFec1Ssrc)); |
| 444 | SsrcGroup fec_group2("FEC", MAKE_VECTOR(kFec2Ssrc)); |
| 445 | SsrcGroup fec_group3("FEC", MAKE_VECTOR(kFec3Ssrc)); |
| 446 | |
| 447 | std::vector<SsrcGroup> ssrc_groups; |
| 448 | ssrc_groups.push_back(sim_group); |
| 449 | ssrc_groups.push_back(fec_group1); |
| 450 | ssrc_groups.push_back(fec_group2); |
| 451 | ssrc_groups.push_back(fec_group3); |
| 452 | |
| 453 | StreamParams simulcast_params; |
| 454 | simulcast_params.id = kVideoTrack1; |
| 455 | simulcast_params.ssrcs = MAKE_VECTOR(kSimulcastParamsSsrc); |
| 456 | simulcast_params.ssrc_groups = ssrc_groups; |
| 457 | simulcast_params.cname = "Video_SIM_FEC"; |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 458 | simulcast_params.set_stream_ids({kMediaStream1}); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 459 | |
| 460 | StreamParamsVec video_streams; |
| 461 | video_streams.push_back(simulcast_params); |
| 462 | |
| 463 | return video_streams; |
| 464 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | |
| 466 | bool CompareCryptoParams(const CryptoParamsVec& c1, |
| 467 | const CryptoParamsVec& c2) { |
| 468 | if (c1.size() != c2.size()) |
| 469 | return false; |
| 470 | for (size_t i = 0; i < c1.size(); ++i) |
| 471 | if (c1[i].tag != c2[i].tag || c1[i].cipher_suite != c2[i].cipher_suite || |
| 472 | c1[i].key_params != c2[i].key_params || |
| 473 | c1[i].session_params != c2[i].session_params) |
| 474 | return false; |
| 475 | return true; |
| 476 | } |
| 477 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 478 | // Returns true if the transport info contains "renomination" as an |
| 479 | // ICE option. |
| 480 | bool GetIceRenomination(const TransportInfo* transport_info) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 481 | return absl::c_linear_search(transport_info->description.transport_options, |
| 482 | "renomination"); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 483 | } |
| 484 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 485 | void TestTransportInfo(bool offer, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 486 | const MediaSessionOptions& options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 487 | bool has_current_desc) { |
| 488 | const std::string current_audio_ufrag = "current_audio_ufrag"; |
| 489 | const std::string current_audio_pwd = "current_audio_pwd"; |
| 490 | const std::string current_video_ufrag = "current_video_ufrag"; |
| 491 | const std::string current_video_pwd = "current_video_pwd"; |
| 492 | const std::string current_data_ufrag = "current_data_ufrag"; |
| 493 | const std::string current_data_pwd = "current_data_pwd"; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 494 | std::unique_ptr<SessionDescription> current_desc; |
| 495 | std::unique_ptr<SessionDescription> desc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 496 | if (has_current_desc) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 497 | current_desc = std::make_unique<SessionDescription>(); |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 498 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 499 | "audio", |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 500 | TransportDescription(current_audio_ufrag, current_audio_pwd))); |
| 501 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 502 | "video", |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 503 | TransportDescription(current_video_ufrag, current_video_pwd))); |
| 504 | current_desc->AddTransportInfo(TransportInfo( |
| 505 | "data", TransportDescription(current_data_ufrag, current_data_pwd))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 506 | } |
| 507 | if (offer) { |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 508 | desc = f1_.CreateOffer(options, current_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | } else { |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 510 | std::unique_ptr<SessionDescription> offer; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 511 | offer = f1_.CreateOffer(options, NULL); |
| 512 | desc = f1_.CreateAnswer(offer.get(), options, current_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 513 | } |
| 514 | ASSERT_TRUE(desc.get() != NULL); |
| 515 | const TransportInfo* ti_audio = desc->GetTransportInfoByName("audio"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 516 | if (options.has_audio()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 517 | EXPECT_TRUE(ti_audio != NULL); |
| 518 | if (has_current_desc) { |
| 519 | EXPECT_EQ(current_audio_ufrag, ti_audio->description.ice_ufrag); |
| 520 | EXPECT_EQ(current_audio_pwd, ti_audio->description.ice_pwd); |
| 521 | } else { |
| 522 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 523 | ti_audio->description.ice_ufrag.size()); |
| 524 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 525 | ti_audio->description.ice_pwd.size()); |
| 526 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 527 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 528 | FindFirstMediaDescriptionByMid("audio", options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 529 | EXPECT_EQ( |
| 530 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 531 | GetIceRenomination(ti_audio)); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 532 | EXPECT_EQ(media_desc_options_it->transport_options.opaque_parameters, |
| 533 | ti_audio->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 534 | |
| 535 | } else { |
| 536 | EXPECT_TRUE(ti_audio == NULL); |
| 537 | } |
| 538 | const TransportInfo* ti_video = desc->GetTransportInfoByName("video"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 539 | if (options.has_video()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 540 | EXPECT_TRUE(ti_video != NULL); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 541 | auto media_desc_options_it = |
| 542 | FindFirstMediaDescriptionByMid("video", options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 543 | if (options.bundle_enabled) { |
| 544 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 545 | ti_video->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 546 | EXPECT_EQ(ti_audio->description.ice_pwd, ti_video->description.ice_pwd); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 547 | EXPECT_EQ(ti_audio->description.opaque_parameters, |
| 548 | ti_video->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 549 | } else { |
| 550 | if (has_current_desc) { |
| 551 | EXPECT_EQ(current_video_ufrag, ti_video->description.ice_ufrag); |
| 552 | EXPECT_EQ(current_video_pwd, ti_video->description.ice_pwd); |
| 553 | } else { |
| 554 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 555 | ti_video->description.ice_ufrag.size()); |
| 556 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 557 | ti_video->description.ice_pwd.size()); |
| 558 | } |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 559 | EXPECT_EQ(media_desc_options_it->transport_options.opaque_parameters, |
| 560 | ti_video->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 561 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 562 | EXPECT_EQ( |
| 563 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 564 | GetIceRenomination(ti_video)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 565 | } else { |
| 566 | EXPECT_TRUE(ti_video == NULL); |
| 567 | } |
| 568 | const TransportInfo* ti_data = desc->GetTransportInfoByName("data"); |
| 569 | if (options.has_data()) { |
| 570 | EXPECT_TRUE(ti_data != NULL); |
| 571 | if (options.bundle_enabled) { |
| 572 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 573 | ti_data->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 574 | 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] | 575 | } else { |
| 576 | if (has_current_desc) { |
| 577 | EXPECT_EQ(current_data_ufrag, ti_data->description.ice_ufrag); |
| 578 | EXPECT_EQ(current_data_pwd, ti_data->description.ice_pwd); |
| 579 | } else { |
| 580 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 581 | ti_data->description.ice_ufrag.size()); |
| 582 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 583 | ti_data->description.ice_pwd.size()); |
| 584 | } |
| 585 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 586 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 587 | FindFirstMediaDescriptionByMid("data", options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 588 | EXPECT_EQ( |
| 589 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 590 | GetIceRenomination(ti_data)); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 591 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 592 | } else { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 593 | EXPECT_TRUE(ti_data == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
| 597 | void TestCryptoWithBundle(bool offer) { |
| 598 | f1_.set_secure(SEC_ENABLED); |
| 599 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 600 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 601 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 602 | &options); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 603 | std::unique_ptr<SessionDescription> ref_desc; |
| 604 | std::unique_ptr<SessionDescription> desc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 605 | if (offer) { |
| 606 | options.bundle_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 607 | ref_desc = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | options.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 609 | desc = f1_.CreateOffer(options, ref_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 610 | } else { |
| 611 | options.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 612 | ref_desc = f1_.CreateOffer(options, NULL); |
| 613 | desc = f1_.CreateAnswer(ref_desc.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 614 | } |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 615 | ASSERT_TRUE(desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 616 | const cricket::MediaContentDescription* audio_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 617 | desc->GetContentDescriptionByName("audio"); |
| 618 | ASSERT_TRUE(audio_media_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 619 | const cricket::MediaContentDescription* video_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 620 | desc->GetContentDescriptionByName("video"); |
| 621 | ASSERT_TRUE(video_media_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | EXPECT_TRUE(CompareCryptoParams(audio_media_desc->cryptos(), |
| 623 | video_media_desc->cryptos())); |
| 624 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 625 | EXPECT_EQ(kDefaultSrtpCryptoSuite, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 626 | audio_media_desc->cryptos()[0].cipher_suite); |
| 627 | |
| 628 | // Verify the selected crypto is one from the reference audio |
| 629 | // media content. |
| 630 | const cricket::MediaContentDescription* ref_audio_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 631 | ref_desc->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 632 | bool found = false; |
| 633 | for (size_t i = 0; i < ref_audio_media_desc->cryptos().size(); ++i) { |
| 634 | if (ref_audio_media_desc->cryptos()[i].Matches( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 635 | audio_media_desc->cryptos()[0])) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 636 | found = true; |
| 637 | break; |
| 638 | } |
| 639 | } |
| 640 | EXPECT_TRUE(found); |
| 641 | } |
| 642 | |
| 643 | // This test that the audio and video media direction is set to |
| 644 | // |expected_direction_in_answer| in an answer if the offer direction is set |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 645 | // 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] | 646 | void TestMediaDirectionInAnswer( |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 647 | RtpTransceiverDirection direction_in_offer, |
| 648 | RtpTransceiverDirection expected_direction_in_answer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 649 | MediaSessionOptions offer_opts; |
| 650 | AddAudioVideoSections(direction_in_offer, &offer_opts); |
| 651 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 652 | std::unique_ptr<SessionDescription> offer = |
| 653 | f1_.CreateOffer(offer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | ASSERT_TRUE(offer.get() != NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 655 | ContentInfo* ac_offer = offer->GetContentByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 656 | ASSERT_TRUE(ac_offer != NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 657 | ContentInfo* vc_offer = offer->GetContentByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 658 | ASSERT_TRUE(vc_offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 659 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 660 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 661 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 662 | std::unique_ptr<SessionDescription> answer = |
| 663 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 664 | const AudioContentDescription* acd_answer = |
| 665 | GetFirstAudioContentDescription(answer.get()); |
| 666 | EXPECT_EQ(expected_direction_in_answer, acd_answer->direction()); |
| 667 | const VideoContentDescription* vcd_answer = |
| 668 | GetFirstVideoContentDescription(answer.get()); |
| 669 | EXPECT_EQ(expected_direction_in_answer, vcd_answer->direction()); |
| 670 | } |
| 671 | |
| 672 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 673 | RTC_DCHECK(content); |
| 674 | RTC_CHECK(content->media_description()); |
| 675 | const cricket::AudioContentDescription* audio_desc = |
| 676 | content->media_description()->as_audio(); |
| 677 | RTC_CHECK(audio_desc); |
| 678 | for (const cricket::AudioCodec& codec : audio_desc->codecs()) { |
| 679 | if (codec.name == "CN") { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 680 | return false; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 681 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 682 | } |
| 683 | return true; |
| 684 | } |
| 685 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 686 | void TestVideoGcmCipher(bool gcm_offer, bool gcm_answer) { |
| 687 | MediaSessionOptions offer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 688 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &offer_opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 689 | offer_opts.crypto_options.srtp.enable_gcm_crypto_suites = gcm_offer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 690 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 691 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 692 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &answer_opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 693 | answer_opts.crypto_options.srtp.enable_gcm_crypto_suites = gcm_answer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 694 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 695 | f1_.set_secure(SEC_ENABLED); |
| 696 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 697 | std::unique_ptr<SessionDescription> offer = |
| 698 | f1_.CreateOffer(offer_opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 699 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 700 | std::unique_ptr<SessionDescription> answer = |
| 701 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 702 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 703 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 704 | ASSERT_TRUE(ac != NULL); |
| 705 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 706 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 707 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 708 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 709 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 710 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 711 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 712 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 713 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 714 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 715 | if (gcm_offer && gcm_answer) { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 716 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 717 | } else { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 718 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 719 | } |
| 720 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 721 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 722 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 723 | EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 724 | if (gcm_offer && gcm_answer) { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 725 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuiteGcm); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 726 | } else { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 727 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 728 | } |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 729 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 732 | void TestTransportSequenceNumberNegotiation( |
| 733 | const cricket::RtpHeaderExtensions& local, |
| 734 | const cricket::RtpHeaderExtensions& offered, |
| 735 | const cricket::RtpHeaderExtensions& expectedAnswer) { |
| 736 | MediaSessionOptions opts; |
| 737 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 738 | f1_.set_audio_rtp_header_extensions(offered); |
| 739 | f1_.set_video_rtp_header_extensions(offered); |
| 740 | f2_.set_audio_rtp_header_extensions(local); |
| 741 | f2_.set_video_rtp_header_extensions(local); |
| 742 | |
| 743 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 744 | ASSERT_TRUE(offer.get() != NULL); |
| 745 | std::unique_ptr<SessionDescription> answer = |
| 746 | f2_.CreateAnswer(offer.get(), opts, NULL); |
| 747 | |
| 748 | EXPECT_EQ( |
| 749 | expectedAnswer, |
| 750 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 751 | EXPECT_EQ( |
| 752 | expectedAnswer, |
| 753 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
| 754 | } |
| 755 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 756 | protected: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 757 | UniqueRandomIdGenerator ssrc_generator1; |
| 758 | UniqueRandomIdGenerator ssrc_generator2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 759 | MediaSessionDescriptionFactory f1_; |
| 760 | MediaSessionDescriptionFactory f2_; |
| 761 | TransportDescriptionFactory tdf1_; |
| 762 | TransportDescriptionFactory tdf2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | // Create a typical audio offer, and ensure it matches what we expect. |
| 766 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { |
| 767 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 768 | std::unique_ptr<SessionDescription> offer = |
| 769 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 770 | ASSERT_TRUE(offer.get() != NULL); |
| 771 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 772 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 773 | ASSERT_TRUE(ac != NULL); |
| 774 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 775 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 776 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 777 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 778 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 779 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 780 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 781 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 782 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 783 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | // Create a typical video offer, and ensure it matches what we expect. |
| 787 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoOffer) { |
| 788 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 789 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 790 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 791 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 792 | ASSERT_TRUE(offer.get() != NULL); |
| 793 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 794 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 795 | ASSERT_TRUE(ac != NULL); |
| 796 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 797 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 798 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 799 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 800 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 801 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 802 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 803 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 804 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 805 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 806 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 807 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 808 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 809 | EXPECT_EQ(f1_.video_sendrecv_codecs(), vcd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 810 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 811 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 812 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 813 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 814 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // Test creating an offer with bundle where the Codecs have the same dynamic |
| 818 | // RTP playlod type. The test verifies that the offer don't contain the |
| 819 | // duplicate RTP payload types. |
| 820 | TEST_F(MediaSessionDescriptionFactoryTest, TestBundleOfferWithSameCodecPlType) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 821 | const VideoCodec& offered_video_codec = f2_.video_sendrecv_codecs()[0]; |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 822 | const AudioCodec& offered_audio_codec = f2_.audio_sendrecv_codecs()[0]; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 823 | const RtpDataCodec& offered_data_codec = f2_.rtp_data_codecs()[0]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 824 | ASSERT_EQ(offered_video_codec.id, offered_audio_codec.id); |
| 825 | ASSERT_EQ(offered_video_codec.id, offered_data_codec.id); |
| 826 | |
| 827 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 828 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 829 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 830 | opts.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 831 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 832 | const VideoContentDescription* vcd = |
| 833 | GetFirstVideoContentDescription(offer.get()); |
| 834 | const AudioContentDescription* acd = |
| 835 | GetFirstAudioContentDescription(offer.get()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 836 | const RtpDataContentDescription* dcd = |
| 837 | GetFirstRtpDataContentDescription(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 838 | ASSERT_TRUE(NULL != vcd); |
| 839 | ASSERT_TRUE(NULL != acd); |
| 840 | ASSERT_TRUE(NULL != dcd); |
| 841 | EXPECT_NE(vcd->codecs()[0].id, acd->codecs()[0].id); |
| 842 | EXPECT_NE(vcd->codecs()[0].id, dcd->codecs()[0].id); |
| 843 | EXPECT_NE(acd->codecs()[0].id, dcd->codecs()[0].id); |
| 844 | EXPECT_EQ(vcd->codecs()[0].name, offered_video_codec.name); |
| 845 | EXPECT_EQ(acd->codecs()[0].name, offered_audio_codec.name); |
| 846 | EXPECT_EQ(dcd->codecs()[0].name, offered_data_codec.name); |
| 847 | } |
| 848 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 849 | // Test creating an updated offer with bundle, audio, video and data |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 850 | // after an audio only session has been negotiated. |
| 851 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 852 | TestCreateUpdatedVideoOfferWithBundle) { |
| 853 | f1_.set_secure(SEC_ENABLED); |
| 854 | f2_.set_secure(SEC_ENABLED); |
| 855 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 856 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 857 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 858 | &opts); |
| 859 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 860 | RtpTransceiverDirection::kInactive, kStopped, |
| 861 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 862 | opts.data_channel_type = cricket::DCT_NONE; |
| 863 | opts.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 864 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 865 | std::unique_ptr<SessionDescription> answer = |
| 866 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 867 | |
| 868 | MediaSessionOptions updated_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 869 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &updated_opts); |
| 870 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 871 | &updated_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 872 | updated_opts.bundle_enabled = true; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 873 | std::unique_ptr<SessionDescription> updated_offer( |
| 874 | f1_.CreateOffer(updated_opts, answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 875 | |
| 876 | const AudioContentDescription* acd = |
| 877 | GetFirstAudioContentDescription(updated_offer.get()); |
| 878 | const VideoContentDescription* vcd = |
| 879 | GetFirstVideoContentDescription(updated_offer.get()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 880 | const RtpDataContentDescription* dcd = |
| 881 | GetFirstRtpDataContentDescription(updated_offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | EXPECT_TRUE(NULL != vcd); |
| 883 | EXPECT_TRUE(NULL != acd); |
| 884 | EXPECT_TRUE(NULL != dcd); |
| 885 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 886 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 887 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 888 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 889 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 890 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 891 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 892 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 893 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 894 | // Create a RTP data offer, and ensure it matches what we expect. |
| 895 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateRtpDataOffer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 896 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 897 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 898 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 899 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 900 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | ASSERT_TRUE(offer.get() != NULL); |
| 902 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 903 | const ContentInfo* dc = offer->GetContentByName("data"); |
| 904 | ASSERT_TRUE(ac != NULL); |
| 905 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 906 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 907 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 908 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 909 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 910 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 911 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 912 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attched. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 913 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 914 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 915 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 916 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 917 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 918 | EXPECT_EQ(f1_.rtp_data_codecs(), dcd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 919 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 920 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 921 | dcd->bandwidth()); // default bandwidth (auto) |
| 922 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 923 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 924 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 925 | } |
| 926 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 927 | // Create an SCTP data offer with bundle without error. |
| 928 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { |
| 929 | MediaSessionOptions opts; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 930 | opts.bundle_enabled = true; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 931 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 932 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 933 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 934 | EXPECT_TRUE(offer.get() != NULL); |
| 935 | EXPECT_TRUE(offer->GetContentByName("data") != NULL); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 +0000 | [diff] [blame] | 936 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 937 | ASSERT_TRUE(dcd); |
| 938 | // Since this transport is insecure, the protocol should be "SCTP". |
| 939 | EXPECT_EQ(cricket::kMediaProtocolSctp, dcd->protocol()); |
| 940 | } |
| 941 | |
| 942 | // Create an SCTP data offer with bundle without error. |
| 943 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSecureSctpDataOffer) { |
| 944 | MediaSessionOptions opts; |
| 945 | opts.bundle_enabled = true; |
| 946 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 947 | f1_.set_secure(SEC_ENABLED); |
| 948 | tdf1_.set_secure(SEC_ENABLED); |
| 949 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 950 | EXPECT_TRUE(offer.get() != NULL); |
| 951 | EXPECT_TRUE(offer->GetContentByName("data") != NULL); |
| 952 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 953 | ASSERT_TRUE(dcd); |
| 954 | // The protocol should now be "UDP/DTLS/SCTP" |
| 955 | EXPECT_EQ(cricket::kMediaProtocolUdpDtlsSctp, dcd->protocol()); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 956 | } |
| 957 | |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 958 | // Test creating an sctp data channel from an already generated offer. |
| 959 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { |
| 960 | MediaSessionOptions opts; |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 961 | opts.bundle_enabled = true; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 962 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 963 | f1_.set_secure(SEC_ENABLED); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 964 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 965 | ASSERT_TRUE(offer1.get() != NULL); |
| 966 | const ContentInfo* data = offer1->GetContentByName("data"); |
| 967 | ASSERT_TRUE(data != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 968 | ASSERT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 969 | |
| 970 | // Now set data_channel_type to 'none' (default) and make sure that the |
| 971 | // datachannel type that gets generated from the previous offer, is of the |
| 972 | // same type. |
| 973 | opts.data_channel_type = cricket::DCT_NONE; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 974 | std::unique_ptr<SessionDescription> offer2( |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 975 | f1_.CreateOffer(opts, offer1.get())); |
| 976 | data = offer2->GetContentByName("data"); |
| 977 | ASSERT_TRUE(data != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 978 | EXPECT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 981 | // Test that if BUNDLE is enabled and all media sections are rejected then the |
| 982 | // BUNDLE group is not present in the re-offer. |
| 983 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferNoBundleGroupIfAllRejected) { |
| 984 | MediaSessionOptions opts; |
| 985 | opts.bundle_enabled = true; |
| 986 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 987 | RtpTransceiverDirection::kSendRecv, kActive, |
| 988 | &opts); |
| 989 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 990 | |
| 991 | opts.media_description_options[0].stopped = true; |
| 992 | std::unique_ptr<SessionDescription> reoffer = |
| 993 | f1_.CreateOffer(opts, offer.get()); |
| 994 | |
| 995 | EXPECT_FALSE(reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); |
| 996 | } |
| 997 | |
| 998 | // Test that if BUNDLE is enabled and the remote re-offer does not include a |
| 999 | // BUNDLE group since all media sections are rejected, then the re-answer also |
| 1000 | // does not include a BUNDLE group. |
| 1001 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerNoBundleGroupIfAllRejected) { |
| 1002 | MediaSessionOptions opts; |
| 1003 | opts.bundle_enabled = true; |
| 1004 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1005 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1006 | &opts); |
| 1007 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1008 | std::unique_ptr<SessionDescription> answer = |
| 1009 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1010 | |
| 1011 | opts.media_description_options[0].stopped = true; |
| 1012 | std::unique_ptr<SessionDescription> reoffer = |
| 1013 | f1_.CreateOffer(opts, offer.get()); |
| 1014 | std::unique_ptr<SessionDescription> reanswer = |
| 1015 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1016 | |
| 1017 | EXPECT_FALSE(reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); |
| 1018 | } |
| 1019 | |
| 1020 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 1021 | // was rejected then the new offerer-tagged media section is the non-rejected |
| 1022 | // media section. |
| 1023 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferChangeBundleOffererTagged) { |
| 1024 | MediaSessionOptions opts; |
| 1025 | opts.bundle_enabled = true; |
| 1026 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1027 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1028 | &opts); |
| 1029 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1030 | |
| 1031 | // Reject the audio m= section and add a video m= section. |
| 1032 | opts.media_description_options[0].stopped = true; |
| 1033 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1034 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1035 | &opts); |
| 1036 | std::unique_ptr<SessionDescription> reoffer = |
| 1037 | f1_.CreateOffer(opts, offer.get()); |
| 1038 | |
| 1039 | const cricket::ContentGroup* bundle_group = |
| 1040 | reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1041 | ASSERT_TRUE(bundle_group); |
| 1042 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 1043 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 1044 | } |
| 1045 | |
| 1046 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 1047 | // was rejected and a new media section is added, then the re-answer BUNDLE |
| 1048 | // group will contain only the non-rejected media section. |
| 1049 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerChangedBundleOffererTagged) { |
| 1050 | MediaSessionOptions opts; |
| 1051 | opts.bundle_enabled = true; |
| 1052 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1053 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1054 | &opts); |
| 1055 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1056 | std::unique_ptr<SessionDescription> answer = |
| 1057 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1058 | |
| 1059 | // Reject the audio m= section and add a video m= section. |
| 1060 | opts.media_description_options[0].stopped = true; |
| 1061 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1062 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1063 | &opts); |
| 1064 | std::unique_ptr<SessionDescription> reoffer = |
| 1065 | f1_.CreateOffer(opts, offer.get()); |
| 1066 | std::unique_ptr<SessionDescription> reanswer = |
| 1067 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1068 | |
| 1069 | const cricket::ContentGroup* bundle_group = |
| 1070 | reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1071 | ASSERT_TRUE(bundle_group); |
| 1072 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 1073 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 1074 | } |
| 1075 | |
| 1076 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1077 | // and there is still a non-rejected media section that was in the initial |
| 1078 | // offer, then the ICE credentials do not change in the reoffer offerer-tagged |
| 1079 | // media section. |
| 1080 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1081 | ReOfferChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1082 | MediaSessionOptions opts; |
| 1083 | opts.bundle_enabled = true; |
| 1084 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 1085 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1086 | std::unique_ptr<SessionDescription> answer = |
| 1087 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1088 | |
| 1089 | // Reject the audio m= section. |
| 1090 | opts.media_description_options[0].stopped = true; |
| 1091 | std::unique_ptr<SessionDescription> reoffer = |
| 1092 | f1_.CreateOffer(opts, offer.get()); |
| 1093 | |
| 1094 | const TransportDescription* offer_tagged = |
| 1095 | offer->GetTransportDescriptionByName("audio"); |
| 1096 | ASSERT_TRUE(offer_tagged); |
| 1097 | const TransportDescription* reoffer_tagged = |
| 1098 | reoffer->GetTransportDescriptionByName("video"); |
| 1099 | ASSERT_TRUE(reoffer_tagged); |
| 1100 | EXPECT_EQ(offer_tagged->ice_ufrag, reoffer_tagged->ice_ufrag); |
| 1101 | EXPECT_EQ(offer_tagged->ice_pwd, reoffer_tagged->ice_pwd); |
| 1102 | } |
| 1103 | |
| 1104 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1105 | // and there is still a non-rejected media section that was in the initial |
| 1106 | // offer, then the ICE credentials do not change in the reanswer answerer-tagged |
| 1107 | // media section. |
| 1108 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1109 | ReAnswerChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1110 | MediaSessionOptions opts; |
| 1111 | opts.bundle_enabled = true; |
| 1112 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 1113 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1114 | std::unique_ptr<SessionDescription> answer = |
| 1115 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1116 | |
| 1117 | // Reject the audio m= section. |
| 1118 | opts.media_description_options[0].stopped = true; |
| 1119 | std::unique_ptr<SessionDescription> reoffer = |
| 1120 | f1_.CreateOffer(opts, offer.get()); |
| 1121 | std::unique_ptr<SessionDescription> reanswer = |
| 1122 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1123 | |
| 1124 | const TransportDescription* answer_tagged = |
| 1125 | answer->GetTransportDescriptionByName("audio"); |
| 1126 | ASSERT_TRUE(answer_tagged); |
| 1127 | const TransportDescription* reanswer_tagged = |
| 1128 | reanswer->GetTransportDescriptionByName("video"); |
| 1129 | ASSERT_TRUE(reanswer_tagged); |
| 1130 | EXPECT_EQ(answer_tagged->ice_ufrag, reanswer_tagged->ice_ufrag); |
| 1131 | EXPECT_EQ(answer_tagged->ice_pwd, reanswer_tagged->ice_pwd); |
| 1132 | } |
| 1133 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1134 | // Create an audio, video offer without legacy StreamParams. |
| 1135 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1136 | TestCreateOfferWithoutLegacyStreams) { |
| 1137 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1138 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1139 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1140 | ASSERT_TRUE(offer.get() != NULL); |
| 1141 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 1142 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 1143 | ASSERT_TRUE(ac != NULL); |
| 1144 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1145 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1146 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1147 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1148 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1149 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1152 | // Creates an audio+video sendonly offer. |
| 1153 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSendOnlyOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1154 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1155 | AddAudioVideoSections(RtpTransceiverDirection::kSendOnly, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1156 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 1157 | {kMediaStream1}, 1, &opts); |
| 1158 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 1159 | {kMediaStream1}, 1, &opts); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1160 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1161 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1162 | ASSERT_TRUE(offer.get() != NULL); |
| 1163 | EXPECT_EQ(2u, offer->contents().size()); |
| 1164 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[0], MEDIA_TYPE_AUDIO)); |
| 1165 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1166 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1167 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1168 | GetMediaDirection(&offer->contents()[0])); |
| 1169 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1170 | GetMediaDirection(&offer->contents()[1])); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1173 | // Verifies that the order of the media contents in the current |
| 1174 | // SessionDescription is preserved in the new SessionDescription. |
| 1175 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { |
| 1176 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1177 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1178 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1179 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1180 | ASSERT_TRUE(offer1.get() != NULL); |
| 1181 | EXPECT_EQ(1u, offer1->contents().size()); |
| 1182 | EXPECT_TRUE(IsMediaContentOfType(&offer1->contents()[0], MEDIA_TYPE_DATA)); |
| 1183 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1184 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1185 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1186 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1187 | std::unique_ptr<SessionDescription> offer2( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1188 | f1_.CreateOffer(opts, offer1.get())); |
| 1189 | ASSERT_TRUE(offer2.get() != NULL); |
| 1190 | EXPECT_EQ(2u, offer2->contents().size()); |
| 1191 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[0], MEDIA_TYPE_DATA)); |
| 1192 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1193 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1194 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1195 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1196 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1197 | std::unique_ptr<SessionDescription> offer3( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1198 | f1_.CreateOffer(opts, offer2.get())); |
| 1199 | ASSERT_TRUE(offer3.get() != NULL); |
| 1200 | EXPECT_EQ(3u, offer3->contents().size()); |
| 1201 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[0], MEDIA_TYPE_DATA)); |
| 1202 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1203 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[2], MEDIA_TYPE_AUDIO)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1206 | // Create a typical audio answer, and ensure it matches what we expect. |
| 1207 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswer) { |
| 1208 | f1_.set_secure(SEC_ENABLED); |
| 1209 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1210 | std::unique_ptr<SessionDescription> offer = |
| 1211 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1212 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1213 | std::unique_ptr<SessionDescription> answer = |
| 1214 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1215 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1216 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1217 | ASSERT_TRUE(ac != NULL); |
| 1218 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1219 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1220 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1221 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1222 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1223 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1224 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1225 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1226 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1227 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1230 | // Create a typical audio answer with GCM ciphers enabled, and ensure it |
| 1231 | // matches what we expect. |
| 1232 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { |
| 1233 | f1_.set_secure(SEC_ENABLED); |
| 1234 | f2_.set_secure(SEC_ENABLED); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1235 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1236 | opts.crypto_options.srtp.enable_gcm_crypto_suites = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1237 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1238 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1239 | std::unique_ptr<SessionDescription> answer = |
| 1240 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1241 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1242 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1243 | ASSERT_TRUE(ac != NULL); |
| 1244 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1245 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1246 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1247 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1248 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1249 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1250 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1251 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1252 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1253 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1256 | // Create a typical video answer, and ensure it matches what we expect. |
| 1257 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { |
| 1258 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1259 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1260 | f1_.set_secure(SEC_ENABLED); |
| 1261 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1262 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1263 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1264 | std::unique_ptr<SessionDescription> answer = |
| 1265 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1266 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1267 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1268 | ASSERT_TRUE(ac != NULL); |
| 1269 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1270 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1271 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1272 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1273 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1274 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1275 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1276 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1277 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1278 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1279 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1280 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1281 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1282 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 1283 | EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1284 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1285 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1288 | // Create a typical video answer with GCM ciphers enabled, and ensure it |
| 1289 | // matches what we expect. |
| 1290 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcm) { |
| 1291 | TestVideoGcmCipher(true, true); |
| 1292 | } |
| 1293 | |
| 1294 | // Create a typical video answer with GCM ciphers enabled for the offer only, |
| 1295 | // and ensure it matches what we expect. |
| 1296 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmOffer) { |
| 1297 | TestVideoGcmCipher(true, false); |
| 1298 | } |
| 1299 | |
| 1300 | // Create a typical video answer with GCM ciphers enabled for the answer only, |
| 1301 | // and ensure it matches what we expect. |
| 1302 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmAnswer) { |
| 1303 | TestVideoGcmCipher(false, true); |
| 1304 | } |
| 1305 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1306 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1307 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1308 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1309 | f1_.set_secure(SEC_ENABLED); |
| 1310 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1311 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1312 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1313 | std::unique_ptr<SessionDescription> answer = |
| 1314 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1315 | const ContentInfo* ac = answer->GetContentByName("audio"); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1316 | const ContentInfo* dc = answer->GetContentByName("data"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1317 | ASSERT_TRUE(ac != NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1318 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1319 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1320 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1321 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1322 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1323 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1324 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1325 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1326 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1327 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1328 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1329 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1330 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1331 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1332 | EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1333 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1334 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1337 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1338 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1339 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1340 | opts.crypto_options.srtp.enable_gcm_crypto_suites = true; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1341 | f1_.set_secure(SEC_ENABLED); |
| 1342 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1343 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1344 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1345 | std::unique_ptr<SessionDescription> answer = |
| 1346 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1347 | const ContentInfo* ac = answer->GetContentByName("audio"); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1348 | const ContentInfo* dc = answer->GetContentByName("data"); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1349 | ASSERT_TRUE(ac != NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1350 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1351 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1352 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1353 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1354 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1355 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1356 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1357 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1358 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1359 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1360 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1361 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1362 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1363 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1364 | EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1365 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuiteGcm); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1366 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1367 | } |
| 1368 | |
Harald Alvestrand | c5effc2 | 2019-06-11 11:46:59 +0200 | [diff] [blame] | 1369 | // The use_sctpmap flag should be set in an Sctp DataContentDescription by |
| 1370 | // default. The answer's use_sctpmap flag should match the offer's. |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1371 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { |
| 1372 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1373 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1374 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1375 | ASSERT_TRUE(offer.get() != NULL); |
| 1376 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1377 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1378 | SctpDataContentDescription* dcd_offer = |
| 1379 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1380 | EXPECT_TRUE(dcd_offer->use_sctpmap()); |
| 1381 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1382 | std::unique_ptr<SessionDescription> answer = |
| 1383 | f2_.CreateAnswer(offer.get(), opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1384 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1385 | ASSERT_TRUE(dc_answer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1386 | const SctpDataContentDescription* dcd_answer = |
| 1387 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1388 | EXPECT_TRUE(dcd_answer->use_sctpmap()); |
| 1389 | } |
| 1390 | |
| 1391 | // The answer's use_sctpmap flag should match the offer's. |
| 1392 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerWithoutSctpmap) { |
| 1393 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1394 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1395 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1396 | ASSERT_TRUE(offer.get() != NULL); |
| 1397 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1398 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1399 | SctpDataContentDescription* dcd_offer = |
| 1400 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1401 | dcd_offer->set_use_sctpmap(false); |
| 1402 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1403 | std::unique_ptr<SessionDescription> answer = |
| 1404 | f2_.CreateAnswer(offer.get(), opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1405 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1406 | ASSERT_TRUE(dc_answer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1407 | const SctpDataContentDescription* dcd_answer = |
| 1408 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1409 | EXPECT_FALSE(dcd_answer->use_sctpmap()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1412 | // Test that a valid answer will be created for "DTLS/SCTP", "UDP/DTLS/SCTP" |
| 1413 | // and "TCP/DTLS/SCTP" offers. |
| 1414 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1415 | TestCreateDataAnswerToDifferentOfferedProtos) { |
| 1416 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1417 | // test). |
| 1418 | f1_.set_secure(SEC_ENABLED); |
| 1419 | f2_.set_secure(SEC_ENABLED); |
| 1420 | tdf1_.set_secure(SEC_ENABLED); |
| 1421 | tdf2_.set_secure(SEC_ENABLED); |
| 1422 | |
| 1423 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1424 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1425 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1426 | ASSERT_TRUE(offer.get() != nullptr); |
| 1427 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1428 | ASSERT_TRUE(dc_offer != nullptr); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1429 | SctpDataContentDescription* dcd_offer = |
| 1430 | dc_offer->media_description()->as_sctp(); |
| 1431 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1432 | |
| 1433 | std::vector<std::string> protos = {"DTLS/SCTP", "UDP/DTLS/SCTP", |
| 1434 | "TCP/DTLS/SCTP"}; |
| 1435 | for (const std::string& proto : protos) { |
| 1436 | dcd_offer->set_protocol(proto); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1437 | std::unique_ptr<SessionDescription> answer = |
| 1438 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1439 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1440 | ASSERT_TRUE(dc_answer != nullptr); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1441 | const SctpDataContentDescription* dcd_answer = |
| 1442 | dc_answer->media_description()->as_sctp(); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1443 | EXPECT_FALSE(dc_answer->rejected); |
| 1444 | EXPECT_EQ(proto, dcd_answer->protocol()); |
| 1445 | } |
| 1446 | } |
| 1447 | |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 1448 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1449 | TestCreateDataAnswerToOfferWithDefinedMessageSize) { |
| 1450 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1451 | // test). |
| 1452 | f1_.set_secure(SEC_ENABLED); |
| 1453 | f2_.set_secure(SEC_ENABLED); |
| 1454 | tdf1_.set_secure(SEC_ENABLED); |
| 1455 | tdf2_.set_secure(SEC_ENABLED); |
| 1456 | |
| 1457 | MediaSessionOptions opts; |
| 1458 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 1459 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1460 | ASSERT_TRUE(offer.get() != nullptr); |
| 1461 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1462 | ASSERT_TRUE(dc_offer != nullptr); |
| 1463 | SctpDataContentDescription* dcd_offer = |
| 1464 | dc_offer->media_description()->as_sctp(); |
| 1465 | ASSERT_TRUE(dcd_offer); |
| 1466 | dcd_offer->set_max_message_size(1234); |
| 1467 | std::unique_ptr<SessionDescription> answer = |
| 1468 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1469 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1470 | ASSERT_TRUE(dc_answer != nullptr); |
| 1471 | const SctpDataContentDescription* dcd_answer = |
| 1472 | dc_answer->media_description()->as_sctp(); |
| 1473 | EXPECT_FALSE(dc_answer->rejected); |
| 1474 | EXPECT_EQ(1234, dcd_answer->max_message_size()); |
| 1475 | } |
| 1476 | |
| 1477 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1478 | TestCreateDataAnswerToOfferWithZeroMessageSize) { |
| 1479 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1480 | // test). |
| 1481 | f1_.set_secure(SEC_ENABLED); |
| 1482 | f2_.set_secure(SEC_ENABLED); |
| 1483 | tdf1_.set_secure(SEC_ENABLED); |
| 1484 | tdf2_.set_secure(SEC_ENABLED); |
| 1485 | |
| 1486 | MediaSessionOptions opts; |
| 1487 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 1488 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1489 | ASSERT_TRUE(offer.get() != nullptr); |
| 1490 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1491 | ASSERT_TRUE(dc_offer != nullptr); |
| 1492 | SctpDataContentDescription* dcd_offer = |
| 1493 | dc_offer->media_description()->as_sctp(); |
| 1494 | ASSERT_TRUE(dcd_offer); |
| 1495 | dcd_offer->set_max_message_size(0); |
| 1496 | std::unique_ptr<SessionDescription> answer = |
| 1497 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1498 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1499 | ASSERT_TRUE(dc_answer != nullptr); |
| 1500 | const SctpDataContentDescription* dcd_answer = |
| 1501 | dc_answer->media_description()->as_sctp(); |
| 1502 | EXPECT_FALSE(dc_answer->rejected); |
| 1503 | EXPECT_EQ(cricket::kSctpSendBufferSize, dcd_answer->max_message_size()); |
| 1504 | } |
| 1505 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1506 | // Verifies that the order of the media contents in the offer is preserved in |
| 1507 | // the answer. |
| 1508 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { |
| 1509 | MediaSessionOptions opts; |
| 1510 | |
| 1511 | // Creates a data only offer. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1512 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1513 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1514 | ASSERT_TRUE(offer1.get() != NULL); |
| 1515 | |
| 1516 | // Appends audio to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1517 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1518 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1519 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1520 | std::unique_ptr<SessionDescription> offer2( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1521 | f1_.CreateOffer(opts, offer1.get())); |
| 1522 | ASSERT_TRUE(offer2.get() != NULL); |
| 1523 | |
| 1524 | // Appends video to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1525 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1526 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1527 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1528 | std::unique_ptr<SessionDescription> offer3( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1529 | f1_.CreateOffer(opts, offer2.get())); |
| 1530 | ASSERT_TRUE(offer3.get() != NULL); |
| 1531 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1532 | std::unique_ptr<SessionDescription> answer = |
| 1533 | f2_.CreateAnswer(offer3.get(), opts, NULL); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1534 | ASSERT_TRUE(answer.get() != NULL); |
| 1535 | EXPECT_EQ(3u, answer->contents().size()); |
| 1536 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[0], MEDIA_TYPE_DATA)); |
| 1537 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[1], MEDIA_TYPE_AUDIO)); |
| 1538 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[2], MEDIA_TYPE_VIDEO)); |
| 1539 | } |
| 1540 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1541 | // TODO(deadbeef): Extend these tests to ensure the correct direction with other |
| 1542 | // answerer settings. |
| 1543 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1544 | // This test that the media direction is set to send/receive in an answer if |
| 1545 | // the offer is send receive. |
| 1546 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendReceiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1547 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendRecv, |
| 1548 | RtpTransceiverDirection::kSendRecv); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | // This test that the media direction is set to receive only in an answer if |
| 1552 | // the offer is send only. |
| 1553 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1554 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendOnly, |
| 1555 | RtpTransceiverDirection::kRecvOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | // This test that the media direction is set to send only in an answer if |
| 1559 | // the offer is recv only. |
| 1560 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToRecvOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1561 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kRecvOnly, |
| 1562 | RtpTransceiverDirection::kSendOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | // This test that the media direction is set to inactive in an answer if |
| 1566 | // the offer is inactive. |
| 1567 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToInactiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1568 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kInactive, |
| 1569 | RtpTransceiverDirection::kInactive); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | // Test that a data content with an unknown protocol is rejected in an answer. |
| 1573 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1574 | CreateDataAnswerToOfferWithUnknownProtocol) { |
| 1575 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1576 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1577 | f1_.set_secure(SEC_ENABLED); |
| 1578 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1579 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 1580 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1581 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1582 | RtpDataContentDescription* dcd_offer = |
| 1583 | dc_offer->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1584 | ASSERT_TRUE(dcd_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1585 | // Offer must be acceptable as an RTP protocol in order to be set. |
| 1586 | std::string protocol = "RTP/a weird unknown protocol"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1587 | dcd_offer->set_protocol(protocol); |
| 1588 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1589 | std::unique_ptr<SessionDescription> answer = |
| 1590 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1591 | |
| 1592 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1593 | ASSERT_TRUE(dc_answer != NULL); |
| 1594 | EXPECT_TRUE(dc_answer->rejected); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1595 | const RtpDataContentDescription* dcd_answer = |
| 1596 | dc_answer->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1597 | ASSERT_TRUE(dcd_answer != NULL); |
| 1598 | EXPECT_EQ(protocol, dcd_answer->protocol()); |
| 1599 | } |
| 1600 | |
| 1601 | // Test that the media protocol is RTP/AVPF if DTLS and SDES are disabled. |
| 1602 | TEST_F(MediaSessionDescriptionFactoryTest, AudioOfferAnswerWithCryptoDisabled) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1603 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1604 | f1_.set_secure(SEC_DISABLED); |
| 1605 | f2_.set_secure(SEC_DISABLED); |
| 1606 | tdf1_.set_secure(SEC_DISABLED); |
| 1607 | tdf2_.set_secure(SEC_DISABLED); |
| 1608 | |
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 | const AudioContentDescription* offer_acd = |
| 1611 | GetFirstAudioContentDescription(offer.get()); |
| 1612 | ASSERT_TRUE(offer_acd != NULL); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1613 | EXPECT_EQ(cricket::kMediaProtocolAvpf, offer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1614 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1615 | std::unique_ptr<SessionDescription> answer = |
| 1616 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1617 | |
| 1618 | const ContentInfo* ac_answer = answer->GetContentByName("audio"); |
| 1619 | ASSERT_TRUE(ac_answer != NULL); |
| 1620 | EXPECT_FALSE(ac_answer->rejected); |
| 1621 | |
| 1622 | const AudioContentDescription* answer_acd = |
| 1623 | GetFirstAudioContentDescription(answer.get()); |
| 1624 | ASSERT_TRUE(answer_acd != NULL); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1625 | EXPECT_EQ(cricket::kMediaProtocolAvpf, answer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | // Create a video offer and answer and ensure the RTP header extensions |
| 1629 | // matches what we expect. |
| 1630 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferAnswerWithRtpExtensions) { |
| 1631 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1632 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1633 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1634 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1635 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1636 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 1637 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1638 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1639 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1640 | std::unique_ptr<SessionDescription> answer = |
| 1641 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1642 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1643 | EXPECT_EQ( |
| 1644 | MAKE_VECTOR(kAudioRtpExtension1), |
| 1645 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1646 | EXPECT_EQ( |
| 1647 | MAKE_VECTOR(kVideoRtpExtension1), |
| 1648 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1649 | EXPECT_EQ( |
| 1650 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1651 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1652 | EXPECT_EQ( |
| 1653 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1654 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 1657 | // Create a audio/video offer and answer and ensure that the |
| 1658 | // TransportSequenceNumber RTP header extensions are handled correctly. 02 is |
| 1659 | // supported and should take precedence even though not listed among locally |
| 1660 | // supported extensions. |
| 1661 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1662 | TestOfferAnswerWithTransportSequenceNumberInOffer) { |
| 1663 | TestTransportSequenceNumberNegotiation( |
| 1664 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1665 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Offer. |
| 1666 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01)); // Expected answer. |
| 1667 | } |
| 1668 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1669 | TestOfferAnswerWithTransportSequenceNumber01And02InOffer) { |
| 1670 | TestTransportSequenceNumberNegotiation( |
| 1671 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1672 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Offer. |
| 1673 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1674 | } |
| 1675 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1676 | TestOfferAnswerWithTransportSequenceNumber02InOffer) { |
| 1677 | TestTransportSequenceNumberNegotiation( |
| 1678 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1679 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Offer. |
| 1680 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1681 | } |
| 1682 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1683 | TEST_F(MediaSessionDescriptionFactoryTest, |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1684 | TestNegotiateFrameDescriptorWhenUnexposedLocally) { |
| 1685 | MediaSessionOptions opts; |
| 1686 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1687 | |
| 1688 | const auto offered = MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00); |
| 1689 | f1_.set_audio_rtp_header_extensions(offered); |
| 1690 | f1_.set_video_rtp_header_extensions(offered); |
| 1691 | const auto local = MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01); |
| 1692 | f2_.set_audio_rtp_header_extensions(local); |
| 1693 | f2_.set_video_rtp_header_extensions(local); |
| 1694 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1695 | std::unique_ptr<SessionDescription> answer = |
| 1696 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1697 | EXPECT_THAT( |
| 1698 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1699 | ElementsAreArray(offered)); |
| 1700 | EXPECT_THAT( |
| 1701 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1702 | ElementsAreArray(offered)); |
| 1703 | } |
| 1704 | |
| 1705 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1706 | TestNegotiateFrameDescriptorWhenExposedLocally) { |
| 1707 | MediaSessionOptions opts; |
| 1708 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1709 | |
| 1710 | const auto offered = MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00); |
| 1711 | f1_.set_audio_rtp_header_extensions(offered); |
| 1712 | f1_.set_video_rtp_header_extensions(offered); |
| 1713 | const auto local = MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00); |
| 1714 | f2_.set_audio_rtp_header_extensions(local); |
| 1715 | f2_.set_video_rtp_header_extensions(local); |
| 1716 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1717 | std::unique_ptr<SessionDescription> answer = |
| 1718 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1719 | EXPECT_THAT( |
| 1720 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1721 | ElementsAreArray(offered)); |
| 1722 | EXPECT_THAT( |
| 1723 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1724 | ElementsAreArray(offered)); |
| 1725 | } |
| 1726 | |
| 1727 | TEST_F(MediaSessionDescriptionFactoryTest, |
Danil Chapovalov | 5f999a7 | 2020-02-20 16:39:05 +0100 | [diff] [blame] | 1728 | NegotiateDependencyDescriptorWhenUnexposedLocally) { |
| 1729 | MediaSessionOptions opts; |
| 1730 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1731 | |
| 1732 | RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); |
| 1733 | RtpExtension local_tsn(RtpExtension::kTransportSequenceNumberUri, 5); |
| 1734 | f1_.set_video_rtp_header_extensions({offer_dd}); |
| 1735 | f2_.set_video_rtp_header_extensions({local_tsn}); |
| 1736 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1737 | std::unique_ptr<SessionDescription> answer = |
| 1738 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1739 | EXPECT_THAT( |
| 1740 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1741 | ElementsAre(offer_dd)); |
| 1742 | } |
| 1743 | |
| 1744 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1745 | NegotiateDependencyDescriptorWhenExposedLocally) { |
| 1746 | MediaSessionOptions opts; |
| 1747 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1748 | |
| 1749 | RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); |
| 1750 | RtpExtension local_dd(RtpExtension::kDependencyDescriptorUri, 5); |
| 1751 | f1_.set_video_rtp_header_extensions({offer_dd}); |
| 1752 | f2_.set_video_rtp_header_extensions({local_dd}); |
| 1753 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1754 | std::unique_ptr<SessionDescription> answer = |
| 1755 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1756 | EXPECT_THAT( |
| 1757 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1758 | ElementsAre(offer_dd)); |
| 1759 | } |
| 1760 | |
| 1761 | TEST_F(MediaSessionDescriptionFactoryTest, |
Minyue Li | 430e4a0 | 2020-03-10 10:59:37 +0100 | [diff] [blame] | 1762 | NegotiateAbsoluteCaptureTimeWhenUnexposedLocally) { |
| 1763 | MediaSessionOptions opts; |
| 1764 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1765 | |
| 1766 | const cricket::RtpHeaderExtensions offered_extensions = { |
| 1767 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 7)}; |
| 1768 | const cricket::RtpHeaderExtensions local_extensions = { |
| 1769 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, 5)}; |
| 1770 | f1_.set_video_rtp_header_extensions(offered_extensions); |
| 1771 | f1_.set_audio_rtp_header_extensions(offered_extensions); |
| 1772 | f2_.set_video_rtp_header_extensions(local_extensions); |
| 1773 | f2_.set_audio_rtp_header_extensions(local_extensions); |
| 1774 | |
| 1775 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1776 | std::unique_ptr<SessionDescription> answer = |
| 1777 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1778 | EXPECT_THAT( |
| 1779 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1780 | ElementsAreArray(offered_extensions)); |
| 1781 | EXPECT_THAT( |
| 1782 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1783 | ElementsAreArray(offered_extensions)); |
| 1784 | } |
| 1785 | |
| 1786 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1787 | NegotiateAbsoluteCaptureTimeWhenExposedLocally) { |
| 1788 | MediaSessionOptions opts; |
| 1789 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1790 | |
| 1791 | const cricket::RtpHeaderExtensions offered_extensions = { |
| 1792 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 7)}; |
| 1793 | const cricket::RtpHeaderExtensions local_extensions = { |
| 1794 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; |
| 1795 | f1_.set_video_rtp_header_extensions(offered_extensions); |
| 1796 | f1_.set_audio_rtp_header_extensions(offered_extensions); |
| 1797 | f2_.set_video_rtp_header_extensions(local_extensions); |
| 1798 | f2_.set_audio_rtp_header_extensions(local_extensions); |
| 1799 | |
| 1800 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1801 | std::unique_ptr<SessionDescription> answer = |
| 1802 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1803 | EXPECT_THAT( |
| 1804 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1805 | ElementsAreArray(offered_extensions)); |
| 1806 | EXPECT_THAT( |
| 1807 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1808 | ElementsAreArray(offered_extensions)); |
| 1809 | } |
| 1810 | |
| 1811 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1812 | DoNotNegotiateAbsoluteCaptureTimeWhenNotOffered) { |
| 1813 | MediaSessionOptions opts; |
| 1814 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1815 | |
| 1816 | const cricket::RtpHeaderExtensions offered_extensions = { |
| 1817 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, 7)}; |
| 1818 | const cricket::RtpHeaderExtensions local_extensions = { |
| 1819 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; |
| 1820 | f1_.set_video_rtp_header_extensions(offered_extensions); |
| 1821 | f1_.set_audio_rtp_header_extensions(offered_extensions); |
| 1822 | f2_.set_video_rtp_header_extensions(local_extensions); |
| 1823 | f2_.set_audio_rtp_header_extensions(local_extensions); |
| 1824 | |
| 1825 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1826 | std::unique_ptr<SessionDescription> answer = |
| 1827 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1828 | EXPECT_THAT( |
| 1829 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1830 | IsEmpty()); |
| 1831 | EXPECT_THAT( |
| 1832 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1833 | IsEmpty()); |
| 1834 | } |
| 1835 | |
| 1836 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1837 | TestOfferAnswerWithEncryptedRtpExtensionsBoth) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1838 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1839 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1840 | |
| 1841 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1842 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1843 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1844 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1845 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1846 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1847 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1848 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1849 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1850 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1851 | std::unique_ptr<SessionDescription> answer = |
| 1852 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1853 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1854 | EXPECT_EQ( |
| 1855 | MAKE_VECTOR(kAudioRtpExtensionEncrypted1), |
| 1856 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1857 | EXPECT_EQ( |
| 1858 | MAKE_VECTOR(kVideoRtpExtensionEncrypted1), |
| 1859 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1860 | EXPECT_EQ( |
| 1861 | MAKE_VECTOR(kAudioRtpExtensionEncryptedAnswer), |
| 1862 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1863 | EXPECT_EQ( |
| 1864 | MAKE_VECTOR(kVideoRtpExtensionEncryptedAnswer), |
| 1865 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1869 | TestOfferAnswerWithEncryptedRtpExtensionsOffer) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1870 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1871 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1872 | |
| 1873 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1874 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1875 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1876 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1877 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1878 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1879 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1880 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1881 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1882 | std::unique_ptr<SessionDescription> answer = |
| 1883 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1884 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1885 | EXPECT_EQ( |
| 1886 | MAKE_VECTOR(kAudioRtpExtensionEncrypted1), |
| 1887 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1888 | EXPECT_EQ( |
| 1889 | MAKE_VECTOR(kVideoRtpExtensionEncrypted1), |
| 1890 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1891 | EXPECT_EQ( |
| 1892 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1893 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1894 | EXPECT_EQ( |
| 1895 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1896 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1900 | TestOfferAnswerWithEncryptedRtpExtensionsAnswer) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1901 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1902 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1903 | |
| 1904 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1905 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1906 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1907 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1908 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1909 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1910 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1911 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1912 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1913 | std::unique_ptr<SessionDescription> answer = |
| 1914 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1915 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1916 | EXPECT_EQ( |
| 1917 | MAKE_VECTOR(kAudioRtpExtension1), |
| 1918 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1919 | EXPECT_EQ( |
| 1920 | MAKE_VECTOR(kVideoRtpExtension1), |
| 1921 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1922 | EXPECT_EQ( |
| 1923 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1924 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1925 | EXPECT_EQ( |
| 1926 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1927 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1930 | // Create an audio, video, data answer without legacy StreamParams. |
| 1931 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1932 | TestCreateAnswerWithoutLegacyStreams) { |
| 1933 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1934 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1935 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1936 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1937 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1938 | std::unique_ptr<SessionDescription> answer = |
| 1939 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1940 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1941 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1942 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 1943 | ASSERT_TRUE(ac != NULL); |
| 1944 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1945 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1946 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1947 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1948 | |
| 1949 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
| 1950 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1951 | EXPECT_FALSE(dcd->has_ssrcs()); // No StreamParams. |
| 1952 | } |
| 1953 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1954 | // Create a typical video answer, and ensure it matches what we expect. |
| 1955 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { |
| 1956 | MediaSessionOptions offer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1957 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &offer_opts); |
| 1958 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, |
| 1959 | &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1960 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1961 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1962 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
| 1963 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, |
| 1964 | &answer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1965 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1966 | std::unique_ptr<SessionDescription> offer; |
| 1967 | std::unique_ptr<SessionDescription> answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1968 | |
| 1969 | offer_opts.rtcp_mux_enabled = true; |
| 1970 | answer_opts.rtcp_mux_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1971 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 1972 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1973 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1974 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1975 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1976 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1977 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1978 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1979 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1980 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1981 | EXPECT_TRUE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1982 | EXPECT_TRUE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1983 | EXPECT_TRUE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1984 | EXPECT_TRUE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1985 | |
| 1986 | offer_opts.rtcp_mux_enabled = true; |
| 1987 | answer_opts.rtcp_mux_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1988 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 1989 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1990 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1991 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1992 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1993 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1994 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1995 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1996 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1997 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1998 | EXPECT_TRUE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1999 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2000 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2001 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2002 | |
| 2003 | offer_opts.rtcp_mux_enabled = false; |
| 2004 | answer_opts.rtcp_mux_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2005 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 2006 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2007 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 2008 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2009 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2010 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 2011 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2012 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2013 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2014 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2015 | EXPECT_FALSE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2016 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2017 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2018 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2019 | |
| 2020 | offer_opts.rtcp_mux_enabled = false; |
| 2021 | answer_opts.rtcp_mux_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2022 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 2023 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2024 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 2025 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2026 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2027 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 2028 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2029 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2030 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2031 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2032 | EXPECT_FALSE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2033 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2034 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2035 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | // Create an audio-only answer to a video offer. |
| 2039 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerToVideo) { |
| 2040 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2041 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2042 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2043 | &opts); |
| 2044 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2045 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2046 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2047 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2048 | ASSERT_TRUE(offer.get() != NULL); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2049 | |
| 2050 | opts.media_description_options[1].stopped = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2051 | std::unique_ptr<SessionDescription> answer = |
| 2052 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2053 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2054 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 2055 | ASSERT_TRUE(ac != NULL); |
| 2056 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2057 | ASSERT_TRUE(vc->media_description() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2058 | EXPECT_TRUE(vc->rejected); |
| 2059 | } |
| 2060 | |
| 2061 | // Create an audio-only answer to an offer with data. |
| 2062 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateNoDataAnswerToDataOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2063 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2064 | opts.data_channel_type = cricket::DCT_RTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2065 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2066 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2067 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2068 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2069 | ASSERT_TRUE(offer.get() != NULL); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2070 | |
| 2071 | opts.media_description_options[1].stopped = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2072 | std::unique_ptr<SessionDescription> answer = |
| 2073 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2074 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2075 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 2076 | ASSERT_TRUE(ac != NULL); |
| 2077 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2078 | ASSERT_TRUE(dc->media_description() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2079 | EXPECT_TRUE(dc->rejected); |
| 2080 | } |
| 2081 | |
| 2082 | // Create an answer that rejects the contents which are rejected in the offer. |
| 2083 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2084 | CreateAnswerToOfferWithRejectedMedia) { |
| 2085 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2086 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 2087 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2088 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2089 | ASSERT_TRUE(offer.get() != NULL); |
| 2090 | ContentInfo* ac = offer->GetContentByName("audio"); |
| 2091 | ContentInfo* vc = offer->GetContentByName("video"); |
| 2092 | ContentInfo* dc = offer->GetContentByName("data"); |
| 2093 | ASSERT_TRUE(ac != NULL); |
| 2094 | ASSERT_TRUE(vc != NULL); |
| 2095 | ASSERT_TRUE(dc != NULL); |
| 2096 | ac->rejected = true; |
| 2097 | vc->rejected = true; |
| 2098 | dc->rejected = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2099 | std::unique_ptr<SessionDescription> answer = |
| 2100 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2101 | ac = answer->GetContentByName("audio"); |
| 2102 | vc = answer->GetContentByName("video"); |
| 2103 | dc = answer->GetContentByName("data"); |
| 2104 | ASSERT_TRUE(ac != NULL); |
| 2105 | ASSERT_TRUE(vc != NULL); |
| 2106 | ASSERT_TRUE(dc != NULL); |
| 2107 | EXPECT_TRUE(ac->rejected); |
| 2108 | EXPECT_TRUE(vc->rejected); |
| 2109 | EXPECT_TRUE(dc->rejected); |
| 2110 | } |
| 2111 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2112 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2113 | CreateAnswerSupportsMixedOneAndTwoByteHeaderExtensions) { |
| 2114 | MediaSessionOptions opts; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2115 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2116 | // Offer without request of mixed one- and two-byte header extensions. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2117 | offer->set_extmap_allow_mixed(false); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2118 | ASSERT_TRUE(offer.get() != NULL); |
| 2119 | std::unique_ptr<SessionDescription> answer_no_support( |
| 2120 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2121 | EXPECT_FALSE(answer_no_support->extmap_allow_mixed()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2122 | |
| 2123 | // Offer with request of mixed one- and two-byte header extensions. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2124 | offer->set_extmap_allow_mixed(true); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2125 | ASSERT_TRUE(offer.get() != NULL); |
| 2126 | std::unique_ptr<SessionDescription> answer_support( |
| 2127 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2128 | EXPECT_TRUE(answer_support->extmap_allow_mixed()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2132 | CreateAnswerSupportsMixedOneAndTwoByteHeaderExtensionsOnMediaLevel) { |
| 2133 | MediaSessionOptions opts; |
| 2134 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2135 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2136 | MediaContentDescription* video_offer = |
| 2137 | offer->GetContentDescriptionByName("video"); |
| 2138 | ASSERT_TRUE(video_offer); |
| 2139 | MediaContentDescription* audio_offer = |
| 2140 | offer->GetContentDescriptionByName("audio"); |
| 2141 | ASSERT_TRUE(audio_offer); |
| 2142 | |
| 2143 | // Explicit disable of mixed one-two byte header support in offer. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2144 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 2145 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2146 | |
| 2147 | ASSERT_TRUE(offer.get() != NULL); |
| 2148 | std::unique_ptr<SessionDescription> answer_no_support( |
| 2149 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 2150 | MediaContentDescription* video_answer = |
| 2151 | answer_no_support->GetContentDescriptionByName("video"); |
| 2152 | MediaContentDescription* audio_answer = |
| 2153 | answer_no_support->GetContentDescriptionByName("audio"); |
| 2154 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2155 | video_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2156 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2157 | audio_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2158 | |
| 2159 | // Enable mixed one-two byte header support in offer. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2160 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
| 2161 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2162 | ASSERT_TRUE(offer.get() != NULL); |
| 2163 | std::unique_ptr<SessionDescription> answer_support( |
| 2164 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 2165 | video_answer = answer_support->GetContentDescriptionByName("video"); |
| 2166 | audio_answer = answer_support->GetContentDescriptionByName("audio"); |
| 2167 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2168 | video_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2169 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2170 | audio_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2171 | } |
| 2172 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2173 | // Create an audio and video offer with: |
| 2174 | // - one video track |
| 2175 | // - two audio tracks |
| 2176 | // - two data tracks |
| 2177 | // and ensure it matches what we expect. Also updates the initial offer by |
| 2178 | // adding a new video track and replaces one of the audio tracks. |
| 2179 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { |
| 2180 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2181 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2182 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2183 | {kMediaStream1}, 1, &opts); |
| 2184 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2185 | {kMediaStream1}, 1, &opts); |
| 2186 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2187 | {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2188 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2189 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2190 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack1, |
| 2191 | {kMediaStream1}, 1, &opts); |
| 2192 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack2, |
| 2193 | {kMediaStream1}, 1, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2194 | |
| 2195 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2196 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2197 | |
| 2198 | ASSERT_TRUE(offer.get() != NULL); |
| 2199 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 2200 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 2201 | const ContentInfo* dc = offer->GetContentByName("data"); |
| 2202 | ASSERT_TRUE(ac != NULL); |
| 2203 | ASSERT_TRUE(vc != NULL); |
| 2204 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2205 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 2206 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2207 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2208 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 2209 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2210 | |
| 2211 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2212 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2213 | EXPECT_EQ(audio_streams[0].cname, audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2214 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2215 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2216 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2217 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2218 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2219 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2220 | |
| 2221 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2222 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2223 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2224 | |
| 2225 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2226 | EXPECT_EQ(f1_.video_sendrecv_codecs(), vcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2227 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2228 | |
| 2229 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2230 | ASSERT_EQ(1U, video_streams.size()); |
| 2231 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2232 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2233 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2234 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2235 | |
| 2236 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2237 | EXPECT_EQ(f1_.rtp_data_codecs(), dcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2238 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2239 | |
| 2240 | const StreamParamsVec& data_streams = dcd->streams(); |
| 2241 | ASSERT_EQ(2U, data_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2242 | EXPECT_EQ(data_streams[0].cname, data_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2243 | EXPECT_EQ(kDataTrack1, data_streams[0].id); |
| 2244 | ASSERT_EQ(1U, data_streams[0].ssrcs.size()); |
| 2245 | EXPECT_NE(0U, data_streams[0].ssrcs[0]); |
| 2246 | EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 2247 | ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 2248 | EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 2249 | |
| 2250 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2251 | dcd->bandwidth()); // default bandwidth (auto) |
| 2252 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2253 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2254 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2255 | // Update the offer. Add a new video track that is not synched to the |
| 2256 | // other tracks and replace audio track 2 with audio track 3. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2257 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2258 | {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2259 | DetachSenderFromMediaSection("audio", kAudioTrack2, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2260 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack3, |
| 2261 | {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2262 | DetachSenderFromMediaSection("data", kDataTrack2, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2263 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack3, |
| 2264 | {kMediaStream1}, 1, &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2265 | std::unique_ptr<SessionDescription> updated_offer( |
| 2266 | f1_.CreateOffer(opts, offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2267 | |
| 2268 | ASSERT_TRUE(updated_offer.get() != NULL); |
| 2269 | ac = updated_offer->GetContentByName("audio"); |
| 2270 | vc = updated_offer->GetContentByName("video"); |
| 2271 | dc = updated_offer->GetContentByName("data"); |
| 2272 | ASSERT_TRUE(ac != NULL); |
| 2273 | ASSERT_TRUE(vc != NULL); |
| 2274 | ASSERT_TRUE(dc != NULL); |
| 2275 | const AudioContentDescription* updated_acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2276 | ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2277 | const VideoContentDescription* updated_vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2278 | vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2279 | const RtpDataContentDescription* updated_dcd = |
| 2280 | dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2281 | |
| 2282 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2283 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2284 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2285 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
| 2286 | EXPECT_EQ(dcd->type(), updated_dcd->type()); |
| 2287 | EXPECT_EQ(dcd->codecs(), updated_dcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2288 | ASSERT_CRYPTO(updated_acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2289 | EXPECT_TRUE(CompareCryptoParams(acd->cryptos(), updated_acd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2290 | ASSERT_CRYPTO(updated_vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2291 | EXPECT_TRUE(CompareCryptoParams(vcd->cryptos(), updated_vcd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2292 | ASSERT_CRYPTO(updated_dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2293 | EXPECT_TRUE(CompareCryptoParams(dcd->cryptos(), updated_dcd->cryptos())); |
| 2294 | |
| 2295 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2296 | ASSERT_EQ(2U, updated_audio_streams.size()); |
| 2297 | EXPECT_EQ(audio_streams[0], updated_audio_streams[0]); |
| 2298 | EXPECT_EQ(kAudioTrack3, updated_audio_streams[1].id); // New audio track. |
| 2299 | ASSERT_EQ(1U, updated_audio_streams[1].ssrcs.size()); |
| 2300 | EXPECT_NE(0U, updated_audio_streams[1].ssrcs[0]); |
| 2301 | EXPECT_EQ(updated_audio_streams[0].cname, updated_audio_streams[1].cname); |
| 2302 | |
| 2303 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2304 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2305 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2306 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2307 | // All the media streams in one PeerConnection share one RTCP CNAME. |
| 2308 | 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] | 2309 | |
| 2310 | const StreamParamsVec& updated_data_streams = updated_dcd->streams(); |
| 2311 | ASSERT_EQ(2U, updated_data_streams.size()); |
| 2312 | EXPECT_EQ(data_streams[0], updated_data_streams[0]); |
| 2313 | EXPECT_EQ(kDataTrack3, updated_data_streams[1].id); // New data track. |
| 2314 | ASSERT_EQ(1U, updated_data_streams[1].ssrcs.size()); |
| 2315 | EXPECT_NE(0U, updated_data_streams[1].ssrcs[0]); |
| 2316 | EXPECT_EQ(updated_data_streams[0].cname, updated_data_streams[1].cname); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2317 | // The stream correctly got the CNAME from the MediaSessionOptions. |
| 2318 | // The Expected RTCP CNAME is the default one as we are using the default |
| 2319 | // MediaSessionOptions. |
| 2320 | EXPECT_EQ(updated_data_streams[0].cname, cricket::kDefaultRtcpCname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2323 | // Create an offer with simulcast video stream. |
| 2324 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { |
| 2325 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2326 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2327 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2328 | &opts); |
| 2329 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2330 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2331 | &opts); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2332 | const int num_sim_layers = 3; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2333 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2334 | {kMediaStream1}, num_sim_layers, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2335 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2336 | |
| 2337 | ASSERT_TRUE(offer.get() != NULL); |
| 2338 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 2339 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2340 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2341 | |
| 2342 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2343 | ASSERT_EQ(1U, video_streams.size()); |
| 2344 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2345 | const SsrcGroup* sim_ssrc_group = |
| 2346 | video_streams[0].get_ssrc_group(cricket::kSimSsrcGroupSemantics); |
| 2347 | ASSERT_TRUE(sim_ssrc_group != NULL); |
| 2348 | EXPECT_EQ(static_cast<size_t>(num_sim_layers), sim_ssrc_group->ssrcs.size()); |
| 2349 | } |
| 2350 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2351 | MATCHER(RidDescriptionEquals, "Verifies that two RidDescriptions are equal.") { |
| 2352 | const RidDescription& rid1 = ::testing::get<0>(arg); |
| 2353 | const RidDescription& rid2 = ::testing::get<1>(arg); |
| 2354 | return rid1.rid == rid2.rid && rid1.direction == rid2.direction; |
| 2355 | } |
| 2356 | |
| 2357 | static void CheckSimulcastInSessionDescription( |
| 2358 | const SessionDescription* description, |
| 2359 | const std::string& content_name, |
| 2360 | const std::vector<RidDescription>& send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2361 | const SimulcastLayerList& send_layers) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2362 | ASSERT_NE(description, nullptr); |
| 2363 | const ContentInfo* content = description->GetContentByName(content_name); |
| 2364 | ASSERT_NE(content, nullptr); |
| 2365 | const MediaContentDescription* cd = content->media_description(); |
| 2366 | ASSERT_NE(cd, nullptr); |
| 2367 | const StreamParamsVec& streams = cd->streams(); |
| 2368 | ASSERT_THAT(streams, SizeIs(1)); |
| 2369 | const StreamParams& stream = streams[0]; |
| 2370 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2371 | EXPECT_TRUE(stream.has_rids()); |
| 2372 | const std::vector<RidDescription> rids = stream.rids(); |
| 2373 | |
| 2374 | EXPECT_THAT(rids, Pointwise(RidDescriptionEquals(), send_rids)); |
| 2375 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2376 | EXPECT_TRUE(cd->HasSimulcast()); |
| 2377 | const SimulcastDescription& simulcast = cd->simulcast_description(); |
| 2378 | EXPECT_THAT(simulcast.send_layers(), SizeIs(send_layers.size())); |
| 2379 | EXPECT_THAT(simulcast.send_layers(), Pointwise(Eq(), send_layers)); |
| 2380 | |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2381 | ASSERT_THAT(simulcast.receive_layers().GetAllLayers(), SizeIs(0)); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | // Create an offer with spec-compliant simulcast video stream. |
| 2385 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastOffer) { |
| 2386 | MediaSessionOptions opts; |
| 2387 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2388 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2389 | &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2390 | std::vector<RidDescription> send_rids; |
| 2391 | send_rids.push_back(RidDescription("f", RidDirection::kSend)); |
| 2392 | send_rids.push_back(RidDescription("h", RidDirection::kSend)); |
| 2393 | send_rids.push_back(RidDescription("q", RidDirection::kSend)); |
| 2394 | SimulcastLayerList simulcast_layers; |
| 2395 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[0].rid, false)); |
| 2396 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[1].rid, true)); |
| 2397 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[2].rid, false)); |
| 2398 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2399 | {kMediaStream1}, send_rids, |
| 2400 | simulcast_layers, 0, &opts); |
| 2401 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2402 | |
| 2403 | CheckSimulcastInSessionDescription(offer.get(), "video", send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2404 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | // Create an offer that signals RIDs (not SSRCs) without Simulcast. |
| 2408 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2409 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferWithRidsNoSimulcast) { |
| 2410 | MediaSessionOptions opts; |
| 2411 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2412 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2413 | &opts); |
| 2414 | RidDescription rid("f", RidDirection::kSend); |
| 2415 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2416 | {kMediaStream1}, {rid}, |
| 2417 | SimulcastLayerList(), 0, &opts); |
| 2418 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2419 | |
| 2420 | ASSERT_NE(offer.get(), nullptr); |
| 2421 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2422 | ASSERT_NE(content, nullptr); |
| 2423 | const MediaContentDescription* cd = content->media_description(); |
| 2424 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2425 | const StreamParamsVec& streams = cd->streams(); |
| 2426 | ASSERT_THAT(streams, SizeIs(1)); |
| 2427 | const StreamParams& stream = streams[0]; |
| 2428 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2429 | EXPECT_FALSE(stream.has_rids()); |
| 2430 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2431 | } |
| 2432 | |
| 2433 | // Create an answer with spec-compliant simulcast video stream. |
| 2434 | // In this scenario, the SFU is the caller requesting that we send Simulcast. |
| 2435 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastAnswer) { |
| 2436 | MediaSessionOptions offer_opts; |
| 2437 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2438 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2439 | &offer_opts); |
| 2440 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2441 | {kMediaStream1}, 1, &offer_opts); |
| 2442 | std::unique_ptr<SessionDescription> offer = |
| 2443 | f1_.CreateOffer(offer_opts, nullptr); |
| 2444 | |
| 2445 | MediaSessionOptions answer_opts; |
| 2446 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2447 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2448 | &answer_opts); |
| 2449 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2450 | std::vector<RidDescription> rid_descriptions{ |
| 2451 | RidDescription("f", RidDirection::kSend), |
| 2452 | RidDescription("h", RidDirection::kSend), |
| 2453 | RidDescription("q", RidDirection::kSend), |
| 2454 | }; |
| 2455 | SimulcastLayerList simulcast_layers; |
| 2456 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[0].rid, false)); |
| 2457 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[1].rid, true)); |
| 2458 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[2].rid, false)); |
| 2459 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2460 | {kMediaStream1}, rid_descriptions, |
| 2461 | simulcast_layers, 0, &answer_opts); |
| 2462 | std::unique_ptr<SessionDescription> answer = |
| 2463 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
| 2464 | |
| 2465 | CheckSimulcastInSessionDescription(answer.get(), "video", rid_descriptions, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2466 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | // Create an answer that signals RIDs (not SSRCs) without Simulcast. |
| 2470 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2471 | // Note that RID Direction is not the same as the transceiver direction. |
| 2472 | TEST_F(MediaSessionDescriptionFactoryTest, TestAnswerWithRidsNoSimulcast) { |
| 2473 | MediaSessionOptions offer_opts; |
| 2474 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2475 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2476 | &offer_opts); |
| 2477 | RidDescription rid_offer("f", RidDirection::kSend); |
| 2478 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2479 | {kMediaStream1}, {rid_offer}, |
| 2480 | SimulcastLayerList(), 0, &offer_opts); |
| 2481 | std::unique_ptr<SessionDescription> offer = |
| 2482 | f1_.CreateOffer(offer_opts, nullptr); |
| 2483 | |
| 2484 | MediaSessionOptions answer_opts; |
| 2485 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2486 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2487 | &answer_opts); |
| 2488 | |
| 2489 | RidDescription rid_answer("f", RidDirection::kReceive); |
| 2490 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2491 | {kMediaStream1}, {rid_answer}, |
| 2492 | SimulcastLayerList(), 0, &answer_opts); |
| 2493 | std::unique_ptr<SessionDescription> answer = |
| 2494 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
| 2495 | |
| 2496 | ASSERT_NE(answer.get(), nullptr); |
| 2497 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2498 | ASSERT_NE(content, nullptr); |
| 2499 | const MediaContentDescription* cd = content->media_description(); |
| 2500 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2501 | const StreamParamsVec& streams = cd->streams(); |
| 2502 | ASSERT_THAT(streams, SizeIs(1)); |
| 2503 | const StreamParams& stream = streams[0]; |
| 2504 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2505 | EXPECT_FALSE(stream.has_rids()); |
| 2506 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2507 | } |
| 2508 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2509 | // Create an audio and video answer to a standard video offer with: |
| 2510 | // - one video track |
| 2511 | // - two audio tracks |
| 2512 | // - two data tracks |
| 2513 | // and ensure it matches what we expect. Also updates the initial answer by |
| 2514 | // adding a new video track and removes one of the audio tracks. |
| 2515 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { |
| 2516 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2517 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2518 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2519 | &offer_opts); |
| 2520 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2521 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2522 | &offer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2523 | offer_opts.data_channel_type = cricket::DCT_RTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2524 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2525 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2526 | &offer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2527 | f1_.set_secure(SEC_ENABLED); |
| 2528 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2529 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(offer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2530 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2531 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2532 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2533 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2534 | &answer_opts); |
| 2535 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2536 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2537 | &answer_opts); |
| 2538 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2539 | {kMediaStream1}, 1, &answer_opts); |
| 2540 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2541 | {kMediaStream1}, 1, &answer_opts); |
| 2542 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2543 | {kMediaStream1}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2544 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2545 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2546 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2547 | &answer_opts); |
| 2548 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack1, |
| 2549 | {kMediaStream1}, 1, &answer_opts); |
| 2550 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack2, |
| 2551 | {kMediaStream1}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2552 | answer_opts.data_channel_type = cricket::DCT_RTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2553 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2554 | std::unique_ptr<SessionDescription> answer = |
| 2555 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2556 | |
| 2557 | ASSERT_TRUE(answer.get() != NULL); |
| 2558 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2559 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 2560 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 2561 | ASSERT_TRUE(ac != NULL); |
| 2562 | ASSERT_TRUE(vc != NULL); |
| 2563 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2564 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 2565 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2566 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2567 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
| 2568 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
| 2569 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2570 | |
| 2571 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2572 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2573 | |
| 2574 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2575 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2576 | EXPECT_TRUE(audio_streams[0].cname == audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2577 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2578 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2579 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2580 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2581 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2582 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2583 | |
| 2584 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2585 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
| 2586 | |
| 2587 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2588 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2589 | |
| 2590 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2591 | ASSERT_EQ(1U, video_streams.size()); |
| 2592 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2593 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2594 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2595 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2596 | |
| 2597 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2598 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2599 | |
| 2600 | const StreamParamsVec& data_streams = dcd->streams(); |
| 2601 | ASSERT_EQ(2U, data_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2602 | EXPECT_TRUE(data_streams[0].cname == data_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2603 | EXPECT_EQ(kDataTrack1, data_streams[0].id); |
| 2604 | ASSERT_EQ(1U, data_streams[0].ssrcs.size()); |
| 2605 | EXPECT_NE(0U, data_streams[0].ssrcs[0]); |
| 2606 | EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 2607 | ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 2608 | EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 2609 | |
| 2610 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2611 | dcd->bandwidth()); // default bandwidth (auto) |
| 2612 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2613 | |
| 2614 | // 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] | 2615 | // other tracks and remove 1 audio track. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2616 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2617 | {kMediaStream2}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2618 | DetachSenderFromMediaSection("audio", kAudioTrack2, &answer_opts); |
| 2619 | DetachSenderFromMediaSection("data", kDataTrack2, &answer_opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2620 | std::unique_ptr<SessionDescription> updated_answer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2621 | f2_.CreateAnswer(offer.get(), answer_opts, answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2622 | |
| 2623 | ASSERT_TRUE(updated_answer.get() != NULL); |
| 2624 | ac = updated_answer->GetContentByName("audio"); |
| 2625 | vc = updated_answer->GetContentByName("video"); |
| 2626 | dc = updated_answer->GetContentByName("data"); |
| 2627 | ASSERT_TRUE(ac != NULL); |
| 2628 | ASSERT_TRUE(vc != NULL); |
| 2629 | ASSERT_TRUE(dc != NULL); |
| 2630 | const AudioContentDescription* updated_acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2631 | ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2632 | const VideoContentDescription* updated_vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2633 | vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2634 | const RtpDataContentDescription* updated_dcd = |
| 2635 | dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2636 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2637 | ASSERT_CRYPTO(updated_acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2638 | EXPECT_TRUE(CompareCryptoParams(acd->cryptos(), updated_acd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2639 | ASSERT_CRYPTO(updated_vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2640 | EXPECT_TRUE(CompareCryptoParams(vcd->cryptos(), updated_vcd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2641 | ASSERT_CRYPTO(updated_dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2642 | EXPECT_TRUE(CompareCryptoParams(dcd->cryptos(), updated_dcd->cryptos())); |
| 2643 | |
| 2644 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2645 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2646 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2647 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
| 2648 | EXPECT_EQ(dcd->type(), updated_dcd->type()); |
| 2649 | EXPECT_EQ(dcd->codecs(), updated_dcd->codecs()); |
| 2650 | |
| 2651 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2652 | ASSERT_EQ(1U, updated_audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2653 | EXPECT_TRUE(audio_streams[0] == updated_audio_streams[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2654 | |
| 2655 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2656 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2657 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2658 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2659 | // All media streams in one PeerConnection share one CNAME. |
| 2660 | 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] | 2661 | |
| 2662 | const StreamParamsVec& updated_data_streams = updated_dcd->streams(); |
| 2663 | ASSERT_EQ(1U, updated_data_streams.size()); |
| 2664 | EXPECT_TRUE(data_streams[0] == updated_data_streams[0]); |
| 2665 | } |
| 2666 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2667 | // Create an updated offer after creating an answer to the original offer and |
| 2668 | // verify that the codecs that were part of the original answer are not changed |
| 2669 | // in the updated offer. |
| 2670 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2671 | RespondentCreatesOfferAfterCreatingAnswer) { |
| 2672 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2673 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2674 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2675 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 2676 | std::unique_ptr<SessionDescription> answer = |
| 2677 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2678 | |
| 2679 | const AudioContentDescription* acd = |
| 2680 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2681 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2682 | |
| 2683 | const VideoContentDescription* vcd = |
| 2684 | GetFirstVideoContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2685 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2686 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2687 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2688 | f2_.CreateOffer(opts, answer.get())); |
| 2689 | |
| 2690 | // The expected audio codecs are the common audio codecs from the first |
| 2691 | // offer/answer exchange plus the audio codecs only |f2_| offer, sorted in |
| 2692 | // preference order. |
wu@webrtc.org | ff1b1bf | 2014-06-20 20:57:42 +0000 | [diff] [blame] | 2693 | // TODO(wu): |updated_offer| should not include the codec |
| 2694 | // (i.e. |kAudioCodecs2[0]|) the other side doesn't support. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2695 | const AudioCodec kUpdatedAudioCodecOffer[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 2696 | kAudioCodecsAnswer[0], |
| 2697 | kAudioCodecsAnswer[1], |
| 2698 | kAudioCodecs2[0], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2699 | }; |
| 2700 | |
| 2701 | // The expected video codecs are the common video codecs from the first |
| 2702 | // offer/answer exchange plus the video codecs only |f2_| offer, sorted in |
| 2703 | // preference order. |
| 2704 | const VideoCodec kUpdatedVideoCodecOffer[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 2705 | kVideoCodecsAnswer[0], |
| 2706 | kVideoCodecs2[1], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2707 | }; |
| 2708 | |
| 2709 | const AudioContentDescription* updated_acd = |
| 2710 | GetFirstAudioContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2711 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kUpdatedAudioCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2712 | |
| 2713 | const VideoContentDescription* updated_vcd = |
| 2714 | GetFirstVideoContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2715 | EXPECT_THAT(updated_vcd->codecs(), ElementsAreArray(kUpdatedVideoCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2718 | // Test that a reoffer does not reuse audio codecs from a previous media section |
| 2719 | // that is being recycled. |
| 2720 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2721 | ReOfferDoesNotReUseRecycledAudioCodecs) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2722 | f1_.set_video_codecs({}, {}); |
| 2723 | f2_.set_video_codecs({}, {}); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2724 | |
| 2725 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2726 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2727 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2728 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2729 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2730 | std::unique_ptr<SessionDescription> answer = |
| 2731 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2732 | |
| 2733 | // Recycle the media section by changing its mid. |
| 2734 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2735 | std::unique_ptr<SessionDescription> reoffer = |
| 2736 | f2_.CreateOffer(opts, answer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2737 | |
| 2738 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2739 | // section was not recycled the payload types would match the initial offerer. |
| 2740 | const AudioContentDescription* acd = |
| 2741 | GetFirstAudioContentDescription(reoffer.get()); |
| 2742 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecs2)); |
| 2743 | } |
| 2744 | |
| 2745 | // Test that a reoffer does not reuse video codecs from a previous media section |
| 2746 | // that is being recycled. |
| 2747 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2748 | ReOfferDoesNotReUseRecycledVideoCodecs) { |
| 2749 | f1_.set_audio_codecs({}, {}); |
| 2750 | f2_.set_audio_codecs({}, {}); |
| 2751 | |
| 2752 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2753 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2754 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2755 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2756 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2757 | auto answer = f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2758 | |
| 2759 | // Recycle the media section by changing its mid. |
| 2760 | opts.media_description_options[0].mid = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2761 | std::unique_ptr<SessionDescription> reoffer = |
| 2762 | f2_.CreateOffer(opts, answer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2763 | |
| 2764 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2765 | // section was not recycled the payload types would match the initial offerer. |
| 2766 | const VideoContentDescription* vcd = |
| 2767 | GetFirstVideoContentDescription(reoffer.get()); |
| 2768 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecs2)); |
| 2769 | } |
| 2770 | |
| 2771 | // Test that a reanswer does not reuse audio codecs from a previous media |
| 2772 | // section that is being recycled. |
| 2773 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2774 | ReAnswerDoesNotReUseRecycledAudioCodecs) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2775 | f1_.set_video_codecs({}, {}); |
| 2776 | f2_.set_video_codecs({}, {}); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2777 | |
| 2778 | // Perform initial offer/answer in reverse (|f2_| as offerer) so that the |
| 2779 | // second offer/answer is forward (|f1_| as offerer). |
| 2780 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2781 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2782 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2783 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2784 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, nullptr); |
| 2785 | std::unique_ptr<SessionDescription> answer = |
| 2786 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2787 | |
| 2788 | // Recycle the media section by changing its mid. |
| 2789 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2790 | std::unique_ptr<SessionDescription> reoffer = |
| 2791 | f1_.CreateOffer(opts, answer.get()); |
| 2792 | std::unique_ptr<SessionDescription> reanswer = |
| 2793 | f2_.CreateAnswer(reoffer.get(), opts, offer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2794 | |
| 2795 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2796 | // section was not recycled the payload types would match the initial offerer. |
| 2797 | const AudioContentDescription* acd = |
| 2798 | GetFirstAudioContentDescription(reanswer.get()); |
| 2799 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
| 2800 | } |
| 2801 | |
| 2802 | // Test that a reanswer does not reuse video codecs from a previous media |
| 2803 | // section that is being recycled. |
| 2804 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2805 | ReAnswerDoesNotReUseRecycledVideoCodecs) { |
| 2806 | f1_.set_audio_codecs({}, {}); |
| 2807 | f2_.set_audio_codecs({}, {}); |
| 2808 | |
| 2809 | // Perform initial offer/answer in reverse (|f2_| as offerer) so that the |
| 2810 | // second offer/answer is forward (|f1_| as offerer). |
| 2811 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2812 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2813 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2814 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2815 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, nullptr); |
| 2816 | std::unique_ptr<SessionDescription> answer = |
| 2817 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2818 | |
| 2819 | // Recycle the media section by changing its mid. |
| 2820 | opts.media_description_options[0].mid = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2821 | std::unique_ptr<SessionDescription> reoffer = |
| 2822 | f1_.CreateOffer(opts, answer.get()); |
| 2823 | std::unique_ptr<SessionDescription> reanswer = |
| 2824 | f2_.CreateAnswer(reoffer.get(), opts, offer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2825 | |
| 2826 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2827 | // section was not recycled the payload types would match the initial offerer. |
| 2828 | const VideoContentDescription* vcd = |
| 2829 | GetFirstVideoContentDescription(reanswer.get()); |
| 2830 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
| 2831 | } |
| 2832 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2833 | // Create an updated offer after creating an answer to the original offer and |
| 2834 | // verify that the codecs that were part of the original answer are not changed |
| 2835 | // in the updated offer. In this test Rtx is enabled. |
| 2836 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2837 | RespondentCreatesOfferAfterCreatingAnswerWithRtx) { |
| 2838 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2839 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2840 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2841 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2842 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2843 | // 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] | 2844 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2845 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2846 | |
| 2847 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2848 | // 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] | 2849 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2850 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2851 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2852 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2853 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2854 | std::unique_ptr<SessionDescription> answer = |
| 2855 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2856 | |
| 2857 | const VideoContentDescription* vcd = |
| 2858 | GetFirstVideoContentDescription(answer.get()); |
| 2859 | |
| 2860 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2861 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 2862 | &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2863 | |
| 2864 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2865 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 2866 | // Now, make sure we get same result (except for the order) if |f2_| creates |
| 2867 | // an updated offer even though the default payload types between |f1_| and |
| 2868 | // |f2_| are different. |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2869 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2870 | f2_.CreateOffer(opts, answer.get())); |
| 2871 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2872 | std::unique_ptr<SessionDescription> updated_answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2873 | f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); |
| 2874 | |
| 2875 | const VideoContentDescription* updated_vcd = |
| 2876 | GetFirstVideoContentDescription(updated_answer.get()); |
| 2877 | |
| 2878 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 2879 | } |
| 2880 | |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2881 | // Regression test for: |
| 2882 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8332 |
| 2883 | // Existing codecs should always appear before new codecs in re-offers. But |
| 2884 | // under a specific set of circumstances, the existing RTX codec was ending up |
| 2885 | // added to the end of the list. |
| 2886 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2887 | RespondentCreatesOfferAfterCreatingAnswerWithRemappedRtxPayloadType) { |
| 2888 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2889 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2890 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2891 | &opts); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2892 | // We specifically choose different preferred payload types for VP8 to |
| 2893 | // trigger the issue. |
| 2894 | cricket::VideoCodec vp8_offerer(100, "VP8"); |
| 2895 | cricket::VideoCodec vp8_offerer_rtx = |
| 2896 | VideoCodec::CreateRtxCodec(101, vp8_offerer.id); |
| 2897 | cricket::VideoCodec vp8_answerer(110, "VP8"); |
| 2898 | cricket::VideoCodec vp8_answerer_rtx = |
| 2899 | VideoCodec::CreateRtxCodec(111, vp8_answerer.id); |
| 2900 | cricket::VideoCodec vp9(120, "VP9"); |
| 2901 | cricket::VideoCodec vp9_rtx = VideoCodec::CreateRtxCodec(121, vp9.id); |
| 2902 | |
| 2903 | std::vector<VideoCodec> f1_codecs = {vp8_offerer, vp8_offerer_rtx}; |
| 2904 | // We also specifically cause the answerer to prefer VP9, such that if it |
| 2905 | // *doesn't* honor the existing preferred codec (VP8) we'll notice. |
| 2906 | std::vector<VideoCodec> f2_codecs = {vp9, vp9_rtx, vp8_answerer, |
| 2907 | vp8_answerer_rtx}; |
| 2908 | |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2909 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 2910 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2911 | std::vector<AudioCodec> audio_codecs; |
| 2912 | f1_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2913 | f2_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2914 | |
| 2915 | // Offer will be {VP8, RTX for VP8}. Answer will be the same. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2916 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2917 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2918 | std::unique_ptr<SessionDescription> answer = |
| 2919 | f2_.CreateAnswer(offer.get(), opts, NULL); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2920 | |
| 2921 | // Updated offer *should* be {VP8, RTX for VP8, VP9, RTX for VP9}. |
| 2922 | // But if the bug is triggered, RTX for VP8 ends up last. |
| 2923 | std::unique_ptr<SessionDescription> updated_offer( |
| 2924 | f2_.CreateOffer(opts, answer.get())); |
| 2925 | |
| 2926 | const VideoContentDescription* vcd = |
| 2927 | GetFirstVideoContentDescription(updated_offer.get()); |
| 2928 | std::vector<cricket::VideoCodec> codecs = vcd->codecs(); |
| 2929 | ASSERT_EQ(4u, codecs.size()); |
| 2930 | EXPECT_EQ(vp8_offerer, codecs[0]); |
| 2931 | EXPECT_EQ(vp8_offerer_rtx, codecs[1]); |
| 2932 | EXPECT_EQ(vp9, codecs[2]); |
| 2933 | EXPECT_EQ(vp9_rtx, codecs[3]); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2936 | // Create an updated offer that adds video after creating an audio only answer |
| 2937 | // to the original offer. This test verifies that if a video codec and the RTX |
| 2938 | // codec have the same default payload type as an audio codec that is already in |
| 2939 | // use, the added codecs payload types are changed. |
| 2940 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2941 | RespondentCreatesOfferWithVideoAndRtxAfterCreatingAudioAnswer) { |
| 2942 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2943 | // 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] | 2944 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2945 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2946 | |
| 2947 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2948 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2949 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2950 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2951 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2952 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 2953 | std::unique_ptr<SessionDescription> answer = |
| 2954 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2955 | |
| 2956 | const AudioContentDescription* acd = |
| 2957 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2958 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2959 | |
| 2960 | // Now - let |f2_| add video with RTX and let the payload type the RTX codec |
| 2961 | // reference be the same as an audio codec that was negotiated in the |
| 2962 | // first offer/answer exchange. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2963 | opts.media_description_options.clear(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2964 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2965 | |
| 2966 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2967 | int used_pl_type = acd->codecs()[0].id; |
| 2968 | 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] | 2969 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, used_pl_type), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2970 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2971 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2972 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2973 | f2_.CreateOffer(opts, answer.get())); |
| 2974 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2975 | std::unique_ptr<SessionDescription> updated_answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2976 | f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); |
| 2977 | |
| 2978 | const AudioContentDescription* updated_acd = |
| 2979 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2980 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2981 | |
| 2982 | const VideoContentDescription* updated_vcd = |
| 2983 | GetFirstVideoContentDescription(updated_answer.get()); |
| 2984 | |
| 2985 | ASSERT_EQ("H264", updated_vcd->codecs()[0].name); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2986 | ASSERT_EQ(cricket::kRtxCodecName, updated_vcd->codecs()[1].name); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2987 | int new_h264_pl_type = updated_vcd->codecs()[0].id; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2988 | EXPECT_NE(used_pl_type, new_h264_pl_type); |
| 2989 | VideoCodec rtx = updated_vcd->codecs()[1]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2990 | int pt_referenced_by_rtx = rtc::FromString<int>( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2991 | rtx.params[cricket::kCodecParamAssociatedPayloadType]); |
| 2992 | EXPECT_EQ(new_h264_pl_type, pt_referenced_by_rtx); |
| 2993 | } |
| 2994 | |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 2995 | // Create an updated offer with RTX after creating an answer to an offer |
| 2996 | // without RTX, and with different default payload types. |
| 2997 | // Verify that the added RTX codec references the correct payload type. |
| 2998 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2999 | RespondentCreatesOfferWithRtxAfterCreatingAnswerWithoutRtx) { |
| 3000 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3001 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3002 | |
| 3003 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3004 | // This creates rtx for H264 with the payload type |f2_| uses. |
| 3005 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3006 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3007 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3008 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3009 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3010 | std::unique_ptr<SessionDescription> answer = |
| 3011 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3012 | |
| 3013 | const VideoContentDescription* vcd = |
| 3014 | GetFirstVideoContentDescription(answer.get()); |
| 3015 | |
| 3016 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
| 3017 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3018 | |
| 3019 | // Now, ensure that the RTX codec is created correctly when |f2_| creates an |
| 3020 | // updated offer, even though the default payload types are different from |
| 3021 | // those of |f1_|. |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3022 | std::unique_ptr<SessionDescription> updated_offer( |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3023 | f2_.CreateOffer(opts, answer.get())); |
| 3024 | ASSERT_TRUE(updated_offer); |
| 3025 | |
| 3026 | const VideoContentDescription* updated_vcd = |
| 3027 | GetFirstVideoContentDescription(updated_offer.get()); |
| 3028 | |
| 3029 | // New offer should attempt to add H263, and RTX for H264. |
| 3030 | expected_codecs.push_back(kVideoCodecs2[1]); |
| 3031 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[1].id), |
| 3032 | &expected_codecs); |
| 3033 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 3034 | } |
| 3035 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3036 | // Test that RTX is ignored when there is no associated payload type parameter. |
| 3037 | TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { |
| 3038 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3039 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3040 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3041 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3042 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3043 | // This creates RTX without associated payload type parameter. |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3044 | AddRtxCodec(VideoCodec(126, cricket::kRtxCodecName), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3045 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3046 | |
| 3047 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3048 | // This creates RTX for H264 with the payload type |f2_| uses. |
| 3049 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3050 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3051 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3052 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3053 | ASSERT_TRUE(offer.get() != NULL); |
| 3054 | // kCodecParamAssociatedPayloadType will always be added to the offer when RTX |
| 3055 | // is selected. Manually remove kCodecParamAssociatedPayloadType so that it |
| 3056 | // is possible to test that that RTX is dropped when |
| 3057 | // kCodecParamAssociatedPayloadType is missing in the offer. |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3058 | MediaContentDescription* media_desc = |
| 3059 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3060 | ASSERT_TRUE(media_desc); |
| 3061 | VideoContentDescription* desc = media_desc->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3062 | std::vector<VideoCodec> codecs = desc->codecs(); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 3063 | for (VideoCodec& codec : codecs) { |
| 3064 | if (codec.name.find(cricket::kRtxCodecName) == 0) { |
| 3065 | codec.params.clear(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3066 | } |
| 3067 | } |
| 3068 | desc->set_codecs(codecs); |
| 3069 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3070 | std::unique_ptr<SessionDescription> answer = |
| 3071 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3072 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 3073 | EXPECT_THAT( |
| 3074 | GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), |
| 3075 | Not(Contains(cricket::kRtxCodecName))); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | // Test that RTX will be filtered out in the answer if its associated payload |
| 3079 | // type doesn't match the local value. |
| 3080 | TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { |
| 3081 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3082 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3083 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3084 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3085 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3086 | // This creates RTX for H264 in sender. |
| 3087 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3088 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3089 | |
| 3090 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3091 | // This creates RTX for H263 in receiver. |
| 3092 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[1].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3093 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3094 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3095 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3096 | ASSERT_TRUE(offer.get() != NULL); |
| 3097 | // Associated payload type doesn't match, therefore, RTX codec is removed in |
| 3098 | // the answer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3099 | std::unique_ptr<SessionDescription> answer = |
| 3100 | f2_.CreateAnswer(offer.get(), opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3101 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 3102 | EXPECT_THAT( |
| 3103 | GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), |
| 3104 | Not(Contains(cricket::kRtxCodecName))); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | // Test that when multiple RTX codecs are offered, only the matched RTX codec |
| 3108 | // is added in the answer, and the unsupported RTX codec is filtered out. |
| 3109 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3110 | FilterOutUnsupportedRtxWhenCreatingAnswer) { |
| 3111 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3112 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3113 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3114 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3115 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3116 | // This creates RTX for H264-SVC in sender. |
| 3117 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3118 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3119 | |
| 3120 | // This creates RTX for H264 in sender. |
| 3121 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3122 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3123 | |
| 3124 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3125 | // This creates RTX for H264 in receiver. |
| 3126 | AddRtxCodec(VideoCodec::CreateRtxCodec(124, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3127 | f2_.set_video_codecs(f2_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3128 | |
| 3129 | // H264-SVC codec is removed in the answer, therefore, associated RTX codec |
| 3130 | // for H264-SVC should also be removed. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3131 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3132 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3133 | std::unique_ptr<SessionDescription> answer = |
| 3134 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3135 | const VideoContentDescription* vcd = |
| 3136 | GetFirstVideoContentDescription(answer.get()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3137 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
| 3138 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 3139 | &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3140 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3141 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3142 | } |
| 3143 | |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3144 | // Test that after one RTX codec has been negotiated, a new offer can attempt |
| 3145 | // to add another. |
| 3146 | TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { |
| 3147 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3148 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3149 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3150 | &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3151 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3152 | // This creates RTX for H264 for the offerer. |
| 3153 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3154 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3155 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3156 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3157 | ASSERT_TRUE(offer); |
| 3158 | const VideoContentDescription* vcd = |
| 3159 | GetFirstVideoContentDescription(offer.get()); |
| 3160 | |
| 3161 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3162 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 3163 | &expected_codecs); |
| 3164 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3165 | |
| 3166 | // Now, attempt to add RTX for H264-SVC. |
| 3167 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3168 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3169 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3170 | std::unique_ptr<SessionDescription> updated_offer( |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3171 | f1_.CreateOffer(opts, offer.get())); |
| 3172 | ASSERT_TRUE(updated_offer); |
| 3173 | vcd = GetFirstVideoContentDescription(updated_offer.get()); |
| 3174 | |
| 3175 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), |
| 3176 | &expected_codecs); |
| 3177 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3178 | } |
| 3179 | |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3180 | // Test that when RTX is used in conjunction with simulcast, an RTX ssrc is |
| 3181 | // generated for each simulcast ssrc and correctly grouped. |
| 3182 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { |
| 3183 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3184 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3185 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3186 | &opts); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3187 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3188 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3189 | {"stream1label"}, 3, &opts); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3190 | |
| 3191 | // Use a single real codec, and then add RTX for it. |
| 3192 | std::vector<VideoCodec> f1_codecs; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3193 | f1_codecs.push_back(VideoCodec(97, "H264")); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3194 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, 97), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3195 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3196 | |
| 3197 | // Ensure that the offer has an RTX ssrc for each regular ssrc, and that there |
| 3198 | // is a FID ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3199 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3200 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3201 | MediaContentDescription* media_desc = |
| 3202 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3203 | ASSERT_TRUE(media_desc); |
| 3204 | VideoContentDescription* desc = media_desc->as_video(); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3205 | const StreamParamsVec& streams = desc->streams(); |
| 3206 | // Single stream. |
| 3207 | ASSERT_EQ(1u, streams.size()); |
| 3208 | // Stream should have 6 ssrcs: 3 for video, 3 for RTX. |
| 3209 | EXPECT_EQ(6u, streams[0].ssrcs.size()); |
| 3210 | // And should have a SIM group for the simulcast. |
| 3211 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3212 | // And a FID group for RTX. |
| 3213 | EXPECT_TRUE(streams[0].has_ssrc_group("FID")); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3214 | std::vector<uint32_t> primary_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3215 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3216 | EXPECT_EQ(3u, primary_ssrcs.size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3217 | std::vector<uint32_t> fid_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3218 | streams[0].GetFidSsrcs(primary_ssrcs, &fid_ssrcs); |
| 3219 | EXPECT_EQ(3u, fid_ssrcs.size()); |
| 3220 | } |
| 3221 | |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3222 | // Test that, when the FlexFEC codec is added, a FlexFEC ssrc is created |
| 3223 | // together with a FEC-FR grouping. |
| 3224 | TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { |
| 3225 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3226 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3227 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3228 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3229 | // Add single stream. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3230 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3231 | {"stream1label"}, 1, &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3232 | |
| 3233 | // Use a single real codec, and then add FlexFEC for it. |
| 3234 | std::vector<VideoCodec> f1_codecs; |
| 3235 | f1_codecs.push_back(VideoCodec(97, "H264")); |
| 3236 | f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3237 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3238 | |
| 3239 | // Ensure that the offer has a single FlexFEC ssrc and that |
| 3240 | // there is no FEC-FR ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3241 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3242 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3243 | MediaContentDescription* media_desc = |
| 3244 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3245 | ASSERT_TRUE(media_desc); |
| 3246 | VideoContentDescription* desc = media_desc->as_video(); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3247 | const StreamParamsVec& streams = desc->streams(); |
| 3248 | // Single stream. |
| 3249 | ASSERT_EQ(1u, streams.size()); |
| 3250 | // Stream should have 2 ssrcs: 1 for video, 1 for FlexFEC. |
| 3251 | EXPECT_EQ(2u, streams[0].ssrcs.size()); |
| 3252 | // And should have a FEC-FR group for FlexFEC. |
| 3253 | EXPECT_TRUE(streams[0].has_ssrc_group("FEC-FR")); |
| 3254 | std::vector<uint32_t> primary_ssrcs; |
| 3255 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3256 | ASSERT_EQ(1u, primary_ssrcs.size()); |
| 3257 | uint32_t flexfec_ssrc; |
| 3258 | EXPECT_TRUE(streams[0].GetFecFrSsrc(primary_ssrcs[0], &flexfec_ssrc)); |
| 3259 | EXPECT_NE(flexfec_ssrc, 0u); |
| 3260 | } |
| 3261 | |
| 3262 | // Test that FlexFEC is disabled for simulcast. |
| 3263 | // TODO(brandtr): Remove this test when we support simulcast, either through |
| 3264 | // multiple FlexfecSenders, or through multistream protection. |
| 3265 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { |
| 3266 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3267 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3268 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3269 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3270 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3271 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3272 | {"stream1label"}, 3, &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3273 | |
| 3274 | // Use a single real codec, and then add FlexFEC for it. |
| 3275 | std::vector<VideoCodec> f1_codecs; |
| 3276 | f1_codecs.push_back(VideoCodec(97, "H264")); |
| 3277 | f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3278 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3279 | |
| 3280 | // Ensure that the offer has no FlexFEC ssrcs for each regular ssrc, and that |
| 3281 | // there is no FEC-FR ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3282 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3283 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3284 | MediaContentDescription* media_desc = |
| 3285 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3286 | ASSERT_TRUE(media_desc); |
| 3287 | VideoContentDescription* desc = media_desc->as_video(); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3288 | const StreamParamsVec& streams = desc->streams(); |
| 3289 | // Single stream. |
| 3290 | ASSERT_EQ(1u, streams.size()); |
| 3291 | // Stream should have 3 ssrcs: 3 for video, 0 for FlexFEC. |
| 3292 | EXPECT_EQ(3u, streams[0].ssrcs.size()); |
| 3293 | // And should have a SIM group for the simulcast. |
| 3294 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3295 | // And not a FEC-FR group for FlexFEC. |
| 3296 | EXPECT_FALSE(streams[0].has_ssrc_group("FEC-FR")); |
| 3297 | std::vector<uint32_t> primary_ssrcs; |
| 3298 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3299 | EXPECT_EQ(3u, primary_ssrcs.size()); |
| 3300 | for (uint32_t primary_ssrc : primary_ssrcs) { |
| 3301 | uint32_t flexfec_ssrc; |
| 3302 | EXPECT_FALSE(streams[0].GetFecFrSsrc(primary_ssrc, &flexfec_ssrc)); |
| 3303 | } |
| 3304 | } |
| 3305 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3306 | // Create an updated offer after creating an answer to the original offer and |
| 3307 | // verify that the RTP header extensions that were part of the original answer |
| 3308 | // are not changed in the updated offer. |
| 3309 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3310 | RespondentCreatesOfferAfterCreatingAnswerWithRtpExtensions) { |
| 3311 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3312 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3313 | |
| 3314 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 3315 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 3316 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 3317 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 3318 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3319 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 3320 | std::unique_ptr<SessionDescription> answer = |
| 3321 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3322 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3323 | EXPECT_EQ( |
| 3324 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 3325 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 3326 | EXPECT_EQ( |
| 3327 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 3328 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3329 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3330 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3331 | f2_.CreateOffer(opts, answer.get())); |
| 3332 | |
| 3333 | // The expected RTP header extensions in the new offer are the resulting |
| 3334 | // extensions from the first offer/answer exchange plus the extensions only |
| 3335 | // |f2_| offer. |
| 3336 | // 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] | 3337 | // |f1_| for another extensions, it is changed to 13. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3338 | const RtpExtension kUpdatedAudioRtpExtensions[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 3339 | kAudioRtpExtensionAnswer[0], |
| 3340 | RtpExtension(kAudioRtpExtension2[1].uri, 13), |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3341 | kAudioRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3342 | }; |
| 3343 | |
| 3344 | // 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] | 3345 | // |f1_| for another extensions, is is changed to 12. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3346 | const RtpExtension kUpdatedVideoRtpExtensions[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 3347 | kVideoRtpExtensionAnswer[0], |
| 3348 | RtpExtension(kVideoRtpExtension2[1].uri, 12), |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3349 | kVideoRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3350 | }; |
| 3351 | |
| 3352 | const AudioContentDescription* updated_acd = |
| 3353 | GetFirstAudioContentDescription(updated_offer.get()); |
| 3354 | EXPECT_EQ(MAKE_VECTOR(kUpdatedAudioRtpExtensions), |
| 3355 | updated_acd->rtp_header_extensions()); |
| 3356 | |
| 3357 | const VideoContentDescription* updated_vcd = |
| 3358 | GetFirstVideoContentDescription(updated_offer.get()); |
| 3359 | EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoRtpExtensions), |
| 3360 | updated_vcd->rtp_header_extensions()); |
| 3361 | } |
| 3362 | |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3363 | // Verify that if the same RTP extension URI is used for audio and video, the |
| 3364 | // same ID is used. Also verify that the ID isn't changed when creating an |
| 3365 | // updated offer (this was previously a bug). |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3366 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3367 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3368 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3369 | |
| 3370 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension3)); |
| 3371 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension3)); |
| 3372 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3373 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3374 | |
| 3375 | // Since the audio extensions used ID 3 for "both_audio_and_video", so should |
| 3376 | // the video extensions. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3377 | const RtpExtension kExpectedVideoRtpExtension[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 3378 | kVideoRtpExtension3[0], |
| 3379 | kAudioRtpExtension3[1], |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3380 | }; |
| 3381 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3382 | EXPECT_EQ( |
| 3383 | MAKE_VECTOR(kAudioRtpExtension3), |
| 3384 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3385 | EXPECT_EQ( |
| 3386 | MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 3387 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3388 | |
| 3389 | // Nothing should change when creating a new offer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3390 | std::unique_ptr<SessionDescription> updated_offer( |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3391 | f1_.CreateOffer(opts, offer.get())); |
| 3392 | |
| 3393 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3394 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3395 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3396 | EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3397 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3398 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3401 | // Same as "RtpExtensionIdReused" above for encrypted RTP extensions. |
| 3402 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { |
| 3403 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3404 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3405 | |
| 3406 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 3407 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 3408 | |
| 3409 | f1_.set_audio_rtp_header_extensions( |
| 3410 | MAKE_VECTOR(kAudioRtpExtension3ForEncryption)); |
| 3411 | f1_.set_video_rtp_header_extensions( |
| 3412 | MAKE_VECTOR(kVideoRtpExtension3ForEncryption)); |
| 3413 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3414 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3415 | |
| 3416 | // The extensions that are shared between audio and video should use the same |
| 3417 | // id. |
| 3418 | const RtpExtension kExpectedVideoRtpExtension[] = { |
| 3419 | kVideoRtpExtension3ForEncryption[0], |
| 3420 | kAudioRtpExtension3ForEncryptionOffer[1], |
| 3421 | kAudioRtpExtension3ForEncryptionOffer[2], |
| 3422 | }; |
| 3423 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3424 | EXPECT_EQ( |
| 3425 | MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
| 3426 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3427 | EXPECT_EQ( |
| 3428 | MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 3429 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3430 | |
| 3431 | // Nothing should change when creating a new offer |
| 3432 | std::unique_ptr<SessionDescription> updated_offer( |
| 3433 | f1_.CreateOffer(opts, offer.get())); |
| 3434 | |
| 3435 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3436 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3437 | ->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3438 | EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3439 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3440 | ->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3443 | TEST(MediaSessionDescription, CopySessionDescription) { |
| 3444 | SessionDescription source; |
| 3445 | cricket::ContentGroup group(cricket::CN_AUDIO); |
| 3446 | source.AddGroup(group); |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 3447 | std::unique_ptr<AudioContentDescription> acd = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 3448 | std::make_unique<AudioContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3449 | acd->set_codecs(MAKE_VECTOR(kAudioCodecs1)); |
| 3450 | acd->AddLegacyStream(1); |
Harald Alvestrand | 0fb07f8 | 2020-02-27 20:21:37 +0100 | [diff] [blame] | 3451 | source.AddContent(cricket::CN_AUDIO, MediaProtocolType::kRtp, acd->Clone()); |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 3452 | std::unique_ptr<VideoContentDescription> vcd = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 3453 | std::make_unique<VideoContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3454 | vcd->set_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 3455 | vcd->AddLegacyStream(2); |
Harald Alvestrand | 0fb07f8 | 2020-02-27 20:21:37 +0100 | [diff] [blame] | 3456 | source.AddContent(cricket::CN_VIDEO, MediaProtocolType::kRtp, vcd->Clone()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3457 | |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 3458 | std::unique_ptr<SessionDescription> copy = source.Clone(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3459 | ASSERT_TRUE(copy.get() != NULL); |
| 3460 | EXPECT_TRUE(copy->HasGroup(cricket::CN_AUDIO)); |
| 3461 | const ContentInfo* ac = copy->GetContentByName("audio"); |
| 3462 | const ContentInfo* vc = copy->GetContentByName("video"); |
| 3463 | ASSERT_TRUE(ac != NULL); |
| 3464 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 3465 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3466 | const AudioContentDescription* acd_copy = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3467 | EXPECT_EQ(acd->codecs(), acd_copy->codecs()); |
| 3468 | EXPECT_EQ(1u, acd->first_ssrc()); |
| 3469 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 3470 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3471 | const VideoContentDescription* vcd_copy = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3472 | EXPECT_EQ(vcd->codecs(), vcd_copy->codecs()); |
| 3473 | EXPECT_EQ(2u, vcd->first_ssrc()); |
| 3474 | } |
| 3475 | |
| 3476 | // The below TestTransportInfoXXX tests create different offers/answers, and |
| 3477 | // ensure the TransportInfo in the SessionDescription matches what we expect. |
| 3478 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudio) { |
| 3479 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3480 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3481 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3482 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3483 | TestTransportInfo(true, options, false); |
| 3484 | } |
| 3485 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3486 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3487 | TestTransportInfoOfferIceRenomination) { |
| 3488 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3489 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3490 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3491 | &options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3492 | options.media_description_options[0] |
| 3493 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3494 | TestTransportInfo(true, options, false); |
| 3495 | } |
| 3496 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3497 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudioCurrent) { |
| 3498 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3499 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3500 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3501 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3502 | TestTransportInfo(true, options, true); |
| 3503 | } |
| 3504 | |
| 3505 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferMultimedia) { |
| 3506 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3507 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3508 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3509 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3510 | TestTransportInfo(true, options, false); |
| 3511 | } |
| 3512 | |
| 3513 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3514 | TestTransportInfoOfferMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3515 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3516 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3517 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3518 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3519 | TestTransportInfo(true, options, true); |
| 3520 | } |
| 3521 | |
| 3522 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferBundle) { |
| 3523 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3524 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3525 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3526 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3527 | options.bundle_enabled = true; |
| 3528 | TestTransportInfo(true, options, false); |
| 3529 | } |
| 3530 | |
| 3531 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3532 | TestTransportInfoOfferBundleCurrent) { |
| 3533 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3534 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3535 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3536 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3537 | options.bundle_enabled = true; |
| 3538 | TestTransportInfo(true, options, true); |
| 3539 | } |
| 3540 | |
| 3541 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerAudio) { |
| 3542 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3543 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3544 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3545 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3546 | TestTransportInfo(false, options, false); |
| 3547 | } |
| 3548 | |
| 3549 | TEST_F(MediaSessionDescriptionFactoryTest, |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3550 | TestTransportInfoAnswerIceRenomination) { |
| 3551 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3552 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3553 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3554 | &options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3555 | options.media_description_options[0] |
| 3556 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3557 | TestTransportInfo(false, options, false); |
| 3558 | } |
| 3559 | |
| 3560 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3561 | TestTransportInfoAnswerAudioCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3562 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3563 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3564 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3565 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3566 | TestTransportInfo(false, options, true); |
| 3567 | } |
| 3568 | |
| 3569 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerMultimedia) { |
| 3570 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3571 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3572 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3573 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3574 | TestTransportInfo(false, options, false); |
| 3575 | } |
| 3576 | |
| 3577 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3578 | TestTransportInfoAnswerMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3579 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3580 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3581 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3582 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3583 | TestTransportInfo(false, options, true); |
| 3584 | } |
| 3585 | |
| 3586 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerBundle) { |
| 3587 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3588 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3589 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3590 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3591 | options.bundle_enabled = true; |
| 3592 | TestTransportInfo(false, options, false); |
| 3593 | } |
| 3594 | |
| 3595 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3596 | TestTransportInfoAnswerBundleCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3597 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3598 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3599 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3600 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3601 | options.bundle_enabled = true; |
| 3602 | TestTransportInfo(false, options, true); |
| 3603 | } |
| 3604 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 3605 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3606 | TestTransportInfoOfferBundlesTransportOptions) { |
| 3607 | MediaSessionOptions options; |
| 3608 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3609 | |
| 3610 | cricket::OpaqueTransportParameters audio_params; |
| 3611 | audio_params.protocol = "audio-transport"; |
| 3612 | audio_params.parameters = "audio-params"; |
| 3613 | FindFirstMediaDescriptionByMid("audio", &options) |
| 3614 | ->transport_options.opaque_parameters = audio_params; |
| 3615 | |
| 3616 | cricket::OpaqueTransportParameters video_params; |
| 3617 | video_params.protocol = "video-transport"; |
| 3618 | video_params.parameters = "video-params"; |
| 3619 | FindFirstMediaDescriptionByMid("video", &options) |
| 3620 | ->transport_options.opaque_parameters = video_params; |
| 3621 | |
| 3622 | TestTransportInfo(/*offer=*/true, options, /*has_current_desc=*/false); |
| 3623 | } |
| 3624 | |
| 3625 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3626 | TestTransportInfoAnswerBundlesTransportOptions) { |
| 3627 | MediaSessionOptions options; |
| 3628 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3629 | |
| 3630 | cricket::OpaqueTransportParameters audio_params; |
| 3631 | audio_params.protocol = "audio-transport"; |
| 3632 | audio_params.parameters = "audio-params"; |
| 3633 | FindFirstMediaDescriptionByMid("audio", &options) |
| 3634 | ->transport_options.opaque_parameters = audio_params; |
| 3635 | |
| 3636 | cricket::OpaqueTransportParameters video_params; |
| 3637 | video_params.protocol = "video-transport"; |
| 3638 | video_params.parameters = "video-params"; |
| 3639 | FindFirstMediaDescriptionByMid("video", &options) |
| 3640 | ->transport_options.opaque_parameters = video_params; |
| 3641 | |
| 3642 | TestTransportInfo(/*offer=*/false, options, /*has_current_desc=*/false); |
| 3643 | } |
| 3644 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 3645 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolAddedToOffer) { |
| 3646 | MediaSessionOptions options; |
| 3647 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3648 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3649 | &options); |
| 3650 | |
| 3651 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3652 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3653 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3654 | |
| 3655 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3656 | |
| 3657 | EXPECT_EQ(offer->GetContentDescriptionByName("audio")->alt_protocol(), "foo"); |
| 3658 | EXPECT_EQ(offer->GetContentDescriptionByName("video")->alt_protocol(), "bar"); |
| 3659 | EXPECT_EQ(offer->GetContentDescriptionByName("data")->alt_protocol(), "baz"); |
| 3660 | } |
| 3661 | |
| 3662 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolAddedToAnswer) { |
| 3663 | MediaSessionOptions options; |
| 3664 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3665 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3666 | &options); |
| 3667 | |
| 3668 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3669 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3670 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3671 | |
| 3672 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3673 | std::unique_ptr<SessionDescription> answer = |
| 3674 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3675 | |
| 3676 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3677 | "foo"); |
| 3678 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3679 | "bar"); |
| 3680 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), "baz"); |
| 3681 | } |
| 3682 | |
| 3683 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolNotInOffer) { |
| 3684 | MediaSessionOptions options; |
| 3685 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3686 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3687 | &options); |
| 3688 | |
| 3689 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3690 | |
| 3691 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3692 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3693 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3694 | |
| 3695 | std::unique_ptr<SessionDescription> answer = |
| 3696 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3697 | |
| 3698 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3699 | absl::nullopt); |
| 3700 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3701 | absl::nullopt); |
| 3702 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), |
| 3703 | absl::nullopt); |
| 3704 | } |
| 3705 | |
| 3706 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolDifferentInOffer) { |
| 3707 | MediaSessionOptions options; |
| 3708 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3709 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3710 | &options); |
| 3711 | |
| 3712 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "not-foo"; |
| 3713 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "not-bar"; |
| 3714 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "not-baz"; |
| 3715 | |
| 3716 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3717 | |
| 3718 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3719 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3720 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3721 | |
| 3722 | std::unique_ptr<SessionDescription> answer = |
| 3723 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3724 | |
| 3725 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3726 | absl::nullopt); |
| 3727 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3728 | absl::nullopt); |
| 3729 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), |
| 3730 | absl::nullopt); |
| 3731 | } |
| 3732 | |
| 3733 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolNotInAnswer) { |
| 3734 | MediaSessionOptions options; |
| 3735 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3736 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3737 | &options); |
| 3738 | |
| 3739 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3740 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3741 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3742 | |
| 3743 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3744 | |
| 3745 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = |
| 3746 | absl::nullopt; |
| 3747 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = |
| 3748 | absl::nullopt; |
| 3749 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = |
| 3750 | absl::nullopt; |
| 3751 | |
| 3752 | std::unique_ptr<SessionDescription> answer = |
| 3753 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3754 | |
| 3755 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3756 | absl::nullopt); |
| 3757 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3758 | absl::nullopt); |
| 3759 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), |
| 3760 | absl::nullopt); |
| 3761 | } |
| 3762 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3763 | // Create an offer with bundle enabled and verify the crypto parameters are |
| 3764 | // the common set of the available cryptos. |
| 3765 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithOfferBundle) { |
| 3766 | TestCryptoWithBundle(true); |
| 3767 | } |
| 3768 | |
| 3769 | // Create an answer with bundle enabled and verify the crypto parameters are |
| 3770 | // the common set of the available cryptos. |
| 3771 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithAnswerBundle) { |
| 3772 | TestCryptoWithBundle(false); |
| 3773 | } |
| 3774 | |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3775 | // Verifies that creating answer fails if the offer has UDP/TLS/RTP/SAVPF but |
| 3776 | // DTLS is not enabled locally. |
| 3777 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3778 | TestOfferDtlsSavpfWithoutDtlsFailed) { |
| 3779 | f1_.set_secure(SEC_ENABLED); |
| 3780 | f2_.set_secure(SEC_ENABLED); |
| 3781 | tdf1_.set_secure(SEC_DISABLED); |
| 3782 | tdf2_.set_secure(SEC_DISABLED); |
| 3783 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3784 | std::unique_ptr<SessionDescription> offer = |
| 3785 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3786 | ASSERT_TRUE(offer.get() != NULL); |
| 3787 | ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 3788 | ASSERT_TRUE(offer_content != NULL); |
| 3789 | AudioContentDescription* offer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3790 | offer_content->media_description()->as_audio(); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3791 | offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 3792 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3793 | std::unique_ptr<SessionDescription> answer = |
| 3794 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3795 | ASSERT_TRUE(answer != NULL); |
| 3796 | ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 3797 | ASSERT_TRUE(answer_content != NULL); |
| 3798 | |
| 3799 | ASSERT_TRUE(answer_content->rejected); |
| 3800 | } |
| 3801 | |
| 3802 | // Offers UDP/TLS/RTP/SAVPF and verifies the answer can be created and contains |
| 3803 | // UDP/TLS/RTP/SAVPF. |
| 3804 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferDtlsSavpfCreateAnswer) { |
| 3805 | f1_.set_secure(SEC_ENABLED); |
| 3806 | f2_.set_secure(SEC_ENABLED); |
| 3807 | tdf1_.set_secure(SEC_ENABLED); |
| 3808 | tdf2_.set_secure(SEC_ENABLED); |
| 3809 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3810 | std::unique_ptr<SessionDescription> offer = |
| 3811 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3812 | ASSERT_TRUE(offer.get() != NULL); |
| 3813 | ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 3814 | ASSERT_TRUE(offer_content != NULL); |
| 3815 | AudioContentDescription* offer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3816 | offer_content->media_description()->as_audio(); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3817 | offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 3818 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3819 | std::unique_ptr<SessionDescription> answer = |
| 3820 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3821 | ASSERT_TRUE(answer != NULL); |
| 3822 | |
| 3823 | const ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 3824 | ASSERT_TRUE(answer_content != NULL); |
| 3825 | ASSERT_FALSE(answer_content->rejected); |
| 3826 | |
| 3827 | const AudioContentDescription* answer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3828 | answer_content->media_description()->as_audio(); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3829 | EXPECT_EQ(cricket::kMediaProtocolDtlsSavpf, answer_audio_desc->protocol()); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3830 | } |
| 3831 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3832 | // Test that we include both SDES and DTLS in the offer, but only include SDES |
| 3833 | // in the answer if DTLS isn't negotiated. |
| 3834 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoDtls) { |
| 3835 | f1_.set_secure(SEC_ENABLED); |
| 3836 | f2_.set_secure(SEC_ENABLED); |
| 3837 | tdf1_.set_secure(SEC_ENABLED); |
| 3838 | tdf2_.set_secure(SEC_DISABLED); |
| 3839 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3840 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3841 | std::unique_ptr<SessionDescription> offer, answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3842 | const cricket::MediaContentDescription* audio_media_desc; |
| 3843 | const cricket::MediaContentDescription* video_media_desc; |
| 3844 | const cricket::TransportDescription* audio_trans_desc; |
| 3845 | const cricket::TransportDescription* video_trans_desc; |
| 3846 | |
| 3847 | // Generate an offer with SDES and DTLS support. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3848 | offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3849 | ASSERT_TRUE(offer.get() != NULL); |
| 3850 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3851 | audio_media_desc = offer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3852 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3853 | video_media_desc = offer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3854 | ASSERT_TRUE(video_media_desc != NULL); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 3855 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3856 | EXPECT_EQ(1u, video_media_desc->cryptos().size()); |
| 3857 | |
| 3858 | audio_trans_desc = offer->GetTransportDescriptionByName("audio"); |
| 3859 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3860 | video_trans_desc = offer->GetTransportDescriptionByName("video"); |
| 3861 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3862 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3863 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
| 3864 | |
| 3865 | // Generate an answer with only SDES support, since tdf2 has crypto disabled. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3866 | answer = f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3867 | ASSERT_TRUE(answer.get() != NULL); |
| 3868 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3869 | audio_media_desc = answer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3870 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3871 | video_media_desc = answer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3872 | ASSERT_TRUE(video_media_desc != NULL); |
| 3873 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
| 3874 | EXPECT_EQ(1u, video_media_desc->cryptos().size()); |
| 3875 | |
| 3876 | audio_trans_desc = answer->GetTransportDescriptionByName("audio"); |
| 3877 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3878 | video_trans_desc = answer->GetTransportDescriptionByName("video"); |
| 3879 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3880 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() == NULL); |
| 3881 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() == NULL); |
| 3882 | |
| 3883 | // Enable DTLS; the answer should now only have DTLS support. |
| 3884 | tdf2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3885 | answer = f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3886 | ASSERT_TRUE(answer.get() != NULL); |
| 3887 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3888 | audio_media_desc = answer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3889 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3890 | video_media_desc = answer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3891 | ASSERT_TRUE(video_media_desc != NULL); |
| 3892 | EXPECT_TRUE(audio_media_desc->cryptos().empty()); |
| 3893 | EXPECT_TRUE(video_media_desc->cryptos().empty()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3894 | EXPECT_EQ(cricket::kMediaProtocolSavpf, audio_media_desc->protocol()); |
| 3895 | EXPECT_EQ(cricket::kMediaProtocolSavpf, video_media_desc->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3896 | |
| 3897 | audio_trans_desc = answer->GetTransportDescriptionByName("audio"); |
| 3898 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3899 | video_trans_desc = answer->GetTransportDescriptionByName("video"); |
| 3900 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3901 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3902 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3903 | |
| 3904 | // Try creating offer again. DTLS enabled now, crypto's should be empty |
| 3905 | // in new offer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3906 | offer = f1_.CreateOffer(options, offer.get()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3907 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3908 | audio_media_desc = offer->GetContentDescriptionByName("audio"); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3909 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3910 | video_media_desc = offer->GetContentDescriptionByName("video"); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3911 | ASSERT_TRUE(video_media_desc != NULL); |
| 3912 | EXPECT_TRUE(audio_media_desc->cryptos().empty()); |
| 3913 | EXPECT_TRUE(video_media_desc->cryptos().empty()); |
| 3914 | |
| 3915 | audio_trans_desc = offer->GetTransportDescriptionByName("audio"); |
| 3916 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3917 | video_trans_desc = offer->GetTransportDescriptionByName("video"); |
| 3918 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3919 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3920 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | // Test that an answer can't be created if cryptos are required but the offer is |
| 3924 | // unsecure. |
| 3925 | TEST_F(MediaSessionDescriptionFactoryTest, TestSecureAnswerToUnsecureOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3926 | MediaSessionOptions options = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3927 | f1_.set_secure(SEC_DISABLED); |
| 3928 | tdf1_.set_secure(SEC_DISABLED); |
| 3929 | f2_.set_secure(SEC_REQUIRED); |
| 3930 | tdf1_.set_secure(SEC_ENABLED); |
| 3931 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3932 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3933 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3934 | std::unique_ptr<SessionDescription> answer = |
| 3935 | f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3936 | EXPECT_TRUE(answer.get() == NULL); |
| 3937 | } |
| 3938 | |
| 3939 | // Test that we accept a DTLS offer without SDES and create an appropriate |
| 3940 | // answer. |
| 3941 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { |
| 3942 | f1_.set_secure(SEC_DISABLED); |
| 3943 | f2_.set_secure(SEC_ENABLED); |
| 3944 | tdf1_.set_secure(SEC_ENABLED); |
| 3945 | tdf2_.set_secure(SEC_ENABLED); |
| 3946 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3947 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3948 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3949 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3950 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3951 | // Generate an offer with DTLS but without SDES. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3952 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3953 | ASSERT_TRUE(offer.get() != NULL); |
| 3954 | |
| 3955 | const AudioContentDescription* audio_offer = |
| 3956 | GetFirstAudioContentDescription(offer.get()); |
| 3957 | ASSERT_TRUE(audio_offer->cryptos().empty()); |
| 3958 | const VideoContentDescription* video_offer = |
| 3959 | GetFirstVideoContentDescription(offer.get()); |
| 3960 | ASSERT_TRUE(video_offer->cryptos().empty()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 3961 | const RtpDataContentDescription* data_offer = |
| 3962 | GetFirstRtpDataContentDescription(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3963 | ASSERT_TRUE(data_offer->cryptos().empty()); |
| 3964 | |
| 3965 | const cricket::TransportDescription* audio_offer_trans_desc = |
| 3966 | offer->GetTransportDescriptionByName("audio"); |
| 3967 | ASSERT_TRUE(audio_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 3968 | const cricket::TransportDescription* video_offer_trans_desc = |
| 3969 | offer->GetTransportDescriptionByName("video"); |
| 3970 | ASSERT_TRUE(video_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 3971 | const cricket::TransportDescription* data_offer_trans_desc = |
| 3972 | offer->GetTransportDescriptionByName("data"); |
| 3973 | ASSERT_TRUE(data_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 3974 | |
| 3975 | // Generate an answer with DTLS. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3976 | std::unique_ptr<SessionDescription> answer = |
| 3977 | f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3978 | ASSERT_TRUE(answer.get() != NULL); |
| 3979 | |
| 3980 | const cricket::TransportDescription* audio_answer_trans_desc = |
| 3981 | answer->GetTransportDescriptionByName("audio"); |
| 3982 | EXPECT_TRUE(audio_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 3983 | const cricket::TransportDescription* video_answer_trans_desc = |
| 3984 | answer->GetTransportDescriptionByName("video"); |
| 3985 | EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 3986 | const cricket::TransportDescription* data_answer_trans_desc = |
| 3987 | answer->GetTransportDescriptionByName("data"); |
| 3988 | EXPECT_TRUE(data_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 3989 | } |
| 3990 | |
| 3991 | // Verifies if vad_enabled option is set to false, CN codecs are not present in |
| 3992 | // offer or answer. |
| 3993 | TEST_F(MediaSessionDescriptionFactoryTest, TestVADEnableOption) { |
| 3994 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3995 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3996 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3997 | ASSERT_TRUE(offer.get() != NULL); |
| 3998 | const ContentInfo* audio_content = offer->GetContentByName("audio"); |
| 3999 | EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); |
| 4000 | |
| 4001 | options.vad_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4002 | offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4003 | ASSERT_TRUE(offer.get() != NULL); |
| 4004 | audio_content = offer->GetContentByName("audio"); |
| 4005 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4006 | std::unique_ptr<SessionDescription> answer = |
| 4007 | f1_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4008 | ASSERT_TRUE(answer.get() != NULL); |
| 4009 | audio_content = answer->GetContentByName("audio"); |
| 4010 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
| 4011 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4012 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4013 | // Test that the generated MIDs match the existing offer. |
| 4014 | TEST_F(MediaSessionDescriptionFactoryTest, TestMIDsMatchesExistingOffer) { |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4015 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4016 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_modified", |
| 4017 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 4018 | &opts); |
| 4019 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_modified", |
| 4020 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 4021 | &opts); |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4022 | opts.data_channel_type = cricket::DCT_SCTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4023 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data_modified", |
| 4024 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4025 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4026 | // Create offer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4027 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 4028 | std::unique_ptr<SessionDescription> updated_offer( |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4029 | f1_.CreateOffer(opts, offer.get())); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4030 | |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4031 | const ContentInfo* audio_content = GetFirstAudioContent(updated_offer.get()); |
| 4032 | const ContentInfo* video_content = GetFirstVideoContent(updated_offer.get()); |
| 4033 | const ContentInfo* data_content = GetFirstDataContent(updated_offer.get()); |
| 4034 | ASSERT_TRUE(audio_content != nullptr); |
| 4035 | ASSERT_TRUE(video_content != nullptr); |
| 4036 | ASSERT_TRUE(data_content != nullptr); |
| 4037 | EXPECT_EQ("audio_modified", audio_content->name); |
| 4038 | EXPECT_EQ("video_modified", video_content->name); |
| 4039 | EXPECT_EQ("data_modified", data_content->name); |
| 4040 | } |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4041 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4042 | // The following tests verify that the unified plan SDP is supported. |
| 4043 | // Test that we can create an offer with multiple media sections of same media |
| 4044 | // type. |
| 4045 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4046 | CreateOfferWithMultipleAVMediaSections) { |
| 4047 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4048 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 4049 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4050 | &opts); |
| 4051 | AttachSenderToMediaDescriptionOptions( |
| 4052 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4053 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4054 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 4055 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4056 | &opts); |
| 4057 | AttachSenderToMediaDescriptionOptions( |
| 4058 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4059 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4060 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 4061 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4062 | &opts); |
| 4063 | AttachSenderToMediaDescriptionOptions( |
| 4064 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4065 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4066 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 4067 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4068 | &opts); |
| 4069 | AttachSenderToMediaDescriptionOptions( |
| 4070 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4071 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4072 | ASSERT_TRUE(offer); |
| 4073 | |
| 4074 | ASSERT_EQ(4u, offer->contents().size()); |
| 4075 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 4076 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4077 | offer->contents()[0].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4078 | ASSERT_EQ(1u, acd->streams().size()); |
| 4079 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4080 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4081 | |
| 4082 | EXPECT_FALSE(offer->contents()[1].rejected); |
| 4083 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4084 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4085 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4086 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4087 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4088 | |
| 4089 | EXPECT_FALSE(offer->contents()[2].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4090 | acd = offer->contents()[2].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4091 | ASSERT_EQ(1u, acd->streams().size()); |
| 4092 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4093 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4094 | |
| 4095 | EXPECT_FALSE(offer->contents()[3].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4096 | vcd = offer->contents()[3].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4097 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4098 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4099 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | // Test that we can create an answer with multiple media sections of same media |
| 4103 | // type. |
| 4104 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4105 | CreateAnswerWithMultipleAVMediaSections) { |
| 4106 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4107 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 4108 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4109 | &opts); |
| 4110 | AttachSenderToMediaDescriptionOptions( |
| 4111 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4112 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4113 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 4114 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4115 | &opts); |
| 4116 | AttachSenderToMediaDescriptionOptions( |
| 4117 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4118 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4119 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 4120 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4121 | &opts); |
| 4122 | AttachSenderToMediaDescriptionOptions( |
| 4123 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4124 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4125 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 4126 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4127 | &opts); |
| 4128 | AttachSenderToMediaDescriptionOptions( |
| 4129 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4130 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4131 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4132 | ASSERT_TRUE(offer); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4133 | std::unique_ptr<SessionDescription> answer = |
| 4134 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4135 | |
| 4136 | ASSERT_EQ(4u, answer->contents().size()); |
| 4137 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 4138 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4139 | answer->contents()[0].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4140 | ASSERT_EQ(1u, acd->streams().size()); |
| 4141 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4142 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4143 | |
| 4144 | EXPECT_FALSE(answer->contents()[1].rejected); |
| 4145 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4146 | answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4147 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4148 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4149 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4150 | |
| 4151 | EXPECT_FALSE(answer->contents()[2].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4152 | acd = answer->contents()[2].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4153 | ASSERT_EQ(1u, acd->streams().size()); |
| 4154 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4155 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4156 | |
| 4157 | EXPECT_FALSE(answer->contents()[3].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4158 | vcd = answer->contents()[3].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4159 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4160 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4161 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | // Test that the media section will be rejected in offer if the corresponding |
| 4165 | // MediaDescriptionOptions is stopped by the offerer. |
| 4166 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4167 | CreateOfferWithMediaSectionStoppedByOfferer) { |
| 4168 | // Create an offer with two audio sections and one of them is stopped. |
| 4169 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4170 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4171 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4172 | &offer_opts); |
| 4173 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4174 | RtpTransceiverDirection::kInactive, kStopped, |
| 4175 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4176 | std::unique_ptr<SessionDescription> offer = |
| 4177 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4178 | ASSERT_TRUE(offer); |
| 4179 | ASSERT_EQ(2u, offer->contents().size()); |
| 4180 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 4181 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 4182 | } |
| 4183 | |
| 4184 | // Test that the media section will be rejected in answer if the corresponding |
| 4185 | // MediaDescriptionOptions is stopped by the offerer. |
| 4186 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4187 | CreateAnswerWithMediaSectionStoppedByOfferer) { |
| 4188 | // Create an offer with two audio sections and one of them is stopped. |
| 4189 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4190 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4191 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4192 | &offer_opts); |
| 4193 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4194 | RtpTransceiverDirection::kInactive, kStopped, |
| 4195 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4196 | std::unique_ptr<SessionDescription> offer = |
| 4197 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4198 | ASSERT_TRUE(offer); |
| 4199 | ASSERT_EQ(2u, offer->contents().size()); |
| 4200 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 4201 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 4202 | |
| 4203 | // Create an answer based on the offer. |
| 4204 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4205 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4206 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4207 | &answer_opts); |
| 4208 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4209 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4210 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4211 | std::unique_ptr<SessionDescription> answer = |
| 4212 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4213 | ASSERT_EQ(2u, answer->contents().size()); |
| 4214 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 4215 | EXPECT_TRUE(answer->contents()[1].rejected); |
| 4216 | } |
| 4217 | |
| 4218 | // Test that the media section will be rejected in answer if the corresponding |
| 4219 | // MediaDescriptionOptions is stopped by the answerer. |
| 4220 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4221 | CreateAnswerWithMediaSectionRejectedByAnswerer) { |
| 4222 | // Create an offer with two audio sections. |
| 4223 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4224 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4225 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4226 | &offer_opts); |
| 4227 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4228 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4229 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4230 | std::unique_ptr<SessionDescription> offer = |
| 4231 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4232 | ASSERT_TRUE(offer); |
| 4233 | ASSERT_EQ(2u, offer->contents().size()); |
| 4234 | ASSERT_FALSE(offer->contents()[0].rejected); |
| 4235 | ASSERT_FALSE(offer->contents()[1].rejected); |
| 4236 | |
| 4237 | // The answerer rejects one of the audio sections. |
| 4238 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4239 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4240 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4241 | &answer_opts); |
| 4242 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4243 | RtpTransceiverDirection::kInactive, kStopped, |
| 4244 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4245 | std::unique_ptr<SessionDescription> answer = |
| 4246 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4247 | ASSERT_EQ(2u, answer->contents().size()); |
| 4248 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 4249 | EXPECT_TRUE(answer->contents()[1].rejected); |
Zhi Huang | 3518e7b | 2018-01-30 13:20:35 -0800 | [diff] [blame] | 4250 | |
| 4251 | // The TransportInfo of the rejected m= section is expected to be added in the |
| 4252 | // answer. |
| 4253 | EXPECT_EQ(offer->transport_infos().size(), answer->transport_infos().size()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | // Test the generated media sections has the same order of the |
| 4257 | // corresponding MediaDescriptionOptions. |
| 4258 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4259 | CreateOfferRespectsMediaDescriptionOptionsOrder) { |
| 4260 | MediaSessionOptions opts; |
| 4261 | // This tests put video section first because normally audio comes first by |
| 4262 | // default. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4263 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4264 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4265 | &opts); |
| 4266 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 4267 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4268 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4269 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4270 | |
| 4271 | ASSERT_TRUE(offer); |
| 4272 | ASSERT_EQ(2u, offer->contents().size()); |
| 4273 | EXPECT_EQ("video", offer->contents()[0].name); |
| 4274 | EXPECT_EQ("audio", offer->contents()[1].name); |
| 4275 | } |
| 4276 | |
| 4277 | // Test that different media sections using the same codec have same payload |
| 4278 | // type. |
| 4279 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4280 | PayloadTypesSharedByMediaSectionsOfSameType) { |
| 4281 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4282 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4283 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4284 | &opts); |
| 4285 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4286 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4287 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4288 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4289 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4290 | ASSERT_TRUE(offer); |
| 4291 | ASSERT_EQ(2u, offer->contents().size()); |
| 4292 | const VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4293 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4294 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4295 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4296 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 4297 | ASSERT_EQ(2u, vcd1->codecs().size()); |
| 4298 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 4299 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 4300 | EXPECT_EQ(vcd1->codecs()[1].name, vcd2->codecs()[1].name); |
| 4301 | EXPECT_EQ(vcd1->codecs()[1].id, vcd2->codecs()[1].id); |
| 4302 | |
| 4303 | // Create answer and negotiate the codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4304 | std::unique_ptr<SessionDescription> answer = |
| 4305 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4306 | ASSERT_TRUE(answer); |
| 4307 | ASSERT_EQ(2u, answer->contents().size()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4308 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4309 | vcd2 = answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4310 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 4311 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4312 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 4313 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 4314 | } |
| 4315 | |
| 4316 | // Test that the codec preference order per media section is respected in |
| 4317 | // subsequent offer. |
| 4318 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4319 | CreateOfferRespectsCodecPreferenceOrder) { |
| 4320 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4321 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4322 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4323 | &opts); |
| 4324 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4325 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4326 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4327 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4328 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4329 | ASSERT_TRUE(offer); |
| 4330 | ASSERT_EQ(2u, offer->contents().size()); |
| 4331 | VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4332 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4333 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4334 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4335 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4336 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4337 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4338 | |
| 4339 | // Change the codec preference of the first video section and create a |
| 4340 | // follow-up offer. |
| 4341 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4342 | vcd1->set_codecs(video_codecs_reverse); |
| 4343 | std::unique_ptr<SessionDescription> updated_offer( |
| 4344 | f1_.CreateOffer(opts, offer.get())); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4345 | vcd1 = updated_offer->contents()[0].media_description()->as_video(); |
| 4346 | vcd2 = updated_offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4347 | // The video codec preference order should be respected. |
| 4348 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4349 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4350 | } |
| 4351 | |
| 4352 | // Test that the codec preference order per media section is respected in |
| 4353 | // the answer. |
| 4354 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4355 | CreateAnswerRespectsCodecPreferenceOrder) { |
| 4356 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4357 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4358 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4359 | &opts); |
| 4360 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4361 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4362 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4363 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4364 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4365 | ASSERT_TRUE(offer); |
| 4366 | ASSERT_EQ(2u, offer->contents().size()); |
| 4367 | VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4368 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4369 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4370 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4371 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4372 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4373 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4374 | |
| 4375 | // Change the codec preference of the first video section and create an |
| 4376 | // answer. |
| 4377 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4378 | vcd1->set_codecs(video_codecs_reverse); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4379 | std::unique_ptr<SessionDescription> answer = |
| 4380 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4381 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4382 | vcd2 = answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4383 | // The video codec preference order should be respected. |
| 4384 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4385 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4386 | } |
| 4387 | |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4388 | // Test that when creating an answer, the codecs use local parameters instead of |
| 4389 | // the remote ones. |
| 4390 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerWithLocalCodecParams) { |
| 4391 | const std::string audio_param_name = "audio_param"; |
| 4392 | const std::string audio_value1 = "audio_v1"; |
| 4393 | const std::string audio_value2 = "audio_v2"; |
| 4394 | const std::string video_param_name = "video_param"; |
| 4395 | const std::string video_value1 = "video_v1"; |
| 4396 | const std::string video_value2 = "video_v2"; |
| 4397 | |
| 4398 | auto audio_codecs1 = MAKE_VECTOR(kAudioCodecs1); |
| 4399 | auto audio_codecs2 = MAKE_VECTOR(kAudioCodecs1); |
| 4400 | auto video_codecs1 = MAKE_VECTOR(kVideoCodecs1); |
| 4401 | auto video_codecs2 = MAKE_VECTOR(kVideoCodecs1); |
| 4402 | |
| 4403 | // Set the parameters for codecs. |
| 4404 | audio_codecs1[0].SetParam(audio_param_name, audio_value1); |
| 4405 | video_codecs1[0].SetParam(video_param_name, video_value1); |
| 4406 | audio_codecs2[0].SetParam(audio_param_name, audio_value2); |
| 4407 | video_codecs2[0].SetParam(video_param_name, video_value2); |
| 4408 | |
| 4409 | f1_.set_audio_codecs(audio_codecs1, audio_codecs1); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4410 | f1_.set_video_codecs(video_codecs1, video_codecs1); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4411 | f2_.set_audio_codecs(audio_codecs2, audio_codecs2); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4412 | f2_.set_video_codecs(video_codecs2, video_codecs2); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4413 | |
| 4414 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4415 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 4416 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4417 | &opts); |
| 4418 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4419 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4420 | &opts); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4421 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4422 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4423 | ASSERT_TRUE(offer); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4424 | auto offer_acd = offer->contents()[0].media_description()->as_audio(); |
| 4425 | auto offer_vcd = offer->contents()[1].media_description()->as_video(); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4426 | std::string value; |
| 4427 | EXPECT_TRUE(offer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4428 | EXPECT_EQ(audio_value1, value); |
| 4429 | EXPECT_TRUE(offer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4430 | EXPECT_EQ(video_value1, value); |
| 4431 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4432 | std::unique_ptr<SessionDescription> answer = |
| 4433 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4434 | ASSERT_TRUE(answer); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4435 | auto answer_acd = answer->contents()[0].media_description()->as_audio(); |
| 4436 | auto answer_vcd = answer->contents()[1].media_description()->as_video(); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4437 | // Use the parameters from the local codecs. |
| 4438 | EXPECT_TRUE(answer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4439 | EXPECT_EQ(audio_value2, value); |
| 4440 | EXPECT_TRUE(answer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4441 | EXPECT_EQ(video_value2, value); |
| 4442 | } |
| 4443 | |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4444 | // Test that matching packetization-mode is part of the criteria for matching |
| 4445 | // H264 codecs (in addition to profile-level-id). Previously, this was not the |
| 4446 | // case, so the first H264 codec with the same profile-level-id would match and |
| 4447 | // the payload type in the answer would be incorrect. |
| 4448 | // This is a regression test for bugs.webrtc.org/8808 |
| 4449 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4450 | H264MatchCriteriaIncludesPacketizationMode) { |
| 4451 | // Create two H264 codecs with the same profile level ID and different |
| 4452 | // packetization modes. |
| 4453 | VideoCodec h264_pm0(96, "H264"); |
| 4454 | h264_pm0.params[cricket::kH264FmtpProfileLevelId] = "42c01f"; |
| 4455 | h264_pm0.params[cricket::kH264FmtpPacketizationMode] = "0"; |
| 4456 | VideoCodec h264_pm1(97, "H264"); |
| 4457 | h264_pm1.params[cricket::kH264FmtpProfileLevelId] = "42c01f"; |
| 4458 | h264_pm1.params[cricket::kH264FmtpPacketizationMode] = "1"; |
| 4459 | |
| 4460 | // Offerer will send both codecs, answerer should choose the one with matching |
| 4461 | // packetization mode (and not the first one it sees). |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4462 | f1_.set_video_codecs({h264_pm0, h264_pm1}, {h264_pm0, h264_pm1}); |
| 4463 | f2_.set_video_codecs({h264_pm1}, {h264_pm1}); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4464 | |
| 4465 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4466 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4467 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4468 | &opts); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4469 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4470 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4471 | ASSERT_TRUE(offer); |
| 4472 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4473 | std::unique_ptr<SessionDescription> answer = |
| 4474 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4475 | ASSERT_TRUE(answer); |
| 4476 | |
| 4477 | // Answer should have one negotiated codec with packetization-mode=1 using the |
| 4478 | // offered payload type. |
| 4479 | ASSERT_EQ(1u, answer->contents().size()); |
| 4480 | auto answer_vcd = answer->contents()[0].media_description()->as_video(); |
| 4481 | ASSERT_EQ(1u, answer_vcd->codecs().size()); |
| 4482 | auto answer_codec = answer_vcd->codecs()[0]; |
| 4483 | EXPECT_EQ(h264_pm1.id, answer_codec.id); |
| 4484 | } |
| 4485 | |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4486 | class MediaProtocolTest : public ::testing::TestWithParam<const char*> { |
| 4487 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4488 | MediaProtocolTest() |
| 4489 | : f1_(&tdf1_, &ssrc_generator1), f2_(&tdf2_, &ssrc_generator2) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4490 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 4491 | MAKE_VECTOR(kAudioCodecs1)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4492 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1), |
| 4493 | MAKE_VECTOR(kVideoCodecs1)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 4494 | f1_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4495 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 4496 | MAKE_VECTOR(kAudioCodecs2)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4497 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2), |
| 4498 | MAKE_VECTOR(kVideoCodecs2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 4499 | f2_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4500 | f1_.set_secure(SEC_ENABLED); |
| 4501 | f2_.set_secure(SEC_ENABLED); |
| 4502 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 4503 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4504 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 4505 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4506 | tdf1_.set_secure(SEC_ENABLED); |
| 4507 | tdf2_.set_secure(SEC_ENABLED); |
| 4508 | } |
| 4509 | |
| 4510 | protected: |
| 4511 | MediaSessionDescriptionFactory f1_; |
| 4512 | MediaSessionDescriptionFactory f2_; |
| 4513 | TransportDescriptionFactory tdf1_; |
| 4514 | TransportDescriptionFactory tdf2_; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4515 | UniqueRandomIdGenerator ssrc_generator1; |
| 4516 | UniqueRandomIdGenerator ssrc_generator2; |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4517 | }; |
| 4518 | |
| 4519 | TEST_P(MediaProtocolTest, TestAudioVideoAcceptance) { |
| 4520 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4521 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4522 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4523 | ASSERT_TRUE(offer.get() != nullptr); |
| 4524 | // Set the protocol for all the contents. |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 4525 | for (auto& content : offer.get()->contents()) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4526 | content.media_description()->set_protocol(GetParam()); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4527 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4528 | std::unique_ptr<SessionDescription> answer = |
| 4529 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4530 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4531 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 4532 | ASSERT_TRUE(ac != nullptr); |
| 4533 | ASSERT_TRUE(vc != nullptr); |
| 4534 | EXPECT_FALSE(ac->rejected); // the offer is accepted |
| 4535 | EXPECT_FALSE(vc->rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4536 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 4537 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4538 | EXPECT_EQ(GetParam(), acd->protocol()); |
| 4539 | EXPECT_EQ(GetParam(), vcd->protocol()); |
| 4540 | } |
| 4541 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4542 | INSTANTIATE_TEST_SUITE_P(MediaProtocolPatternTest, |
| 4543 | MediaProtocolTest, |
| 4544 | ::testing::ValuesIn(kMediaProtocols)); |
| 4545 | INSTANTIATE_TEST_SUITE_P(MediaProtocolDtlsPatternTest, |
| 4546 | MediaProtocolTest, |
| 4547 | ::testing::ValuesIn(kMediaProtocolsDtls)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4548 | |
| 4549 | TEST_F(MediaSessionDescriptionFactoryTest, TestSetAudioCodecs) { |
| 4550 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4551 | UniqueRandomIdGenerator ssrc_generator; |
| 4552 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4553 | std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4554 | std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4555 | |
| 4556 | // The merged list of codecs should contain any send codecs that are also |
| 4557 | // nominally in the recieve codecs list. Payload types should be picked from |
| 4558 | // the send codecs and a number-of-channels of 0 and 1 should be equivalent |
| 4559 | // (set to 1). This equals what happens when the send codecs are used in an |
| 4560 | // offer and the receive codecs are used in the following answer. |
| 4561 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4562 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4563 | const std::vector<AudioCodec> no_codecs; |
| 4564 | |
| 4565 | RTC_CHECK_EQ(send_codecs[1].name, "iLBC") |
| 4566 | << "Please don't change shared test data!"; |
| 4567 | RTC_CHECK_EQ(recv_codecs[2].name, "iLBC") |
| 4568 | << "Please don't change shared test data!"; |
| 4569 | // Alter iLBC send codec to have zero channels, to test that that is handled |
| 4570 | // properly. |
| 4571 | send_codecs[1].channels = 0; |
| 4572 | |
| 4573 | // Alther iLBC receive codec to be lowercase, to test that case conversions |
| 4574 | // are handled properly. |
| 4575 | recv_codecs[2].name = "ilbc"; |
| 4576 | |
| 4577 | // Test proper merge |
| 4578 | sf.set_audio_codecs(send_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4579 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4580 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4581 | EXPECT_EQ(sendrecv_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4582 | |
| 4583 | // Test empty send codecs list |
| 4584 | sf.set_audio_codecs(no_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4585 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4586 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4587 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4588 | |
| 4589 | // Test empty recv codecs list |
| 4590 | sf.set_audio_codecs(send_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4591 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4592 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4593 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4594 | |
| 4595 | // Test all empty codec lists |
| 4596 | sf.set_audio_codecs(no_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4597 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4598 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4599 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | namespace { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4603 | // Compare the two vectors of codecs ignoring the payload type. |
| 4604 | template <class Codec> |
| 4605 | bool CodecsMatch(const std::vector<Codec>& codecs1, |
| 4606 | const std::vector<Codec>& codecs2) { |
| 4607 | if (codecs1.size() != codecs2.size()) { |
| 4608 | return false; |
| 4609 | } |
| 4610 | |
| 4611 | for (size_t i = 0; i < codecs1.size(); ++i) { |
| 4612 | if (!codecs1[i].Matches(codecs2[i])) { |
| 4613 | return false; |
| 4614 | } |
| 4615 | } |
| 4616 | return true; |
| 4617 | } |
| 4618 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4619 | void TestAudioCodecsOffer(RtpTransceiverDirection direction) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4620 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4621 | UniqueRandomIdGenerator ssrc_generator; |
| 4622 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4623 | const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4624 | const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4625 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4626 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4627 | sf.set_audio_codecs(send_codecs, recv_codecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4628 | |
| 4629 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4630 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 4631 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4632 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4633 | if (direction == RtpTransceiverDirection::kSendRecv || |
| 4634 | direction == RtpTransceiverDirection::kSendOnly) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4635 | AttachSenderToMediaDescriptionOptions( |
| 4636 | "audio", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4637 | } |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4638 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4639 | std::unique_ptr<SessionDescription> offer = sf.CreateOffer(opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4640 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4641 | ContentInfo* ac = offer->GetContentByName("audio"); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4642 | |
| 4643 | // 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] | 4644 | // that the codecs put in are right. This happens when we neither want to |
| 4645 | // send nor receive audio. The checks are still in place if at some point |
| 4646 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4647 | if (ac) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4648 | AudioContentDescription* acd = ac->media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4649 | // sendrecv and inactive should both present lists as if the channel was |
| 4650 | // to be used for sending and receiving. Inactive essentially means it |
| 4651 | // might eventually be used anything, but we don't know more at this |
| 4652 | // moment. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4653 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4654 | EXPECT_TRUE(CodecsMatch<AudioCodec>(send_codecs, acd->codecs())); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4655 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4656 | EXPECT_TRUE(CodecsMatch<AudioCodec>(recv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4657 | } else { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4658 | EXPECT_TRUE(CodecsMatch<AudioCodec>(sendrecv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4659 | } |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | static const AudioCodec kOfferAnswerCodecs[] = { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4664 | AudioCodec(0, "codec0", 16000, -1, 1), |
| 4665 | AudioCodec(1, "codec1", 8000, 13300, 1), |
| 4666 | AudioCodec(2, "codec2", 8000, 64000, 1), |
| 4667 | AudioCodec(3, "codec3", 8000, 64000, 1), |
| 4668 | AudioCodec(4, "codec4", 8000, 0, 2), |
| 4669 | AudioCodec(5, "codec5", 32000, 0, 1), |
| 4670 | AudioCodec(6, "codec6", 48000, 0, 1)}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4671 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4672 | /* The codecs groups below are chosen as per the matrix below. The objective |
| 4673 | * is to have different sets of codecs in the inputs, to get unique sets of |
| 4674 | * codecs after negotiation, depending on offer and answer communication |
| 4675 | * directions. One-way directions in the offer should either result in the |
| 4676 | * opposite direction in the answer, or an inactive answer. Regardless, the |
| 4677 | * choice of codecs should be as if the answer contained the opposite |
| 4678 | * direction. Inactive offers should be treated as sendrecv/sendrecv. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4679 | * |
| 4680 | * | Offer | Answer | Result |
| 4681 | * codec|send recv sr | send recv sr | s/r r/s sr/s sr/r sr/sr |
| 4682 | * 0 | x - - | - x - | x - - - - |
| 4683 | * 1 | x x x | - x - | x - - x - |
| 4684 | * 2 | - x - | x - - | - x - - - |
| 4685 | * 3 | x x x | x - - | - x x - - |
| 4686 | * 4 | - x - | x x x | - x - - - |
| 4687 | * 5 | x - - | x x x | x - - - - |
| 4688 | * 6 | x x x | x x x | x x x x x |
| 4689 | */ |
| 4690 | // Codecs used by offerer in the AudioCodecsAnswerTest |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4691 | static const int kOfferSendCodecs[] = {0, 1, 3, 5, 6}; |
| 4692 | static const int kOfferRecvCodecs[] = {1, 2, 3, 4, 6}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4693 | // Codecs used in the answerer in the AudioCodecsAnswerTest. The order is |
| 4694 | // jumbled to catch the answer not following the order in the offer. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4695 | static const int kAnswerSendCodecs[] = {6, 5, 2, 3, 4}; |
| 4696 | static const int kAnswerRecvCodecs[] = {6, 5, 4, 1, 0}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4697 | // The resulting sets of codecs in the answer in the AudioCodecsAnswerTest |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4698 | static const int kResultSend_RecvCodecs[] = {0, 1, 5, 6}; |
| 4699 | static const int kResultRecv_SendCodecs[] = {2, 3, 4, 6}; |
| 4700 | static const int kResultSendrecv_SendCodecs[] = {3, 6}; |
| 4701 | static const int kResultSendrecv_RecvCodecs[] = {1, 6}; |
| 4702 | static const int kResultSendrecv_SendrecvCodecs[] = {6}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4703 | |
| 4704 | template <typename T, int IDXS> |
| 4705 | std::vector<T> VectorFromIndices(const T* array, const int (&indices)[IDXS]) { |
| 4706 | std::vector<T> out; |
| 4707 | out.reserve(IDXS); |
| 4708 | for (int idx : indices) |
| 4709 | out.push_back(array[idx]); |
| 4710 | |
| 4711 | return out; |
| 4712 | } |
| 4713 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4714 | void TestAudioCodecsAnswer(RtpTransceiverDirection offer_direction, |
| 4715 | RtpTransceiverDirection answer_direction, |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4716 | bool add_legacy_stream) { |
| 4717 | TransportDescriptionFactory offer_tdf; |
| 4718 | TransportDescriptionFactory answer_tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4719 | UniqueRandomIdGenerator ssrc_generator1, ssrc_generator2; |
| 4720 | MediaSessionDescriptionFactory offer_factory(&offer_tdf, &ssrc_generator1); |
| 4721 | MediaSessionDescriptionFactory answer_factory(&answer_tdf, &ssrc_generator2); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4722 | offer_factory.set_audio_codecs( |
| 4723 | VectorFromIndices(kOfferAnswerCodecs, kOfferSendCodecs), |
| 4724 | VectorFromIndices(kOfferAnswerCodecs, kOfferRecvCodecs)); |
| 4725 | answer_factory.set_audio_codecs( |
| 4726 | VectorFromIndices(kOfferAnswerCodecs, kAnswerSendCodecs), |
| 4727 | VectorFromIndices(kOfferAnswerCodecs, kAnswerRecvCodecs)); |
| 4728 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4729 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4730 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", offer_direction, |
| 4731 | kActive, &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4732 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4733 | if (webrtc::RtpTransceiverDirectionHasSend(offer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4734 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4735 | kAudioTrack1, {kMediaStream1}, 1, |
| 4736 | &offer_opts); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4737 | } |
| 4738 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4739 | std::unique_ptr<SessionDescription> offer = |
| 4740 | offer_factory.CreateOffer(offer_opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4741 | ASSERT_TRUE(offer.get() != NULL); |
| 4742 | |
| 4743 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4744 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", answer_direction, |
| 4745 | kActive, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4746 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4747 | if (webrtc::RtpTransceiverDirectionHasSend(answer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4748 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4749 | kAudioTrack1, {kMediaStream1}, 1, |
| 4750 | &answer_opts); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4751 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4752 | std::unique_ptr<SessionDescription> answer = |
| 4753 | answer_factory.CreateAnswer(offer.get(), answer_opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4754 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4755 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4756 | // If the factory didn't add any audio content to the answer, we cannot |
| 4757 | // check that the codecs put in are right. This happens when we neither want |
| 4758 | // to send nor receive audio. The checks are still in place if at some point |
| 4759 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4760 | if (ac) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4761 | ASSERT_EQ(MEDIA_TYPE_AUDIO, ac->media_description()->type()); |
| 4762 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4763 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4764 | std::vector<AudioCodec> target_codecs; |
| 4765 | // For offers with sendrecv or inactive, we should never reply with more |
| 4766 | // codecs than offered, with these codec sets. |
| 4767 | switch (offer_direction) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4768 | case RtpTransceiverDirection::kInactive: |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4769 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4770 | kResultSendrecv_SendrecvCodecs); |
| 4771 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4772 | case RtpTransceiverDirection::kSendOnly: |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4773 | target_codecs = |
| 4774 | VectorFromIndices(kOfferAnswerCodecs, kResultSend_RecvCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4775 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4776 | case RtpTransceiverDirection::kRecvOnly: |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4777 | target_codecs = |
| 4778 | VectorFromIndices(kOfferAnswerCodecs, kResultRecv_SendCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4779 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4780 | case RtpTransceiverDirection::kSendRecv: |
| 4781 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4782 | target_codecs = |
| 4783 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_SendCodecs); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4784 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4785 | target_codecs = |
| 4786 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_RecvCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4787 | } else { |
| 4788 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4789 | kResultSendrecv_SendrecvCodecs); |
| 4790 | } |
| 4791 | break; |
Markus Handell | 45c104b | 2020-03-11 10:51:13 +0100 | [diff] [blame] | 4792 | default: |
| 4793 | RTC_NOTREACHED(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4794 | } |
| 4795 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4796 | auto format_codecs = [](const std::vector<AudioCodec>& codecs) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 4797 | rtc::StringBuilder os; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4798 | bool first = true; |
| 4799 | os << "{"; |
| 4800 | for (const auto& c : codecs) { |
| 4801 | os << (first ? " " : ", ") << c.id; |
| 4802 | first = false; |
| 4803 | } |
| 4804 | os << " }"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 4805 | return os.Release(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4806 | }; |
| 4807 | |
| 4808 | EXPECT_TRUE(acd->codecs() == target_codecs) |
| 4809 | << "Expected: " << format_codecs(target_codecs) |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4810 | << ", got: " << format_codecs(acd->codecs()) << "; Offered: " |
| 4811 | << webrtc::RtpTransceiverDirectionToString(offer_direction) |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4812 | << ", answerer wants: " |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4813 | << webrtc::RtpTransceiverDirectionToString(answer_direction) |
| 4814 | << "; got: " |
| 4815 | << webrtc::RtpTransceiverDirectionToString(acd->direction()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4816 | } else { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4817 | EXPECT_EQ(offer_direction, RtpTransceiverDirection::kInactive) |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4818 | << "Only inactive offers are allowed to not generate any audio " |
| 4819 | "content"; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4820 | } |
| 4821 | } |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 4822 | |
| 4823 | } // namespace |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4824 | |
| 4825 | class AudioCodecsOfferTest |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4826 | : public ::testing::TestWithParam<RtpTransceiverDirection> {}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4827 | |
| 4828 | TEST_P(AudioCodecsOfferTest, TestCodecsInOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4829 | TestAudioCodecsOffer(GetParam()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4830 | } |
| 4831 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4832 | INSTANTIATE_TEST_SUITE_P(MediaSessionDescriptionFactoryTest, |
| 4833 | AudioCodecsOfferTest, |
| 4834 | ::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4835 | RtpTransceiverDirection::kRecvOnly, |
| 4836 | RtpTransceiverDirection::kSendRecv, |
| 4837 | RtpTransceiverDirection::kInactive)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4838 | |
| 4839 | class AudioCodecsAnswerTest |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4840 | : public ::testing::TestWithParam<::testing::tuple<RtpTransceiverDirection, |
| 4841 | RtpTransceiverDirection, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4842 | bool>> {}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4843 | |
| 4844 | TEST_P(AudioCodecsAnswerTest, TestCodecsInAnswer) { |
ehmaldonado | abcef5d | 2017-02-08 04:07:11 -0800 | [diff] [blame] | 4845 | TestAudioCodecsAnswer(::testing::get<0>(GetParam()), |
| 4846 | ::testing::get<1>(GetParam()), |
| 4847 | ::testing::get<2>(GetParam())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4848 | } |
| 4849 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4850 | INSTANTIATE_TEST_SUITE_P( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4851 | MediaSessionDescriptionFactoryTest, |
| 4852 | AudioCodecsAnswerTest, |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4853 | ::testing::Combine(::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4854 | RtpTransceiverDirection::kRecvOnly, |
| 4855 | RtpTransceiverDirection::kSendRecv, |
| 4856 | RtpTransceiverDirection::kInactive), |
| 4857 | ::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4858 | RtpTransceiverDirection::kRecvOnly, |
| 4859 | RtpTransceiverDirection::kSendRecv, |
| 4860 | RtpTransceiverDirection::kInactive), |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4861 | ::testing::Bool())); |