henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [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 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 14 | #include <cstdint> |
| 15 | #include <map> |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 16 | #include <memory> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 17 | #include <sstream> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 18 | #include <string> |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 19 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 22 | #include "absl/algorithm/container.h" |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 19:14:05 | [diff] [blame] | 23 | #include "absl/memory/memory.h" |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 24 | #include "absl/strings/str_replace.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 25 | #include "absl/strings/string_view.h" |
| 26 | #include "absl/types/optional.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 27 | #include "api/array_view.h" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 28 | #include "api/crypto_params.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 29 | #include "api/jsep_session_description.h" |
| 30 | #include "api/media_types.h" |
| 31 | #include "api/rtp_parameters.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 32 | #include "api/rtp_transceiver_direction.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 33 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 34 | #include "media/base/media_constants.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 35 | #include "media/base/rid_description.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 36 | #include "media/base/stream_params.h" |
| 37 | #include "p2p/base/p2p_constants.h" |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 38 | #include "p2p/base/port.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 39 | #include "p2p/base/transport_description.h" |
| 40 | #include "p2p/base/transport_info.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 41 | #include "pc/media_protocol_names.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 42 | #include "pc/media_session.h" |
| 43 | #include "pc/session_description.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 44 | #include "pc/simulcast_description.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 45 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 46 | #include "rtc_base/message_digest.h" |
| 47 | #include "rtc_base/socket_address.h" |
| 48 | #include "rtc_base/ssl_fingerprint.h" |
| 49 | #include "rtc_base/string_encode.h" |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 50 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 51 | #include "test/gtest.h" |
Patrik Höglund | 563934e | 2017-09-15 07:04:28 | [diff] [blame] | 52 | |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 53 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 54 | #include "pc/test/android_test_initializer.h" |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 55 | #endif |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 56 | #include "pc/webrtc_sdp.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 57 | |
| 58 | using cricket::AudioCodec; |
| 59 | using cricket::AudioContentDescription; |
| 60 | using cricket::Candidate; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 61 | using cricket::ContentGroup; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 62 | using cricket::ContentInfo; |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 63 | using cricket::CryptoParams; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 64 | using cricket::ICE_CANDIDATE_COMPONENT_RTCP; |
| 65 | using cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 66 | using cricket::kFecSsrcGroupSemantics; |
| 67 | using cricket::LOCAL_PORT_TYPE; |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 68 | using cricket::MediaProtocolType; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 69 | using cricket::RELAY_PORT_TYPE; |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 70 | using cricket::RidDescription; |
| 71 | using cricket::RidDirection; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 72 | using cricket::SctpDataContentDescription; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 73 | using cricket::SessionDescription; |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 74 | using cricket::SimulcastDescription; |
| 75 | using cricket::SimulcastLayer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 76 | using cricket::StreamParams; |
| 77 | using cricket::STUN_PORT_TYPE; |
| 78 | using cricket::TransportDescription; |
| 79 | using cricket::TransportInfo; |
| 80 | using cricket::VideoCodec; |
| 81 | using cricket::VideoContentDescription; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 82 | using ::testing::ElementsAre; |
| 83 | using ::testing::Field; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 84 | using webrtc::IceCandidateCollection; |
| 85 | using webrtc::IceCandidateInterface; |
| 86 | using webrtc::JsepIceCandidate; |
| 87 | using webrtc::JsepSessionDescription; |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 88 | using webrtc::RtpExtension; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 89 | using webrtc::RtpTransceiverDirection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 90 | using webrtc::SdpParseError; |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 91 | using webrtc::SdpType; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 92 | using webrtc::SessionDescriptionInterface; |
| 93 | |
| 94 | typedef std::vector<AudioCodec> AudioCodecs; |
| 95 | typedef std::vector<Candidate> Candidates; |
| 96 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 97 | static const uint32_t kDefaultSctpPort = 5000; |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 98 | static const uint16_t kUnusualSctpPort = 9556; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 99 | static const char kSessionTime[] = "t=0 0\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 100 | static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 101 | static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 102 | static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 103 | static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 104 | static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 105 | static const uint32_t kCandidateGeneration = 2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 106 | static const char kCandidateFoundation1[] = "a0+B/1"; |
| 107 | static const char kCandidateFoundation2[] = "a0+B/2"; |
| 108 | static const char kCandidateFoundation3[] = "a0+B/3"; |
| 109 | static const char kCandidateFoundation4[] = "a0+B/4"; |
| 110 | static const char kAttributeCryptoVoice[] = |
| 111 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 112 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 113 | "dummy_session_params\r\n"; |
| 114 | static const char kAttributeCryptoVideo[] = |
| 115 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 116 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 117 | static const char kFingerprint[] = |
| 118 | "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 119 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"; |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 120 | static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 121 | static const int kExtmapId = 1; |
| 122 | static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime"; |
| 123 | static const char kExtmap[] = |
| 124 | "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n"; |
| 125 | static const char kExtmapWithDirectionAndAttribute[] = |
| 126 | "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n"; |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 127 | static const char kExtmapWithDirectionAndAttributeEncrypted[] = |
| 128 | "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt " |
| 129 | "http://example.com/082005/ext.htm#ttime a1 a2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 130 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 131 | static const uint8_t kIdentityDigest[] = { |
| 132 | 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02, |
| 133 | 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 134 | |
lally@webrtc.org | 3480728 | 2015-02-24 20:19:39 | [diff] [blame] | 135 | static const char kDtlsSctp[] = "DTLS/SCTP"; |
| 136 | static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; |
| 137 | static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 138 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 139 | struct CodecParams { |
| 140 | int max_ptime; |
| 141 | int ptime; |
| 142 | int min_ptime; |
| 143 | int sprop_stereo; |
| 144 | int stereo; |
| 145 | int useinband; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 | [diff] [blame] | 146 | int maxaveragebitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 147 | }; |
| 148 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 149 | // TODO(deadbeef): In these reference strings, use "a=fingerprint" by default |
| 150 | // instead of "a=crypto", and have an explicit test for adding "a=crypto". |
| 151 | // Currently it's the other way around. |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 152 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 153 | // Reference sdp string |
| 154 | static const char kSdpFullString[] = |
| 155 | "v=0\r\n" |
| 156 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 157 | "s=-\r\n" |
| 158 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 159 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 160 | "a=msid-semantic: WMS local_stream_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 161 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 162 | "c=IN IP4 74.125.127.126\r\n" |
| 163 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 164 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 165 | "generation 2\r\n" |
| 166 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 167 | "generation 2\r\n" |
| 168 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 169 | "generation 2\r\n" |
| 170 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 171 | "generation 2\r\n" |
| 172 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 173 | "raddr 192.168.1.5 rport 2346 " |
| 174 | "generation 2\r\n" |
| 175 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 176 | "raddr 192.168.1.5 rport 2348 " |
| 177 | "generation 2\r\n" |
| 178 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 179 | "a=mid:audio_content_name\r\n" |
| 180 | "a=sendrecv\r\n" |
| 181 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 182 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 183 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 184 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 185 | "dummy_session_params\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 186 | "a=rtpmap:111 opus/48000/2\r\n" |
| 187 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 188 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 189 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 190 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 191 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 192 | "c=IN IP4 74.125.224.39\r\n" |
| 193 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 194 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 195 | "generation 2\r\n" |
| 196 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 197 | "generation 2\r\n" |
| 198 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 199 | "generation 2\r\n" |
| 200 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 201 | "generation 2\r\n" |
| 202 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 203 | "generation 2\r\n" |
| 204 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 205 | "generation 2\r\n" |
| 206 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 207 | "a=mid:video_content_name\r\n" |
| 208 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 209 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 210 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 211 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 212 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 213 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 214 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 215 | "a=ssrc:3 cname:stream_1_cname\r\n" |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 216 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 217 | |
| 218 | // SDP reference string without the candidates. |
| 219 | static const char kSdpString[] = |
| 220 | "v=0\r\n" |
| 221 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 222 | "s=-\r\n" |
| 223 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 224 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 225 | "a=msid-semantic: WMS local_stream_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 226 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 227 | "c=IN IP4 0.0.0.0\r\n" |
| 228 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 229 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 230 | "a=mid:audio_content_name\r\n" |
| 231 | "a=sendrecv\r\n" |
| 232 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 233 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 234 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 235 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 236 | "dummy_session_params\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 237 | "a=rtpmap:111 opus/48000/2\r\n" |
| 238 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 239 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 240 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 241 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 242 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 243 | "c=IN IP4 0.0.0.0\r\n" |
| 244 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 245 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 246 | "a=mid:video_content_name\r\n" |
| 247 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 248 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 249 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 250 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 251 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 252 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 253 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 254 | "a=ssrc:3 cname:stream_1_cname\r\n" |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 255 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 256 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 257 | // draft-ietf-mmusic-sctp-sdp-03 |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 258 | static const char kSdpSctpDataChannelString[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 259 | "m=application 9 UDP/DTLS/SCTP 5000\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 260 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 261 | "a=ice-ufrag:ufrag_data\r\n" |
| 262 | "a=ice-pwd:pwd_data\r\n" |
| 263 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 | [diff] [blame] | 264 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 265 | |
lally@webrtc.org | ec97c65 | 2015-02-24 20:18:48 | [diff] [blame] | 266 | // draft-ietf-mmusic-sctp-sdp-12 |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 267 | // Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26, |
| 268 | // since the separator after "sctp-port" needs to be a colon. |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 269 | static const char kSdpSctpDataChannelStringWithSctpPort[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 270 | "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n" |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 | [diff] [blame] | 271 | "a=sctp-port 5000\r\n" |
| 272 | "c=IN IP4 0.0.0.0\r\n" |
| 273 | "a=ice-ufrag:ufrag_data\r\n" |
| 274 | "a=ice-pwd:pwd_data\r\n" |
| 275 | "a=mid:data_content_name\r\n"; |
| 276 | |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 277 | // draft-ietf-mmusic-sctp-sdp-26 |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 278 | static const char kSdpSctpDataChannelStringWithSctpColonPort[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 279 | "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n" |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 280 | "a=sctp-port:5000\r\n" |
| 281 | "c=IN IP4 0.0.0.0\r\n" |
| 282 | "a=ice-ufrag:ufrag_data\r\n" |
| 283 | "a=ice-pwd:pwd_data\r\n" |
| 284 | "a=mid:data_content_name\r\n"; |
| 285 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 286 | static const char kSdpSctpDataChannelWithCandidatesString[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 287 | "m=application 2345 UDP/DTLS/SCTP 5000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 288 | "c=IN IP4 74.125.127.126\r\n" |
| 289 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 290 | "generation 2\r\n" |
| 291 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 292 | "generation 2\r\n" |
| 293 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 294 | "raddr 192.168.1.5 rport 2346 " |
| 295 | "generation 2\r\n" |
| 296 | "a=ice-ufrag:ufrag_data\r\n" |
| 297 | "a=ice-pwd:pwd_data\r\n" |
| 298 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 | [diff] [blame] | 299 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 300 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 301 | static const char kSdpConferenceString[] = |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 302 | "v=0\r\n" |
| 303 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 304 | "s=-\r\n" |
| 305 | "t=0 0\r\n" |
| 306 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 307 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 308 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 309 | "a=x-google-flag:conference\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 310 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 311 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 312 | "a=x-google-flag:conference\r\n"; |
| 313 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 314 | static const char kSdpSessionString[] = |
| 315 | "v=0\r\n" |
| 316 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 317 | "s=-\r\n" |
| 318 | "t=0 0\r\n" |
| 319 | "a=msid-semantic: WMS local_stream\r\n"; |
| 320 | |
| 321 | static const char kSdpAudioString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 322 | "m=audio 9 RTP/SAVPF 111\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 323 | "c=IN IP4 0.0.0.0\r\n" |
| 324 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 325 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 326 | "a=mid:audio_content_name\r\n" |
| 327 | "a=sendrecv\r\n" |
| 328 | "a=rtpmap:111 opus/48000/2\r\n" |
| 329 | "a=ssrc:1 cname:stream_1_cname\r\n" |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 330 | "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 331 | |
| 332 | static const char kSdpVideoString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 333 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 334 | "c=IN IP4 0.0.0.0\r\n" |
| 335 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 336 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 337 | "a=mid:video_content_name\r\n" |
| 338 | "a=sendrecv\r\n" |
| 339 | "a=rtpmap:120 VP8/90000\r\n" |
| 340 | "a=ssrc:2 cname:stream_1_cname\r\n" |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 341 | "a=ssrc:2 msid:local_stream video_track_id_1\r\n"; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 342 | |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 343 | // Reference sdp string using bundle-only. |
| 344 | static const char kBundleOnlySdpFullString[] = |
| 345 | "v=0\r\n" |
| 346 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 347 | "s=-\r\n" |
| 348 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 349 | "a=extmap-allow-mixed\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 350 | "a=group:BUNDLE audio_content_name video_content_name\r\n" |
| 351 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 352 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 353 | "c=IN IP4 74.125.127.126\r\n" |
| 354 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 355 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 356 | "generation 2\r\n" |
| 357 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 358 | "generation 2\r\n" |
| 359 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 360 | "generation 2\r\n" |
| 361 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 362 | "generation 2\r\n" |
| 363 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 364 | "raddr 192.168.1.5 rport 2346 " |
| 365 | "generation 2\r\n" |
| 366 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 367 | "raddr 192.168.1.5 rport 2348 " |
| 368 | "generation 2\r\n" |
| 369 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 370 | "a=mid:audio_content_name\r\n" |
| 371 | "a=sendrecv\r\n" |
| 372 | "a=rtcp-mux\r\n" |
| 373 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 374 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 375 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 376 | "dummy_session_params\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 377 | "a=rtpmap:111 opus/48000/2\r\n" |
| 378 | "a=rtpmap:103 ISAC/16000\r\n" |
| 379 | "a=rtpmap:104 ISAC/32000\r\n" |
| 380 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 381 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 382 | "m=video 0 RTP/SAVPF 120\r\n" |
| 383 | "c=IN IP4 0.0.0.0\r\n" |
| 384 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 385 | "a=bundle-only\r\n" |
| 386 | "a=mid:video_content_name\r\n" |
| 387 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 388 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 389 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 390 | "a=rtpmap:120 VP8/90000\r\n" |
| 391 | "a=ssrc-group:FEC 2 3\r\n" |
| 392 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 393 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 394 | "a=ssrc:3 cname:stream_1_cname\r\n" |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 395 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"; |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 396 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 397 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 398 | // tracks. |
| 399 | static const char kPlanBSdpFullString[] = |
| 400 | "v=0\r\n" |
| 401 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 402 | "s=-\r\n" |
| 403 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 404 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 405 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 406 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 407 | "c=IN IP4 74.125.127.126\r\n" |
| 408 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 409 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 410 | "generation 2\r\n" |
| 411 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 412 | "generation 2\r\n" |
| 413 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 414 | "generation 2\r\n" |
| 415 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 416 | "generation 2\r\n" |
| 417 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 418 | "raddr 192.168.1.5 rport 2346 " |
| 419 | "generation 2\r\n" |
| 420 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 421 | "raddr 192.168.1.5 rport 2348 " |
| 422 | "generation 2\r\n" |
| 423 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 424 | "a=mid:audio_content_name\r\n" |
| 425 | "a=sendrecv\r\n" |
| 426 | "a=rtcp-mux\r\n" |
| 427 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 428 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 429 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 430 | "dummy_session_params\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 431 | "a=rtpmap:111 opus/48000/2\r\n" |
| 432 | "a=rtpmap:103 ISAC/16000\r\n" |
| 433 | "a=rtpmap:104 ISAC/32000\r\n" |
| 434 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 435 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 436 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 437 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 438 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 439 | "c=IN IP4 74.125.224.39\r\n" |
| 440 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 441 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 442 | "generation 2\r\n" |
| 443 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 444 | "generation 2\r\n" |
| 445 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 446 | "generation 2\r\n" |
| 447 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 448 | "generation 2\r\n" |
| 449 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 450 | "generation 2\r\n" |
| 451 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 452 | "generation 2\r\n" |
| 453 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 454 | "a=mid:video_content_name\r\n" |
| 455 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 456 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 457 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 458 | "a=rtpmap:120 VP8/90000\r\n" |
| 459 | "a=ssrc-group:FEC 2 3\r\n" |
| 460 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 461 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 462 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 463 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 464 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 465 | "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 466 | "a=ssrc:6 cname:stream_2_cname\r\n" |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 467 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 468 | |
| 469 | // Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 470 | // tracks. |
| 471 | static const char kUnifiedPlanSdpFullString[] = |
| 472 | "v=0\r\n" |
| 473 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 474 | "s=-\r\n" |
| 475 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 476 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 477 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 478 | // Audio track 1, stream 1 (with candidates). |
| 479 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 480 | "c=IN IP4 74.125.127.126\r\n" |
| 481 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 482 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 483 | "generation 2\r\n" |
| 484 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 485 | "generation 2\r\n" |
| 486 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 487 | "generation 2\r\n" |
| 488 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 489 | "generation 2\r\n" |
| 490 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 491 | "raddr 192.168.1.5 rport 2346 " |
| 492 | "generation 2\r\n" |
| 493 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 494 | "raddr 192.168.1.5 rport 2348 " |
| 495 | "generation 2\r\n" |
| 496 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 497 | "a=mid:audio_content_name\r\n" |
| 498 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 499 | "a=sendrecv\r\n" |
| 500 | "a=rtcp-mux\r\n" |
| 501 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 502 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 503 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 504 | "dummy_session_params\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 505 | "a=rtpmap:111 opus/48000/2\r\n" |
| 506 | "a=rtpmap:103 ISAC/16000\r\n" |
| 507 | "a=rtpmap:104 ISAC/32000\r\n" |
| 508 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 509 | // Video track 1, stream 1 (with candidates). |
| 510 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 511 | "c=IN IP4 74.125.224.39\r\n" |
| 512 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 513 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 514 | "generation 2\r\n" |
| 515 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 516 | "generation 2\r\n" |
| 517 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 518 | "generation 2\r\n" |
| 519 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 520 | "generation 2\r\n" |
| 521 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 522 | "generation 2\r\n" |
| 523 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 524 | "generation 2\r\n" |
| 525 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 526 | "a=mid:video_content_name\r\n" |
| 527 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 528 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 529 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 530 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 531 | "a=rtpmap:120 VP8/90000\r\n" |
| 532 | "a=ssrc-group:FEC 2 3\r\n" |
| 533 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 534 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 535 | // Audio track 2, stream 2. |
| 536 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 537 | "c=IN IP4 0.0.0.0\r\n" |
| 538 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 539 | "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 540 | "a=mid:audio_content_name_2\r\n" |
| 541 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
| 542 | "a=sendrecv\r\n" |
| 543 | "a=rtcp-mux\r\n" |
| 544 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 545 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 546 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 547 | "dummy_session_params\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 548 | "a=rtpmap:111 opus/48000/2\r\n" |
| 549 | "a=rtpmap:103 ISAC/16000\r\n" |
| 550 | "a=rtpmap:104 ISAC/32000\r\n" |
| 551 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 552 | // Video track 2, stream 2. |
| 553 | "m=video 9 RTP/SAVPF 120\r\n" |
| 554 | "c=IN IP4 0.0.0.0\r\n" |
| 555 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 556 | "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n" |
| 557 | "a=mid:video_content_name_2\r\n" |
| 558 | "a=msid:local_stream_2 video_track_id_2\r\n" |
| 559 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 560 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 561 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 562 | "a=rtpmap:120 VP8/90000\r\n" |
| 563 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 564 | // Video track 3, stream 2. |
| 565 | "m=video 9 RTP/SAVPF 120\r\n" |
| 566 | "c=IN IP4 0.0.0.0\r\n" |
| 567 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 568 | "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n" |
| 569 | "a=mid:video_content_name_3\r\n" |
| 570 | "a=msid:local_stream_2 video_track_id_3\r\n" |
| 571 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 572 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 573 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 574 | "a=rtpmap:120 VP8/90000\r\n" |
| 575 | "a=ssrc:6 cname:stream_2_cname\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 576 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 577 | // Unified Plan SDP reference string: |
| 578 | // - audio track 1 has 1 a=msid lines |
| 579 | // - audio track 2 has 2 a=msid lines |
| 580 | // - audio track 3 has 1 a=msid line with the special "-" marker signifying that |
| 581 | // there are 0 media stream ids. |
| 582 | // This Unified Plan SDP represents a SDP that signals the msid using both |
| 583 | // a=msid and a=ssrc msid semantics. |
| 584 | static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] = |
| 585 | "v=0\r\n" |
| 586 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 587 | "s=-\r\n" |
| 588 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 589 | "a=extmap-allow-mixed\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 590 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 591 | // Audio track 1, with 1 stream id. |
| 592 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 593 | "c=IN IP4 74.125.127.126\r\n" |
| 594 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 595 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 596 | "generation 2\r\n" |
| 597 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 598 | "generation 2\r\n" |
| 599 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 600 | "generation 2\r\n" |
| 601 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 602 | "generation 2\r\n" |
| 603 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 604 | "raddr 192.168.1.5 rport 2346 " |
| 605 | "generation 2\r\n" |
| 606 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 607 | "raddr 192.168.1.5 rport 2348 " |
| 608 | "generation 2\r\n" |
| 609 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 610 | "a=mid:audio_content_name\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 611 | "a=sendrecv\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 612 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 613 | "a=rtcp-mux\r\n" |
| 614 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 615 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 616 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 617 | "dummy_session_params\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 618 | "a=rtpmap:111 opus/48000/2\r\n" |
| 619 | "a=rtpmap:103 ISAC/16000\r\n" |
| 620 | "a=rtpmap:104 ISAC/32000\r\n" |
| 621 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 622 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 623 | // Audio track 2, with two stream ids. |
| 624 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 625 | "c=IN IP4 0.0.0.0\r\n" |
| 626 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 627 | "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 628 | "a=mid:audio_content_name_2\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 629 | "a=sendrecv\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 630 | "a=msid:local_stream_1 audio_track_id_2\r\n" |
| 631 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 632 | "a=rtcp-mux\r\n" |
| 633 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 634 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 635 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 636 | "dummy_session_params\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 637 | "a=rtpmap:111 opus/48000/2\r\n" |
| 638 | "a=rtpmap:103 ISAC/16000\r\n" |
| 639 | "a=rtpmap:104 ISAC/32000\r\n" |
| 640 | "a=ssrc:4 cname:stream_1_cname\r\n" |
| 641 | // The support for Plan B msid signaling only includes the |
| 642 | // first media stream id "local_stream_1." |
| 643 | "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 644 | // Audio track 3, with no stream ids. |
| 645 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 646 | "c=IN IP4 0.0.0.0\r\n" |
| 647 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 648 | "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n" |
| 649 | "a=mid:audio_content_name_3\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 650 | "a=sendrecv\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 651 | "a=msid:- audio_track_id_3\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 652 | "a=rtcp-mux\r\n" |
| 653 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 654 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 655 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 656 | "dummy_session_params\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 657 | "a=rtpmap:111 opus/48000/2\r\n" |
| 658 | "a=rtpmap:103 ISAC/16000\r\n" |
| 659 | "a=rtpmap:104 ISAC/32000\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 660 | "a=ssrc:7 cname:stream_2_cname\r\n" |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 661 | "a=ssrc:7 msid:- audio_track_id_3\r\n"; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 662 | |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 663 | // SDP string for unified plan without SSRCs |
| 664 | static const char kUnifiedPlanSdpFullStringNoSsrc[] = |
| 665 | "v=0\r\n" |
| 666 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 667 | "s=-\r\n" |
| 668 | "t=0 0\r\n" |
| 669 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 670 | // Audio track 1, stream 1 (with candidates). |
| 671 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 672 | "c=IN IP4 74.125.127.126\r\n" |
| 673 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 674 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 675 | "generation 2\r\n" |
| 676 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 677 | "generation 2\r\n" |
| 678 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 679 | "generation 2\r\n" |
| 680 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 681 | "generation 2\r\n" |
| 682 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 683 | "raddr 192.168.1.5 rport 2346 " |
| 684 | "generation 2\r\n" |
| 685 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 686 | "raddr 192.168.1.5 rport 2348 " |
| 687 | "generation 2\r\n" |
| 688 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 689 | "a=mid:audio_content_name\r\n" |
| 690 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 691 | "a=sendrecv\r\n" |
| 692 | "a=rtcp-mux\r\n" |
| 693 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 694 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 695 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 696 | "dummy_session_params\r\n" |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 697 | "a=rtpmap:111 opus/48000/2\r\n" |
| 698 | "a=rtpmap:103 ISAC/16000\r\n" |
| 699 | "a=rtpmap:104 ISAC/32000\r\n" |
| 700 | // Video track 1, stream 1 (with candidates). |
| 701 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 702 | "c=IN IP4 74.125.224.39\r\n" |
| 703 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 704 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 705 | "generation 2\r\n" |
| 706 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 707 | "generation 2\r\n" |
| 708 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 709 | "generation 2\r\n" |
| 710 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 711 | "generation 2\r\n" |
| 712 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 713 | "generation 2\r\n" |
| 714 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 715 | "generation 2\r\n" |
| 716 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 717 | "a=mid:video_content_name\r\n" |
| 718 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 719 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 720 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 721 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 722 | "a=rtpmap:120 VP8/90000\r\n" |
| 723 | // Audio track 2, stream 2. |
| 724 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 725 | "c=IN IP4 0.0.0.0\r\n" |
| 726 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 727 | "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 728 | "a=mid:audio_content_name_2\r\n" |
| 729 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
| 730 | "a=sendrecv\r\n" |
| 731 | "a=rtcp-mux\r\n" |
| 732 | "a=rtcp-rsize\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 733 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 734 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 735 | "dummy_session_params\r\n" |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 736 | "a=rtpmap:111 opus/48000/2\r\n" |
| 737 | "a=rtpmap:103 ISAC/16000\r\n" |
| 738 | "a=rtpmap:104 ISAC/32000\r\n" |
| 739 | // Video track 2, stream 2. |
| 740 | "m=video 9 RTP/SAVPF 120\r\n" |
| 741 | "c=IN IP4 0.0.0.0\r\n" |
| 742 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 743 | "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n" |
| 744 | "a=mid:video_content_name_2\r\n" |
| 745 | "a=msid:local_stream_2 video_track_id_2\r\n" |
| 746 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 747 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 748 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 749 | "a=rtpmap:120 VP8/90000\r\n" |
| 750 | // Video track 3, stream 2. |
| 751 | "m=video 9 RTP/SAVPF 120\r\n" |
| 752 | "c=IN IP4 0.0.0.0\r\n" |
| 753 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 754 | "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n" |
| 755 | "a=mid:video_content_name_3\r\n" |
| 756 | "a=msid:local_stream_2 video_track_id_3\r\n" |
| 757 | "a=sendrecv\r\n" |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 758 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 759 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 760 | "a=rtpmap:120 VP8/90000\r\n"; |
| 761 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 762 | // One candidate reference string as per W3c spec. |
| 763 | // candidate:<blah> not a=candidate:<blah>CRLF |
| 764 | static const char kRawCandidate[] = |
| 765 | "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2"; |
| 766 | // One candidate reference string. |
| 767 | static const char kSdpOneCandidate[] = |
| 768 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 769 | "generation 2\r\n"; |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 770 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 771 | static const char kSdpTcpActiveCandidate[] = |
| 772 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 773 | "tcptype active generation 2"; |
| 774 | static const char kSdpTcpPassiveCandidate[] = |
| 775 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 776 | "tcptype passive generation 2"; |
| 777 | static const char kSdpTcpSOCandidate[] = |
| 778 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 779 | "tcptype so generation 2"; |
| 780 | static const char kSdpTcpInvalidCandidate[] = |
| 781 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 782 | "tcptype invalid generation 2"; |
| 783 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 784 | // One candidate reference string with IPV6 address. |
| 785 | static const char kRawIPV6Candidate[] = |
| 786 | "candidate:a0+B/1 1 udp 2130706432 " |
ehmaldonado | 121cabb | 2017-05-05 19:04:36 | [diff] [blame] | 787 | "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 788 | |
| 789 | // One candidate reference string. |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 790 | static const char kSdpOneCandidateWithUfragPwd[] = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 791 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name" |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 792 | " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 793 | |
Zach Stein | b336c27 | 2018-08-09 08:16:13 | [diff] [blame] | 794 | static const char kRawHostnameCandidate[] = |
| 795 | "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2"; |
| 796 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 797 | // Session id and version |
| 798 | static const char kSessionId[] = "18446744069414584320"; |
| 799 | static const char kSessionVersion[] = "18446462598732840960"; |
| 800 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 801 | // ICE options. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 802 | static const char kIceOption1[] = "iceoption1"; |
| 803 | static const char kIceOption2[] = "iceoption2"; |
| 804 | static const char kIceOption3[] = "iceoption3"; |
| 805 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 806 | // ICE ufrags/passwords. |
| 807 | static const char kUfragVoice[] = "ufrag_voice"; |
| 808 | static const char kPwdVoice[] = "pwd_voice"; |
| 809 | static const char kUfragVideo[] = "ufrag_video"; |
| 810 | static const char kPwdVideo[] = "pwd_video"; |
| 811 | static const char kUfragData[] = "ufrag_data"; |
| 812 | static const char kPwdData[] = "pwd_data"; |
| 813 | |
| 814 | // Extra ufrags/passwords for extra unified plan m= sections. |
| 815 | static const char kUfragVoice2[] = "ufrag_voice_2"; |
| 816 | static const char kPwdVoice2[] = "pwd_voice_2"; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 817 | static const char kUfragVoice3[] = "ufrag_voice_3"; |
| 818 | static const char kPwdVoice3[] = "pwd_voice_3"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 819 | static const char kUfragVideo2[] = "ufrag_video_2"; |
| 820 | static const char kPwdVideo2[] = "pwd_video_2"; |
| 821 | static const char kUfragVideo3[] = "ufrag_video_3"; |
| 822 | static const char kPwdVideo3[] = "pwd_video_3"; |
| 823 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 824 | // Content name |
| 825 | static const char kAudioContentName[] = "audio_content_name"; |
| 826 | static const char kVideoContentName[] = "video_content_name"; |
| 827 | static const char kDataContentName[] = "data_content_name"; |
| 828 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 829 | // Extra content names for extra unified plan m= sections. |
| 830 | static const char kAudioContentName2[] = "audio_content_name_2"; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 831 | static const char kAudioContentName3[] = "audio_content_name_3"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 832 | static const char kVideoContentName2[] = "video_content_name_2"; |
| 833 | static const char kVideoContentName3[] = "video_content_name_3"; |
| 834 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 835 | // MediaStream 1 |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 836 | static const char kStreamId1[] = "local_stream_1"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 837 | static const char kStream1Cname[] = "stream_1_cname"; |
| 838 | static const char kAudioTrackId1[] = "audio_track_id_1"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 839 | static const uint32_t kAudioTrack1Ssrc = 1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 840 | static const char kVideoTrackId1[] = "video_track_id_1"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 841 | static const uint32_t kVideoTrack1Ssrc1 = 2; |
| 842 | static const uint32_t kVideoTrack1Ssrc2 = 3; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 843 | |
| 844 | // MediaStream 2 |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 845 | static const char kStreamId2[] = "local_stream_2"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 846 | static const char kStream2Cname[] = "stream_2_cname"; |
| 847 | static const char kAudioTrackId2[] = "audio_track_id_2"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 848 | static const uint32_t kAudioTrack2Ssrc = 4; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 849 | static const char kVideoTrackId2[] = "video_track_id_2"; |
| 850 | static const uint32_t kVideoTrack2Ssrc = 5; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 851 | static const char kVideoTrackId3[] = "video_track_id_3"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 852 | static const uint32_t kVideoTrack3Ssrc = 6; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 853 | static const char kAudioTrackId3[] = "audio_track_id_3"; |
| 854 | static const uint32_t kAudioTrack3Ssrc = 7; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 855 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 856 | // Candidate |
| 857 | static const char kDummyMid[] = "dummy_mid"; |
| 858 | static const int kDummyIndex = 123; |
| 859 | |
| 860 | // Misc |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 861 | static SdpType kDummyType = SdpType::kOffer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 862 | |
| 863 | // Helper functions |
| 864 | |
| 865 | static bool SdpDeserialize(const std::string& message, |
| 866 | JsepSessionDescription* jdesc) { |
| 867 | return webrtc::SdpDeserialize(message, jdesc, NULL); |
| 868 | } |
| 869 | |
| 870 | static bool SdpDeserializeCandidate(const std::string& message, |
| 871 | JsepIceCandidate* candidate) { |
| 872 | return webrtc::SdpDeserializeCandidate(message, candidate, NULL); |
| 873 | } |
| 874 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 875 | // Add some extra `newlines` to the `message` after `line`. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 876 | static void InjectAfter(const std::string& line, |
| 877 | const std::string& newlines, |
| 878 | std::string* message) { |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 879 | absl::StrReplaceAll({{line, line + newlines}}, message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | static void Replace(const std::string& line, |
| 883 | const std::string& newlines, |
| 884 | std::string* message) { |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 885 | absl::StrReplaceAll({{line, newlines}}, message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 886 | } |
| 887 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 888 | // Expect a parse failure on the line containing `bad_part` when attempting to |
| 889 | // parse `bad_sdp`. |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 890 | static void ExpectParseFailure(const std::string& bad_sdp, |
| 891 | const std::string& bad_part) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 892 | JsepSessionDescription desc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 893 | SdpParseError error; |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 894 | bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error); |
Harald Alvestrand | 99bcf60 | 2021-03-03 07:44:39 | [diff] [blame] | 895 | ASSERT_FALSE(ret); |
| 896 | EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str())) |
| 897 | << "Did not find " << bad_part << " in " << error.line; |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 898 | } |
| 899 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 900 | // Expect fail to parse kSdpFullString if replace `good_part` with `bad_part`. |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 901 | static void ExpectParseFailure(const char* good_part, const char* bad_part) { |
| 902 | std::string bad_sdp = kSdpFullString; |
| 903 | Replace(good_part, bad_part, &bad_sdp); |
| 904 | ExpectParseFailure(bad_sdp, bad_part); |
| 905 | } |
| 906 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 907 | // Expect fail to parse kSdpFullString if add `newlines` after `injectpoint`. |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 908 | static void ExpectParseFailureWithNewLines(const std::string& injectpoint, |
| 909 | const std::string& newlines, |
| 910 | const std::string& bad_part) { |
| 911 | std::string bad_sdp = kSdpFullString; |
| 912 | InjectAfter(injectpoint, newlines, &bad_sdp); |
| 913 | ExpectParseFailure(bad_sdp, bad_part); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 914 | } |
| 915 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 916 | static void ReplaceDirection(RtpTransceiverDirection direction, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 917 | std::string* message) { |
| 918 | std::string new_direction; |
| 919 | switch (direction) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 920 | case RtpTransceiverDirection::kInactive: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 921 | new_direction = "a=inactive"; |
| 922 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 923 | case RtpTransceiverDirection::kSendOnly: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 924 | new_direction = "a=sendonly"; |
| 925 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 926 | case RtpTransceiverDirection::kRecvOnly: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 927 | new_direction = "a=recvonly"; |
| 928 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 929 | case RtpTransceiverDirection::kSendRecv: |
Markus Handell | 45c104b | 2020-03-11 09:51:13 | [diff] [blame] | 930 | new_direction = "a=sendrecv"; |
| 931 | break; |
| 932 | case RtpTransceiverDirection::kStopped: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 933 | default: |
Artem Titov | d325196 | 2021-11-15 15:57:07 | [diff] [blame] | 934 | RTC_DCHECK_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 935 | new_direction = "a=sendrecv"; |
| 936 | break; |
| 937 | } |
| 938 | Replace("a=sendrecv", new_direction, message); |
| 939 | } |
| 940 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 941 | static void ReplaceRejected(bool audio_rejected, |
| 942 | bool video_rejected, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 943 | std::string* message) { |
| 944 | if (audio_rejected) { |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 945 | Replace("m=audio 9", "m=audio 0", message); |
| 946 | Replace(kAttributeIceUfragVoice, "", message); |
| 947 | Replace(kAttributeIcePwdVoice, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 948 | } |
| 949 | if (video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 950 | Replace("m=video 9", "m=video 0", message); |
| 951 | Replace(kAttributeIceUfragVideo, "", message); |
| 952 | Replace(kAttributeIcePwdVideo, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | // WebRtcSdpTest |
| 957 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 958 | class WebRtcSdpTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 959 | public: |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 960 | WebRtcSdpTest() : jdesc_(kDummyType) { |
phoglund | 37ebcf0 | 2016-01-08 13:04:57 | [diff] [blame] | 961 | #ifdef WEBRTC_ANDROID |
| 962 | webrtc::InitializeAndroidObjects(); |
| 963 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 964 | // AudioContentDescription |
| 965 | audio_desc_ = CreateAudioContentDescription(); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 966 | StreamParams audio_stream; |
| 967 | audio_stream.id = kAudioTrackId1; |
| 968 | audio_stream.cname = kStream1Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 969 | audio_stream.set_stream_ids({kStreamId1}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 970 | audio_stream.ssrcs.push_back(kAudioTrack1Ssrc); |
| 971 | audio_desc_->AddStream(audio_stream); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 972 | rtc::SocketAddress audio_addr("74.125.127.126", 2345); |
| 973 | audio_desc_->set_connection_address(audio_addr); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 974 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 975 | absl::WrapUnique(audio_desc_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 976 | |
| 977 | // VideoContentDescription |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 978 | video_desc_ = CreateVideoContentDescription(); |
| 979 | StreamParams video_stream; |
| 980 | video_stream.id = kVideoTrackId1; |
| 981 | video_stream.cname = kStream1Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 982 | video_stream.set_stream_ids({kStreamId1}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 983 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc1); |
| 984 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc2); |
| 985 | cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs); |
| 986 | video_stream.ssrc_groups.push_back(ssrc_group); |
| 987 | video_desc_->AddStream(video_stream); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 988 | rtc::SocketAddress video_addr("74.125.224.39", 3457); |
| 989 | video_desc_->set_connection_address(video_addr); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 990 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, |
| 991 | absl::WrapUnique(video_desc_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 992 | |
| 993 | // TransportInfo |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 994 | desc_.AddTransportInfo(TransportInfo( |
| 995 | kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))); |
| 996 | desc_.AddTransportInfo(TransportInfo( |
| 997 | kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 998 | |
| 999 | // v4 host |
| 1000 | int port = 1234; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1001 | rtc::SocketAddress address("192.168.1.5", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1002 | Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1003 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1004 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1005 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1006 | Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1007 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1008 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1009 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1010 | Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1011 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1012 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1013 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1014 | Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1015 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1016 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1017 | |
| 1018 | // v6 host |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1019 | rtc::SocketAddress v6_address("::1", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1020 | cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1021 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1022 | cricket::LOCAL_PORT_TYPE, |
| 1023 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1024 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1025 | cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1026 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1027 | cricket::LOCAL_PORT_TYPE, |
| 1028 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1029 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1030 | cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1031 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1032 | cricket::LOCAL_PORT_TYPE, |
| 1033 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1034 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1035 | cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1036 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1037 | cricket::LOCAL_PORT_TYPE, |
| 1038 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1039 | |
| 1040 | // stun |
| 1041 | int port_stun = 2345; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1042 | rtc::SocketAddress address_stun("74.125.127.126", port_stun++); |
| 1043 | rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1044 | cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1045 | address_stun, kCandidatePriority, "", "", |
| 1046 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1047 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1048 | candidate9.set_related_address(rel_address_stun); |
| 1049 | |
| 1050 | address_stun.SetPort(port_stun++); |
| 1051 | rel_address_stun.SetPort(port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1052 | cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1053 | address_stun, kCandidatePriority, "", "", |
| 1054 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1055 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1056 | candidate10.set_related_address(rel_address_stun); |
| 1057 | |
| 1058 | // relay |
| 1059 | int port_relay = 3456; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1060 | rtc::SocketAddress address_relay("74.125.224.39", port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1061 | cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1062 | address_relay, kCandidatePriority, "", "", |
| 1063 | cricket::RELAY_PORT_TYPE, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1064 | kCandidateGeneration, kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1065 | address_relay.SetPort(port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1066 | cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1067 | address_relay, kCandidatePriority, "", "", |
| 1068 | RELAY_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1069 | kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1070 | |
| 1071 | // voice |
| 1072 | candidates_.push_back(candidate1); |
| 1073 | candidates_.push_back(candidate2); |
| 1074 | candidates_.push_back(candidate5); |
| 1075 | candidates_.push_back(candidate6); |
| 1076 | candidates_.push_back(candidate9); |
| 1077 | candidates_.push_back(candidate10); |
| 1078 | |
| 1079 | // video |
| 1080 | candidates_.push_back(candidate3); |
| 1081 | candidates_.push_back(candidate4); |
| 1082 | candidates_.push_back(candidate7); |
| 1083 | candidates_.push_back(candidate8); |
| 1084 | candidates_.push_back(candidate11); |
| 1085 | candidates_.push_back(candidate12); |
| 1086 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1087 | jcandidate_.reset( |
| 1088 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1089 | |
| 1090 | // Set up JsepSessionDescription. |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1091 | jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1092 | std::string mline_id; |
| 1093 | int mline_index = 0; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1094 | for (size_t i = 0; i < candidates_.size(); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1095 | // In this test, the audio m line index will be 0, and the video m line |
| 1096 | // will be 1. |
| 1097 | bool is_video = (i > 5); |
| 1098 | mline_id = is_video ? "video_content_name" : "audio_content_name"; |
| 1099 | mline_index = is_video ? 1 : 0; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1100 | JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1101 | jdesc_.AddCandidate(&jice); |
| 1102 | } |
| 1103 | } |
| 1104 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1105 | void RemoveVideoCandidates() { |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1106 | const IceCandidateCollection* video_candidates_collection = |
| 1107 | jdesc_.candidates(1); |
| 1108 | ASSERT_NE(nullptr, video_candidates_collection); |
| 1109 | std::vector<cricket::Candidate> video_candidates; |
| 1110 | for (size_t i = 0; i < video_candidates_collection->count(); ++i) { |
| 1111 | cricket::Candidate c = video_candidates_collection->at(i)->candidate(); |
| 1112 | c.set_transport_name("video_content_name"); |
| 1113 | video_candidates.push_back(c); |
| 1114 | } |
| 1115 | jdesc_.RemoveCandidates(video_candidates); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | // Turns the existing reference description into a description using |
| 1119 | // a=bundle-only. This means no transport attributes and a 0 port value on |
| 1120 | // the m= sections not associated with the BUNDLE-tag. |
| 1121 | void MakeBundleOnlyDescription() { |
| 1122 | RemoveVideoCandidates(); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1123 | |
| 1124 | // And the rest of the transport attributes. |
| 1125 | desc_.transport_infos()[1].description.ice_ufrag.clear(); |
| 1126 | desc_.transport_infos()[1].description.ice_pwd.clear(); |
| 1127 | desc_.transport_infos()[1].description.connection_role = |
| 1128 | cricket::CONNECTIONROLE_NONE; |
| 1129 | |
| 1130 | // Set bundle-only flag. |
| 1131 | desc_.contents()[1].bundle_only = true; |
| 1132 | |
| 1133 | // Add BUNDLE group. |
| 1134 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1135 | group.AddContentName(kAudioContentName); |
| 1136 | group.AddContentName(kVideoContentName); |
| 1137 | desc_.AddGroup(group); |
| 1138 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1139 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1140 | jdesc_.session_version())); |
| 1141 | } |
| 1142 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1143 | // Turns the existing reference description into a plan B description, |
| 1144 | // with 2 audio tracks and 3 video tracks. |
| 1145 | void MakePlanBDescription() { |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1146 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1147 | video_desc_ = new VideoContentDescription(*video_desc_); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1148 | |
| 1149 | StreamParams audio_track_2; |
| 1150 | audio_track_2.id = kAudioTrackId2; |
| 1151 | audio_track_2.cname = kStream2Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1152 | audio_track_2.set_stream_ids({kStreamId2}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1153 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1154 | audio_desc_->AddStream(audio_track_2); |
| 1155 | |
| 1156 | StreamParams video_track_2; |
| 1157 | video_track_2.id = kVideoTrackId2; |
| 1158 | video_track_2.cname = kStream2Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1159 | video_track_2.set_stream_ids({kStreamId2}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1160 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 1161 | video_desc_->AddStream(video_track_2); |
| 1162 | |
| 1163 | StreamParams video_track_3; |
| 1164 | video_track_3.id = kVideoTrackId3; |
| 1165 | video_track_3.cname = kStream2Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1166 | video_track_3.set_stream_ids({kStreamId2}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1167 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 1168 | video_desc_->AddStream(video_track_3); |
| 1169 | |
| 1170 | desc_.RemoveContentByName(kAudioContentName); |
| 1171 | desc_.RemoveContentByName(kVideoContentName); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1172 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 1173 | absl::WrapUnique(audio_desc_)); |
| 1174 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, |
| 1175 | absl::WrapUnique(video_desc_)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1176 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1177 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1178 | jdesc_.session_version())); |
| 1179 | } |
| 1180 | |
| 1181 | // Turns the existing reference description into a unified plan description, |
| 1182 | // with 2 audio tracks and 3 video tracks. |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1183 | void MakeUnifiedPlanDescription(bool use_ssrcs = true) { |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1184 | // Audio track 2. |
| 1185 | AudioContentDescription* audio_desc_2 = CreateAudioContentDescription(); |
| 1186 | StreamParams audio_track_2; |
| 1187 | audio_track_2.id = kAudioTrackId2; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1188 | audio_track_2.set_stream_ids({kStreamId2}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1189 | if (use_ssrcs) { |
| 1190 | audio_track_2.cname = kStream2Cname; |
| 1191 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1192 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1193 | audio_desc_2->AddStream(audio_track_2); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1194 | desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, |
| 1195 | absl::WrapUnique(audio_desc_2)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1196 | desc_.AddTransportInfo(TransportInfo( |
| 1197 | kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1198 | // Video track 2, in stream 2. |
| 1199 | VideoContentDescription* video_desc_2 = CreateVideoContentDescription(); |
| 1200 | StreamParams video_track_2; |
| 1201 | video_track_2.id = kVideoTrackId2; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1202 | video_track_2.set_stream_ids({kStreamId2}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1203 | if (use_ssrcs) { |
| 1204 | video_track_2.cname = kStream2Cname; |
| 1205 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 1206 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1207 | video_desc_2->AddStream(video_track_2); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1208 | desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, |
| 1209 | absl::WrapUnique(video_desc_2)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1210 | desc_.AddTransportInfo(TransportInfo( |
| 1211 | kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1212 | |
| 1213 | // Video track 3, in stream 2. |
| 1214 | VideoContentDescription* video_desc_3 = CreateVideoContentDescription(); |
| 1215 | StreamParams video_track_3; |
| 1216 | video_track_3.id = kVideoTrackId3; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1217 | video_track_3.set_stream_ids({kStreamId2}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1218 | if (use_ssrcs) { |
| 1219 | video_track_3.cname = kStream2Cname; |
| 1220 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 1221 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1222 | video_desc_3->AddStream(video_track_3); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1223 | desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, |
| 1224 | absl::WrapUnique(video_desc_3)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1225 | desc_.AddTransportInfo(TransportInfo( |
| 1226 | kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 1227 | desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1228 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1229 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1230 | jdesc_.session_version())); |
| 1231 | } |
| 1232 | |
| 1233 | // Creates an audio content description with no streams, and some default |
| 1234 | // configuration. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1235 | AudioContentDescription* CreateAudioContentDescription() { |
| 1236 | AudioContentDescription* audio = new AudioContentDescription(); |
| 1237 | audio->set_rtcp_mux(true); |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 1238 | audio->set_rtcp_reduced_size(true); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1239 | audio->AddCrypto(CryptoParams( |
| 1240 | 1, "AES_CM_128_HMAC_SHA1_32", |
| 1241 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32", |
| 1242 | "dummy_session_params")); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1243 | audio->set_protocol(cricket::kMediaProtocolSavpf); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1244 | audio->AddCodec(cricket::CreateAudioCodec(111, "opus", 48000, 2)); |
| 1245 | audio->AddCodec(cricket::CreateAudioCodec(103, "ISAC", 16000, 1)); |
| 1246 | audio->AddCodec(cricket::CreateAudioCodec(104, "ISAC", 32000, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1247 | return audio; |
| 1248 | } |
| 1249 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1250 | // Turns the existing reference description into a unified plan description, |
| 1251 | // with 3 audio MediaContentDescriptions with special StreamParams that |
| 1252 | // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id - |
| 1253 | // audio track 2 has 2 media stream ids - audio track 3 has 0 media stream ids |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 1254 | void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) { |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1255 | desc_.RemoveContentByName(kVideoContentName); |
| 1256 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 1257 | RemoveVideoCandidates(); |
| 1258 | |
| 1259 | // Audio track 2 has 2 media stream ids. |
| 1260 | AudioContentDescription* audio_desc_2 = CreateAudioContentDescription(); |
| 1261 | StreamParams audio_track_2; |
| 1262 | audio_track_2.id = kAudioTrackId2; |
| 1263 | audio_track_2.cname = kStream1Cname; |
| 1264 | audio_track_2.set_stream_ids({kStreamId1, kStreamId2}); |
| 1265 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1266 | audio_desc_2->AddStream(audio_track_2); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1267 | desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, |
| 1268 | absl::WrapUnique(audio_desc_2)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1269 | desc_.AddTransportInfo(TransportInfo( |
| 1270 | kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1271 | |
| 1272 | // Audio track 3 has no stream ids. |
| 1273 | AudioContentDescription* audio_desc_3 = CreateAudioContentDescription(); |
| 1274 | StreamParams audio_track_3; |
| 1275 | audio_track_3.id = kAudioTrackId3; |
| 1276 | audio_track_3.cname = kStream2Cname; |
| 1277 | audio_track_3.set_stream_ids({}); |
| 1278 | audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc); |
| 1279 | audio_desc_3->AddStream(audio_track_3); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1280 | desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, |
| 1281 | absl::WrapUnique(audio_desc_3)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1282 | desc_.AddTransportInfo(TransportInfo( |
| 1283 | kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))); |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 1284 | desc_.set_msid_signaling(msid_signaling); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1285 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1286 | jdesc_.session_version())); |
| 1287 | } |
| 1288 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1289 | // Turns the existing reference description into a unified plan description |
| 1290 | // with one audio MediaContentDescription that contains one StreamParams with |
| 1291 | // 0 ssrcs. |
| 1292 | void MakeUnifiedPlanDescriptionNoSsrcSignaling() { |
| 1293 | desc_.RemoveContentByName(kVideoContentName); |
| 1294 | desc_.RemoveContentByName(kAudioContentName); |
| 1295 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 1296 | RemoveVideoCandidates(); |
| 1297 | |
| 1298 | AudioContentDescription* audio_desc = CreateAudioContentDescription(); |
| 1299 | StreamParams audio_track; |
| 1300 | audio_track.id = kAudioTrackId1; |
| 1301 | audio_track.set_stream_ids({kStreamId1}); |
| 1302 | audio_desc->AddStream(audio_track); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1303 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 1304 | absl::WrapUnique(audio_desc)); |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1305 | |
| 1306 | // Enable signaling a=msid lines. |
| 1307 | desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1308 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1309 | jdesc_.session_version())); |
| 1310 | } |
| 1311 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1312 | // Creates a video content description with no streams, and some default |
| 1313 | // configuration. |
| 1314 | VideoContentDescription* CreateVideoContentDescription() { |
| 1315 | VideoContentDescription* video = new VideoContentDescription(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1316 | video->AddCrypto(CryptoParams( |
| 1317 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 1318 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", "")); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1319 | video->set_protocol(cricket::kMediaProtocolSavpf); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1320 | video->AddCodec(cricket::CreateVideoCodec(120, "VP8")); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1321 | return video; |
| 1322 | } |
| 1323 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1324 | template <class MCD> |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1325 | void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1326 | // type |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1327 | EXPECT_EQ(cd1->type(), cd2->type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1328 | |
| 1329 | // content direction |
| 1330 | EXPECT_EQ(cd1->direction(), cd2->direction()); |
| 1331 | |
| 1332 | // rtcp_mux |
| 1333 | EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux()); |
| 1334 | |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 1335 | // rtcp_reduced_size |
| 1336 | EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size()); |
| 1337 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1338 | // cryptos |
| 1339 | EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size()); |
| 1340 | if (cd1->cryptos().size() != cd2->cryptos().size()) { |
| 1341 | ADD_FAILURE(); |
| 1342 | return; |
| 1343 | } |
| 1344 | for (size_t i = 0; i < cd1->cryptos().size(); ++i) { |
| 1345 | const CryptoParams c1 = cd1->cryptos().at(i); |
| 1346 | const CryptoParams c2 = cd2->cryptos().at(i); |
| 1347 | EXPECT_TRUE(c1.Matches(c2)); |
| 1348 | EXPECT_EQ(c1.key_params, c2.key_params); |
| 1349 | EXPECT_EQ(c1.session_params, c2.session_params); |
| 1350 | } |
| 1351 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1352 | // protocol |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 | [diff] [blame] | 1353 | // Use an equivalence class here, for old and new versions of the |
| 1354 | // protocol description. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1355 | if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp || |
| 1356 | cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp || |
| 1357 | cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) { |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 1358 | const bool cd2_is_also_dtls_sctp = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1359 | cd2->protocol() == cricket::kMediaProtocolDtlsSctp || |
| 1360 | cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp || |
| 1361 | cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp; |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 1362 | EXPECT_TRUE(cd2_is_also_dtls_sctp); |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 | [diff] [blame] | 1363 | } else { |
| 1364 | EXPECT_EQ(cd1->protocol(), cd2->protocol()); |
| 1365 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1366 | |
| 1367 | // codecs |
| 1368 | EXPECT_EQ(cd1->codecs(), cd2->codecs()); |
| 1369 | |
| 1370 | // bandwidth |
| 1371 | EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth()); |
| 1372 | |
| 1373 | // streams |
| 1374 | EXPECT_EQ(cd1->streams(), cd2->streams()); |
| 1375 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 1376 | // extmap-allow-mixed |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 1377 | EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 1378 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1379 | // extmap |
| 1380 | ASSERT_EQ(cd1->rtp_header_extensions().size(), |
| 1381 | cd2->rtp_header_extensions().size()); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1382 | for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 1383 | const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); |
| 1384 | const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1385 | EXPECT_EQ(ext1.uri, ext2.uri); |
| 1386 | EXPECT_EQ(ext1.id, ext2.id); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1387 | EXPECT_EQ(ext1.encrypt, ext2.encrypt); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1388 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1389 | } |
| 1390 | |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1391 | void CompareRidDescriptionIds(const std::vector<RidDescription>& rids, |
| 1392 | const std::vector<std::string>& ids) { |
| 1393 | // Order of elements does not matter, only equivalence of sets. |
| 1394 | EXPECT_EQ(rids.size(), ids.size()); |
| 1395 | for (const std::string& id : ids) { |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 1396 | EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) { |
| 1397 | return rid.rid == id; |
| 1398 | })); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 1402 | void CompareSimulcastDescription(const SimulcastDescription& simulcast1, |
| 1403 | const SimulcastDescription& simulcast2) { |
| 1404 | EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size()); |
| 1405 | EXPECT_EQ(simulcast1.receive_layers().size(), |
| 1406 | simulcast2.receive_layers().size()); |
| 1407 | } |
| 1408 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1409 | void CompareSctpDataContentDescription( |
| 1410 | const SctpDataContentDescription* dcd1, |
| 1411 | const SctpDataContentDescription* dcd2) { |
Harald Alvestrand | 26bf7c4 | 2019-04-23 05:20:17 | [diff] [blame] | 1412 | EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1413 | EXPECT_EQ(dcd1->port(), dcd2->port()); |
| 1414 | EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size()); |
Harald Alvestrand | 26bf7c4 | 2019-04-23 05:20:17 | [diff] [blame] | 1415 | } |
| 1416 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1417 | void CompareSessionDescription(const SessionDescription& desc1, |
| 1418 | const SessionDescription& desc2) { |
| 1419 | // Compare content descriptions. |
| 1420 | if (desc1.contents().size() != desc2.contents().size()) { |
| 1421 | ADD_FAILURE(); |
| 1422 | return; |
| 1423 | } |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1424 | for (size_t i = 0; i < desc1.contents().size(); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1425 | const cricket::ContentInfo& c1 = desc1.contents().at(i); |
| 1426 | const cricket::ContentInfo& c2 = desc2.contents().at(i); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1427 | // ContentInfo properties. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1428 | EXPECT_EQ(c1.name, c2.name); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1429 | EXPECT_EQ(c1.type, c2.type); |
| 1430 | EXPECT_EQ(c1.rejected, c2.rejected); |
| 1431 | EXPECT_EQ(c1.bundle_only, c2.bundle_only); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1432 | |
| 1433 | ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2)); |
| 1434 | if (IsAudioContent(&c1)) { |
| 1435 | const AudioContentDescription* acd1 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1436 | c1.media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1437 | const AudioContentDescription* acd2 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1438 | c2.media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1439 | CompareMediaContentDescription<AudioContentDescription>(acd1, acd2); |
| 1440 | } |
| 1441 | |
| 1442 | ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2)); |
| 1443 | if (IsVideoContent(&c1)) { |
| 1444 | const VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1445 | c1.media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1446 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1447 | c2.media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1448 | CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2); |
| 1449 | } |
| 1450 | |
| 1451 | ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1452 | if (c1.media_description()->as_sctp()) { |
| 1453 | ASSERT_TRUE(c2.media_description()->as_sctp()); |
| 1454 | const SctpDataContentDescription* scd1 = |
| 1455 | c1.media_description()->as_sctp(); |
| 1456 | const SctpDataContentDescription* scd2 = |
| 1457 | c2.media_description()->as_sctp(); |
| 1458 | CompareSctpDataContentDescription(scd1, scd2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1459 | } |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 1460 | |
| 1461 | CompareSimulcastDescription( |
| 1462 | c1.media_description()->simulcast_description(), |
| 1463 | c2.media_description()->simulcast_description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | // group |
| 1467 | const cricket::ContentGroups groups1 = desc1.groups(); |
| 1468 | const cricket::ContentGroups groups2 = desc2.groups(); |
| 1469 | EXPECT_EQ(groups1.size(), groups1.size()); |
| 1470 | if (groups1.size() != groups2.size()) { |
| 1471 | ADD_FAILURE(); |
| 1472 | return; |
| 1473 | } |
| 1474 | for (size_t i = 0; i < groups1.size(); ++i) { |
| 1475 | const cricket::ContentGroup group1 = groups1.at(i); |
| 1476 | const cricket::ContentGroup group2 = groups2.at(i); |
| 1477 | EXPECT_EQ(group1.semantics(), group2.semantics()); |
| 1478 | const cricket::ContentNames names1 = group1.content_names(); |
| 1479 | const cricket::ContentNames names2 = group2.content_names(); |
| 1480 | EXPECT_EQ(names1.size(), names2.size()); |
| 1481 | if (names1.size() != names2.size()) { |
| 1482 | ADD_FAILURE(); |
| 1483 | return; |
| 1484 | } |
| 1485 | cricket::ContentNames::const_iterator iter1 = names1.begin(); |
| 1486 | cricket::ContentNames::const_iterator iter2 = names2.begin(); |
| 1487 | while (iter1 != names1.end()) { |
| 1488 | EXPECT_EQ(*iter1++, *iter2++); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | // transport info |
| 1493 | const cricket::TransportInfos transports1 = desc1.transport_infos(); |
| 1494 | const cricket::TransportInfos transports2 = desc2.transport_infos(); |
| 1495 | EXPECT_EQ(transports1.size(), transports2.size()); |
| 1496 | if (transports1.size() != transports2.size()) { |
| 1497 | ADD_FAILURE(); |
| 1498 | return; |
| 1499 | } |
| 1500 | for (size_t i = 0; i < transports1.size(); ++i) { |
| 1501 | const cricket::TransportInfo transport1 = transports1.at(i); |
| 1502 | const cricket::TransportInfo transport2 = transports2.at(i); |
| 1503 | EXPECT_EQ(transport1.content_name, transport2.content_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1504 | EXPECT_EQ(transport1.description.ice_ufrag, |
| 1505 | transport2.description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1506 | EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd); |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 1507 | EXPECT_EQ(transport1.description.ice_mode, |
| 1508 | transport2.description.ice_mode); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1509 | if (transport1.description.identity_fingerprint) { |
| 1510 | EXPECT_EQ(*transport1.description.identity_fingerprint, |
| 1511 | *transport2.description.identity_fingerprint); |
| 1512 | } else { |
| 1513 | EXPECT_EQ(transport1.description.identity_fingerprint.get(), |
| 1514 | transport2.description.identity_fingerprint.get()); |
| 1515 | } |
| 1516 | EXPECT_EQ(transport1.description.transport_options, |
| 1517 | transport2.description.transport_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1518 | } |
deadbeef | c80741f | 2015-10-22 20:14:45 | [diff] [blame] | 1519 | |
| 1520 | // global attributes |
| 1521 | EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported()); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 1522 | EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1523 | } |
| 1524 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1525 | bool CompareSessionDescription(const JsepSessionDescription& desc1, |
| 1526 | const JsepSessionDescription& desc2) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1527 | EXPECT_EQ(desc1.session_id(), desc2.session_id()); |
| 1528 | EXPECT_EQ(desc1.session_version(), desc2.session_version()); |
| 1529 | CompareSessionDescription(*desc1.description(), *desc2.description()); |
| 1530 | if (desc1.number_of_mediasections() != desc2.number_of_mediasections()) |
| 1531 | return false; |
| 1532 | for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) { |
| 1533 | const IceCandidateCollection* cc1 = desc1.candidates(i); |
| 1534 | const IceCandidateCollection* cc2 = desc2.candidates(i); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1535 | if (cc1->count() != cc2->count()) { |
| 1536 | ADD_FAILURE(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1537 | return false; |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1538 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1539 | for (size_t j = 0; j < cc1->count(); ++j) { |
| 1540 | const IceCandidateInterface* c1 = cc1->at(j); |
| 1541 | const IceCandidateInterface* c2 = cc2->at(j); |
| 1542 | EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid()); |
| 1543 | EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index()); |
| 1544 | EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate())); |
| 1545 | } |
| 1546 | } |
| 1547 | return true; |
| 1548 | } |
| 1549 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1550 | // Disable the ice-ufrag and ice-pwd in given `sdp` message by replacing |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1551 | // them with invalid keywords so that the parser will just ignore them. |
| 1552 | bool RemoveCandidateUfragPwd(std::string* sdp) { |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 1553 | absl::StrReplaceAll( |
| 1554 | {{"a=ice-ufrag", "a=xice-ufrag"}, {"a=ice-pwd", "a=xice-pwd"}}, sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1555 | return true; |
| 1556 | } |
| 1557 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 1558 | // Update the candidates in `jdesc` to use the given `ufrag` and `pwd`. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1559 | bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, |
| 1560 | int mline_index, |
| 1561 | const std::string& ufrag, |
| 1562 | const std::string& pwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1563 | std::string content_name; |
| 1564 | if (mline_index == 0) { |
| 1565 | content_name = kAudioContentName; |
| 1566 | } else if (mline_index == 1) { |
| 1567 | content_name = kVideoContentName; |
| 1568 | } else { |
Artem Titov | d325196 | 2021-11-15 15:57:07 | [diff] [blame] | 1569 | RTC_DCHECK_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1570 | } |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1571 | TransportInfo transport_info(content_name, |
| 1572 | TransportDescription(ufrag, pwd)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1573 | SessionDescription* desc = |
| 1574 | const_cast<SessionDescription*>(jdesc->description()); |
| 1575 | desc->RemoveTransportInfoByName(content_name); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1576 | desc->AddTransportInfo(transport_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1577 | for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) { |
| 1578 | const IceCandidateCollection* cc = jdesc_.candidates(i); |
| 1579 | for (size_t j = 0; j < cc->count(); ++j) { |
| 1580 | if (cc->at(j)->sdp_mline_index() == mline_index) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1581 | const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag); |
| 1582 | const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | return true; |
| 1587 | } |
| 1588 | |
| 1589 | void AddIceOptions(const std::string& content_name, |
| 1590 | const std::vector<std::string>& transport_options) { |
| 1591 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1592 | cricket::TransportInfo transport_info = |
| 1593 | *(desc_.GetTransportInfoByName(content_name)); |
| 1594 | desc_.RemoveTransportInfoByName(content_name); |
| 1595 | transport_info.description.transport_options = transport_options; |
| 1596 | desc_.AddTransportInfo(transport_info); |
| 1597 | } |
| 1598 | |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1599 | void SetIceUfragPwd(const std::string& content_name, |
| 1600 | const std::string& ice_ufrag, |
| 1601 | const std::string& ice_pwd) { |
| 1602 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1603 | cricket::TransportInfo transport_info = |
| 1604 | *(desc_.GetTransportInfoByName(content_name)); |
| 1605 | desc_.RemoveTransportInfoByName(content_name); |
| 1606 | transport_info.description.ice_ufrag = ice_ufrag; |
| 1607 | transport_info.description.ice_pwd = ice_pwd; |
| 1608 | desc_.AddTransportInfo(transport_info); |
| 1609 | } |
| 1610 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1611 | void AddFingerprint() { |
| 1612 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 1613 | desc_.RemoveTransportInfoByName(kVideoContentName); |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 1614 | rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1615 | desc_.AddTransportInfo(TransportInfo( |
deadbeef | 46eed76 | 2016-01-28 21:24:37 | [diff] [blame] | 1616 | kAudioContentName, |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1617 | TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice, |
| 1618 | cricket::ICEMODE_FULL, |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1619 | cricket::CONNECTIONROLE_NONE, &fingerprint))); |
| 1620 | desc_.AddTransportInfo(TransportInfo( |
deadbeef | 46eed76 | 2016-01-28 21:24:37 | [diff] [blame] | 1621 | kVideoContentName, |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1622 | TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, |
| 1623 | cricket::ICEMODE_FULL, |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1624 | cricket::CONNECTIONROLE_NONE, &fingerprint))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1625 | } |
| 1626 | |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1627 | void AddExtmap(bool encrypted) { |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1628 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1629 | video_desc_ = new VideoContentDescription(*video_desc_); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1630 | audio_desc_->AddRtpHeaderExtension( |
| 1631 | RtpExtension(kExtmapUri, kExtmapId, encrypted)); |
| 1632 | video_desc_->AddRtpHeaderExtension( |
| 1633 | RtpExtension(kExtmapUri, kExtmapId, encrypted)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1634 | desc_.RemoveContentByName(kAudioContentName); |
| 1635 | desc_.RemoveContentByName(kVideoContentName); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1636 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 1637 | absl::WrapUnique(audio_desc_)); |
| 1638 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, |
| 1639 | absl::WrapUnique(video_desc_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1640 | } |
| 1641 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 1642 | void RemoveCryptos() { |
| 1643 | audio_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1644 | video_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1645 | } |
| 1646 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1647 | // Removes everything in StreamParams from the session description that is |
| 1648 | // used for a=ssrc lines. |
| 1649 | void RemoveSsrcSignalingFromStreamParams() { |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1650 | for (cricket::ContentInfo& content_info : |
| 1651 | jdesc_.description()->contents()) { |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1652 | // With Unified Plan there should be one StreamParams per m= section. |
| 1653 | StreamParams& stream = |
| 1654 | content_info.media_description()->mutable_streams()[0]; |
| 1655 | stream.ssrcs.clear(); |
| 1656 | stream.ssrc_groups.clear(); |
| 1657 | stream.cname.clear(); |
| 1658 | } |
| 1659 | } |
| 1660 | |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 1661 | // Removes all a=ssrc lines from the SDP string, except for the |
| 1662 | // "a=ssrc:... cname:..." lines. |
| 1663 | void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) { |
| 1664 | const char kAttributeSsrc[] = "a=ssrc"; |
| 1665 | const char kAttributeCname[] = "cname"; |
| 1666 | size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc); |
| 1667 | while (ssrc_line_pos != std::string::npos) { |
| 1668 | size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos); |
| 1669 | size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos); |
| 1670 | size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos); |
| 1671 | if (cname_pos == std::string::npos || cname_pos > end_line_pos) { |
| 1672 | // Only erase a=ssrc lines that don't contain "cname". |
| 1673 | sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos); |
| 1674 | ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos); |
| 1675 | } else { |
| 1676 | // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line. |
| 1677 | ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos); |
| 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1682 | // Removes all a=ssrc lines from the SDP string. |
| 1683 | void RemoveSsrcLinesFromSdpString(std::string* sdp_string) { |
| 1684 | const char kAttributeSsrc[] = "a=ssrc"; |
| 1685 | while (sdp_string->find(kAttributeSsrc) != std::string::npos) { |
| 1686 | size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc); |
| 1687 | size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute); |
| 1688 | size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute); |
| 1689 | sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos); |
| 1690 | } |
| 1691 | } |
| 1692 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1693 | bool TestSerializeDirection(RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1694 | audio_desc_->set_direction(direction); |
| 1695 | video_desc_->set_direction(direction); |
| 1696 | std::string new_sdp = kSdpFullString; |
| 1697 | ReplaceDirection(direction, &new_sdp); |
| 1698 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1699 | if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1700 | jdesc_.session_version())) { |
| 1701 | return false; |
| 1702 | } |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 1703 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1704 | EXPECT_EQ(new_sdp, message); |
| 1705 | return true; |
| 1706 | } |
| 1707 | |
| 1708 | bool TestSerializeRejected(bool audio_rejected, bool video_rejected) { |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1709 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1710 | video_desc_ = new VideoContentDescription(*video_desc_); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 1711 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1712 | desc_.RemoveContentByName(kAudioContentName); |
| 1713 | desc_.RemoveContentByName(kVideoContentName); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1714 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1715 | absl::WrapUnique(audio_desc_)); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1716 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1717 | absl::WrapUnique(video_desc_)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1718 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1719 | audio_rejected ? "" : kPwdVoice); |
| 1720 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1721 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1722 | |
| 1723 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1724 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1725 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1726 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 1727 | MakeDescriptionWithoutCandidates(&jdesc_no_candidates); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 1728 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1729 | EXPECT_EQ(new_sdp, message); |
| 1730 | return true; |
| 1731 | } |
| 1732 | |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1733 | void AddSctpDataChannel(bool use_sctpmap) { |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1734 | std::unique_ptr<SctpDataContentDescription> data( |
| 1735 | new SctpDataContentDescription()); |
| 1736 | sctp_desc_ = data.get(); |
| 1737 | sctp_desc_->set_use_sctpmap(use_sctpmap); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 1738 | sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1739 | sctp_desc_->set_port(kDefaultSctpPort); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1740 | desc_.AddContent(kDataContentName, MediaProtocolType::kSctp, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1741 | std::move(data)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1742 | desc_.AddTransportInfo(TransportInfo( |
| 1743 | kDataContentName, TransportDescription(kUfragData, kPwdData))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1744 | } |
| 1745 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1746 | bool TestDeserializeDirection(RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1747 | std::string new_sdp = kSdpFullString; |
| 1748 | ReplaceDirection(direction, &new_sdp); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1749 | JsepSessionDescription new_jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1750 | |
| 1751 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1752 | |
| 1753 | audio_desc_->set_direction(direction); |
| 1754 | video_desc_->set_direction(direction); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1755 | if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1756 | jdesc_.session_version())) { |
| 1757 | return false; |
| 1758 | } |
| 1759 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1760 | return true; |
| 1761 | } |
| 1762 | |
| 1763 | bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1764 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1765 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1766 | JsepSessionDescription new_jdesc(SdpType::kOffer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1767 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1768 | |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1769 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1770 | video_desc_ = new VideoContentDescription(*video_desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1771 | desc_.RemoveContentByName(kAudioContentName); |
| 1772 | desc_.RemoveContentByName(kVideoContentName); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1773 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1774 | absl::WrapUnique(audio_desc_)); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1775 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1776 | absl::WrapUnique(video_desc_)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1777 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1778 | audio_rejected ? "" : kPwdVoice); |
| 1779 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1780 | video_rejected ? "" : kPwdVideo); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1781 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1782 | if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1783 | jdesc_.session_version())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1784 | return false; |
| 1785 | } |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1786 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1787 | return true; |
| 1788 | } |
| 1789 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1790 | void TestDeserializeExtmap(bool session_level, |
| 1791 | bool media_level, |
| 1792 | bool encrypted) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1793 | AddExtmap(encrypted); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1794 | JsepSessionDescription new_jdesc(SdpType::kOffer); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1795 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1796 | jdesc_.session_version())); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1797 | JsepSessionDescription jdesc_with_extmap(SdpType::kOffer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1798 | std::string sdp_with_extmap = kSdpString; |
| 1799 | if (session_level) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1800 | InjectAfter(kSessionTime, |
| 1801 | encrypted ? kExtmapWithDirectionAndAttributeEncrypted |
| 1802 | : kExtmapWithDirectionAndAttribute, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1803 | &sdp_with_extmap); |
| 1804 | } |
| 1805 | if (media_level) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1806 | InjectAfter(kAttributeIcePwdVoice, |
| 1807 | encrypted ? kExtmapWithDirectionAndAttributeEncrypted |
| 1808 | : kExtmapWithDirectionAndAttribute, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1809 | &sdp_with_extmap); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1810 | InjectAfter(kAttributeIcePwdVideo, |
| 1811 | encrypted ? kExtmapWithDirectionAndAttributeEncrypted |
| 1812 | : kExtmapWithDirectionAndAttribute, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1813 | &sdp_with_extmap); |
| 1814 | } |
| 1815 | // The extmap can't be present at the same time in both session level and |
| 1816 | // media level. |
| 1817 | if (session_level && media_level) { |
| 1818 | SdpParseError error; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1819 | EXPECT_FALSE( |
| 1820 | webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1821 | EXPECT_NE(std::string::npos, error.description.find("a=extmap")); |
| 1822 | } else { |
| 1823 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap)); |
| 1824 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc)); |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | void VerifyCodecParameter(const cricket::CodecParameterMap& params, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1829 | const std::string& name, |
| 1830 | int expected_value) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1831 | cricket::CodecParameterMap::const_iterator found = params.find(name); |
| 1832 | ASSERT_TRUE(found != params.end()); |
Jonas Olsson | 6b1985d | 2018-07-05 09:59:48 | [diff] [blame] | 1833 | EXPECT_EQ(found->second, rtc::ToString(expected_value)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | void TestDeserializeCodecParams(const CodecParams& params, |
| 1837 | JsepSessionDescription* jdesc_output) { |
| 1838 | std::string sdp = |
| 1839 | "v=0\r\n" |
| 1840 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1841 | "s=-\r\n" |
| 1842 | "t=0 0\r\n" |
| 1843 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1844 | // this parser, and will be added to the SDP when serializing a session |
| 1845 | // description. |
| 1846 | "a=msid-semantic: WMS\r\n" |
| 1847 | // Pl type 111 preferred. |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 1848 | "m=audio 9 RTP/SAVPF 111 104 103 105\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1849 | // Pltype 111 listed before 103 and 104 in the map. |
| 1850 | "a=rtpmap:111 opus/48000/2\r\n" |
| 1851 | // Pltype 103 listed before 104. |
| 1852 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 1853 | "a=rtpmap:104 ISAC/32000\r\n" |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 1854 | "a=rtpmap:105 telephone-event/8000\r\n" |
| 1855 | "a=fmtp:105 0-15,66,70\r\n" |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 | [diff] [blame] | 1856 | "a=fmtp:111 "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1857 | std::ostringstream os; |
Donald Curtis | 144d018 | 2015-05-15 20:14:24 | [diff] [blame] | 1858 | os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 | [diff] [blame] | 1859 | << "; sprop-stereo=" << params.sprop_stereo |
| 1860 | << "; useinbandfec=" << params.useinband |
Jonas Olsson | b2b2031 | 2020-01-14 11:11:31 | [diff] [blame] | 1861 | << "; maxaveragebitrate=" << params.maxaveragebitrate |
| 1862 | << "\r\n" |
| 1863 | "a=ptime:" |
| 1864 | << params.ptime |
| 1865 | << "\r\n" |
| 1866 | "a=maxptime:" |
| 1867 | << params.max_ptime << "\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1868 | sdp += os.str(); |
| 1869 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1870 | os.clear(); |
| 1871 | os.str(""); |
| 1872 | // Pl type 100 preferred. |
Philipp Hancke | b7bc243 | 2021-03-11 14:28:00 | [diff] [blame] | 1873 | os << "m=video 9 RTP/SAVPF 99 95 96\r\n" |
| 1874 | "a=rtpmap:96 VP9/90000\r\n" // out-of-order wrt the m= line. |
Jonas Olsson | b2b2031 | 2020-01-14 11:11:31 | [diff] [blame] | 1875 | "a=rtpmap:99 VP8/90000\r\n" |
| 1876 | "a=rtpmap:95 RTX/90000\r\n" |
| 1877 | "a=fmtp:95 apt=99;\r\n"; |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1878 | sdp += os.str(); |
| 1879 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1880 | // Deserialize |
| 1881 | SdpParseError error; |
| 1882 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1883 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1884 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1885 | GetFirstAudioContentDescription(jdesc_output->description()); |
| 1886 | ASSERT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1887 | ASSERT_FALSE(acd->codecs().empty()); |
| 1888 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1889 | EXPECT_EQ("opus", opus.name); |
| 1890 | EXPECT_EQ(111, opus.id); |
| 1891 | VerifyCodecParameter(opus.params, "minptime", params.min_ptime); |
| 1892 | VerifyCodecParameter(opus.params, "stereo", params.stereo); |
| 1893 | VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo); |
| 1894 | VerifyCodecParameter(opus.params, "useinbandfec", params.useinband); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 | [diff] [blame] | 1895 | VerifyCodecParameter(opus.params, "maxaveragebitrate", |
| 1896 | params.maxaveragebitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1897 | for (size_t i = 0; i < acd->codecs().size(); ++i) { |
| 1898 | cricket::AudioCodec codec = acd->codecs()[i]; |
| 1899 | VerifyCodecParameter(codec.params, "ptime", params.ptime); |
| 1900 | VerifyCodecParameter(codec.params, "maxptime", params.max_ptime); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1901 | } |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1902 | |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 1903 | cricket::AudioCodec dtmf = acd->codecs()[3]; |
| 1904 | EXPECT_EQ("telephone-event", dtmf.name); |
| 1905 | EXPECT_EQ(105, dtmf.id); |
| 1906 | EXPECT_EQ(3u, |
| 1907 | dtmf.params.size()); // ptime and max_ptime count as parameters. |
| 1908 | EXPECT_EQ(dtmf.params.begin()->first, ""); |
| 1909 | EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70"); |
| 1910 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1911 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1912 | GetFirstVideoContentDescription(jdesc_output->description()); |
| 1913 | ASSERT_TRUE(vcd); |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1914 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1915 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1916 | EXPECT_EQ("VP8", vp8.name); |
| 1917 | EXPECT_EQ(99, vp8.id); |
| 1918 | cricket::VideoCodec rtx = vcd->codecs()[1]; |
| 1919 | EXPECT_EQ("RTX", rtx.name); |
| 1920 | EXPECT_EQ(95, rtx.id); |
| 1921 | VerifyCodecParameter(rtx.params, "apt", vp8.id); |
Philipp Hancke | b7bc243 | 2021-03-11 14:28:00 | [diff] [blame] | 1922 | // VP9 is listed last in the m= line so should come after VP8 and RTX. |
| 1923 | cricket::VideoCodec vp9 = vcd->codecs()[2]; |
| 1924 | EXPECT_EQ("VP9", vp9.name); |
| 1925 | EXPECT_EQ(96, vp9.id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output, |
| 1929 | bool use_wildcard) { |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1930 | std::string sdp_session_and_audio = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1931 | "v=0\r\n" |
| 1932 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1933 | "s=-\r\n" |
| 1934 | "t=0 0\r\n" |
| 1935 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1936 | // this parser, and will be added to the SDP when serializing a session |
| 1937 | // description. |
| 1938 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 1939 | "m=audio 9 RTP/SAVPF 111\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1940 | "a=rtpmap:111 opus/48000/2\r\n"; |
| 1941 | std::string sdp_video = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1942 | "m=video 3457 RTP/SAVPF 101\r\n" |
| 1943 | "a=rtpmap:101 VP8/90000\r\n" |
Elad Alon | fadb181 | 2019-05-24 11:40:02 | [diff] [blame] | 1944 | "a=rtcp-fb:101 goog-lntf\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1945 | "a=rtcp-fb:101 nack\r\n" |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 | [diff] [blame] | 1946 | "a=rtcp-fb:101 nack pli\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1947 | "a=rtcp-fb:101 goog-remb\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1948 | std::ostringstream os; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1949 | os << sdp_session_and_audio; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1950 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n"; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1951 | os << sdp_video; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1952 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n"; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1953 | std::string sdp = os.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1954 | // Deserialize |
| 1955 | SdpParseError error; |
| 1956 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1957 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1958 | GetFirstAudioContentDescription(jdesc_output->description()); |
| 1959 | ASSERT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1960 | ASSERT_FALSE(acd->codecs().empty()); |
| 1961 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1962 | EXPECT_EQ(111, opus.id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1963 | EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam( |
| 1964 | cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1965 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1966 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1967 | GetFirstVideoContentDescription(jdesc_output->description()); |
| 1968 | ASSERT_TRUE(vcd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1969 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1970 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
Philipp Hancke | 7f4270d | 2023-02-23 12:20:25 | [diff] [blame] | 1971 | EXPECT_EQ(vp8.name, "VP8"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1972 | EXPECT_EQ(101, vp8.id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1973 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
Elad Alon | fadb181 | 2019-05-24 11:40:02 | [diff] [blame] | 1974 | cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty))); |
| 1975 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1976 | cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
| 1977 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
| 1978 | cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli))); |
| 1979 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
| 1980 | cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty))); |
| 1981 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
| 1982 | cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | // Two SDP messages can mean the same thing but be different strings, e.g. |
| 1986 | // some of the lines can be serialized in different order. |
| 1987 | // However, a deserialized description can be compared field by field and has |
| 1988 | // no order. If deserializer has already been tested, serializing then |
| 1989 | // deserializing and comparing JsepSessionDescription will test |
| 1990 | // the serializer sufficiently. |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 1991 | void TestSerialize(const JsepSessionDescription& jdesc) { |
| 1992 | std::string message = webrtc::SdpSerialize(jdesc); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1993 | JsepSessionDescription jdesc_output_des(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1994 | SdpParseError error; |
| 1995 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); |
| 1996 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); |
| 1997 | } |
| 1998 | |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 1999 | // Calling 'Initialize' with a copy of the inner SessionDescription will |
| 2000 | // create a copy of the JsepSessionDescription without candidates. The |
| 2001 | // 'connection address' field, previously set from the candidates, must also |
| 2002 | // be reset. |
| 2003 | void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) { |
| 2004 | rtc::SocketAddress audio_addr("0.0.0.0", 9); |
| 2005 | rtc::SocketAddress video_addr("0.0.0.0", 9); |
| 2006 | audio_desc_->set_connection_address(audio_addr); |
| 2007 | video_desc_->set_connection_address(video_addr); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2008 | ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2009 | } |
| 2010 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2011 | protected: |
| 2012 | SessionDescription desc_; |
| 2013 | AudioContentDescription* audio_desc_; |
| 2014 | VideoContentDescription* video_desc_; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2015 | SctpDataContentDescription* sctp_desc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2016 | Candidates candidates_; |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 2017 | std::unique_ptr<IceCandidateInterface> jcandidate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2018 | JsepSessionDescription jdesc_; |
| 2019 | }; |
| 2020 | |
| 2021 | void TestMismatch(const std::string& string1, const std::string& string2) { |
| 2022 | int position = 0; |
| 2023 | for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { |
| 2024 | if (string1.c_str()[i] != string2.c_str()[i]) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 | [diff] [blame] | 2025 | position = static_cast<int>(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2026 | break; |
| 2027 | } |
| 2028 | } |
| 2029 | EXPECT_EQ(0, position) << "Strings mismatch at the " << position |
| 2030 | << " character\n" |
Jonas Olsson | b2b2031 | 2020-01-14 11:11:31 | [diff] [blame] | 2031 | " 1: " |
| 2032 | << string1.substr(position, 20) |
| 2033 | << "\n" |
| 2034 | " 2: " |
| 2035 | << string2.substr(position, 20) << "\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2036 | } |
| 2037 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2038 | TEST_F(WebRtcSdpTest, SerializeSessionDescription) { |
| 2039 | // SessionDescription with desc and candidates. |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2040 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2041 | TestMismatch(std::string(kSdpFullString), message); |
| 2042 | } |
| 2043 | |
| 2044 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2045 | JsepSessionDescription jdesc_empty(kDummyType); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2046 | EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2047 | } |
| 2048 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 2049 | // This tests serialization of SDP with a=crypto and a=fingerprint, as would be |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2050 | // the case in a DTLS offer. |
| 2051 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) { |
| 2052 | AddFingerprint(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2053 | JsepSessionDescription jdesc_with_fingerprint(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2054 | MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2055 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2056 | |
| 2057 | std::string sdp_with_fingerprint = kSdpString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2058 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2059 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2060 | |
| 2061 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 2062 | } |
| 2063 | |
| 2064 | // This tests serialization of SDP with a=fingerprint with no a=crypto, as would |
| 2065 | // be the case in a DTLS answer. |
| 2066 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) { |
| 2067 | AddFingerprint(); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 2068 | RemoveCryptos(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2069 | JsepSessionDescription jdesc_with_fingerprint(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2070 | MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2071 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2072 | |
| 2073 | std::string sdp_with_fingerprint = kSdpString; |
| 2074 | Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint); |
| 2075 | Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2076 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2077 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2078 | |
| 2079 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 2080 | } |
| 2081 | |
| 2082 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { |
| 2083 | // JsepSessionDescription with desc but without candidates. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2084 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2085 | MakeDescriptionWithoutCandidates(&jdesc_no_candidates); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2086 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2087 | EXPECT_EQ(std::string(kSdpString), message); |
| 2088 | } |
| 2089 | |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 2090 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundles) { |
| 2091 | ContentGroup group1(cricket::GROUP_TYPE_BUNDLE); |
| 2092 | group1.AddContentName(kAudioContentName); |
| 2093 | group1.AddContentName(kVideoContentName); |
| 2094 | desc_.AddGroup(group1); |
| 2095 | ContentGroup group2(cricket::GROUP_TYPE_BUNDLE); |
| 2096 | group2.AddContentName(kAudioContentName2); |
| 2097 | desc_.AddGroup(group2); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2098 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2099 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2100 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2101 | std::string sdp_with_bundle = kSdpFullString; |
| 2102 | InjectAfter(kSessionTime, |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame] | 2103 | "a=group:BUNDLE audio_content_name video_content_name\r\n" |
| 2104 | "a=group:BUNDLE audio_content_name_2\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2105 | &sdp_with_bundle); |
| 2106 | EXPECT_EQ(sdp_with_bundle, message); |
| 2107 | } |
| 2108 | |
| 2109 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2110 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2111 | vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755. |
| 2112 | vcd->set_bandwidth_type("AS"); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2113 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2114 | acd->set_bandwidth(555); |
| 2115 | acd->set_bandwidth_type("TIAS"); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2116 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2117 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2118 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2119 | std::string sdp_with_bandwidth = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2120 | InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2121 | &sdp_with_bandwidth); |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2122 | InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n", |
| 2123 | &sdp_with_bandwidth); |
| 2124 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 2125 | } |
| 2126 | |
| 2127 | // Should default to b=AS if bandwidth_type isn't set. |
| 2128 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) { |
| 2129 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 2130 | vcd->set_bandwidth(100 * 1000); |
| 2131 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 2132 | jdesc_.session_version())); |
| 2133 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 2134 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2135 | InjectAfter("c=IN IP4 74.125.224.39\r\n", "b=AS:100\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2136 | &sdp_with_bandwidth); |
| 2137 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 2138 | } |
| 2139 | |
| 2140 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) { |
| 2141 | std::vector<std::string> transport_options; |
| 2142 | transport_options.push_back(kIceOption1); |
| 2143 | transport_options.push_back(kIceOption3); |
| 2144 | AddIceOptions(kAudioContentName, transport_options); |
| 2145 | transport_options.clear(); |
| 2146 | transport_options.push_back(kIceOption2); |
| 2147 | transport_options.push_back(kIceOption3); |
| 2148 | AddIceOptions(kVideoContentName, transport_options); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2149 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2150 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2151 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2152 | std::string sdp_with_ice_options = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2153 | InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2154 | &sdp_with_ice_options); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2155 | InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2156 | &sdp_with_ice_options); |
| 2157 | EXPECT_EQ(sdp_with_ice_options, message); |
| 2158 | } |
| 2159 | |
| 2160 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2161 | EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2165 | EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2169 | EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) { |
| 2173 | EXPECT_TRUE(TestSerializeRejected(true, false)); |
| 2174 | } |
| 2175 | |
| 2176 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) { |
| 2177 | EXPECT_TRUE(TestSerializeRejected(false, true)); |
| 2178 | } |
| 2179 | |
| 2180 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) { |
| 2181 | EXPECT_TRUE(TestSerializeRejected(true, true)); |
| 2182 | } |
| 2183 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2184 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2185 | bool use_sctpmap = true; |
| 2186 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2187 | JsepSessionDescription jsep_desc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2188 | |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2189 | MakeDescriptionWithoutCandidates(&jsep_desc); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2190 | std::string message = webrtc::SdpSerialize(jsep_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2191 | |
| 2192 | std::string expected_sdp = kSdpString; |
| 2193 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2194 | EXPECT_EQ(message, expected_sdp); |
| 2195 | } |
| 2196 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2197 | void MutateJsepSctpPort(JsepSessionDescription* jdesc, |
| 2198 | const SessionDescription& desc, |
| 2199 | int port) { |
| 2200 | // Take our pre-built session description and change the SCTP port. |
| 2201 | std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone(); |
| 2202 | SctpDataContentDescription* dcdesc = |
| 2203 | mutant->GetContentDescriptionByName(kDataContentName)->as_sctp(); |
| 2204 | dcdesc->set_port(port); |
| 2205 | ASSERT_TRUE( |
| 2206 | jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion)); |
| 2207 | } |
| 2208 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2209 | TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2210 | bool use_sctpmap = true; |
| 2211 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2212 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2213 | MakeDescriptionWithoutCandidates(&jsep_desc); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2214 | |
| 2215 | const int kNewPort = 1234; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2216 | MutateJsepSctpPort(&jsep_desc, desc_, kNewPort); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2217 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2218 | std::string message = webrtc::SdpSerialize(jsep_desc); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2219 | |
| 2220 | std::string expected_sdp = kSdpString; |
| 2221 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2222 | |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 2223 | absl::StrReplaceAll( |
| 2224 | {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}}, |
| 2225 | &expected_sdp); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2226 | |
| 2227 | EXPECT_EQ(expected_sdp, message); |
| 2228 | } |
| 2229 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2230 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) { |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2231 | jdesc_.description()->set_extmap_allow_mixed(true); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2232 | TestSerialize(jdesc_); |
| 2233 | } |
| 2234 | |
| 2235 | TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) { |
| 2236 | cricket::MediaContentDescription* video_desc = |
| 2237 | jdesc_.description()->GetContentDescriptionByName(kVideoContentName); |
| 2238 | ASSERT_TRUE(video_desc); |
| 2239 | cricket::MediaContentDescription* audio_desc = |
| 2240 | jdesc_.description()->GetContentDescriptionByName(kAudioContentName); |
| 2241 | ASSERT_TRUE(audio_desc); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2242 | video_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2243 | cricket::MediaContentDescription::kMedia); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2244 | audio_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2245 | cricket::MediaContentDescription::kMedia); |
| 2246 | TestSerialize(jdesc_); |
| 2247 | } |
| 2248 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2249 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2250 | bool encrypted = false; |
| 2251 | AddExtmap(encrypted); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2252 | JsepSessionDescription desc_with_extmap(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2253 | MakeDescriptionWithoutCandidates(&desc_with_extmap); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2254 | std::string message = webrtc::SdpSerialize(desc_with_extmap); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2255 | |
| 2256 | std::string sdp_with_extmap = kSdpString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2257 | InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap); |
| 2258 | InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2259 | |
| 2260 | EXPECT_EQ(sdp_with_extmap, message); |
| 2261 | } |
| 2262 | |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2263 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) { |
| 2264 | bool encrypted = true; |
| 2265 | AddExtmap(encrypted); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2266 | JsepSessionDescription desc_with_extmap(kDummyType); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2267 | ASSERT_TRUE( |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2268 | desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2269 | TestSerialize(desc_with_extmap); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2270 | } |
| 2271 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2272 | TEST_F(WebRtcSdpTest, SerializeCandidates) { |
| 2273 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); |
wu@webrtc.org | ec9f5fb | 2014-06-24 17:05:10 | [diff] [blame] | 2274 | EXPECT_EQ(std::string(kRawCandidate), message); |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 2275 | |
| 2276 | Candidate candidate_with_ufrag(candidates_.front()); |
| 2277 | candidate_with_ufrag.set_username("ABC"); |
| 2278 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, |
| 2279 | candidate_with_ufrag)); |
| 2280 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2281 | EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); |
honghaiz | a0c44ea | 2016-03-23 23:07:48 | [diff] [blame] | 2282 | |
| 2283 | Candidate candidate_with_network_info(candidates_.front()); |
| 2284 | candidate_with_network_info.set_network_id(1); |
| 2285 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2286 | candidate_with_network_info)); |
| 2287 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2288 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message); |
| 2289 | candidate_with_network_info.set_network_cost(999); |
| 2290 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2291 | candidate_with_network_info)); |
| 2292 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2293 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999", |
| 2294 | message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2295 | } |
| 2296 | |
Zach Stein | b336c27 | 2018-08-09 08:16:13 | [diff] [blame] | 2297 | TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) { |
| 2298 | rtc::SocketAddress address("a.test", 1234); |
| 2299 | cricket::Candidate candidate( |
| 2300 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority, |
| 2301 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 2302 | JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate); |
| 2303 | std::string message = webrtc::SdpSerializeCandidate(jcandidate); |
| 2304 | EXPECT_EQ(std::string(kRawHostnameCandidate), message); |
| 2305 | } |
| 2306 | |
mallinath@webrtc.org | e999bd0 | 2014-08-13 06:05:55 | [diff] [blame] | 2307 | TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 2308 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 2309 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2310 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2311 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2312 | candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 2313 | std::unique_ptr<IceCandidateInterface> jcandidate( |
| 2314 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2315 | |
| 2316 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
| 2317 | EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
| 2318 | } |
| 2319 | |
Taylor Brandstetter | 8206bc0 | 2020-04-02 19:36:38 | [diff] [blame] | 2320 | // Test serializing a TCP candidate that came in with a missing tcptype. This |
| 2321 | // shouldn't happen according to the spec, but our implementation has been |
| 2322 | // accepting this for quite some time, treating it as a passive candidate. |
| 2323 | // |
| 2324 | // So, we should be able to at least convert such candidates to and from SDP. |
| 2325 | // See: bugs.webrtc.org/11423 |
| 2326 | TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) { |
| 2327 | std::string missing_tcptype = |
| 2328 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host"; |
| 2329 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2330 | EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate)); |
| 2331 | |
| 2332 | EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR), |
| 2333 | jcandidate.candidate().tcptype()); |
| 2334 | } |
| 2335 | |
| 2336 | TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) { |
| 2337 | std::string ssltcp = |
| 2338 | "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype " |
| 2339 | "passive"; |
| 2340 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2341 | EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate)); |
| 2342 | |
| 2343 | EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol()); |
| 2344 | } |
| 2345 | |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2346 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) { |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 2347 | cricket::VideoCodec h264_codec = cricket::CreateVideoCodec("H264"); |
magjed | 509e4fe | 2016-11-18 09:34:11 | [diff] [blame] | 2348 | h264_codec.SetParam("profile-level-id", "42e01f"); |
| 2349 | h264_codec.SetParam("level-asymmetry-allowed", "1"); |
| 2350 | h264_codec.SetParam("packetization-mode", "1"); |
| 2351 | video_desc_->AddCodec(h264_codec); |
| 2352 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2353 | jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2354 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2355 | std::string message = webrtc::SdpSerialize(jdesc_); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2356 | size_t after_pt = message.find(" H264/90000"); |
| 2357 | ASSERT_NE(after_pt, std::string::npos); |
| 2358 | size_t before_pt = message.rfind("a=rtpmap:", after_pt); |
| 2359 | ASSERT_NE(before_pt, std::string::npos); |
| 2360 | before_pt += strlen("a=rtpmap:"); |
| 2361 | std::string pt = message.substr(before_pt, after_pt - before_pt); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 2362 | // TODO(hta): Check if payload type `pt` occurs in the m=video line. |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2363 | std::string to_find = "a=fmtp:" + pt + " "; |
| 2364 | size_t fmtp_pos = message.find(to_find); |
| 2365 | ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find; |
Mirko Bonadei | 37ec55e | 2019-01-28 10:43:52 | [diff] [blame] | 2366 | size_t fmtp_endpos = message.find('\n', fmtp_pos); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2367 | ASSERT_NE(std::string::npos, fmtp_endpos); |
| 2368 | std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos); |
| 2369 | EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1")); |
| 2370 | EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1")); |
| 2371 | EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f")); |
hta | 62a216e | 2016-04-15 18:02:14 | [diff] [blame] | 2372 | // Check that there are no spaces after semicolons. |
| 2373 | // https://bugs.webrtc.org/5793 |
| 2374 | EXPECT_EQ(std::string::npos, fmtp_value.find("; ")); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2375 | } |
| 2376 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2377 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2378 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2379 | // Deserialize |
| 2380 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 2381 | // Verify |
| 2382 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2383 | } |
| 2384 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2385 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2386 | JsepSessionDescription jdesc(kDummyType); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2387 | const char kSdpWithoutMline[] = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2388 | "v=0\r\n" |
| 2389 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2390 | "s=-\r\n" |
| 2391 | "t=0 0\r\n" |
| 2392 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2393 | // Deserialize |
| 2394 | EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc)); |
| 2395 | EXPECT_EQ(0u, jdesc.description()->contents().size()); |
| 2396 | } |
| 2397 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2398 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2399 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2400 | std::string sdp_without_carriage_return = kSdpFullString; |
| 2401 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 2402 | // Deserialize |
| 2403 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 2404 | // Verify |
| 2405 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2406 | } |
| 2407 | |
| 2408 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 2409 | // SessionDescription with desc but without candidates. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2410 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2411 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2412 | kSessionVersion)); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2413 | JsepSessionDescription new_jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2414 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 2415 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 2416 | } |
| 2417 | |
| 2418 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 2419 | static const char kSdpNoRtpmapString[] = |
| 2420 | "v=0\r\n" |
| 2421 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2422 | "s=-\r\n" |
| 2423 | "t=0 0\r\n" |
| 2424 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 2425 | // Codec that doesn't appear in the m= line will be ignored. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 2426 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2427 | // The rtpmap line for static payload codec is optional. |
Philipp Hancke | 32c60b8 | 2022-05-31 14:51:23 | [diff] [blame] | 2428 | "a=rtpmap:18 G729/8000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2429 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2430 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2431 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2432 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2433 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 2434 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2435 | AudioCodecs ref_codecs; |
deadbeef | 67cf2c1 | 2016-04-13 17:07:16 | [diff] [blame] | 2436 | // The codecs in the AudioContentDescription should be in the same order as |
| 2437 | // the payload types (<fmt>s) on the m= line. |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 2438 | ref_codecs.push_back(cricket::CreateAudioCodec(0, "PCMU", 8000, 1)); |
| 2439 | ref_codecs.push_back(cricket::CreateAudioCodec(18, "G729", 8000, 1)); |
| 2440 | ref_codecs.push_back(cricket::CreateAudioCodec(103, "ISAC", 16000, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2441 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 2442 | } |
| 2443 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2444 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) { |
| 2445 | static const char kSdpNoRtpmapString[] = |
| 2446 | "v=0\r\n" |
| 2447 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2448 | "s=-\r\n" |
| 2449 | "t=0 0\r\n" |
| 2450 | "m=audio 49232 RTP/AVP 18 103\r\n" |
| 2451 | "a=fmtp:18 annexb=yes\r\n" |
| 2452 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2453 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2454 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2455 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2456 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 2457 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2458 | |
| 2459 | cricket::AudioCodec g729 = audio->codecs()[0]; |
| 2460 | EXPECT_EQ("G729", g729.name); |
| 2461 | EXPECT_EQ(8000, g729.clockrate); |
| 2462 | EXPECT_EQ(18, g729.id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2463 | cricket::CodecParameterMap::iterator found = g729.params.find("annexb"); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2464 | ASSERT_TRUE(found != g729.params.end()); |
| 2465 | EXPECT_EQ(found->second, "yes"); |
| 2466 | |
| 2467 | cricket::AudioCodec isac = audio->codecs()[1]; |
| 2468 | EXPECT_EQ("ISAC", isac.name); |
| 2469 | EXPECT_EQ(103, isac.id); |
| 2470 | EXPECT_EQ(16000, isac.clockrate); |
| 2471 | } |
| 2472 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2473 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 2474 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 2475 | // Add a DTLS a=fingerprint attribute to our session description. |
| 2476 | AddFingerprint(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2477 | JsepSessionDescription new_jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2478 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2479 | jdesc_.session_version())); |
| 2480 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2481 | JsepSessionDescription jdesc_with_fingerprint(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2482 | std::string sdp_with_fingerprint = kSdpString; |
| 2483 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2484 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 2485 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 2486 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 2487 | } |
| 2488 | |
| 2489 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2490 | JsepSessionDescription jdesc_with_bundle(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2491 | std::string sdp_with_bundle = kSdpFullString; |
| 2492 | InjectAfter(kSessionTime, |
| 2493 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 2494 | &sdp_with_bundle); |
| 2495 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 2496 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 2497 | group.AddContentName(kAudioContentName); |
| 2498 | group.AddContentName(kVideoContentName); |
| 2499 | desc_.AddGroup(group); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2500 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2501 | jdesc_.session_version())); |
| 2502 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 2503 | } |
| 2504 | |
| 2505 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2506 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2507 | std::string sdp_with_bandwidth = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2508 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=AS:100\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2509 | &sdp_with_bandwidth); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2510 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=AS:50\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2511 | &sdp_with_bandwidth); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2512 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2513 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2514 | vcd->set_bandwidth(100 * 1000); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2515 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2516 | acd->set_bandwidth(50 * 1000); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2517 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2518 | jdesc_.session_version())); |
| 2519 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2520 | } |
| 2521 | |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2522 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) { |
| 2523 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
| 2524 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2525 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n", |
| 2526 | &sdp_with_bandwidth); |
| 2527 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n", |
| 2528 | &sdp_with_bandwidth); |
| 2529 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2530 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 2531 | vcd->set_bandwidth(100 * 1000); |
| 2532 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
| 2533 | acd->set_bandwidth(50 * 1000); |
| 2534 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 2535 | jdesc_.session_version())); |
| 2536 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2537 | } |
| 2538 | |
Philipp Hancke | fbbfc02 | 2020-07-31 06:30:50 | [diff] [blame] | 2539 | TEST_F(WebRtcSdpTest, |
| 2540 | DeserializeSessionDescriptionWithUnknownBandwidthModifier) { |
| 2541 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
| 2542 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2543 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 2544 | "b=unknown:100000\r\n", &sdp_with_bandwidth); |
| 2545 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 2546 | "b=unknown:50000\r\n", &sdp_with_bandwidth); |
| 2547 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2548 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 2549 | vcd->set_bandwidth(-1); |
| 2550 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
| 2551 | acd->set_bandwidth(-1); |
| 2552 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 2553 | jdesc_.session_version())); |
| 2554 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2555 | } |
| 2556 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2557 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2558 | JsepSessionDescription jdesc_with_ice_options(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2559 | std::string sdp_with_ice_options = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2560 | InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2561 | &sdp_with_ice_options); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2562 | InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2563 | &sdp_with_ice_options); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2564 | InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2565 | &sdp_with_ice_options); |
| 2566 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 2567 | std::vector<std::string> transport_options; |
| 2568 | transport_options.push_back(kIceOption3); |
| 2569 | transport_options.push_back(kIceOption1); |
| 2570 | AddIceOptions(kAudioContentName, transport_options); |
| 2571 | transport_options.clear(); |
| 2572 | transport_options.push_back(kIceOption3); |
| 2573 | transport_options.push_back(kIceOption2); |
| 2574 | AddIceOptions(kVideoContentName, transport_options); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2575 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2576 | jdesc_.session_version())); |
| 2577 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 2578 | } |
| 2579 | |
| 2580 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 2581 | // Remove the original ice-ufrag and ice-pwd |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2582 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2583 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 2584 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 2585 | // Add session level ufrag and pwd |
| 2586 | InjectAfter(kSessionTime, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2587 | "a=ice-pwd:session+level+icepwd\r\n" |
| 2588 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 2589 | &sdp_with_ufrag_pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2590 | // Add media level ufrag and pwd for audio |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2591 | InjectAfter( |
| 2592 | "a=mid:audio_content_name\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2593 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 2594 | &sdp_with_ufrag_pwd); |
| 2595 | // Update the candidate ufrag and pwd to the expected ones. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2596 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag", |
| 2597 | "media+level+icepwd")); |
| 2598 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag", |
| 2599 | "session+level+icepwd")); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2600 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 2601 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 2602 | } |
| 2603 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2604 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2605 | EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2609 | EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2613 | EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 2617 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 2618 | } |
| 2619 | |
| 2620 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 2621 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 2622 | } |
| 2623 | |
| 2624 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 2625 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 2626 | } |
| 2627 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2628 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) { |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2629 | jdesc_.description()->set_extmap_allow_mixed(true); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2630 | std::string sdp_with_extmap_allow_mixed = kSdpFullString; |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2631 | // Deserialize |
| 2632 | JsepSessionDescription jdesc_deserialized(kDummyType); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2633 | ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized)); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2634 | // Verify |
| 2635 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized)); |
| 2636 | } |
| 2637 | |
| 2638 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) { |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2639 | jdesc_.description()->set_extmap_allow_mixed(false); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2640 | std::string sdp_without_extmap_allow_mixed = kSdpFullString; |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2641 | Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2642 | // Deserialize |
| 2643 | JsepSessionDescription jdesc_deserialized(kDummyType); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2644 | ASSERT_TRUE( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2645 | SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized)); |
| 2646 | // Verify |
| 2647 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized)); |
| 2648 | } |
| 2649 | |
| 2650 | TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) { |
| 2651 | cricket::MediaContentDescription* video_desc = |
| 2652 | jdesc_.description()->GetContentDescriptionByName(kVideoContentName); |
| 2653 | ASSERT_TRUE(video_desc); |
| 2654 | cricket::MediaContentDescription* audio_desc = |
| 2655 | jdesc_.description()->GetContentDescriptionByName(kAudioContentName); |
| 2656 | ASSERT_TRUE(audio_desc); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2657 | video_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2658 | cricket::MediaContentDescription::kMedia); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2659 | audio_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2660 | cricket::MediaContentDescription::kMedia); |
| 2661 | |
| 2662 | std::string sdp_with_extmap_allow_mixed = kSdpFullString; |
| 2663 | InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed, |
| 2664 | &sdp_with_extmap_allow_mixed); |
| 2665 | InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed, |
| 2666 | &sdp_with_extmap_allow_mixed); |
| 2667 | |
| 2668 | // Deserialize |
| 2669 | JsepSessionDescription jdesc_deserialized(kDummyType); |
| 2670 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized)); |
| 2671 | // Verify |
| 2672 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized)); |
| 2673 | } |
| 2674 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2675 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 2676 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2677 | |
| 2678 | std::string sdp = kSdpOneCandidate; |
| 2679 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2680 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2681 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2682 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
honghaiz | a0c44ea | 2016-03-23 23:07:48 | [diff] [blame] | 2683 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2684 | |
| 2685 | // Candidate line without generation extension. |
| 2686 | sdp = kSdpOneCandidate; |
| 2687 | Replace(" generation 2", "", &sdp); |
| 2688 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2689 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2690 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2691 | Candidate expected = jcandidate_->candidate(); |
| 2692 | expected.set_generation(0); |
| 2693 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2694 | |
honghaiz | a0c44ea | 2016-03-23 23:07:48 | [diff] [blame] | 2695 | // Candidate with network id and/or cost. |
| 2696 | sdp = kSdpOneCandidate; |
| 2697 | Replace(" generation 2", " generation 2 network-id 2", &sdp); |
| 2698 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2699 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2700 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2701 | expected = jcandidate_->candidate(); |
| 2702 | expected.set_network_id(2); |
| 2703 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2704 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
| 2705 | // Add network cost |
| 2706 | Replace(" network-id 2", " network-id 2 network-cost 9", &sdp); |
| 2707 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2708 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2709 | EXPECT_EQ(9, jcandidate.candidate().network_cost()); |
| 2710 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2711 | sdp = kSdpTcpActiveCandidate; |
| 2712 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2713 | // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 2714 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 2715 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2716 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2717 | kCandidateFoundation1); |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 2718 | std::unique_ptr<IceCandidateInterface> jcandidate_template( |
| 2719 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2720 | EXPECT_TRUE( |
| 2721 | jcandidate.candidate().IsEquivalent(jcandidate_template->candidate())); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2722 | sdp = kSdpTcpPassiveCandidate; |
| 2723 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2724 | sdp = kSdpTcpSOCandidate; |
| 2725 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | // This test verifies the deserialization of candidate-attribute |
David Sanders | 60c588d | 2022-03-19 08:43:10 | [diff] [blame] | 2729 | // as per RFC 5245. Candidate-attribute will be of the format |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2730 | // candidate:<blah>. This format will be used when candidates |
| 2731 | // are trickled. |
| 2732 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 2733 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2734 | |
| 2735 | std::string candidate_attribute = kRawCandidate; |
| 2736 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2737 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2738 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2739 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2740 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 2741 | |
| 2742 | // Candidate line without generation extension. |
| 2743 | candidate_attribute = kRawCandidate; |
| 2744 | Replace(" generation 2", "", &candidate_attribute); |
| 2745 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2746 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2747 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2748 | Candidate expected = jcandidate_->candidate(); |
| 2749 | expected.set_generation(0); |
| 2750 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2751 | |
| 2752 | // Candidate line without candidate: |
| 2753 | candidate_attribute = kRawCandidate; |
| 2754 | Replace("candidate:", "", &candidate_attribute); |
| 2755 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2756 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2757 | // Candidate line with IPV6 address. |
| 2758 | EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate)); |
Zach Stein | b336c27 | 2018-08-09 08:16:13 | [diff] [blame] | 2759 | |
| 2760 | // Candidate line with hostname address. |
| 2761 | EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | // This test verifies that the deserialization of an invalid candidate string |
| 2765 | // fails. |
| 2766 | TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2767 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2768 | |
| 2769 | std::string candidate_attribute = kRawCandidate; |
| 2770 | candidate_attribute.replace(0, 1, "x"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2771 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2772 | |
| 2773 | candidate_attribute = kSdpOneCandidate; |
| 2774 | candidate_attribute.replace(0, 1, "x"); |
| 2775 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2776 | |
| 2777 | candidate_attribute = kRawCandidate; |
| 2778 | candidate_attribute.append("\r\n"); |
| 2779 | candidate_attribute.append(kRawCandidate); |
| 2780 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2781 | |
| 2782 | EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2783 | } |
| 2784 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2785 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2786 | bool use_sctpmap = true; |
| 2787 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2788 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2789 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2790 | |
| 2791 | std::string sdp_with_data = kSdpString; |
| 2792 | sdp_with_data.append(kSdpSctpDataChannelString); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2793 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2794 | |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 2795 | // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString). |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 2796 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2797 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2798 | |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 2799 | // Verify with DTLS/SCTP. |
| 2800 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp), |
| 2801 | kDtlsSctp); |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 2802 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2803 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2804 | |
| 2805 | // Verify with TCP/DTLS/SCTP. |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 2806 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2807 | kTcpDtlsSctp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2808 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2809 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2810 | } |
| 2811 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2812 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2813 | bool use_sctpmap = false; |
| 2814 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2815 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2816 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2817 | |
| 2818 | std::string sdp_with_data = kSdpString; |
| 2819 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2820 | JsepSessionDescription jdesc_output(kDummyType); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2821 | |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 | [diff] [blame] | 2822 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2823 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2824 | } |
| 2825 | |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2826 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2827 | bool use_sctpmap = false; |
| 2828 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2829 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2830 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2831 | |
| 2832 | std::string sdp_with_data = kSdpString; |
| 2833 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2834 | JsepSessionDescription jdesc_output(kDummyType); |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2835 | |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2836 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2837 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2838 | } |
| 2839 | |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 2840 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) { |
| 2841 | bool use_sctpmap = true; |
| 2842 | AddSctpDataChannel(use_sctpmap); |
| 2843 | JsepSessionDescription jdesc(kDummyType); |
| 2844 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
| 2845 | |
| 2846 | std::string sdp = kSdpSessionString; |
| 2847 | sdp += kSdpSctpDataChannelString; |
| 2848 | |
| 2849 | const char needle[] = "m=application "; |
| 2850 | sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus "); |
| 2851 | |
| 2852 | JsepSessionDescription jdesc_output(kDummyType); |
| 2853 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 2854 | |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 2855 | EXPECT_EQ(1u, jdesc_output.description()->contents().size()); |
| 2856 | EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected); |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 2857 | } |
| 2858 | |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2859 | // Helper function to set the max-message-size parameter in the |
| 2860 | // SCTP data codec. |
| 2861 | void MutateJsepSctpMaxMessageSize(const SessionDescription& desc, |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2862 | int new_value, |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2863 | JsepSessionDescription* jdesc) { |
Harald Alvestrand | 8da35a6 | 2019-05-10 07:31:04 | [diff] [blame] | 2864 | std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2865 | SctpDataContentDescription* dcdesc = |
| 2866 | mutant->GetContentDescriptionByName(kDataContentName)->as_sctp(); |
| 2867 | dcdesc->set_max_message_size(new_value); |
Harald Alvestrand | 8da35a6 | 2019-05-10 07:31:04 | [diff] [blame] | 2868 | jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion); |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) { |
| 2872 | bool use_sctpmap = false; |
| 2873 | AddSctpDataChannel(use_sctpmap); |
| 2874 | JsepSessionDescription jdesc(kDummyType); |
| 2875 | std::string sdp_with_data = kSdpString; |
| 2876 | |
| 2877 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
| 2878 | sdp_with_data.append("a=max-message-size:12345\r\n"); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2879 | MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc); |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2880 | JsepSessionDescription jdesc_output(kDummyType); |
| 2881 | |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2882 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2883 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2884 | } |
| 2885 | |
Harald Alvestrand | fbb45bd | 2019-05-15 06:07:47 | [diff] [blame] | 2886 | TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) { |
| 2887 | bool use_sctpmap = false; |
| 2888 | AddSctpDataChannel(use_sctpmap); |
| 2889 | JsepSessionDescription jdesc(kDummyType); |
| 2890 | MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc); |
| 2891 | std::string message = webrtc::SdpSerialize(jdesc); |
| 2892 | EXPECT_NE(std::string::npos, |
| 2893 | message.find("\r\na=max-message-size:12345\r\n")); |
| 2894 | JsepSessionDescription jdesc_output(kDummyType); |
| 2895 | EXPECT_TRUE(SdpDeserialize(message, &jdesc_output)); |
| 2896 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2897 | } |
| 2898 | |
| 2899 | TEST_F(WebRtcSdpTest, |
| 2900 | SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) { |
| 2901 | // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6 |
| 2902 | // The default max message size is 64K. |
| 2903 | bool use_sctpmap = false; |
| 2904 | AddSctpDataChannel(use_sctpmap); |
| 2905 | JsepSessionDescription jdesc(kDummyType); |
| 2906 | MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc); |
| 2907 | std::string message = webrtc::SdpSerialize(jdesc); |
| 2908 | EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:")); |
| 2909 | JsepSessionDescription jdesc_output(kDummyType); |
| 2910 | EXPECT_TRUE(SdpDeserialize(message, &jdesc_output)); |
| 2911 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2912 | } |
| 2913 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2914 | // Test to check the behaviour if sctp-port is specified |
| 2915 | // on the m= line and in a=sctp-port. |
| 2916 | TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2917 | bool use_sctpmap = true; |
| 2918 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2919 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2920 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2921 | |
| 2922 | std::string sdp_with_data = kSdpString; |
| 2923 | // Append m= attributes |
| 2924 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2925 | // Append a=sctp-port attribute |
| 2926 | sdp_with_data.append("a=sctp-port 5000\r\n"); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2927 | JsepSessionDescription jdesc_output(kDummyType); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2928 | |
| 2929 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2930 | } |
| 2931 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2932 | // Test behavior if a=rtpmap occurs in an SCTP section. |
| 2933 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) { |
| 2934 | std::string sdp_with_data = kSdpString; |
| 2935 | // Append m= attributes |
| 2936 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2937 | // Append a=rtpmap attribute |
| 2938 | sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n"); |
| 2939 | JsepSessionDescription jdesc_output(kDummyType); |
| 2940 | // Correct behavior is to ignore the extra attribute. |
| 2941 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2942 | } |
| 2943 | |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 | [diff] [blame] | 2944 | // For crbug/344475. |
| 2945 | TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { |
| 2946 | std::string sdp_with_data = kSdpString; |
| 2947 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2948 | // Remove the "\n" at the end. |
| 2949 | sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2950 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 | [diff] [blame] | 2951 | |
| 2952 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2953 | // No crash is a pass. |
| 2954 | } |
| 2955 | |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2956 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) { |
| 2957 | bool use_sctpmap = true; |
| 2958 | AddSctpDataChannel(use_sctpmap); |
| 2959 | |
| 2960 | // First setup the expected JsepSessionDescription. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2961 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2962 | MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 2963 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2964 | // Then get the deserialized JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 2965 | std::string sdp_with_data = kSdpString; |
| 2966 | sdp_with_data.append(kSdpSctpDataChannelString); |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 2967 | absl::StrReplaceAll( |
| 2968 | {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}}, |
| 2969 | &sdp_with_data); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2970 | JsepSessionDescription jdesc_output(kDummyType); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 2971 | |
| 2972 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2973 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | TEST_F(WebRtcSdpTest, |
| 2977 | DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) { |
| 2978 | bool use_sctpmap = false; |
| 2979 | AddSctpDataChannel(use_sctpmap); |
| 2980 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2981 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2982 | MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2983 | |
| 2984 | // We need to test the deserialized JsepSessionDescription from |
| 2985 | // kSdpSctpDataChannelStringWithSctpPort for |
| 2986 | // draft-ietf-mmusic-sctp-sdp-07 |
| 2987 | // a=sctp-port |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2988 | std::string sdp_with_data = kSdpString; |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2989 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 2990 | absl::StrReplaceAll( |
| 2991 | {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}}, |
| 2992 | &sdp_with_data); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2993 | JsepSessionDescription jdesc_output(kDummyType); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2994 | |
| 2995 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2996 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 2997 | } |
| 2998 | |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 2999 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 3000 | bool use_sctpmap = true; |
| 3001 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3002 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 3003 | SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_); |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3004 | dcd->set_bandwidth(100 * 1000); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3005 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3006 | |
| 3007 | std::string sdp_with_bandwidth = kSdpString; |
| 3008 | sdp_with_bandwidth.append(kSdpSctpDataChannelString); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3009 | InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n", |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3010 | &sdp_with_bandwidth); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3011 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3012 | |
| 3013 | // SCTP has congestion control, so we shouldn't limit the bandwidth |
| 3014 | // as we do for RTP. |
| 3015 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 3016 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 3017 | } |
| 3018 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3019 | class WebRtcSdpExtmapTest : public WebRtcSdpTest, |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 3020 | public ::testing::WithParamInterface<bool> {}; |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3021 | |
| 3022 | TEST_P(WebRtcSdpExtmapTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3023 | DeserializeSessionDescriptionWithSessionLevelExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3024 | bool encrypted = GetParam(); |
| 3025 | TestDeserializeExtmap(true, false, encrypted); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3026 | } |
| 3027 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3028 | TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3029 | bool encrypted = GetParam(); |
| 3030 | TestDeserializeExtmap(false, true, encrypted); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3031 | } |
| 3032 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3033 | TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3034 | bool encrypted = GetParam(); |
| 3035 | TestDeserializeExtmap(true, true, encrypted); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3036 | } |
| 3037 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 3038 | INSTANTIATE_TEST_SUITE_P(Encrypted, |
| 3039 | WebRtcSdpExtmapTest, |
| 3040 | ::testing::Values(false, true)); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3041 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 | [diff] [blame] | 3042 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3043 | JsepSessionDescription jdesc(kDummyType); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 | [diff] [blame] | 3044 | std::string sdp = kSdpFullString; |
| 3045 | sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. |
| 3046 | // Deserialize |
| 3047 | SdpParseError error; |
| 3048 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 3049 | const std::string lastline = "a=ssrc:3 msid:local_stream_1 video_track_id_1"; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 | [diff] [blame] | 3050 | EXPECT_EQ(lastline, error.line); |
| 3051 | EXPECT_EQ("Invalid SDP line.", error.description); |
| 3052 | } |
| 3053 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3054 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 3055 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 3056 | std::string new_sdp = kSdpOneCandidate; |
| 3057 | Replace("udp", "unsupported_transport", &new_sdp); |
| 3058 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 3059 | new_sdp = kSdpOneCandidate; |
| 3060 | Replace("udp", "uDP", &new_sdp); |
| 3061 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 3062 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 3063 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 3064 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 3065 | } |
| 3066 | |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 3067 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3068 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 3069 | EXPECT_TRUE( |
| 3070 | SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3071 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 3072 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 3073 | Candidate ref_candidate = jcandidate_->candidate(); |
| 3074 | ref_candidate.set_username("user_rtp"); |
| 3075 | ref_candidate.set_password("password_rtp"); |
| 3076 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 3077 | } |
| 3078 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3079 | TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3080 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3081 | |
| 3082 | // Deserialize |
| 3083 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
| 3084 | |
| 3085 | // Verify |
| 3086 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3087 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3088 | EXPECT_TRUE(audio->conference_mode()); |
| 3089 | |
| 3090 | cricket::VideoContentDescription* video = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3091 | cricket::GetFirstVideoContentDescription(jdesc.description()); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3092 | EXPECT_TRUE(video->conference_mode()); |
| 3093 | } |
| 3094 | |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3095 | TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3096 | JsepSessionDescription jdesc(kDummyType); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3097 | |
| 3098 | // We tested deserialization already above, so just test that if we serialize |
| 3099 | // and deserialize the flag doesn't disappear. |
| 3100 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3101 | std::string reserialized = webrtc::SdpSerialize(jdesc); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3102 | EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc)); |
| 3103 | |
| 3104 | // Verify. |
| 3105 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3106 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3107 | EXPECT_TRUE(audio->conference_mode()); |
| 3108 | |
| 3109 | cricket::VideoContentDescription* video = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3110 | cricket::GetFirstVideoContentDescription(jdesc.description()); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3111 | EXPECT_TRUE(video->conference_mode()); |
| 3112 | } |
| 3113 | |
Sebastian Jansson | 97321b6 | 2019-07-24 12:01:18 | [diff] [blame] | 3114 | TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) { |
| 3115 | { |
| 3116 | // By default remote estimates are disabled. |
| 3117 | JsepSessionDescription dst(kDummyType); |
| 3118 | SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst); |
| 3119 | EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description()) |
| 3120 | ->remote_estimate()); |
| 3121 | } |
| 3122 | { |
| 3123 | // When remote estimate is enabled, the setting is propagated via SDP. |
| 3124 | cricket::GetFirstVideoContentDescription(jdesc_.description()) |
| 3125 | ->set_remote_estimate(true); |
| 3126 | JsepSessionDescription dst(kDummyType); |
| 3127 | SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst); |
| 3128 | EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description()) |
| 3129 | ->remote_estimate()); |
| 3130 | } |
| 3131 | } |
| 3132 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3133 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 3134 | const char kSdpDestroyer[] = "!@#$%^&"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 | [diff] [blame] | 3135 | const char kSdpEmptyType[] = " =candidate"; |
| 3136 | const char kSdpEqualAsPlus[] = "a+candidate"; |
| 3137 | const char kSdpSpaceAfterEqual[] = "a= candidate"; |
| 3138 | const char kSdpUpperType[] = "A=candidate"; |
| 3139 | const char kSdpEmptyLine[] = ""; |
| 3140 | const char kSdpMissingValue[] = "a="; |
| 3141 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3142 | const char kSdpBrokenFingerprint[] = |
| 3143 | "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3144 | "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3145 | const char kSdpExtraField[] = |
| 3146 | "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3147 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX"; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3148 | const char kSdpMissingSpace[] = |
| 3149 | "a=fingerprint:sha-1" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3150 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 | [diff] [blame] | 3151 | // MD5 is not allowed in fingerprints. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3152 | const char kSdpMd5[] = |
| 3153 | "a=fingerprint:md5 " |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 | [diff] [blame] | 3154 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3155 | |
| 3156 | // Broken session description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3157 | ExpectParseFailure("v=", kSdpDestroyer); |
| 3158 | ExpectParseFailure("o=", kSdpDestroyer); |
| 3159 | ExpectParseFailure("s=-", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3160 | // Broken time description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3161 | ExpectParseFailure("t=", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3162 | |
| 3163 | // Broken media description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3164 | ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39"); |
| 3165 | ExpectParseFailure("m=video", kSdpDestroyer); |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 3166 | ExpectParseFailure("m=", "c=IN IP4 74.125.224.39"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3167 | |
| 3168 | // Invalid lines |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 | [diff] [blame] | 3169 | ExpectParseFailure("a=candidate", kSdpEmptyType); |
| 3170 | ExpectParseFailure("a=candidate", kSdpEqualAsPlus); |
| 3171 | ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual); |
| 3172 | ExpectParseFailure("a=candidate", kSdpUpperType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3173 | |
| 3174 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 3175 | // because it's orthogonal to what we are replacing and hence |
| 3176 | // safe. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 | [diff] [blame] | 3177 | ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint); |
| 3178 | ExpectParseFailure("a=sendrecv", kSdpExtraField); |
| 3179 | ExpectParseFailure("a=sendrecv", kSdpMissingSpace); |
| 3180 | ExpectParseFailure("a=sendrecv", kSdpMd5); |
| 3181 | |
| 3182 | // Empty Line |
| 3183 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine); |
| 3184 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) { |
| 3188 | // ssrc |
| 3189 | ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue"); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3190 | ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3"); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 3191 | // crypto |
| 3192 | ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue "); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3193 | // rtpmap |
| 3194 | ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue "); |
| 3195 | ExpectParseFailure("opus/48000/2", "opus/badvalue/2"); |
| 3196 | ExpectParseFailure("opus/48000/2", "opus/48000/badvalue"); |
| 3197 | // candidate |
| 3198 | ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432"); |
| 3199 | ExpectParseFailure("1 udp 2130706432", "1 udp badvalue"); |
| 3200 | ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue"); |
| 3201 | ExpectParseFailure("rport 2346", "rport badvalue"); |
| 3202 | ExpectParseFailure("rport 2346 generation 2", |
| 3203 | "rport 2346 generation badvalue"); |
| 3204 | // m line |
| 3205 | ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104", |
| 3206 | "m=audio 2345 RTP/SAVPF 111 badvalue 104"); |
| 3207 | |
| 3208 | // bandwidth |
| 3209 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3210 | "b=AS:badvalue\r\n", "b=AS:badvalue"); |
Philipp Hancke | fbbfc02 | 2020-07-31 06:30:50 | [diff] [blame] | 3211 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n", |
| 3212 | "b=AS"); |
| 3213 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n", |
| 3214 | "b=AS:"); |
| 3215 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 3216 | "b=AS:12:34\r\n", "b=AS:12:34"); |
| 3217 | |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3218 | // rtcp-fb |
| 3219 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 3220 | "a=rtcp-fb:badvalue nack\r\n", |
| 3221 | "a=rtcp-fb:badvalue nack"); |
| 3222 | // extmap |
| 3223 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 3224 | "a=extmap:badvalue http://example.com\r\n", |
| 3225 | "a=extmap:badvalue http://example.com"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3229 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3230 | |
| 3231 | const char kSdpWithReorderedPlTypesString[] = |
| 3232 | "v=0\r\n" |
| 3233 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3234 | "s=-\r\n" |
| 3235 | "t=0 0\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 3236 | "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3237 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 3238 | // in the map. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3239 | "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 3240 | "a=rtpmap:104 ISAC/32000\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3241 | |
| 3242 | // Deserialize |
| 3243 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 3244 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3245 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3246 | GetFirstAudioContentDescription(jdesc_output.description()); |
| 3247 | ASSERT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3248 | ASSERT_FALSE(acd->codecs().empty()); |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 3249 | EXPECT_EQ("ISAC", acd->codecs()[0].name); |
| 3250 | EXPECT_EQ(32000, acd->codecs()[0].clockrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3251 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 3252 | } |
| 3253 | |
| 3254 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3255 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3256 | CodecParams params; |
| 3257 | params.max_ptime = 40; |
| 3258 | params.ptime = 30; |
| 3259 | params.min_ptime = 10; |
| 3260 | params.sprop_stereo = 1; |
| 3261 | params.stereo = 1; |
| 3262 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 | [diff] [blame] | 3263 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3264 | TestDeserializeCodecParams(params, &jdesc_output); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3265 | TestSerialize(jdesc_output); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 3269 | const bool kUseWildcard = false; |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3270 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3271 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3272 | TestSerialize(jdesc_output); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 3276 | const bool kUseWildcard = true; |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3277 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3278 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3279 | TestSerialize(jdesc_output); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3283 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3284 | |
| 3285 | const char kSdpWithFmtpString[] = |
| 3286 | "v=0\r\n" |
| 3287 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3288 | "s=-\r\n" |
| 3289 | "t=0 0\r\n" |
| 3290 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3291 | "a=rtpmap:120 VP8/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3292 | "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n"; |
| 3293 | |
| 3294 | // Deserialize |
| 3295 | SdpParseError error; |
Donald Curtis | 144d018 | 2015-05-15 20:14:24 | [diff] [blame] | 3296 | EXPECT_TRUE( |
| 3297 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3298 | |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3299 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3300 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3301 | ASSERT_TRUE(vcd); |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3302 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3303 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 3304 | EXPECT_EQ("VP8", vp8.name); |
| 3305 | EXPECT_EQ(120, vp8.id); |
| 3306 | cricket::CodecParameterMap::iterator found = |
| 3307 | vp8.params.find("x-google-min-bitrate"); |
| 3308 | ASSERT_TRUE(found != vp8.params.end()); |
| 3309 | EXPECT_EQ(found->second, "10"); |
| 3310 | found = vp8.params.find("x-google-max-quantization"); |
| 3311 | ASSERT_TRUE(found != vp8.params.end()); |
| 3312 | EXPECT_EQ(found->second, "40"); |
| 3313 | } |
| 3314 | |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3315 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3316 | JsepSessionDescription jdesc_output(kDummyType); |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3317 | |
| 3318 | const char kSdpWithFmtpString[] = |
| 3319 | "v=0\r\n" |
| 3320 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3321 | "s=-\r\n" |
| 3322 | "t=0 0\r\n" |
| 3323 | "m=video 49170 RTP/AVP 98\r\n" |
| 3324 | "a=rtpmap:98 H264/90000\r\n" |
| 3325 | "a=fmtp:98 profile-level-id=42A01E; " |
| 3326 | "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n"; |
| 3327 | |
| 3328 | // Deserialize. |
| 3329 | SdpParseError error; |
| 3330 | EXPECT_TRUE( |
| 3331 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
| 3332 | |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3333 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3334 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3335 | ASSERT_TRUE(vcd); |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3336 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3337 | cricket::VideoCodec h264 = vcd->codecs()[0]; |
| 3338 | EXPECT_EQ("H264", h264.name); |
| 3339 | EXPECT_EQ(98, h264.id); |
| 3340 | cricket::CodecParameterMap::const_iterator found = |
| 3341 | h264.params.find("profile-level-id"); |
| 3342 | ASSERT_TRUE(found != h264.params.end()); |
| 3343 | EXPECT_EQ(found->second, "42A01E"); |
| 3344 | found = h264.params.find("sprop-parameter-sets"); |
| 3345 | ASSERT_TRUE(found != h264.params.end()); |
| 3346 | EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA=="); |
| 3347 | } |
| 3348 | |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3349 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3350 | JsepSessionDescription jdesc_output(kDummyType); |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3351 | |
| 3352 | const char kSdpWithFmtpString[] = |
| 3353 | "v=0\r\n" |
| 3354 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3355 | "s=-\r\n" |
| 3356 | "t=0 0\r\n" |
| 3357 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3358 | "a=rtpmap:120 VP8/90000\r\n" |
| 3359 | "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3360 | |
| 3361 | // Deserialize |
| 3362 | SdpParseError error; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3363 | EXPECT_TRUE( |
| 3364 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3365 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3366 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3367 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3368 | ASSERT_TRUE(vcd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3369 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3370 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 3371 | EXPECT_EQ("VP8", vp8.name); |
| 3372 | EXPECT_EQ(120, vp8.id); |
| 3373 | cricket::CodecParameterMap::iterator found = |
| 3374 | vp8.params.find("x-google-min-bitrate"); |
| 3375 | ASSERT_TRUE(found != vp8.params.end()); |
| 3376 | EXPECT_EQ(found->second, "10"); |
| 3377 | found = vp8.params.find("x-google-max-quantization"); |
| 3378 | ASSERT_TRUE(found != vp8.params.end()); |
| 3379 | EXPECT_EQ(found->second, "40"); |
| 3380 | } |
| 3381 | |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 3382 | TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) { |
| 3383 | JsepSessionDescription jdesc_output(kDummyType); |
| 3384 | |
| 3385 | const char kSdpWithPacketizationString[] = |
| 3386 | "v=0\r\n" |
| 3387 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3388 | "s=-\r\n" |
| 3389 | "t=0 0\r\n" |
| 3390 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 3391 | "a=rtpmap:111 opus/48000/2\r\n" |
| 3392 | "a=packetization:111 unknownpacketizationattributeforaudio\r\n" |
| 3393 | "m=video 3457 RTP/SAVPF 120 121 122\r\n" |
| 3394 | "a=rtpmap:120 VP8/90000\r\n" |
| 3395 | "a=packetization:120 raw\r\n" |
| 3396 | "a=rtpmap:121 VP9/90000\r\n" |
| 3397 | "a=rtpmap:122 H264/90000\r\n" |
| 3398 | "a=packetization:122 unknownpacketizationattributevalue\r\n"; |
| 3399 | |
| 3400 | SdpParseError error; |
| 3401 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output, |
| 3402 | &error)); |
| 3403 | |
| 3404 | AudioContentDescription* acd = |
| 3405 | GetFirstAudioContentDescription(jdesc_output.description()); |
| 3406 | ASSERT_TRUE(acd); |
| 3407 | ASSERT_THAT(acd->codecs(), testing::SizeIs(1)); |
| 3408 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 3409 | EXPECT_EQ(opus.name, "opus"); |
| 3410 | EXPECT_EQ(opus.id, 111); |
| 3411 | |
| 3412 | const VideoContentDescription* vcd = |
| 3413 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3414 | ASSERT_TRUE(vcd); |
| 3415 | ASSERT_THAT(vcd->codecs(), testing::SizeIs(3)); |
| 3416 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 3417 | EXPECT_EQ(vp8.name, "VP8"); |
| 3418 | EXPECT_EQ(vp8.id, 120); |
| 3419 | EXPECT_EQ(vp8.packetization, "raw"); |
| 3420 | cricket::VideoCodec vp9 = vcd->codecs()[1]; |
| 3421 | EXPECT_EQ(vp9.name, "VP9"); |
| 3422 | EXPECT_EQ(vp9.id, 121); |
| 3423 | EXPECT_EQ(vp9.packetization, absl::nullopt); |
| 3424 | cricket::VideoCodec h264 = vcd->codecs()[2]; |
| 3425 | EXPECT_EQ(h264.name, "H264"); |
| 3426 | EXPECT_EQ(h264.id, 122); |
| 3427 | EXPECT_EQ(h264.packetization, absl::nullopt); |
| 3428 | } |
| 3429 | |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3430 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3431 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3432 | |
| 3433 | cricket::AudioCodecs codecs = acd->codecs(); |
| 3434 | codecs[0].params["unknown-future-parameter"] = "SomeFutureValue"; |
| 3435 | acd->set_codecs(codecs); |
| 3436 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3437 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3438 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3439 | std::string message = webrtc::SdpSerialize(jdesc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3440 | std::string sdp_with_fmtp = kSdpFullString; |
| 3441 | InjectAfter("a=rtpmap:111 opus/48000/2\r\n", |
| 3442 | "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n", |
| 3443 | &sdp_with_fmtp); |
| 3444 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3445 | } |
| 3446 | |
| 3447 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3448 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3449 | |
| 3450 | cricket::AudioCodecs codecs = acd->codecs(); |
| 3451 | codecs[0].params["stereo"] = "1"; |
| 3452 | acd->set_codecs(codecs); |
| 3453 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3454 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3455 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3456 | std::string message = webrtc::SdpSerialize(jdesc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3457 | std::string sdp_with_fmtp = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3458 | InjectAfter("a=rtpmap:111 opus/48000/2\r\n", "a=fmtp:111 stereo=1\r\n", |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3459 | &sdp_with_fmtp); |
| 3460 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3461 | } |
| 3462 | |
| 3463 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3464 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3465 | |
| 3466 | cricket::AudioCodecs codecs = acd->codecs(); |
| 3467 | codecs[0].params["ptime"] = "20"; |
| 3468 | codecs[0].params["maxptime"] = "120"; |
| 3469 | acd->set_codecs(codecs); |
| 3470 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3471 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3472 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3473 | std::string message = webrtc::SdpSerialize(jdesc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3474 | std::string sdp_with_fmtp = kSdpFullString; |
| 3475 | InjectAfter("a=rtpmap:104 ISAC/32000\r\n", |
| 3476 | "a=maxptime:120\r\n" // No comma here. String merging! |
| 3477 | "a=ptime:20\r\n", |
| 3478 | &sdp_with_fmtp); |
| 3479 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3480 | } |
| 3481 | |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 3482 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) { |
| 3483 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
| 3484 | |
| 3485 | cricket::AudioCodecs codecs = acd->codecs(); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 3486 | cricket::AudioCodec dtmf = |
| 3487 | cricket::CreateAudioCodec(105, "telephone-event", 8000, 1); |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 3488 | dtmf.params[""] = "0-15"; |
| 3489 | codecs.push_back(dtmf); |
| 3490 | acd->set_codecs(codecs); |
| 3491 | |
| 3492 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 3493 | jdesc_.session_version())); |
| 3494 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 3495 | std::string sdp_with_fmtp = kSdpFullString; |
| 3496 | InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp); |
| 3497 | InjectAfter( |
| 3498 | "a=rtpmap:104 ISAC/32000\r\n", |
| 3499 | "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging! |
| 3500 | "a=fmtp:105 0-15\r\n", |
| 3501 | &sdp_with_fmtp); |
| 3502 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3503 | } |
| 3504 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3505 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3506 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3507 | |
| 3508 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 3509 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 3510 | vcd->set_codecs(codecs); |
| 3511 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3512 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3513 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3514 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3515 | std::string sdp_with_fmtp = kSdpFullString; |
| 3516 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3517 | "a=fmtp:120 x-google-min-bitrate=10\r\n", &sdp_with_fmtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3518 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3519 | } |
| 3520 | |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 3521 | TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) { |
| 3522 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 3523 | |
| 3524 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 3525 | codecs[0].packetization = "raw"; |
| 3526 | vcd->set_codecs(codecs); |
| 3527 | |
| 3528 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 3529 | jdesc_.session_version())); |
| 3530 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 3531 | std::string sdp_with_packetization = kSdpFullString; |
| 3532 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n", |
| 3533 | &sdp_with_packetization); |
| 3534 | EXPECT_EQ(sdp_with_packetization, message); |
| 3535 | } |
| 3536 | |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 3537 | TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) { |
| 3538 | // Deserialize the baseline description, making sure it's ICE full. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3539 | JsepSessionDescription jdesc_with_icelite(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3540 | std::string sdp_with_icelite = kSdpFullString; |
| 3541 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 3542 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 3543 | const cricket::TransportInfo* tinfo1 = |
| 3544 | desc->GetTransportInfoByName("audio_content_name"); |
| 3545 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 3546 | const cricket::TransportInfo* tinfo2 = |
| 3547 | desc->GetTransportInfoByName("video_content_name"); |
| 3548 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 3549 | |
| 3550 | // Add "a=ice-lite" and deserialize, making sure it's ICE lite. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3551 | InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3552 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 3553 | desc = jdesc_with_icelite.description(); |
| 3554 | const cricket::TransportInfo* atinfo = |
| 3555 | desc->GetTransportInfoByName("audio_content_name"); |
| 3556 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 3557 | const cricket::TransportInfo* vtinfo = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3558 | desc->GetTransportInfoByName("video_content_name"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3559 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 3560 | |
| 3561 | // Now that we know deserialization works, we can use TestSerialize to test |
| 3562 | // serialization. |
| 3563 | TestSerialize(jdesc_with_icelite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 3567 | // correctly in the output SDP. |
| 3568 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 3569 | std::string sdp_with_data = kSdpString; |
| 3570 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3571 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3572 | |
| 3573 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3574 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3575 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3576 | |
| 3577 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 3578 | AddFingerprint(); |
| 3579 | TransportInfo audio_transport_info = |
| 3580 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 3581 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3582 | audio_transport_info.description.connection_role); |
| 3583 | audio_transport_info.description.connection_role = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3584 | cricket::CONNECTIONROLE_ACTIVE; |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3585 | |
| 3586 | TransportInfo video_transport_info = |
| 3587 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 3588 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3589 | video_transport_info.description.connection_role); |
| 3590 | video_transport_info.description.connection_role = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3591 | cricket::CONNECTIONROLE_ACTIVE; |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3592 | |
| 3593 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 3594 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 3595 | |
| 3596 | desc_.AddTransportInfo(audio_transport_info); |
| 3597 | desc_.AddTransportInfo(video_transport_info); |
| 3598 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3599 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3600 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3601 | std::string message = webrtc::SdpSerialize(jdesc_); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3602 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3603 | |
| 3604 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3605 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup); |
| 3606 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup); |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 3607 | // Now adding `setup` attribute. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3608 | InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3609 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 3610 | } |
| 3611 | |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 | [diff] [blame] | 3612 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributeActpass) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3613 | JsepSessionDescription jdesc_with_dtlssetup(kDummyType); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3614 | std::string sdp_with_dtlssetup = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3615 | InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3616 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 3617 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 3618 | const cricket::TransportInfo* atinfo = |
| 3619 | desc->GetTransportInfoByName("audio_content_name"); |
| 3620 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3621 | atinfo->description.connection_role); |
| 3622 | const cricket::TransportInfo* vtinfo = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3623 | desc->GetTransportInfoByName("video_content_name"); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3624 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3625 | vtinfo->description.connection_role); |
| 3626 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3627 | |
Harald Alvestrand | efece42 | 2021-08-19 09:12:51 | [diff] [blame] | 3628 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributeActive) { |
| 3629 | JsepSessionDescription jdesc_with_dtlssetup(kDummyType); |
| 3630 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3631 | InjectAfter(kSessionTime, "a=setup:active\r\n", &sdp_with_dtlssetup); |
| 3632 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 3633 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 3634 | const cricket::TransportInfo* atinfo = |
| 3635 | desc->GetTransportInfoByName("audio_content_name"); |
| 3636 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, |
| 3637 | atinfo->description.connection_role); |
| 3638 | const cricket::TransportInfo* vtinfo = |
| 3639 | desc->GetTransportInfoByName("video_content_name"); |
| 3640 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, |
| 3641 | vtinfo->description.connection_role); |
| 3642 | } |
| 3643 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttributePassive) { |
| 3644 | JsepSessionDescription jdesc_with_dtlssetup(kDummyType); |
| 3645 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3646 | InjectAfter(kSessionTime, "a=setup:passive\r\n", &sdp_with_dtlssetup); |
| 3647 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 3648 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 3649 | const cricket::TransportInfo* atinfo = |
| 3650 | desc->GetTransportInfoByName("audio_content_name"); |
| 3651 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 3652 | atinfo->description.connection_role); |
| 3653 | const cricket::TransportInfo* vtinfo = |
| 3654 | desc->GetTransportInfoByName("video_content_name"); |
| 3655 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 3656 | vtinfo->description.connection_role); |
| 3657 | } |
| 3658 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3659 | // Verifies that the order of the serialized m-lines follows the order of the |
| 3660 | // ContentInfo in SessionDescription, and vise versa for deserialization. |
| 3661 | TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3662 | JsepSessionDescription jdesc(kDummyType); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3663 | const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString, |
| 3664 | kSdpSctpDataChannelString}; |
| 3665 | const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO, |
| 3666 | cricket::MEDIA_TYPE_VIDEO, |
| 3667 | cricket::MEDIA_TYPE_DATA}; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3668 | |
| 3669 | // Verifies all 6 permutations. |
| 3670 | for (size_t i = 0; i < 6; ++i) { |
| 3671 | size_t media_content_in_sdp[3]; |
| 3672 | // The index of the first media content. |
| 3673 | media_content_in_sdp[0] = i / 2; |
| 3674 | // The index of the second media content. |
| 3675 | media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3; |
| 3676 | // The index of the third media content. |
| 3677 | media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3; |
| 3678 | |
| 3679 | std::string sdp_string = kSdpSessionString; |
| 3680 | for (size_t i = 0; i < 3; ++i) |
| 3681 | sdp_string += media_content_sdps[media_content_in_sdp[i]]; |
| 3682 | |
| 3683 | EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc)); |
| 3684 | cricket::SessionDescription* desc = jdesc.description(); |
| 3685 | EXPECT_EQ(3u, desc->contents().size()); |
| 3686 | |
| 3687 | for (size_t i = 0; i < 3; ++i) { |
| 3688 | const cricket::MediaContentDescription* mdesc = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3689 | desc->contents()[i].media_description(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3690 | EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 3691 | } |
| 3692 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3693 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3694 | EXPECT_EQ(sdp_string, serialized_sdp); |
| 3695 | } |
| 3696 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3697 | |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3698 | TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) { |
| 3699 | MakeBundleOnlyDescription(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3700 | JsepSessionDescription deserialized_description(kDummyType); |
deadbeef | 12771a1 | 2017-01-03 21:53:47 | [diff] [blame] | 3701 | ASSERT_TRUE( |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3702 | SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description)); |
| 3703 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3704 | } |
| 3705 | |
deadbeef | 12771a1 | 2017-01-03 21:53:47 | [diff] [blame] | 3706 | // The semantics of "a=bundle-only" are only defined when it's used in |
| 3707 | // combination with a 0 port on the m= line. We should ignore it if used with a |
| 3708 | // nonzero port. |
| 3709 | TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) { |
| 3710 | // Make the base bundle-only description but unset the bundle-only flag. |
| 3711 | MakeBundleOnlyDescription(); |
| 3712 | jdesc_.description()->contents()[1].bundle_only = false; |
| 3713 | |
| 3714 | std::string modified_sdp = kBundleOnlySdpFullString; |
| 3715 | Replace("m=video 0", "m=video 9", &modified_sdp); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3716 | JsepSessionDescription deserialized_description(kDummyType); |
deadbeef | 12771a1 | 2017-01-03 21:53:47 | [diff] [blame] | 3717 | ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description)); |
| 3718 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) { |
| 3722 | MakeBundleOnlyDescription(); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3723 | TestSerialize(jdesc_); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3724 | } |
| 3725 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3726 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) { |
| 3727 | MakePlanBDescription(); |
| 3728 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3729 | JsepSessionDescription deserialized_description(kDummyType); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3730 | EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description)); |
| 3731 | |
| 3732 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3733 | } |
| 3734 | |
| 3735 | TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) { |
| 3736 | MakePlanBDescription(); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3737 | TestSerialize(jdesc_); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) { |
| 3741 | MakeUnifiedPlanDescription(); |
| 3742 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3743 | JsepSessionDescription deserialized_description(kDummyType); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 | [diff] [blame] | 3744 | EXPECT_TRUE( |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3745 | SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); |
| 3746 | |
| 3747 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3748 | } |
| 3749 | |
| 3750 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { |
| 3751 | MakeUnifiedPlanDescription(); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3752 | TestSerialize(jdesc_); |
| 3753 | } |
| 3754 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3755 | // This tests deserializing a Unified Plan SDP that is compatible with both |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 3756 | // Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc |
| 3757 | // msid" lines and "a=msid " lines. It tests the case for audio/video tracks |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3758 | // with no stream ids and multiple stream ids. For parsing this, the Unified |
| 3759 | // Plan a=msid lines should take priority, because the Plan B style a=ssrc msid |
| 3760 | // lines do not support multiple stream ids and no stream ids. |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 3761 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) { |
| 3762 | // Create both msid lines for Plan B and Unified Plan support. |
| 3763 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3764 | cricket::kMsidSignalingMediaSection | |
| 3765 | cricket::kMsidSignalingSsrcAttribute); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3766 | |
| 3767 | JsepSessionDescription deserialized_description(kDummyType); |
| 3768 | EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid, |
| 3769 | &deserialized_description)); |
| 3770 | |
| 3771 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
Henrik Boström | 5b14778 | 2018-12-04 10:25:05 | [diff] [blame] | 3772 | EXPECT_EQ(cricket::kMsidSignalingMediaSection | |
| 3773 | cricket::kMsidSignalingSsrcAttribute, |
| 3774 | deserialized_description.description()->msid_signaling()); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3775 | } |
| 3776 | |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 3777 | // Tests the serialization of a Unified Plan SDP that is compatible for both |
| 3778 | // Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc |
| 3779 | // msid" lines and "a=msid " lines. It tests the case for no stream ids and |
| 3780 | // multiple stream ids. |
| 3781 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) { |
| 3782 | // Create both msid lines for Plan B and Unified Plan support. |
| 3783 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3784 | cricket::kMsidSignalingMediaSection | |
| 3785 | cricket::kMsidSignalingSsrcAttribute); |
| 3786 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc_); |
| 3787 | // We explicitly test that the serialized SDP string is equal to the hard |
| 3788 | // coded SDP string. This is necessary, because in the parser "a=msid" lines |
| 3789 | // take priority over "a=ssrc msid" lines. This means if we just used |
| 3790 | // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines, |
| 3791 | // and still pass, because the deserialized version would be the same. |
| 3792 | EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp); |
| 3793 | } |
| 3794 | |
| 3795 | // Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines |
| 3796 | // that signal stream IDs) is deserialized appropriately. It tests the case for |
| 3797 | // no stream ids and multiple stream ids. |
| 3798 | TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) { |
| 3799 | // Only create a=msid lines for strictly Unified Plan stream ID support. |
| 3800 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3801 | cricket::kMsidSignalingMediaSection); |
| 3802 | |
| 3803 | JsepSessionDescription deserialized_description(kDummyType); |
| 3804 | std::string unified_plan_sdp_string = |
| 3805 | kUnifiedPlanSdpFullStringWithSpecialMsid; |
| 3806 | RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string); |
| 3807 | EXPECT_TRUE( |
| 3808 | SdpDeserialize(unified_plan_sdp_string, &deserialized_description)); |
| 3809 | |
| 3810 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3811 | } |
| 3812 | |
| 3813 | // Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines |
| 3814 | // that signal stream IDs) is serialized appropriately. It tests the case for no |
| 3815 | // stream ids and multiple stream ids. |
| 3816 | TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) { |
| 3817 | // Only create a=msid lines for strictly Unified Plan stream ID support. |
| 3818 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3819 | cricket::kMsidSignalingMediaSection); |
| 3820 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3821 | TestSerialize(jdesc_); |
| 3822 | } |
| 3823 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 3824 | // This tests that a Unified Plan SDP with no a=ssrc lines is |
| 3825 | // serialized/deserialized appropriately. In this case the |
| 3826 | // MediaContentDescription will contain a StreamParams object that doesn't have |
| 3827 | // any SSRCs. Vice versa, this will be created upon deserializing an SDP with no |
| 3828 | // SSRC lines. |
| 3829 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) { |
| 3830 | MakeUnifiedPlanDescription(); |
| 3831 | RemoveSsrcSignalingFromStreamParams(); |
| 3832 | std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString; |
| 3833 | RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string); |
| 3834 | |
| 3835 | JsepSessionDescription deserialized_description(kDummyType); |
| 3836 | EXPECT_TRUE( |
| 3837 | SdpDeserialize(unified_plan_sdp_string, &deserialized_description)); |
| 3838 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3839 | } |
| 3840 | |
| 3841 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) { |
| 3842 | MakeUnifiedPlanDescription(); |
| 3843 | RemoveSsrcSignalingFromStreamParams(); |
| 3844 | |
| 3845 | TestSerialize(jdesc_); |
| 3846 | } |
| 3847 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3848 | TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) { |
| 3849 | JsepSessionDescription jsep_desc(kDummyType); |
| 3850 | ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc)); |
| 3851 | EXPECT_EQ(0, jsep_desc.description()->msid_signaling()); |
| 3852 | } |
| 3853 | |
| 3854 | TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) { |
| 3855 | JsepSessionDescription jsep_desc(kDummyType); |
| 3856 | std::string sdp = kSdpSessionString; |
| 3857 | sdp += kSdpSctpDataChannelString; |
| 3858 | ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 3859 | EXPECT_EQ(0, jsep_desc.description()->msid_signaling()); |
| 3860 | } |
| 3861 | |
| 3862 | TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) { |
| 3863 | JsepSessionDescription jsep_desc(kDummyType); |
| 3864 | ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc)); |
| 3865 | EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute, |
| 3866 | jsep_desc.description()->msid_signaling()); |
| 3867 | } |
| 3868 | |
| 3869 | TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) { |
| 3870 | JsepSessionDescription jsep_desc(kDummyType); |
| 3871 | ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc)); |
| 3872 | EXPECT_EQ(cricket::kMsidSignalingMediaSection, |
| 3873 | jsep_desc.description()->msid_signaling()); |
| 3874 | } |
| 3875 | |
| 3876 | const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1"; |
| 3877 | const char kSsrcAttributeMsidLine[] = |
| 3878 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1"; |
| 3879 | |
| 3880 | TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) { |
| 3881 | jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection); |
| 3882 | std::string sdp = webrtc::SdpSerialize(jdesc_); |
| 3883 | |
| 3884 | EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine)); |
| 3885 | EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine)); |
| 3886 | } |
| 3887 | |
| 3888 | TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) { |
| 3889 | jdesc_.description()->set_msid_signaling( |
| 3890 | cricket::kMsidSignalingSsrcAttribute); |
| 3891 | std::string sdp = webrtc::SdpSerialize(jdesc_); |
| 3892 | |
| 3893 | EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine)); |
| 3894 | EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine)); |
| 3895 | } |
| 3896 | |
| 3897 | TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) { |
| 3898 | jdesc_.description()->set_msid_signaling( |
| 3899 | cricket::kMsidSignalingMediaSection | |
| 3900 | cricket::kMsidSignalingSsrcAttribute); |
| 3901 | std::string sdp = webrtc::SdpSerialize(jdesc_); |
| 3902 | |
| 3903 | EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine)); |
| 3904 | EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3905 | } |
deadbeef | 7e146cb | 2016-09-28 17:04:34 | [diff] [blame] | 3906 | |
deadbeef | b236257 | 2016-12-14 00:37:06 | [diff] [blame] | 3907 | // Regression test for integer overflow bug: |
| 3908 | // https://bugs.chromium.org/p/chromium/issues/detail?id=648071 |
| 3909 | TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) { |
deadbeef | b236257 | 2016-12-14 00:37:06 | [diff] [blame] | 3910 | // Bandwidth attribute is the max signed 32-bit int, which will get |
| 3911 | // multiplied by 1000 and cause int overflow if not careful. |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3912 | static const char kSdpWithLargeBandwidth[] = |
deadbeef | b236257 | 2016-12-14 00:37:06 | [diff] [blame] | 3913 | "v=0\r\n" |
| 3914 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3915 | "s=-\r\n" |
| 3916 | "t=0 0\r\n" |
| 3917 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3918 | "b=AS:2147483647\r\n" |
| 3919 | "foo=fail\r\n"; |
| 3920 | |
| 3921 | ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail"); |
| 3922 | } |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3923 | |
deadbeef | bc88c6b | 2017-08-02 18:26:34 | [diff] [blame] | 3924 | // Similar to the above, except that negative values are illegal, not just |
| 3925 | // error-prone as large values are. |
| 3926 | // https://bugs.chromium.org/p/chromium/issues/detail?id=675361 |
| 3927 | TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) { |
| 3928 | static const char kSdpWithNegativeBandwidth[] = |
| 3929 | "v=0\r\n" |
| 3930 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3931 | "s=-\r\n" |
| 3932 | "t=0 0\r\n" |
| 3933 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3934 | "b=AS:-1000\r\n"; |
| 3935 | |
| 3936 | ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000"); |
| 3937 | } |
| 3938 | |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3939 | // An exception to the above rule: a value of -1 for b=AS should just be |
| 3940 | // ignored, resulting in "kAutoBandwidth" in the deserialized object. |
| 3941 | // Applications historically may be using "b=AS:-1" to mean "no bandwidth |
| 3942 | // limit", but this is now what ommitting the attribute entirely will do, so |
| 3943 | // ignoring it will have the intended effect. |
| 3944 | TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) { |
| 3945 | static const char kSdpWithBandwidthOfNegativeOne[] = |
| 3946 | "v=0\r\n" |
| 3947 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3948 | "s=-\r\n" |
| 3949 | "t=0 0\r\n" |
| 3950 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3951 | "b=AS:-1\r\n"; |
| 3952 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3953 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3954 | EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output)); |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3955 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3956 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3957 | ASSERT_TRUE(vcd); |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3958 | EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth()); |
| 3959 | } |
| 3960 | |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3961 | // Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only |
| 3962 | // the "a=ice-ufrag"/"a=ice-pwd" attributes are used. |
| 3963 | // Regression test for: |
| 3964 | // https://bugs.chromium.org/p/chromium/issues/detail?id=681286 |
| 3965 | TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) { |
| 3966 | // Important piece is "ufrag foo pwd bar". |
| 3967 | static const char kSdpWithIceCredentialsInCandidateString[] = |
| 3968 | "v=0\r\n" |
| 3969 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3970 | "s=-\r\n" |
| 3971 | "t=0 0\r\n" |
| 3972 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 3973 | "c=IN IP4 0.0.0.0\r\n" |
| 3974 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 3975 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 3976 | "a=rtpmap:111 opus/48000/2\r\n" |
| 3977 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 3978 | "generation 2 ufrag foo pwd bar\r\n"; |
| 3979 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3980 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3981 | EXPECT_TRUE( |
| 3982 | SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output)); |
| 3983 | const IceCandidateCollection* candidates = jdesc_output.candidates(0); |
| 3984 | ASSERT_NE(nullptr, candidates); |
Mirko Bonadei | e12c1fe | 2018-07-03 10:53:23 | [diff] [blame] | 3985 | ASSERT_EQ(1U, candidates->count()); |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3986 | cricket::Candidate c = candidates->at(0)->candidate(); |
| 3987 | EXPECT_EQ("ufrag_voice", c.username()); |
| 3988 | EXPECT_EQ("pwd_voice", c.password()); |
| 3989 | } |
deadbeef | 90f1e1e | 2017-02-10 20:35:05 | [diff] [blame] | 3990 | |
Johannes Kron | 211856b | 2018-09-06 10:12:28 | [diff] [blame] | 3991 | // Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are |
| 3992 | // ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used. |
| 3993 | // Regression test for: |
| 3994 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=9712 |
| 3995 | TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) { |
| 3996 | static const char kSdpWithFooIceCredentials[] = |
| 3997 | "v=0\r\n" |
| 3998 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3999 | "s=-\r\n" |
| 4000 | "t=0 0\r\n" |
| 4001 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4002 | "c=IN IP4 0.0.0.0\r\n" |
| 4003 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 4004 | "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n" |
| 4005 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 4006 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4007 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 4008 | "generation 2\r\n"; |
| 4009 | |
| 4010 | JsepSessionDescription jdesc_output(kDummyType); |
| 4011 | EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output)); |
| 4012 | const IceCandidateCollection* candidates = jdesc_output.candidates(0); |
| 4013 | ASSERT_NE(nullptr, candidates); |
| 4014 | ASSERT_EQ(1U, candidates->count()); |
| 4015 | cricket::Candidate c = candidates->at(0)->candidate(); |
| 4016 | EXPECT_EQ("ufrag_voice", c.username()); |
| 4017 | EXPECT_EQ("pwd_voice", c.password()); |
| 4018 | } |
| 4019 | |
deadbeef | 90f1e1e | 2017-02-10 20:35:05 | [diff] [blame] | 4020 | // Test that SDP with an invalid port number in "a=candidate" lines is |
| 4021 | // rejected, without crashing. |
| 4022 | // Regression test for: |
| 4023 | // https://bugs.chromium.org/p/chromium/issues/detail?id=677029 |
| 4024 | TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) { |
| 4025 | static const char kSdpWithInvalidCandidatePort[] = |
| 4026 | "v=0\r\n" |
| 4027 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4028 | "s=-\r\n" |
| 4029 | "t=0 0\r\n" |
| 4030 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4031 | "c=IN IP4 0.0.0.0\r\n" |
| 4032 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 4033 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 4034 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4035 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host " |
| 4036 | "generation 2 raddr 192.168.1.1 rport 87654321\r\n"; |
| 4037 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4038 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | 90f1e1e | 2017-02-10 20:35:05 | [diff] [blame] | 4039 | EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output)); |
| 4040 | } |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4041 | |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4042 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithStreamIdAndTrackId) { |
| 4043 | std::string sdp = |
| 4044 | "v=0\r\n" |
| 4045 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4046 | "s=-\r\n" |
| 4047 | "t=0 0\r\n" |
| 4048 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4049 | "c=IN IP4 0.0.0.0\r\n" |
| 4050 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4051 | "a=msid:stream_id track_id\r\n"; |
| 4052 | |
| 4053 | JsepSessionDescription jdesc_output(kDummyType); |
| 4054 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4055 | auto stream = jdesc_output.description() |
| 4056 | ->contents()[0] |
| 4057 | .media_description() |
| 4058 | ->streams()[0]; |
| 4059 | ASSERT_EQ(stream.stream_ids().size(), 1u); |
| 4060 | EXPECT_EQ(stream.stream_ids()[0], "stream_id"); |
| 4061 | EXPECT_EQ(stream.id, "track_id"); |
| 4062 | } |
| 4063 | |
| 4064 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithEmptyStreamIdAndTrackId) { |
| 4065 | std::string sdp = |
| 4066 | "v=0\r\n" |
| 4067 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4068 | "s=-\r\n" |
| 4069 | "t=0 0\r\n" |
| 4070 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4071 | "c=IN IP4 0.0.0.0\r\n" |
| 4072 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4073 | "a=msid:- track_id\r\n"; |
| 4074 | |
| 4075 | JsepSessionDescription jdesc_output(kDummyType); |
| 4076 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4077 | auto stream = jdesc_output.description() |
| 4078 | ->contents()[0] |
| 4079 | .media_description() |
| 4080 | ->streams()[0]; |
| 4081 | ASSERT_EQ(stream.stream_ids().size(), 0u); |
| 4082 | EXPECT_EQ(stream.id, "track_id"); |
| 4083 | } |
| 4084 | |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4085 | // Test that "a=msid" with a missing track ID is rejected and doesn't crash. |
| 4086 | // Regression test for: |
| 4087 | // https://bugs.chromium.org/p/chromium/issues/detail?id=686405 |
| 4088 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) { |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4089 | std::string sdp = |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4090 | "v=0\r\n" |
| 4091 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4092 | "s=-\r\n" |
| 4093 | "t=0 0\r\n" |
| 4094 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4095 | "c=IN IP4 0.0.0.0\r\n" |
| 4096 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4097 | "a=msid:stream_id \r\n"; |
| 4098 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4099 | JsepSessionDescription jdesc_output(kDummyType); |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4100 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4101 | } |
| 4102 | |
Philipp Hancke | b493db9 | 2022-12-08 11:46:20 | [diff] [blame] | 4103 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutColon) { |
| 4104 | std::string sdp = |
| 4105 | "v=0\r\n" |
| 4106 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4107 | "s=-\r\n" |
| 4108 | "t=0 0\r\n" |
| 4109 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4110 | "c=IN IP4 0.0.0.0\r\n" |
| 4111 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4112 | "a=msid\r\n"; |
| 4113 | |
| 4114 | JsepSessionDescription jdesc_output(kDummyType); |
| 4115 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); |
| 4116 | } |
| 4117 | |
| 4118 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAttributes) { |
| 4119 | std::string sdp = |
| 4120 | "v=0\r\n" |
| 4121 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4122 | "s=-\r\n" |
| 4123 | "t=0 0\r\n" |
| 4124 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4125 | "c=IN IP4 0.0.0.0\r\n" |
| 4126 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4127 | "a=msid:\r\n"; |
| 4128 | |
| 4129 | JsepSessionDescription jdesc_output(kDummyType); |
| 4130 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); |
| 4131 | } |
| 4132 | |
| 4133 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithTooManySpaces) { |
| 4134 | std::string sdp = |
| 4135 | "v=0\r\n" |
| 4136 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4137 | "s=-\r\n" |
| 4138 | "t=0 0\r\n" |
| 4139 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4140 | "c=IN IP4 0.0.0.0\r\n" |
| 4141 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4142 | "a=msid:stream_id track_id bogus\r\n"; |
| 4143 | |
| 4144 | JsepSessionDescription jdesc_output(kDummyType); |
| 4145 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); |
| 4146 | } |
| 4147 | |
| 4148 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithDifferentTrackIds) { |
| 4149 | std::string sdp = |
| 4150 | "v=0\r\n" |
| 4151 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4152 | "s=-\r\n" |
| 4153 | "t=0 0\r\n" |
| 4154 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4155 | "c=IN IP4 0.0.0.0\r\n" |
| 4156 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4157 | "a=msid:stream_id track_id\r\n" |
| 4158 | "a=msid:stream_id2 track_id2\r\n"; |
| 4159 | |
| 4160 | JsepSessionDescription jdesc_output(kDummyType); |
| 4161 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); |
| 4162 | } |
| 4163 | |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4164 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppData) { |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4165 | std::string sdp = |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4166 | "v=0\r\n" |
| 4167 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4168 | "s=-\r\n" |
| 4169 | "t=0 0\r\n" |
| 4170 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4171 | "c=IN IP4 0.0.0.0\r\n" |
| 4172 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4173 | "a=msid:stream_id\r\n"; |
| 4174 | |
| 4175 | JsepSessionDescription jdesc_output(kDummyType); |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4176 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4177 | auto stream = jdesc_output.description() |
| 4178 | ->contents()[0] |
| 4179 | .media_description() |
| 4180 | ->streams()[0]; |
| 4181 | ASSERT_EQ(stream.stream_ids().size(), 1u); |
| 4182 | EXPECT_EQ(stream.stream_ids()[0], "stream_id"); |
| 4183 | // Track id is randomly generated. |
| 4184 | EXPECT_NE(stream.id, ""); |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataTwoStreams) { |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4188 | std::string sdp = |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4189 | "v=0\r\n" |
| 4190 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4191 | "s=-\r\n" |
| 4192 | "t=0 0\r\n" |
| 4193 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4194 | "c=IN IP4 0.0.0.0\r\n" |
| 4195 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4196 | "a=msid:stream_id\r\n" |
| 4197 | "a=msid:stream_id2\r\n"; |
| 4198 | |
| 4199 | JsepSessionDescription jdesc_output(kDummyType); |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4200 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4201 | auto stream = jdesc_output.description() |
| 4202 | ->contents()[0] |
| 4203 | .media_description() |
| 4204 | ->streams()[0]; |
| 4205 | ASSERT_EQ(stream.stream_ids().size(), 2u); |
| 4206 | EXPECT_EQ(stream.stream_ids()[0], "stream_id"); |
| 4207 | EXPECT_EQ(stream.stream_ids()[1], "stream_id2"); |
| 4208 | // Track id is randomly generated. |
| 4209 | EXPECT_NE(stream.id, ""); |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataDuplicate) { |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4213 | std::string sdp = |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4214 | "v=0\r\n" |
| 4215 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4216 | "s=-\r\n" |
| 4217 | "t=0 0\r\n" |
| 4218 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4219 | "c=IN IP4 0.0.0.0\r\n" |
| 4220 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4221 | "a=msid:stream_id\r\n" |
| 4222 | "a=msid:stream_id\r\n"; |
| 4223 | |
| 4224 | JsepSessionDescription jdesc_output(kDummyType); |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4225 | // This is somewhat silly but accept it. Duplicates get filtered. |
| 4226 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4227 | auto stream = jdesc_output.description() |
| 4228 | ->contents()[0] |
| 4229 | .media_description() |
| 4230 | ->streams()[0]; |
| 4231 | ASSERT_EQ(stream.stream_ids().size(), 1u); |
| 4232 | EXPECT_EQ(stream.stream_ids()[0], "stream_id"); |
| 4233 | // Track id is randomly generated. |
| 4234 | EXPECT_NE(stream.id, ""); |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataMixed) { |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4238 | std::string sdp = |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4239 | "v=0\r\n" |
| 4240 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4241 | "s=-\r\n" |
| 4242 | "t=0 0\r\n" |
| 4243 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4244 | "c=IN IP4 0.0.0.0\r\n" |
| 4245 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4246 | "a=msid:stream_id\r\n" |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4247 | "a=msid:stream_id2 track_id\r\n"; |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4248 | |
| 4249 | JsepSessionDescription jdesc_output(kDummyType); |
| 4250 | // Mixing the syntax like this is not a good idea but we accept it |
| 4251 | // and the result is the second track_id. |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4252 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4253 | auto stream = jdesc_output.description() |
| 4254 | ->contents()[0] |
| 4255 | .media_description() |
| 4256 | ->streams()[0]; |
| 4257 | ASSERT_EQ(stream.stream_ids().size(), 2u); |
| 4258 | EXPECT_EQ(stream.stream_ids()[0], "stream_id"); |
| 4259 | EXPECT_EQ(stream.stream_ids()[1], "stream_id2"); |
| 4260 | |
| 4261 | // Track id is taken from second line. |
| 4262 | EXPECT_EQ(stream.id, "track_id"); |
| 4263 | } |
| 4264 | |
Philipp Hancke | b493db9 | 2022-12-08 11:46:20 | [diff] [blame] | 4265 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataMixed2) { |
| 4266 | std::string sdp = |
| 4267 | "v=0\r\n" |
| 4268 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4269 | "s=-\r\n" |
| 4270 | "t=0 0\r\n" |
| 4271 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4272 | "c=IN IP4 0.0.0.0\r\n" |
| 4273 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4274 | "a=msid:stream_id track_id\r\n" |
| 4275 | "a=msid:stream_id2\r\n"; |
| 4276 | |
| 4277 | JsepSessionDescription jdesc_output(kDummyType); |
| 4278 | // Mixing the syntax like this is not a good idea but we accept it |
| 4279 | // and the result is the second track_id. |
| 4280 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4281 | auto stream = jdesc_output.description() |
| 4282 | ->contents()[0] |
| 4283 | .media_description() |
| 4284 | ->streams()[0]; |
| 4285 | ASSERT_EQ(stream.stream_ids().size(), 2u); |
| 4286 | EXPECT_EQ(stream.stream_ids()[0], "stream_id"); |
| 4287 | EXPECT_EQ(stream.stream_ids()[1], "stream_id2"); |
| 4288 | |
| 4289 | // Track id is taken from first line. |
| 4290 | EXPECT_EQ(stream.id, "track_id"); |
| 4291 | } |
| 4292 | |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4293 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataMixedNoStream) { |
| 4294 | std::string sdp = |
| 4295 | "v=0\r\n" |
| 4296 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4297 | "s=-\r\n" |
| 4298 | "t=0 0\r\n" |
| 4299 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4300 | "c=IN IP4 0.0.0.0\r\n" |
| 4301 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4302 | "a=msid:stream_id\r\n" |
| 4303 | "a=msid:- track_id\r\n"; |
| 4304 | |
| 4305 | JsepSessionDescription jdesc_output(kDummyType); |
| 4306 | // This is somewhat undefined behavior but accept it and expect a single |
| 4307 | // stream. |
| 4308 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4309 | auto stream = jdesc_output.description() |
| 4310 | ->contents()[0] |
| 4311 | .media_description() |
| 4312 | ->streams()[0]; |
| 4313 | ASSERT_EQ(stream.stream_ids().size(), 1u); |
| 4314 | EXPECT_EQ(stream.stream_ids()[0], "stream_id"); |
| 4315 | EXPECT_EQ(stream.id, "track_id"); |
Philipp Hancke | e093c48 | 2022-12-05 12:20:01 | [diff] [blame] | 4316 | } |
| 4317 | |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4318 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) { |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4319 | std::string sdp = |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4320 | "v=0\r\n" |
| 4321 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4322 | "s=-\r\n" |
| 4323 | "t=0 0\r\n" |
| 4324 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4325 | "c=IN IP4 0.0.0.0\r\n" |
| 4326 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4327 | "a=msid: track_id\r\n"; |
| 4328 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4329 | JsepSessionDescription jdesc_output(kDummyType); |
Philipp Hancke | 3c52989 | 2022-12-05 18:59:10 | [diff] [blame] | 4330 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4331 | } |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4332 | |
| 4333 | // Tests that if both session-level address and media-level address exist, use |
| 4334 | // the media-level address. |
| 4335 | TEST_F(WebRtcSdpTest, ParseConnectionData) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4336 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4337 | |
| 4338 | // Sesssion-level address. |
| 4339 | std::string sdp = kSdpFullString; |
| 4340 | InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp); |
| 4341 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4342 | |
| 4343 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4344 | EXPECT_EQ("74.125.127.126:2345", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4345 | content1.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4346 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4347 | EXPECT_EQ("74.125.224.39:3457", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4348 | content2.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | // Tests that the session-level connection address will be used if the media |
| 4352 | // level-addresses are not specified. |
| 4353 | TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4354 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4355 | |
| 4356 | // Sesssion-level address. |
| 4357 | std::string sdp = kSdpString; |
| 4358 | InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp); |
| 4359 | // Remove the media level addresses. |
| 4360 | Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp); |
| 4361 | Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp); |
| 4362 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4363 | |
| 4364 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4365 | EXPECT_EQ("192.168.0.3:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4366 | content1.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4367 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4368 | EXPECT_EQ("192.168.0.3:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4369 | content2.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4373 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4374 | |
| 4375 | std::string sdp = kSdpString; |
| 4376 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4377 | Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n", |
| 4378 | "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 " |
| 4379 | "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n", |
| 4380 | &sdp); |
| 4381 | Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n", |
| 4382 | "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 " |
| 4383 | "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n", |
| 4384 | &sdp); |
| 4385 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4386 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4387 | EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4388 | content1.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4389 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4390 | EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4391 | content2.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4392 | } |
| 4393 | |
Qingsi Wang | 5699142 | 2019-02-08 20:53:06 | [diff] [blame] | 4394 | // Test that a c= line that contains a hostname connection address can be |
| 4395 | // parsed. |
| 4396 | TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) { |
| 4397 | JsepSessionDescription jsep_desc(kDummyType); |
| 4398 | std::string sdp = kSdpString; |
| 4399 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4400 | |
| 4401 | sdp = kSdpString; |
| 4402 | Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp); |
| 4403 | Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp); |
| 4404 | ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4405 | |
| 4406 | ASSERT_NE(nullptr, jsep_desc.description()); |
| 4407 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4408 | EXPECT_EQ("example.local:9", |
| 4409 | content1.media_description()->connection_address().ToString()); |
| 4410 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4411 | EXPECT_EQ("example.local:9", |
| 4412 | content2.media_description()->connection_address().ToString()); |
| 4413 | } |
| 4414 | |
| 4415 | // Test that the invalid or unsupported connection data cannot be parsed. |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4416 | TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4417 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4418 | std::string sdp = kSdpString; |
| 4419 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4420 | |
| 4421 | // Unsupported multicast IPv4 address. |
| 4422 | sdp = kSdpFullString; |
| 4423 | Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp); |
| 4424 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4425 | |
| 4426 | // Unsupported multicast IPv6 address. |
| 4427 | sdp = kSdpFullString; |
| 4428 | Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp); |
| 4429 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4430 | |
| 4431 | // Mismatched address type. |
| 4432 | sdp = kSdpFullString; |
| 4433 | Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp); |
| 4434 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4435 | |
| 4436 | sdp = kSdpFullString; |
| 4437 | Replace("c=IN IP4 74.125.224.39\r\n", |
| 4438 | "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp); |
| 4439 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4440 | } |
| 4441 | |
| 4442 | TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4443 | JsepSessionDescription expected_jsep(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4444 | MakeDescriptionWithoutCandidates(&expected_jsep); |
| 4445 | // Serialization. |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 4446 | std::string message = webrtc::SdpSerialize(expected_jsep); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4447 | // Deserialization. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4448 | JsepSessionDescription jdesc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4449 | EXPECT_TRUE(SdpDeserialize(message, &jdesc)); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4450 | auto audio_desc = jdesc.description() |
| 4451 | ->GetContentByName(kAudioContentName) |
| 4452 | ->media_description(); |
| 4453 | auto video_desc = jdesc.description() |
| 4454 | ->GetContentByName(kVideoContentName) |
| 4455 | ->media_description(); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4456 | EXPECT_EQ(audio_desc_->connection_address().ToString(), |
| 4457 | audio_desc->connection_address().ToString()); |
| 4458 | EXPECT_EQ(video_desc_->connection_address().ToString(), |
| 4459 | video_desc->connection_address().ToString()); |
| 4460 | } |
Taylor Brandstetter | 93a7b24 | 2018-04-16 17:45:24 | [diff] [blame] | 4461 | |
| 4462 | // RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be |
| 4463 | // used (i.e., a single space as the session name)." So we should accept that. |
| 4464 | TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) { |
| 4465 | JsepSessionDescription jsep_desc(kDummyType); |
| 4466 | std::string sdp = kSdpString; |
| 4467 | Replace("s=-\r\n", "s= \r\n", &sdp); |
| 4468 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4469 | } |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4470 | |
| 4471 | // Simulcast malformed input test for invalid format. |
| 4472 | TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) { |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 4473 | ExpectParseFailureWithNewLines( |
| 4474 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n", "a=simulcast:\r\n", |
| 4475 | "a=simulcast:"); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | // Tests that duplicate simulcast entries in the SDP triggers a parse failure. |
| 4479 | TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) { |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 4480 | ExpectParseFailureWithNewLines( |
| 4481 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n", |
| 4482 | "a=simulcast:send 1\r\na=simulcast:recv 2\r\n", "a=simulcast:"); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4483 | } |
| 4484 | |
| 4485 | // Validates that deserialization uses the a=simulcast: attribute |
| 4486 | TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) { |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4487 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4488 | sdp += "a=rid:1 send\r\n"; |
| 4489 | sdp += "a=rid:2 send\r\n"; |
| 4490 | sdp += "a=rid:3 send\r\n"; |
| 4491 | sdp += "a=rid:4 recv\r\n"; |
| 4492 | sdp += "a=rid:5 recv\r\n"; |
| 4493 | sdp += "a=rid:6 recv\r\n"; |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4494 | sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n"; |
| 4495 | JsepSessionDescription output(kDummyType); |
| 4496 | SdpParseError error; |
| 4497 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4498 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4499 | const cricket::MediaContentDescription* media = |
| 4500 | contents.back().media_description(); |
| 4501 | EXPECT_TRUE(media->HasSimulcast()); |
| 4502 | EXPECT_EQ(2ul, media->simulcast_description().send_layers().size()); |
| 4503 | EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size()); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4504 | EXPECT_FALSE(media->streams().empty()); |
| 4505 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4506 | CompareRidDescriptionIds(rids, {"1", "2", "3"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | // Validates that deserialization removes rids that do not appear in SDP |
| 4510 | TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) { |
| 4511 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4512 | sdp += "a=rid:1 send\r\n"; |
| 4513 | sdp += "a=rid:3 send\r\n"; |
| 4514 | sdp += "a=rid:4 recv\r\n"; |
| 4515 | sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n"; |
| 4516 | JsepSessionDescription output(kDummyType); |
| 4517 | SdpParseError error; |
| 4518 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4519 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4520 | const cricket::MediaContentDescription* media = |
| 4521 | contents.back().media_description(); |
| 4522 | EXPECT_TRUE(media->HasSimulcast()); |
| 4523 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4524 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4525 | EXPECT_EQ(1ul, simulcast.receive_layers().size()); |
| 4526 | |
| 4527 | std::vector<SimulcastLayer> all_send_layers = |
| 4528 | simulcast.send_layers().GetAllLayers(); |
| 4529 | EXPECT_EQ(2ul, all_send_layers.size()); |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 4530 | EXPECT_EQ(0, |
| 4531 | absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) { |
| 4532 | return layer.rid == "2"; |
| 4533 | })); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4534 | |
| 4535 | std::vector<SimulcastLayer> all_receive_layers = |
| 4536 | simulcast.receive_layers().GetAllLayers(); |
| 4537 | ASSERT_EQ(1ul, all_receive_layers.size()); |
| 4538 | EXPECT_EQ("4", all_receive_layers[0].rid); |
| 4539 | |
| 4540 | EXPECT_FALSE(media->streams().empty()); |
| 4541 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4542 | CompareRidDescriptionIds(rids, {"1", "3"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | // Validates that Simulcast removes rids that appear in both send and receive. |
| 4546 | TEST_F(WebRtcSdpTest, |
| 4547 | TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) { |
| 4548 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4549 | sdp += "a=rid:1 send\r\n"; |
| 4550 | sdp += "a=rid:2 send\r\n"; |
| 4551 | sdp += "a=rid:3 send\r\n"; |
| 4552 | sdp += "a=rid:4 recv\r\n"; |
| 4553 | sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n"; |
| 4554 | JsepSessionDescription output(kDummyType); |
| 4555 | SdpParseError error; |
| 4556 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4557 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4558 | const cricket::MediaContentDescription* media = |
| 4559 | contents.back().media_description(); |
| 4560 | EXPECT_TRUE(media->HasSimulcast()); |
| 4561 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4562 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4563 | EXPECT_EQ(1ul, simulcast.receive_layers().size()); |
| 4564 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4565 | EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size()); |
| 4566 | |
| 4567 | EXPECT_FALSE(media->streams().empty()); |
| 4568 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4569 | CompareRidDescriptionIds(rids, {"1", "3"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | // Ignores empty rid line. |
| 4573 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) { |
| 4574 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4575 | sdp += "a=rid:1 send\r\n"; |
| 4576 | sdp += "a=rid:2 send\r\n"; |
| 4577 | sdp += "a=rid\r\n"; // Should ignore this line. |
| 4578 | sdp += "a=rid:\r\n"; // Should ignore this line. |
| 4579 | sdp += "a=simulcast:send 1;2\r\n"; |
| 4580 | JsepSessionDescription output(kDummyType); |
| 4581 | SdpParseError error; |
| 4582 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4583 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4584 | const cricket::MediaContentDescription* media = |
| 4585 | contents.back().media_description(); |
| 4586 | EXPECT_TRUE(media->HasSimulcast()); |
| 4587 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4588 | EXPECT_TRUE(simulcast.receive_layers().empty()); |
| 4589 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4590 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4591 | |
| 4592 | EXPECT_FALSE(media->streams().empty()); |
| 4593 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4594 | CompareRidDescriptionIds(rids, {"1", "2"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | // Ignores malformed rid lines. |
| 4598 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) { |
| 4599 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4600 | sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line. |
| 4601 | sdp += "a=rid:2 receive\r\n"; // Should ignore this line. |
| 4602 | sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line. |
| 4603 | sdp += "a=rid:4\r\n"; // Should ignore this line. |
| 4604 | sdp += "a=rid:5 send\r\n"; |
| 4605 | sdp += "a=simulcast:send 1,2,3;4,5\r\n"; |
| 4606 | JsepSessionDescription output(kDummyType); |
| 4607 | SdpParseError error; |
| 4608 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4609 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4610 | const cricket::MediaContentDescription* media = |
| 4611 | contents.back().media_description(); |
| 4612 | EXPECT_TRUE(media->HasSimulcast()); |
| 4613 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4614 | EXPECT_TRUE(simulcast.receive_layers().empty()); |
| 4615 | EXPECT_EQ(1ul, simulcast.send_layers().size()); |
| 4616 | EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size()); |
| 4617 | |
| 4618 | EXPECT_FALSE(media->streams().empty()); |
| 4619 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4620 | CompareRidDescriptionIds(rids, {"5"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | // Removes RIDs that specify a different format than the m= section. |
| 4624 | TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) { |
| 4625 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4626 | sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID. |
| 4627 | sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether. |
| 4628 | sdp += "a=simulcast:send 1;2\r\n"; |
| 4629 | JsepSessionDescription output(kDummyType); |
| 4630 | SdpParseError error; |
| 4631 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4632 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4633 | const cricket::MediaContentDescription* media = |
| 4634 | contents.back().media_description(); |
| 4635 | EXPECT_TRUE(media->HasSimulcast()); |
| 4636 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4637 | EXPECT_TRUE(simulcast.receive_layers().empty()); |
| 4638 | EXPECT_EQ(1ul, simulcast.send_layers().size()); |
| 4639 | EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size()); |
| 4640 | EXPECT_EQ("1", simulcast.send_layers()[0][0].rid); |
| 4641 | EXPECT_EQ(1ul, media->streams().size()); |
| 4642 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4643 | EXPECT_EQ(1ul, rids.size()); |
| 4644 | EXPECT_EQ("1", rids[0].rid); |
| 4645 | EXPECT_EQ(1ul, rids[0].payload_types.size()); |
| 4646 | EXPECT_EQ(120, rids[0].payload_types[0]); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | // Ignores duplicate rid lines |
| 4650 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) { |
| 4651 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4652 | sdp += "a=rid:1 send\r\n"; |
| 4653 | sdp += "a=rid:2 send\r\n"; |
| 4654 | sdp += "a=rid:2 send\r\n"; |
| 4655 | sdp += "a=rid:3 send\r\n"; |
| 4656 | sdp += "a=rid:4 recv\r\n"; |
| 4657 | sdp += "a=simulcast:send 1,2;3 recv 4\r\n"; |
| 4658 | JsepSessionDescription output(kDummyType); |
| 4659 | SdpParseError error; |
| 4660 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4661 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4662 | const cricket::MediaContentDescription* media = |
| 4663 | contents.back().media_description(); |
| 4664 | EXPECT_TRUE(media->HasSimulcast()); |
| 4665 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4666 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4667 | EXPECT_EQ(1ul, simulcast.receive_layers().size()); |
| 4668 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4669 | EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size()); |
| 4670 | |
| 4671 | EXPECT_FALSE(media->streams().empty()); |
| 4672 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4673 | CompareRidDescriptionIds(rids, {"1", "3"}); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4674 | } |
| 4675 | |
Florent Castelli | c442197 | 2019-07-02 18:27:42 | [diff] [blame] | 4676 | TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) { |
| 4677 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4678 | sdp += "a=rid:1 recv\r\n"; |
| 4679 | sdp += "a=rid:2 recv\r\n"; |
| 4680 | sdp += "a=simulcast:send 1;2\r\n"; |
| 4681 | JsepSessionDescription output(kDummyType); |
| 4682 | SdpParseError error; |
| 4683 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4684 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4685 | const cricket::MediaContentDescription* media = |
| 4686 | contents.back().media_description(); |
| 4687 | EXPECT_FALSE(media->HasSimulcast()); |
| 4688 | } |
| 4689 | |
| 4690 | TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) { |
| 4691 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4692 | sdp += "a=rid:1 send\r\n"; |
| 4693 | sdp += "a=rid:2 send\r\n"; |
| 4694 | sdp += "a=simulcast:recv 1;2\r\n"; |
| 4695 | JsepSessionDescription output(kDummyType); |
| 4696 | SdpParseError error; |
| 4697 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4698 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4699 | const cricket::MediaContentDescription* media = |
| 4700 | contents.back().media_description(); |
| 4701 | EXPECT_FALSE(media->HasSimulcast()); |
| 4702 | } |
| 4703 | |
| 4704 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) { |
| 4705 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4706 | sdp += "a=rid:1 send\r\n"; |
| 4707 | sdp += "a=rid:2 send\r\n"; |
| 4708 | sdp += "a=rid:3 send\r\n"; |
| 4709 | sdp += "a=rid:4 recv\r\n"; |
| 4710 | sdp += "a=rid:5 recv\r\n"; |
| 4711 | sdp += "a=rid:6 recv\r\n"; |
| 4712 | sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n"; |
| 4713 | JsepSessionDescription output(kDummyType); |
| 4714 | SdpParseError error; |
| 4715 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4716 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4717 | const cricket::MediaContentDescription* media = |
| 4718 | contents.back().media_description(); |
| 4719 | EXPECT_TRUE(media->HasSimulcast()); |
| 4720 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4721 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4722 | EXPECT_EQ(2ul, simulcast.receive_layers().size()); |
| 4723 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4724 | EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size()); |
| 4725 | |
| 4726 | EXPECT_FALSE(media->streams().empty()); |
| 4727 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4728 | CompareRidDescriptionIds(rids, {"1", "3"}); |
| 4729 | } |
| 4730 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4731 | // Simulcast serialization integration test. |
| 4732 | // This test will serialize and deserialize the description and compare. |
| 4733 | // More detailed tests for parsing simulcast can be found in |
| 4734 | // unit tests for SdpSerializer. |
| 4735 | TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) { |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4736 | MakeUnifiedPlanDescription(/* use_ssrcs = */ false); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4737 | auto description = jdesc_.description(); |
| 4738 | auto media = description->GetContentDescriptionByName(kVideoContentName3); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4739 | ASSERT_EQ(media->streams().size(), 1ul); |
| 4740 | StreamParams& send_stream = media->mutable_streams()[0]; |
| 4741 | std::vector<RidDescription> send_rids; |
| 4742 | send_rids.push_back(RidDescription("1", RidDirection::kSend)); |
| 4743 | send_rids.push_back(RidDescription("2", RidDirection::kSend)); |
| 4744 | send_rids.push_back(RidDescription("3", RidDirection::kSend)); |
| 4745 | send_rids.push_back(RidDescription("4", RidDirection::kSend)); |
| 4746 | send_stream.set_rids(send_rids); |
Florent Castelli | b60141b | 2019-07-03 10:47:54 | [diff] [blame] | 4747 | std::vector<RidDescription> receive_rids; |
| 4748 | receive_rids.push_back(RidDescription("5", RidDirection::kReceive)); |
| 4749 | receive_rids.push_back(RidDescription("6", RidDirection::kReceive)); |
| 4750 | receive_rids.push_back(RidDescription("7", RidDirection::kReceive)); |
| 4751 | media->set_receive_rids(receive_rids); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4752 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4753 | SimulcastDescription& simulcast = media->simulcast_description(); |
| 4754 | simulcast.send_layers().AddLayerWithAlternatives( |
| 4755 | {SimulcastLayer("2", false), SimulcastLayer("1", true)}); |
| 4756 | simulcast.send_layers().AddLayerWithAlternatives( |
| 4757 | {SimulcastLayer("4", false), SimulcastLayer("3", false)}); |
Florent Castelli | b60141b | 2019-07-03 10:47:54 | [diff] [blame] | 4758 | simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)}); |
| 4759 | simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)}); |
| 4760 | simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)}); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4761 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4762 | TestSerialize(jdesc_); |
| 4763 | } |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 4764 | |
| 4765 | // Test that the content name is empty if the media section does not have an |
| 4766 | // a=mid line. |
| 4767 | TEST_F(WebRtcSdpTest, ParseNoMid) { |
| 4768 | std::string sdp = kSdpString; |
| 4769 | Replace("a=mid:audio_content_name\r\n", "", &sdp); |
| 4770 | Replace("a=mid:video_content_name\r\n", "", &sdp); |
| 4771 | |
| 4772 | JsepSessionDescription output(kDummyType); |
| 4773 | SdpParseError error; |
| 4774 | ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4775 | |
| 4776 | EXPECT_THAT(output.description()->contents(), |
| 4777 | ElementsAre(Field("name", &cricket::ContentInfo::name, ""), |
| 4778 | Field("name", &cricket::ContentInfo::name, ""))); |
| 4779 | } |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 19:34:26 | [diff] [blame] | 4780 | |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 4781 | TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) { |
| 4782 | AddSctpDataChannel(false); // Don't use sctpmap |
| 4783 | JsepSessionDescription jsep_desc(kDummyType); |
| 4784 | MakeDescriptionWithoutCandidates(&jsep_desc); |
| 4785 | std::string message = webrtc::SdpSerialize(jsep_desc); |
| 4786 | EXPECT_NE(std::string::npos, |
| 4787 | message.find(cricket::kMediaProtocolUdpDtlsSctp)); |
| 4788 | } |
| 4789 | |
| 4790 | TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) { |
| 4791 | AddSctpDataChannel(false); |
| 4792 | std::string protocols[] = {cricket::kMediaProtocolDtlsSctp, |
| 4793 | cricket::kMediaProtocolUdpDtlsSctp, |
| 4794 | cricket::kMediaProtocolTcpDtlsSctp}; |
| 4795 | for (const auto& protocol : protocols) { |
| 4796 | sctp_desc_->set_protocol(protocol); |
| 4797 | JsepSessionDescription jsep_desc(kDummyType); |
| 4798 | MakeDescriptionWithoutCandidates(&jsep_desc); |
| 4799 | std::string message = webrtc::SdpSerialize(jsep_desc); |
| 4800 | EXPECT_NE(std::string::npos, message.find(protocol)); |
| 4801 | JsepSessionDescription jsep_output(kDummyType); |
| 4802 | SdpParseError error; |
| 4803 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error)); |
| 4804 | } |
| 4805 | } |
Taylor Brandstetter | 4256df0 | 2020-02-18 22:05:07 | [diff] [blame] | 4806 | |
| 4807 | // According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME |
| 4808 | // attribute is mandatory, but we relax that restriction. |
| 4809 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) { |
| 4810 | std::string sdp_without_cname = kSdpFullString; |
| 4811 | Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname); |
| 4812 | JsepSessionDescription new_jdesc(kDummyType); |
| 4813 | EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc)); |
| 4814 | |
| 4815 | audio_desc_->mutable_streams()[0].cname = ""; |
| 4816 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 4817 | jdesc_.session_version())); |
| 4818 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 4819 | } |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4820 | |
Dor Hen | d1831cb | 2023-02-03 01:59:28 | [diff] [blame] | 4821 | TEST_F(WebRtcSdpTest, |
| 4822 | DeserializeSdpWithUnrecognizedApplicationProtocolRejectsSection) { |
| 4823 | const char* unsupported_application_protocols[] = { |
| 4824 | "bogus/RTP/", "RTP/SAVPF", "DTLS/SCTP/RTP/", "DTLS/SCTPRTP/", |
| 4825 | "obviously-bogus", "UDP/TL/RTSP/SAVPF", "UDP/TL/RTSP/S"}; |
| 4826 | |
| 4827 | for (auto proto : unsupported_application_protocols) { |
| 4828 | JsepSessionDescription jdesc_output(kDummyType); |
| 4829 | std::string sdp = kSdpSessionString; |
| 4830 | sdp.append("m=application 9 "); |
| 4831 | sdp.append(proto); |
| 4832 | sdp.append(" 101\r\n"); |
| 4833 | |
| 4834 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4835 | |
| 4836 | // Make sure we actually parsed a single media section |
| 4837 | ASSERT_EQ(1u, jdesc_output.description()->contents().size()); |
| 4838 | |
| 4839 | // Content is not getting parsed as sctp but instead unsupported. |
| 4840 | EXPECT_EQ(nullptr, jdesc_output.description() |
| 4841 | ->contents()[0] |
| 4842 | .media_description() |
| 4843 | ->as_sctp()); |
| 4844 | EXPECT_NE(nullptr, jdesc_output.description() |
| 4845 | ->contents()[0] |
| 4846 | .media_description() |
| 4847 | ->as_unsupported()); |
| 4848 | |
| 4849 | // Reject the content |
| 4850 | EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected); |
| 4851 | } |
| 4852 | } |
| 4853 | |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4854 | TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) { |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4855 | std::string sdp = kSdpSessionString; |
| 4856 | sdp += |
| 4857 | "m=bogus 9 RTP/SAVPF 0 8\r\n" |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 4858 | "c=IN IP4 0.0.0.0\r\n" |
| 4859 | "a=mid:bogusmid\r\n"; |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4860 | sdp += |
| 4861 | "m=audio/something 9 RTP/SAVPF 0 8\r\n" |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 4862 | "c=IN IP4 0.0.0.0\r\n" |
| 4863 | "a=mid:somethingmid\r\n"; |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4864 | |
| 4865 | JsepSessionDescription jdesc_output(kDummyType); |
| 4866 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4867 | |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 4868 | ASSERT_EQ(2u, jdesc_output.description()->contents().size()); |
| 4869 | ASSERT_NE(nullptr, jdesc_output.description() |
| 4870 | ->contents()[0] |
| 4871 | .media_description() |
| 4872 | ->as_unsupported()); |
| 4873 | ASSERT_NE(nullptr, jdesc_output.description() |
| 4874 | ->contents()[1] |
| 4875 | .media_description() |
| 4876 | ->as_unsupported()); |
| 4877 | |
| 4878 | EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected); |
| 4879 | EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected); |
| 4880 | |
| 4881 | EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid"); |
| 4882 | EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid"); |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4883 | } |
Philipp Hancke | b70c953 | 2021-01-13 09:40:06 | [diff] [blame] | 4884 | |
| 4885 | TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) { |
| 4886 | std::string sdp = |
| 4887 | "v=0\r\n" |
| 4888 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4889 | "s=-\r\n" |
| 4890 | "t=0 0\r\n"; |
| 4891 | |
| 4892 | ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"), |
| 4893 | "m=audio"); |
| 4894 | ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"), |
| 4895 | "m=video"); |
| 4896 | ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"), |
| 4897 | "m=video"); |
Philipp Hancke | b70c953 | 2021-01-13 09:40:06 | [diff] [blame] | 4898 | } |
Philipp Hancke | cd467b5 | 2021-01-29 08:29:47 | [diff] [blame] | 4899 | |
| 4900 | // Regression test for: |
| 4901 | // https://bugs.chromium.org/p/chromium/issues/detail?id=1171965 |
| 4902 | TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) { |
| 4903 | std::string sdp = |
| 4904 | "v=0\r\n" |
| 4905 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4906 | "s=-\r\n" |
| 4907 | "t=0 0\r\n" |
| 4908 | "m=o 1 DTLS/SCTP 5000\r\n" |
| 4909 | "a=sctp-port\r\n"; |
| 4910 | |
| 4911 | JsepSessionDescription jdesc_output(kDummyType); |
| 4912 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4913 | } |
Harald Alvestrand | 99bcf60 | 2021-03-03 07:44:39 | [diff] [blame] | 4914 | |
| 4915 | TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) { |
| 4916 | std::string sdp = kSdpString; |
| 4917 | // [ is an illegal token value. |
| 4918 | Replace("a=mid:", "a=mid:[]", &sdp); |
| 4919 | ExpectParseFailure(std::string(sdp), "a=mid:[]"); |
| 4920 | } |
Philipp Hancke | d58ac5a | 2021-11-25 07:57:54 | [diff] [blame] | 4921 | |
| 4922 | TEST_F(WebRtcSdpTest, MaxChannels) { |
| 4923 | std::string sdp = |
| 4924 | "v=0\r\n" |
| 4925 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 4926 | "s=-\r\n" |
| 4927 | "t=0 0\r\n" |
| 4928 | "m=audio 49232 RTP/AVP 108\r\n" |
| 4929 | "a=rtpmap:108 ISAC/16000/512\r\n"; |
| 4930 | |
| 4931 | ExpectParseFailure(sdp, "a=rtpmap:108 ISAC/16000/512"); |
| 4932 | } |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 4933 | |
Philipp Hancke | 32c60b8 | 2022-05-31 14:51:23 | [diff] [blame] | 4934 | TEST_F(WebRtcSdpTest, DuplicateAudioRtpmapWithConflict) { |
| 4935 | std::string sdp = |
| 4936 | "v=0\r\n" |
| 4937 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 4938 | "s=-\r\n" |
| 4939 | "t=0 0\r\n" |
| 4940 | "m=audio 49232 RTP/AVP 108\r\n" |
Philipp Hancke | 32c60b8 | 2022-05-31 14:51:23 | [diff] [blame] | 4941 | "a=rtpmap:108 ISAC/16000\r\n" |
Philipp Hancke | 62c20f3 | 2022-07-07 09:06:36 | [diff] [blame] | 4942 | "a=rtpmap:108 G711/16000\r\n"; |
Philipp Hancke | 32c60b8 | 2022-05-31 14:51:23 | [diff] [blame] | 4943 | |
Philipp Hancke | 62c20f3 | 2022-07-07 09:06:36 | [diff] [blame] | 4944 | ExpectParseFailure(sdp, "a=rtpmap:108 G711/16000"); |
Philipp Hancke | 32c60b8 | 2022-05-31 14:51:23 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | TEST_F(WebRtcSdpTest, DuplicateVideoRtpmapWithConflict) { |
| 4948 | std::string sdp = |
| 4949 | "v=0\r\n" |
| 4950 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 4951 | "s=-\r\n" |
| 4952 | "t=0 0\r\n" |
| 4953 | "m=video 49232 RTP/AVP 108\r\n" |
| 4954 | "a=rtpmap:108 VP8/90000\r\n" |
| 4955 | "a=rtpmap:108 VP9/90000\r\n"; |
| 4956 | |
| 4957 | ExpectParseFailure(sdp, "a=rtpmap:108 VP9/90000"); |
| 4958 | } |
| 4959 | |
| 4960 | TEST_F(WebRtcSdpTest, FmtpBeforeRtpMap) { |
| 4961 | std::string sdp = |
| 4962 | "v=0\r\n" |
| 4963 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 4964 | "s=-\r\n" |
| 4965 | "t=0 0\r\n" |
| 4966 | "m=video 49232 RTP/AVP 108\r\n" |
| 4967 | "a=fmtp:108 profile-level=1\r\n" |
| 4968 | "a=rtpmap:108 VP9/90000\r\n"; |
| 4969 | |
| 4970 | JsepSessionDescription jdesc_output(kDummyType); |
| 4971 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4972 | } |
| 4973 | |
Andrey Logvin | 1d848e1 | 2022-06-22 09:39:19 | [diff] [blame] | 4974 | TEST_F(WebRtcSdpTest, StaticallyAssignedPayloadTypeWithDifferentCasing) { |
| 4975 | std::string sdp = |
| 4976 | "v=0\r\n" |
| 4977 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 4978 | "s=-\r\n" |
| 4979 | "t=0 0\r\n" |
| 4980 | "m=audio 49232 RTP/AVP 18\r\n" |
| 4981 | // Casing differs from statically assigned type, this should |
| 4982 | // still be accepted. |
| 4983 | "a=rtpmap:18 g729/8000\r\n"; |
| 4984 | |
| 4985 | JsepSessionDescription jdesc_output(kDummyType); |
| 4986 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4987 | } |
| 4988 | |
Harald Alvestrand | 88b8dec1 | 2022-04-07 09:54:51 | [diff] [blame] | 4989 | // This tests parsing of SDP with unknown ssrc-specific attributes. |
| 4990 | TEST_F(WebRtcSdpTest, ParseIgnoreUnknownSsrcSpecificAttribute) { |
| 4991 | std::string sdp = kSdpString; |
| 4992 | sdp += "a=ssrc:1 mslabel:something\r\n"; |
| 4993 | |
| 4994 | JsepSessionDescription output(kDummyType); |
| 4995 | SdpParseError error; |
| 4996 | ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4997 | } |
Philipp Hancke | 5561599 | 2023-02-21 09:49:18 | [diff] [blame] | 4998 | |
| 4999 | TEST_F(WebRtcSdpTest, ParseSessionLevelExtmapAttributes) { |
| 5000 | std::string sdp = |
| 5001 | "v=0\r\n" |
| 5002 | "o=- 0 3 IN IP4 127.0.0.1\r\n" |
| 5003 | "s=-\r\n" |
| 5004 | "t=0 0\r\n" |
| 5005 | "a=group:BUNDLE 0\r\n" |
| 5006 | "a=fingerprint:sha-1 " |
| 5007 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n" |
| 5008 | "a=setup:actpass\r\n" |
| 5009 | "a=ice-ufrag:ETEn\r\n" |
| 5010 | "a=ice-pwd:OtSK0WpNtpUjkY4+86js7Z/l\r\n" |
| 5011 | "a=extmap:3 " |
| 5012 | "http://www.ietf.org/id/" |
| 5013 | "draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n" |
| 5014 | "m=audio 9 UDP/TLS/RTP/SAVPF 111\r\n" |
| 5015 | "c=IN IP4 0.0.0.0\r\n" |
| 5016 | "a=rtcp-mux\r\n" |
| 5017 | "a=sendonly\r\n" |
| 5018 | "a=mid:0\r\n" |
| 5019 | "a=rtpmap:111 opus/48000/2\r\n"; |
| 5020 | JsepSessionDescription jdesc(kDummyType); |
| 5021 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc)); |
| 5022 | ASSERT_EQ(1u, jdesc.description()->contents().size()); |
| 5023 | const auto content = jdesc.description()->contents()[0]; |
| 5024 | const auto* audio_description = content.media_description()->as_audio(); |
| 5025 | ASSERT_NE(audio_description, nullptr); |
| 5026 | const auto& extensions = audio_description->rtp_header_extensions(); |
| 5027 | ASSERT_EQ(1u, extensions.size()); |
| 5028 | EXPECT_EQ(extensions[0].uri, |
| 5029 | "http://www.ietf.org/id/" |
| 5030 | "draft-holmer-rmcat-transport-wide-cc-extensions-01"); |
| 5031 | EXPECT_EQ(extensions[0].id, 3); |
| 5032 | } |
| 5033 | |
| 5034 | TEST_F(WebRtcSdpTest, RejectSessionLevelMediaLevelExtmapMixedUsage) { |
| 5035 | std::string sdp = |
| 5036 | "v=0\r\n" |
| 5037 | "o=- 0 3 IN IP4 127.0.0.1\r\n" |
| 5038 | "s=-\r\n" |
| 5039 | "t=0 0\r\n" |
| 5040 | "a=group:BUNDLE 0\r\n" |
| 5041 | "a=fingerprint:sha-1 " |
| 5042 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n" |
| 5043 | "a=setup:actpass\r\n" |
| 5044 | "a=ice-ufrag:ETEn\r\n" |
| 5045 | "a=ice-pwd:OtSK0WpNtpUjkY4+86js7Z/l\r\n" |
| 5046 | "a=extmap:3 " |
| 5047 | "http://www.ietf.org/id/" |
| 5048 | "draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n" |
| 5049 | "m=audio 9 UDP/TLS/RTP/SAVPF 111\r\n" |
| 5050 | "a=extmap:2 " |
| 5051 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n" |
| 5052 | "c=IN IP4 0.0.0.0\r\n" |
| 5053 | "a=rtcp-mux\r\n" |
| 5054 | "a=sendonly\r\n" |
| 5055 | "a=mid:0\r\n" |
| 5056 | "a=rtpmap:111 opus/48000/2\r\n"; |
| 5057 | JsepSessionDescription jdesc(kDummyType); |
| 5058 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc)); |
| 5059 | } |
Philipp Hancke | 6a38a3e | 2023-06-15 05:21:56 | [diff] [blame] | 5060 | |
| 5061 | TEST_F(WebRtcSdpTest, RejectDuplicateSsrcInSsrcGroup) { |
| 5062 | std::string sdp = |
| 5063 | "v=0\r\n" |
| 5064 | "o=- 0 3 IN IP4 127.0.0.1\r\n" |
| 5065 | "s=-\r\n" |
| 5066 | "t=0 0\r\n" |
| 5067 | "a=group:BUNDLE 0\r\n" |
| 5068 | "a=fingerprint:sha-1 " |
| 5069 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n" |
| 5070 | "a=setup:actpass\r\n" |
| 5071 | "a=ice-ufrag:ETEn\r\n" |
| 5072 | "a=ice-pwd:OtSK0WpNtpUjkY4+86js7Z/l\r\n" |
| 5073 | "m=video 9 UDP/TLS/RTP/SAVPF 96 97\r\n" |
| 5074 | "c=IN IP4 0.0.0.0\r\n" |
| 5075 | "a=rtcp-mux\r\n" |
| 5076 | "a=sendonly\r\n" |
| 5077 | "a=mid:0\r\n" |
| 5078 | "a=rtpmap:96 VP8/90000\r\n" |
| 5079 | "a=rtpmap:97 rtx/90000\r\n" |
| 5080 | "a=fmtp:97 apt=96\r\n" |
| 5081 | "a=ssrc-group:FID 1234 1234\r\n" |
| 5082 | "a=ssrc:1234 cname:test\r\n"; |
| 5083 | JsepSessionDescription jdesc(kDummyType); |
| 5084 | EXPECT_FALSE(SdpDeserialize(sdp, &jdesc)); |
| 5085 | } |