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