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