blob: e53232410208305c86dae21fbc23ccda6a612bd8 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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.org28e20752013-07-10 00:45:369 */
10
kwibergd1fe2812016-04-27 13:47:2911#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3612#include <set>
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "api/jsepsessiondescription.h"
17#include "media/base/mediaconstants.h"
18#include "media/engine/webrtcvideoengine.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "p2p/base/p2pconstants.h"
20#include "pc/mediasession.h"
21#include "rtc_base/checks.h"
22#include "rtc_base/gunit.h"
23#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "rtc_base/stringencode.h"
25#include "rtc_base/stringutils.h"
Patrik Höglund563934e2017-09-15 07:04:2826
ossu7bb87ee2017-01-23 12:56:2527#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 04:47:3128#include "pc/test/androidtestinitializer.h"
ossu7bb87ee2017-01-23 12:56:2529#endif
Mirko Bonadei92ea95e2017-09-15 04:47:3130#include "pc/webrtcsdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:3631
32using cricket::AudioCodec;
33using cricket::AudioContentDescription;
34using cricket::Candidate;
35using cricket::ContentInfo;
36using cricket::CryptoParams;
37using cricket::ContentGroup;
38using cricket::DataCodec;
39using cricket::DataContentDescription;
40using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
41using cricket::ICE_CANDIDATE_COMPONENT_RTP;
42using cricket::kFecSsrcGroupSemantics;
43using cricket::LOCAL_PORT_TYPE;
44using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:3645using cricket::NS_JINGLE_RTP;
henrike@webrtc.org28e20752013-07-10 00:45:3646using cricket::RELAY_PORT_TYPE;
47using cricket::SessionDescription;
48using cricket::StreamParams;
49using cricket::STUN_PORT_TYPE;
50using cricket::TransportDescription;
51using cricket::TransportInfo;
52using cricket::VideoCodec;
53using cricket::VideoContentDescription;
54using webrtc::IceCandidateCollection;
55using webrtc::IceCandidateInterface;
56using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
isheriff6f8d6862016-05-26 18:24:5558using webrtc::RtpExtension;
henrike@webrtc.org28e20752013-07-10 00:45:3659using webrtc::SdpParseError;
60using webrtc::SessionDescriptionInterface;
61
62typedef std::vector<AudioCodec> AudioCodecs;
63typedef std::vector<Candidate> Candidates;
64
Peter Boström0c4e06b2015-10-07 10:23:2165static const uint32_t kDefaultSctpPort = 5000;
zstein4b2e0822017-02-18 03:48:3866static const char kDefaultSctpPortStr[] = "5000";
67static const uint16_t kUnusualSctpPort = 9556;
68static const char kUnusualSctpPortStr[] = "9556";
henrike@webrtc.org28e20752013-07-10 00:45:3669static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2170static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 23:17:1471static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3672static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 23:17:1473static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3674static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2175static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:3676static const char kCandidateFoundation1[] = "a0+B/1";
77static const char kCandidateFoundation2[] = "a0+B/2";
78static const char kCandidateFoundation3[] = "a0+B/3";
79static const char kCandidateFoundation4[] = "a0+B/4";
80static const char kAttributeCryptoVoice[] =
81 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
82 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
83 "dummy_session_params\r\n";
84static const char kAttributeCryptoVideo[] =
85 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
86 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
87static const char kFingerprint[] = "a=fingerprint:sha-1 "
88 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
89static const int kExtmapId = 1;
90static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
91static const char kExtmap[] =
92 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
93static const char kExtmapWithDirectionAndAttribute[] =
94 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
jbauch5869f502017-06-29 19:31:3695static const char kExtmapWithDirectionAndAttributeEncrypted[] =
96 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
97 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3698
Peter Boström0c4e06b2015-10-07 10:23:2199static const uint8_t kIdentityDigest[] = {
100 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
101 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:36102
lally@webrtc.org34807282015-02-24 20:19:39103static const char kDtlsSctp[] = "DTLS/SCTP";
104static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
105static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35106
henrike@webrtc.org28e20752013-07-10 00:45:36107struct CodecParams {
108 int max_ptime;
109 int ptime;
110 int min_ptime;
111 int sprop_stereo;
112 int stereo;
113 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59114 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36115};
116
deadbeef9d3584c2016-02-17 01:54:10117// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
118// instead of "a=crypto", and have an explicit test for adding "a=crypto".
119// Currently it's the other way around.
120
henrike@webrtc.org28e20752013-07-10 00:45:36121// Reference sdp string
122static const char kSdpFullString[] =
123 "v=0\r\n"
124 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
125 "s=-\r\n"
126 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10127 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36128 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
129 "c=IN IP4 74.125.127.126\r\n"
130 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
131 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
132 "generation 2\r\n"
133 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
134 "generation 2\r\n"
135 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
136 "generation 2\r\n"
137 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
138 "generation 2\r\n"
139 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
140 "raddr 192.168.1.5 rport 2346 "
141 "generation 2\r\n"
142 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
143 "raddr 192.168.1.5 rport 2348 "
144 "generation 2\r\n"
145 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
146 "a=mid:audio_content_name\r\n"
147 "a=sendrecv\r\n"
148 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51149 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36150 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
151 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
152 "dummy_session_params\r\n"
153 "a=rtpmap:111 opus/48000/2\r\n"
154 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41155 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36156 "a=ssrc:1 cname:stream_1_cname\r\n"
157 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
158 "a=ssrc:1 mslabel:local_stream_1\r\n"
159 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36160 "m=video 3457 RTP/SAVPF 120\r\n"
161 "c=IN IP4 74.125.224.39\r\n"
162 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
163 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
164 "generation 2\r\n"
165 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
166 "generation 2\r\n"
167 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
168 "generation 2\r\n"
169 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
170 "generation 2\r\n"
171 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
172 "generation 2\r\n"
173 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
174 "generation 2\r\n"
175 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
176 "a=mid:video_content_name\r\n"
177 "a=sendrecv\r\n"
178 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
179 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
180 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10181 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36182 "a=ssrc:2 cname:stream_1_cname\r\n"
183 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
184 "a=ssrc:2 mslabel:local_stream_1\r\n"
185 "a=ssrc:2 label:video_track_id_1\r\n"
186 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10187 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36188 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10189 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36190
191// SDP reference string without the candidates.
192static const char kSdpString[] =
193 "v=0\r\n"
194 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
195 "s=-\r\n"
196 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10197 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22198 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06199 "c=IN IP4 0.0.0.0\r\n"
200 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36201 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
202 "a=mid:audio_content_name\r\n"
203 "a=sendrecv\r\n"
204 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51205 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36206 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
207 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
208 "dummy_session_params\r\n"
209 "a=rtpmap:111 opus/48000/2\r\n"
210 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41211 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36212 "a=ssrc:1 cname:stream_1_cname\r\n"
213 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
214 "a=ssrc:1 mslabel:local_stream_1\r\n"
215 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22216 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06217 "c=IN IP4 0.0.0.0\r\n"
218 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36219 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
220 "a=mid:video_content_name\r\n"
221 "a=sendrecv\r\n"
222 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
223 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
224 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10225 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36226 "a=ssrc:2 cname:stream_1_cname\r\n"
227 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
228 "a=ssrc:2 mslabel:local_stream_1\r\n"
229 "a=ssrc:2 label:video_track_id_1\r\n"
230 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10231 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36232 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10233 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36234
235static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22236 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06237 "c=IN IP4 0.0.0.0\r\n"
238 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36239 "a=ice-ufrag:ufrag_data\r\n"
240 "a=ice-pwd:pwd_data\r\n"
241 "a=mid:data_content_name\r\n"
242 "a=sendrecv\r\n"
243 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
244 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
245 "a=rtpmap:101 google-data/90000\r\n"
246 "a=ssrc:10 cname:data_channel_cname\r\n"
247 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
248 "a=ssrc:10 mslabel:data_channel\r\n"
249 "a=ssrc:10 label:data_channeld0\r\n";
250
251static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22252 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06253 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36254 "a=ice-ufrag:ufrag_data\r\n"
255 "a=ice-pwd:pwd_data\r\n"
256 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33257 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36258
lally@webrtc.orgec97c652015-02-24 20:18:48259// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56260static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26261 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
262 "a=max-message-size=100000\r\n"
263 "a=sctp-port 5000\r\n"
264 "c=IN IP4 0.0.0.0\r\n"
265 "a=ice-ufrag:ufrag_data\r\n"
266 "a=ice-pwd:pwd_data\r\n"
267 "a=mid:data_content_name\r\n";
268
lally69f57602015-10-08 17:15:04269static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
270 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
271 "a=max-message-size=100000\r\n"
272 "a=sctp-port:5000\r\n"
273 "c=IN IP4 0.0.0.0\r\n"
274 "a=ice-ufrag:ufrag_data\r\n"
275 "a=ice-pwd:pwd_data\r\n"
276 "a=mid:data_content_name\r\n";
277
henrike@webrtc.org28e20752013-07-10 00:45:36278static const char kSdpSctpDataChannelWithCandidatesString[] =
279 "m=application 2345 DTLS/SCTP 5000\r\n"
280 "c=IN IP4 74.125.127.126\r\n"
281 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
282 "generation 2\r\n"
283 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
284 "generation 2\r\n"
285 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
286 "raddr 192.168.1.5 rport 2346 "
287 "generation 2\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"
wu@webrtc.org97077a32013-10-25 21:18:33291 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36292
jiayl@webrtc.org9c16c392014-05-01 18:30:30293static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04294 "v=0\r\n"
295 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
296 "s=-\r\n"
297 "t=0 0\r\n"
298 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22299 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06300 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04301 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22302 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06303 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04304 "a=x-google-flag:conference\r\n";
305
jiayl@webrtc.orge7d47a12014-08-05 19:19:05306static const char kSdpSessionString[] =
307 "v=0\r\n"
308 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
309 "s=-\r\n"
310 "t=0 0\r\n"
311 "a=msid-semantic: WMS local_stream\r\n";
312
313static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22314 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06315 "c=IN IP4 0.0.0.0\r\n"
316 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05317 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
318 "a=mid:audio_content_name\r\n"
319 "a=sendrecv\r\n"
320 "a=rtpmap:111 opus/48000/2\r\n"
321 "a=ssrc:1 cname:stream_1_cname\r\n"
322 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
323 "a=ssrc:1 mslabel:local_stream\r\n"
324 "a=ssrc:1 label:audio_track_id_1\r\n";
325
326static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22327 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06328 "c=IN IP4 0.0.0.0\r\n"
329 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05330 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
331 "a=mid:video_content_name\r\n"
332 "a=sendrecv\r\n"
333 "a=rtpmap:120 VP8/90000\r\n"
334 "a=ssrc:2 cname:stream_1_cname\r\n"
335 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
336 "a=ssrc:2 mslabel:local_stream\r\n"
337 "a=ssrc:2 label:video_track_id_1\r\n";
338
deadbeef25ed4352016-12-13 02:37:36339// Reference sdp string using bundle-only.
340static const char kBundleOnlySdpFullString[] =
341 "v=0\r\n"
342 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
343 "s=-\r\n"
344 "t=0 0\r\n"
345 "a=group:BUNDLE audio_content_name video_content_name\r\n"
346 "a=msid-semantic: WMS local_stream_1\r\n"
347 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
348 "c=IN IP4 74.125.127.126\r\n"
349 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
350 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
351 "generation 2\r\n"
352 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
353 "generation 2\r\n"
354 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
355 "generation 2\r\n"
356 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
357 "generation 2\r\n"
358 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
359 "raddr 192.168.1.5 rport 2346 "
360 "generation 2\r\n"
361 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
362 "raddr 192.168.1.5 rport 2348 "
363 "generation 2\r\n"
364 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
365 "a=mid:audio_content_name\r\n"
366 "a=sendrecv\r\n"
367 "a=rtcp-mux\r\n"
368 "a=rtcp-rsize\r\n"
369 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
370 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
371 "dummy_session_params\r\n"
372 "a=rtpmap:111 opus/48000/2\r\n"
373 "a=rtpmap:103 ISAC/16000\r\n"
374 "a=rtpmap:104 ISAC/32000\r\n"
375 "a=ssrc:1 cname:stream_1_cname\r\n"
376 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
377 "a=ssrc:1 mslabel:local_stream_1\r\n"
378 "a=ssrc:1 label:audio_track_id_1\r\n"
379 "m=video 0 RTP/SAVPF 120\r\n"
380 "c=IN IP4 0.0.0.0\r\n"
381 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
382 "a=bundle-only\r\n"
383 "a=mid:video_content_name\r\n"
384 "a=sendrecv\r\n"
385 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
386 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
387 "a=rtpmap:120 VP8/90000\r\n"
388 "a=ssrc-group:FEC 2 3\r\n"
389 "a=ssrc:2 cname:stream_1_cname\r\n"
390 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
391 "a=ssrc:2 mslabel:local_stream_1\r\n"
392 "a=ssrc:2 label:video_track_id_1\r\n"
393 "a=ssrc:3 cname:stream_1_cname\r\n"
394 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
395 "a=ssrc:3 mslabel:local_stream_1\r\n"
396 "a=ssrc:3 label:video_track_id_1\r\n";
397
deadbeef9d3584c2016-02-17 01:54:10398// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
399// tracks.
400static const char kPlanBSdpFullString[] =
401 "v=0\r\n"
402 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
403 "s=-\r\n"
404 "t=0 0\r\n"
405 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
406 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
407 "c=IN IP4 74.125.127.126\r\n"
408 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
409 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
410 "generation 2\r\n"
411 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
412 "generation 2\r\n"
413 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
414 "generation 2\r\n"
415 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
416 "generation 2\r\n"
417 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
418 "raddr 192.168.1.5 rport 2346 "
419 "generation 2\r\n"
420 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
421 "raddr 192.168.1.5 rport 2348 "
422 "generation 2\r\n"
423 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
424 "a=mid:audio_content_name\r\n"
425 "a=sendrecv\r\n"
426 "a=rtcp-mux\r\n"
427 "a=rtcp-rsize\r\n"
428 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
429 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
430 "dummy_session_params\r\n"
431 "a=rtpmap:111 opus/48000/2\r\n"
432 "a=rtpmap:103 ISAC/16000\r\n"
433 "a=rtpmap:104 ISAC/32000\r\n"
434 "a=ssrc:1 cname:stream_1_cname\r\n"
435 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
436 "a=ssrc:1 mslabel:local_stream_1\r\n"
437 "a=ssrc:1 label:audio_track_id_1\r\n"
438 "a=ssrc:4 cname:stream_2_cname\r\n"
439 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
440 "a=ssrc:4 mslabel:local_stream_2\r\n"
441 "a=ssrc:4 label:audio_track_id_2\r\n"
442 "m=video 3457 RTP/SAVPF 120\r\n"
443 "c=IN IP4 74.125.224.39\r\n"
444 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
445 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
446 "generation 2\r\n"
447 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
448 "generation 2\r\n"
449 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
450 "generation 2\r\n"
451 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
452 "generation 2\r\n"
453 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
454 "generation 2\r\n"
455 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
456 "generation 2\r\n"
457 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
458 "a=mid:video_content_name\r\n"
459 "a=sendrecv\r\n"
460 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
461 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
462 "a=rtpmap:120 VP8/90000\r\n"
463 "a=ssrc-group:FEC 2 3\r\n"
464 "a=ssrc:2 cname:stream_1_cname\r\n"
465 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
466 "a=ssrc:2 mslabel:local_stream_1\r\n"
467 "a=ssrc:2 label:video_track_id_1\r\n"
468 "a=ssrc:3 cname:stream_1_cname\r\n"
469 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
470 "a=ssrc:3 mslabel:local_stream_1\r\n"
471 "a=ssrc:3 label:video_track_id_1\r\n"
472 "a=ssrc:5 cname:stream_2_cname\r\n"
473 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
474 "a=ssrc:5 mslabel:local_stream_2\r\n"
475 "a=ssrc:5 label:video_track_id_2\r\n"
476 "a=ssrc:6 cname:stream_2_cname\r\n"
477 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
478 "a=ssrc:6 mslabel:local_stream_2\r\n"
479 "a=ssrc:6 label:video_track_id_3\r\n";
480
Taylor Brandstetter5de6b752016-03-10 01:02:30481// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
482// tracks, but with the unified plan "a=msid" attribute.
483static const char kPlanBSdpFullStringWithMsid[] =
484 "v=0\r\n"
485 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
486 "s=-\r\n"
487 "t=0 0\r\n"
488 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
489 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
490 "c=IN IP4 74.125.127.126\r\n"
491 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
492 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
493 "generation 2\r\n"
494 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
495 "generation 2\r\n"
496 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
497 "generation 2\r\n"
498 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
499 "generation 2\r\n"
500 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
501 "raddr 192.168.1.5 rport 2346 "
502 "generation 2\r\n"
503 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
504 "raddr 192.168.1.5 rport 2348 "
505 "generation 2\r\n"
506 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
507 "a=mid:audio_content_name\r\n"
508 "a=msid:local_stream_1 audio_track_id_1\r\n"
509 "a=sendrecv\r\n"
510 "a=rtcp-mux\r\n"
511 "a=rtcp-rsize\r\n"
512 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
513 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
514 "dummy_session_params\r\n"
515 "a=rtpmap:111 opus/48000/2\r\n"
516 "a=rtpmap:103 ISAC/16000\r\n"
517 "a=rtpmap:104 ISAC/32000\r\n"
518 "a=ssrc:1 cname:stream_1_cname\r\n"
519 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
520 "a=ssrc:1 mslabel:local_stream_1\r\n"
521 "a=ssrc:1 label:audio_track_id_1\r\n"
522 "a=ssrc:4 cname:stream_2_cname\r\n"
523 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
524 "a=ssrc:4 mslabel:local_stream_2\r\n"
525 "a=ssrc:4 label:audio_track_id_2\r\n"
526 "m=video 3457 RTP/SAVPF 120\r\n"
527 "c=IN IP4 74.125.224.39\r\n"
528 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
529 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
530 "generation 2\r\n"
531 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
532 "generation 2\r\n"
533 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
534 "generation 2\r\n"
535 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
536 "generation 2\r\n"
537 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
538 "generation 2\r\n"
539 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
540 "generation 2\r\n"
541 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
542 "a=mid:video_content_name\r\n"
543 "a=msid:local_stream_1 video_track_id_1\r\n"
544 "a=sendrecv\r\n"
545 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
546 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
547 "a=rtpmap:120 VP8/90000\r\n"
548 "a=ssrc-group:FEC 2 3\r\n"
549 "a=ssrc:2 cname:stream_1_cname\r\n"
550 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
551 "a=ssrc:2 mslabel:local_stream_1\r\n"
552 "a=ssrc:2 label:video_track_id_1\r\n"
553 "a=ssrc:3 cname:stream_1_cname\r\n"
554 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
555 "a=ssrc:3 mslabel:local_stream_1\r\n"
556 "a=ssrc:3 label:video_track_id_1\r\n"
557 "a=ssrc:5 cname:stream_2_cname\r\n"
558 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
559 "a=ssrc:5 mslabel:local_stream_2\r\n"
560 "a=ssrc:5 label:video_track_id_2\r\n"
561 "a=ssrc:6 cname:stream_2_cname\r\n"
562 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
563 "a=ssrc:6 mslabel:local_stream_2\r\n"
564 "a=ssrc:6 label:video_track_id_3\r\n";
565
deadbeef9d3584c2016-02-17 01:54:10566// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
567// tracks.
568static const char kUnifiedPlanSdpFullString[] =
569 "v=0\r\n"
570 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
571 "s=-\r\n"
572 "t=0 0\r\n"
573 "a=msid-semantic: WMS local_stream_1\r\n"
574 // Audio track 1, stream 1 (with candidates).
575 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
576 "c=IN IP4 74.125.127.126\r\n"
577 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
578 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
579 "generation 2\r\n"
580 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
581 "generation 2\r\n"
582 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
583 "generation 2\r\n"
584 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
585 "generation 2\r\n"
586 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
587 "raddr 192.168.1.5 rport 2346 "
588 "generation 2\r\n"
589 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
590 "raddr 192.168.1.5 rport 2348 "
591 "generation 2\r\n"
592 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
593 "a=mid:audio_content_name\r\n"
594 "a=msid:local_stream_1 audio_track_id_1\r\n"
595 "a=sendrecv\r\n"
596 "a=rtcp-mux\r\n"
597 "a=rtcp-rsize\r\n"
598 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
599 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
600 "dummy_session_params\r\n"
601 "a=rtpmap:111 opus/48000/2\r\n"
602 "a=rtpmap:103 ISAC/16000\r\n"
603 "a=rtpmap:104 ISAC/32000\r\n"
604 "a=ssrc:1 cname:stream_1_cname\r\n"
605 // Video track 1, stream 1 (with candidates).
606 "m=video 3457 RTP/SAVPF 120\r\n"
607 "c=IN IP4 74.125.224.39\r\n"
608 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
609 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
610 "generation 2\r\n"
611 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
612 "generation 2\r\n"
613 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
614 "generation 2\r\n"
615 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
616 "generation 2\r\n"
617 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
618 "generation 2\r\n"
619 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
620 "generation 2\r\n"
621 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
622 "a=mid:video_content_name\r\n"
623 "a=msid:local_stream_1 video_track_id_1\r\n"
624 "a=sendrecv\r\n"
625 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
626 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
627 "a=rtpmap:120 VP8/90000\r\n"
628 "a=ssrc-group:FEC 2 3\r\n"
629 "a=ssrc:2 cname:stream_1_cname\r\n"
630 "a=ssrc:3 cname:stream_1_cname\r\n"
631 // Audio track 2, stream 2.
632 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
633 "c=IN IP4 0.0.0.0\r\n"
634 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
635 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
636 "a=mid:audio_content_name_2\r\n"
637 "a=msid:local_stream_2 audio_track_id_2\r\n"
638 "a=sendrecv\r\n"
639 "a=rtcp-mux\r\n"
640 "a=rtcp-rsize\r\n"
641 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
642 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
643 "dummy_session_params\r\n"
644 "a=rtpmap:111 opus/48000/2\r\n"
645 "a=rtpmap:103 ISAC/16000\r\n"
646 "a=rtpmap:104 ISAC/32000\r\n"
647 "a=ssrc:4 cname:stream_2_cname\r\n"
648 // Video track 2, stream 2.
649 "m=video 9 RTP/SAVPF 120\r\n"
650 "c=IN IP4 0.0.0.0\r\n"
651 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
652 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
653 "a=mid:video_content_name_2\r\n"
654 "a=msid:local_stream_2 video_track_id_2\r\n"
655 "a=sendrecv\r\n"
656 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
657 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
658 "a=rtpmap:120 VP8/90000\r\n"
659 "a=ssrc:5 cname:stream_2_cname\r\n"
660 // Video track 3, stream 2.
661 "m=video 9 RTP/SAVPF 120\r\n"
662 "c=IN IP4 0.0.0.0\r\n"
663 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
664 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
665 "a=mid:video_content_name_3\r\n"
666 "a=msid:local_stream_2 video_track_id_3\r\n"
667 "a=sendrecv\r\n"
668 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
669 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
670 "a=rtpmap:120 VP8/90000\r\n"
671 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36672
673// One candidate reference string as per W3c spec.
674// candidate:<blah> not a=candidate:<blah>CRLF
675static const char kRawCandidate[] =
676 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
677// One candidate reference string.
678static const char kSdpOneCandidate[] =
679 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
680 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15681
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20682static const char kSdpTcpActiveCandidate[] =
683 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
684 "tcptype active generation 2";
685static const char kSdpTcpPassiveCandidate[] =
686 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
687 "tcptype passive generation 2";
688static const char kSdpTcpSOCandidate[] =
689 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
690 "tcptype so generation 2";
691static const char kSdpTcpInvalidCandidate[] =
692 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
693 "tcptype invalid generation 2";
694
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15695// One candidate reference string with IPV6 address.
696static const char kRawIPV6Candidate[] =
697 "candidate:a0+B/1 1 udp 2130706432 "
ehmaldonado121cabb2017-05-05 19:04:36698 "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36699
700// One candidate reference string.
honghaiza54a0802015-12-17 02:37:23701static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36702 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-17 02:37:23703 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36704
705// Session id and version
706static const char kSessionId[] = "18446744069414584320";
707static const char kSessionVersion[] = "18446462598732840960";
708
deadbeef9d3584c2016-02-17 01:54:10709// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36710static const char kIceOption1[] = "iceoption1";
711static const char kIceOption2[] = "iceoption2";
712static const char kIceOption3[] = "iceoption3";
713
deadbeef9d3584c2016-02-17 01:54:10714// ICE ufrags/passwords.
715static const char kUfragVoice[] = "ufrag_voice";
716static const char kPwdVoice[] = "pwd_voice";
717static const char kUfragVideo[] = "ufrag_video";
718static const char kPwdVideo[] = "pwd_video";
719static const char kUfragData[] = "ufrag_data";
720static const char kPwdData[] = "pwd_data";
721
722// Extra ufrags/passwords for extra unified plan m= sections.
723static const char kUfragVoice2[] = "ufrag_voice_2";
724static const char kPwdVoice2[] = "pwd_voice_2";
725static const char kUfragVideo2[] = "ufrag_video_2";
726static const char kPwdVideo2[] = "pwd_video_2";
727static const char kUfragVideo3[] = "ufrag_video_3";
728static const char kPwdVideo3[] = "pwd_video_3";
729
henrike@webrtc.org28e20752013-07-10 00:45:36730// Content name
731static const char kAudioContentName[] = "audio_content_name";
732static const char kVideoContentName[] = "video_content_name";
733static const char kDataContentName[] = "data_content_name";
734
deadbeef9d3584c2016-02-17 01:54:10735// Extra content names for extra unified plan m= sections.
736static const char kAudioContentName2[] = "audio_content_name_2";
737static const char kVideoContentName2[] = "video_content_name_2";
738static const char kVideoContentName3[] = "video_content_name_3";
739
henrike@webrtc.org28e20752013-07-10 00:45:36740// MediaStream 1
741static const char kStreamLabel1[] = "local_stream_1";
742static const char kStream1Cname[] = "stream_1_cname";
743static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 10:23:21744static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36745static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-17 01:54:10746static const uint32_t kVideoTrack1Ssrc1 = 2;
747static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36748
749// MediaStream 2
750static const char kStreamLabel2[] = "local_stream_2";
751static const char kStream2Cname[] = "stream_2_cname";
752static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 10:23:21753static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-17 01:54:10754static const char kVideoTrackId2[] = "video_track_id_2";
755static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36756static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-17 01:54:10757static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36758
759// DataChannel
760static const char kDataChannelLabel[] = "data_channel";
761static const char kDataChannelMsid[] = "data_channeld0";
762static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 10:23:21763static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36764
765// Candidate
766static const char kDummyMid[] = "dummy_mid";
767static const int kDummyIndex = 123;
768
769// Misc
770static const char kDummyString[] = "dummy";
771
772// Helper functions
773
774static bool SdpDeserialize(const std::string& message,
775 JsepSessionDescription* jdesc) {
776 return webrtc::SdpDeserialize(message, jdesc, NULL);
777}
778
779static bool SdpDeserializeCandidate(const std::string& message,
780 JsepIceCandidate* candidate) {
781 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
782}
783
784// Add some extra |newlines| to the |message| after |line|.
785static void InjectAfter(const std::string& line,
786 const std::string& newlines,
787 std::string* message) {
788 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52789 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36790 tmp.c_str(), tmp.length(), message);
791}
792
793static void Replace(const std::string& line,
794 const std::string& newlines,
795 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52796 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36797 newlines.c_str(), newlines.length(), message);
798}
799
wu@webrtc.org5e760e72014-04-02 23:19:09800// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
801// message.
802static void ExpectParseFailure(const std::string& bad_sdp,
803 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36804 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36805 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09806 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36807 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09808 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
809}
810
811// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
812static void ExpectParseFailure(const char* good_part, const char* bad_part) {
813 std::string bad_sdp = kSdpFullString;
814 Replace(good_part, bad_part, &bad_sdp);
815 ExpectParseFailure(bad_sdp, bad_part);
816}
817
818// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
819static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
820 const std::string& newlines,
821 const std::string& bad_part) {
822 std::string bad_sdp = kSdpFullString;
823 InjectAfter(injectpoint, newlines, &bad_sdp);
824 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36825}
826
827static void ReplaceDirection(cricket::MediaContentDirection direction,
828 std::string* message) {
829 std::string new_direction;
830 switch (direction) {
831 case cricket::MD_INACTIVE:
832 new_direction = "a=inactive";
833 break;
834 case cricket::MD_SENDONLY:
835 new_direction = "a=sendonly";
836 break;
837 case cricket::MD_RECVONLY:
838 new_direction = "a=recvonly";
839 break;
840 case cricket::MD_SENDRECV:
841 default:
842 new_direction = "a=sendrecv";
843 break;
844 }
845 Replace("a=sendrecv", new_direction, message);
846}
847
848static void ReplaceRejected(bool audio_rejected, bool video_rejected,
849 std::string* message) {
850 if (audio_rejected) {
deadbeef3f7219b2015-12-28 23:17:14851 Replace("m=audio 9", "m=audio 0", message);
852 Replace(kAttributeIceUfragVoice, "", message);
853 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36854 }
855 if (video_rejected) {
deadbeef3f7219b2015-12-28 23:17:14856 Replace("m=video 9", "m=video 0", message);
857 Replace(kAttributeIceUfragVideo, "", message);
858 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36859 }
860}
861
862// WebRtcSdpTest
863
864class WebRtcSdpTest : public testing::Test {
865 public:
866 WebRtcSdpTest()
867 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 13:04:57868#ifdef WEBRTC_ANDROID
869 webrtc::InitializeAndroidObjects();
870#endif
henrike@webrtc.org28e20752013-07-10 00:45:36871 // AudioContentDescription
872 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-17 01:54:10873 StreamParams audio_stream;
874 audio_stream.id = kAudioTrackId1;
875 audio_stream.cname = kStream1Cname;
876 audio_stream.sync_label = kStreamLabel1;
877 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
878 audio_desc_->AddStream(audio_stream);
zhihuang38989e52017-03-21 18:04:53879 rtc::SocketAddress audio_addr("74.125.127.126", 2345);
880 audio_desc_->set_connection_address(audio_addr);
henrike@webrtc.org28e20752013-07-10 00:45:36881 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
882
883 // VideoContentDescription
deadbeef9d3584c2016-02-17 01:54:10884 video_desc_ = CreateVideoContentDescription();
885 StreamParams video_stream;
886 video_stream.id = kVideoTrackId1;
887 video_stream.cname = kStream1Cname;
888 video_stream.sync_label = kStreamLabel1;
889 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
890 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
891 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
892 video_stream.ssrc_groups.push_back(ssrc_group);
893 video_desc_->AddStream(video_stream);
zhihuang38989e52017-03-21 18:04:53894 rtc::SocketAddress video_addr("74.125.224.39", 3457);
895 video_desc_->set_connection_address(video_addr);
deadbeef9d3584c2016-02-17 01:54:10896 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36897
898 // TransportInfo
deadbeef9d3584c2016-02-17 01:54:10899 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
900 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
901 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
902 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36903
904 // v4 host
905 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52906 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07907 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31908 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
909 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36910 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07911 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31912 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
913 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36914 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07915 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31916 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
917 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36918 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07919 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31920 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
921 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36922
923 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52924 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07925 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
926 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31927 cricket::LOCAL_PORT_TYPE,
928 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36929 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07930 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
931 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31932 cricket::LOCAL_PORT_TYPE,
933 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36934 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07935 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
936 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31937 cricket::LOCAL_PORT_TYPE,
938 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36939 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07940 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
941 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31942 cricket::LOCAL_PORT_TYPE,
943 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36944
945 // stun
946 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52947 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
948 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07949 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
950 address_stun, kCandidatePriority, "", "",
951 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31952 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36953 candidate9.set_related_address(rel_address_stun);
954
955 address_stun.SetPort(port_stun++);
956 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07957 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
958 address_stun, kCandidatePriority, "", "",
959 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31960 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36961 candidate10.set_related_address(rel_address_stun);
962
963 // relay
964 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52965 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07966 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
967 address_relay, kCandidatePriority, "", "",
968 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31969 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36970 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07971 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
972 address_relay, kCandidatePriority, "", "",
973 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31974 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36975
976 // voice
977 candidates_.push_back(candidate1);
978 candidates_.push_back(candidate2);
979 candidates_.push_back(candidate5);
980 candidates_.push_back(candidate6);
981 candidates_.push_back(candidate9);
982 candidates_.push_back(candidate10);
983
984 // video
985 candidates_.push_back(candidate3);
986 candidates_.push_back(candidate4);
987 candidates_.push_back(candidate7);
988 candidates_.push_back(candidate8);
989 candidates_.push_back(candidate11);
990 candidates_.push_back(candidate12);
991
992 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
993 0, candidate1));
994
995 // Set up JsepSessionDescription.
996 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
997 std::string mline_id;
998 int mline_index = 0;
999 for (size_t i = 0; i< candidates_.size(); ++i) {
1000 // In this test, the audio m line index will be 0, and the video m line
1001 // will be 1.
1002 bool is_video = (i > 5);
1003 mline_id = is_video ? "video_content_name" : "audio_content_name";
1004 mline_index = is_video ? 1 : 0;
1005 JsepIceCandidate jice(mline_id,
1006 mline_index,
1007 candidates_.at(i));
1008 jdesc_.AddCandidate(&jice);
1009 }
1010 }
1011
deadbeef25ed4352016-12-13 02:37:361012 // Turns the existing reference description into a description using
1013 // a=bundle-only. This means no transport attributes and a 0 port value on
1014 // the m= sections not associated with the BUNDLE-tag.
1015 void MakeBundleOnlyDescription() {
1016 // Remove video candidates. JsepSessionDescription doesn't make it
1017 // simple.
1018 const IceCandidateCollection* video_candidates_collection =
1019 jdesc_.candidates(1);
1020 ASSERT_NE(nullptr, video_candidates_collection);
1021 std::vector<cricket::Candidate> video_candidates;
1022 for (size_t i = 0; i < video_candidates_collection->count(); ++i) {
1023 cricket::Candidate c = video_candidates_collection->at(i)->candidate();
1024 c.set_transport_name("video_content_name");
1025 video_candidates.push_back(c);
1026 }
1027 jdesc_.RemoveCandidates(video_candidates);
1028
1029 // And the rest of the transport attributes.
1030 desc_.transport_infos()[1].description.ice_ufrag.clear();
1031 desc_.transport_infos()[1].description.ice_pwd.clear();
1032 desc_.transport_infos()[1].description.connection_role =
1033 cricket::CONNECTIONROLE_NONE;
1034
1035 // Set bundle-only flag.
1036 desc_.contents()[1].bundle_only = true;
1037
1038 // Add BUNDLE group.
1039 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1040 group.AddContentName(kAudioContentName);
1041 group.AddContentName(kVideoContentName);
1042 desc_.AddGroup(group);
1043
1044 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1045 jdesc_.session_version()));
1046 }
1047
deadbeef9d3584c2016-02-17 01:54:101048 // Turns the existing reference description into a plan B description,
1049 // with 2 audio tracks and 3 video tracks.
1050 void MakePlanBDescription() {
1051 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
1052 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
1053
1054 StreamParams audio_track_2;
1055 audio_track_2.id = kAudioTrackId2;
1056 audio_track_2.cname = kStream2Cname;
1057 audio_track_2.sync_label = kStreamLabel2;
1058 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1059 audio_desc_->AddStream(audio_track_2);
1060
1061 StreamParams video_track_2;
1062 video_track_2.id = kVideoTrackId2;
1063 video_track_2.cname = kStream2Cname;
1064 video_track_2.sync_label = kStreamLabel2;
1065 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1066 video_desc_->AddStream(video_track_2);
1067
1068 StreamParams video_track_3;
1069 video_track_3.id = kVideoTrackId3;
1070 video_track_3.cname = kStream2Cname;
1071 video_track_3.sync_label = kStreamLabel2;
1072 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1073 video_desc_->AddStream(video_track_3);
1074
1075 desc_.RemoveContentByName(kAudioContentName);
1076 desc_.RemoveContentByName(kVideoContentName);
1077 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1078 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1079
1080 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1081 jdesc_.session_version()));
1082 }
1083
1084 // Turns the existing reference description into a unified plan description,
1085 // with 2 audio tracks and 3 video tracks.
1086 void MakeUnifiedPlanDescription() {
1087 // Audio track 2.
1088 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
1089 StreamParams audio_track_2;
1090 audio_track_2.id = kAudioTrackId2;
1091 audio_track_2.cname = kStream2Cname;
1092 audio_track_2.sync_label = kStreamLabel2;
1093 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
1094 audio_desc_2->AddStream(audio_track_2);
1095 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
1096 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1097 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
deadbeef9d3584c2016-02-17 01:54:101098 // Video track 2, in stream 2.
1099 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
1100 StreamParams video_track_2;
1101 video_track_2.id = kVideoTrackId2;
1102 video_track_2.cname = kStream2Cname;
1103 video_track_2.sync_label = kStreamLabel2;
1104 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1105 video_desc_2->AddStream(video_track_2);
1106 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1107 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1108 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1109
1110 // Video track 3, in stream 2.
1111 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1112 StreamParams video_track_3;
1113 video_track_3.id = kVideoTrackId3;
1114 video_track_3.cname = kStream2Cname;
1115 video_track_3.sync_label = kStreamLabel2;
1116 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1117 video_desc_3->AddStream(video_track_3);
1118 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1119 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1120 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1121
1122 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1123 jdesc_.session_version()));
1124 }
1125
1126 // Creates an audio content description with no streams, and some default
1127 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:361128 AudioContentDescription* CreateAudioContentDescription() {
1129 AudioContentDescription* audio = new AudioContentDescription();
1130 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 20:37:511131 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:361132 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1133 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1134 "dummy_session_params"));
1135 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 17:07:161136 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-17 01:54:101137 audio->AddCodec(opus);
ossue1405ad2017-01-23 16:55:481138 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 0, 1));
1139 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:361140 return audio;
1141 }
1142
deadbeef9d3584c2016-02-17 01:54:101143 // Creates a video content description with no streams, and some default
1144 // configuration.
1145 VideoContentDescription* CreateVideoContentDescription() {
1146 VideoContentDescription* video = new VideoContentDescription();
1147 video->AddCrypto(CryptoParams(
1148 1, "AES_CM_128_HMAC_SHA1_80",
1149 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1150 video->set_protocol(cricket::kMediaProtocolSavpf);
1151 video->AddCodec(
perkj26752742016-10-24 08:21:161152 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName));
deadbeef9d3584c2016-02-17 01:54:101153 return video;
1154 }
1155
henrike@webrtc.org28e20752013-07-10 00:45:361156 template <class MCD>
1157 void CompareMediaContentDescription(const MCD* cd1,
1158 const MCD* cd2) {
1159 // type
1160 EXPECT_EQ(cd1->type(), cd1->type());
1161
1162 // content direction
1163 EXPECT_EQ(cd1->direction(), cd2->direction());
1164
1165 // rtcp_mux
1166 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1167
deadbeef13871492015-12-09 20:37:511168 // rtcp_reduced_size
1169 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1170
henrike@webrtc.org28e20752013-07-10 00:45:361171 // cryptos
1172 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1173 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1174 ADD_FAILURE();
1175 return;
1176 }
1177 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1178 const CryptoParams c1 = cd1->cryptos().at(i);
1179 const CryptoParams c2 = cd2->cryptos().at(i);
1180 EXPECT_TRUE(c1.Matches(c2));
1181 EXPECT_EQ(c1.key_params, c2.key_params);
1182 EXPECT_EQ(c1.session_params, c2.session_params);
1183 }
lally@webrtc.orgd7b61652015-02-24 20:18:551184
henrike@webrtc.org28e20752013-07-10 00:45:361185 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:551186 // Use an equivalence class here, for old and new versions of the
1187 // protocol description.
1188 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:351189 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1190 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1191 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:551192 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:351193 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1194 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1195 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:551196 } else {
1197 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1198 }
henrike@webrtc.org28e20752013-07-10 00:45:361199
1200 // codecs
1201 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1202
1203 // bandwidth
1204 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1205
1206 // streams
1207 EXPECT_EQ(cd1->streams(), cd2->streams());
1208
1209 // extmap
1210 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1211 cd2->rtp_header_extensions().size());
1212 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
isheriff6f8d6862016-05-26 18:24:551213 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1214 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
henrike@webrtc.org28e20752013-07-10 00:45:361215 EXPECT_EQ(ext1.uri, ext2.uri);
1216 EXPECT_EQ(ext1.id, ext2.id);
jbauch5869f502017-06-29 19:31:361217 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
henrike@webrtc.org28e20752013-07-10 00:45:361218 }
henrike@webrtc.org28e20752013-07-10 00:45:361219 }
1220
zstein4b2e0822017-02-18 03:48:381221 void CompareDataContentDescription(const DataContentDescription* dcd1,
1222 const DataContentDescription* dcd2) {
1223 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1224 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1225 }
henrike@webrtc.org28e20752013-07-10 00:45:361226
1227 void CompareSessionDescription(const SessionDescription& desc1,
1228 const SessionDescription& desc2) {
1229 // Compare content descriptions.
1230 if (desc1.contents().size() != desc2.contents().size()) {
1231 ADD_FAILURE();
1232 return;
1233 }
1234 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1235 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1236 const cricket::ContentInfo& c2 = desc2.contents().at(i);
deadbeef25ed4352016-12-13 02:37:361237 // ContentInfo properties.
henrike@webrtc.org28e20752013-07-10 00:45:361238 EXPECT_EQ(c1.name, c2.name);
deadbeef25ed4352016-12-13 02:37:361239 EXPECT_EQ(c1.type, c2.type);
1240 EXPECT_EQ(c1.rejected, c2.rejected);
1241 EXPECT_EQ(c1.bundle_only, c2.bundle_only);
henrike@webrtc.org28e20752013-07-10 00:45:361242
1243 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1244 if (IsAudioContent(&c1)) {
1245 const AudioContentDescription* acd1 =
1246 static_cast<const AudioContentDescription*>(c1.description);
1247 const AudioContentDescription* acd2 =
1248 static_cast<const AudioContentDescription*>(c2.description);
1249 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1250 }
1251
1252 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1253 if (IsVideoContent(&c1)) {
1254 const VideoContentDescription* vcd1 =
1255 static_cast<const VideoContentDescription*>(c1.description);
1256 const VideoContentDescription* vcd2 =
1257 static_cast<const VideoContentDescription*>(c2.description);
1258 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1259 }
1260
1261 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1262 if (IsDataContent(&c1)) {
1263 const DataContentDescription* dcd1 =
1264 static_cast<const DataContentDescription*>(c1.description);
1265 const DataContentDescription* dcd2 =
1266 static_cast<const DataContentDescription*>(c2.description);
zstein4b2e0822017-02-18 03:48:381267 CompareDataContentDescription(dcd1, dcd2);
henrike@webrtc.org28e20752013-07-10 00:45:361268 }
1269 }
1270
1271 // group
1272 const cricket::ContentGroups groups1 = desc1.groups();
1273 const cricket::ContentGroups groups2 = desc2.groups();
1274 EXPECT_EQ(groups1.size(), groups1.size());
1275 if (groups1.size() != groups2.size()) {
1276 ADD_FAILURE();
1277 return;
1278 }
1279 for (size_t i = 0; i < groups1.size(); ++i) {
1280 const cricket::ContentGroup group1 = groups1.at(i);
1281 const cricket::ContentGroup group2 = groups2.at(i);
1282 EXPECT_EQ(group1.semantics(), group2.semantics());
1283 const cricket::ContentNames names1 = group1.content_names();
1284 const cricket::ContentNames names2 = group2.content_names();
1285 EXPECT_EQ(names1.size(), names2.size());
1286 if (names1.size() != names2.size()) {
1287 ADD_FAILURE();
1288 return;
1289 }
1290 cricket::ContentNames::const_iterator iter1 = names1.begin();
1291 cricket::ContentNames::const_iterator iter2 = names2.begin();
1292 while (iter1 != names1.end()) {
1293 EXPECT_EQ(*iter1++, *iter2++);
1294 }
1295 }
1296
1297 // transport info
1298 const cricket::TransportInfos transports1 = desc1.transport_infos();
1299 const cricket::TransportInfos transports2 = desc2.transport_infos();
1300 EXPECT_EQ(transports1.size(), transports2.size());
1301 if (transports1.size() != transports2.size()) {
1302 ADD_FAILURE();
1303 return;
1304 }
1305 for (size_t i = 0; i < transports1.size(); ++i) {
1306 const cricket::TransportInfo transport1 = transports1.at(i);
1307 const cricket::TransportInfo transport2 = transports2.at(i);
1308 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:361309 EXPECT_EQ(transport1.description.ice_ufrag,
1310 transport2.description.ice_ufrag);
1311 EXPECT_EQ(transport1.description.ice_pwd,
1312 transport2.description.ice_pwd);
1313 if (transport1.description.identity_fingerprint) {
1314 EXPECT_EQ(*transport1.description.identity_fingerprint,
1315 *transport2.description.identity_fingerprint);
1316 } else {
1317 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1318 transport2.description.identity_fingerprint.get());
1319 }
1320 EXPECT_EQ(transport1.description.transport_options,
1321 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:361322 }
deadbeefc80741f2015-10-22 20:14:451323
1324 // global attributes
1325 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:361326 }
1327
henrike@webrtc.org28e20752013-07-10 00:45:361328 bool CompareSessionDescription(
1329 const JsepSessionDescription& desc1,
1330 const JsepSessionDescription& desc2) {
1331 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1332 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1333 CompareSessionDescription(*desc1.description(), *desc2.description());
1334 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1335 return false;
1336 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1337 const IceCandidateCollection* cc1 = desc1.candidates(i);
1338 const IceCandidateCollection* cc2 = desc2.candidates(i);
deadbeef25ed4352016-12-13 02:37:361339 if (cc1->count() != cc2->count()) {
1340 ADD_FAILURE();
henrike@webrtc.org28e20752013-07-10 00:45:361341 return false;
deadbeef25ed4352016-12-13 02:37:361342 }
henrike@webrtc.org28e20752013-07-10 00:45:361343 for (size_t j = 0; j < cc1->count(); ++j) {
1344 const IceCandidateInterface* c1 = cc1->at(j);
1345 const IceCandidateInterface* c2 = cc2->at(j);
1346 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1347 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1348 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1349 }
1350 }
1351 return true;
1352 }
1353
1354 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1355 // them with invalid keywords so that the parser will just ignore them.
1356 bool RemoveCandidateUfragPwd(std::string* sdp) {
1357 const char ice_ufrag[] = "a=ice-ufrag";
1358 const char ice_ufragx[] = "a=xice-ufrag";
1359 const char ice_pwd[] = "a=ice-pwd";
1360 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521361 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:361362 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521363 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:361364 ice_pwdx, strlen(ice_pwdx), sdp);
1365 return true;
1366 }
1367
1368 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1369 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1370 const std::string& ufrag, const std::string& pwd) {
1371 std::string content_name;
1372 if (mline_index == 0) {
1373 content_name = kAudioContentName;
1374 } else if (mline_index == 1) {
1375 content_name = kVideoContentName;
1376 } else {
nissec80e7412017-01-11 13:56:461377 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:361378 }
1379 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-18 01:54:521380 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:361381 SessionDescription* desc =
1382 const_cast<SessionDescription*>(jdesc->description());
1383 desc->RemoveTransportInfoByName(content_name);
1384 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1385 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1386 const IceCandidateCollection* cc = jdesc_.candidates(i);
1387 for (size_t j = 0; j < cc->count(); ++j) {
1388 if (cc->at(j)->sdp_mline_index() == mline_index) {
1389 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1390 ufrag);
1391 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1392 pwd);
1393 }
1394 }
1395 }
1396 return true;
1397 }
1398
1399 void AddIceOptions(const std::string& content_name,
1400 const std::vector<std::string>& transport_options) {
1401 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1402 cricket::TransportInfo transport_info =
1403 *(desc_.GetTransportInfoByName(content_name));
1404 desc_.RemoveTransportInfoByName(content_name);
1405 transport_info.description.transport_options = transport_options;
1406 desc_.AddTransportInfo(transport_info);
1407 }
1408
deadbeef3f7219b2015-12-28 23:17:141409 void SetIceUfragPwd(const std::string& content_name,
1410 const std::string& ice_ufrag,
1411 const std::string& ice_pwd) {
1412 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1413 cricket::TransportInfo transport_info =
1414 *(desc_.GetTransportInfoByName(content_name));
1415 desc_.RemoveTransportInfoByName(content_name);
1416 transport_info.description.ice_ufrag = ice_ufrag;
1417 transport_info.description.ice_pwd = ice_pwd;
1418 desc_.AddTransportInfo(transport_info);
1419 }
1420
henrike@webrtc.org28e20752013-07-10 00:45:361421 void AddFingerprint() {
1422 desc_.RemoveTransportInfoByName(kAudioContentName);
1423 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521424 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:361425 kIdentityDigest,
1426 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 21:24:371427 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1428 kAudioContentName,
deadbeef9d3584c2016-02-17 01:54:101429 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1430 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 21:24:371431 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1432 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1433 kVideoContentName,
deadbeef9d3584c2016-02-17 01:54:101434 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1435 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 21:24:371436 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:361437 }
1438
jbauch5869f502017-06-29 19:31:361439 void AddExtmap(bool encrypted) {
henrike@webrtc.org28e20752013-07-10 00:45:361440 audio_desc_ = static_cast<AudioContentDescription*>(
1441 audio_desc_->Copy());
1442 video_desc_ = static_cast<VideoContentDescription*>(
1443 video_desc_->Copy());
jbauch5869f502017-06-29 19:31:361444 audio_desc_->AddRtpHeaderExtension(
1445 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1446 video_desc_->AddRtpHeaderExtension(
1447 RtpExtension(kExtmapUri, kExtmapId, encrypted));
henrike@webrtc.org28e20752013-07-10 00:45:361448 desc_.RemoveContentByName(kAudioContentName);
1449 desc_.RemoveContentByName(kVideoContentName);
1450 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1451 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1452 }
1453
1454 void RemoveCryptos() {
1455 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1456 video_desc_->set_cryptos(std::vector<CryptoParams>());
1457 }
1458
1459 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1460 audio_desc_->set_direction(direction);
1461 video_desc_->set_direction(direction);
1462 std::string new_sdp = kSdpFullString;
1463 ReplaceDirection(direction, &new_sdp);
1464
1465 if (!jdesc_.Initialize(desc_.Copy(),
1466 jdesc_.session_id(),
1467 jdesc_.session_version())) {
1468 return false;
1469 }
deadbeef9d3584c2016-02-17 01:54:101470 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361471 EXPECT_EQ(new_sdp, message);
1472 return true;
1473 }
1474
1475 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1476 audio_desc_ = static_cast<AudioContentDescription*>(
1477 audio_desc_->Copy());
1478 video_desc_ = static_cast<VideoContentDescription*>(
1479 video_desc_->Copy());
zhihuang38989e52017-03-21 18:04:531480
henrike@webrtc.org28e20752013-07-10 00:45:361481 desc_.RemoveContentByName(kAudioContentName);
1482 desc_.RemoveContentByName(kVideoContentName);
1483 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1484 audio_desc_);
1485 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1486 video_desc_);
deadbeef9d3584c2016-02-17 01:54:101487 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1488 audio_rejected ? "" : kPwdVoice);
1489 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1490 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141491
1492 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361493 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1494
deadbeef3f7219b2015-12-28 23:17:141495 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 18:04:531496 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-17 01:54:101497 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:361498 EXPECT_EQ(new_sdp, message);
1499 return true;
1500 }
1501
zstein4b2e0822017-02-18 03:48:381502 void AddSctpDataChannel(bool use_sctpmap) {
kwibergd1fe2812016-04-27 13:47:291503 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361504 data_desc_ = data.get();
zstein4b2e0822017-02-18 03:48:381505 data_desc_->set_use_sctpmap(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:361506 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
solenberg9fa49752016-10-08 20:02:441507 DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 17:07:161508 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:021509 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1510 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:361511 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-17 01:54:101512 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1513 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:361514 }
1515
1516 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 13:47:291517 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361518 data_desc_ = data.get();
1519
deadbeef67cf2c12016-04-13 17:07:161520 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:361521 StreamParams data_stream;
1522 data_stream.id = kDataChannelMsid;
1523 data_stream.cname = kDataChannelCname;
1524 data_stream.sync_label = kDataChannelLabel;
1525 data_stream.ssrcs.push_back(kDataChannelSsrc);
1526 data_desc_->AddStream(data_stream);
1527 data_desc_->AddCrypto(CryptoParams(
1528 1, "AES_CM_128_HMAC_SHA1_80",
1529 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1530 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1531 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-17 01:54:101532 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1533 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:361534 }
1535
1536 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1537 std::string new_sdp = kSdpFullString;
1538 ReplaceDirection(direction, &new_sdp);
1539 JsepSessionDescription new_jdesc(kDummyString);
1540
1541 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1542
1543 audio_desc_->set_direction(direction);
1544 video_desc_->set_direction(direction);
1545 if (!jdesc_.Initialize(desc_.Copy(),
1546 jdesc_.session_id(),
1547 jdesc_.session_version())) {
1548 return false;
1549 }
1550 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1551 return true;
1552 }
1553
1554 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 23:17:141555 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361556 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1557 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361558 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 23:17:141559
henrike@webrtc.org28e20752013-07-10 00:45:361560 audio_desc_ = static_cast<AudioContentDescription*>(
1561 audio_desc_->Copy());
1562 video_desc_ = static_cast<VideoContentDescription*>(
1563 video_desc_->Copy());
1564 desc_.RemoveContentByName(kAudioContentName);
1565 desc_.RemoveContentByName(kVideoContentName);
1566 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1567 audio_desc_);
1568 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1569 video_desc_);
deadbeef9d3584c2016-02-17 01:54:101570 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1571 audio_rejected ? "" : kPwdVoice);
1572 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1573 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141574 JsepSessionDescription jdesc_no_candidates(kDummyString);
1575 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1576 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:361577 return false;
1578 }
deadbeef3f7219b2015-12-28 23:17:141579 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:361580 return true;
1581 }
1582
jbauch5869f502017-06-29 19:31:361583 void TestDeserializeExtmap(bool session_level, bool media_level,
1584 bool encrypted) {
1585 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:361586 JsepSessionDescription new_jdesc("dummy");
1587 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1588 jdesc_.session_id(),
1589 jdesc_.session_version()));
1590 JsepSessionDescription jdesc_with_extmap("dummy");
1591 std::string sdp_with_extmap = kSdpString;
1592 if (session_level) {
jbauch5869f502017-06-29 19:31:361593 InjectAfter(kSessionTime,
1594 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1595 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361596 &sdp_with_extmap);
1597 }
1598 if (media_level) {
jbauch5869f502017-06-29 19:31:361599 InjectAfter(kAttributeIcePwdVoice,
1600 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1601 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361602 &sdp_with_extmap);
jbauch5869f502017-06-29 19:31:361603 InjectAfter(kAttributeIcePwdVideo,
1604 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1605 : kExtmapWithDirectionAndAttribute,
henrike@webrtc.org28e20752013-07-10 00:45:361606 &sdp_with_extmap);
1607 }
1608 // The extmap can't be present at the same time in both session level and
1609 // media level.
1610 if (session_level && media_level) {
1611 SdpParseError error;
1612 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1613 &jdesc_with_extmap, &error));
1614 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1615 } else {
1616 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1617 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1618 }
1619 }
1620
1621 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1622 const std::string& name, int expected_value) {
1623 cricket::CodecParameterMap::const_iterator found = params.find(name);
1624 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521625 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:361626 }
1627
1628 void TestDeserializeCodecParams(const CodecParams& params,
1629 JsepSessionDescription* jdesc_output) {
1630 std::string sdp =
1631 "v=0\r\n"
1632 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1633 "s=-\r\n"
1634 "t=0 0\r\n"
1635 // Include semantics for WebRTC Media Streams since it is supported by
1636 // this parser, and will be added to the SDP when serializing a session
1637 // description.
1638 "a=msid-semantic: WMS\r\n"
1639 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411640 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361641 // Pltype 111 listed before 103 and 104 in the map.
1642 "a=rtpmap:111 opus/48000/2\r\n"
1643 // Pltype 103 listed before 104.
1644 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411645 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:151646 "a=fmtp:111 0-15,66,70\r\n"
1647 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:361648 std::ostringstream os;
Donald Curtis144d0182015-05-15 20:14:241649 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:151650 << "; sprop-stereo=" << params.sprop_stereo
1651 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 16:21:231652 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361653 << "a=ptime:" << params.ptime << "\r\n"
1654 << "a=maxptime:" << params.max_ptime << "\r\n";
1655 sdp += os.str();
1656
stefan@webrtc.org85d27942014-06-09 12:51:391657 os.clear();
1658 os.str("");
1659 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221660 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:391661 << "a=rtpmap:99 VP8/90000\r\n"
1662 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:231663 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:391664 sdp += os.str();
1665
henrike@webrtc.org28e20752013-07-10 00:45:361666 // Deserialize
1667 SdpParseError error;
1668 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1669
1670 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1671 ASSERT_TRUE(ac != NULL);
1672 const AudioContentDescription* acd =
1673 static_cast<const AudioContentDescription*>(ac->description);
1674 ASSERT_FALSE(acd->codecs().empty());
1675 cricket::AudioCodec opus = acd->codecs()[0];
1676 EXPECT_EQ("opus", opus.name);
1677 EXPECT_EQ(111, opus.id);
1678 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1679 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1680 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1681 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:591682 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1683 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:361684 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1685 cricket::AudioCodec codec = acd->codecs()[i];
1686 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1687 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
henrike@webrtc.org28e20752013-07-10 00:45:361688 }
stefan@webrtc.org85d27942014-06-09 12:51:391689
1690 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1691 ASSERT_TRUE(vc != NULL);
1692 const VideoContentDescription* vcd =
1693 static_cast<const VideoContentDescription*>(vc->description);
1694 ASSERT_FALSE(vcd->codecs().empty());
1695 cricket::VideoCodec vp8 = vcd->codecs()[0];
1696 EXPECT_EQ("VP8", vp8.name);
1697 EXPECT_EQ(99, vp8.id);
1698 cricket::VideoCodec rtx = vcd->codecs()[1];
1699 EXPECT_EQ("RTX", rtx.name);
1700 EXPECT_EQ(95, rtx.id);
1701 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:361702 }
1703
1704 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1705 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:461706 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:361707 "v=0\r\n"
1708 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1709 "s=-\r\n"
1710 "t=0 0\r\n"
1711 // Include semantics for WebRTC Media Streams since it is supported by
1712 // this parser, and will be added to the SDP when serializing a session
1713 // description.
1714 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221715 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461716 "a=rtpmap:111 opus/48000/2\r\n";
1717 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:361718 "m=video 3457 RTP/SAVPF 101\r\n"
1719 "a=rtpmap:101 VP8/90000\r\n"
1720 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:581721 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461722 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:361723 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:461724 os << sdp_session_and_audio;
1725 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1726 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:361727 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:461728 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:361729 // Deserialize
1730 SdpParseError error;
1731 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1732 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1733 ASSERT_TRUE(ac != NULL);
1734 const AudioContentDescription* acd =
1735 static_cast<const AudioContentDescription*>(ac->description);
1736 ASSERT_FALSE(acd->codecs().empty());
1737 cricket::AudioCodec opus = acd->codecs()[0];
1738 EXPECT_EQ(111, opus.id);
1739 EXPECT_TRUE(opus.HasFeedbackParam(
1740 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1741 cricket::kParamValueEmpty)));
1742
1743 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1744 ASSERT_TRUE(vc != NULL);
1745 const VideoContentDescription* vcd =
1746 static_cast<const VideoContentDescription*>(vc->description);
1747 ASSERT_FALSE(vcd->codecs().empty());
1748 cricket::VideoCodec vp8 = vcd->codecs()[0];
1749 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1750 vp8.name.c_str());
1751 EXPECT_EQ(101, vp8.id);
1752 EXPECT_TRUE(vp8.HasFeedbackParam(
1753 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1754 cricket::kParamValueEmpty)));
1755 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:581756 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1757 cricket::kRtcpFbNackParamPli)));
1758 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:361759 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1760 cricket::kParamValueEmpty)));
1761 EXPECT_TRUE(vp8.HasFeedbackParam(
1762 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1763 cricket::kRtcpFbCcmParamFir)));
1764 }
1765
1766 // Two SDP messages can mean the same thing but be different strings, e.g.
1767 // some of the lines can be serialized in different order.
1768 // However, a deserialized description can be compared field by field and has
1769 // no order. If deserializer has already been tested, serializing then
1770 // deserializing and comparing JsepSessionDescription will test
1771 // the serializer sufficiently.
deadbeef9d3584c2016-02-17 01:54:101772 void TestSerialize(const JsepSessionDescription& jdesc,
1773 bool unified_plan_sdp) {
1774 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:361775 JsepSessionDescription jdesc_output_des(kDummyString);
1776 SdpParseError error;
1777 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1778 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1779 }
1780
zhihuang38989e52017-03-21 18:04:531781 // Calling 'Initialize' with a copy of the inner SessionDescription will
1782 // create a copy of the JsepSessionDescription without candidates. The
1783 // 'connection address' field, previously set from the candidates, must also
1784 // be reset.
1785 void MakeDescriptionWithoutCandidates(JsepSessionDescription* jdesc) {
1786 rtc::SocketAddress audio_addr("0.0.0.0", 9);
1787 rtc::SocketAddress video_addr("0.0.0.0", 9);
1788 audio_desc_->set_connection_address(audio_addr);
1789 video_desc_->set_connection_address(video_addr);
1790 ASSERT_TRUE(jdesc->Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1791 }
1792
henrike@webrtc.org28e20752013-07-10 00:45:361793 protected:
1794 SessionDescription desc_;
1795 AudioContentDescription* audio_desc_;
1796 VideoContentDescription* video_desc_;
1797 DataContentDescription* data_desc_;
1798 Candidates candidates_;
kwibergd1fe2812016-04-27 13:47:291799 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:361800 JsepSessionDescription jdesc_;
1801};
1802
1803void TestMismatch(const std::string& string1, const std::string& string2) {
1804 int position = 0;
1805 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1806 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:491807 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:361808 break;
1809 }
1810 }
1811 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1812 << " character\n"
1813 << " 1: " << string1.substr(position, 20) << "\n"
1814 << " 2: " << string2.substr(position, 20) << "\n";
1815}
1816
henrike@webrtc.org28e20752013-07-10 00:45:361817TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1818 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-17 01:54:101819 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361820 TestMismatch(std::string(kSdpFullString), message);
1821}
1822
1823TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1824 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-17 01:54:101825 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:361826}
1827
1828// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1829// the case in a DTLS offer.
1830TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1831 AddFingerprint();
1832 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 18:04:531833 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-17 01:54:101834 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:361835
1836 std::string sdp_with_fingerprint = kSdpString;
1837 InjectAfter(kAttributeIcePwdVoice,
1838 kFingerprint, &sdp_with_fingerprint);
1839 InjectAfter(kAttributeIcePwdVideo,
1840 kFingerprint, &sdp_with_fingerprint);
1841
1842 EXPECT_EQ(sdp_with_fingerprint, message);
1843}
1844
1845// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1846// be the case in a DTLS answer.
1847TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1848 AddFingerprint();
1849 RemoveCryptos();
1850 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
zhihuang38989e52017-03-21 18:04:531851 MakeDescriptionWithoutCandidates(&jdesc_with_fingerprint);
deadbeef9d3584c2016-02-17 01:54:101852 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:361853
1854 std::string sdp_with_fingerprint = kSdpString;
1855 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1856 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1857 InjectAfter(kAttributeIcePwdVoice,
1858 kFingerprint, &sdp_with_fingerprint);
1859 InjectAfter(kAttributeIcePwdVideo,
1860 kFingerprint, &sdp_with_fingerprint);
1861
1862 EXPECT_EQ(sdp_with_fingerprint, message);
1863}
1864
1865TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1866 // JsepSessionDescription with desc but without candidates.
1867 JsepSessionDescription jdesc_no_candidates(kDummyString);
zhihuang38989e52017-03-21 18:04:531868 MakeDescriptionWithoutCandidates(&jdesc_no_candidates);
deadbeef9d3584c2016-02-17 01:54:101869 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:361870 EXPECT_EQ(std::string(kSdpString), message);
1871}
1872
1873TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1874 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1875 group.AddContentName(kAudioContentName);
1876 group.AddContentName(kVideoContentName);
1877 desc_.AddGroup(group);
1878 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1879 jdesc_.session_id(),
1880 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101881 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361882 std::string sdp_with_bundle = kSdpFullString;
1883 InjectAfter(kSessionTime,
1884 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1885 &sdp_with_bundle);
1886 EXPECT_EQ(sdp_with_bundle, message);
1887}
1888
1889TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1890 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1891 GetFirstVideoContent(&desc_)->description);
1892 vcd->set_bandwidth(100 * 1000);
1893 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1894 GetFirstAudioContent(&desc_)->description);
1895 acd->set_bandwidth(50 * 1000);
1896 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1897 jdesc_.session_id(),
1898 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101899 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361900 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:131901 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:361902 "b=AS:100\r\n",
1903 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:131904 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:361905 "b=AS:50\r\n",
1906 &sdp_with_bandwidth);
1907 EXPECT_EQ(sdp_with_bandwidth, message);
1908}
1909
1910TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1911 std::vector<std::string> transport_options;
1912 transport_options.push_back(kIceOption1);
1913 transport_options.push_back(kIceOption3);
1914 AddIceOptions(kAudioContentName, transport_options);
1915 transport_options.clear();
1916 transport_options.push_back(kIceOption2);
1917 transport_options.push_back(kIceOption3);
1918 AddIceOptions(kVideoContentName, transport_options);
1919 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1920 jdesc_.session_id(),
1921 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101922 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361923 std::string sdp_with_ice_options = kSdpFullString;
1924 InjectAfter(kAttributeIcePwdVoice,
1925 "a=ice-options:iceoption1 iceoption3\r\n",
1926 &sdp_with_ice_options);
1927 InjectAfter(kAttributeIcePwdVideo,
1928 "a=ice-options:iceoption2 iceoption3\r\n",
1929 &sdp_with_ice_options);
1930 EXPECT_EQ(sdp_with_ice_options, message);
1931}
1932
1933TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1934 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1935}
1936
1937TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1938 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1939}
1940
1941TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1942 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1943}
1944
1945TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1946 EXPECT_TRUE(TestSerializeRejected(true, false));
1947}
1948
1949TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1950 EXPECT_TRUE(TestSerializeRejected(false, true));
1951}
1952
1953TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1954 EXPECT_TRUE(TestSerializeRejected(true, true));
1955}
1956
1957TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1958 AddRtpDataChannel();
1959 JsepSessionDescription jsep_desc(kDummyString);
1960
zhihuang38989e52017-03-21 18:04:531961 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-17 01:54:101962 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:361963
1964 std::string expected_sdp = kSdpString;
1965 expected_sdp.append(kSdpRtpDataChannelString);
1966 EXPECT_EQ(expected_sdp, message);
1967}
1968
1969TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
zstein4b2e0822017-02-18 03:48:381970 bool use_sctpmap = true;
1971 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:361972 JsepSessionDescription jsep_desc(kDummyString);
1973
zhihuang38989e52017-03-21 18:04:531974 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-17 01:54:101975 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:361976
1977 std::string expected_sdp = kSdpString;
1978 expected_sdp.append(kSdpSctpDataChannelString);
1979 EXPECT_EQ(message, expected_sdp);
1980}
1981
jiayl@webrtc.org9c16c392014-05-01 18:30:301982TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
zstein4b2e0822017-02-18 03:48:381983 bool use_sctpmap = true;
1984 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.org9c16c392014-05-01 18:30:301985 JsepSessionDescription jsep_desc(kDummyString);
zhihuang38989e52017-03-21 18:04:531986 MakeDescriptionWithoutCandidates(&jsep_desc);
jiayl@webrtc.org9c16c392014-05-01 18:30:301987 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1988 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1989
1990 const int kNewPort = 1234;
solenberg9fa49752016-10-08 20:02:441991 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType,
deadbeef67cf2c12016-04-13 17:07:161992 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:301993 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1994 dcdesc->AddOrReplaceCodec(codec);
1995
deadbeef9d3584c2016-02-17 01:54:101996 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:301997
1998 std::string expected_sdp = kSdpString;
1999 expected_sdp.append(kSdpSctpDataChannelString);
2000
2001 char default_portstr[16];
2002 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:522003 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:302004 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:522005 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2006 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:302007 new_portstr, strlen(new_portstr),
2008 &expected_sdp);
2009
2010 EXPECT_EQ(expected_sdp, message);
2011}
2012
wu@webrtc.orgcadf9042013-08-30 21:24:162013TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
zhihuang38989e52017-03-21 18:04:532014 JsepSessionDescription jsep_desc(kDummyString);
wu@webrtc.orgcadf9042013-08-30 21:24:162015 AddRtpDataChannel();
2016 data_desc_->set_bandwidth(100*1000);
zhihuang38989e52017-03-21 18:04:532017 MakeDescriptionWithoutCandidates(&jsep_desc);
deadbeef9d3584c2016-02-17 01:54:102018 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:162019
2020 std::string expected_sdp = kSdpString;
2021 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 22:31:252022 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:062023 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
sergeyu@chromium.orga59696b2013-09-13 23:48:582024 "b=AS:100\r\n",
2025 &expected_sdp);
2026 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:162027}
2028
henrike@webrtc.org28e20752013-07-10 00:45:362029TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
jbauch5869f502017-06-29 19:31:362030 bool encrypted = false;
2031 AddExtmap(encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:362032 JsepSessionDescription desc_with_extmap("dummy");
zhihuang38989e52017-03-21 18:04:532033 MakeDescriptionWithoutCandidates(&desc_with_extmap);
deadbeef9d3584c2016-02-17 01:54:102034 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:362035
2036 std::string sdp_with_extmap = kSdpString;
2037 InjectAfter("a=mid:audio_content_name\r\n",
2038 kExtmap, &sdp_with_extmap);
2039 InjectAfter("a=mid:video_content_name\r\n",
2040 kExtmap, &sdp_with_extmap);
2041
2042 EXPECT_EQ(sdp_with_extmap, message);
2043}
2044
jbauch5869f502017-06-29 19:31:362045TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2046 bool encrypted = true;
2047 AddExtmap(encrypted);
2048 JsepSessionDescription desc_with_extmap("dummy");
2049 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2050 kSessionId, kSessionVersion));
2051 TestSerialize(desc_with_extmap, false);
2052}
2053
henrike@webrtc.org28e20752013-07-10 00:45:362054TEST_F(WebRtcSdpTest, SerializeCandidates) {
2055 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:102056 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-17 02:37:232057
2058 Candidate candidate_with_ufrag(candidates_.front());
2059 candidate_with_ufrag.set_username("ABC");
2060 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2061 candidate_with_ufrag));
2062 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2063 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 23:07:482064
2065 Candidate candidate_with_network_info(candidates_.front());
2066 candidate_with_network_info.set_network_id(1);
2067 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2068 candidate_with_network_info));
2069 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2070 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2071 candidate_with_network_info.set_network_cost(999);
2072 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2073 candidate_with_network_info));
2074 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2075 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2076 message);
henrike@webrtc.org28e20752013-07-10 00:45:362077}
2078
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202079// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2080// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:552081TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:072082 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312083 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2084 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2085 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202086 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 13:47:292087 std::unique_ptr<IceCandidateInterface> jcandidate(
2088 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202089
2090 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2091 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2092}
2093
htaa6b99442016-04-12 17:29:172094TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
magjed509e4fe2016-11-18 09:34:112095 cricket::VideoCodec h264_codec("H264");
2096 h264_codec.SetParam("profile-level-id", "42e01f");
2097 h264_codec.SetParam("level-asymmetry-allowed", "1");
2098 h264_codec.SetParam("packetization-mode", "1");
2099 video_desc_->AddCodec(h264_codec);
2100
htaa6b99442016-04-12 17:29:172101 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2102
2103 std::string message = webrtc::SdpSerialize(jdesc_, false);
2104 size_t after_pt = message.find(" H264/90000");
2105 ASSERT_NE(after_pt, std::string::npos);
2106 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2107 ASSERT_NE(before_pt, std::string::npos);
2108 before_pt += strlen("a=rtpmap:");
2109 std::string pt = message.substr(before_pt, after_pt - before_pt);
2110 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2111 std::string to_find = "a=fmtp:" + pt + " ";
2112 size_t fmtp_pos = message.find(to_find);
2113 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2114 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2115 ASSERT_NE(std::string::npos, fmtp_endpos);
2116 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2117 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2118 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2119 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 18:02:142120 // Check that there are no spaces after semicolons.
2121 // https://bugs.webrtc.org/5793
2122 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 17:29:172123}
2124
henrike@webrtc.org28e20752013-07-10 00:45:362125TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2126 JsepSessionDescription jdesc(kDummyString);
2127 // Deserialize
2128 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2129 // Verify
2130 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2131}
2132
wu@webrtc.orgcecfd182013-10-30 05:18:122133TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2134 JsepSessionDescription jdesc(kDummyString);
2135 const char kSdpWithoutMline[] =
2136 "v=0\r\n"
2137 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2138 "s=-\r\n"
2139 "t=0 0\r\n"
2140 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2141 // Deserialize
2142 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2143 EXPECT_EQ(0u, jdesc.description()->contents().size());
2144}
2145
henrike@webrtc.org28e20752013-07-10 00:45:362146TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2147 JsepSessionDescription jdesc(kDummyString);
2148 std::string sdp_without_carriage_return = kSdpFullString;
2149 Replace("\r\n", "\n", &sdp_without_carriage_return);
2150 // Deserialize
2151 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2152 // Verify
2153 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2154}
2155
2156TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2157 // SessionDescription with desc but without candidates.
2158 JsepSessionDescription jdesc_no_candidates(kDummyString);
2159 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2160 kSessionId, kSessionVersion));
2161 JsepSessionDescription new_jdesc(kDummyString);
2162 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2163 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2164}
2165
2166TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2167 static const char kSdpNoRtpmapString[] =
2168 "v=0\r\n"
2169 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2170 "s=-\r\n"
2171 "t=0 0\r\n"
2172 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2173 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412174 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362175 // The rtpmap line for static payload codec is optional.
2176 "a=rtpmap:18 G729/16000\r\n"
2177 "a=rtpmap:103 ISAC/16000\r\n";
2178
2179 JsepSessionDescription jdesc(kDummyString);
2180 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2181 cricket::AudioContentDescription* audio =
2182 static_cast<AudioContentDescription*>(
2183 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2184 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 17:07:162185 // The codecs in the AudioContentDescription should be in the same order as
2186 // the payload types (<fmt>s) on the m= line.
2187 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2188 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
ossue1405ad2017-01-23 16:55:482189 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 0, 1));
henrike@webrtc.org28e20752013-07-10 00:45:362190 EXPECT_EQ(ref_codecs, audio->codecs());
2191}
2192
henrike@webrtc.org704bf9e2014-02-27 17:52:042193TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2194 static const char kSdpNoRtpmapString[] =
2195 "v=0\r\n"
2196 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2197 "s=-\r\n"
2198 "t=0 0\r\n"
2199 "m=audio 49232 RTP/AVP 18 103\r\n"
2200 "a=fmtp:18 annexb=yes\r\n"
2201 "a=rtpmap:103 ISAC/16000\r\n";
2202
2203 JsepSessionDescription jdesc(kDummyString);
2204 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2205 cricket::AudioContentDescription* audio =
2206 static_cast<AudioContentDescription*>(
2207 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2208
2209 cricket::AudioCodec g729 = audio->codecs()[0];
2210 EXPECT_EQ("G729", g729.name);
2211 EXPECT_EQ(8000, g729.clockrate);
2212 EXPECT_EQ(18, g729.id);
2213 cricket::CodecParameterMap::iterator found =
2214 g729.params.find("annexb");
2215 ASSERT_TRUE(found != g729.params.end());
2216 EXPECT_EQ(found->second, "yes");
2217
2218 cricket::AudioCodec isac = audio->codecs()[1];
2219 EXPECT_EQ("ISAC", isac.name);
2220 EXPECT_EQ(103, isac.id);
2221 EXPECT_EQ(16000, isac.clockrate);
2222}
2223
henrike@webrtc.org28e20752013-07-10 00:45:362224// Ensure that we can deserialize SDP with a=fingerprint properly.
2225TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2226 // Add a DTLS a=fingerprint attribute to our session description.
2227 AddFingerprint();
2228 JsepSessionDescription new_jdesc(kDummyString);
2229 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2230 jdesc_.session_id(),
2231 jdesc_.session_version()));
2232
2233 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2234 std::string sdp_with_fingerprint = kSdpString;
2235 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2236 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2237 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2238 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2239}
2240
2241TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2242 JsepSessionDescription jdesc_with_bundle(kDummyString);
2243 std::string sdp_with_bundle = kSdpFullString;
2244 InjectAfter(kSessionTime,
2245 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2246 &sdp_with_bundle);
2247 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2248 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2249 group.AddContentName(kAudioContentName);
2250 group.AddContentName(kVideoContentName);
2251 desc_.AddGroup(group);
2252 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2253 jdesc_.session_id(),
2254 jdesc_.session_version()));
2255 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2256}
2257
2258TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2259 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2260 std::string sdp_with_bandwidth = kSdpFullString;
2261 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2262 "b=AS:100\r\n",
2263 &sdp_with_bandwidth);
2264 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2265 "b=AS:50\r\n",
2266 &sdp_with_bandwidth);
2267 EXPECT_TRUE(
2268 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2269 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2270 GetFirstVideoContent(&desc_)->description);
2271 vcd->set_bandwidth(100 * 1000);
2272 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2273 GetFirstAudioContent(&desc_)->description);
2274 acd->set_bandwidth(50 * 1000);
2275 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2276 jdesc_.session_id(),
2277 jdesc_.session_version()));
2278 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2279}
2280
2281TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2282 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2283 std::string sdp_with_ice_options = kSdpFullString;
2284 InjectAfter(kSessionTime,
2285 "a=ice-options:iceoption3\r\n",
2286 &sdp_with_ice_options);
2287 InjectAfter(kAttributeIcePwdVoice,
2288 "a=ice-options:iceoption1\r\n",
2289 &sdp_with_ice_options);
2290 InjectAfter(kAttributeIcePwdVideo,
2291 "a=ice-options:iceoption2\r\n",
2292 &sdp_with_ice_options);
2293 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2294 std::vector<std::string> transport_options;
2295 transport_options.push_back(kIceOption3);
2296 transport_options.push_back(kIceOption1);
2297 AddIceOptions(kAudioContentName, transport_options);
2298 transport_options.clear();
2299 transport_options.push_back(kIceOption3);
2300 transport_options.push_back(kIceOption2);
2301 AddIceOptions(kVideoContentName, transport_options);
2302 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2303 jdesc_.session_id(),
2304 jdesc_.session_version()));
2305 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2306}
2307
2308TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2309 // Remove the original ice-ufrag and ice-pwd
2310 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2311 std::string sdp_with_ufrag_pwd = kSdpFullString;
2312 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2313 // Add session level ufrag and pwd
2314 InjectAfter(kSessionTime,
2315 "a=ice-pwd:session+level+icepwd\r\n"
2316 "a=ice-ufrag:session+level+iceufrag\r\n",
2317 &sdp_with_ufrag_pwd);
2318 // Add media level ufrag and pwd for audio
2319 InjectAfter("a=mid:audio_content_name\r\n",
2320 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2321 &sdp_with_ufrag_pwd);
2322 // Update the candidate ufrag and pwd to the expected ones.
2323 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2324 "media+level+iceufrag", "media+level+icepwd"));
2325 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2326 "session+level+iceufrag", "session+level+icepwd"));
2327 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2328 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2329}
2330
henrike@webrtc.org28e20752013-07-10 00:45:362331TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2332 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2333}
2334
2335TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2336 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2337}
2338
2339TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2340 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2341}
2342
2343TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2344 EXPECT_TRUE(TestDeserializeRejected(true, false));
2345}
2346
2347TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2348 EXPECT_TRUE(TestDeserializeRejected(false, true));
2349}
2350
2351TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2352 EXPECT_TRUE(TestDeserializeRejected(true, true));
2353}
2354
2355// Tests that we can still handle the sdp uses mslabel and label instead of
2356// msid for backward compatibility.
2357TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 20:14:452358 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:362359 JsepSessionDescription jdesc(kDummyString);
2360 std::string sdp_without_msid = kSdpFullString;
2361 Replace("msid", "xmsid", &sdp_without_msid);
2362 // Deserialize
2363 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2364 // Verify
2365 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2366}
2367
2368TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2369 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2370
2371 std::string sdp = kSdpOneCandidate;
2372 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2373 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2374 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2375 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 23:07:482376 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:362377
2378 // Candidate line without generation extension.
2379 sdp = kSdpOneCandidate;
2380 Replace(" generation 2", "", &sdp);
2381 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2382 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2383 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2384 Candidate expected = jcandidate_->candidate();
2385 expected.set_generation(0);
2386 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2387
honghaiza0c44ea2016-03-23 23:07:482388 // Candidate with network id and/or cost.
2389 sdp = kSdpOneCandidate;
2390 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2391 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2392 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2393 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2394 expected = jcandidate_->candidate();
2395 expected.set_network_id(2);
2396 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2397 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2398 // Add network cost
2399 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2400 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2401 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2402 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2403
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202404 sdp = kSdpTcpActiveCandidate;
2405 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2406 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:072407 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312408 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2409 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2410 kCandidateFoundation1);
kwibergd1fe2812016-04-27 13:47:292411 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2412 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202413 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2414 jcandidate_template->candidate()));
2415 sdp = kSdpTcpPassiveCandidate;
2416 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2417 sdp = kSdpTcpSOCandidate;
2418 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362419}
2420
2421// This test verifies the deserialization of candidate-attribute
2422// as per RFC 5245. Candiate-attribute will be of the format
2423// candidate:<blah>. This format will be used when candidates
2424// are trickled.
2425TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2426 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2427
2428 std::string candidate_attribute = kRawCandidate;
2429 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2430 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2431 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2432 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2433 EXPECT_EQ(2u, jcandidate.candidate().generation());
2434
2435 // Candidate line without generation extension.
2436 candidate_attribute = kRawCandidate;
2437 Replace(" generation 2", "", &candidate_attribute);
2438 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2439 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2440 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2441 Candidate expected = jcandidate_->candidate();
2442 expected.set_generation(0);
2443 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2444
2445 // Candidate line without candidate:
2446 candidate_attribute = kRawCandidate;
2447 Replace("candidate:", "", &candidate_attribute);
2448 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2449
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152450 // Candidate line with IPV6 address.
2451 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2452}
2453
2454// This test verifies that the deserialization of an invalid candidate string
2455// fails.
2456TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2457 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2458
2459 std::string candidate_attribute = kRawCandidate;
2460 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:362461 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152462
2463 candidate_attribute = kSdpOneCandidate;
2464 candidate_attribute.replace(0, 1, "x");
2465 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2466
2467 candidate_attribute = kRawCandidate;
2468 candidate_attribute.append("\r\n");
2469 candidate_attribute.append(kRawCandidate);
2470 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2471
2472 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362473}
2474
2475TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2476 AddRtpDataChannel();
2477 JsepSessionDescription jdesc(kDummyString);
2478 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2479
2480 std::string sdp_with_data = kSdpString;
2481 sdp_with_data.append(kSdpRtpDataChannelString);
2482 JsepSessionDescription jdesc_output(kDummyString);
2483
2484 // Deserialize
2485 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2486 // Verify
2487 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2488}
2489
2490TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
zstein4b2e0822017-02-18 03:48:382491 bool use_sctpmap = true;
2492 AddSctpDataChannel(use_sctpmap);
henrike@webrtc.org28e20752013-07-10 00:45:362493 JsepSessionDescription jdesc(kDummyString);
2494 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2495
2496 std::string sdp_with_data = kSdpString;
2497 sdp_with_data.append(kSdpSctpDataChannelString);
2498 JsepSessionDescription jdesc_output(kDummyString);
2499
lally@webrtc.org36300852015-02-24 20:19:352500 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2501 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2502 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2503
2504 // Verify with UDP/DTLS/SCTP.
2505 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2506 strlen(kDtlsSctp), kUdpDtlsSctp);
2507 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2508 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2509
2510 // Verify with TCP/DTLS/SCTP.
2511 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2512 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:362513 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2514 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2515}
2516
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562517TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
zstein4b2e0822017-02-18 03:48:382518 bool use_sctpmap = false;
2519 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562520 JsepSessionDescription jdesc(kDummyString);
2521 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2522
2523 std::string sdp_with_data = kSdpString;
2524 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2525 JsepSessionDescription jdesc_output(kDummyString);
2526
lally@webrtc.org36300852015-02-24 20:19:352527 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562528 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2529 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562530
lally@webrtc.org36300852015-02-24 20:19:352531 // Verify with UDP/DTLS/SCTP.
2532 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2533 strlen(kDtlsSctp), kUdpDtlsSctp);
2534 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2535 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:262536
lally@webrtc.org36300852015-02-24 20:19:352537 // Verify with TCP/DTLS/SCTP.
2538 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2539 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:262540 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2541 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2542}
2543
lally69f57602015-10-08 17:15:042544TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
zstein4b2e0822017-02-18 03:48:382545 bool use_sctpmap = false;
2546 AddSctpDataChannel(use_sctpmap);
lally69f57602015-10-08 17:15:042547 JsepSessionDescription jdesc(kDummyString);
2548 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2549
2550 std::string sdp_with_data = kSdpString;
2551 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2552 JsepSessionDescription jdesc_output(kDummyString);
2553
2554 // Verify with DTLS/SCTP.
2555 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2556 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2557
2558 // Verify with UDP/DTLS/SCTP.
2559 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2560 strlen(kDtlsSctp), kUdpDtlsSctp);
2561 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2562 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2563
2564 // Verify with TCP/DTLS/SCTP.
2565 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2566 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2567 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2568 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2569}
2570
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562571// Test to check the behaviour if sctp-port is specified
2572// on the m= line and in a=sctp-port.
2573TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
zstein4b2e0822017-02-18 03:48:382574 bool use_sctpmap = true;
2575 AddSctpDataChannel(use_sctpmap);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562576 JsepSessionDescription jdesc(kDummyString);
2577 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2578
2579 std::string sdp_with_data = kSdpString;
2580 // Append m= attributes
2581 sdp_with_data.append(kSdpSctpDataChannelString);
2582 // Append a=sctp-port attribute
2583 sdp_with_data.append("a=sctp-port 5000\r\n");
2584 JsepSessionDescription jdesc_output(kDummyString);
2585
2586 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2587}
2588
henrike@webrtc.org571df2d2014-02-19 23:04:262589// For crbug/344475.
2590TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2591 std::string sdp_with_data = kSdpString;
2592 sdp_with_data.append(kSdpSctpDataChannelString);
2593 // Remove the "\n" at the end.
2594 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2595 JsepSessionDescription jdesc_output(kDummyString);
2596
2597 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2598 // No crash is a pass.
2599}
2600
Steve Anton36b29d12017-10-30 16:57:422601void MutateJsepSctpPort(JsepSessionDescription* jdesc,
zstein4b2e0822017-02-18 03:48:382602 const SessionDescription& desc) {
wu@webrtc.org78187522013-10-07 23:32:022603 // take our pre-built session description and change the SCTP port.
zstein4b2e0822017-02-18 03:48:382604 cricket::SessionDescription* mutant = desc.Copy();
wu@webrtc.org78187522013-10-07 23:32:022605 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2606 mutant->GetContentDescriptionByName(kDataContentName));
2607 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:222608 EXPECT_EQ(1U, codecs.size());
solenberg9fa49752016-10-08 20:02:442609 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:022610 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:302611 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:022612
2613 // note: mutant's owned by jdesc now.
Steve Anton36b29d12017-10-30 16:57:422614 ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion));
wu@webrtc.org78187522013-10-07 23:32:022615 mutant = NULL;
zstein4b2e0822017-02-18 03:48:382616}
2617
2618TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndUnusualPort) {
2619 bool use_sctpmap = true;
2620 AddSctpDataChannel(use_sctpmap);
2621
2622 // First setup the expected JsepSessionDescription.
2623 JsepSessionDescription jdesc(kDummyString);
Steve Anton36b29d12017-10-30 16:57:422624 MutateJsepSctpPort(&jdesc, desc_);
wu@webrtc.org78187522013-10-07 23:32:022625
jiayl@webrtc.org9c16c392014-05-01 18:30:302626 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:022627 std::string sdp_with_data = kSdpString;
2628 sdp_with_data.append(kSdpSctpDataChannelString);
zstein4b2e0822017-02-18 03:48:382629 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2630 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2631 &sdp_with_data);
wu@webrtc.org78187522013-10-07 23:32:022632 JsepSessionDescription jdesc_output(kDummyString);
2633
2634 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2635 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
zstein4b2e0822017-02-18 03:48:382636}
2637
2638TEST_F(WebRtcSdpTest,
2639 DeserializeSdpWithSctpDataChannelAndUnusualPortInAttribute) {
2640 bool use_sctpmap = false;
2641 AddSctpDataChannel(use_sctpmap);
2642
2643 JsepSessionDescription jdesc(kDummyString);
Steve Anton36b29d12017-10-30 16:57:422644 MutateJsepSctpPort(&jdesc, desc_);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562645
2646 // We need to test the deserialized JsepSessionDescription from
2647 // kSdpSctpDataChannelStringWithSctpPort for
2648 // draft-ietf-mmusic-sctp-sdp-07
2649 // a=sctp-port
zstein4b2e0822017-02-18 03:48:382650 std::string sdp_with_data = kSdpString;
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562651 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
zstein4b2e0822017-02-18 03:48:382652 rtc::replace_substrs(kDefaultSctpPortStr, strlen(kDefaultSctpPortStr),
2653 kUnusualSctpPortStr, strlen(kUnusualSctpPortStr),
2654 &sdp_with_data);
2655 JsepSessionDescription jdesc_output(kDummyString);
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562656
2657 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2658 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:022659}
2660
wu@webrtc.orgcadf9042013-08-30 21:24:162661TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 22:31:252662 // We want to test that deserializing data content limits bandwidth
2663 // settings (it should never be greater than the default).
2664 // This should prevent someone from using unlimited data bandwidth through
2665 // JS and "breaking the Internet".
2666 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:162667 std::string sdp_with_bandwidth = kSdpString;
2668 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2669 InjectAfter("a=mid:data_content_name\r\n",
2670 "b=AS:100\r\n",
2671 &sdp_with_bandwidth);
2672 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2673
Peter Thatcherc0c3a862015-06-24 22:31:252674 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2675}
2676
2677TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
zstein4b2e0822017-02-18 03:48:382678 bool use_sctpmap = true;
2679 AddSctpDataChannel(use_sctpmap);
Peter Thatcherc0c3a862015-06-24 22:31:252680 JsepSessionDescription jdesc(kDummyString);
2681 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2682 GetFirstDataContent(&desc_)->description);
2683 dcd->set_bandwidth(100 * 1000);
2684 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2685
2686 std::string sdp_with_bandwidth = kSdpString;
2687 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
2688 InjectAfter("a=mid:data_content_name\r\n",
2689 "b=AS:100\r\n",
2690 &sdp_with_bandwidth);
2691 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2692
2693 // SCTP has congestion control, so we shouldn't limit the bandwidth
2694 // as we do for RTP.
2695 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:162696 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2697}
2698
jbauch5869f502017-06-29 19:31:362699class WebRtcSdpExtmapTest
2700 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2701};
2702
2703TEST_P(WebRtcSdpExtmapTest,
2704 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2705 bool encrypted = GetParam();
2706 TestDeserializeExtmap(true, false, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:362707}
2708
jbauch5869f502017-06-29 19:31:362709TEST_P(WebRtcSdpExtmapTest,
2710 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2711 bool encrypted = GetParam();
2712 TestDeserializeExtmap(false, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:362713}
2714
jbauch5869f502017-06-29 19:31:362715TEST_P(WebRtcSdpExtmapTest,
2716 DeserializeSessionDescriptionWithInvalidExtmap) {
2717 bool encrypted = GetParam();
2718 TestDeserializeExtmap(true, true, encrypted);
henrike@webrtc.org28e20752013-07-10 00:45:362719}
2720
jbauch5869f502017-06-29 19:31:362721INSTANTIATE_TEST_CASE_P(Encrypted,
2722 WebRtcSdpExtmapTest,
2723 ::testing::Values(false, true));
2724
sergeyu@chromium.org5bc25c42013-12-05 00:24:062725TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2726 JsepSessionDescription jdesc(kDummyString);
2727 std::string sdp = kSdpFullString;
2728 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2729 // Deserialize
2730 SdpParseError error;
2731 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-17 01:54:102732 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:062733 EXPECT_EQ(lastline, error.line);
2734 EXPECT_EQ("Invalid SDP line.", error.description);
2735}
2736
henrike@webrtc.org28e20752013-07-10 00:45:362737TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2738 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2739 std::string new_sdp = kSdpOneCandidate;
2740 Replace("udp", "unsupported_transport", &new_sdp);
2741 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2742 new_sdp = kSdpOneCandidate;
2743 Replace("udp", "uDP", &new_sdp);
2744 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2745 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2746 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2747 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2748}
2749
honghaiza54a0802015-12-17 02:37:232750TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:362751 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-17 02:37:232752 EXPECT_TRUE(
2753 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362754 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2755 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2756 Candidate ref_candidate = jcandidate_->candidate();
2757 ref_candidate.set_username("user_rtp");
2758 ref_candidate.set_password("password_rtp");
2759 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2760}
2761
henrike@webrtc.org704bf9e2014-02-27 17:52:042762TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2763 JsepSessionDescription jdesc(kDummyString);
2764
2765 // Deserialize
2766 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2767
2768 // Verify
2769 cricket::AudioContentDescription* audio =
2770 static_cast<AudioContentDescription*>(
2771 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2772 EXPECT_TRUE(audio->conference_mode());
2773
2774 cricket::VideoContentDescription* video =
2775 static_cast<VideoContentDescription*>(
2776 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2777 EXPECT_TRUE(video->conference_mode());
2778}
2779
deadbeefd45aea82017-09-16 08:24:292780TEST_F(WebRtcSdpTest, SerializeSdpWithConferenceFlag) {
2781 JsepSessionDescription jdesc(kDummyString);
2782
2783 // We tested deserialization already above, so just test that if we serialize
2784 // and deserialize the flag doesn't disappear.
2785 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2786 std::string reserialized = webrtc::SdpSerialize(jdesc, false);
2787 EXPECT_TRUE(SdpDeserialize(reserialized, &jdesc));
2788
2789 // Verify.
2790 cricket::AudioContentDescription* audio =
2791 static_cast<AudioContentDescription*>(
2792 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2793 EXPECT_TRUE(audio->conference_mode());
2794
2795 cricket::VideoContentDescription* video =
2796 static_cast<VideoContentDescription*>(
2797 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2798 EXPECT_TRUE(video->conference_mode());
2799}
2800
henrike@webrtc.org28e20752013-07-10 00:45:362801TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2802 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:512803 const char kSdpEmptyType[] = " =candidate";
2804 const char kSdpEqualAsPlus[] = "a+candidate";
2805 const char kSdpSpaceAfterEqual[] = "a= candidate";
2806 const char kSdpUpperType[] = "A=candidate";
2807 const char kSdpEmptyLine[] = "";
2808 const char kSdpMissingValue[] = "a=";
2809
2810 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:362811 "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
decurtis@webrtc.org8af11042015-01-07 19:15:512812 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:362813 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX";
decurtis@webrtc.org8af11042015-01-07 19:15:512814 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:362815 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB";
henrika@webrtc.orgaebb1ad2014-01-14 10:00:582816 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:512817 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:582818 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:362819
2820 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:092821 ExpectParseFailure("v=", kSdpDestroyer);
2822 ExpectParseFailure("o=", kSdpDestroyer);
2823 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362824 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:092825 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362826
2827 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:092828 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2829 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362830
2831 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:512832 ExpectParseFailure("a=candidate", kSdpEmptyType);
2833 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2834 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2835 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:362836
2837 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2838 // because it's orthogonal to what we are replacing and hence
2839 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:512840 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2841 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2842 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2843 ExpectParseFailure("a=sendrecv", kSdpMd5);
2844
2845 // Empty Line
2846 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2847 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:092848}
2849
2850TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2851 // ssrc
2852 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-17 01:54:102853 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:092854 // crypto
2855 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2856 // rtpmap
2857 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2858 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2859 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2860 // candidate
2861 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2862 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2863 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2864 ExpectParseFailure("rport 2346", "rport badvalue");
2865 ExpectParseFailure("rport 2346 generation 2",
2866 "rport 2346 generation badvalue");
2867 // m line
2868 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2869 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2870
2871 // bandwidth
2872 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2873 "b=AS:badvalue\r\n",
2874 "b=AS:badvalue");
2875 // rtcp-fb
2876 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2877 "a=rtcp-fb:badvalue nack\r\n",
2878 "a=rtcp-fb:badvalue nack");
2879 // extmap
2880 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2881 "a=extmap:badvalue http://example.com\r\n",
2882 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:362883}
2884
2885TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2886 JsepSessionDescription jdesc_output(kDummyString);
2887
2888 const char kSdpWithReorderedPlTypesString[] =
2889 "v=0\r\n"
2890 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2891 "s=-\r\n"
2892 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:222893 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:362894 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2895 // in the map.
2896 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412897 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:362898
2899 // Deserialize
2900 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2901
2902 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2903 ASSERT_TRUE(ac != NULL);
2904 const AudioContentDescription* acd =
2905 static_cast<const AudioContentDescription*>(ac->description);
2906 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412907 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2908 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:362909 EXPECT_EQ(104, acd->codecs()[0].id);
2910}
2911
2912TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2913 JsepSessionDescription jdesc_output(kDummyString);
2914 CodecParams params;
2915 params.max_ptime = 40;
2916 params.ptime = 30;
2917 params.min_ptime = 10;
2918 params.sprop_stereo = 1;
2919 params.stereo = 1;
2920 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:592921 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:362922 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-17 01:54:102923 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362924}
2925
2926TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2927 const bool kUseWildcard = false;
2928 JsepSessionDescription jdesc_output(kDummyString);
2929 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-17 01:54:102930 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362931}
2932
2933TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2934 const bool kUseWildcard = true;
2935 JsepSessionDescription jdesc_output(kDummyString);
2936 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-17 01:54:102937 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362938}
2939
2940TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2941 JsepSessionDescription jdesc_output(kDummyString);
2942
2943 const char kSdpWithFmtpString[] =
2944 "v=0\r\n"
2945 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2946 "s=-\r\n"
2947 "t=0 0\r\n"
2948 "m=video 3457 RTP/SAVPF 120\r\n"
2949 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:232950 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2951
2952 // Deserialize
2953 SdpParseError error;
Donald Curtis144d0182015-05-15 20:14:242954 EXPECT_TRUE(
2955 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 16:21:232956
2957 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2958 ASSERT_TRUE(vc != NULL);
2959 const VideoContentDescription* vcd =
2960 static_cast<const VideoContentDescription*>(vc->description);
2961 ASSERT_FALSE(vcd->codecs().empty());
2962 cricket::VideoCodec vp8 = vcd->codecs()[0];
2963 EXPECT_EQ("VP8", vp8.name);
2964 EXPECT_EQ(120, vp8.id);
2965 cricket::CodecParameterMap::iterator found =
2966 vp8.params.find("x-google-min-bitrate");
2967 ASSERT_TRUE(found != vp8.params.end());
2968 EXPECT_EQ(found->second, "10");
2969 found = vp8.params.find("x-google-max-quantization");
2970 ASSERT_TRUE(found != vp8.params.end());
2971 EXPECT_EQ(found->second, "40");
2972}
2973
johan2d8d23e2016-06-03 08:22:422974TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) {
2975 JsepSessionDescription jdesc_output(kDummyString);
2976
2977 const char kSdpWithFmtpString[] =
2978 "v=0\r\n"
2979 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2980 "s=-\r\n"
2981 "t=0 0\r\n"
2982 "m=video 49170 RTP/AVP 98\r\n"
2983 "a=rtpmap:98 H264/90000\r\n"
2984 "a=fmtp:98 profile-level-id=42A01E; "
2985 "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n";
2986
2987 // Deserialize.
2988 SdpParseError error;
2989 EXPECT_TRUE(
2990 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
2991
2992 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2993 ASSERT_TRUE(vc != NULL);
2994 const VideoContentDescription* vcd =
2995 static_cast<const VideoContentDescription*>(vc->description);
2996 ASSERT_TRUE(vcd != NULL);
2997 ASSERT_FALSE(vcd->codecs().empty());
2998 cricket::VideoCodec h264 = vcd->codecs()[0];
2999 EXPECT_EQ("H264", h264.name);
3000 EXPECT_EQ(98, h264.id);
3001 cricket::CodecParameterMap::const_iterator found =
3002 h264.params.find("profile-level-id");
3003 ASSERT_TRUE(found != h264.params.end());
3004 EXPECT_EQ(found->second, "42A01E");
3005 found = h264.params.find("sprop-parameter-sets");
3006 ASSERT_TRUE(found != h264.params.end());
3007 EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA==");
3008}
3009
Donald Curtis0e07f922015-05-15 16:21:233010TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
3011 JsepSessionDescription jdesc_output(kDummyString);
3012
3013 const char kSdpWithFmtpString[] =
3014 "v=0\r\n"
3015 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3016 "s=-\r\n"
3017 "t=0 0\r\n"
3018 "m=video 3457 RTP/SAVPF 120\r\n"
3019 "a=rtpmap:120 VP8/90000\r\n"
3020 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:363021
3022 // Deserialize
3023 SdpParseError error;
3024 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
3025 &error));
3026
3027 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3028 ASSERT_TRUE(vc != NULL);
3029 const VideoContentDescription* vcd =
3030 static_cast<const VideoContentDescription*>(vc->description);
3031 ASSERT_FALSE(vcd->codecs().empty());
3032 cricket::VideoCodec vp8 = vcd->codecs()[0];
3033 EXPECT_EQ("VP8", vp8.name);
3034 EXPECT_EQ(120, vp8.id);
3035 cricket::CodecParameterMap::iterator found =
3036 vp8.params.find("x-google-min-bitrate");
3037 ASSERT_TRUE(found != vp8.params.end());
3038 EXPECT_EQ(found->second, "10");
3039 found = vp8.params.find("x-google-max-quantization");
3040 ASSERT_TRUE(found != vp8.params.end());
3041 EXPECT_EQ(found->second, "40");
3042}
3043
ossuaa4b0772017-01-30 15:41:183044TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithUnknownParameter) {
3045 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3046 GetFirstAudioContent(&desc_)->description);
3047
3048 cricket::AudioCodecs codecs = acd->codecs();
3049 codecs[0].params["unknown-future-parameter"] = "SomeFutureValue";
3050 acd->set_codecs(codecs);
3051
3052 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3053 jdesc_.session_id(),
3054 jdesc_.session_version()));
3055 std::string message = webrtc::SdpSerialize(jdesc_, false);
3056 std::string sdp_with_fmtp = kSdpFullString;
3057 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3058 "a=fmtp:111 unknown-future-parameter=SomeFutureValue\r\n",
3059 &sdp_with_fmtp);
3060 EXPECT_EQ(sdp_with_fmtp, message);
3061}
3062
3063TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithKnownFmtpParameter) {
3064 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3065 GetFirstAudioContent(&desc_)->description);
3066
3067 cricket::AudioCodecs codecs = acd->codecs();
3068 codecs[0].params["stereo"] = "1";
3069 acd->set_codecs(codecs);
3070
3071 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3072 jdesc_.session_id(),
3073 jdesc_.session_version()));
3074 std::string message = webrtc::SdpSerialize(jdesc_, false);
3075 std::string sdp_with_fmtp = kSdpFullString;
3076 InjectAfter("a=rtpmap:111 opus/48000/2\r\n",
3077 "a=fmtp:111 stereo=1\r\n",
3078 &sdp_with_fmtp);
3079 EXPECT_EQ(sdp_with_fmtp, message);
3080}
3081
3082TEST_F(WebRtcSdpTest, SerializeAudioFmtpWithPTimeAndMaxPTime) {
3083 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
3084 GetFirstAudioContent(&desc_)->description);
3085
3086 cricket::AudioCodecs codecs = acd->codecs();
3087 codecs[0].params["ptime"] = "20";
3088 codecs[0].params["maxptime"] = "120";
3089 acd->set_codecs(codecs);
3090
3091 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3092 jdesc_.session_id(),
3093 jdesc_.session_version()));
3094 std::string message = webrtc::SdpSerialize(jdesc_, false);
3095 std::string sdp_with_fmtp = kSdpFullString;
3096 InjectAfter("a=rtpmap:104 ISAC/32000\r\n",
3097 "a=maxptime:120\r\n" // No comma here. String merging!
3098 "a=ptime:20\r\n",
3099 &sdp_with_fmtp);
3100 EXPECT_EQ(sdp_with_fmtp, message);
3101}
3102
henrike@webrtc.org28e20752013-07-10 00:45:363103TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
3104 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
3105 GetFirstVideoContent(&desc_)->description);
3106
3107 cricket::VideoCodecs codecs = vcd->codecs();
3108 codecs[0].params["x-google-min-bitrate"] = "10";
3109 vcd->set_codecs(codecs);
3110
3111 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3112 jdesc_.session_id(),
3113 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:103114 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:363115 std::string sdp_with_fmtp = kSdpFullString;
3116 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
3117 "a=fmtp:120 x-google-min-bitrate=10\r\n",
3118 &sdp_with_fmtp);
3119 EXPECT_EQ(sdp_with_fmtp, message);
3120}
3121
3122TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
3123 JsepSessionDescription jdesc_with_icelite(kDummyString);
3124 std::string sdp_with_icelite = kSdpFullString;
3125 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3126 cricket::SessionDescription* desc = jdesc_with_icelite.description();
3127 const cricket::TransportInfo* tinfo1 =
3128 desc->GetTransportInfoByName("audio_content_name");
3129 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
3130 const cricket::TransportInfo* tinfo2 =
3131 desc->GetTransportInfoByName("video_content_name");
3132 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
3133 InjectAfter(kSessionTime,
3134 "a=ice-lite\r\n",
3135 &sdp_with_icelite);
3136 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
3137 desc = jdesc_with_icelite.description();
3138 const cricket::TransportInfo* atinfo =
3139 desc->GetTransportInfoByName("audio_content_name");
3140 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
3141 const cricket::TransportInfo* vtinfo =
3142 desc->GetTransportInfoByName("video_content_name");
3143 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
3144}
3145
3146// Verifies that the candidates in the input SDP are parsed and serialized
3147// correctly in the output SDP.
3148TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3149 std::string sdp_with_data = kSdpString;
3150 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3151 JsepSessionDescription jdesc_output(kDummyString);
3152
3153 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-17 01:54:103154 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:363155}
sergeyu@chromium.org0be6aa02013-08-23 23:21:253156
3157TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3158 AddFingerprint();
3159 TransportInfo audio_transport_info =
3160 *(desc_.GetTransportInfoByName(kAudioContentName));
3161 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3162 audio_transport_info.description.connection_role);
3163 audio_transport_info.description.connection_role =
3164 cricket::CONNECTIONROLE_ACTIVE;
3165
3166 TransportInfo video_transport_info =
3167 *(desc_.GetTransportInfoByName(kVideoContentName));
3168 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3169 video_transport_info.description.connection_role);
3170 video_transport_info.description.connection_role =
3171 cricket::CONNECTIONROLE_ACTIVE;
3172
3173 desc_.RemoveTransportInfoByName(kAudioContentName);
3174 desc_.RemoveTransportInfoByName(kVideoContentName);
3175
3176 desc_.AddTransportInfo(audio_transport_info);
3177 desc_.AddTransportInfo(video_transport_info);
3178
3179 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3180 jdesc_.session_id(),
3181 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:103182 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253183 std::string sdp_with_dtlssetup = kSdpFullString;
3184
3185 // Fingerprint attribute is necessary to add DTLS setup attribute.
3186 InjectAfter(kAttributeIcePwdVoice,
3187 kFingerprint, &sdp_with_dtlssetup);
3188 InjectAfter(kAttributeIcePwdVideo,
3189 kFingerprint, &sdp_with_dtlssetup);
3190 // Now adding |setup| attribute.
3191 InjectAfter(kFingerprint,
3192 "a=setup:active\r\n", &sdp_with_dtlssetup);
3193 EXPECT_EQ(sdp_with_dtlssetup, message);
3194}
3195
3196TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3197 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3198 std::string sdp_with_dtlssetup = kSdpFullString;
3199 InjectAfter(kSessionTime,
3200 "a=setup:actpass\r\n",
3201 &sdp_with_dtlssetup);
3202 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3203 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3204 const cricket::TransportInfo* atinfo =
3205 desc->GetTransportInfoByName("audio_content_name");
3206 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3207 atinfo->description.connection_role);
3208 const cricket::TransportInfo* vtinfo =
3209 desc->GetTransportInfoByName("video_content_name");
3210 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3211 vtinfo->description.connection_role);
3212}
jiayl@webrtc.orge7d47a12014-08-05 19:19:053213
3214// Verifies that the order of the serialized m-lines follows the order of the
3215// ContentInfo in SessionDescription, and vise versa for deserialization.
3216TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3217 JsepSessionDescription jdesc(kDummyString);
3218 const std::string media_content_sdps[3] = {
3219 kSdpAudioString,
3220 kSdpVideoString,
3221 kSdpSctpDataChannelString
3222 };
3223 const cricket::MediaType media_types[3] = {
3224 cricket::MEDIA_TYPE_AUDIO,
3225 cricket::MEDIA_TYPE_VIDEO,
3226 cricket::MEDIA_TYPE_DATA
3227 };
3228
3229 // Verifies all 6 permutations.
3230 for (size_t i = 0; i < 6; ++i) {
3231 size_t media_content_in_sdp[3];
3232 // The index of the first media content.
3233 media_content_in_sdp[0] = i / 2;
3234 // The index of the second media content.
3235 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3236 // The index of the third media content.
3237 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3238
3239 std::string sdp_string = kSdpSessionString;
3240 for (size_t i = 0; i < 3; ++i)
3241 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3242
3243 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3244 cricket::SessionDescription* desc = jdesc.description();
3245 EXPECT_EQ(3u, desc->contents().size());
3246
3247 for (size_t i = 0; i < 3; ++i) {
3248 const cricket::MediaContentDescription* mdesc =
3249 static_cast<const cricket::MediaContentDescription*>(
3250 desc->contents()[i].description);
3251 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3252 }
3253
deadbeef9d3584c2016-02-17 01:54:103254 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:053255 EXPECT_EQ(sdp_string, serialized_sdp);
3256 }
3257}
deadbeef9d3584c2016-02-17 01:54:103258
deadbeef25ed4352016-12-13 02:37:363259TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) {
3260 MakeBundleOnlyDescription();
3261 JsepSessionDescription deserialized_description(kDummyString);
deadbeef12771a12017-01-03 21:53:473262 ASSERT_TRUE(
deadbeef25ed4352016-12-13 02:37:363263 SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description));
3264 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3265}
3266
deadbeef12771a12017-01-03 21:53:473267// The semantics of "a=bundle-only" are only defined when it's used in
3268// combination with a 0 port on the m= line. We should ignore it if used with a
3269// nonzero port.
3270TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) {
3271 // Make the base bundle-only description but unset the bundle-only flag.
3272 MakeBundleOnlyDescription();
3273 jdesc_.description()->contents()[1].bundle_only = false;
3274
3275 std::string modified_sdp = kBundleOnlySdpFullString;
3276 Replace("m=video 0", "m=video 9", &modified_sdp);
3277 JsepSessionDescription deserialized_description(kDummyString);
3278 ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description));
3279 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
deadbeef25ed4352016-12-13 02:37:363280}
3281
3282TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) {
3283 MakeBundleOnlyDescription();
3284 TestSerialize(jdesc_, false);
3285}
3286
deadbeef9d3584c2016-02-17 01:54:103287TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3288 MakePlanBDescription();
3289
3290 JsepSessionDescription deserialized_description(kDummyString);
3291 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3292
3293 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3294}
3295
3296TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3297 MakePlanBDescription();
3298 TestSerialize(jdesc_, false);
3299}
3300
Taylor Brandstetter5de6b752016-03-10 01:02:303301// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3302// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3303// some extent). If we parse this, the Plan B msid attribute (which is more
3304// specific, since it's at the SSRC level) should take priority.
3305TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3306 MakePlanBDescription();
3307
3308 JsepSessionDescription deserialized_description(kDummyString);
3309 EXPECT_TRUE(
3310 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3311
3312 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3313}
3314
deadbeef9d3584c2016-02-17 01:54:103315TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3316 MakeUnifiedPlanDescription();
3317
3318 JsepSessionDescription deserialized_description(kDummyString);
3319 EXPECT_TRUE(
3320 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3321
3322 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3323}
3324
3325TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3326 MakeUnifiedPlanDescription();
3327 TestSerialize(jdesc_, true);
3328}
deadbeef7e146cb2016-09-28 17:04:343329
3330// Regression test for heap overflow bug:
3331// https://bugs.chromium.org/p/chromium/issues/detail?id=647916
3332TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) {
deadbeef7e146cb2016-09-28 17:04:343333 // The issue occurs when the sctp-port attribute is found in a video
3334 // description. The actual heap overflow occurs when parsing the fmtp line.
deadbeef7bcdb692017-01-20 20:43:583335 static const char kSdpWithSctpPortInVideoDescription[] =
deadbeef7e146cb2016-09-28 17:04:343336 "v=0\r\n"
3337 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3338 "s=-\r\n"
3339 "t=0 0\r\n"
3340 "m=video 9 UDP/DTLS/SCTP 120\r\n"
3341 "a=sctp-port 5000\r\n"
3342 "a=fmtp:108 foo=10\r\n";
3343
3344 ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription),
3345 "sctp-port");
3346}
deadbeefb2362572016-12-14 00:37:063347
3348// Regression test for integer overflow bug:
3349// https://bugs.chromium.org/p/chromium/issues/detail?id=648071
3350TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) {
deadbeefb2362572016-12-14 00:37:063351 // Bandwidth attribute is the max signed 32-bit int, which will get
3352 // multiplied by 1000 and cause int overflow if not careful.
deadbeef7bcdb692017-01-20 20:43:583353 static const char kSdpWithLargeBandwidth[] =
deadbeefb2362572016-12-14 00:37:063354 "v=0\r\n"
3355 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3356 "s=-\r\n"
3357 "t=0 0\r\n"
3358 "m=video 3457 RTP/SAVPF 120\r\n"
3359 "b=AS:2147483647\r\n"
3360 "foo=fail\r\n";
3361
3362 ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail");
3363}
deadbeef7bcdb692017-01-20 20:43:583364
deadbeefbc88c6b2017-08-02 18:26:343365// Similar to the above, except that negative values are illegal, not just
3366// error-prone as large values are.
3367// https://bugs.chromium.org/p/chromium/issues/detail?id=675361
3368TEST_F(WebRtcSdpTest, DeserializingNegativeBandwidthLimitFails) {
3369 static const char kSdpWithNegativeBandwidth[] =
3370 "v=0\r\n"
3371 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3372 "s=-\r\n"
3373 "t=0 0\r\n"
3374 "m=video 3457 RTP/SAVPF 120\r\n"
3375 "b=AS:-1000\r\n";
3376
3377 ExpectParseFailure(std::string(kSdpWithNegativeBandwidth), "b=AS:-1000");
3378}
3379
deadbeef3e8016e2017-08-04 00:49:303380// An exception to the above rule: a value of -1 for b=AS should just be
3381// ignored, resulting in "kAutoBandwidth" in the deserialized object.
3382// Applications historically may be using "b=AS:-1" to mean "no bandwidth
3383// limit", but this is now what ommitting the attribute entirely will do, so
3384// ignoring it will have the intended effect.
3385TEST_F(WebRtcSdpTest, BandwidthLimitOfNegativeOneIgnored) {
3386 static const char kSdpWithBandwidthOfNegativeOne[] =
3387 "v=0\r\n"
3388 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3389 "s=-\r\n"
3390 "t=0 0\r\n"
3391 "m=video 3457 RTP/SAVPF 120\r\n"
3392 "b=AS:-1\r\n";
3393
3394 JsepSessionDescription jdesc_output(kDummyString);
3395 EXPECT_TRUE(SdpDeserialize(kSdpWithBandwidthOfNegativeOne, &jdesc_output));
3396 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
3397 ASSERT_NE(nullptr, vc);
3398 const VideoContentDescription* vcd =
3399 static_cast<const VideoContentDescription*>(vc->description);
3400 EXPECT_EQ(cricket::kAutoBandwidth, vcd->bandwidth());
3401}
3402
deadbeef7bcdb692017-01-20 20:43:583403// Test that "ufrag"/"pwd" in the candidate line itself are ignored, and only
3404// the "a=ice-ufrag"/"a=ice-pwd" attributes are used.
3405// Regression test for:
3406// https://bugs.chromium.org/p/chromium/issues/detail?id=681286
3407TEST_F(WebRtcSdpTest, IceCredentialsInCandidateStringIgnored) {
3408 // Important piece is "ufrag foo pwd bar".
3409 static const char kSdpWithIceCredentialsInCandidateString[] =
3410 "v=0\r\n"
3411 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3412 "s=-\r\n"
3413 "t=0 0\r\n"
3414 "m=audio 9 RTP/SAVPF 111\r\n"
3415 "c=IN IP4 0.0.0.0\r\n"
3416 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3417 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3418 "a=rtpmap:111 opus/48000/2\r\n"
3419 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
3420 "generation 2 ufrag foo pwd bar\r\n";
3421
3422 JsepSessionDescription jdesc_output(kDummyString);
3423 EXPECT_TRUE(
3424 SdpDeserialize(kSdpWithIceCredentialsInCandidateString, &jdesc_output));
3425 const IceCandidateCollection* candidates = jdesc_output.candidates(0);
3426 ASSERT_NE(nullptr, candidates);
3427 ASSERT_EQ(1, candidates->count());
3428 cricket::Candidate c = candidates->at(0)->candidate();
3429 EXPECT_EQ("ufrag_voice", c.username());
3430 EXPECT_EQ("pwd_voice", c.password());
3431}
deadbeef90f1e1e2017-02-10 20:35:053432
3433// Test that SDP with an invalid port number in "a=candidate" lines is
3434// rejected, without crashing.
3435// Regression test for:
3436// https://bugs.chromium.org/p/chromium/issues/detail?id=677029
3437TEST_F(WebRtcSdpTest, DeserializeInvalidPortInCandidateAttribute) {
3438 static const char kSdpWithInvalidCandidatePort[] =
3439 "v=0\r\n"
3440 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3441 "s=-\r\n"
3442 "t=0 0\r\n"
3443 "m=audio 9 RTP/SAVPF 111\r\n"
3444 "c=IN IP4 0.0.0.0\r\n"
3445 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
3446 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
3447 "a=rtpmap:111 opus/48000/2\r\n"
3448 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 12345678 typ host "
3449 "generation 2 raddr 192.168.1.1 rport 87654321\r\n";
3450
3451 JsepSessionDescription jdesc_output(kDummyString);
3452 EXPECT_FALSE(SdpDeserialize(kSdpWithInvalidCandidatePort, &jdesc_output));
3453}
deadbeefa4549d62017-02-11 01:26:223454
3455// Test that "a=msid" with a missing track ID is rejected and doesn't crash.
3456// Regression test for:
3457// https://bugs.chromium.org/p/chromium/issues/detail?id=686405
3458TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) {
3459 static const char kSdpWithMissingTrackId[] =
3460 "v=0\r\n"
3461 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3462 "s=-\r\n"
3463 "t=0 0\r\n"
3464 "m=audio 9 RTP/SAVPF 111\r\n"
3465 "c=IN IP4 0.0.0.0\r\n"
3466 "a=rtpmap:111 opus/48000/2\r\n"
3467 "a=msid:stream_id \r\n";
3468
3469 JsepSessionDescription jdesc_output(kDummyString);
3470 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingTrackId, &jdesc_output));
3471}
3472
3473TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingStreamId) {
3474 static const char kSdpWithMissingStreamId[] =
3475 "v=0\r\n"
3476 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
3477 "s=-\r\n"
3478 "t=0 0\r\n"
3479 "m=audio 9 RTP/SAVPF 111\r\n"
3480 "c=IN IP4 0.0.0.0\r\n"
3481 "a=rtpmap:111 opus/48000/2\r\n"
3482 "a=msid: track_id\r\n";
3483
3484 JsepSessionDescription jdesc_output(kDummyString);
3485 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3486}
zhihuang38989e52017-03-21 18:04:533487
3488// Tests that if both session-level address and media-level address exist, use
3489// the media-level address.
3490TEST_F(WebRtcSdpTest, ParseConnectionData) {
3491 JsepSessionDescription jsep_desc(kDummyString);
3492
3493 // Sesssion-level address.
3494 std::string sdp = kSdpFullString;
3495 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3496 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3497
3498 const auto& content1 = jsep_desc.description()->contents()[0];
3499 EXPECT_EQ("74.125.127.126:2345",
3500 static_cast<cricket::MediaContentDescription*>(content1.description)
3501 ->connection_address()
3502 .ToString());
3503 const auto& content2 = jsep_desc.description()->contents()[1];
3504 EXPECT_EQ("74.125.224.39:3457",
3505 static_cast<cricket::MediaContentDescription*>(content2.description)
3506 ->connection_address()
3507 .ToString());
3508}
3509
3510// Tests that the session-level connection address will be used if the media
3511// level-addresses are not specified.
3512TEST_F(WebRtcSdpTest, ParseConnectionDataSessionLevelOnly) {
3513 JsepSessionDescription jsep_desc(kDummyString);
3514
3515 // Sesssion-level address.
3516 std::string sdp = kSdpString;
3517 InjectAfter("s=-\r\n", "c=IN IP4 192.168.0.3\r\n", &sdp);
3518 // Remove the media level addresses.
3519 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3520 Replace("c=IN IP4 0.0.0.0\r\n", "", &sdp);
3521 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3522
3523 const auto& content1 = jsep_desc.description()->contents()[0];
3524 EXPECT_EQ("192.168.0.3:9",
3525 static_cast<cricket::MediaContentDescription*>(content1.description)
3526 ->connection_address()
3527 .ToString());
3528 const auto& content2 = jsep_desc.description()->contents()[1];
3529 EXPECT_EQ("192.168.0.3:9",
3530 static_cast<cricket::MediaContentDescription*>(content2.description)
3531 ->connection_address()
3532 .ToString());
3533}
3534
3535TEST_F(WebRtcSdpTest, ParseConnectionDataIPv6) {
3536 JsepSessionDescription jsep_desc(kDummyString);
3537
3538 std::string sdp = kSdpString;
3539 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3540 Replace("m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP4 0.0.0.0\r\n",
3541 "m=audio 9 RTP/SAVPF 111 103 104\r\nc=IN IP6 "
3542 "2001:0db8:85a3:0000:0000:8a2e:0370:7335\r\n",
3543 &sdp);
3544 Replace("m=video 9 RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\n",
3545 "m=video 9 RTP/SAVPF 120\r\nc=IN IP6 "
3546 "2001:0db8:85a3:0000:0000:8a2e:0370:7336\r\n",
3547 &sdp);
3548 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3549 const auto& content1 = jsep_desc.description()->contents()[0];
3550 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7335]:9",
3551 static_cast<cricket::MediaContentDescription*>(content1.description)
3552 ->connection_address()
3553 .ToString());
3554 const auto& content2 = jsep_desc.description()->contents()[1];
3555 EXPECT_EQ("[2001:db8:85a3::8a2e:370:7336]:9",
3556 static_cast<cricket::MediaContentDescription*>(content2.description)
3557 ->connection_address()
3558 .ToString());
3559}
3560
3561// Test that the invalid or unsupprted connection data cannot be parsed.
3562TEST_F(WebRtcSdpTest, ParseConnectionDataFailure) {
3563 JsepSessionDescription jsep_desc(kDummyString);
3564 std::string sdp = kSdpString;
3565 EXPECT_TRUE(SdpDeserialize(sdp, &jsep_desc));
3566
3567 // Unsupported multicast IPv4 address.
3568 sdp = kSdpFullString;
3569 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP4 74.125.224.39/127\r\n", &sdp);
3570 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3571
3572 // Unsupported multicast IPv6 address.
3573 sdp = kSdpFullString;
3574 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 ::1/3\r\n", &sdp);
3575 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3576
3577 // Mismatched address type.
3578 sdp = kSdpFullString;
3579 Replace("c=IN IP4 74.125.224.39\r\n", "c=IN IP6 74.125.224.39\r\n", &sdp);
3580 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3581
3582 sdp = kSdpFullString;
3583 Replace("c=IN IP4 74.125.224.39\r\n",
3584 "c=IN IP4 2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n", &sdp);
3585 EXPECT_FALSE(SdpDeserialize(sdp, &jsep_desc));
3586}
3587
3588TEST_F(WebRtcSdpTest, SerializeAndDeserializeWithConnectionAddress) {
3589 JsepSessionDescription expected_jsep(kDummyString);
3590 MakeDescriptionWithoutCandidates(&expected_jsep);
3591 // Serialization.
3592 std::string message = webrtc::SdpSerialize(expected_jsep, false);
3593 // Deserialization.
3594 JsepSessionDescription jdesc(kDummyString);
3595 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
3596 auto audio_desc = static_cast<cricket::MediaContentDescription*>(
3597 jdesc.description()->GetContentByName(kAudioContentName)->description);
3598 auto video_desc = static_cast<cricket::MediaContentDescription*>(
3599 jdesc.description()->GetContentByName(kVideoContentName)->description);
3600 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3601 audio_desc->connection_address().ToString());
3602 EXPECT_EQ(video_desc_->connection_address().ToString(),
3603 video_desc->connection_address().ToString());
3604}