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