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 | 57cabed | 2020-04-01 12:03:11 +0200 | [diff] [blame] | 21 | #include "absl/strings/match.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "media/base/test_utils.h" |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 24 | #include "media/sctp/sctp_transport_internal.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "p2p/base/p2p_constants.h" |
| 26 | #include "p2p/base/transport_description.h" |
| 27 | #include "p2p/base/transport_info.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "pc/rtp_media_utils.h" |
| 29 | #include "pc/srtp_filter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "rtc_base/fake_ssl_identity.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 33 | #include "rtc_base/message_digest.h" |
| 34 | #include "rtc_base/ssl_adapter.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 35 | #include "rtc_base/strings/string_builder.h" |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 36 | #include "rtc_base/unique_id_generator.h" |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 37 | #include "test/gmock.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 39 | #define ASSERT_CRYPTO(cd, s, cs) \ |
| 40 | ASSERT_EQ(s, cd->cryptos().size()); \ |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 41 | ASSERT_EQ(cs, cd->cryptos()[0].cipher_suite) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
| 43 | typedef std::vector<cricket::Candidate> Candidates; |
| 44 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 45 | using cricket::AudioCodec; |
| 46 | using cricket::AudioContentDescription; |
| 47 | using cricket::ContentInfo; |
| 48 | using cricket::CryptoParamsVec; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 49 | using cricket::GetFirstAudioContent; |
| 50 | using cricket::GetFirstAudioContentDescription; |
| 51 | using cricket::GetFirstDataContent; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 52 | using cricket::GetFirstRtpDataContentDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 53 | using cricket::GetFirstVideoContent; |
| 54 | using cricket::GetFirstVideoContentDescription; |
| 55 | using cricket::kAutoBandwidth; |
| 56 | using cricket::MEDIA_TYPE_AUDIO; |
| 57 | using cricket::MEDIA_TYPE_DATA; |
| 58 | using cricket::MEDIA_TYPE_VIDEO; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | using cricket::MediaContentDescription; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 60 | using cricket::MediaDescriptionOptions; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 61 | using cricket::MediaProtocolType; |
| 62 | using cricket::MediaSessionDescriptionFactory; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | using cricket::MediaSessionOptions; |
| 64 | using cricket::MediaType; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 65 | using cricket::RidDescription; |
| 66 | using cricket::RidDirection; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 67 | using cricket::RtpDataCodec; |
| 68 | using cricket::RtpDataContentDescription; |
| 69 | using cricket::SctpDataContentDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 70 | using cricket::SEC_DISABLED; |
| 71 | using cricket::SEC_ENABLED; |
| 72 | using cricket::SEC_REQUIRED; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | using cricket::SessionDescription; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 74 | using cricket::SimulcastDescription; |
| 75 | using cricket::SimulcastLayer; |
| 76 | using cricket::SimulcastLayerList; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | using cricket::SsrcGroup; |
| 78 | using cricket::StreamParams; |
| 79 | using cricket::StreamParamsVec; |
| 80 | using cricket::TransportDescription; |
| 81 | using cricket::TransportDescriptionFactory; |
| 82 | using cricket::TransportInfo; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | using cricket::VideoCodec; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 84 | using cricket::VideoContentDescription; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 85 | using rtc::CS_AEAD_AES_128_GCM; |
| 86 | using rtc::CS_AEAD_AES_256_GCM; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 87 | using rtc::CS_AES_CM_128_HMAC_SHA1_32; |
| 88 | using rtc::CS_AES_CM_128_HMAC_SHA1_80; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 89 | using rtc::UniqueRandomIdGenerator; |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 90 | using ::testing::Contains; |
| 91 | using ::testing::Each; |
Danil Chapovalov | 5f999a7 | 2020-02-20 16:39:05 +0100 | [diff] [blame] | 92 | using ::testing::ElementsAre; |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 93 | using ::testing::ElementsAreArray; |
| 94 | using ::testing::Eq; |
| 95 | using ::testing::Field; |
| 96 | using ::testing::IsEmpty; |
| 97 | using ::testing::IsFalse; |
| 98 | using ::testing::Ne; |
| 99 | using ::testing::Not; |
| 100 | using ::testing::Pointwise; |
| 101 | using ::testing::SizeIs; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 102 | using webrtc::RtpExtension; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 103 | using webrtc::RtpTransceiverDirection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | |
| 105 | static const AudioCodec kAudioCodecs1[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 106 | AudioCodec(103, "ISAC", 16000, -1, 1), |
| 107 | AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 108 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
| 109 | AudioCodec(8, "PCMA", 8000, 64000, 1), |
| 110 | AudioCodec(117, "red", 8000, 0, 1), |
| 111 | AudioCodec(107, "CN", 48000, 0, 1)}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 112 | |
| 113 | static const AudioCodec kAudioCodecs2[] = { |
Henrik Lundin | f8ed561 | 2018-05-07 12:05:57 +0200 | [diff] [blame] | 114 | AudioCodec(126, "foo", 16000, 22000, 1), |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 115 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
| 116 | AudioCodec(127, "iLBC", 8000, 13300, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | static const AudioCodec kAudioCodecsAnswer[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 120 | AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 121 | AudioCodec(0, "PCMU", 8000, 64000, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 124 | static const VideoCodec kVideoCodecs1[] = {VideoCodec(96, "H264-SVC"), |
| 125 | VideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 126 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 127 | static const VideoCodec kVideoCodecs1Reverse[] = {VideoCodec(97, "H264"), |
| 128 | VideoCodec(96, "H264-SVC")}; |
| 129 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 130 | static const VideoCodec kVideoCodecs2[] = {VideoCodec(126, "H264"), |
| 131 | VideoCodec(127, "H263")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 133 | static const VideoCodec kVideoCodecsAnswer[] = {VideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 134 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 135 | static const RtpDataCodec kDataCodecs1[] = {RtpDataCodec(98, "binary-data"), |
| 136 | RtpDataCodec(99, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 138 | static const RtpDataCodec kDataCodecs2[] = {RtpDataCodec(126, "binary-data"), |
| 139 | RtpDataCodec(127, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 141 | static const RtpDataCodec kDataCodecsAnswer[] = { |
| 142 | RtpDataCodec(98, "binary-data"), RtpDataCodec(99, "utf8-text")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 144 | static const RtpExtension kAudioRtpExtension1[] = { |
| 145 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 146 | RtpExtension("http://google.com/testing/audio_something", 10), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 149 | static const RtpExtension kAudioRtpExtensionEncrypted1[] = { |
| 150 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 151 | RtpExtension("http://google.com/testing/audio_something", 10), |
| 152 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
| 153 | }; |
| 154 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 155 | static const RtpExtension kAudioRtpExtension2[] = { |
| 156 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 2), |
| 157 | RtpExtension("http://google.com/testing/audio_something_else", 8), |
| 158 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 161 | static const RtpExtension kAudioRtpExtension3[] = { |
| 162 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 163 | RtpExtension("http://google.com/testing/both_audio_and_video", 3), |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 166 | static const RtpExtension kAudioRtpExtension3ForEncryption[] = { |
| 167 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 168 | // Use RTP extension that supports encryption. |
| 169 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 170 | }; |
| 171 | |
| 172 | static const RtpExtension kAudioRtpExtension3ForEncryptionOffer[] = { |
| 173 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 174 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 175 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14, true), |
| 176 | }; |
| 177 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 178 | static const RtpExtension kAudioRtpExtensionAnswer[] = { |
| 179 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 182 | static const RtpExtension kAudioRtpExtensionEncryptedAnswer[] = { |
| 183 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
| 184 | }; |
| 185 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 186 | static const RtpExtension kVideoRtpExtension1[] = { |
| 187 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 188 | RtpExtension("http://google.com/testing/video_something", 13), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 191 | static const RtpExtension kVideoRtpExtensionEncrypted1[] = { |
| 192 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 193 | RtpExtension("http://google.com/testing/video_something", 13), |
| 194 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 11, true), |
| 195 | }; |
| 196 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 197 | static const RtpExtension kVideoRtpExtension2[] = { |
| 198 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 2), |
| 199 | RtpExtension("http://google.com/testing/video_something_else", 14), |
| 200 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | }; |
| 202 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 203 | static const RtpExtension kVideoRtpExtension3[] = { |
| 204 | RtpExtension("http://google.com/testing/video_something", 4), |
| 205 | RtpExtension("http://google.com/testing/both_audio_and_video", 5), |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 208 | static const RtpExtension kVideoRtpExtension3ForEncryption[] = { |
| 209 | RtpExtension("http://google.com/testing/video_something", 4), |
| 210 | // Use RTP extension that supports encryption. |
| 211 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 5), |
| 212 | }; |
| 213 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 214 | static const RtpExtension kVideoRtpExtensionAnswer[] = { |
| 215 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 218 | static const RtpExtension kVideoRtpExtensionEncryptedAnswer[] = { |
| 219 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 11, true), |
| 220 | }; |
| 221 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 222 | static const RtpExtension kRtpExtensionTransportSequenceNumber01[] = { |
| 223 | RtpExtension("http://www.ietf.org/id/" |
| 224 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 225 | 1), |
| 226 | }; |
| 227 | |
| 228 | static const RtpExtension kRtpExtensionTransportSequenceNumber01And02[] = { |
| 229 | RtpExtension("http://www.ietf.org/id/" |
| 230 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 231 | 1), |
Johannes Kron | 8cc711a | 2019-03-07 22:36:35 +0100 | [diff] [blame] | 232 | RtpExtension( |
| 233 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 234 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | static const RtpExtension kRtpExtensionTransportSequenceNumber02[] = { |
Johannes Kron | 8cc711a | 2019-03-07 22:36:35 +0100 | [diff] [blame] | 238 | RtpExtension( |
| 239 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 240 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 241 | }; |
| 242 | |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 243 | static const RtpExtension kRtpExtensionGenericFrameDescriptorUri00[] = { |
| 244 | RtpExtension("http://www.webrtc.org/experiments/rtp-hdrext/" |
| 245 | "generic-frame-descriptor-00", |
| 246 | 3), |
| 247 | }; |
| 248 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 249 | static const uint32_t kSimulcastParamsSsrc[] = {10, 11, 20, 21, 30, 31}; |
| 250 | static const uint32_t kSimSsrc[] = {10, 20, 30}; |
| 251 | static const uint32_t kFec1Ssrc[] = {10, 11}; |
| 252 | static const uint32_t kFec2Ssrc[] = {20, 21}; |
| 253 | static const uint32_t kFec3Ssrc[] = {30, 31}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 254 | |
| 255 | static const char kMediaStream1[] = "stream_1"; |
| 256 | static const char kMediaStream2[] = "stream_2"; |
| 257 | static const char kVideoTrack1[] = "video_1"; |
| 258 | static const char kVideoTrack2[] = "video_2"; |
| 259 | static const char kAudioTrack1[] = "audio_1"; |
| 260 | static const char kAudioTrack2[] = "audio_2"; |
| 261 | static const char kAudioTrack3[] = "audio_3"; |
| 262 | static const char kDataTrack1[] = "data_1"; |
| 263 | static const char kDataTrack2[] = "data_2"; |
| 264 | static const char kDataTrack3[] = "data_3"; |
| 265 | |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 266 | static const char* kMediaProtocols[] = {"RTP/AVP", "RTP/SAVP", "RTP/AVPF", |
| 267 | "RTP/SAVPF"}; |
| 268 | static const char* kMediaProtocolsDtls[] = { |
| 269 | "TCP/TLS/RTP/SAVPF", "TCP/TLS/RTP/SAVP", "UDP/TLS/RTP/SAVPF", |
| 270 | "UDP/TLS/RTP/SAVP"}; |
| 271 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 272 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 273 | // default changes. |
| 274 | static const char* kDefaultSrtpCryptoSuite = CS_AES_CM_128_HMAC_SHA1_80; |
| 275 | static const char* kDefaultSrtpCryptoSuiteGcm = CS_AEAD_AES_256_GCM; |
| 276 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 277 | // These constants are used to make the code using "AddMediaDescriptionOptions" |
| 278 | // more readable. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 279 | static constexpr bool kStopped = true; |
| 280 | static constexpr bool kActive = false; |
| 281 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 282 | static bool IsMediaContentOfType(const ContentInfo* content, |
| 283 | MediaType media_type) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 284 | RTC_DCHECK(content); |
| 285 | return content->media_description()->type() == media_type; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 288 | static RtpTransceiverDirection GetMediaDirection(const ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 289 | RTC_DCHECK(content); |
| 290 | return content->media_description()->direction(); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 291 | } |
| 292 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 293 | static void AddRtxCodec(const VideoCodec& rtx_codec, |
| 294 | std::vector<VideoCodec>* codecs) { |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 295 | ASSERT_FALSE(cricket::FindCodecById(*codecs, rtx_codec.id)); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 296 | codecs->push_back(rtx_codec); |
| 297 | } |
| 298 | |
| 299 | template <class T> |
| 300 | static std::vector<std::string> GetCodecNames(const std::vector<T>& codecs) { |
| 301 | std::vector<std::string> codec_names; |
Mirko Bonadei | 649a4c2 | 2019-01-29 10:11:53 +0100 | [diff] [blame] | 302 | codec_names.reserve(codecs.size()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 303 | for (const auto& codec : codecs) { |
| 304 | codec_names.push_back(codec.name); |
| 305 | } |
| 306 | return codec_names; |
| 307 | } |
| 308 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 309 | // This is used for test only. MIDs are not the identification of the |
| 310 | // MediaDescriptionOptions since some end points may not support MID and the SDP |
| 311 | // may not contain 'mid'. |
| 312 | std::vector<MediaDescriptionOptions>::iterator FindFirstMediaDescriptionByMid( |
| 313 | const std::string& mid, |
| 314 | MediaSessionOptions* opts) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 315 | return absl::c_find_if( |
| 316 | opts->media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 317 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
| 318 | } |
| 319 | |
| 320 | std::vector<MediaDescriptionOptions>::const_iterator |
| 321 | FindFirstMediaDescriptionByMid(const std::string& mid, |
| 322 | const MediaSessionOptions& opts) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 323 | return absl::c_find_if( |
| 324 | opts.media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 325 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | // Add a media section to the |session_options|. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 329 | static void AddMediaDescriptionOptions(MediaType type, |
| 330 | const std::string& mid, |
| 331 | RtpTransceiverDirection direction, |
| 332 | bool stopped, |
| 333 | MediaSessionOptions* opts) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 334 | opts->media_description_options.push_back( |
| 335 | MediaDescriptionOptions(type, mid, direction, stopped)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 338 | static void AddAudioVideoSections(RtpTransceiverDirection direction, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 339 | MediaSessionOptions* opts) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 340 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 341 | opts); |
| 342 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", direction, kActive, |
| 343 | opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | static void AddDataSection(cricket::DataChannelType dct, |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 347 | RtpTransceiverDirection direction, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 348 | MediaSessionOptions* opts) { |
| 349 | opts->data_channel_type = dct; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 350 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", direction, kActive, opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 353 | static void AttachSenderToMediaDescriptionOptions( |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 354 | const std::string& mid, |
| 355 | MediaType type, |
| 356 | const std::string& track_id, |
| 357 | const std::vector<std::string>& stream_ids, |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 358 | const std::vector<RidDescription>& rids, |
| 359 | const SimulcastLayerList& simulcast_layers, |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 360 | int num_sim_layer, |
| 361 | MediaSessionOptions* session_options) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 362 | auto it = FindFirstMediaDescriptionByMid(mid, session_options); |
| 363 | switch (type) { |
| 364 | case MEDIA_TYPE_AUDIO: |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 365 | it->AddAudioSender(track_id, stream_ids); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 366 | break; |
| 367 | case MEDIA_TYPE_VIDEO: |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 368 | it->AddVideoSender(track_id, stream_ids, rids, simulcast_layers, |
| 369 | num_sim_layer); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 370 | break; |
| 371 | case MEDIA_TYPE_DATA: |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 372 | RTC_CHECK(stream_ids.size() == 1U); |
| 373 | it->AddRtpDataChannel(track_id, stream_ids[0]); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 374 | break; |
| 375 | default: |
| 376 | RTC_NOTREACHED(); |
| 377 | } |
| 378 | } |
| 379 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 380 | static void AttachSenderToMediaDescriptionOptions( |
| 381 | const std::string& mid, |
| 382 | MediaType type, |
| 383 | const std::string& track_id, |
| 384 | const std::vector<std::string>& stream_ids, |
| 385 | int num_sim_layer, |
| 386 | MediaSessionOptions* session_options) { |
| 387 | AttachSenderToMediaDescriptionOptions(mid, type, track_id, stream_ids, {}, |
| 388 | SimulcastLayerList(), num_sim_layer, |
| 389 | session_options); |
| 390 | } |
| 391 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 392 | static void DetachSenderFromMediaSection(const std::string& mid, |
| 393 | const std::string& track_id, |
| 394 | MediaSessionOptions* session_options) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 395 | std::vector<cricket::SenderOptions>& sender_options_list = |
| 396 | FindFirstMediaDescriptionByMid(mid, session_options)->sender_options; |
| 397 | auto sender_it = |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 398 | absl::c_find_if(sender_options_list, |
| 399 | [track_id](const cricket::SenderOptions& sender_options) { |
| 400 | return sender_options.track_id == track_id; |
| 401 | }); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 402 | RTC_DCHECK(sender_it != sender_options_list.end()); |
| 403 | sender_options_list.erase(sender_it); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | // Helper function used to create a default MediaSessionOptions for Plan B SDP. |
| 407 | // (https://tools.ietf.org/html/draft-uberti-rtcweb-plan-00). |
| 408 | static MediaSessionOptions CreatePlanBMediaSessionOptions() { |
| 409 | MediaSessionOptions session_options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 410 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 411 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 412 | &session_options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 413 | return session_options; |
| 414 | } |
| 415 | |
Philipp Hancke | 1aec2bf | 2020-05-12 10:11:27 +0200 | [diff] [blame] | 416 | // prefers GCM SDES crypto suites by removing non-GCM defaults. |
| 417 | void PreferGcmCryptoParameters(CryptoParamsVec* cryptos) { |
| 418 | cryptos->erase( |
| 419 | std::remove_if(cryptos->begin(), cryptos->end(), |
| 420 | [](const cricket::CryptoParams& crypto) { |
| 421 | return crypto.cipher_suite != CS_AEAD_AES_256_GCM && |
| 422 | crypto.cipher_suite != CS_AEAD_AES_128_GCM; |
| 423 | }), |
| 424 | cryptos->end()); |
| 425 | } |
| 426 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 427 | // TODO(zhihuang): Most of these tests were written while MediaSessionOptions |
| 428 | // was designed for Plan B SDP, where only one audio "m=" section and one video |
| 429 | // "m=" section could be generated, and ordering couldn't be controlled. Many of |
| 430 | // 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] | 431 | class MediaSessionDescriptionFactoryTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 432 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 433 | MediaSessionDescriptionFactoryTest() |
| 434 | : f1_(&tdf1_, &ssrc_generator1), f2_(&tdf2_, &ssrc_generator2) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 435 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 436 | MAKE_VECTOR(kAudioCodecs1)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 437 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1), |
| 438 | MAKE_VECTOR(kVideoCodecs1)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 439 | f1_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 440 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 441 | MAKE_VECTOR(kAudioCodecs2)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 442 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2), |
| 443 | MAKE_VECTOR(kVideoCodecs2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 444 | f2_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
Henrik Boström | 3a14bf3 | 2015-08-31 09:27:58 +0200 | [diff] [blame] | 445 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 446 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
Henrik Boström | 3a14bf3 | 2015-08-31 09:27:58 +0200 | [diff] [blame] | 447 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 448 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 449 | } |
| 450 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 451 | // Create a video StreamParamsVec object with: |
| 452 | // - one video stream with 3 simulcast streams and FEC, |
| 453 | StreamParamsVec CreateComplexVideoStreamParamsVec() { |
| 454 | SsrcGroup sim_group("SIM", MAKE_VECTOR(kSimSsrc)); |
| 455 | SsrcGroup fec_group1("FEC", MAKE_VECTOR(kFec1Ssrc)); |
| 456 | SsrcGroup fec_group2("FEC", MAKE_VECTOR(kFec2Ssrc)); |
| 457 | SsrcGroup fec_group3("FEC", MAKE_VECTOR(kFec3Ssrc)); |
| 458 | |
| 459 | std::vector<SsrcGroup> ssrc_groups; |
| 460 | ssrc_groups.push_back(sim_group); |
| 461 | ssrc_groups.push_back(fec_group1); |
| 462 | ssrc_groups.push_back(fec_group2); |
| 463 | ssrc_groups.push_back(fec_group3); |
| 464 | |
| 465 | StreamParams simulcast_params; |
| 466 | simulcast_params.id = kVideoTrack1; |
| 467 | simulcast_params.ssrcs = MAKE_VECTOR(kSimulcastParamsSsrc); |
| 468 | simulcast_params.ssrc_groups = ssrc_groups; |
| 469 | simulcast_params.cname = "Video_SIM_FEC"; |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 470 | simulcast_params.set_stream_ids({kMediaStream1}); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 471 | |
| 472 | StreamParamsVec video_streams; |
| 473 | video_streams.push_back(simulcast_params); |
| 474 | |
| 475 | return video_streams; |
| 476 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 477 | |
| 478 | bool CompareCryptoParams(const CryptoParamsVec& c1, |
| 479 | const CryptoParamsVec& c2) { |
| 480 | if (c1.size() != c2.size()) |
| 481 | return false; |
| 482 | for (size_t i = 0; i < c1.size(); ++i) |
| 483 | if (c1[i].tag != c2[i].tag || c1[i].cipher_suite != c2[i].cipher_suite || |
| 484 | c1[i].key_params != c2[i].key_params || |
| 485 | c1[i].session_params != c2[i].session_params) |
| 486 | return false; |
| 487 | return true; |
| 488 | } |
| 489 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 490 | // Returns true if the transport info contains "renomination" as an |
| 491 | // ICE option. |
| 492 | bool GetIceRenomination(const TransportInfo* transport_info) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 493 | return absl::c_linear_search(transport_info->description.transport_options, |
| 494 | "renomination"); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 495 | } |
| 496 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 497 | void TestTransportInfo(bool offer, |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 498 | const MediaSessionOptions& options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 499 | bool has_current_desc) { |
| 500 | const std::string current_audio_ufrag = "current_audio_ufrag"; |
| 501 | const std::string current_audio_pwd = "current_audio_pwd"; |
| 502 | const std::string current_video_ufrag = "current_video_ufrag"; |
| 503 | const std::string current_video_pwd = "current_video_pwd"; |
| 504 | const std::string current_data_ufrag = "current_data_ufrag"; |
| 505 | const std::string current_data_pwd = "current_data_pwd"; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 506 | std::unique_ptr<SessionDescription> current_desc; |
| 507 | std::unique_ptr<SessionDescription> desc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 508 | if (has_current_desc) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 509 | current_desc = std::make_unique<SessionDescription>(); |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 510 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 511 | "audio", |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 512 | TransportDescription(current_audio_ufrag, current_audio_pwd))); |
| 513 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 514 | "video", |
Steve Anton | 06817cd | 2018-12-18 15:55:30 -0800 | [diff] [blame] | 515 | TransportDescription(current_video_ufrag, current_video_pwd))); |
| 516 | current_desc->AddTransportInfo(TransportInfo( |
| 517 | "data", TransportDescription(current_data_ufrag, current_data_pwd))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 518 | } |
| 519 | if (offer) { |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 520 | desc = f1_.CreateOffer(options, current_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 521 | } else { |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 522 | std::unique_ptr<SessionDescription> offer; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 523 | offer = f1_.CreateOffer(options, NULL); |
| 524 | desc = f1_.CreateAnswer(offer.get(), options, current_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 525 | } |
| 526 | ASSERT_TRUE(desc.get() != NULL); |
| 527 | const TransportInfo* ti_audio = desc->GetTransportInfoByName("audio"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 528 | if (options.has_audio()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 529 | EXPECT_TRUE(ti_audio != NULL); |
| 530 | if (has_current_desc) { |
| 531 | EXPECT_EQ(current_audio_ufrag, ti_audio->description.ice_ufrag); |
| 532 | EXPECT_EQ(current_audio_pwd, ti_audio->description.ice_pwd); |
| 533 | } else { |
| 534 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 535 | ti_audio->description.ice_ufrag.size()); |
| 536 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 537 | ti_audio->description.ice_pwd.size()); |
| 538 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 539 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 540 | FindFirstMediaDescriptionByMid("audio", options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 541 | EXPECT_EQ( |
| 542 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 543 | GetIceRenomination(ti_audio)); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 544 | EXPECT_EQ(media_desc_options_it->transport_options.opaque_parameters, |
| 545 | ti_audio->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 546 | |
| 547 | } else { |
| 548 | EXPECT_TRUE(ti_audio == NULL); |
| 549 | } |
| 550 | const TransportInfo* ti_video = desc->GetTransportInfoByName("video"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 551 | if (options.has_video()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 552 | EXPECT_TRUE(ti_video != NULL); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 553 | auto media_desc_options_it = |
| 554 | FindFirstMediaDescriptionByMid("video", options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | if (options.bundle_enabled) { |
| 556 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 557 | ti_video->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 558 | 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] | 559 | EXPECT_EQ(ti_audio->description.opaque_parameters, |
| 560 | ti_video->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 561 | } else { |
| 562 | if (has_current_desc) { |
| 563 | EXPECT_EQ(current_video_ufrag, ti_video->description.ice_ufrag); |
| 564 | EXPECT_EQ(current_video_pwd, ti_video->description.ice_pwd); |
| 565 | } else { |
| 566 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 567 | ti_video->description.ice_ufrag.size()); |
| 568 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 569 | ti_video->description.ice_pwd.size()); |
| 570 | } |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 571 | EXPECT_EQ(media_desc_options_it->transport_options.opaque_parameters, |
| 572 | ti_video->description.opaque_parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 573 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 574 | EXPECT_EQ( |
| 575 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 576 | GetIceRenomination(ti_video)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 577 | } else { |
| 578 | EXPECT_TRUE(ti_video == NULL); |
| 579 | } |
| 580 | const TransportInfo* ti_data = desc->GetTransportInfoByName("data"); |
| 581 | if (options.has_data()) { |
| 582 | EXPECT_TRUE(ti_data != NULL); |
| 583 | if (options.bundle_enabled) { |
| 584 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 585 | ti_data->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 586 | 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] | 587 | } else { |
| 588 | if (has_current_desc) { |
| 589 | EXPECT_EQ(current_data_ufrag, ti_data->description.ice_ufrag); |
| 590 | EXPECT_EQ(current_data_pwd, ti_data->description.ice_pwd); |
| 591 | } else { |
| 592 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 593 | ti_data->description.ice_ufrag.size()); |
| 594 | EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 595 | ti_data->description.ice_pwd.size()); |
| 596 | } |
| 597 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 598 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 599 | FindFirstMediaDescriptionByMid("data", options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 600 | EXPECT_EQ( |
| 601 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 602 | GetIceRenomination(ti_data)); |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 603 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 604 | } else { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 605 | EXPECT_TRUE(ti_data == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
| 609 | void TestCryptoWithBundle(bool offer) { |
| 610 | f1_.set_secure(SEC_ENABLED); |
| 611 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 612 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 613 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 614 | &options); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 615 | std::unique_ptr<SessionDescription> ref_desc; |
| 616 | std::unique_ptr<SessionDescription> desc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 617 | if (offer) { |
| 618 | options.bundle_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 619 | ref_desc = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 620 | options.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 621 | desc = f1_.CreateOffer(options, ref_desc.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | } else { |
| 623 | options.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 624 | ref_desc = f1_.CreateOffer(options, NULL); |
| 625 | desc = f1_.CreateAnswer(ref_desc.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 626 | } |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 627 | ASSERT_TRUE(desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 628 | const cricket::MediaContentDescription* audio_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 629 | desc->GetContentDescriptionByName("audio"); |
| 630 | ASSERT_TRUE(audio_media_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 631 | const cricket::MediaContentDescription* video_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 632 | desc->GetContentDescriptionByName("video"); |
| 633 | ASSERT_TRUE(video_media_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 634 | EXPECT_TRUE(CompareCryptoParams(audio_media_desc->cryptos(), |
| 635 | video_media_desc->cryptos())); |
| 636 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 637 | EXPECT_EQ(kDefaultSrtpCryptoSuite, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 638 | audio_media_desc->cryptos()[0].cipher_suite); |
| 639 | |
| 640 | // Verify the selected crypto is one from the reference audio |
| 641 | // media content. |
| 642 | const cricket::MediaContentDescription* ref_audio_media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 643 | ref_desc->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 644 | bool found = false; |
| 645 | for (size_t i = 0; i < ref_audio_media_desc->cryptos().size(); ++i) { |
| 646 | if (ref_audio_media_desc->cryptos()[i].Matches( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 647 | audio_media_desc->cryptos()[0])) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 648 | found = true; |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | EXPECT_TRUE(found); |
| 653 | } |
| 654 | |
| 655 | // This test that the audio and video media direction is set to |
| 656 | // |expected_direction_in_answer| in an answer if the offer direction is set |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 657 | // 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] | 658 | void TestMediaDirectionInAnswer( |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 659 | RtpTransceiverDirection direction_in_offer, |
| 660 | RtpTransceiverDirection expected_direction_in_answer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 661 | MediaSessionOptions offer_opts; |
| 662 | AddAudioVideoSections(direction_in_offer, &offer_opts); |
| 663 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 664 | std::unique_ptr<SessionDescription> offer = |
| 665 | f1_.CreateOffer(offer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 666 | ASSERT_TRUE(offer.get() != NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 667 | ContentInfo* ac_offer = offer->GetContentByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 668 | ASSERT_TRUE(ac_offer != NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 669 | ContentInfo* vc_offer = offer->GetContentByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 670 | ASSERT_TRUE(vc_offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 671 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 672 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 673 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 674 | std::unique_ptr<SessionDescription> answer = |
| 675 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 676 | const AudioContentDescription* acd_answer = |
| 677 | GetFirstAudioContentDescription(answer.get()); |
| 678 | EXPECT_EQ(expected_direction_in_answer, acd_answer->direction()); |
| 679 | const VideoContentDescription* vcd_answer = |
| 680 | GetFirstVideoContentDescription(answer.get()); |
| 681 | EXPECT_EQ(expected_direction_in_answer, vcd_answer->direction()); |
| 682 | } |
| 683 | |
| 684 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 685 | RTC_DCHECK(content); |
| 686 | RTC_CHECK(content->media_description()); |
| 687 | const cricket::AudioContentDescription* audio_desc = |
| 688 | content->media_description()->as_audio(); |
| 689 | RTC_CHECK(audio_desc); |
| 690 | for (const cricket::AudioCodec& codec : audio_desc->codecs()) { |
| 691 | if (codec.name == "CN") { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 692 | return false; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 693 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 694 | } |
| 695 | return true; |
| 696 | } |
| 697 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 698 | void TestVideoGcmCipher(bool gcm_offer, bool gcm_answer) { |
| 699 | MediaSessionOptions offer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 700 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &offer_opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 701 | offer_opts.crypto_options.srtp.enable_gcm_crypto_suites = gcm_offer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 702 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 703 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 704 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &answer_opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 705 | answer_opts.crypto_options.srtp.enable_gcm_crypto_suites = gcm_answer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 706 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 707 | f1_.set_secure(SEC_ENABLED); |
| 708 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 709 | std::unique_ptr<SessionDescription> offer = |
| 710 | f1_.CreateOffer(offer_opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 711 | ASSERT_TRUE(offer.get() != NULL); |
Philipp Hancke | 1aec2bf | 2020-05-12 10:11:27 +0200 | [diff] [blame] | 712 | if (gcm_offer && gcm_answer) { |
| 713 | for (cricket::ContentInfo& content : offer->contents()) { |
| 714 | auto cryptos = content.media_description()->cryptos(); |
| 715 | PreferGcmCryptoParameters(&cryptos); |
| 716 | content.media_description()->set_cryptos(cryptos); |
| 717 | } |
| 718 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 719 | std::unique_ptr<SessionDescription> answer = |
| 720 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 721 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 722 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 723 | ASSERT_TRUE(ac != NULL); |
| 724 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 725 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 726 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 727 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 728 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 729 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 730 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 731 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 732 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 733 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 734 | if (gcm_offer && gcm_answer) { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 735 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 736 | } else { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 737 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 738 | } |
| 739 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 740 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 741 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 742 | EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 743 | if (gcm_offer && gcm_answer) { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 744 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuiteGcm); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 745 | } else { |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 746 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 747 | } |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 748 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 751 | void TestTransportSequenceNumberNegotiation( |
| 752 | const cricket::RtpHeaderExtensions& local, |
| 753 | const cricket::RtpHeaderExtensions& offered, |
| 754 | const cricket::RtpHeaderExtensions& expectedAnswer) { |
| 755 | MediaSessionOptions opts; |
| 756 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 757 | f1_.set_audio_rtp_header_extensions(offered); |
| 758 | f1_.set_video_rtp_header_extensions(offered); |
| 759 | f2_.set_audio_rtp_header_extensions(local); |
| 760 | f2_.set_video_rtp_header_extensions(local); |
| 761 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 762 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 763 | ASSERT_TRUE(offer.get() != NULL); |
| 764 | std::unique_ptr<SessionDescription> answer = |
| 765 | f2_.CreateAnswer(offer.get(), opts, NULL); |
| 766 | |
| 767 | EXPECT_EQ( |
| 768 | expectedAnswer, |
| 769 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 770 | EXPECT_EQ( |
| 771 | expectedAnswer, |
| 772 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
| 773 | } |
| 774 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 775 | protected: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 776 | UniqueRandomIdGenerator ssrc_generator1; |
| 777 | UniqueRandomIdGenerator ssrc_generator2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 778 | MediaSessionDescriptionFactory f1_; |
| 779 | MediaSessionDescriptionFactory f2_; |
| 780 | TransportDescriptionFactory tdf1_; |
| 781 | TransportDescriptionFactory tdf2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 782 | }; |
| 783 | |
| 784 | // Create a typical audio offer, and ensure it matches what we expect. |
| 785 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { |
| 786 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 787 | std::unique_ptr<SessionDescription> offer = |
| 788 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 789 | ASSERT_TRUE(offer.get() != NULL); |
| 790 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 791 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 792 | ASSERT_TRUE(ac != NULL); |
| 793 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 794 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 795 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 796 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 797 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 798 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 799 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 800 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 801 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 802 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | // Create a typical video offer, and ensure it matches what we expect. |
| 806 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoOffer) { |
| 807 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 808 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 809 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 810 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 811 | ASSERT_TRUE(offer.get() != NULL); |
| 812 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 813 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 814 | ASSERT_TRUE(ac != NULL); |
| 815 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 816 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 817 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 818 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 819 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 820 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 821 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 822 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 823 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 824 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 825 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 826 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 827 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 828 | EXPECT_EQ(f1_.video_sendrecv_codecs(), vcd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 829 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 830 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 831 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 832 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 833 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | // Test creating an offer with bundle where the Codecs have the same dynamic |
| 837 | // RTP playlod type. The test verifies that the offer don't contain the |
| 838 | // duplicate RTP payload types. |
| 839 | TEST_F(MediaSessionDescriptionFactoryTest, TestBundleOfferWithSameCodecPlType) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 840 | const VideoCodec& offered_video_codec = f2_.video_sendrecv_codecs()[0]; |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 841 | const AudioCodec& offered_audio_codec = f2_.audio_sendrecv_codecs()[0]; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 842 | const RtpDataCodec& offered_data_codec = f2_.rtp_data_codecs()[0]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 843 | ASSERT_EQ(offered_video_codec.id, offered_audio_codec.id); |
| 844 | ASSERT_EQ(offered_video_codec.id, offered_data_codec.id); |
| 845 | |
| 846 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 847 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 848 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 849 | opts.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 850 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 851 | const VideoContentDescription* vcd = |
| 852 | GetFirstVideoContentDescription(offer.get()); |
| 853 | const AudioContentDescription* acd = |
| 854 | GetFirstAudioContentDescription(offer.get()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 855 | const RtpDataContentDescription* dcd = |
| 856 | GetFirstRtpDataContentDescription(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 857 | ASSERT_TRUE(NULL != vcd); |
| 858 | ASSERT_TRUE(NULL != acd); |
| 859 | ASSERT_TRUE(NULL != dcd); |
| 860 | EXPECT_NE(vcd->codecs()[0].id, acd->codecs()[0].id); |
| 861 | EXPECT_NE(vcd->codecs()[0].id, dcd->codecs()[0].id); |
| 862 | EXPECT_NE(acd->codecs()[0].id, dcd->codecs()[0].id); |
| 863 | EXPECT_EQ(vcd->codecs()[0].name, offered_video_codec.name); |
| 864 | EXPECT_EQ(acd->codecs()[0].name, offered_audio_codec.name); |
| 865 | EXPECT_EQ(dcd->codecs()[0].name, offered_data_codec.name); |
| 866 | } |
| 867 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 868 | // Test creating an updated offer with bundle, audio, video and data |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 869 | // after an audio only session has been negotiated. |
| 870 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 871 | TestCreateUpdatedVideoOfferWithBundle) { |
| 872 | f1_.set_secure(SEC_ENABLED); |
| 873 | f2_.set_secure(SEC_ENABLED); |
| 874 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 875 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 876 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 877 | &opts); |
| 878 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 879 | RtpTransceiverDirection::kInactive, kStopped, |
| 880 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 881 | opts.data_channel_type = cricket::DCT_NONE; |
| 882 | opts.bundle_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 883 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 884 | std::unique_ptr<SessionDescription> answer = |
| 885 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | |
| 887 | MediaSessionOptions updated_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 888 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &updated_opts); |
| 889 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 890 | &updated_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 891 | updated_opts.bundle_enabled = true; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 892 | std::unique_ptr<SessionDescription> updated_offer( |
| 893 | f1_.CreateOffer(updated_opts, answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 894 | |
| 895 | const AudioContentDescription* acd = |
| 896 | GetFirstAudioContentDescription(updated_offer.get()); |
| 897 | const VideoContentDescription* vcd = |
| 898 | GetFirstVideoContentDescription(updated_offer.get()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 899 | const RtpDataContentDescription* dcd = |
| 900 | GetFirstRtpDataContentDescription(updated_offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | EXPECT_TRUE(NULL != vcd); |
| 902 | EXPECT_TRUE(NULL != acd); |
| 903 | EXPECT_TRUE(NULL != dcd); |
| 904 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 905 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 906 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 907 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 908 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 909 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 910 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 911 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 912 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 913 | // Create a RTP data offer, and ensure it matches what we expect. |
| 914 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateRtpDataOffer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 915 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 916 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 917 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 918 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 919 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 920 | ASSERT_TRUE(offer.get() != NULL); |
| 921 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 922 | const ContentInfo* dc = offer->GetContentByName("data"); |
| 923 | ASSERT_TRUE(ac != NULL); |
| 924 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 925 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 926 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 927 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 928 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 930 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 931 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attched. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 932 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 933 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 934 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 935 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 936 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 937 | EXPECT_EQ(f1_.rtp_data_codecs(), dcd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 938 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 939 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 940 | dcd->bandwidth()); // default bandwidth (auto) |
| 941 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 942 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 943 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 944 | } |
| 945 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 946 | // Create an SCTP data offer with bundle without error. |
| 947 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { |
| 948 | MediaSessionOptions opts; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 949 | opts.bundle_enabled = true; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 950 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 951 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 952 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 953 | EXPECT_TRUE(offer.get() != NULL); |
| 954 | EXPECT_TRUE(offer->GetContentByName("data") != NULL); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 +0000 | [diff] [blame] | 955 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 956 | ASSERT_TRUE(dcd); |
| 957 | // Since this transport is insecure, the protocol should be "SCTP". |
| 958 | EXPECT_EQ(cricket::kMediaProtocolSctp, dcd->protocol()); |
| 959 | } |
| 960 | |
| 961 | // Create an SCTP data offer with bundle without error. |
| 962 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSecureSctpDataOffer) { |
| 963 | MediaSessionOptions opts; |
| 964 | opts.bundle_enabled = true; |
| 965 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 966 | f1_.set_secure(SEC_ENABLED); |
| 967 | tdf1_.set_secure(SEC_ENABLED); |
| 968 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 969 | EXPECT_TRUE(offer.get() != NULL); |
| 970 | EXPECT_TRUE(offer->GetContentByName("data") != NULL); |
| 971 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 972 | ASSERT_TRUE(dcd); |
| 973 | // The protocol should now be "UDP/DTLS/SCTP" |
| 974 | EXPECT_EQ(cricket::kMediaProtocolUdpDtlsSctp, dcd->protocol()); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 975 | } |
| 976 | |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 977 | // Test creating an sctp data channel from an already generated offer. |
| 978 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { |
| 979 | MediaSessionOptions opts; |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 980 | opts.bundle_enabled = true; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 981 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 982 | f1_.set_secure(SEC_ENABLED); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 983 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 984 | ASSERT_TRUE(offer1.get() != NULL); |
| 985 | const ContentInfo* data = offer1->GetContentByName("data"); |
| 986 | ASSERT_TRUE(data != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 987 | ASSERT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 988 | |
| 989 | // Now set data_channel_type to 'none' (default) and make sure that the |
| 990 | // datachannel type that gets generated from the previous offer, is of the |
| 991 | // same type. |
| 992 | opts.data_channel_type = cricket::DCT_NONE; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 993 | std::unique_ptr<SessionDescription> offer2( |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 994 | f1_.CreateOffer(opts, offer1.get())); |
| 995 | data = offer2->GetContentByName("data"); |
| 996 | ASSERT_TRUE(data != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 997 | EXPECT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 1000 | // Test that if BUNDLE is enabled and all media sections are rejected then the |
| 1001 | // BUNDLE group is not present in the re-offer. |
| 1002 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferNoBundleGroupIfAllRejected) { |
| 1003 | MediaSessionOptions opts; |
| 1004 | opts.bundle_enabled = true; |
| 1005 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1006 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1007 | &opts); |
| 1008 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1009 | |
| 1010 | opts.media_description_options[0].stopped = true; |
| 1011 | std::unique_ptr<SessionDescription> reoffer = |
| 1012 | f1_.CreateOffer(opts, offer.get()); |
| 1013 | |
| 1014 | EXPECT_FALSE(reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); |
| 1015 | } |
| 1016 | |
| 1017 | // Test that if BUNDLE is enabled and the remote re-offer does not include a |
| 1018 | // BUNDLE group since all media sections are rejected, then the re-answer also |
| 1019 | // does not include a BUNDLE group. |
| 1020 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerNoBundleGroupIfAllRejected) { |
| 1021 | MediaSessionOptions opts; |
| 1022 | opts.bundle_enabled = true; |
| 1023 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1024 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1025 | &opts); |
| 1026 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1027 | std::unique_ptr<SessionDescription> answer = |
| 1028 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1029 | |
| 1030 | opts.media_description_options[0].stopped = true; |
| 1031 | std::unique_ptr<SessionDescription> reoffer = |
| 1032 | f1_.CreateOffer(opts, offer.get()); |
| 1033 | std::unique_ptr<SessionDescription> reanswer = |
| 1034 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1035 | |
| 1036 | EXPECT_FALSE(reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); |
| 1037 | } |
| 1038 | |
| 1039 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 1040 | // was rejected then the new offerer-tagged media section is the non-rejected |
| 1041 | // media section. |
| 1042 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferChangeBundleOffererTagged) { |
| 1043 | MediaSessionOptions opts; |
| 1044 | opts.bundle_enabled = true; |
| 1045 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1046 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1047 | &opts); |
| 1048 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1049 | |
| 1050 | // Reject the audio m= section and add a video m= section. |
| 1051 | opts.media_description_options[0].stopped = true; |
| 1052 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1053 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1054 | &opts); |
| 1055 | std::unique_ptr<SessionDescription> reoffer = |
| 1056 | f1_.CreateOffer(opts, offer.get()); |
| 1057 | |
| 1058 | const cricket::ContentGroup* bundle_group = |
| 1059 | reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1060 | ASSERT_TRUE(bundle_group); |
| 1061 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 1062 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 1063 | } |
| 1064 | |
| 1065 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 1066 | // was rejected and a new media section is added, then the re-answer BUNDLE |
| 1067 | // group will contain only the non-rejected media section. |
| 1068 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerChangedBundleOffererTagged) { |
| 1069 | MediaSessionOptions opts; |
| 1070 | opts.bundle_enabled = true; |
| 1071 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1072 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1073 | &opts); |
| 1074 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1075 | std::unique_ptr<SessionDescription> answer = |
| 1076 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1077 | |
| 1078 | // Reject the audio m= section and add a video m= section. |
| 1079 | opts.media_description_options[0].stopped = true; |
| 1080 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1081 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1082 | &opts); |
| 1083 | std::unique_ptr<SessionDescription> reoffer = |
| 1084 | f1_.CreateOffer(opts, offer.get()); |
| 1085 | std::unique_ptr<SessionDescription> reanswer = |
| 1086 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1087 | |
| 1088 | const cricket::ContentGroup* bundle_group = |
| 1089 | reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1090 | ASSERT_TRUE(bundle_group); |
| 1091 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 1092 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 1093 | } |
| 1094 | |
| 1095 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1096 | // and there is still a non-rejected media section that was in the initial |
| 1097 | // offer, then the ICE credentials do not change in the reoffer offerer-tagged |
| 1098 | // media section. |
| 1099 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1100 | ReOfferChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1101 | MediaSessionOptions opts; |
| 1102 | opts.bundle_enabled = true; |
| 1103 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 1104 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1105 | std::unique_ptr<SessionDescription> answer = |
| 1106 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1107 | |
| 1108 | // Reject the audio m= section. |
| 1109 | opts.media_description_options[0].stopped = true; |
| 1110 | std::unique_ptr<SessionDescription> reoffer = |
| 1111 | f1_.CreateOffer(opts, offer.get()); |
| 1112 | |
| 1113 | const TransportDescription* offer_tagged = |
| 1114 | offer->GetTransportDescriptionByName("audio"); |
| 1115 | ASSERT_TRUE(offer_tagged); |
| 1116 | const TransportDescription* reoffer_tagged = |
| 1117 | reoffer->GetTransportDescriptionByName("video"); |
| 1118 | ASSERT_TRUE(reoffer_tagged); |
| 1119 | EXPECT_EQ(offer_tagged->ice_ufrag, reoffer_tagged->ice_ufrag); |
| 1120 | EXPECT_EQ(offer_tagged->ice_pwd, reoffer_tagged->ice_pwd); |
| 1121 | } |
| 1122 | |
| 1123 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1124 | // and there is still a non-rejected media section that was in the initial |
| 1125 | // offer, then the ICE credentials do not change in the reanswer answerer-tagged |
| 1126 | // media section. |
| 1127 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1128 | ReAnswerChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1129 | MediaSessionOptions opts; |
| 1130 | opts.bundle_enabled = true; |
| 1131 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 1132 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1133 | std::unique_ptr<SessionDescription> answer = |
| 1134 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1135 | |
| 1136 | // Reject the audio m= section. |
| 1137 | opts.media_description_options[0].stopped = true; |
| 1138 | std::unique_ptr<SessionDescription> reoffer = |
| 1139 | f1_.CreateOffer(opts, offer.get()); |
| 1140 | std::unique_ptr<SessionDescription> reanswer = |
| 1141 | f2_.CreateAnswer(reoffer.get(), opts, answer.get()); |
| 1142 | |
| 1143 | const TransportDescription* answer_tagged = |
| 1144 | answer->GetTransportDescriptionByName("audio"); |
| 1145 | ASSERT_TRUE(answer_tagged); |
| 1146 | const TransportDescription* reanswer_tagged = |
| 1147 | reanswer->GetTransportDescriptionByName("video"); |
| 1148 | ASSERT_TRUE(reanswer_tagged); |
| 1149 | EXPECT_EQ(answer_tagged->ice_ufrag, reanswer_tagged->ice_ufrag); |
| 1150 | EXPECT_EQ(answer_tagged->ice_pwd, reanswer_tagged->ice_pwd); |
| 1151 | } |
| 1152 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1153 | // Create an audio, video offer without legacy StreamParams. |
| 1154 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1155 | TestCreateOfferWithoutLegacyStreams) { |
| 1156 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1157 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1158 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1159 | ASSERT_TRUE(offer.get() != NULL); |
| 1160 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 1161 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 1162 | ASSERT_TRUE(ac != NULL); |
| 1163 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1164 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1165 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1166 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1167 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1168 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1171 | // Creates an audio+video sendonly offer. |
| 1172 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSendOnlyOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1173 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1174 | AddAudioVideoSections(RtpTransceiverDirection::kSendOnly, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1175 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 1176 | {kMediaStream1}, 1, &opts); |
| 1177 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 1178 | {kMediaStream1}, 1, &opts); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1179 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1180 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1181 | ASSERT_TRUE(offer.get() != NULL); |
| 1182 | EXPECT_EQ(2u, offer->contents().size()); |
| 1183 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[0], MEDIA_TYPE_AUDIO)); |
| 1184 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1185 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1186 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1187 | GetMediaDirection(&offer->contents()[0])); |
| 1188 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1189 | GetMediaDirection(&offer->contents()[1])); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1192 | // Verifies that the order of the media contents in the current |
| 1193 | // SessionDescription is preserved in the new SessionDescription. |
| 1194 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { |
| 1195 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1196 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1197 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1198 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1199 | ASSERT_TRUE(offer1.get() != NULL); |
| 1200 | EXPECT_EQ(1u, offer1->contents().size()); |
| 1201 | EXPECT_TRUE(IsMediaContentOfType(&offer1->contents()[0], MEDIA_TYPE_DATA)); |
| 1202 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1203 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1204 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1205 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1206 | std::unique_ptr<SessionDescription> offer2( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1207 | f1_.CreateOffer(opts, offer1.get())); |
| 1208 | ASSERT_TRUE(offer2.get() != NULL); |
| 1209 | EXPECT_EQ(2u, offer2->contents().size()); |
| 1210 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[0], MEDIA_TYPE_DATA)); |
| 1211 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1212 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1213 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1214 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1215 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1216 | std::unique_ptr<SessionDescription> offer3( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1217 | f1_.CreateOffer(opts, offer2.get())); |
| 1218 | ASSERT_TRUE(offer3.get() != NULL); |
| 1219 | EXPECT_EQ(3u, offer3->contents().size()); |
| 1220 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[0], MEDIA_TYPE_DATA)); |
| 1221 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1222 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[2], MEDIA_TYPE_AUDIO)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1225 | // Create a typical audio answer, and ensure it matches what we expect. |
| 1226 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswer) { |
| 1227 | f1_.set_secure(SEC_ENABLED); |
| 1228 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1229 | std::unique_ptr<SessionDescription> offer = |
| 1230 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1231 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1232 | std::unique_ptr<SessionDescription> answer = |
| 1233 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1234 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1235 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1236 | ASSERT_TRUE(ac != NULL); |
| 1237 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1238 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1239 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1240 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1241 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1242 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1243 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1244 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1245 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1246 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1249 | // Create a typical audio answer with GCM ciphers enabled, and ensure it |
| 1250 | // matches what we expect. |
| 1251 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { |
| 1252 | f1_.set_secure(SEC_ENABLED); |
| 1253 | f2_.set_secure(SEC_ENABLED); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1254 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1255 | opts.crypto_options.srtp.enable_gcm_crypto_suites = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1256 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1257 | ASSERT_TRUE(offer.get() != NULL); |
Philipp Hancke | 1aec2bf | 2020-05-12 10:11:27 +0200 | [diff] [blame] | 1258 | for (cricket::ContentInfo& content : offer->contents()) { |
| 1259 | auto cryptos = content.media_description()->cryptos(); |
| 1260 | PreferGcmCryptoParameters(&cryptos); |
| 1261 | content.media_description()->set_cryptos(cryptos); |
| 1262 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1263 | std::unique_ptr<SessionDescription> answer = |
| 1264 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1265 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1266 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1267 | ASSERT_TRUE(ac != NULL); |
| 1268 | ASSERT_TRUE(vc == NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1269 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1270 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1271 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1272 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1273 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1274 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1275 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1276 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1277 | EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1280 | // Create a typical video answer, and ensure it matches what we expect. |
| 1281 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { |
| 1282 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1283 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1284 | f1_.set_secure(SEC_ENABLED); |
| 1285 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1286 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1287 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1288 | std::unique_ptr<SessionDescription> answer = |
| 1289 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1290 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1291 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1292 | ASSERT_TRUE(ac != NULL); |
| 1293 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1294 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1295 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1296 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1297 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1298 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1299 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1300 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1301 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1302 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1303 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1304 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1305 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1306 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 1307 | EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1308 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1309 | EXPECT_EQ(cricket::kMediaProtocolSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1312 | // Create a typical video answer with GCM ciphers enabled, and ensure it |
| 1313 | // matches what we expect. |
| 1314 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcm) { |
| 1315 | TestVideoGcmCipher(true, true); |
| 1316 | } |
| 1317 | |
| 1318 | // Create a typical video answer with GCM ciphers enabled for the offer only, |
| 1319 | // and ensure it matches what we expect. |
| 1320 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmOffer) { |
| 1321 | TestVideoGcmCipher(true, false); |
| 1322 | } |
| 1323 | |
| 1324 | // Create a typical video answer with GCM ciphers enabled for the answer only, |
| 1325 | // and ensure it matches what we expect. |
| 1326 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmAnswer) { |
| 1327 | TestVideoGcmCipher(false, true); |
| 1328 | } |
| 1329 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1330 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1331 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1332 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1333 | f1_.set_secure(SEC_ENABLED); |
| 1334 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1335 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1336 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1337 | std::unique_ptr<SessionDescription> answer = |
| 1338 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1339 | const ContentInfo* ac = answer->GetContentByName("audio"); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1340 | const ContentInfo* dc = answer->GetContentByName("data"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1341 | ASSERT_TRUE(ac != NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1342 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1343 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1344 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1345 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1346 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1347 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1348 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1349 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1350 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1351 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1352 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1353 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1354 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1355 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1356 | EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1357 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1358 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1361 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1362 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1363 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1364 | opts.crypto_options.srtp.enable_gcm_crypto_suites = true; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1365 | f1_.set_secure(SEC_ENABLED); |
| 1366 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1367 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1368 | ASSERT_TRUE(offer.get() != NULL); |
Philipp Hancke | 1aec2bf | 2020-05-12 10:11:27 +0200 | [diff] [blame] | 1369 | for (cricket::ContentInfo& content : offer->contents()) { |
| 1370 | auto cryptos = content.media_description()->cryptos(); |
| 1371 | PreferGcmCryptoParameters(&cryptos); |
| 1372 | content.media_description()->set_cryptos(cryptos); |
| 1373 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1374 | std::unique_ptr<SessionDescription> answer = |
| 1375 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1376 | const ContentInfo* ac = answer->GetContentByName("audio"); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1377 | const ContentInfo* dc = answer->GetContentByName("data"); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1378 | ASSERT_TRUE(ac != NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1379 | ASSERT_TRUE(dc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1380 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1381 | EXPECT_EQ(MediaProtocolType::kRtp, dc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1382 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1383 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1384 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1385 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1386 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1387 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1388 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1389 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuiteGcm); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1390 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1391 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1392 | EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1393 | EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 1394 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuiteGcm); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1395 | EXPECT_EQ(cricket::kMediaProtocolSavpf, dcd->protocol()); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1396 | } |
| 1397 | |
Harald Alvestrand | c5effc2 | 2019-06-11 11:46:59 +0200 | [diff] [blame] | 1398 | // The use_sctpmap flag should be set in an Sctp DataContentDescription by |
| 1399 | // default. The answer's use_sctpmap flag should match the offer's. |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1400 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { |
| 1401 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1402 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1403 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1404 | ASSERT_TRUE(offer.get() != NULL); |
| 1405 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1406 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1407 | SctpDataContentDescription* dcd_offer = |
| 1408 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1409 | EXPECT_TRUE(dcd_offer->use_sctpmap()); |
| 1410 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1411 | std::unique_ptr<SessionDescription> answer = |
| 1412 | f2_.CreateAnswer(offer.get(), opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1413 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1414 | ASSERT_TRUE(dc_answer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1415 | const SctpDataContentDescription* dcd_answer = |
| 1416 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1417 | EXPECT_TRUE(dcd_answer->use_sctpmap()); |
| 1418 | } |
| 1419 | |
| 1420 | // The answer's use_sctpmap flag should match the offer's. |
| 1421 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerWithoutSctpmap) { |
| 1422 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1423 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1424 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1425 | ASSERT_TRUE(offer.get() != NULL); |
| 1426 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1427 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1428 | SctpDataContentDescription* dcd_offer = |
| 1429 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1430 | dcd_offer->set_use_sctpmap(false); |
| 1431 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1432 | std::unique_ptr<SessionDescription> answer = |
| 1433 | f2_.CreateAnswer(offer.get(), opts, NULL); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1434 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1435 | ASSERT_TRUE(dc_answer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1436 | const SctpDataContentDescription* dcd_answer = |
| 1437 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 1438 | EXPECT_FALSE(dcd_answer->use_sctpmap()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1441 | // Test that a valid answer will be created for "DTLS/SCTP", "UDP/DTLS/SCTP" |
| 1442 | // and "TCP/DTLS/SCTP" offers. |
| 1443 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1444 | TestCreateDataAnswerToDifferentOfferedProtos) { |
| 1445 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1446 | // test). |
| 1447 | f1_.set_secure(SEC_ENABLED); |
| 1448 | f2_.set_secure(SEC_ENABLED); |
| 1449 | tdf1_.set_secure(SEC_ENABLED); |
| 1450 | tdf2_.set_secure(SEC_ENABLED); |
| 1451 | |
| 1452 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1453 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1454 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1455 | ASSERT_TRUE(offer.get() != nullptr); |
| 1456 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1457 | ASSERT_TRUE(dc_offer != nullptr); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1458 | SctpDataContentDescription* dcd_offer = |
| 1459 | dc_offer->media_description()->as_sctp(); |
| 1460 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1461 | |
| 1462 | std::vector<std::string> protos = {"DTLS/SCTP", "UDP/DTLS/SCTP", |
| 1463 | "TCP/DTLS/SCTP"}; |
| 1464 | for (const std::string& proto : protos) { |
| 1465 | dcd_offer->set_protocol(proto); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1466 | std::unique_ptr<SessionDescription> answer = |
| 1467 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1468 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1469 | ASSERT_TRUE(dc_answer != nullptr); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1470 | const SctpDataContentDescription* dcd_answer = |
| 1471 | dc_answer->media_description()->as_sctp(); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 1472 | EXPECT_FALSE(dc_answer->rejected); |
| 1473 | EXPECT_EQ(proto, dcd_answer->protocol()); |
| 1474 | } |
| 1475 | } |
| 1476 | |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 1477 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1478 | TestCreateDataAnswerToOfferWithDefinedMessageSize) { |
| 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(1234); |
| 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(1234, dcd_answer->max_message_size()); |
| 1504 | } |
| 1505 | |
| 1506 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1507 | TestCreateDataAnswerToOfferWithZeroMessageSize) { |
| 1508 | // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1509 | // test). |
| 1510 | f1_.set_secure(SEC_ENABLED); |
| 1511 | f2_.set_secure(SEC_ENABLED); |
| 1512 | tdf1_.set_secure(SEC_ENABLED); |
| 1513 | tdf2_.set_secure(SEC_ENABLED); |
| 1514 | |
| 1515 | MediaSessionOptions opts; |
| 1516 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
| 1517 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1518 | ASSERT_TRUE(offer.get() != nullptr); |
| 1519 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1520 | ASSERT_TRUE(dc_offer != nullptr); |
| 1521 | SctpDataContentDescription* dcd_offer = |
| 1522 | dc_offer->media_description()->as_sctp(); |
| 1523 | ASSERT_TRUE(dcd_offer); |
| 1524 | dcd_offer->set_max_message_size(0); |
| 1525 | std::unique_ptr<SessionDescription> answer = |
| 1526 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1527 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1528 | ASSERT_TRUE(dc_answer != nullptr); |
| 1529 | const SctpDataContentDescription* dcd_answer = |
| 1530 | dc_answer->media_description()->as_sctp(); |
| 1531 | EXPECT_FALSE(dc_answer->rejected); |
| 1532 | EXPECT_EQ(cricket::kSctpSendBufferSize, dcd_answer->max_message_size()); |
| 1533 | } |
| 1534 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1535 | // Verifies that the order of the media contents in the offer is preserved in |
| 1536 | // the answer. |
| 1537 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { |
| 1538 | MediaSessionOptions opts; |
| 1539 | |
| 1540 | // Creates a data only offer. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1541 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kSendRecv, &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1542 | std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1543 | ASSERT_TRUE(offer1.get() != NULL); |
| 1544 | |
| 1545 | // Appends audio to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1546 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1547 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1548 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1549 | std::unique_ptr<SessionDescription> offer2( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1550 | f1_.CreateOffer(opts, offer1.get())); |
| 1551 | ASSERT_TRUE(offer2.get() != NULL); |
| 1552 | |
| 1553 | // Appends video to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 1554 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1555 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1556 | &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1557 | std::unique_ptr<SessionDescription> offer3( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1558 | f1_.CreateOffer(opts, offer2.get())); |
| 1559 | ASSERT_TRUE(offer3.get() != NULL); |
| 1560 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1561 | std::unique_ptr<SessionDescription> answer = |
| 1562 | f2_.CreateAnswer(offer3.get(), opts, NULL); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1563 | ASSERT_TRUE(answer.get() != NULL); |
| 1564 | EXPECT_EQ(3u, answer->contents().size()); |
| 1565 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[0], MEDIA_TYPE_DATA)); |
| 1566 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[1], MEDIA_TYPE_AUDIO)); |
| 1567 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[2], MEDIA_TYPE_VIDEO)); |
| 1568 | } |
| 1569 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1570 | // TODO(deadbeef): Extend these tests to ensure the correct direction with other |
| 1571 | // answerer settings. |
| 1572 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1573 | // This test that the media direction is set to send/receive in an answer if |
| 1574 | // the offer is send receive. |
| 1575 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendReceiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1576 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendRecv, |
| 1577 | RtpTransceiverDirection::kSendRecv); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | // This test that the media direction is set to receive only in an answer if |
| 1581 | // the offer is send only. |
| 1582 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1583 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendOnly, |
| 1584 | RtpTransceiverDirection::kRecvOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | // This test that the media direction is set to send only in an answer if |
| 1588 | // the offer is recv only. |
| 1589 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToRecvOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1590 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kRecvOnly, |
| 1591 | RtpTransceiverDirection::kSendOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | // This test that the media direction is set to inactive in an answer if |
| 1595 | // the offer is inactive. |
| 1596 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToInactiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1597 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kInactive, |
| 1598 | RtpTransceiverDirection::kInactive); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | // Test that a data content with an unknown protocol is rejected in an answer. |
| 1602 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1603 | CreateDataAnswerToOfferWithUnknownProtocol) { |
| 1604 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1605 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1606 | f1_.set_secure(SEC_ENABLED); |
| 1607 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1608 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 1609 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1610 | ASSERT_TRUE(dc_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1611 | RtpDataContentDescription* dcd_offer = |
| 1612 | dc_offer->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1613 | ASSERT_TRUE(dcd_offer != NULL); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1614 | // Offer must be acceptable as an RTP protocol in order to be set. |
| 1615 | std::string protocol = "RTP/a weird unknown protocol"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1616 | dcd_offer->set_protocol(protocol); |
| 1617 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1618 | std::unique_ptr<SessionDescription> answer = |
| 1619 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | |
| 1621 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1622 | ASSERT_TRUE(dc_answer != NULL); |
| 1623 | EXPECT_TRUE(dc_answer->rejected); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1624 | const RtpDataContentDescription* dcd_answer = |
| 1625 | dc_answer->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1626 | ASSERT_TRUE(dcd_answer != NULL); |
| 1627 | EXPECT_EQ(protocol, dcd_answer->protocol()); |
| 1628 | } |
| 1629 | |
| 1630 | // Test that the media protocol is RTP/AVPF if DTLS and SDES are disabled. |
| 1631 | TEST_F(MediaSessionDescriptionFactoryTest, AudioOfferAnswerWithCryptoDisabled) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1632 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1633 | f1_.set_secure(SEC_DISABLED); |
| 1634 | f2_.set_secure(SEC_DISABLED); |
| 1635 | tdf1_.set_secure(SEC_DISABLED); |
| 1636 | tdf2_.set_secure(SEC_DISABLED); |
| 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 | const AudioContentDescription* offer_acd = |
| 1640 | GetFirstAudioContentDescription(offer.get()); |
| 1641 | ASSERT_TRUE(offer_acd != NULL); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1642 | EXPECT_EQ(cricket::kMediaProtocolAvpf, offer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1643 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1644 | std::unique_ptr<SessionDescription> answer = |
| 1645 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1646 | |
| 1647 | const ContentInfo* ac_answer = answer->GetContentByName("audio"); |
| 1648 | ASSERT_TRUE(ac_answer != NULL); |
| 1649 | EXPECT_FALSE(ac_answer->rejected); |
| 1650 | |
| 1651 | const AudioContentDescription* answer_acd = |
| 1652 | GetFirstAudioContentDescription(answer.get()); |
| 1653 | ASSERT_TRUE(answer_acd != NULL); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 1654 | EXPECT_EQ(cricket::kMediaProtocolAvpf, answer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | // Create a video offer and answer and ensure the RTP header extensions |
| 1658 | // matches what we expect. |
| 1659 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferAnswerWithRtpExtensions) { |
| 1660 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1661 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1662 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1663 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1664 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1665 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1666 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1667 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1668 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1669 | std::unique_ptr<SessionDescription> answer = |
| 1670 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1671 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1672 | EXPECT_EQ( |
| 1673 | MAKE_VECTOR(kAudioRtpExtension1), |
| 1674 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1675 | EXPECT_EQ( |
| 1676 | MAKE_VECTOR(kVideoRtpExtension1), |
| 1677 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1678 | EXPECT_EQ( |
| 1679 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1680 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1681 | EXPECT_EQ( |
| 1682 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1683 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Johannes Kron | ce8e867 | 2019-02-22 13:06:44 +0100 | [diff] [blame] | 1686 | // Create a audio/video offer and answer and ensure that the |
| 1687 | // TransportSequenceNumber RTP header extensions are handled correctly. 02 is |
| 1688 | // supported and should take precedence even though not listed among locally |
| 1689 | // supported extensions. |
| 1690 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1691 | TestOfferAnswerWithTransportSequenceNumberInOffer) { |
| 1692 | TestTransportSequenceNumberNegotiation( |
| 1693 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1694 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Offer. |
| 1695 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01)); // Expected answer. |
| 1696 | } |
| 1697 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1698 | TestOfferAnswerWithTransportSequenceNumber01And02InOffer) { |
| 1699 | TestTransportSequenceNumberNegotiation( |
| 1700 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1701 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Offer. |
| 1702 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1703 | } |
| 1704 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1705 | TestOfferAnswerWithTransportSequenceNumber02InOffer) { |
| 1706 | TestTransportSequenceNumberNegotiation( |
| 1707 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1708 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Offer. |
| 1709 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1710 | } |
| 1711 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1712 | TEST_F(MediaSessionDescriptionFactoryTest, |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1713 | TestNegotiateFrameDescriptorWhenUnexposedLocally) { |
| 1714 | MediaSessionOptions opts; |
| 1715 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1716 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1717 | const auto offered = MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00); |
| 1718 | f1_.set_audio_rtp_header_extensions(offered); |
| 1719 | f1_.set_video_rtp_header_extensions(offered); |
| 1720 | const auto local = MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01); |
| 1721 | f2_.set_audio_rtp_header_extensions(local); |
| 1722 | f2_.set_video_rtp_header_extensions(local); |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1723 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1724 | std::unique_ptr<SessionDescription> answer = |
| 1725 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1726 | EXPECT_THAT( |
| 1727 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1728 | ElementsAreArray(offered)); |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1729 | EXPECT_THAT( |
| 1730 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1731 | ElementsAreArray(offered)); |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1735 | TestNegotiateFrameDescriptorWhenExposedLocally) { |
| 1736 | MediaSessionOptions opts; |
| 1737 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1738 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1739 | const auto offered = MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00); |
| 1740 | f1_.set_audio_rtp_header_extensions(offered); |
| 1741 | f1_.set_video_rtp_header_extensions(offered); |
| 1742 | const auto local = MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00); |
| 1743 | f2_.set_audio_rtp_header_extensions(local); |
| 1744 | f2_.set_video_rtp_header_extensions(local); |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1745 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1746 | std::unique_ptr<SessionDescription> answer = |
| 1747 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1748 | EXPECT_THAT( |
| 1749 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1750 | ElementsAreArray(offered)); |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1751 | EXPECT_THAT( |
| 1752 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1753 | ElementsAreArray(offered)); |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | TEST_F(MediaSessionDescriptionFactoryTest, |
Danil Chapovalov | 5f999a7 | 2020-02-20 16:39:05 +0100 | [diff] [blame] | 1757 | NegotiateDependencyDescriptorWhenUnexposedLocally) { |
| 1758 | MediaSessionOptions opts; |
| 1759 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1760 | |
| 1761 | RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); |
Markus Handell | 71db9ac | 2020-06-08 19:48:49 +0200 | [diff] [blame] | 1762 | RtpExtension local_tsn(RtpExtension::kTransportSequenceNumberUri, 5); |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1763 | f1_.set_video_rtp_header_extensions({offer_dd}); |
| 1764 | f2_.set_video_rtp_header_extensions({local_tsn}); |
| 1765 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Danil Chapovalov | 5f999a7 | 2020-02-20 16:39:05 +0100 | [diff] [blame] | 1766 | std::unique_ptr<SessionDescription> answer = |
| 1767 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1768 | EXPECT_THAT( |
| 1769 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1770 | ElementsAre(offer_dd)); |
| 1771 | } |
| 1772 | |
| 1773 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1774 | NegotiateDependencyDescriptorWhenExposedLocally) { |
| 1775 | MediaSessionOptions opts; |
| 1776 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1777 | |
| 1778 | RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); |
| 1779 | RtpExtension local_dd(RtpExtension::kDependencyDescriptorUri, 5); |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1780 | f1_.set_video_rtp_header_extensions({offer_dd}); |
| 1781 | f2_.set_video_rtp_header_extensions({local_dd}); |
Danil Chapovalov | 5f999a7 | 2020-02-20 16:39:05 +0100 | [diff] [blame] | 1782 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1783 | std::unique_ptr<SessionDescription> answer = |
| 1784 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1785 | EXPECT_THAT( |
| 1786 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1787 | ElementsAre(offer_dd)); |
| 1788 | } |
| 1789 | |
| 1790 | TEST_F(MediaSessionDescriptionFactoryTest, |
Minyue Li | 430e4a0 | 2020-03-10 10:59:37 +0100 | [diff] [blame] | 1791 | NegotiateAbsoluteCaptureTimeWhenUnexposedLocally) { |
| 1792 | MediaSessionOptions opts; |
| 1793 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1794 | |
| 1795 | const cricket::RtpHeaderExtensions offered_extensions = { |
| 1796 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 7)}; |
| 1797 | const cricket::RtpHeaderExtensions local_extensions = { |
| 1798 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, 5)}; |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1799 | f1_.set_video_rtp_header_extensions(offered_extensions); |
| 1800 | f1_.set_audio_rtp_header_extensions(offered_extensions); |
| 1801 | f2_.set_video_rtp_header_extensions(local_extensions); |
| 1802 | f2_.set_audio_rtp_header_extensions(local_extensions); |
| 1803 | |
Minyue Li | 430e4a0 | 2020-03-10 10:59:37 +0100 | [diff] [blame] | 1804 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1805 | std::unique_ptr<SessionDescription> answer = |
| 1806 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1807 | EXPECT_THAT( |
| 1808 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1809 | ElementsAreArray(offered_extensions)); |
| 1810 | EXPECT_THAT( |
| 1811 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1812 | ElementsAreArray(offered_extensions)); |
| 1813 | } |
| 1814 | |
| 1815 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1816 | NegotiateAbsoluteCaptureTimeWhenExposedLocally) { |
| 1817 | MediaSessionOptions opts; |
| 1818 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1819 | |
| 1820 | const cricket::RtpHeaderExtensions offered_extensions = { |
| 1821 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 7)}; |
| 1822 | const cricket::RtpHeaderExtensions local_extensions = { |
| 1823 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1824 | f1_.set_video_rtp_header_extensions(offered_extensions); |
| 1825 | f1_.set_audio_rtp_header_extensions(offered_extensions); |
| 1826 | f2_.set_video_rtp_header_extensions(local_extensions); |
| 1827 | f2_.set_audio_rtp_header_extensions(local_extensions); |
| 1828 | |
Minyue Li | 430e4a0 | 2020-03-10 10:59:37 +0100 | [diff] [blame] | 1829 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1830 | std::unique_ptr<SessionDescription> answer = |
| 1831 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1832 | EXPECT_THAT( |
| 1833 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1834 | ElementsAreArray(offered_extensions)); |
| 1835 | EXPECT_THAT( |
| 1836 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1837 | ElementsAreArray(offered_extensions)); |
| 1838 | } |
| 1839 | |
| 1840 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1841 | DoNotNegotiateAbsoluteCaptureTimeWhenNotOffered) { |
| 1842 | MediaSessionOptions opts; |
| 1843 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1844 | |
| 1845 | const cricket::RtpHeaderExtensions offered_extensions = { |
| 1846 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, 7)}; |
| 1847 | const cricket::RtpHeaderExtensions local_extensions = { |
| 1848 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1849 | f1_.set_video_rtp_header_extensions(offered_extensions); |
| 1850 | f1_.set_audio_rtp_header_extensions(offered_extensions); |
| 1851 | f2_.set_video_rtp_header_extensions(local_extensions); |
| 1852 | f2_.set_audio_rtp_header_extensions(local_extensions); |
| 1853 | |
Minyue Li | 430e4a0 | 2020-03-10 10:59:37 +0100 | [diff] [blame] | 1854 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 1855 | std::unique_ptr<SessionDescription> answer = |
| 1856 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
| 1857 | EXPECT_THAT( |
| 1858 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1859 | IsEmpty()); |
| 1860 | EXPECT_THAT( |
| 1861 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1862 | IsEmpty()); |
| 1863 | } |
| 1864 | |
| 1865 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1866 | TestOfferAnswerWithEncryptedRtpExtensionsBoth) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1867 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1868 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1869 | |
| 1870 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1871 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1872 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1873 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1874 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1875 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1876 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 1877 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1878 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1879 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1880 | std::unique_ptr<SessionDescription> answer = |
| 1881 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1882 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1883 | EXPECT_EQ( |
| 1884 | MAKE_VECTOR(kAudioRtpExtensionEncrypted1), |
| 1885 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1886 | EXPECT_EQ( |
| 1887 | MAKE_VECTOR(kVideoRtpExtensionEncrypted1), |
| 1888 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1889 | EXPECT_EQ( |
| 1890 | MAKE_VECTOR(kAudioRtpExtensionEncryptedAnswer), |
| 1891 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1892 | EXPECT_EQ( |
| 1893 | MAKE_VECTOR(kVideoRtpExtensionEncryptedAnswer), |
| 1894 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1898 | TestOfferAnswerWithEncryptedRtpExtensionsOffer) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1899 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1900 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1901 | |
| 1902 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1903 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1904 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1905 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1906 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1907 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 1908 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1909 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1910 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1911 | std::unique_ptr<SessionDescription> answer = |
| 1912 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1913 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1914 | EXPECT_EQ( |
| 1915 | MAKE_VECTOR(kAudioRtpExtensionEncrypted1), |
| 1916 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1917 | EXPECT_EQ( |
| 1918 | MAKE_VECTOR(kVideoRtpExtensionEncrypted1), |
| 1919 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1920 | EXPECT_EQ( |
| 1921 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1922 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1923 | EXPECT_EQ( |
| 1924 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1925 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1929 | TestOfferAnswerWithEncryptedRtpExtensionsAnswer) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1930 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1931 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1932 | |
| 1933 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1934 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 1935 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1936 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1937 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1938 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 1939 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1940 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1941 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1942 | std::unique_ptr<SessionDescription> answer = |
| 1943 | f2_.CreateAnswer(offer.get(), opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1944 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1945 | EXPECT_EQ( |
| 1946 | MAKE_VECTOR(kAudioRtpExtension1), |
| 1947 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1948 | EXPECT_EQ( |
| 1949 | MAKE_VECTOR(kVideoRtpExtension1), |
| 1950 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1951 | EXPECT_EQ( |
| 1952 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1953 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1954 | EXPECT_EQ( |
| 1955 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1956 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1959 | // Create an audio, video, data answer without legacy StreamParams. |
| 1960 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1961 | TestCreateAnswerWithoutLegacyStreams) { |
| 1962 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1963 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1964 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1965 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1966 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 1967 | std::unique_ptr<SessionDescription> answer = |
| 1968 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1969 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1970 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 1971 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 1972 | ASSERT_TRUE(ac != NULL); |
| 1973 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1974 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 1975 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 1976 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1977 | |
| 1978 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
| 1979 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1980 | EXPECT_FALSE(dcd->has_ssrcs()); // No StreamParams. |
| 1981 | } |
| 1982 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1983 | // Create a typical video answer, and ensure it matches what we expect. |
| 1984 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { |
| 1985 | MediaSessionOptions offer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1986 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &offer_opts); |
| 1987 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, |
| 1988 | &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1989 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1990 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1991 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
| 1992 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, |
| 1993 | &answer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1994 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1995 | std::unique_ptr<SessionDescription> offer; |
| 1996 | std::unique_ptr<SessionDescription> answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1997 | |
| 1998 | offer_opts.rtcp_mux_enabled = true; |
| 1999 | answer_opts.rtcp_mux_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2000 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 2001 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2002 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 2003 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2004 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2005 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 2006 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2007 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2008 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2009 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2010 | EXPECT_TRUE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2011 | EXPECT_TRUE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2012 | EXPECT_TRUE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2013 | EXPECT_TRUE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2014 | |
| 2015 | offer_opts.rtcp_mux_enabled = true; |
| 2016 | answer_opts.rtcp_mux_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2017 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 2018 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2019 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 2020 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2021 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2022 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 2023 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2024 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2025 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2026 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2027 | EXPECT_TRUE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2028 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2029 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2030 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2031 | |
| 2032 | offer_opts.rtcp_mux_enabled = false; |
| 2033 | answer_opts.rtcp_mux_enabled = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2034 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 2035 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2036 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 2037 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2038 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2039 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 2040 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2041 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2042 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2043 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2044 | EXPECT_FALSE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2045 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2046 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2047 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2048 | |
| 2049 | offer_opts.rtcp_mux_enabled = false; |
| 2050 | answer_opts.rtcp_mux_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2051 | offer = f1_.CreateOffer(offer_opts, NULL); |
| 2052 | answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2053 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 2054 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2055 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2056 | ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 2057 | ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2058 | ASSERT_TRUE(NULL != GetFirstRtpDataContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2059 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2060 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2061 | EXPECT_FALSE(GetFirstRtpDataContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2062 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2063 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2064 | EXPECT_FALSE(GetFirstRtpDataContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | // Create an audio-only answer to a video offer. |
| 2068 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerToVideo) { |
| 2069 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2070 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2071 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2072 | &opts); |
| 2073 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2074 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2075 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2076 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2077 | ASSERT_TRUE(offer.get() != NULL); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2078 | |
| 2079 | opts.media_description_options[1].stopped = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2080 | std::unique_ptr<SessionDescription> answer = |
| 2081 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2082 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2083 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 2084 | ASSERT_TRUE(ac != NULL); |
| 2085 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2086 | ASSERT_TRUE(vc->media_description() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2087 | EXPECT_TRUE(vc->rejected); |
| 2088 | } |
| 2089 | |
| 2090 | // Create an audio-only answer to an offer with data. |
| 2091 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateNoDataAnswerToDataOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2092 | MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2093 | opts.data_channel_type = cricket::DCT_RTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2094 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2095 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2096 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2097 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2098 | ASSERT_TRUE(offer.get() != NULL); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2099 | |
| 2100 | opts.media_description_options[1].stopped = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2101 | std::unique_ptr<SessionDescription> answer = |
| 2102 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2103 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2104 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 2105 | ASSERT_TRUE(ac != NULL); |
| 2106 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2107 | ASSERT_TRUE(dc->media_description() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2108 | EXPECT_TRUE(dc->rejected); |
| 2109 | } |
| 2110 | |
| 2111 | // Create an answer that rejects the contents which are rejected in the offer. |
| 2112 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2113 | CreateAnswerToOfferWithRejectedMedia) { |
| 2114 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2115 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 2116 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2117 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2118 | ASSERT_TRUE(offer.get() != NULL); |
| 2119 | ContentInfo* ac = offer->GetContentByName("audio"); |
| 2120 | ContentInfo* vc = offer->GetContentByName("video"); |
| 2121 | ContentInfo* dc = offer->GetContentByName("data"); |
| 2122 | ASSERT_TRUE(ac != NULL); |
| 2123 | ASSERT_TRUE(vc != NULL); |
| 2124 | ASSERT_TRUE(dc != NULL); |
| 2125 | ac->rejected = true; |
| 2126 | vc->rejected = true; |
| 2127 | dc->rejected = true; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2128 | std::unique_ptr<SessionDescription> answer = |
| 2129 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2130 | ac = answer->GetContentByName("audio"); |
| 2131 | vc = answer->GetContentByName("video"); |
| 2132 | dc = answer->GetContentByName("data"); |
| 2133 | ASSERT_TRUE(ac != NULL); |
| 2134 | ASSERT_TRUE(vc != NULL); |
| 2135 | ASSERT_TRUE(dc != NULL); |
| 2136 | EXPECT_TRUE(ac->rejected); |
| 2137 | EXPECT_TRUE(vc->rejected); |
| 2138 | EXPECT_TRUE(dc->rejected); |
| 2139 | } |
| 2140 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2141 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2142 | CreateAnswerSupportsMixedOneAndTwoByteHeaderExtensions) { |
| 2143 | MediaSessionOptions opts; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2144 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2145 | // Offer without request of mixed one- and two-byte header extensions. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2146 | offer->set_extmap_allow_mixed(false); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2147 | ASSERT_TRUE(offer.get() != NULL); |
| 2148 | std::unique_ptr<SessionDescription> answer_no_support( |
| 2149 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2150 | EXPECT_FALSE(answer_no_support->extmap_allow_mixed()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2151 | |
| 2152 | // Offer with request of mixed one- and two-byte header extensions. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2153 | offer->set_extmap_allow_mixed(true); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2154 | ASSERT_TRUE(offer.get() != NULL); |
| 2155 | std::unique_ptr<SessionDescription> answer_support( |
| 2156 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2157 | EXPECT_TRUE(answer_support->extmap_allow_mixed()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2161 | CreateAnswerSupportsMixedOneAndTwoByteHeaderExtensionsOnMediaLevel) { |
| 2162 | MediaSessionOptions opts; |
| 2163 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2164 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2165 | MediaContentDescription* video_offer = |
| 2166 | offer->GetContentDescriptionByName("video"); |
| 2167 | ASSERT_TRUE(video_offer); |
| 2168 | MediaContentDescription* audio_offer = |
| 2169 | offer->GetContentDescriptionByName("audio"); |
| 2170 | ASSERT_TRUE(audio_offer); |
| 2171 | |
| 2172 | // Explicit disable of mixed one-two byte header support in offer. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2173 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 2174 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2175 | |
| 2176 | ASSERT_TRUE(offer.get() != NULL); |
| 2177 | std::unique_ptr<SessionDescription> answer_no_support( |
| 2178 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 2179 | MediaContentDescription* video_answer = |
| 2180 | answer_no_support->GetContentDescriptionByName("video"); |
| 2181 | MediaContentDescription* audio_answer = |
| 2182 | answer_no_support->GetContentDescriptionByName("audio"); |
| 2183 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2184 | video_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2185 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2186 | audio_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2187 | |
| 2188 | // Enable mixed one-two byte header support in offer. |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2189 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
| 2190 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2191 | ASSERT_TRUE(offer.get() != NULL); |
| 2192 | std::unique_ptr<SessionDescription> answer_support( |
| 2193 | f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 2194 | video_answer = answer_support->GetContentDescriptionByName("video"); |
| 2195 | audio_answer = answer_support->GetContentDescriptionByName("audio"); |
| 2196 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2197 | video_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2198 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 2199 | audio_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 2200 | } |
| 2201 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2202 | // Create an audio and video offer with: |
| 2203 | // - one video track |
| 2204 | // - two audio tracks |
| 2205 | // - two data tracks |
| 2206 | // and ensure it matches what we expect. Also updates the initial offer by |
| 2207 | // adding a new video track and replaces one of the audio tracks. |
| 2208 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { |
| 2209 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2210 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2211 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2212 | {kMediaStream1}, 1, &opts); |
| 2213 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2214 | {kMediaStream1}, 1, &opts); |
| 2215 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2216 | {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2217 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2218 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kSendRecv, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2219 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack1, |
| 2220 | {kMediaStream1}, 1, &opts); |
| 2221 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack2, |
| 2222 | {kMediaStream1}, 1, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2223 | |
| 2224 | f1_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2225 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2226 | |
| 2227 | ASSERT_TRUE(offer.get() != NULL); |
| 2228 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 2229 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 2230 | const ContentInfo* dc = offer->GetContentByName("data"); |
| 2231 | ASSERT_TRUE(ac != NULL); |
| 2232 | ASSERT_TRUE(vc != NULL); |
| 2233 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2234 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 2235 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2236 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2237 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 2238 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2239 | |
| 2240 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2241 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2242 | EXPECT_EQ(audio_streams[0].cname, audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2243 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2244 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2245 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2246 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2247 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2248 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2249 | |
| 2250 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2251 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2252 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2253 | |
| 2254 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2255 | EXPECT_EQ(f1_.video_sendrecv_codecs(), vcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2256 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2257 | |
| 2258 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2259 | ASSERT_EQ(1U, video_streams.size()); |
| 2260 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2261 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2262 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2263 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2264 | |
| 2265 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2266 | EXPECT_EQ(f1_.rtp_data_codecs(), dcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2267 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2268 | |
| 2269 | const StreamParamsVec& data_streams = dcd->streams(); |
| 2270 | ASSERT_EQ(2U, data_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2271 | EXPECT_EQ(data_streams[0].cname, data_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2272 | EXPECT_EQ(kDataTrack1, data_streams[0].id); |
| 2273 | ASSERT_EQ(1U, data_streams[0].ssrcs.size()); |
| 2274 | EXPECT_NE(0U, data_streams[0].ssrcs[0]); |
| 2275 | EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 2276 | ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 2277 | EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 2278 | |
| 2279 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2280 | dcd->bandwidth()); // default bandwidth (auto) |
| 2281 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2282 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2283 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2284 | // Update the offer. Add a new video track that is not synched to the |
| 2285 | // other tracks and replace audio track 2 with audio track 3. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2286 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2287 | {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2288 | DetachSenderFromMediaSection("audio", kAudioTrack2, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2289 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack3, |
| 2290 | {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2291 | DetachSenderFromMediaSection("data", kDataTrack2, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2292 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack3, |
| 2293 | {kMediaStream1}, 1, &opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2294 | std::unique_ptr<SessionDescription> updated_offer( |
| 2295 | f1_.CreateOffer(opts, offer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2296 | |
| 2297 | ASSERT_TRUE(updated_offer.get() != NULL); |
| 2298 | ac = updated_offer->GetContentByName("audio"); |
| 2299 | vc = updated_offer->GetContentByName("video"); |
| 2300 | dc = updated_offer->GetContentByName("data"); |
| 2301 | ASSERT_TRUE(ac != NULL); |
| 2302 | ASSERT_TRUE(vc != NULL); |
| 2303 | ASSERT_TRUE(dc != NULL); |
| 2304 | const AudioContentDescription* updated_acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2305 | ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2306 | const VideoContentDescription* updated_vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2307 | vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2308 | const RtpDataContentDescription* updated_dcd = |
| 2309 | dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2310 | |
| 2311 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2312 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2313 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2314 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
| 2315 | EXPECT_EQ(dcd->type(), updated_dcd->type()); |
| 2316 | EXPECT_EQ(dcd->codecs(), updated_dcd->codecs()); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2317 | ASSERT_CRYPTO(updated_acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2318 | EXPECT_TRUE(CompareCryptoParams(acd->cryptos(), updated_acd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2319 | ASSERT_CRYPTO(updated_vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2320 | EXPECT_TRUE(CompareCryptoParams(vcd->cryptos(), updated_vcd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2321 | ASSERT_CRYPTO(updated_dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2322 | EXPECT_TRUE(CompareCryptoParams(dcd->cryptos(), updated_dcd->cryptos())); |
| 2323 | |
| 2324 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2325 | ASSERT_EQ(2U, updated_audio_streams.size()); |
| 2326 | EXPECT_EQ(audio_streams[0], updated_audio_streams[0]); |
| 2327 | EXPECT_EQ(kAudioTrack3, updated_audio_streams[1].id); // New audio track. |
| 2328 | ASSERT_EQ(1U, updated_audio_streams[1].ssrcs.size()); |
| 2329 | EXPECT_NE(0U, updated_audio_streams[1].ssrcs[0]); |
| 2330 | EXPECT_EQ(updated_audio_streams[0].cname, updated_audio_streams[1].cname); |
| 2331 | |
| 2332 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2333 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2334 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2335 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2336 | // All the media streams in one PeerConnection share one RTCP CNAME. |
| 2337 | 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] | 2338 | |
| 2339 | const StreamParamsVec& updated_data_streams = updated_dcd->streams(); |
| 2340 | ASSERT_EQ(2U, updated_data_streams.size()); |
| 2341 | EXPECT_EQ(data_streams[0], updated_data_streams[0]); |
| 2342 | EXPECT_EQ(kDataTrack3, updated_data_streams[1].id); // New data track. |
| 2343 | ASSERT_EQ(1U, updated_data_streams[1].ssrcs.size()); |
| 2344 | EXPECT_NE(0U, updated_data_streams[1].ssrcs[0]); |
| 2345 | EXPECT_EQ(updated_data_streams[0].cname, updated_data_streams[1].cname); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2346 | // The stream correctly got the CNAME from the MediaSessionOptions. |
| 2347 | // The Expected RTCP CNAME is the default one as we are using the default |
| 2348 | // MediaSessionOptions. |
| 2349 | EXPECT_EQ(updated_data_streams[0].cname, cricket::kDefaultRtcpCname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2352 | // Create an offer with simulcast video stream. |
| 2353 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { |
| 2354 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2355 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2356 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2357 | &opts); |
| 2358 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2359 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2360 | &opts); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2361 | const int num_sim_layers = 3; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2362 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2363 | {kMediaStream1}, num_sim_layers, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2364 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2365 | |
| 2366 | ASSERT_TRUE(offer.get() != NULL); |
| 2367 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 2368 | ASSERT_TRUE(vc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2369 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2370 | |
| 2371 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2372 | ASSERT_EQ(1U, video_streams.size()); |
| 2373 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2374 | const SsrcGroup* sim_ssrc_group = |
| 2375 | video_streams[0].get_ssrc_group(cricket::kSimSsrcGroupSemantics); |
| 2376 | ASSERT_TRUE(sim_ssrc_group != NULL); |
| 2377 | EXPECT_EQ(static_cast<size_t>(num_sim_layers), sim_ssrc_group->ssrcs.size()); |
| 2378 | } |
| 2379 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2380 | MATCHER(RidDescriptionEquals, "Verifies that two RidDescriptions are equal.") { |
| 2381 | const RidDescription& rid1 = ::testing::get<0>(arg); |
| 2382 | const RidDescription& rid2 = ::testing::get<1>(arg); |
| 2383 | return rid1.rid == rid2.rid && rid1.direction == rid2.direction; |
| 2384 | } |
| 2385 | |
| 2386 | static void CheckSimulcastInSessionDescription( |
| 2387 | const SessionDescription* description, |
| 2388 | const std::string& content_name, |
| 2389 | const std::vector<RidDescription>& send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2390 | const SimulcastLayerList& send_layers) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2391 | ASSERT_NE(description, nullptr); |
| 2392 | const ContentInfo* content = description->GetContentByName(content_name); |
| 2393 | ASSERT_NE(content, nullptr); |
| 2394 | const MediaContentDescription* cd = content->media_description(); |
| 2395 | ASSERT_NE(cd, nullptr); |
| 2396 | const StreamParamsVec& streams = cd->streams(); |
| 2397 | ASSERT_THAT(streams, SizeIs(1)); |
| 2398 | const StreamParams& stream = streams[0]; |
| 2399 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2400 | EXPECT_TRUE(stream.has_rids()); |
| 2401 | const std::vector<RidDescription> rids = stream.rids(); |
| 2402 | |
| 2403 | EXPECT_THAT(rids, Pointwise(RidDescriptionEquals(), send_rids)); |
| 2404 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2405 | EXPECT_TRUE(cd->HasSimulcast()); |
| 2406 | const SimulcastDescription& simulcast = cd->simulcast_description(); |
| 2407 | EXPECT_THAT(simulcast.send_layers(), SizeIs(send_layers.size())); |
| 2408 | EXPECT_THAT(simulcast.send_layers(), Pointwise(Eq(), send_layers)); |
| 2409 | |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2410 | ASSERT_THAT(simulcast.receive_layers().GetAllLayers(), SizeIs(0)); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | // Create an offer with spec-compliant simulcast video stream. |
| 2414 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastOffer) { |
| 2415 | MediaSessionOptions opts; |
| 2416 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2417 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2418 | &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2419 | std::vector<RidDescription> send_rids; |
| 2420 | send_rids.push_back(RidDescription("f", RidDirection::kSend)); |
| 2421 | send_rids.push_back(RidDescription("h", RidDirection::kSend)); |
| 2422 | send_rids.push_back(RidDescription("q", RidDirection::kSend)); |
| 2423 | SimulcastLayerList simulcast_layers; |
| 2424 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[0].rid, false)); |
| 2425 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[1].rid, true)); |
| 2426 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[2].rid, false)); |
| 2427 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2428 | {kMediaStream1}, send_rids, |
| 2429 | simulcast_layers, 0, &opts); |
| 2430 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2431 | |
| 2432 | CheckSimulcastInSessionDescription(offer.get(), "video", send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2433 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | // Create an offer that signals RIDs (not SSRCs) without Simulcast. |
| 2437 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2438 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferWithRidsNoSimulcast) { |
| 2439 | MediaSessionOptions opts; |
| 2440 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2441 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2442 | &opts); |
| 2443 | RidDescription rid("f", RidDirection::kSend); |
| 2444 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2445 | {kMediaStream1}, {rid}, |
| 2446 | SimulcastLayerList(), 0, &opts); |
| 2447 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2448 | |
| 2449 | ASSERT_NE(offer.get(), nullptr); |
| 2450 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2451 | ASSERT_NE(content, nullptr); |
| 2452 | const MediaContentDescription* cd = content->media_description(); |
| 2453 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2454 | const StreamParamsVec& streams = cd->streams(); |
| 2455 | ASSERT_THAT(streams, SizeIs(1)); |
| 2456 | const StreamParams& stream = streams[0]; |
| 2457 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2458 | EXPECT_FALSE(stream.has_rids()); |
| 2459 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2460 | } |
| 2461 | |
| 2462 | // Create an answer with spec-compliant simulcast video stream. |
| 2463 | // In this scenario, the SFU is the caller requesting that we send Simulcast. |
| 2464 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastAnswer) { |
| 2465 | MediaSessionOptions offer_opts; |
| 2466 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2467 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2468 | &offer_opts); |
| 2469 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2470 | {kMediaStream1}, 1, &offer_opts); |
| 2471 | std::unique_ptr<SessionDescription> offer = |
| 2472 | f1_.CreateOffer(offer_opts, nullptr); |
| 2473 | |
| 2474 | MediaSessionOptions answer_opts; |
| 2475 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2476 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2477 | &answer_opts); |
| 2478 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2479 | std::vector<RidDescription> rid_descriptions{ |
| 2480 | RidDescription("f", RidDirection::kSend), |
| 2481 | RidDescription("h", RidDirection::kSend), |
| 2482 | RidDescription("q", RidDirection::kSend), |
| 2483 | }; |
| 2484 | SimulcastLayerList simulcast_layers; |
| 2485 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[0].rid, false)); |
| 2486 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[1].rid, true)); |
| 2487 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[2].rid, false)); |
| 2488 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2489 | {kMediaStream1}, rid_descriptions, |
| 2490 | simulcast_layers, 0, &answer_opts); |
| 2491 | std::unique_ptr<SessionDescription> answer = |
| 2492 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
| 2493 | |
| 2494 | CheckSimulcastInSessionDescription(answer.get(), "video", rid_descriptions, |
Amit Hilbuch | b7446ed | 2019-01-28 12:25:25 -0800 | [diff] [blame] | 2495 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | // Create an answer that signals RIDs (not SSRCs) without Simulcast. |
| 2499 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2500 | // Note that RID Direction is not the same as the transceiver direction. |
| 2501 | TEST_F(MediaSessionDescriptionFactoryTest, TestAnswerWithRidsNoSimulcast) { |
| 2502 | MediaSessionOptions offer_opts; |
| 2503 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2504 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2505 | &offer_opts); |
| 2506 | RidDescription rid_offer("f", RidDirection::kSend); |
| 2507 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2508 | {kMediaStream1}, {rid_offer}, |
| 2509 | SimulcastLayerList(), 0, &offer_opts); |
| 2510 | std::unique_ptr<SessionDescription> offer = |
| 2511 | f1_.CreateOffer(offer_opts, nullptr); |
| 2512 | |
| 2513 | MediaSessionOptions answer_opts; |
| 2514 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2515 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2516 | &answer_opts); |
| 2517 | |
| 2518 | RidDescription rid_answer("f", RidDirection::kReceive); |
| 2519 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2520 | {kMediaStream1}, {rid_answer}, |
| 2521 | SimulcastLayerList(), 0, &answer_opts); |
| 2522 | std::unique_ptr<SessionDescription> answer = |
| 2523 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
| 2524 | |
| 2525 | ASSERT_NE(answer.get(), nullptr); |
| 2526 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2527 | ASSERT_NE(content, nullptr); |
| 2528 | const MediaContentDescription* cd = content->media_description(); |
| 2529 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2530 | const StreamParamsVec& streams = cd->streams(); |
| 2531 | ASSERT_THAT(streams, SizeIs(1)); |
| 2532 | const StreamParams& stream = streams[0]; |
| 2533 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2534 | EXPECT_FALSE(stream.has_rids()); |
| 2535 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2536 | } |
| 2537 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2538 | // Create an audio and video answer to a standard video offer with: |
| 2539 | // - one video track |
| 2540 | // - two audio tracks |
| 2541 | // - two data tracks |
| 2542 | // and ensure it matches what we expect. Also updates the initial answer by |
| 2543 | // adding a new video track and removes one of the audio tracks. |
| 2544 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { |
| 2545 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2546 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2547 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2548 | &offer_opts); |
| 2549 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2550 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2551 | &offer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2552 | offer_opts.data_channel_type = cricket::DCT_RTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2553 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2554 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2555 | &offer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2556 | f1_.set_secure(SEC_ENABLED); |
| 2557 | f2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2558 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(offer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2559 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2560 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2561 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2562 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2563 | &answer_opts); |
| 2564 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2565 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2566 | &answer_opts); |
| 2567 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2568 | {kMediaStream1}, 1, &answer_opts); |
| 2569 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2570 | {kMediaStream1}, 1, &answer_opts); |
| 2571 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2572 | {kMediaStream1}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2573 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2574 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", |
| 2575 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2576 | &answer_opts); |
| 2577 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack1, |
| 2578 | {kMediaStream1}, 1, &answer_opts); |
| 2579 | AttachSenderToMediaDescriptionOptions("data", MEDIA_TYPE_DATA, kDataTrack2, |
| 2580 | {kMediaStream1}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2581 | answer_opts.data_channel_type = cricket::DCT_RTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2582 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2583 | std::unique_ptr<SessionDescription> answer = |
| 2584 | f2_.CreateAnswer(offer.get(), answer_opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2585 | |
| 2586 | ASSERT_TRUE(answer.get() != NULL); |
| 2587 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2588 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 2589 | const ContentInfo* dc = answer->GetContentByName("data"); |
| 2590 | ASSERT_TRUE(ac != NULL); |
| 2591 | ASSERT_TRUE(vc != NULL); |
| 2592 | ASSERT_TRUE(dc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2593 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 2594 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2595 | const RtpDataContentDescription* dcd = dc->media_description()->as_rtp_data(); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2596 | ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); |
| 2597 | ASSERT_CRYPTO(vcd, 1U, kDefaultSrtpCryptoSuite); |
| 2598 | ASSERT_CRYPTO(dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2599 | |
| 2600 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2601 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2602 | |
| 2603 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2604 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2605 | EXPECT_TRUE(audio_streams[0].cname == audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2606 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2607 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2608 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2609 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2610 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2611 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2612 | |
| 2613 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2614 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
| 2615 | |
| 2616 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2617 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2618 | |
| 2619 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2620 | ASSERT_EQ(1U, video_streams.size()); |
| 2621 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2622 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2623 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2624 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2625 | |
| 2626 | EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2627 | EXPECT_THAT(dcd->codecs(), ElementsAreArray(kDataCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2628 | |
| 2629 | const StreamParamsVec& data_streams = dcd->streams(); |
| 2630 | ASSERT_EQ(2U, data_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2631 | EXPECT_TRUE(data_streams[0].cname == data_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2632 | EXPECT_EQ(kDataTrack1, data_streams[0].id); |
| 2633 | ASSERT_EQ(1U, data_streams[0].ssrcs.size()); |
| 2634 | EXPECT_NE(0U, data_streams[0].ssrcs[0]); |
| 2635 | EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 2636 | ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 2637 | EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 2638 | |
| 2639 | EXPECT_EQ(cricket::kDataMaxBandwidth, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2640 | dcd->bandwidth()); // default bandwidth (auto) |
| 2641 | EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2642 | |
| 2643 | // 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] | 2644 | // other tracks and remove 1 audio track. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2645 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2646 | {kMediaStream2}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2647 | DetachSenderFromMediaSection("audio", kAudioTrack2, &answer_opts); |
| 2648 | DetachSenderFromMediaSection("data", kDataTrack2, &answer_opts); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2649 | std::unique_ptr<SessionDescription> updated_answer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2650 | f2_.CreateAnswer(offer.get(), answer_opts, answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2651 | |
| 2652 | ASSERT_TRUE(updated_answer.get() != NULL); |
| 2653 | ac = updated_answer->GetContentByName("audio"); |
| 2654 | vc = updated_answer->GetContentByName("video"); |
| 2655 | dc = updated_answer->GetContentByName("data"); |
| 2656 | ASSERT_TRUE(ac != NULL); |
| 2657 | ASSERT_TRUE(vc != NULL); |
| 2658 | ASSERT_TRUE(dc != NULL); |
| 2659 | const AudioContentDescription* updated_acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2660 | ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2661 | const VideoContentDescription* updated_vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2662 | vc->media_description()->as_video(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 2663 | const RtpDataContentDescription* updated_dcd = |
| 2664 | dc->media_description()->as_rtp_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2665 | |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2666 | ASSERT_CRYPTO(updated_acd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2667 | EXPECT_TRUE(CompareCryptoParams(acd->cryptos(), updated_acd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2668 | ASSERT_CRYPTO(updated_vcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2669 | EXPECT_TRUE(CompareCryptoParams(vcd->cryptos(), updated_vcd->cryptos())); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 2670 | ASSERT_CRYPTO(updated_dcd, 1U, kDefaultSrtpCryptoSuite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2671 | EXPECT_TRUE(CompareCryptoParams(dcd->cryptos(), updated_dcd->cryptos())); |
| 2672 | |
| 2673 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2674 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2675 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2676 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
| 2677 | EXPECT_EQ(dcd->type(), updated_dcd->type()); |
| 2678 | EXPECT_EQ(dcd->codecs(), updated_dcd->codecs()); |
| 2679 | |
| 2680 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2681 | ASSERT_EQ(1U, updated_audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2682 | EXPECT_TRUE(audio_streams[0] == updated_audio_streams[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2683 | |
| 2684 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2685 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2686 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2687 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 2688 | // All media streams in one PeerConnection share one CNAME. |
| 2689 | 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] | 2690 | |
| 2691 | const StreamParamsVec& updated_data_streams = updated_dcd->streams(); |
| 2692 | ASSERT_EQ(1U, updated_data_streams.size()); |
| 2693 | EXPECT_TRUE(data_streams[0] == updated_data_streams[0]); |
| 2694 | } |
| 2695 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2696 | // Create an updated offer after creating an answer to the original offer and |
| 2697 | // verify that the codecs that were part of the original answer are not changed |
| 2698 | // in the updated offer. |
| 2699 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2700 | RespondentCreatesOfferAfterCreatingAnswer) { |
| 2701 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2702 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2703 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2704 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 2705 | std::unique_ptr<SessionDescription> answer = |
| 2706 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2707 | |
| 2708 | const AudioContentDescription* acd = |
| 2709 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2710 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2711 | |
| 2712 | const VideoContentDescription* vcd = |
| 2713 | GetFirstVideoContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2714 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2715 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2716 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2717 | f2_.CreateOffer(opts, answer.get())); |
| 2718 | |
| 2719 | // The expected audio codecs are the common audio codecs from the first |
| 2720 | // offer/answer exchange plus the audio codecs only |f2_| offer, sorted in |
| 2721 | // preference order. |
wu@webrtc.org | ff1b1bf | 2014-06-20 20:57:42 +0000 | [diff] [blame] | 2722 | // TODO(wu): |updated_offer| should not include the codec |
| 2723 | // (i.e. |kAudioCodecs2[0]|) the other side doesn't support. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2724 | const AudioCodec kUpdatedAudioCodecOffer[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 2725 | kAudioCodecsAnswer[0], |
| 2726 | kAudioCodecsAnswer[1], |
| 2727 | kAudioCodecs2[0], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2728 | }; |
| 2729 | |
| 2730 | // The expected video codecs are the common video codecs from the first |
| 2731 | // offer/answer exchange plus the video codecs only |f2_| offer, sorted in |
| 2732 | // preference order. |
| 2733 | const VideoCodec kUpdatedVideoCodecOffer[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 2734 | kVideoCodecsAnswer[0], |
| 2735 | kVideoCodecs2[1], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2736 | }; |
| 2737 | |
| 2738 | const AudioContentDescription* updated_acd = |
| 2739 | GetFirstAudioContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2740 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kUpdatedAudioCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2741 | |
| 2742 | const VideoContentDescription* updated_vcd = |
| 2743 | GetFirstVideoContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2744 | EXPECT_THAT(updated_vcd->codecs(), ElementsAreArray(kUpdatedVideoCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2747 | // Test that a reoffer does not reuse audio codecs from a previous media section |
| 2748 | // that is being recycled. |
| 2749 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2750 | ReOfferDoesNotReUseRecycledAudioCodecs) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2751 | f1_.set_video_codecs({}, {}); |
| 2752 | f2_.set_video_codecs({}, {}); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2753 | |
| 2754 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2755 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2756 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2757 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2758 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2759 | std::unique_ptr<SessionDescription> answer = |
| 2760 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2761 | |
| 2762 | // Recycle the media section by changing its mid. |
| 2763 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2764 | std::unique_ptr<SessionDescription> reoffer = |
| 2765 | f2_.CreateOffer(opts, answer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2766 | |
| 2767 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2768 | // section was not recycled the payload types would match the initial offerer. |
| 2769 | const AudioContentDescription* acd = |
| 2770 | GetFirstAudioContentDescription(reoffer.get()); |
| 2771 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecs2)); |
| 2772 | } |
| 2773 | |
| 2774 | // Test that a reoffer does not reuse video codecs from a previous media section |
| 2775 | // that is being recycled. |
| 2776 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2777 | ReOfferDoesNotReUseRecycledVideoCodecs) { |
| 2778 | f1_.set_audio_codecs({}, {}); |
| 2779 | f2_.set_audio_codecs({}, {}); |
| 2780 | |
| 2781 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2782 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2783 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2784 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2785 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
| 2786 | auto answer = f2_.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 = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2790 | std::unique_ptr<SessionDescription> reoffer = |
| 2791 | f2_.CreateOffer(opts, answer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2792 | |
| 2793 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2794 | // section was not recycled the payload types would match the initial offerer. |
| 2795 | const VideoContentDescription* vcd = |
| 2796 | GetFirstVideoContentDescription(reoffer.get()); |
| 2797 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecs2)); |
| 2798 | } |
| 2799 | |
| 2800 | // Test that a reanswer does not reuse audio codecs from a previous media |
| 2801 | // section that is being recycled. |
| 2802 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2803 | ReAnswerDoesNotReUseRecycledAudioCodecs) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2804 | f1_.set_video_codecs({}, {}); |
| 2805 | f2_.set_video_codecs({}, {}); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2806 | |
| 2807 | // Perform initial offer/answer in reverse (|f2_| as offerer) so that the |
| 2808 | // second offer/answer is forward (|f1_| as offerer). |
| 2809 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2810 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2811 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2812 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2813 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, nullptr); |
| 2814 | std::unique_ptr<SessionDescription> answer = |
| 2815 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2816 | |
| 2817 | // Recycle the media section by changing its mid. |
| 2818 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2819 | std::unique_ptr<SessionDescription> reoffer = |
| 2820 | f1_.CreateOffer(opts, answer.get()); |
| 2821 | std::unique_ptr<SessionDescription> reanswer = |
| 2822 | f2_.CreateAnswer(reoffer.get(), opts, offer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2823 | |
| 2824 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2825 | // section was not recycled the payload types would match the initial offerer. |
| 2826 | const AudioContentDescription* acd = |
| 2827 | GetFirstAudioContentDescription(reanswer.get()); |
| 2828 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
| 2829 | } |
| 2830 | |
| 2831 | // Test that a reanswer does not reuse video codecs from a previous media |
| 2832 | // section that is being recycled. |
| 2833 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2834 | ReAnswerDoesNotReUseRecycledVideoCodecs) { |
| 2835 | f1_.set_audio_codecs({}, {}); |
| 2836 | f2_.set_audio_codecs({}, {}); |
| 2837 | |
| 2838 | // Perform initial offer/answer in reverse (|f2_| as offerer) so that the |
| 2839 | // second offer/answer is forward (|f1_| as offerer). |
| 2840 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2841 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2842 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2843 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2844 | std::unique_ptr<SessionDescription> offer = f2_.CreateOffer(opts, nullptr); |
| 2845 | std::unique_ptr<SessionDescription> answer = |
| 2846 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2847 | |
| 2848 | // Recycle the media section by changing its mid. |
| 2849 | opts.media_description_options[0].mid = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2850 | std::unique_ptr<SessionDescription> reoffer = |
| 2851 | f1_.CreateOffer(opts, answer.get()); |
| 2852 | std::unique_ptr<SessionDescription> reanswer = |
| 2853 | f2_.CreateAnswer(reoffer.get(), opts, offer.get()); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2854 | |
| 2855 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2856 | // section was not recycled the payload types would match the initial offerer. |
| 2857 | const VideoContentDescription* vcd = |
| 2858 | GetFirstVideoContentDescription(reanswer.get()); |
| 2859 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
| 2860 | } |
| 2861 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2862 | // Create an updated offer after creating an answer to the original offer and |
| 2863 | // verify that the codecs that were part of the original answer are not changed |
| 2864 | // in the updated offer. In this test Rtx is enabled. |
| 2865 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2866 | RespondentCreatesOfferAfterCreatingAnswerWithRtx) { |
| 2867 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2868 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2869 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2870 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2871 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2872 | // 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] | 2873 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2874 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2875 | |
| 2876 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2877 | // 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] | 2878 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2879 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2880 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2881 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2882 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2883 | std::unique_ptr<SessionDescription> answer = |
| 2884 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2885 | |
| 2886 | const VideoContentDescription* vcd = |
| 2887 | GetFirstVideoContentDescription(answer.get()); |
| 2888 | |
| 2889 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2890 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 2891 | &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2892 | |
| 2893 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2894 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 2895 | // Now, make sure we get same result (except for the order) if |f2_| creates |
| 2896 | // an updated offer even though the default payload types between |f1_| and |
| 2897 | // |f2_| are different. |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2898 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2899 | f2_.CreateOffer(opts, answer.get())); |
| 2900 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2901 | std::unique_ptr<SessionDescription> updated_answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2902 | f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); |
| 2903 | |
| 2904 | const VideoContentDescription* updated_vcd = |
| 2905 | GetFirstVideoContentDescription(updated_answer.get()); |
| 2906 | |
| 2907 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 2908 | } |
| 2909 | |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2910 | // Regression test for: |
| 2911 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8332 |
| 2912 | // Existing codecs should always appear before new codecs in re-offers. But |
| 2913 | // under a specific set of circumstances, the existing RTX codec was ending up |
| 2914 | // added to the end of the list. |
| 2915 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2916 | RespondentCreatesOfferAfterCreatingAnswerWithRemappedRtxPayloadType) { |
| 2917 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2918 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2919 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2920 | &opts); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2921 | // We specifically choose different preferred payload types for VP8 to |
| 2922 | // trigger the issue. |
| 2923 | cricket::VideoCodec vp8_offerer(100, "VP8"); |
| 2924 | cricket::VideoCodec vp8_offerer_rtx = |
| 2925 | VideoCodec::CreateRtxCodec(101, vp8_offerer.id); |
| 2926 | cricket::VideoCodec vp8_answerer(110, "VP8"); |
| 2927 | cricket::VideoCodec vp8_answerer_rtx = |
| 2928 | VideoCodec::CreateRtxCodec(111, vp8_answerer.id); |
| 2929 | cricket::VideoCodec vp9(120, "VP9"); |
| 2930 | cricket::VideoCodec vp9_rtx = VideoCodec::CreateRtxCodec(121, vp9.id); |
| 2931 | |
| 2932 | std::vector<VideoCodec> f1_codecs = {vp8_offerer, vp8_offerer_rtx}; |
| 2933 | // We also specifically cause the answerer to prefer VP9, such that if it |
| 2934 | // *doesn't* honor the existing preferred codec (VP8) we'll notice. |
| 2935 | std::vector<VideoCodec> f2_codecs = {vp9, vp9_rtx, vp8_answerer, |
| 2936 | vp8_answerer_rtx}; |
| 2937 | |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2938 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 2939 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2940 | std::vector<AudioCodec> audio_codecs; |
| 2941 | f1_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2942 | f2_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2943 | |
| 2944 | // Offer will be {VP8, RTX for VP8}. Answer will be the same. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2945 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2946 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2947 | std::unique_ptr<SessionDescription> answer = |
| 2948 | f2_.CreateAnswer(offer.get(), opts, NULL); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2949 | |
| 2950 | // Updated offer *should* be {VP8, RTX for VP8, VP9, RTX for VP9}. |
| 2951 | // But if the bug is triggered, RTX for VP8 ends up last. |
| 2952 | std::unique_ptr<SessionDescription> updated_offer( |
| 2953 | f2_.CreateOffer(opts, answer.get())); |
| 2954 | |
| 2955 | const VideoContentDescription* vcd = |
| 2956 | GetFirstVideoContentDescription(updated_offer.get()); |
| 2957 | std::vector<cricket::VideoCodec> codecs = vcd->codecs(); |
| 2958 | ASSERT_EQ(4u, codecs.size()); |
| 2959 | EXPECT_EQ(vp8_offerer, codecs[0]); |
| 2960 | EXPECT_EQ(vp8_offerer_rtx, codecs[1]); |
| 2961 | EXPECT_EQ(vp9, codecs[2]); |
| 2962 | EXPECT_EQ(vp9_rtx, codecs[3]); |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2965 | // Create an updated offer that adds video after creating an audio only answer |
| 2966 | // to the original offer. This test verifies that if a video codec and the RTX |
| 2967 | // codec have the same default payload type as an audio codec that is already in |
| 2968 | // use, the added codecs payload types are changed. |
| 2969 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2970 | RespondentCreatesOfferWithVideoAndRtxAfterCreatingAudioAnswer) { |
| 2971 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2972 | // 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] | 2973 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2974 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2975 | |
| 2976 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 2977 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2978 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2979 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2980 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 2981 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 2982 | std::unique_ptr<SessionDescription> answer = |
| 2983 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2984 | |
| 2985 | const AudioContentDescription* acd = |
| 2986 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 2987 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2988 | |
| 2989 | // Now - let |f2_| add video with RTX and let the payload type the RTX codec |
| 2990 | // reference be the same as an audio codec that was negotiated in the |
| 2991 | // first offer/answer exchange. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2992 | opts.media_description_options.clear(); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2993 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2994 | |
| 2995 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2996 | int used_pl_type = acd->codecs()[0].id; |
| 2997 | 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] | 2998 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, used_pl_type), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2999 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3000 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3001 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3002 | f2_.CreateOffer(opts, answer.get())); |
| 3003 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3004 | std::unique_ptr<SessionDescription> updated_answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3005 | f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); |
| 3006 | |
| 3007 | const AudioContentDescription* updated_acd = |
| 3008 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3009 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3010 | |
| 3011 | const VideoContentDescription* updated_vcd = |
| 3012 | GetFirstVideoContentDescription(updated_answer.get()); |
| 3013 | |
| 3014 | ASSERT_EQ("H264", updated_vcd->codecs()[0].name); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3015 | ASSERT_EQ(cricket::kRtxCodecName, updated_vcd->codecs()[1].name); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3016 | int new_h264_pl_type = updated_vcd->codecs()[0].id; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3017 | EXPECT_NE(used_pl_type, new_h264_pl_type); |
| 3018 | VideoCodec rtx = updated_vcd->codecs()[1]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3019 | int pt_referenced_by_rtx = rtc::FromString<int>( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3020 | rtx.params[cricket::kCodecParamAssociatedPayloadType]); |
| 3021 | EXPECT_EQ(new_h264_pl_type, pt_referenced_by_rtx); |
| 3022 | } |
| 3023 | |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3024 | // Create an updated offer with RTX after creating an answer to an offer |
| 3025 | // without RTX, and with different default payload types. |
| 3026 | // Verify that the added RTX codec references the correct payload type. |
| 3027 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3028 | RespondentCreatesOfferWithRtxAfterCreatingAnswerWithoutRtx) { |
| 3029 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3030 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3031 | |
| 3032 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3033 | // This creates rtx for H264 with the payload type |f2_| uses. |
| 3034 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3035 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3036 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3037 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3038 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3039 | std::unique_ptr<SessionDescription> answer = |
| 3040 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3041 | |
| 3042 | const VideoContentDescription* vcd = |
| 3043 | GetFirstVideoContentDescription(answer.get()); |
| 3044 | |
| 3045 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
| 3046 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3047 | |
| 3048 | // Now, ensure that the RTX codec is created correctly when |f2_| creates an |
| 3049 | // updated offer, even though the default payload types are different from |
| 3050 | // those of |f1_|. |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3051 | std::unique_ptr<SessionDescription> updated_offer( |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3052 | f2_.CreateOffer(opts, answer.get())); |
| 3053 | ASSERT_TRUE(updated_offer); |
| 3054 | |
| 3055 | const VideoContentDescription* updated_vcd = |
| 3056 | GetFirstVideoContentDescription(updated_offer.get()); |
| 3057 | |
| 3058 | // New offer should attempt to add H263, and RTX for H264. |
| 3059 | expected_codecs.push_back(kVideoCodecs2[1]); |
| 3060 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[1].id), |
| 3061 | &expected_codecs); |
| 3062 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 3063 | } |
| 3064 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3065 | // Test that RTX is ignored when there is no associated payload type parameter. |
| 3066 | TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { |
| 3067 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3068 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3069 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3070 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3071 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3072 | // This creates RTX without associated payload type parameter. |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3073 | AddRtxCodec(VideoCodec(126, cricket::kRtxCodecName), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3074 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3075 | |
| 3076 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3077 | // This creates RTX for H264 with the payload type |f2_| uses. |
| 3078 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3079 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3080 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3081 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3082 | ASSERT_TRUE(offer.get() != NULL); |
| 3083 | // kCodecParamAssociatedPayloadType will always be added to the offer when RTX |
| 3084 | // is selected. Manually remove kCodecParamAssociatedPayloadType so that it |
| 3085 | // is possible to test that that RTX is dropped when |
| 3086 | // kCodecParamAssociatedPayloadType is missing in the offer. |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3087 | MediaContentDescription* media_desc = |
| 3088 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3089 | ASSERT_TRUE(media_desc); |
| 3090 | VideoContentDescription* desc = media_desc->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3091 | std::vector<VideoCodec> codecs = desc->codecs(); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 3092 | for (VideoCodec& codec : codecs) { |
Mirko Bonadei | 57cabed | 2020-04-01 12:03:11 +0200 | [diff] [blame] | 3093 | if (absl::StartsWith(codec.name, cricket::kRtxCodecName)) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 3094 | codec.params.clear(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | desc->set_codecs(codecs); |
| 3098 | |
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); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +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 RTX will be filtered out in the answer if its associated payload |
| 3108 | // type doesn't match the local value. |
| 3109 | TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { |
| 3110 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3111 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3112 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3113 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3114 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3115 | // This creates RTX for H264 in sender. |
| 3116 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3117 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3118 | |
| 3119 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3120 | // This creates RTX for H263 in receiver. |
| 3121 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[1].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3122 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3123 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3124 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3125 | ASSERT_TRUE(offer.get() != NULL); |
| 3126 | // Associated payload type doesn't match, therefore, RTX codec is removed in |
| 3127 | // the answer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3128 | std::unique_ptr<SessionDescription> answer = |
| 3129 | f2_.CreateAnswer(offer.get(), opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3130 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 3131 | EXPECT_THAT( |
| 3132 | GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), |
| 3133 | Not(Contains(cricket::kRtxCodecName))); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | // Test that when multiple RTX codecs are offered, only the matched RTX codec |
| 3137 | // is added in the answer, and the unsupported RTX codec is filtered out. |
| 3138 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3139 | FilterOutUnsupportedRtxWhenCreatingAnswer) { |
| 3140 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3141 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3142 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3143 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3144 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3145 | // This creates RTX for H264-SVC in sender. |
| 3146 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3147 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3148 | |
| 3149 | // This creates RTX for H264 in sender. |
| 3150 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3151 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3152 | |
| 3153 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3154 | // This creates RTX for H264 in receiver. |
| 3155 | AddRtxCodec(VideoCodec::CreateRtxCodec(124, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3156 | f2_.set_video_codecs(f2_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3157 | |
| 3158 | // H264-SVC codec is removed in the answer, therefore, associated RTX codec |
| 3159 | // for H264-SVC should also be removed. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3160 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3161 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3162 | std::unique_ptr<SessionDescription> answer = |
| 3163 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3164 | const VideoContentDescription* vcd = |
| 3165 | GetFirstVideoContentDescription(answer.get()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3166 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
| 3167 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 3168 | &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3169 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3170 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3171 | } |
| 3172 | |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3173 | // Test that after one RTX codec has been negotiated, a new offer can attempt |
| 3174 | // to add another. |
| 3175 | TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { |
| 3176 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3177 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3178 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3179 | &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3180 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3181 | // This creates RTX for H264 for the offerer. |
| 3182 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3183 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3184 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3185 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3186 | ASSERT_TRUE(offer); |
| 3187 | const VideoContentDescription* vcd = |
| 3188 | GetFirstVideoContentDescription(offer.get()); |
| 3189 | |
| 3190 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3191 | AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 3192 | &expected_codecs); |
| 3193 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3194 | |
| 3195 | // Now, attempt to add RTX for H264-SVC. |
| 3196 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3197 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3198 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3199 | std::unique_ptr<SessionDescription> updated_offer( |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 3200 | f1_.CreateOffer(opts, offer.get())); |
| 3201 | ASSERT_TRUE(updated_offer); |
| 3202 | vcd = GetFirstVideoContentDescription(updated_offer.get()); |
| 3203 | |
| 3204 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), |
| 3205 | &expected_codecs); |
| 3206 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3207 | } |
| 3208 | |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3209 | // Test that when RTX is used in conjunction with simulcast, an RTX ssrc is |
| 3210 | // generated for each simulcast ssrc and correctly grouped. |
| 3211 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { |
| 3212 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3213 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3214 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3215 | &opts); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3216 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3217 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3218 | {"stream1label"}, 3, &opts); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3219 | |
| 3220 | // Use a single real codec, and then add RTX for it. |
| 3221 | std::vector<VideoCodec> f1_codecs; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3222 | f1_codecs.push_back(VideoCodec(97, "H264")); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3223 | AddRtxCodec(VideoCodec::CreateRtxCodec(125, 97), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3224 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3225 | |
| 3226 | // Ensure that the offer has an RTX ssrc for each regular ssrc, and that there |
| 3227 | // is a FID ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3228 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3229 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3230 | MediaContentDescription* media_desc = |
| 3231 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3232 | ASSERT_TRUE(media_desc); |
| 3233 | VideoContentDescription* desc = media_desc->as_video(); |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3234 | const StreamParamsVec& streams = desc->streams(); |
| 3235 | // Single stream. |
| 3236 | ASSERT_EQ(1u, streams.size()); |
| 3237 | // Stream should have 6 ssrcs: 3 for video, 3 for RTX. |
| 3238 | EXPECT_EQ(6u, streams[0].ssrcs.size()); |
| 3239 | // And should have a SIM group for the simulcast. |
| 3240 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3241 | // And a FID group for RTX. |
| 3242 | EXPECT_TRUE(streams[0].has_ssrc_group("FID")); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3243 | std::vector<uint32_t> primary_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3244 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3245 | EXPECT_EQ(3u, primary_ssrcs.size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3246 | std::vector<uint32_t> fid_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 3247 | streams[0].GetFidSsrcs(primary_ssrcs, &fid_ssrcs); |
| 3248 | EXPECT_EQ(3u, fid_ssrcs.size()); |
| 3249 | } |
| 3250 | |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3251 | // Test that, when the FlexFEC codec is added, a FlexFEC ssrc is created |
| 3252 | // together with a FEC-FR grouping. |
| 3253 | TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { |
| 3254 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3255 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3256 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3257 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3258 | // Add single stream. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3259 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3260 | {"stream1label"}, 1, &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3261 | |
| 3262 | // Use a single real codec, and then add FlexFEC for it. |
| 3263 | std::vector<VideoCodec> f1_codecs; |
| 3264 | f1_codecs.push_back(VideoCodec(97, "H264")); |
| 3265 | f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3266 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3267 | |
| 3268 | // Ensure that the offer has a single FlexFEC ssrc and that |
| 3269 | // there is no FEC-FR ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3270 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3271 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3272 | MediaContentDescription* media_desc = |
| 3273 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3274 | ASSERT_TRUE(media_desc); |
| 3275 | VideoContentDescription* desc = media_desc->as_video(); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3276 | const StreamParamsVec& streams = desc->streams(); |
| 3277 | // Single stream. |
| 3278 | ASSERT_EQ(1u, streams.size()); |
| 3279 | // Stream should have 2 ssrcs: 1 for video, 1 for FlexFEC. |
| 3280 | EXPECT_EQ(2u, streams[0].ssrcs.size()); |
| 3281 | // And should have a FEC-FR group for FlexFEC. |
| 3282 | EXPECT_TRUE(streams[0].has_ssrc_group("FEC-FR")); |
| 3283 | std::vector<uint32_t> primary_ssrcs; |
| 3284 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3285 | ASSERT_EQ(1u, primary_ssrcs.size()); |
| 3286 | uint32_t flexfec_ssrc; |
| 3287 | EXPECT_TRUE(streams[0].GetFecFrSsrc(primary_ssrcs[0], &flexfec_ssrc)); |
| 3288 | EXPECT_NE(flexfec_ssrc, 0u); |
| 3289 | } |
| 3290 | |
| 3291 | // Test that FlexFEC is disabled for simulcast. |
| 3292 | // TODO(brandtr): Remove this test when we support simulcast, either through |
| 3293 | // multiple FlexfecSenders, or through multistream protection. |
| 3294 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { |
| 3295 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3296 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3297 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3298 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3299 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3300 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3301 | {"stream1label"}, 3, &opts); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3302 | |
| 3303 | // Use a single real codec, and then add FlexFEC for it. |
| 3304 | std::vector<VideoCodec> f1_codecs; |
| 3305 | f1_codecs.push_back(VideoCodec(97, "H264")); |
| 3306 | f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 3307 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3308 | |
| 3309 | // Ensure that the offer has no FlexFEC ssrcs for each regular ssrc, and that |
| 3310 | // there is no FEC-FR ssrc + grouping for each. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3311 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3312 | ASSERT_TRUE(offer.get() != nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3313 | MediaContentDescription* media_desc = |
| 3314 | offer->GetContentDescriptionByName(cricket::CN_VIDEO); |
| 3315 | ASSERT_TRUE(media_desc); |
| 3316 | VideoContentDescription* desc = media_desc->as_video(); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 3317 | const StreamParamsVec& streams = desc->streams(); |
| 3318 | // Single stream. |
| 3319 | ASSERT_EQ(1u, streams.size()); |
| 3320 | // Stream should have 3 ssrcs: 3 for video, 0 for FlexFEC. |
| 3321 | EXPECT_EQ(3u, streams[0].ssrcs.size()); |
| 3322 | // And should have a SIM group for the simulcast. |
| 3323 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3324 | // And not a FEC-FR group for FlexFEC. |
| 3325 | EXPECT_FALSE(streams[0].has_ssrc_group("FEC-FR")); |
| 3326 | std::vector<uint32_t> primary_ssrcs; |
| 3327 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3328 | EXPECT_EQ(3u, primary_ssrcs.size()); |
| 3329 | for (uint32_t primary_ssrc : primary_ssrcs) { |
| 3330 | uint32_t flexfec_ssrc; |
| 3331 | EXPECT_FALSE(streams[0].GetFecFrSsrc(primary_ssrc, &flexfec_ssrc)); |
| 3332 | } |
| 3333 | } |
| 3334 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3335 | // Create an updated offer after creating an answer to the original offer and |
| 3336 | // verify that the RTP header extensions that were part of the original answer |
| 3337 | // are not changed in the updated offer. |
| 3338 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3339 | RespondentCreatesOfferAfterCreatingAnswerWithRtpExtensions) { |
| 3340 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3341 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3342 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 3343 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 3344 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 3345 | f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 3346 | f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 3347 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3348 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
| 3349 | std::unique_ptr<SessionDescription> answer = |
| 3350 | f2_.CreateAnswer(offer.get(), opts, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3351 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3352 | EXPECT_EQ( |
| 3353 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 3354 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 3355 | EXPECT_EQ( |
| 3356 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 3357 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3358 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3359 | std::unique_ptr<SessionDescription> updated_offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3360 | f2_.CreateOffer(opts, answer.get())); |
| 3361 | |
| 3362 | // The expected RTP header extensions in the new offer are the resulting |
| 3363 | // extensions from the first offer/answer exchange plus the extensions only |
| 3364 | // |f2_| offer. |
| 3365 | // 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] | 3366 | // |f1_| for another extensions, it is changed to 13. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3367 | const RtpExtension kUpdatedAudioRtpExtensions[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 3368 | kAudioRtpExtensionAnswer[0], |
| 3369 | RtpExtension(kAudioRtpExtension2[1].uri, 13), |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3370 | kAudioRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3371 | }; |
| 3372 | |
| 3373 | // 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] | 3374 | // |f1_| for another extensions, is is changed to 12. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3375 | const RtpExtension kUpdatedVideoRtpExtensions[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 3376 | kVideoRtpExtensionAnswer[0], |
| 3377 | RtpExtension(kVideoRtpExtension2[1].uri, 12), |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3378 | kVideoRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3379 | }; |
| 3380 | |
| 3381 | const AudioContentDescription* updated_acd = |
| 3382 | GetFirstAudioContentDescription(updated_offer.get()); |
| 3383 | EXPECT_EQ(MAKE_VECTOR(kUpdatedAudioRtpExtensions), |
| 3384 | updated_acd->rtp_header_extensions()); |
| 3385 | |
| 3386 | const VideoContentDescription* updated_vcd = |
| 3387 | GetFirstVideoContentDescription(updated_offer.get()); |
| 3388 | EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoRtpExtensions), |
| 3389 | updated_vcd->rtp_header_extensions()); |
| 3390 | } |
| 3391 | |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3392 | // Verify that if the same RTP extension URI is used for audio and video, the |
| 3393 | // same ID is used. Also verify that the ID isn't changed when creating an |
| 3394 | // updated offer (this was previously a bug). |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3395 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3396 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3397 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3398 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 3399 | f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension3)); |
| 3400 | f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension3)); |
| 3401 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3402 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3403 | |
| 3404 | // Since the audio extensions used ID 3 for "both_audio_and_video", so should |
| 3405 | // the video extensions. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 3406 | const RtpExtension kExpectedVideoRtpExtension[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 3407 | kVideoRtpExtension3[0], |
| 3408 | kAudioRtpExtension3[1], |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3409 | }; |
| 3410 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3411 | EXPECT_EQ( |
| 3412 | MAKE_VECTOR(kAudioRtpExtension3), |
| 3413 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3414 | EXPECT_EQ( |
| 3415 | MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 3416 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3417 | |
| 3418 | // Nothing should change when creating a new offer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3419 | std::unique_ptr<SessionDescription> updated_offer( |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3420 | f1_.CreateOffer(opts, offer.get())); |
| 3421 | |
| 3422 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3423 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3424 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3425 | EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3426 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3427 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-20 17:30:13 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3430 | // Same as "RtpExtensionIdReused" above for encrypted RTP extensions. |
| 3431 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { |
| 3432 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3433 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3434 | |
| 3435 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 3436 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 3437 | |
Markus Handell | 6f727da | 2020-06-12 15:24:54 +0000 | [diff] [blame^] | 3438 | f1_.set_audio_rtp_header_extensions( |
| 3439 | MAKE_VECTOR(kAudioRtpExtension3ForEncryption)); |
| 3440 | f1_.set_video_rtp_header_extensions( |
| 3441 | MAKE_VECTOR(kVideoRtpExtension3ForEncryption)); |
| 3442 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3443 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, NULL); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3444 | |
| 3445 | // The extensions that are shared between audio and video should use the same |
| 3446 | // id. |
| 3447 | const RtpExtension kExpectedVideoRtpExtension[] = { |
| 3448 | kVideoRtpExtension3ForEncryption[0], |
| 3449 | kAudioRtpExtension3ForEncryptionOffer[1], |
| 3450 | kAudioRtpExtension3ForEncryptionOffer[2], |
| 3451 | }; |
| 3452 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3453 | EXPECT_EQ( |
| 3454 | MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
| 3455 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3456 | EXPECT_EQ( |
| 3457 | MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 3458 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3459 | |
| 3460 | // Nothing should change when creating a new offer |
| 3461 | std::unique_ptr<SessionDescription> updated_offer( |
| 3462 | f1_.CreateOffer(opts, offer.get())); |
| 3463 | |
| 3464 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3465 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3466 | ->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3467 | EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3468 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3469 | ->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3472 | TEST(MediaSessionDescription, CopySessionDescription) { |
| 3473 | SessionDescription source; |
| 3474 | cricket::ContentGroup group(cricket::CN_AUDIO); |
| 3475 | source.AddGroup(group); |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 3476 | std::unique_ptr<AudioContentDescription> acd = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 3477 | std::make_unique<AudioContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3478 | acd->set_codecs(MAKE_VECTOR(kAudioCodecs1)); |
| 3479 | acd->AddLegacyStream(1); |
Harald Alvestrand | 0fb07f8 | 2020-02-27 20:21:37 +0100 | [diff] [blame] | 3480 | source.AddContent(cricket::CN_AUDIO, MediaProtocolType::kRtp, acd->Clone()); |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 3481 | std::unique_ptr<VideoContentDescription> vcd = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 3482 | std::make_unique<VideoContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3483 | vcd->set_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 3484 | vcd->AddLegacyStream(2); |
Harald Alvestrand | 0fb07f8 | 2020-02-27 20:21:37 +0100 | [diff] [blame] | 3485 | source.AddContent(cricket::CN_VIDEO, MediaProtocolType::kRtp, vcd->Clone()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3486 | |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 3487 | std::unique_ptr<SessionDescription> copy = source.Clone(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3488 | ASSERT_TRUE(copy.get() != NULL); |
| 3489 | EXPECT_TRUE(copy->HasGroup(cricket::CN_AUDIO)); |
| 3490 | const ContentInfo* ac = copy->GetContentByName("audio"); |
| 3491 | const ContentInfo* vc = copy->GetContentByName("video"); |
| 3492 | ASSERT_TRUE(ac != NULL); |
| 3493 | ASSERT_TRUE(vc != NULL); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 3494 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3495 | const AudioContentDescription* acd_copy = ac->media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3496 | EXPECT_EQ(acd->codecs(), acd_copy->codecs()); |
| 3497 | EXPECT_EQ(1u, acd->first_ssrc()); |
| 3498 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 3499 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3500 | const VideoContentDescription* vcd_copy = vc->media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3501 | EXPECT_EQ(vcd->codecs(), vcd_copy->codecs()); |
| 3502 | EXPECT_EQ(2u, vcd->first_ssrc()); |
| 3503 | } |
| 3504 | |
| 3505 | // The below TestTransportInfoXXX tests create different offers/answers, and |
| 3506 | // ensure the TransportInfo in the SessionDescription matches what we expect. |
| 3507 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudio) { |
| 3508 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3509 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3510 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3511 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3512 | TestTransportInfo(true, options, false); |
| 3513 | } |
| 3514 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3515 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3516 | TestTransportInfoOfferIceRenomination) { |
| 3517 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3518 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3519 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3520 | &options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3521 | options.media_description_options[0] |
| 3522 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3523 | TestTransportInfo(true, options, false); |
| 3524 | } |
| 3525 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3526 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudioCurrent) { |
| 3527 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3528 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3529 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3530 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3531 | TestTransportInfo(true, options, true); |
| 3532 | } |
| 3533 | |
| 3534 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferMultimedia) { |
| 3535 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3536 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3537 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3538 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3539 | TestTransportInfo(true, options, false); |
| 3540 | } |
| 3541 | |
| 3542 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3543 | TestTransportInfoOfferMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3544 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3545 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3546 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3547 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3548 | TestTransportInfo(true, options, true); |
| 3549 | } |
| 3550 | |
| 3551 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferBundle) { |
| 3552 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3553 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3554 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3555 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3556 | options.bundle_enabled = true; |
| 3557 | TestTransportInfo(true, options, false); |
| 3558 | } |
| 3559 | |
| 3560 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3561 | TestTransportInfoOfferBundleCurrent) { |
| 3562 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3563 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3564 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3565 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3566 | options.bundle_enabled = true; |
| 3567 | TestTransportInfo(true, options, true); |
| 3568 | } |
| 3569 | |
| 3570 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerAudio) { |
| 3571 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3572 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3573 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3574 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3575 | TestTransportInfo(false, options, false); |
| 3576 | } |
| 3577 | |
| 3578 | TEST_F(MediaSessionDescriptionFactoryTest, |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3579 | TestTransportInfoAnswerIceRenomination) { |
| 3580 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3581 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3582 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3583 | &options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3584 | options.media_description_options[0] |
| 3585 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 3586 | TestTransportInfo(false, options, false); |
| 3587 | } |
| 3588 | |
| 3589 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3590 | TestTransportInfoAnswerAudioCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3591 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 3592 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3593 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3594 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3595 | TestTransportInfo(false, options, true); |
| 3596 | } |
| 3597 | |
| 3598 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerMultimedia) { |
| 3599 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3600 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3601 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3602 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3603 | TestTransportInfo(false, options, false); |
| 3604 | } |
| 3605 | |
| 3606 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3607 | TestTransportInfoAnswerMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3608 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3609 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3610 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3611 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3612 | TestTransportInfo(false, options, true); |
| 3613 | } |
| 3614 | |
| 3615 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerBundle) { |
| 3616 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3617 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3618 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3619 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3620 | options.bundle_enabled = true; |
| 3621 | TestTransportInfo(false, options, false); |
| 3622 | } |
| 3623 | |
| 3624 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3625 | TestTransportInfoAnswerBundleCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3626 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3627 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3628 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3629 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3630 | options.bundle_enabled = true; |
| 3631 | TestTransportInfo(false, options, true); |
| 3632 | } |
| 3633 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 3634 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3635 | TestTransportInfoOfferBundlesTransportOptions) { |
| 3636 | MediaSessionOptions options; |
| 3637 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3638 | |
| 3639 | cricket::OpaqueTransportParameters audio_params; |
| 3640 | audio_params.protocol = "audio-transport"; |
| 3641 | audio_params.parameters = "audio-params"; |
| 3642 | FindFirstMediaDescriptionByMid("audio", &options) |
| 3643 | ->transport_options.opaque_parameters = audio_params; |
| 3644 | |
| 3645 | cricket::OpaqueTransportParameters video_params; |
| 3646 | video_params.protocol = "video-transport"; |
| 3647 | video_params.parameters = "video-params"; |
| 3648 | FindFirstMediaDescriptionByMid("video", &options) |
| 3649 | ->transport_options.opaque_parameters = video_params; |
| 3650 | |
| 3651 | TestTransportInfo(/*offer=*/true, options, /*has_current_desc=*/false); |
| 3652 | } |
| 3653 | |
| 3654 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3655 | TestTransportInfoAnswerBundlesTransportOptions) { |
| 3656 | MediaSessionOptions options; |
| 3657 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3658 | |
| 3659 | cricket::OpaqueTransportParameters audio_params; |
| 3660 | audio_params.protocol = "audio-transport"; |
| 3661 | audio_params.parameters = "audio-params"; |
| 3662 | FindFirstMediaDescriptionByMid("audio", &options) |
| 3663 | ->transport_options.opaque_parameters = audio_params; |
| 3664 | |
| 3665 | cricket::OpaqueTransportParameters video_params; |
| 3666 | video_params.protocol = "video-transport"; |
| 3667 | video_params.parameters = "video-params"; |
| 3668 | FindFirstMediaDescriptionByMid("video", &options) |
| 3669 | ->transport_options.opaque_parameters = video_params; |
| 3670 | |
| 3671 | TestTransportInfo(/*offer=*/false, options, /*has_current_desc=*/false); |
| 3672 | } |
| 3673 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 3674 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolAddedToOffer) { |
| 3675 | MediaSessionOptions options; |
| 3676 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3677 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3678 | &options); |
| 3679 | |
| 3680 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3681 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3682 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3683 | |
| 3684 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3685 | |
| 3686 | EXPECT_EQ(offer->GetContentDescriptionByName("audio")->alt_protocol(), "foo"); |
| 3687 | EXPECT_EQ(offer->GetContentDescriptionByName("video")->alt_protocol(), "bar"); |
| 3688 | EXPECT_EQ(offer->GetContentDescriptionByName("data")->alt_protocol(), "baz"); |
| 3689 | } |
| 3690 | |
| 3691 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolAddedToAnswer) { |
| 3692 | MediaSessionOptions options; |
| 3693 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3694 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3695 | &options); |
| 3696 | |
| 3697 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3698 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3699 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3700 | |
| 3701 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3702 | std::unique_ptr<SessionDescription> answer = |
| 3703 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3704 | |
| 3705 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3706 | "foo"); |
| 3707 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3708 | "bar"); |
| 3709 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), "baz"); |
| 3710 | } |
| 3711 | |
| 3712 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolNotInOffer) { |
| 3713 | MediaSessionOptions options; |
| 3714 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3715 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3716 | &options); |
| 3717 | |
| 3718 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3719 | |
| 3720 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3721 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3722 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3723 | |
| 3724 | std::unique_ptr<SessionDescription> answer = |
| 3725 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3726 | |
| 3727 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3728 | absl::nullopt); |
| 3729 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3730 | absl::nullopt); |
| 3731 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), |
| 3732 | absl::nullopt); |
| 3733 | } |
| 3734 | |
| 3735 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolDifferentInOffer) { |
| 3736 | MediaSessionOptions options; |
| 3737 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3738 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3739 | &options); |
| 3740 | |
| 3741 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "not-foo"; |
| 3742 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "not-bar"; |
| 3743 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "not-baz"; |
| 3744 | |
| 3745 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3746 | |
| 3747 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3748 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3749 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3750 | |
| 3751 | std::unique_ptr<SessionDescription> answer = |
| 3752 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3753 | |
| 3754 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3755 | absl::nullopt); |
| 3756 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3757 | absl::nullopt); |
| 3758 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), |
| 3759 | absl::nullopt); |
| 3760 | } |
| 3761 | |
| 3762 | TEST_F(MediaSessionDescriptionFactoryTest, AltProtocolNotInAnswer) { |
| 3763 | MediaSessionOptions options; |
| 3764 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3765 | AddDataSection(cricket::DCT_SCTP, RtpTransceiverDirection::kRecvOnly, |
| 3766 | &options); |
| 3767 | |
| 3768 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = "foo"; |
| 3769 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = "bar"; |
| 3770 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = "baz"; |
| 3771 | |
| 3772 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, nullptr); |
| 3773 | |
| 3774 | FindFirstMediaDescriptionByMid("audio", &options)->alt_protocol = |
| 3775 | absl::nullopt; |
| 3776 | FindFirstMediaDescriptionByMid("video", &options)->alt_protocol = |
| 3777 | absl::nullopt; |
| 3778 | FindFirstMediaDescriptionByMid("data", &options)->alt_protocol = |
| 3779 | absl::nullopt; |
| 3780 | |
| 3781 | std::unique_ptr<SessionDescription> answer = |
| 3782 | f1_.CreateAnswer(offer.get(), options, nullptr); |
| 3783 | |
| 3784 | EXPECT_EQ(answer->GetContentDescriptionByName("audio")->alt_protocol(), |
| 3785 | absl::nullopt); |
| 3786 | EXPECT_EQ(answer->GetContentDescriptionByName("video")->alt_protocol(), |
| 3787 | absl::nullopt); |
| 3788 | EXPECT_EQ(answer->GetContentDescriptionByName("data")->alt_protocol(), |
| 3789 | absl::nullopt); |
| 3790 | } |
| 3791 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3792 | // Create an offer with bundle enabled and verify the crypto parameters are |
| 3793 | // the common set of the available cryptos. |
| 3794 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithOfferBundle) { |
| 3795 | TestCryptoWithBundle(true); |
| 3796 | } |
| 3797 | |
| 3798 | // Create an answer with bundle enabled and verify the crypto parameters are |
| 3799 | // the common set of the available cryptos. |
| 3800 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithAnswerBundle) { |
| 3801 | TestCryptoWithBundle(false); |
| 3802 | } |
| 3803 | |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3804 | // Verifies that creating answer fails if the offer has UDP/TLS/RTP/SAVPF but |
| 3805 | // DTLS is not enabled locally. |
| 3806 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3807 | TestOfferDtlsSavpfWithoutDtlsFailed) { |
| 3808 | f1_.set_secure(SEC_ENABLED); |
| 3809 | f2_.set_secure(SEC_ENABLED); |
| 3810 | tdf1_.set_secure(SEC_DISABLED); |
| 3811 | tdf2_.set_secure(SEC_DISABLED); |
| 3812 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3813 | std::unique_ptr<SessionDescription> offer = |
| 3814 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3815 | ASSERT_TRUE(offer.get() != NULL); |
| 3816 | ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 3817 | ASSERT_TRUE(offer_content != NULL); |
| 3818 | AudioContentDescription* offer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3819 | offer_content->media_description()->as_audio(); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3820 | offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 3821 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3822 | std::unique_ptr<SessionDescription> answer = |
| 3823 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3824 | ASSERT_TRUE(answer != NULL); |
| 3825 | ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 3826 | ASSERT_TRUE(answer_content != NULL); |
| 3827 | |
| 3828 | ASSERT_TRUE(answer_content->rejected); |
| 3829 | } |
| 3830 | |
| 3831 | // Offers UDP/TLS/RTP/SAVPF and verifies the answer can be created and contains |
| 3832 | // UDP/TLS/RTP/SAVPF. |
| 3833 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferDtlsSavpfCreateAnswer) { |
| 3834 | f1_.set_secure(SEC_ENABLED); |
| 3835 | f2_.set_secure(SEC_ENABLED); |
| 3836 | tdf1_.set_secure(SEC_ENABLED); |
| 3837 | tdf2_.set_secure(SEC_ENABLED); |
| 3838 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3839 | std::unique_ptr<SessionDescription> offer = |
| 3840 | f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3841 | ASSERT_TRUE(offer.get() != NULL); |
| 3842 | ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 3843 | ASSERT_TRUE(offer_content != NULL); |
| 3844 | AudioContentDescription* offer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3845 | offer_content->media_description()->as_audio(); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3846 | offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 3847 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3848 | std::unique_ptr<SessionDescription> answer = |
| 3849 | f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3850 | ASSERT_TRUE(answer != NULL); |
| 3851 | |
| 3852 | const ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 3853 | ASSERT_TRUE(answer_content != NULL); |
| 3854 | ASSERT_FALSE(answer_content->rejected); |
| 3855 | |
| 3856 | const AudioContentDescription* answer_audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3857 | answer_content->media_description()->as_audio(); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3858 | EXPECT_EQ(cricket::kMediaProtocolDtlsSavpf, answer_audio_desc->protocol()); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3861 | // Test that we include both SDES and DTLS in the offer, but only include SDES |
| 3862 | // in the answer if DTLS isn't negotiated. |
| 3863 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoDtls) { |
| 3864 | f1_.set_secure(SEC_ENABLED); |
| 3865 | f2_.set_secure(SEC_ENABLED); |
| 3866 | tdf1_.set_secure(SEC_ENABLED); |
| 3867 | tdf2_.set_secure(SEC_DISABLED); |
| 3868 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3869 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 3870 | std::unique_ptr<SessionDescription> offer, answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3871 | const cricket::MediaContentDescription* audio_media_desc; |
| 3872 | const cricket::MediaContentDescription* video_media_desc; |
| 3873 | const cricket::TransportDescription* audio_trans_desc; |
| 3874 | const cricket::TransportDescription* video_trans_desc; |
| 3875 | |
| 3876 | // Generate an offer with SDES and DTLS support. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3877 | offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3878 | ASSERT_TRUE(offer.get() != NULL); |
| 3879 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3880 | audio_media_desc = offer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3881 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3882 | video_media_desc = offer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3883 | ASSERT_TRUE(video_media_desc != NULL); |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 3884 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3885 | EXPECT_EQ(1u, video_media_desc->cryptos().size()); |
| 3886 | |
| 3887 | audio_trans_desc = offer->GetTransportDescriptionByName("audio"); |
| 3888 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3889 | video_trans_desc = offer->GetTransportDescriptionByName("video"); |
| 3890 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3891 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3892 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
| 3893 | |
| 3894 | // Generate an answer with only SDES support, since tdf2 has crypto disabled. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3895 | answer = f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3896 | ASSERT_TRUE(answer.get() != NULL); |
| 3897 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3898 | audio_media_desc = answer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3899 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3900 | video_media_desc = answer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3901 | ASSERT_TRUE(video_media_desc != NULL); |
| 3902 | EXPECT_EQ(1u, audio_media_desc->cryptos().size()); |
| 3903 | EXPECT_EQ(1u, video_media_desc->cryptos().size()); |
| 3904 | |
| 3905 | audio_trans_desc = answer->GetTransportDescriptionByName("audio"); |
| 3906 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3907 | video_trans_desc = answer->GetTransportDescriptionByName("video"); |
| 3908 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3909 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() == NULL); |
| 3910 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() == NULL); |
| 3911 | |
| 3912 | // Enable DTLS; the answer should now only have DTLS support. |
| 3913 | tdf2_.set_secure(SEC_ENABLED); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3914 | answer = f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3915 | ASSERT_TRUE(answer.get() != NULL); |
| 3916 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3917 | audio_media_desc = answer->GetContentDescriptionByName("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3918 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3919 | video_media_desc = answer->GetContentDescriptionByName("video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3920 | ASSERT_TRUE(video_media_desc != NULL); |
| 3921 | EXPECT_TRUE(audio_media_desc->cryptos().empty()); |
| 3922 | EXPECT_TRUE(video_media_desc->cryptos().empty()); |
Steve Anton | e38a5a1 | 2018-11-21 16:05:15 -0800 | [diff] [blame] | 3923 | EXPECT_EQ(cricket::kMediaProtocolSavpf, audio_media_desc->protocol()); |
| 3924 | EXPECT_EQ(cricket::kMediaProtocolSavpf, video_media_desc->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3925 | |
| 3926 | audio_trans_desc = answer->GetTransportDescriptionByName("audio"); |
| 3927 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3928 | video_trans_desc = answer->GetTransportDescriptionByName("video"); |
| 3929 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3930 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3931 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3932 | |
| 3933 | // Try creating offer again. DTLS enabled now, crypto's should be empty |
| 3934 | // in new offer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3935 | offer = f1_.CreateOffer(options, offer.get()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3936 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3937 | audio_media_desc = offer->GetContentDescriptionByName("audio"); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3938 | ASSERT_TRUE(audio_media_desc != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3939 | video_media_desc = offer->GetContentDescriptionByName("video"); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3940 | ASSERT_TRUE(video_media_desc != NULL); |
| 3941 | EXPECT_TRUE(audio_media_desc->cryptos().empty()); |
| 3942 | EXPECT_TRUE(video_media_desc->cryptos().empty()); |
| 3943 | |
| 3944 | audio_trans_desc = offer->GetTransportDescriptionByName("audio"); |
| 3945 | ASSERT_TRUE(audio_trans_desc != NULL); |
| 3946 | video_trans_desc = offer->GetTransportDescriptionByName("video"); |
| 3947 | ASSERT_TRUE(video_trans_desc != NULL); |
| 3948 | ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 3949 | ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | // Test that an answer can't be created if cryptos are required but the offer is |
| 3953 | // unsecure. |
| 3954 | TEST_F(MediaSessionDescriptionFactoryTest, TestSecureAnswerToUnsecureOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3955 | MediaSessionOptions options = CreatePlanBMediaSessionOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3956 | f1_.set_secure(SEC_DISABLED); |
| 3957 | tdf1_.set_secure(SEC_DISABLED); |
| 3958 | f2_.set_secure(SEC_REQUIRED); |
| 3959 | tdf1_.set_secure(SEC_ENABLED); |
| 3960 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3961 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3962 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3963 | std::unique_ptr<SessionDescription> answer = |
| 3964 | f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3965 | EXPECT_TRUE(answer.get() == NULL); |
| 3966 | } |
| 3967 | |
| 3968 | // Test that we accept a DTLS offer without SDES and create an appropriate |
| 3969 | // answer. |
| 3970 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { |
| 3971 | f1_.set_secure(SEC_DISABLED); |
| 3972 | f2_.set_secure(SEC_ENABLED); |
| 3973 | tdf1_.set_secure(SEC_ENABLED); |
| 3974 | tdf2_.set_secure(SEC_ENABLED); |
| 3975 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 3976 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
| 3977 | AddDataSection(cricket::DCT_RTP, RtpTransceiverDirection::kRecvOnly, |
| 3978 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3979 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3980 | // Generate an offer with DTLS but without SDES. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 3981 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3982 | ASSERT_TRUE(offer.get() != NULL); |
| 3983 | |
| 3984 | const AudioContentDescription* audio_offer = |
| 3985 | GetFirstAudioContentDescription(offer.get()); |
| 3986 | ASSERT_TRUE(audio_offer->cryptos().empty()); |
| 3987 | const VideoContentDescription* video_offer = |
| 3988 | GetFirstVideoContentDescription(offer.get()); |
| 3989 | ASSERT_TRUE(video_offer->cryptos().empty()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 3990 | const RtpDataContentDescription* data_offer = |
| 3991 | GetFirstRtpDataContentDescription(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3992 | ASSERT_TRUE(data_offer->cryptos().empty()); |
| 3993 | |
| 3994 | const cricket::TransportDescription* audio_offer_trans_desc = |
| 3995 | offer->GetTransportDescriptionByName("audio"); |
| 3996 | ASSERT_TRUE(audio_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 3997 | const cricket::TransportDescription* video_offer_trans_desc = |
| 3998 | offer->GetTransportDescriptionByName("video"); |
| 3999 | ASSERT_TRUE(video_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 4000 | const cricket::TransportDescription* data_offer_trans_desc = |
| 4001 | offer->GetTransportDescriptionByName("data"); |
| 4002 | ASSERT_TRUE(data_offer_trans_desc->identity_fingerprint.get() != NULL); |
| 4003 | |
| 4004 | // Generate an answer with DTLS. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4005 | std::unique_ptr<SessionDescription> answer = |
| 4006 | f2_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4007 | ASSERT_TRUE(answer.get() != NULL); |
| 4008 | |
| 4009 | const cricket::TransportDescription* audio_answer_trans_desc = |
| 4010 | answer->GetTransportDescriptionByName("audio"); |
| 4011 | EXPECT_TRUE(audio_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 4012 | const cricket::TransportDescription* video_answer_trans_desc = |
| 4013 | answer->GetTransportDescriptionByName("video"); |
| 4014 | EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 4015 | const cricket::TransportDescription* data_answer_trans_desc = |
| 4016 | answer->GetTransportDescriptionByName("data"); |
| 4017 | EXPECT_TRUE(data_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 4018 | } |
| 4019 | |
| 4020 | // Verifies if vad_enabled option is set to false, CN codecs are not present in |
| 4021 | // offer or answer. |
| 4022 | TEST_F(MediaSessionDescriptionFactoryTest, TestVADEnableOption) { |
| 4023 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4024 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4025 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4026 | ASSERT_TRUE(offer.get() != NULL); |
| 4027 | const ContentInfo* audio_content = offer->GetContentByName("audio"); |
| 4028 | EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); |
| 4029 | |
| 4030 | options.vad_enabled = false; |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4031 | offer = f1_.CreateOffer(options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4032 | ASSERT_TRUE(offer.get() != NULL); |
| 4033 | audio_content = offer->GetContentByName("audio"); |
| 4034 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4035 | std::unique_ptr<SessionDescription> answer = |
| 4036 | f1_.CreateAnswer(offer.get(), options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4037 | ASSERT_TRUE(answer.get() != NULL); |
| 4038 | audio_content = answer->GetContentByName("audio"); |
| 4039 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
| 4040 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4041 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4042 | // Test that the generated MIDs match the existing offer. |
| 4043 | TEST_F(MediaSessionDescriptionFactoryTest, TestMIDsMatchesExistingOffer) { |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4044 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4045 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_modified", |
| 4046 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 4047 | &opts); |
| 4048 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_modified", |
| 4049 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 4050 | &opts); |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4051 | opts.data_channel_type = cricket::DCT_SCTP; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4052 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data_modified", |
| 4053 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4054 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4055 | // Create offer. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4056 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 4057 | std::unique_ptr<SessionDescription> updated_offer( |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4058 | f1_.CreateOffer(opts, offer.get())); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4059 | |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 4060 | const ContentInfo* audio_content = GetFirstAudioContent(updated_offer.get()); |
| 4061 | const ContentInfo* video_content = GetFirstVideoContent(updated_offer.get()); |
| 4062 | const ContentInfo* data_content = GetFirstDataContent(updated_offer.get()); |
| 4063 | ASSERT_TRUE(audio_content != nullptr); |
| 4064 | ASSERT_TRUE(video_content != nullptr); |
| 4065 | ASSERT_TRUE(data_content != nullptr); |
| 4066 | EXPECT_EQ("audio_modified", audio_content->name); |
| 4067 | EXPECT_EQ("video_modified", video_content->name); |
| 4068 | EXPECT_EQ("data_modified", data_content->name); |
| 4069 | } |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4070 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4071 | // The following tests verify that the unified plan SDP is supported. |
| 4072 | // Test that we can create an offer with multiple media sections of same media |
| 4073 | // type. |
| 4074 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4075 | CreateOfferWithMultipleAVMediaSections) { |
| 4076 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4077 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 4078 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4079 | &opts); |
| 4080 | AttachSenderToMediaDescriptionOptions( |
| 4081 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4082 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4083 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 4084 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4085 | &opts); |
| 4086 | AttachSenderToMediaDescriptionOptions( |
| 4087 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4088 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4089 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 4090 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4091 | &opts); |
| 4092 | AttachSenderToMediaDescriptionOptions( |
| 4093 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4094 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4095 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 4096 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4097 | &opts); |
| 4098 | AttachSenderToMediaDescriptionOptions( |
| 4099 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4100 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4101 | ASSERT_TRUE(offer); |
| 4102 | |
| 4103 | ASSERT_EQ(4u, offer->contents().size()); |
| 4104 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 4105 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4106 | offer->contents()[0].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4107 | ASSERT_EQ(1u, acd->streams().size()); |
| 4108 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4109 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4110 | |
| 4111 | EXPECT_FALSE(offer->contents()[1].rejected); |
| 4112 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4113 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4114 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4115 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4116 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4117 | |
| 4118 | EXPECT_FALSE(offer->contents()[2].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4119 | acd = offer->contents()[2].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4120 | ASSERT_EQ(1u, acd->streams().size()); |
| 4121 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4122 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4123 | |
| 4124 | EXPECT_FALSE(offer->contents()[3].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4125 | vcd = offer->contents()[3].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4126 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4127 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4128 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | // Test that we can create an answer with multiple media sections of same media |
| 4132 | // type. |
| 4133 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4134 | CreateAnswerWithMultipleAVMediaSections) { |
| 4135 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4136 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 4137 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4138 | &opts); |
| 4139 | AttachSenderToMediaDescriptionOptions( |
| 4140 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4141 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4142 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 4143 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4144 | &opts); |
| 4145 | AttachSenderToMediaDescriptionOptions( |
| 4146 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4147 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4148 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 4149 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4150 | &opts); |
| 4151 | AttachSenderToMediaDescriptionOptions( |
| 4152 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4153 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4154 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 4155 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4156 | &opts); |
| 4157 | AttachSenderToMediaDescriptionOptions( |
| 4158 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4159 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4160 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4161 | ASSERT_TRUE(offer); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4162 | std::unique_ptr<SessionDescription> answer = |
| 4163 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4164 | |
| 4165 | ASSERT_EQ(4u, answer->contents().size()); |
| 4166 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 4167 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4168 | answer->contents()[0].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4169 | ASSERT_EQ(1u, acd->streams().size()); |
| 4170 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4171 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4172 | |
| 4173 | EXPECT_FALSE(answer->contents()[1].rejected); |
| 4174 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4175 | answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4176 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4177 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4178 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4179 | |
| 4180 | EXPECT_FALSE(answer->contents()[2].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4181 | acd = answer->contents()[2].media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4182 | ASSERT_EQ(1u, acd->streams().size()); |
| 4183 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4184 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4185 | |
| 4186 | EXPECT_FALSE(answer->contents()[3].rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4187 | vcd = answer->contents()[3].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4188 | ASSERT_EQ(1u, vcd->streams().size()); |
| 4189 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4190 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | // Test that the media section will be rejected in offer if the corresponding |
| 4194 | // MediaDescriptionOptions is stopped by the offerer. |
| 4195 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4196 | CreateOfferWithMediaSectionStoppedByOfferer) { |
| 4197 | // Create an offer with two audio sections and one of them is stopped. |
| 4198 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4199 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4200 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4201 | &offer_opts); |
| 4202 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4203 | RtpTransceiverDirection::kInactive, kStopped, |
| 4204 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4205 | std::unique_ptr<SessionDescription> offer = |
| 4206 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4207 | ASSERT_TRUE(offer); |
| 4208 | ASSERT_EQ(2u, offer->contents().size()); |
| 4209 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 4210 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 4211 | } |
| 4212 | |
| 4213 | // Test that the media section will be rejected in answer if the corresponding |
| 4214 | // MediaDescriptionOptions is stopped by the offerer. |
| 4215 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4216 | CreateAnswerWithMediaSectionStoppedByOfferer) { |
| 4217 | // Create an offer with two audio sections and one of them is stopped. |
| 4218 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4219 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4220 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4221 | &offer_opts); |
| 4222 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4223 | RtpTransceiverDirection::kInactive, kStopped, |
| 4224 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4225 | std::unique_ptr<SessionDescription> offer = |
| 4226 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4227 | ASSERT_TRUE(offer); |
| 4228 | ASSERT_EQ(2u, offer->contents().size()); |
| 4229 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 4230 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 4231 | |
| 4232 | // Create an answer based on the offer. |
| 4233 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4234 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4235 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4236 | &answer_opts); |
| 4237 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4238 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4239 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4240 | std::unique_ptr<SessionDescription> answer = |
| 4241 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4242 | ASSERT_EQ(2u, answer->contents().size()); |
| 4243 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 4244 | EXPECT_TRUE(answer->contents()[1].rejected); |
| 4245 | } |
| 4246 | |
| 4247 | // Test that the media section will be rejected in answer if the corresponding |
| 4248 | // MediaDescriptionOptions is stopped by the answerer. |
| 4249 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4250 | CreateAnswerWithMediaSectionRejectedByAnswerer) { |
| 4251 | // Create an offer with two audio sections. |
| 4252 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4253 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4254 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4255 | &offer_opts); |
| 4256 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4257 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4258 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4259 | std::unique_ptr<SessionDescription> offer = |
| 4260 | f1_.CreateOffer(offer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4261 | ASSERT_TRUE(offer); |
| 4262 | ASSERT_EQ(2u, offer->contents().size()); |
| 4263 | ASSERT_FALSE(offer->contents()[0].rejected); |
| 4264 | ASSERT_FALSE(offer->contents()[1].rejected); |
| 4265 | |
| 4266 | // The answerer rejects one of the audio sections. |
| 4267 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4268 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 4269 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4270 | &answer_opts); |
| 4271 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 4272 | RtpTransceiverDirection::kInactive, kStopped, |
| 4273 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4274 | std::unique_ptr<SessionDescription> answer = |
| 4275 | f2_.CreateAnswer(offer.get(), answer_opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4276 | ASSERT_EQ(2u, answer->contents().size()); |
| 4277 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 4278 | EXPECT_TRUE(answer->contents()[1].rejected); |
Zhi Huang | 3518e7b | 2018-01-30 13:20:35 -0800 | [diff] [blame] | 4279 | |
| 4280 | // The TransportInfo of the rejected m= section is expected to be added in the |
| 4281 | // answer. |
| 4282 | EXPECT_EQ(offer->transport_infos().size(), answer->transport_infos().size()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | // Test the generated media sections has the same order of the |
| 4286 | // corresponding MediaDescriptionOptions. |
| 4287 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4288 | CreateOfferRespectsMediaDescriptionOptionsOrder) { |
| 4289 | MediaSessionOptions opts; |
| 4290 | // This tests put video section first because normally audio comes first by |
| 4291 | // default. |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4292 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4293 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4294 | &opts); |
| 4295 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 4296 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4297 | &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4298 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4299 | |
| 4300 | ASSERT_TRUE(offer); |
| 4301 | ASSERT_EQ(2u, offer->contents().size()); |
| 4302 | EXPECT_EQ("video", offer->contents()[0].name); |
| 4303 | EXPECT_EQ("audio", offer->contents()[1].name); |
| 4304 | } |
| 4305 | |
| 4306 | // Test that different media sections using the same codec have same payload |
| 4307 | // type. |
| 4308 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4309 | PayloadTypesSharedByMediaSectionsOfSameType) { |
| 4310 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4311 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4312 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4313 | &opts); |
| 4314 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4315 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4316 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4317 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4318 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4319 | ASSERT_TRUE(offer); |
| 4320 | ASSERT_EQ(2u, offer->contents().size()); |
| 4321 | const VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4322 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4323 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4324 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4325 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 4326 | ASSERT_EQ(2u, vcd1->codecs().size()); |
| 4327 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 4328 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 4329 | EXPECT_EQ(vcd1->codecs()[1].name, vcd2->codecs()[1].name); |
| 4330 | EXPECT_EQ(vcd1->codecs()[1].id, vcd2->codecs()[1].id); |
| 4331 | |
| 4332 | // Create answer and negotiate the codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4333 | std::unique_ptr<SessionDescription> answer = |
| 4334 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4335 | ASSERT_TRUE(answer); |
| 4336 | ASSERT_EQ(2u, answer->contents().size()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4337 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4338 | vcd2 = answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4339 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 4340 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4341 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 4342 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 4343 | } |
| 4344 | |
| 4345 | // Test that the codec preference order per media section is respected in |
| 4346 | // subsequent offer. |
| 4347 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4348 | CreateOfferRespectsCodecPreferenceOrder) { |
| 4349 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4350 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4351 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4352 | &opts); |
| 4353 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4354 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4355 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4356 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4357 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4358 | ASSERT_TRUE(offer); |
| 4359 | ASSERT_EQ(2u, offer->contents().size()); |
| 4360 | VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4361 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4362 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4363 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4364 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4365 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4366 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4367 | |
| 4368 | // Change the codec preference of the first video section and create a |
| 4369 | // follow-up offer. |
| 4370 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4371 | vcd1->set_codecs(video_codecs_reverse); |
| 4372 | std::unique_ptr<SessionDescription> updated_offer( |
| 4373 | f1_.CreateOffer(opts, offer.get())); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4374 | vcd1 = updated_offer->contents()[0].media_description()->as_video(); |
| 4375 | vcd2 = updated_offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4376 | // The video codec preference order should be respected. |
| 4377 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4378 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4379 | } |
| 4380 | |
| 4381 | // Test that the codec preference order per media section is respected in |
| 4382 | // the answer. |
| 4383 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4384 | CreateAnswerRespectsCodecPreferenceOrder) { |
| 4385 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4386 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4387 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4388 | &opts); |
| 4389 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4390 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4391 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4392 | // Create an offer with two video sections using same codecs. |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4393 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4394 | ASSERT_TRUE(offer); |
| 4395 | ASSERT_EQ(2u, offer->contents().size()); |
| 4396 | VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4397 | offer->contents()[0].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4398 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4399 | offer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4400 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4401 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4402 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4403 | |
| 4404 | // Change the codec preference of the first video section and create an |
| 4405 | // answer. |
| 4406 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4407 | vcd1->set_codecs(video_codecs_reverse); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4408 | std::unique_ptr<SessionDescription> answer = |
| 4409 | f1_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4410 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4411 | vcd2 = answer->contents()[1].media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4412 | // The video codec preference order should be respected. |
| 4413 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4414 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4415 | } |
| 4416 | |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4417 | // Test that when creating an answer, the codecs use local parameters instead of |
| 4418 | // the remote ones. |
| 4419 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerWithLocalCodecParams) { |
| 4420 | const std::string audio_param_name = "audio_param"; |
| 4421 | const std::string audio_value1 = "audio_v1"; |
| 4422 | const std::string audio_value2 = "audio_v2"; |
| 4423 | const std::string video_param_name = "video_param"; |
| 4424 | const std::string video_value1 = "video_v1"; |
| 4425 | const std::string video_value2 = "video_v2"; |
| 4426 | |
| 4427 | auto audio_codecs1 = MAKE_VECTOR(kAudioCodecs1); |
| 4428 | auto audio_codecs2 = MAKE_VECTOR(kAudioCodecs1); |
| 4429 | auto video_codecs1 = MAKE_VECTOR(kVideoCodecs1); |
| 4430 | auto video_codecs2 = MAKE_VECTOR(kVideoCodecs1); |
| 4431 | |
| 4432 | // Set the parameters for codecs. |
| 4433 | audio_codecs1[0].SetParam(audio_param_name, audio_value1); |
| 4434 | video_codecs1[0].SetParam(video_param_name, video_value1); |
| 4435 | audio_codecs2[0].SetParam(audio_param_name, audio_value2); |
| 4436 | video_codecs2[0].SetParam(video_param_name, video_value2); |
| 4437 | |
| 4438 | f1_.set_audio_codecs(audio_codecs1, audio_codecs1); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4439 | f1_.set_video_codecs(video_codecs1, video_codecs1); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4440 | f2_.set_audio_codecs(audio_codecs2, audio_codecs2); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4441 | f2_.set_video_codecs(video_codecs2, video_codecs2); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4442 | |
| 4443 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4444 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 4445 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4446 | &opts); |
| 4447 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4448 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4449 | &opts); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4450 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4451 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4452 | ASSERT_TRUE(offer); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4453 | auto offer_acd = offer->contents()[0].media_description()->as_audio(); |
| 4454 | auto offer_vcd = offer->contents()[1].media_description()->as_video(); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4455 | std::string value; |
| 4456 | EXPECT_TRUE(offer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4457 | EXPECT_EQ(audio_value1, value); |
| 4458 | EXPECT_TRUE(offer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4459 | EXPECT_EQ(video_value1, value); |
| 4460 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4461 | std::unique_ptr<SessionDescription> answer = |
| 4462 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4463 | ASSERT_TRUE(answer); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4464 | auto answer_acd = answer->contents()[0].media_description()->as_audio(); |
| 4465 | auto answer_vcd = answer->contents()[1].media_description()->as_video(); |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 4466 | // Use the parameters from the local codecs. |
| 4467 | EXPECT_TRUE(answer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4468 | EXPECT_EQ(audio_value2, value); |
| 4469 | EXPECT_TRUE(answer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4470 | EXPECT_EQ(video_value2, value); |
| 4471 | } |
| 4472 | |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4473 | // Test that matching packetization-mode is part of the criteria for matching |
| 4474 | // H264 codecs (in addition to profile-level-id). Previously, this was not the |
| 4475 | // case, so the first H264 codec with the same profile-level-id would match and |
| 4476 | // the payload type in the answer would be incorrect. |
| 4477 | // This is a regression test for bugs.webrtc.org/8808 |
| 4478 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4479 | H264MatchCriteriaIncludesPacketizationMode) { |
| 4480 | // Create two H264 codecs with the same profile level ID and different |
| 4481 | // packetization modes. |
| 4482 | VideoCodec h264_pm0(96, "H264"); |
| 4483 | h264_pm0.params[cricket::kH264FmtpProfileLevelId] = "42c01f"; |
| 4484 | h264_pm0.params[cricket::kH264FmtpPacketizationMode] = "0"; |
| 4485 | VideoCodec h264_pm1(97, "H264"); |
| 4486 | h264_pm1.params[cricket::kH264FmtpProfileLevelId] = "42c01f"; |
| 4487 | h264_pm1.params[cricket::kH264FmtpPacketizationMode] = "1"; |
| 4488 | |
| 4489 | // Offerer will send both codecs, answerer should choose the one with matching |
| 4490 | // packetization mode (and not the first one it sees). |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4491 | f1_.set_video_codecs({h264_pm0, h264_pm1}, {h264_pm0, h264_pm1}); |
| 4492 | f2_.set_video_codecs({h264_pm1}, {h264_pm1}); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4493 | |
| 4494 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4495 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4496 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4497 | &opts); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4498 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4499 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4500 | ASSERT_TRUE(offer); |
| 4501 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4502 | std::unique_ptr<SessionDescription> answer = |
| 4503 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
Steve Anton | 9c1fb1e | 2018-02-26 15:09:41 -0800 | [diff] [blame] | 4504 | ASSERT_TRUE(answer); |
| 4505 | |
| 4506 | // Answer should have one negotiated codec with packetization-mode=1 using the |
| 4507 | // offered payload type. |
| 4508 | ASSERT_EQ(1u, answer->contents().size()); |
| 4509 | auto answer_vcd = answer->contents()[0].media_description()->as_video(); |
| 4510 | ASSERT_EQ(1u, answer_vcd->codecs().size()); |
| 4511 | auto answer_codec = answer_vcd->codecs()[0]; |
| 4512 | EXPECT_EQ(h264_pm1.id, answer_codec.id); |
| 4513 | } |
| 4514 | |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4515 | class MediaProtocolTest : public ::testing::TestWithParam<const char*> { |
| 4516 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4517 | MediaProtocolTest() |
| 4518 | : f1_(&tdf1_, &ssrc_generator1), f2_(&tdf2_, &ssrc_generator2) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4519 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 4520 | MAKE_VECTOR(kAudioCodecs1)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4521 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1), |
| 4522 | MAKE_VECTOR(kVideoCodecs1)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 4523 | f1_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4524 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 4525 | MAKE_VECTOR(kAudioCodecs2)); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 4526 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2), |
| 4527 | MAKE_VECTOR(kVideoCodecs2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 4528 | f2_.set_rtp_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4529 | f1_.set_secure(SEC_ENABLED); |
| 4530 | f2_.set_secure(SEC_ENABLED); |
| 4531 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 4532 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4533 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 4534 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4535 | tdf1_.set_secure(SEC_ENABLED); |
| 4536 | tdf2_.set_secure(SEC_ENABLED); |
| 4537 | } |
| 4538 | |
| 4539 | protected: |
| 4540 | MediaSessionDescriptionFactory f1_; |
| 4541 | MediaSessionDescriptionFactory f2_; |
| 4542 | TransportDescriptionFactory tdf1_; |
| 4543 | TransportDescriptionFactory tdf2_; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4544 | UniqueRandomIdGenerator ssrc_generator1; |
| 4545 | UniqueRandomIdGenerator ssrc_generator2; |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4546 | }; |
| 4547 | |
| 4548 | TEST_P(MediaProtocolTest, TestAudioVideoAcceptance) { |
| 4549 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4550 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4551 | std::unique_ptr<SessionDescription> offer = f1_.CreateOffer(opts, nullptr); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4552 | ASSERT_TRUE(offer.get() != nullptr); |
| 4553 | // Set the protocol for all the contents. |
Harald Alvestrand | 1716d39 | 2019-06-03 20:35:45 +0200 | [diff] [blame] | 4554 | for (auto& content : offer.get()->contents()) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4555 | content.media_description()->set_protocol(GetParam()); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4556 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4557 | std::unique_ptr<SessionDescription> answer = |
| 4558 | f2_.CreateAnswer(offer.get(), opts, nullptr); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4559 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4560 | const ContentInfo* vc = answer->GetContentByName("video"); |
| 4561 | ASSERT_TRUE(ac != nullptr); |
| 4562 | ASSERT_TRUE(vc != nullptr); |
| 4563 | EXPECT_FALSE(ac->rejected); // the offer is accepted |
| 4564 | EXPECT_FALSE(vc->rejected); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4565 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
| 4566 | const VideoContentDescription* vcd = vc->media_description()->as_video(); |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 4567 | EXPECT_EQ(GetParam(), acd->protocol()); |
| 4568 | EXPECT_EQ(GetParam(), vcd->protocol()); |
| 4569 | } |
| 4570 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4571 | INSTANTIATE_TEST_SUITE_P(MediaProtocolPatternTest, |
| 4572 | MediaProtocolTest, |
| 4573 | ::testing::ValuesIn(kMediaProtocols)); |
| 4574 | INSTANTIATE_TEST_SUITE_P(MediaProtocolDtlsPatternTest, |
| 4575 | MediaProtocolTest, |
| 4576 | ::testing::ValuesIn(kMediaProtocolsDtls)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4577 | |
| 4578 | TEST_F(MediaSessionDescriptionFactoryTest, TestSetAudioCodecs) { |
| 4579 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4580 | UniqueRandomIdGenerator ssrc_generator; |
| 4581 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4582 | std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4583 | std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4584 | |
| 4585 | // The merged list of codecs should contain any send codecs that are also |
| 4586 | // nominally in the recieve codecs list. Payload types should be picked from |
| 4587 | // the send codecs and a number-of-channels of 0 and 1 should be equivalent |
| 4588 | // (set to 1). This equals what happens when the send codecs are used in an |
| 4589 | // offer and the receive codecs are used in the following answer. |
| 4590 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4591 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4592 | const std::vector<AudioCodec> no_codecs; |
| 4593 | |
| 4594 | RTC_CHECK_EQ(send_codecs[1].name, "iLBC") |
| 4595 | << "Please don't change shared test data!"; |
| 4596 | RTC_CHECK_EQ(recv_codecs[2].name, "iLBC") |
| 4597 | << "Please don't change shared test data!"; |
| 4598 | // Alter iLBC send codec to have zero channels, to test that that is handled |
| 4599 | // properly. |
| 4600 | send_codecs[1].channels = 0; |
| 4601 | |
Philipp Hancke | b41316c | 2020-05-26 13:45:20 +0200 | [diff] [blame] | 4602 | // Alter iLBC receive codec to be lowercase, to test that case conversions |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4603 | // are handled properly. |
| 4604 | recv_codecs[2].name = "ilbc"; |
| 4605 | |
| 4606 | // Test proper merge |
| 4607 | sf.set_audio_codecs(send_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4608 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4609 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4610 | EXPECT_EQ(sendrecv_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4611 | |
| 4612 | // Test empty send codecs list |
| 4613 | sf.set_audio_codecs(no_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4614 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4615 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4616 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4617 | |
| 4618 | // Test empty recv codecs list |
| 4619 | sf.set_audio_codecs(send_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4620 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4621 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4622 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4623 | |
| 4624 | // Test all empty codec lists |
| 4625 | sf.set_audio_codecs(no_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4626 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4627 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4628 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | namespace { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4632 | // Compare the two vectors of codecs ignoring the payload type. |
| 4633 | template <class Codec> |
| 4634 | bool CodecsMatch(const std::vector<Codec>& codecs1, |
| 4635 | const std::vector<Codec>& codecs2) { |
| 4636 | if (codecs1.size() != codecs2.size()) { |
| 4637 | return false; |
| 4638 | } |
| 4639 | |
| 4640 | for (size_t i = 0; i < codecs1.size(); ++i) { |
| 4641 | if (!codecs1[i].Matches(codecs2[i])) { |
| 4642 | return false; |
| 4643 | } |
| 4644 | } |
| 4645 | return true; |
| 4646 | } |
| 4647 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4648 | void TestAudioCodecsOffer(RtpTransceiverDirection direction) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4649 | TransportDescriptionFactory tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4650 | UniqueRandomIdGenerator ssrc_generator; |
| 4651 | MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4652 | const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4653 | const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4654 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4655 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4656 | sf.set_audio_codecs(send_codecs, recv_codecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4657 | |
| 4658 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4659 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 4660 | &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4661 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4662 | if (direction == RtpTransceiverDirection::kSendRecv || |
| 4663 | direction == RtpTransceiverDirection::kSendOnly) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4664 | AttachSenderToMediaDescriptionOptions( |
| 4665 | "audio", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4666 | } |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4667 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4668 | std::unique_ptr<SessionDescription> offer = sf.CreateOffer(opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4669 | ASSERT_TRUE(offer.get() != NULL); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4670 | ContentInfo* ac = offer->GetContentByName("audio"); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4671 | |
| 4672 | // 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] | 4673 | // that the codecs put in are right. This happens when we neither want to |
| 4674 | // send nor receive audio. The checks are still in place if at some point |
| 4675 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4676 | if (ac) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4677 | AudioContentDescription* acd = ac->media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4678 | // sendrecv and inactive should both present lists as if the channel was |
| 4679 | // to be used for sending and receiving. Inactive essentially means it |
| 4680 | // might eventually be used anything, but we don't know more at this |
| 4681 | // moment. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4682 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4683 | EXPECT_TRUE(CodecsMatch<AudioCodec>(send_codecs, acd->codecs())); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4684 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4685 | EXPECT_TRUE(CodecsMatch<AudioCodec>(recv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4686 | } else { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4687 | EXPECT_TRUE(CodecsMatch<AudioCodec>(sendrecv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4688 | } |
| 4689 | } |
| 4690 | } |
| 4691 | |
| 4692 | static const AudioCodec kOfferAnswerCodecs[] = { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4693 | AudioCodec(0, "codec0", 16000, -1, 1), |
| 4694 | AudioCodec(1, "codec1", 8000, 13300, 1), |
| 4695 | AudioCodec(2, "codec2", 8000, 64000, 1), |
| 4696 | AudioCodec(3, "codec3", 8000, 64000, 1), |
| 4697 | AudioCodec(4, "codec4", 8000, 0, 2), |
| 4698 | AudioCodec(5, "codec5", 32000, 0, 1), |
| 4699 | AudioCodec(6, "codec6", 48000, 0, 1)}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4700 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4701 | /* The codecs groups below are chosen as per the matrix below. The objective |
| 4702 | * is to have different sets of codecs in the inputs, to get unique sets of |
| 4703 | * codecs after negotiation, depending on offer and answer communication |
| 4704 | * directions. One-way directions in the offer should either result in the |
| 4705 | * opposite direction in the answer, or an inactive answer. Regardless, the |
| 4706 | * choice of codecs should be as if the answer contained the opposite |
| 4707 | * direction. Inactive offers should be treated as sendrecv/sendrecv. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4708 | * |
| 4709 | * | Offer | Answer | Result |
| 4710 | * codec|send recv sr | send recv sr | s/r r/s sr/s sr/r sr/sr |
| 4711 | * 0 | x - - | - x - | x - - - - |
| 4712 | * 1 | x x x | - x - | x - - x - |
| 4713 | * 2 | - x - | x - - | - x - - - |
| 4714 | * 3 | x x x | x - - | - x x - - |
| 4715 | * 4 | - x - | x x x | - x - - - |
| 4716 | * 5 | x - - | x x x | x - - - - |
| 4717 | * 6 | x x x | x x x | x x x x x |
| 4718 | */ |
| 4719 | // Codecs used by offerer in the AudioCodecsAnswerTest |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4720 | static const int kOfferSendCodecs[] = {0, 1, 3, 5, 6}; |
| 4721 | static const int kOfferRecvCodecs[] = {1, 2, 3, 4, 6}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4722 | // Codecs used in the answerer in the AudioCodecsAnswerTest. The order is |
| 4723 | // jumbled to catch the answer not following the order in the offer. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4724 | static const int kAnswerSendCodecs[] = {6, 5, 2, 3, 4}; |
| 4725 | static const int kAnswerRecvCodecs[] = {6, 5, 4, 1, 0}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4726 | // The resulting sets of codecs in the answer in the AudioCodecsAnswerTest |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4727 | static const int kResultSend_RecvCodecs[] = {0, 1, 5, 6}; |
| 4728 | static const int kResultRecv_SendCodecs[] = {2, 3, 4, 6}; |
| 4729 | static const int kResultSendrecv_SendCodecs[] = {3, 6}; |
| 4730 | static const int kResultSendrecv_RecvCodecs[] = {1, 6}; |
| 4731 | static const int kResultSendrecv_SendrecvCodecs[] = {6}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4732 | |
| 4733 | template <typename T, int IDXS> |
| 4734 | std::vector<T> VectorFromIndices(const T* array, const int (&indices)[IDXS]) { |
| 4735 | std::vector<T> out; |
| 4736 | out.reserve(IDXS); |
| 4737 | for (int idx : indices) |
| 4738 | out.push_back(array[idx]); |
| 4739 | |
| 4740 | return out; |
| 4741 | } |
| 4742 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4743 | void TestAudioCodecsAnswer(RtpTransceiverDirection offer_direction, |
| 4744 | RtpTransceiverDirection answer_direction, |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4745 | bool add_legacy_stream) { |
| 4746 | TransportDescriptionFactory offer_tdf; |
| 4747 | TransportDescriptionFactory answer_tdf; |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 4748 | UniqueRandomIdGenerator ssrc_generator1, ssrc_generator2; |
| 4749 | MediaSessionDescriptionFactory offer_factory(&offer_tdf, &ssrc_generator1); |
| 4750 | MediaSessionDescriptionFactory answer_factory(&answer_tdf, &ssrc_generator2); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4751 | offer_factory.set_audio_codecs( |
| 4752 | VectorFromIndices(kOfferAnswerCodecs, kOfferSendCodecs), |
| 4753 | VectorFromIndices(kOfferAnswerCodecs, kOfferRecvCodecs)); |
| 4754 | answer_factory.set_audio_codecs( |
| 4755 | VectorFromIndices(kOfferAnswerCodecs, kAnswerSendCodecs), |
| 4756 | VectorFromIndices(kOfferAnswerCodecs, kAnswerRecvCodecs)); |
| 4757 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4758 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4759 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", offer_direction, |
| 4760 | kActive, &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4761 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4762 | if (webrtc::RtpTransceiverDirectionHasSend(offer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4763 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4764 | kAudioTrack1, {kMediaStream1}, 1, |
| 4765 | &offer_opts); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4766 | } |
| 4767 | |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4768 | std::unique_ptr<SessionDescription> offer = |
| 4769 | offer_factory.CreateOffer(offer_opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4770 | ASSERT_TRUE(offer.get() != NULL); |
| 4771 | |
| 4772 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4773 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", answer_direction, |
| 4774 | kActive, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4775 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4776 | if (webrtc::RtpTransceiverDirectionHasSend(answer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 10:13:58 -0800 | [diff] [blame] | 4777 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4778 | kAudioTrack1, {kMediaStream1}, 1, |
| 4779 | &answer_opts); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4780 | } |
Steve Anton | 6fe1fba | 2018-12-11 10:15:23 -0800 | [diff] [blame] | 4781 | std::unique_ptr<SessionDescription> answer = |
| 4782 | answer_factory.CreateAnswer(offer.get(), answer_opts, NULL); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4783 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4784 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4785 | // If the factory didn't add any audio content to the answer, we cannot |
| 4786 | // check that the codecs put in are right. This happens when we neither want |
| 4787 | // to send nor receive audio. The checks are still in place if at some point |
| 4788 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4789 | if (ac) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 4790 | ASSERT_EQ(MEDIA_TYPE_AUDIO, ac->media_description()->type()); |
| 4791 | const AudioContentDescription* acd = ac->media_description()->as_audio(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4792 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4793 | std::vector<AudioCodec> target_codecs; |
| 4794 | // For offers with sendrecv or inactive, we should never reply with more |
| 4795 | // codecs than offered, with these codec sets. |
| 4796 | switch (offer_direction) { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4797 | case RtpTransceiverDirection::kInactive: |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4798 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4799 | kResultSendrecv_SendrecvCodecs); |
| 4800 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4801 | case RtpTransceiverDirection::kSendOnly: |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4802 | target_codecs = |
| 4803 | VectorFromIndices(kOfferAnswerCodecs, kResultSend_RecvCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4804 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4805 | case RtpTransceiverDirection::kRecvOnly: |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4806 | target_codecs = |
| 4807 | VectorFromIndices(kOfferAnswerCodecs, kResultRecv_SendCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4808 | break; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4809 | case RtpTransceiverDirection::kSendRecv: |
| 4810 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4811 | target_codecs = |
| 4812 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_SendCodecs); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4813 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4814 | target_codecs = |
| 4815 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_RecvCodecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4816 | } else { |
| 4817 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4818 | kResultSendrecv_SendrecvCodecs); |
| 4819 | } |
| 4820 | break; |
Markus Handell | 45c104b | 2020-03-11 10:51:13 +0100 | [diff] [blame] | 4821 | default: |
| 4822 | RTC_NOTREACHED(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4823 | } |
| 4824 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4825 | auto format_codecs = [](const std::vector<AudioCodec>& codecs) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 4826 | rtc::StringBuilder os; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4827 | bool first = true; |
| 4828 | os << "{"; |
| 4829 | for (const auto& c : codecs) { |
| 4830 | os << (first ? " " : ", ") << c.id; |
| 4831 | first = false; |
| 4832 | } |
| 4833 | os << " }"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 4834 | return os.Release(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4835 | }; |
| 4836 | |
| 4837 | EXPECT_TRUE(acd->codecs() == target_codecs) |
| 4838 | << "Expected: " << format_codecs(target_codecs) |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4839 | << ", got: " << format_codecs(acd->codecs()) << "; Offered: " |
| 4840 | << webrtc::RtpTransceiverDirectionToString(offer_direction) |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4841 | << ", answerer wants: " |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4842 | << webrtc::RtpTransceiverDirectionToString(answer_direction) |
| 4843 | << "; got: " |
| 4844 | << webrtc::RtpTransceiverDirectionToString(acd->direction()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4845 | } else { |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4846 | EXPECT_EQ(offer_direction, RtpTransceiverDirection::kInactive) |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4847 | << "Only inactive offers are allowed to not generate any audio " |
| 4848 | "content"; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4849 | } |
| 4850 | } |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 4851 | |
| 4852 | } // namespace |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4853 | |
| 4854 | class AudioCodecsOfferTest |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4855 | : public ::testing::TestWithParam<RtpTransceiverDirection> {}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4856 | |
| 4857 | TEST_P(AudioCodecsOfferTest, TestCodecsInOffer) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4858 | TestAudioCodecsOffer(GetParam()); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4859 | } |
| 4860 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4861 | INSTANTIATE_TEST_SUITE_P(MediaSessionDescriptionFactoryTest, |
| 4862 | AudioCodecsOfferTest, |
| 4863 | ::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4864 | RtpTransceiverDirection::kRecvOnly, |
| 4865 | RtpTransceiverDirection::kSendRecv, |
| 4866 | RtpTransceiverDirection::kInactive)); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4867 | |
| 4868 | class AudioCodecsAnswerTest |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4869 | : public ::testing::TestWithParam<::testing::tuple<RtpTransceiverDirection, |
| 4870 | RtpTransceiverDirection, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4871 | bool>> {}; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4872 | |
| 4873 | TEST_P(AudioCodecsAnswerTest, TestCodecsInAnswer) { |
ehmaldonado | abcef5d | 2017-02-08 04:07:11 -0800 | [diff] [blame] | 4874 | TestAudioCodecsAnswer(::testing::get<0>(GetParam()), |
| 4875 | ::testing::get<1>(GetParam()), |
| 4876 | ::testing::get<2>(GetParam())); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4879 | INSTANTIATE_TEST_SUITE_P( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4880 | MediaSessionDescriptionFactoryTest, |
| 4881 | AudioCodecsAnswerTest, |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 4882 | ::testing::Combine(::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4883 | RtpTransceiverDirection::kRecvOnly, |
| 4884 | RtpTransceiverDirection::kSendRecv, |
| 4885 | RtpTransceiverDirection::kInactive), |
| 4886 | ::testing::Values(RtpTransceiverDirection::kSendOnly, |
| 4887 | RtpTransceiverDirection::kRecvOnly, |
| 4888 | RtpTransceiverDirection::kSendRecv, |
| 4889 | RtpTransceiverDirection::kInactive), |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 4890 | ::testing::Bool())); |