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