blob: 4bc84fdc12d66ffc0d883edac67a79b9d5b20bdf [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
Henrik Kjellander15583c12016-02-10 09:53:1216#include "webrtc/api/jsepsessiondescription.h"
17#ifdef WEBRTC_ANDROID
18#include "webrtc/api/test/androidtestinitializer.h"
19#endif
20#include "webrtc/api/webrtcsdp.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5221#include "webrtc/base/gunit.h"
22#include "webrtc/base/logging.h"
23#include "webrtc/base/messagedigest.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5224#include "webrtc/base/sslfingerprint.h"
25#include "webrtc/base/stringencode.h"
26#include "webrtc/base/stringutils.h"
kjellanderf4752772016-03-02 13:42:3027#include "webrtc/media/base/mediaconstants.h"
htaa6b99442016-04-12 17:29:1728#include "webrtc/media/engine/webrtcvideoengine2.h"
29#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
kjellanderf4752772016-03-02 13:42:3030#include "webrtc/p2p/base/p2pconstants.h"
kjellander@webrtc.org9b8df252016-02-12 05:47:5931#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:3632
33using cricket::AudioCodec;
34using cricket::AudioContentDescription;
35using cricket::Candidate;
36using cricket::ContentInfo;
37using cricket::CryptoParams;
38using cricket::ContentGroup;
39using cricket::DataCodec;
40using cricket::DataContentDescription;
41using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
42using cricket::ICE_CANDIDATE_COMPONENT_RTP;
43using cricket::kFecSsrcGroupSemantics;
44using cricket::LOCAL_PORT_TYPE;
45using cricket::NS_JINGLE_DRAFT_SCTP;
henrike@webrtc.org28e20752013-07-10 00:45:3646using cricket::NS_JINGLE_RTP;
47using cricket::RtpHeaderExtension;
48using cricket::RELAY_PORT_TYPE;
49using cricket::SessionDescription;
50using cricket::StreamParams;
51using cricket::STUN_PORT_TYPE;
52using cricket::TransportDescription;
53using cricket::TransportInfo;
54using cricket::VideoCodec;
55using cricket::VideoContentDescription;
56using webrtc::IceCandidateCollection;
57using webrtc::IceCandidateInterface;
58using webrtc::JsepIceCandidate;
59using webrtc::JsepSessionDescription;
60using webrtc::SdpParseError;
61using webrtc::SessionDescriptionInterface;
62
63typedef std::vector<AudioCodec> AudioCodecs;
64typedef std::vector<Candidate> Candidates;
65
Peter Boström0c4e06b2015-10-07 10:23:2166static const uint32_t kDefaultSctpPort = 5000;
henrike@webrtc.org28e20752013-07-10 00:45:3667static const char kSessionTime[] = "t=0 0\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2168static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
deadbeef3f7219b2015-12-28 23:17:1469static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3670static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n";
deadbeef3f7219b2015-12-28 23:17:1471static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:3672static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n";
Peter Boström0c4e06b2015-10-07 10:23:2173static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:3674static const char kCandidateFoundation1[] = "a0+B/1";
75static const char kCandidateFoundation2[] = "a0+B/2";
76static const char kCandidateFoundation3[] = "a0+B/3";
77static const char kCandidateFoundation4[] = "a0+B/4";
78static const char kAttributeCryptoVoice[] =
79 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
80 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
81 "dummy_session_params\r\n";
82static const char kAttributeCryptoVideo[] =
83 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
84 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
85static const char kFingerprint[] = "a=fingerprint:sha-1 "
86 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
87static const int kExtmapId = 1;
88static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
89static const char kExtmap[] =
90 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
91static const char kExtmapWithDirectionAndAttribute[] =
92 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
93
Peter Boström0c4e06b2015-10-07 10:23:2194static const uint8_t kIdentityDigest[] = {
95 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
96 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
henrike@webrtc.org28e20752013-07-10 00:45:3697
lally@webrtc.org34807282015-02-24 20:19:3998static const char kDtlsSctp[] = "DTLS/SCTP";
99static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
100static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
lally@webrtc.org36300852015-02-24 20:19:35101
henrike@webrtc.org28e20752013-07-10 00:45:36102struct CodecParams {
103 int max_ptime;
104 int ptime;
105 int min_ptime;
106 int sprop_stereo;
107 int stereo;
108 int useinband;
henrike@webrtc.org1e09a712013-07-26 19:17:59109 int maxaveragebitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36110};
111
deadbeef9d3584c2016-02-17 01:54:10112// TODO(deadbeef): In these reference strings, use "a=fingerprint" by default
113// instead of "a=crypto", and have an explicit test for adding "a=crypto".
114// Currently it's the other way around.
115
henrike@webrtc.org28e20752013-07-10 00:45:36116// Reference sdp string
117static const char kSdpFullString[] =
118 "v=0\r\n"
119 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
120 "s=-\r\n"
121 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10122 "a=msid-semantic: WMS local_stream_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36123 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
124 "c=IN IP4 74.125.127.126\r\n"
125 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
126 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
127 "generation 2\r\n"
128 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
129 "generation 2\r\n"
130 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
131 "generation 2\r\n"
132 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
133 "generation 2\r\n"
134 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
135 "raddr 192.168.1.5 rport 2346 "
136 "generation 2\r\n"
137 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
138 "raddr 192.168.1.5 rport 2348 "
139 "generation 2\r\n"
140 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
141 "a=mid:audio_content_name\r\n"
142 "a=sendrecv\r\n"
143 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51144 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36145 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
146 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
147 "dummy_session_params\r\n"
148 "a=rtpmap:111 opus/48000/2\r\n"
149 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41150 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36151 "a=ssrc:1 cname:stream_1_cname\r\n"
152 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
153 "a=ssrc:1 mslabel:local_stream_1\r\n"
154 "a=ssrc:1 label:audio_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36155 "m=video 3457 RTP/SAVPF 120\r\n"
156 "c=IN IP4 74.125.224.39\r\n"
157 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
158 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
159 "generation 2\r\n"
160 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
161 "generation 2\r\n"
162 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
163 "generation 2\r\n"
164 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
165 "generation 2\r\n"
166 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
167 "generation 2\r\n"
168 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
169 "generation 2\r\n"
170 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
171 "a=mid:video_content_name\r\n"
172 "a=sendrecv\r\n"
173 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
174 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
175 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10176 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36177 "a=ssrc:2 cname:stream_1_cname\r\n"
178 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
179 "a=ssrc:2 mslabel:local_stream_1\r\n"
180 "a=ssrc:2 label:video_track_id_1\r\n"
181 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10182 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36183 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10184 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36185
186// SDP reference string without the candidates.
187static const char kSdpString[] =
188 "v=0\r\n"
189 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
190 "s=-\r\n"
191 "t=0 0\r\n"
deadbeef9d3584c2016-02-17 01:54:10192 "a=msid-semantic: WMS local_stream_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22193 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06194 "c=IN IP4 0.0.0.0\r\n"
195 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36196 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
197 "a=mid:audio_content_name\r\n"
198 "a=sendrecv\r\n"
199 "a=rtcp-mux\r\n"
deadbeef13871492015-12-09 20:37:51200 "a=rtcp-rsize\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36201 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
202 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
203 "dummy_session_params\r\n"
204 "a=rtpmap:111 opus/48000/2\r\n"
205 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41206 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36207 "a=ssrc:1 cname:stream_1_cname\r\n"
208 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
209 "a=ssrc:1 mslabel:local_stream_1\r\n"
210 "a=ssrc:1 label:audio_track_id_1\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22211 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06212 "c=IN IP4 0.0.0.0\r\n"
213 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36214 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
215 "a=mid:video_content_name\r\n"
216 "a=sendrecv\r\n"
217 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
218 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
219 "a=rtpmap:120 VP8/90000\r\n"
deadbeef9d3584c2016-02-17 01:54:10220 "a=ssrc-group:FEC 2 3\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36221 "a=ssrc:2 cname:stream_1_cname\r\n"
222 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
223 "a=ssrc:2 mslabel:local_stream_1\r\n"
224 "a=ssrc:2 label:video_track_id_1\r\n"
225 "a=ssrc:3 cname:stream_1_cname\r\n"
deadbeef9d3584c2016-02-17 01:54:10226 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36227 "a=ssrc:3 mslabel:local_stream_1\r\n"
deadbeef9d3584c2016-02-17 01:54:10228 "a=ssrc:3 label:video_track_id_1\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36229
230static const char kSdpRtpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22231 "m=application 9 RTP/SAVPF 101\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06232 "c=IN IP4 0.0.0.0\r\n"
233 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36234 "a=ice-ufrag:ufrag_data\r\n"
235 "a=ice-pwd:pwd_data\r\n"
236 "a=mid:data_content_name\r\n"
237 "a=sendrecv\r\n"
238 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
239 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n"
240 "a=rtpmap:101 google-data/90000\r\n"
241 "a=ssrc:10 cname:data_channel_cname\r\n"
242 "a=ssrc:10 msid:data_channel data_channeld0\r\n"
243 "a=ssrc:10 mslabel:data_channel\r\n"
244 "a=ssrc:10 label:data_channeld0\r\n";
245
246static const char kSdpSctpDataChannelString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22247 "m=application 9 DTLS/SCTP 5000\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06248 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:36249 "a=ice-ufrag:ufrag_data\r\n"
250 "a=ice-pwd:pwd_data\r\n"
251 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33252 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36253
lally@webrtc.orgec97c652015-02-24 20:18:48254// draft-ietf-mmusic-sctp-sdp-12
jiayl@webrtc.orgddb85ab2014-09-05 16:31:56255static const char kSdpSctpDataChannelStringWithSctpPort[] =
lally@webrtc.orgc7848b72015-02-24 20:19:26256 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
257 "a=max-message-size=100000\r\n"
258 "a=sctp-port 5000\r\n"
259 "c=IN IP4 0.0.0.0\r\n"
260 "a=ice-ufrag:ufrag_data\r\n"
261 "a=ice-pwd:pwd_data\r\n"
262 "a=mid:data_content_name\r\n";
263
lally69f57602015-10-08 17:15:04264static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
265 "m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
266 "a=max-message-size=100000\r\n"
267 "a=sctp-port:5000\r\n"
268 "c=IN IP4 0.0.0.0\r\n"
269 "a=ice-ufrag:ufrag_data\r\n"
270 "a=ice-pwd:pwd_data\r\n"
271 "a=mid:data_content_name\r\n";
272
henrike@webrtc.org28e20752013-07-10 00:45:36273static const char kSdpSctpDataChannelWithCandidatesString[] =
274 "m=application 2345 DTLS/SCTP 5000\r\n"
275 "c=IN IP4 74.125.127.126\r\n"
276 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
277 "generation 2\r\n"
278 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
279 "generation 2\r\n"
280 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
281 "raddr 192.168.1.5 rport 2346 "
282 "generation 2\r\n"
283 "a=ice-ufrag:ufrag_data\r\n"
284 "a=ice-pwd:pwd_data\r\n"
285 "a=mid:data_content_name\r\n"
wu@webrtc.org97077a32013-10-25 21:18:33286 "a=sctpmap:5000 webrtc-datachannel 1024\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36287
jiayl@webrtc.org9c16c392014-05-01 18:30:30288static const char kSdpConferenceString[] =
henrike@webrtc.org704bf9e2014-02-27 17:52:04289 "v=0\r\n"
290 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
291 "s=-\r\n"
292 "t=0 0\r\n"
293 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22294 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06295 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04296 "a=x-google-flag:conference\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22297 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06298 "c=IN IP4 0.0.0.0\r\n"
henrike@webrtc.org704bf9e2014-02-27 17:52:04299 "a=x-google-flag:conference\r\n";
300
jiayl@webrtc.orge7d47a12014-08-05 19:19:05301static const char kSdpSessionString[] =
302 "v=0\r\n"
303 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
304 "s=-\r\n"
305 "t=0 0\r\n"
306 "a=msid-semantic: WMS local_stream\r\n";
307
308static const char kSdpAudioString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22309 "m=audio 9 RTP/SAVPF 111\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06310 "c=IN IP4 0.0.0.0\r\n"
311 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05312 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
313 "a=mid:audio_content_name\r\n"
314 "a=sendrecv\r\n"
315 "a=rtpmap:111 opus/48000/2\r\n"
316 "a=ssrc:1 cname:stream_1_cname\r\n"
317 "a=ssrc:1 msid:local_stream audio_track_id_1\r\n"
318 "a=ssrc:1 mslabel:local_stream\r\n"
319 "a=ssrc:1 label:audio_track_id_1\r\n";
320
321static const char kSdpVideoString[] =
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:22322 "m=video 9 RTP/SAVPF 120\r\n"
perkj@webrtc.orgd105cc82014-11-07 11:22:06323 "c=IN IP4 0.0.0.0\r\n"
324 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
jiayl@webrtc.orge7d47a12014-08-05 19:19:05325 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
326 "a=mid:video_content_name\r\n"
327 "a=sendrecv\r\n"
328 "a=rtpmap:120 VP8/90000\r\n"
329 "a=ssrc:2 cname:stream_1_cname\r\n"
330 "a=ssrc:2 msid:local_stream video_track_id_1\r\n"
331 "a=ssrc:2 mslabel:local_stream\r\n"
332 "a=ssrc:2 label:video_track_id_1\r\n";
333
deadbeef9d3584c2016-02-17 01:54:10334// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
335// tracks.
336static const char kPlanBSdpFullString[] =
337 "v=0\r\n"
338 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
339 "s=-\r\n"
340 "t=0 0\r\n"
341 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
342 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
343 "c=IN IP4 74.125.127.126\r\n"
344 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
345 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
346 "generation 2\r\n"
347 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
348 "generation 2\r\n"
349 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
350 "generation 2\r\n"
351 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
352 "generation 2\r\n"
353 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
354 "raddr 192.168.1.5 rport 2346 "
355 "generation 2\r\n"
356 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
357 "raddr 192.168.1.5 rport 2348 "
358 "generation 2\r\n"
359 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
360 "a=mid:audio_content_name\r\n"
361 "a=sendrecv\r\n"
362 "a=rtcp-mux\r\n"
363 "a=rtcp-rsize\r\n"
364 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
365 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
366 "dummy_session_params\r\n"
367 "a=rtpmap:111 opus/48000/2\r\n"
368 "a=rtpmap:103 ISAC/16000\r\n"
369 "a=rtpmap:104 ISAC/32000\r\n"
370 "a=ssrc:1 cname:stream_1_cname\r\n"
371 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
372 "a=ssrc:1 mslabel:local_stream_1\r\n"
373 "a=ssrc:1 label:audio_track_id_1\r\n"
374 "a=ssrc:4 cname:stream_2_cname\r\n"
375 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
376 "a=ssrc:4 mslabel:local_stream_2\r\n"
377 "a=ssrc:4 label:audio_track_id_2\r\n"
378 "m=video 3457 RTP/SAVPF 120\r\n"
379 "c=IN IP4 74.125.224.39\r\n"
380 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
381 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
382 "generation 2\r\n"
383 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
384 "generation 2\r\n"
385 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
386 "generation 2\r\n"
387 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
388 "generation 2\r\n"
389 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
390 "generation 2\r\n"
391 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
392 "generation 2\r\n"
393 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
394 "a=mid:video_content_name\r\n"
395 "a=sendrecv\r\n"
396 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
397 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
398 "a=rtpmap:120 VP8/90000\r\n"
399 "a=ssrc-group:FEC 2 3\r\n"
400 "a=ssrc:2 cname:stream_1_cname\r\n"
401 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
402 "a=ssrc:2 mslabel:local_stream_1\r\n"
403 "a=ssrc:2 label:video_track_id_1\r\n"
404 "a=ssrc:3 cname:stream_1_cname\r\n"
405 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
406 "a=ssrc:3 mslabel:local_stream_1\r\n"
407 "a=ssrc:3 label:video_track_id_1\r\n"
408 "a=ssrc:5 cname:stream_2_cname\r\n"
409 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
410 "a=ssrc:5 mslabel:local_stream_2\r\n"
411 "a=ssrc:5 label:video_track_id_2\r\n"
412 "a=ssrc:6 cname:stream_2_cname\r\n"
413 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
414 "a=ssrc:6 mslabel:local_stream_2\r\n"
415 "a=ssrc:6 label:video_track_id_3\r\n";
416
Taylor Brandstetter5de6b752016-03-10 01:02:30417// Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video
418// tracks, but with the unified plan "a=msid" attribute.
419static const char kPlanBSdpFullStringWithMsid[] =
420 "v=0\r\n"
421 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
422 "s=-\r\n"
423 "t=0 0\r\n"
424 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"
425 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
426 "c=IN IP4 74.125.127.126\r\n"
427 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
428 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
429 "generation 2\r\n"
430 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
431 "generation 2\r\n"
432 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
433 "generation 2\r\n"
434 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
435 "generation 2\r\n"
436 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
437 "raddr 192.168.1.5 rport 2346 "
438 "generation 2\r\n"
439 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
440 "raddr 192.168.1.5 rport 2348 "
441 "generation 2\r\n"
442 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
443 "a=mid:audio_content_name\r\n"
444 "a=msid:local_stream_1 audio_track_id_1\r\n"
445 "a=sendrecv\r\n"
446 "a=rtcp-mux\r\n"
447 "a=rtcp-rsize\r\n"
448 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
449 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
450 "dummy_session_params\r\n"
451 "a=rtpmap:111 opus/48000/2\r\n"
452 "a=rtpmap:103 ISAC/16000\r\n"
453 "a=rtpmap:104 ISAC/32000\r\n"
454 "a=ssrc:1 cname:stream_1_cname\r\n"
455 "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n"
456 "a=ssrc:1 mslabel:local_stream_1\r\n"
457 "a=ssrc:1 label:audio_track_id_1\r\n"
458 "a=ssrc:4 cname:stream_2_cname\r\n"
459 "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n"
460 "a=ssrc:4 mslabel:local_stream_2\r\n"
461 "a=ssrc:4 label:audio_track_id_2\r\n"
462 "m=video 3457 RTP/SAVPF 120\r\n"
463 "c=IN IP4 74.125.224.39\r\n"
464 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
465 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
466 "generation 2\r\n"
467 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
468 "generation 2\r\n"
469 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
470 "generation 2\r\n"
471 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
472 "generation 2\r\n"
473 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
474 "generation 2\r\n"
475 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
476 "generation 2\r\n"
477 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
478 "a=mid:video_content_name\r\n"
479 "a=msid:local_stream_1 video_track_id_1\r\n"
480 "a=sendrecv\r\n"
481 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
482 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
483 "a=rtpmap:120 VP8/90000\r\n"
484 "a=ssrc-group:FEC 2 3\r\n"
485 "a=ssrc:2 cname:stream_1_cname\r\n"
486 "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n"
487 "a=ssrc:2 mslabel:local_stream_1\r\n"
488 "a=ssrc:2 label:video_track_id_1\r\n"
489 "a=ssrc:3 cname:stream_1_cname\r\n"
490 "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n"
491 "a=ssrc:3 mslabel:local_stream_1\r\n"
492 "a=ssrc:3 label:video_track_id_1\r\n"
493 "a=ssrc:5 cname:stream_2_cname\r\n"
494 "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n"
495 "a=ssrc:5 mslabel:local_stream_2\r\n"
496 "a=ssrc:5 label:video_track_id_2\r\n"
497 "a=ssrc:6 cname:stream_2_cname\r\n"
498 "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n"
499 "a=ssrc:6 mslabel:local_stream_2\r\n"
500 "a=ssrc:6 label:video_track_id_3\r\n";
501
deadbeef9d3584c2016-02-17 01:54:10502// Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video
503// tracks.
504static const char kUnifiedPlanSdpFullString[] =
505 "v=0\r\n"
506 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
507 "s=-\r\n"
508 "t=0 0\r\n"
509 "a=msid-semantic: WMS local_stream_1\r\n"
510 // Audio track 1, stream 1 (with candidates).
511 "m=audio 2345 RTP/SAVPF 111 103 104\r\n"
512 "c=IN IP4 74.125.127.126\r\n"
513 "a=rtcp:2347 IN IP4 74.125.127.126\r\n"
514 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
515 "generation 2\r\n"
516 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host "
517 "generation 2\r\n"
518 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host "
519 "generation 2\r\n"
520 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host "
521 "generation 2\r\n"
522 "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx "
523 "raddr 192.168.1.5 rport 2346 "
524 "generation 2\r\n"
525 "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx "
526 "raddr 192.168.1.5 rport 2348 "
527 "generation 2\r\n"
528 "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n"
529 "a=mid:audio_content_name\r\n"
530 "a=msid:local_stream_1 audio_track_id_1\r\n"
531 "a=sendrecv\r\n"
532 "a=rtcp-mux\r\n"
533 "a=rtcp-rsize\r\n"
534 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
535 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
536 "dummy_session_params\r\n"
537 "a=rtpmap:111 opus/48000/2\r\n"
538 "a=rtpmap:103 ISAC/16000\r\n"
539 "a=rtpmap:104 ISAC/32000\r\n"
540 "a=ssrc:1 cname:stream_1_cname\r\n"
541 // Video track 1, stream 1 (with candidates).
542 "m=video 3457 RTP/SAVPF 120\r\n"
543 "c=IN IP4 74.125.224.39\r\n"
544 "a=rtcp:3456 IN IP4 74.125.224.39\r\n"
545 "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host "
546 "generation 2\r\n"
547 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host "
548 "generation 2\r\n"
549 "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host "
550 "generation 2\r\n"
551 "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host "
552 "generation 2\r\n"
553 "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay "
554 "generation 2\r\n"
555 "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay "
556 "generation 2\r\n"
557 "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n"
558 "a=mid:video_content_name\r\n"
559 "a=msid:local_stream_1 video_track_id_1\r\n"
560 "a=sendrecv\r\n"
561 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
562 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
563 "a=rtpmap:120 VP8/90000\r\n"
564 "a=ssrc-group:FEC 2 3\r\n"
565 "a=ssrc:2 cname:stream_1_cname\r\n"
566 "a=ssrc:3 cname:stream_1_cname\r\n"
567 // Audio track 2, stream 2.
568 "m=audio 9 RTP/SAVPF 111 103 104\r\n"
569 "c=IN IP4 0.0.0.0\r\n"
570 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
571 "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n"
572 "a=mid:audio_content_name_2\r\n"
573 "a=msid:local_stream_2 audio_track_id_2\r\n"
574 "a=sendrecv\r\n"
575 "a=rtcp-mux\r\n"
576 "a=rtcp-rsize\r\n"
577 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
578 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
579 "dummy_session_params\r\n"
580 "a=rtpmap:111 opus/48000/2\r\n"
581 "a=rtpmap:103 ISAC/16000\r\n"
582 "a=rtpmap:104 ISAC/32000\r\n"
583 "a=ssrc:4 cname:stream_2_cname\r\n"
584 // Video track 2, stream 2.
585 "m=video 9 RTP/SAVPF 120\r\n"
586 "c=IN IP4 0.0.0.0\r\n"
587 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
588 "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n"
589 "a=mid:video_content_name_2\r\n"
590 "a=msid:local_stream_2 video_track_id_2\r\n"
591 "a=sendrecv\r\n"
592 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
593 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
594 "a=rtpmap:120 VP8/90000\r\n"
595 "a=ssrc:5 cname:stream_2_cname\r\n"
596 // Video track 3, stream 2.
597 "m=video 9 RTP/SAVPF 120\r\n"
598 "c=IN IP4 0.0.0.0\r\n"
599 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
600 "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n"
601 "a=mid:video_content_name_3\r\n"
602 "a=msid:local_stream_2 video_track_id_3\r\n"
603 "a=sendrecv\r\n"
604 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
605 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"
606 "a=rtpmap:120 VP8/90000\r\n"
607 "a=ssrc:6 cname:stream_2_cname\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36608
609// One candidate reference string as per W3c spec.
610// candidate:<blah> not a=candidate:<blah>CRLF
611static const char kRawCandidate[] =
612 "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2";
613// One candidate reference string.
614static const char kSdpOneCandidate[] =
615 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host "
616 "generation 2\r\n";
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15617
mallinath@webrtc.org2d60c5e2014-08-08 22:29:20618static const char kSdpTcpActiveCandidate[] =
619 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
620 "tcptype active generation 2";
621static const char kSdpTcpPassiveCandidate[] =
622 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
623 "tcptype passive generation 2";
624static const char kSdpTcpSOCandidate[] =
625 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
626 "tcptype so generation 2";
627static const char kSdpTcpInvalidCandidate[] =
628 "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host "
629 "tcptype invalid generation 2";
630
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:15631// One candidate reference string with IPV6 address.
632static const char kRawIPV6Candidate[] =
633 "candidate:a0+B/1 1 udp 2130706432 "
634 "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2";
henrike@webrtc.org28e20752013-07-10 00:45:36635
636// One candidate reference string.
honghaiza54a0802015-12-17 02:37:23637static const char kSdpOneCandidateWithUfragPwd[] =
henrike@webrtc.org28e20752013-07-10 00:45:36638 "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name"
honghaiza54a0802015-12-17 02:37:23639 " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:36640
641// Session id and version
642static const char kSessionId[] = "18446744069414584320";
643static const char kSessionVersion[] = "18446462598732840960";
644
deadbeef9d3584c2016-02-17 01:54:10645// ICE options.
henrike@webrtc.org28e20752013-07-10 00:45:36646static const char kIceOption1[] = "iceoption1";
647static const char kIceOption2[] = "iceoption2";
648static const char kIceOption3[] = "iceoption3";
649
deadbeef9d3584c2016-02-17 01:54:10650// ICE ufrags/passwords.
651static const char kUfragVoice[] = "ufrag_voice";
652static const char kPwdVoice[] = "pwd_voice";
653static const char kUfragVideo[] = "ufrag_video";
654static const char kPwdVideo[] = "pwd_video";
655static const char kUfragData[] = "ufrag_data";
656static const char kPwdData[] = "pwd_data";
657
658// Extra ufrags/passwords for extra unified plan m= sections.
659static const char kUfragVoice2[] = "ufrag_voice_2";
660static const char kPwdVoice2[] = "pwd_voice_2";
661static const char kUfragVideo2[] = "ufrag_video_2";
662static const char kPwdVideo2[] = "pwd_video_2";
663static const char kUfragVideo3[] = "ufrag_video_3";
664static const char kPwdVideo3[] = "pwd_video_3";
665
henrike@webrtc.org28e20752013-07-10 00:45:36666// Content name
667static const char kAudioContentName[] = "audio_content_name";
668static const char kVideoContentName[] = "video_content_name";
669static const char kDataContentName[] = "data_content_name";
670
deadbeef9d3584c2016-02-17 01:54:10671// Extra content names for extra unified plan m= sections.
672static const char kAudioContentName2[] = "audio_content_name_2";
673static const char kVideoContentName2[] = "video_content_name_2";
674static const char kVideoContentName3[] = "video_content_name_3";
675
henrike@webrtc.org28e20752013-07-10 00:45:36676// MediaStream 1
677static const char kStreamLabel1[] = "local_stream_1";
678static const char kStream1Cname[] = "stream_1_cname";
679static const char kAudioTrackId1[] = "audio_track_id_1";
Peter Boström0c4e06b2015-10-07 10:23:21680static const uint32_t kAudioTrack1Ssrc = 1;
henrike@webrtc.org28e20752013-07-10 00:45:36681static const char kVideoTrackId1[] = "video_track_id_1";
deadbeef9d3584c2016-02-17 01:54:10682static const uint32_t kVideoTrack1Ssrc1 = 2;
683static const uint32_t kVideoTrack1Ssrc2 = 3;
henrike@webrtc.org28e20752013-07-10 00:45:36684
685// MediaStream 2
686static const char kStreamLabel2[] = "local_stream_2";
687static const char kStream2Cname[] = "stream_2_cname";
688static const char kAudioTrackId2[] = "audio_track_id_2";
Peter Boström0c4e06b2015-10-07 10:23:21689static const uint32_t kAudioTrack2Ssrc = 4;
deadbeef9d3584c2016-02-17 01:54:10690static const char kVideoTrackId2[] = "video_track_id_2";
691static const uint32_t kVideoTrack2Ssrc = 5;
henrike@webrtc.org28e20752013-07-10 00:45:36692static const char kVideoTrackId3[] = "video_track_id_3";
deadbeef9d3584c2016-02-17 01:54:10693static const uint32_t kVideoTrack3Ssrc = 6;
henrike@webrtc.org28e20752013-07-10 00:45:36694
695// DataChannel
696static const char kDataChannelLabel[] = "data_channel";
697static const char kDataChannelMsid[] = "data_channeld0";
698static const char kDataChannelCname[] = "data_channel_cname";
Peter Boström0c4e06b2015-10-07 10:23:21699static const uint32_t kDataChannelSsrc = 10;
henrike@webrtc.org28e20752013-07-10 00:45:36700
701// Candidate
702static const char kDummyMid[] = "dummy_mid";
703static const int kDummyIndex = 123;
704
705// Misc
706static const char kDummyString[] = "dummy";
707
708// Helper functions
709
710static bool SdpDeserialize(const std::string& message,
711 JsepSessionDescription* jdesc) {
712 return webrtc::SdpDeserialize(message, jdesc, NULL);
713}
714
715static bool SdpDeserializeCandidate(const std::string& message,
716 JsepIceCandidate* candidate) {
717 return webrtc::SdpDeserializeCandidate(message, candidate, NULL);
718}
719
720// Add some extra |newlines| to the |message| after |line|.
721static void InjectAfter(const std::string& line,
722 const std::string& newlines,
723 std::string* message) {
724 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52725 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36726 tmp.c_str(), tmp.length(), message);
727}
728
729static void Replace(const std::string& line,
730 const std::string& newlines,
731 std::string* message) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52732 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36733 newlines.c_str(), newlines.length(), message);
734}
735
wu@webrtc.org5e760e72014-04-02 23:19:09736// Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error
737// message.
738static void ExpectParseFailure(const std::string& bad_sdp,
739 const std::string& bad_part) {
henrike@webrtc.org28e20752013-07-10 00:45:36740 JsepSessionDescription desc(kDummyString);
henrike@webrtc.org28e20752013-07-10 00:45:36741 SdpParseError error;
wu@webrtc.org5e760e72014-04-02 23:19:09742 bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error);
henrike@webrtc.org28e20752013-07-10 00:45:36743 EXPECT_FALSE(ret);
wu@webrtc.org5e760e72014-04-02 23:19:09744 EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str()));
745}
746
747// Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|.
748static void ExpectParseFailure(const char* good_part, const char* bad_part) {
749 std::string bad_sdp = kSdpFullString;
750 Replace(good_part, bad_part, &bad_sdp);
751 ExpectParseFailure(bad_sdp, bad_part);
752}
753
754// Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|.
755static void ExpectParseFailureWithNewLines(const std::string& injectpoint,
756 const std::string& newlines,
757 const std::string& bad_part) {
758 std::string bad_sdp = kSdpFullString;
759 InjectAfter(injectpoint, newlines, &bad_sdp);
760 ExpectParseFailure(bad_sdp, bad_part);
henrike@webrtc.org28e20752013-07-10 00:45:36761}
762
763static void ReplaceDirection(cricket::MediaContentDirection direction,
764 std::string* message) {
765 std::string new_direction;
766 switch (direction) {
767 case cricket::MD_INACTIVE:
768 new_direction = "a=inactive";
769 break;
770 case cricket::MD_SENDONLY:
771 new_direction = "a=sendonly";
772 break;
773 case cricket::MD_RECVONLY:
774 new_direction = "a=recvonly";
775 break;
776 case cricket::MD_SENDRECV:
777 default:
778 new_direction = "a=sendrecv";
779 break;
780 }
781 Replace("a=sendrecv", new_direction, message);
782}
783
784static void ReplaceRejected(bool audio_rejected, bool video_rejected,
785 std::string* message) {
786 if (audio_rejected) {
deadbeef3f7219b2015-12-28 23:17:14787 Replace("m=audio 9", "m=audio 0", message);
788 Replace(kAttributeIceUfragVoice, "", message);
789 Replace(kAttributeIcePwdVoice, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36790 }
791 if (video_rejected) {
deadbeef3f7219b2015-12-28 23:17:14792 Replace("m=video 9", "m=video 0", message);
793 Replace(kAttributeIceUfragVideo, "", message);
794 Replace(kAttributeIcePwdVideo, "", message);
henrike@webrtc.org28e20752013-07-10 00:45:36795 }
796}
797
798// WebRtcSdpTest
799
800class WebRtcSdpTest : public testing::Test {
801 public:
802 WebRtcSdpTest()
803 : jdesc_(kDummyString) {
phoglund37ebcf02016-01-08 13:04:57804#ifdef WEBRTC_ANDROID
805 webrtc::InitializeAndroidObjects();
806#endif
henrike@webrtc.org28e20752013-07-10 00:45:36807 // AudioContentDescription
808 audio_desc_ = CreateAudioContentDescription();
deadbeef9d3584c2016-02-17 01:54:10809 StreamParams audio_stream;
810 audio_stream.id = kAudioTrackId1;
811 audio_stream.cname = kStream1Cname;
812 audio_stream.sync_label = kStreamLabel1;
813 audio_stream.ssrcs.push_back(kAudioTrack1Ssrc);
814 audio_desc_->AddStream(audio_stream);
henrike@webrtc.org28e20752013-07-10 00:45:36815 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
816
817 // VideoContentDescription
deadbeef9d3584c2016-02-17 01:54:10818 video_desc_ = CreateVideoContentDescription();
819 StreamParams video_stream;
820 video_stream.id = kVideoTrackId1;
821 video_stream.cname = kStream1Cname;
822 video_stream.sync_label = kStreamLabel1;
823 video_stream.ssrcs.push_back(kVideoTrack1Ssrc1);
824 video_stream.ssrcs.push_back(kVideoTrack1Ssrc2);
825 cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs);
826 video_stream.ssrc_groups.push_back(ssrc_group);
827 video_desc_->AddStream(video_stream);
828 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
henrike@webrtc.org28e20752013-07-10 00:45:36829
830 // TransportInfo
deadbeef9d3584c2016-02-17 01:54:10831 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
832 kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice))));
833 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
834 kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo))));
henrike@webrtc.org28e20752013-07-10 00:45:36835
836 // v4 host
837 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52838 rtc::SocketAddress address("192.168.1.5", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07839 Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31840 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
841 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36842 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07843 Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31844 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
845 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36846 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07847 Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31848 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
849 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36850 address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07851 Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
guoweis@webrtc.org950c5182014-12-16 23:01:31852 kCandidatePriority, "", "", LOCAL_PORT_TYPE,
853 kCandidateGeneration, kCandidateFoundation1);
henrike@webrtc.org28e20752013-07-10 00:45:36854
855 // v6 host
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52856 rtc::SocketAddress v6_address("::1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07857 cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
858 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31859 cricket::LOCAL_PORT_TYPE,
860 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36861 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07862 cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
863 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31864 cricket::LOCAL_PORT_TYPE,
865 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36866 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07867 cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
868 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31869 cricket::LOCAL_PORT_TYPE,
870 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36871 v6_address.SetPort(port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07872 cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
873 v6_address, kCandidatePriority, "", "",
guoweis@webrtc.org950c5182014-12-16 23:01:31874 cricket::LOCAL_PORT_TYPE,
875 kCandidateGeneration, kCandidateFoundation2);
henrike@webrtc.org28e20752013-07-10 00:45:36876
877 // stun
878 int port_stun = 2345;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52879 rtc::SocketAddress address_stun("74.125.127.126", port_stun++);
880 rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07881 cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
882 address_stun, kCandidatePriority, "", "",
883 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31884 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36885 candidate9.set_related_address(rel_address_stun);
886
887 address_stun.SetPort(port_stun++);
888 rel_address_stun.SetPort(port_stun++);
guoweis@webrtc.org61c12472015-01-15 06:53:07889 cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
890 address_stun, kCandidatePriority, "", "",
891 STUN_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31892 kCandidateFoundation3);
henrike@webrtc.org28e20752013-07-10 00:45:36893 candidate10.set_related_address(rel_address_stun);
894
895 // relay
896 int port_relay = 3456;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52897 rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07898 cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
899 address_relay, kCandidatePriority, "", "",
900 cricket::RELAY_PORT_TYPE,
guoweis@webrtc.org950c5182014-12-16 23:01:31901 kCandidateGeneration, kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36902 address_relay.SetPort(port_relay++);
guoweis@webrtc.org61c12472015-01-15 06:53:07903 cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
904 address_relay, kCandidatePriority, "", "",
905 RELAY_PORT_TYPE, kCandidateGeneration,
guoweis@webrtc.org950c5182014-12-16 23:01:31906 kCandidateFoundation4);
henrike@webrtc.org28e20752013-07-10 00:45:36907
908 // voice
909 candidates_.push_back(candidate1);
910 candidates_.push_back(candidate2);
911 candidates_.push_back(candidate5);
912 candidates_.push_back(candidate6);
913 candidates_.push_back(candidate9);
914 candidates_.push_back(candidate10);
915
916 // video
917 candidates_.push_back(candidate3);
918 candidates_.push_back(candidate4);
919 candidates_.push_back(candidate7);
920 candidates_.push_back(candidate8);
921 candidates_.push_back(candidate11);
922 candidates_.push_back(candidate12);
923
924 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"),
925 0, candidate1));
926
927 // Set up JsepSessionDescription.
928 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
929 std::string mline_id;
930 int mline_index = 0;
931 for (size_t i = 0; i< candidates_.size(); ++i) {
932 // In this test, the audio m line index will be 0, and the video m line
933 // will be 1.
934 bool is_video = (i > 5);
935 mline_id = is_video ? "video_content_name" : "audio_content_name";
936 mline_index = is_video ? 1 : 0;
937 JsepIceCandidate jice(mline_id,
938 mline_index,
939 candidates_.at(i));
940 jdesc_.AddCandidate(&jice);
941 }
942 }
943
deadbeef9d3584c2016-02-17 01:54:10944 // Turns the existing reference description into a plan B description,
945 // with 2 audio tracks and 3 video tracks.
946 void MakePlanBDescription() {
947 audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy());
948 video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy());
949
950 StreamParams audio_track_2;
951 audio_track_2.id = kAudioTrackId2;
952 audio_track_2.cname = kStream2Cname;
953 audio_track_2.sync_label = kStreamLabel2;
954 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
955 audio_desc_->AddStream(audio_track_2);
956
957 StreamParams video_track_2;
958 video_track_2.id = kVideoTrackId2;
959 video_track_2.cname = kStream2Cname;
960 video_track_2.sync_label = kStreamLabel2;
961 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
962 video_desc_->AddStream(video_track_2);
963
964 StreamParams video_track_3;
965 video_track_3.id = kVideoTrackId3;
966 video_track_3.cname = kStream2Cname;
967 video_track_3.sync_label = kStreamLabel2;
968 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
969 video_desc_->AddStream(video_track_3);
970
971 desc_.RemoveContentByName(kAudioContentName);
972 desc_.RemoveContentByName(kVideoContentName);
973 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
974 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
975
976 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
977 jdesc_.session_version()));
978 }
979
980 // Turns the existing reference description into a unified plan description,
981 // with 2 audio tracks and 3 video tracks.
982 void MakeUnifiedPlanDescription() {
983 // Audio track 2.
984 AudioContentDescription* audio_desc_2 = CreateAudioContentDescription();
985 StreamParams audio_track_2;
986 audio_track_2.id = kAudioTrackId2;
987 audio_track_2.cname = kStream2Cname;
988 audio_track_2.sync_label = kStreamLabel2;
989 audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc);
990 audio_desc_2->AddStream(audio_track_2);
991 desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2);
992 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
993 kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2))));
994
995 // Video track 2, in stream 2.
996 VideoContentDescription* video_desc_2 = CreateVideoContentDescription();
997 StreamParams video_track_2;
998 video_track_2.id = kVideoTrackId2;
999 video_track_2.cname = kStream2Cname;
1000 video_track_2.sync_label = kStreamLabel2;
1001 video_track_2.ssrcs.push_back(kVideoTrack2Ssrc);
1002 video_desc_2->AddStream(video_track_2);
1003 desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2);
1004 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1005 kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2))));
1006
1007 // Video track 3, in stream 2.
1008 VideoContentDescription* video_desc_3 = CreateVideoContentDescription();
1009 StreamParams video_track_3;
1010 video_track_3.id = kVideoTrackId3;
1011 video_track_3.cname = kStream2Cname;
1012 video_track_3.sync_label = kStreamLabel2;
1013 video_track_3.ssrcs.push_back(kVideoTrack3Ssrc);
1014 video_desc_3->AddStream(video_track_3);
1015 desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3);
1016 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1017 kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3))));
1018
1019 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(),
1020 jdesc_.session_version()));
1021 }
1022
1023 // Creates an audio content description with no streams, and some default
1024 // configuration.
henrike@webrtc.org28e20752013-07-10 00:45:361025 AudioContentDescription* CreateAudioContentDescription() {
1026 AudioContentDescription* audio = new AudioContentDescription();
1027 audio->set_rtcp_mux(true);
deadbeef13871492015-12-09 20:37:511028 audio->set_rtcp_reduced_size(true);
henrike@webrtc.org28e20752013-07-10 00:45:361029 audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32",
1030 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32",
1031 "dummy_session_params"));
1032 audio->set_protocol(cricket::kMediaProtocolSavpf);
deadbeef67cf2c12016-04-13 17:07:161033 AudioCodec opus(111, "opus", 48000, 0, 2);
deadbeef9d3584c2016-02-17 01:54:101034 audio->AddCodec(opus);
deadbeef67cf2c12016-04-13 17:07:161035 audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1));
1036 audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1));
henrike@webrtc.org28e20752013-07-10 00:45:361037 return audio;
1038 }
1039
deadbeef9d3584c2016-02-17 01:54:101040 // Creates a video content description with no streams, and some default
1041 // configuration.
1042 VideoContentDescription* CreateVideoContentDescription() {
1043 VideoContentDescription* video = new VideoContentDescription();
1044 video->AddCrypto(CryptoParams(
1045 1, "AES_CM_128_HMAC_SHA1_80",
1046 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", ""));
1047 video->set_protocol(cricket::kMediaProtocolSavpf);
1048 video->AddCodec(
1049 VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName,
1050 JsepSessionDescription::kMaxVideoCodecWidth,
1051 JsepSessionDescription::kMaxVideoCodecHeight,
deadbeef67cf2c12016-04-13 17:07:161052 JsepSessionDescription::kDefaultVideoCodecFramerate));
deadbeef9d3584c2016-02-17 01:54:101053 return video;
1054 }
1055
henrike@webrtc.org28e20752013-07-10 00:45:361056 template <class MCD>
1057 void CompareMediaContentDescription(const MCD* cd1,
1058 const MCD* cd2) {
1059 // type
1060 EXPECT_EQ(cd1->type(), cd1->type());
1061
1062 // content direction
1063 EXPECT_EQ(cd1->direction(), cd2->direction());
1064
1065 // rtcp_mux
1066 EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux());
1067
deadbeef13871492015-12-09 20:37:511068 // rtcp_reduced_size
1069 EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size());
1070
henrike@webrtc.org28e20752013-07-10 00:45:361071 // cryptos
1072 EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size());
1073 if (cd1->cryptos().size() != cd2->cryptos().size()) {
1074 ADD_FAILURE();
1075 return;
1076 }
1077 for (size_t i = 0; i< cd1->cryptos().size(); ++i) {
1078 const CryptoParams c1 = cd1->cryptos().at(i);
1079 const CryptoParams c2 = cd2->cryptos().at(i);
1080 EXPECT_TRUE(c1.Matches(c2));
1081 EXPECT_EQ(c1.key_params, c2.key_params);
1082 EXPECT_EQ(c1.session_params, c2.session_params);
1083 }
lally@webrtc.orgd7b61652015-02-24 20:18:551084
henrike@webrtc.org28e20752013-07-10 00:45:361085 // protocol
lally@webrtc.orgd7b61652015-02-24 20:18:551086 // Use an equivalence class here, for old and new versions of the
1087 // protocol description.
1088 if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:351089 || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1090 || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) {
1091 const bool cd2_is_also_dtls_sctp =
lally@webrtc.orgd7b61652015-02-24 20:18:551092 cd2->protocol() == cricket::kMediaProtocolDtlsSctp
lally@webrtc.org36300852015-02-24 20:19:351093 || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp
1094 || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp;
1095 EXPECT_TRUE(cd2_is_also_dtls_sctp);
lally@webrtc.orgd7b61652015-02-24 20:18:551096 } else {
1097 EXPECT_EQ(cd1->protocol(), cd2->protocol());
1098 }
henrike@webrtc.org28e20752013-07-10 00:45:361099
1100 // codecs
1101 EXPECT_EQ(cd1->codecs(), cd2->codecs());
1102
1103 // bandwidth
1104 EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth());
1105
1106 // streams
1107 EXPECT_EQ(cd1->streams(), cd2->streams());
1108
1109 // extmap
1110 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1111 cd2->rtp_header_extensions().size());
1112 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1113 const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i);
1114 const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i);
1115 EXPECT_EQ(ext1.uri, ext2.uri);
1116 EXPECT_EQ(ext1.id, ext2.id);
1117 }
henrike@webrtc.org28e20752013-07-10 00:45:361118 }
1119
1120
1121 void CompareSessionDescription(const SessionDescription& desc1,
1122 const SessionDescription& desc2) {
1123 // Compare content descriptions.
1124 if (desc1.contents().size() != desc2.contents().size()) {
1125 ADD_FAILURE();
1126 return;
1127 }
1128 for (size_t i = 0 ; i < desc1.contents().size(); ++i) {
1129 const cricket::ContentInfo& c1 = desc1.contents().at(i);
1130 const cricket::ContentInfo& c2 = desc2.contents().at(i);
1131 // content name
1132 EXPECT_EQ(c1.name, c2.name);
1133 // content type
1134 // Note, ASSERT will return from the function, but will not stop the test.
1135 ASSERT_EQ(c1.type, c2.type);
1136
1137 ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2));
1138 if (IsAudioContent(&c1)) {
1139 const AudioContentDescription* acd1 =
1140 static_cast<const AudioContentDescription*>(c1.description);
1141 const AudioContentDescription* acd2 =
1142 static_cast<const AudioContentDescription*>(c2.description);
1143 CompareMediaContentDescription<AudioContentDescription>(acd1, acd2);
1144 }
1145
1146 ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2));
1147 if (IsVideoContent(&c1)) {
1148 const VideoContentDescription* vcd1 =
1149 static_cast<const VideoContentDescription*>(c1.description);
1150 const VideoContentDescription* vcd2 =
1151 static_cast<const VideoContentDescription*>(c2.description);
1152 CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2);
1153 }
1154
1155 ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2));
1156 if (IsDataContent(&c1)) {
1157 const DataContentDescription* dcd1 =
1158 static_cast<const DataContentDescription*>(c1.description);
1159 const DataContentDescription* dcd2 =
1160 static_cast<const DataContentDescription*>(c2.description);
1161 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1162 }
1163 }
1164
1165 // group
1166 const cricket::ContentGroups groups1 = desc1.groups();
1167 const cricket::ContentGroups groups2 = desc2.groups();
1168 EXPECT_EQ(groups1.size(), groups1.size());
1169 if (groups1.size() != groups2.size()) {
1170 ADD_FAILURE();
1171 return;
1172 }
1173 for (size_t i = 0; i < groups1.size(); ++i) {
1174 const cricket::ContentGroup group1 = groups1.at(i);
1175 const cricket::ContentGroup group2 = groups2.at(i);
1176 EXPECT_EQ(group1.semantics(), group2.semantics());
1177 const cricket::ContentNames names1 = group1.content_names();
1178 const cricket::ContentNames names2 = group2.content_names();
1179 EXPECT_EQ(names1.size(), names2.size());
1180 if (names1.size() != names2.size()) {
1181 ADD_FAILURE();
1182 return;
1183 }
1184 cricket::ContentNames::const_iterator iter1 = names1.begin();
1185 cricket::ContentNames::const_iterator iter2 = names2.begin();
1186 while (iter1 != names1.end()) {
1187 EXPECT_EQ(*iter1++, *iter2++);
1188 }
1189 }
1190
1191 // transport info
1192 const cricket::TransportInfos transports1 = desc1.transport_infos();
1193 const cricket::TransportInfos transports2 = desc2.transport_infos();
1194 EXPECT_EQ(transports1.size(), transports2.size());
1195 if (transports1.size() != transports2.size()) {
1196 ADD_FAILURE();
1197 return;
1198 }
1199 for (size_t i = 0; i < transports1.size(); ++i) {
1200 const cricket::TransportInfo transport1 = transports1.at(i);
1201 const cricket::TransportInfo transport2 = transports2.at(i);
1202 EXPECT_EQ(transport1.content_name, transport2.content_name);
henrike@webrtc.org28e20752013-07-10 00:45:361203 EXPECT_EQ(transport1.description.ice_ufrag,
1204 transport2.description.ice_ufrag);
1205 EXPECT_EQ(transport1.description.ice_pwd,
1206 transport2.description.ice_pwd);
1207 if (transport1.description.identity_fingerprint) {
1208 EXPECT_EQ(*transport1.description.identity_fingerprint,
1209 *transport2.description.identity_fingerprint);
1210 } else {
1211 EXPECT_EQ(transport1.description.identity_fingerprint.get(),
1212 transport2.description.identity_fingerprint.get());
1213 }
1214 EXPECT_EQ(transport1.description.transport_options,
1215 transport2.description.transport_options);
henrike@webrtc.org28e20752013-07-10 00:45:361216 }
deadbeefc80741f2015-10-22 20:14:451217
1218 // global attributes
1219 EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported());
henrike@webrtc.org28e20752013-07-10 00:45:361220 }
1221
henrike@webrtc.org28e20752013-07-10 00:45:361222 bool CompareSessionDescription(
1223 const JsepSessionDescription& desc1,
1224 const JsepSessionDescription& desc2) {
1225 EXPECT_EQ(desc1.session_id(), desc2.session_id());
1226 EXPECT_EQ(desc1.session_version(), desc2.session_version());
1227 CompareSessionDescription(*desc1.description(), *desc2.description());
1228 if (desc1.number_of_mediasections() != desc2.number_of_mediasections())
1229 return false;
1230 for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) {
1231 const IceCandidateCollection* cc1 = desc1.candidates(i);
1232 const IceCandidateCollection* cc2 = desc2.candidates(i);
1233 if (cc1->count() != cc2->count())
1234 return false;
1235 for (size_t j = 0; j < cc1->count(); ++j) {
1236 const IceCandidateInterface* c1 = cc1->at(j);
1237 const IceCandidateInterface* c2 = cc2->at(j);
1238 EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid());
1239 EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index());
1240 EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate()));
1241 }
1242 }
1243 return true;
1244 }
1245
1246 // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing
1247 // them with invalid keywords so that the parser will just ignore them.
1248 bool RemoveCandidateUfragPwd(std::string* sdp) {
1249 const char ice_ufrag[] = "a=ice-ufrag";
1250 const char ice_ufragx[] = "a=xice-ufrag";
1251 const char ice_pwd[] = "a=ice-pwd";
1252 const char ice_pwdx[] = "a=xice-pwd";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521253 rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag),
henrike@webrtc.org28e20752013-07-10 00:45:361254 ice_ufragx, strlen(ice_ufragx), sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521255 rtc::replace_substrs(ice_pwd, strlen(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:361256 ice_pwdx, strlen(ice_pwdx), sdp);
1257 return true;
1258 }
1259
1260 // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|.
1261 bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index,
1262 const std::string& ufrag, const std::string& pwd) {
1263 std::string content_name;
1264 if (mline_index == 0) {
1265 content_name = kAudioContentName;
1266 } else if (mline_index == 1) {
1267 content_name = kVideoContentName;
1268 } else {
1269 ASSERT(false);
1270 }
1271 TransportInfo transport_info(
Peter Thatcher7cbd1882015-09-18 01:54:521272 content_name, TransportDescription(ufrag, pwd));
henrike@webrtc.org28e20752013-07-10 00:45:361273 SessionDescription* desc =
1274 const_cast<SessionDescription*>(jdesc->description());
1275 desc->RemoveTransportInfoByName(content_name);
1276 EXPECT_TRUE(desc->AddTransportInfo(transport_info));
1277 for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) {
1278 const IceCandidateCollection* cc = jdesc_.candidates(i);
1279 for (size_t j = 0; j < cc->count(); ++j) {
1280 if (cc->at(j)->sdp_mline_index() == mline_index) {
1281 const_cast<Candidate&>(cc->at(j)->candidate()).set_username(
1282 ufrag);
1283 const_cast<Candidate&>(cc->at(j)->candidate()).set_password(
1284 pwd);
1285 }
1286 }
1287 }
1288 return true;
1289 }
1290
1291 void AddIceOptions(const std::string& content_name,
1292 const std::vector<std::string>& transport_options) {
1293 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1294 cricket::TransportInfo transport_info =
1295 *(desc_.GetTransportInfoByName(content_name));
1296 desc_.RemoveTransportInfoByName(content_name);
1297 transport_info.description.transport_options = transport_options;
1298 desc_.AddTransportInfo(transport_info);
1299 }
1300
deadbeef3f7219b2015-12-28 23:17:141301 void SetIceUfragPwd(const std::string& content_name,
1302 const std::string& ice_ufrag,
1303 const std::string& ice_pwd) {
1304 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL);
1305 cricket::TransportInfo transport_info =
1306 *(desc_.GetTransportInfoByName(content_name));
1307 desc_.RemoveTransportInfoByName(content_name);
1308 transport_info.description.ice_ufrag = ice_ufrag;
1309 transport_info.description.ice_pwd = ice_pwd;
1310 desc_.AddTransportInfo(transport_info);
1311 }
1312
henrike@webrtc.org28e20752013-07-10 00:45:361313 void AddFingerprint() {
1314 desc_.RemoveTransportInfoByName(kAudioContentName);
1315 desc_.RemoveTransportInfoByName(kVideoContentName);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521316 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1,
henrike@webrtc.org28e20752013-07-10 00:45:361317 kIdentityDigest,
1318 sizeof(kIdentityDigest));
deadbeef46eed762016-01-28 21:24:371319 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1320 kAudioContentName,
deadbeef9d3584c2016-02-17 01:54:101321 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1322 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 21:24:371323 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1324 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1325 kVideoContentName,
deadbeef9d3584c2016-02-17 01:54:101326 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1327 cricket::ICEMODE_FULL,
deadbeef46eed762016-01-28 21:24:371328 cricket::CONNECTIONROLE_NONE, &fingerprint))));
henrike@webrtc.org28e20752013-07-10 00:45:361329 }
1330
1331 void AddExtmap() {
1332 audio_desc_ = static_cast<AudioContentDescription*>(
1333 audio_desc_->Copy());
1334 video_desc_ = static_cast<VideoContentDescription*>(
1335 video_desc_->Copy());
1336 audio_desc_->AddRtpHeaderExtension(
1337 RtpHeaderExtension(kExtmapUri, kExtmapId));
1338 video_desc_->AddRtpHeaderExtension(
1339 RtpHeaderExtension(kExtmapUri, kExtmapId));
1340 desc_.RemoveContentByName(kAudioContentName);
1341 desc_.RemoveContentByName(kVideoContentName);
1342 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1343 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1344 }
1345
1346 void RemoveCryptos() {
1347 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1348 video_desc_->set_cryptos(std::vector<CryptoParams>());
1349 }
1350
1351 bool TestSerializeDirection(cricket::MediaContentDirection direction) {
1352 audio_desc_->set_direction(direction);
1353 video_desc_->set_direction(direction);
1354 std::string new_sdp = kSdpFullString;
1355 ReplaceDirection(direction, &new_sdp);
1356
1357 if (!jdesc_.Initialize(desc_.Copy(),
1358 jdesc_.session_id(),
1359 jdesc_.session_version())) {
1360 return false;
1361 }
deadbeef9d3584c2016-02-17 01:54:101362 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361363 EXPECT_EQ(new_sdp, message);
1364 return true;
1365 }
1366
1367 bool TestSerializeRejected(bool audio_rejected, bool video_rejected) {
1368 audio_desc_ = static_cast<AudioContentDescription*>(
1369 audio_desc_->Copy());
1370 video_desc_ = static_cast<VideoContentDescription*>(
1371 video_desc_->Copy());
1372 desc_.RemoveContentByName(kAudioContentName);
1373 desc_.RemoveContentByName(kVideoContentName);
1374 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1375 audio_desc_);
1376 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1377 video_desc_);
deadbeef9d3584c2016-02-17 01:54:101378 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1379 audio_rejected ? "" : kPwdVoice);
1380 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1381 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141382
1383 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361384 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1385
deadbeef3f7219b2015-12-28 23:17:141386 JsepSessionDescription jdesc_no_candidates(kDummyString);
1387 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1388 kSessionVersion)) {
henrike@webrtc.org28e20752013-07-10 00:45:361389 return false;
1390 }
deadbeef9d3584c2016-02-17 01:54:101391 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:361392 EXPECT_EQ(new_sdp, message);
1393 return true;
1394 }
1395
1396 void AddSctpDataChannel() {
kwibergd1fe2812016-04-27 13:47:291397 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361398 data_desc_ = data.get();
1399 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp);
wu@webrtc.org78187522013-10-07 23:32:021400 DataCodec codec(cricket::kGoogleSctpDataCodecId,
deadbeef67cf2c12016-04-13 17:07:161401 cricket::kGoogleSctpDataCodecName);
wu@webrtc.org78187522013-10-07 23:32:021402 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort);
1403 data_desc_->AddCodec(codec);
henrike@webrtc.org28e20752013-07-10 00:45:361404 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release());
deadbeef9d3584c2016-02-17 01:54:101405 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1406 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:361407 }
1408
1409 void AddRtpDataChannel() {
kwibergd1fe2812016-04-27 13:47:291410 std::unique_ptr<DataContentDescription> data(new DataContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:361411 data_desc_ = data.get();
1412
deadbeef67cf2c12016-04-13 17:07:161413 data_desc_->AddCodec(DataCodec(101, "google-data"));
henrike@webrtc.org28e20752013-07-10 00:45:361414 StreamParams data_stream;
1415 data_stream.id = kDataChannelMsid;
1416 data_stream.cname = kDataChannelCname;
1417 data_stream.sync_label = kDataChannelLabel;
1418 data_stream.ssrcs.push_back(kDataChannelSsrc);
1419 data_desc_->AddStream(data_stream);
1420 data_desc_->AddCrypto(CryptoParams(
1421 1, "AES_CM_128_HMAC_SHA1_80",
1422 "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", ""));
1423 data_desc_->set_protocol(cricket::kMediaProtocolSavpf);
1424 desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release());
deadbeef9d3584c2016-02-17 01:54:101425 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1426 kDataContentName, TransportDescription(kUfragData, kPwdData))));
henrike@webrtc.org28e20752013-07-10 00:45:361427 }
1428
1429 bool TestDeserializeDirection(cricket::MediaContentDirection direction) {
1430 std::string new_sdp = kSdpFullString;
1431 ReplaceDirection(direction, &new_sdp);
1432 JsepSessionDescription new_jdesc(kDummyString);
1433
1434 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
1435
1436 audio_desc_->set_direction(direction);
1437 video_desc_->set_direction(direction);
1438 if (!jdesc_.Initialize(desc_.Copy(),
1439 jdesc_.session_id(),
1440 jdesc_.session_version())) {
1441 return false;
1442 }
1443 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc));
1444 return true;
1445 }
1446
1447 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) {
deadbeef3f7219b2015-12-28 23:17:141448 std::string new_sdp = kSdpString;
henrike@webrtc.org28e20752013-07-10 00:45:361449 ReplaceRejected(audio_rejected, video_rejected, &new_sdp);
1450 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:361451 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc));
deadbeef3f7219b2015-12-28 23:17:141452
henrike@webrtc.org28e20752013-07-10 00:45:361453 audio_desc_ = static_cast<AudioContentDescription*>(
1454 audio_desc_->Copy());
1455 video_desc_ = static_cast<VideoContentDescription*>(
1456 video_desc_->Copy());
1457 desc_.RemoveContentByName(kAudioContentName);
1458 desc_.RemoveContentByName(kVideoContentName);
1459 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected,
1460 audio_desc_);
1461 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected,
1462 video_desc_);
deadbeef9d3584c2016-02-17 01:54:101463 SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice,
1464 audio_rejected ? "" : kPwdVoice);
1465 SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo,
1466 video_rejected ? "" : kPwdVideo);
deadbeef3f7219b2015-12-28 23:17:141467 JsepSessionDescription jdesc_no_candidates(kDummyString);
1468 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1469 jdesc_.session_version())) {
henrike@webrtc.org28e20752013-07-10 00:45:361470 return false;
1471 }
deadbeef3f7219b2015-12-28 23:17:141472 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
henrike@webrtc.org28e20752013-07-10 00:45:361473 return true;
1474 }
1475
1476 void TestDeserializeExtmap(bool session_level, bool media_level) {
1477 AddExtmap();
1478 JsepSessionDescription new_jdesc("dummy");
1479 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1480 jdesc_.session_id(),
1481 jdesc_.session_version()));
1482 JsepSessionDescription jdesc_with_extmap("dummy");
1483 std::string sdp_with_extmap = kSdpString;
1484 if (session_level) {
1485 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute,
1486 &sdp_with_extmap);
1487 }
1488 if (media_level) {
1489 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute,
1490 &sdp_with_extmap);
1491 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute,
1492 &sdp_with_extmap);
1493 }
1494 // The extmap can't be present at the same time in both session level and
1495 // media level.
1496 if (session_level && media_level) {
1497 SdpParseError error;
1498 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1499 &jdesc_with_extmap, &error));
1500 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1501 } else {
1502 EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap));
1503 EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc));
1504 }
1505 }
1506
1507 void VerifyCodecParameter(const cricket::CodecParameterMap& params,
1508 const std::string& name, int expected_value) {
1509 cricket::CodecParameterMap::const_iterator found = params.find(name);
1510 ASSERT_TRUE(found != params.end());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:521511 EXPECT_EQ(found->second, rtc::ToString<int>(expected_value));
henrike@webrtc.org28e20752013-07-10 00:45:361512 }
1513
1514 void TestDeserializeCodecParams(const CodecParams& params,
1515 JsepSessionDescription* jdesc_output) {
1516 std::string sdp =
1517 "v=0\r\n"
1518 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1519 "s=-\r\n"
1520 "t=0 0\r\n"
1521 // Include semantics for WebRTC Media Streams since it is supported by
1522 // this parser, and will be added to the SDP when serializing a session
1523 // description.
1524 "a=msid-semantic: WMS\r\n"
1525 // Pl type 111 preferred.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411526 "m=audio 9 RTP/SAVPF 111 104 103\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361527 // Pltype 111 listed before 103 and 104 in the map.
1528 "a=rtpmap:111 opus/48000/2\r\n"
1529 // Pltype 103 listed before 104.
1530 "a=rtpmap:103 ISAC/16000\r\n"
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:411531 "a=rtpmap:104 ISAC/32000\r\n"
mallinath@webrtc.orga5506692013-08-12 21:18:151532 "a=fmtp:111 0-15,66,70\r\n"
1533 "a=fmtp:111 ";
henrike@webrtc.org28e20752013-07-10 00:45:361534 std::ostringstream os;
Donald Curtis144d0182015-05-15 20:14:241535 os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo
mallinath@webrtc.orga5506692013-08-12 21:18:151536 << "; sprop-stereo=" << params.sprop_stereo
1537 << "; useinbandfec=" << params.useinband
Donald Curtis0e07f922015-05-15 16:21:231538 << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:361539 << "a=ptime:" << params.ptime << "\r\n"
1540 << "a=maxptime:" << params.max_ptime << "\r\n";
1541 sdp += os.str();
1542
stefan@webrtc.org85d27942014-06-09 12:51:391543 os.clear();
1544 os.str("");
1545 // Pl type 100 preferred.
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221546 os << "m=video 9 RTP/SAVPF 99 95\r\n"
stefan@webrtc.org85d27942014-06-09 12:51:391547 << "a=rtpmap:99 VP8/90000\r\n"
1548 << "a=rtpmap:95 RTX/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:231549 << "a=fmtp:95 apt=99;\r\n";
stefan@webrtc.org85d27942014-06-09 12:51:391550 sdp += os.str();
1551
henrike@webrtc.org28e20752013-07-10 00:45:361552 // Deserialize
1553 SdpParseError error;
1554 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1555
1556 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1557 ASSERT_TRUE(ac != NULL);
1558 const AudioContentDescription* acd =
1559 static_cast<const AudioContentDescription*>(ac->description);
1560 ASSERT_FALSE(acd->codecs().empty());
1561 cricket::AudioCodec opus = acd->codecs()[0];
1562 EXPECT_EQ("opus", opus.name);
1563 EXPECT_EQ(111, opus.id);
1564 VerifyCodecParameter(opus.params, "minptime", params.min_ptime);
1565 VerifyCodecParameter(opus.params, "stereo", params.stereo);
1566 VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo);
1567 VerifyCodecParameter(opus.params, "useinbandfec", params.useinband);
henrike@webrtc.org1e09a712013-07-26 19:17:591568 VerifyCodecParameter(opus.params, "maxaveragebitrate",
1569 params.maxaveragebitrate);
henrike@webrtc.org28e20752013-07-10 00:45:361570 for (size_t i = 0; i < acd->codecs().size(); ++i) {
1571 cricket::AudioCodec codec = acd->codecs()[i];
1572 VerifyCodecParameter(codec.params, "ptime", params.ptime);
1573 VerifyCodecParameter(codec.params, "maxptime", params.max_ptime);
1574 if (codec.name == "ISAC") {
1575 if (codec.clockrate == 16000) {
1576 EXPECT_EQ(32000, codec.bitrate);
1577 } else {
1578 EXPECT_EQ(56000, codec.bitrate);
1579 }
1580 }
1581 }
stefan@webrtc.org85d27942014-06-09 12:51:391582
1583 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1584 ASSERT_TRUE(vc != NULL);
1585 const VideoContentDescription* vcd =
1586 static_cast<const VideoContentDescription*>(vc->description);
1587 ASSERT_FALSE(vcd->codecs().empty());
1588 cricket::VideoCodec vp8 = vcd->codecs()[0];
1589 EXPECT_EQ("VP8", vp8.name);
1590 EXPECT_EQ(99, vp8.id);
1591 cricket::VideoCodec rtx = vcd->codecs()[1];
1592 EXPECT_EQ("RTX", rtx.name);
1593 EXPECT_EQ(95, rtx.id);
1594 VerifyCodecParameter(rtx.params, "apt", vp8.id);
henrike@webrtc.org28e20752013-07-10 00:45:361595 }
1596
1597 void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output,
1598 bool use_wildcard) {
jlmiller@webrtc.orga744a282015-02-18 21:37:461599 std::string sdp_session_and_audio =
henrike@webrtc.org28e20752013-07-10 00:45:361600 "v=0\r\n"
1601 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
1602 "s=-\r\n"
1603 "t=0 0\r\n"
1604 // Include semantics for WebRTC Media Streams since it is supported by
1605 // this parser, and will be added to the SDP when serializing a session
1606 // description.
1607 "a=msid-semantic: WMS\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:221608 "m=audio 9 RTP/SAVPF 111\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461609 "a=rtpmap:111 opus/48000/2\r\n";
1610 std::string sdp_video =
henrike@webrtc.org28e20752013-07-10 00:45:361611 "m=video 3457 RTP/SAVPF 101\r\n"
1612 "a=rtpmap:101 VP8/90000\r\n"
1613 "a=rtcp-fb:101 nack\r\n"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:581614 "a=rtcp-fb:101 nack pli\r\n"
jlmiller@webrtc.orga744a282015-02-18 21:37:461615 "a=rtcp-fb:101 goog-remb\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:361616 std::ostringstream os;
jlmiller@webrtc.orga744a282015-02-18 21:37:461617 os << sdp_session_and_audio;
1618 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n";
1619 os << sdp_video;
henrike@webrtc.org28e20752013-07-10 00:45:361620 os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n";
jlmiller@webrtc.orga744a282015-02-18 21:37:461621 std::string sdp = os.str();
henrike@webrtc.org28e20752013-07-10 00:45:361622 // Deserialize
1623 SdpParseError error;
1624 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));
1625 const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description());
1626 ASSERT_TRUE(ac != NULL);
1627 const AudioContentDescription* acd =
1628 static_cast<const AudioContentDescription*>(ac->description);
1629 ASSERT_FALSE(acd->codecs().empty());
1630 cricket::AudioCodec opus = acd->codecs()[0];
1631 EXPECT_EQ(111, opus.id);
1632 EXPECT_TRUE(opus.HasFeedbackParam(
1633 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1634 cricket::kParamValueEmpty)));
1635
1636 const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description());
1637 ASSERT_TRUE(vc != NULL);
1638 const VideoContentDescription* vcd =
1639 static_cast<const VideoContentDescription*>(vc->description);
1640 ASSERT_FALSE(vcd->codecs().empty());
1641 cricket::VideoCodec vp8 = vcd->codecs()[0];
1642 EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName,
1643 vp8.name.c_str());
1644 EXPECT_EQ(101, vp8.id);
1645 EXPECT_TRUE(vp8.HasFeedbackParam(
1646 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1647 cricket::kParamValueEmpty)));
1648 EXPECT_TRUE(vp8.HasFeedbackParam(
henrika@webrtc.orgaebb1ad2014-01-14 10:00:581649 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1650 cricket::kRtcpFbNackParamPli)));
1651 EXPECT_TRUE(vp8.HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:361652 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1653 cricket::kParamValueEmpty)));
1654 EXPECT_TRUE(vp8.HasFeedbackParam(
1655 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1656 cricket::kRtcpFbCcmParamFir)));
1657 }
1658
1659 // Two SDP messages can mean the same thing but be different strings, e.g.
1660 // some of the lines can be serialized in different order.
1661 // However, a deserialized description can be compared field by field and has
1662 // no order. If deserializer has already been tested, serializing then
1663 // deserializing and comparing JsepSessionDescription will test
1664 // the serializer sufficiently.
deadbeef9d3584c2016-02-17 01:54:101665 void TestSerialize(const JsepSessionDescription& jdesc,
1666 bool unified_plan_sdp) {
1667 std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp);
henrike@webrtc.org28e20752013-07-10 00:45:361668 JsepSessionDescription jdesc_output_des(kDummyString);
1669 SdpParseError error;
1670 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error));
1671 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des));
1672 }
1673
1674 protected:
1675 SessionDescription desc_;
1676 AudioContentDescription* audio_desc_;
1677 VideoContentDescription* video_desc_;
1678 DataContentDescription* data_desc_;
1679 Candidates candidates_;
kwibergd1fe2812016-04-27 13:47:291680 std::unique_ptr<IceCandidateInterface> jcandidate_;
henrike@webrtc.org28e20752013-07-10 00:45:361681 JsepSessionDescription jdesc_;
1682};
1683
1684void TestMismatch(const std::string& string1, const std::string& string2) {
1685 int position = 0;
1686 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
1687 if (string1.c_str()[i] != string2.c_str()[i]) {
henrike@webrtc.org28654cb2013-07-22 21:07:491688 position = static_cast<int>(i);
henrike@webrtc.org28e20752013-07-10 00:45:361689 break;
1690 }
1691 }
1692 EXPECT_EQ(0, position) << "Strings mismatch at the " << position
1693 << " character\n"
1694 << " 1: " << string1.substr(position, 20) << "\n"
1695 << " 2: " << string2.substr(position, 20) << "\n";
1696}
1697
henrike@webrtc.org28e20752013-07-10 00:45:361698TEST_F(WebRtcSdpTest, SerializeSessionDescription) {
1699 // SessionDescription with desc and candidates.
deadbeef9d3584c2016-02-17 01:54:101700 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361701 TestMismatch(std::string(kSdpFullString), message);
1702}
1703
1704TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) {
1705 JsepSessionDescription jdesc_empty(kDummyString);
deadbeef9d3584c2016-02-17 01:54:101706 EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false));
henrike@webrtc.org28e20752013-07-10 00:45:361707}
1708
guoweis@webrtc.org57ac2c82015-02-06 00:45:131709// This tests serialization of SDP with only IPv6 candidates and verifies that
1710// IPv6 is used as default address in c line according to preference.
1711TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) {
1712 // Only test 1 m line.
1713 desc_.RemoveContentByName("video_content_name");
1714 // Stun has a high preference than local host.
1715 cricket::Candidate candidate1(
1716 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1717 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1718 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1719 cricket::Candidate candidate2(
1720 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1721 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1722 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1723 JsepSessionDescription jdesc(kDummyString);
1724 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1725
1726 // Only add the candidates to audio m line.
1727 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1728 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1729 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1730 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-17 01:54:101731 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:131732
1733 // Audio line should have a c line like this one.
1734 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
1735 // Shouldn't have a IP4 c line.
1736 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1737}
1738
1739// This tests serialization of SDP with both IPv4 and IPv6 candidates and
1740// verifies that IPv4 is used as default address in c line even if the
1741// preference of IPv4 is lower.
1742TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) {
1743 // Only test 1 m line.
1744 desc_.RemoveContentByName("video_content_name");
1745 cricket::Candidate candidate_v4(
1746 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1747 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
1748 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1749 cricket::Candidate candidate_v6(
1750 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1751 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1752 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1753 JsepSessionDescription jdesc(kDummyString);
1754 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1755
1756 // Only add the candidates to audio m line.
1757 JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4);
1758 JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6);
1759 ASSERT_TRUE(jdesc.AddCandidate(&jice_v4));
1760 ASSERT_TRUE(jdesc.AddCandidate(&jice_v6));
deadbeef9d3584c2016-02-17 01:54:101761 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:131762
1763 // Audio line should have a c line like this one.
1764 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
1765 // Shouldn't have a IP6 c line.
1766 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
1767}
1768
1769// This tests serialization of SDP with both UDP and TCP candidates and
1770// verifies that UDP is used as default address in c line even if the
1771// preference of UDP is lower.
1772TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) {
1773 // Only test 1 m line.
1774 desc_.RemoveContentByName("video_content_name");
1775 // Stun has a high preference than local host.
1776 cricket::Candidate candidate1(
1777 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1778 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1779 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1780 cricket::Candidate candidate2(
1781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
1782 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
1783 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
1784 kCandidateFoundation1);
1785 JsepSessionDescription jdesc(kDummyString);
1786 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1787
1788 // Only add the candidates to audio m line.
1789 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1790 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1791 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1792 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-17 01:54:101793 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:131794
1795 // Audio line should have a c line like this one.
1796 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
1797 std::string::npos);
1798 // Shouldn't have a IP4 c line.
1799 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
1800}
1801
1802// This tests serialization of SDP with only TCP candidates and verifies that
1803// null IPv4 is used as default address in c line.
1804TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) {
1805 // Only test 1 m line.
1806 desc_.RemoveContentByName("video_content_name");
1807 // Stun has a high preference than local host.
1808 cricket::Candidate candidate1(
1809 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1810 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
1811 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1812 cricket::Candidate candidate2(
1813 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
1814 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
1815 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
1816 JsepSessionDescription jdesc(kDummyString);
1817 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1818
1819 // Only add the candidates to audio m line.
1820 JsepIceCandidate jice1("audio_content_name", 0, candidate1);
1821 JsepIceCandidate jice2("audio_content_name", 0, candidate2);
1822 ASSERT_TRUE(jdesc.AddCandidate(&jice1));
1823 ASSERT_TRUE(jdesc.AddCandidate(&jice2));
deadbeef9d3584c2016-02-17 01:54:101824 std::string message = webrtc::SdpSerialize(jdesc, false);
guoweis@webrtc.org57ac2c82015-02-06 00:45:131825
1826 // Audio line should have a c line like this one when no any default exists.
1827 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
1828}
1829
henrike@webrtc.org28e20752013-07-10 00:45:361830// This tests serialization of SDP with a=crypto and a=fingerprint, as would be
1831// the case in a DTLS offer.
1832TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) {
1833 AddFingerprint();
1834 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1835 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1836 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-17 01:54:101837 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:361838
1839 std::string sdp_with_fingerprint = kSdpString;
1840 InjectAfter(kAttributeIcePwdVoice,
1841 kFingerprint, &sdp_with_fingerprint);
1842 InjectAfter(kAttributeIcePwdVideo,
1843 kFingerprint, &sdp_with_fingerprint);
1844
1845 EXPECT_EQ(sdp_with_fingerprint, message);
1846}
1847
1848// This tests serialization of SDP with a=fingerprint with no a=crypto, as would
1849// be the case in a DTLS answer.
1850TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) {
1851 AddFingerprint();
1852 RemoveCryptos();
1853 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
1854 ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(),
1855 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-17 01:54:101856 std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false);
henrike@webrtc.org28e20752013-07-10 00:45:361857
1858 std::string sdp_with_fingerprint = kSdpString;
1859 Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint);
1860 Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint);
1861 InjectAfter(kAttributeIcePwdVoice,
1862 kFingerprint, &sdp_with_fingerprint);
1863 InjectAfter(kAttributeIcePwdVideo,
1864 kFingerprint, &sdp_with_fingerprint);
1865
1866 EXPECT_EQ(sdp_with_fingerprint, message);
1867}
1868
1869TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) {
1870 // JsepSessionDescription with desc but without candidates.
1871 JsepSessionDescription jdesc_no_candidates(kDummyString);
deadbeef3f7219b2015-12-28 23:17:141872 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId,
1873 kSessionVersion));
deadbeef9d3584c2016-02-17 01:54:101874 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false);
henrike@webrtc.org28e20752013-07-10 00:45:361875 EXPECT_EQ(std::string(kSdpString), message);
1876}
1877
1878TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) {
1879 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
1880 group.AddContentName(kAudioContentName);
1881 group.AddContentName(kVideoContentName);
1882 desc_.AddGroup(group);
1883 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1884 jdesc_.session_id(),
1885 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101886 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361887 std::string sdp_with_bundle = kSdpFullString;
1888 InjectAfter(kSessionTime,
1889 "a=group:BUNDLE audio_content_name video_content_name\r\n",
1890 &sdp_with_bundle);
1891 EXPECT_EQ(sdp_with_bundle, message);
1892}
1893
1894TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) {
1895 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
1896 GetFirstVideoContent(&desc_)->description);
1897 vcd->set_bandwidth(100 * 1000);
1898 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
1899 GetFirstAudioContent(&desc_)->description);
1900 acd->set_bandwidth(50 * 1000);
1901 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1902 jdesc_.session_id(),
1903 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101904 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361905 std::string sdp_with_bandwidth = kSdpFullString;
wu@webrtc.org4c3e9912014-07-16 21:03:131906 InjectAfter("c=IN IP4 74.125.224.39\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:361907 "b=AS:100\r\n",
1908 &sdp_with_bandwidth);
wu@webrtc.org4c3e9912014-07-16 21:03:131909 InjectAfter("c=IN IP4 74.125.127.126\r\n",
henrike@webrtc.org28e20752013-07-10 00:45:361910 "b=AS:50\r\n",
1911 &sdp_with_bandwidth);
1912 EXPECT_EQ(sdp_with_bandwidth, message);
1913}
1914
1915TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) {
1916 std::vector<std::string> transport_options;
1917 transport_options.push_back(kIceOption1);
1918 transport_options.push_back(kIceOption3);
1919 AddIceOptions(kAudioContentName, transport_options);
1920 transport_options.clear();
1921 transport_options.push_back(kIceOption2);
1922 transport_options.push_back(kIceOption3);
1923 AddIceOptions(kVideoContentName, transport_options);
1924 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
1925 jdesc_.session_id(),
1926 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:101927 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:361928 std::string sdp_with_ice_options = kSdpFullString;
1929 InjectAfter(kAttributeIcePwdVoice,
1930 "a=ice-options:iceoption1 iceoption3\r\n",
1931 &sdp_with_ice_options);
1932 InjectAfter(kAttributeIcePwdVideo,
1933 "a=ice-options:iceoption2 iceoption3\r\n",
1934 &sdp_with_ice_options);
1935 EXPECT_EQ(sdp_with_ice_options, message);
1936}
1937
1938TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) {
1939 EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY));
1940}
1941
1942TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) {
1943 EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY));
1944}
1945
1946TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) {
1947 EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE));
1948}
1949
1950TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) {
1951 EXPECT_TRUE(TestSerializeRejected(true, false));
1952}
1953
1954TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) {
1955 EXPECT_TRUE(TestSerializeRejected(false, true));
1956}
1957
1958TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) {
1959 EXPECT_TRUE(TestSerializeRejected(true, true));
1960}
1961
1962TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) {
1963 AddRtpDataChannel();
1964 JsepSessionDescription jsep_desc(kDummyString);
1965
1966 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-17 01:54:101967 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:361968
1969 std::string expected_sdp = kSdpString;
1970 expected_sdp.append(kSdpRtpDataChannelString);
1971 EXPECT_EQ(expected_sdp, message);
1972}
1973
1974TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) {
1975 AddSctpDataChannel();
1976 JsepSessionDescription jsep_desc(kDummyString);
1977
1978 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-17 01:54:101979 std::string message = webrtc::SdpSerialize(jsep_desc, false);
henrike@webrtc.org28e20752013-07-10 00:45:361980
1981 std::string expected_sdp = kSdpString;
1982 expected_sdp.append(kSdpSctpDataChannelString);
1983 EXPECT_EQ(message, expected_sdp);
1984}
1985
jiayl@webrtc.org9c16c392014-05-01 18:30:301986TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) {
1987 AddSctpDataChannel();
1988 JsepSessionDescription jsep_desc(kDummyString);
1989
1990 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
1991 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
1992 jsep_desc.description()->GetContentDescriptionByName(kDataContentName));
1993
1994 const int kNewPort = 1234;
deadbeef67cf2c12016-04-13 17:07:161995 cricket::DataCodec codec(cricket::kGoogleSctpDataCodecId,
1996 cricket::kGoogleSctpDataCodecName);
jiayl@webrtc.org9c16c392014-05-01 18:30:301997 codec.SetParam(cricket::kCodecParamPort, kNewPort);
1998 dcdesc->AddOrReplaceCodec(codec);
1999
deadbeef9d3584c2016-02-17 01:54:102000 std::string message = webrtc::SdpSerialize(jsep_desc, false);
jiayl@webrtc.org9c16c392014-05-01 18:30:302001
2002 std::string expected_sdp = kSdpString;
2003 expected_sdp.append(kSdpSctpDataChannelString);
2004
2005 char default_portstr[16];
2006 char new_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:522007 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
jiayl@webrtc.org9c16c392014-05-01 18:30:302008 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:522009 rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort);
2010 rtc::replace_substrs(default_portstr, strlen(default_portstr),
jiayl@webrtc.org9c16c392014-05-01 18:30:302011 new_portstr, strlen(new_portstr),
2012 &expected_sdp);
2013
2014 EXPECT_EQ(expected_sdp, message);
2015}
2016
wu@webrtc.orgcadf9042013-08-30 21:24:162017TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) {
2018 AddRtpDataChannel();
2019 data_desc_->set_bandwidth(100*1000);
2020 JsepSessionDescription jsep_desc(kDummyString);
2021
2022 ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-17 01:54:102023 std::string message = webrtc::SdpSerialize(jsep_desc, false);
wu@webrtc.orgcadf9042013-08-30 21:24:162024
2025 std::string expected_sdp = kSdpString;
2026 expected_sdp.append(kSdpRtpDataChannelString);
Peter Thatcherc0c3a862015-06-24 22:31:252027 // Serializing data content shouldn't ignore bandwidth settings.
perkj@webrtc.orgd105cc82014-11-07 11:22:062028 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
sergeyu@chromium.orga59696b2013-09-13 23:48:582029 "b=AS:100\r\n",
2030 &expected_sdp);
2031 EXPECT_EQ(expected_sdp, message);
wu@webrtc.orgcadf9042013-08-30 21:24:162032}
2033
henrike@webrtc.org28e20752013-07-10 00:45:362034TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2035 AddExtmap();
2036 JsepSessionDescription desc_with_extmap("dummy");
2037 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2038 kSessionId, kSessionVersion));
deadbeef9d3584c2016-02-17 01:54:102039 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
henrike@webrtc.org28e20752013-07-10 00:45:362040
2041 std::string sdp_with_extmap = kSdpString;
2042 InjectAfter("a=mid:audio_content_name\r\n",
2043 kExtmap, &sdp_with_extmap);
2044 InjectAfter("a=mid:video_content_name\r\n",
2045 kExtmap, &sdp_with_extmap);
2046
2047 EXPECT_EQ(sdp_with_extmap, message);
2048}
2049
henrike@webrtc.org28e20752013-07-10 00:45:362050TEST_F(WebRtcSdpTest, SerializeCandidates) {
2051 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
wu@webrtc.orgec9f5fb2014-06-24 17:05:102052 EXPECT_EQ(std::string(kRawCandidate), message);
honghaiza54a0802015-12-17 02:37:232053
2054 Candidate candidate_with_ufrag(candidates_.front());
2055 candidate_with_ufrag.set_username("ABC");
2056 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2057 candidate_with_ufrag));
2058 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2059 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
honghaiza0c44ea2016-03-23 23:07:482060
2061 Candidate candidate_with_network_info(candidates_.front());
2062 candidate_with_network_info.set_network_id(1);
2063 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2064 candidate_with_network_info));
2065 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2066 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
2067 candidate_with_network_info.set_network_cost(999);
2068 jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
2069 candidate_with_network_info));
2070 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2071 EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
2072 message);
henrike@webrtc.org28e20752013-07-10 00:45:362073}
2074
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202075// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
2076// RFC 6544.
mallinath@webrtc.orge999bd02014-08-13 06:05:552077TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
guoweis@webrtc.org61c12472015-01-15 06:53:072078 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312079 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2080 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2081 kCandidateFoundation1);
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202082 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
kwibergd1fe2812016-04-27 13:47:292083 std::unique_ptr<IceCandidateInterface> jcandidate(
2084 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202085
2086 std::string message = webrtc::SdpSerializeCandidate(*jcandidate);
2087 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message);
2088}
2089
htaa6b99442016-04-12 17:29:172090TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) {
2091 if (!webrtc::H264Encoder::IsSupported())
2092 return;
2093 for (const auto& codec : cricket::DefaultVideoCodecList()) {
2094 video_desc_->AddCodec(codec);
2095 }
2096 jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion);
2097
2098 std::string message = webrtc::SdpSerialize(jdesc_, false);
2099 size_t after_pt = message.find(" H264/90000");
2100 ASSERT_NE(after_pt, std::string::npos);
2101 size_t before_pt = message.rfind("a=rtpmap:", after_pt);
2102 ASSERT_NE(before_pt, std::string::npos);
2103 before_pt += strlen("a=rtpmap:");
2104 std::string pt = message.substr(before_pt, after_pt - before_pt);
2105 // TODO(hta): Check if payload type |pt| occurs in the m=video line.
2106 std::string to_find = "a=fmtp:" + pt + " ";
2107 size_t fmtp_pos = message.find(to_find);
2108 ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find;
2109 size_t fmtp_endpos = message.find("\n", fmtp_pos);
2110 ASSERT_NE(std::string::npos, fmtp_endpos);
2111 std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos);
2112 EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1"));
2113 EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1"));
2114 EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f"));
hta62a216e2016-04-15 18:02:142115 // Check that there are no spaces after semicolons.
2116 // https://bugs.webrtc.org/5793
2117 EXPECT_EQ(std::string::npos, fmtp_value.find("; "));
htaa6b99442016-04-12 17:29:172118}
2119
henrike@webrtc.org28e20752013-07-10 00:45:362120TEST_F(WebRtcSdpTest, DeserializeSessionDescription) {
2121 JsepSessionDescription jdesc(kDummyString);
2122 // Deserialize
2123 EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc));
2124 // Verify
2125 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2126}
2127
wu@webrtc.orgcecfd182013-10-30 05:18:122128TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) {
2129 JsepSessionDescription jdesc(kDummyString);
2130 const char kSdpWithoutMline[] =
2131 "v=0\r\n"
2132 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2133 "s=-\r\n"
2134 "t=0 0\r\n"
2135 "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n";
2136 // Deserialize
2137 EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc));
2138 EXPECT_EQ(0u, jdesc.description()->contents().size());
2139}
2140
henrike@webrtc.org28e20752013-07-10 00:45:362141TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) {
2142 JsepSessionDescription jdesc(kDummyString);
2143 std::string sdp_without_carriage_return = kSdpFullString;
2144 Replace("\r\n", "\n", &sdp_without_carriage_return);
2145 // Deserialize
2146 EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc));
2147 // Verify
2148 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2149}
2150
2151TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) {
2152 // SessionDescription with desc but without candidates.
2153 JsepSessionDescription jdesc_no_candidates(kDummyString);
2154 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(),
2155 kSessionId, kSessionVersion));
2156 JsepSessionDescription new_jdesc(kDummyString);
2157 EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc));
2158 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
2159}
2160
2161TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) {
2162 static const char kSdpNoRtpmapString[] =
2163 "v=0\r\n"
2164 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2165 "s=-\r\n"
2166 "t=0 0\r\n"
2167 "m=audio 49232 RTP/AVP 0 18 103\r\n"
2168 // Codec that doesn't appear in the m= line will be ignored.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412169 "a=rtpmap:104 ISAC/32000\r\n"
henrike@webrtc.org28e20752013-07-10 00:45:362170 // The rtpmap line for static payload codec is optional.
2171 "a=rtpmap:18 G729/16000\r\n"
2172 "a=rtpmap:103 ISAC/16000\r\n";
2173
2174 JsepSessionDescription jdesc(kDummyString);
2175 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2176 cricket::AudioContentDescription* audio =
2177 static_cast<AudioContentDescription*>(
2178 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2179 AudioCodecs ref_codecs;
deadbeef67cf2c12016-04-13 17:07:162180 // The codecs in the AudioContentDescription should be in the same order as
2181 // the payload types (<fmt>s) on the m= line.
2182 ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1));
2183 ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1));
2184 ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1));
henrike@webrtc.org28e20752013-07-10 00:45:362185 EXPECT_EQ(ref_codecs, audio->codecs());
2186}
2187
henrike@webrtc.org704bf9e2014-02-27 17:52:042188TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) {
2189 static const char kSdpNoRtpmapString[] =
2190 "v=0\r\n"
2191 "o=- 11 22 IN IP4 127.0.0.1\r\n"
2192 "s=-\r\n"
2193 "t=0 0\r\n"
2194 "m=audio 49232 RTP/AVP 18 103\r\n"
2195 "a=fmtp:18 annexb=yes\r\n"
2196 "a=rtpmap:103 ISAC/16000\r\n";
2197
2198 JsepSessionDescription jdesc(kDummyString);
2199 EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc));
2200 cricket::AudioContentDescription* audio =
2201 static_cast<AudioContentDescription*>(
2202 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2203
2204 cricket::AudioCodec g729 = audio->codecs()[0];
2205 EXPECT_EQ("G729", g729.name);
2206 EXPECT_EQ(8000, g729.clockrate);
2207 EXPECT_EQ(18, g729.id);
2208 cricket::CodecParameterMap::iterator found =
2209 g729.params.find("annexb");
2210 ASSERT_TRUE(found != g729.params.end());
2211 EXPECT_EQ(found->second, "yes");
2212
2213 cricket::AudioCodec isac = audio->codecs()[1];
2214 EXPECT_EQ("ISAC", isac.name);
2215 EXPECT_EQ(103, isac.id);
2216 EXPECT_EQ(16000, isac.clockrate);
2217}
2218
henrike@webrtc.org28e20752013-07-10 00:45:362219// Ensure that we can deserialize SDP with a=fingerprint properly.
2220TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) {
2221 // Add a DTLS a=fingerprint attribute to our session description.
2222 AddFingerprint();
2223 JsepSessionDescription new_jdesc(kDummyString);
2224 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
2225 jdesc_.session_id(),
2226 jdesc_.session_version()));
2227
2228 JsepSessionDescription jdesc_with_fingerprint(kDummyString);
2229 std::string sdp_with_fingerprint = kSdpString;
2230 InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint);
2231 InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint);
2232 EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint));
2233 EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc));
2234}
2235
2236TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) {
2237 JsepSessionDescription jdesc_with_bundle(kDummyString);
2238 std::string sdp_with_bundle = kSdpFullString;
2239 InjectAfter(kSessionTime,
2240 "a=group:BUNDLE audio_content_name video_content_name\r\n",
2241 &sdp_with_bundle);
2242 EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle));
2243 ContentGroup group(cricket::GROUP_TYPE_BUNDLE);
2244 group.AddContentName(kAudioContentName);
2245 group.AddContentName(kVideoContentName);
2246 desc_.AddGroup(group);
2247 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2248 jdesc_.session_id(),
2249 jdesc_.session_version()));
2250 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle));
2251}
2252
2253TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) {
2254 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2255 std::string sdp_with_bandwidth = kSdpFullString;
2256 InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n",
2257 "b=AS:100\r\n",
2258 &sdp_with_bandwidth);
2259 InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n",
2260 "b=AS:50\r\n",
2261 &sdp_with_bandwidth);
2262 EXPECT_TRUE(
2263 SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2264 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2265 GetFirstVideoContent(&desc_)->description);
2266 vcd->set_bandwidth(100 * 1000);
2267 AudioContentDescription* acd = static_cast<AudioContentDescription*>(
2268 GetFirstAudioContent(&desc_)->description);
2269 acd->set_bandwidth(50 * 1000);
2270 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2271 jdesc_.session_id(),
2272 jdesc_.session_version()));
2273 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth));
2274}
2275
2276TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) {
2277 JsepSessionDescription jdesc_with_ice_options(kDummyString);
2278 std::string sdp_with_ice_options = kSdpFullString;
2279 InjectAfter(kSessionTime,
2280 "a=ice-options:iceoption3\r\n",
2281 &sdp_with_ice_options);
2282 InjectAfter(kAttributeIcePwdVoice,
2283 "a=ice-options:iceoption1\r\n",
2284 &sdp_with_ice_options);
2285 InjectAfter(kAttributeIcePwdVideo,
2286 "a=ice-options:iceoption2\r\n",
2287 &sdp_with_ice_options);
2288 EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options));
2289 std::vector<std::string> transport_options;
2290 transport_options.push_back(kIceOption3);
2291 transport_options.push_back(kIceOption1);
2292 AddIceOptions(kAudioContentName, transport_options);
2293 transport_options.clear();
2294 transport_options.push_back(kIceOption3);
2295 transport_options.push_back(kIceOption2);
2296 AddIceOptions(kVideoContentName, transport_options);
2297 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2298 jdesc_.session_id(),
2299 jdesc_.session_version()));
2300 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options));
2301}
2302
2303TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) {
2304 // Remove the original ice-ufrag and ice-pwd
2305 JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString);
2306 std::string sdp_with_ufrag_pwd = kSdpFullString;
2307 EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd));
2308 // Add session level ufrag and pwd
2309 InjectAfter(kSessionTime,
2310 "a=ice-pwd:session+level+icepwd\r\n"
2311 "a=ice-ufrag:session+level+iceufrag\r\n",
2312 &sdp_with_ufrag_pwd);
2313 // Add media level ufrag and pwd for audio
2314 InjectAfter("a=mid:audio_content_name\r\n",
2315 "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n",
2316 &sdp_with_ufrag_pwd);
2317 // Update the candidate ufrag and pwd to the expected ones.
2318 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0,
2319 "media+level+iceufrag", "media+level+icepwd"));
2320 EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1,
2321 "session+level+iceufrag", "session+level+icepwd"));
2322 EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd));
2323 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd));
2324}
2325
henrike@webrtc.org28e20752013-07-10 00:45:362326TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) {
2327 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY));
2328}
2329
2330TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) {
2331 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY));
2332}
2333
2334TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) {
2335 EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE));
2336}
2337
2338TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) {
2339 EXPECT_TRUE(TestDeserializeRejected(true, false));
2340}
2341
2342TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) {
2343 EXPECT_TRUE(TestDeserializeRejected(false, true));
2344}
2345
2346TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) {
2347 EXPECT_TRUE(TestDeserializeRejected(true, true));
2348}
2349
2350// Tests that we can still handle the sdp uses mslabel and label instead of
2351// msid for backward compatibility.
2352TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) {
deadbeefc80741f2015-10-22 20:14:452353 jdesc_.description()->set_msid_supported(false);
henrike@webrtc.org28e20752013-07-10 00:45:362354 JsepSessionDescription jdesc(kDummyString);
2355 std::string sdp_without_msid = kSdpFullString;
2356 Replace("msid", "xmsid", &sdp_without_msid);
2357 // Deserialize
2358 EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc));
2359 // Verify
2360 EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc));
2361}
2362
2363TEST_F(WebRtcSdpTest, DeserializeCandidate) {
2364 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2365
2366 std::string sdp = kSdpOneCandidate;
2367 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2368 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2369 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2370 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
honghaiza0c44ea2016-03-23 23:07:482371 EXPECT_EQ(0, jcandidate.candidate().network_cost());
henrike@webrtc.org28e20752013-07-10 00:45:362372
2373 // Candidate line without generation extension.
2374 sdp = kSdpOneCandidate;
2375 Replace(" generation 2", "", &sdp);
2376 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2377 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2378 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2379 Candidate expected = jcandidate_->candidate();
2380 expected.set_generation(0);
2381 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2382
honghaiza0c44ea2016-03-23 23:07:482383 // Candidate with network id and/or cost.
2384 sdp = kSdpOneCandidate;
2385 Replace(" generation 2", " generation 2 network-id 2", &sdp);
2386 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2387 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2388 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2389 expected = jcandidate_->candidate();
2390 expected.set_network_id(2);
2391 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2392 EXPECT_EQ(0, jcandidate.candidate().network_cost());
2393 // Add network cost
2394 Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
2395 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2396 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2397 EXPECT_EQ(9, jcandidate.candidate().network_cost());
2398
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202399 sdp = kSdpTcpActiveCandidate;
2400 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2401 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
guoweis@webrtc.org61c12472015-01-15 06:53:072402 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
guoweis@webrtc.org950c5182014-12-16 23:01:312403 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
2404 "", "", LOCAL_PORT_TYPE, kCandidateGeneration,
2405 kCandidateFoundation1);
kwibergd1fe2812016-04-27 13:47:292406 std::unique_ptr<IceCandidateInterface> jcandidate_template(
2407 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));
mallinath@webrtc.org2d60c5e2014-08-08 22:29:202408 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(
2409 jcandidate_template->candidate()));
2410 sdp = kSdpTcpPassiveCandidate;
2411 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
2412 sdp = kSdpTcpSOCandidate;
2413 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362414}
2415
2416// This test verifies the deserialization of candidate-attribute
2417// as per RFC 5245. Candiate-attribute will be of the format
2418// candidate:<blah>. This format will be used when candidates
2419// are trickled.
2420TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) {
2421 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2422
2423 std::string candidate_attribute = kRawCandidate;
2424 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2425 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2426 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2427 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2428 EXPECT_EQ(2u, jcandidate.candidate().generation());
2429
2430 // Candidate line without generation extension.
2431 candidate_attribute = kRawCandidate;
2432 Replace(" generation 2", "", &candidate_attribute);
2433 EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2434 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2435 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2436 Candidate expected = jcandidate_->candidate();
2437 expected.set_generation(0);
2438 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
2439
2440 // Candidate line without candidate:
2441 candidate_attribute = kRawCandidate;
2442 Replace("candidate:", "", &candidate_attribute);
2443 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2444
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152445 // Candidate line with IPV6 address.
2446 EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate));
2447}
2448
2449// This test verifies that the deserialization of an invalid candidate string
2450// fails.
2451TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) {
2452 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2453
2454 std::string candidate_attribute = kRawCandidate;
2455 candidate_attribute.replace(0, 1, "x");
henrike@webrtc.org28e20752013-07-10 00:45:362456 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
jiayl@webrtc.org7ec3f9f2014-08-08 23:09:152457
2458 candidate_attribute = kSdpOneCandidate;
2459 candidate_attribute.replace(0, 1, "x");
2460 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2461
2462 candidate_attribute = kRawCandidate;
2463 candidate_attribute.append("\r\n");
2464 candidate_attribute.append(kRawCandidate);
2465 EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate));
2466
2467 EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362468}
2469
2470TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) {
2471 AddRtpDataChannel();
2472 JsepSessionDescription jdesc(kDummyString);
2473 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2474
2475 std::string sdp_with_data = kSdpString;
2476 sdp_with_data.append(kSdpRtpDataChannelString);
2477 JsepSessionDescription jdesc_output(kDummyString);
2478
2479 // Deserialize
2480 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2481 // Verify
2482 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2483}
2484
2485TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) {
2486 AddSctpDataChannel();
2487 JsepSessionDescription jdesc(kDummyString);
2488 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2489
2490 std::string sdp_with_data = kSdpString;
2491 sdp_with_data.append(kSdpSctpDataChannelString);
2492 JsepSessionDescription jdesc_output(kDummyString);
2493
lally@webrtc.org36300852015-02-24 20:19:352494 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString).
2495 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2496 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2497
2498 // Verify with UDP/DTLS/SCTP.
2499 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2500 strlen(kDtlsSctp), kUdpDtlsSctp);
2501 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2502 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2503
2504 // Verify with TCP/DTLS/SCTP.
2505 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2506 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
henrike@webrtc.org28e20752013-07-10 00:45:362507 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2508 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2509}
2510
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562511TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
2512 AddSctpDataChannel();
2513 JsepSessionDescription jdesc(kDummyString);
2514 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2515
2516 std::string sdp_with_data = kSdpString;
2517 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2518 JsepSessionDescription jdesc_output(kDummyString);
2519
lally@webrtc.org36300852015-02-24 20:19:352520 // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort).
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562521 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2522 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562523
lally@webrtc.org36300852015-02-24 20:19:352524 // Verify with UDP/DTLS/SCTP.
2525 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2526 strlen(kDtlsSctp), kUdpDtlsSctp);
2527 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2528 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
lally@webrtc.orgc7848b72015-02-24 20:19:262529
lally@webrtc.org36300852015-02-24 20:19:352530 // Verify with TCP/DTLS/SCTP.
2531 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2532 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
lally@webrtc.orgc7848b72015-02-24 20:19:262533 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2534 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2535}
2536
lally69f57602015-10-08 17:15:042537TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
2538 AddSctpDataChannel();
2539 JsepSessionDescription jdesc(kDummyString);
2540 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2541
2542 std::string sdp_with_data = kSdpString;
2543 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
2544 JsepSessionDescription jdesc_output(kDummyString);
2545
2546 // Verify with DTLS/SCTP.
2547 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2548 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2549
2550 // Verify with UDP/DTLS/SCTP.
2551 sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
2552 strlen(kDtlsSctp), kUdpDtlsSctp);
2553 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2554 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2555
2556 // Verify with TCP/DTLS/SCTP.
2557 sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
2558 strlen(kUdpDtlsSctp), kTcpDtlsSctp);
2559 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2560 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
2561}
2562
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562563// Test to check the behaviour if sctp-port is specified
2564// on the m= line and in a=sctp-port.
2565TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {
2566 AddSctpDataChannel();
2567 JsepSessionDescription jdesc(kDummyString);
2568 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2569
2570 std::string sdp_with_data = kSdpString;
2571 // Append m= attributes
2572 sdp_with_data.append(kSdpSctpDataChannelString);
2573 // Append a=sctp-port attribute
2574 sdp_with_data.append("a=sctp-port 5000\r\n");
2575 JsepSessionDescription jdesc_output(kDummyString);
2576
2577 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2578}
2579
henrike@webrtc.org571df2d2014-02-19 23:04:262580// For crbug/344475.
2581TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) {
2582 std::string sdp_with_data = kSdpString;
2583 sdp_with_data.append(kSdpSctpDataChannelString);
2584 // Remove the "\n" at the end.
2585 sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1);
2586 JsepSessionDescription jdesc_output(kDummyString);
2587
2588 EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output));
2589 // No crash is a pass.
2590}
2591
wu@webrtc.org78187522013-10-07 23:32:022592TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) {
2593 AddSctpDataChannel();
Peter Boström0c4e06b2015-10-07 10:23:212594 const uint16_t kUnusualSctpPort = 9556;
wu@webrtc.org78187522013-10-07 23:32:022595 char default_portstr[16];
2596 char unusual_portstr[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:522597 rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:022598 kDefaultSctpPort);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:522599 rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d",
wu@webrtc.org78187522013-10-07 23:32:022600 kUnusualSctpPort);
2601
jiayl@webrtc.org9c16c392014-05-01 18:30:302602 // First setup the expected JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:022603 JsepSessionDescription jdesc(kDummyString);
2604 // take our pre-built session description and change the SCTP port.
2605 cricket::SessionDescription* mutant = desc_.Copy();
2606 DataContentDescription* dcdesc = static_cast<DataContentDescription*>(
2607 mutant->GetContentDescriptionByName(kDataContentName));
2608 std::vector<cricket::DataCodec> codecs(dcdesc->codecs());
pkasting@chromium.orgd3245462015-02-23 21:28:222609 EXPECT_EQ(1U, codecs.size());
2610 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id);
wu@webrtc.org78187522013-10-07 23:32:022611 codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort);
jiayl@webrtc.org9c16c392014-05-01 18:30:302612 dcdesc->set_codecs(codecs);
wu@webrtc.org78187522013-10-07 23:32:022613
2614 // note: mutant's owned by jdesc now.
2615 ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion));
2616 mutant = NULL;
2617
jiayl@webrtc.org9c16c392014-05-01 18:30:302618 // Then get the deserialized JsepSessionDescription.
wu@webrtc.org78187522013-10-07 23:32:022619 std::string sdp_with_data = kSdpString;
2620 sdp_with_data.append(kSdpSctpDataChannelString);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:522621 rtc::replace_substrs(default_portstr, strlen(default_portstr),
wu@webrtc.org78187522013-10-07 23:32:022622 unusual_portstr, strlen(unusual_portstr),
2623 &sdp_with_data);
2624 JsepSessionDescription jdesc_output(kDummyString);
2625
2626 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2627 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
jiayl@webrtc.orgddb85ab2014-09-05 16:31:562628
2629 // We need to test the deserialized JsepSessionDescription from
2630 // kSdpSctpDataChannelStringWithSctpPort for
2631 // draft-ietf-mmusic-sctp-sdp-07
2632 // a=sctp-port
2633 sdp_with_data = kSdpString;
2634 sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort);
2635 rtc::replace_substrs(default_portstr, strlen(default_portstr),
2636 unusual_portstr, strlen(unusual_portstr),
2637 &sdp_with_data);
2638
2639 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
2640 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
wu@webrtc.org78187522013-10-07 23:32:022641}
2642
wu@webrtc.orgcadf9042013-08-30 21:24:162643TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) {
Peter Thatcherc0c3a862015-06-24 22:31:252644 // We want to test that deserializing data content limits bandwidth
2645 // settings (it should never be greater than the default).
2646 // This should prevent someone from using unlimited data bandwidth through
2647 // JS and "breaking the Internet".
2648 // See: https://code.google.com/p/chromium/issues/detail?id=280726
wu@webrtc.orgcadf9042013-08-30 21:24:162649 std::string sdp_with_bandwidth = kSdpString;
2650 sdp_with_bandwidth.append(kSdpRtpDataChannelString);
2651 InjectAfter("a=mid:data_content_name\r\n",
2652 "b=AS:100\r\n",
2653 &sdp_with_bandwidth);
2654 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2655
Peter Thatcherc0c3a862015-06-24 22:31:252656 EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2657}
2658
2659TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) {
2660 AddSctpDataChannel();
2661 JsepSessionDescription jdesc(kDummyString);
2662 DataContentDescription* dcd = static_cast<DataContentDescription*>(
2663 GetFirstDataContent(&desc_)->description);
2664 dcd->set_bandwidth(100 * 1000);
2665 ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
2666
2667 std::string sdp_with_bandwidth = kSdpString;
2668 sdp_with_bandwidth.append(kSdpSctpDataChannelString);
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
2674 // SCTP has congestion control, so we shouldn't limit the bandwidth
2675 // as we do for RTP.
2676 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
wu@webrtc.orgcadf9042013-08-30 21:24:162677 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2678}
2679
henrike@webrtc.org28e20752013-07-10 00:45:362680TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) {
2681 TestDeserializeExtmap(true, false);
2682}
2683
2684TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) {
2685 TestDeserializeExtmap(false, true);
2686}
2687
2688TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) {
2689 TestDeserializeExtmap(true, true);
2690}
2691
sergeyu@chromium.org5bc25c42013-12-05 00:24:062692TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2693 JsepSessionDescription jdesc(kDummyString);
2694 std::string sdp = kSdpFullString;
2695 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2696 // Deserialize
2697 SdpParseError error;
2698 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
deadbeef9d3584c2016-02-17 01:54:102699 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
sergeyu@chromium.org5bc25c42013-12-05 00:24:062700 EXPECT_EQ(lastline, error.line);
2701 EXPECT_EQ("Invalid SDP line.", error.description);
2702}
2703
henrike@webrtc.org28e20752013-07-10 00:45:362704TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) {
2705 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
2706 std::string new_sdp = kSdpOneCandidate;
2707 Replace("udp", "unsupported_transport", &new_sdp);
2708 EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2709 new_sdp = kSdpOneCandidate;
2710 Replace("udp", "uDP", &new_sdp);
2711 EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate));
2712 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2713 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2714 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
2715}
2716
honghaiza54a0802015-12-17 02:37:232717TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) {
henrike@webrtc.org28e20752013-07-10 00:45:362718 JsepIceCandidate jcandidate(kDummyMid, kDummyIndex);
honghaiza54a0802015-12-17 02:37:232719 EXPECT_TRUE(
2720 SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate));
henrike@webrtc.org28e20752013-07-10 00:45:362721 EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
2722 EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
2723 Candidate ref_candidate = jcandidate_->candidate();
2724 ref_candidate.set_username("user_rtp");
2725 ref_candidate.set_password("password_rtp");
2726 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate));
2727}
2728
henrike@webrtc.org704bf9e2014-02-27 17:52:042729TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) {
2730 JsepSessionDescription jdesc(kDummyString);
2731
2732 // Deserialize
2733 EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc));
2734
2735 // Verify
2736 cricket::AudioContentDescription* audio =
2737 static_cast<AudioContentDescription*>(
2738 jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO));
2739 EXPECT_TRUE(audio->conference_mode());
2740
2741 cricket::VideoContentDescription* video =
2742 static_cast<VideoContentDescription*>(
2743 jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO));
2744 EXPECT_TRUE(video->conference_mode());
2745}
2746
henrike@webrtc.org28e20752013-07-10 00:45:362747TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) {
2748 const char kSdpDestroyer[] = "!@#$%^&";
decurtis@webrtc.org8af11042015-01-07 19:15:512749 const char kSdpEmptyType[] = " =candidate";
2750 const char kSdpEqualAsPlus[] = "a+candidate";
2751 const char kSdpSpaceAfterEqual[] = "a= candidate";
2752 const char kSdpUpperType[] = "A=candidate";
2753 const char kSdpEmptyLine[] = "";
2754 const char kSdpMissingValue[] = "a=";
2755
2756 const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:362757 "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:512758 const char kSdpExtraField[] = "a=fingerprint:sha-1 "
henrike@webrtc.org28e20752013-07-10 00:45:362759 "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:512760 const char kSdpMissingSpace[] = "a=fingerprint:sha-1"
henrike@webrtc.org28e20752013-07-10 00:45:362761 "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:582762 // MD5 is not allowed in fingerprints.
decurtis@webrtc.org8af11042015-01-07 19:15:512763 const char kSdpMd5[] = "a=fingerprint:md5 "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:582764 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B";
henrike@webrtc.org28e20752013-07-10 00:45:362765
2766 // Broken session description
wu@webrtc.org5e760e72014-04-02 23:19:092767 ExpectParseFailure("v=", kSdpDestroyer);
2768 ExpectParseFailure("o=", kSdpDestroyer);
2769 ExpectParseFailure("s=-", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362770 // Broken time description
wu@webrtc.org5e760e72014-04-02 23:19:092771 ExpectParseFailure("t=", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362772
2773 // Broken media description
wu@webrtc.org5e760e72014-04-02 23:19:092774 ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39");
2775 ExpectParseFailure("m=video", kSdpDestroyer);
henrike@webrtc.org28e20752013-07-10 00:45:362776
2777 // Invalid lines
decurtis@webrtc.org8af11042015-01-07 19:15:512778 ExpectParseFailure("a=candidate", kSdpEmptyType);
2779 ExpectParseFailure("a=candidate", kSdpEqualAsPlus);
2780 ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual);
2781 ExpectParseFailure("a=candidate", kSdpUpperType);
henrike@webrtc.org28e20752013-07-10 00:45:362782
2783 // Bogus fingerprint replacing a=sendrev. We selected this attribute
2784 // because it's orthogonal to what we are replacing and hence
2785 // safe.
decurtis@webrtc.org8af11042015-01-07 19:15:512786 ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint);
2787 ExpectParseFailure("a=sendrecv", kSdpExtraField);
2788 ExpectParseFailure("a=sendrecv", kSdpMissingSpace);
2789 ExpectParseFailure("a=sendrecv", kSdpMd5);
2790
2791 // Empty Line
2792 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine);
2793 ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue);
wu@webrtc.org5e760e72014-04-02 23:19:092794}
2795
2796TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) {
2797 // ssrc
2798 ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue");
deadbeef9d3584c2016-02-17 01:54:102799 ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3");
wu@webrtc.org5e760e72014-04-02 23:19:092800 // crypto
2801 ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue ");
2802 // rtpmap
2803 ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue ");
2804 ExpectParseFailure("opus/48000/2", "opus/badvalue/2");
2805 ExpectParseFailure("opus/48000/2", "opus/48000/badvalue");
2806 // candidate
2807 ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432");
2808 ExpectParseFailure("1 udp 2130706432", "1 udp badvalue");
2809 ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue");
2810 ExpectParseFailure("rport 2346", "rport badvalue");
2811 ExpectParseFailure("rport 2346 generation 2",
2812 "rport 2346 generation badvalue");
2813 // m line
2814 ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104",
2815 "m=audio 2345 RTP/SAVPF 111 badvalue 104");
2816
2817 // bandwidth
2818 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2819 "b=AS:badvalue\r\n",
2820 "b=AS:badvalue");
2821 // rtcp-fb
2822 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2823 "a=rtcp-fb:badvalue nack\r\n",
2824 "a=rtcp-fb:badvalue nack");
2825 // extmap
2826 ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n",
2827 "a=extmap:badvalue http://example.com\r\n",
2828 "a=extmap:badvalue http://example.com");
henrike@webrtc.org28e20752013-07-10 00:45:362829}
2830
2831TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) {
2832 JsepSessionDescription jdesc_output(kDummyString);
2833
2834 const char kSdpWithReorderedPlTypesString[] =
2835 "v=0\r\n"
2836 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2837 "s=-\r\n"
2838 "t=0 0\r\n"
pthatcher@webrtc.orgc9d6d142014-10-23 23:37:222839 "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred.
henrike@webrtc.org28e20752013-07-10 00:45:362840 "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104
2841 // in the map.
2842 "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map.
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412843 "a=rtpmap:104 ISAC/32000\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:362844
2845 // Deserialize
2846 EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output));
2847
2848 const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description());
2849 ASSERT_TRUE(ac != NULL);
2850 const AudioContentDescription* acd =
2851 static_cast<const AudioContentDescription*>(ac->description);
2852 ASSERT_FALSE(acd->codecs().empty());
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:412853 EXPECT_EQ("ISAC", acd->codecs()[0].name);
2854 EXPECT_EQ(32000, acd->codecs()[0].clockrate);
henrike@webrtc.org28e20752013-07-10 00:45:362855 EXPECT_EQ(104, acd->codecs()[0].id);
2856}
2857
2858TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) {
2859 JsepSessionDescription jdesc_output(kDummyString);
2860 CodecParams params;
2861 params.max_ptime = 40;
2862 params.ptime = 30;
2863 params.min_ptime = 10;
2864 params.sprop_stereo = 1;
2865 params.stereo = 1;
2866 params.useinband = 1;
henrike@webrtc.org1e09a712013-07-26 19:17:592867 params.maxaveragebitrate = 128000;
henrike@webrtc.org28e20752013-07-10 00:45:362868 TestDeserializeCodecParams(params, &jdesc_output);
deadbeef9d3584c2016-02-17 01:54:102869 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362870}
2871
2872TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) {
2873 const bool kUseWildcard = false;
2874 JsepSessionDescription jdesc_output(kDummyString);
2875 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-17 01:54:102876 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362877}
2878
2879TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) {
2880 const bool kUseWildcard = true;
2881 JsepSessionDescription jdesc_output(kDummyString);
2882 TestDeserializeRtcpFb(&jdesc_output, kUseWildcard);
deadbeef9d3584c2016-02-17 01:54:102883 TestSerialize(jdesc_output, false);
henrike@webrtc.org28e20752013-07-10 00:45:362884}
2885
2886TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) {
2887 JsepSessionDescription jdesc_output(kDummyString);
2888
2889 const char kSdpWithFmtpString[] =
2890 "v=0\r\n"
2891 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2892 "s=-\r\n"
2893 "t=0 0\r\n"
2894 "m=video 3457 RTP/SAVPF 120\r\n"
2895 "a=rtpmap:120 VP8/90000\r\n"
Donald Curtis0e07f922015-05-15 16:21:232896 "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n";
2897
2898 // Deserialize
2899 SdpParseError error;
Donald Curtis144d0182015-05-15 20:14:242900 EXPECT_TRUE(
2901 webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error));
Donald Curtis0e07f922015-05-15 16:21:232902
2903 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2904 ASSERT_TRUE(vc != NULL);
2905 const VideoContentDescription* vcd =
2906 static_cast<const VideoContentDescription*>(vc->description);
2907 ASSERT_FALSE(vcd->codecs().empty());
2908 cricket::VideoCodec vp8 = vcd->codecs()[0];
2909 EXPECT_EQ("VP8", vp8.name);
2910 EXPECT_EQ(120, vp8.id);
2911 cricket::CodecParameterMap::iterator found =
2912 vp8.params.find("x-google-min-bitrate");
2913 ASSERT_TRUE(found != vp8.params.end());
2914 EXPECT_EQ(found->second, "10");
2915 found = vp8.params.find("x-google-max-quantization");
2916 ASSERT_TRUE(found != vp8.params.end());
2917 EXPECT_EQ(found->second, "40");
2918}
2919
2920TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) {
2921 JsepSessionDescription jdesc_output(kDummyString);
2922
2923 const char kSdpWithFmtpString[] =
2924 "v=0\r\n"
2925 "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n"
2926 "s=-\r\n"
2927 "t=0 0\r\n"
2928 "m=video 3457 RTP/SAVPF 120\r\n"
2929 "a=rtpmap:120 VP8/90000\r\n"
2930 "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n";
henrike@webrtc.org28e20752013-07-10 00:45:362931
2932 // Deserialize
2933 SdpParseError error;
2934 EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output,
2935 &error));
2936
2937 const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description());
2938 ASSERT_TRUE(vc != NULL);
2939 const VideoContentDescription* vcd =
2940 static_cast<const VideoContentDescription*>(vc->description);
2941 ASSERT_FALSE(vcd->codecs().empty());
2942 cricket::VideoCodec vp8 = vcd->codecs()[0];
2943 EXPECT_EQ("VP8", vp8.name);
2944 EXPECT_EQ(120, vp8.id);
2945 cricket::CodecParameterMap::iterator found =
2946 vp8.params.find("x-google-min-bitrate");
2947 ASSERT_TRUE(found != vp8.params.end());
2948 EXPECT_EQ(found->second, "10");
2949 found = vp8.params.find("x-google-max-quantization");
2950 ASSERT_TRUE(found != vp8.params.end());
2951 EXPECT_EQ(found->second, "40");
2952}
2953
2954TEST_F(WebRtcSdpTest, SerializeVideoFmtp) {
2955 VideoContentDescription* vcd = static_cast<VideoContentDescription*>(
2956 GetFirstVideoContent(&desc_)->description);
2957
2958 cricket::VideoCodecs codecs = vcd->codecs();
2959 codecs[0].params["x-google-min-bitrate"] = "10";
2960 vcd->set_codecs(codecs);
2961
2962 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
2963 jdesc_.session_id(),
2964 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:102965 std::string message = webrtc::SdpSerialize(jdesc_, false);
henrike@webrtc.org28e20752013-07-10 00:45:362966 std::string sdp_with_fmtp = kSdpFullString;
2967 InjectAfter("a=rtpmap:120 VP8/90000\r\n",
2968 "a=fmtp:120 x-google-min-bitrate=10\r\n",
2969 &sdp_with_fmtp);
2970 EXPECT_EQ(sdp_with_fmtp, message);
2971}
2972
2973TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) {
2974 JsepSessionDescription jdesc_with_icelite(kDummyString);
2975 std::string sdp_with_icelite = kSdpFullString;
2976 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2977 cricket::SessionDescription* desc = jdesc_with_icelite.description();
2978 const cricket::TransportInfo* tinfo1 =
2979 desc->GetTransportInfoByName("audio_content_name");
2980 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode);
2981 const cricket::TransportInfo* tinfo2 =
2982 desc->GetTransportInfoByName("video_content_name");
2983 EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode);
2984 InjectAfter(kSessionTime,
2985 "a=ice-lite\r\n",
2986 &sdp_with_icelite);
2987 EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite));
2988 desc = jdesc_with_icelite.description();
2989 const cricket::TransportInfo* atinfo =
2990 desc->GetTransportInfoByName("audio_content_name");
2991 EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode);
2992 const cricket::TransportInfo* vtinfo =
2993 desc->GetTransportInfoByName("video_content_name");
2994 EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode);
2995}
2996
2997// Verifies that the candidates in the input SDP are parsed and serialized
2998// correctly in the output SDP.
2999TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) {
3000 std::string sdp_with_data = kSdpString;
3001 sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString);
3002 JsepSessionDescription jdesc_output(kDummyString);
3003
3004 EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
deadbeef9d3584c2016-02-17 01:54:103005 EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false));
henrike@webrtc.org28e20752013-07-10 00:45:363006}
sergeyu@chromium.org0be6aa02013-08-23 23:21:253007
3008TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) {
3009 AddFingerprint();
3010 TransportInfo audio_transport_info =
3011 *(desc_.GetTransportInfoByName(kAudioContentName));
3012 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3013 audio_transport_info.description.connection_role);
3014 audio_transport_info.description.connection_role =
3015 cricket::CONNECTIONROLE_ACTIVE;
3016
3017 TransportInfo video_transport_info =
3018 *(desc_.GetTransportInfoByName(kVideoContentName));
3019 EXPECT_EQ(cricket::CONNECTIONROLE_NONE,
3020 video_transport_info.description.connection_role);
3021 video_transport_info.description.connection_role =
3022 cricket::CONNECTIONROLE_ACTIVE;
3023
3024 desc_.RemoveTransportInfoByName(kAudioContentName);
3025 desc_.RemoveTransportInfoByName(kVideoContentName);
3026
3027 desc_.AddTransportInfo(audio_transport_info);
3028 desc_.AddTransportInfo(video_transport_info);
3029
3030 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(),
3031 jdesc_.session_id(),
3032 jdesc_.session_version()));
deadbeef9d3584c2016-02-17 01:54:103033 std::string message = webrtc::SdpSerialize(jdesc_, false);
sergeyu@chromium.org0be6aa02013-08-23 23:21:253034 std::string sdp_with_dtlssetup = kSdpFullString;
3035
3036 // Fingerprint attribute is necessary to add DTLS setup attribute.
3037 InjectAfter(kAttributeIcePwdVoice,
3038 kFingerprint, &sdp_with_dtlssetup);
3039 InjectAfter(kAttributeIcePwdVideo,
3040 kFingerprint, &sdp_with_dtlssetup);
3041 // Now adding |setup| attribute.
3042 InjectAfter(kFingerprint,
3043 "a=setup:active\r\n", &sdp_with_dtlssetup);
3044 EXPECT_EQ(sdp_with_dtlssetup, message);
3045}
3046
3047TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) {
3048 JsepSessionDescription jdesc_with_dtlssetup(kDummyString);
3049 std::string sdp_with_dtlssetup = kSdpFullString;
3050 InjectAfter(kSessionTime,
3051 "a=setup:actpass\r\n",
3052 &sdp_with_dtlssetup);
3053 EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup));
3054 cricket::SessionDescription* desc = jdesc_with_dtlssetup.description();
3055 const cricket::TransportInfo* atinfo =
3056 desc->GetTransportInfoByName("audio_content_name");
3057 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3058 atinfo->description.connection_role);
3059 const cricket::TransportInfo* vtinfo =
3060 desc->GetTransportInfoByName("video_content_name");
3061 EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS,
3062 vtinfo->description.connection_role);
3063}
jiayl@webrtc.orge7d47a12014-08-05 19:19:053064
3065// Verifies that the order of the serialized m-lines follows the order of the
3066// ContentInfo in SessionDescription, and vise versa for deserialization.
3067TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) {
3068 JsepSessionDescription jdesc(kDummyString);
3069 const std::string media_content_sdps[3] = {
3070 kSdpAudioString,
3071 kSdpVideoString,
3072 kSdpSctpDataChannelString
3073 };
3074 const cricket::MediaType media_types[3] = {
3075 cricket::MEDIA_TYPE_AUDIO,
3076 cricket::MEDIA_TYPE_VIDEO,
3077 cricket::MEDIA_TYPE_DATA
3078 };
3079
3080 // Verifies all 6 permutations.
3081 for (size_t i = 0; i < 6; ++i) {
3082 size_t media_content_in_sdp[3];
3083 // The index of the first media content.
3084 media_content_in_sdp[0] = i / 2;
3085 // The index of the second media content.
3086 media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3;
3087 // The index of the third media content.
3088 media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3;
3089
3090 std::string sdp_string = kSdpSessionString;
3091 for (size_t i = 0; i < 3; ++i)
3092 sdp_string += media_content_sdps[media_content_in_sdp[i]];
3093
3094 EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc));
3095 cricket::SessionDescription* desc = jdesc.description();
3096 EXPECT_EQ(3u, desc->contents().size());
3097
3098 for (size_t i = 0; i < 3; ++i) {
3099 const cricket::MediaContentDescription* mdesc =
3100 static_cast<const cricket::MediaContentDescription*>(
3101 desc->contents()[i].description);
3102 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type());
3103 }
3104
deadbeef9d3584c2016-02-17 01:54:103105 std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false);
jiayl@webrtc.orge7d47a12014-08-05 19:19:053106 EXPECT_EQ(sdp_string, serialized_sdp);
3107 }
3108}
deadbeef9d3584c2016-02-17 01:54:103109
3110TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) {
3111 MakePlanBDescription();
3112
3113 JsepSessionDescription deserialized_description(kDummyString);
3114 EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description));
3115
3116 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3117}
3118
3119TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) {
3120 MakePlanBDescription();
3121 TestSerialize(jdesc_, false);
3122}
3123
Taylor Brandstetter5de6b752016-03-10 01:02:303124// Some WebRTC endpoints include the msid in both the Plan B and Unified Plan
3125// ways, to make SDP that's compatible with both Plan B and Unified Plan (to
3126// some extent). If we parse this, the Plan B msid attribute (which is more
3127// specific, since it's at the SSRC level) should take priority.
3128TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) {
3129 MakePlanBDescription();
3130
3131 JsepSessionDescription deserialized_description(kDummyString);
3132 EXPECT_TRUE(
3133 SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description));
3134
3135 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3136}
3137
deadbeef9d3584c2016-02-17 01:54:103138TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) {
3139 MakeUnifiedPlanDescription();
3140
3141 JsepSessionDescription deserialized_description(kDummyString);
3142 EXPECT_TRUE(
3143 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description));
3144
3145 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description));
3146}
3147
3148TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) {
3149 MakeUnifiedPlanDescription();
3150 TestSerialize(jdesc_, true);
3151}