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 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 14 | #include <algorithm> |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 15 | #include <cstdint> |
| 16 | #include <map> |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 17 | #include <memory> |
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" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 25 | #include "api/array_view.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 26 | #include "api/crypto_params.h" |
| 27 | #include "api/jsep_session_description.h" |
| 28 | #include "api/media_types.h" |
| 29 | #include "api/rtp_parameters.h" |
| 30 | #include "api/rtp_transceiver_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 31 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 32 | #include "media/base/media_constants.h" |
| 33 | #include "media/base/stream_params.h" |
| 34 | #include "p2p/base/p2p_constants.h" |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 35 | #include "p2p/base/port.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 36 | #include "p2p/base/transport_description.h" |
| 37 | #include "p2p/base/transport_info.h" |
| 38 | #include "pc/media_session.h" |
| 39 | #include "pc/session_description.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 40 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 41 | #include "rtc_base/message_digest.h" |
| 42 | #include "rtc_base/socket_address.h" |
| 43 | #include "rtc_base/ssl_fingerprint.h" |
| 44 | #include "rtc_base/string_encode.h" |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 45 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 46 | #include "test/gtest.h" |
Patrik Höglund | 563934e | 2017-09-15 07:04:28 | [diff] [blame] | 47 | |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 48 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 49 | #include "pc/test/android_test_initializer.h" |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 50 | #endif |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 51 | #include "pc/webrtc_sdp.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 52 | |
| 53 | using cricket::AudioCodec; |
| 54 | using cricket::AudioContentDescription; |
| 55 | using cricket::Candidate; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 56 | using cricket::ContentGroup; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 57 | using cricket::ContentInfo; |
| 58 | using cricket::CryptoParams; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 59 | using cricket::ICE_CANDIDATE_COMPONENT_RTCP; |
| 60 | using cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 61 | using cricket::kFecSsrcGroupSemantics; |
| 62 | using cricket::LOCAL_PORT_TYPE; |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 63 | using cricket::MediaProtocolType; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 64 | using cricket::RELAY_PORT_TYPE; |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 65 | using cricket::RidDescription; |
| 66 | using cricket::RidDirection; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 67 | using cricket::SctpDataContentDescription; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 68 | using cricket::SessionDescription; |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 69 | using cricket::SimulcastDescription; |
| 70 | using cricket::SimulcastLayer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 71 | using cricket::StreamParams; |
| 72 | using cricket::STUN_PORT_TYPE; |
| 73 | using cricket::TransportDescription; |
| 74 | using cricket::TransportInfo; |
| 75 | using cricket::VideoCodec; |
| 76 | using cricket::VideoContentDescription; |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 77 | using ::testing::ElementsAre; |
| 78 | using ::testing::Field; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 79 | using webrtc::IceCandidateCollection; |
| 80 | using webrtc::IceCandidateInterface; |
| 81 | using webrtc::JsepIceCandidate; |
| 82 | using webrtc::JsepSessionDescription; |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 83 | using webrtc::RtpExtension; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 84 | using webrtc::RtpTransceiverDirection; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 85 | using webrtc::SdpParseError; |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 86 | using webrtc::SdpType; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 87 | using webrtc::SessionDescriptionInterface; |
| 88 | |
| 89 | typedef std::vector<AudioCodec> AudioCodecs; |
| 90 | typedef std::vector<Candidate> Candidates; |
| 91 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 92 | static const uint32_t kDefaultSctpPort = 5000; |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 93 | static const uint16_t kUnusualSctpPort = 9556; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 94 | static const char kSessionTime[] = "t=0 0\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 95 | static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 96 | static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 97 | static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 98 | static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 99 | static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 100 | static const uint32_t kCandidateGeneration = 2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 101 | static const char kCandidateFoundation1[] = "a0+B/1"; |
| 102 | static const char kCandidateFoundation2[] = "a0+B/2"; |
| 103 | static const char kCandidateFoundation3[] = "a0+B/3"; |
| 104 | static const char kCandidateFoundation4[] = "a0+B/4"; |
| 105 | static const char kAttributeCryptoVoice[] = |
| 106 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 107 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 108 | "dummy_session_params\r\n"; |
| 109 | static const char kAttributeCryptoVideo[] = |
| 110 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 111 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 112 | static const char kFingerprint[] = |
| 113 | "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 114 | "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] | 115 | static const char kExtmapAllowMixed[] = "a=extmap-allow-mixed\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 116 | static const int kExtmapId = 1; |
| 117 | static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime"; |
| 118 | static const char kExtmap[] = |
| 119 | "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n"; |
| 120 | static const char kExtmapWithDirectionAndAttribute[] = |
| 121 | "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] | 122 | static const char kExtmapWithDirectionAndAttributeEncrypted[] = |
| 123 | "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt " |
| 124 | "http://example.com/082005/ext.htm#ttime a1 a2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 125 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 126 | static const uint8_t kIdentityDigest[] = { |
| 127 | 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02, |
| 128 | 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 129 | |
lally@webrtc.org | 3480728 | 2015-02-24 20:19:39 | [diff] [blame] | 130 | static const char kDtlsSctp[] = "DTLS/SCTP"; |
| 131 | static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; |
| 132 | static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 133 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 134 | struct CodecParams { |
| 135 | int max_ptime; |
| 136 | int ptime; |
| 137 | int min_ptime; |
| 138 | int sprop_stereo; |
| 139 | int stereo; |
| 140 | int useinband; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 | [diff] [blame] | 141 | int maxaveragebitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 142 | }; |
| 143 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 144 | // TODO(deadbeef): In these reference strings, use "a=fingerprint" by default |
| 145 | // instead of "a=crypto", and have an explicit test for adding "a=crypto". |
| 146 | // Currently it's the other way around. |
| 147 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 148 | // Reference sdp string |
| 149 | static const char kSdpFullString[] = |
| 150 | "v=0\r\n" |
| 151 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 152 | "s=-\r\n" |
| 153 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 154 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 155 | "a=msid-semantic: WMS local_stream_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 156 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 157 | "c=IN IP4 74.125.127.126\r\n" |
| 158 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 159 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 160 | "generation 2\r\n" |
| 161 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 162 | "generation 2\r\n" |
| 163 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 164 | "generation 2\r\n" |
| 165 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 166 | "generation 2\r\n" |
| 167 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 168 | "raddr 192.168.1.5 rport 2346 " |
| 169 | "generation 2\r\n" |
| 170 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 171 | "raddr 192.168.1.5 rport 2348 " |
| 172 | "generation 2\r\n" |
| 173 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 174 | "a=mid:audio_content_name\r\n" |
| 175 | "a=sendrecv\r\n" |
| 176 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 177 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 178 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 179 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 180 | "dummy_session_params\r\n" |
| 181 | "a=rtpmap:111 opus/48000/2\r\n" |
| 182 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 183 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 184 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 185 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 186 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 187 | "a=ssrc:1 label:audio_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 188 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 189 | "c=IN IP4 74.125.224.39\r\n" |
| 190 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 191 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 192 | "generation 2\r\n" |
| 193 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 194 | "generation 2\r\n" |
| 195 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 196 | "generation 2\r\n" |
| 197 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 198 | "generation 2\r\n" |
| 199 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 200 | "generation 2\r\n" |
| 201 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 202 | "generation 2\r\n" |
| 203 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 204 | "a=mid:video_content_name\r\n" |
| 205 | "a=sendrecv\r\n" |
| 206 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 207 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 208 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 209 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 210 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 211 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 212 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 213 | "a=ssrc:2 label:video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 214 | "a=ssrc:3 cname:stream_1_cname\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 215 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 216 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 217 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 218 | |
| 219 | // SDP reference string without the candidates. |
| 220 | static const char kSdpString[] = |
| 221 | "v=0\r\n" |
| 222 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 223 | "s=-\r\n" |
| 224 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 225 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 226 | "a=msid-semantic: WMS local_stream_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 227 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 228 | "c=IN IP4 0.0.0.0\r\n" |
| 229 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 230 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 231 | "a=mid:audio_content_name\r\n" |
| 232 | "a=sendrecv\r\n" |
| 233 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 234 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 235 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 236 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 237 | "dummy_session_params\r\n" |
| 238 | "a=rtpmap:111 opus/48000/2\r\n" |
| 239 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 240 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 241 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 242 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 243 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 244 | "a=ssrc:1 label:audio_track_id_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 245 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 246 | "c=IN IP4 0.0.0.0\r\n" |
| 247 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 248 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 249 | "a=mid:video_content_name\r\n" |
| 250 | "a=sendrecv\r\n" |
| 251 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 252 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 253 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 254 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 255 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 256 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 257 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 258 | "a=ssrc:2 label:video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 259 | "a=ssrc:3 cname:stream_1_cname\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 260 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 261 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 262 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 263 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 264 | // draft-ietf-mmusic-sctp-sdp-03 |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 265 | static const char kSdpSctpDataChannelString[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 266 | "m=application 9 UDP/DTLS/SCTP 5000\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 267 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 268 | "a=ice-ufrag:ufrag_data\r\n" |
| 269 | "a=ice-pwd:pwd_data\r\n" |
| 270 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 | [diff] [blame] | 271 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 272 | |
lally@webrtc.org | ec97c65 | 2015-02-24 20:18:48 | [diff] [blame] | 273 | // draft-ietf-mmusic-sctp-sdp-12 |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 274 | // Note - this is invalid per draft-ietf-mmusic-sctp-sdp-26, |
| 275 | // since the separator after "sctp-port" needs to be a colon. |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 276 | static const char kSdpSctpDataChannelStringWithSctpPort[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 277 | "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n" |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 | [diff] [blame] | 278 | "a=sctp-port 5000\r\n" |
| 279 | "c=IN IP4 0.0.0.0\r\n" |
| 280 | "a=ice-ufrag:ufrag_data\r\n" |
| 281 | "a=ice-pwd:pwd_data\r\n" |
| 282 | "a=mid:data_content_name\r\n"; |
| 283 | |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 284 | // draft-ietf-mmusic-sctp-sdp-26 |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 285 | static const char kSdpSctpDataChannelStringWithSctpColonPort[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 286 | "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n" |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 287 | "a=sctp-port:5000\r\n" |
| 288 | "c=IN IP4 0.0.0.0\r\n" |
| 289 | "a=ice-ufrag:ufrag_data\r\n" |
| 290 | "a=ice-pwd:pwd_data\r\n" |
| 291 | "a=mid:data_content_name\r\n"; |
| 292 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 293 | static const char kSdpSctpDataChannelWithCandidatesString[] = |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 294 | "m=application 2345 UDP/DTLS/SCTP 5000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 295 | "c=IN IP4 74.125.127.126\r\n" |
| 296 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 297 | "generation 2\r\n" |
| 298 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 299 | "generation 2\r\n" |
| 300 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 301 | "raddr 192.168.1.5 rport 2346 " |
| 302 | "generation 2\r\n" |
| 303 | "a=ice-ufrag:ufrag_data\r\n" |
| 304 | "a=ice-pwd:pwd_data\r\n" |
| 305 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 | [diff] [blame] | 306 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 307 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 308 | static const char kSdpConferenceString[] = |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 309 | "v=0\r\n" |
| 310 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 311 | "s=-\r\n" |
| 312 | "t=0 0\r\n" |
| 313 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 314 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 315 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 316 | "a=x-google-flag:conference\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 317 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 318 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 319 | "a=x-google-flag:conference\r\n"; |
| 320 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 321 | static const char kSdpSessionString[] = |
| 322 | "v=0\r\n" |
| 323 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 324 | "s=-\r\n" |
| 325 | "t=0 0\r\n" |
| 326 | "a=msid-semantic: WMS local_stream\r\n"; |
| 327 | |
| 328 | static const char kSdpAudioString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 329 | "m=audio 9 RTP/SAVPF 111\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 330 | "c=IN IP4 0.0.0.0\r\n" |
| 331 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 332 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 333 | "a=mid:audio_content_name\r\n" |
| 334 | "a=sendrecv\r\n" |
| 335 | "a=rtpmap:111 opus/48000/2\r\n" |
| 336 | "a=ssrc:1 cname:stream_1_cname\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 337 | "a=ssrc:1 msid:local_stream audio_track_id_1\r\n" |
| 338 | "a=ssrc:1 mslabel:local_stream\r\n" |
| 339 | "a=ssrc:1 label:audio_track_id_1\r\n"; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 340 | |
| 341 | static const char kSdpVideoString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 342 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 | [diff] [blame] | 343 | "c=IN IP4 0.0.0.0\r\n" |
| 344 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 345 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 346 | "a=mid:video_content_name\r\n" |
| 347 | "a=sendrecv\r\n" |
| 348 | "a=rtpmap:120 VP8/90000\r\n" |
| 349 | "a=ssrc:2 cname:stream_1_cname\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 350 | "a=ssrc:2 msid:local_stream video_track_id_1\r\n" |
| 351 | "a=ssrc:2 mslabel:local_stream\r\n" |
| 352 | "a=ssrc:2 label:video_track_id_1\r\n"; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 353 | |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 354 | // Reference sdp string using bundle-only. |
| 355 | static const char kBundleOnlySdpFullString[] = |
| 356 | "v=0\r\n" |
| 357 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 358 | "s=-\r\n" |
| 359 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 360 | "a=extmap-allow-mixed\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 361 | "a=group:BUNDLE audio_content_name video_content_name\r\n" |
| 362 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 363 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 364 | "c=IN IP4 74.125.127.126\r\n" |
| 365 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 366 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 367 | "generation 2\r\n" |
| 368 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 369 | "generation 2\r\n" |
| 370 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 371 | "generation 2\r\n" |
| 372 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 373 | "generation 2\r\n" |
| 374 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 375 | "raddr 192.168.1.5 rport 2346 " |
| 376 | "generation 2\r\n" |
| 377 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 378 | "raddr 192.168.1.5 rport 2348 " |
| 379 | "generation 2\r\n" |
| 380 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 381 | "a=mid:audio_content_name\r\n" |
| 382 | "a=sendrecv\r\n" |
| 383 | "a=rtcp-mux\r\n" |
| 384 | "a=rtcp-rsize\r\n" |
| 385 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 386 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 387 | "dummy_session_params\r\n" |
| 388 | "a=rtpmap:111 opus/48000/2\r\n" |
| 389 | "a=rtpmap:103 ISAC/16000\r\n" |
| 390 | "a=rtpmap:104 ISAC/32000\r\n" |
| 391 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 392 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 393 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 394 | "a=ssrc:1 label:audio_track_id_1\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 395 | "m=video 0 RTP/SAVPF 120\r\n" |
| 396 | "c=IN IP4 0.0.0.0\r\n" |
| 397 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 398 | "a=bundle-only\r\n" |
| 399 | "a=mid:video_content_name\r\n" |
| 400 | "a=sendrecv\r\n" |
| 401 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 402 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 403 | "a=rtpmap:120 VP8/90000\r\n" |
| 404 | "a=ssrc-group:FEC 2 3\r\n" |
| 405 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 406 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 407 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 408 | "a=ssrc:2 label:video_track_id_1\r\n" |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 409 | "a=ssrc:3 cname:stream_1_cname\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 410 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 411 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 412 | "a=ssrc:3 label:video_track_id_1\r\n"; |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 413 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 414 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 415 | // tracks. |
| 416 | static const char kPlanBSdpFullString[] = |
| 417 | "v=0\r\n" |
| 418 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 419 | "s=-\r\n" |
| 420 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 421 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 422 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 423 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 424 | "c=IN IP4 74.125.127.126\r\n" |
| 425 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 426 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 427 | "generation 2\r\n" |
| 428 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 429 | "generation 2\r\n" |
| 430 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 431 | "generation 2\r\n" |
| 432 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 433 | "generation 2\r\n" |
| 434 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 435 | "raddr 192.168.1.5 rport 2346 " |
| 436 | "generation 2\r\n" |
| 437 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 438 | "raddr 192.168.1.5 rport 2348 " |
| 439 | "generation 2\r\n" |
| 440 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 441 | "a=mid:audio_content_name\r\n" |
| 442 | "a=sendrecv\r\n" |
| 443 | "a=rtcp-mux\r\n" |
| 444 | "a=rtcp-rsize\r\n" |
| 445 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 446 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 447 | "dummy_session_params\r\n" |
| 448 | "a=rtpmap:111 opus/48000/2\r\n" |
| 449 | "a=rtpmap:103 ISAC/16000\r\n" |
| 450 | "a=rtpmap:104 ISAC/32000\r\n" |
| 451 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 452 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 453 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 454 | "a=ssrc:1 label:audio_track_id_1\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 455 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 456 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 457 | "a=ssrc:4 mslabel:local_stream_2\r\n" |
| 458 | "a=ssrc:4 label:audio_track_id_2\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 459 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 460 | "c=IN IP4 74.125.224.39\r\n" |
| 461 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 462 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 463 | "generation 2\r\n" |
| 464 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 465 | "generation 2\r\n" |
| 466 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 467 | "generation 2\r\n" |
| 468 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 469 | "generation 2\r\n" |
| 470 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 471 | "generation 2\r\n" |
| 472 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 473 | "generation 2\r\n" |
| 474 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 475 | "a=mid:video_content_name\r\n" |
| 476 | "a=sendrecv\r\n" |
| 477 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 478 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 479 | "a=rtpmap:120 VP8/90000\r\n" |
| 480 | "a=ssrc-group:FEC 2 3\r\n" |
| 481 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 482 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 483 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 484 | "a=ssrc:2 label:video_track_id_1\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 485 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 486 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 487 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 488 | "a=ssrc:3 label:video_track_id_1\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 489 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 490 | "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 491 | "a=ssrc:5 mslabel:local_stream_2\r\n" |
| 492 | "a=ssrc:5 label:video_track_id_2\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 493 | "a=ssrc:6 cname:stream_2_cname\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 494 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n" |
| 495 | "a=ssrc:6 mslabel:local_stream_2\r\n" |
| 496 | "a=ssrc:6 label:video_track_id_3\r\n"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 497 | |
| 498 | // Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 499 | // tracks. |
| 500 | static const char kUnifiedPlanSdpFullString[] = |
| 501 | "v=0\r\n" |
| 502 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 503 | "s=-\r\n" |
| 504 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 505 | "a=extmap-allow-mixed\r\n" |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 506 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 507 | // Audio track 1, stream 1 (with candidates). |
| 508 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 509 | "c=IN IP4 74.125.127.126\r\n" |
| 510 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 511 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 512 | "generation 2\r\n" |
| 513 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 514 | "generation 2\r\n" |
| 515 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 516 | "generation 2\r\n" |
| 517 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 518 | "generation 2\r\n" |
| 519 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 520 | "raddr 192.168.1.5 rport 2346 " |
| 521 | "generation 2\r\n" |
| 522 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 523 | "raddr 192.168.1.5 rport 2348 " |
| 524 | "generation 2\r\n" |
| 525 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 526 | "a=mid:audio_content_name\r\n" |
| 527 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 528 | "a=sendrecv\r\n" |
| 529 | "a=rtcp-mux\r\n" |
| 530 | "a=rtcp-rsize\r\n" |
| 531 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 532 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 533 | "dummy_session_params\r\n" |
| 534 | "a=rtpmap:111 opus/48000/2\r\n" |
| 535 | "a=rtpmap:103 ISAC/16000\r\n" |
| 536 | "a=rtpmap:104 ISAC/32000\r\n" |
| 537 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 538 | // Video track 1, stream 1 (with candidates). |
| 539 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 540 | "c=IN IP4 74.125.224.39\r\n" |
| 541 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 542 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 543 | "generation 2\r\n" |
| 544 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 545 | "generation 2\r\n" |
| 546 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 547 | "generation 2\r\n" |
| 548 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 549 | "generation 2\r\n" |
| 550 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 551 | "generation 2\r\n" |
| 552 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 553 | "generation 2\r\n" |
| 554 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 555 | "a=mid:video_content_name\r\n" |
| 556 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 557 | "a=sendrecv\r\n" |
| 558 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 559 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 560 | "a=rtpmap:120 VP8/90000\r\n" |
| 561 | "a=ssrc-group:FEC 2 3\r\n" |
| 562 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 563 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 564 | // Audio track 2, stream 2. |
| 565 | "m=audio 9 RTP/SAVPF 111 103 104\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_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 569 | "a=mid:audio_content_name_2\r\n" |
| 570 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
| 571 | "a=sendrecv\r\n" |
| 572 | "a=rtcp-mux\r\n" |
| 573 | "a=rtcp-rsize\r\n" |
| 574 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 575 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 576 | "dummy_session_params\r\n" |
| 577 | "a=rtpmap:111 opus/48000/2\r\n" |
| 578 | "a=rtpmap:103 ISAC/16000\r\n" |
| 579 | "a=rtpmap:104 ISAC/32000\r\n" |
| 580 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 581 | // Video track 2, stream 2. |
| 582 | "m=video 9 RTP/SAVPF 120\r\n" |
| 583 | "c=IN IP4 0.0.0.0\r\n" |
| 584 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 585 | "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n" |
| 586 | "a=mid:video_content_name_2\r\n" |
| 587 | "a=msid:local_stream_2 video_track_id_2\r\n" |
| 588 | "a=sendrecv\r\n" |
| 589 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 590 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 591 | "a=rtpmap:120 VP8/90000\r\n" |
| 592 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 593 | // Video track 3, stream 2. |
| 594 | "m=video 9 RTP/SAVPF 120\r\n" |
| 595 | "c=IN IP4 0.0.0.0\r\n" |
| 596 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 597 | "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n" |
| 598 | "a=mid:video_content_name_3\r\n" |
| 599 | "a=msid:local_stream_2 video_track_id_3\r\n" |
| 600 | "a=sendrecv\r\n" |
| 601 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 602 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 603 | "a=rtpmap:120 VP8/90000\r\n" |
| 604 | "a=ssrc:6 cname:stream_2_cname\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 605 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 606 | // Unified Plan SDP reference string: |
| 607 | // - audio track 1 has 1 a=msid lines |
| 608 | // - audio track 2 has 2 a=msid lines |
| 609 | // - audio track 3 has 1 a=msid line with the special "-" marker signifying that |
| 610 | // there are 0 media stream ids. |
| 611 | // This Unified Plan SDP represents a SDP that signals the msid using both |
| 612 | // a=msid and a=ssrc msid semantics. |
| 613 | static const char kUnifiedPlanSdpFullStringWithSpecialMsid[] = |
| 614 | "v=0\r\n" |
| 615 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 616 | "s=-\r\n" |
| 617 | "t=0 0\r\n" |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 618 | "a=extmap-allow-mixed\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 619 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 620 | // Audio track 1, with 1 stream id. |
| 621 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 622 | "c=IN IP4 74.125.127.126\r\n" |
| 623 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 624 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 625 | "generation 2\r\n" |
| 626 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 627 | "generation 2\r\n" |
| 628 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 629 | "generation 2\r\n" |
| 630 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 631 | "generation 2\r\n" |
| 632 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 633 | "raddr 192.168.1.5 rport 2346 " |
| 634 | "generation 2\r\n" |
| 635 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 636 | "raddr 192.168.1.5 rport 2348 " |
| 637 | "generation 2\r\n" |
| 638 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 639 | "a=mid:audio_content_name\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 640 | "a=sendrecv\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 641 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 642 | "a=rtcp-mux\r\n" |
| 643 | "a=rtcp-rsize\r\n" |
| 644 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 645 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 646 | "dummy_session_params\r\n" |
| 647 | "a=rtpmap:111 opus/48000/2\r\n" |
| 648 | "a=rtpmap:103 ISAC/16000\r\n" |
| 649 | "a=rtpmap:104 ISAC/32000\r\n" |
| 650 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 651 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 652 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 653 | "a=ssrc:1 label:audio_track_id_1\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 654 | // Audio track 2, with two stream ids. |
| 655 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 656 | "c=IN IP4 0.0.0.0\r\n" |
| 657 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 658 | "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 659 | "a=mid:audio_content_name_2\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 660 | "a=sendrecv\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 661 | "a=msid:local_stream_1 audio_track_id_2\r\n" |
| 662 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 663 | "a=rtcp-mux\r\n" |
| 664 | "a=rtcp-rsize\r\n" |
| 665 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 666 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 667 | "dummy_session_params\r\n" |
| 668 | "a=rtpmap:111 opus/48000/2\r\n" |
| 669 | "a=rtpmap:103 ISAC/16000\r\n" |
| 670 | "a=rtpmap:104 ISAC/32000\r\n" |
| 671 | "a=ssrc:4 cname:stream_1_cname\r\n" |
| 672 | // The support for Plan B msid signaling only includes the |
| 673 | // first media stream id "local_stream_1." |
| 674 | "a=ssrc:4 msid:local_stream_1 audio_track_id_2\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 675 | "a=ssrc:4 mslabel:local_stream_1\r\n" |
| 676 | "a=ssrc:4 label:audio_track_id_2\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 677 | // Audio track 3, with no stream ids. |
| 678 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 679 | "c=IN IP4 0.0.0.0\r\n" |
| 680 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 681 | "a=ice-ufrag:ufrag_voice_3\r\na=ice-pwd:pwd_voice_3\r\n" |
| 682 | "a=mid:audio_content_name_3\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 683 | "a=sendrecv\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 684 | "a=msid:- audio_track_id_3\r\n" |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 685 | "a=rtcp-mux\r\n" |
| 686 | "a=rtcp-rsize\r\n" |
| 687 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 688 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 689 | "dummy_session_params\r\n" |
| 690 | "a=rtpmap:111 opus/48000/2\r\n" |
| 691 | "a=rtpmap:103 ISAC/16000\r\n" |
| 692 | "a=rtpmap:104 ISAC/32000\r\n" |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 693 | "a=ssrc:7 cname:stream_2_cname\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 694 | "a=ssrc:7 msid:- audio_track_id_3\r\n" |
| 695 | "a=ssrc:7 mslabel:-\r\n" |
| 696 | "a=ssrc:7 label:audio_track_id_3\r\n"; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 697 | |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 698 | // SDP string for unified plan without SSRCs |
| 699 | static const char kUnifiedPlanSdpFullStringNoSsrc[] = |
| 700 | "v=0\r\n" |
| 701 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 702 | "s=-\r\n" |
| 703 | "t=0 0\r\n" |
| 704 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 705 | // Audio track 1, stream 1 (with candidates). |
| 706 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 707 | "c=IN IP4 74.125.127.126\r\n" |
| 708 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 709 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 710 | "generation 2\r\n" |
| 711 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 712 | "generation 2\r\n" |
| 713 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 714 | "generation 2\r\n" |
| 715 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 716 | "generation 2\r\n" |
| 717 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 718 | "raddr 192.168.1.5 rport 2346 " |
| 719 | "generation 2\r\n" |
| 720 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 721 | "raddr 192.168.1.5 rport 2348 " |
| 722 | "generation 2\r\n" |
| 723 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 724 | "a=mid:audio_content_name\r\n" |
| 725 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 726 | "a=sendrecv\r\n" |
| 727 | "a=rtcp-mux\r\n" |
| 728 | "a=rtcp-rsize\r\n" |
| 729 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 730 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 731 | "dummy_session_params\r\n" |
| 732 | "a=rtpmap:111 opus/48000/2\r\n" |
| 733 | "a=rtpmap:103 ISAC/16000\r\n" |
| 734 | "a=rtpmap:104 ISAC/32000\r\n" |
| 735 | // Video track 1, stream 1 (with candidates). |
| 736 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 737 | "c=IN IP4 74.125.224.39\r\n" |
| 738 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 739 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 740 | "generation 2\r\n" |
| 741 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 742 | "generation 2\r\n" |
| 743 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 744 | "generation 2\r\n" |
| 745 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 746 | "generation 2\r\n" |
| 747 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 748 | "generation 2\r\n" |
| 749 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 750 | "generation 2\r\n" |
| 751 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 752 | "a=mid:video_content_name\r\n" |
| 753 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 754 | "a=sendrecv\r\n" |
| 755 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 756 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 757 | "a=rtpmap:120 VP8/90000\r\n" |
| 758 | // Audio track 2, stream 2. |
| 759 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 760 | "c=IN IP4 0.0.0.0\r\n" |
| 761 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 762 | "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 763 | "a=mid:audio_content_name_2\r\n" |
| 764 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
| 765 | "a=sendrecv\r\n" |
| 766 | "a=rtcp-mux\r\n" |
| 767 | "a=rtcp-rsize\r\n" |
| 768 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 769 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 770 | "dummy_session_params\r\n" |
| 771 | "a=rtpmap:111 opus/48000/2\r\n" |
| 772 | "a=rtpmap:103 ISAC/16000\r\n" |
| 773 | "a=rtpmap:104 ISAC/32000\r\n" |
| 774 | // Video track 2, stream 2. |
| 775 | "m=video 9 RTP/SAVPF 120\r\n" |
| 776 | "c=IN IP4 0.0.0.0\r\n" |
| 777 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 778 | "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n" |
| 779 | "a=mid:video_content_name_2\r\n" |
| 780 | "a=msid:local_stream_2 video_track_id_2\r\n" |
| 781 | "a=sendrecv\r\n" |
| 782 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 783 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 784 | "a=rtpmap:120 VP8/90000\r\n" |
| 785 | // Video track 3, stream 2. |
| 786 | "m=video 9 RTP/SAVPF 120\r\n" |
| 787 | "c=IN IP4 0.0.0.0\r\n" |
| 788 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 789 | "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n" |
| 790 | "a=mid:video_content_name_3\r\n" |
| 791 | "a=msid:local_stream_2 video_track_id_3\r\n" |
| 792 | "a=sendrecv\r\n" |
| 793 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 794 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 795 | "a=rtpmap:120 VP8/90000\r\n"; |
| 796 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 797 | // One candidate reference string as per W3c spec. |
| 798 | // candidate:<blah> not a=candidate:<blah>CRLF |
| 799 | static const char kRawCandidate[] = |
| 800 | "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2"; |
| 801 | // One candidate reference string. |
| 802 | static const char kSdpOneCandidate[] = |
| 803 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 804 | "generation 2\r\n"; |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 805 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 806 | static const char kSdpTcpActiveCandidate[] = |
| 807 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 808 | "tcptype active generation 2"; |
| 809 | static const char kSdpTcpPassiveCandidate[] = |
| 810 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 811 | "tcptype passive generation 2"; |
| 812 | static const char kSdpTcpSOCandidate[] = |
| 813 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 814 | "tcptype so generation 2"; |
| 815 | static const char kSdpTcpInvalidCandidate[] = |
| 816 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 817 | "tcptype invalid generation 2"; |
| 818 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 819 | // One candidate reference string with IPV6 address. |
| 820 | static const char kRawIPV6Candidate[] = |
| 821 | "candidate:a0+B/1 1 udp 2130706432 " |
ehmaldonado | 121cabb | 2017-05-05 19:04:36 | [diff] [blame] | 822 | "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] | 823 | |
| 824 | // One candidate reference string. |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 825 | static const char kSdpOneCandidateWithUfragPwd[] = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 826 | "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] | 827 | " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 828 | |
Zach Stein | b336c27 | 2018-08-09 08:16:13 | [diff] [blame] | 829 | static const char kRawHostnameCandidate[] = |
| 830 | "candidate:a0+B/1 1 udp 2130706432 a.test 1234 typ host generation 2"; |
| 831 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 832 | // Session id and version |
| 833 | static const char kSessionId[] = "18446744069414584320"; |
| 834 | static const char kSessionVersion[] = "18446462598732840960"; |
| 835 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 836 | // ICE options. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 837 | static const char kIceOption1[] = "iceoption1"; |
| 838 | static const char kIceOption2[] = "iceoption2"; |
| 839 | static const char kIceOption3[] = "iceoption3"; |
| 840 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 841 | // ICE ufrags/passwords. |
| 842 | static const char kUfragVoice[] = "ufrag_voice"; |
| 843 | static const char kPwdVoice[] = "pwd_voice"; |
| 844 | static const char kUfragVideo[] = "ufrag_video"; |
| 845 | static const char kPwdVideo[] = "pwd_video"; |
| 846 | static const char kUfragData[] = "ufrag_data"; |
| 847 | static const char kPwdData[] = "pwd_data"; |
| 848 | |
| 849 | // Extra ufrags/passwords for extra unified plan m= sections. |
| 850 | static const char kUfragVoice2[] = "ufrag_voice_2"; |
| 851 | static const char kPwdVoice2[] = "pwd_voice_2"; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 852 | static const char kUfragVoice3[] = "ufrag_voice_3"; |
| 853 | static const char kPwdVoice3[] = "pwd_voice_3"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 854 | static const char kUfragVideo2[] = "ufrag_video_2"; |
| 855 | static const char kPwdVideo2[] = "pwd_video_2"; |
| 856 | static const char kUfragVideo3[] = "ufrag_video_3"; |
| 857 | static const char kPwdVideo3[] = "pwd_video_3"; |
| 858 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 859 | // Content name |
| 860 | static const char kAudioContentName[] = "audio_content_name"; |
| 861 | static const char kVideoContentName[] = "video_content_name"; |
| 862 | static const char kDataContentName[] = "data_content_name"; |
| 863 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 864 | // Extra content names for extra unified plan m= sections. |
| 865 | static const char kAudioContentName2[] = "audio_content_name_2"; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 866 | static const char kAudioContentName3[] = "audio_content_name_3"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 867 | static const char kVideoContentName2[] = "video_content_name_2"; |
| 868 | static const char kVideoContentName3[] = "video_content_name_3"; |
| 869 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 870 | // MediaStream 1 |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 871 | static const char kStreamId1[] = "local_stream_1"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 872 | static const char kStream1Cname[] = "stream_1_cname"; |
| 873 | static const char kAudioTrackId1[] = "audio_track_id_1"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 874 | static const uint32_t kAudioTrack1Ssrc = 1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 875 | static const char kVideoTrackId1[] = "video_track_id_1"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 876 | static const uint32_t kVideoTrack1Ssrc1 = 2; |
| 877 | static const uint32_t kVideoTrack1Ssrc2 = 3; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 878 | |
| 879 | // MediaStream 2 |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 880 | static const char kStreamId2[] = "local_stream_2"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 881 | static const char kStream2Cname[] = "stream_2_cname"; |
| 882 | static const char kAudioTrackId2[] = "audio_track_id_2"; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 883 | static const uint32_t kAudioTrack2Ssrc = 4; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 884 | static const char kVideoTrackId2[] = "video_track_id_2"; |
| 885 | static const uint32_t kVideoTrack2Ssrc = 5; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 886 | static const char kVideoTrackId3[] = "video_track_id_3"; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 887 | static const uint32_t kVideoTrack3Ssrc = 6; |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 888 | static const char kAudioTrackId3[] = "audio_track_id_3"; |
| 889 | static const uint32_t kAudioTrack3Ssrc = 7; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 890 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 891 | // Candidate |
| 892 | static const char kDummyMid[] = "dummy_mid"; |
| 893 | static const int kDummyIndex = 123; |
| 894 | |
| 895 | // Misc |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 896 | static SdpType kDummyType = SdpType::kOffer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 897 | |
| 898 | // Helper functions |
| 899 | |
| 900 | static bool SdpDeserialize(const std::string& message, |
| 901 | JsepSessionDescription* jdesc) { |
| 902 | return webrtc::SdpDeserialize(message, jdesc, NULL); |
| 903 | } |
| 904 | |
| 905 | static bool SdpDeserializeCandidate(const std::string& message, |
| 906 | JsepIceCandidate* candidate) { |
| 907 | return webrtc::SdpDeserializeCandidate(message, candidate, NULL); |
| 908 | } |
| 909 | |
| 910 | // Add some extra |newlines| to the |message| after |line|. |
| 911 | static void InjectAfter(const std::string& line, |
| 912 | const std::string& newlines, |
| 913 | std::string* message) { |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 914 | absl::StrReplaceAll({{line, line + newlines}}, message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | static void Replace(const std::string& line, |
| 918 | const std::string& newlines, |
| 919 | std::string* message) { |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 920 | absl::StrReplaceAll({{line, newlines}}, message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 921 | } |
| 922 | |
Philipp Hancke | b70c953 | 2021-01-13 09:40:06 | [diff] [blame] | 923 | // Expect a parse failure on the line containing |bad_part| when attempting to |
| 924 | // parse |bad_sdp|. |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 925 | static void ExpectParseFailure(const std::string& bad_sdp, |
| 926 | const std::string& bad_part) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 927 | JsepSessionDescription desc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 928 | SdpParseError error; |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 929 | bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error); |
Harald Alvestrand | 99bcf60 | 2021-03-03 07:44:39 | [diff] [blame] | 930 | ASSERT_FALSE(ret); |
| 931 | EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str())) |
| 932 | << "Did not find " << bad_part << " in " << error.line; |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | // Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|. |
| 936 | static void ExpectParseFailure(const char* good_part, const char* bad_part) { |
| 937 | std::string bad_sdp = kSdpFullString; |
| 938 | Replace(good_part, bad_part, &bad_sdp); |
| 939 | ExpectParseFailure(bad_sdp, bad_part); |
| 940 | } |
| 941 | |
| 942 | // Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|. |
| 943 | static void ExpectParseFailureWithNewLines(const std::string& injectpoint, |
| 944 | const std::string& newlines, |
| 945 | const std::string& bad_part) { |
| 946 | std::string bad_sdp = kSdpFullString; |
| 947 | InjectAfter(injectpoint, newlines, &bad_sdp); |
| 948 | ExpectParseFailure(bad_sdp, bad_part); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 949 | } |
| 950 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 951 | static void ReplaceDirection(RtpTransceiverDirection direction, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 952 | std::string* message) { |
| 953 | std::string new_direction; |
| 954 | switch (direction) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 955 | case RtpTransceiverDirection::kInactive: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 956 | new_direction = "a=inactive"; |
| 957 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 958 | case RtpTransceiverDirection::kSendOnly: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 959 | new_direction = "a=sendonly"; |
| 960 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 961 | case RtpTransceiverDirection::kRecvOnly: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 962 | new_direction = "a=recvonly"; |
| 963 | break; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 964 | case RtpTransceiverDirection::kSendRecv: |
Markus Handell | 45c104b | 2020-03-11 09:51:13 | [diff] [blame] | 965 | new_direction = "a=sendrecv"; |
| 966 | break; |
| 967 | case RtpTransceiverDirection::kStopped: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 968 | default: |
Markus Handell | 45c104b | 2020-03-11 09:51:13 | [diff] [blame] | 969 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 970 | new_direction = "a=sendrecv"; |
| 971 | break; |
| 972 | } |
| 973 | Replace("a=sendrecv", new_direction, message); |
| 974 | } |
| 975 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 976 | static void ReplaceRejected(bool audio_rejected, |
| 977 | bool video_rejected, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 978 | std::string* message) { |
| 979 | if (audio_rejected) { |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 980 | Replace("m=audio 9", "m=audio 0", message); |
| 981 | Replace(kAttributeIceUfragVoice, "", message); |
| 982 | Replace(kAttributeIcePwdVoice, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 983 | } |
| 984 | if (video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 985 | Replace("m=video 9", "m=video 0", message); |
| 986 | Replace(kAttributeIceUfragVideo, "", message); |
| 987 | Replace(kAttributeIcePwdVideo, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
| 991 | // WebRtcSdpTest |
| 992 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 993 | class WebRtcSdpTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 994 | public: |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 995 | WebRtcSdpTest() : jdesc_(kDummyType) { |
phoglund | 37ebcf0 | 2016-01-08 13:04:57 | [diff] [blame] | 996 | #ifdef WEBRTC_ANDROID |
| 997 | webrtc::InitializeAndroidObjects(); |
| 998 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 999 | // AudioContentDescription |
| 1000 | audio_desc_ = CreateAudioContentDescription(); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1001 | StreamParams audio_stream; |
| 1002 | audio_stream.id = kAudioTrackId1; |
| 1003 | audio_stream.cname = kStream1Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1004 | audio_stream.set_stream_ids({kStreamId1}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1005 | audio_stream.ssrcs.push_back(kAudioTrack1Ssrc); |
| 1006 | audio_desc_->AddStream(audio_stream); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 1007 | rtc::SocketAddress audio_addr("74.125.127.126", 2345); |
| 1008 | audio_desc_->set_connection_address(audio_addr); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1009 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 1010 | absl::WrapUnique(audio_desc_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1011 | |
| 1012 | // VideoContentDescription |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1013 | video_desc_ = CreateVideoContentDescription(); |
| 1014 | StreamParams video_stream; |
| 1015 | video_stream.id = kVideoTrackId1; |
| 1016 | video_stream.cname = kStream1Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1017 | video_stream.set_stream_ids({kStreamId1}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1018 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc1); |
| 1019 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc2); |
| 1020 | cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs); |
| 1021 | video_stream.ssrc_groups.push_back(ssrc_group); |
| 1022 | video_desc_->AddStream(video_stream); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 1023 | rtc::SocketAddress video_addr("74.125.224.39", 3457); |
| 1024 | video_desc_->set_connection_address(video_addr); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1025 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, |
| 1026 | absl::WrapUnique(video_desc_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1027 | |
| 1028 | // TransportInfo |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1029 | desc_.AddTransportInfo(TransportInfo( |
| 1030 | kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))); |
| 1031 | desc_.AddTransportInfo(TransportInfo( |
| 1032 | kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1033 | |
| 1034 | // v4 host |
| 1035 | int port = 1234; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1036 | rtc::SocketAddress address("192.168.1.5", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1037 | Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1038 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1039 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1040 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1041 | Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1042 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1043 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1044 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1045 | Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1046 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1047 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1048 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1049 | Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1050 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 1051 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1052 | |
| 1053 | // v6 host |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1054 | rtc::SocketAddress v6_address("::1", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1055 | cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1056 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1057 | cricket::LOCAL_PORT_TYPE, |
| 1058 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1059 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1060 | cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1061 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1062 | cricket::LOCAL_PORT_TYPE, |
| 1063 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1064 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1065 | cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1066 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1067 | cricket::LOCAL_PORT_TYPE, |
| 1068 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1069 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1070 | cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1071 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1072 | cricket::LOCAL_PORT_TYPE, |
| 1073 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1074 | |
| 1075 | // stun |
| 1076 | int port_stun = 2345; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1077 | rtc::SocketAddress address_stun("74.125.127.126", port_stun++); |
| 1078 | rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1079 | cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1080 | address_stun, kCandidatePriority, "", "", |
| 1081 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1082 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1083 | candidate9.set_related_address(rel_address_stun); |
| 1084 | |
| 1085 | address_stun.SetPort(port_stun++); |
| 1086 | rel_address_stun.SetPort(port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1087 | cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1088 | address_stun, kCandidatePriority, "", "", |
| 1089 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1090 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1091 | candidate10.set_related_address(rel_address_stun); |
| 1092 | |
| 1093 | // relay |
| 1094 | int port_relay = 3456; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 1095 | rtc::SocketAddress address_relay("74.125.224.39", port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1096 | cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 1097 | address_relay, kCandidatePriority, "", "", |
| 1098 | cricket::RELAY_PORT_TYPE, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1099 | kCandidateGeneration, kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1100 | address_relay.SetPort(port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 1101 | cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1102 | address_relay, kCandidatePriority, "", "", |
| 1103 | RELAY_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 1104 | kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1105 | |
| 1106 | // voice |
| 1107 | candidates_.push_back(candidate1); |
| 1108 | candidates_.push_back(candidate2); |
| 1109 | candidates_.push_back(candidate5); |
| 1110 | candidates_.push_back(candidate6); |
| 1111 | candidates_.push_back(candidate9); |
| 1112 | candidates_.push_back(candidate10); |
| 1113 | |
| 1114 | // video |
| 1115 | candidates_.push_back(candidate3); |
| 1116 | candidates_.push_back(candidate4); |
| 1117 | candidates_.push_back(candidate7); |
| 1118 | candidates_.push_back(candidate8); |
| 1119 | candidates_.push_back(candidate11); |
| 1120 | candidates_.push_back(candidate12); |
| 1121 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1122 | jcandidate_.reset( |
| 1123 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1124 | |
| 1125 | // Set up JsepSessionDescription. |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1126 | jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1127 | std::string mline_id; |
| 1128 | int mline_index = 0; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1129 | for (size_t i = 0; i < candidates_.size(); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1130 | // In this test, the audio m line index will be 0, and the video m line |
| 1131 | // will be 1. |
| 1132 | bool is_video = (i > 5); |
| 1133 | mline_id = is_video ? "video_content_name" : "audio_content_name"; |
| 1134 | mline_index = is_video ? 1 : 0; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1135 | JsepIceCandidate jice(mline_id, mline_index, candidates_.at(i)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1136 | jdesc_.AddCandidate(&jice); |
| 1137 | } |
| 1138 | } |
| 1139 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1140 | void RemoveVideoCandidates() { |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1141 | const IceCandidateCollection* video_candidates_collection = |
| 1142 | jdesc_.candidates(1); |
| 1143 | ASSERT_NE(nullptr, video_candidates_collection); |
| 1144 | std::vector<cricket::Candidate> video_candidates; |
| 1145 | for (size_t i = 0; i < video_candidates_collection->count(); ++i) { |
| 1146 | cricket::Candidate c = video_candidates_collection->at(i)->candidate(); |
| 1147 | c.set_transport_name("video_content_name"); |
| 1148 | video_candidates.push_back(c); |
| 1149 | } |
| 1150 | jdesc_.RemoveCandidates(video_candidates); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | // Turns the existing reference description into a description using |
| 1154 | // a=bundle-only. This means no transport attributes and a 0 port value on |
| 1155 | // the m= sections not associated with the BUNDLE-tag. |
| 1156 | void MakeBundleOnlyDescription() { |
| 1157 | RemoveVideoCandidates(); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1158 | |
| 1159 | // And the rest of the transport attributes. |
| 1160 | desc_.transport_infos()[1].description.ice_ufrag.clear(); |
| 1161 | desc_.transport_infos()[1].description.ice_pwd.clear(); |
| 1162 | desc_.transport_infos()[1].description.connection_role = |
| 1163 | cricket::CONNECTIONROLE_NONE; |
| 1164 | |
| 1165 | // Set bundle-only flag. |
| 1166 | desc_.contents()[1].bundle_only = true; |
| 1167 | |
| 1168 | // Add BUNDLE group. |
| 1169 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1170 | group.AddContentName(kAudioContentName); |
| 1171 | group.AddContentName(kVideoContentName); |
| 1172 | desc_.AddGroup(group); |
| 1173 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1174 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1175 | jdesc_.session_version())); |
| 1176 | } |
| 1177 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1178 | // Turns the existing reference description into a plan B description, |
| 1179 | // with 2 audio tracks and 3 video tracks. |
| 1180 | void MakePlanBDescription() { |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1181 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1182 | video_desc_ = new VideoContentDescription(*video_desc_); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1183 | |
| 1184 | StreamParams audio_track_2; |
| 1185 | audio_track_2.id = kAudioTrackId2; |
| 1186 | audio_track_2.cname = kStream2Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1187 | audio_track_2.set_stream_ids({kStreamId2}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1188 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1189 | audio_desc_->AddStream(audio_track_2); |
| 1190 | |
| 1191 | StreamParams video_track_2; |
| 1192 | video_track_2.id = kVideoTrackId2; |
| 1193 | video_track_2.cname = kStream2Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1194 | video_track_2.set_stream_ids({kStreamId2}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1195 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 1196 | video_desc_->AddStream(video_track_2); |
| 1197 | |
| 1198 | StreamParams video_track_3; |
| 1199 | video_track_3.id = kVideoTrackId3; |
| 1200 | video_track_3.cname = kStream2Cname; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1201 | video_track_3.set_stream_ids({kStreamId2}); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1202 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 1203 | video_desc_->AddStream(video_track_3); |
| 1204 | |
| 1205 | desc_.RemoveContentByName(kAudioContentName); |
| 1206 | desc_.RemoveContentByName(kVideoContentName); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1207 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 1208 | absl::WrapUnique(audio_desc_)); |
| 1209 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, |
| 1210 | absl::WrapUnique(video_desc_)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1211 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1212 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1213 | jdesc_.session_version())); |
| 1214 | } |
| 1215 | |
| 1216 | // Turns the existing reference description into a unified plan description, |
| 1217 | // with 2 audio tracks and 3 video tracks. |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1218 | void MakeUnifiedPlanDescription(bool use_ssrcs = true) { |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1219 | // Audio track 2. |
| 1220 | AudioContentDescription* audio_desc_2 = CreateAudioContentDescription(); |
| 1221 | StreamParams audio_track_2; |
| 1222 | audio_track_2.id = kAudioTrackId2; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1223 | audio_track_2.set_stream_ids({kStreamId2}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1224 | if (use_ssrcs) { |
| 1225 | audio_track_2.cname = kStream2Cname; |
| 1226 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1227 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1228 | audio_desc_2->AddStream(audio_track_2); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1229 | desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, |
| 1230 | absl::WrapUnique(audio_desc_2)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1231 | desc_.AddTransportInfo(TransportInfo( |
| 1232 | kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1233 | // Video track 2, in stream 2. |
| 1234 | VideoContentDescription* video_desc_2 = CreateVideoContentDescription(); |
| 1235 | StreamParams video_track_2; |
| 1236 | video_track_2.id = kVideoTrackId2; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1237 | video_track_2.set_stream_ids({kStreamId2}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1238 | if (use_ssrcs) { |
| 1239 | video_track_2.cname = kStream2Cname; |
| 1240 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 1241 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1242 | video_desc_2->AddStream(video_track_2); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1243 | desc_.AddContent(kVideoContentName2, MediaProtocolType::kRtp, |
| 1244 | absl::WrapUnique(video_desc_2)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1245 | desc_.AddTransportInfo(TransportInfo( |
| 1246 | kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1247 | |
| 1248 | // Video track 3, in stream 2. |
| 1249 | VideoContentDescription* video_desc_3 = CreateVideoContentDescription(); |
| 1250 | StreamParams video_track_3; |
| 1251 | video_track_3.id = kVideoTrackId3; |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1252 | video_track_3.set_stream_ids({kStreamId2}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1253 | if (use_ssrcs) { |
| 1254 | video_track_3.cname = kStream2Cname; |
| 1255 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 1256 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1257 | video_desc_3->AddStream(video_track_3); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1258 | desc_.AddContent(kVideoContentName3, MediaProtocolType::kRtp, |
| 1259 | absl::WrapUnique(video_desc_3)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1260 | desc_.AddTransportInfo(TransportInfo( |
| 1261 | kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 1262 | desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1263 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1264 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1265 | jdesc_.session_version())); |
| 1266 | } |
| 1267 | |
| 1268 | // Creates an audio content description with no streams, and some default |
| 1269 | // configuration. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1270 | AudioContentDescription* CreateAudioContentDescription() { |
| 1271 | AudioContentDescription* audio = new AudioContentDescription(); |
| 1272 | audio->set_rtcp_mux(true); |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 1273 | audio->set_rtcp_reduced_size(true); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1274 | audio->AddCrypto(CryptoParams( |
| 1275 | 1, "AES_CM_128_HMAC_SHA1_32", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1276 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32", |
| 1277 | "dummy_session_params")); |
| 1278 | audio->set_protocol(cricket::kMediaProtocolSavpf); |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 1279 | audio->AddCodec(AudioCodec(111, "opus", 48000, 0, 2)); |
ossu | e1405ad | 2017-01-23 16:55:48 | [diff] [blame] | 1280 | audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1)); |
| 1281 | audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1282 | return audio; |
| 1283 | } |
| 1284 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1285 | // Turns the existing reference description into a unified plan description, |
| 1286 | // with 3 audio MediaContentDescriptions with special StreamParams that |
| 1287 | // contain 0 or multiple stream ids: - audio track 1 has 1 media stream id - |
| 1288 | // 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] | 1289 | void MakeUnifiedPlanDescriptionMultipleStreamIds(const int msid_signaling) { |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1290 | desc_.RemoveContentByName(kVideoContentName); |
| 1291 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 1292 | RemoveVideoCandidates(); |
| 1293 | |
| 1294 | // Audio track 2 has 2 media stream ids. |
| 1295 | AudioContentDescription* audio_desc_2 = CreateAudioContentDescription(); |
| 1296 | StreamParams audio_track_2; |
| 1297 | audio_track_2.id = kAudioTrackId2; |
| 1298 | audio_track_2.cname = kStream1Cname; |
| 1299 | audio_track_2.set_stream_ids({kStreamId1, kStreamId2}); |
| 1300 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1301 | audio_desc_2->AddStream(audio_track_2); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1302 | desc_.AddContent(kAudioContentName2, MediaProtocolType::kRtp, |
| 1303 | absl::WrapUnique(audio_desc_2)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1304 | desc_.AddTransportInfo(TransportInfo( |
| 1305 | kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1306 | |
| 1307 | // Audio track 3 has no stream ids. |
| 1308 | AudioContentDescription* audio_desc_3 = CreateAudioContentDescription(); |
| 1309 | StreamParams audio_track_3; |
| 1310 | audio_track_3.id = kAudioTrackId3; |
| 1311 | audio_track_3.cname = kStream2Cname; |
| 1312 | audio_track_3.set_stream_ids({}); |
| 1313 | audio_track_3.ssrcs.push_back(kAudioTrack3Ssrc); |
| 1314 | audio_desc_3->AddStream(audio_track_3); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1315 | desc_.AddContent(kAudioContentName3, MediaProtocolType::kRtp, |
| 1316 | absl::WrapUnique(audio_desc_3)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1317 | desc_.AddTransportInfo(TransportInfo( |
| 1318 | kAudioContentName3, TransportDescription(kUfragVoice3, kPwdVoice3))); |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 1319 | desc_.set_msid_signaling(msid_signaling); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1320 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 1321 | jdesc_.session_version())); |
| 1322 | } |
| 1323 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1324 | // Turns the existing reference description into a unified plan description |
| 1325 | // with one audio MediaContentDescription that contains one StreamParams with |
| 1326 | // 0 ssrcs. |
| 1327 | void MakeUnifiedPlanDescriptionNoSsrcSignaling() { |
| 1328 | desc_.RemoveContentByName(kVideoContentName); |
| 1329 | desc_.RemoveContentByName(kAudioContentName); |
| 1330 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 1331 | RemoveVideoCandidates(); |
| 1332 | |
| 1333 | AudioContentDescription* audio_desc = CreateAudioContentDescription(); |
| 1334 | StreamParams audio_track; |
| 1335 | audio_track.id = kAudioTrackId1; |
| 1336 | audio_track.set_stream_ids({kStreamId1}); |
| 1337 | audio_desc->AddStream(audio_track); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1338 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 1339 | absl::WrapUnique(audio_desc)); |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1340 | |
| 1341 | // Enable signaling a=msid lines. |
| 1342 | desc_.set_msid_signaling(cricket::kMsidSignalingMediaSection); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1343 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1344 | jdesc_.session_version())); |
| 1345 | } |
| 1346 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1347 | // Creates a video content description with no streams, and some default |
| 1348 | // configuration. |
| 1349 | VideoContentDescription* CreateVideoContentDescription() { |
| 1350 | VideoContentDescription* video = new VideoContentDescription(); |
| 1351 | video->AddCrypto(CryptoParams( |
| 1352 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 1353 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", "")); |
| 1354 | video->set_protocol(cricket::kMediaProtocolSavpf); |
| 1355 | video->AddCodec( |
perkj | 2675274 | 2016-10-24 08:21:16 | [diff] [blame] | 1356 | VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1357 | return video; |
| 1358 | } |
| 1359 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1360 | template <class MCD> |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1361 | void CompareMediaContentDescription(const MCD* cd1, const MCD* cd2) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1362 | // type |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1363 | EXPECT_EQ(cd1->type(), cd2->type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1364 | |
| 1365 | // content direction |
| 1366 | EXPECT_EQ(cd1->direction(), cd2->direction()); |
| 1367 | |
| 1368 | // rtcp_mux |
| 1369 | EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux()); |
| 1370 | |
deadbeef | 1387149 | 2015-12-09 20:37:51 | [diff] [blame] | 1371 | // rtcp_reduced_size |
| 1372 | EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size()); |
| 1373 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1374 | // cryptos |
| 1375 | EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size()); |
| 1376 | if (cd1->cryptos().size() != cd2->cryptos().size()) { |
| 1377 | ADD_FAILURE(); |
| 1378 | return; |
| 1379 | } |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1380 | for (size_t i = 0; i < cd1->cryptos().size(); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1381 | const CryptoParams c1 = cd1->cryptos().at(i); |
| 1382 | const CryptoParams c2 = cd2->cryptos().at(i); |
| 1383 | EXPECT_TRUE(c1.Matches(c2)); |
| 1384 | EXPECT_EQ(c1.key_params, c2.key_params); |
| 1385 | EXPECT_EQ(c1.session_params, c2.session_params); |
| 1386 | } |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 | [diff] [blame] | 1387 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1388 | // protocol |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 | [diff] [blame] | 1389 | // Use an equivalence class here, for old and new versions of the |
| 1390 | // protocol description. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1391 | if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp || |
| 1392 | cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp || |
| 1393 | cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) { |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 1394 | const bool cd2_is_also_dtls_sctp = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1395 | cd2->protocol() == cricket::kMediaProtocolDtlsSctp || |
| 1396 | cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp || |
| 1397 | cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp; |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 1398 | EXPECT_TRUE(cd2_is_also_dtls_sctp); |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 | [diff] [blame] | 1399 | } else { |
| 1400 | EXPECT_EQ(cd1->protocol(), cd2->protocol()); |
| 1401 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1402 | |
| 1403 | // codecs |
| 1404 | EXPECT_EQ(cd1->codecs(), cd2->codecs()); |
| 1405 | |
| 1406 | // bandwidth |
| 1407 | EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth()); |
| 1408 | |
| 1409 | // streams |
| 1410 | EXPECT_EQ(cd1->streams(), cd2->streams()); |
| 1411 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 1412 | // extmap-allow-mixed |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 1413 | EXPECT_EQ(cd1->extmap_allow_mixed_enum(), cd2->extmap_allow_mixed_enum()); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 1414 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1415 | // extmap |
| 1416 | ASSERT_EQ(cd1->rtp_header_extensions().size(), |
| 1417 | cd2->rtp_header_extensions().size()); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1418 | for (size_t i = 0; i < cd1->rtp_header_extensions().size(); ++i) { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 1419 | const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); |
| 1420 | const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1421 | EXPECT_EQ(ext1.uri, ext2.uri); |
| 1422 | EXPECT_EQ(ext1.id, ext2.id); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1423 | EXPECT_EQ(ext1.encrypt, ext2.encrypt); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1424 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1425 | } |
| 1426 | |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1427 | void CompareRidDescriptionIds(const std::vector<RidDescription>& rids, |
| 1428 | const std::vector<std::string>& ids) { |
| 1429 | // Order of elements does not matter, only equivalence of sets. |
| 1430 | EXPECT_EQ(rids.size(), ids.size()); |
| 1431 | for (const std::string& id : ids) { |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 1432 | EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) { |
| 1433 | return rid.rid == id; |
| 1434 | })); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 1435 | } |
| 1436 | } |
| 1437 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 1438 | void CompareSimulcastDescription(const SimulcastDescription& simulcast1, |
| 1439 | const SimulcastDescription& simulcast2) { |
| 1440 | EXPECT_EQ(simulcast1.send_layers().size(), simulcast2.send_layers().size()); |
| 1441 | EXPECT_EQ(simulcast1.receive_layers().size(), |
| 1442 | simulcast2.receive_layers().size()); |
| 1443 | } |
| 1444 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1445 | void CompareSctpDataContentDescription( |
| 1446 | const SctpDataContentDescription* dcd1, |
| 1447 | const SctpDataContentDescription* dcd2) { |
Harald Alvestrand | 26bf7c4 | 2019-04-23 05:20:17 | [diff] [blame] | 1448 | EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap()); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1449 | EXPECT_EQ(dcd1->port(), dcd2->port()); |
| 1450 | EXPECT_EQ(dcd1->max_message_size(), dcd2->max_message_size()); |
Harald Alvestrand | 26bf7c4 | 2019-04-23 05:20:17 | [diff] [blame] | 1451 | } |
| 1452 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1453 | void CompareSessionDescription(const SessionDescription& desc1, |
| 1454 | const SessionDescription& desc2) { |
| 1455 | // Compare content descriptions. |
| 1456 | if (desc1.contents().size() != desc2.contents().size()) { |
| 1457 | ADD_FAILURE(); |
| 1458 | return; |
| 1459 | } |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1460 | for (size_t i = 0; i < desc1.contents().size(); ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1461 | const cricket::ContentInfo& c1 = desc1.contents().at(i); |
| 1462 | const cricket::ContentInfo& c2 = desc2.contents().at(i); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1463 | // ContentInfo properties. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1464 | EXPECT_EQ(c1.name, c2.name); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1465 | EXPECT_EQ(c1.type, c2.type); |
| 1466 | EXPECT_EQ(c1.rejected, c2.rejected); |
| 1467 | EXPECT_EQ(c1.bundle_only, c2.bundle_only); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1468 | |
| 1469 | ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2)); |
| 1470 | if (IsAudioContent(&c1)) { |
| 1471 | const AudioContentDescription* acd1 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1472 | c1.media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1473 | const AudioContentDescription* acd2 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1474 | c2.media_description()->as_audio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1475 | CompareMediaContentDescription<AudioContentDescription>(acd1, acd2); |
| 1476 | } |
| 1477 | |
| 1478 | ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2)); |
| 1479 | if (IsVideoContent(&c1)) { |
| 1480 | const VideoContentDescription* vcd1 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1481 | c1.media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1482 | const VideoContentDescription* vcd2 = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1483 | c2.media_description()->as_video(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1484 | CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2); |
| 1485 | } |
| 1486 | |
| 1487 | ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2)); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1488 | if (c1.media_description()->as_sctp()) { |
| 1489 | ASSERT_TRUE(c2.media_description()->as_sctp()); |
| 1490 | const SctpDataContentDescription* scd1 = |
| 1491 | c1.media_description()->as_sctp(); |
| 1492 | const SctpDataContentDescription* scd2 = |
| 1493 | c2.media_description()->as_sctp(); |
| 1494 | CompareSctpDataContentDescription(scd1, scd2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1495 | } |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 1496 | |
| 1497 | CompareSimulcastDescription( |
| 1498 | c1.media_description()->simulcast_description(), |
| 1499 | c2.media_description()->simulcast_description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | // group |
| 1503 | const cricket::ContentGroups groups1 = desc1.groups(); |
| 1504 | const cricket::ContentGroups groups2 = desc2.groups(); |
| 1505 | EXPECT_EQ(groups1.size(), groups1.size()); |
| 1506 | if (groups1.size() != groups2.size()) { |
| 1507 | ADD_FAILURE(); |
| 1508 | return; |
| 1509 | } |
| 1510 | for (size_t i = 0; i < groups1.size(); ++i) { |
| 1511 | const cricket::ContentGroup group1 = groups1.at(i); |
| 1512 | const cricket::ContentGroup group2 = groups2.at(i); |
| 1513 | EXPECT_EQ(group1.semantics(), group2.semantics()); |
| 1514 | const cricket::ContentNames names1 = group1.content_names(); |
| 1515 | const cricket::ContentNames names2 = group2.content_names(); |
| 1516 | EXPECT_EQ(names1.size(), names2.size()); |
| 1517 | if (names1.size() != names2.size()) { |
| 1518 | ADD_FAILURE(); |
| 1519 | return; |
| 1520 | } |
| 1521 | cricket::ContentNames::const_iterator iter1 = names1.begin(); |
| 1522 | cricket::ContentNames::const_iterator iter2 = names2.begin(); |
| 1523 | while (iter1 != names1.end()) { |
| 1524 | EXPECT_EQ(*iter1++, *iter2++); |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | // transport info |
| 1529 | const cricket::TransportInfos transports1 = desc1.transport_infos(); |
| 1530 | const cricket::TransportInfos transports2 = desc2.transport_infos(); |
| 1531 | EXPECT_EQ(transports1.size(), transports2.size()); |
| 1532 | if (transports1.size() != transports2.size()) { |
| 1533 | ADD_FAILURE(); |
| 1534 | return; |
| 1535 | } |
| 1536 | for (size_t i = 0; i < transports1.size(); ++i) { |
| 1537 | const cricket::TransportInfo transport1 = transports1.at(i); |
| 1538 | const cricket::TransportInfo transport2 = transports2.at(i); |
| 1539 | EXPECT_EQ(transport1.content_name, transport2.content_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1540 | EXPECT_EQ(transport1.description.ice_ufrag, |
| 1541 | transport2.description.ice_ufrag); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1542 | EXPECT_EQ(transport1.description.ice_pwd, transport2.description.ice_pwd); |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 1543 | EXPECT_EQ(transport1.description.ice_mode, |
| 1544 | transport2.description.ice_mode); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1545 | if (transport1.description.identity_fingerprint) { |
| 1546 | EXPECT_EQ(*transport1.description.identity_fingerprint, |
| 1547 | *transport2.description.identity_fingerprint); |
| 1548 | } else { |
| 1549 | EXPECT_EQ(transport1.description.identity_fingerprint.get(), |
| 1550 | transport2.description.identity_fingerprint.get()); |
| 1551 | } |
| 1552 | EXPECT_EQ(transport1.description.transport_options, |
| 1553 | transport2.description.transport_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1554 | } |
deadbeef | c80741f | 2015-10-22 20:14:45 | [diff] [blame] | 1555 | |
| 1556 | // global attributes |
| 1557 | EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported()); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 1558 | EXPECT_EQ(desc1.extmap_allow_mixed(), desc2.extmap_allow_mixed()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1559 | } |
| 1560 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1561 | bool CompareSessionDescription(const JsepSessionDescription& desc1, |
| 1562 | const JsepSessionDescription& desc2) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1563 | EXPECT_EQ(desc1.session_id(), desc2.session_id()); |
| 1564 | EXPECT_EQ(desc1.session_version(), desc2.session_version()); |
| 1565 | CompareSessionDescription(*desc1.description(), *desc2.description()); |
| 1566 | if (desc1.number_of_mediasections() != desc2.number_of_mediasections()) |
| 1567 | return false; |
| 1568 | for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) { |
| 1569 | const IceCandidateCollection* cc1 = desc1.candidates(i); |
| 1570 | const IceCandidateCollection* cc2 = desc2.candidates(i); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1571 | if (cc1->count() != cc2->count()) { |
| 1572 | ADD_FAILURE(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1573 | return false; |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 1574 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1575 | for (size_t j = 0; j < cc1->count(); ++j) { |
| 1576 | const IceCandidateInterface* c1 = cc1->at(j); |
| 1577 | const IceCandidateInterface* c2 = cc2->at(j); |
| 1578 | EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid()); |
| 1579 | EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index()); |
| 1580 | EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate())); |
| 1581 | } |
| 1582 | } |
| 1583 | return true; |
| 1584 | } |
| 1585 | |
| 1586 | // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing |
| 1587 | // them with invalid keywords so that the parser will just ignore them. |
| 1588 | bool RemoveCandidateUfragPwd(std::string* sdp) { |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 1589 | absl::StrReplaceAll( |
| 1590 | {{"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] | 1591 | return true; |
| 1592 | } |
| 1593 | |
| 1594 | // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1595 | bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, |
| 1596 | int mline_index, |
| 1597 | const std::string& ufrag, |
| 1598 | const std::string& pwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1599 | std::string content_name; |
| 1600 | if (mline_index == 0) { |
| 1601 | content_name = kAudioContentName; |
| 1602 | } else if (mline_index == 1) { |
| 1603 | content_name = kVideoContentName; |
| 1604 | } else { |
nisse | c80e741 | 2017-01-11 13:56:46 | [diff] [blame] | 1605 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1606 | } |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1607 | TransportInfo transport_info(content_name, |
| 1608 | TransportDescription(ufrag, pwd)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1609 | SessionDescription* desc = |
| 1610 | const_cast<SessionDescription*>(jdesc->description()); |
| 1611 | desc->RemoveTransportInfoByName(content_name); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1612 | desc->AddTransportInfo(transport_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1613 | for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) { |
| 1614 | const IceCandidateCollection* cc = jdesc_.candidates(i); |
| 1615 | for (size_t j = 0; j < cc->count(); ++j) { |
| 1616 | if (cc->at(j)->sdp_mline_index() == mline_index) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1617 | const_cast<Candidate&>(cc->at(j)->candidate()).set_username(ufrag); |
| 1618 | const_cast<Candidate&>(cc->at(j)->candidate()).set_password(pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | return true; |
| 1623 | } |
| 1624 | |
| 1625 | void AddIceOptions(const std::string& content_name, |
| 1626 | const std::vector<std::string>& transport_options) { |
| 1627 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1628 | cricket::TransportInfo transport_info = |
| 1629 | *(desc_.GetTransportInfoByName(content_name)); |
| 1630 | desc_.RemoveTransportInfoByName(content_name); |
| 1631 | transport_info.description.transport_options = transport_options; |
| 1632 | desc_.AddTransportInfo(transport_info); |
| 1633 | } |
| 1634 | |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1635 | void SetIceUfragPwd(const std::string& content_name, |
| 1636 | const std::string& ice_ufrag, |
| 1637 | const std::string& ice_pwd) { |
| 1638 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1639 | cricket::TransportInfo transport_info = |
| 1640 | *(desc_.GetTransportInfoByName(content_name)); |
| 1641 | desc_.RemoveTransportInfoByName(content_name); |
| 1642 | transport_info.description.ice_ufrag = ice_ufrag; |
| 1643 | transport_info.description.ice_pwd = ice_pwd; |
| 1644 | desc_.AddTransportInfo(transport_info); |
| 1645 | } |
| 1646 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1647 | void AddFingerprint() { |
| 1648 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 1649 | desc_.RemoveTransportInfoByName(kVideoContentName); |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 1650 | rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, kIdentityDigest); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1651 | desc_.AddTransportInfo(TransportInfo( |
deadbeef | 46eed76 | 2016-01-28 21:24:37 | [diff] [blame] | 1652 | kAudioContentName, |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1653 | TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice, |
| 1654 | cricket::ICEMODE_FULL, |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1655 | cricket::CONNECTIONROLE_NONE, &fingerprint))); |
| 1656 | desc_.AddTransportInfo(TransportInfo( |
deadbeef | 46eed76 | 2016-01-28 21:24:37 | [diff] [blame] | 1657 | kVideoContentName, |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1658 | TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, |
| 1659 | cricket::ICEMODE_FULL, |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1660 | cricket::CONNECTIONROLE_NONE, &fingerprint))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1661 | } |
| 1662 | |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1663 | void AddExtmap(bool encrypted) { |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1664 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1665 | video_desc_ = new VideoContentDescription(*video_desc_); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1666 | audio_desc_->AddRtpHeaderExtension( |
| 1667 | RtpExtension(kExtmapUri, kExtmapId, encrypted)); |
| 1668 | video_desc_->AddRtpHeaderExtension( |
| 1669 | RtpExtension(kExtmapUri, kExtmapId, encrypted)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1670 | desc_.RemoveContentByName(kAudioContentName); |
| 1671 | desc_.RemoveContentByName(kVideoContentName); |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1672 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, |
| 1673 | absl::WrapUnique(audio_desc_)); |
| 1674 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, |
| 1675 | absl::WrapUnique(video_desc_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | void RemoveCryptos() { |
| 1679 | audio_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1680 | video_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1681 | } |
| 1682 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1683 | // Removes everything in StreamParams from the session description that is |
| 1684 | // used for a=ssrc lines. |
| 1685 | void RemoveSsrcSignalingFromStreamParams() { |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1686 | for (cricket::ContentInfo& content_info : |
| 1687 | jdesc_.description()->contents()) { |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1688 | // With Unified Plan there should be one StreamParams per m= section. |
| 1689 | StreamParams& stream = |
| 1690 | content_info.media_description()->mutable_streams()[0]; |
| 1691 | stream.ssrcs.clear(); |
| 1692 | stream.ssrc_groups.clear(); |
| 1693 | stream.cname.clear(); |
| 1694 | } |
| 1695 | } |
| 1696 | |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 1697 | // Removes all a=ssrc lines from the SDP string, except for the |
| 1698 | // "a=ssrc:... cname:..." lines. |
| 1699 | void RemoveSsrcMsidLinesFromSdpString(std::string* sdp_string) { |
| 1700 | const char kAttributeSsrc[] = "a=ssrc"; |
| 1701 | const char kAttributeCname[] = "cname"; |
| 1702 | size_t ssrc_line_pos = sdp_string->find(kAttributeSsrc); |
| 1703 | while (ssrc_line_pos != std::string::npos) { |
| 1704 | size_t beg_line_pos = sdp_string->rfind('\n', ssrc_line_pos); |
| 1705 | size_t end_line_pos = sdp_string->find('\n', ssrc_line_pos); |
| 1706 | size_t cname_pos = sdp_string->find(kAttributeCname, ssrc_line_pos); |
| 1707 | if (cname_pos == std::string::npos || cname_pos > end_line_pos) { |
| 1708 | // Only erase a=ssrc lines that don't contain "cname". |
| 1709 | sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos); |
| 1710 | ssrc_line_pos = sdp_string->find(kAttributeSsrc, beg_line_pos); |
| 1711 | } else { |
| 1712 | // Skip the "a=ssrc:... cname" line and find the next "a=ssrc" line. |
| 1713 | ssrc_line_pos = sdp_string->find(kAttributeSsrc, end_line_pos); |
| 1714 | } |
| 1715 | } |
| 1716 | } |
| 1717 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 1718 | // Removes all a=ssrc lines from the SDP string. |
| 1719 | void RemoveSsrcLinesFromSdpString(std::string* sdp_string) { |
| 1720 | const char kAttributeSsrc[] = "a=ssrc"; |
| 1721 | while (sdp_string->find(kAttributeSsrc) != std::string::npos) { |
| 1722 | size_t pos_ssrc_attribute = sdp_string->find(kAttributeSsrc); |
| 1723 | size_t beg_line_pos = sdp_string->rfind('\n', pos_ssrc_attribute); |
| 1724 | size_t end_line_pos = sdp_string->find('\n', pos_ssrc_attribute); |
| 1725 | sdp_string->erase(beg_line_pos, end_line_pos - beg_line_pos); |
| 1726 | } |
| 1727 | } |
| 1728 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1729 | bool TestSerializeDirection(RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1730 | audio_desc_->set_direction(direction); |
| 1731 | video_desc_->set_direction(direction); |
| 1732 | std::string new_sdp = kSdpFullString; |
| 1733 | ReplaceDirection(direction, &new_sdp); |
| 1734 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1735 | if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1736 | jdesc_.session_version())) { |
| 1737 | return false; |
| 1738 | } |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 1739 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1740 | EXPECT_EQ(new_sdp, message); |
| 1741 | return true; |
| 1742 | } |
| 1743 | |
| 1744 | bool TestSerializeRejected(bool audio_rejected, bool video_rejected) { |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1745 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1746 | video_desc_ = new VideoContentDescription(*video_desc_); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 1747 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1748 | desc_.RemoveContentByName(kAudioContentName); |
| 1749 | desc_.RemoveContentByName(kVideoContentName); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1750 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1751 | absl::WrapUnique(audio_desc_)); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1752 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1753 | absl::WrapUnique(video_desc_)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1754 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1755 | audio_rejected ? "" : kPwdVoice); |
| 1756 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1757 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1758 | |
| 1759 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1760 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1761 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1762 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 1763 | MakeDescriptionWithoutCandidates(&jdesc_no_candidates); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 1764 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1765 | EXPECT_EQ(new_sdp, message); |
| 1766 | return true; |
| 1767 | } |
| 1768 | |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 1769 | void AddSctpDataChannel(bool use_sctpmap) { |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1770 | std::unique_ptr<SctpDataContentDescription> data( |
| 1771 | new SctpDataContentDescription()); |
| 1772 | sctp_desc_ = data.get(); |
| 1773 | sctp_desc_->set_use_sctpmap(use_sctpmap); |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 1774 | sctp_desc_->set_protocol(cricket::kMediaProtocolUdpDtlsSctp); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 1775 | sctp_desc_->set_port(kDefaultSctpPort); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1776 | desc_.AddContent(kDataContentName, MediaProtocolType::kSctp, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1777 | std::move(data)); |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1778 | desc_.AddTransportInfo(TransportInfo( |
| 1779 | kDataContentName, TransportDescription(kUfragData, kPwdData))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1780 | } |
| 1781 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 1782 | bool TestDeserializeDirection(RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1783 | std::string new_sdp = kSdpFullString; |
| 1784 | ReplaceDirection(direction, &new_sdp); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1785 | JsepSessionDescription new_jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1786 | |
| 1787 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1788 | |
| 1789 | audio_desc_->set_direction(direction); |
| 1790 | video_desc_->set_direction(direction); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1791 | if (!jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1792 | jdesc_.session_version())) { |
| 1793 | return false; |
| 1794 | } |
| 1795 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1796 | return true; |
| 1797 | } |
| 1798 | |
| 1799 | bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1800 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1801 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1802 | JsepSessionDescription new_jdesc(SdpType::kOffer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1803 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1804 | |
Harald Alvestrand | b97d2fe | 2020-02-28 10:54:40 | [diff] [blame] | 1805 | audio_desc_ = new AudioContentDescription(*audio_desc_); |
| 1806 | video_desc_ = new VideoContentDescription(*video_desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1807 | desc_.RemoveContentByName(kAudioContentName); |
| 1808 | desc_.RemoveContentByName(kVideoContentName); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1809 | desc_.AddContent(kAudioContentName, MediaProtocolType::kRtp, audio_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1810 | absl::WrapUnique(audio_desc_)); |
Steve Anton | 5adfafd | 2017-12-21 00:34:00 | [diff] [blame] | 1811 | desc_.AddContent(kVideoContentName, MediaProtocolType::kRtp, video_rejected, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1812 | absl::WrapUnique(video_desc_)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 1813 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1814 | audio_rejected ? "" : kPwdVoice); |
| 1815 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1816 | video_rejected ? "" : kPwdVideo); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1817 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1818 | if (!jdesc_no_candidates.Initialize(desc_.Clone(), jdesc_.session_id(), |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1819 | jdesc_.session_version())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1820 | return false; |
| 1821 | } |
deadbeef | 3f7219b | 2015-12-28 23:17:14 | [diff] [blame] | 1822 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1823 | return true; |
| 1824 | } |
| 1825 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1826 | void TestDeserializeExtmap(bool session_level, |
| 1827 | bool media_level, |
| 1828 | bool encrypted) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1829 | AddExtmap(encrypted); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1830 | JsepSessionDescription new_jdesc(SdpType::kOffer); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 1831 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1832 | jdesc_.session_version())); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 1833 | JsepSessionDescription jdesc_with_extmap(SdpType::kOffer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1834 | std::string sdp_with_extmap = kSdpString; |
| 1835 | if (session_level) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1836 | InjectAfter(kSessionTime, |
| 1837 | encrypted ? kExtmapWithDirectionAndAttributeEncrypted |
| 1838 | : kExtmapWithDirectionAndAttribute, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1839 | &sdp_with_extmap); |
| 1840 | } |
| 1841 | if (media_level) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1842 | InjectAfter(kAttributeIcePwdVoice, |
| 1843 | encrypted ? kExtmapWithDirectionAndAttributeEncrypted |
| 1844 | : kExtmapWithDirectionAndAttribute, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1845 | &sdp_with_extmap); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 1846 | InjectAfter(kAttributeIcePwdVideo, |
| 1847 | encrypted ? kExtmapWithDirectionAndAttributeEncrypted |
| 1848 | : kExtmapWithDirectionAndAttribute, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1849 | &sdp_with_extmap); |
| 1850 | } |
| 1851 | // The extmap can't be present at the same time in both session level and |
| 1852 | // media level. |
| 1853 | if (session_level && media_level) { |
| 1854 | SdpParseError error; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1855 | EXPECT_FALSE( |
| 1856 | webrtc::SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap, &error)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1857 | EXPECT_NE(std::string::npos, error.description.find("a=extmap")); |
| 1858 | } else { |
| 1859 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap)); |
| 1860 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc)); |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | void VerifyCodecParameter(const cricket::CodecParameterMap& params, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1865 | const std::string& name, |
| 1866 | int expected_value) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1867 | cricket::CodecParameterMap::const_iterator found = params.find(name); |
| 1868 | ASSERT_TRUE(found != params.end()); |
Jonas Olsson | 6b1985d | 2018-07-05 09:59:48 | [diff] [blame] | 1869 | EXPECT_EQ(found->second, rtc::ToString(expected_value)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | void TestDeserializeCodecParams(const CodecParams& params, |
| 1873 | JsepSessionDescription* jdesc_output) { |
| 1874 | std::string sdp = |
| 1875 | "v=0\r\n" |
| 1876 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1877 | "s=-\r\n" |
| 1878 | "t=0 0\r\n" |
| 1879 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1880 | // this parser, and will be added to the SDP when serializing a session |
| 1881 | // description. |
| 1882 | "a=msid-semantic: WMS\r\n" |
| 1883 | // Pl type 111 preferred. |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 1884 | "m=audio 9 RTP/SAVPF 111 104 103 105\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1885 | // Pltype 111 listed before 103 and 104 in the map. |
| 1886 | "a=rtpmap:111 opus/48000/2\r\n" |
| 1887 | // Pltype 103 listed before 104. |
| 1888 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 1889 | "a=rtpmap:104 ISAC/32000\r\n" |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 1890 | "a=rtpmap:105 telephone-event/8000\r\n" |
| 1891 | "a=fmtp:105 0-15,66,70\r\n" |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 | [diff] [blame] | 1892 | "a=fmtp:111 "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1893 | std::ostringstream os; |
Donald Curtis | 144d018 | 2015-05-15 20:14:24 | [diff] [blame] | 1894 | os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 | [diff] [blame] | 1895 | << "; sprop-stereo=" << params.sprop_stereo |
| 1896 | << "; useinbandfec=" << params.useinband |
Jonas Olsson | b2b2031 | 2020-01-14 11:11:31 | [diff] [blame] | 1897 | << "; maxaveragebitrate=" << params.maxaveragebitrate |
| 1898 | << "\r\n" |
| 1899 | "a=ptime:" |
| 1900 | << params.ptime |
| 1901 | << "\r\n" |
| 1902 | "a=maxptime:" |
| 1903 | << params.max_ptime << "\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1904 | sdp += os.str(); |
| 1905 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1906 | os.clear(); |
| 1907 | os.str(""); |
| 1908 | // Pl type 100 preferred. |
Philipp Hancke | b7bc243 | 2021-03-11 14:28:00 | [diff] [blame] | 1909 | os << "m=video 9 RTP/SAVPF 99 95 96\r\n" |
| 1910 | "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] | 1911 | "a=rtpmap:99 VP8/90000\r\n" |
| 1912 | "a=rtpmap:95 RTX/90000\r\n" |
| 1913 | "a=fmtp:95 apt=99;\r\n"; |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1914 | sdp += os.str(); |
| 1915 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1916 | // Deserialize |
| 1917 | SdpParseError error; |
| 1918 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1919 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1920 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1921 | GetFirstAudioContentDescription(jdesc_output->description()); |
| 1922 | ASSERT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1923 | ASSERT_FALSE(acd->codecs().empty()); |
| 1924 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1925 | EXPECT_EQ("opus", opus.name); |
| 1926 | EXPECT_EQ(111, opus.id); |
| 1927 | VerifyCodecParameter(opus.params, "minptime", params.min_ptime); |
| 1928 | VerifyCodecParameter(opus.params, "stereo", params.stereo); |
| 1929 | VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo); |
| 1930 | VerifyCodecParameter(opus.params, "useinbandfec", params.useinband); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 | [diff] [blame] | 1931 | VerifyCodecParameter(opus.params, "maxaveragebitrate", |
| 1932 | params.maxaveragebitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1933 | for (size_t i = 0; i < acd->codecs().size(); ++i) { |
| 1934 | cricket::AudioCodec codec = acd->codecs()[i]; |
| 1935 | VerifyCodecParameter(codec.params, "ptime", params.ptime); |
| 1936 | VerifyCodecParameter(codec.params, "maxptime", params.max_ptime); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1937 | } |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1938 | |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 1939 | cricket::AudioCodec dtmf = acd->codecs()[3]; |
| 1940 | EXPECT_EQ("telephone-event", dtmf.name); |
| 1941 | EXPECT_EQ(105, dtmf.id); |
| 1942 | EXPECT_EQ(3u, |
| 1943 | dtmf.params.size()); // ptime and max_ptime count as parameters. |
| 1944 | EXPECT_EQ(dtmf.params.begin()->first, ""); |
| 1945 | EXPECT_EQ(dtmf.params.begin()->second, "0-15,66,70"); |
| 1946 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1947 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1948 | GetFirstVideoContentDescription(jdesc_output->description()); |
| 1949 | ASSERT_TRUE(vcd); |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 1950 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1951 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1952 | EXPECT_EQ("VP8", vp8.name); |
| 1953 | EXPECT_EQ(99, vp8.id); |
| 1954 | cricket::VideoCodec rtx = vcd->codecs()[1]; |
| 1955 | EXPECT_EQ("RTX", rtx.name); |
| 1956 | EXPECT_EQ(95, rtx.id); |
| 1957 | VerifyCodecParameter(rtx.params, "apt", vp8.id); |
Philipp Hancke | b7bc243 | 2021-03-11 14:28:00 | [diff] [blame] | 1958 | // VP9 is listed last in the m= line so should come after VP8 and RTX. |
| 1959 | cricket::VideoCodec vp9 = vcd->codecs()[2]; |
| 1960 | EXPECT_EQ("VP9", vp9.name); |
| 1961 | EXPECT_EQ(96, vp9.id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output, |
| 1965 | bool use_wildcard) { |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1966 | std::string sdp_session_and_audio = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1967 | "v=0\r\n" |
| 1968 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1969 | "s=-\r\n" |
| 1970 | "t=0 0\r\n" |
| 1971 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1972 | // this parser, and will be added to the SDP when serializing a session |
| 1973 | // description. |
| 1974 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 1975 | "m=audio 9 RTP/SAVPF 111\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1976 | "a=rtpmap:111 opus/48000/2\r\n"; |
| 1977 | std::string sdp_video = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1978 | "m=video 3457 RTP/SAVPF 101\r\n" |
| 1979 | "a=rtpmap:101 VP8/90000\r\n" |
Elad Alon | fadb181 | 2019-05-24 11:40:02 | [diff] [blame] | 1980 | "a=rtcp-fb:101 goog-lntf\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1981 | "a=rtcp-fb:101 nack\r\n" |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 | [diff] [blame] | 1982 | "a=rtcp-fb:101 nack pli\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1983 | "a=rtcp-fb:101 goog-remb\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1984 | std::ostringstream os; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1985 | os << sdp_session_and_audio; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1986 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n"; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1987 | os << sdp_video; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1988 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n"; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 | [diff] [blame] | 1989 | std::string sdp = os.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1990 | // Deserialize |
| 1991 | SdpParseError error; |
| 1992 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1993 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 1994 | GetFirstAudioContentDescription(jdesc_output->description()); |
| 1995 | ASSERT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1996 | ASSERT_FALSE(acd->codecs().empty()); |
| 1997 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1998 | EXPECT_EQ(111, opus.id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1999 | EXPECT_TRUE(opus.HasFeedbackParam(cricket::FeedbackParam( |
| 2000 | cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2001 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2002 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2003 | GetFirstVideoContentDescription(jdesc_output->description()); |
| 2004 | ASSERT_TRUE(vcd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2005 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2006 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2007 | EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName, |
| 2008 | vp8.name.c_str()); |
| 2009 | EXPECT_EQ(101, vp8.id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2010 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
Elad Alon | fadb181 | 2019-05-24 11:40:02 | [diff] [blame] | 2011 | cricket::kRtcpFbParamLntf, cricket::kParamValueEmpty))); |
| 2012 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2013 | cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
| 2014 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
| 2015 | cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli))); |
| 2016 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
| 2017 | cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty))); |
| 2018 | EXPECT_TRUE(vp8.HasFeedbackParam(cricket::FeedbackParam( |
| 2019 | cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | // Two SDP messages can mean the same thing but be different strings, e.g. |
| 2023 | // some of the lines can be serialized in different order. |
| 2024 | // However, a deserialized description can be compared field by field and has |
| 2025 | // no order. If deserializer has already been tested, serializing then |
| 2026 | // deserializing and comparing JsepSessionDescription will test |
| 2027 | // the serializer sufficiently. |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2028 | void TestSerialize(const JsepSessionDescription& jdesc) { |
| 2029 | std::string message = webrtc::SdpSerialize(jdesc); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2030 | JsepSessionDescription jdesc_output_des(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2031 | SdpParseError error; |
| 2032 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); |
| 2033 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); |
| 2034 | } |
| 2035 | |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2036 | // Calling 'Initialize' with a copy of the inner SessionDescription will |
| 2037 | // create a copy of the JsepSessionDescription without candidates. The |
| 2038 | // 'connection address' field, previously set from the candidates, must also |
| 2039 | // be reset. |
| 2040 | void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) { |
| 2041 | rtc::SocketAddress audio_addr("0.0.0.0", 9); |
| 2042 | rtc::SocketAddress video_addr("0.0.0.0", 9); |
| 2043 | audio_desc_->set_connection_address(audio_addr); |
| 2044 | video_desc_->set_connection_address(video_addr); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2045 | ASSERT_TRUE(jdesc->Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2046 | } |
| 2047 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2048 | protected: |
| 2049 | SessionDescription desc_; |
| 2050 | AudioContentDescription* audio_desc_; |
| 2051 | VideoContentDescription* video_desc_; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2052 | SctpDataContentDescription* sctp_desc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2053 | Candidates candidates_; |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 2054 | std::unique_ptr<IceCandidateInterface> jcandidate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2055 | JsepSessionDescription jdesc_; |
| 2056 | }; |
| 2057 | |
| 2058 | void TestMismatch(const std::string& string1, const std::string& string2) { |
| 2059 | int position = 0; |
| 2060 | for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { |
| 2061 | if (string1.c_str()[i] != string2.c_str()[i]) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 | [diff] [blame] | 2062 | position = static_cast<int>(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2063 | break; |
| 2064 | } |
| 2065 | } |
| 2066 | EXPECT_EQ(0, position) << "Strings mismatch at the " << position |
| 2067 | << " character\n" |
Jonas Olsson | b2b2031 | 2020-01-14 11:11:31 | [diff] [blame] | 2068 | " 1: " |
| 2069 | << string1.substr(position, 20) |
| 2070 | << "\n" |
| 2071 | " 2: " |
| 2072 | << string2.substr(position, 20) << "\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2073 | } |
| 2074 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2075 | TEST_F(WebRtcSdpTest, SerializeSessionDescription) { |
| 2076 | // SessionDescription with desc and candidates. |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2077 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2078 | TestMismatch(std::string(kSdpFullString), message); |
| 2079 | } |
| 2080 | |
| 2081 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2082 | JsepSessionDescription jdesc_empty(kDummyType); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2083 | EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | // This tests serialization of SDP with a=crypto and a=fingerprint, as would be |
| 2087 | // the case in a DTLS offer. |
| 2088 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) { |
| 2089 | AddFingerprint(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2090 | JsepSessionDescription jdesc_with_fingerprint(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2091 | MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2092 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2093 | |
| 2094 | std::string sdp_with_fingerprint = kSdpString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2095 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2096 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2097 | |
| 2098 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 2099 | } |
| 2100 | |
| 2101 | // This tests serialization of SDP with a=fingerprint with no a=crypto, as would |
| 2102 | // be the case in a DTLS answer. |
| 2103 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) { |
| 2104 | AddFingerprint(); |
| 2105 | RemoveCryptos(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2106 | JsepSessionDescription jdesc_with_fingerprint(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2107 | MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2108 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2109 | |
| 2110 | std::string sdp_with_fingerprint = kSdpString; |
| 2111 | Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint); |
| 2112 | Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2113 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2114 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2115 | |
| 2116 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 2117 | } |
| 2118 | |
| 2119 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { |
| 2120 | // JsepSessionDescription with desc but without candidates. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2121 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2122 | MakeDescriptionWithoutCandidates(&jdesc_no_candidates); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2123 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2124 | EXPECT_EQ(std::string(kSdpString), message); |
| 2125 | } |
| 2126 | |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame^] | 2127 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundles) { |
| 2128 | ContentGroup group1(cricket::GROUP_TYPE_BUNDLE); |
| 2129 | group1.AddContentName(kAudioContentName); |
| 2130 | group1.AddContentName(kVideoContentName); |
| 2131 | desc_.AddGroup(group1); |
| 2132 | ContentGroup group2(cricket::GROUP_TYPE_BUNDLE); |
| 2133 | group2.AddContentName(kAudioContentName2); |
| 2134 | desc_.AddGroup(group2); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2135 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2136 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2137 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2138 | std::string sdp_with_bundle = kSdpFullString; |
| 2139 | InjectAfter(kSessionTime, |
Henrik Boström | f8187e0 | 2021-04-26 19:04:26 | [diff] [blame^] | 2140 | "a=group:BUNDLE audio_content_name video_content_name\r\n" |
| 2141 | "a=group:BUNDLE audio_content_name_2\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2142 | &sdp_with_bundle); |
| 2143 | EXPECT_EQ(sdp_with_bundle, message); |
| 2144 | } |
| 2145 | |
| 2146 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2147 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2148 | vcd->set_bandwidth(100 * 1000 + 755); // Integer division will drop the 755. |
| 2149 | vcd->set_bandwidth_type("AS"); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2150 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2151 | acd->set_bandwidth(555); |
| 2152 | acd->set_bandwidth_type("TIAS"); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2153 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2154 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2155 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2156 | std::string sdp_with_bandwidth = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2157 | 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] | 2158 | &sdp_with_bandwidth); |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2159 | InjectAfter("c=IN IP4 74.125.127.126\r\n", "b=TIAS:555\r\n", |
| 2160 | &sdp_with_bandwidth); |
| 2161 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 2162 | } |
| 2163 | |
| 2164 | // Should default to b=AS if bandwidth_type isn't set. |
| 2165 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithMissingBandwidthType) { |
| 2166 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 2167 | vcd->set_bandwidth(100 * 1000); |
| 2168 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 2169 | jdesc_.session_version())); |
| 2170 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 2171 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2172 | 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] | 2173 | &sdp_with_bandwidth); |
| 2174 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 2175 | } |
| 2176 | |
| 2177 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) { |
| 2178 | std::vector<std::string> transport_options; |
| 2179 | transport_options.push_back(kIceOption1); |
| 2180 | transport_options.push_back(kIceOption3); |
| 2181 | AddIceOptions(kAudioContentName, transport_options); |
| 2182 | transport_options.clear(); |
| 2183 | transport_options.push_back(kIceOption2); |
| 2184 | transport_options.push_back(kIceOption3); |
| 2185 | AddIceOptions(kVideoContentName, transport_options); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2186 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2187 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2188 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2189 | std::string sdp_with_ice_options = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2190 | InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1 iceoption3\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2191 | &sdp_with_ice_options); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2192 | InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2 iceoption3\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2193 | &sdp_with_ice_options); |
| 2194 | EXPECT_EQ(sdp_with_ice_options, message); |
| 2195 | } |
| 2196 | |
| 2197 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2198 | EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kRecvOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2202 | EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kSendOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2206 | EXPECT_TRUE(TestSerializeDirection(RtpTransceiverDirection::kInactive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) { |
| 2210 | EXPECT_TRUE(TestSerializeRejected(true, false)); |
| 2211 | } |
| 2212 | |
| 2213 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) { |
| 2214 | EXPECT_TRUE(TestSerializeRejected(false, true)); |
| 2215 | } |
| 2216 | |
| 2217 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) { |
| 2218 | EXPECT_TRUE(TestSerializeRejected(true, true)); |
| 2219 | } |
| 2220 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2221 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2222 | bool use_sctpmap = true; |
| 2223 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2224 | JsepSessionDescription jsep_desc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2225 | |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2226 | MakeDescriptionWithoutCandidates(&jsep_desc); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2227 | std::string message = webrtc::SdpSerialize(jsep_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2228 | |
| 2229 | std::string expected_sdp = kSdpString; |
| 2230 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2231 | EXPECT_EQ(message, expected_sdp); |
| 2232 | } |
| 2233 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2234 | void MutateJsepSctpPort(JsepSessionDescription* jdesc, |
| 2235 | const SessionDescription& desc, |
| 2236 | int port) { |
| 2237 | // Take our pre-built session description and change the SCTP port. |
| 2238 | std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone(); |
| 2239 | SctpDataContentDescription* dcdesc = |
| 2240 | mutant->GetContentDescriptionByName(kDataContentName)->as_sctp(); |
| 2241 | dcdesc->set_port(port); |
| 2242 | ASSERT_TRUE( |
| 2243 | jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion)); |
| 2244 | } |
| 2245 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2246 | TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2247 | bool use_sctpmap = true; |
| 2248 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2249 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2250 | MakeDescriptionWithoutCandidates(&jsep_desc); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2251 | |
| 2252 | const int kNewPort = 1234; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2253 | MutateJsepSctpPort(&jsep_desc, desc_, kNewPort); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2254 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2255 | std::string message = webrtc::SdpSerialize(jsep_desc); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2256 | |
| 2257 | std::string expected_sdp = kSdpString; |
| 2258 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2259 | |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 2260 | absl::StrReplaceAll( |
| 2261 | {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kNewPort)}}, |
| 2262 | &expected_sdp); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 2263 | |
| 2264 | EXPECT_EQ(expected_sdp, message); |
| 2265 | } |
| 2266 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2267 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapAllowMixed) { |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2268 | jdesc_.description()->set_extmap_allow_mixed(true); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2269 | TestSerialize(jdesc_); |
| 2270 | } |
| 2271 | |
| 2272 | TEST_F(WebRtcSdpTest, SerializeMediaContentDescriptionWithExtmapAllowMixed) { |
| 2273 | cricket::MediaContentDescription* video_desc = |
| 2274 | jdesc_.description()->GetContentDescriptionByName(kVideoContentName); |
| 2275 | ASSERT_TRUE(video_desc); |
| 2276 | cricket::MediaContentDescription* audio_desc = |
| 2277 | jdesc_.description()->GetContentDescriptionByName(kAudioContentName); |
| 2278 | ASSERT_TRUE(audio_desc); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2279 | video_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2280 | cricket::MediaContentDescription::kMedia); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2281 | audio_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2282 | cricket::MediaContentDescription::kMedia); |
| 2283 | TestSerialize(jdesc_); |
| 2284 | } |
| 2285 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2286 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2287 | bool encrypted = false; |
| 2288 | AddExtmap(encrypted); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2289 | JsepSessionDescription desc_with_extmap(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 2290 | MakeDescriptionWithoutCandidates(&desc_with_extmap); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2291 | std::string message = webrtc::SdpSerialize(desc_with_extmap); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2292 | |
| 2293 | std::string sdp_with_extmap = kSdpString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2294 | InjectAfter("a=mid:audio_content_name\r\n", kExtmap, &sdp_with_extmap); |
| 2295 | InjectAfter("a=mid:video_content_name\r\n", kExtmap, &sdp_with_extmap); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2296 | |
| 2297 | EXPECT_EQ(sdp_with_extmap, message); |
| 2298 | } |
| 2299 | |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2300 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) { |
| 2301 | bool encrypted = true; |
| 2302 | AddExtmap(encrypted); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2303 | JsepSessionDescription desc_with_extmap(kDummyType); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2304 | ASSERT_TRUE( |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2305 | desc_with_extmap.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2306 | TestSerialize(desc_with_extmap); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 2307 | } |
| 2308 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2309 | TEST_F(WebRtcSdpTest, SerializeCandidates) { |
| 2310 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); |
wu@webrtc.org | ec9f5fb | 2014-06-24 17:05:10 | [diff] [blame] | 2311 | EXPECT_EQ(std::string(kRawCandidate), message); |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 2312 | |
| 2313 | Candidate candidate_with_ufrag(candidates_.front()); |
| 2314 | candidate_with_ufrag.set_username("ABC"); |
| 2315 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, |
| 2316 | candidate_with_ufrag)); |
| 2317 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2318 | EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); |
honghaiz | a0c44ea | 2016-03-23 23:07:48 | [diff] [blame] | 2319 | |
| 2320 | Candidate candidate_with_network_info(candidates_.front()); |
| 2321 | candidate_with_network_info.set_network_id(1); |
| 2322 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2323 | candidate_with_network_info)); |
| 2324 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2325 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message); |
| 2326 | candidate_with_network_info.set_network_cost(999); |
| 2327 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2328 | candidate_with_network_info)); |
| 2329 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2330 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999", |
| 2331 | message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2332 | } |
| 2333 | |
Zach Stein | b336c27 | 2018-08-09 08:16:13 | [diff] [blame] | 2334 | TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) { |
| 2335 | rtc::SocketAddress address("a.test", 1234); |
| 2336 | cricket::Candidate candidate( |
| 2337 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority, |
| 2338 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 2339 | JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate); |
| 2340 | std::string message = webrtc::SdpSerializeCandidate(jcandidate); |
| 2341 | EXPECT_EQ(std::string(kRawHostnameCandidate), message); |
| 2342 | } |
| 2343 | |
mallinath@webrtc.org | e999bd0 | 2014-08-13 06:05:55 | [diff] [blame] | 2344 | TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 2345 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 2346 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2347 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2348 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2349 | candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 2350 | std::unique_ptr<IceCandidateInterface> jcandidate( |
| 2351 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2352 | |
| 2353 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
| 2354 | EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
| 2355 | } |
| 2356 | |
Taylor Brandstetter | 8206bc0 | 2020-04-02 19:36:38 | [diff] [blame] | 2357 | // Test serializing a TCP candidate that came in with a missing tcptype. This |
| 2358 | // shouldn't happen according to the spec, but our implementation has been |
| 2359 | // accepting this for quite some time, treating it as a passive candidate. |
| 2360 | // |
| 2361 | // So, we should be able to at least convert such candidates to and from SDP. |
| 2362 | // See: bugs.webrtc.org/11423 |
| 2363 | TEST_F(WebRtcSdpTest, ParseTcpCandidateWithoutTcptype) { |
| 2364 | std::string missing_tcptype = |
| 2365 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9999 typ host"; |
| 2366 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2367 | EXPECT_TRUE(SdpDeserializeCandidate(missing_tcptype, &jcandidate)); |
| 2368 | |
| 2369 | EXPECT_EQ(std::string(cricket::TCPTYPE_PASSIVE_STR), |
| 2370 | jcandidate.candidate().tcptype()); |
| 2371 | } |
| 2372 | |
| 2373 | TEST_F(WebRtcSdpTest, ParseSslTcpCandidate) { |
| 2374 | std::string ssltcp = |
| 2375 | "candidate:a0+B/1 1 ssltcp 2130706432 192.168.1.5 9999 typ host tcptype " |
| 2376 | "passive"; |
| 2377 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2378 | EXPECT_TRUE(SdpDeserializeCandidate(ssltcp, &jcandidate)); |
| 2379 | |
| 2380 | EXPECT_EQ(std::string("ssltcp"), jcandidate.candidate().protocol()); |
| 2381 | } |
| 2382 | |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2383 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) { |
magjed | 509e4fe | 2016-11-18 09:34:11 | [diff] [blame] | 2384 | cricket::VideoCodec h264_codec("H264"); |
| 2385 | h264_codec.SetParam("profile-level-id", "42e01f"); |
| 2386 | h264_codec.SetParam("level-asymmetry-allowed", "1"); |
| 2387 | h264_codec.SetParam("packetization-mode", "1"); |
| 2388 | video_desc_->AddCodec(h264_codec); |
| 2389 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2390 | jdesc_.Initialize(desc_.Clone(), kSessionId, kSessionVersion); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2391 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 2392 | std::string message = webrtc::SdpSerialize(jdesc_); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2393 | size_t after_pt = message.find(" H264/90000"); |
| 2394 | ASSERT_NE(after_pt, std::string::npos); |
| 2395 | size_t before_pt = message.rfind("a=rtpmap:", after_pt); |
| 2396 | ASSERT_NE(before_pt, std::string::npos); |
| 2397 | before_pt += strlen("a=rtpmap:"); |
| 2398 | std::string pt = message.substr(before_pt, after_pt - before_pt); |
| 2399 | // TODO(hta): Check if payload type |pt| occurs in the m=video line. |
| 2400 | std::string to_find = "a=fmtp:" + pt + " "; |
| 2401 | size_t fmtp_pos = message.find(to_find); |
| 2402 | ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find; |
Mirko Bonadei | 37ec55e | 2019-01-28 10:43:52 | [diff] [blame] | 2403 | size_t fmtp_endpos = message.find('\n', fmtp_pos); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2404 | ASSERT_NE(std::string::npos, fmtp_endpos); |
| 2405 | std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos); |
| 2406 | EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1")); |
| 2407 | EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1")); |
| 2408 | EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f")); |
hta | 62a216e | 2016-04-15 18:02:14 | [diff] [blame] | 2409 | // Check that there are no spaces after semicolons. |
| 2410 | // https://bugs.webrtc.org/5793 |
| 2411 | EXPECT_EQ(std::string::npos, fmtp_value.find("; ")); |
hta | a6b9944 | 2016-04-12 17:29:17 | [diff] [blame] | 2412 | } |
| 2413 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2414 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2415 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2416 | // Deserialize |
| 2417 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 2418 | // Verify |
| 2419 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2420 | } |
| 2421 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2422 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2423 | JsepSessionDescription jdesc(kDummyType); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2424 | const char kSdpWithoutMline[] = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2425 | "v=0\r\n" |
| 2426 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2427 | "s=-\r\n" |
| 2428 | "t=0 0\r\n" |
| 2429 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 | [diff] [blame] | 2430 | // Deserialize |
| 2431 | EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc)); |
| 2432 | EXPECT_EQ(0u, jdesc.description()->contents().size()); |
| 2433 | } |
| 2434 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2435 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2436 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2437 | std::string sdp_without_carriage_return = kSdpFullString; |
| 2438 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 2439 | // Deserialize |
| 2440 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 2441 | // Verify |
| 2442 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2443 | } |
| 2444 | |
| 2445 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 2446 | // SessionDescription with desc but without candidates. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2447 | JsepSessionDescription jdesc_no_candidates(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2448 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Clone(), kSessionId, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2449 | kSessionVersion)); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2450 | JsepSessionDescription new_jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2451 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 2452 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 2453 | } |
| 2454 | |
| 2455 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 2456 | static const char kSdpNoRtpmapString[] = |
| 2457 | "v=0\r\n" |
| 2458 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2459 | "s=-\r\n" |
| 2460 | "t=0 0\r\n" |
| 2461 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 2462 | // Codec that doesn't appear in the m= line will be ignored. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 2463 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2464 | // The rtpmap line for static payload codec is optional. |
| 2465 | "a=rtpmap:18 G729/16000\r\n" |
| 2466 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2467 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2468 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2469 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2470 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 2471 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2472 | AudioCodecs ref_codecs; |
deadbeef | 67cf2c1 | 2016-04-13 17:07:16 | [diff] [blame] | 2473 | // The codecs in the AudioContentDescription should be in the same order as |
| 2474 | // the payload types (<fmt>s) on the m= line. |
| 2475 | ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1)); |
| 2476 | ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1)); |
ossu | e1405ad | 2017-01-23 16:55:48 | [diff] [blame] | 2477 | ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2478 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 2479 | } |
| 2480 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2481 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) { |
| 2482 | static const char kSdpNoRtpmapString[] = |
| 2483 | "v=0\r\n" |
| 2484 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2485 | "s=-\r\n" |
| 2486 | "t=0 0\r\n" |
| 2487 | "m=audio 49232 RTP/AVP 18 103\r\n" |
| 2488 | "a=fmtp:18 annexb=yes\r\n" |
| 2489 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2490 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2491 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2492 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2493 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 2494 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2495 | |
| 2496 | cricket::AudioCodec g729 = audio->codecs()[0]; |
| 2497 | EXPECT_EQ("G729", g729.name); |
| 2498 | EXPECT_EQ(8000, g729.clockrate); |
| 2499 | EXPECT_EQ(18, g729.id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2500 | cricket::CodecParameterMap::iterator found = g729.params.find("annexb"); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 2501 | ASSERT_TRUE(found != g729.params.end()); |
| 2502 | EXPECT_EQ(found->second, "yes"); |
| 2503 | |
| 2504 | cricket::AudioCodec isac = audio->codecs()[1]; |
| 2505 | EXPECT_EQ("ISAC", isac.name); |
| 2506 | EXPECT_EQ(103, isac.id); |
| 2507 | EXPECT_EQ(16000, isac.clockrate); |
| 2508 | } |
| 2509 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2510 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 2511 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 2512 | // Add a DTLS a=fingerprint attribute to our session description. |
| 2513 | AddFingerprint(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2514 | JsepSessionDescription new_jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2515 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2516 | jdesc_.session_version())); |
| 2517 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2518 | JsepSessionDescription jdesc_with_fingerprint(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2519 | std::string sdp_with_fingerprint = kSdpString; |
| 2520 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2521 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 2522 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 2523 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 2524 | } |
| 2525 | |
| 2526 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2527 | JsepSessionDescription jdesc_with_bundle(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2528 | std::string sdp_with_bundle = kSdpFullString; |
| 2529 | InjectAfter(kSessionTime, |
| 2530 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 2531 | &sdp_with_bundle); |
| 2532 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 2533 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 2534 | group.AddContentName(kAudioContentName); |
| 2535 | group.AddContentName(kVideoContentName); |
| 2536 | desc_.AddGroup(group); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2537 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2538 | jdesc_.session_version())); |
| 2539 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 2540 | } |
| 2541 | |
| 2542 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2543 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2544 | std::string sdp_with_bandwidth = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2545 | 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] | 2546 | &sdp_with_bandwidth); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2547 | 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] | 2548 | &sdp_with_bandwidth); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2549 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2550 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2551 | vcd->set_bandwidth(100 * 1000); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 2552 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2553 | acd->set_bandwidth(50 * 1000); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2554 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2555 | jdesc_.session_version())); |
| 2556 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2557 | } |
| 2558 | |
Taylor Brandstetter | ee8c246 | 2020-07-27 22:52:02 | [diff] [blame] | 2559 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithTiasBandwidth) { |
| 2560 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
| 2561 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2562 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", "b=TIAS:100000\r\n", |
| 2563 | &sdp_with_bandwidth); |
| 2564 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", "b=TIAS:50000\r\n", |
| 2565 | &sdp_with_bandwidth); |
| 2566 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2567 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 2568 | vcd->set_bandwidth(100 * 1000); |
| 2569 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
| 2570 | acd->set_bandwidth(50 * 1000); |
| 2571 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 2572 | jdesc_.session_version())); |
| 2573 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2574 | } |
| 2575 | |
Philipp Hancke | fbbfc02 | 2020-07-31 06:30:50 | [diff] [blame] | 2576 | TEST_F(WebRtcSdpTest, |
| 2577 | DeserializeSessionDescriptionWithUnknownBandwidthModifier) { |
| 2578 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
| 2579 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2580 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 2581 | "b=unknown:100000\r\n", &sdp_with_bandwidth); |
| 2582 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 2583 | "b=unknown:50000\r\n", &sdp_with_bandwidth); |
| 2584 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2585 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 2586 | vcd->set_bandwidth(-1); |
| 2587 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
| 2588 | acd->set_bandwidth(-1); |
| 2589 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 2590 | jdesc_.session_version())); |
| 2591 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2592 | } |
| 2593 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2594 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2595 | JsepSessionDescription jdesc_with_ice_options(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2596 | std::string sdp_with_ice_options = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2597 | InjectAfter(kSessionTime, "a=ice-options:iceoption3\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2598 | &sdp_with_ice_options); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2599 | InjectAfter(kAttributeIcePwdVoice, "a=ice-options:iceoption1\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2600 | &sdp_with_ice_options); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2601 | InjectAfter(kAttributeIcePwdVideo, "a=ice-options:iceoption2\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2602 | &sdp_with_ice_options); |
| 2603 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 2604 | std::vector<std::string> transport_options; |
| 2605 | transport_options.push_back(kIceOption3); |
| 2606 | transport_options.push_back(kIceOption1); |
| 2607 | AddIceOptions(kAudioContentName, transport_options); |
| 2608 | transport_options.clear(); |
| 2609 | transport_options.push_back(kIceOption3); |
| 2610 | transport_options.push_back(kIceOption2); |
| 2611 | AddIceOptions(kVideoContentName, transport_options); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2612 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2613 | jdesc_.session_version())); |
| 2614 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 2615 | } |
| 2616 | |
| 2617 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 2618 | // Remove the original ice-ufrag and ice-pwd |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2619 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2620 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 2621 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 2622 | // Add session level ufrag and pwd |
| 2623 | InjectAfter(kSessionTime, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2624 | "a=ice-pwd:session+level+icepwd\r\n" |
| 2625 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 2626 | &sdp_with_ufrag_pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2627 | // Add media level ufrag and pwd for audio |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2628 | InjectAfter( |
| 2629 | "a=mid:audio_content_name\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2630 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 2631 | &sdp_with_ufrag_pwd); |
| 2632 | // Update the candidate ufrag and pwd to the expected ones. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2633 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, "media+level+iceufrag", |
| 2634 | "media+level+icepwd")); |
| 2635 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, "session+level+iceufrag", |
| 2636 | "session+level+icepwd")); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2637 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 2638 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 2639 | } |
| 2640 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2641 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2642 | EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kRecvOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2646 | EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kSendOnly)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 2650 | EXPECT_TRUE(TestDeserializeDirection(RtpTransceiverDirection::kInactive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 2654 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 2655 | } |
| 2656 | |
| 2657 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 2658 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 2659 | } |
| 2660 | |
| 2661 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 2662 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 2663 | } |
| 2664 | |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 2665 | // Tests that we can still handle the sdp uses mslabel and label instead of |
| 2666 | // msid for backward compatibility. |
| 2667 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) { |
| 2668 | jdesc_.description()->set_msid_supported(false); |
| 2669 | JsepSessionDescription jdesc(kDummyType); |
| 2670 | std::string sdp_without_msid = kSdpFullString; |
| 2671 | Replace("msid", "xmsid", &sdp_without_msid); |
| 2672 | // Deserialize |
| 2673 | EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc)); |
| 2674 | // Verify |
| 2675 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2676 | EXPECT_FALSE(jdesc.description()->msid_signaling() & |
| 2677 | ~cricket::kMsidSignalingSsrcAttribute); |
| 2678 | } |
| 2679 | |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2680 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithExtmapAllowMixed) { |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2681 | jdesc_.description()->set_extmap_allow_mixed(true); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2682 | std::string sdp_with_extmap_allow_mixed = kSdpFullString; |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2683 | // Deserialize |
| 2684 | JsepSessionDescription jdesc_deserialized(kDummyType); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2685 | ASSERT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized)); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2686 | // Verify |
| 2687 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized)); |
| 2688 | } |
| 2689 | |
| 2690 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutExtmapAllowMixed) { |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2691 | jdesc_.description()->set_extmap_allow_mixed(false); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2692 | std::string sdp_without_extmap_allow_mixed = kSdpFullString; |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2693 | Replace(kExtmapAllowMixed, "", &sdp_without_extmap_allow_mixed); |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2694 | // Deserialize |
| 2695 | JsepSessionDescription jdesc_deserialized(kDummyType); |
Emil Lundmark | 801c999 | 2021-01-19 12:06:32 | [diff] [blame] | 2696 | ASSERT_TRUE( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2697 | SdpDeserialize(sdp_without_extmap_allow_mixed, &jdesc_deserialized)); |
| 2698 | // Verify |
| 2699 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized)); |
| 2700 | } |
| 2701 | |
| 2702 | TEST_F(WebRtcSdpTest, DeserializeMediaContentDescriptionWithExtmapAllowMixed) { |
| 2703 | cricket::MediaContentDescription* video_desc = |
| 2704 | jdesc_.description()->GetContentDescriptionByName(kVideoContentName); |
| 2705 | ASSERT_TRUE(video_desc); |
| 2706 | cricket::MediaContentDescription* audio_desc = |
| 2707 | jdesc_.description()->GetContentDescriptionByName(kAudioContentName); |
| 2708 | ASSERT_TRUE(audio_desc); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2709 | video_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2710 | cricket::MediaContentDescription::kMedia); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 2711 | audio_desc->set_extmap_allow_mixed_enum( |
Johannes Kron | 0854eb6 | 2018-10-10 20:33:20 | [diff] [blame] | 2712 | cricket::MediaContentDescription::kMedia); |
| 2713 | |
| 2714 | std::string sdp_with_extmap_allow_mixed = kSdpFullString; |
| 2715 | InjectAfter("a=mid:audio_content_name\r\n", kExtmapAllowMixed, |
| 2716 | &sdp_with_extmap_allow_mixed); |
| 2717 | InjectAfter("a=mid:video_content_name\r\n", kExtmapAllowMixed, |
| 2718 | &sdp_with_extmap_allow_mixed); |
| 2719 | |
| 2720 | // Deserialize |
| 2721 | JsepSessionDescription jdesc_deserialized(kDummyType); |
| 2722 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap_allow_mixed, &jdesc_deserialized)); |
| 2723 | // Verify |
| 2724 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_deserialized)); |
| 2725 | } |
| 2726 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2727 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 2728 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2729 | |
| 2730 | std::string sdp = kSdpOneCandidate; |
| 2731 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2732 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2733 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2734 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
honghaiz | a0c44ea | 2016-03-23 23:07:48 | [diff] [blame] | 2735 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2736 | |
| 2737 | // Candidate line without generation extension. |
| 2738 | sdp = kSdpOneCandidate; |
| 2739 | Replace(" generation 2", "", &sdp); |
| 2740 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2741 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2742 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2743 | Candidate expected = jcandidate_->candidate(); |
| 2744 | expected.set_generation(0); |
| 2745 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2746 | |
honghaiz | a0c44ea | 2016-03-23 23:07:48 | [diff] [blame] | 2747 | // Candidate with network id and/or cost. |
| 2748 | sdp = kSdpOneCandidate; |
| 2749 | Replace(" generation 2", " generation 2 network-id 2", &sdp); |
| 2750 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2751 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2752 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2753 | expected = jcandidate_->candidate(); |
| 2754 | expected.set_network_id(2); |
| 2755 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2756 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
| 2757 | // Add network cost |
| 2758 | Replace(" network-id 2", " network-id 2 network-cost 9", &sdp); |
| 2759 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2760 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2761 | EXPECT_EQ(9, jcandidate.candidate().network_cost()); |
| 2762 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2763 | sdp = kSdpTcpActiveCandidate; |
| 2764 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2765 | // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 | [diff] [blame] | 2766 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 2767 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2768 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2769 | kCandidateFoundation1); |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 2770 | std::unique_ptr<IceCandidateInterface> jcandidate_template( |
| 2771 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2772 | EXPECT_TRUE( |
| 2773 | jcandidate.candidate().IsEquivalent(jcandidate_template->candidate())); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 | [diff] [blame] | 2774 | sdp = kSdpTcpPassiveCandidate; |
| 2775 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2776 | sdp = kSdpTcpSOCandidate; |
| 2777 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | // This test verifies the deserialization of candidate-attribute |
| 2781 | // as per RFC 5245. Candiate-attribute will be of the format |
| 2782 | // candidate:<blah>. This format will be used when candidates |
| 2783 | // are trickled. |
| 2784 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 2785 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2786 | |
| 2787 | std::string candidate_attribute = kRawCandidate; |
| 2788 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2789 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2790 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2791 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2792 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 2793 | |
| 2794 | // Candidate line without generation extension. |
| 2795 | candidate_attribute = kRawCandidate; |
| 2796 | Replace(" generation 2", "", &candidate_attribute); |
| 2797 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2798 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2799 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2800 | Candidate expected = jcandidate_->candidate(); |
| 2801 | expected.set_generation(0); |
| 2802 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2803 | |
| 2804 | // Candidate line without candidate: |
| 2805 | candidate_attribute = kRawCandidate; |
| 2806 | Replace("candidate:", "", &candidate_attribute); |
| 2807 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2808 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2809 | // Candidate line with IPV6 address. |
| 2810 | EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate)); |
Zach Stein | b336c27 | 2018-08-09 08:16:13 | [diff] [blame] | 2811 | |
| 2812 | // Candidate line with hostname address. |
| 2813 | EXPECT_TRUE(SdpDeserializeCandidate(kRawHostnameCandidate, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | // This test verifies that the deserialization of an invalid candidate string |
| 2817 | // fails. |
| 2818 | TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2819 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2820 | |
| 2821 | std::string candidate_attribute = kRawCandidate; |
| 2822 | candidate_attribute.replace(0, 1, "x"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2823 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 | [diff] [blame] | 2824 | |
| 2825 | candidate_attribute = kSdpOneCandidate; |
| 2826 | candidate_attribute.replace(0, 1, "x"); |
| 2827 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2828 | |
| 2829 | candidate_attribute = kRawCandidate; |
| 2830 | candidate_attribute.append("\r\n"); |
| 2831 | candidate_attribute.append(kRawCandidate); |
| 2832 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2833 | |
| 2834 | EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2835 | } |
| 2836 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2837 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2838 | bool use_sctpmap = true; |
| 2839 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2840 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2841 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2842 | |
| 2843 | std::string sdp_with_data = kSdpString; |
| 2844 | sdp_with_data.append(kSdpSctpDataChannelString); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2845 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2846 | |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 2847 | // Verify with UDP/DTLS/SCTP (already in kSdpSctpDataChannelString). |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 2848 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2849 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2850 | |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 2851 | // Verify with DTLS/SCTP. |
| 2852 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), strlen(kUdpDtlsSctp), |
| 2853 | kDtlsSctp); |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 | [diff] [blame] | 2854 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2855 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2856 | |
| 2857 | // Verify with TCP/DTLS/SCTP. |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 2858 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), strlen(kDtlsSctp), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 2859 | kTcpDtlsSctp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2860 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2861 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2862 | } |
| 2863 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2864 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2865 | bool use_sctpmap = false; |
| 2866 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2867 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2868 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2869 | |
| 2870 | std::string sdp_with_data = kSdpString; |
| 2871 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2872 | JsepSessionDescription jdesc_output(kDummyType); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2873 | |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 | [diff] [blame] | 2874 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2875 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2876 | } |
| 2877 | |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2878 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2879 | bool use_sctpmap = false; |
| 2880 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2881 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2882 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2883 | |
| 2884 | std::string sdp_with_data = kSdpString; |
| 2885 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2886 | JsepSessionDescription jdesc_output(kDummyType); |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2887 | |
lally | 69f5760 | 2015-10-08 17:15:04 | [diff] [blame] | 2888 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2889 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2890 | } |
| 2891 | |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 2892 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsButWrongMediaType) { |
| 2893 | bool use_sctpmap = true; |
| 2894 | AddSctpDataChannel(use_sctpmap); |
| 2895 | JsepSessionDescription jdesc(kDummyType); |
| 2896 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
| 2897 | |
| 2898 | std::string sdp = kSdpSessionString; |
| 2899 | sdp += kSdpSctpDataChannelString; |
| 2900 | |
| 2901 | const char needle[] = "m=application "; |
| 2902 | sdp.replace(sdp.find(needle), strlen(needle), "m=application:bogus "); |
| 2903 | |
| 2904 | JsepSessionDescription jdesc_output(kDummyType); |
| 2905 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 2906 | |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 2907 | EXPECT_EQ(1u, jdesc_output.description()->contents().size()); |
| 2908 | EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected); |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 2909 | } |
| 2910 | |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2911 | // Helper function to set the max-message-size parameter in the |
| 2912 | // SCTP data codec. |
| 2913 | void MutateJsepSctpMaxMessageSize(const SessionDescription& desc, |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2914 | int new_value, |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2915 | JsepSessionDescription* jdesc) { |
Harald Alvestrand | 8da35a6 | 2019-05-10 07:31:04 | [diff] [blame] | 2916 | std::unique_ptr<cricket::SessionDescription> mutant = desc.Clone(); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2917 | SctpDataContentDescription* dcdesc = |
| 2918 | mutant->GetContentDescriptionByName(kDataContentName)->as_sctp(); |
| 2919 | dcdesc->set_max_message_size(new_value); |
Harald Alvestrand | 8da35a6 | 2019-05-10 07:31:04 | [diff] [blame] | 2920 | jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion); |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) { |
| 2924 | bool use_sctpmap = false; |
| 2925 | AddSctpDataChannel(use_sctpmap); |
| 2926 | JsepSessionDescription jdesc(kDummyType); |
| 2927 | std::string sdp_with_data = kSdpString; |
| 2928 | |
| 2929 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
| 2930 | sdp_with_data.append("a=max-message-size:12345\r\n"); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2931 | MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc); |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2932 | JsepSessionDescription jdesc_output(kDummyType); |
| 2933 | |
Harald Alvestrand | 48cce4d | 2019-04-11 08:41:24 | [diff] [blame] | 2934 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2935 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2936 | } |
| 2937 | |
Harald Alvestrand | fbb45bd | 2019-05-15 06:07:47 | [diff] [blame] | 2938 | TEST_F(WebRtcSdpTest, SerializeSdpWithSctpDataChannelWithMaxMessageSize) { |
| 2939 | bool use_sctpmap = false; |
| 2940 | AddSctpDataChannel(use_sctpmap); |
| 2941 | JsepSessionDescription jdesc(kDummyType); |
| 2942 | MutateJsepSctpMaxMessageSize(desc_, 12345, &jdesc); |
| 2943 | std::string message = webrtc::SdpSerialize(jdesc); |
| 2944 | EXPECT_NE(std::string::npos, |
| 2945 | message.find("\r\na=max-message-size:12345\r\n")); |
| 2946 | JsepSessionDescription jdesc_output(kDummyType); |
| 2947 | EXPECT_TRUE(SdpDeserialize(message, &jdesc_output)); |
| 2948 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2949 | } |
| 2950 | |
| 2951 | TEST_F(WebRtcSdpTest, |
| 2952 | SerializeSdpWithSctpDataChannelWithDefaultMaxMessageSize) { |
| 2953 | // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6 |
| 2954 | // The default max message size is 64K. |
| 2955 | bool use_sctpmap = false; |
| 2956 | AddSctpDataChannel(use_sctpmap); |
| 2957 | JsepSessionDescription jdesc(kDummyType); |
| 2958 | MutateJsepSctpMaxMessageSize(desc_, 65536, &jdesc); |
| 2959 | std::string message = webrtc::SdpSerialize(jdesc); |
| 2960 | EXPECT_EQ(std::string::npos, message.find("\r\na=max-message-size:")); |
| 2961 | JsepSessionDescription jdesc_output(kDummyType); |
| 2962 | EXPECT_TRUE(SdpDeserialize(message, &jdesc_output)); |
| 2963 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2964 | } |
| 2965 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2966 | // Test to check the behaviour if sctp-port is specified |
| 2967 | // on the m= line and in a=sctp-port. |
| 2968 | TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 2969 | bool use_sctpmap = true; |
| 2970 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2971 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 2972 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2973 | |
| 2974 | std::string sdp_with_data = kSdpString; |
| 2975 | // Append m= attributes |
| 2976 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2977 | // Append a=sctp-port attribute |
| 2978 | sdp_with_data.append("a=sctp-port 5000\r\n"); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 2979 | JsepSessionDescription jdesc_output(kDummyType); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 2980 | |
| 2981 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2982 | } |
| 2983 | |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 2984 | // Test behavior if a=rtpmap occurs in an SCTP section. |
| 2985 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpmapAttribute) { |
| 2986 | std::string sdp_with_data = kSdpString; |
| 2987 | // Append m= attributes |
| 2988 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2989 | // Append a=rtpmap attribute |
| 2990 | sdp_with_data.append("a=rtpmap:111 opus/48000/2\r\n"); |
| 2991 | JsepSessionDescription jdesc_output(kDummyType); |
| 2992 | // Correct behavior is to ignore the extra attribute. |
| 2993 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2994 | } |
| 2995 | |
| 2996 | TEST_F(WebRtcSdpTest, DeserializeSdpWithStrangeApplicationProtocolNames) { |
Harald Alvestrand | 7af57c6 | 2021-04-16 11:12:14 | [diff] [blame] | 2997 | static const char* bad_strings[] = { |
| 2998 | "DTLS/SCTPRTP/", "obviously-bogus", "UDP/TL/RTSP/SAVPF", |
| 2999 | "UDP/TL/RTSP/S", "DTLS/SCTP/RTP/FOO", "obviously-bogus/RTP/"}; |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 3000 | for (auto proto : bad_strings) { |
| 3001 | std::string sdp_with_data = kSdpString; |
| 3002 | sdp_with_data.append("m=application 9 "); |
| 3003 | sdp_with_data.append(proto); |
| 3004 | sdp_with_data.append(" 47\r\n"); |
| 3005 | JsepSessionDescription jdesc_output(kDummyType); |
| 3006 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)) |
| 3007 | << "Parsing should have failed on " << proto; |
| 3008 | } |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 3009 | } |
| 3010 | |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 | [diff] [blame] | 3011 | // For crbug/344475. |
| 3012 | TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { |
| 3013 | std::string sdp_with_data = kSdpString; |
| 3014 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 3015 | // Remove the "\n" at the end. |
| 3016 | sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3017 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 | [diff] [blame] | 3018 | |
| 3019 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 3020 | // No crash is a pass. |
| 3021 | } |
| 3022 | |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 3023 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) { |
| 3024 | bool use_sctpmap = true; |
| 3025 | AddSctpDataChannel(use_sctpmap); |
| 3026 | |
| 3027 | // First setup the expected JsepSessionDescription. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3028 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 3029 | MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 3030 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 | [diff] [blame] | 3031 | // Then get the deserialized JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 3032 | std::string sdp_with_data = kSdpString; |
| 3033 | sdp_with_data.append(kSdpSctpDataChannelString); |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 3034 | absl::StrReplaceAll( |
| 3035 | {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}}, |
| 3036 | &sdp_with_data); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3037 | JsepSessionDescription jdesc_output(kDummyType); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 3038 | |
| 3039 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 3040 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | TEST_F(WebRtcSdpTest, |
| 3044 | DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) { |
| 3045 | bool use_sctpmap = false; |
| 3046 | AddSctpDataChannel(use_sctpmap); |
| 3047 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3048 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 3049 | MutateJsepSctpPort(&jdesc, desc_, kUnusualSctpPort); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 3050 | |
| 3051 | // We need to test the deserialized JsepSessionDescription from |
| 3052 | // kSdpSctpDataChannelStringWithSctpPort for |
| 3053 | // draft-ietf-mmusic-sctp-sdp-07 |
| 3054 | // a=sctp-port |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 3055 | std::string sdp_with_data = kSdpString; |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 3056 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 3057 | absl::StrReplaceAll( |
| 3058 | {{rtc::ToString(kDefaultSctpPort), rtc::ToString(kUnusualSctpPort)}}, |
| 3059 | &sdp_with_data); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3060 | JsepSessionDescription jdesc_output(kDummyType); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 | [diff] [blame] | 3061 | |
| 3062 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 3063 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 3064 | } |
| 3065 | |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3066 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { |
zstein | 4b2e082 | 2017-02-18 03:48:38 | [diff] [blame] | 3067 | bool use_sctpmap = true; |
| 3068 | AddSctpDataChannel(use_sctpmap); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3069 | JsepSessionDescription jdesc(kDummyType); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 3070 | SctpDataContentDescription* dcd = GetFirstSctpDataContentDescription(&desc_); |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3071 | dcd->set_bandwidth(100 * 1000); |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3072 | ASSERT_TRUE(jdesc.Initialize(desc_.Clone(), kSessionId, kSessionVersion)); |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3073 | |
| 3074 | std::string sdp_with_bandwidth = kSdpString; |
| 3075 | sdp_with_bandwidth.append(kSdpSctpDataChannelString); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3076 | InjectAfter("a=mid:data_content_name\r\n", "b=AS:100\r\n", |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3077 | &sdp_with_bandwidth); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3078 | JsepSessionDescription jdesc_with_bandwidth(kDummyType); |
Peter Thatcher | c0c3a86 | 2015-06-24 22:31:25 | [diff] [blame] | 3079 | |
| 3080 | // SCTP has congestion control, so we shouldn't limit the bandwidth |
| 3081 | // as we do for RTP. |
| 3082 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 3083 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 3084 | } |
| 3085 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3086 | class WebRtcSdpExtmapTest : public WebRtcSdpTest, |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 3087 | public ::testing::WithParamInterface<bool> {}; |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3088 | |
| 3089 | TEST_P(WebRtcSdpExtmapTest, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3090 | DeserializeSessionDescriptionWithSessionLevelExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3091 | bool encrypted = GetParam(); |
| 3092 | TestDeserializeExtmap(true, false, encrypted); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3093 | } |
| 3094 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3095 | TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3096 | bool encrypted = GetParam(); |
| 3097 | TestDeserializeExtmap(false, true, encrypted); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3098 | } |
| 3099 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3100 | TEST_P(WebRtcSdpExtmapTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3101 | bool encrypted = GetParam(); |
| 3102 | TestDeserializeExtmap(true, true, encrypted); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3103 | } |
| 3104 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 3105 | INSTANTIATE_TEST_SUITE_P(Encrypted, |
| 3106 | WebRtcSdpExtmapTest, |
| 3107 | ::testing::Values(false, true)); |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 3108 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 | [diff] [blame] | 3109 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3110 | JsepSessionDescription jdesc(kDummyType); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 | [diff] [blame] | 3111 | std::string sdp = kSdpFullString; |
| 3112 | sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. |
| 3113 | // Deserialize |
| 3114 | SdpParseError error; |
| 3115 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 3116 | const std::string lastline = "a=ssrc:3 label:video_track_id_1"; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 | [diff] [blame] | 3117 | EXPECT_EQ(lastline, error.line); |
| 3118 | EXPECT_EQ("Invalid SDP line.", error.description); |
| 3119 | } |
| 3120 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3121 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 3122 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 3123 | std::string new_sdp = kSdpOneCandidate; |
| 3124 | Replace("udp", "unsupported_transport", &new_sdp); |
| 3125 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 3126 | new_sdp = kSdpOneCandidate; |
| 3127 | Replace("udp", "uDP", &new_sdp); |
| 3128 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 3129 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 3130 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 3131 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 3132 | } |
| 3133 | |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 3134 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3135 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
honghaiz | a54a080 | 2015-12-17 02:37:23 | [diff] [blame] | 3136 | EXPECT_TRUE( |
| 3137 | SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3138 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 3139 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 3140 | Candidate ref_candidate = jcandidate_->candidate(); |
| 3141 | ref_candidate.set_username("user_rtp"); |
| 3142 | ref_candidate.set_password("password_rtp"); |
| 3143 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 3144 | } |
| 3145 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3146 | TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3147 | JsepSessionDescription jdesc(kDummyType); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3148 | |
| 3149 | // Deserialize |
| 3150 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
| 3151 | |
| 3152 | // Verify |
| 3153 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3154 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3155 | EXPECT_TRUE(audio->conference_mode()); |
| 3156 | |
| 3157 | cricket::VideoContentDescription* video = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3158 | cricket::GetFirstVideoContentDescription(jdesc.description()); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 | [diff] [blame] | 3159 | EXPECT_TRUE(video->conference_mode()); |
| 3160 | } |
| 3161 | |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3162 | TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3163 | JsepSessionDescription jdesc(kDummyType); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3164 | |
| 3165 | // We tested deserialization already above, so just test that if we serialize |
| 3166 | // and deserialize the flag doesn't disappear. |
| 3167 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3168 | std::string reserialized = webrtc::SdpSerialize(jdesc); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3169 | EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc)); |
| 3170 | |
| 3171 | // Verify. |
| 3172 | cricket::AudioContentDescription* audio = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3173 | cricket::GetFirstAudioContentDescription(jdesc.description()); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3174 | EXPECT_TRUE(audio->conference_mode()); |
| 3175 | |
| 3176 | cricket::VideoContentDescription* video = |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 3177 | cricket::GetFirstVideoContentDescription(jdesc.description()); |
deadbeef | d45aea8 | 2017-09-16 08:24:29 | [diff] [blame] | 3178 | EXPECT_TRUE(video->conference_mode()); |
| 3179 | } |
| 3180 | |
Sebastian Jansson | 97321b6 | 2019-07-24 12:01:18 | [diff] [blame] | 3181 | TEST_F(WebRtcSdpTest, SerializeAndDeserializeRemoteNetEstimate) { |
| 3182 | { |
| 3183 | // By default remote estimates are disabled. |
| 3184 | JsepSessionDescription dst(kDummyType); |
| 3185 | SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst); |
| 3186 | EXPECT_FALSE(cricket::GetFirstVideoContentDescription(dst.description()) |
| 3187 | ->remote_estimate()); |
| 3188 | } |
| 3189 | { |
| 3190 | // When remote estimate is enabled, the setting is propagated via SDP. |
| 3191 | cricket::GetFirstVideoContentDescription(jdesc_.description()) |
| 3192 | ->set_remote_estimate(true); |
| 3193 | JsepSessionDescription dst(kDummyType); |
| 3194 | SdpDeserialize(webrtc::SdpSerialize(jdesc_), &dst); |
| 3195 | EXPECT_TRUE(cricket::GetFirstVideoContentDescription(dst.description()) |
| 3196 | ->remote_estimate()); |
| 3197 | } |
| 3198 | } |
| 3199 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3200 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 3201 | const char kSdpDestroyer[] = "!@#$%^&"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 | [diff] [blame] | 3202 | const char kSdpEmptyType[] = " =candidate"; |
| 3203 | const char kSdpEqualAsPlus[] = "a+candidate"; |
| 3204 | const char kSdpSpaceAfterEqual[] = "a= candidate"; |
| 3205 | const char kSdpUpperType[] = "A=candidate"; |
| 3206 | const char kSdpEmptyLine[] = ""; |
| 3207 | const char kSdpMissingValue[] = "a="; |
| 3208 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3209 | const char kSdpBrokenFingerprint[] = |
| 3210 | "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3211 | "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] | 3212 | const char kSdpExtraField[] = |
| 3213 | "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3214 | "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] | 3215 | const char kSdpMissingSpace[] = |
| 3216 | "a=fingerprint:sha-1" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3217 | "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] | 3218 | // MD5 is not allowed in fingerprints. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3219 | const char kSdpMd5[] = |
| 3220 | "a=fingerprint:md5 " |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 | [diff] [blame] | 3221 | "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] | 3222 | |
| 3223 | // Broken session description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3224 | ExpectParseFailure("v=", kSdpDestroyer); |
| 3225 | ExpectParseFailure("o=", kSdpDestroyer); |
| 3226 | ExpectParseFailure("s=-", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3227 | // Broken time description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3228 | ExpectParseFailure("t=", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3229 | |
| 3230 | // Broken media description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3231 | ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39"); |
| 3232 | ExpectParseFailure("m=video", kSdpDestroyer); |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 3233 | ExpectParseFailure("m=", "c=IN IP4 74.125.224.39"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3234 | |
| 3235 | // Invalid lines |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 | [diff] [blame] | 3236 | ExpectParseFailure("a=candidate", kSdpEmptyType); |
| 3237 | ExpectParseFailure("a=candidate", kSdpEqualAsPlus); |
| 3238 | ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual); |
| 3239 | ExpectParseFailure("a=candidate", kSdpUpperType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3240 | |
| 3241 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 3242 | // because it's orthogonal to what we are replacing and hence |
| 3243 | // safe. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 | [diff] [blame] | 3244 | ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint); |
| 3245 | ExpectParseFailure("a=sendrecv", kSdpExtraField); |
| 3246 | ExpectParseFailure("a=sendrecv", kSdpMissingSpace); |
| 3247 | ExpectParseFailure("a=sendrecv", kSdpMd5); |
| 3248 | |
| 3249 | // Empty Line |
| 3250 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine); |
| 3251 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) { |
| 3255 | // ssrc |
| 3256 | ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue"); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3257 | ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3"); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3258 | // crypto |
| 3259 | ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue "); |
| 3260 | // rtpmap |
| 3261 | ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue "); |
| 3262 | ExpectParseFailure("opus/48000/2", "opus/badvalue/2"); |
| 3263 | ExpectParseFailure("opus/48000/2", "opus/48000/badvalue"); |
| 3264 | // candidate |
| 3265 | ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432"); |
| 3266 | ExpectParseFailure("1 udp 2130706432", "1 udp badvalue"); |
| 3267 | ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue"); |
| 3268 | ExpectParseFailure("rport 2346", "rport badvalue"); |
| 3269 | ExpectParseFailure("rport 2346 generation 2", |
| 3270 | "rport 2346 generation badvalue"); |
| 3271 | // m line |
| 3272 | ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104", |
| 3273 | "m=audio 2345 RTP/SAVPF 111 badvalue 104"); |
| 3274 | |
| 3275 | // bandwidth |
| 3276 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3277 | "b=AS:badvalue\r\n", "b=AS:badvalue"); |
Philipp Hancke | fbbfc02 | 2020-07-31 06:30:50 | [diff] [blame] | 3278 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS\r\n", |
| 3279 | "b=AS"); |
| 3280 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", "b=AS:\r\n", |
| 3281 | "b=AS:"); |
| 3282 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 3283 | "b=AS:12:34\r\n", "b=AS:12:34"); |
| 3284 | |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 | [diff] [blame] | 3285 | // rtcp-fb |
| 3286 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 3287 | "a=rtcp-fb:badvalue nack\r\n", |
| 3288 | "a=rtcp-fb:badvalue nack"); |
| 3289 | // extmap |
| 3290 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 3291 | "a=extmap:badvalue http://example.com\r\n", |
| 3292 | "a=extmap:badvalue http://example.com"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3296 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3297 | |
| 3298 | const char kSdpWithReorderedPlTypesString[] = |
| 3299 | "v=0\r\n" |
| 3300 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3301 | "s=-\r\n" |
| 3302 | "t=0 0\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 | [diff] [blame] | 3303 | "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3304 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 3305 | // in the map. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3306 | "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] | 3307 | "a=rtpmap:104 ISAC/32000\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3308 | |
| 3309 | // Deserialize |
| 3310 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 3311 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3312 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3313 | GetFirstAudioContentDescription(jdesc_output.description()); |
| 3314 | ASSERT_TRUE(acd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3315 | ASSERT_FALSE(acd->codecs().empty()); |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 | [diff] [blame] | 3316 | EXPECT_EQ("ISAC", acd->codecs()[0].name); |
| 3317 | EXPECT_EQ(32000, acd->codecs()[0].clockrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3318 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 3319 | } |
| 3320 | |
| 3321 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3322 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3323 | CodecParams params; |
| 3324 | params.max_ptime = 40; |
| 3325 | params.ptime = 30; |
| 3326 | params.min_ptime = 10; |
| 3327 | params.sprop_stereo = 1; |
| 3328 | params.stereo = 1; |
| 3329 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 | [diff] [blame] | 3330 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3331 | TestDeserializeCodecParams(params, &jdesc_output); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3332 | TestSerialize(jdesc_output); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 3336 | const bool kUseWildcard = false; |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3337 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3338 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3339 | TestSerialize(jdesc_output); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 3343 | const bool kUseWildcard = true; |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3344 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3345 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3346 | TestSerialize(jdesc_output); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3350 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [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" |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3359 | "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n"; |
| 3360 | |
| 3361 | // Deserialize |
| 3362 | SdpParseError error; |
Donald Curtis | 144d018 | 2015-05-15 20:14:24 | [diff] [blame] | 3363 | EXPECT_TRUE( |
| 3364 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3365 | |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [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); |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [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 | |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3382 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3383 | JsepSessionDescription jdesc_output(kDummyType); |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3384 | |
| 3385 | const char kSdpWithFmtpString[] = |
| 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=video 49170 RTP/AVP 98\r\n" |
| 3391 | "a=rtpmap:98 H264/90000\r\n" |
| 3392 | "a=fmtp:98 profile-level-id=42A01E; " |
| 3393 | "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n"; |
| 3394 | |
| 3395 | // Deserialize. |
| 3396 | SdpParseError error; |
| 3397 | EXPECT_TRUE( |
| 3398 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
| 3399 | |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3400 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3401 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3402 | ASSERT_TRUE(vcd); |
johan | 2d8d23e | 2016-06-03 08:22:42 | [diff] [blame] | 3403 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3404 | cricket::VideoCodec h264 = vcd->codecs()[0]; |
| 3405 | EXPECT_EQ("H264", h264.name); |
| 3406 | EXPECT_EQ(98, h264.id); |
| 3407 | cricket::CodecParameterMap::const_iterator found = |
| 3408 | h264.params.find("profile-level-id"); |
| 3409 | ASSERT_TRUE(found != h264.params.end()); |
| 3410 | EXPECT_EQ(found->second, "42A01E"); |
| 3411 | found = h264.params.find("sprop-parameter-sets"); |
| 3412 | ASSERT_TRUE(found != h264.params.end()); |
| 3413 | EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA=="); |
| 3414 | } |
| 3415 | |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3416 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3417 | JsepSessionDescription jdesc_output(kDummyType); |
Donald Curtis | 0e07f92 | 2015-05-15 16:21:23 | [diff] [blame] | 3418 | |
| 3419 | const char kSdpWithFmtpString[] = |
| 3420 | "v=0\r\n" |
| 3421 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3422 | "s=-\r\n" |
| 3423 | "t=0 0\r\n" |
| 3424 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3425 | "a=rtpmap:120 VP8/90000\r\n" |
| 3426 | "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] | 3427 | |
| 3428 | // Deserialize |
| 3429 | SdpParseError error; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3430 | EXPECT_TRUE( |
| 3431 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3432 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3433 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3434 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3435 | ASSERT_TRUE(vcd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3436 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3437 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 3438 | EXPECT_EQ("VP8", vp8.name); |
| 3439 | EXPECT_EQ(120, vp8.id); |
| 3440 | cricket::CodecParameterMap::iterator found = |
| 3441 | vp8.params.find("x-google-min-bitrate"); |
| 3442 | ASSERT_TRUE(found != vp8.params.end()); |
| 3443 | EXPECT_EQ(found->second, "10"); |
| 3444 | found = vp8.params.find("x-google-max-quantization"); |
| 3445 | ASSERT_TRUE(found != vp8.params.end()); |
| 3446 | EXPECT_EQ(found->second, "40"); |
| 3447 | } |
| 3448 | |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 3449 | TEST_F(WebRtcSdpTest, DeserializePacketizationAttributeWithIllegalValue) { |
| 3450 | JsepSessionDescription jdesc_output(kDummyType); |
| 3451 | |
| 3452 | const char kSdpWithPacketizationString[] = |
| 3453 | "v=0\r\n" |
| 3454 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3455 | "s=-\r\n" |
| 3456 | "t=0 0\r\n" |
| 3457 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 3458 | "a=rtpmap:111 opus/48000/2\r\n" |
| 3459 | "a=packetization:111 unknownpacketizationattributeforaudio\r\n" |
| 3460 | "m=video 3457 RTP/SAVPF 120 121 122\r\n" |
| 3461 | "a=rtpmap:120 VP8/90000\r\n" |
| 3462 | "a=packetization:120 raw\r\n" |
| 3463 | "a=rtpmap:121 VP9/90000\r\n" |
| 3464 | "a=rtpmap:122 H264/90000\r\n" |
| 3465 | "a=packetization:122 unknownpacketizationattributevalue\r\n"; |
| 3466 | |
| 3467 | SdpParseError error; |
| 3468 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithPacketizationString, &jdesc_output, |
| 3469 | &error)); |
| 3470 | |
| 3471 | AudioContentDescription* acd = |
| 3472 | GetFirstAudioContentDescription(jdesc_output.description()); |
| 3473 | ASSERT_TRUE(acd); |
| 3474 | ASSERT_THAT(acd->codecs(), testing::SizeIs(1)); |
| 3475 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 3476 | EXPECT_EQ(opus.name, "opus"); |
| 3477 | EXPECT_EQ(opus.id, 111); |
| 3478 | |
| 3479 | const VideoContentDescription* vcd = |
| 3480 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3481 | ASSERT_TRUE(vcd); |
| 3482 | ASSERT_THAT(vcd->codecs(), testing::SizeIs(3)); |
| 3483 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 3484 | EXPECT_EQ(vp8.name, "VP8"); |
| 3485 | EXPECT_EQ(vp8.id, 120); |
| 3486 | EXPECT_EQ(vp8.packetization, "raw"); |
| 3487 | cricket::VideoCodec vp9 = vcd->codecs()[1]; |
| 3488 | EXPECT_EQ(vp9.name, "VP9"); |
| 3489 | EXPECT_EQ(vp9.id, 121); |
| 3490 | EXPECT_EQ(vp9.packetization, absl::nullopt); |
| 3491 | cricket::VideoCodec h264 = vcd->codecs()[2]; |
| 3492 | EXPECT_EQ(h264.name, "H264"); |
| 3493 | EXPECT_EQ(h264.id, 122); |
| 3494 | EXPECT_EQ(h264.packetization, absl::nullopt); |
| 3495 | } |
| 3496 | |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3497 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3498 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3499 | |
| 3500 | cricket::AudioCodecs codecs = acd->codecs(); |
| 3501 | codecs[0].params["unknown-future-parameter"] = "SomeFutureValue"; |
| 3502 | acd->set_codecs(codecs); |
| 3503 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3504 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3505 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3506 | std::string message = webrtc::SdpSerialize(jdesc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3507 | std::string sdp_with_fmtp = kSdpFullString; |
| 3508 | InjectAfter("a=rtpmap:111 opus/48000/2\r\n", |
| 3509 | "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n", |
| 3510 | &sdp_with_fmtp); |
| 3511 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3512 | } |
| 3513 | |
| 3514 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3515 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3516 | |
| 3517 | cricket::AudioCodecs codecs = acd->codecs(); |
| 3518 | codecs[0].params["stereo"] = "1"; |
| 3519 | acd->set_codecs(codecs); |
| 3520 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3521 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3522 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3523 | std::string message = webrtc::SdpSerialize(jdesc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3524 | std::string sdp_with_fmtp = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3525 | 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] | 3526 | &sdp_with_fmtp); |
| 3527 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3528 | } |
| 3529 | |
| 3530 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3531 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3532 | |
| 3533 | cricket::AudioCodecs codecs = acd->codecs(); |
| 3534 | codecs[0].params["ptime"] = "20"; |
| 3535 | codecs[0].params["maxptime"] = "120"; |
| 3536 | acd->set_codecs(codecs); |
| 3537 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3538 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3539 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3540 | std::string message = webrtc::SdpSerialize(jdesc_); |
ossu | aa4b077 | 2017-01-30 15:41:18 | [diff] [blame] | 3541 | std::string sdp_with_fmtp = kSdpFullString; |
| 3542 | InjectAfter("a=rtpmap:104 ISAC/32000\r\n", |
| 3543 | "a=maxptime:120\r\n" // No comma here. String merging! |
| 3544 | "a=ptime:20\r\n", |
| 3545 | &sdp_with_fmtp); |
| 3546 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3547 | } |
| 3548 | |
Philipp Hancke | f2a4ec1 | 2020-07-01 19:07:32 | [diff] [blame] | 3549 | TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithTelephoneEvent) { |
| 3550 | AudioContentDescription* acd = GetFirstAudioContentDescription(&desc_); |
| 3551 | |
| 3552 | cricket::AudioCodecs codecs = acd->codecs(); |
| 3553 | cricket::AudioCodec dtmf(105, "telephone-event", 8000, 0, 1); |
| 3554 | dtmf.params[""] = "0-15"; |
| 3555 | codecs.push_back(dtmf); |
| 3556 | acd->set_codecs(codecs); |
| 3557 | |
| 3558 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 3559 | jdesc_.session_version())); |
| 3560 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 3561 | std::string sdp_with_fmtp = kSdpFullString; |
| 3562 | InjectAfter("m=audio 2345 RTP/SAVPF 111 103 104", " 105", &sdp_with_fmtp); |
| 3563 | InjectAfter( |
| 3564 | "a=rtpmap:104 ISAC/32000\r\n", |
| 3565 | "a=rtpmap:105 telephone-event/8000\r\n" // No comma here. String merging! |
| 3566 | "a=fmtp:105 0-15\r\n", |
| 3567 | &sdp_with_fmtp); |
| 3568 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3569 | } |
| 3570 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3571 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3572 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3573 | |
| 3574 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 3575 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 3576 | vcd->set_codecs(codecs); |
| 3577 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3578 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3579 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3580 | std::string message = webrtc::SdpSerialize(jdesc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3581 | std::string sdp_with_fmtp = kSdpFullString; |
| 3582 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3583 | "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] | 3584 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3585 | } |
| 3586 | |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 3587 | TEST_F(WebRtcSdpTest, SerializeVideoPacketizationAttribute) { |
| 3588 | VideoContentDescription* vcd = GetFirstVideoContentDescription(&desc_); |
| 3589 | |
| 3590 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 3591 | codecs[0].packetization = "raw"; |
| 3592 | vcd->set_codecs(codecs); |
| 3593 | |
| 3594 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 3595 | jdesc_.session_version())); |
| 3596 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 3597 | std::string sdp_with_packetization = kSdpFullString; |
| 3598 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", "a=packetization:120 raw\r\n", |
| 3599 | &sdp_with_packetization); |
| 3600 | EXPECT_EQ(sdp_with_packetization, message); |
| 3601 | } |
| 3602 | |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 3603 | TEST_F(WebRtcSdpTest, DeserializeAndSerializeSdpWithIceLite) { |
| 3604 | // Deserialize the baseline description, making sure it's ICE full. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3605 | JsepSessionDescription jdesc_with_icelite(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3606 | std::string sdp_with_icelite = kSdpFullString; |
| 3607 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 3608 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 3609 | const cricket::TransportInfo* tinfo1 = |
| 3610 | desc->GetTransportInfoByName("audio_content_name"); |
| 3611 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 3612 | const cricket::TransportInfo* tinfo2 = |
| 3613 | desc->GetTransportInfoByName("video_content_name"); |
| 3614 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 3615 | |
| 3616 | // Add "a=ice-lite" and deserialize, making sure it's ICE lite. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3617 | InjectAfter(kSessionTime, "a=ice-lite\r\n", &sdp_with_icelite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3618 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 3619 | desc = jdesc_with_icelite.description(); |
| 3620 | const cricket::TransportInfo* atinfo = |
| 3621 | desc->GetTransportInfoByName("audio_content_name"); |
| 3622 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 3623 | const cricket::TransportInfo* vtinfo = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3624 | desc->GetTransportInfoByName("video_content_name"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3625 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
Taylor Brandstetter | 2f65ec5 | 2018-05-24 18:37:28 | [diff] [blame] | 3626 | |
| 3627 | // Now that we know deserialization works, we can use TestSerialize to test |
| 3628 | // serialization. |
| 3629 | TestSerialize(jdesc_with_icelite); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 3633 | // correctly in the output SDP. |
| 3634 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 3635 | std::string sdp_with_data = kSdpString; |
| 3636 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3637 | JsepSessionDescription jdesc_output(kDummyType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3638 | |
| 3639 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3640 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3641 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3642 | |
| 3643 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 3644 | AddFingerprint(); |
| 3645 | TransportInfo audio_transport_info = |
| 3646 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 3647 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3648 | audio_transport_info.description.connection_role); |
| 3649 | audio_transport_info.description.connection_role = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3650 | cricket::CONNECTIONROLE_ACTIVE; |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3651 | |
| 3652 | TransportInfo video_transport_info = |
| 3653 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 3654 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3655 | video_transport_info.description.connection_role); |
| 3656 | video_transport_info.description.connection_role = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3657 | cricket::CONNECTIONROLE_ACTIVE; |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3658 | |
| 3659 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 3660 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 3661 | |
| 3662 | desc_.AddTransportInfo(audio_transport_info); |
| 3663 | desc_.AddTransportInfo(video_transport_info); |
| 3664 | |
Harald Alvestrand | 4d7160e | 2019-04-12 05:01:29 | [diff] [blame] | 3665 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3666 | jdesc_.session_version())); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3667 | std::string message = webrtc::SdpSerialize(jdesc_); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3668 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3669 | |
| 3670 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3671 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_dtlssetup); |
| 3672 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_dtlssetup); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3673 | // Now adding |setup| attribute. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3674 | InjectAfter(kFingerprint, "a=setup:active\r\n", &sdp_with_dtlssetup); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3675 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 3676 | } |
| 3677 | |
| 3678 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3679 | JsepSessionDescription jdesc_with_dtlssetup(kDummyType); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3680 | std::string sdp_with_dtlssetup = kSdpFullString; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3681 | InjectAfter(kSessionTime, "a=setup:actpass\r\n", &sdp_with_dtlssetup); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3682 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 3683 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 3684 | const cricket::TransportInfo* atinfo = |
| 3685 | desc->GetTransportInfoByName("audio_content_name"); |
| 3686 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3687 | atinfo->description.connection_role); |
| 3688 | const cricket::TransportInfo* vtinfo = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3689 | desc->GetTransportInfoByName("video_content_name"); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 3690 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3691 | vtinfo->description.connection_role); |
| 3692 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3693 | |
| 3694 | // Verifies that the order of the serialized m-lines follows the order of the |
| 3695 | // ContentInfo in SessionDescription, and vise versa for deserialization. |
| 3696 | TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3697 | JsepSessionDescription jdesc(kDummyType); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 3698 | const std::string media_content_sdps[3] = {kSdpAudioString, kSdpVideoString, |
| 3699 | kSdpSctpDataChannelString}; |
| 3700 | const cricket::MediaType media_types[3] = {cricket::MEDIA_TYPE_AUDIO, |
| 3701 | cricket::MEDIA_TYPE_VIDEO, |
| 3702 | cricket::MEDIA_TYPE_DATA}; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3703 | |
| 3704 | // Verifies all 6 permutations. |
| 3705 | for (size_t i = 0; i < 6; ++i) { |
| 3706 | size_t media_content_in_sdp[3]; |
| 3707 | // The index of the first media content. |
| 3708 | media_content_in_sdp[0] = i / 2; |
| 3709 | // The index of the second media content. |
| 3710 | media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3; |
| 3711 | // The index of the third media content. |
| 3712 | media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3; |
| 3713 | |
| 3714 | std::string sdp_string = kSdpSessionString; |
| 3715 | for (size_t i = 0; i < 3; ++i) |
| 3716 | sdp_string += media_content_sdps[media_content_in_sdp[i]]; |
| 3717 | |
| 3718 | EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc)); |
| 3719 | cricket::SessionDescription* desc = jdesc.description(); |
| 3720 | EXPECT_EQ(3u, desc->contents().size()); |
| 3721 | |
| 3722 | for (size_t i = 0; i < 3; ++i) { |
| 3723 | const cricket::MediaContentDescription* mdesc = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3724 | desc->contents()[i].media_description(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3725 | EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 3726 | } |
| 3727 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3728 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 | [diff] [blame] | 3729 | EXPECT_EQ(sdp_string, serialized_sdp); |
| 3730 | } |
| 3731 | } |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3732 | |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3733 | TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) { |
| 3734 | MakeBundleOnlyDescription(); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3735 | JsepSessionDescription deserialized_description(kDummyType); |
deadbeef | 12771a1 | 2017-01-03 21:53:47 | [diff] [blame] | 3736 | ASSERT_TRUE( |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3737 | SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description)); |
| 3738 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3739 | } |
| 3740 | |
deadbeef | 12771a1 | 2017-01-03 21:53:47 | [diff] [blame] | 3741 | // The semantics of "a=bundle-only" are only defined when it's used in |
| 3742 | // combination with a 0 port on the m= line. We should ignore it if used with a |
| 3743 | // nonzero port. |
| 3744 | TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) { |
| 3745 | // Make the base bundle-only description but unset the bundle-only flag. |
| 3746 | MakeBundleOnlyDescription(); |
| 3747 | jdesc_.description()->contents()[1].bundle_only = false; |
| 3748 | |
| 3749 | std::string modified_sdp = kBundleOnlySdpFullString; |
| 3750 | Replace("m=video 0", "m=video 9", &modified_sdp); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3751 | JsepSessionDescription deserialized_description(kDummyType); |
deadbeef | 12771a1 | 2017-01-03 21:53:47 | [diff] [blame] | 3752 | ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description)); |
| 3753 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) { |
| 3757 | MakeBundleOnlyDescription(); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3758 | TestSerialize(jdesc_); |
deadbeef | 25ed435 | 2016-12-13 02:37:36 | [diff] [blame] | 3759 | } |
| 3760 | |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3761 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) { |
| 3762 | MakePlanBDescription(); |
| 3763 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3764 | JsepSessionDescription deserialized_description(kDummyType); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3765 | EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description)); |
| 3766 | |
| 3767 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3768 | } |
| 3769 | |
| 3770 | TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) { |
| 3771 | MakePlanBDescription(); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3772 | TestSerialize(jdesc_); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) { |
| 3776 | MakeUnifiedPlanDescription(); |
| 3777 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3778 | JsepSessionDescription deserialized_description(kDummyType); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3779 | EXPECT_TRUE( |
| 3780 | SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); |
| 3781 | |
| 3782 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3783 | } |
| 3784 | |
| 3785 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { |
| 3786 | MakeUnifiedPlanDescription(); |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3787 | TestSerialize(jdesc_); |
| 3788 | } |
| 3789 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3790 | // This tests deserializing a Unified Plan SDP that is compatible with both |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 3791 | // Unified Plan and Plan B style SDP, meaning that it contains both "a=ssrc |
| 3792 | // 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] | 3793 | // with no stream ids and multiple stream ids. For parsing this, the Unified |
| 3794 | // Plan a=msid lines should take priority, because the Plan B style a=ssrc msid |
| 3795 | // lines do not support multiple stream ids and no stream ids. |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 3796 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionSpecialMsid) { |
| 3797 | // Create both msid lines for Plan B and Unified Plan support. |
| 3798 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3799 | cricket::kMsidSignalingMediaSection | |
| 3800 | cricket::kMsidSignalingSsrcAttribute); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3801 | |
| 3802 | JsepSessionDescription deserialized_description(kDummyType); |
| 3803 | EXPECT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullStringWithSpecialMsid, |
| 3804 | &deserialized_description)); |
| 3805 | |
| 3806 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
Henrik Boström | 5b14778 | 2018-12-04 10:25:05 | [diff] [blame] | 3807 | EXPECT_EQ(cricket::kMsidSignalingMediaSection | |
| 3808 | cricket::kMsidSignalingSsrcAttribute, |
| 3809 | deserialized_description.description()->msid_signaling()); |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3810 | } |
| 3811 | |
Seth Hampson | 7fa6ee6 | 2018-10-17 17:25:28 | [diff] [blame] | 3812 | // Tests the serialization of a Unified Plan SDP that is compatible for both |
| 3813 | // Unified Plan and Plan B style SDPs, meaning that it contains both "a=ssrc |
| 3814 | // msid" lines and "a=msid " lines. It tests the case for no stream ids and |
| 3815 | // multiple stream ids. |
| 3816 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionSpecialMsid) { |
| 3817 | // Create both msid lines for Plan B and Unified Plan support. |
| 3818 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3819 | cricket::kMsidSignalingMediaSection | |
| 3820 | cricket::kMsidSignalingSsrcAttribute); |
| 3821 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc_); |
| 3822 | // We explicitly test that the serialized SDP string is equal to the hard |
| 3823 | // coded SDP string. This is necessary, because in the parser "a=msid" lines |
| 3824 | // take priority over "a=ssrc msid" lines. This means if we just used |
| 3825 | // TestSerialize(), it could serialize an SDP that omits "a=ssrc msid" lines, |
| 3826 | // and still pass, because the deserialized version would be the same. |
| 3827 | EXPECT_EQ(kUnifiedPlanSdpFullStringWithSpecialMsid, serialized_sdp); |
| 3828 | } |
| 3829 | |
| 3830 | // Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines |
| 3831 | // that signal stream IDs) is deserialized appropriately. It tests the case for |
| 3832 | // no stream ids and multiple stream ids. |
| 3833 | TEST_F(WebRtcSdpTest, UnifiedPlanDeserializeSessionDescriptionSpecialMsid) { |
| 3834 | // Only create a=msid lines for strictly Unified Plan stream ID support. |
| 3835 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3836 | cricket::kMsidSignalingMediaSection); |
| 3837 | |
| 3838 | JsepSessionDescription deserialized_description(kDummyType); |
| 3839 | std::string unified_plan_sdp_string = |
| 3840 | kUnifiedPlanSdpFullStringWithSpecialMsid; |
| 3841 | RemoveSsrcMsidLinesFromSdpString(&unified_plan_sdp_string); |
| 3842 | EXPECT_TRUE( |
| 3843 | SdpDeserialize(unified_plan_sdp_string, &deserialized_description)); |
| 3844 | |
| 3845 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3846 | } |
| 3847 | |
| 3848 | // Tests that a Unified Plan style SDP (does not contain "a=ssrc msid" lines |
| 3849 | // that signal stream IDs) is serialized appropriately. It tests the case for no |
| 3850 | // stream ids and multiple stream ids. |
| 3851 | TEST_F(WebRtcSdpTest, UnifiedPlanSerializeSessionDescriptionSpecialMsid) { |
| 3852 | // Only create a=msid lines for strictly Unified Plan stream ID support. |
| 3853 | MakeUnifiedPlanDescriptionMultipleStreamIds( |
| 3854 | cricket::kMsidSignalingMediaSection); |
| 3855 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 3856 | TestSerialize(jdesc_); |
| 3857 | } |
| 3858 | |
Seth Hampson | 5897a6e | 2018-04-03 18:16:33 | [diff] [blame] | 3859 | // This tests that a Unified Plan SDP with no a=ssrc lines is |
| 3860 | // serialized/deserialized appropriately. In this case the |
| 3861 | // MediaContentDescription will contain a StreamParams object that doesn't have |
| 3862 | // any SSRCs. Vice versa, this will be created upon deserializing an SDP with no |
| 3863 | // SSRC lines. |
| 3864 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescriptionNoSsrcSignaling) { |
| 3865 | MakeUnifiedPlanDescription(); |
| 3866 | RemoveSsrcSignalingFromStreamParams(); |
| 3867 | std::string unified_plan_sdp_string = kUnifiedPlanSdpFullString; |
| 3868 | RemoveSsrcLinesFromSdpString(&unified_plan_sdp_string); |
| 3869 | |
| 3870 | JsepSessionDescription deserialized_description(kDummyType); |
| 3871 | EXPECT_TRUE( |
| 3872 | SdpDeserialize(unified_plan_sdp_string, &deserialized_description)); |
| 3873 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3874 | } |
| 3875 | |
| 3876 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescriptionNoSsrcSignaling) { |
| 3877 | MakeUnifiedPlanDescription(); |
| 3878 | RemoveSsrcSignalingFromStreamParams(); |
| 3879 | |
| 3880 | TestSerialize(jdesc_); |
| 3881 | } |
| 3882 | |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 3883 | TEST_F(WebRtcSdpTest, EmptyDescriptionHasNoMsidSignaling) { |
| 3884 | JsepSessionDescription jsep_desc(kDummyType); |
| 3885 | ASSERT_TRUE(SdpDeserialize(kSdpSessionString, &jsep_desc)); |
| 3886 | EXPECT_EQ(0, jsep_desc.description()->msid_signaling()); |
| 3887 | } |
| 3888 | |
| 3889 | TEST_F(WebRtcSdpTest, DataChannelOnlyHasNoMsidSignaling) { |
| 3890 | JsepSessionDescription jsep_desc(kDummyType); |
| 3891 | std::string sdp = kSdpSessionString; |
| 3892 | sdp += kSdpSctpDataChannelString; |
| 3893 | ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 3894 | EXPECT_EQ(0, jsep_desc.description()->msid_signaling()); |
| 3895 | } |
| 3896 | |
| 3897 | TEST_F(WebRtcSdpTest, PlanBHasSsrcAttributeMsidSignaling) { |
| 3898 | JsepSessionDescription jsep_desc(kDummyType); |
| 3899 | ASSERT_TRUE(SdpDeserialize(kPlanBSdpFullString, &jsep_desc)); |
| 3900 | EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute, |
| 3901 | jsep_desc.description()->msid_signaling()); |
| 3902 | } |
| 3903 | |
| 3904 | TEST_F(WebRtcSdpTest, UnifiedPlanHasMediaSectionMsidSignaling) { |
| 3905 | JsepSessionDescription jsep_desc(kDummyType); |
| 3906 | ASSERT_TRUE(SdpDeserialize(kUnifiedPlanSdpFullString, &jsep_desc)); |
| 3907 | EXPECT_EQ(cricket::kMsidSignalingMediaSection, |
| 3908 | jsep_desc.description()->msid_signaling()); |
| 3909 | } |
| 3910 | |
| 3911 | const char kMediaSectionMsidLine[] = "a=msid:local_stream_1 audio_track_id_1"; |
| 3912 | const char kSsrcAttributeMsidLine[] = |
| 3913 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1"; |
| 3914 | |
| 3915 | TEST_F(WebRtcSdpTest, SerializeOnlyMediaSectionMsid) { |
| 3916 | jdesc_.description()->set_msid_signaling(cricket::kMsidSignalingMediaSection); |
| 3917 | std::string sdp = webrtc::SdpSerialize(jdesc_); |
| 3918 | |
| 3919 | EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine)); |
| 3920 | EXPECT_EQ(std::string::npos, sdp.find(kSsrcAttributeMsidLine)); |
| 3921 | } |
| 3922 | |
| 3923 | TEST_F(WebRtcSdpTest, SerializeOnlySsrcAttributeMsid) { |
| 3924 | jdesc_.description()->set_msid_signaling( |
| 3925 | cricket::kMsidSignalingSsrcAttribute); |
| 3926 | std::string sdp = webrtc::SdpSerialize(jdesc_); |
| 3927 | |
| 3928 | EXPECT_EQ(std::string::npos, sdp.find(kMediaSectionMsidLine)); |
| 3929 | EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine)); |
| 3930 | } |
| 3931 | |
| 3932 | TEST_F(WebRtcSdpTest, SerializeBothMediaSectionAndSsrcAttributeMsid) { |
| 3933 | jdesc_.description()->set_msid_signaling( |
| 3934 | cricket::kMsidSignalingMediaSection | |
| 3935 | cricket::kMsidSignalingSsrcAttribute); |
| 3936 | std::string sdp = webrtc::SdpSerialize(jdesc_); |
| 3937 | |
| 3938 | EXPECT_NE(std::string::npos, sdp.find(kMediaSectionMsidLine)); |
| 3939 | EXPECT_NE(std::string::npos, sdp.find(kSsrcAttributeMsidLine)); |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 3940 | } |
deadbeef | 7e146cb | 2016-09-28 17:04:34 | [diff] [blame] | 3941 | |
deadbeef | b236257 | 2016-12-14 00:37:06 | [diff] [blame] | 3942 | // Regression test for integer overflow bug: |
| 3943 | // https://bugs.chromium.org/p/chromium/issues/detail?id=648071 |
| 3944 | TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) { |
deadbeef | b236257 | 2016-12-14 00:37:06 | [diff] [blame] | 3945 | // Bandwidth attribute is the max signed 32-bit int, which will get |
| 3946 | // multiplied by 1000 and cause int overflow if not careful. |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3947 | static const char kSdpWithLargeBandwidth[] = |
deadbeef | b236257 | 2016-12-14 00:37:06 | [diff] [blame] | 3948 | "v=0\r\n" |
| 3949 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3950 | "s=-\r\n" |
| 3951 | "t=0 0\r\n" |
| 3952 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3953 | "b=AS:2147483647\r\n" |
| 3954 | "foo=fail\r\n"; |
| 3955 | |
| 3956 | ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail"); |
| 3957 | } |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3958 | |
deadbeef | bc88c6b | 2017-08-02 18:26:34 | [diff] [blame] | 3959 | // Similar to the above, except that negative values are illegal, not just |
| 3960 | // error-prone as large values are. |
| 3961 | // https://bugs.chromium.org/p/chromium/issues/detail?id=675361 |
| 3962 | TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) { |
| 3963 | static const char kSdpWithNegativeBandwidth[] = |
| 3964 | "v=0\r\n" |
| 3965 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3966 | "s=-\r\n" |
| 3967 | "t=0 0\r\n" |
| 3968 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3969 | "b=AS:-1000\r\n"; |
| 3970 | |
| 3971 | ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000"); |
| 3972 | } |
| 3973 | |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3974 | // An exception to the above rule: a value of -1 for b=AS should just be |
| 3975 | // ignored, resulting in "kAutoBandwidth" in the deserialized object. |
| 3976 | // Applications historically may be using "b=AS:-1" to mean "no bandwidth |
| 3977 | // limit", but this is now what ommitting the attribute entirely will do, so |
| 3978 | // ignoring it will have the intended effect. |
| 3979 | TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) { |
| 3980 | static const char kSdpWithBandwidthOfNegativeOne[] = |
| 3981 | "v=0\r\n" |
| 3982 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3983 | "s=-\r\n" |
| 3984 | "t=0 0\r\n" |
| 3985 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3986 | "b=AS:-1\r\n"; |
| 3987 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 3988 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3989 | EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output)); |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3990 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 3991 | GetFirstVideoContentDescription(jdesc_output.description()); |
| 3992 | ASSERT_TRUE(vcd); |
deadbeef | 3e8016e | 2017-08-04 00:49:30 | [diff] [blame] | 3993 | EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth()); |
| 3994 | } |
| 3995 | |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 3996 | // Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only |
| 3997 | // the "a=ice-ufrag"/"a=ice-pwd" attributes are used. |
| 3998 | // Regression test for: |
| 3999 | // https://bugs.chromium.org/p/chromium/issues/detail?id=681286 |
| 4000 | TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) { |
| 4001 | // Important piece is "ufrag foo pwd bar". |
| 4002 | static const char kSdpWithIceCredentialsInCandidateString[] = |
| 4003 | "v=0\r\n" |
| 4004 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4005 | "s=-\r\n" |
| 4006 | "t=0 0\r\n" |
| 4007 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4008 | "c=IN IP4 0.0.0.0\r\n" |
| 4009 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 4010 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 4011 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4012 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 4013 | "generation 2 ufrag foo pwd bar\r\n"; |
| 4014 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4015 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 4016 | EXPECT_TRUE( |
| 4017 | SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output)); |
| 4018 | const IceCandidateCollection* candidates = jdesc_output.candidates(0); |
| 4019 | ASSERT_NE(nullptr, candidates); |
Mirko Bonadei | e12c1fe | 2018-07-03 10:53:23 | [diff] [blame] | 4020 | ASSERT_EQ(1U, candidates->count()); |
deadbeef | 7bcdb69 | 2017-01-20 20:43:58 | [diff] [blame] | 4021 | cricket::Candidate c = candidates->at(0)->candidate(); |
| 4022 | EXPECT_EQ("ufrag_voice", c.username()); |
| 4023 | EXPECT_EQ("pwd_voice", c.password()); |
| 4024 | } |
deadbeef | 90f1e1e | 2017-02-10 20:35:05 | [diff] [blame] | 4025 | |
Johannes Kron | 211856b | 2018-09-06 10:12:28 | [diff] [blame] | 4026 | // Test that attribute lines "a=ice-ufrag-something"/"a=ice-pwd-something" are |
| 4027 | // ignored, and only the "a=ice-ufrag"/"a=ice-pwd" attributes are used. |
| 4028 | // Regression test for: |
| 4029 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=9712 |
| 4030 | TEST_F(WebRtcSdpTest, AttributeWithPartialMatchingNameIsIgnored) { |
| 4031 | static const char kSdpWithFooIceCredentials[] = |
| 4032 | "v=0\r\n" |
| 4033 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4034 | "s=-\r\n" |
| 4035 | "t=0 0\r\n" |
| 4036 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4037 | "c=IN IP4 0.0.0.0\r\n" |
| 4038 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 4039 | "a=ice-ufrag-something:foo\r\na=ice-pwd-something:bar\r\n" |
| 4040 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 4041 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4042 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 4043 | "generation 2\r\n"; |
| 4044 | |
| 4045 | JsepSessionDescription jdesc_output(kDummyType); |
| 4046 | EXPECT_TRUE(SdpDeserialize(kSdpWithFooIceCredentials, &jdesc_output)); |
| 4047 | const IceCandidateCollection* candidates = jdesc_output.candidates(0); |
| 4048 | ASSERT_NE(nullptr, candidates); |
| 4049 | ASSERT_EQ(1U, candidates->count()); |
| 4050 | cricket::Candidate c = candidates->at(0)->candidate(); |
| 4051 | EXPECT_EQ("ufrag_voice", c.username()); |
| 4052 | EXPECT_EQ("pwd_voice", c.password()); |
| 4053 | } |
| 4054 | |
deadbeef | 90f1e1e | 2017-02-10 20:35:05 | [diff] [blame] | 4055 | // Test that SDP with an invalid port number in "a=candidate" lines is |
| 4056 | // rejected, without crashing. |
| 4057 | // Regression test for: |
| 4058 | // https://bugs.chromium.org/p/chromium/issues/detail?id=677029 |
| 4059 | TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) { |
| 4060 | static const char kSdpWithInvalidCandidatePort[] = |
| 4061 | "v=0\r\n" |
| 4062 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4063 | "s=-\r\n" |
| 4064 | "t=0 0\r\n" |
| 4065 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4066 | "c=IN IP4 0.0.0.0\r\n" |
| 4067 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 4068 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 4069 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4070 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host " |
| 4071 | "generation 2 raddr 192.168.1.1 rport 87654321\r\n"; |
| 4072 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4073 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | 90f1e1e | 2017-02-10 20:35:05 | [diff] [blame] | 4074 | EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output)); |
| 4075 | } |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4076 | |
| 4077 | // Test that "a=msid" with a missing track ID is rejected and doesn't crash. |
| 4078 | // Regression test for: |
| 4079 | // https://bugs.chromium.org/p/chromium/issues/detail?id=686405 |
| 4080 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) { |
| 4081 | static const char kSdpWithMissingTrackId[] = |
| 4082 | "v=0\r\n" |
| 4083 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4084 | "s=-\r\n" |
| 4085 | "t=0 0\r\n" |
| 4086 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4087 | "c=IN IP4 0.0.0.0\r\n" |
| 4088 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4089 | "a=msid:stream_id \r\n"; |
| 4090 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4091 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4092 | EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output)); |
| 4093 | } |
| 4094 | |
| 4095 | TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) { |
| 4096 | static const char kSdpWithMissingStreamId[] = |
| 4097 | "v=0\r\n" |
| 4098 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4099 | "s=-\r\n" |
| 4100 | "t=0 0\r\n" |
| 4101 | "m=audio 9 RTP/SAVPF 111\r\n" |
| 4102 | "c=IN IP4 0.0.0.0\r\n" |
| 4103 | "a=rtpmap:111 opus/48000/2\r\n" |
| 4104 | "a=msid: track_id\r\n"; |
| 4105 | |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4106 | JsepSessionDescription jdesc_output(kDummyType); |
deadbeef | a4549d6 | 2017-02-11 01:26:22 | [diff] [blame] | 4107 | EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output)); |
| 4108 | } |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4109 | |
| 4110 | // Tests that if both session-level address and media-level address exist, use |
| 4111 | // the media-level address. |
| 4112 | TEST_F(WebRtcSdpTest, ParseConnectionData) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4113 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4114 | |
| 4115 | // Sesssion-level address. |
| 4116 | std::string sdp = kSdpFullString; |
| 4117 | InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp); |
| 4118 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4119 | |
| 4120 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4121 | EXPECT_EQ("74.125.127.126:2345", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4122 | content1.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4123 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4124 | EXPECT_EQ("74.125.224.39:3457", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4125 | content2.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | // Tests that the session-level connection address will be used if the media |
| 4129 | // level-addresses are not specified. |
| 4130 | TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4131 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4132 | |
| 4133 | // Sesssion-level address. |
| 4134 | std::string sdp = kSdpString; |
| 4135 | InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp); |
| 4136 | // Remove the media level addresses. |
| 4137 | Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp); |
| 4138 | Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp); |
| 4139 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4140 | |
| 4141 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4142 | EXPECT_EQ("192.168.0.3:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4143 | content1.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4144 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4145 | EXPECT_EQ("192.168.0.3:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4146 | content2.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4150 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4151 | |
| 4152 | std::string sdp = kSdpString; |
| 4153 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4154 | Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n", |
| 4155 | "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 " |
| 4156 | "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n", |
| 4157 | &sdp); |
| 4158 | Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n", |
| 4159 | "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 " |
| 4160 | "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n", |
| 4161 | &sdp); |
| 4162 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4163 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4164 | EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4165 | content1.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4166 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4167 | EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9", |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4168 | content2.media_description()->connection_address().ToString()); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4169 | } |
| 4170 | |
Qingsi Wang | 5699142 | 2019-02-08 20:53:06 | [diff] [blame] | 4171 | // Test that a c= line that contains a hostname connection address can be |
| 4172 | // parsed. |
| 4173 | TEST_F(WebRtcSdpTest, ParseConnectionDataWithHostnameConnectionAddress) { |
| 4174 | JsepSessionDescription jsep_desc(kDummyType); |
| 4175 | std::string sdp = kSdpString; |
| 4176 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4177 | |
| 4178 | sdp = kSdpString; |
| 4179 | Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp); |
| 4180 | Replace("c=IN IP4 0.0.0.0\r\n", "c=IN IP4 example.local\r\n", &sdp); |
| 4181 | ASSERT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4182 | |
| 4183 | ASSERT_NE(nullptr, jsep_desc.description()); |
| 4184 | const auto& content1 = jsep_desc.description()->contents()[0]; |
| 4185 | EXPECT_EQ("example.local:9", |
| 4186 | content1.media_description()->connection_address().ToString()); |
| 4187 | const auto& content2 = jsep_desc.description()->contents()[1]; |
| 4188 | EXPECT_EQ("example.local:9", |
| 4189 | content2.media_description()->connection_address().ToString()); |
| 4190 | } |
| 4191 | |
| 4192 | // Test that the invalid or unsupported connection data cannot be parsed. |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4193 | TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4194 | JsepSessionDescription jsep_desc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4195 | std::string sdp = kSdpString; |
| 4196 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4197 | |
| 4198 | // Unsupported multicast IPv4 address. |
| 4199 | sdp = kSdpFullString; |
| 4200 | Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp); |
| 4201 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4202 | |
| 4203 | // Unsupported multicast IPv6 address. |
| 4204 | sdp = kSdpFullString; |
| 4205 | Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp); |
| 4206 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4207 | |
| 4208 | // Mismatched address type. |
| 4209 | sdp = kSdpFullString; |
| 4210 | Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp); |
| 4211 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4212 | |
| 4213 | sdp = kSdpFullString; |
| 4214 | Replace("c=IN IP4 74.125.224.39\r\n", |
| 4215 | "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp); |
| 4216 | EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc)); |
| 4217 | } |
| 4218 | |
| 4219 | TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) { |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4220 | JsepSessionDescription expected_jsep(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4221 | MakeDescriptionWithoutCandidates(&expected_jsep); |
| 4222 | // Serialization. |
Steve Anton | e831b8c | 2018-02-01 20:22:16 | [diff] [blame] | 4223 | std::string message = webrtc::SdpSerialize(expected_jsep); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4224 | // Deserialization. |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 4225 | JsepSessionDescription jdesc(kDummyType); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4226 | EXPECT_TRUE(SdpDeserialize(message, &jdesc)); |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 4227 | auto audio_desc = jdesc.description() |
| 4228 | ->GetContentByName(kAudioContentName) |
| 4229 | ->media_description(); |
| 4230 | auto video_desc = jdesc.description() |
| 4231 | ->GetContentByName(kVideoContentName) |
| 4232 | ->media_description(); |
zhihuang | 38989e5 | 2017-03-21 18:04:53 | [diff] [blame] | 4233 | EXPECT_EQ(audio_desc_->connection_address().ToString(), |
| 4234 | audio_desc->connection_address().ToString()); |
| 4235 | EXPECT_EQ(video_desc_->connection_address().ToString(), |
| 4236 | video_desc->connection_address().ToString()); |
| 4237 | } |
Taylor Brandstetter | 93a7b24 | 2018-04-16 17:45:24 | [diff] [blame] | 4238 | |
| 4239 | // RFC4566 says "If a session has no meaningful name, the value "s= " SHOULD be |
| 4240 | // used (i.e., a single space as the session name)." So we should accept that. |
| 4241 | TEST_F(WebRtcSdpTest, DeserializeEmptySessionName) { |
| 4242 | JsepSessionDescription jsep_desc(kDummyType); |
| 4243 | std::string sdp = kSdpString; |
| 4244 | Replace("s=-\r\n", "s= \r\n", &sdp); |
| 4245 | EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc)); |
| 4246 | } |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4247 | |
| 4248 | // Simulcast malformed input test for invalid format. |
| 4249 | TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_EmptyAttribute) { |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 4250 | ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n", |
| 4251 | "a=simulcast:\r\n", "a=simulcast:"); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | // Tests that duplicate simulcast entries in the SDP triggers a parse failure. |
| 4255 | TEST_F(WebRtcSdpTest, DeserializeSimulcastNegative_DuplicateAttribute) { |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 | [diff] [blame] | 4256 | ExpectParseFailureWithNewLines("a=ssrc:3 label:video_track_id_1\r\n", |
| 4257 | "a=simulcast:send 1\r\na=simulcast:recv 2\r\n", |
| 4258 | "a=simulcast:"); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | // Validates that deserialization uses the a=simulcast: attribute |
| 4262 | TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttribute) { |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4263 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4264 | sdp += "a=rid:1 send\r\n"; |
| 4265 | sdp += "a=rid:2 send\r\n"; |
| 4266 | sdp += "a=rid:3 send\r\n"; |
| 4267 | sdp += "a=rid:4 recv\r\n"; |
| 4268 | sdp += "a=rid:5 recv\r\n"; |
| 4269 | sdp += "a=rid:6 recv\r\n"; |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4270 | sdp += "a=simulcast:send 1,2;3 recv 4;5;6\r\n"; |
| 4271 | JsepSessionDescription output(kDummyType); |
| 4272 | SdpParseError error; |
| 4273 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4274 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4275 | const cricket::MediaContentDescription* media = |
| 4276 | contents.back().media_description(); |
| 4277 | EXPECT_TRUE(media->HasSimulcast()); |
| 4278 | EXPECT_EQ(2ul, media->simulcast_description().send_layers().size()); |
| 4279 | EXPECT_EQ(3ul, media->simulcast_description().receive_layers().size()); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4280 | EXPECT_FALSE(media->streams().empty()); |
| 4281 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4282 | CompareRidDescriptionIds(rids, {"1", "2", "3"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | // Validates that deserialization removes rids that do not appear in SDP |
| 4286 | TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) { |
| 4287 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4288 | sdp += "a=rid:1 send\r\n"; |
| 4289 | sdp += "a=rid:3 send\r\n"; |
| 4290 | sdp += "a=rid:4 recv\r\n"; |
| 4291 | sdp += "a=simulcast:send 1,2;3 recv 4;5,6\r\n"; |
| 4292 | JsepSessionDescription output(kDummyType); |
| 4293 | SdpParseError error; |
| 4294 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4295 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4296 | const cricket::MediaContentDescription* media = |
| 4297 | contents.back().media_description(); |
| 4298 | EXPECT_TRUE(media->HasSimulcast()); |
| 4299 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4300 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4301 | EXPECT_EQ(1ul, simulcast.receive_layers().size()); |
| 4302 | |
| 4303 | std::vector<SimulcastLayer> all_send_layers = |
| 4304 | simulcast.send_layers().GetAllLayers(); |
| 4305 | EXPECT_EQ(2ul, all_send_layers.size()); |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 4306 | EXPECT_EQ(0, |
| 4307 | absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) { |
| 4308 | return layer.rid == "2"; |
| 4309 | })); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4310 | |
| 4311 | std::vector<SimulcastLayer> all_receive_layers = |
| 4312 | simulcast.receive_layers().GetAllLayers(); |
| 4313 | ASSERT_EQ(1ul, all_receive_layers.size()); |
| 4314 | EXPECT_EQ("4", all_receive_layers[0].rid); |
| 4315 | |
| 4316 | EXPECT_FALSE(media->streams().empty()); |
| 4317 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4318 | CompareRidDescriptionIds(rids, {"1", "3"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | // Validates that Simulcast removes rids that appear in both send and receive. |
| 4322 | TEST_F(WebRtcSdpTest, |
| 4323 | TestDeserializeSimulcastAttributeRemovesDuplicateSendReceive) { |
| 4324 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4325 | sdp += "a=rid:1 send\r\n"; |
| 4326 | sdp += "a=rid:2 send\r\n"; |
| 4327 | sdp += "a=rid:3 send\r\n"; |
| 4328 | sdp += "a=rid:4 recv\r\n"; |
| 4329 | sdp += "a=simulcast:send 1;2;3 recv 2;4\r\n"; |
| 4330 | JsepSessionDescription output(kDummyType); |
| 4331 | SdpParseError error; |
| 4332 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4333 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4334 | const cricket::MediaContentDescription* media = |
| 4335 | contents.back().media_description(); |
| 4336 | EXPECT_TRUE(media->HasSimulcast()); |
| 4337 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4338 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4339 | EXPECT_EQ(1ul, simulcast.receive_layers().size()); |
| 4340 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4341 | EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size()); |
| 4342 | |
| 4343 | EXPECT_FALSE(media->streams().empty()); |
| 4344 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4345 | CompareRidDescriptionIds(rids, {"1", "3"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | // Ignores empty rid line. |
| 4349 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresEmptyRidLines) { |
| 4350 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4351 | sdp += "a=rid:1 send\r\n"; |
| 4352 | sdp += "a=rid:2 send\r\n"; |
| 4353 | sdp += "a=rid\r\n"; // Should ignore this line. |
| 4354 | sdp += "a=rid:\r\n"; // Should ignore this line. |
| 4355 | sdp += "a=simulcast:send 1;2\r\n"; |
| 4356 | JsepSessionDescription output(kDummyType); |
| 4357 | SdpParseError error; |
| 4358 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4359 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4360 | const cricket::MediaContentDescription* media = |
| 4361 | contents.back().media_description(); |
| 4362 | EXPECT_TRUE(media->HasSimulcast()); |
| 4363 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4364 | EXPECT_TRUE(simulcast.receive_layers().empty()); |
| 4365 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4366 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4367 | |
| 4368 | EXPECT_FALSE(media->streams().empty()); |
| 4369 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4370 | CompareRidDescriptionIds(rids, {"1", "2"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | // Ignores malformed rid lines. |
| 4374 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresMalformedRidLines) { |
| 4375 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4376 | sdp += "a=rid:1 send pt=\r\n"; // Should ignore this line. |
| 4377 | sdp += "a=rid:2 receive\r\n"; // Should ignore this line. |
| 4378 | sdp += "a=rid:3 max-width=720;pt=120\r\n"; // Should ignore this line. |
| 4379 | sdp += "a=rid:4\r\n"; // Should ignore this line. |
| 4380 | sdp += "a=rid:5 send\r\n"; |
| 4381 | sdp += "a=simulcast:send 1,2,3;4,5\r\n"; |
| 4382 | JsepSessionDescription output(kDummyType); |
| 4383 | SdpParseError error; |
| 4384 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4385 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4386 | const cricket::MediaContentDescription* media = |
| 4387 | contents.back().media_description(); |
| 4388 | EXPECT_TRUE(media->HasSimulcast()); |
| 4389 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4390 | EXPECT_TRUE(simulcast.receive_layers().empty()); |
| 4391 | EXPECT_EQ(1ul, simulcast.send_layers().size()); |
| 4392 | EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size()); |
| 4393 | |
| 4394 | EXPECT_FALSE(media->streams().empty()); |
| 4395 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4396 | CompareRidDescriptionIds(rids, {"5"}); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | // Removes RIDs that specify a different format than the m= section. |
| 4400 | TEST_F(WebRtcSdpTest, TestDeserializeRemovesRidsWithInvalidCodec) { |
| 4401 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4402 | sdp += "a=rid:1 send pt=121,120\r\n"; // Should remove 121 and keep RID. |
| 4403 | sdp += "a=rid:2 send pt=121\r\n"; // Should remove RID altogether. |
| 4404 | sdp += "a=simulcast:send 1;2\r\n"; |
| 4405 | JsepSessionDescription output(kDummyType); |
| 4406 | SdpParseError error; |
| 4407 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4408 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4409 | const cricket::MediaContentDescription* media = |
| 4410 | contents.back().media_description(); |
| 4411 | EXPECT_TRUE(media->HasSimulcast()); |
| 4412 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4413 | EXPECT_TRUE(simulcast.receive_layers().empty()); |
| 4414 | EXPECT_EQ(1ul, simulcast.send_layers().size()); |
| 4415 | EXPECT_EQ(1ul, simulcast.send_layers().GetAllLayers().size()); |
| 4416 | EXPECT_EQ("1", simulcast.send_layers()[0][0].rid); |
| 4417 | EXPECT_EQ(1ul, media->streams().size()); |
| 4418 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4419 | EXPECT_EQ(1ul, rids.size()); |
| 4420 | EXPECT_EQ("1", rids[0].rid); |
| 4421 | EXPECT_EQ(1ul, rids[0].payload_types.size()); |
| 4422 | EXPECT_EQ(120, rids[0].payload_types[0]); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | // Ignores duplicate rid lines |
| 4426 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresDuplicateRidLines) { |
| 4427 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4428 | sdp += "a=rid:1 send\r\n"; |
| 4429 | sdp += "a=rid:2 send\r\n"; |
| 4430 | sdp += "a=rid:2 send\r\n"; |
| 4431 | sdp += "a=rid:3 send\r\n"; |
| 4432 | sdp += "a=rid:4 recv\r\n"; |
| 4433 | sdp += "a=simulcast:send 1,2;3 recv 4\r\n"; |
| 4434 | JsepSessionDescription output(kDummyType); |
| 4435 | SdpParseError error; |
| 4436 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4437 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4438 | const cricket::MediaContentDescription* media = |
| 4439 | contents.back().media_description(); |
| 4440 | EXPECT_TRUE(media->HasSimulcast()); |
| 4441 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4442 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4443 | EXPECT_EQ(1ul, simulcast.receive_layers().size()); |
| 4444 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4445 | EXPECT_EQ(1ul, simulcast.receive_layers().GetAllLayers().size()); |
| 4446 | |
| 4447 | EXPECT_FALSE(media->streams().empty()); |
| 4448 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4449 | CompareRidDescriptionIds(rids, {"1", "3"}); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4450 | } |
| 4451 | |
Florent Castelli | c442197 | 2019-07-02 18:27:42 | [diff] [blame] | 4452 | TEST_F(WebRtcSdpTest, TestDeserializeRidSendDirection) { |
| 4453 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4454 | sdp += "a=rid:1 recv\r\n"; |
| 4455 | sdp += "a=rid:2 recv\r\n"; |
| 4456 | sdp += "a=simulcast:send 1;2\r\n"; |
| 4457 | JsepSessionDescription output(kDummyType); |
| 4458 | SdpParseError error; |
| 4459 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4460 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4461 | const cricket::MediaContentDescription* media = |
| 4462 | contents.back().media_description(); |
| 4463 | EXPECT_FALSE(media->HasSimulcast()); |
| 4464 | } |
| 4465 | |
| 4466 | TEST_F(WebRtcSdpTest, TestDeserializeRidRecvDirection) { |
| 4467 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4468 | sdp += "a=rid:1 send\r\n"; |
| 4469 | sdp += "a=rid:2 send\r\n"; |
| 4470 | sdp += "a=simulcast:recv 1;2\r\n"; |
| 4471 | JsepSessionDescription output(kDummyType); |
| 4472 | SdpParseError error; |
| 4473 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4474 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4475 | const cricket::MediaContentDescription* media = |
| 4476 | contents.back().media_description(); |
| 4477 | EXPECT_FALSE(media->HasSimulcast()); |
| 4478 | } |
| 4479 | |
| 4480 | TEST_F(WebRtcSdpTest, TestDeserializeIgnoresWrongRidDirectionLines) { |
| 4481 | std::string sdp = kUnifiedPlanSdpFullStringNoSsrc; |
| 4482 | sdp += "a=rid:1 send\r\n"; |
| 4483 | sdp += "a=rid:2 send\r\n"; |
| 4484 | sdp += "a=rid:3 send\r\n"; |
| 4485 | sdp += "a=rid:4 recv\r\n"; |
| 4486 | sdp += "a=rid:5 recv\r\n"; |
| 4487 | sdp += "a=rid:6 recv\r\n"; |
| 4488 | sdp += "a=simulcast:send 1;5;3 recv 4;2;6\r\n"; |
| 4489 | JsepSessionDescription output(kDummyType); |
| 4490 | SdpParseError error; |
| 4491 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4492 | const cricket::ContentInfos& contents = output.description()->contents(); |
| 4493 | const cricket::MediaContentDescription* media = |
| 4494 | contents.back().media_description(); |
| 4495 | EXPECT_TRUE(media->HasSimulcast()); |
| 4496 | const SimulcastDescription& simulcast = media->simulcast_description(); |
| 4497 | EXPECT_EQ(2ul, simulcast.send_layers().size()); |
| 4498 | EXPECT_EQ(2ul, simulcast.receive_layers().size()); |
| 4499 | EXPECT_EQ(2ul, simulcast.send_layers().GetAllLayers().size()); |
| 4500 | EXPECT_EQ(2ul, simulcast.receive_layers().GetAllLayers().size()); |
| 4501 | |
| 4502 | EXPECT_FALSE(media->streams().empty()); |
| 4503 | const std::vector<RidDescription>& rids = media->streams()[0].rids(); |
| 4504 | CompareRidDescriptionIds(rids, {"1", "3"}); |
| 4505 | } |
| 4506 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4507 | // Simulcast serialization integration test. |
| 4508 | // This test will serialize and deserialize the description and compare. |
| 4509 | // More detailed tests for parsing simulcast can be found in |
| 4510 | // unit tests for SdpSerializer. |
| 4511 | TEST_F(WebRtcSdpTest, SerializeSimulcast_ComplexSerialization) { |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4512 | MakeUnifiedPlanDescription(/* use_ssrcs = */ false); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4513 | auto description = jdesc_.description(); |
| 4514 | auto media = description->GetContentDescriptionByName(kVideoContentName3); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4515 | ASSERT_EQ(media->streams().size(), 1ul); |
| 4516 | StreamParams& send_stream = media->mutable_streams()[0]; |
| 4517 | std::vector<RidDescription> send_rids; |
| 4518 | send_rids.push_back(RidDescription("1", RidDirection::kSend)); |
| 4519 | send_rids.push_back(RidDescription("2", RidDirection::kSend)); |
| 4520 | send_rids.push_back(RidDescription("3", RidDirection::kSend)); |
| 4521 | send_rids.push_back(RidDescription("4", RidDirection::kSend)); |
| 4522 | send_stream.set_rids(send_rids); |
Florent Castelli | b60141b | 2019-07-03 10:47:54 | [diff] [blame] | 4523 | std::vector<RidDescription> receive_rids; |
| 4524 | receive_rids.push_back(RidDescription("5", RidDirection::kReceive)); |
| 4525 | receive_rids.push_back(RidDescription("6", RidDirection::kReceive)); |
| 4526 | receive_rids.push_back(RidDescription("7", RidDirection::kReceive)); |
| 4527 | media->set_receive_rids(receive_rids); |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 4528 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4529 | SimulcastDescription& simulcast = media->simulcast_description(); |
| 4530 | simulcast.send_layers().AddLayerWithAlternatives( |
| 4531 | {SimulcastLayer("2", false), SimulcastLayer("1", true)}); |
| 4532 | simulcast.send_layers().AddLayerWithAlternatives( |
| 4533 | {SimulcastLayer("4", false), SimulcastLayer("3", false)}); |
Florent Castelli | b60141b | 2019-07-03 10:47:54 | [diff] [blame] | 4534 | simulcast.receive_layers().AddLayer({SimulcastLayer("5", false)}); |
| 4535 | simulcast.receive_layers().AddLayer({SimulcastLayer("6", false)}); |
| 4536 | simulcast.receive_layers().AddLayer({SimulcastLayer("7", false)}); |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4537 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 4538 | TestSerialize(jdesc_); |
| 4539 | } |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 4540 | |
| 4541 | // Test that the content name is empty if the media section does not have an |
| 4542 | // a=mid line. |
| 4543 | TEST_F(WebRtcSdpTest, ParseNoMid) { |
| 4544 | std::string sdp = kSdpString; |
| 4545 | Replace("a=mid:audio_content_name\r\n", "", &sdp); |
| 4546 | Replace("a=mid:video_content_name\r\n", "", &sdp); |
| 4547 | |
| 4548 | JsepSessionDescription output(kDummyType); |
| 4549 | SdpParseError error; |
| 4550 | ASSERT_TRUE(webrtc::SdpDeserialize(sdp, &output, &error)); |
| 4551 | |
| 4552 | EXPECT_THAT(output.description()->contents(), |
| 4553 | ElementsAre(Field("name", &cricket::ContentInfo::name, ""), |
| 4554 | Field("name", &cricket::ContentInfo::name, ""))); |
| 4555 | } |
Piotr (Peter) Slatala | 13e570f | 2019-02-27 19:34:26 | [diff] [blame] | 4556 | |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 4557 | TEST_F(WebRtcSdpTest, SerializeWithDefaultSctpProtocol) { |
| 4558 | AddSctpDataChannel(false); // Don't use sctpmap |
| 4559 | JsepSessionDescription jsep_desc(kDummyType); |
| 4560 | MakeDescriptionWithoutCandidates(&jsep_desc); |
| 4561 | std::string message = webrtc::SdpSerialize(jsep_desc); |
| 4562 | EXPECT_NE(std::string::npos, |
| 4563 | message.find(cricket::kMediaProtocolUdpDtlsSctp)); |
| 4564 | } |
| 4565 | |
| 4566 | TEST_F(WebRtcSdpTest, DeserializeWithAllSctpProtocols) { |
| 4567 | AddSctpDataChannel(false); |
| 4568 | std::string protocols[] = {cricket::kMediaProtocolDtlsSctp, |
| 4569 | cricket::kMediaProtocolUdpDtlsSctp, |
| 4570 | cricket::kMediaProtocolTcpDtlsSctp}; |
| 4571 | for (const auto& protocol : protocols) { |
| 4572 | sctp_desc_->set_protocol(protocol); |
| 4573 | JsepSessionDescription jsep_desc(kDummyType); |
| 4574 | MakeDescriptionWithoutCandidates(&jsep_desc); |
| 4575 | std::string message = webrtc::SdpSerialize(jsep_desc); |
| 4576 | EXPECT_NE(std::string::npos, message.find(protocol)); |
| 4577 | JsepSessionDescription jsep_output(kDummyType); |
| 4578 | SdpParseError error; |
| 4579 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jsep_output, &error)); |
| 4580 | } |
| 4581 | } |
Taylor Brandstetter | 4256df0 | 2020-02-18 22:05:07 | [diff] [blame] | 4582 | |
| 4583 | // According to https://tools.ietf.org/html/rfc5576#section-6.1, the CNAME |
| 4584 | // attribute is mandatory, but we relax that restriction. |
| 4585 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCname) { |
| 4586 | std::string sdp_without_cname = kSdpFullString; |
| 4587 | Replace("a=ssrc:1 cname:stream_1_cname\r\n", "", &sdp_without_cname); |
| 4588 | JsepSessionDescription new_jdesc(kDummyType); |
| 4589 | EXPECT_TRUE(SdpDeserialize(sdp_without_cname, &new_jdesc)); |
| 4590 | |
| 4591 | audio_desc_->mutable_streams()[0].cname = ""; |
| 4592 | ASSERT_TRUE(jdesc_.Initialize(desc_.Clone(), jdesc_.session_id(), |
| 4593 | jdesc_.session_version())); |
| 4594 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 4595 | } |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4596 | |
| 4597 | TEST_F(WebRtcSdpTest, DeserializeSdpWithUnsupportedMediaType) { |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4598 | std::string sdp = kSdpSessionString; |
| 4599 | sdp += |
| 4600 | "m=bogus 9 RTP/SAVPF 0 8\r\n" |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 4601 | "c=IN IP4 0.0.0.0\r\n" |
| 4602 | "a=mid:bogusmid\r\n"; |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4603 | sdp += |
| 4604 | "m=audio/something 9 RTP/SAVPF 0 8\r\n" |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 4605 | "c=IN IP4 0.0.0.0\r\n" |
| 4606 | "a=mid:somethingmid\r\n"; |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4607 | |
| 4608 | JsepSessionDescription jdesc_output(kDummyType); |
| 4609 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4610 | |
Philipp Hancke | 4e8c115 | 2020-10-13 10:43:15 | [diff] [blame] | 4611 | ASSERT_EQ(2u, jdesc_output.description()->contents().size()); |
| 4612 | ASSERT_NE(nullptr, jdesc_output.description() |
| 4613 | ->contents()[0] |
| 4614 | .media_description() |
| 4615 | ->as_unsupported()); |
| 4616 | ASSERT_NE(nullptr, jdesc_output.description() |
| 4617 | ->contents()[1] |
| 4618 | .media_description() |
| 4619 | ->as_unsupported()); |
| 4620 | |
| 4621 | EXPECT_TRUE(jdesc_output.description()->contents()[0].rejected); |
| 4622 | EXPECT_TRUE(jdesc_output.description()->contents()[1].rejected); |
| 4623 | |
| 4624 | EXPECT_EQ(jdesc_output.description()->contents()[0].name, "bogusmid"); |
| 4625 | EXPECT_EQ(jdesc_output.description()->contents()[1].name, "somethingmid"); |
Philipp Hancke | efc55b0 | 2020-06-26 08:17:05 | [diff] [blame] | 4626 | } |
Philipp Hancke | b70c953 | 2021-01-13 09:40:06 | [diff] [blame] | 4627 | |
| 4628 | TEST_F(WebRtcSdpTest, MediaTypeProtocolMismatch) { |
| 4629 | std::string sdp = |
| 4630 | "v=0\r\n" |
| 4631 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4632 | "s=-\r\n" |
| 4633 | "t=0 0\r\n"; |
| 4634 | |
| 4635 | ExpectParseFailure(std::string(sdp + "m=audio 9 UDP/DTLS/SCTP 120\r\n"), |
| 4636 | "m=audio"); |
| 4637 | ExpectParseFailure(std::string(sdp + "m=video 9 UDP/DTLS/SCTP 120\r\n"), |
| 4638 | "m=video"); |
| 4639 | ExpectParseFailure(std::string(sdp + "m=video 9 SOMETHING 120\r\n"), |
| 4640 | "m=video"); |
| 4641 | ExpectParseFailure(std::string(sdp + "m=application 9 SOMETHING 120\r\n"), |
| 4642 | "m=application"); |
| 4643 | } |
Philipp Hancke | cd467b5 | 2021-01-29 08:29:47 | [diff] [blame] | 4644 | |
| 4645 | // Regression test for: |
| 4646 | // https://bugs.chromium.org/p/chromium/issues/detail?id=1171965 |
| 4647 | TEST_F(WebRtcSdpTest, SctpPortInUnsupportedContent) { |
| 4648 | std::string sdp = |
| 4649 | "v=0\r\n" |
| 4650 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 4651 | "s=-\r\n" |
| 4652 | "t=0 0\r\n" |
| 4653 | "m=o 1 DTLS/SCTP 5000\r\n" |
| 4654 | "a=sctp-port\r\n"; |
| 4655 | |
| 4656 | JsepSessionDescription jdesc_output(kDummyType); |
| 4657 | EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); |
| 4658 | } |
Harald Alvestrand | 99bcf60 | 2021-03-03 07:44:39 | [diff] [blame] | 4659 | |
| 4660 | TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) { |
| 4661 | std::string sdp = kSdpString; |
| 4662 | // [ is an illegal token value. |
| 4663 | Replace("a=mid:", "a=mid:[]", &sdp); |
| 4664 | ExpectParseFailure(std::string(sdp), "a=mid:[]"); |
| 4665 | } |