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