henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [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 | [diff] [blame] | 9 | */ |
| 10 | |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 11 | #include "pc/media_session.h" |
| 12 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
Amit Hilbuch | 77938e6 | 2018-12-21 17:23:38 | [diff] [blame] | 15 | #include <algorithm> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 16 | #include <cstdint> |
| 17 | #include <map> |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 18 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 19 | #include <string> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 20 | #include <tuple> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 23 | #include "absl/algorithm/container.h" |
Mirko Bonadei | 57cabed | 2020-04-01 10:03:11 | [diff] [blame] | 24 | #include "absl/strings/match.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 25 | #include "absl/strings/string_view.h" |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 26 | #include "absl/types/optional.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 27 | #include "api/candidate.h" |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 28 | #include "api/rtp_parameters.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 29 | #include "media/base/codec.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 30 | #include "media/base/media_constants.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 31 | #include "media/base/test_utils.h" |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 32 | #include "media/sctp/sctp_transport_internal.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 33 | #include "p2p/base/p2p_constants.h" |
| 34 | #include "p2p/base/transport_description.h" |
| 35 | #include "p2p/base/transport_info.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 36 | #include "pc/media_protocol_names.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 37 | #include "pc/rtp_media_utils.h" |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 38 | #include "pc/rtp_parameters_conversion.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 39 | #include "rtc_base/arraysize.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 40 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 41 | #include "rtc_base/fake_ssl_identity.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 42 | #include "rtc_base/rtc_certificate.h" |
| 43 | #include "rtc_base/ssl_identity.h" |
| 44 | #include "rtc_base/ssl_stream_adapter.h" |
| 45 | #include "rtc_base/string_encode.h" |
Jonas Olsson | 366a50c | 2018-09-06 11:41:30 | [diff] [blame] | 46 | #include "rtc_base/strings/string_builder.h" |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 47 | #include "rtc_base/unique_id_generator.h" |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 48 | #include "test/gmock.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 49 | #include "test/gtest.h" |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 50 | #include "test/scoped_key_value_config.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 51 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 52 | namespace cricket { |
| 53 | namespace { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 54 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 55 | using ::rtc::kCsAeadAes128Gcm; |
| 56 | using ::rtc::kCsAeadAes256Gcm; |
| 57 | using ::rtc::kCsAesCm128HmacSha1_32; |
| 58 | using ::rtc::kCsAesCm128HmacSha1_80; |
| 59 | using ::rtc::UniqueRandomIdGenerator; |
| 60 | using ::testing::Bool; |
| 61 | using ::testing::Combine; |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 62 | using ::testing::Contains; |
| 63 | using ::testing::Each; |
Danil Chapovalov | 5f999a7 | 2020-02-20 15:39:05 | [diff] [blame] | 64 | using ::testing::ElementsAre; |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 65 | using ::testing::ElementsAreArray; |
| 66 | using ::testing::Eq; |
| 67 | using ::testing::Field; |
| 68 | using ::testing::IsEmpty; |
| 69 | using ::testing::IsFalse; |
| 70 | using ::testing::Ne; |
| 71 | using ::testing::Not; |
| 72 | using ::testing::Pointwise; |
| 73 | using ::testing::SizeIs; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 74 | using ::testing::Values; |
| 75 | using ::testing::ValuesIn; |
| 76 | using ::webrtc::RtpExtension; |
| 77 | using ::webrtc::RtpTransceiverDirection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 78 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 79 | using Candidates = std::vector<Candidate>; |
| 80 | |
| 81 | AudioCodec CreateRedAudioCodec(absl::string_view encoding_id) { |
| 82 | AudioCodec red = CreateAudioCodec(63, "red", 48000, 2); |
| 83 | red.SetParam(kCodecParamNotInNameValueFormat, |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 84 | std::string(encoding_id) + '/' + std::string(encoding_id)); |
| 85 | return red; |
| 86 | } |
| 87 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 88 | const AudioCodec kAudioCodecs1[] = {CreateAudioCodec(111, "opus", 48000, 2), |
| 89 | CreateRedAudioCodec("111"), |
| 90 | CreateAudioCodec(102, "iLBC", 8000, 1), |
| 91 | CreateAudioCodec(0, "PCMU", 8000, 1), |
| 92 | CreateAudioCodec(8, "PCMA", 8000, 1), |
| 93 | CreateAudioCodec(117, "red", 8000, 1), |
| 94 | CreateAudioCodec(107, "CN", 48000, 1)}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 95 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 96 | const AudioCodec kAudioCodecs2[] = { |
| 97 | CreateAudioCodec(126, "foo", 16000, 1), |
| 98 | CreateAudioCodec(0, "PCMU", 8000, 1), |
| 99 | CreateAudioCodec(127, "iLBC", 8000, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 100 | }; |
| 101 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 102 | const AudioCodec kAudioCodecsAnswer[] = { |
| 103 | CreateAudioCodec(102, "iLBC", 8000, 1), |
| 104 | CreateAudioCodec(0, "PCMU", 8000, 1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 105 | }; |
| 106 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 107 | const VideoCodec kVideoCodecs1[] = {CreateVideoCodec(96, "H264-SVC"), |
| 108 | CreateVideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 109 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 110 | const VideoCodec kVideoCodecs1Reverse[] = {CreateVideoCodec(97, "H264"), |
| 111 | CreateVideoCodec(96, "H264-SVC")}; |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 112 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 113 | const VideoCodec kVideoCodecs2[] = {CreateVideoCodec(126, "H264"), |
| 114 | CreateVideoCodec(127, "H263")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 115 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 116 | const VideoCodec kVideoCodecsAnswer[] = {CreateVideoCodec(97, "H264")}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 117 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 118 | const RtpExtension kAudioRtpExtension1[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 119 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 120 | RtpExtension("http://google.com/testing/audio_something", 10), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 121 | }; |
| 122 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 123 | const RtpExtension kAudioRtpExtensionEncrypted1[] = { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 124 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
| 125 | RtpExtension("http://google.com/testing/audio_something", 10), |
| 126 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 127 | RtpExtension("http://google.com/testing/audio_something", 11, true), |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 128 | }; |
| 129 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 130 | const RtpExtension kAudioRtpExtension2[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 131 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 2), |
| 132 | RtpExtension("http://google.com/testing/audio_something_else", 8), |
| 133 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 134 | }; |
| 135 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 136 | const RtpExtension kAudioRtpExtension3[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 137 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 138 | RtpExtension("http://google.com/testing/both_audio_and_video", 3), |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 139 | }; |
| 140 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 141 | const RtpExtension kAudioRtpExtension3ForEncryption[] = { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 142 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 143 | // Use RTP extension that supports encryption. |
| 144 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 145 | }; |
| 146 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 147 | const RtpExtension kAudioRtpExtension3ForEncryptionOffer[] = { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 148 | RtpExtension("http://google.com/testing/audio_something", 2), |
| 149 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 150 | RtpExtension("http://google.com/testing/audio_something", 14, true), |
| 151 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 13, true), |
| 152 | }; |
| 153 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 154 | const RtpExtension kVideoRtpExtension3ForEncryptionOffer[] = { |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 155 | RtpExtension("http://google.com/testing/video_something", 4), |
| 156 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 3), |
| 157 | RtpExtension("http://google.com/testing/video_something", 12, true), |
| 158 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 13, true), |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 159 | }; |
| 160 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 161 | const RtpExtension kAudioRtpExtensionAnswer[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 162 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 8), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 163 | }; |
| 164 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 165 | const RtpExtension kAudioRtpExtensionEncryptedAnswer[] = { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 166 | RtpExtension("urn:ietf:params:rtp-hdrext:ssrc-audio-level", 12, true), |
| 167 | }; |
| 168 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 169 | const RtpExtension kVideoRtpExtension1[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 170 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 171 | RtpExtension("http://google.com/testing/video_something", 13), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 172 | }; |
| 173 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 174 | const RtpExtension kVideoRtpExtensionEncrypted1[] = { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 175 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
| 176 | RtpExtension("http://google.com/testing/video_something", 13), |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 177 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 9, true), |
| 178 | RtpExtension("http://google.com/testing/video_something", 7, true), |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 179 | }; |
| 180 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 181 | const RtpExtension kVideoRtpExtension2[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 182 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 2), |
| 183 | RtpExtension("http://google.com/testing/video_something_else", 14), |
| 184 | RtpExtension("http://google.com/testing/both_audio_and_video", 7), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 185 | }; |
| 186 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 187 | const RtpExtension kVideoRtpExtension3[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 188 | RtpExtension("http://google.com/testing/video_something", 4), |
| 189 | RtpExtension("http://google.com/testing/both_audio_and_video", 5), |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 190 | }; |
| 191 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 192 | const RtpExtension kVideoRtpExtension3ForEncryption[] = { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 193 | RtpExtension("http://google.com/testing/video_something", 4), |
| 194 | // Use RTP extension that supports encryption. |
| 195 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 5), |
| 196 | }; |
| 197 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 198 | const RtpExtension kVideoRtpExtensionAnswer[] = { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 199 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 14), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 200 | }; |
| 201 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 202 | const RtpExtension kVideoRtpExtensionEncryptedAnswer[] = { |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 203 | RtpExtension("urn:ietf:params:rtp-hdrext:toffset", 9, true), |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 204 | }; |
| 205 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 206 | const RtpExtension kRtpExtensionTransportSequenceNumber01[] = { |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 207 | RtpExtension("http://www.ietf.org/id/" |
| 208 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 209 | 1), |
| 210 | }; |
| 211 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 212 | const RtpExtension kRtpExtensionTransportSequenceNumber01And02[] = { |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 213 | RtpExtension("http://www.ietf.org/id/" |
| 214 | "draft-holmer-rmcat-transport-wide-cc-extensions-01", |
| 215 | 1), |
Johannes Kron | 8cc711a | 2019-03-07 21:36:35 | [diff] [blame] | 216 | RtpExtension( |
| 217 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 218 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 219 | }; |
| 220 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 221 | const RtpExtension kRtpExtensionTransportSequenceNumber02[] = { |
Johannes Kron | 8cc711a | 2019-03-07 21:36:35 | [diff] [blame] | 222 | RtpExtension( |
| 223 | "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02", |
| 224 | 2), |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 225 | }; |
| 226 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 227 | const RtpExtension kRtpExtensionGenericFrameDescriptorUri00[] = { |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 228 | RtpExtension("http://www.webrtc.org/experiments/rtp-hdrext/" |
| 229 | "generic-frame-descriptor-00", |
| 230 | 3), |
| 231 | }; |
| 232 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 233 | const uint32_t kSimulcastParamsSsrc[] = {10, 11, 20, 21, 30, 31}; |
| 234 | const uint32_t kSimSsrc[] = {10, 20, 30}; |
| 235 | const uint32_t kFec1Ssrc[] = {10, 11}; |
| 236 | const uint32_t kFec2Ssrc[] = {20, 21}; |
| 237 | const uint32_t kFec3Ssrc[] = {30, 31}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 238 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 239 | const char kMediaStream1[] = "stream_1"; |
| 240 | const char kMediaStream2[] = "stream_2"; |
| 241 | const char kVideoTrack1[] = "video_1"; |
| 242 | const char kVideoTrack2[] = "video_2"; |
| 243 | const char kAudioTrack1[] = "audio_1"; |
| 244 | const char kAudioTrack2[] = "audio_2"; |
| 245 | const char kAudioTrack3[] = "audio_3"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 246 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 247 | const char* kMediaProtocols[] = {"RTP/AVP", "RTP/SAVP", "RTP/AVPF", |
| 248 | "RTP/SAVPF"}; |
| 249 | const char* kMediaProtocolsDtls[] = {"TCP/TLS/RTP/SAVPF", "TCP/TLS/RTP/SAVP", |
| 250 | "UDP/TLS/RTP/SAVPF", "UDP/TLS/RTP/SAVP"}; |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 251 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 252 | // These constants are used to make the code using "AddMediaDescriptionOptions" |
| 253 | // more readable. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 254 | constexpr bool kStopped = true; |
| 255 | constexpr bool kActive = false; |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 256 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 257 | bool IsMediaContentOfType(const ContentInfo* content, MediaType media_type) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 258 | RTC_DCHECK(content); |
| 259 | return content->media_description()->type() == media_type; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 260 | } |
| 261 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 262 | RtpTransceiverDirection GetMediaDirection(const ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 263 | RTC_DCHECK(content); |
| 264 | return content->media_description()->direction(); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 | [diff] [blame] | 265 | } |
| 266 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 267 | void AddRtxCodec(const VideoCodec& rtx_codec, std::vector<VideoCodec>* codecs) { |
| 268 | ASSERT_FALSE(FindCodecById(*codecs, rtx_codec.id)); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 269 | codecs->push_back(rtx_codec); |
| 270 | } |
| 271 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 272 | std::vector<std::string> GetCodecNames(const std::vector<Codec>& codecs) { |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 273 | std::vector<std::string> codec_names; |
Mirko Bonadei | 649a4c2 | 2019-01-29 09:11:53 | [diff] [blame] | 274 | codec_names.reserve(codecs.size()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 275 | for (const auto& codec : codecs) { |
| 276 | codec_names.push_back(codec.name); |
| 277 | } |
| 278 | return codec_names; |
| 279 | } |
| 280 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 281 | // This is used for test only. MIDs are not the identification of the |
| 282 | // MediaDescriptionOptions since some end points may not support MID and the SDP |
| 283 | // may not contain 'mid'. |
| 284 | std::vector<MediaDescriptionOptions>::iterator FindFirstMediaDescriptionByMid( |
| 285 | const std::string& mid, |
| 286 | MediaSessionOptions* opts) { |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 287 | return absl::c_find_if( |
| 288 | opts->media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 289 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
| 290 | } |
| 291 | |
| 292 | std::vector<MediaDescriptionOptions>::const_iterator |
| 293 | FindFirstMediaDescriptionByMid(const std::string& mid, |
| 294 | const MediaSessionOptions& opts) { |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 295 | return absl::c_find_if( |
| 296 | opts.media_description_options, |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 297 | [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 298 | } |
| 299 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 300 | // Add a media section to the `session_options`. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 301 | void AddMediaDescriptionOptions(MediaType type, |
| 302 | const std::string& mid, |
| 303 | RtpTransceiverDirection direction, |
| 304 | bool stopped, |
| 305 | MediaSessionOptions* opts) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 306 | opts->media_description_options.push_back( |
| 307 | MediaDescriptionOptions(type, mid, direction, stopped)); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 308 | } |
| 309 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 310 | void AddAudioVideoSections(RtpTransceiverDirection direction, |
| 311 | MediaSessionOptions* opts) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 312 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 313 | opts); |
| 314 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", direction, kActive, |
| 315 | opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 316 | } |
| 317 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 318 | void AddDataSection(RtpTransceiverDirection direction, |
| 319 | MediaSessionOptions* opts) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 320 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data", direction, kActive, opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 321 | } |
| 322 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 323 | void AttachSenderToMediaDescriptionOptions( |
Steve Anton | 8ffb9c3 | 2017-08-31 22:45:38 | [diff] [blame] | 324 | const std::string& mid, |
| 325 | MediaType type, |
| 326 | const std::string& track_id, |
| 327 | const std::vector<std::string>& stream_ids, |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 328 | const std::vector<RidDescription>& rids, |
| 329 | const SimulcastLayerList& simulcast_layers, |
Steve Anton | 8ffb9c3 | 2017-08-31 22:45:38 | [diff] [blame] | 330 | int num_sim_layer, |
| 331 | MediaSessionOptions* session_options) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 332 | auto it = FindFirstMediaDescriptionByMid(mid, session_options); |
| 333 | switch (type) { |
| 334 | case MEDIA_TYPE_AUDIO: |
Steve Anton | 8ffb9c3 | 2017-08-31 22:45:38 | [diff] [blame] | 335 | it->AddAudioSender(track_id, stream_ids); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 336 | break; |
| 337 | case MEDIA_TYPE_VIDEO: |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 338 | it->AddVideoSender(track_id, stream_ids, rids, simulcast_layers, |
| 339 | num_sim_layer); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 340 | break; |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 341 | default: |
Artem Titov | d325196 | 2021-11-15 15:57:07 | [diff] [blame] | 342 | RTC_DCHECK_NOTREACHED(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 346 | void AttachSenderToMediaDescriptionOptions( |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 347 | const std::string& mid, |
| 348 | MediaType type, |
| 349 | const std::string& track_id, |
| 350 | const std::vector<std::string>& stream_ids, |
| 351 | int num_sim_layer, |
| 352 | MediaSessionOptions* session_options) { |
| 353 | AttachSenderToMediaDescriptionOptions(mid, type, track_id, stream_ids, {}, |
| 354 | SimulcastLayerList(), num_sim_layer, |
| 355 | session_options); |
| 356 | } |
| 357 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 358 | void DetachSenderFromMediaSection(const std::string& mid, |
| 359 | const std::string& track_id, |
| 360 | MediaSessionOptions* session_options) { |
| 361 | std::vector<SenderOptions>& sender_options_list = |
Steve Anton | 3a66edf | 2018-09-10 19:57:37 | [diff] [blame] | 362 | FindFirstMediaDescriptionByMid(mid, session_options)->sender_options; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 363 | auto sender_it = absl::c_find_if( |
| 364 | sender_options_list, [track_id](const SenderOptions& sender_options) { |
| 365 | return sender_options.track_id == track_id; |
| 366 | }); |
Steve Anton | 3a66edf | 2018-09-10 19:57:37 | [diff] [blame] | 367 | RTC_DCHECK(sender_it != sender_options_list.end()); |
| 368 | sender_options_list.erase(sender_it); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 369 | } |
| 370 | |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 371 | // Helper function used to create recv-only audio MediaSessionOptions. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 372 | MediaSessionOptions CreateAudioMediaSession() { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 373 | MediaSessionOptions session_options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 374 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 375 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 376 | &session_options); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 377 | return session_options; |
| 378 | } |
| 379 | |
| 380 | // TODO(zhihuang): Most of these tests were written while MediaSessionOptions |
| 381 | // was designed for Plan B SDP, where only one audio "m=" section and one video |
| 382 | // "m=" section could be generated, and ordering couldn't be controlled. Many of |
| 383 | // these tests may be obsolete as a result, and should be refactored or removed. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 384 | class MediaSessionDescriptionFactoryTest : public testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 385 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 386 | MediaSessionDescriptionFactoryTest() |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 387 | : tdf1_(field_trials), |
| 388 | tdf2_(field_trials), |
Philipp Hancke | 332c56f | 2023-09-27 08:06:37 | [diff] [blame] | 389 | f1_(nullptr, false, &ssrc_generator1, &tdf1_), |
| 390 | f2_(nullptr, false, &ssrc_generator2, &tdf2_) { |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 391 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 392 | MAKE_VECTOR(kAudioCodecs1)); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 393 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1), |
| 394 | MAKE_VECTOR(kVideoCodecs1)); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 395 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 396 | MAKE_VECTOR(kAudioCodecs2)); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 397 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2), |
| 398 | MAKE_VECTOR(kVideoCodecs2)); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 399 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
| 400 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
| 401 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
| 402 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 403 | } |
| 404 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 405 | // Create a video StreamParamsVec object with: |
| 406 | // - one video stream with 3 simulcast streams and FEC, |
| 407 | StreamParamsVec CreateComplexVideoStreamParamsVec() { |
| 408 | SsrcGroup sim_group("SIM", MAKE_VECTOR(kSimSsrc)); |
| 409 | SsrcGroup fec_group1("FEC", MAKE_VECTOR(kFec1Ssrc)); |
| 410 | SsrcGroup fec_group2("FEC", MAKE_VECTOR(kFec2Ssrc)); |
| 411 | SsrcGroup fec_group3("FEC", MAKE_VECTOR(kFec3Ssrc)); |
| 412 | |
| 413 | std::vector<SsrcGroup> ssrc_groups; |
| 414 | ssrc_groups.push_back(sim_group); |
| 415 | ssrc_groups.push_back(fec_group1); |
| 416 | ssrc_groups.push_back(fec_group2); |
| 417 | ssrc_groups.push_back(fec_group3); |
| 418 | |
| 419 | StreamParams simulcast_params; |
| 420 | simulcast_params.id = kVideoTrack1; |
| 421 | simulcast_params.ssrcs = MAKE_VECTOR(kSimulcastParamsSsrc); |
| 422 | simulcast_params.ssrc_groups = ssrc_groups; |
| 423 | simulcast_params.cname = "Video_SIM_FEC"; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 424 | simulcast_params.set_stream_ids({kMediaStream1}); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 425 | |
| 426 | StreamParamsVec video_streams; |
| 427 | video_streams.push_back(simulcast_params); |
| 428 | |
| 429 | return video_streams; |
| 430 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 431 | |
Honghai Zhang | 4cedf2b | 2016-08-31 15:18:11 | [diff] [blame] | 432 | // Returns true if the transport info contains "renomination" as an |
| 433 | // ICE option. |
| 434 | bool GetIceRenomination(const TransportInfo* transport_info) { |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 435 | return absl::c_linear_search(transport_info->description.transport_options, |
| 436 | "renomination"); |
Honghai Zhang | 4cedf2b | 2016-08-31 15:18:11 | [diff] [blame] | 437 | } |
| 438 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 439 | void TestTransportInfo(bool offer, |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 440 | const MediaSessionOptions& options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 441 | bool has_current_desc) { |
| 442 | const std::string current_audio_ufrag = "current_audio_ufrag"; |
| 443 | const std::string current_audio_pwd = "current_audio_pwd"; |
| 444 | const std::string current_video_ufrag = "current_video_ufrag"; |
| 445 | const std::string current_video_pwd = "current_video_pwd"; |
| 446 | const std::string current_data_ufrag = "current_data_ufrag"; |
| 447 | const std::string current_data_pwd = "current_data_pwd"; |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 448 | std::unique_ptr<SessionDescription> current_desc; |
| 449 | std::unique_ptr<SessionDescription> desc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 450 | if (has_current_desc) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 451 | current_desc = std::make_unique<SessionDescription>(); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 452 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 453 | "audio", |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 454 | TransportDescription(current_audio_ufrag, current_audio_pwd))); |
| 455 | current_desc->AddTransportInfo(TransportInfo( |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 456 | "video", |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 457 | TransportDescription(current_video_ufrag, current_video_pwd))); |
| 458 | current_desc->AddTransportInfo(TransportInfo( |
| 459 | "data", TransportDescription(current_data_ufrag, current_data_pwd))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 460 | } |
| 461 | if (offer) { |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 462 | desc = f1_.CreateOfferOrError(options, current_desc.get()).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 463 | } else { |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 464 | std::unique_ptr<SessionDescription> offer; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 465 | offer = f1_.CreateOfferOrError(options, nullptr).MoveValue(); |
| 466 | desc = f1_.CreateAnswerOrError(offer.get(), options, current_desc.get()) |
| 467 | .MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 468 | } |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 469 | ASSERT_TRUE(desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 470 | const TransportInfo* ti_audio = desc->GetTransportInfoByName("audio"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 | [diff] [blame] | 471 | if (options.has_audio()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 472 | if (has_current_desc) { |
| 473 | EXPECT_EQ(current_audio_ufrag, ti_audio->description.ice_ufrag); |
| 474 | EXPECT_EQ(current_audio_pwd, ti_audio->description.ice_pwd); |
| 475 | } else { |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 476 | EXPECT_EQ(static_cast<size_t>(ICE_UFRAG_LENGTH), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 477 | ti_audio->description.ice_ufrag.size()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 478 | EXPECT_EQ(static_cast<size_t>(ICE_PWD_LENGTH), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 479 | ti_audio->description.ice_pwd.size()); |
| 480 | } |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 481 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 482 | FindFirstMediaDescriptionByMid("audio", options); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 483 | EXPECT_EQ( |
| 484 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 485 | GetIceRenomination(ti_audio)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 486 | } |
| 487 | const TransportInfo* ti_video = desc->GetTransportInfoByName("video"); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 | [diff] [blame] | 488 | if (options.has_video()) { |
Bjorn A Mellem | c85ebbe | 2019-06-07 17:28:06 | [diff] [blame] | 489 | auto media_desc_options_it = |
| 490 | FindFirstMediaDescriptionByMid("video", options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 491 | if (options.bundle_enabled) { |
| 492 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 493 | ti_video->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 494 | EXPECT_EQ(ti_audio->description.ice_pwd, ti_video->description.ice_pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 495 | } else { |
| 496 | if (has_current_desc) { |
| 497 | EXPECT_EQ(current_video_ufrag, ti_video->description.ice_ufrag); |
| 498 | EXPECT_EQ(current_video_pwd, ti_video->description.ice_pwd); |
| 499 | } else { |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 500 | EXPECT_EQ(static_cast<size_t>(ICE_UFRAG_LENGTH), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 501 | ti_video->description.ice_ufrag.size()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 502 | EXPECT_EQ(static_cast<size_t>(ICE_PWD_LENGTH), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 503 | ti_video->description.ice_pwd.size()); |
| 504 | } |
| 505 | } |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 506 | EXPECT_EQ( |
| 507 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 508 | GetIceRenomination(ti_video)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 509 | } |
| 510 | const TransportInfo* ti_data = desc->GetTransportInfoByName("data"); |
| 511 | if (options.has_data()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 512 | if (options.bundle_enabled) { |
| 513 | EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 514 | ti_data->description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 515 | EXPECT_EQ(ti_audio->description.ice_pwd, ti_data->description.ice_pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 516 | } else { |
| 517 | if (has_current_desc) { |
| 518 | EXPECT_EQ(current_data_ufrag, ti_data->description.ice_ufrag); |
| 519 | EXPECT_EQ(current_data_pwd, ti_data->description.ice_pwd); |
| 520 | } else { |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 521 | EXPECT_EQ(static_cast<size_t>(ICE_UFRAG_LENGTH), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 522 | ti_data->description.ice_ufrag.size()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 523 | EXPECT_EQ(static_cast<size_t>(ICE_PWD_LENGTH), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 524 | ti_data->description.ice_pwd.size()); |
| 525 | } |
| 526 | } |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 527 | auto media_desc_options_it = |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 528 | FindFirstMediaDescriptionByMid("data", options); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 529 | EXPECT_EQ( |
| 530 | media_desc_options_it->transport_options.enable_ice_renomination, |
| 531 | GetIceRenomination(ti_data)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 535 | // This test that the audio and video media direction is set to |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 536 | // `expected_direction_in_answer` in an answer if the offer direction is set |
| 537 | // to `direction_in_offer` and the answer is willing to both send and receive. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 538 | void TestMediaDirectionInAnswer( |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 539 | RtpTransceiverDirection direction_in_offer, |
| 540 | RtpTransceiverDirection expected_direction_in_answer) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 541 | MediaSessionOptions offer_opts; |
| 542 | AddAudioVideoSections(direction_in_offer, &offer_opts); |
| 543 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 544 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 545 | f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
| 546 | ASSERT_TRUE(offer.get()); |
terelius | 8c011e5 | 2016-04-26 12:28:11 | [diff] [blame] | 547 | ContentInfo* ac_offer = offer->GetContentByName("audio"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 548 | ASSERT_TRUE(ac_offer); |
terelius | 8c011e5 | 2016-04-26 12:28:11 | [diff] [blame] | 549 | ContentInfo* vc_offer = offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 550 | ASSERT_TRUE(vc_offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 551 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 552 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 553 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 554 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 555 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 556 | const AudioContentDescription* acd_answer = |
| 557 | GetFirstAudioContentDescription(answer.get()); |
| 558 | EXPECT_EQ(expected_direction_in_answer, acd_answer->direction()); |
| 559 | const VideoContentDescription* vcd_answer = |
| 560 | GetFirstVideoContentDescription(answer.get()); |
| 561 | EXPECT_EQ(expected_direction_in_answer, vcd_answer->direction()); |
| 562 | } |
| 563 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 564 | bool VerifyNoCNCodecs(const ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 565 | RTC_DCHECK(content); |
| 566 | RTC_CHECK(content->media_description()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 567 | for (const Codec& codec : content->media_description()->codecs()) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 568 | if (codec.name == "CN") { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 569 | return false; |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 570 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 571 | } |
| 572 | return true; |
| 573 | } |
| 574 | |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 575 | void TestTransportSequenceNumberNegotiation( |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 576 | const RtpHeaderExtensions& local, |
| 577 | const RtpHeaderExtensions& offered, |
| 578 | const RtpHeaderExtensions& expectedAnswer) { |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 579 | MediaSessionOptions opts; |
| 580 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 581 | SetAudioVideoRtpHeaderExtensions(offered, offered, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 582 | std::unique_ptr<SessionDescription> offer = |
| 583 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 584 | ASSERT_TRUE(offer.get()); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 585 | SetAudioVideoRtpHeaderExtensions(local, local, &opts); |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 586 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 587 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 588 | |
| 589 | EXPECT_EQ( |
| 590 | expectedAnswer, |
| 591 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 592 | EXPECT_EQ( |
| 593 | expectedAnswer, |
| 594 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
| 595 | } |
| 596 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 597 | std::vector<webrtc::RtpHeaderExtensionCapability> |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 598 | HeaderExtensionCapabilitiesFromRtpExtensions(RtpHeaderExtensions extensions) { |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 599 | std::vector<webrtc::RtpHeaderExtensionCapability> capabilities; |
| 600 | for (const auto& extension : extensions) { |
| 601 | webrtc::RtpHeaderExtensionCapability capability( |
| 602 | extension.uri, extension.id, |
| 603 | webrtc::RtpTransceiverDirection::kSendRecv); |
| 604 | capabilities.push_back(capability); |
| 605 | } |
| 606 | return capabilities; |
| 607 | } |
| 608 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 609 | void SetAudioVideoRtpHeaderExtensions(RtpHeaderExtensions audio_exts, |
| 610 | RtpHeaderExtensions video_exts, |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 611 | MediaSessionOptions* opts) { |
| 612 | auto audio_caps = HeaderExtensionCapabilitiesFromRtpExtensions(audio_exts); |
| 613 | auto video_caps = HeaderExtensionCapabilitiesFromRtpExtensions(video_exts); |
| 614 | for (auto& entry : opts->media_description_options) { |
| 615 | switch (entry.type) { |
| 616 | case MEDIA_TYPE_AUDIO: |
| 617 | entry.header_extensions = audio_caps; |
| 618 | break; |
| 619 | case MEDIA_TYPE_VIDEO: |
| 620 | entry.header_extensions = video_caps; |
| 621 | break; |
| 622 | default: |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 628 | protected: |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 629 | webrtc::test::ScopedKeyValueConfig field_trials; |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 630 | UniqueRandomIdGenerator ssrc_generator1; |
| 631 | UniqueRandomIdGenerator ssrc_generator2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 632 | TransportDescriptionFactory tdf1_; |
| 633 | TransportDescriptionFactory tdf2_; |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 634 | MediaSessionDescriptionFactory f1_; |
| 635 | MediaSessionDescriptionFactory f2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | // Create a typical audio offer, and ensure it matches what we expect. |
| 639 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 640 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 641 | f1_.CreateOfferOrError(CreateAudioMediaSession(), nullptr).MoveValue(); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 642 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 643 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 644 | const ContentInfo* vc = offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 645 | ASSERT_TRUE(ac); |
| 646 | EXPECT_FALSE(vc); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 647 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 648 | const MediaContentDescription* acd = ac->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 649 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 650 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 651 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 652 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 653 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 654 | EXPECT_EQ(kMediaProtocolDtlsSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 655 | } |
| 656 | |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 657 | // Create an offer with just Opus and RED. |
| 658 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 659 | TestCreateAudioOfferWithJustOpusAndRed) { |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 660 | // First, prefer to only use opus and red. |
| 661 | std::vector<webrtc::RtpCodecCapability> preferences; |
| 662 | preferences.push_back( |
| 663 | webrtc::ToRtpCodecCapability(f1_.audio_sendrecv_codecs()[0])); |
| 664 | preferences.push_back( |
| 665 | webrtc::ToRtpCodecCapability(f1_.audio_sendrecv_codecs()[1])); |
| 666 | EXPECT_EQ("opus", preferences[0].name); |
| 667 | EXPECT_EQ("red", preferences[1].name); |
| 668 | |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 669 | auto opts = CreateAudioMediaSession(); |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 670 | opts.media_description_options.at(0).codec_preferences = preferences; |
| 671 | std::unique_ptr<SessionDescription> offer = |
| 672 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 673 | ASSERT_TRUE(offer.get()); |
| 674 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 675 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 676 | ASSERT_TRUE(ac != NULL); |
| 677 | ASSERT_TRUE(vc == NULL); |
| 678 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 679 | const MediaContentDescription* acd = ac->media_description(); |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 680 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 681 | EXPECT_EQ(2U, acd->codecs().size()); |
| 682 | EXPECT_EQ("opus", acd->codecs()[0].name); |
| 683 | EXPECT_EQ("red", acd->codecs()[1].name); |
| 684 | } |
| 685 | |
| 686 | // Create an offer with RED before Opus, which enables RED with Opus encoding. |
| 687 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOfferWithRedForOpus) { |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 688 | // First, prefer to only use opus and red. |
| 689 | std::vector<webrtc::RtpCodecCapability> preferences; |
| 690 | preferences.push_back( |
| 691 | webrtc::ToRtpCodecCapability(f1_.audio_sendrecv_codecs()[1])); |
| 692 | preferences.push_back( |
| 693 | webrtc::ToRtpCodecCapability(f1_.audio_sendrecv_codecs()[0])); |
| 694 | EXPECT_EQ("red", preferences[0].name); |
| 695 | EXPECT_EQ("opus", preferences[1].name); |
| 696 | |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 697 | auto opts = CreateAudioMediaSession(); |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 698 | opts.media_description_options.at(0).codec_preferences = preferences; |
| 699 | std::unique_ptr<SessionDescription> offer = |
| 700 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 701 | ASSERT_TRUE(offer.get()); |
| 702 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 703 | const ContentInfo* vc = offer->GetContentByName("video"); |
| 704 | ASSERT_TRUE(ac != NULL); |
| 705 | ASSERT_TRUE(vc == NULL); |
| 706 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 707 | const MediaContentDescription* acd = ac->media_description(); |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 708 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 709 | EXPECT_EQ(2U, acd->codecs().size()); |
| 710 | EXPECT_EQ("red", acd->codecs()[0].name); |
| 711 | EXPECT_EQ("opus", acd->codecs()[1].name); |
| 712 | } |
| 713 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 714 | // Create a typical video offer, and ensure it matches what we expect. |
| 715 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoOffer) { |
| 716 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 717 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 718 | std::unique_ptr<SessionDescription> offer = |
| 719 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 720 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 721 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 722 | const ContentInfo* vc = offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 723 | ASSERT_TRUE(ac); |
| 724 | ASSERT_TRUE(vc); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 725 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 726 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 727 | const MediaContentDescription* acd = ac->media_description(); |
| 728 | const MediaContentDescription* vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 729 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 730 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 731 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 732 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 733 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 734 | EXPECT_EQ(kMediaProtocolDtlsSavpf, acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 735 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 736 | EXPECT_EQ(f1_.video_sendrecv_codecs(), vcd->codecs()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 737 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 738 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 739 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 740 | EXPECT_EQ(kMediaProtocolDtlsSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | // Test creating an offer with bundle where the Codecs have the same dynamic |
| 744 | // RTP playlod type. The test verifies that the offer don't contain the |
| 745 | // duplicate RTP payload types. |
| 746 | TEST_F(MediaSessionDescriptionFactoryTest, TestBundleOfferWithSameCodecPlType) { |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 747 | const VideoCodec& offered_video_codec = f2_.video_sendrecv_codecs()[0]; |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 748 | const AudioCodec& offered_audio_codec = f2_.audio_sendrecv_codecs()[0]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 749 | ASSERT_EQ(offered_video_codec.id, offered_audio_codec.id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 750 | |
| 751 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 752 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 753 | opts.bundle_enabled = true; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 754 | std::unique_ptr<SessionDescription> offer = |
| 755 | f2_.CreateOfferOrError(opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 756 | const VideoContentDescription* vcd = |
| 757 | GetFirstVideoContentDescription(offer.get()); |
| 758 | const AudioContentDescription* acd = |
| 759 | GetFirstAudioContentDescription(offer.get()); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 760 | ASSERT_TRUE(vcd); |
| 761 | ASSERT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 762 | EXPECT_NE(vcd->codecs()[0].id, acd->codecs()[0].id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 763 | EXPECT_EQ(vcd->codecs()[0].name, offered_video_codec.name); |
| 764 | EXPECT_EQ(acd->codecs()[0].name, offered_audio_codec.name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 765 | } |
| 766 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 767 | // Test creating an updated offer with bundle, audio, video and data |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 768 | // after an audio only session has been negotiated. |
| 769 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 770 | TestCreateUpdatedVideoOfferWithBundle) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 771 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 772 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 773 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 774 | &opts); |
| 775 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 776 | RtpTransceiverDirection::kInactive, kStopped, |
| 777 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 778 | opts.bundle_enabled = true; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 779 | std::unique_ptr<SessionDescription> offer = |
| 780 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 781 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 782 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 783 | |
| 784 | MediaSessionOptions updated_opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 785 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &updated_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 786 | updated_opts.bundle_enabled = true; |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 787 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 788 | f1_.CreateOfferOrError(updated_opts, answer.get()).MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 789 | |
| 790 | const AudioContentDescription* acd = |
| 791 | GetFirstAudioContentDescription(updated_offer.get()); |
| 792 | const VideoContentDescription* vcd = |
| 793 | GetFirstVideoContentDescription(updated_offer.get()); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 794 | EXPECT_TRUE(vcd); |
| 795 | EXPECT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 796 | |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 797 | EXPECT_EQ(kMediaProtocolDtlsSavpf, acd->protocol()); |
| 798 | EXPECT_EQ(kMediaProtocolDtlsSavpf, vcd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 799 | } |
| 800 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 801 | // Create an SCTP data offer with bundle without error. |
| 802 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { |
| 803 | MediaSessionOptions opts; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 804 | opts.bundle_enabled = true; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 805 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 806 | std::unique_ptr<SessionDescription> offer = |
| 807 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 808 | EXPECT_TRUE(offer.get()); |
| 809 | EXPECT_TRUE(offer->GetContentByName("data")); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 810 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 811 | ASSERT_TRUE(dcd); |
| 812 | // Since this transport is insecure, the protocol should be "SCTP". |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 813 | EXPECT_EQ(kMediaProtocolUdpDtlsSctp, dcd->protocol()); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | // Create an SCTP data offer with bundle without error. |
| 817 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSecureSctpDataOffer) { |
| 818 | MediaSessionOptions opts; |
| 819 | opts.bundle_enabled = true; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 820 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 821 | std::unique_ptr<SessionDescription> offer = |
| 822 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 823 | EXPECT_TRUE(offer.get()); |
| 824 | EXPECT_TRUE(offer->GetContentByName("data")); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 825 | auto dcd = GetFirstSctpDataContentDescription(offer.get()); |
| 826 | ASSERT_TRUE(dcd); |
| 827 | // The protocol should now be "UDP/DTLS/SCTP" |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 828 | EXPECT_EQ(kMediaProtocolUdpDtlsSctp, dcd->protocol()); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 829 | } |
| 830 | |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 | [diff] [blame] | 831 | // Test creating an sctp data channel from an already generated offer. |
| 832 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { |
| 833 | MediaSessionOptions opts; |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 | [diff] [blame] | 834 | opts.bundle_enabled = true; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 835 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 836 | std::unique_ptr<SessionDescription> offer1( |
| 837 | f1_.CreateOfferOrError(opts, nullptr).MoveValue()); |
| 838 | ASSERT_TRUE(offer1.get()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 | [diff] [blame] | 839 | const ContentInfo* data = offer1->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 840 | ASSERT_TRUE(data); |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 841 | ASSERT_EQ(kMediaProtocolUdpDtlsSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 | [diff] [blame] | 842 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 843 | std::unique_ptr<SessionDescription> offer2( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 844 | f1_.CreateOfferOrError(opts, offer1.get()).MoveValue()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 | [diff] [blame] | 845 | data = offer2->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 846 | ASSERT_TRUE(data); |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 847 | EXPECT_EQ(kMediaProtocolUdpDtlsSctp, data->media_description()->protocol()); |
tommi@webrtc.org | f15dee6 | 2014-10-27 22:15:04 | [diff] [blame] | 848 | } |
| 849 | |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 850 | // Test that if BUNDLE is enabled and all media sections are rejected then the |
| 851 | // BUNDLE group is not present in the re-offer. |
| 852 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferNoBundleGroupIfAllRejected) { |
| 853 | MediaSessionOptions opts; |
| 854 | opts.bundle_enabled = true; |
| 855 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 856 | RtpTransceiverDirection::kSendRecv, kActive, |
| 857 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 858 | std::unique_ptr<SessionDescription> offer = |
| 859 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 860 | |
| 861 | opts.media_description_options[0].stopped = true; |
| 862 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 863 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 864 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 865 | EXPECT_FALSE(reoffer->GetGroupByName(GROUP_TYPE_BUNDLE)); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | // Test that if BUNDLE is enabled and the remote re-offer does not include a |
| 869 | // BUNDLE group since all media sections are rejected, then the re-answer also |
| 870 | // does not include a BUNDLE group. |
| 871 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerNoBundleGroupIfAllRejected) { |
| 872 | MediaSessionOptions opts; |
| 873 | opts.bundle_enabled = true; |
| 874 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 875 | RtpTransceiverDirection::kSendRecv, kActive, |
| 876 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 877 | std::unique_ptr<SessionDescription> offer = |
| 878 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 879 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 880 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 881 | |
| 882 | opts.media_description_options[0].stopped = true; |
| 883 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 884 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 885 | std::unique_ptr<SessionDescription> reanswer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 886 | f2_.CreateAnswerOrError(reoffer.get(), opts, answer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 887 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 888 | EXPECT_FALSE(reanswer->GetGroupByName(GROUP_TYPE_BUNDLE)); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 892 | // was rejected then the new offerer-tagged media section is the non-rejected |
| 893 | // media section. |
| 894 | TEST_F(MediaSessionDescriptionFactoryTest, ReOfferChangeBundleOffererTagged) { |
| 895 | MediaSessionOptions opts; |
| 896 | opts.bundle_enabled = true; |
| 897 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 898 | RtpTransceiverDirection::kSendRecv, kActive, |
| 899 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 900 | std::unique_ptr<SessionDescription> offer = |
| 901 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 902 | |
| 903 | // Reject the audio m= section and add a video m= section. |
| 904 | opts.media_description_options[0].stopped = true; |
| 905 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 906 | RtpTransceiverDirection::kSendRecv, kActive, |
| 907 | &opts); |
| 908 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 909 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 910 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 911 | const ContentGroup* bundle_group = reoffer->GetGroupByName(GROUP_TYPE_BUNDLE); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 912 | ASSERT_TRUE(bundle_group); |
| 913 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 914 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 915 | } |
| 916 | |
| 917 | // Test that if BUNDLE is enabled and the previous offerer-tagged media section |
| 918 | // was rejected and a new media section is added, then the re-answer BUNDLE |
| 919 | // group will contain only the non-rejected media section. |
| 920 | TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerChangedBundleOffererTagged) { |
| 921 | MediaSessionOptions opts; |
| 922 | opts.bundle_enabled = true; |
| 923 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 924 | RtpTransceiverDirection::kSendRecv, kActive, |
| 925 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 926 | std::unique_ptr<SessionDescription> offer = |
| 927 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 928 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 929 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 930 | |
| 931 | // Reject the audio m= section and add a video m= section. |
| 932 | opts.media_description_options[0].stopped = true; |
| 933 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 934 | RtpTransceiverDirection::kSendRecv, kActive, |
| 935 | &opts); |
| 936 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 937 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 938 | std::unique_ptr<SessionDescription> reanswer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 939 | f2_.CreateAnswerOrError(reoffer.get(), opts, answer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 940 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 941 | const ContentGroup* bundle_group = |
| 942 | reanswer->GetGroupByName(GROUP_TYPE_BUNDLE); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 943 | ASSERT_TRUE(bundle_group); |
| 944 | EXPECT_FALSE(bundle_group->HasContentName("audio")); |
| 945 | EXPECT_TRUE(bundle_group->HasContentName("video")); |
| 946 | } |
| 947 | |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 948 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 949 | CreateAnswerForOfferWithMultipleBundleGroups) { |
| 950 | // Create an offer with 4 m= sections, initially without BUNDLE groups. |
| 951 | MediaSessionOptions opts; |
| 952 | opts.bundle_enabled = false; |
| 953 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "1", |
| 954 | RtpTransceiverDirection::kSendRecv, kActive, |
| 955 | &opts); |
| 956 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "2", |
| 957 | RtpTransceiverDirection::kSendRecv, kActive, |
| 958 | &opts); |
| 959 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "3", |
| 960 | RtpTransceiverDirection::kSendRecv, kActive, |
| 961 | &opts); |
| 962 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "4", |
| 963 | RtpTransceiverDirection::kSendRecv, kActive, |
| 964 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 965 | std::unique_ptr<SessionDescription> offer = |
| 966 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 967 | ASSERT_TRUE(offer->groups().empty()); |
| 968 | |
| 969 | // Munge the offer to have two groups. Offers like these cannot be generated |
| 970 | // without munging, but it is valid to receive such offers from remote |
| 971 | // endpoints. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 972 | ContentGroup bundle_group1(GROUP_TYPE_BUNDLE); |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 973 | bundle_group1.AddContentName("1"); |
| 974 | bundle_group1.AddContentName("2"); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 975 | ContentGroup bundle_group2(GROUP_TYPE_BUNDLE); |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 976 | bundle_group2.AddContentName("3"); |
| 977 | bundle_group2.AddContentName("4"); |
| 978 | offer->AddGroup(bundle_group1); |
| 979 | offer->AddGroup(bundle_group2); |
| 980 | |
| 981 | // If BUNDLE is enabled, the answer to this offer should accept both BUNDLE |
| 982 | // groups. |
| 983 | opts.bundle_enabled = true; |
| 984 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 985 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 986 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 987 | std::vector<const ContentGroup*> answer_groups = |
| 988 | answer->GetGroupsByName(GROUP_TYPE_BUNDLE); |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 989 | ASSERT_EQ(answer_groups.size(), 2u); |
| 990 | EXPECT_EQ(answer_groups[0]->content_names().size(), 2u); |
| 991 | EXPECT_TRUE(answer_groups[0]->HasContentName("1")); |
| 992 | EXPECT_TRUE(answer_groups[0]->HasContentName("2")); |
| 993 | EXPECT_EQ(answer_groups[1]->content_names().size(), 2u); |
| 994 | EXPECT_TRUE(answer_groups[1]->HasContentName("3")); |
| 995 | EXPECT_TRUE(answer_groups[1]->HasContentName("4")); |
| 996 | |
| 997 | // If BUNDLE is disabled, the answer to this offer should reject both BUNDLE |
| 998 | // groups. |
| 999 | opts.bundle_enabled = false; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1000 | answer = f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 1001 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1002 | answer_groups = answer->GetGroupsByName(GROUP_TYPE_BUNDLE); |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 1003 | // Rejected groups are still listed, but they are empty. |
| 1004 | ASSERT_EQ(answer_groups.size(), 2u); |
| 1005 | EXPECT_TRUE(answer_groups[0]->content_names().empty()); |
| 1006 | EXPECT_TRUE(answer_groups[1]->content_names().empty()); |
| 1007 | } |
| 1008 | |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1009 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1010 | // and there is still a non-rejected media section that was in the initial |
| 1011 | // offer, then the ICE credentials do not change in the reoffer offerer-tagged |
| 1012 | // media section. |
| 1013 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1014 | ReOfferChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1015 | MediaSessionOptions opts; |
| 1016 | opts.bundle_enabled = true; |
| 1017 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1018 | std::unique_ptr<SessionDescription> offer = |
| 1019 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1020 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1021 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1022 | |
| 1023 | // Reject the audio m= section. |
| 1024 | opts.media_description_options[0].stopped = true; |
| 1025 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1026 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1027 | |
| 1028 | const TransportDescription* offer_tagged = |
| 1029 | offer->GetTransportDescriptionByName("audio"); |
| 1030 | ASSERT_TRUE(offer_tagged); |
| 1031 | const TransportDescription* reoffer_tagged = |
| 1032 | reoffer->GetTransportDescriptionByName("video"); |
| 1033 | ASSERT_TRUE(reoffer_tagged); |
| 1034 | EXPECT_EQ(offer_tagged->ice_ufrag, reoffer_tagged->ice_ufrag); |
| 1035 | EXPECT_EQ(offer_tagged->ice_pwd, reoffer_tagged->ice_pwd); |
| 1036 | } |
| 1037 | |
| 1038 | // Test that if the BUNDLE offerer-tagged media section is changed in a reoffer |
| 1039 | // and there is still a non-rejected media section that was in the initial |
| 1040 | // offer, then the ICE credentials do not change in the reanswer answerer-tagged |
| 1041 | // media section. |
| 1042 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1043 | ReAnswerChangeBundleOffererTaggedKeepsIceCredentials) { |
| 1044 | MediaSessionOptions opts; |
| 1045 | opts.bundle_enabled = true; |
| 1046 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1047 | std::unique_ptr<SessionDescription> offer = |
| 1048 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1049 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1050 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1051 | |
| 1052 | // Reject the audio m= section. |
| 1053 | opts.media_description_options[0].stopped = true; |
| 1054 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1055 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1056 | std::unique_ptr<SessionDescription> reanswer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1057 | f2_.CreateAnswerOrError(reoffer.get(), opts, answer.get()).MoveValue(); |
Steve Anton | 2bed397 | 2019-01-05 01:04:30 | [diff] [blame] | 1058 | |
| 1059 | const TransportDescription* answer_tagged = |
| 1060 | answer->GetTransportDescriptionByName("audio"); |
| 1061 | ASSERT_TRUE(answer_tagged); |
| 1062 | const TransportDescription* reanswer_tagged = |
| 1063 | reanswer->GetTransportDescriptionByName("video"); |
| 1064 | ASSERT_TRUE(reanswer_tagged); |
| 1065 | EXPECT_EQ(answer_tagged->ice_ufrag, reanswer_tagged->ice_ufrag); |
| 1066 | EXPECT_EQ(answer_tagged->ice_pwd, reanswer_tagged->ice_pwd); |
| 1067 | } |
| 1068 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1069 | // Create an audio, video offer without legacy StreamParams. |
| 1070 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1071 | TestCreateOfferWithoutLegacyStreams) { |
| 1072 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1073 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1074 | std::unique_ptr<SessionDescription> offer = |
| 1075 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1076 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1077 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 1078 | const ContentInfo* vc = offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1079 | ASSERT_TRUE(ac); |
| 1080 | ASSERT_TRUE(vc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 1081 | const MediaContentDescription* acd = ac->media_description(); |
| 1082 | const MediaContentDescription* vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1083 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1084 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1085 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1086 | } |
| 1087 | |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 | [diff] [blame] | 1088 | // Creates an audio+video sendonly offer. |
| 1089 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSendOnlyOffer) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 1090 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1091 | AddAudioVideoSections(RtpTransceiverDirection::kSendOnly, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 1092 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 1093 | {kMediaStream1}, 1, &opts); |
| 1094 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 1095 | {kMediaStream1}, 1, &opts); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 | [diff] [blame] | 1096 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1097 | std::unique_ptr<SessionDescription> offer = |
| 1098 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1099 | ASSERT_TRUE(offer.get()); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 | [diff] [blame] | 1100 | EXPECT_EQ(2u, offer->contents().size()); |
| 1101 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[0], MEDIA_TYPE_AUDIO)); |
| 1102 | EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1103 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1104 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1105 | GetMediaDirection(&offer->contents()[0])); |
| 1106 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
| 1107 | GetMediaDirection(&offer->contents()[1])); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 | [diff] [blame] | 1108 | } |
| 1109 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1110 | // Verifies that the order of the media contents in the current |
| 1111 | // SessionDescription is preserved in the new SessionDescription. |
| 1112 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { |
| 1113 | MediaSessionOptions opts; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 1114 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1115 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1116 | std::unique_ptr<SessionDescription> offer1( |
| 1117 | f1_.CreateOfferOrError(opts, nullptr).MoveValue()); |
| 1118 | ASSERT_TRUE(offer1.get()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1119 | EXPECT_EQ(1u, offer1->contents().size()); |
| 1120 | EXPECT_TRUE(IsMediaContentOfType(&offer1->contents()[0], MEDIA_TYPE_DATA)); |
| 1121 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 1122 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1123 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1124 | &opts); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 1125 | std::unique_ptr<SessionDescription> offer2( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1126 | f1_.CreateOfferOrError(opts, offer1.get()).MoveValue()); |
| 1127 | ASSERT_TRUE(offer2.get()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1128 | EXPECT_EQ(2u, offer2->contents().size()); |
| 1129 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[0], MEDIA_TYPE_DATA)); |
| 1130 | EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1131 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 1132 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1133 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1134 | &opts); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 1135 | std::unique_ptr<SessionDescription> offer3( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1136 | f1_.CreateOfferOrError(opts, offer2.get()).MoveValue()); |
| 1137 | ASSERT_TRUE(offer3.get()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1138 | EXPECT_EQ(3u, offer3->contents().size()); |
| 1139 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[0], MEDIA_TYPE_DATA)); |
| 1140 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[1], MEDIA_TYPE_VIDEO)); |
| 1141 | EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[2], MEDIA_TYPE_AUDIO)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1142 | } |
| 1143 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1144 | // Create a typical audio answer, and ensure it matches what we expect. |
| 1145 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswer) { |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1146 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 1147 | f1_.CreateOfferOrError(CreateAudioMediaSession(), nullptr).MoveValue(); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1148 | ASSERT_TRUE(offer.get()); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1149 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 1150 | f2_.CreateAnswerOrError(offer.get(), CreateAudioMediaSession(), nullptr) |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1151 | .MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1152 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1153 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1154 | ASSERT_TRUE(ac); |
| 1155 | EXPECT_FALSE(vc); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1156 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 1157 | const MediaContentDescription* acd = ac->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1158 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 1159 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 1160 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1161 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1162 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 1163 | EXPECT_EQ(kMediaProtocolDtlsSavpf, acd->protocol()); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | // Create a typical audio answer with GCM ciphers enabled, and ensure it |
| 1167 | // matches what we expect. |
| 1168 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 1169 | MediaSessionOptions opts = CreateAudioMediaSession(); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1170 | std::unique_ptr<SessionDescription> offer = |
| 1171 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1172 | ASSERT_TRUE(offer.get()); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1173 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1174 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1175 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1176 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1177 | ASSERT_TRUE(ac); |
| 1178 | EXPECT_FALSE(vc); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1179 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 1180 | const MediaContentDescription* acd = ac->media_description(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1181 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 1182 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
| 1183 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 1184 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 1185 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 1186 | EXPECT_EQ(kMediaProtocolDtlsSavpf, acd->protocol()); |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 1187 | } |
| 1188 | |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1189 | // Create an audio answer with no common codecs, and ensure it is rejected. |
| 1190 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1191 | TestCreateAudioAnswerWithNoCommonCodecs) { |
| 1192 | MediaSessionOptions opts; |
| 1193 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1194 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1195 | &opts); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1196 | std::vector f1_codecs = {CreateAudioCodec(96, "opus", 48000, 1)}; |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1197 | f1_.set_audio_codecs(f1_codecs, f1_codecs); |
| 1198 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1199 | std::vector f2_codecs = {CreateAudioCodec(0, "PCMU", 8000, 1)}; |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1200 | f2_.set_audio_codecs(f2_codecs, f2_codecs); |
| 1201 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1202 | std::unique_ptr<SessionDescription> offer = |
| 1203 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1204 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1205 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1206 | const ContentInfo* ac = answer->GetContentByName("audio"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1207 | ASSERT_TRUE(ac); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1208 | EXPECT_TRUE(ac->rejected); |
| 1209 | } |
| 1210 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1211 | // Create a typical video answer, and ensure it matches what we expect. |
| 1212 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { |
| 1213 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1214 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1215 | std::unique_ptr<SessionDescription> offer = |
| 1216 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1217 | ASSERT_TRUE(offer.get()); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1218 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1219 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1220 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1221 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1222 | ASSERT_TRUE(ac); |
| 1223 | ASSERT_TRUE(vc); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1224 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
| 1225 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 1226 | const MediaContentDescription* acd = ac->media_description(); |
| 1227 | const MediaContentDescription* vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1228 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 1229 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1230 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 1231 | EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1232 | EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1233 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 1234 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1235 | EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 1236 | EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 1237 | EXPECT_EQ(kMediaProtocolDtlsSavpf, vcd->protocol()); |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 1238 | } |
| 1239 | |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1240 | // Create a video answer with no common codecs, and ensure it is rejected. |
| 1241 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1242 | TestCreateVideoAnswerWithNoCommonCodecs) { |
| 1243 | MediaSessionOptions opts; |
| 1244 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1245 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1246 | &opts); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1247 | std::vector f1_codecs = {CreateVideoCodec(96, "H264")}; |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1248 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 1249 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1250 | std::vector f2_codecs = {CreateVideoCodec(97, "VP8")}; |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1251 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
| 1252 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1253 | std::unique_ptr<SessionDescription> offer = |
| 1254 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1255 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1256 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1257 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1258 | ASSERT_TRUE(vc); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1259 | EXPECT_TRUE(vc->rejected); |
| 1260 | } |
| 1261 | |
| 1262 | // Create a video answer with no common codecs (but a common FEC codec), and |
| 1263 | // ensure it is rejected. |
| 1264 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1265 | TestCreateVideoAnswerWithOnlyFecCodecsCommon) { |
| 1266 | MediaSessionOptions opts; |
| 1267 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1268 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1269 | &opts); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1270 | std::vector f1_codecs = {CreateVideoCodec(96, "H264"), |
| 1271 | CreateVideoCodec(118, "flexfec-03")}; |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1272 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 1273 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1274 | std::vector f2_codecs = {CreateVideoCodec(97, "VP8"), |
| 1275 | CreateVideoCodec(118, "flexfec-03")}; |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1276 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
| 1277 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1278 | std::unique_ptr<SessionDescription> offer = |
| 1279 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1280 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1281 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1282 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1283 | ASSERT_TRUE(vc); |
Philipp Hancke | 2f3168f | 2022-05-16 12:41:32 | [diff] [blame] | 1284 | EXPECT_TRUE(vc->rejected); |
| 1285 | } |
| 1286 | |
Harald Alvestrand | c5effc2 | 2019-06-11 09:46:59 | [diff] [blame] | 1287 | // The use_sctpmap flag should be set in an Sctp DataContentDescription by |
| 1288 | // default. The answer's use_sctpmap flag should match the offer's. |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1289 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { |
| 1290 | MediaSessionOptions opts; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 1291 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1292 | std::unique_ptr<SessionDescription> offer = |
| 1293 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1294 | ASSERT_TRUE(offer.get()); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1295 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1296 | ASSERT_TRUE(dc_offer); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1297 | SctpDataContentDescription* dcd_offer = |
| 1298 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1299 | EXPECT_TRUE(dcd_offer->use_sctpmap()); |
| 1300 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1301 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1302 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1303 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1304 | ASSERT_TRUE(dc_answer); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1305 | const SctpDataContentDescription* dcd_answer = |
| 1306 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1307 | EXPECT_TRUE(dcd_answer->use_sctpmap()); |
| 1308 | } |
| 1309 | |
| 1310 | // The answer's use_sctpmap flag should match the offer's. |
| 1311 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerWithoutSctpmap) { |
| 1312 | MediaSessionOptions opts; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 1313 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1314 | std::unique_ptr<SessionDescription> offer = |
| 1315 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1316 | ASSERT_TRUE(offer.get()); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1317 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1318 | ASSERT_TRUE(dc_offer); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1319 | SctpDataContentDescription* dcd_offer = |
| 1320 | dc_offer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1321 | dcd_offer->set_use_sctpmap(false); |
| 1322 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1323 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1324 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1325 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1326 | ASSERT_TRUE(dc_answer); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1327 | const SctpDataContentDescription* dcd_answer = |
| 1328 | dc_answer->media_description()->as_sctp(); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1329 | EXPECT_FALSE(dcd_answer->use_sctpmap()); |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 1330 | } |
| 1331 | |
deadbeef | 8b7e9ad | 2017-05-25 16:38:55 | [diff] [blame] | 1332 | // Test that a valid answer will be created for "DTLS/SCTP", "UDP/DTLS/SCTP" |
| 1333 | // and "TCP/DTLS/SCTP" offers. |
| 1334 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1335 | TestCreateDataAnswerToDifferentOfferedProtos) { |
deadbeef | 8b7e9ad | 2017-05-25 16:38:55 | [diff] [blame] | 1336 | MediaSessionOptions opts; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 1337 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1338 | std::unique_ptr<SessionDescription> offer = |
| 1339 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1340 | ASSERT_TRUE(offer.get()); |
deadbeef | 8b7e9ad | 2017-05-25 16:38:55 | [diff] [blame] | 1341 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1342 | ASSERT_TRUE(dc_offer); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1343 | SctpDataContentDescription* dcd_offer = |
| 1344 | dc_offer->media_description()->as_sctp(); |
| 1345 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 16:38:55 | [diff] [blame] | 1346 | |
| 1347 | std::vector<std::string> protos = {"DTLS/SCTP", "UDP/DTLS/SCTP", |
| 1348 | "TCP/DTLS/SCTP"}; |
| 1349 | for (const std::string& proto : protos) { |
| 1350 | dcd_offer->set_protocol(proto); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1351 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1352 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
deadbeef | 8b7e9ad | 2017-05-25 16:38:55 | [diff] [blame] | 1353 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1354 | ASSERT_TRUE(dc_answer); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1355 | const SctpDataContentDescription* dcd_answer = |
| 1356 | dc_answer->media_description()->as_sctp(); |
deadbeef | 8b7e9ad | 2017-05-25 16:38:55 | [diff] [blame] | 1357 | EXPECT_FALSE(dc_answer->rejected); |
| 1358 | EXPECT_EQ(proto, dcd_answer->protocol()); |
| 1359 | } |
| 1360 | } |
| 1361 | |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1362 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1363 | TestCreateDataAnswerToOfferWithDefinedMessageSize) { |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1364 | MediaSessionOptions opts; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 1365 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1366 | std::unique_ptr<SessionDescription> offer = |
| 1367 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1368 | ASSERT_TRUE(offer.get()); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1369 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1370 | ASSERT_TRUE(dc_offer); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1371 | SctpDataContentDescription* dcd_offer = |
| 1372 | dc_offer->media_description()->as_sctp(); |
| 1373 | ASSERT_TRUE(dcd_offer); |
| 1374 | dcd_offer->set_max_message_size(1234); |
| 1375 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1376 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1377 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1378 | ASSERT_TRUE(dc_answer); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1379 | const SctpDataContentDescription* dcd_answer = |
| 1380 | dc_answer->media_description()->as_sctp(); |
| 1381 | EXPECT_FALSE(dc_answer->rejected); |
| 1382 | EXPECT_EQ(1234, dcd_answer->max_message_size()); |
| 1383 | } |
| 1384 | |
| 1385 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1386 | TestCreateDataAnswerToOfferWithZeroMessageSize) { |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1387 | MediaSessionOptions opts; |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 1388 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1389 | std::unique_ptr<SessionDescription> offer = |
| 1390 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1391 | ASSERT_TRUE(offer.get()); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1392 | ContentInfo* dc_offer = offer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1393 | ASSERT_TRUE(dc_offer); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1394 | SctpDataContentDescription* dcd_offer = |
| 1395 | dc_offer->media_description()->as_sctp(); |
| 1396 | ASSERT_TRUE(dcd_offer); |
| 1397 | dcd_offer->set_max_message_size(0); |
| 1398 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1399 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1400 | const ContentInfo* dc_answer = answer->GetContentByName("data"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1401 | ASSERT_TRUE(dc_answer); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1402 | const SctpDataContentDescription* dcd_answer = |
| 1403 | dc_answer->media_description()->as_sctp(); |
| 1404 | EXPECT_FALSE(dc_answer->rejected); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1405 | EXPECT_EQ(kSctpSendBufferSize, dcd_answer->max_message_size()); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 09:49:17 | [diff] [blame] | 1406 | } |
| 1407 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1408 | // Verifies that the order of the media contents in the offer is preserved in |
| 1409 | // the answer. |
| 1410 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { |
| 1411 | MediaSessionOptions opts; |
| 1412 | |
| 1413 | // Creates a data only offer. |
Florent Castelli | 516e284 | 2021-04-19 13:29:50 | [diff] [blame] | 1414 | AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1415 | std::unique_ptr<SessionDescription> offer1( |
| 1416 | f1_.CreateOfferOrError(opts, nullptr).MoveValue()); |
| 1417 | ASSERT_TRUE(offer1.get()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1418 | |
| 1419 | // Appends audio to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 1420 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1421 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1422 | &opts); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 1423 | std::unique_ptr<SessionDescription> offer2( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1424 | f1_.CreateOfferOrError(opts, offer1.get()).MoveValue()); |
| 1425 | ASSERT_TRUE(offer2.get()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1426 | |
| 1427 | // Appends video to the offer. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 1428 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1429 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 1430 | &opts); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 1431 | std::unique_ptr<SessionDescription> offer3( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1432 | f1_.CreateOfferOrError(opts, offer2.get()).MoveValue()); |
| 1433 | ASSERT_TRUE(offer3.get()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1434 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1435 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1436 | f2_.CreateAnswerOrError(offer3.get(), opts, nullptr).MoveValue(); |
| 1437 | ASSERT_TRUE(answer.get()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 1438 | EXPECT_EQ(3u, answer->contents().size()); |
| 1439 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[0], MEDIA_TYPE_DATA)); |
| 1440 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[1], MEDIA_TYPE_AUDIO)); |
| 1441 | EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[2], MEDIA_TYPE_VIDEO)); |
| 1442 | } |
| 1443 | |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 1444 | // TODO(deadbeef): Extend these tests to ensure the correct direction with other |
| 1445 | // answerer settings. |
| 1446 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1447 | // This test that the media direction is set to send/receive in an answer if |
| 1448 | // the offer is send receive. |
| 1449 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendReceiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1450 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendRecv, |
| 1451 | RtpTransceiverDirection::kSendRecv); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | // This test that the media direction is set to receive only in an answer if |
| 1455 | // the offer is send only. |
| 1456 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToSendOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1457 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kSendOnly, |
| 1458 | RtpTransceiverDirection::kRecvOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | // This test that the media direction is set to send only in an answer if |
| 1462 | // the offer is recv only. |
| 1463 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToRecvOnlyOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1464 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kRecvOnly, |
| 1465 | RtpTransceiverDirection::kSendOnly); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | // This test that the media direction is set to inactive in an answer if |
| 1469 | // the offer is inactive. |
| 1470 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToInactiveOffer) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1471 | TestMediaDirectionInAnswer(RtpTransceiverDirection::kInactive, |
| 1472 | RtpTransceiverDirection::kInactive); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1473 | } |
| 1474 | |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 1475 | // Test that the media protocol is RTP/AVPF if DTLS is disabled. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1476 | TEST_F(MediaSessionDescriptionFactoryTest, AudioOfferAnswerWithCryptoDisabled) { |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 1477 | MediaSessionOptions opts = CreateAudioMediaSession(); |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 1478 | tdf1_.SetInsecureForTesting(); |
| 1479 | tdf1_.set_certificate(nullptr); |
| 1480 | tdf2_.SetInsecureForTesting(); |
| 1481 | tdf2_.set_certificate(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1482 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1483 | std::unique_ptr<SessionDescription> offer = |
| 1484 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1485 | const AudioContentDescription* offer_acd = |
| 1486 | GetFirstAudioContentDescription(offer.get()); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1487 | ASSERT_TRUE(offer_acd); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1488 | EXPECT_EQ(kMediaProtocolAvpf, offer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1489 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1490 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1491 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1492 | |
| 1493 | const ContentInfo* ac_answer = answer->GetContentByName("audio"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1494 | ASSERT_TRUE(ac_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1495 | EXPECT_FALSE(ac_answer->rejected); |
| 1496 | |
| 1497 | const AudioContentDescription* answer_acd = |
| 1498 | GetFirstAudioContentDescription(answer.get()); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1499 | ASSERT_TRUE(answer_acd); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1500 | EXPECT_EQ(kMediaProtocolAvpf, answer_acd->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | // Create a video offer and answer and ensure the RTP header extensions |
| 1504 | // matches what we expect. |
| 1505 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferAnswerWithRtpExtensions) { |
| 1506 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1507 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1508 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), |
| 1509 | MAKE_VECTOR(kVideoRtpExtension1), &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1510 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1511 | std::unique_ptr<SessionDescription> offer = |
| 1512 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1513 | ASSERT_TRUE(offer.get()); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1514 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), |
| 1515 | MAKE_VECTOR(kVideoRtpExtension2), &opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1516 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1517 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1518 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1519 | EXPECT_EQ( |
| 1520 | MAKE_VECTOR(kAudioRtpExtension1), |
| 1521 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1522 | EXPECT_EQ( |
| 1523 | MAKE_VECTOR(kVideoRtpExtension1), |
| 1524 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1525 | EXPECT_EQ( |
| 1526 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1527 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1528 | EXPECT_EQ( |
| 1529 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1530 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1531 | } |
| 1532 | |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1533 | // Create a audio/video offer and answer and ensure that the |
Philipp Hancke | 657b65f | 2024-01-29 08:50:01 | [diff] [blame] | 1534 | // TransportSequenceNumber RTP v1 and v2 header extensions are handled |
| 1535 | // correctly. |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1536 | TEST_F(MediaSessionDescriptionFactoryTest, |
Philipp Hancke | 657b65f | 2024-01-29 08:50:01 | [diff] [blame] | 1537 | TestOfferAnswerWithTransportSequenceNumberV1LocalAndV1InOffer) { |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1538 | TestTransportSequenceNumberNegotiation( |
| 1539 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1540 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Offer. |
| 1541 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01)); // Expected answer. |
| 1542 | } |
| 1543 | TEST_F(MediaSessionDescriptionFactoryTest, |
Philipp Hancke | 657b65f | 2024-01-29 08:50:01 | [diff] [blame] | 1544 | TestOfferAnswerWithTransportSequenceNumberV1LocalAndV1V2InOffer) { |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1545 | TestTransportSequenceNumberNegotiation( |
| 1546 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1547 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Offer. |
Philipp Hancke | 657b65f | 2024-01-29 08:50:01 | [diff] [blame] | 1548 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01)); // Expected answer. |
| 1549 | } |
| 1550 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1551 | TestOfferAnswerWithTransportSequenceNumberV1LocalAndV2InOffer) { |
| 1552 | TestTransportSequenceNumberNegotiation( |
| 1553 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Local. |
| 1554 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Offer. |
| 1555 | {}); // Expected answer. |
| 1556 | } |
| 1557 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1558 | TestOfferAnswerWithTransportSequenceNumberV2LocalAndV1InOffer) { |
| 1559 | TestTransportSequenceNumberNegotiation( |
| 1560 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Local. |
| 1561 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Offer. |
| 1562 | {}); // Expected answer. |
| 1563 | } |
| 1564 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1565 | TestOfferAnswerWithTransportSequenceNumberV2LocalAndV1V2InOffer) { |
| 1566 | TestTransportSequenceNumberNegotiation( |
| 1567 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Local. |
| 1568 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Offer. |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1569 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1570 | } |
| 1571 | TEST_F(MediaSessionDescriptionFactoryTest, |
Philipp Hancke | 657b65f | 2024-01-29 08:50:01 | [diff] [blame] | 1572 | TestOfferAnswerWithTransportSequenceNumberV2LocalAndV2InOffer) { |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1573 | TestTransportSequenceNumberNegotiation( |
Philipp Hancke | 657b65f | 2024-01-29 08:50:01 | [diff] [blame] | 1574 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Local. |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1575 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Offer. |
| 1576 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1577 | } |
Philipp Hancke | 657b65f | 2024-01-29 08:50:01 | [diff] [blame] | 1578 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1579 | TestOfferAnswerWithTransportSequenceNumberV1V2LocalAndV1InOffer) { |
| 1580 | TestTransportSequenceNumberNegotiation( |
| 1581 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Local. |
| 1582 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), // Offer. |
| 1583 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01)); // Expected answer. |
| 1584 | } |
| 1585 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1586 | TestOfferAnswerWithTransportSequenceNumberV1V2LocalAndV2InOffer) { |
| 1587 | TestTransportSequenceNumberNegotiation( |
| 1588 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Local. |
| 1589 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02), // Offer. |
| 1590 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber02)); // Expected answer. |
| 1591 | } |
| 1592 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1593 | TestOfferAnswerWithTransportSequenceNumberV1V2LocalAndV1V2InOffer) { |
| 1594 | TestTransportSequenceNumberNegotiation( |
| 1595 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Local. |
| 1596 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01And02), // Offer. |
| 1597 | MAKE_VECTOR( |
| 1598 | kRtpExtensionTransportSequenceNumber01And02)); // Expected answer. |
| 1599 | } |
Johannes Kron | ce8e867 | 2019-02-22 12:06:44 | [diff] [blame] | 1600 | |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1601 | TEST_F(MediaSessionDescriptionFactoryTest, |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1602 | TestNegotiateFrameDescriptorWhenUnexposedLocally) { |
| 1603 | MediaSessionOptions opts; |
| 1604 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1605 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1606 | SetAudioVideoRtpHeaderExtensions( |
| 1607 | MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), |
| 1608 | MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1609 | std::unique_ptr<SessionDescription> offer = |
| 1610 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1611 | SetAudioVideoRtpHeaderExtensions( |
| 1612 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), |
| 1613 | MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), &opts); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1614 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1615 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1616 | EXPECT_THAT( |
| 1617 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1618 | ElementsAreArray(kRtpExtensionGenericFrameDescriptorUri00)); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1619 | EXPECT_THAT( |
| 1620 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1621 | ElementsAreArray(kRtpExtensionGenericFrameDescriptorUri00)); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1625 | TestNegotiateFrameDescriptorWhenExposedLocally) { |
| 1626 | MediaSessionOptions opts; |
| 1627 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1628 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1629 | SetAudioVideoRtpHeaderExtensions( |
| 1630 | MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), |
| 1631 | MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1632 | std::unique_ptr<SessionDescription> offer = |
| 1633 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1634 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1635 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1636 | EXPECT_THAT( |
| 1637 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1638 | ElementsAreArray(kRtpExtensionGenericFrameDescriptorUri00)); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1639 | EXPECT_THAT( |
| 1640 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1641 | ElementsAreArray(kRtpExtensionGenericFrameDescriptorUri00)); |
Markus Handell | c1cbf6b | 2020-02-17 19:03:57 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | TEST_F(MediaSessionDescriptionFactoryTest, |
Danil Chapovalov | 5f999a7 | 2020-02-20 15:39:05 | [diff] [blame] | 1645 | NegotiateDependencyDescriptorWhenUnexposedLocally) { |
| 1646 | MediaSessionOptions opts; |
| 1647 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1648 | |
| 1649 | RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1650 | SetAudioVideoRtpHeaderExtensions({}, {offer_dd}, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1651 | std::unique_ptr<SessionDescription> offer = |
| 1652 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1653 | RtpExtension local_tsn(RtpExtension::kTransportSequenceNumberUri, 5); |
| 1654 | SetAudioVideoRtpHeaderExtensions({}, {local_tsn}, &opts); |
Danil Chapovalov | 5f999a7 | 2020-02-20 15:39:05 | [diff] [blame] | 1655 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1656 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Danil Chapovalov | 5f999a7 | 2020-02-20 15:39:05 | [diff] [blame] | 1657 | EXPECT_THAT( |
| 1658 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1659 | ElementsAre(offer_dd)); |
| 1660 | } |
| 1661 | |
| 1662 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1663 | NegotiateDependencyDescriptorWhenExposedLocally) { |
| 1664 | MediaSessionOptions opts; |
| 1665 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1666 | |
| 1667 | RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); |
| 1668 | RtpExtension local_dd(RtpExtension::kDependencyDescriptorUri, 5); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1669 | SetAudioVideoRtpHeaderExtensions({}, {offer_dd}, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1670 | std::unique_ptr<SessionDescription> offer = |
| 1671 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1672 | SetAudioVideoRtpHeaderExtensions({}, {local_dd}, &opts); |
Danil Chapovalov | 5f999a7 | 2020-02-20 15:39:05 | [diff] [blame] | 1673 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1674 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Danil Chapovalov | 5f999a7 | 2020-02-20 15:39:05 | [diff] [blame] | 1675 | EXPECT_THAT( |
| 1676 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1677 | ElementsAre(offer_dd)); |
| 1678 | } |
| 1679 | |
| 1680 | TEST_F(MediaSessionDescriptionFactoryTest, |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1681 | NegotiateAbsoluteCaptureTimeWhenUnexposedLocally) { |
| 1682 | MediaSessionOptions opts; |
| 1683 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1684 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1685 | const RtpHeaderExtensions offered_extensions = { |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1686 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 7)}; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1687 | const RtpHeaderExtensions local_extensions = { |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1688 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, 5)}; |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1689 | SetAudioVideoRtpHeaderExtensions(offered_extensions, offered_extensions, |
| 1690 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1691 | std::unique_ptr<SessionDescription> offer = |
| 1692 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1693 | SetAudioVideoRtpHeaderExtensions(local_extensions, local_extensions, &opts); |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1694 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1695 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1696 | EXPECT_THAT( |
| 1697 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1698 | ElementsAreArray(offered_extensions)); |
| 1699 | EXPECT_THAT( |
| 1700 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1701 | ElementsAreArray(offered_extensions)); |
| 1702 | } |
| 1703 | |
| 1704 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1705 | NegotiateAbsoluteCaptureTimeWhenExposedLocally) { |
| 1706 | MediaSessionOptions opts; |
| 1707 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1708 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1709 | const RtpHeaderExtensions offered_extensions = { |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1710 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 7)}; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1711 | const RtpHeaderExtensions local_extensions = { |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1712 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1713 | SetAudioVideoRtpHeaderExtensions(offered_extensions, offered_extensions, |
| 1714 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1715 | std::unique_ptr<SessionDescription> offer = |
| 1716 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1717 | SetAudioVideoRtpHeaderExtensions(local_extensions, local_extensions, &opts); |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1718 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1719 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1720 | EXPECT_THAT( |
| 1721 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1722 | ElementsAreArray(offered_extensions)); |
| 1723 | EXPECT_THAT( |
| 1724 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1725 | ElementsAreArray(offered_extensions)); |
| 1726 | } |
| 1727 | |
| 1728 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1729 | DoNotNegotiateAbsoluteCaptureTimeWhenNotOffered) { |
| 1730 | MediaSessionOptions opts; |
| 1731 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
| 1732 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1733 | const RtpHeaderExtensions offered_extensions = { |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1734 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, 7)}; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 1735 | const RtpHeaderExtensions local_extensions = { |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1736 | RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1737 | SetAudioVideoRtpHeaderExtensions(offered_extensions, offered_extensions, |
| 1738 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1739 | std::unique_ptr<SessionDescription> offer = |
| 1740 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1741 | SetAudioVideoRtpHeaderExtensions(local_extensions, local_extensions, &opts); |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1742 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1743 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Minyue Li | 430e4a0 | 2020-03-10 09:59:37 | [diff] [blame] | 1744 | EXPECT_THAT( |
| 1745 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), |
| 1746 | IsEmpty()); |
| 1747 | EXPECT_THAT( |
| 1748 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), |
| 1749 | IsEmpty()); |
| 1750 | } |
| 1751 | |
| 1752 | TEST_F(MediaSessionDescriptionFactoryTest, |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1753 | OffersUnstoppedExtensionsWithAudioVideoExtensionStopped) { |
| 1754 | MediaSessionOptions opts; |
| 1755 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1756 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1757 | &opts); |
| 1758 | opts.media_description_options.back().header_extensions = { |
| 1759 | webrtc::RtpHeaderExtensionCapability("uri1", 1, |
| 1760 | RtpTransceiverDirection::kStopped), |
| 1761 | webrtc::RtpHeaderExtensionCapability("uri2", 3, |
| 1762 | RtpTransceiverDirection::kSendOnly)}; |
| 1763 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 1764 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1765 | &opts); |
| 1766 | opts.media_description_options.back().header_extensions = { |
| 1767 | webrtc::RtpHeaderExtensionCapability("uri1", 1, |
| 1768 | RtpTransceiverDirection::kStopped), |
| 1769 | webrtc::RtpHeaderExtensionCapability("uri3", 7, |
| 1770 | RtpTransceiverDirection::kSendOnly)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1771 | auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1772 | EXPECT_THAT( |
| 1773 | offer->contents(), |
| 1774 | ElementsAre( |
| 1775 | Property(&ContentInfo::media_description, |
| 1776 | Pointee(Property( |
| 1777 | &MediaContentDescription::rtp_header_extensions, |
| 1778 | ElementsAre(Field(&RtpExtension::uri, "uri2"))))), |
| 1779 | Property(&ContentInfo::media_description, |
| 1780 | Pointee(Property( |
| 1781 | &MediaContentDescription::rtp_header_extensions, |
| 1782 | ElementsAre(Field(&RtpExtension::uri, "uri3"))))))); |
| 1783 | } |
| 1784 | |
| 1785 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1786 | OffersUnstoppedExtensionsWithAudioExtensionStopped) { |
| 1787 | MediaSessionOptions opts; |
| 1788 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1789 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1790 | &opts); |
| 1791 | opts.media_description_options.back().header_extensions = { |
| 1792 | webrtc::RtpHeaderExtensionCapability("uri1", 1, |
| 1793 | RtpTransceiverDirection::kSendOnly), |
| 1794 | webrtc::RtpHeaderExtensionCapability("uri2", 3, |
| 1795 | RtpTransceiverDirection::kStopped)}; |
| 1796 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 1797 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1798 | &opts); |
| 1799 | opts.media_description_options.back().header_extensions = { |
| 1800 | webrtc::RtpHeaderExtensionCapability("uri42", 42, |
| 1801 | RtpTransceiverDirection::kSendRecv), |
| 1802 | webrtc::RtpHeaderExtensionCapability("uri3", 7, |
| 1803 | RtpTransceiverDirection::kSendOnly)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1804 | auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1805 | EXPECT_THAT( |
| 1806 | offer->contents(), |
| 1807 | ElementsAre( |
| 1808 | Property(&ContentInfo::media_description, |
| 1809 | Pointee(Property( |
| 1810 | &MediaContentDescription::rtp_header_extensions, |
| 1811 | ElementsAre(Field(&RtpExtension::uri, "uri1"))))), |
| 1812 | Property( |
| 1813 | &ContentInfo::media_description, |
| 1814 | Pointee(Property( |
| 1815 | &MediaContentDescription::rtp_header_extensions, |
| 1816 | UnorderedElementsAre(Field(&RtpExtension::uri, "uri3"), |
| 1817 | Field(&RtpExtension::uri, "uri42"))))))); |
| 1818 | } |
| 1819 | |
| 1820 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1821 | OffersUnstoppedExtensionsWithVideoExtensionStopped) { |
| 1822 | MediaSessionOptions opts; |
| 1823 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1824 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1825 | &opts); |
| 1826 | opts.media_description_options.back().header_extensions = { |
| 1827 | webrtc::RtpHeaderExtensionCapability("uri1", 5, |
| 1828 | RtpTransceiverDirection::kSendOnly), |
| 1829 | webrtc::RtpHeaderExtensionCapability("uri2", 7, |
| 1830 | RtpTransceiverDirection::kSendRecv)}; |
| 1831 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 1832 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1833 | &opts); |
| 1834 | opts.media_description_options.back().header_extensions = { |
| 1835 | webrtc::RtpHeaderExtensionCapability("uri42", 42, |
| 1836 | RtpTransceiverDirection::kSendRecv), |
| 1837 | webrtc::RtpHeaderExtensionCapability("uri3", 7, |
| 1838 | RtpTransceiverDirection::kStopped)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1839 | auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1840 | EXPECT_THAT( |
| 1841 | offer->contents(), |
| 1842 | ElementsAre( |
| 1843 | Property( |
| 1844 | &ContentInfo::media_description, |
| 1845 | Pointee(Property( |
| 1846 | &MediaContentDescription::rtp_header_extensions, |
| 1847 | UnorderedElementsAre(Field(&RtpExtension::uri, "uri1"), |
| 1848 | Field(&RtpExtension::uri, "uri2"))))), |
| 1849 | Property(&ContentInfo::media_description, |
| 1850 | Pointee(Property( |
| 1851 | &MediaContentDescription::rtp_header_extensions, |
| 1852 | ElementsAre(Field(&RtpExtension::uri, "uri42"))))))); |
| 1853 | } |
| 1854 | |
| 1855 | TEST_F(MediaSessionDescriptionFactoryTest, AnswersUnstoppedExtensions) { |
| 1856 | MediaSessionOptions opts; |
| 1857 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1858 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1859 | &opts); |
| 1860 | opts.media_description_options.back().header_extensions = { |
| 1861 | webrtc::RtpHeaderExtensionCapability("uri1", 4, |
| 1862 | RtpTransceiverDirection::kStopped), |
| 1863 | webrtc::RtpHeaderExtensionCapability("uri2", 3, |
| 1864 | RtpTransceiverDirection::kSendOnly), |
| 1865 | webrtc::RtpHeaderExtensionCapability("uri3", 2, |
| 1866 | RtpTransceiverDirection::kRecvOnly), |
| 1867 | webrtc::RtpHeaderExtensionCapability("uri4", 1, |
| 1868 | RtpTransceiverDirection::kSendRecv)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1869 | auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1870 | opts.media_description_options.back().header_extensions = { |
| 1871 | webrtc::RtpHeaderExtensionCapability("uri1", 4, |
| 1872 | RtpTransceiverDirection::kSendOnly), |
| 1873 | webrtc::RtpHeaderExtensionCapability("uri2", 3, |
| 1874 | RtpTransceiverDirection::kRecvOnly), |
| 1875 | webrtc::RtpHeaderExtensionCapability("uri3", 2, |
| 1876 | RtpTransceiverDirection::kStopped), |
| 1877 | webrtc::RtpHeaderExtensionCapability("uri4", 1, |
| 1878 | RtpTransceiverDirection::kSendRecv)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1879 | auto answer = f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1880 | EXPECT_THAT( |
| 1881 | answer->contents(), |
| 1882 | ElementsAre(Property( |
| 1883 | &ContentInfo::media_description, |
| 1884 | Pointee(Property(&MediaContentDescription::rtp_header_extensions, |
| 1885 | ElementsAre(Field(&RtpExtension::uri, "uri2"), |
| 1886 | Field(&RtpExtension::uri, "uri4"))))))); |
| 1887 | } |
| 1888 | |
| 1889 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 1890 | AppendsUnstoppedExtensionsToCurrentDescription) { |
| 1891 | MediaSessionOptions opts; |
| 1892 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 1893 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1894 | &opts); |
| 1895 | opts.media_description_options.back().header_extensions = { |
| 1896 | webrtc::RtpHeaderExtensionCapability("uri1", 1, |
| 1897 | RtpTransceiverDirection::kSendRecv)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1898 | auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1899 | opts.media_description_options.back().header_extensions = { |
| 1900 | webrtc::RtpHeaderExtensionCapability("uri1", 2, |
| 1901 | RtpTransceiverDirection::kSendRecv), |
| 1902 | webrtc::RtpHeaderExtensionCapability("uri2", 3, |
| 1903 | RtpTransceiverDirection::kRecvOnly), |
| 1904 | webrtc::RtpHeaderExtensionCapability("uri3", 5, |
| 1905 | RtpTransceiverDirection::kStopped), |
| 1906 | webrtc::RtpHeaderExtensionCapability("uri4", 6, |
| 1907 | RtpTransceiverDirection::kSendRecv)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1908 | auto offer2 = f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1909 | EXPECT_THAT( |
| 1910 | offer2->contents(), |
| 1911 | ElementsAre(Property( |
| 1912 | &ContentInfo::media_description, |
| 1913 | Pointee(Property(&MediaContentDescription::rtp_header_extensions, |
| 1914 | ElementsAre(Field(&RtpExtension::uri, "uri1"), |
| 1915 | Field(&RtpExtension::uri, "uri2"), |
| 1916 | Field(&RtpExtension::uri, "uri4"))))))); |
| 1917 | } |
| 1918 | |
| 1919 | TEST_F(MediaSessionDescriptionFactoryTest, |
Philipp Hancke | 49e5587 | 2023-03-30 11:51:39 | [diff] [blame] | 1920 | AllowsStoppedExtensionsToBeRemovedFromSubsequentOffer) { |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1921 | MediaSessionOptions opts; |
| 1922 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 1923 | RtpTransceiverDirection::kSendRecv, kActive, |
| 1924 | &opts); |
| 1925 | opts.media_description_options.back().header_extensions = { |
| 1926 | webrtc::RtpHeaderExtensionCapability("uri1", 1, |
| 1927 | RtpTransceiverDirection::kSendRecv), |
Philipp Hancke | 49e5587 | 2023-03-30 11:51:39 | [diff] [blame] | 1928 | webrtc::RtpHeaderExtensionCapability("uri2", 2, |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1929 | RtpTransceiverDirection::kSendRecv)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1930 | auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1931 | |
Philipp Hancke | 49e5587 | 2023-03-30 11:51:39 | [diff] [blame] | 1932 | // Check that a subsequent offer after setting "uri2" to stopped no longer |
| 1933 | // contains the extension. |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1934 | opts.media_description_options.back().header_extensions = { |
| 1935 | webrtc::RtpHeaderExtensionCapability("uri1", 1, |
| 1936 | RtpTransceiverDirection::kSendRecv), |
| 1937 | webrtc::RtpHeaderExtensionCapability("uri2", 2, |
| 1938 | RtpTransceiverDirection::kStopped)}; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1939 | auto offer2 = f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1940 | EXPECT_THAT( |
| 1941 | offer2->contents(), |
| 1942 | ElementsAre(Property( |
| 1943 | &ContentInfo::media_description, |
| 1944 | Pointee(Property(&MediaContentDescription::rtp_header_extensions, |
Philipp Hancke | 49e5587 | 2023-03-30 11:51:39 | [diff] [blame] | 1945 | ElementsAre(Field(&RtpExtension::uri, "uri1"))))))); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1949 | TestOfferAnswerWithEncryptedRtpExtensionsBoth) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1950 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1951 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1952 | |
| 1953 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1954 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1955 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1956 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), |
| 1957 | MAKE_VECTOR(kVideoRtpExtension1), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1958 | std::unique_ptr<SessionDescription> offer = |
| 1959 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1960 | ASSERT_TRUE(offer.get()); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1961 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), |
| 1962 | MAKE_VECTOR(kVideoRtpExtension2), &opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1963 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1964 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1965 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1966 | EXPECT_EQ( |
| 1967 | MAKE_VECTOR(kAudioRtpExtensionEncrypted1), |
| 1968 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 1969 | EXPECT_EQ( |
| 1970 | MAKE_VECTOR(kVideoRtpExtensionEncrypted1), |
| 1971 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 1972 | EXPECT_EQ( |
| 1973 | MAKE_VECTOR(kAudioRtpExtensionEncryptedAnswer), |
| 1974 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 1975 | EXPECT_EQ( |
| 1976 | MAKE_VECTOR(kVideoRtpExtensionEncryptedAnswer), |
| 1977 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1981 | TestOfferAnswerWithEncryptedRtpExtensionsOffer) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1982 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1983 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1984 | |
| 1985 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1986 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1987 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), |
| 1988 | MAKE_VECTOR(kVideoRtpExtension1), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1989 | std::unique_ptr<SessionDescription> offer = |
| 1990 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 1991 | ASSERT_TRUE(offer.get()); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 1992 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), |
| 1993 | MAKE_VECTOR(kVideoRtpExtension2), &opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 1994 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 1995 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1996 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [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(kAudioRtpExtensionAnswer), |
| 2005 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 2006 | EXPECT_EQ( |
| 2007 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 2008 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2012 | TestOfferAnswerWithEncryptedRtpExtensionsAnswer) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2013 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2014 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2015 | |
| 2016 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 2017 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 2018 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), |
| 2019 | MAKE_VECTOR(kVideoRtpExtension1), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2020 | std::unique_ptr<SessionDescription> offer = |
| 2021 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 2022 | ASSERT_TRUE(offer.get()); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 2023 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), |
| 2024 | MAKE_VECTOR(kVideoRtpExtension2), &opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2025 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2026 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2027 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2028 | EXPECT_EQ( |
| 2029 | MAKE_VECTOR(kAudioRtpExtension1), |
| 2030 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 2031 | EXPECT_EQ( |
| 2032 | MAKE_VECTOR(kVideoRtpExtension1), |
| 2033 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
| 2034 | EXPECT_EQ( |
| 2035 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 2036 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 2037 | EXPECT_EQ( |
| 2038 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 2039 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2040 | } |
| 2041 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2042 | // Create an audio, video, data answer without legacy StreamParams. |
| 2043 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2044 | TestCreateAnswerWithoutLegacyStreams) { |
| 2045 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2046 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2047 | std::unique_ptr<SessionDescription> offer = |
| 2048 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 2049 | ASSERT_TRUE(offer.get()); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2050 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2051 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2052 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2053 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2054 | ASSERT_TRUE(ac); |
| 2055 | ASSERT_TRUE(vc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 2056 | const MediaContentDescription* acd = ac->media_description(); |
| 2057 | const MediaContentDescription* vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2058 | |
| 2059 | EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
| 2060 | EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2061 | } |
| 2062 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2063 | // Create a typical video answer, and ensure it matches what we expect. |
| 2064 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { |
| 2065 | MediaSessionOptions offer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2066 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2067 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2068 | MediaSessionOptions answer_opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2069 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2070 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2071 | std::unique_ptr<SessionDescription> offer; |
| 2072 | std::unique_ptr<SessionDescription> answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2073 | |
| 2074 | offer_opts.rtcp_mux_enabled = true; |
| 2075 | answer_opts.rtcp_mux_enabled = true; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2076 | offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
| 2077 | answer = |
| 2078 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
| 2079 | ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); |
| 2080 | ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); |
| 2081 | ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); |
| 2082 | ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2083 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2084 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2085 | EXPECT_TRUE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2086 | EXPECT_TRUE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2087 | |
| 2088 | offer_opts.rtcp_mux_enabled = true; |
| 2089 | answer_opts.rtcp_mux_enabled = false; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2090 | offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
| 2091 | answer = |
| 2092 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
| 2093 | ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); |
| 2094 | ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); |
| 2095 | ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); |
| 2096 | ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2097 | EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2098 | EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2099 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2100 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2101 | |
| 2102 | offer_opts.rtcp_mux_enabled = false; |
| 2103 | answer_opts.rtcp_mux_enabled = true; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2104 | offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
| 2105 | answer = |
| 2106 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
| 2107 | ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); |
| 2108 | ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); |
| 2109 | ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); |
| 2110 | ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2111 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2112 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2113 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2114 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2115 | |
| 2116 | offer_opts.rtcp_mux_enabled = false; |
| 2117 | answer_opts.rtcp_mux_enabled = false; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2118 | offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
| 2119 | answer = |
| 2120 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
| 2121 | ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); |
| 2122 | ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); |
| 2123 | ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); |
| 2124 | ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2125 | EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 2126 | EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2127 | EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 2128 | EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | // Create an audio-only answer to a video offer. |
| 2132 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerToVideo) { |
| 2133 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2134 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2135 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2136 | &opts); |
| 2137 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2138 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2139 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2140 | std::unique_ptr<SessionDescription> offer = |
| 2141 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 2142 | ASSERT_TRUE(offer.get()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2143 | |
| 2144 | opts.media_description_options[1].stopped = true; |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2145 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2146 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2147 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2148 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2149 | ASSERT_TRUE(ac); |
| 2150 | ASSERT_TRUE(vc); |
| 2151 | ASSERT_TRUE(vc->media_description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2152 | EXPECT_TRUE(vc->rejected); |
| 2153 | } |
| 2154 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2155 | // Create an answer that rejects the contents which are rejected in the offer. |
| 2156 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2157 | CreateAnswerToOfferWithRejectedMedia) { |
| 2158 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2159 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2160 | std::unique_ptr<SessionDescription> offer = |
| 2161 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 2162 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2163 | ContentInfo* ac = offer->GetContentByName("audio"); |
| 2164 | ContentInfo* vc = offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2165 | ASSERT_TRUE(ac); |
| 2166 | ASSERT_TRUE(vc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2167 | ac->rejected = true; |
| 2168 | vc->rejected = true; |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2169 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2170 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2171 | ac = answer->GetContentByName("audio"); |
| 2172 | vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2173 | ASSERT_TRUE(ac); |
| 2174 | ASSERT_TRUE(vc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2175 | EXPECT_TRUE(ac->rejected); |
| 2176 | EXPECT_TRUE(vc->rejected); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2177 | } |
| 2178 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2179 | TEST_F(MediaSessionDescriptionFactoryTest, |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2180 | OfferAndAnswerDoesNotHaveMixedByteSessionAttribute) { |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2181 | MediaSessionOptions opts; |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2182 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2183 | f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2184 | offer->set_extmap_allow_mixed(false); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2185 | |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2186 | std::unique_ptr<SessionDescription> answer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2187 | f2_.CreateAnswerOrError(offer.get(), opts, |
| 2188 | /*current_description=*/nullptr) |
| 2189 | .MoveValue()); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2190 | |
| 2191 | EXPECT_FALSE(answer->extmap_allow_mixed()); |
| 2192 | } |
| 2193 | |
| 2194 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2195 | OfferAndAnswerHaveMixedByteSessionAttribute) { |
| 2196 | MediaSessionOptions opts; |
| 2197 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2198 | f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2199 | offer->set_extmap_allow_mixed(true); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2200 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2201 | std::unique_ptr<SessionDescription> answer_support( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2202 | f2_.CreateAnswerOrError(offer.get(), opts, |
| 2203 | /*current_description=*/nullptr) |
| 2204 | .MoveValue()); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2205 | |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2206 | EXPECT_TRUE(answer_support->extmap_allow_mixed()); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | TEST_F(MediaSessionDescriptionFactoryTest, |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2210 | OfferAndAnswerDoesNotHaveMixedByteMediaAttributes) { |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2211 | MediaSessionOptions opts; |
| 2212 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2213 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2214 | f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2215 | offer->set_extmap_allow_mixed(false); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2216 | MediaContentDescription* audio_offer = |
| 2217 | offer->GetContentDescriptionByName("audio"); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2218 | MediaContentDescription* video_offer = |
| 2219 | offer->GetContentDescriptionByName("video"); |
| 2220 | ASSERT_EQ(MediaContentDescription::kNo, |
| 2221 | audio_offer->extmap_allow_mixed_enum()); |
| 2222 | ASSERT_EQ(MediaContentDescription::kNo, |
| 2223 | video_offer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2224 | |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2225 | std::unique_ptr<SessionDescription> answer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2226 | f2_.CreateAnswerOrError(offer.get(), opts, |
| 2227 | /*current_description=*/nullptr) |
| 2228 | .MoveValue()); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2229 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2230 | MediaContentDescription* audio_answer = |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2231 | answer->GetContentDescriptionByName("audio"); |
| 2232 | MediaContentDescription* video_answer = |
| 2233 | answer->GetContentDescriptionByName("video"); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2234 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2235 | audio_answer->extmap_allow_mixed_enum()); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2236 | EXPECT_EQ(MediaContentDescription::kNo, |
| 2237 | video_answer->extmap_allow_mixed_enum()); |
| 2238 | } |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2239 | |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2240 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2241 | OfferAndAnswerHaveSameMixedByteMediaAttributes) { |
| 2242 | MediaSessionOptions opts; |
| 2243 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 2244 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2245 | f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2246 | offer->set_extmap_allow_mixed(false); |
| 2247 | MediaContentDescription* audio_offer = |
| 2248 | offer->GetContentDescriptionByName("audio"); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2249 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2250 | MediaContentDescription* video_offer = |
| 2251 | offer->GetContentDescriptionByName("video"); |
| 2252 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
| 2253 | |
| 2254 | std::unique_ptr<SessionDescription> answer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2255 | f2_.CreateAnswerOrError(offer.get(), opts, |
| 2256 | /*current_description=*/nullptr) |
| 2257 | .MoveValue()); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2258 | |
| 2259 | MediaContentDescription* audio_answer = |
| 2260 | answer->GetContentDescriptionByName("audio"); |
| 2261 | MediaContentDescription* video_answer = |
| 2262 | answer->GetContentDescriptionByName("video"); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2263 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2264 | audio_answer->extmap_allow_mixed_enum()); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2265 | EXPECT_EQ(MediaContentDescription::kMedia, |
| 2266 | video_answer->extmap_allow_mixed_enum()); |
| 2267 | } |
| 2268 | |
| 2269 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2270 | OfferAndAnswerHaveDifferentMixedByteMediaAttributes) { |
| 2271 | MediaSessionOptions opts; |
| 2272 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
| 2273 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2274 | f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2275 | offer->set_extmap_allow_mixed(false); |
| 2276 | MediaContentDescription* audio_offer = |
| 2277 | offer->GetContentDescriptionByName("audio"); |
| 2278 | audio_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kNo); |
| 2279 | MediaContentDescription* video_offer = |
| 2280 | offer->GetContentDescriptionByName("video"); |
| 2281 | video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
| 2282 | |
| 2283 | std::unique_ptr<SessionDescription> answer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2284 | f2_.CreateAnswerOrError(offer.get(), opts, |
| 2285 | /*current_description=*/nullptr) |
| 2286 | .MoveValue()); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2287 | |
| 2288 | MediaContentDescription* audio_answer = |
| 2289 | answer->GetContentDescriptionByName("audio"); |
| 2290 | MediaContentDescription* video_answer = |
| 2291 | answer->GetContentDescriptionByName("video"); |
| 2292 | EXPECT_EQ(MediaContentDescription::kNo, |
| 2293 | audio_answer->extmap_allow_mixed_enum()); |
| 2294 | EXPECT_EQ(MediaContentDescription::kMedia, |
| 2295 | video_answer->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2296 | } |
| 2297 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2298 | // Create an audio and video offer with: |
| 2299 | // - one video track |
| 2300 | // - two audio tracks |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2301 | // and ensure it matches what we expect. Also updates the initial offer by |
| 2302 | // adding a new video track and replaces one of the audio tracks. |
| 2303 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { |
| 2304 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2305 | AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2306 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2307 | {kMediaStream1}, 1, &opts); |
| 2308 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2309 | {kMediaStream1}, 1, &opts); |
| 2310 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2311 | {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2312 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2313 | std::unique_ptr<SessionDescription> offer = |
| 2314 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2315 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2316 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2317 | const ContentInfo* ac = offer->GetContentByName("audio"); |
| 2318 | const ContentInfo* vc = offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2319 | ASSERT_TRUE(ac); |
| 2320 | ASSERT_TRUE(vc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 2321 | const MediaContentDescription* acd = ac->media_description(); |
| 2322 | const MediaContentDescription* vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2323 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 2324 | EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2325 | |
| 2326 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2327 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2328 | EXPECT_EQ(audio_streams[0].cname, audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2329 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2330 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2331 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2332 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2333 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2334 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2335 | |
| 2336 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2337 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2338 | |
| 2339 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2340 | EXPECT_EQ(f1_.video_sendrecv_codecs(), vcd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2341 | |
| 2342 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2343 | ASSERT_EQ(1U, video_streams.size()); |
| 2344 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2345 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2346 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2347 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2348 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2349 | // Update the offer. Add a new video track that is not synched to the |
| 2350 | // other tracks and replace audio track 2 with audio track 3. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2351 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2352 | {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2353 | DetachSenderFromMediaSection("audio", kAudioTrack2, &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2354 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack3, |
| 2355 | {kMediaStream1}, 1, &opts); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2356 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2357 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2358 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2359 | ASSERT_TRUE(updated_offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2360 | ac = updated_offer->GetContentByName("audio"); |
| 2361 | vc = updated_offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2362 | ASSERT_TRUE(ac); |
| 2363 | ASSERT_TRUE(vc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 2364 | const MediaContentDescription* updated_acd = ac->media_description(); |
| 2365 | const MediaContentDescription* updated_vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2366 | |
| 2367 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2368 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2369 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2370 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2371 | |
| 2372 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2373 | ASSERT_EQ(2U, updated_audio_streams.size()); |
| 2374 | EXPECT_EQ(audio_streams[0], updated_audio_streams[0]); |
| 2375 | EXPECT_EQ(kAudioTrack3, updated_audio_streams[1].id); // New audio track. |
| 2376 | ASSERT_EQ(1U, updated_audio_streams[1].ssrcs.size()); |
| 2377 | EXPECT_NE(0U, updated_audio_streams[1].ssrcs[0]); |
| 2378 | EXPECT_EQ(updated_audio_streams[0].cname, updated_audio_streams[1].cname); |
| 2379 | |
| 2380 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2381 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2382 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2383 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-07 01:40:30 | [diff] [blame] | 2384 | // All the media streams in one PeerConnection share one RTCP CNAME. |
| 2385 | EXPECT_EQ(updated_video_streams[1].cname, updated_video_streams[0].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2386 | } |
| 2387 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2388 | // Create an offer with simulcast video stream. |
| 2389 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { |
| 2390 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2391 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2392 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2393 | &opts); |
| 2394 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2395 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2396 | &opts); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2397 | const int num_sim_layers = 3; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2398 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2399 | {kMediaStream1}, num_sim_layers, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2400 | std::unique_ptr<SessionDescription> offer = |
| 2401 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2402 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2403 | ASSERT_TRUE(offer.get()); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2404 | const ContentInfo* vc = offer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2405 | ASSERT_TRUE(vc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 2406 | const MediaContentDescription* vcd = vc->media_description(); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2407 | |
| 2408 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2409 | ASSERT_EQ(1U, video_streams.size()); |
| 2410 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2411 | const SsrcGroup* sim_ssrc_group = |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2412 | video_streams[0].get_ssrc_group(kSimSsrcGroupSemantics); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2413 | ASSERT_TRUE(sim_ssrc_group); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2414 | EXPECT_EQ(static_cast<size_t>(num_sim_layers), sim_ssrc_group->ssrcs.size()); |
| 2415 | } |
| 2416 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2417 | MATCHER(RidDescriptionEquals, "Verifies that two RidDescriptions are equal.") { |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2418 | const RidDescription& rid1 = std::get<0>(arg); |
| 2419 | const RidDescription& rid2 = std::get<1>(arg); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2420 | return rid1.rid == rid2.rid && rid1.direction == rid2.direction; |
| 2421 | } |
| 2422 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2423 | void CheckSimulcastInSessionDescription( |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2424 | const SessionDescription* description, |
| 2425 | const std::string& content_name, |
| 2426 | const std::vector<RidDescription>& send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 20:25:25 | [diff] [blame] | 2427 | const SimulcastLayerList& send_layers) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2428 | ASSERT_NE(description, nullptr); |
| 2429 | const ContentInfo* content = description->GetContentByName(content_name); |
| 2430 | ASSERT_NE(content, nullptr); |
| 2431 | const MediaContentDescription* cd = content->media_description(); |
| 2432 | ASSERT_NE(cd, nullptr); |
| 2433 | const StreamParamsVec& streams = cd->streams(); |
| 2434 | ASSERT_THAT(streams, SizeIs(1)); |
| 2435 | const StreamParams& stream = streams[0]; |
| 2436 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2437 | EXPECT_TRUE(stream.has_rids()); |
| 2438 | const std::vector<RidDescription> rids = stream.rids(); |
| 2439 | |
| 2440 | EXPECT_THAT(rids, Pointwise(RidDescriptionEquals(), send_rids)); |
| 2441 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2442 | EXPECT_TRUE(cd->HasSimulcast()); |
| 2443 | const SimulcastDescription& simulcast = cd->simulcast_description(); |
| 2444 | EXPECT_THAT(simulcast.send_layers(), SizeIs(send_layers.size())); |
| 2445 | EXPECT_THAT(simulcast.send_layers(), Pointwise(Eq(), send_layers)); |
| 2446 | |
Amit Hilbuch | b7446ed | 2019-01-28 20:25:25 | [diff] [blame] | 2447 | ASSERT_THAT(simulcast.receive_layers().GetAllLayers(), SizeIs(0)); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | // Create an offer with spec-compliant simulcast video stream. |
| 2451 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastOffer) { |
| 2452 | MediaSessionOptions opts; |
| 2453 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2454 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2455 | &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2456 | std::vector<RidDescription> send_rids; |
| 2457 | send_rids.push_back(RidDescription("f", RidDirection::kSend)); |
| 2458 | send_rids.push_back(RidDescription("h", RidDirection::kSend)); |
| 2459 | send_rids.push_back(RidDescription("q", RidDirection::kSend)); |
| 2460 | SimulcastLayerList simulcast_layers; |
| 2461 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[0].rid, false)); |
| 2462 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[1].rid, true)); |
| 2463 | simulcast_layers.AddLayer(SimulcastLayer(send_rids[2].rid, false)); |
| 2464 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2465 | {kMediaStream1}, send_rids, |
| 2466 | simulcast_layers, 0, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2467 | std::unique_ptr<SessionDescription> offer = |
| 2468 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2469 | |
| 2470 | CheckSimulcastInSessionDescription(offer.get(), "video", send_rids, |
Amit Hilbuch | b7446ed | 2019-01-28 20:25:25 | [diff] [blame] | 2471 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | // Create an offer that signals RIDs (not SSRCs) without Simulcast. |
| 2475 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2476 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferWithRidsNoSimulcast) { |
| 2477 | MediaSessionOptions opts; |
| 2478 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2479 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2480 | &opts); |
| 2481 | RidDescription rid("f", RidDirection::kSend); |
| 2482 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2483 | {kMediaStream1}, {rid}, |
| 2484 | SimulcastLayerList(), 0, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2485 | std::unique_ptr<SessionDescription> offer = |
| 2486 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2487 | |
| 2488 | ASSERT_NE(offer.get(), nullptr); |
| 2489 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2490 | ASSERT_NE(content, nullptr); |
| 2491 | const MediaContentDescription* cd = content->media_description(); |
| 2492 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2493 | const StreamParamsVec& streams = cd->streams(); |
| 2494 | ASSERT_THAT(streams, SizeIs(1)); |
| 2495 | const StreamParams& stream = streams[0]; |
| 2496 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2497 | EXPECT_FALSE(stream.has_rids()); |
| 2498 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2499 | } |
| 2500 | |
| 2501 | // Create an answer with spec-compliant simulcast video stream. |
| 2502 | // In this scenario, the SFU is the caller requesting that we send Simulcast. |
| 2503 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastAnswer) { |
| 2504 | MediaSessionOptions offer_opts; |
| 2505 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2506 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2507 | &offer_opts); |
| 2508 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2509 | {kMediaStream1}, 1, &offer_opts); |
| 2510 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2511 | f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2512 | |
| 2513 | MediaSessionOptions answer_opts; |
| 2514 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2515 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2516 | &answer_opts); |
| 2517 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2518 | std::vector<RidDescription> rid_descriptions{ |
| 2519 | RidDescription("f", RidDirection::kSend), |
| 2520 | RidDescription("h", RidDirection::kSend), |
| 2521 | RidDescription("q", RidDirection::kSend), |
| 2522 | }; |
| 2523 | SimulcastLayerList simulcast_layers; |
| 2524 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[0].rid, false)); |
| 2525 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[1].rid, true)); |
| 2526 | simulcast_layers.AddLayer(SimulcastLayer(rid_descriptions[2].rid, false)); |
| 2527 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2528 | {kMediaStream1}, rid_descriptions, |
| 2529 | simulcast_layers, 0, &answer_opts); |
| 2530 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2531 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2532 | |
| 2533 | CheckSimulcastInSessionDescription(answer.get(), "video", rid_descriptions, |
Amit Hilbuch | b7446ed | 2019-01-28 20:25:25 | [diff] [blame] | 2534 | simulcast_layers); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | // Create an answer that signals RIDs (not SSRCs) without Simulcast. |
| 2538 | // In this scenario, RIDs do not need to be negotiated (there is only one). |
| 2539 | // Note that RID Direction is not the same as the transceiver direction. |
| 2540 | TEST_F(MediaSessionDescriptionFactoryTest, TestAnswerWithRidsNoSimulcast) { |
| 2541 | MediaSessionOptions offer_opts; |
| 2542 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2543 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2544 | &offer_opts); |
| 2545 | RidDescription rid_offer("f", RidDirection::kSend); |
| 2546 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2547 | {kMediaStream1}, {rid_offer}, |
| 2548 | SimulcastLayerList(), 0, &offer_opts); |
| 2549 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2550 | f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2551 | |
| 2552 | MediaSessionOptions answer_opts; |
| 2553 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2554 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2555 | &answer_opts); |
| 2556 | |
| 2557 | RidDescription rid_answer("f", RidDirection::kReceive); |
| 2558 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2559 | {kMediaStream1}, {rid_answer}, |
| 2560 | SimulcastLayerList(), 0, &answer_opts); |
| 2561 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2562 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2563 | |
| 2564 | ASSERT_NE(answer.get(), nullptr); |
| 2565 | const ContentInfo* content = offer->GetContentByName("video"); |
| 2566 | ASSERT_NE(content, nullptr); |
| 2567 | const MediaContentDescription* cd = content->media_description(); |
| 2568 | ASSERT_NE(cd, nullptr); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2569 | const StreamParamsVec& streams = cd->streams(); |
| 2570 | ASSERT_THAT(streams, SizeIs(1)); |
| 2571 | const StreamParams& stream = streams[0]; |
| 2572 | ASSERT_THAT(stream.ssrcs, IsEmpty()); |
| 2573 | EXPECT_FALSE(stream.has_rids()); |
| 2574 | EXPECT_FALSE(cd->HasSimulcast()); |
| 2575 | } |
| 2576 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2577 | // Create an audio and video answer to a standard video offer with: |
| 2578 | // - one video track |
| 2579 | // - two audio tracks |
| 2580 | // - two data tracks |
| 2581 | // and ensure it matches what we expect. Also updates the initial answer by |
| 2582 | // adding a new video track and removes one of the audio tracks. |
| 2583 | TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { |
| 2584 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2585 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2586 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2587 | &offer_opts); |
| 2588 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2589 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2590 | &offer_opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2591 | std::unique_ptr<SessionDescription> offer = |
| 2592 | f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2593 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2594 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2595 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2596 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2597 | &answer_opts); |
| 2598 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2599 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2600 | &answer_opts); |
| 2601 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 2602 | {kMediaStream1}, 1, &answer_opts); |
| 2603 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 2604 | {kMediaStream1}, 1, &answer_opts); |
| 2605 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 2606 | {kMediaStream1}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2607 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2608 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2609 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2610 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2611 | ASSERT_TRUE(answer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2612 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 2613 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2614 | ASSERT_TRUE(ac); |
| 2615 | ASSERT_TRUE(vc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 2616 | const MediaContentDescription* acd = ac->media_description(); |
| 2617 | const MediaContentDescription* vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2618 | |
| 2619 | EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2620 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2621 | |
| 2622 | const StreamParamsVec& audio_streams = acd->streams(); |
| 2623 | ASSERT_EQ(2U, audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2624 | EXPECT_TRUE(audio_streams[0].cname == audio_streams[1].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2625 | EXPECT_EQ(kAudioTrack1, audio_streams[0].id); |
| 2626 | ASSERT_EQ(1U, audio_streams[0].ssrcs.size()); |
| 2627 | EXPECT_NE(0U, audio_streams[0].ssrcs[0]); |
| 2628 | EXPECT_EQ(kAudioTrack2, audio_streams[1].id); |
| 2629 | ASSERT_EQ(1U, audio_streams[1].ssrcs.size()); |
| 2630 | EXPECT_NE(0U, audio_streams[1].ssrcs[0]); |
| 2631 | |
| 2632 | EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 2633 | EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
| 2634 | |
| 2635 | EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2636 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2637 | |
| 2638 | const StreamParamsVec& video_streams = vcd->streams(); |
| 2639 | ASSERT_EQ(1U, video_streams.size()); |
| 2640 | EXPECT_EQ(video_streams[0].cname, audio_streams[0].cname); |
| 2641 | EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 2642 | EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 2643 | EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 2644 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2645 | // Update the answer. Add a new video track that is not synched to the |
zhihuang | 8f65cdf | 2016-05-07 01:40:30 | [diff] [blame] | 2646 | // other tracks and remove 1 audio track. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2647 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 2648 | {kMediaStream2}, 1, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2649 | DetachSenderFromMediaSection("audio", kAudioTrack2, &answer_opts); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2650 | std::unique_ptr<SessionDescription> updated_answer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2651 | f2_.CreateAnswerOrError(offer.get(), answer_opts, answer.get()) |
| 2652 | .MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2653 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2654 | ASSERT_TRUE(updated_answer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2655 | ac = updated_answer->GetContentByName("audio"); |
| 2656 | vc = updated_answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2657 | ASSERT_TRUE(ac); |
| 2658 | ASSERT_TRUE(vc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 2659 | const MediaContentDescription* updated_acd = ac->media_description(); |
| 2660 | const MediaContentDescription* updated_vcd = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2661 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2662 | EXPECT_EQ(acd->type(), updated_acd->type()); |
| 2663 | EXPECT_EQ(acd->codecs(), updated_acd->codecs()); |
| 2664 | EXPECT_EQ(vcd->type(), updated_vcd->type()); |
| 2665 | EXPECT_EQ(vcd->codecs(), updated_vcd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2666 | |
| 2667 | const StreamParamsVec& updated_audio_streams = updated_acd->streams(); |
| 2668 | ASSERT_EQ(1U, updated_audio_streams.size()); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2669 | EXPECT_TRUE(audio_streams[0] == updated_audio_streams[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2670 | |
| 2671 | const StreamParamsVec& updated_video_streams = updated_vcd->streams(); |
| 2672 | ASSERT_EQ(2U, updated_video_streams.size()); |
| 2673 | EXPECT_EQ(video_streams[0], updated_video_streams[0]); |
| 2674 | EXPECT_EQ(kVideoTrack2, updated_video_streams[1].id); |
zhihuang | 8f65cdf | 2016-05-07 01:40:30 | [diff] [blame] | 2675 | // All media streams in one PeerConnection share one CNAME. |
| 2676 | EXPECT_EQ(updated_video_streams[1].cname, updated_video_streams[0].cname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2677 | } |
| 2678 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2679 | // Create an updated offer after creating an answer to the original offer and |
| 2680 | // verify that the codecs that were part of the original answer are not changed |
| 2681 | // in the updated offer. |
| 2682 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2683 | RespondentCreatesOfferAfterCreatingAnswer) { |
| 2684 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2685 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2686 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2687 | std::unique_ptr<SessionDescription> offer = |
| 2688 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2689 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2690 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2691 | |
| 2692 | const AudioContentDescription* acd = |
| 2693 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2694 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2695 | |
| 2696 | const VideoContentDescription* vcd = |
| 2697 | GetFirstVideoContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2698 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2699 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2700 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2701 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2702 | |
| 2703 | // The expected audio codecs are the common audio codecs from the first |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2704 | // offer/answer exchange plus the audio codecs only `f2_` offer, sorted in |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2705 | // preference order. |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2706 | // TODO(wu): `updated_offer` should not include the codec |
Artem Titov | cfea218 | 2021-08-09 23:22:31 | [diff] [blame] | 2707 | // (i.e. `kAudioCodecs2[0]`) the other side doesn't support. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2708 | const AudioCodec kUpdatedAudioCodecOffer[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 2709 | kAudioCodecsAnswer[0], |
| 2710 | kAudioCodecsAnswer[1], |
| 2711 | kAudioCodecs2[0], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2712 | }; |
| 2713 | |
| 2714 | // The expected video codecs are the common video codecs from the first |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2715 | // offer/answer exchange plus the video codecs only `f2_` offer, sorted in |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2716 | // preference order. |
| 2717 | const VideoCodec kUpdatedVideoCodecOffer[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 2718 | kVideoCodecsAnswer[0], |
| 2719 | kVideoCodecs2[1], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2720 | }; |
| 2721 | |
| 2722 | const AudioContentDescription* updated_acd = |
| 2723 | GetFirstAudioContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2724 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kUpdatedAudioCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2725 | |
| 2726 | const VideoContentDescription* updated_vcd = |
| 2727 | GetFirstVideoContentDescription(updated_offer.get()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2728 | EXPECT_THAT(updated_vcd->codecs(), ElementsAreArray(kUpdatedVideoCodecOffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2729 | } |
| 2730 | |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2731 | // Test that a reoffer does not reuse audio codecs from a previous media section |
| 2732 | // that is being recycled. |
| 2733 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2734 | ReOfferDoesNotReUseRecycledAudioCodecs) { |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2735 | f1_.set_video_codecs({}, {}); |
| 2736 | f2_.set_video_codecs({}, {}); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2737 | |
| 2738 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2739 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2740 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2741 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2742 | std::unique_ptr<SessionDescription> offer = |
| 2743 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2744 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2745 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2746 | |
| 2747 | // Recycle the media section by changing its mid. |
| 2748 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2749 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2750 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2751 | |
| 2752 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2753 | // section was not recycled the payload types would match the initial offerer. |
| 2754 | const AudioContentDescription* acd = |
| 2755 | GetFirstAudioContentDescription(reoffer.get()); |
| 2756 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecs2)); |
| 2757 | } |
| 2758 | |
| 2759 | // Test that a reoffer does not reuse video codecs from a previous media section |
| 2760 | // that is being recycled. |
| 2761 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2762 | ReOfferDoesNotReUseRecycledVideoCodecs) { |
| 2763 | f1_.set_audio_codecs({}, {}); |
| 2764 | f2_.set_audio_codecs({}, {}); |
| 2765 | |
| 2766 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2767 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2768 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2769 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2770 | std::unique_ptr<SessionDescription> offer = |
| 2771 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 2772 | auto answer = f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2773 | |
| 2774 | // Recycle the media section by changing its mid. |
| 2775 | opts.media_description_options[0].mid = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2776 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2777 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2778 | |
| 2779 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2780 | // section was not recycled the payload types would match the initial offerer. |
| 2781 | const VideoContentDescription* vcd = |
| 2782 | GetFirstVideoContentDescription(reoffer.get()); |
| 2783 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecs2)); |
| 2784 | } |
| 2785 | |
| 2786 | // Test that a reanswer does not reuse audio codecs from a previous media |
| 2787 | // section that is being recycled. |
| 2788 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2789 | ReAnswerDoesNotReUseRecycledAudioCodecs) { |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2790 | f1_.set_video_codecs({}, {}); |
| 2791 | f2_.set_video_codecs({}, {}); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2792 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2793 | // Perform initial offer/answer in reverse (`f2_` as offerer) so that the |
| 2794 | // second offer/answer is forward (`f1_` as offerer). |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2795 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2796 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", |
| 2797 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2798 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2799 | std::unique_ptr<SessionDescription> offer = |
| 2800 | f2_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2801 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2802 | f1_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2803 | |
| 2804 | // Recycle the media section by changing its mid. |
| 2805 | opts.media_description_options[0].mid = "a1"; |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2806 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2807 | f1_.CreateOfferOrError(opts, answer.get()).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2808 | std::unique_ptr<SessionDescription> reanswer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2809 | f2_.CreateAnswerOrError(reoffer.get(), opts, offer.get()).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2810 | |
| 2811 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2812 | // section was not recycled the payload types would match the initial offerer. |
| 2813 | const AudioContentDescription* acd = |
| 2814 | GetFirstAudioContentDescription(reanswer.get()); |
| 2815 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
| 2816 | } |
| 2817 | |
| 2818 | // Test that a reanswer does not reuse video codecs from a previous media |
| 2819 | // section that is being recycled. |
| 2820 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2821 | ReAnswerDoesNotReUseRecycledVideoCodecs) { |
| 2822 | f1_.set_audio_codecs({}, {}); |
| 2823 | f2_.set_audio_codecs({}, {}); |
| 2824 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2825 | // Perform initial offer/answer in reverse (`f2_` as offerer) so that the |
| 2826 | // second offer/answer is forward (`f1_` as offerer). |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2827 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2828 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", |
| 2829 | RtpTransceiverDirection::kSendRecv, kActive, |
| 2830 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2831 | std::unique_ptr<SessionDescription> offer = |
| 2832 | f2_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2833 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2834 | f1_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2835 | |
| 2836 | // Recycle the media section by changing its mid. |
| 2837 | opts.media_description_options[0].mid = "v1"; |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2838 | std::unique_ptr<SessionDescription> reoffer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2839 | f1_.CreateOfferOrError(opts, answer.get()).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2840 | std::unique_ptr<SessionDescription> reanswer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2841 | f2_.CreateAnswerOrError(reoffer.get(), opts, offer.get()).MoveValue(); |
Steve Anton | 5c72e71 | 2018-12-10 22:25:30 | [diff] [blame] | 2842 | |
| 2843 | // Expect that the results of the first negotiation are ignored. If the m= |
| 2844 | // section was not recycled the payload types would match the initial offerer. |
| 2845 | const VideoContentDescription* vcd = |
| 2846 | GetFirstVideoContentDescription(reanswer.get()); |
| 2847 | EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); |
| 2848 | } |
| 2849 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2850 | // Create an updated offer after creating an answer to the original offer and |
| 2851 | // verify that the codecs that were part of the original answer are not changed |
| 2852 | // in the updated offer. In this test Rtx is enabled. |
| 2853 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2854 | RespondentCreatesOfferAfterCreatingAnswerWithRtx) { |
| 2855 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2856 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2857 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2858 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2859 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2860 | // This creates rtx for H264 with the payload type `f1_` uses. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2861 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2862 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2863 | |
| 2864 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2865 | // This creates rtx for H264 with the payload type `f2_` uses. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2866 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2867 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2868 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2869 | std::unique_ptr<SessionDescription> offer = |
| 2870 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 2871 | ASSERT_TRUE(offer.get()); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2872 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2873 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2874 | |
| 2875 | const VideoContentDescription* vcd = |
| 2876 | GetFirstVideoContentDescription(answer.get()); |
| 2877 | |
| 2878 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2879 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2880 | |
| 2881 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2882 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2883 | // Now, make sure we get same result (except for the order) if `f2_` creates |
| 2884 | // an updated offer even though the default payload types between `f1_` and |
| 2885 | // `f2_` are different. |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2886 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2887 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2888 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2889 | std::unique_ptr<SessionDescription> updated_answer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2890 | f1_.CreateAnswerOrError(updated_offer.get(), opts, answer.get()) |
| 2891 | .MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2892 | |
| 2893 | const VideoContentDescription* updated_vcd = |
| 2894 | GetFirstVideoContentDescription(updated_answer.get()); |
| 2895 | |
| 2896 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 2897 | } |
| 2898 | |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2899 | // Regression test for: |
| 2900 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8332 |
| 2901 | // Existing codecs should always appear before new codecs in re-offers. But |
| 2902 | // under a specific set of circumstances, the existing RTX codec was ending up |
| 2903 | // added to the end of the list. |
| 2904 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2905 | RespondentCreatesOfferAfterCreatingAnswerWithRemappedRtxPayloadType) { |
| 2906 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2907 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 2908 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2909 | &opts); |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2910 | // We specifically choose different preferred payload types for VP8 to |
| 2911 | // trigger the issue. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2912 | VideoCodec vp8_offerer = CreateVideoCodec(100, "VP8"); |
| 2913 | VideoCodec vp8_offerer_rtx = CreateVideoRtxCodec(101, vp8_offerer.id); |
| 2914 | VideoCodec vp8_answerer = CreateVideoCodec(110, "VP8"); |
| 2915 | VideoCodec vp8_answerer_rtx = CreateVideoRtxCodec(111, vp8_answerer.id); |
| 2916 | VideoCodec vp9 = CreateVideoCodec(120, "VP9"); |
| 2917 | VideoCodec vp9_rtx = CreateVideoRtxCodec(121, vp9.id); |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2918 | |
| 2919 | std::vector<VideoCodec> f1_codecs = {vp8_offerer, vp8_offerer_rtx}; |
| 2920 | // We also specifically cause the answerer to prefer VP9, such that if it |
| 2921 | // *doesn't* honor the existing preferred codec (VP8) we'll notice. |
| 2922 | std::vector<VideoCodec> f2_codecs = {vp9, vp9_rtx, vp8_answerer, |
| 2923 | vp8_answerer_rtx}; |
| 2924 | |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2925 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 2926 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2927 | std::vector<AudioCodec> audio_codecs; |
| 2928 | f1_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2929 | f2_.set_audio_codecs(audio_codecs, audio_codecs); |
| 2930 | |
| 2931 | // Offer will be {VP8, RTX for VP8}. Answer will be the same. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2932 | std::unique_ptr<SessionDescription> offer = |
| 2933 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 2934 | ASSERT_TRUE(offer.get()); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2935 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2936 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2937 | |
| 2938 | // Updated offer *should* be {VP8, RTX for VP8, VP9, RTX for VP9}. |
| 2939 | // But if the bug is triggered, RTX for VP8 ends up last. |
| 2940 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2941 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2942 | |
| 2943 | const VideoContentDescription* vcd = |
| 2944 | GetFirstVideoContentDescription(updated_offer.get()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2945 | std::vector<VideoCodec> codecs = vcd->codecs(); |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2946 | ASSERT_EQ(4u, codecs.size()); |
| 2947 | EXPECT_EQ(vp8_offerer, codecs[0]); |
| 2948 | EXPECT_EQ(vp8_offerer_rtx, codecs[1]); |
| 2949 | EXPECT_EQ(vp9, codecs[2]); |
| 2950 | EXPECT_EQ(vp9_rtx, codecs[3]); |
Taylor Brandstetter | 1c34974 | 2017-10-04 01:25:36 | [diff] [blame] | 2951 | } |
| 2952 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2953 | // Create an updated offer that adds video after creating an audio only answer |
| 2954 | // to the original offer. This test verifies that if a video codec and the RTX |
| 2955 | // codec have the same default payload type as an audio codec that is already in |
| 2956 | // use, the added codecs payload types are changed. |
| 2957 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 2958 | RespondentCreatesOfferWithVideoAndRtxAfterCreatingAudioAnswer) { |
| 2959 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2960 | // This creates rtx for H264 with the payload type `f1_` uses. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2961 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2962 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2963 | |
| 2964 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 2965 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 2966 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 2967 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2968 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2969 | std::unique_ptr<SessionDescription> offer = |
| 2970 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 2971 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2972 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2973 | |
| 2974 | const AudioContentDescription* acd = |
| 2975 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2976 | EXPECT_THAT(acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2977 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2978 | // 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 | [diff] [blame] | 2979 | // reference be the same as an audio codec that was negotiated in the |
| 2980 | // first offer/answer exchange. |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 2981 | opts.media_description_options.clear(); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2982 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2983 | |
| 2984 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2985 | int used_pl_type = acd->codecs()[0].id; |
| 2986 | f2_codecs[0].id = used_pl_type; // Set the payload type for H264. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 2987 | AddRtxCodec(CreateVideoRtxCodec(125, used_pl_type), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 2988 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2989 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2990 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2991 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2992 | ASSERT_TRUE(updated_offer); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 2993 | std::unique_ptr<SessionDescription> updated_answer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 2994 | f1_.CreateAnswerOrError(updated_offer.get(), opts, answer.get()) |
| 2995 | .MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2996 | |
| 2997 | const AudioContentDescription* updated_acd = |
| 2998 | GetFirstAudioContentDescription(answer.get()); |
Steve Anton | e38a5a1 | 2018-11-22 00:05:15 | [diff] [blame] | 2999 | EXPECT_THAT(updated_acd->codecs(), ElementsAreArray(kAudioCodecsAnswer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3000 | |
| 3001 | const VideoContentDescription* updated_vcd = |
| 3002 | GetFirstVideoContentDescription(updated_answer.get()); |
| 3003 | |
| 3004 | ASSERT_EQ("H264", updated_vcd->codecs()[0].name); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3005 | ASSERT_EQ(kRtxCodecName, updated_vcd->codecs()[1].name); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3006 | int new_h264_pl_type = updated_vcd->codecs()[0].id; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3007 | EXPECT_NE(used_pl_type, new_h264_pl_type); |
| 3008 | VideoCodec rtx = updated_vcd->codecs()[1]; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3009 | int pt_referenced_by_rtx = |
| 3010 | rtc::FromString<int>(rtx.params[kCodecParamAssociatedPayloadType]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3011 | EXPECT_EQ(new_h264_pl_type, pt_referenced_by_rtx); |
| 3012 | } |
| 3013 | |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3014 | // Create an updated offer with RTX after creating an answer to an offer |
| 3015 | // without RTX, and with different default payload types. |
| 3016 | // Verify that the added RTX codec references the correct payload type. |
| 3017 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3018 | RespondentCreatesOfferWithRtxAfterCreatingAnswerWithoutRtx) { |
| 3019 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3020 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3021 | |
| 3022 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 3023 | // This creates rtx for H264 with the payload type `f2_` uses. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3024 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3025 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3026 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3027 | std::unique_ptr<SessionDescription> offer = |
| 3028 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 3029 | ASSERT_TRUE(offer.get()); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3030 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3031 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3032 | |
| 3033 | const VideoContentDescription* vcd = |
| 3034 | GetFirstVideoContentDescription(answer.get()); |
| 3035 | |
| 3036 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
| 3037 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3038 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 3039 | // Now, ensure that the RTX codec is created correctly when `f2_` creates an |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3040 | // updated offer, even though the default payload types are different from |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 3041 | // those of `f1_`. |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 3042 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3043 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3044 | ASSERT_TRUE(updated_offer); |
| 3045 | |
| 3046 | const VideoContentDescription* updated_vcd = |
| 3047 | GetFirstVideoContentDescription(updated_offer.get()); |
| 3048 | |
| 3049 | // New offer should attempt to add H263, and RTX for H264. |
| 3050 | expected_codecs.push_back(kVideoCodecs2[1]); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3051 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs1[1].id), &expected_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3052 | EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 3053 | } |
| 3054 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3055 | // Test that RTX is ignored when there is no associated payload type parameter. |
| 3056 | TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { |
| 3057 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3058 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3059 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3060 | &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3061 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3062 | // This creates RTX without associated payload type parameter. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3063 | AddRtxCodec(CreateVideoCodec(126, kRtxCodecName), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3064 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3065 | |
| 3066 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 3067 | // This creates RTX for H264 with the payload type `f2_` uses. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3068 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3069 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3070 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3071 | std::unique_ptr<SessionDescription> offer = |
| 3072 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 3073 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3074 | // kCodecParamAssociatedPayloadType will always be added to the offer when RTX |
| 3075 | // is selected. Manually remove kCodecParamAssociatedPayloadType so that it |
| 3076 | // is possible to test that that RTX is dropped when |
| 3077 | // kCodecParamAssociatedPayloadType is missing in the offer. |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3078 | MediaContentDescription* media_desc = |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3079 | offer->GetContentDescriptionByName(CN_VIDEO); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3080 | ASSERT_TRUE(media_desc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3081 | std::vector<Codec> codecs = media_desc->codecs(); |
| 3082 | for (Codec& codec : codecs) { |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3083 | if (absl::StartsWith(codec.name, kRtxCodecName)) { |
Steve Anton | 3a66edf | 2018-09-10 19:57:37 | [diff] [blame] | 3084 | codec.params.clear(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3085 | } |
| 3086 | } |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3087 | media_desc->set_codecs(codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3088 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3089 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3090 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3091 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 3092 | EXPECT_THAT( |
| 3093 | GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3094 | Not(Contains(kRtxCodecName))); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | // Test that RTX will be filtered out in the answer if its associated payload |
| 3098 | // type doesn't match the local value. |
| 3099 | TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { |
| 3100 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3101 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3102 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3103 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3104 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3105 | // This creates RTX for H264 in sender. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3106 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3107 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3108 | |
| 3109 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3110 | // This creates RTX for H263 in receiver. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3111 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs2[1].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3112 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3113 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3114 | std::unique_ptr<SessionDescription> offer = |
| 3115 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 3116 | ASSERT_TRUE(offer.get()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3117 | // Associated payload type doesn't match, therefore, RTX codec is removed in |
| 3118 | // the answer. |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3119 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3120 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3121 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 3122 | EXPECT_THAT( |
| 3123 | GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3124 | Not(Contains(kRtxCodecName))); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | // Test that when multiple RTX codecs are offered, only the matched RTX codec |
| 3128 | // is added in the answer, and the unsupported RTX codec is filtered out. |
| 3129 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3130 | FilterOutUnsupportedRtxWhenCreatingAnswer) { |
| 3131 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3132 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3133 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3134 | &opts); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3135 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3136 | // This creates RTX for H264-SVC in sender. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3137 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3138 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3139 | |
| 3140 | // This creates RTX for H264 in sender. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3141 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3142 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3143 | |
| 3144 | std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 3145 | // This creates RTX for H264 in receiver. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3146 | AddRtxCodec(CreateVideoRtxCodec(124, kVideoCodecs2[0].id), &f2_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3147 | f2_.set_video_codecs(f2_codecs, f1_codecs); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3148 | |
| 3149 | // H264-SVC codec is removed in the answer, therefore, associated RTX codec |
| 3150 | // for H264-SVC should also be removed. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3151 | std::unique_ptr<SessionDescription> offer = |
| 3152 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 3153 | ASSERT_TRUE(offer.get()); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3154 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3155 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3156 | const VideoContentDescription* vcd = |
| 3157 | GetFirstVideoContentDescription(answer.get()); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3158 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3159 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &expected_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3160 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 | [diff] [blame] | 3161 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3162 | } |
| 3163 | |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3164 | // Test that after one RTX codec has been negotiated, a new offer can attempt |
| 3165 | // to add another. |
| 3166 | TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { |
| 3167 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3168 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3169 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3170 | &opts); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3171 | std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 3172 | // This creates RTX for H264 for the offerer. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3173 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3174 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3175 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3176 | std::unique_ptr<SessionDescription> offer = |
| 3177 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3178 | ASSERT_TRUE(offer); |
| 3179 | const VideoContentDescription* vcd = |
| 3180 | GetFirstVideoContentDescription(offer.get()); |
| 3181 | |
| 3182 | std::vector<VideoCodec> expected_codecs = MAKE_VECTOR(kVideoCodecs1); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3183 | AddRtxCodec(CreateVideoRtxCodec(126, kVideoCodecs1[1].id), &expected_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3184 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3185 | |
| 3186 | // Now, attempt to add RTX for H264-SVC. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3187 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3188 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3189 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 3190 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3191 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3192 | ASSERT_TRUE(updated_offer); |
| 3193 | vcd = GetFirstVideoContentDescription(updated_offer.get()); |
| 3194 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3195 | AddRtxCodec(CreateVideoRtxCodec(125, kVideoCodecs1[0].id), &expected_codecs); |
Taylor Brandstetter | 6ec641b | 2016-03-05 00:47:56 | [diff] [blame] | 3196 | EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 3197 | } |
| 3198 | |
Noah Richards | 2e7a098 | 2015-05-18 21:02:54 | [diff] [blame] | 3199 | // Test that when RTX is used in conjunction with simulcast, an RTX ssrc is |
| 3200 | // generated for each simulcast ssrc and correctly grouped. |
| 3201 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { |
| 3202 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3203 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3204 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3205 | &opts); |
Noah Richards | 2e7a098 | 2015-05-18 21:02:54 | [diff] [blame] | 3206 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3207 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3208 | {"stream1label"}, 3, &opts); |
Noah Richards | 2e7a098 | 2015-05-18 21:02:54 | [diff] [blame] | 3209 | |
| 3210 | // Use a single real codec, and then add RTX for it. |
| 3211 | std::vector<VideoCodec> f1_codecs; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3212 | f1_codecs.push_back(CreateVideoCodec(97, "H264")); |
| 3213 | AddRtxCodec(CreateVideoRtxCodec(125, 97), &f1_codecs); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3214 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
Noah Richards | 2e7a098 | 2015-05-18 21:02:54 | [diff] [blame] | 3215 | |
| 3216 | // Ensure that the offer has an RTX ssrc for each regular ssrc, and that there |
| 3217 | // is a FID ssrc + grouping for each. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3218 | std::unique_ptr<SessionDescription> offer = |
| 3219 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 3220 | ASSERT_TRUE(offer.get()); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3221 | MediaContentDescription* media_desc = |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3222 | offer->GetContentDescriptionByName(CN_VIDEO); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3223 | ASSERT_TRUE(media_desc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3224 | const StreamParamsVec& streams = media_desc->streams(); |
Noah Richards | 2e7a098 | 2015-05-18 21:02:54 | [diff] [blame] | 3225 | // Single stream. |
| 3226 | ASSERT_EQ(1u, streams.size()); |
| 3227 | // Stream should have 6 ssrcs: 3 for video, 3 for RTX. |
| 3228 | EXPECT_EQ(6u, streams[0].ssrcs.size()); |
| 3229 | // And should have a SIM group for the simulcast. |
| 3230 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3231 | // And a FID group for RTX. |
| 3232 | EXPECT_TRUE(streams[0].has_ssrc_group("FID")); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 3233 | std::vector<uint32_t> primary_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 21:02:54 | [diff] [blame] | 3234 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3235 | EXPECT_EQ(3u, primary_ssrcs.size()); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 3236 | std::vector<uint32_t> fid_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 21:02:54 | [diff] [blame] | 3237 | streams[0].GetFidSsrcs(primary_ssrcs, &fid_ssrcs); |
| 3238 | EXPECT_EQ(3u, fid_ssrcs.size()); |
| 3239 | } |
| 3240 | |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3241 | // Test that, when the FlexFEC codec is added, a FlexFEC ssrc is created |
Philipp Hancke | fedc7ab | 2020-11-17 20:59:12 | [diff] [blame] | 3242 | // together with a FEC-FR grouping. Guarded by WebRTC-FlexFEC-03 trial. |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3243 | TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 3244 | webrtc::test::ScopedKeyValueConfig override_field_trials( |
| 3245 | field_trials, "WebRTC-FlexFEC-03/Enabled/"); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3246 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3247 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3248 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3249 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3250 | // Add single stream. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3251 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3252 | {"stream1label"}, 1, &opts); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3253 | |
| 3254 | // Use a single real codec, and then add FlexFEC for it. |
| 3255 | std::vector<VideoCodec> f1_codecs; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3256 | f1_codecs.push_back(CreateVideoCodec(97, "H264")); |
| 3257 | f1_codecs.push_back(CreateVideoCodec(118, "flexfec-03")); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3258 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3259 | |
| 3260 | // Ensure that the offer has a single FlexFEC ssrc and that |
| 3261 | // there is no FEC-FR ssrc + grouping for each. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3262 | std::unique_ptr<SessionDescription> offer = |
| 3263 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 3264 | ASSERT_TRUE(offer.get()); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3265 | MediaContentDescription* media_desc = |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3266 | offer->GetContentDescriptionByName(CN_VIDEO); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3267 | ASSERT_TRUE(media_desc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3268 | const StreamParamsVec& streams = media_desc->streams(); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3269 | // Single stream. |
| 3270 | ASSERT_EQ(1u, streams.size()); |
| 3271 | // Stream should have 2 ssrcs: 1 for video, 1 for FlexFEC. |
| 3272 | EXPECT_EQ(2u, streams[0].ssrcs.size()); |
| 3273 | // And should have a FEC-FR group for FlexFEC. |
| 3274 | EXPECT_TRUE(streams[0].has_ssrc_group("FEC-FR")); |
| 3275 | std::vector<uint32_t> primary_ssrcs; |
| 3276 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3277 | ASSERT_EQ(1u, primary_ssrcs.size()); |
| 3278 | uint32_t flexfec_ssrc; |
| 3279 | EXPECT_TRUE(streams[0].GetFecFrSsrc(primary_ssrcs[0], &flexfec_ssrc)); |
| 3280 | EXPECT_NE(flexfec_ssrc, 0u); |
| 3281 | } |
| 3282 | |
| 3283 | // Test that FlexFEC is disabled for simulcast. |
| 3284 | // TODO(brandtr): Remove this test when we support simulcast, either through |
| 3285 | // multiple FlexfecSenders, or through multistream protection. |
| 3286 | TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 3287 | webrtc::test::ScopedKeyValueConfig override_field_trials( |
| 3288 | field_trials, "WebRTC-FlexFEC-03/Enabled/"); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3289 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3290 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3291 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3292 | &opts); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3293 | // Add simulcast streams. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3294 | AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, "stream1", |
| 3295 | {"stream1label"}, 3, &opts); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3296 | |
| 3297 | // Use a single real codec, and then add FlexFEC for it. |
| 3298 | std::vector<VideoCodec> f1_codecs; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3299 | f1_codecs.push_back(CreateVideoCodec(97, "H264")); |
| 3300 | f1_codecs.push_back(CreateVideoCodec(118, "flexfec-03")); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 3301 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3302 | |
| 3303 | // Ensure that the offer has no FlexFEC ssrcs for each regular ssrc, and that |
| 3304 | // there is no FEC-FR ssrc + grouping for each. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3305 | std::unique_ptr<SessionDescription> offer = |
| 3306 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 3307 | ASSERT_TRUE(offer.get()); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3308 | MediaContentDescription* media_desc = |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3309 | offer->GetContentDescriptionByName(CN_VIDEO); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3310 | ASSERT_TRUE(media_desc); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3311 | const StreamParamsVec& streams = media_desc->streams(); |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 3312 | // Single stream. |
| 3313 | ASSERT_EQ(1u, streams.size()); |
| 3314 | // Stream should have 3 ssrcs: 3 for video, 0 for FlexFEC. |
| 3315 | EXPECT_EQ(3u, streams[0].ssrcs.size()); |
| 3316 | // And should have a SIM group for the simulcast. |
| 3317 | EXPECT_TRUE(streams[0].has_ssrc_group("SIM")); |
| 3318 | // And not a FEC-FR group for FlexFEC. |
| 3319 | EXPECT_FALSE(streams[0].has_ssrc_group("FEC-FR")); |
| 3320 | std::vector<uint32_t> primary_ssrcs; |
| 3321 | streams[0].GetPrimarySsrcs(&primary_ssrcs); |
| 3322 | EXPECT_EQ(3u, primary_ssrcs.size()); |
| 3323 | for (uint32_t primary_ssrc : primary_ssrcs) { |
| 3324 | uint32_t flexfec_ssrc; |
| 3325 | EXPECT_FALSE(streams[0].GetFecFrSsrc(primary_ssrc, &flexfec_ssrc)); |
| 3326 | } |
| 3327 | } |
| 3328 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3329 | // Create an updated offer after creating an answer to the original offer and |
| 3330 | // verify that the RTP header extensions that were part of the original answer |
| 3331 | // are not changed in the updated offer. |
| 3332 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3333 | RespondentCreatesOfferAfterCreatingAnswerWithRtpExtensions) { |
| 3334 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3335 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3336 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 3337 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), |
| 3338 | MAKE_VECTOR(kVideoRtpExtension1), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3339 | std::unique_ptr<SessionDescription> offer = |
| 3340 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 3341 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), |
| 3342 | MAKE_VECTOR(kVideoRtpExtension2), &opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3343 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3344 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3345 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3346 | EXPECT_EQ( |
| 3347 | MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 3348 | GetFirstAudioContentDescription(answer.get())->rtp_header_extensions()); |
| 3349 | EXPECT_EQ( |
| 3350 | MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 3351 | GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3352 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 3353 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3354 | f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3355 | |
| 3356 | // The expected RTP header extensions in the new offer are the resulting |
| 3357 | // extensions from the first offer/answer exchange plus the extensions only |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 3358 | // `f2_` offer. |
| 3359 | // Since the default local extension id `f2_` uses has already been used by |
| 3360 | // `f1_` for another extensions, it is changed to 13. |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 3361 | const RtpExtension kUpdatedAudioRtpExtensions[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 3362 | kAudioRtpExtensionAnswer[0], |
| 3363 | RtpExtension(kAudioRtpExtension2[1].uri, 13), |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 3364 | kAudioRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3365 | }; |
| 3366 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 3367 | // Since the default local extension id `f2_` uses has already been used by |
| 3368 | // `f1_` for another extensions, is is changed to 12. |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 3369 | const RtpExtension kUpdatedVideoRtpExtensions[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 3370 | kVideoRtpExtensionAnswer[0], |
| 3371 | RtpExtension(kVideoRtpExtension2[1].uri, 12), |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 3372 | kVideoRtpExtension2[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3373 | }; |
| 3374 | |
| 3375 | const AudioContentDescription* updated_acd = |
| 3376 | GetFirstAudioContentDescription(updated_offer.get()); |
| 3377 | EXPECT_EQ(MAKE_VECTOR(kUpdatedAudioRtpExtensions), |
| 3378 | updated_acd->rtp_header_extensions()); |
| 3379 | |
| 3380 | const VideoContentDescription* updated_vcd = |
| 3381 | GetFirstVideoContentDescription(updated_offer.get()); |
| 3382 | EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoRtpExtensions), |
| 3383 | updated_vcd->rtp_header_extensions()); |
| 3384 | } |
| 3385 | |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3386 | // Verify that if the same RTP extension URI is used for audio and video, the |
| 3387 | // same ID is used. Also verify that the ID isn't changed when creating an |
| 3388 | // updated offer (this was previously a bug). |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 3389 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3390 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3391 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3392 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 3393 | SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension3), |
| 3394 | MAKE_VECTOR(kVideoRtpExtension3), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3395 | std::unique_ptr<SessionDescription> offer = |
| 3396 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3397 | |
| 3398 | // Since the audio extensions used ID 3 for "both_audio_and_video", so should |
| 3399 | // the video extensions. |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 3400 | const RtpExtension kExpectedVideoRtpExtension[] = { |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 3401 | kVideoRtpExtension3[0], |
| 3402 | kAudioRtpExtension3[1], |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3403 | }; |
| 3404 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3405 | EXPECT_EQ( |
| 3406 | MAKE_VECTOR(kAudioRtpExtension3), |
| 3407 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3408 | EXPECT_EQ( |
| 3409 | MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 3410 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3411 | |
| 3412 | // Nothing should change when creating a new offer |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 3413 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3414 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3415 | |
| 3416 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3417 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3418 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3419 | EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3420 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3421 | ->rtp_header_extensions()); |
deadbeef | a5b273a | 2015-08-21 00:30:13 | [diff] [blame] | 3422 | } |
| 3423 | |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3424 | // Same as "RtpExtensionIdReused" above for encrypted RTP extensions. |
| 3425 | TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { |
| 3426 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3427 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3428 | |
| 3429 | f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 3430 | f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 3431 | |
Markus Handell | 755c65d | 2020-06-23 23:06:10 | [diff] [blame] | 3432 | SetAudioVideoRtpHeaderExtensions( |
| 3433 | MAKE_VECTOR(kAudioRtpExtension3ForEncryption), |
| 3434 | MAKE_VECTOR(kVideoRtpExtension3ForEncryption), &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3435 | std::unique_ptr<SessionDescription> offer = |
| 3436 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3437 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3438 | EXPECT_EQ( |
| 3439 | MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
| 3440 | GetFirstAudioContentDescription(offer.get())->rtp_header_extensions()); |
| 3441 | EXPECT_EQ( |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 3442 | MAKE_VECTOR(kVideoRtpExtension3ForEncryptionOffer), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3443 | GetFirstVideoContentDescription(offer.get())->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3444 | |
| 3445 | // Nothing should change when creating a new offer |
| 3446 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3447 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3448 | |
| 3449 | EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3450 | GetFirstAudioContentDescription(updated_offer.get()) |
| 3451 | ->rtp_header_extensions()); |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 3452 | EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtension3ForEncryptionOffer), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3453 | GetFirstVideoContentDescription(updated_offer.get()) |
| 3454 | ->rtp_header_extensions()); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3455 | } |
| 3456 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3457 | TEST(MediaSessionDescription, CopySessionDescription) { |
| 3458 | SessionDescription source; |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3459 | ContentGroup group(CN_AUDIO); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3460 | source.AddGroup(group); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 3461 | std::unique_ptr<AudioContentDescription> acd = |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 3462 | std::make_unique<AudioContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3463 | acd->set_codecs(MAKE_VECTOR(kAudioCodecs1)); |
| 3464 | acd->AddLegacyStream(1); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3465 | source.AddContent(CN_AUDIO, MediaProtocolType::kRtp, acd->Clone()); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 3466 | std::unique_ptr<VideoContentDescription> vcd = |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 3467 | std::make_unique<VideoContentDescription>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3468 | vcd->set_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 3469 | vcd->AddLegacyStream(2); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3470 | source.AddContent(CN_VIDEO, MediaProtocolType::kRtp, vcd->Clone()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3471 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3472 | std::unique_ptr<SessionDescription> copy = source.Clone(); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3473 | ASSERT_TRUE(copy.get()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3474 | EXPECT_TRUE(copy->HasGroup(CN_AUDIO)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3475 | const ContentInfo* ac = copy->GetContentByName("audio"); |
| 3476 | const ContentInfo* vc = copy->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3477 | ASSERT_TRUE(ac); |
| 3478 | ASSERT_TRUE(vc); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 3479 | EXPECT_EQ(MediaProtocolType::kRtp, ac->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3480 | const MediaContentDescription* acd_copy = ac->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3481 | EXPECT_EQ(acd->codecs(), acd_copy->codecs()); |
| 3482 | EXPECT_EQ(1u, acd->first_ssrc()); |
| 3483 | |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 3484 | EXPECT_EQ(MediaProtocolType::kRtp, vc->type); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3485 | const MediaContentDescription* vcd_copy = vc->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3486 | EXPECT_EQ(vcd->codecs(), vcd_copy->codecs()); |
| 3487 | EXPECT_EQ(2u, vcd->first_ssrc()); |
| 3488 | } |
| 3489 | |
| 3490 | // The below TestTransportInfoXXX tests create different offers/answers, and |
| 3491 | // ensure the TransportInfo in the SessionDescription matches what we expect. |
| 3492 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudio) { |
| 3493 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3494 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3495 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3496 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3497 | TestTransportInfo(true, options, false); |
| 3498 | } |
| 3499 | |
Honghai Zhang | 4cedf2b | 2016-08-31 15:18:11 | [diff] [blame] | 3500 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3501 | TestTransportInfoOfferIceRenomination) { |
| 3502 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3503 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3504 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3505 | &options); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3506 | options.media_description_options[0] |
| 3507 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 15:18:11 | [diff] [blame] | 3508 | TestTransportInfo(true, options, false); |
| 3509 | } |
| 3510 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3511 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudioCurrent) { |
| 3512 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3513 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3514 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3515 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3516 | TestTransportInfo(true, options, true); |
| 3517 | } |
| 3518 | |
| 3519 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferMultimedia) { |
| 3520 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3521 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3522 | TestTransportInfo(true, options, false); |
| 3523 | } |
| 3524 | |
| 3525 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3526 | TestTransportInfoOfferMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3527 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3528 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3529 | TestTransportInfo(true, options, true); |
| 3530 | } |
| 3531 | |
| 3532 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferBundle) { |
| 3533 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3534 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3535 | options.bundle_enabled = true; |
| 3536 | TestTransportInfo(true, options, false); |
| 3537 | } |
| 3538 | |
| 3539 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3540 | TestTransportInfoOfferBundleCurrent) { |
| 3541 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3542 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3543 | options.bundle_enabled = true; |
| 3544 | TestTransportInfo(true, options, true); |
| 3545 | } |
| 3546 | |
| 3547 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerAudio) { |
| 3548 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3549 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3550 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3551 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3552 | TestTransportInfo(false, options, false); |
| 3553 | } |
| 3554 | |
| 3555 | TEST_F(MediaSessionDescriptionFactoryTest, |
Honghai Zhang | 4cedf2b | 2016-08-31 15:18:11 | [diff] [blame] | 3556 | TestTransportInfoAnswerIceRenomination) { |
| 3557 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3558 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3559 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3560 | &options); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3561 | options.media_description_options[0] |
| 3562 | .transport_options.enable_ice_renomination = true; |
Honghai Zhang | 4cedf2b | 2016-08-31 15:18:11 | [diff] [blame] | 3563 | TestTransportInfo(false, options, false); |
| 3564 | } |
| 3565 | |
| 3566 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3567 | TestTransportInfoAnswerAudioCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3568 | MediaSessionOptions options; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3569 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3570 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3571 | &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3572 | TestTransportInfo(false, options, true); |
| 3573 | } |
| 3574 | |
| 3575 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerMultimedia) { |
| 3576 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3577 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3578 | TestTransportInfo(false, options, false); |
| 3579 | } |
| 3580 | |
| 3581 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3582 | TestTransportInfoAnswerMultimediaCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3583 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3584 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3585 | TestTransportInfo(false, options, true); |
| 3586 | } |
| 3587 | |
| 3588 | TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerBundle) { |
| 3589 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3590 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3591 | options.bundle_enabled = true; |
| 3592 | TestTransportInfo(false, options, false); |
| 3593 | } |
| 3594 | |
| 3595 | TEST_F(MediaSessionDescriptionFactoryTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3596 | TestTransportInfoAnswerBundleCurrent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3597 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3598 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3599 | options.bundle_enabled = true; |
| 3600 | TestTransportInfo(false, options, true); |
| 3601 | } |
| 3602 | |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 | [diff] [blame] | 3603 | // Offers UDP/TLS/RTP/SAVPF and verifies the answer can be created and contains |
| 3604 | // UDP/TLS/RTP/SAVPF. |
| 3605 | TEST_F(MediaSessionDescriptionFactoryTest, TestOfferDtlsSavpfCreateAnswer) { |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3606 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 3607 | f1_.CreateOfferOrError(CreateAudioMediaSession(), nullptr).MoveValue(); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3608 | ASSERT_TRUE(offer.get()); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 | [diff] [blame] | 3609 | ContentInfo* offer_content = offer->GetContentByName("audio"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3610 | ASSERT_TRUE(offer_content); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3611 | MediaContentDescription* offer_audio_desc = |
| 3612 | offer_content->media_description(); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3613 | offer_audio_desc->set_protocol(kMediaProtocolDtlsSavpf); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 | [diff] [blame] | 3614 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3615 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 7fbcc8c | 2023-11-02 09:53:21 | [diff] [blame] | 3616 | f2_.CreateAnswerOrError(offer.get(), CreateAudioMediaSession(), nullptr) |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3617 | .MoveValue(); |
| 3618 | ASSERT_TRUE(answer); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 | [diff] [blame] | 3619 | |
| 3620 | const ContentInfo* answer_content = answer->GetContentByName("audio"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3621 | ASSERT_TRUE(answer_content); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 | [diff] [blame] | 3622 | ASSERT_FALSE(answer_content->rejected); |
| 3623 | |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3624 | const MediaContentDescription* answer_audio_desc = |
| 3625 | answer_content->media_description(); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3626 | EXPECT_EQ(kMediaProtocolDtlsSavpf, answer_audio_desc->protocol()); |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 | [diff] [blame] | 3627 | } |
| 3628 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 3629 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3630 | // Test that we accept a DTLS offer without SDES and create an appropriate |
| 3631 | // answer. |
| 3632 | TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 3633 | /* TODO(hta): Figure this one out. |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 3634 | f1_.set_secure(SEC_DISABLED); |
| 3635 | f2_.set_secure(SEC_ENABLED); |
| 3636 | tdf1_.set_secure(SEC_ENABLED); |
| 3637 | tdf2_.set_secure(SEC_ENABLED); |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 3638 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3639 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3640 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3641 | |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 3642 | // Generate an offer with DTLS |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3643 | std::unique_ptr<SessionDescription> offer = |
| 3644 | f1_.CreateOfferOrError(options, nullptr).MoveValue(); |
| 3645 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3646 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3647 | const TransportDescription* audio_offer_trans_desc = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3648 | offer->GetTransportDescriptionByName("audio"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3649 | ASSERT_TRUE(audio_offer_trans_desc->identity_fingerprint.get()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3650 | const TransportDescription* video_offer_trans_desc = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3651 | offer->GetTransportDescriptionByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3652 | ASSERT_TRUE(video_offer_trans_desc->identity_fingerprint.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3653 | |
| 3654 | // Generate an answer with DTLS. |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3655 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3656 | f2_.CreateAnswerOrError(offer.get(), options, nullptr).MoveValue(); |
| 3657 | ASSERT_TRUE(answer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3658 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3659 | const TransportDescription* audio_answer_trans_desc = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3660 | answer->GetTransportDescriptionByName("audio"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3661 | EXPECT_TRUE(audio_answer_trans_desc->identity_fingerprint.get()); |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 3662 | const TransportDescription* video_answer_trans_desc = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3663 | answer->GetTransportDescriptionByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3664 | EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | // Verifies if vad_enabled option is set to false, CN codecs are not present in |
| 3668 | // offer or answer. |
| 3669 | TEST_F(MediaSessionDescriptionFactoryTest, TestVADEnableOption) { |
| 3670 | MediaSessionOptions options; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3671 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3672 | std::unique_ptr<SessionDescription> offer = |
| 3673 | f1_.CreateOfferOrError(options, nullptr).MoveValue(); |
| 3674 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3675 | const ContentInfo* audio_content = offer->GetContentByName("audio"); |
| 3676 | EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); |
| 3677 | |
| 3678 | options.vad_enabled = false; |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3679 | offer = f1_.CreateOfferOrError(options, nullptr).MoveValue(); |
| 3680 | ASSERT_TRUE(offer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3681 | audio_content = offer->GetContentByName("audio"); |
| 3682 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3683 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3684 | f1_.CreateAnswerOrError(offer.get(), options, nullptr).MoveValue(); |
| 3685 | ASSERT_TRUE(answer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3686 | audio_content = answer->GetContentByName("audio"); |
| 3687 | EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
| 3688 | } |
deadbeef | 44f0819 | 2015-12-16 00:20:09 | [diff] [blame] | 3689 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3690 | // Test that the generated MIDs match the existing offer. |
| 3691 | TEST_F(MediaSessionDescriptionFactoryTest, TestMIDsMatchesExistingOffer) { |
deadbeef | 44f0819 | 2015-12-16 00:20:09 | [diff] [blame] | 3692 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3693 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_modified", |
| 3694 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3695 | &opts); |
| 3696 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_modified", |
| 3697 | RtpTransceiverDirection::kRecvOnly, kActive, |
| 3698 | &opts); |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3699 | AddMediaDescriptionOptions(MEDIA_TYPE_DATA, "data_modified", |
| 3700 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3701 | &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3702 | // Create offer. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3703 | std::unique_ptr<SessionDescription> offer = |
| 3704 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 3705 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3706 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3707 | |
deadbeef | 44f0819 | 2015-12-16 00:20:09 | [diff] [blame] | 3708 | const ContentInfo* audio_content = GetFirstAudioContent(updated_offer.get()); |
| 3709 | const ContentInfo* video_content = GetFirstVideoContent(updated_offer.get()); |
| 3710 | const ContentInfo* data_content = GetFirstDataContent(updated_offer.get()); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3711 | ASSERT_TRUE(audio_content); |
| 3712 | ASSERT_TRUE(video_content); |
| 3713 | ASSERT_TRUE(data_content); |
deadbeef | 44f0819 | 2015-12-16 00:20:09 | [diff] [blame] | 3714 | EXPECT_EQ("audio_modified", audio_content->name); |
| 3715 | EXPECT_EQ("video_modified", video_content->name); |
| 3716 | EXPECT_EQ("data_modified", data_content->name); |
| 3717 | } |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 3718 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3719 | // The following tests verify that the unified plan SDP is supported. |
| 3720 | // Test that we can create an offer with multiple media sections of same media |
| 3721 | // type. |
| 3722 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3723 | CreateOfferWithMultipleAVMediaSections) { |
| 3724 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3725 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 3726 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3727 | &opts); |
| 3728 | AttachSenderToMediaDescriptionOptions( |
| 3729 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3730 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3731 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 3732 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3733 | &opts); |
| 3734 | AttachSenderToMediaDescriptionOptions( |
| 3735 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3736 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3737 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 3738 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3739 | &opts); |
| 3740 | AttachSenderToMediaDescriptionOptions( |
| 3741 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3742 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3743 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 3744 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3745 | &opts); |
| 3746 | AttachSenderToMediaDescriptionOptions( |
| 3747 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3748 | std::unique_ptr<SessionDescription> offer = |
| 3749 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3750 | ASSERT_TRUE(offer); |
| 3751 | |
| 3752 | ASSERT_EQ(4u, offer->contents().size()); |
| 3753 | EXPECT_FALSE(offer->contents()[0].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3754 | const MediaContentDescription* acd = offer->contents()[0].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3755 | ASSERT_EQ(1u, acd->streams().size()); |
| 3756 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3757 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3758 | |
| 3759 | EXPECT_FALSE(offer->contents()[1].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3760 | const MediaContentDescription* vcd = offer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3761 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3762 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3763 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3764 | |
| 3765 | EXPECT_FALSE(offer->contents()[2].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3766 | acd = offer->contents()[2].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3767 | ASSERT_EQ(1u, acd->streams().size()); |
| 3768 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3769 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3770 | |
| 3771 | EXPECT_FALSE(offer->contents()[3].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3772 | vcd = offer->contents()[3].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3773 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3774 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3775 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | // Test that we can create an answer with multiple media sections of same media |
| 3779 | // type. |
| 3780 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3781 | CreateAnswerWithMultipleAVMediaSections) { |
| 3782 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3783 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_1", |
| 3784 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3785 | &opts); |
| 3786 | AttachSenderToMediaDescriptionOptions( |
| 3787 | "audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3788 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3789 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_1", |
| 3790 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3791 | &opts); |
| 3792 | AttachSenderToMediaDescriptionOptions( |
| 3793 | "video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3794 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3795 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio_2", |
| 3796 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3797 | &opts); |
| 3798 | AttachSenderToMediaDescriptionOptions( |
| 3799 | "audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3800 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3801 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video_2", |
| 3802 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3803 | &opts); |
| 3804 | AttachSenderToMediaDescriptionOptions( |
| 3805 | "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3806 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3807 | std::unique_ptr<SessionDescription> offer = |
| 3808 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3809 | ASSERT_TRUE(offer); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3810 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3811 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3812 | |
| 3813 | ASSERT_EQ(4u, answer->contents().size()); |
| 3814 | EXPECT_FALSE(answer->contents()[0].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3815 | const MediaContentDescription* acd = |
| 3816 | answer->contents()[0].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3817 | ASSERT_EQ(1u, acd->streams().size()); |
| 3818 | EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3819 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3820 | |
| 3821 | EXPECT_FALSE(answer->contents()[1].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3822 | const MediaContentDescription* vcd = |
| 3823 | answer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3824 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3825 | EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3826 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3827 | |
| 3828 | EXPECT_FALSE(answer->contents()[2].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3829 | acd = answer->contents()[2].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3830 | ASSERT_EQ(1u, acd->streams().size()); |
| 3831 | EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3832 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, acd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3833 | |
| 3834 | EXPECT_FALSE(answer->contents()[3].rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3835 | vcd = answer->contents()[3].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3836 | ASSERT_EQ(1u, vcd->streams().size()); |
| 3837 | EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 3838 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, vcd->direction()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | // Test that the media section will be rejected in offer if the corresponding |
| 3842 | // MediaDescriptionOptions is stopped by the offerer. |
| 3843 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3844 | CreateOfferWithMediaSectionStoppedByOfferer) { |
| 3845 | // Create an offer with two audio sections and one of them is stopped. |
| 3846 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3847 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3848 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3849 | &offer_opts); |
| 3850 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3851 | RtpTransceiverDirection::kInactive, kStopped, |
| 3852 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3853 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3854 | f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3855 | ASSERT_TRUE(offer); |
| 3856 | ASSERT_EQ(2u, offer->contents().size()); |
| 3857 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 3858 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 3859 | } |
| 3860 | |
| 3861 | // Test that the media section will be rejected in answer if the corresponding |
| 3862 | // MediaDescriptionOptions is stopped by the offerer. |
| 3863 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3864 | CreateAnswerWithMediaSectionStoppedByOfferer) { |
| 3865 | // Create an offer with two audio sections and one of them is stopped. |
| 3866 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3867 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3868 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3869 | &offer_opts); |
| 3870 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3871 | RtpTransceiverDirection::kInactive, kStopped, |
| 3872 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3873 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3874 | f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3875 | ASSERT_TRUE(offer); |
| 3876 | ASSERT_EQ(2u, offer->contents().size()); |
| 3877 | EXPECT_FALSE(offer->contents()[0].rejected); |
| 3878 | EXPECT_TRUE(offer->contents()[1].rejected); |
| 3879 | |
| 3880 | // Create an answer based on the offer. |
| 3881 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3882 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3883 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3884 | &answer_opts); |
| 3885 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3886 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3887 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3888 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3889 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3890 | ASSERT_EQ(2u, answer->contents().size()); |
| 3891 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 3892 | EXPECT_TRUE(answer->contents()[1].rejected); |
| 3893 | } |
| 3894 | |
| 3895 | // Test that the media section will be rejected in answer if the corresponding |
| 3896 | // MediaDescriptionOptions is stopped by the answerer. |
| 3897 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3898 | CreateAnswerWithMediaSectionRejectedByAnswerer) { |
| 3899 | // Create an offer with two audio sections. |
| 3900 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3901 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3902 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3903 | &offer_opts); |
| 3904 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3905 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3906 | &offer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3907 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3908 | f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3909 | ASSERT_TRUE(offer); |
| 3910 | ASSERT_EQ(2u, offer->contents().size()); |
| 3911 | ASSERT_FALSE(offer->contents()[0].rejected); |
| 3912 | ASSERT_FALSE(offer->contents()[1].rejected); |
| 3913 | |
| 3914 | // The answerer rejects one of the audio sections. |
| 3915 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3916 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio1", |
| 3917 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3918 | &answer_opts); |
| 3919 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio2", |
| 3920 | RtpTransceiverDirection::kInactive, kStopped, |
| 3921 | &answer_opts); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3922 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3923 | f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3924 | ASSERT_EQ(2u, answer->contents().size()); |
| 3925 | EXPECT_FALSE(answer->contents()[0].rejected); |
| 3926 | EXPECT_TRUE(answer->contents()[1].rejected); |
Zhi Huang | 3518e7b | 2018-01-30 21:20:35 | [diff] [blame] | 3927 | |
| 3928 | // The TransportInfo of the rejected m= section is expected to be added in the |
| 3929 | // answer. |
| 3930 | EXPECT_EQ(offer->transport_infos().size(), answer->transport_infos().size()); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | // Test the generated media sections has the same order of the |
| 3934 | // corresponding MediaDescriptionOptions. |
| 3935 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3936 | CreateOfferRespectsMediaDescriptionOptionsOrder) { |
| 3937 | MediaSessionOptions opts; |
| 3938 | // This tests put video section first because normally audio comes first by |
| 3939 | // default. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3940 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 3941 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3942 | &opts); |
| 3943 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 3944 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3945 | &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3946 | std::unique_ptr<SessionDescription> offer = |
| 3947 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3948 | |
| 3949 | ASSERT_TRUE(offer); |
| 3950 | ASSERT_EQ(2u, offer->contents().size()); |
| 3951 | EXPECT_EQ("video", offer->contents()[0].name); |
| 3952 | EXPECT_EQ("audio", offer->contents()[1].name); |
| 3953 | } |
| 3954 | |
| 3955 | // Test that different media sections using the same codec have same payload |
| 3956 | // type. |
| 3957 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 3958 | PayloadTypesSharedByMediaSectionsOfSameType) { |
| 3959 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 3960 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 3961 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3962 | &opts); |
| 3963 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 3964 | RtpTransceiverDirection::kSendRecv, kActive, |
| 3965 | &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3966 | // Create an offer with two video sections using same codecs. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3967 | std::unique_ptr<SessionDescription> offer = |
| 3968 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3969 | ASSERT_TRUE(offer); |
| 3970 | ASSERT_EQ(2u, offer->contents().size()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3971 | const MediaContentDescription* vcd1 = |
| 3972 | offer->contents()[0].media_description(); |
| 3973 | const MediaContentDescription* vcd2 = |
| 3974 | offer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3975 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 3976 | ASSERT_EQ(2u, vcd1->codecs().size()); |
| 3977 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 3978 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 3979 | EXPECT_EQ(vcd1->codecs()[1].name, vcd2->codecs()[1].name); |
| 3980 | EXPECT_EQ(vcd1->codecs()[1].id, vcd2->codecs()[1].id); |
| 3981 | |
| 3982 | // Create answer and negotiate the codecs. |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 3983 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 3984 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3985 | ASSERT_TRUE(answer); |
| 3986 | ASSERT_EQ(2u, answer->contents().size()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 3987 | vcd1 = answer->contents()[0].media_description(); |
| 3988 | vcd2 = answer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 3989 | EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); |
| 3990 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 3991 | EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); |
| 3992 | EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); |
| 3993 | } |
| 3994 | |
Qiu Jianlin | b3488d0 | 2023-12-07 00:12:12 | [diff] [blame] | 3995 | #ifdef RTC_ENABLE_H265 |
| 3996 | // Test verifying that negotiating codecs with the same tx-mode retains the |
| 3997 | // tx-mode value. |
| 3998 | TEST_F(MediaSessionDescriptionFactoryTest, H265TxModeIsEqualRetainIt) { |
| 3999 | std::vector f1_codecs = {CreateVideoCodec(96, "H265")}; |
| 4000 | f1_codecs.back().tx_mode = "mrst"; |
| 4001 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 4002 | |
| 4003 | std::vector f2_codecs = {CreateVideoCodec(96, "H265")}; |
| 4004 | f2_codecs.back().tx_mode = "mrst"; |
| 4005 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
| 4006 | |
| 4007 | MediaSessionOptions opts; |
| 4008 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4009 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4010 | &opts); |
| 4011 | |
| 4012 | // Create an offer with two video sections using same codecs. |
| 4013 | std::unique_ptr<SessionDescription> offer = |
| 4014 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 4015 | ASSERT_TRUE(offer); |
| 4016 | ASSERT_EQ(1u, offer->contents().size()); |
| 4017 | const MediaContentDescription* vcd1 = |
| 4018 | offer->contents()[0].media_description(); |
| 4019 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4020 | EXPECT_EQ(vcd1->codecs()[0].tx_mode, "mrst"); |
| 4021 | |
| 4022 | // Create answer and negotiate the codecs. |
| 4023 | std::unique_ptr<SessionDescription> answer = |
| 4024 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
| 4025 | ASSERT_TRUE(answer); |
| 4026 | ASSERT_EQ(1u, answer->contents().size()); |
| 4027 | vcd1 = answer->contents()[0].media_description(); |
| 4028 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4029 | EXPECT_EQ(vcd1->codecs()[0].tx_mode, "mrst"); |
| 4030 | } |
| 4031 | |
| 4032 | // Test verifying that negotiating codecs with different tx_mode removes |
| 4033 | // the tx_mode value. |
| 4034 | TEST_F(MediaSessionDescriptionFactoryTest, H265TxModeIsDifferentDropCodecs) { |
| 4035 | std::vector f1_codecs = {CreateVideoCodec(96, "H265")}; |
| 4036 | f1_codecs.back().tx_mode = "mrst"; |
| 4037 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 4038 | |
| 4039 | std::vector f2_codecs = {CreateVideoCodec(96, "H265")}; |
| 4040 | f2_codecs.back().tx_mode = "mrmt"; |
| 4041 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
| 4042 | |
| 4043 | MediaSessionOptions opts; |
| 4044 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4045 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4046 | &opts); |
| 4047 | |
| 4048 | // Create an offer with two video sections using same codecs. |
| 4049 | std::unique_ptr<SessionDescription> offer = |
| 4050 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 4051 | ASSERT_TRUE(offer); |
| 4052 | ASSERT_EQ(1u, offer->contents().size()); |
| 4053 | const VideoContentDescription* vcd1 = |
| 4054 | offer->contents()[0].media_description()->as_video(); |
| 4055 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4056 | EXPECT_EQ(vcd1->codecs()[0].tx_mode, "mrst"); |
| 4057 | |
| 4058 | // Create answer and negotiate the codecs. |
| 4059 | std::unique_ptr<SessionDescription> answer = |
| 4060 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
| 4061 | ASSERT_TRUE(answer); |
| 4062 | ASSERT_EQ(1u, answer->contents().size()); |
| 4063 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4064 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4065 | EXPECT_EQ(vcd1->codecs()[0].tx_mode, absl::nullopt); |
| 4066 | } |
| 4067 | #endif |
| 4068 | |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 4069 | // Test verifying that negotiating codecs with the same packetization retains |
| 4070 | // the packetization value. |
| 4071 | TEST_F(MediaSessionDescriptionFactoryTest, PacketizationIsEqual) { |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4072 | std::vector f1_codecs = {CreateVideoCodec(96, "H264")}; |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 4073 | f1_codecs.back().packetization = "raw"; |
| 4074 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 4075 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4076 | std::vector f2_codecs = {CreateVideoCodec(96, "H264")}; |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 4077 | f2_codecs.back().packetization = "raw"; |
| 4078 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
| 4079 | |
| 4080 | MediaSessionOptions opts; |
| 4081 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4082 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4083 | &opts); |
| 4084 | |
| 4085 | // Create an offer with two video sections using same codecs. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4086 | std::unique_ptr<SessionDescription> offer = |
| 4087 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 4088 | ASSERT_TRUE(offer); |
| 4089 | ASSERT_EQ(1u, offer->contents().size()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4090 | const MediaContentDescription* vcd1 = |
| 4091 | offer->contents()[0].media_description(); |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 4092 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4093 | EXPECT_EQ(vcd1->codecs()[0].packetization, "raw"); |
| 4094 | |
| 4095 | // Create answer and negotiate the codecs. |
| 4096 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4097 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 4098 | ASSERT_TRUE(answer); |
| 4099 | ASSERT_EQ(1u, answer->contents().size()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4100 | vcd1 = answer->contents()[0].media_description(); |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 4101 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4102 | EXPECT_EQ(vcd1->codecs()[0].packetization, "raw"); |
| 4103 | } |
| 4104 | |
Tony Herre | a5c8ee1 | 2023-11-30 11:24:09 | [diff] [blame] | 4105 | // Test verifying that negotiating codecs with different packetization removes |
| 4106 | // the packetization value. |
| 4107 | TEST_F(MediaSessionDescriptionFactoryTest, PacketizationIsDifferent) { |
| 4108 | std::vector f1_codecs = {CreateVideoCodec(96, "H264")}; |
| 4109 | f1_codecs.back().packetization = "raw"; |
| 4110 | f1_.set_video_codecs(f1_codecs, f1_codecs); |
| 4111 | |
| 4112 | std::vector f2_codecs = {CreateVideoCodec(96, "H264")}; |
| 4113 | f2_codecs.back().packetization = "notraw"; |
| 4114 | f2_.set_video_codecs(f2_codecs, f2_codecs); |
| 4115 | |
| 4116 | MediaSessionOptions opts; |
| 4117 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4118 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4119 | &opts); |
| 4120 | |
| 4121 | // Create an offer with two video sections using same codecs. |
| 4122 | std::unique_ptr<SessionDescription> offer = |
| 4123 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 4124 | ASSERT_TRUE(offer); |
| 4125 | ASSERT_EQ(1u, offer->contents().size()); |
| 4126 | const VideoContentDescription* vcd1 = |
| 4127 | offer->contents()[0].media_description()->as_video(); |
| 4128 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4129 | EXPECT_EQ(vcd1->codecs()[0].packetization, "raw"); |
| 4130 | |
| 4131 | // Create answer and negotiate the codecs. |
| 4132 | std::unique_ptr<SessionDescription> answer = |
| 4133 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
| 4134 | ASSERT_TRUE(answer); |
| 4135 | ASSERT_EQ(1u, answer->contents().size()); |
| 4136 | vcd1 = answer->contents()[0].media_description()->as_video(); |
| 4137 | ASSERT_EQ(1u, vcd1->codecs().size()); |
| 4138 | EXPECT_EQ(vcd1->codecs()[0].packetization, absl::nullopt); |
| 4139 | } |
| 4140 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4141 | // Test that the codec preference order per media section is respected in |
| 4142 | // subsequent offer. |
| 4143 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4144 | CreateOfferRespectsCodecPreferenceOrder) { |
| 4145 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4146 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4147 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4148 | &opts); |
| 4149 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4150 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4151 | &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4152 | // Create an offer with two video sections using same codecs. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4153 | std::unique_ptr<SessionDescription> offer = |
| 4154 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4155 | ASSERT_TRUE(offer); |
| 4156 | ASSERT_EQ(2u, offer->contents().size()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4157 | MediaContentDescription* vcd1 = offer->contents()[0].media_description(); |
| 4158 | const MediaContentDescription* vcd2 = |
| 4159 | offer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4160 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4161 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4162 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4163 | |
| 4164 | // Change the codec preference of the first video section and create a |
| 4165 | // follow-up offer. |
| 4166 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4167 | vcd1->set_codecs(video_codecs_reverse); |
| 4168 | std::unique_ptr<SessionDescription> updated_offer( |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4169 | f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4170 | vcd1 = updated_offer->contents()[0].media_description(); |
| 4171 | vcd2 = updated_offer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4172 | // The video codec preference order should be respected. |
| 4173 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4174 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4175 | } |
| 4176 | |
| 4177 | // Test that the codec preference order per media section is respected in |
| 4178 | // the answer. |
| 4179 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4180 | CreateAnswerRespectsCodecPreferenceOrder) { |
| 4181 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4182 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video1", |
| 4183 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4184 | &opts); |
| 4185 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video2", |
| 4186 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4187 | &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4188 | // Create an offer with two video sections using same codecs. |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4189 | std::unique_ptr<SessionDescription> offer = |
| 4190 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4191 | ASSERT_TRUE(offer); |
| 4192 | ASSERT_EQ(2u, offer->contents().size()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4193 | MediaContentDescription* vcd1 = offer->contents()[0].media_description(); |
| 4194 | const MediaContentDescription* vcd2 = |
| 4195 | offer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4196 | auto video_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 4197 | EXPECT_EQ(video_codecs, vcd1->codecs()); |
| 4198 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4199 | |
| 4200 | // Change the codec preference of the first video section and create an |
| 4201 | // answer. |
| 4202 | auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); |
| 4203 | vcd1->set_codecs(video_codecs_reverse); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 4204 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4205 | f1_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4206 | vcd1 = answer->contents()[0].media_description(); |
| 4207 | vcd2 = answer->contents()[1].media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4208 | // The video codec preference order should be respected. |
| 4209 | EXPECT_EQ(video_codecs_reverse, vcd1->codecs()); |
| 4210 | EXPECT_EQ(video_codecs, vcd2->codecs()); |
| 4211 | } |
| 4212 | |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4213 | // Test that when creating an answer, the codecs use local parameters instead of |
| 4214 | // the remote ones. |
| 4215 | TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerWithLocalCodecParams) { |
| 4216 | const std::string audio_param_name = "audio_param"; |
| 4217 | const std::string audio_value1 = "audio_v1"; |
| 4218 | const std::string audio_value2 = "audio_v2"; |
| 4219 | const std::string video_param_name = "video_param"; |
| 4220 | const std::string video_value1 = "video_v1"; |
| 4221 | const std::string video_value2 = "video_v2"; |
| 4222 | |
| 4223 | auto audio_codecs1 = MAKE_VECTOR(kAudioCodecs1); |
| 4224 | auto audio_codecs2 = MAKE_VECTOR(kAudioCodecs1); |
| 4225 | auto video_codecs1 = MAKE_VECTOR(kVideoCodecs1); |
| 4226 | auto video_codecs2 = MAKE_VECTOR(kVideoCodecs1); |
| 4227 | |
| 4228 | // Set the parameters for codecs. |
| 4229 | audio_codecs1[0].SetParam(audio_param_name, audio_value1); |
| 4230 | video_codecs1[0].SetParam(video_param_name, video_value1); |
| 4231 | audio_codecs2[0].SetParam(audio_param_name, audio_value2); |
| 4232 | video_codecs2[0].SetParam(video_param_name, video_value2); |
| 4233 | |
| 4234 | f1_.set_audio_codecs(audio_codecs1, audio_codecs1); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 4235 | f1_.set_video_codecs(video_codecs1, video_codecs1); |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4236 | f2_.set_audio_codecs(audio_codecs2, audio_codecs2); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 4237 | f2_.set_video_codecs(video_codecs2, video_codecs2); |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4238 | |
| 4239 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4240 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", |
| 4241 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4242 | &opts); |
| 4243 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4244 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4245 | &opts); |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4246 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4247 | std::unique_ptr<SessionDescription> offer = |
| 4248 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4249 | ASSERT_TRUE(offer); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4250 | auto offer_acd = offer->contents()[0].media_description(); |
| 4251 | auto offer_vcd = offer->contents()[1].media_description(); |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4252 | std::string value; |
| 4253 | EXPECT_TRUE(offer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4254 | EXPECT_EQ(audio_value1, value); |
| 4255 | EXPECT_TRUE(offer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4256 | EXPECT_EQ(video_value1, value); |
| 4257 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 4258 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4259 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4260 | ASSERT_TRUE(answer); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4261 | auto answer_acd = answer->contents()[0].media_description(); |
| 4262 | auto answer_vcd = answer->contents()[1].media_description(); |
Zhi Huang | 6f36747 | 2017-11-22 21:20:02 | [diff] [blame] | 4263 | // Use the parameters from the local codecs. |
| 4264 | EXPECT_TRUE(answer_acd->codecs()[0].GetParam(audio_param_name, &value)); |
| 4265 | EXPECT_EQ(audio_value2, value); |
| 4266 | EXPECT_TRUE(answer_vcd->codecs()[0].GetParam(video_param_name, &value)); |
| 4267 | EXPECT_EQ(video_value2, value); |
| 4268 | } |
| 4269 | |
Steve Anton | 9c1fb1e | 2018-02-26 23:09:41 | [diff] [blame] | 4270 | // Test that matching packetization-mode is part of the criteria for matching |
| 4271 | // H264 codecs (in addition to profile-level-id). Previously, this was not the |
| 4272 | // case, so the first H264 codec with the same profile-level-id would match and |
| 4273 | // the payload type in the answer would be incorrect. |
| 4274 | // This is a regression test for bugs.webrtc.org/8808 |
| 4275 | TEST_F(MediaSessionDescriptionFactoryTest, |
| 4276 | H264MatchCriteriaIncludesPacketizationMode) { |
| 4277 | // Create two H264 codecs with the same profile level ID and different |
| 4278 | // packetization modes. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4279 | VideoCodec h264_pm0 = CreateVideoCodec(96, "H264"); |
| 4280 | h264_pm0.params[kH264FmtpProfileLevelId] = "42c01f"; |
| 4281 | h264_pm0.params[kH264FmtpPacketizationMode] = "0"; |
| 4282 | VideoCodec h264_pm1 = CreateVideoCodec(97, "H264"); |
| 4283 | h264_pm1.params[kH264FmtpProfileLevelId] = "42c01f"; |
| 4284 | h264_pm1.params[kH264FmtpPacketizationMode] = "1"; |
Steve Anton | 9c1fb1e | 2018-02-26 23:09:41 | [diff] [blame] | 4285 | |
| 4286 | // Offerer will send both codecs, answerer should choose the one with matching |
| 4287 | // packetization mode (and not the first one it sees). |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 4288 | f1_.set_video_codecs({h264_pm0, h264_pm1}, {h264_pm0, h264_pm1}); |
| 4289 | f2_.set_video_codecs({h264_pm1}, {h264_pm1}); |
Steve Anton | 9c1fb1e | 2018-02-26 23:09:41 | [diff] [blame] | 4290 | |
| 4291 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4292 | AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", |
| 4293 | RtpTransceiverDirection::kSendRecv, kActive, |
| 4294 | &opts); |
Steve Anton | 9c1fb1e | 2018-02-26 23:09:41 | [diff] [blame] | 4295 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4296 | std::unique_ptr<SessionDescription> offer = |
| 4297 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
Steve Anton | 9c1fb1e | 2018-02-26 23:09:41 | [diff] [blame] | 4298 | ASSERT_TRUE(offer); |
| 4299 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 4300 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4301 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
Steve Anton | 9c1fb1e | 2018-02-26 23:09:41 | [diff] [blame] | 4302 | ASSERT_TRUE(answer); |
| 4303 | |
| 4304 | // Answer should have one negotiated codec with packetization-mode=1 using the |
| 4305 | // offered payload type. |
| 4306 | ASSERT_EQ(1u, answer->contents().size()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4307 | auto answer_vcd = answer->contents()[0].media_description(); |
Steve Anton | 9c1fb1e | 2018-02-26 23:09:41 | [diff] [blame] | 4308 | ASSERT_EQ(1u, answer_vcd->codecs().size()); |
| 4309 | auto answer_codec = answer_vcd->codecs()[0]; |
| 4310 | EXPECT_EQ(h264_pm1.id, answer_codec.id); |
| 4311 | } |
| 4312 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4313 | class MediaProtocolTest : public testing::TestWithParam<const char*> { |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4314 | public: |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 4315 | MediaProtocolTest() |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 4316 | : tdf1_(field_trials_), |
| 4317 | tdf2_(field_trials_), |
Philipp Hancke | 332c56f | 2023-09-27 08:06:37 | [diff] [blame] | 4318 | f1_(nullptr, false, &ssrc_generator1, &tdf1_), |
| 4319 | f2_(nullptr, false, &ssrc_generator2, &tdf2_) { |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4320 | f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 4321 | MAKE_VECTOR(kAudioCodecs1)); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 4322 | f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1), |
| 4323 | MAKE_VECTOR(kVideoCodecs1)); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4324 | f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 4325 | MAKE_VECTOR(kAudioCodecs2)); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 4326 | f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2), |
| 4327 | MAKE_VECTOR(kVideoCodecs2)); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4328 | tdf1_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-15 02:44:11 | [diff] [blame] | 4329 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4330 | tdf2_.set_certificate(rtc::RTCCertificate::Create( |
kwiberg | fd8be34 | 2016-05-15 02:44:11 | [diff] [blame] | 4331 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | protected: |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 4335 | webrtc::test::ScopedKeyValueConfig field_trials_; |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4336 | TransportDescriptionFactory tdf1_; |
| 4337 | TransportDescriptionFactory tdf2_; |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 4338 | MediaSessionDescriptionFactory f1_; |
| 4339 | MediaSessionDescriptionFactory f2_; |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 4340 | UniqueRandomIdGenerator ssrc_generator1; |
| 4341 | UniqueRandomIdGenerator ssrc_generator2; |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4342 | }; |
| 4343 | |
| 4344 | TEST_P(MediaProtocolTest, TestAudioVideoAcceptance) { |
| 4345 | MediaSessionOptions opts; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4346 | AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4347 | std::unique_ptr<SessionDescription> offer = |
| 4348 | f1_.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 4349 | ASSERT_TRUE(offer.get()); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4350 | // Set the protocol for all the contents. |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 4351 | for (auto& content : offer.get()->contents()) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4352 | content.media_description()->set_protocol(GetParam()); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4353 | } |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 4354 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4355 | f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4356 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4357 | const ContentInfo* vc = answer->GetContentByName("video"); |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4358 | ASSERT_TRUE(ac); |
| 4359 | ASSERT_TRUE(vc); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4360 | EXPECT_FALSE(ac->rejected); // the offer is accepted |
| 4361 | EXPECT_FALSE(vc->rejected); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4362 | const MediaContentDescription* acd = ac->media_description(); |
| 4363 | const MediaContentDescription* vcd = vc->media_description(); |
zhihuang | cf5b37c | 2016-05-05 18:44:35 | [diff] [blame] | 4364 | EXPECT_EQ(GetParam(), acd->protocol()); |
| 4365 | EXPECT_EQ(GetParam(), vcd->protocol()); |
| 4366 | } |
| 4367 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 4368 | INSTANTIATE_TEST_SUITE_P(MediaProtocolPatternTest, |
| 4369 | MediaProtocolTest, |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4370 | ValuesIn(kMediaProtocols)); |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 4371 | INSTANTIATE_TEST_SUITE_P(MediaProtocolDtlsPatternTest, |
| 4372 | MediaProtocolTest, |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4373 | ValuesIn(kMediaProtocolsDtls)); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4374 | |
| 4375 | TEST_F(MediaSessionDescriptionFactoryTest, TestSetAudioCodecs) { |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 4376 | webrtc::test::ScopedKeyValueConfig field_trials; |
| 4377 | TransportDescriptionFactory tdf(field_trials); |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 4378 | tdf.set_certificate(rtc::RTCCertificate::Create( |
| 4379 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id")))); |
| 4380 | |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 4381 | UniqueRandomIdGenerator ssrc_generator; |
Philipp Hancke | 332c56f | 2023-09-27 08:06:37 | [diff] [blame] | 4382 | MediaSessionDescriptionFactory sf(nullptr, false, &ssrc_generator, &tdf); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4383 | std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4384 | std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4385 | |
| 4386 | // The merged list of codecs should contain any send codecs that are also |
Niels Möller | be74b80 | 2022-03-18 13:10:15 | [diff] [blame] | 4387 | // nominally in the receive codecs list. Payload types should be picked from |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4388 | // the send codecs and a number-of-channels of 0 and 1 should be equivalent |
| 4389 | // (set to 1). This equals what happens when the send codecs are used in an |
| 4390 | // offer and the receive codecs are used in the following answer. |
| 4391 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4392 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4393 | const std::vector<AudioCodec> no_codecs; |
| 4394 | |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 4395 | RTC_CHECK_EQ(send_codecs[2].name, "iLBC") |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4396 | << "Please don't change shared test data!"; |
| 4397 | RTC_CHECK_EQ(recv_codecs[2].name, "iLBC") |
| 4398 | << "Please don't change shared test data!"; |
| 4399 | // Alter iLBC send codec to have zero channels, to test that that is handled |
| 4400 | // properly. |
Tomas Lundqvist | a26d6ed | 2023-10-27 12:25:57 | [diff] [blame] | 4401 | send_codecs[2].channels = 0; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4402 | |
Philipp Hancke | b41316cd | 2020-05-26 11:45:20 | [diff] [blame] | 4403 | // Alter iLBC receive codec to be lowercase, to test that case conversions |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4404 | // are handled properly. |
| 4405 | recv_codecs[2].name = "ilbc"; |
| 4406 | |
| 4407 | // Test proper merge |
| 4408 | sf.set_audio_codecs(send_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4409 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4410 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4411 | EXPECT_EQ(sendrecv_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4412 | |
| 4413 | // Test empty send codecs list |
| 4414 | sf.set_audio_codecs(no_codecs, recv_codecs); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4415 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4416 | EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 4417 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4418 | |
| 4419 | // Test empty recv codecs list |
| 4420 | sf.set_audio_codecs(send_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4421 | EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 4422 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4423 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4424 | |
| 4425 | // Test all empty codec lists |
| 4426 | sf.set_audio_codecs(no_codecs, no_codecs); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4427 | EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 4428 | EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 4429 | EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4430 | } |
| 4431 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4432 | // Compare the two vectors of codecs ignoring the payload type. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4433 | bool CodecsMatch(const std::vector<Codec>& codecs1, |
Emil Lundmark | f268afd | 2023-11-08 15:34:11 | [diff] [blame] | 4434 | const std::vector<Codec>& codecs2) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4435 | if (codecs1.size() != codecs2.size()) { |
| 4436 | return false; |
| 4437 | } |
| 4438 | |
| 4439 | for (size_t i = 0; i < codecs1.size(); ++i) { |
Emil Lundmark | f268afd | 2023-11-08 15:34:11 | [diff] [blame] | 4440 | if (!codecs1[i].Matches(codecs2[i])) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4441 | return false; |
| 4442 | } |
| 4443 | } |
| 4444 | return true; |
| 4445 | } |
| 4446 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4447 | void TestAudioCodecsOffer(RtpTransceiverDirection direction) { |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 4448 | webrtc::test::ScopedKeyValueConfig field_trials; |
| 4449 | TransportDescriptionFactory tdf(field_trials); |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 4450 | tdf.set_certificate(rtc::RTCCertificate::Create( |
| 4451 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id")))); |
| 4452 | |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 4453 | UniqueRandomIdGenerator ssrc_generator; |
Philipp Hancke | 332c56f | 2023-09-27 08:06:37 | [diff] [blame] | 4454 | MediaSessionDescriptionFactory sf(nullptr, false, &ssrc_generator, &tdf); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4455 | const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 4456 | const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 4457 | const std::vector<AudioCodec> sendrecv_codecs = |
| 4458 | MAKE_VECTOR(kAudioCodecsAnswer); |
| 4459 | sf.set_audio_codecs(send_codecs, recv_codecs); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4460 | |
| 4461 | MediaSessionOptions opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4462 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", direction, kActive, |
| 4463 | &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4464 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4465 | if (direction == RtpTransceiverDirection::kSendRecv || |
| 4466 | direction == RtpTransceiverDirection::kSendOnly) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4467 | AttachSenderToMediaDescriptionOptions( |
| 4468 | "audio", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4469 | } |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4470 | |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4471 | std::unique_ptr<SessionDescription> offer = |
| 4472 | sf.CreateOfferOrError(opts, nullptr).MoveValue(); |
| 4473 | ASSERT_TRUE(offer.get()); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4474 | ContentInfo* ac = offer->GetContentByName("audio"); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4475 | |
| 4476 | // If the factory didn't add any audio content to the offer, we cannot check |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4477 | // that the codecs put in are right. This happens when we neither want to |
| 4478 | // send nor receive audio. The checks are still in place if at some point |
| 4479 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4480 | if (ac) { |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4481 | MediaContentDescription* acd = ac->media_description(); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4482 | // sendrecv and inactive should both present lists as if the channel was |
| 4483 | // to be used for sending and receiving. Inactive essentially means it |
| 4484 | // might eventually be used anything, but we don't know more at this |
| 4485 | // moment. |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4486 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
Emil Lundmark | f268afd | 2023-11-08 15:34:11 | [diff] [blame] | 4487 | EXPECT_TRUE(CodecsMatch(send_codecs, acd->codecs())); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4488 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
Emil Lundmark | f268afd | 2023-11-08 15:34:11 | [diff] [blame] | 4489 | EXPECT_TRUE(CodecsMatch(recv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4490 | } else { |
Emil Lundmark | f268afd | 2023-11-08 15:34:11 | [diff] [blame] | 4491 | EXPECT_TRUE(CodecsMatch(sendrecv_codecs, acd->codecs())); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4492 | } |
| 4493 | } |
| 4494 | } |
| 4495 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4496 | const AudioCodec kOfferAnswerCodecs[] = { |
| 4497 | CreateAudioCodec(0, "codec0", 16000, 1), |
| 4498 | CreateAudioCodec(1, "codec1", 8000, 1), |
| 4499 | CreateAudioCodec(2, "codec2", 8000, 1), |
| 4500 | CreateAudioCodec(3, "codec3", 8000, 1), |
| 4501 | CreateAudioCodec(4, "codec4", 8000, 2), |
| 4502 | CreateAudioCodec(5, "codec5", 32000, 1), |
| 4503 | CreateAudioCodec(6, "codec6", 48000, 1)}; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4504 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4505 | /* The codecs groups below are chosen as per the matrix below. The objective |
| 4506 | * is to have different sets of codecs in the inputs, to get unique sets of |
| 4507 | * codecs after negotiation, depending on offer and answer communication |
| 4508 | * directions. One-way directions in the offer should either result in the |
| 4509 | * opposite direction in the answer, or an inactive answer. Regardless, the |
| 4510 | * choice of codecs should be as if the answer contained the opposite |
| 4511 | * direction. Inactive offers should be treated as sendrecv/sendrecv. |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4512 | * |
| 4513 | * | Offer | Answer | Result |
| 4514 | * codec|send recv sr | send recv sr | s/r r/s sr/s sr/r sr/sr |
| 4515 | * 0 | x - - | - x - | x - - - - |
| 4516 | * 1 | x x x | - x - | x - - x - |
| 4517 | * 2 | - x - | x - - | - x - - - |
| 4518 | * 3 | x x x | x - - | - x x - - |
| 4519 | * 4 | - x - | x x x | - x - - - |
| 4520 | * 5 | x - - | x x x | x - - - - |
| 4521 | * 6 | x x x | x x x | x x x x x |
| 4522 | */ |
| 4523 | // Codecs used by offerer in the AudioCodecsAnswerTest |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4524 | const int kOfferSendCodecs[] = {0, 1, 3, 5, 6}; |
| 4525 | const int kOfferRecvCodecs[] = {1, 2, 3, 4, 6}; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4526 | // Codecs used in the answerer in the AudioCodecsAnswerTest. The order is |
| 4527 | // jumbled to catch the answer not following the order in the offer. |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4528 | const int kAnswerSendCodecs[] = {6, 5, 2, 3, 4}; |
| 4529 | const int kAnswerRecvCodecs[] = {6, 5, 4, 1, 0}; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4530 | // The resulting sets of codecs in the answer in the AudioCodecsAnswerTest |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4531 | const int kResultSend_RecvCodecs[] = {0, 1, 5, 6}; |
| 4532 | const int kResultRecv_SendCodecs[] = {2, 3, 4, 6}; |
| 4533 | const int kResultSendrecv_SendCodecs[] = {3, 6}; |
| 4534 | const int kResultSendrecv_RecvCodecs[] = {1, 6}; |
| 4535 | const int kResultSendrecv_SendrecvCodecs[] = {6}; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4536 | |
| 4537 | template <typename T, int IDXS> |
| 4538 | std::vector<T> VectorFromIndices(const T* array, const int (&indices)[IDXS]) { |
| 4539 | std::vector<T> out; |
| 4540 | out.reserve(IDXS); |
| 4541 | for (int idx : indices) |
| 4542 | out.push_back(array[idx]); |
| 4543 | |
| 4544 | return out; |
| 4545 | } |
| 4546 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4547 | void TestAudioCodecsAnswer(RtpTransceiverDirection offer_direction, |
| 4548 | RtpTransceiverDirection answer_direction, |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4549 | bool add_legacy_stream) { |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 4550 | webrtc::test::ScopedKeyValueConfig field_trials; |
| 4551 | TransportDescriptionFactory offer_tdf(field_trials); |
| 4552 | TransportDescriptionFactory answer_tdf(field_trials); |
Harald Alvestrand | 974044e | 2024-02-08 13:15:51 | [diff] [blame] | 4553 | offer_tdf.set_certificate(rtc::RTCCertificate::Create( |
| 4554 | std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("offer_id")))); |
| 4555 | answer_tdf.set_certificate( |
| 4556 | rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
| 4557 | new rtc::FakeSSLIdentity("answer_id")))); |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 4558 | UniqueRandomIdGenerator ssrc_generator1, ssrc_generator2; |
Philipp Hancke | 332c56f | 2023-09-27 08:06:37 | [diff] [blame] | 4559 | MediaSessionDescriptionFactory offer_factory(nullptr, false, &ssrc_generator1, |
| 4560 | &offer_tdf); |
| 4561 | MediaSessionDescriptionFactory answer_factory(nullptr, false, |
| 4562 | &ssrc_generator2, &answer_tdf); |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 4563 | |
ossu | 075af92 | 2016-06-14 10:29:38 | [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 10:29:38 | [diff] [blame] | 4571 | MediaSessionOptions offer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4572 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", offer_direction, |
| 4573 | kActive, &offer_opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4574 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4575 | if (webrtc::RtpTransceiverDirectionHasSend(offer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4576 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4577 | kAudioTrack1, {kMediaStream1}, 1, |
| 4578 | &offer_opts); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4579 | } |
| 4580 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 4581 | std::unique_ptr<SessionDescription> offer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4582 | offer_factory.CreateOfferOrError(offer_opts, nullptr).MoveValue(); |
| 4583 | ASSERT_TRUE(offer.get()); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4584 | |
| 4585 | MediaSessionOptions answer_opts; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4586 | AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", answer_direction, |
| 4587 | kActive, &answer_opts); |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4588 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4589 | if (webrtc::RtpTransceiverDirectionHasSend(answer_direction)) { |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 4590 | AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, |
| 4591 | kAudioTrack1, {kMediaStream1}, 1, |
| 4592 | &answer_opts); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4593 | } |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 4594 | std::unique_ptr<SessionDescription> answer = |
Philipp Hancke | 2bf1b99 | 2023-09-26 07:04:46 | [diff] [blame] | 4595 | answer_factory.CreateAnswerOrError(offer.get(), answer_opts, nullptr) |
| 4596 | .MoveValue(); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4597 | const ContentInfo* ac = answer->GetContentByName("audio"); |
| 4598 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4599 | // If the factory didn't add any audio content to the answer, we cannot |
| 4600 | // check that the codecs put in are right. This happens when we neither want |
| 4601 | // to send nor receive audio. The checks are still in place if at some point |
| 4602 | // we'd instead create an inactive stream. |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4603 | if (ac) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4604 | ASSERT_EQ(MEDIA_TYPE_AUDIO, ac->media_description()->type()); |
Philipp Hancke | d0f0f38 | 2023-11-23 19:21:05 | [diff] [blame] | 4605 | const MediaContentDescription* acd = ac->media_description(); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4606 | |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4607 | std::vector<AudioCodec> target_codecs; |
| 4608 | // For offers with sendrecv or inactive, we should never reply with more |
| 4609 | // codecs than offered, with these codec sets. |
| 4610 | switch (offer_direction) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4611 | case RtpTransceiverDirection::kInactive: |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4612 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4613 | kResultSendrecv_SendrecvCodecs); |
| 4614 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4615 | case RtpTransceiverDirection::kSendOnly: |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4616 | target_codecs = |
| 4617 | VectorFromIndices(kOfferAnswerCodecs, kResultSend_RecvCodecs); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4618 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4619 | case RtpTransceiverDirection::kRecvOnly: |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4620 | target_codecs = |
| 4621 | VectorFromIndices(kOfferAnswerCodecs, kResultRecv_SendCodecs); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4622 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4623 | case RtpTransceiverDirection::kSendRecv: |
| 4624 | if (acd->direction() == RtpTransceiverDirection::kSendOnly) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4625 | target_codecs = |
| 4626 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_SendCodecs); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4627 | } else if (acd->direction() == RtpTransceiverDirection::kRecvOnly) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4628 | target_codecs = |
| 4629 | VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_RecvCodecs); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4630 | } else { |
| 4631 | target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 4632 | kResultSendrecv_SendrecvCodecs); |
| 4633 | } |
| 4634 | break; |
Harald Alvestrand | 6060df5 | 2020-08-11 07:54:02 | [diff] [blame] | 4635 | case RtpTransceiverDirection::kStopped: |
| 4636 | // This does not happen in any current test. |
Artem Titov | d325196 | 2021-11-15 15:57:07 | [diff] [blame] | 4637 | RTC_DCHECK_NOTREACHED(); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4638 | } |
| 4639 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4640 | auto format_codecs = [](const std::vector<AudioCodec>& codecs) { |
Jonas Olsson | 366a50c | 2018-09-06 11:41:30 | [diff] [blame] | 4641 | rtc::StringBuilder os; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4642 | bool first = true; |
| 4643 | os << "{"; |
| 4644 | for (const auto& c : codecs) { |
| 4645 | os << (first ? " " : ", ") << c.id; |
| 4646 | first = false; |
| 4647 | } |
| 4648 | os << " }"; |
Jonas Olsson | 84df1c7 | 2018-09-14 14:59:32 | [diff] [blame] | 4649 | return os.Release(); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4650 | }; |
| 4651 | |
| 4652 | EXPECT_TRUE(acd->codecs() == target_codecs) |
| 4653 | << "Expected: " << format_codecs(target_codecs) |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4654 | << ", got: " << format_codecs(acd->codecs()) << "; Offered: " |
| 4655 | << webrtc::RtpTransceiverDirectionToString(offer_direction) |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4656 | << ", answerer wants: " |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4657 | << webrtc::RtpTransceiverDirectionToString(answer_direction) |
| 4658 | << "; got: " |
| 4659 | << webrtc::RtpTransceiverDirectionToString(acd->direction()); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4660 | } else { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 4661 | EXPECT_EQ(offer_direction, RtpTransceiverDirection::kInactive) |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4662 | << "Only inactive offers are allowed to not generate any audio " |
| 4663 | "content"; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4664 | } |
| 4665 | } |
brandtr | 03d5fb1 | 2016-11-22 11:37:59 | [diff] [blame] | 4666 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4667 | using AudioCodecsOfferTest = testing::TestWithParam<RtpTransceiverDirection>; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4668 | |
| 4669 | TEST_P(AudioCodecsOfferTest, TestCodecsInOffer) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 4670 | TestAudioCodecsOffer(GetParam()); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4671 | } |
| 4672 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 4673 | INSTANTIATE_TEST_SUITE_P(MediaSessionDescriptionFactoryTest, |
| 4674 | AudioCodecsOfferTest, |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4675 | Values(RtpTransceiverDirection::kSendOnly, |
| 4676 | RtpTransceiverDirection::kRecvOnly, |
| 4677 | RtpTransceiverDirection::kSendRecv, |
| 4678 | RtpTransceiverDirection::kInactive)); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4679 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4680 | using AudioCodecsAnswerTest = testing::TestWithParam< |
| 4681 | std::tuple<RtpTransceiverDirection, RtpTransceiverDirection, bool>>; |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4682 | |
| 4683 | TEST_P(AudioCodecsAnswerTest, TestCodecsInAnswer) { |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4684 | TestAudioCodecsAnswer(std::get<0>(GetParam()), std::get<1>(GetParam()), |
| 4685 | std::get<2>(GetParam())); |
ossu | 075af92 | 2016-06-14 10:29:38 | [diff] [blame] | 4686 | } |
| 4687 | |
Emil Lundmark | 7d2e616 | 2023-11-08 15:27:45 | [diff] [blame] | 4688 | INSTANTIATE_TEST_SUITE_P(MediaSessionDescriptionFactoryTest, |
| 4689 | AudioCodecsAnswerTest, |
| 4690 | Combine(Values(RtpTransceiverDirection::kSendOnly, |
| 4691 | RtpTransceiverDirection::kRecvOnly, |
| 4692 | RtpTransceiverDirection::kSendRecv, |
| 4693 | RtpTransceiverDirection::kInactive), |
| 4694 | Values(RtpTransceiverDirection::kSendOnly, |
| 4695 | RtpTransceiverDirection::kRecvOnly, |
| 4696 | RtpTransceiverDirection::kSendRecv, |
| 4697 | RtpTransceiverDirection::kInactive), |
| 4698 | Bool())); |
| 4699 | |
| 4700 | } // namespace |
| 4701 | } // namespace cricket |