henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 11 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | #include <set> |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 16 | #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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 21 | #include "webrtc/base/gunit.h" |
| 22 | #include "webrtc/base/logging.h" |
| 23 | #include "webrtc/base/messagedigest.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 24 | #include "webrtc/base/sslfingerprint.h" |
| 25 | #include "webrtc/base/stringencode.h" |
| 26 | #include "webrtc/base/stringutils.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 27 | #include "webrtc/media/base/mediaconstants.h" |
hta | a6b9944 | 2016-04-12 10:29:17 -0700 | [diff] [blame] | 28 | #include "webrtc/media/engine/webrtcvideoengine2.h" |
| 29 | #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 30 | #include "webrtc/p2p/base/p2pconstants.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 31 | #include "webrtc/pc/mediasession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | |
| 33 | using cricket::AudioCodec; |
| 34 | using cricket::AudioContentDescription; |
| 35 | using cricket::Candidate; |
| 36 | using cricket::ContentInfo; |
| 37 | using cricket::CryptoParams; |
| 38 | using cricket::ContentGroup; |
| 39 | using cricket::DataCodec; |
| 40 | using cricket::DataContentDescription; |
| 41 | using cricket::ICE_CANDIDATE_COMPONENT_RTCP; |
| 42 | using cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 43 | using cricket::kFecSsrcGroupSemantics; |
| 44 | using cricket::LOCAL_PORT_TYPE; |
| 45 | using cricket::NS_JINGLE_DRAFT_SCTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | using cricket::NS_JINGLE_RTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | using cricket::RELAY_PORT_TYPE; |
| 48 | using cricket::SessionDescription; |
| 49 | using cricket::StreamParams; |
| 50 | using cricket::STUN_PORT_TYPE; |
| 51 | using cricket::TransportDescription; |
| 52 | using cricket::TransportInfo; |
| 53 | using cricket::VideoCodec; |
| 54 | using cricket::VideoContentDescription; |
| 55 | using webrtc::IceCandidateCollection; |
| 56 | using webrtc::IceCandidateInterface; |
| 57 | using webrtc::JsepIceCandidate; |
| 58 | using webrtc::JsepSessionDescription; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame^] | 59 | using webrtc::RtpExtension; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | using webrtc::SdpParseError; |
| 61 | using webrtc::SessionDescriptionInterface; |
| 62 | |
| 63 | typedef std::vector<AudioCodec> AudioCodecs; |
| 64 | typedef std::vector<Candidate> Candidates; |
| 65 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 66 | static const uint32_t kDefaultSctpPort = 5000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | static const char kSessionTime[] = "t=0 0\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 68 | static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 69 | static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 71 | static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 73 | static const uint32_t kCandidateGeneration = 2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | static const char kCandidateFoundation1[] = "a0+B/1"; |
| 75 | static const char kCandidateFoundation2[] = "a0+B/2"; |
| 76 | static const char kCandidateFoundation3[] = "a0+B/3"; |
| 77 | static const char kCandidateFoundation4[] = "a0+B/4"; |
| 78 | static 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"; |
| 82 | static const char kAttributeCryptoVideo[] = |
| 83 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 84 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"; |
| 85 | static 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"; |
| 87 | static const int kExtmapId = 1; |
| 88 | static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime"; |
| 89 | static const char kExtmap[] = |
| 90 | "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n"; |
| 91 | static const char kExtmapWithDirectionAndAttribute[] = |
| 92 | "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n"; |
| 93 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 94 | static 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | |
lally@webrtc.org | 3480728 | 2015-02-24 20:19:39 +0000 | [diff] [blame] | 98 | static const char kDtlsSctp[] = "DTLS/SCTP"; |
| 99 | static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; |
| 100 | static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 101 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | struct CodecParams { |
| 103 | int max_ptime; |
| 104 | int ptime; |
| 105 | int min_ptime; |
| 106 | int sprop_stereo; |
| 107 | int stereo; |
| 108 | int useinband; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 109 | int maxaveragebitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 112 | // 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | // Reference sdp string |
| 117 | static 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" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 122 | "a=msid-semantic: WMS local_stream_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | "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" |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 144 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | "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.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 150 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 151 | "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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | "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" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 176 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | "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" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 182 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 184 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | |
| 186 | // SDP reference string without the candidates. |
| 187 | static 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" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 192 | "a=msid-semantic: WMS local_stream_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 193 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 194 | "c=IN IP4 0.0.0.0\r\n" |
| 195 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | "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" |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 200 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | "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.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 206 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | "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.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 211 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 212 | "c=IN IP4 0.0.0.0\r\n" |
| 213 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 214 | "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" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 220 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | "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" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 226 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 228 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | |
| 230 | static const char kSdpRtpDataChannelString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 231 | "m=application 9 RTP/SAVPF 101\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 232 | "c=IN IP4 0.0.0.0\r\n" |
| 233 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | "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 | |
| 246 | static const char kSdpSctpDataChannelString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 247 | "m=application 9 DTLS/SCTP 5000\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 248 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 249 | "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.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 252 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | |
lally@webrtc.org | ec97c65 | 2015-02-24 20:18:48 +0000 | [diff] [blame] | 254 | // draft-ietf-mmusic-sctp-sdp-12 |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 255 | static const char kSdpSctpDataChannelStringWithSctpPort[] = |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 256 | "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 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 264 | static 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 273 | static 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.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 286 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 288 | static const char kSdpConferenceString[] = |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 289 | "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.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 294 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 295 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 296 | "a=x-google-flag:conference\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 297 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 298 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 299 | "a=x-google-flag:conference\r\n"; |
| 300 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 301 | static 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 | |
| 308 | static const char kSdpAudioString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 309 | "m=audio 9 RTP/SAVPF 111\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 310 | "c=IN IP4 0.0.0.0\r\n" |
| 311 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 312 | "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 | |
| 321 | static const char kSdpVideoString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 322 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 323 | "c=IN IP4 0.0.0.0\r\n" |
| 324 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 325 | "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 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 334 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 335 | // tracks. |
| 336 | static 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 Brandstetter | 5de6b75 | 2016-03-09 17:02:30 -0800 | [diff] [blame] | 417 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 418 | // tracks, but with the unified plan "a=msid" attribute. |
| 419 | static 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 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 502 | // Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 503 | // tracks. |
| 504 | static 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | |
| 609 | // One candidate reference string as per W3c spec. |
| 610 | // candidate:<blah> not a=candidate:<blah>CRLF |
| 611 | static 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. |
| 614 | static 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.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 617 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 618 | static const char kSdpTcpActiveCandidate[] = |
| 619 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 620 | "tcptype active generation 2"; |
| 621 | static const char kSdpTcpPassiveCandidate[] = |
| 622 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 623 | "tcptype passive generation 2"; |
| 624 | static const char kSdpTcpSOCandidate[] = |
| 625 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 626 | "tcptype so generation 2"; |
| 627 | static 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.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 631 | // One candidate reference string with IPV6 address. |
| 632 | static 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 635 | |
| 636 | // One candidate reference string. |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 637 | static const char kSdpOneCandidateWithUfragPwd[] = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 638 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name" |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 639 | " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 640 | |
| 641 | // Session id and version |
| 642 | static const char kSessionId[] = "18446744069414584320"; |
| 643 | static const char kSessionVersion[] = "18446462598732840960"; |
| 644 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 645 | // ICE options. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 646 | static const char kIceOption1[] = "iceoption1"; |
| 647 | static const char kIceOption2[] = "iceoption2"; |
| 648 | static const char kIceOption3[] = "iceoption3"; |
| 649 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 650 | // ICE ufrags/passwords. |
| 651 | static const char kUfragVoice[] = "ufrag_voice"; |
| 652 | static const char kPwdVoice[] = "pwd_voice"; |
| 653 | static const char kUfragVideo[] = "ufrag_video"; |
| 654 | static const char kPwdVideo[] = "pwd_video"; |
| 655 | static const char kUfragData[] = "ufrag_data"; |
| 656 | static const char kPwdData[] = "pwd_data"; |
| 657 | |
| 658 | // Extra ufrags/passwords for extra unified plan m= sections. |
| 659 | static const char kUfragVoice2[] = "ufrag_voice_2"; |
| 660 | static const char kPwdVoice2[] = "pwd_voice_2"; |
| 661 | static const char kUfragVideo2[] = "ufrag_video_2"; |
| 662 | static const char kPwdVideo2[] = "pwd_video_2"; |
| 663 | static const char kUfragVideo3[] = "ufrag_video_3"; |
| 664 | static const char kPwdVideo3[] = "pwd_video_3"; |
| 665 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 666 | // Content name |
| 667 | static const char kAudioContentName[] = "audio_content_name"; |
| 668 | static const char kVideoContentName[] = "video_content_name"; |
| 669 | static const char kDataContentName[] = "data_content_name"; |
| 670 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 671 | // Extra content names for extra unified plan m= sections. |
| 672 | static const char kAudioContentName2[] = "audio_content_name_2"; |
| 673 | static const char kVideoContentName2[] = "video_content_name_2"; |
| 674 | static const char kVideoContentName3[] = "video_content_name_3"; |
| 675 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 676 | // MediaStream 1 |
| 677 | static const char kStreamLabel1[] = "local_stream_1"; |
| 678 | static const char kStream1Cname[] = "stream_1_cname"; |
| 679 | static const char kAudioTrackId1[] = "audio_track_id_1"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 680 | static const uint32_t kAudioTrack1Ssrc = 1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 681 | static const char kVideoTrackId1[] = "video_track_id_1"; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 682 | static const uint32_t kVideoTrack1Ssrc1 = 2; |
| 683 | static const uint32_t kVideoTrack1Ssrc2 = 3; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 684 | |
| 685 | // MediaStream 2 |
| 686 | static const char kStreamLabel2[] = "local_stream_2"; |
| 687 | static const char kStream2Cname[] = "stream_2_cname"; |
| 688 | static const char kAudioTrackId2[] = "audio_track_id_2"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 689 | static const uint32_t kAudioTrack2Ssrc = 4; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 690 | static const char kVideoTrackId2[] = "video_track_id_2"; |
| 691 | static const uint32_t kVideoTrack2Ssrc = 5; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 692 | static const char kVideoTrackId3[] = "video_track_id_3"; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 693 | static const uint32_t kVideoTrack3Ssrc = 6; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 694 | |
| 695 | // DataChannel |
| 696 | static const char kDataChannelLabel[] = "data_channel"; |
| 697 | static const char kDataChannelMsid[] = "data_channeld0"; |
| 698 | static const char kDataChannelCname[] = "data_channel_cname"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 699 | static const uint32_t kDataChannelSsrc = 10; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 700 | |
| 701 | // Candidate |
| 702 | static const char kDummyMid[] = "dummy_mid"; |
| 703 | static const int kDummyIndex = 123; |
| 704 | |
| 705 | // Misc |
| 706 | static const char kDummyString[] = "dummy"; |
| 707 | |
| 708 | // Helper functions |
| 709 | |
| 710 | static bool SdpDeserialize(const std::string& message, |
| 711 | JsepSessionDescription* jdesc) { |
| 712 | return webrtc::SdpDeserialize(message, jdesc, NULL); |
| 713 | } |
| 714 | |
| 715 | static 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|. |
| 721 | static void InjectAfter(const std::string& line, |
| 722 | const std::string& newlines, |
| 723 | std::string* message) { |
| 724 | const std::string tmp = line + newlines; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 725 | rtc::replace_substrs(line.c_str(), line.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 726 | tmp.c_str(), tmp.length(), message); |
| 727 | } |
| 728 | |
| 729 | static void Replace(const std::string& line, |
| 730 | const std::string& newlines, |
| 731 | std::string* message) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 732 | rtc::replace_substrs(line.c_str(), line.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 733 | newlines.c_str(), newlines.length(), message); |
| 734 | } |
| 735 | |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 736 | // Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error |
| 737 | // message. |
| 738 | static void ExpectParseFailure(const std::string& bad_sdp, |
| 739 | const std::string& bad_part) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 740 | JsepSessionDescription desc(kDummyString); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 741 | SdpParseError error; |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 742 | bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 743 | EXPECT_FALSE(ret); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 744 | 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|. |
| 748 | static 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|. |
| 755 | static 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | static 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 | |
| 784 | static void ReplaceRejected(bool audio_rejected, bool video_rejected, |
| 785 | std::string* message) { |
| 786 | if (audio_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 787 | Replace("m=audio 9", "m=audio 0", message); |
| 788 | Replace(kAttributeIceUfragVoice, "", message); |
| 789 | Replace(kAttributeIcePwdVoice, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 790 | } |
| 791 | if (video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 792 | Replace("m=video 9", "m=video 0", message); |
| 793 | Replace(kAttributeIceUfragVideo, "", message); |
| 794 | Replace(kAttributeIcePwdVideo, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
| 798 | // WebRtcSdpTest |
| 799 | |
| 800 | class WebRtcSdpTest : public testing::Test { |
| 801 | public: |
| 802 | WebRtcSdpTest() |
| 803 | : jdesc_(kDummyString) { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 804 | #ifdef WEBRTC_ANDROID |
| 805 | webrtc::InitializeAndroidObjects(); |
| 806 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 807 | // AudioContentDescription |
| 808 | audio_desc_ = CreateAudioContentDescription(); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 809 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 815 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 816 | |
| 817 | // VideoContentDescription |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 818 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 829 | |
| 830 | // TransportInfo |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 831 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 832 | kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)))); |
| 833 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 834 | kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 835 | |
| 836 | // v4 host |
| 837 | int port = 1234; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 838 | rtc::SocketAddress address("192.168.1.5", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 839 | Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 840 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 841 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 842 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 843 | Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 844 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 845 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 846 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 847 | Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 848 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 849 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 850 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 851 | Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 852 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 853 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 854 | |
| 855 | // v6 host |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 856 | rtc::SocketAddress v6_address("::1", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 857 | cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 858 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 859 | cricket::LOCAL_PORT_TYPE, |
| 860 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 861 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 862 | cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 863 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 864 | cricket::LOCAL_PORT_TYPE, |
| 865 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 866 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 867 | cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 868 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 869 | cricket::LOCAL_PORT_TYPE, |
| 870 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 871 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 872 | cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 873 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 874 | cricket::LOCAL_PORT_TYPE, |
| 875 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 876 | |
| 877 | // stun |
| 878 | int port_stun = 2345; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 879 | rtc::SocketAddress address_stun("74.125.127.126", port_stun++); |
| 880 | rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 881 | cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 882 | address_stun, kCandidatePriority, "", "", |
| 883 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 884 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 885 | candidate9.set_related_address(rel_address_stun); |
| 886 | |
| 887 | address_stun.SetPort(port_stun++); |
| 888 | rel_address_stun.SetPort(port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 889 | cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 890 | address_stun, kCandidatePriority, "", "", |
| 891 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 892 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 893 | candidate10.set_related_address(rel_address_stun); |
| 894 | |
| 895 | // relay |
| 896 | int port_relay = 3456; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 897 | rtc::SocketAddress address_relay("74.125.224.39", port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 898 | cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 899 | address_relay, kCandidatePriority, "", "", |
| 900 | cricket::RELAY_PORT_TYPE, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 901 | kCandidateGeneration, kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | address_relay.SetPort(port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 903 | cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 904 | address_relay, kCandidatePriority, "", "", |
| 905 | RELAY_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 906 | kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 907 | |
| 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 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 944 | // 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1025 | AudioContentDescription* CreateAudioContentDescription() { |
| 1026 | AudioContentDescription* audio = new AudioContentDescription(); |
| 1027 | audio->set_rtcp_mux(true); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 1028 | audio->set_rtcp_reduced_size(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1029 | 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); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1033 | AudioCodec opus(111, "opus", 48000, 0, 2); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1034 | audio->AddCodec(opus); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1035 | audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1)); |
| 1036 | audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1037 | return audio; |
| 1038 | } |
| 1039 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1040 | // 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, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1052 | JsepSessionDescription::kDefaultVideoCodecFramerate)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1053 | return video; |
| 1054 | } |
| 1055 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1056 | 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 | |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 1068 | // rtcp_reduced_size |
| 1069 | EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size()); |
| 1070 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1071 | // 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.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1084 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1085 | // protocol |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1086 | // Use an equivalence class here, for old and new versions of the |
| 1087 | // protocol description. |
| 1088 | if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 1089 | || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp |
| 1090 | || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) { |
| 1091 | const bool cd2_is_also_dtls_sctp = |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1092 | cd2->protocol() == cricket::kMediaProtocolDtlsSctp |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 1093 | || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp |
| 1094 | || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp; |
| 1095 | EXPECT_TRUE(cd2_is_also_dtls_sctp); |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1096 | } else { |
| 1097 | EXPECT_EQ(cd1->protocol(), cd2->protocol()); |
| 1098 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1099 | |
| 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) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame^] | 1113 | const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); |
| 1114 | const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1115 | EXPECT_EQ(ext1.uri, ext2.uri); |
| 1116 | EXPECT_EQ(ext1.id, ext2.id); |
| 1117 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1118 | } |
| 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1203 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1216 | } |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1217 | |
| 1218 | // global attributes |
| 1219 | EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1222 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1253 | rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1254 | ice_ufragx, strlen(ice_ufragx), sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1255 | rtc::replace_substrs(ice_pwd, strlen(ice_pwd), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1256 | 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 Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 1272 | content_name, TransportDescription(ufrag, pwd)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1273 | 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 | |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1301 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1313 | void AddFingerprint() { |
| 1314 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 1315 | desc_.RemoveTransportInfoByName(kVideoContentName); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1316 | rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1317 | kIdentityDigest, |
| 1318 | sizeof(kIdentityDigest)); |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1319 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1320 | kAudioContentName, |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1321 | TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice, |
| 1322 | cricket::ICEMODE_FULL, |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1323 | cricket::CONNECTIONROLE_NONE, &fingerprint)))); |
| 1324 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1325 | kVideoContentName, |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1326 | TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, |
| 1327 | cricket::ICEMODE_FULL, |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1328 | cricket::CONNECTIONROLE_NONE, &fingerprint)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | void AddExtmap() { |
| 1332 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1333 | audio_desc_->Copy()); |
| 1334 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1335 | video_desc_->Copy()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame^] | 1336 | audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); |
| 1337 | video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1338 | desc_.RemoveContentByName(kAudioContentName); |
| 1339 | desc_.RemoveContentByName(kVideoContentName); |
| 1340 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 1341 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
| 1342 | } |
| 1343 | |
| 1344 | void RemoveCryptos() { |
| 1345 | audio_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1346 | video_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1347 | } |
| 1348 | |
| 1349 | bool TestSerializeDirection(cricket::MediaContentDirection direction) { |
| 1350 | audio_desc_->set_direction(direction); |
| 1351 | video_desc_->set_direction(direction); |
| 1352 | std::string new_sdp = kSdpFullString; |
| 1353 | ReplaceDirection(direction, &new_sdp); |
| 1354 | |
| 1355 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1356 | jdesc_.session_id(), |
| 1357 | jdesc_.session_version())) { |
| 1358 | return false; |
| 1359 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1360 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1361 | EXPECT_EQ(new_sdp, message); |
| 1362 | return true; |
| 1363 | } |
| 1364 | |
| 1365 | bool TestSerializeRejected(bool audio_rejected, bool video_rejected) { |
| 1366 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1367 | audio_desc_->Copy()); |
| 1368 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1369 | video_desc_->Copy()); |
| 1370 | desc_.RemoveContentByName(kAudioContentName); |
| 1371 | desc_.RemoveContentByName(kVideoContentName); |
| 1372 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1373 | audio_desc_); |
| 1374 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1375 | video_desc_); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1376 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1377 | audio_rejected ? "" : kPwdVoice); |
| 1378 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1379 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1380 | |
| 1381 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1382 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1383 | |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1384 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1385 | if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1386 | kSessionVersion)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1387 | return false; |
| 1388 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1389 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1390 | EXPECT_EQ(new_sdp, message); |
| 1391 | return true; |
| 1392 | } |
| 1393 | |
| 1394 | void AddSctpDataChannel() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1395 | std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1396 | data_desc_ = data.get(); |
| 1397 | data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1398 | DataCodec codec(cricket::kGoogleSctpDataCodecId, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1399 | cricket::kGoogleSctpDataCodecName); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1400 | codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort); |
| 1401 | data_desc_->AddCodec(codec); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1402 | desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release()); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1403 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1404 | kDataContentName, TransportDescription(kUfragData, kPwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | void AddRtpDataChannel() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1408 | std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1409 | data_desc_ = data.get(); |
| 1410 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1411 | data_desc_->AddCodec(DataCodec(101, "google-data")); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1412 | StreamParams data_stream; |
| 1413 | data_stream.id = kDataChannelMsid; |
| 1414 | data_stream.cname = kDataChannelCname; |
| 1415 | data_stream.sync_label = kDataChannelLabel; |
| 1416 | data_stream.ssrcs.push_back(kDataChannelSsrc); |
| 1417 | data_desc_->AddStream(data_stream); |
| 1418 | data_desc_->AddCrypto(CryptoParams( |
| 1419 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 1420 | "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", "")); |
| 1421 | data_desc_->set_protocol(cricket::kMediaProtocolSavpf); |
| 1422 | desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release()); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1423 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1424 | kDataContentName, TransportDescription(kUfragData, kPwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | bool TestDeserializeDirection(cricket::MediaContentDirection direction) { |
| 1428 | std::string new_sdp = kSdpFullString; |
| 1429 | ReplaceDirection(direction, &new_sdp); |
| 1430 | JsepSessionDescription new_jdesc(kDummyString); |
| 1431 | |
| 1432 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1433 | |
| 1434 | audio_desc_->set_direction(direction); |
| 1435 | video_desc_->set_direction(direction); |
| 1436 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1437 | jdesc_.session_id(), |
| 1438 | jdesc_.session_version())) { |
| 1439 | return false; |
| 1440 | } |
| 1441 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1442 | return true; |
| 1443 | } |
| 1444 | |
| 1445 | bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1446 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1447 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1448 | JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1449 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1450 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1451 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1452 | audio_desc_->Copy()); |
| 1453 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1454 | video_desc_->Copy()); |
| 1455 | desc_.RemoveContentByName(kAudioContentName); |
| 1456 | desc_.RemoveContentByName(kVideoContentName); |
| 1457 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1458 | audio_desc_); |
| 1459 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1460 | video_desc_); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1461 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1462 | audio_rejected ? "" : kPwdVoice); |
| 1463 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1464 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1465 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1466 | if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1467 | jdesc_.session_version())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1468 | return false; |
| 1469 | } |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1470 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1471 | return true; |
| 1472 | } |
| 1473 | |
| 1474 | void TestDeserializeExtmap(bool session_level, bool media_level) { |
| 1475 | AddExtmap(); |
| 1476 | JsepSessionDescription new_jdesc("dummy"); |
| 1477 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 1478 | jdesc_.session_id(), |
| 1479 | jdesc_.session_version())); |
| 1480 | JsepSessionDescription jdesc_with_extmap("dummy"); |
| 1481 | std::string sdp_with_extmap = kSdpString; |
| 1482 | if (session_level) { |
| 1483 | InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute, |
| 1484 | &sdp_with_extmap); |
| 1485 | } |
| 1486 | if (media_level) { |
| 1487 | InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute, |
| 1488 | &sdp_with_extmap); |
| 1489 | InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute, |
| 1490 | &sdp_with_extmap); |
| 1491 | } |
| 1492 | // The extmap can't be present at the same time in both session level and |
| 1493 | // media level. |
| 1494 | if (session_level && media_level) { |
| 1495 | SdpParseError error; |
| 1496 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap, |
| 1497 | &jdesc_with_extmap, &error)); |
| 1498 | EXPECT_NE(std::string::npos, error.description.find("a=extmap")); |
| 1499 | } else { |
| 1500 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap)); |
| 1501 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc)); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void VerifyCodecParameter(const cricket::CodecParameterMap& params, |
| 1506 | const std::string& name, int expected_value) { |
| 1507 | cricket::CodecParameterMap::const_iterator found = params.find(name); |
| 1508 | ASSERT_TRUE(found != params.end()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1509 | EXPECT_EQ(found->second, rtc::ToString<int>(expected_value)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | void TestDeserializeCodecParams(const CodecParams& params, |
| 1513 | JsepSessionDescription* jdesc_output) { |
| 1514 | std::string sdp = |
| 1515 | "v=0\r\n" |
| 1516 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1517 | "s=-\r\n" |
| 1518 | "t=0 0\r\n" |
| 1519 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1520 | // this parser, and will be added to the SDP when serializing a session |
| 1521 | // description. |
| 1522 | "a=msid-semantic: WMS\r\n" |
| 1523 | // Pl type 111 preferred. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 1524 | "m=audio 9 RTP/SAVPF 111 104 103\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1525 | // Pltype 111 listed before 103 and 104 in the map. |
| 1526 | "a=rtpmap:111 opus/48000/2\r\n" |
| 1527 | // Pltype 103 listed before 104. |
| 1528 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 1529 | "a=rtpmap:104 ISAC/32000\r\n" |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1530 | "a=fmtp:111 0-15,66,70\r\n" |
| 1531 | "a=fmtp:111 "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1532 | std::ostringstream os; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 1533 | os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1534 | << "; sprop-stereo=" << params.sprop_stereo |
| 1535 | << "; useinbandfec=" << params.useinband |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 1536 | << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1537 | << "a=ptime:" << params.ptime << "\r\n" |
| 1538 | << "a=maxptime:" << params.max_ptime << "\r\n"; |
| 1539 | sdp += os.str(); |
| 1540 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1541 | os.clear(); |
| 1542 | os.str(""); |
| 1543 | // Pl type 100 preferred. |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 1544 | os << "m=video 9 RTP/SAVPF 99 95\r\n" |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1545 | << "a=rtpmap:99 VP8/90000\r\n" |
| 1546 | << "a=rtpmap:95 RTX/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 1547 | << "a=fmtp:95 apt=99;\r\n"; |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1548 | sdp += os.str(); |
| 1549 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1550 | // Deserialize |
| 1551 | SdpParseError error; |
| 1552 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1553 | |
| 1554 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1555 | ASSERT_TRUE(ac != NULL); |
| 1556 | const AudioContentDescription* acd = |
| 1557 | static_cast<const AudioContentDescription*>(ac->description); |
| 1558 | ASSERT_FALSE(acd->codecs().empty()); |
| 1559 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1560 | EXPECT_EQ("opus", opus.name); |
| 1561 | EXPECT_EQ(111, opus.id); |
| 1562 | VerifyCodecParameter(opus.params, "minptime", params.min_ptime); |
| 1563 | VerifyCodecParameter(opus.params, "stereo", params.stereo); |
| 1564 | VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo); |
| 1565 | VerifyCodecParameter(opus.params, "useinbandfec", params.useinband); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1566 | VerifyCodecParameter(opus.params, "maxaveragebitrate", |
| 1567 | params.maxaveragebitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1568 | for (size_t i = 0; i < acd->codecs().size(); ++i) { |
| 1569 | cricket::AudioCodec codec = acd->codecs()[i]; |
| 1570 | VerifyCodecParameter(codec.params, "ptime", params.ptime); |
| 1571 | VerifyCodecParameter(codec.params, "maxptime", params.max_ptime); |
| 1572 | if (codec.name == "ISAC") { |
| 1573 | if (codec.clockrate == 16000) { |
| 1574 | EXPECT_EQ(32000, codec.bitrate); |
| 1575 | } else { |
| 1576 | EXPECT_EQ(56000, codec.bitrate); |
| 1577 | } |
| 1578 | } |
| 1579 | } |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1580 | |
| 1581 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description()); |
| 1582 | ASSERT_TRUE(vc != NULL); |
| 1583 | const VideoContentDescription* vcd = |
| 1584 | static_cast<const VideoContentDescription*>(vc->description); |
| 1585 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1586 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1587 | EXPECT_EQ("VP8", vp8.name); |
| 1588 | EXPECT_EQ(99, vp8.id); |
| 1589 | cricket::VideoCodec rtx = vcd->codecs()[1]; |
| 1590 | EXPECT_EQ("RTX", rtx.name); |
| 1591 | EXPECT_EQ(95, rtx.id); |
| 1592 | VerifyCodecParameter(rtx.params, "apt", vp8.id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output, |
| 1596 | bool use_wildcard) { |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1597 | std::string sdp_session_and_audio = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1598 | "v=0\r\n" |
| 1599 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1600 | "s=-\r\n" |
| 1601 | "t=0 0\r\n" |
| 1602 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1603 | // this parser, and will be added to the SDP when serializing a session |
| 1604 | // description. |
| 1605 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 1606 | "m=audio 9 RTP/SAVPF 111\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1607 | "a=rtpmap:111 opus/48000/2\r\n"; |
| 1608 | std::string sdp_video = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1609 | "m=video 3457 RTP/SAVPF 101\r\n" |
| 1610 | "a=rtpmap:101 VP8/90000\r\n" |
| 1611 | "a=rtcp-fb:101 nack\r\n" |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1612 | "a=rtcp-fb:101 nack pli\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1613 | "a=rtcp-fb:101 goog-remb\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1614 | std::ostringstream os; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1615 | os << sdp_session_and_audio; |
| 1616 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n"; |
| 1617 | os << sdp_video; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1618 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n"; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1619 | std::string sdp = os.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | // Deserialize |
| 1621 | SdpParseError error; |
| 1622 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1623 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1624 | ASSERT_TRUE(ac != NULL); |
| 1625 | const AudioContentDescription* acd = |
| 1626 | static_cast<const AudioContentDescription*>(ac->description); |
| 1627 | ASSERT_FALSE(acd->codecs().empty()); |
| 1628 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1629 | EXPECT_EQ(111, opus.id); |
| 1630 | EXPECT_TRUE(opus.HasFeedbackParam( |
| 1631 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1632 | cricket::kParamValueEmpty))); |
| 1633 | |
| 1634 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description()); |
| 1635 | ASSERT_TRUE(vc != NULL); |
| 1636 | const VideoContentDescription* vcd = |
| 1637 | static_cast<const VideoContentDescription*>(vc->description); |
| 1638 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1639 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1640 | EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName, |
| 1641 | vp8.name.c_str()); |
| 1642 | EXPECT_EQ(101, vp8.id); |
| 1643 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1644 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1645 | cricket::kParamValueEmpty))); |
| 1646 | EXPECT_TRUE(vp8.HasFeedbackParam( |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1647 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1648 | cricket::kRtcpFbNackParamPli))); |
| 1649 | EXPECT_TRUE(vp8.HasFeedbackParam( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1650 | cricket::FeedbackParam(cricket::kRtcpFbParamRemb, |
| 1651 | cricket::kParamValueEmpty))); |
| 1652 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1653 | cricket::FeedbackParam(cricket::kRtcpFbParamCcm, |
| 1654 | cricket::kRtcpFbCcmParamFir))); |
| 1655 | } |
| 1656 | |
| 1657 | // Two SDP messages can mean the same thing but be different strings, e.g. |
| 1658 | // some of the lines can be serialized in different order. |
| 1659 | // However, a deserialized description can be compared field by field and has |
| 1660 | // no order. If deserializer has already been tested, serializing then |
| 1661 | // deserializing and comparing JsepSessionDescription will test |
| 1662 | // the serializer sufficiently. |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1663 | void TestSerialize(const JsepSessionDescription& jdesc, |
| 1664 | bool unified_plan_sdp) { |
| 1665 | std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1666 | JsepSessionDescription jdesc_output_des(kDummyString); |
| 1667 | SdpParseError error; |
| 1668 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); |
| 1669 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); |
| 1670 | } |
| 1671 | |
| 1672 | protected: |
| 1673 | SessionDescription desc_; |
| 1674 | AudioContentDescription* audio_desc_; |
| 1675 | VideoContentDescription* video_desc_; |
| 1676 | DataContentDescription* data_desc_; |
| 1677 | Candidates candidates_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1678 | std::unique_ptr<IceCandidateInterface> jcandidate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1679 | JsepSessionDescription jdesc_; |
| 1680 | }; |
| 1681 | |
| 1682 | void TestMismatch(const std::string& string1, const std::string& string2) { |
| 1683 | int position = 0; |
| 1684 | for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { |
| 1685 | if (string1.c_str()[i] != string2.c_str()[i]) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1686 | position = static_cast<int>(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1687 | break; |
| 1688 | } |
| 1689 | } |
| 1690 | EXPECT_EQ(0, position) << "Strings mismatch at the " << position |
| 1691 | << " character\n" |
| 1692 | << " 1: " << string1.substr(position, 20) << "\n" |
| 1693 | << " 2: " << string2.substr(position, 20) << "\n"; |
| 1694 | } |
| 1695 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1696 | TEST_F(WebRtcSdpTest, SerializeSessionDescription) { |
| 1697 | // SessionDescription with desc and candidates. |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1698 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1699 | TestMismatch(std::string(kSdpFullString), message); |
| 1700 | } |
| 1701 | |
| 1702 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) { |
| 1703 | JsepSessionDescription jdesc_empty(kDummyString); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1704 | EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1707 | // This tests serialization of SDP with only IPv6 candidates and verifies that |
| 1708 | // IPv6 is used as default address in c line according to preference. |
| 1709 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) { |
| 1710 | // Only test 1 m line. |
| 1711 | desc_.RemoveContentByName("video_content_name"); |
| 1712 | // Stun has a high preference than local host. |
| 1713 | cricket::Candidate candidate1( |
| 1714 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1715 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1716 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1717 | cricket::Candidate candidate2( |
| 1718 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1719 | rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| 1720 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1721 | JsepSessionDescription jdesc(kDummyString); |
| 1722 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1723 | |
| 1724 | // Only add the candidates to audio m line. |
| 1725 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1726 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1727 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1728 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1729 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1730 | |
| 1731 | // Audio line should have a c line like this one. |
| 1732 | EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos); |
| 1733 | // Shouldn't have a IP4 c line. |
| 1734 | EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| 1735 | } |
| 1736 | |
| 1737 | // This tests serialization of SDP with both IPv4 and IPv6 candidates and |
| 1738 | // verifies that IPv4 is used as default address in c line even if the |
| 1739 | // preference of IPv4 is lower. |
| 1740 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) { |
| 1741 | // Only test 1 m line. |
| 1742 | desc_.RemoveContentByName("video_content_name"); |
| 1743 | cricket::Candidate candidate_v4( |
| 1744 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1745 | rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "", |
| 1746 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1747 | cricket::Candidate candidate_v6( |
| 1748 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1749 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1750 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1751 | JsepSessionDescription jdesc(kDummyString); |
| 1752 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1753 | |
| 1754 | // Only add the candidates to audio m line. |
| 1755 | JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4); |
| 1756 | JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6); |
| 1757 | ASSERT_TRUE(jdesc.AddCandidate(&jice_v4)); |
| 1758 | ASSERT_TRUE(jdesc.AddCandidate(&jice_v6)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1759 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1760 | |
| 1761 | // Audio line should have a c line like this one. |
| 1762 | EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos); |
| 1763 | // Shouldn't have a IP6 c line. |
| 1764 | EXPECT_EQ(message.find("c=IN IP6"), std::string::npos); |
| 1765 | } |
| 1766 | |
| 1767 | // This tests serialization of SDP with both UDP and TCP candidates and |
| 1768 | // verifies that UDP is used as default address in c line even if the |
| 1769 | // preference of UDP is lower. |
| 1770 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) { |
| 1771 | // Only test 1 m line. |
| 1772 | desc_.RemoveContentByName("video_content_name"); |
| 1773 | // Stun has a high preference than local host. |
| 1774 | cricket::Candidate candidate1( |
| 1775 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1776 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1777 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1778 | cricket::Candidate candidate2( |
| 1779 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1780 | rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority, |
| 1781 | "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration, |
| 1782 | kCandidateFoundation1); |
| 1783 | JsepSessionDescription jdesc(kDummyString); |
| 1784 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1785 | |
| 1786 | // Only add the candidates to audio m line. |
| 1787 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1788 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1789 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1790 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1791 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1792 | |
| 1793 | // Audio line should have a c line like this one. |
| 1794 | EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"), |
| 1795 | std::string::npos); |
| 1796 | // Shouldn't have a IP4 c line. |
| 1797 | EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| 1798 | } |
| 1799 | |
| 1800 | // This tests serialization of SDP with only TCP candidates and verifies that |
| 1801 | // null IPv4 is used as default address in c line. |
| 1802 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) { |
| 1803 | // Only test 1 m line. |
| 1804 | desc_.RemoveContentByName("video_content_name"); |
| 1805 | // Stun has a high preference than local host. |
| 1806 | cricket::Candidate candidate1( |
| 1807 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1808 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1809 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1810 | cricket::Candidate candidate2( |
| 1811 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1812 | rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| 1813 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1814 | JsepSessionDescription jdesc(kDummyString); |
| 1815 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1816 | |
| 1817 | // Only add the candidates to audio m line. |
| 1818 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1819 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1820 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1821 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1822 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1823 | |
| 1824 | // Audio line should have a c line like this one when no any default exists. |
| 1825 | EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos); |
| 1826 | } |
| 1827 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1828 | // This tests serialization of SDP with a=crypto and a=fingerprint, as would be |
| 1829 | // the case in a DTLS offer. |
| 1830 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) { |
| 1831 | AddFingerprint(); |
| 1832 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1833 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1834 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1835 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1836 | |
| 1837 | std::string sdp_with_fingerprint = kSdpString; |
| 1838 | InjectAfter(kAttributeIcePwdVoice, |
| 1839 | kFingerprint, &sdp_with_fingerprint); |
| 1840 | InjectAfter(kAttributeIcePwdVideo, |
| 1841 | kFingerprint, &sdp_with_fingerprint); |
| 1842 | |
| 1843 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1844 | } |
| 1845 | |
| 1846 | // This tests serialization of SDP with a=fingerprint with no a=crypto, as would |
| 1847 | // be the case in a DTLS answer. |
| 1848 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) { |
| 1849 | AddFingerprint(); |
| 1850 | RemoveCryptos(); |
| 1851 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1852 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1853 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1854 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1855 | |
| 1856 | std::string sdp_with_fingerprint = kSdpString; |
| 1857 | Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint); |
| 1858 | Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint); |
| 1859 | InjectAfter(kAttributeIcePwdVoice, |
| 1860 | kFingerprint, &sdp_with_fingerprint); |
| 1861 | InjectAfter(kAttributeIcePwdVideo, |
| 1862 | kFingerprint, &sdp_with_fingerprint); |
| 1863 | |
| 1864 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1865 | } |
| 1866 | |
| 1867 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { |
| 1868 | // JsepSessionDescription with desc but without candidates. |
| 1869 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1870 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1871 | kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1872 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1873 | EXPECT_EQ(std::string(kSdpString), message); |
| 1874 | } |
| 1875 | |
| 1876 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) { |
| 1877 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1878 | group.AddContentName(kAudioContentName); |
| 1879 | group.AddContentName(kVideoContentName); |
| 1880 | desc_.AddGroup(group); |
| 1881 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1882 | jdesc_.session_id(), |
| 1883 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1884 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1885 | std::string sdp_with_bundle = kSdpFullString; |
| 1886 | InjectAfter(kSessionTime, |
| 1887 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 1888 | &sdp_with_bundle); |
| 1889 | EXPECT_EQ(sdp_with_bundle, message); |
| 1890 | } |
| 1891 | |
| 1892 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) { |
| 1893 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 1894 | GetFirstVideoContent(&desc_)->description); |
| 1895 | vcd->set_bandwidth(100 * 1000); |
| 1896 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 1897 | GetFirstAudioContent(&desc_)->description); |
| 1898 | acd->set_bandwidth(50 * 1000); |
| 1899 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1900 | jdesc_.session_id(), |
| 1901 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1902 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1903 | std::string sdp_with_bandwidth = kSdpFullString; |
wu@webrtc.org | 4c3e991 | 2014-07-16 21:03:13 +0000 | [diff] [blame] | 1904 | InjectAfter("c=IN IP4 74.125.224.39\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1905 | "b=AS:100\r\n", |
| 1906 | &sdp_with_bandwidth); |
wu@webrtc.org | 4c3e991 | 2014-07-16 21:03:13 +0000 | [diff] [blame] | 1907 | InjectAfter("c=IN IP4 74.125.127.126\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1908 | "b=AS:50\r\n", |
| 1909 | &sdp_with_bandwidth); |
| 1910 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 1911 | } |
| 1912 | |
| 1913 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) { |
| 1914 | std::vector<std::string> transport_options; |
| 1915 | transport_options.push_back(kIceOption1); |
| 1916 | transport_options.push_back(kIceOption3); |
| 1917 | AddIceOptions(kAudioContentName, transport_options); |
| 1918 | transport_options.clear(); |
| 1919 | transport_options.push_back(kIceOption2); |
| 1920 | transport_options.push_back(kIceOption3); |
| 1921 | AddIceOptions(kVideoContentName, transport_options); |
| 1922 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1923 | jdesc_.session_id(), |
| 1924 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1925 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1926 | std::string sdp_with_ice_options = kSdpFullString; |
| 1927 | InjectAfter(kAttributeIcePwdVoice, |
| 1928 | "a=ice-options:iceoption1 iceoption3\r\n", |
| 1929 | &sdp_with_ice_options); |
| 1930 | InjectAfter(kAttributeIcePwdVideo, |
| 1931 | "a=ice-options:iceoption2 iceoption3\r\n", |
| 1932 | &sdp_with_ice_options); |
| 1933 | EXPECT_EQ(sdp_with_ice_options, message); |
| 1934 | } |
| 1935 | |
| 1936 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) { |
| 1937 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY)); |
| 1938 | } |
| 1939 | |
| 1940 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) { |
| 1941 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY)); |
| 1942 | } |
| 1943 | |
| 1944 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) { |
| 1945 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE)); |
| 1946 | } |
| 1947 | |
| 1948 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) { |
| 1949 | EXPECT_TRUE(TestSerializeRejected(true, false)); |
| 1950 | } |
| 1951 | |
| 1952 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) { |
| 1953 | EXPECT_TRUE(TestSerializeRejected(false, true)); |
| 1954 | } |
| 1955 | |
| 1956 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) { |
| 1957 | EXPECT_TRUE(TestSerializeRejected(true, true)); |
| 1958 | } |
| 1959 | |
| 1960 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) { |
| 1961 | AddRtpDataChannel(); |
| 1962 | JsepSessionDescription jsep_desc(kDummyString); |
| 1963 | |
| 1964 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1965 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1966 | |
| 1967 | std::string expected_sdp = kSdpString; |
| 1968 | expected_sdp.append(kSdpRtpDataChannelString); |
| 1969 | EXPECT_EQ(expected_sdp, message); |
| 1970 | } |
| 1971 | |
| 1972 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) { |
| 1973 | AddSctpDataChannel(); |
| 1974 | JsepSessionDescription jsep_desc(kDummyString); |
| 1975 | |
| 1976 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1977 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1978 | |
| 1979 | std::string expected_sdp = kSdpString; |
| 1980 | expected_sdp.append(kSdpSctpDataChannelString); |
| 1981 | EXPECT_EQ(message, expected_sdp); |
| 1982 | } |
| 1983 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1984 | TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) { |
| 1985 | AddSctpDataChannel(); |
| 1986 | JsepSessionDescription jsep_desc(kDummyString); |
| 1987 | |
| 1988 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1989 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 1990 | jsep_desc.description()->GetContentDescriptionByName(kDataContentName)); |
| 1991 | |
| 1992 | const int kNewPort = 1234; |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1993 | cricket::DataCodec codec(cricket::kGoogleSctpDataCodecId, |
| 1994 | cricket::kGoogleSctpDataCodecName); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1995 | codec.SetParam(cricket::kCodecParamPort, kNewPort); |
| 1996 | dcdesc->AddOrReplaceCodec(codec); |
| 1997 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1998 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1999 | |
| 2000 | std::string expected_sdp = kSdpString; |
| 2001 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2002 | |
| 2003 | char default_portstr[16]; |
| 2004 | char new_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2005 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2006 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2007 | rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort); |
| 2008 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2009 | new_portstr, strlen(new_portstr), |
| 2010 | &expected_sdp); |
| 2011 | |
| 2012 | EXPECT_EQ(expected_sdp, message); |
| 2013 | } |
| 2014 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2015 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) { |
| 2016 | AddRtpDataChannel(); |
| 2017 | data_desc_->set_bandwidth(100*1000); |
| 2018 | JsepSessionDescription jsep_desc(kDummyString); |
| 2019 | |
| 2020 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2021 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2022 | |
| 2023 | std::string expected_sdp = kSdpString; |
| 2024 | expected_sdp.append(kSdpRtpDataChannelString); |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2025 | // Serializing data content shouldn't ignore bandwidth settings. |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 2026 | InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n", |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2027 | "b=AS:100\r\n", |
| 2028 | &expected_sdp); |
| 2029 | EXPECT_EQ(expected_sdp, message); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2032 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { |
| 2033 | AddExtmap(); |
| 2034 | JsepSessionDescription desc_with_extmap("dummy"); |
| 2035 | ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(), |
| 2036 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2037 | std::string message = webrtc::SdpSerialize(desc_with_extmap, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2038 | |
| 2039 | std::string sdp_with_extmap = kSdpString; |
| 2040 | InjectAfter("a=mid:audio_content_name\r\n", |
| 2041 | kExtmap, &sdp_with_extmap); |
| 2042 | InjectAfter("a=mid:video_content_name\r\n", |
| 2043 | kExtmap, &sdp_with_extmap); |
| 2044 | |
| 2045 | EXPECT_EQ(sdp_with_extmap, message); |
| 2046 | } |
| 2047 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2048 | TEST_F(WebRtcSdpTest, SerializeCandidates) { |
| 2049 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); |
wu@webrtc.org | ec9f5fb | 2014-06-24 17:05:10 +0000 | [diff] [blame] | 2050 | EXPECT_EQ(std::string(kRawCandidate), message); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2051 | |
| 2052 | Candidate candidate_with_ufrag(candidates_.front()); |
| 2053 | candidate_with_ufrag.set_username("ABC"); |
| 2054 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, |
| 2055 | candidate_with_ufrag)); |
| 2056 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2057 | EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2058 | |
| 2059 | Candidate candidate_with_network_info(candidates_.front()); |
| 2060 | candidate_with_network_info.set_network_id(1); |
| 2061 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2062 | candidate_with_network_info)); |
| 2063 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2064 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message); |
| 2065 | candidate_with_network_info.set_network_cost(999); |
| 2066 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2067 | candidate_with_network_info)); |
| 2068 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2069 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999", |
| 2070 | message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2073 | // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing |
| 2074 | // RFC 6544. |
mallinath@webrtc.org | e999bd0 | 2014-08-13 06:05:55 +0000 | [diff] [blame] | 2075 | TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2076 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2077 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2078 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2079 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2080 | candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2081 | std::unique_ptr<IceCandidateInterface> jcandidate( |
| 2082 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2083 | |
| 2084 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
| 2085 | EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
| 2086 | } |
| 2087 | |
hta | a6b9944 | 2016-04-12 10:29:17 -0700 | [diff] [blame] | 2088 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) { |
| 2089 | if (!webrtc::H264Encoder::IsSupported()) |
| 2090 | return; |
| 2091 | for (const auto& codec : cricket::DefaultVideoCodecList()) { |
| 2092 | video_desc_->AddCodec(codec); |
| 2093 | } |
| 2094 | jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion); |
| 2095 | |
| 2096 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
| 2097 | size_t after_pt = message.find(" H264/90000"); |
| 2098 | ASSERT_NE(after_pt, std::string::npos); |
| 2099 | size_t before_pt = message.rfind("a=rtpmap:", after_pt); |
| 2100 | ASSERT_NE(before_pt, std::string::npos); |
| 2101 | before_pt += strlen("a=rtpmap:"); |
| 2102 | std::string pt = message.substr(before_pt, after_pt - before_pt); |
| 2103 | // TODO(hta): Check if payload type |pt| occurs in the m=video line. |
| 2104 | std::string to_find = "a=fmtp:" + pt + " "; |
| 2105 | size_t fmtp_pos = message.find(to_find); |
| 2106 | ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find; |
| 2107 | size_t fmtp_endpos = message.find("\n", fmtp_pos); |
| 2108 | ASSERT_NE(std::string::npos, fmtp_endpos); |
| 2109 | std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos); |
| 2110 | EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1")); |
| 2111 | EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1")); |
| 2112 | EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f")); |
hta | 62a216e | 2016-04-15 11:02:14 -0700 | [diff] [blame] | 2113 | // Check that there are no spaces after semicolons. |
| 2114 | // https://bugs.webrtc.org/5793 |
| 2115 | EXPECT_EQ(std::string::npos, fmtp_value.find("; ")); |
hta | a6b9944 | 2016-04-12 10:29:17 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2118 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
| 2119 | JsepSessionDescription jdesc(kDummyString); |
| 2120 | // Deserialize |
| 2121 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 2122 | // Verify |
| 2123 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2124 | } |
| 2125 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2126 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) { |
| 2127 | JsepSessionDescription jdesc(kDummyString); |
| 2128 | const char kSdpWithoutMline[] = |
| 2129 | "v=0\r\n" |
| 2130 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2131 | "s=-\r\n" |
| 2132 | "t=0 0\r\n" |
| 2133 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"; |
| 2134 | // Deserialize |
| 2135 | EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc)); |
| 2136 | EXPECT_EQ(0u, jdesc.description()->contents().size()); |
| 2137 | } |
| 2138 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2139 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
| 2140 | JsepSessionDescription jdesc(kDummyString); |
| 2141 | std::string sdp_without_carriage_return = kSdpFullString; |
| 2142 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 2143 | // Deserialize |
| 2144 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 2145 | // Verify |
| 2146 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2147 | } |
| 2148 | |
| 2149 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 2150 | // SessionDescription with desc but without candidates. |
| 2151 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 2152 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), |
| 2153 | kSessionId, kSessionVersion)); |
| 2154 | JsepSessionDescription new_jdesc(kDummyString); |
| 2155 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 2156 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 2157 | } |
| 2158 | |
| 2159 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 2160 | static const char kSdpNoRtpmapString[] = |
| 2161 | "v=0\r\n" |
| 2162 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2163 | "s=-\r\n" |
| 2164 | "t=0 0\r\n" |
| 2165 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 2166 | // Codec that doesn't appear in the m= line will be ignored. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2167 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2168 | // The rtpmap line for static payload codec is optional. |
| 2169 | "a=rtpmap:18 G729/16000\r\n" |
| 2170 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2171 | |
| 2172 | JsepSessionDescription jdesc(kDummyString); |
| 2173 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2174 | cricket::AudioContentDescription* audio = |
| 2175 | static_cast<AudioContentDescription*>( |
| 2176 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2177 | AudioCodecs ref_codecs; |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 2178 | // The codecs in the AudioContentDescription should be in the same order as |
| 2179 | // the payload types (<fmt>s) on the m= line. |
| 2180 | ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1)); |
| 2181 | ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1)); |
| 2182 | ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2183 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 2184 | } |
| 2185 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2186 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) { |
| 2187 | static const char kSdpNoRtpmapString[] = |
| 2188 | "v=0\r\n" |
| 2189 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2190 | "s=-\r\n" |
| 2191 | "t=0 0\r\n" |
| 2192 | "m=audio 49232 RTP/AVP 18 103\r\n" |
| 2193 | "a=fmtp:18 annexb=yes\r\n" |
| 2194 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2195 | |
| 2196 | JsepSessionDescription jdesc(kDummyString); |
| 2197 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2198 | cricket::AudioContentDescription* audio = |
| 2199 | static_cast<AudioContentDescription*>( |
| 2200 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2201 | |
| 2202 | cricket::AudioCodec g729 = audio->codecs()[0]; |
| 2203 | EXPECT_EQ("G729", g729.name); |
| 2204 | EXPECT_EQ(8000, g729.clockrate); |
| 2205 | EXPECT_EQ(18, g729.id); |
| 2206 | cricket::CodecParameterMap::iterator found = |
| 2207 | g729.params.find("annexb"); |
| 2208 | ASSERT_TRUE(found != g729.params.end()); |
| 2209 | EXPECT_EQ(found->second, "yes"); |
| 2210 | |
| 2211 | cricket::AudioCodec isac = audio->codecs()[1]; |
| 2212 | EXPECT_EQ("ISAC", isac.name); |
| 2213 | EXPECT_EQ(103, isac.id); |
| 2214 | EXPECT_EQ(16000, isac.clockrate); |
| 2215 | } |
| 2216 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2217 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 2218 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 2219 | // Add a DTLS a=fingerprint attribute to our session description. |
| 2220 | AddFingerprint(); |
| 2221 | JsepSessionDescription new_jdesc(kDummyString); |
| 2222 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 2223 | jdesc_.session_id(), |
| 2224 | jdesc_.session_version())); |
| 2225 | |
| 2226 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 2227 | std::string sdp_with_fingerprint = kSdpString; |
| 2228 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2229 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 2230 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 2231 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 2232 | } |
| 2233 | |
| 2234 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
| 2235 | JsepSessionDescription jdesc_with_bundle(kDummyString); |
| 2236 | std::string sdp_with_bundle = kSdpFullString; |
| 2237 | InjectAfter(kSessionTime, |
| 2238 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 2239 | &sdp_with_bundle); |
| 2240 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 2241 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 2242 | group.AddContentName(kAudioContentName); |
| 2243 | group.AddContentName(kVideoContentName); |
| 2244 | desc_.AddGroup(group); |
| 2245 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2246 | jdesc_.session_id(), |
| 2247 | jdesc_.session_version())); |
| 2248 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 2249 | } |
| 2250 | |
| 2251 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
| 2252 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2253 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2254 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 2255 | "b=AS:100\r\n", |
| 2256 | &sdp_with_bandwidth); |
| 2257 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 2258 | "b=AS:50\r\n", |
| 2259 | &sdp_with_bandwidth); |
| 2260 | EXPECT_TRUE( |
| 2261 | SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2262 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2263 | GetFirstVideoContent(&desc_)->description); |
| 2264 | vcd->set_bandwidth(100 * 1000); |
| 2265 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 2266 | GetFirstAudioContent(&desc_)->description); |
| 2267 | acd->set_bandwidth(50 * 1000); |
| 2268 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2269 | jdesc_.session_id(), |
| 2270 | jdesc_.session_version())); |
| 2271 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2272 | } |
| 2273 | |
| 2274 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
| 2275 | JsepSessionDescription jdesc_with_ice_options(kDummyString); |
| 2276 | std::string sdp_with_ice_options = kSdpFullString; |
| 2277 | InjectAfter(kSessionTime, |
| 2278 | "a=ice-options:iceoption3\r\n", |
| 2279 | &sdp_with_ice_options); |
| 2280 | InjectAfter(kAttributeIcePwdVoice, |
| 2281 | "a=ice-options:iceoption1\r\n", |
| 2282 | &sdp_with_ice_options); |
| 2283 | InjectAfter(kAttributeIcePwdVideo, |
| 2284 | "a=ice-options:iceoption2\r\n", |
| 2285 | &sdp_with_ice_options); |
| 2286 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 2287 | std::vector<std::string> transport_options; |
| 2288 | transport_options.push_back(kIceOption3); |
| 2289 | transport_options.push_back(kIceOption1); |
| 2290 | AddIceOptions(kAudioContentName, transport_options); |
| 2291 | transport_options.clear(); |
| 2292 | transport_options.push_back(kIceOption3); |
| 2293 | transport_options.push_back(kIceOption2); |
| 2294 | AddIceOptions(kVideoContentName, transport_options); |
| 2295 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2296 | jdesc_.session_id(), |
| 2297 | jdesc_.session_version())); |
| 2298 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 2299 | } |
| 2300 | |
| 2301 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 2302 | // Remove the original ice-ufrag and ice-pwd |
| 2303 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString); |
| 2304 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 2305 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 2306 | // Add session level ufrag and pwd |
| 2307 | InjectAfter(kSessionTime, |
| 2308 | "a=ice-pwd:session+level+icepwd\r\n" |
| 2309 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 2310 | &sdp_with_ufrag_pwd); |
| 2311 | // Add media level ufrag and pwd for audio |
| 2312 | InjectAfter("a=mid:audio_content_name\r\n", |
| 2313 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 2314 | &sdp_with_ufrag_pwd); |
| 2315 | // Update the candidate ufrag and pwd to the expected ones. |
| 2316 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, |
| 2317 | "media+level+iceufrag", "media+level+icepwd")); |
| 2318 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, |
| 2319 | "session+level+iceufrag", "session+level+icepwd")); |
| 2320 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 2321 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 2322 | } |
| 2323 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2324 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
| 2325 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY)); |
| 2326 | } |
| 2327 | |
| 2328 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
| 2329 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY)); |
| 2330 | } |
| 2331 | |
| 2332 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
| 2333 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE)); |
| 2334 | } |
| 2335 | |
| 2336 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 2337 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 2338 | } |
| 2339 | |
| 2340 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 2341 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 2342 | } |
| 2343 | |
| 2344 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 2345 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 2346 | } |
| 2347 | |
| 2348 | // Tests that we can still handle the sdp uses mslabel and label instead of |
| 2349 | // msid for backward compatibility. |
| 2350 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2351 | jdesc_.description()->set_msid_supported(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2352 | JsepSessionDescription jdesc(kDummyString); |
| 2353 | std::string sdp_without_msid = kSdpFullString; |
| 2354 | Replace("msid", "xmsid", &sdp_without_msid); |
| 2355 | // Deserialize |
| 2356 | EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc)); |
| 2357 | // Verify |
| 2358 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2359 | } |
| 2360 | |
| 2361 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 2362 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2363 | |
| 2364 | std::string sdp = kSdpOneCandidate; |
| 2365 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2366 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2367 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2368 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2369 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2370 | |
| 2371 | // Candidate line without generation extension. |
| 2372 | sdp = kSdpOneCandidate; |
| 2373 | Replace(" generation 2", "", &sdp); |
| 2374 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2375 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2376 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2377 | Candidate expected = jcandidate_->candidate(); |
| 2378 | expected.set_generation(0); |
| 2379 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2380 | |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2381 | // Candidate with network id and/or cost. |
| 2382 | sdp = kSdpOneCandidate; |
| 2383 | Replace(" generation 2", " generation 2 network-id 2", &sdp); |
| 2384 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2385 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2386 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2387 | expected = jcandidate_->candidate(); |
| 2388 | expected.set_network_id(2); |
| 2389 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2390 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
| 2391 | // Add network cost |
| 2392 | Replace(" network-id 2", " network-id 2 network-cost 9", &sdp); |
| 2393 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2394 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2395 | EXPECT_EQ(9, jcandidate.candidate().network_cost()); |
| 2396 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2397 | sdp = kSdpTcpActiveCandidate; |
| 2398 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2399 | // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2400 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2401 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2402 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2403 | kCandidateFoundation1); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2404 | std::unique_ptr<IceCandidateInterface> jcandidate_template( |
| 2405 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2406 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent( |
| 2407 | jcandidate_template->candidate())); |
| 2408 | sdp = kSdpTcpPassiveCandidate; |
| 2409 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2410 | sdp = kSdpTcpSOCandidate; |
| 2411 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | // This test verifies the deserialization of candidate-attribute |
| 2415 | // as per RFC 5245. Candiate-attribute will be of the format |
| 2416 | // candidate:<blah>. This format will be used when candidates |
| 2417 | // are trickled. |
| 2418 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 2419 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2420 | |
| 2421 | std::string candidate_attribute = kRawCandidate; |
| 2422 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2423 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2424 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2425 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2426 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 2427 | |
| 2428 | // Candidate line without generation extension. |
| 2429 | candidate_attribute = kRawCandidate; |
| 2430 | Replace(" generation 2", "", &candidate_attribute); |
| 2431 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2432 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2433 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2434 | Candidate expected = jcandidate_->candidate(); |
| 2435 | expected.set_generation(0); |
| 2436 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2437 | |
| 2438 | // Candidate line without candidate: |
| 2439 | candidate_attribute = kRawCandidate; |
| 2440 | Replace("candidate:", "", &candidate_attribute); |
| 2441 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2442 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2443 | // Candidate line with IPV6 address. |
| 2444 | EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate)); |
| 2445 | } |
| 2446 | |
| 2447 | // This test verifies that the deserialization of an invalid candidate string |
| 2448 | // fails. |
| 2449 | TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) { |
| 2450 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2451 | |
| 2452 | std::string candidate_attribute = kRawCandidate; |
| 2453 | candidate_attribute.replace(0, 1, "x"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2454 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2455 | |
| 2456 | candidate_attribute = kSdpOneCandidate; |
| 2457 | candidate_attribute.replace(0, 1, "x"); |
| 2458 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2459 | |
| 2460 | candidate_attribute = kRawCandidate; |
| 2461 | candidate_attribute.append("\r\n"); |
| 2462 | candidate_attribute.append(kRawCandidate); |
| 2463 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2464 | |
| 2465 | EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) { |
| 2469 | AddRtpDataChannel(); |
| 2470 | JsepSessionDescription jdesc(kDummyString); |
| 2471 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2472 | |
| 2473 | std::string sdp_with_data = kSdpString; |
| 2474 | sdp_with_data.append(kSdpRtpDataChannelString); |
| 2475 | JsepSessionDescription jdesc_output(kDummyString); |
| 2476 | |
| 2477 | // Deserialize |
| 2478 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2479 | // Verify |
| 2480 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2481 | } |
| 2482 | |
| 2483 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
| 2484 | AddSctpDataChannel(); |
| 2485 | JsepSessionDescription jdesc(kDummyString); |
| 2486 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2487 | |
| 2488 | std::string sdp_with_data = kSdpString; |
| 2489 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2490 | JsepSessionDescription jdesc_output(kDummyString); |
| 2491 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2492 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString). |
| 2493 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2494 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2495 | |
| 2496 | // Verify with UDP/DTLS/SCTP. |
| 2497 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2498 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2499 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2500 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2501 | |
| 2502 | // Verify with TCP/DTLS/SCTP. |
| 2503 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2504 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2505 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2506 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2507 | } |
| 2508 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2509 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { |
| 2510 | AddSctpDataChannel(); |
| 2511 | JsepSessionDescription jdesc(kDummyString); |
| 2512 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2513 | |
| 2514 | std::string sdp_with_data = kSdpString; |
| 2515 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2516 | JsepSessionDescription jdesc_output(kDummyString); |
| 2517 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2518 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort). |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2519 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2520 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2521 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2522 | // Verify with UDP/DTLS/SCTP. |
| 2523 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2524 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2525 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2526 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2527 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2528 | // Verify with TCP/DTLS/SCTP. |
| 2529 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2530 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2531 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2532 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2533 | } |
| 2534 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 2535 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { |
| 2536 | AddSctpDataChannel(); |
| 2537 | JsepSessionDescription jdesc(kDummyString); |
| 2538 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2539 | |
| 2540 | std::string sdp_with_data = kSdpString; |
| 2541 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
| 2542 | JsepSessionDescription jdesc_output(kDummyString); |
| 2543 | |
| 2544 | // Verify with DTLS/SCTP. |
| 2545 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2546 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2547 | |
| 2548 | // Verify with UDP/DTLS/SCTP. |
| 2549 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2550 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2551 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2552 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2553 | |
| 2554 | // Verify with TCP/DTLS/SCTP. |
| 2555 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2556 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
| 2557 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2558 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2559 | } |
| 2560 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2561 | // Test to check the behaviour if sctp-port is specified |
| 2562 | // on the m= line and in a=sctp-port. |
| 2563 | TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { |
| 2564 | AddSctpDataChannel(); |
| 2565 | JsepSessionDescription jdesc(kDummyString); |
| 2566 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2567 | |
| 2568 | std::string sdp_with_data = kSdpString; |
| 2569 | // Append m= attributes |
| 2570 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2571 | // Append a=sctp-port attribute |
| 2572 | sdp_with_data.append("a=sctp-port 5000\r\n"); |
| 2573 | JsepSessionDescription jdesc_output(kDummyString); |
| 2574 | |
| 2575 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2576 | } |
| 2577 | |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 +0000 | [diff] [blame] | 2578 | // For crbug/344475. |
| 2579 | TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { |
| 2580 | std::string sdp_with_data = kSdpString; |
| 2581 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2582 | // Remove the "\n" at the end. |
| 2583 | sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); |
| 2584 | JsepSessionDescription jdesc_output(kDummyString); |
| 2585 | |
| 2586 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2587 | // No crash is a pass. |
| 2588 | } |
| 2589 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2590 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) { |
| 2591 | AddSctpDataChannel(); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2592 | const uint16_t kUnusualSctpPort = 9556; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2593 | char default_portstr[16]; |
| 2594 | char unusual_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2595 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2596 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2597 | rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2598 | kUnusualSctpPort); |
| 2599 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2600 | // First setup the expected JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2601 | JsepSessionDescription jdesc(kDummyString); |
| 2602 | // take our pre-built session description and change the SCTP port. |
| 2603 | cricket::SessionDescription* mutant = desc_.Copy(); |
| 2604 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 2605 | mutant->GetContentDescriptionByName(kDataContentName)); |
| 2606 | std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 2607 | EXPECT_EQ(1U, codecs.size()); |
| 2608 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2609 | codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2610 | dcdesc->set_codecs(codecs); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2611 | |
| 2612 | // note: mutant's owned by jdesc now. |
| 2613 | ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion)); |
| 2614 | mutant = NULL; |
| 2615 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2616 | // Then get the deserialized JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2617 | std::string sdp_with_data = kSdpString; |
| 2618 | sdp_with_data.append(kSdpSctpDataChannelString); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2619 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2620 | unusual_portstr, strlen(unusual_portstr), |
| 2621 | &sdp_with_data); |
| 2622 | JsepSessionDescription jdesc_output(kDummyString); |
| 2623 | |
| 2624 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2625 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2626 | |
| 2627 | // We need to test the deserialized JsepSessionDescription from |
| 2628 | // kSdpSctpDataChannelStringWithSctpPort for |
| 2629 | // draft-ietf-mmusic-sctp-sdp-07 |
| 2630 | // a=sctp-port |
| 2631 | sdp_with_data = kSdpString; |
| 2632 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2633 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
| 2634 | unusual_portstr, strlen(unusual_portstr), |
| 2635 | &sdp_with_data); |
| 2636 | |
| 2637 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2638 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2641 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) { |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2642 | // We want to test that deserializing data content limits bandwidth |
| 2643 | // settings (it should never be greater than the default). |
| 2644 | // This should prevent someone from using unlimited data bandwidth through |
| 2645 | // JS and "breaking the Internet". |
| 2646 | // See: https://code.google.com/p/chromium/issues/detail?id=280726 |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2647 | std::string sdp_with_bandwidth = kSdpString; |
| 2648 | sdp_with_bandwidth.append(kSdpRtpDataChannelString); |
| 2649 | InjectAfter("a=mid:data_content_name\r\n", |
| 2650 | "b=AS:100\r\n", |
| 2651 | &sdp_with_bandwidth); |
| 2652 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2653 | |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2654 | EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2655 | } |
| 2656 | |
| 2657 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { |
| 2658 | AddSctpDataChannel(); |
| 2659 | JsepSessionDescription jdesc(kDummyString); |
| 2660 | DataContentDescription* dcd = static_cast<DataContentDescription*>( |
| 2661 | GetFirstDataContent(&desc_)->description); |
| 2662 | dcd->set_bandwidth(100 * 1000); |
| 2663 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2664 | |
| 2665 | std::string sdp_with_bandwidth = kSdpString; |
| 2666 | sdp_with_bandwidth.append(kSdpSctpDataChannelString); |
| 2667 | InjectAfter("a=mid:data_content_name\r\n", |
| 2668 | "b=AS:100\r\n", |
| 2669 | &sdp_with_bandwidth); |
| 2670 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2671 | |
| 2672 | // SCTP has congestion control, so we shouldn't limit the bandwidth |
| 2673 | // as we do for RTP. |
| 2674 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2675 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 2676 | } |
| 2677 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2678 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { |
| 2679 | TestDeserializeExtmap(true, false); |
| 2680 | } |
| 2681 | |
| 2682 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
| 2683 | TestDeserializeExtmap(false, true); |
| 2684 | } |
| 2685 | |
| 2686 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
| 2687 | TestDeserializeExtmap(true, true); |
| 2688 | } |
| 2689 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2690 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { |
| 2691 | JsepSessionDescription jdesc(kDummyString); |
| 2692 | std::string sdp = kSdpFullString; |
| 2693 | sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. |
| 2694 | // Deserialize |
| 2695 | SdpParseError error; |
| 2696 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2697 | const std::string lastline = "a=ssrc:3 label:video_track_id_1"; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2698 | EXPECT_EQ(lastline, error.line); |
| 2699 | EXPECT_EQ("Invalid SDP line.", error.description); |
| 2700 | } |
| 2701 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2702 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 2703 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2704 | std::string new_sdp = kSdpOneCandidate; |
| 2705 | Replace("udp", "unsupported_transport", &new_sdp); |
| 2706 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2707 | new_sdp = kSdpOneCandidate; |
| 2708 | Replace("udp", "uDP", &new_sdp); |
| 2709 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2710 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2711 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2712 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2713 | } |
| 2714 | |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2715 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2716 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2717 | EXPECT_TRUE( |
| 2718 | SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2719 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2720 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2721 | Candidate ref_candidate = jcandidate_->candidate(); |
| 2722 | ref_candidate.set_username("user_rtp"); |
| 2723 | ref_candidate.set_password("password_rtp"); |
| 2724 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 2725 | } |
| 2726 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2727 | TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) { |
| 2728 | JsepSessionDescription jdesc(kDummyString); |
| 2729 | |
| 2730 | // Deserialize |
| 2731 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
| 2732 | |
| 2733 | // Verify |
| 2734 | cricket::AudioContentDescription* audio = |
| 2735 | static_cast<AudioContentDescription*>( |
| 2736 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2737 | EXPECT_TRUE(audio->conference_mode()); |
| 2738 | |
| 2739 | cricket::VideoContentDescription* video = |
| 2740 | static_cast<VideoContentDescription*>( |
| 2741 | jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO)); |
| 2742 | EXPECT_TRUE(video->conference_mode()); |
| 2743 | } |
| 2744 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2745 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 2746 | const char kSdpDestroyer[] = "!@#$%^&"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2747 | const char kSdpEmptyType[] = " =candidate"; |
| 2748 | const char kSdpEqualAsPlus[] = "a+candidate"; |
| 2749 | const char kSdpSpaceAfterEqual[] = "a= candidate"; |
| 2750 | const char kSdpUpperType[] = "A=candidate"; |
| 2751 | const char kSdpEmptyLine[] = ""; |
| 2752 | const char kSdpMissingValue[] = "a="; |
| 2753 | |
| 2754 | const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2755 | "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2756 | const char kSdpExtraField[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2757 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2758 | const char kSdpMissingSpace[] = "a=fingerprint:sha-1" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2759 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2760 | // MD5 is not allowed in fingerprints. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2761 | const char kSdpMd5[] = "a=fingerprint:md5 " |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2762 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2763 | |
| 2764 | // Broken session description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2765 | ExpectParseFailure("v=", kSdpDestroyer); |
| 2766 | ExpectParseFailure("o=", kSdpDestroyer); |
| 2767 | ExpectParseFailure("s=-", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2768 | // Broken time description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2769 | ExpectParseFailure("t=", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2770 | |
| 2771 | // Broken media description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2772 | ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39"); |
| 2773 | ExpectParseFailure("m=video", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2774 | |
| 2775 | // Invalid lines |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2776 | ExpectParseFailure("a=candidate", kSdpEmptyType); |
| 2777 | ExpectParseFailure("a=candidate", kSdpEqualAsPlus); |
| 2778 | ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual); |
| 2779 | ExpectParseFailure("a=candidate", kSdpUpperType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2780 | |
| 2781 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 2782 | // because it's orthogonal to what we are replacing and hence |
| 2783 | // safe. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2784 | ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint); |
| 2785 | ExpectParseFailure("a=sendrecv", kSdpExtraField); |
| 2786 | ExpectParseFailure("a=sendrecv", kSdpMissingSpace); |
| 2787 | ExpectParseFailure("a=sendrecv", kSdpMd5); |
| 2788 | |
| 2789 | // Empty Line |
| 2790 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine); |
| 2791 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) { |
| 2795 | // ssrc |
| 2796 | ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue"); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2797 | ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3"); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2798 | // crypto |
| 2799 | ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue "); |
| 2800 | // rtpmap |
| 2801 | ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue "); |
| 2802 | ExpectParseFailure("opus/48000/2", "opus/badvalue/2"); |
| 2803 | ExpectParseFailure("opus/48000/2", "opus/48000/badvalue"); |
| 2804 | // candidate |
| 2805 | ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432"); |
| 2806 | ExpectParseFailure("1 udp 2130706432", "1 udp badvalue"); |
| 2807 | ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue"); |
| 2808 | ExpectParseFailure("rport 2346", "rport badvalue"); |
| 2809 | ExpectParseFailure("rport 2346 generation 2", |
| 2810 | "rport 2346 generation badvalue"); |
| 2811 | // m line |
| 2812 | ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104", |
| 2813 | "m=audio 2345 RTP/SAVPF 111 badvalue 104"); |
| 2814 | |
| 2815 | // bandwidth |
| 2816 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2817 | "b=AS:badvalue\r\n", |
| 2818 | "b=AS:badvalue"); |
| 2819 | // rtcp-fb |
| 2820 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2821 | "a=rtcp-fb:badvalue nack\r\n", |
| 2822 | "a=rtcp-fb:badvalue nack"); |
| 2823 | // extmap |
| 2824 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2825 | "a=extmap:badvalue http://example.com\r\n", |
| 2826 | "a=extmap:badvalue http://example.com"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
| 2830 | JsepSessionDescription jdesc_output(kDummyString); |
| 2831 | |
| 2832 | const char kSdpWithReorderedPlTypesString[] = |
| 2833 | "v=0\r\n" |
| 2834 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2835 | "s=-\r\n" |
| 2836 | "t=0 0\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 2837 | "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2838 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 2839 | // in the map. |
| 2840 | "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2841 | "a=rtpmap:104 ISAC/32000\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2842 | |
| 2843 | // Deserialize |
| 2844 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 2845 | |
| 2846 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description()); |
| 2847 | ASSERT_TRUE(ac != NULL); |
| 2848 | const AudioContentDescription* acd = |
| 2849 | static_cast<const AudioContentDescription*>(ac->description); |
| 2850 | ASSERT_FALSE(acd->codecs().empty()); |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2851 | EXPECT_EQ("ISAC", acd->codecs()[0].name); |
| 2852 | EXPECT_EQ(32000, acd->codecs()[0].clockrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2853 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 2854 | } |
| 2855 | |
| 2856 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
| 2857 | JsepSessionDescription jdesc_output(kDummyString); |
| 2858 | CodecParams params; |
| 2859 | params.max_ptime = 40; |
| 2860 | params.ptime = 30; |
| 2861 | params.min_ptime = 10; |
| 2862 | params.sprop_stereo = 1; |
| 2863 | params.stereo = 1; |
| 2864 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2865 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2866 | TestDeserializeCodecParams(params, &jdesc_output); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2867 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 2871 | const bool kUseWildcard = false; |
| 2872 | JsepSessionDescription jdesc_output(kDummyString); |
| 2873 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2874 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 2878 | const bool kUseWildcard = true; |
| 2879 | JsepSessionDescription jdesc_output(kDummyString); |
| 2880 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2881 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
| 2885 | JsepSessionDescription jdesc_output(kDummyString); |
| 2886 | |
| 2887 | const char kSdpWithFmtpString[] = |
| 2888 | "v=0\r\n" |
| 2889 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2890 | "s=-\r\n" |
| 2891 | "t=0 0\r\n" |
| 2892 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2893 | "a=rtpmap:120 VP8/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2894 | "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n"; |
| 2895 | |
| 2896 | // Deserialize |
| 2897 | SdpParseError error; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 2898 | EXPECT_TRUE( |
| 2899 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2900 | |
| 2901 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2902 | ASSERT_TRUE(vc != NULL); |
| 2903 | const VideoContentDescription* vcd = |
| 2904 | static_cast<const VideoContentDescription*>(vc->description); |
| 2905 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2906 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2907 | EXPECT_EQ("VP8", vp8.name); |
| 2908 | EXPECT_EQ(120, vp8.id); |
| 2909 | cricket::CodecParameterMap::iterator found = |
| 2910 | vp8.params.find("x-google-min-bitrate"); |
| 2911 | ASSERT_TRUE(found != vp8.params.end()); |
| 2912 | EXPECT_EQ(found->second, "10"); |
| 2913 | found = vp8.params.find("x-google-max-quantization"); |
| 2914 | ASSERT_TRUE(found != vp8.params.end()); |
| 2915 | EXPECT_EQ(found->second, "40"); |
| 2916 | } |
| 2917 | |
| 2918 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) { |
| 2919 | JsepSessionDescription jdesc_output(kDummyString); |
| 2920 | |
| 2921 | const char kSdpWithFmtpString[] = |
| 2922 | "v=0\r\n" |
| 2923 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2924 | "s=-\r\n" |
| 2925 | "t=0 0\r\n" |
| 2926 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2927 | "a=rtpmap:120 VP8/90000\r\n" |
| 2928 | "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2929 | |
| 2930 | // Deserialize |
| 2931 | SdpParseError error; |
| 2932 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, |
| 2933 | &error)); |
| 2934 | |
| 2935 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2936 | ASSERT_TRUE(vc != NULL); |
| 2937 | const VideoContentDescription* vcd = |
| 2938 | static_cast<const VideoContentDescription*>(vc->description); |
| 2939 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2940 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2941 | EXPECT_EQ("VP8", vp8.name); |
| 2942 | EXPECT_EQ(120, vp8.id); |
| 2943 | cricket::CodecParameterMap::iterator found = |
| 2944 | vp8.params.find("x-google-min-bitrate"); |
| 2945 | ASSERT_TRUE(found != vp8.params.end()); |
| 2946 | EXPECT_EQ(found->second, "10"); |
| 2947 | found = vp8.params.find("x-google-max-quantization"); |
| 2948 | ASSERT_TRUE(found != vp8.params.end()); |
| 2949 | EXPECT_EQ(found->second, "40"); |
| 2950 | } |
| 2951 | |
| 2952 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
| 2953 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2954 | GetFirstVideoContent(&desc_)->description); |
| 2955 | |
| 2956 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 2957 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 2958 | vcd->set_codecs(codecs); |
| 2959 | |
| 2960 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2961 | jdesc_.session_id(), |
| 2962 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2963 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2964 | std::string sdp_with_fmtp = kSdpFullString; |
| 2965 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
| 2966 | "a=fmtp:120 x-google-min-bitrate=10\r\n", |
| 2967 | &sdp_with_fmtp); |
| 2968 | EXPECT_EQ(sdp_with_fmtp, message); |
| 2969 | } |
| 2970 | |
| 2971 | TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) { |
| 2972 | JsepSessionDescription jdesc_with_icelite(kDummyString); |
| 2973 | std::string sdp_with_icelite = kSdpFullString; |
| 2974 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2975 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 2976 | const cricket::TransportInfo* tinfo1 = |
| 2977 | desc->GetTransportInfoByName("audio_content_name"); |
| 2978 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 2979 | const cricket::TransportInfo* tinfo2 = |
| 2980 | desc->GetTransportInfoByName("video_content_name"); |
| 2981 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
| 2982 | InjectAfter(kSessionTime, |
| 2983 | "a=ice-lite\r\n", |
| 2984 | &sdp_with_icelite); |
| 2985 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2986 | desc = jdesc_with_icelite.description(); |
| 2987 | const cricket::TransportInfo* atinfo = |
| 2988 | desc->GetTransportInfoByName("audio_content_name"); |
| 2989 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 2990 | const cricket::TransportInfo* vtinfo = |
| 2991 | desc->GetTransportInfoByName("video_content_name"); |
| 2992 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
| 2993 | } |
| 2994 | |
| 2995 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 2996 | // correctly in the output SDP. |
| 2997 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 2998 | std::string sdp_with_data = kSdpString; |
| 2999 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
| 3000 | JsepSessionDescription jdesc_output(kDummyString); |
| 3001 | |
| 3002 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3003 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3004 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 3005 | |
| 3006 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 3007 | AddFingerprint(); |
| 3008 | TransportInfo audio_transport_info = |
| 3009 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 3010 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3011 | audio_transport_info.description.connection_role); |
| 3012 | audio_transport_info.description.connection_role = |
| 3013 | cricket::CONNECTIONROLE_ACTIVE; |
| 3014 | |
| 3015 | TransportInfo video_transport_info = |
| 3016 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 3017 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3018 | video_transport_info.description.connection_role); |
| 3019 | video_transport_info.description.connection_role = |
| 3020 | cricket::CONNECTIONROLE_ACTIVE; |
| 3021 | |
| 3022 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 3023 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 3024 | |
| 3025 | desc_.AddTransportInfo(audio_transport_info); |
| 3026 | desc_.AddTransportInfo(video_transport_info); |
| 3027 | |
| 3028 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 3029 | jdesc_.session_id(), |
| 3030 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3031 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 3032 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3033 | |
| 3034 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
| 3035 | InjectAfter(kAttributeIcePwdVoice, |
| 3036 | kFingerprint, &sdp_with_dtlssetup); |
| 3037 | InjectAfter(kAttributeIcePwdVideo, |
| 3038 | kFingerprint, &sdp_with_dtlssetup); |
| 3039 | // Now adding |setup| attribute. |
| 3040 | InjectAfter(kFingerprint, |
| 3041 | "a=setup:active\r\n", &sdp_with_dtlssetup); |
| 3042 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 3043 | } |
| 3044 | |
| 3045 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) { |
| 3046 | JsepSessionDescription jdesc_with_dtlssetup(kDummyString); |
| 3047 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3048 | InjectAfter(kSessionTime, |
| 3049 | "a=setup:actpass\r\n", |
| 3050 | &sdp_with_dtlssetup); |
| 3051 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 3052 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 3053 | const cricket::TransportInfo* atinfo = |
| 3054 | desc->GetTransportInfoByName("audio_content_name"); |
| 3055 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3056 | atinfo->description.connection_role); |
| 3057 | const cricket::TransportInfo* vtinfo = |
| 3058 | desc->GetTransportInfoByName("video_content_name"); |
| 3059 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3060 | vtinfo->description.connection_role); |
| 3061 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3062 | |
| 3063 | // Verifies that the order of the serialized m-lines follows the order of the |
| 3064 | // ContentInfo in SessionDescription, and vise versa for deserialization. |
| 3065 | TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) { |
| 3066 | JsepSessionDescription jdesc(kDummyString); |
| 3067 | const std::string media_content_sdps[3] = { |
| 3068 | kSdpAudioString, |
| 3069 | kSdpVideoString, |
| 3070 | kSdpSctpDataChannelString |
| 3071 | }; |
| 3072 | const cricket::MediaType media_types[3] = { |
| 3073 | cricket::MEDIA_TYPE_AUDIO, |
| 3074 | cricket::MEDIA_TYPE_VIDEO, |
| 3075 | cricket::MEDIA_TYPE_DATA |
| 3076 | }; |
| 3077 | |
| 3078 | // Verifies all 6 permutations. |
| 3079 | for (size_t i = 0; i < 6; ++i) { |
| 3080 | size_t media_content_in_sdp[3]; |
| 3081 | // The index of the first media content. |
| 3082 | media_content_in_sdp[0] = i / 2; |
| 3083 | // The index of the second media content. |
| 3084 | media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3; |
| 3085 | // The index of the third media content. |
| 3086 | media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3; |
| 3087 | |
| 3088 | std::string sdp_string = kSdpSessionString; |
| 3089 | for (size_t i = 0; i < 3; ++i) |
| 3090 | sdp_string += media_content_sdps[media_content_in_sdp[i]]; |
| 3091 | |
| 3092 | EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc)); |
| 3093 | cricket::SessionDescription* desc = jdesc.description(); |
| 3094 | EXPECT_EQ(3u, desc->contents().size()); |
| 3095 | |
| 3096 | for (size_t i = 0; i < 3; ++i) { |
| 3097 | const cricket::MediaContentDescription* mdesc = |
| 3098 | static_cast<const cricket::MediaContentDescription*>( |
| 3099 | desc->contents()[i].description); |
| 3100 | EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 3101 | } |
| 3102 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3103 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3104 | EXPECT_EQ(sdp_string, serialized_sdp); |
| 3105 | } |
| 3106 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3107 | |
| 3108 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) { |
| 3109 | MakePlanBDescription(); |
| 3110 | |
| 3111 | JsepSessionDescription deserialized_description(kDummyString); |
| 3112 | EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description)); |
| 3113 | |
| 3114 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3115 | } |
| 3116 | |
| 3117 | TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) { |
| 3118 | MakePlanBDescription(); |
| 3119 | TestSerialize(jdesc_, false); |
| 3120 | } |
| 3121 | |
Taylor Brandstetter | 5de6b75 | 2016-03-09 17:02:30 -0800 | [diff] [blame] | 3122 | // Some WebRTC endpoints include the msid in both the Plan B and Unified Plan |
| 3123 | // ways, to make SDP that's compatible with both Plan B and Unified Plan (to |
| 3124 | // some extent). If we parse this, the Plan B msid attribute (which is more |
| 3125 | // specific, since it's at the SSRC level) should take priority. |
| 3126 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) { |
| 3127 | MakePlanBDescription(); |
| 3128 | |
| 3129 | JsepSessionDescription deserialized_description(kDummyString); |
| 3130 | EXPECT_TRUE( |
| 3131 | SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description)); |
| 3132 | |
| 3133 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3134 | } |
| 3135 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3136 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) { |
| 3137 | MakeUnifiedPlanDescription(); |
| 3138 | |
| 3139 | JsepSessionDescription deserialized_description(kDummyString); |
| 3140 | EXPECT_TRUE( |
| 3141 | SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); |
| 3142 | |
| 3143 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3144 | } |
| 3145 | |
| 3146 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { |
| 3147 | MakeUnifiedPlanDescription(); |
| 3148 | TestSerialize(jdesc_, true); |
| 3149 | } |