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 | |
| 11 | #include <set> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 15 | #include "webrtc/api/jsepsessiondescription.h" |
| 16 | #ifdef WEBRTC_ANDROID |
| 17 | #include "webrtc/api/test/androidtestinitializer.h" |
| 18 | #endif |
| 19 | #include "webrtc/api/webrtcsdp.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 20 | #include "webrtc/base/gunit.h" |
| 21 | #include "webrtc/base/logging.h" |
| 22 | #include "webrtc/base/messagedigest.h" |
| 23 | #include "webrtc/base/scoped_ptr.h" |
| 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" |
| 28 | #include "webrtc/p2p/base/p2pconstants.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 29 | #include "webrtc/pc/mediasession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | |
| 31 | using cricket::AudioCodec; |
| 32 | using cricket::AudioContentDescription; |
| 33 | using cricket::Candidate; |
| 34 | using cricket::ContentInfo; |
| 35 | using cricket::CryptoParams; |
| 36 | using cricket::ContentGroup; |
| 37 | using cricket::DataCodec; |
| 38 | using cricket::DataContentDescription; |
| 39 | using cricket::ICE_CANDIDATE_COMPONENT_RTCP; |
| 40 | using cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 41 | using cricket::kFecSsrcGroupSemantics; |
| 42 | using cricket::LOCAL_PORT_TYPE; |
| 43 | using cricket::NS_JINGLE_DRAFT_SCTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | using cricket::NS_JINGLE_RTP; |
| 45 | using cricket::RtpHeaderExtension; |
| 46 | using cricket::RELAY_PORT_TYPE; |
| 47 | using cricket::SessionDescription; |
| 48 | using cricket::StreamParams; |
| 49 | using cricket::STUN_PORT_TYPE; |
| 50 | using cricket::TransportDescription; |
| 51 | using cricket::TransportInfo; |
| 52 | using cricket::VideoCodec; |
| 53 | using cricket::VideoContentDescription; |
| 54 | using webrtc::IceCandidateCollection; |
| 55 | using webrtc::IceCandidateInterface; |
| 56 | using webrtc::JsepIceCandidate; |
| 57 | using webrtc::JsepSessionDescription; |
| 58 | using webrtc::SdpParseError; |
| 59 | using webrtc::SessionDescriptionInterface; |
| 60 | |
| 61 | typedef std::vector<AudioCodec> AudioCodecs; |
| 62 | typedef std::vector<Candidate> Candidates; |
| 63 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 64 | static const uint32_t kDefaultSctpPort = 5000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | static const char kSessionTime[] = "t=0 0\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 66 | static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 67 | static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 69 | static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 71 | static const uint32_t kCandidateGeneration = 2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | static const char kCandidateFoundation1[] = "a0+B/1"; |
| 73 | static const char kCandidateFoundation2[] = "a0+B/2"; |
| 74 | static const char kCandidateFoundation3[] = "a0+B/3"; |
| 75 | static const char kCandidateFoundation4[] = "a0+B/4"; |
| 76 | static const char kAttributeCryptoVoice[] = |
| 77 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 78 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 79 | "dummy_session_params\r\n"; |
| 80 | static const char kAttributeCryptoVideo[] = |
| 81 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 82 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"; |
| 83 | static const char kFingerprint[] = "a=fingerprint:sha-1 " |
| 84 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"; |
| 85 | static const int kExtmapId = 1; |
| 86 | static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime"; |
| 87 | static const char kExtmap[] = |
| 88 | "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n"; |
| 89 | static const char kExtmapWithDirectionAndAttribute[] = |
| 90 | "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n"; |
| 91 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 92 | static const uint8_t kIdentityDigest[] = { |
| 93 | 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02, |
| 94 | 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | |
lally@webrtc.org | 3480728 | 2015-02-24 20:19:39 +0000 | [diff] [blame] | 96 | static const char kDtlsSctp[] = "DTLS/SCTP"; |
| 97 | static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; |
| 98 | static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 99 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | struct CodecParams { |
| 101 | int max_ptime; |
| 102 | int ptime; |
| 103 | int min_ptime; |
| 104 | int sprop_stereo; |
| 105 | int stereo; |
| 106 | int useinband; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 107 | int maxaveragebitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 110 | // TODO(deadbeef): In these reference strings, use "a=fingerprint" by default |
| 111 | // instead of "a=crypto", and have an explicit test for adding "a=crypto". |
| 112 | // Currently it's the other way around. |
| 113 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | // Reference sdp string |
| 115 | static const char kSdpFullString[] = |
| 116 | "v=0\r\n" |
| 117 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 118 | "s=-\r\n" |
| 119 | "t=0 0\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 120 | "a=msid-semantic: WMS local_stream_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 122 | "c=IN IP4 74.125.127.126\r\n" |
| 123 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 124 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 125 | "generation 2\r\n" |
| 126 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 127 | "generation 2\r\n" |
| 128 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 129 | "generation 2\r\n" |
| 130 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 131 | "generation 2\r\n" |
| 132 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 133 | "raddr 192.168.1.5 rport 2346 " |
| 134 | "generation 2\r\n" |
| 135 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 136 | "raddr 192.168.1.5 rport 2348 " |
| 137 | "generation 2\r\n" |
| 138 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 139 | "a=mid:audio_content_name\r\n" |
| 140 | "a=sendrecv\r\n" |
| 141 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 142 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 144 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 145 | "dummy_session_params\r\n" |
| 146 | "a=rtpmap:111 opus/48000/2\r\n" |
| 147 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 148 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 149 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 150 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 151 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 152 | "a=ssrc:1 label:audio_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 154 | "c=IN IP4 74.125.224.39\r\n" |
| 155 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 156 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 157 | "generation 2\r\n" |
| 158 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 159 | "generation 2\r\n" |
| 160 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 161 | "generation 2\r\n" |
| 162 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 163 | "generation 2\r\n" |
| 164 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 165 | "generation 2\r\n" |
| 166 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 167 | "generation 2\r\n" |
| 168 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 169 | "a=mid:video_content_name\r\n" |
| 170 | "a=sendrecv\r\n" |
| 171 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 172 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 173 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 174 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 175 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 176 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 177 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 178 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 179 | "a=ssrc:3 cname:stream_1_cname\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 180 | "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] | 181 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 182 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | |
| 184 | // SDP reference string without the candidates. |
| 185 | static const char kSdpString[] = |
| 186 | "v=0\r\n" |
| 187 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 188 | "s=-\r\n" |
| 189 | "t=0 0\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 190 | "a=msid-semantic: WMS local_stream_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 191 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 192 | "c=IN IP4 0.0.0.0\r\n" |
| 193 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 195 | "a=mid:audio_content_name\r\n" |
| 196 | "a=sendrecv\r\n" |
| 197 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 198 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 200 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 201 | "dummy_session_params\r\n" |
| 202 | "a=rtpmap:111 opus/48000/2\r\n" |
| 203 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 204 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 205 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 206 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 207 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 208 | "a=ssrc:1 label:audio_track_id_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 209 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 210 | "c=IN IP4 0.0.0.0\r\n" |
| 211 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 213 | "a=mid:video_content_name\r\n" |
| 214 | "a=sendrecv\r\n" |
| 215 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 216 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 217 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 218 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 219 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 220 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 221 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 222 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 223 | "a=ssrc:3 cname:stream_1_cname\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 224 | "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] | 225 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 226 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | |
| 228 | static const char kSdpRtpDataChannelString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 229 | "m=application 9 RTP/SAVPF 101\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 230 | "c=IN IP4 0.0.0.0\r\n" |
| 231 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | "a=ice-ufrag:ufrag_data\r\n" |
| 233 | "a=ice-pwd:pwd_data\r\n" |
| 234 | "a=mid:data_content_name\r\n" |
| 235 | "a=sendrecv\r\n" |
| 236 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 237 | "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n" |
| 238 | "a=rtpmap:101 google-data/90000\r\n" |
| 239 | "a=ssrc:10 cname:data_channel_cname\r\n" |
| 240 | "a=ssrc:10 msid:data_channel data_channeld0\r\n" |
| 241 | "a=ssrc:10 mslabel:data_channel\r\n" |
| 242 | "a=ssrc:10 label:data_channeld0\r\n"; |
| 243 | |
| 244 | static const char kSdpSctpDataChannelString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 245 | "m=application 9 DTLS/SCTP 5000\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 246 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 247 | "a=ice-ufrag:ufrag_data\r\n" |
| 248 | "a=ice-pwd:pwd_data\r\n" |
| 249 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 250 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | |
lally@webrtc.org | ec97c65 | 2015-02-24 20:18:48 +0000 | [diff] [blame] | 252 | // draft-ietf-mmusic-sctp-sdp-12 |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 253 | static const char kSdpSctpDataChannelStringWithSctpPort[] = |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 254 | "m=application 9 DTLS/SCTP webrtc-datachannel\r\n" |
| 255 | "a=max-message-size=100000\r\n" |
| 256 | "a=sctp-port 5000\r\n" |
| 257 | "c=IN IP4 0.0.0.0\r\n" |
| 258 | "a=ice-ufrag:ufrag_data\r\n" |
| 259 | "a=ice-pwd:pwd_data\r\n" |
| 260 | "a=mid:data_content_name\r\n"; |
| 261 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 262 | static const char kSdpSctpDataChannelStringWithSctpColonPort[] = |
| 263 | "m=application 9 DTLS/SCTP webrtc-datachannel\r\n" |
| 264 | "a=max-message-size=100000\r\n" |
| 265 | "a=sctp-port:5000\r\n" |
| 266 | "c=IN IP4 0.0.0.0\r\n" |
| 267 | "a=ice-ufrag:ufrag_data\r\n" |
| 268 | "a=ice-pwd:pwd_data\r\n" |
| 269 | "a=mid:data_content_name\r\n"; |
| 270 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | static const char kSdpSctpDataChannelWithCandidatesString[] = |
| 272 | "m=application 2345 DTLS/SCTP 5000\r\n" |
| 273 | "c=IN IP4 74.125.127.126\r\n" |
| 274 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 275 | "generation 2\r\n" |
| 276 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 277 | "generation 2\r\n" |
| 278 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 279 | "raddr 192.168.1.5 rport 2346 " |
| 280 | "generation 2\r\n" |
| 281 | "a=ice-ufrag:ufrag_data\r\n" |
| 282 | "a=ice-pwd:pwd_data\r\n" |
| 283 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 284 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 285 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 286 | static const char kSdpConferenceString[] = |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 287 | "v=0\r\n" |
| 288 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 289 | "s=-\r\n" |
| 290 | "t=0 0\r\n" |
| 291 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 292 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 293 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 294 | "a=x-google-flag:conference\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 295 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 296 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 297 | "a=x-google-flag:conference\r\n"; |
| 298 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 299 | static const char kSdpSessionString[] = |
| 300 | "v=0\r\n" |
| 301 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 302 | "s=-\r\n" |
| 303 | "t=0 0\r\n" |
| 304 | "a=msid-semantic: WMS local_stream\r\n"; |
| 305 | |
| 306 | static const char kSdpAudioString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 307 | "m=audio 9 RTP/SAVPF 111\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 308 | "c=IN IP4 0.0.0.0\r\n" |
| 309 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 310 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 311 | "a=mid:audio_content_name\r\n" |
| 312 | "a=sendrecv\r\n" |
| 313 | "a=rtpmap:111 opus/48000/2\r\n" |
| 314 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 315 | "a=ssrc:1 msid:local_stream audio_track_id_1\r\n" |
| 316 | "a=ssrc:1 mslabel:local_stream\r\n" |
| 317 | "a=ssrc:1 label:audio_track_id_1\r\n"; |
| 318 | |
| 319 | static const char kSdpVideoString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 320 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 321 | "c=IN IP4 0.0.0.0\r\n" |
| 322 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 323 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 324 | "a=mid:video_content_name\r\n" |
| 325 | "a=sendrecv\r\n" |
| 326 | "a=rtpmap:120 VP8/90000\r\n" |
| 327 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 328 | "a=ssrc:2 msid:local_stream video_track_id_1\r\n" |
| 329 | "a=ssrc:2 mslabel:local_stream\r\n" |
| 330 | "a=ssrc:2 label:video_track_id_1\r\n"; |
| 331 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 332 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 333 | // tracks. |
| 334 | static const char kPlanBSdpFullString[] = |
| 335 | "v=0\r\n" |
| 336 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 337 | "s=-\r\n" |
| 338 | "t=0 0\r\n" |
| 339 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 340 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 341 | "c=IN IP4 74.125.127.126\r\n" |
| 342 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 343 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 344 | "generation 2\r\n" |
| 345 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 346 | "generation 2\r\n" |
| 347 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 348 | "generation 2\r\n" |
| 349 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 350 | "generation 2\r\n" |
| 351 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 352 | "raddr 192.168.1.5 rport 2346 " |
| 353 | "generation 2\r\n" |
| 354 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 355 | "raddr 192.168.1.5 rport 2348 " |
| 356 | "generation 2\r\n" |
| 357 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 358 | "a=mid:audio_content_name\r\n" |
| 359 | "a=sendrecv\r\n" |
| 360 | "a=rtcp-mux\r\n" |
| 361 | "a=rtcp-rsize\r\n" |
| 362 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 363 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 364 | "dummy_session_params\r\n" |
| 365 | "a=rtpmap:111 opus/48000/2\r\n" |
| 366 | "a=rtpmap:103 ISAC/16000\r\n" |
| 367 | "a=rtpmap:104 ISAC/32000\r\n" |
| 368 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 369 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 370 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 371 | "a=ssrc:1 label:audio_track_id_1\r\n" |
| 372 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 373 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
| 374 | "a=ssrc:4 mslabel:local_stream_2\r\n" |
| 375 | "a=ssrc:4 label:audio_track_id_2\r\n" |
| 376 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 377 | "c=IN IP4 74.125.224.39\r\n" |
| 378 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 379 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 380 | "generation 2\r\n" |
| 381 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 382 | "generation 2\r\n" |
| 383 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 384 | "generation 2\r\n" |
| 385 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 386 | "generation 2\r\n" |
| 387 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 388 | "generation 2\r\n" |
| 389 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 390 | "generation 2\r\n" |
| 391 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 392 | "a=mid:video_content_name\r\n" |
| 393 | "a=sendrecv\r\n" |
| 394 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 395 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 396 | "a=rtpmap:120 VP8/90000\r\n" |
| 397 | "a=ssrc-group:FEC 2 3\r\n" |
| 398 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 399 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 400 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 401 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 402 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 403 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 404 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 405 | "a=ssrc:3 label:video_track_id_1\r\n" |
| 406 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 407 | "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n" |
| 408 | "a=ssrc:5 mslabel:local_stream_2\r\n" |
| 409 | "a=ssrc:5 label:video_track_id_2\r\n" |
| 410 | "a=ssrc:6 cname:stream_2_cname\r\n" |
| 411 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n" |
| 412 | "a=ssrc:6 mslabel:local_stream_2\r\n" |
| 413 | "a=ssrc:6 label:video_track_id_3\r\n"; |
| 414 | |
Taylor Brandstetter | 5de6b75 | 2016-03-09 17:02:30 -0800 | [diff] [blame] | 415 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 416 | // tracks, but with the unified plan "a=msid" attribute. |
| 417 | static const char kPlanBSdpFullStringWithMsid[] = |
| 418 | "v=0\r\n" |
| 419 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 420 | "s=-\r\n" |
| 421 | "t=0 0\r\n" |
| 422 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 423 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 424 | "c=IN IP4 74.125.127.126\r\n" |
| 425 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 426 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 427 | "generation 2\r\n" |
| 428 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 429 | "generation 2\r\n" |
| 430 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 431 | "generation 2\r\n" |
| 432 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 433 | "generation 2\r\n" |
| 434 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 435 | "raddr 192.168.1.5 rport 2346 " |
| 436 | "generation 2\r\n" |
| 437 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 438 | "raddr 192.168.1.5 rport 2348 " |
| 439 | "generation 2\r\n" |
| 440 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 441 | "a=mid:audio_content_name\r\n" |
| 442 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 443 | "a=sendrecv\r\n" |
| 444 | "a=rtcp-mux\r\n" |
| 445 | "a=rtcp-rsize\r\n" |
| 446 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 447 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 448 | "dummy_session_params\r\n" |
| 449 | "a=rtpmap:111 opus/48000/2\r\n" |
| 450 | "a=rtpmap:103 ISAC/16000\r\n" |
| 451 | "a=rtpmap:104 ISAC/32000\r\n" |
| 452 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 453 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 454 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 455 | "a=ssrc:1 label:audio_track_id_1\r\n" |
| 456 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 457 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
| 458 | "a=ssrc:4 mslabel:local_stream_2\r\n" |
| 459 | "a=ssrc:4 label:audio_track_id_2\r\n" |
| 460 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 461 | "c=IN IP4 74.125.224.39\r\n" |
| 462 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 463 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 464 | "generation 2\r\n" |
| 465 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 466 | "generation 2\r\n" |
| 467 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 468 | "generation 2\r\n" |
| 469 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 470 | "generation 2\r\n" |
| 471 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 472 | "generation 2\r\n" |
| 473 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 474 | "generation 2\r\n" |
| 475 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 476 | "a=mid:video_content_name\r\n" |
| 477 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 478 | "a=sendrecv\r\n" |
| 479 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 480 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 481 | "a=rtpmap:120 VP8/90000\r\n" |
| 482 | "a=ssrc-group:FEC 2 3\r\n" |
| 483 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 484 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 485 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 486 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 487 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 488 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 489 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 490 | "a=ssrc:3 label:video_track_id_1\r\n" |
| 491 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 492 | "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n" |
| 493 | "a=ssrc:5 mslabel:local_stream_2\r\n" |
| 494 | "a=ssrc:5 label:video_track_id_2\r\n" |
| 495 | "a=ssrc:6 cname:stream_2_cname\r\n" |
| 496 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n" |
| 497 | "a=ssrc:6 mslabel:local_stream_2\r\n" |
| 498 | "a=ssrc:6 label:video_track_id_3\r\n"; |
| 499 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 500 | // Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 501 | // tracks. |
| 502 | static const char kUnifiedPlanSdpFullString[] = |
| 503 | "v=0\r\n" |
| 504 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 505 | "s=-\r\n" |
| 506 | "t=0 0\r\n" |
| 507 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 508 | // Audio track 1, stream 1 (with candidates). |
| 509 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 510 | "c=IN IP4 74.125.127.126\r\n" |
| 511 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 512 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 513 | "generation 2\r\n" |
| 514 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 515 | "generation 2\r\n" |
| 516 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 517 | "generation 2\r\n" |
| 518 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 519 | "generation 2\r\n" |
| 520 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 521 | "raddr 192.168.1.5 rport 2346 " |
| 522 | "generation 2\r\n" |
| 523 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 524 | "raddr 192.168.1.5 rport 2348 " |
| 525 | "generation 2\r\n" |
| 526 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 527 | "a=mid:audio_content_name\r\n" |
| 528 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 529 | "a=sendrecv\r\n" |
| 530 | "a=rtcp-mux\r\n" |
| 531 | "a=rtcp-rsize\r\n" |
| 532 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 533 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 534 | "dummy_session_params\r\n" |
| 535 | "a=rtpmap:111 opus/48000/2\r\n" |
| 536 | "a=rtpmap:103 ISAC/16000\r\n" |
| 537 | "a=rtpmap:104 ISAC/32000\r\n" |
| 538 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 539 | // Video track 1, stream 1 (with candidates). |
| 540 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 541 | "c=IN IP4 74.125.224.39\r\n" |
| 542 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 543 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 544 | "generation 2\r\n" |
| 545 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 546 | "generation 2\r\n" |
| 547 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 548 | "generation 2\r\n" |
| 549 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 550 | "generation 2\r\n" |
| 551 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 552 | "generation 2\r\n" |
| 553 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 554 | "generation 2\r\n" |
| 555 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 556 | "a=mid:video_content_name\r\n" |
| 557 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 558 | "a=sendrecv\r\n" |
| 559 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 560 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 561 | "a=rtpmap:120 VP8/90000\r\n" |
| 562 | "a=ssrc-group:FEC 2 3\r\n" |
| 563 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 564 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 565 | // Audio track 2, stream 2. |
| 566 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 567 | "c=IN IP4 0.0.0.0\r\n" |
| 568 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 569 | "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 570 | "a=mid:audio_content_name_2\r\n" |
| 571 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
| 572 | "a=sendrecv\r\n" |
| 573 | "a=rtcp-mux\r\n" |
| 574 | "a=rtcp-rsize\r\n" |
| 575 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 576 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 577 | "dummy_session_params\r\n" |
| 578 | "a=rtpmap:111 opus/48000/2\r\n" |
| 579 | "a=rtpmap:103 ISAC/16000\r\n" |
| 580 | "a=rtpmap:104 ISAC/32000\r\n" |
| 581 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 582 | // Video track 2, stream 2. |
| 583 | "m=video 9 RTP/SAVPF 120\r\n" |
| 584 | "c=IN IP4 0.0.0.0\r\n" |
| 585 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 586 | "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n" |
| 587 | "a=mid:video_content_name_2\r\n" |
| 588 | "a=msid:local_stream_2 video_track_id_2\r\n" |
| 589 | "a=sendrecv\r\n" |
| 590 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 591 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 592 | "a=rtpmap:120 VP8/90000\r\n" |
| 593 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 594 | // Video track 3, stream 2. |
| 595 | "m=video 9 RTP/SAVPF 120\r\n" |
| 596 | "c=IN IP4 0.0.0.0\r\n" |
| 597 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 598 | "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n" |
| 599 | "a=mid:video_content_name_3\r\n" |
| 600 | "a=msid:local_stream_2 video_track_id_3\r\n" |
| 601 | "a=sendrecv\r\n" |
| 602 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 603 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 604 | "a=rtpmap:120 VP8/90000\r\n" |
| 605 | "a=ssrc:6 cname:stream_2_cname\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | |
| 607 | // One candidate reference string as per W3c spec. |
| 608 | // candidate:<blah> not a=candidate:<blah>CRLF |
| 609 | static const char kRawCandidate[] = |
| 610 | "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2"; |
| 611 | // One candidate reference string. |
| 612 | static const char kSdpOneCandidate[] = |
| 613 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 614 | "generation 2\r\n"; |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 615 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 616 | static const char kSdpTcpActiveCandidate[] = |
| 617 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 618 | "tcptype active generation 2"; |
| 619 | static const char kSdpTcpPassiveCandidate[] = |
| 620 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 621 | "tcptype passive generation 2"; |
| 622 | static const char kSdpTcpSOCandidate[] = |
| 623 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 624 | "tcptype so generation 2"; |
| 625 | static const char kSdpTcpInvalidCandidate[] = |
| 626 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 627 | "tcptype invalid generation 2"; |
| 628 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 629 | // One candidate reference string with IPV6 address. |
| 630 | static const char kRawIPV6Candidate[] = |
| 631 | "candidate:a0+B/1 1 udp 2130706432 " |
| 632 | "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] | 633 | |
| 634 | // One candidate reference string. |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 635 | static const char kSdpOneCandidateWithUfragPwd[] = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 636 | "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] | 637 | " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 638 | |
| 639 | // Session id and version |
| 640 | static const char kSessionId[] = "18446744069414584320"; |
| 641 | static const char kSessionVersion[] = "18446462598732840960"; |
| 642 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 643 | // ICE options. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 644 | static const char kIceOption1[] = "iceoption1"; |
| 645 | static const char kIceOption2[] = "iceoption2"; |
| 646 | static const char kIceOption3[] = "iceoption3"; |
| 647 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 648 | // ICE ufrags/passwords. |
| 649 | static const char kUfragVoice[] = "ufrag_voice"; |
| 650 | static const char kPwdVoice[] = "pwd_voice"; |
| 651 | static const char kUfragVideo[] = "ufrag_video"; |
| 652 | static const char kPwdVideo[] = "pwd_video"; |
| 653 | static const char kUfragData[] = "ufrag_data"; |
| 654 | static const char kPwdData[] = "pwd_data"; |
| 655 | |
| 656 | // Extra ufrags/passwords for extra unified plan m= sections. |
| 657 | static const char kUfragVoice2[] = "ufrag_voice_2"; |
| 658 | static const char kPwdVoice2[] = "pwd_voice_2"; |
| 659 | static const char kUfragVideo2[] = "ufrag_video_2"; |
| 660 | static const char kPwdVideo2[] = "pwd_video_2"; |
| 661 | static const char kUfragVideo3[] = "ufrag_video_3"; |
| 662 | static const char kPwdVideo3[] = "pwd_video_3"; |
| 663 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 664 | // Content name |
| 665 | static const char kAudioContentName[] = "audio_content_name"; |
| 666 | static const char kVideoContentName[] = "video_content_name"; |
| 667 | static const char kDataContentName[] = "data_content_name"; |
| 668 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 669 | // Extra content names for extra unified plan m= sections. |
| 670 | static const char kAudioContentName2[] = "audio_content_name_2"; |
| 671 | static const char kVideoContentName2[] = "video_content_name_2"; |
| 672 | static const char kVideoContentName3[] = "video_content_name_3"; |
| 673 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 674 | // MediaStream 1 |
| 675 | static const char kStreamLabel1[] = "local_stream_1"; |
| 676 | static const char kStream1Cname[] = "stream_1_cname"; |
| 677 | static const char kAudioTrackId1[] = "audio_track_id_1"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 678 | static const uint32_t kAudioTrack1Ssrc = 1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 679 | static const char kVideoTrackId1[] = "video_track_id_1"; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 680 | static const uint32_t kVideoTrack1Ssrc1 = 2; |
| 681 | static const uint32_t kVideoTrack1Ssrc2 = 3; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 682 | |
| 683 | // MediaStream 2 |
| 684 | static const char kStreamLabel2[] = "local_stream_2"; |
| 685 | static const char kStream2Cname[] = "stream_2_cname"; |
| 686 | static const char kAudioTrackId2[] = "audio_track_id_2"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 687 | static const uint32_t kAudioTrack2Ssrc = 4; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 688 | static const char kVideoTrackId2[] = "video_track_id_2"; |
| 689 | static const uint32_t kVideoTrack2Ssrc = 5; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 690 | static const char kVideoTrackId3[] = "video_track_id_3"; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 691 | static const uint32_t kVideoTrack3Ssrc = 6; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 692 | |
| 693 | // DataChannel |
| 694 | static const char kDataChannelLabel[] = "data_channel"; |
| 695 | static const char kDataChannelMsid[] = "data_channeld0"; |
| 696 | static const char kDataChannelCname[] = "data_channel_cname"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 697 | static const uint32_t kDataChannelSsrc = 10; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 698 | |
| 699 | // Candidate |
| 700 | static const char kDummyMid[] = "dummy_mid"; |
| 701 | static const int kDummyIndex = 123; |
| 702 | |
| 703 | // Misc |
| 704 | static const char kDummyString[] = "dummy"; |
| 705 | |
| 706 | // Helper functions |
| 707 | |
| 708 | static bool SdpDeserialize(const std::string& message, |
| 709 | JsepSessionDescription* jdesc) { |
| 710 | return webrtc::SdpDeserialize(message, jdesc, NULL); |
| 711 | } |
| 712 | |
| 713 | static bool SdpDeserializeCandidate(const std::string& message, |
| 714 | JsepIceCandidate* candidate) { |
| 715 | return webrtc::SdpDeserializeCandidate(message, candidate, NULL); |
| 716 | } |
| 717 | |
| 718 | // Add some extra |newlines| to the |message| after |line|. |
| 719 | static void InjectAfter(const std::string& line, |
| 720 | const std::string& newlines, |
| 721 | std::string* message) { |
| 722 | const std::string tmp = line + newlines; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 723 | rtc::replace_substrs(line.c_str(), line.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 724 | tmp.c_str(), tmp.length(), message); |
| 725 | } |
| 726 | |
| 727 | static void Replace(const std::string& line, |
| 728 | const std::string& newlines, |
| 729 | std::string* message) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 730 | rtc::replace_substrs(line.c_str(), line.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 731 | newlines.c_str(), newlines.length(), message); |
| 732 | } |
| 733 | |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 734 | // Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error |
| 735 | // message. |
| 736 | static void ExpectParseFailure(const std::string& bad_sdp, |
| 737 | const std::string& bad_part) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 738 | JsepSessionDescription desc(kDummyString); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 739 | SdpParseError error; |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 740 | bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 741 | EXPECT_FALSE(ret); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 742 | EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str())); |
| 743 | } |
| 744 | |
| 745 | // Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|. |
| 746 | static void ExpectParseFailure(const char* good_part, const char* bad_part) { |
| 747 | std::string bad_sdp = kSdpFullString; |
| 748 | Replace(good_part, bad_part, &bad_sdp); |
| 749 | ExpectParseFailure(bad_sdp, bad_part); |
| 750 | } |
| 751 | |
| 752 | // Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|. |
| 753 | static void ExpectParseFailureWithNewLines(const std::string& injectpoint, |
| 754 | const std::string& newlines, |
| 755 | const std::string& bad_part) { |
| 756 | std::string bad_sdp = kSdpFullString; |
| 757 | InjectAfter(injectpoint, newlines, &bad_sdp); |
| 758 | ExpectParseFailure(bad_sdp, bad_part); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | static void ReplaceDirection(cricket::MediaContentDirection direction, |
| 762 | std::string* message) { |
| 763 | std::string new_direction; |
| 764 | switch (direction) { |
| 765 | case cricket::MD_INACTIVE: |
| 766 | new_direction = "a=inactive"; |
| 767 | break; |
| 768 | case cricket::MD_SENDONLY: |
| 769 | new_direction = "a=sendonly"; |
| 770 | break; |
| 771 | case cricket::MD_RECVONLY: |
| 772 | new_direction = "a=recvonly"; |
| 773 | break; |
| 774 | case cricket::MD_SENDRECV: |
| 775 | default: |
| 776 | new_direction = "a=sendrecv"; |
| 777 | break; |
| 778 | } |
| 779 | Replace("a=sendrecv", new_direction, message); |
| 780 | } |
| 781 | |
| 782 | static void ReplaceRejected(bool audio_rejected, bool video_rejected, |
| 783 | std::string* message) { |
| 784 | if (audio_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 785 | Replace("m=audio 9", "m=audio 0", message); |
| 786 | Replace(kAttributeIceUfragVoice, "", message); |
| 787 | Replace(kAttributeIcePwdVoice, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 788 | } |
| 789 | if (video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 790 | Replace("m=video 9", "m=video 0", message); |
| 791 | Replace(kAttributeIceUfragVideo, "", message); |
| 792 | Replace(kAttributeIcePwdVideo, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
| 796 | // WebRtcSdpTest |
| 797 | |
| 798 | class WebRtcSdpTest : public testing::Test { |
| 799 | public: |
| 800 | WebRtcSdpTest() |
| 801 | : jdesc_(kDummyString) { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 802 | #ifdef WEBRTC_ANDROID |
| 803 | webrtc::InitializeAndroidObjects(); |
| 804 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 805 | // AudioContentDescription |
| 806 | audio_desc_ = CreateAudioContentDescription(); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 807 | StreamParams audio_stream; |
| 808 | audio_stream.id = kAudioTrackId1; |
| 809 | audio_stream.cname = kStream1Cname; |
| 810 | audio_stream.sync_label = kStreamLabel1; |
| 811 | audio_stream.ssrcs.push_back(kAudioTrack1Ssrc); |
| 812 | audio_desc_->AddStream(audio_stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 813 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 814 | |
| 815 | // VideoContentDescription |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 816 | video_desc_ = CreateVideoContentDescription(); |
| 817 | StreamParams video_stream; |
| 818 | video_stream.id = kVideoTrackId1; |
| 819 | video_stream.cname = kStream1Cname; |
| 820 | video_stream.sync_label = kStreamLabel1; |
| 821 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc1); |
| 822 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc2); |
| 823 | cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs); |
| 824 | video_stream.ssrc_groups.push_back(ssrc_group); |
| 825 | video_desc_->AddStream(video_stream); |
| 826 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 827 | |
| 828 | // TransportInfo |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 829 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 830 | kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)))); |
| 831 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 832 | kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 833 | |
| 834 | // v4 host |
| 835 | int port = 1234; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 836 | rtc::SocketAddress address("192.168.1.5", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 837 | Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 838 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 839 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 840 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 841 | Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 842 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 843 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 844 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 845 | Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 846 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 847 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 848 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 849 | Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 850 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 851 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 852 | |
| 853 | // v6 host |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 854 | rtc::SocketAddress v6_address("::1", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 855 | cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 856 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 857 | cricket::LOCAL_PORT_TYPE, |
| 858 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 859 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 860 | cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 861 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 862 | cricket::LOCAL_PORT_TYPE, |
| 863 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 864 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 865 | cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 866 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 867 | cricket::LOCAL_PORT_TYPE, |
| 868 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 869 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 870 | cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 871 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 872 | cricket::LOCAL_PORT_TYPE, |
| 873 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 874 | |
| 875 | // stun |
| 876 | int port_stun = 2345; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 877 | rtc::SocketAddress address_stun("74.125.127.126", port_stun++); |
| 878 | rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 879 | cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 880 | address_stun, kCandidatePriority, "", "", |
| 881 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 882 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 883 | candidate9.set_related_address(rel_address_stun); |
| 884 | |
| 885 | address_stun.SetPort(port_stun++); |
| 886 | rel_address_stun.SetPort(port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 887 | cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 888 | address_stun, kCandidatePriority, "", "", |
| 889 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 890 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 891 | candidate10.set_related_address(rel_address_stun); |
| 892 | |
| 893 | // relay |
| 894 | int port_relay = 3456; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 895 | rtc::SocketAddress address_relay("74.125.224.39", port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 896 | cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 897 | address_relay, kCandidatePriority, "", "", |
| 898 | cricket::RELAY_PORT_TYPE, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 899 | kCandidateGeneration, kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 900 | address_relay.SetPort(port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 901 | cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 902 | address_relay, kCandidatePriority, "", "", |
| 903 | RELAY_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 904 | kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 905 | |
| 906 | // voice |
| 907 | candidates_.push_back(candidate1); |
| 908 | candidates_.push_back(candidate2); |
| 909 | candidates_.push_back(candidate5); |
| 910 | candidates_.push_back(candidate6); |
| 911 | candidates_.push_back(candidate9); |
| 912 | candidates_.push_back(candidate10); |
| 913 | |
| 914 | // video |
| 915 | candidates_.push_back(candidate3); |
| 916 | candidates_.push_back(candidate4); |
| 917 | candidates_.push_back(candidate7); |
| 918 | candidates_.push_back(candidate8); |
| 919 | candidates_.push_back(candidate11); |
| 920 | candidates_.push_back(candidate12); |
| 921 | |
| 922 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), |
| 923 | 0, candidate1)); |
| 924 | |
| 925 | // Set up JsepSessionDescription. |
| 926 | jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion); |
| 927 | std::string mline_id; |
| 928 | int mline_index = 0; |
| 929 | for (size_t i = 0; i< candidates_.size(); ++i) { |
| 930 | // In this test, the audio m line index will be 0, and the video m line |
| 931 | // will be 1. |
| 932 | bool is_video = (i > 5); |
| 933 | mline_id = is_video ? "video_content_name" : "audio_content_name"; |
| 934 | mline_index = is_video ? 1 : 0; |
| 935 | JsepIceCandidate jice(mline_id, |
| 936 | mline_index, |
| 937 | candidates_.at(i)); |
| 938 | jdesc_.AddCandidate(&jice); |
| 939 | } |
| 940 | } |
| 941 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 942 | // Turns the existing reference description into a plan B description, |
| 943 | // with 2 audio tracks and 3 video tracks. |
| 944 | void MakePlanBDescription() { |
| 945 | audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy()); |
| 946 | video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy()); |
| 947 | |
| 948 | StreamParams audio_track_2; |
| 949 | audio_track_2.id = kAudioTrackId2; |
| 950 | audio_track_2.cname = kStream2Cname; |
| 951 | audio_track_2.sync_label = kStreamLabel2; |
| 952 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 953 | audio_desc_->AddStream(audio_track_2); |
| 954 | |
| 955 | StreamParams video_track_2; |
| 956 | video_track_2.id = kVideoTrackId2; |
| 957 | video_track_2.cname = kStream2Cname; |
| 958 | video_track_2.sync_label = kStreamLabel2; |
| 959 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 960 | video_desc_->AddStream(video_track_2); |
| 961 | |
| 962 | StreamParams video_track_3; |
| 963 | video_track_3.id = kVideoTrackId3; |
| 964 | video_track_3.cname = kStream2Cname; |
| 965 | video_track_3.sync_label = kStreamLabel2; |
| 966 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 967 | video_desc_->AddStream(video_track_3); |
| 968 | |
| 969 | desc_.RemoveContentByName(kAudioContentName); |
| 970 | desc_.RemoveContentByName(kVideoContentName); |
| 971 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 972 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
| 973 | |
| 974 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 975 | jdesc_.session_version())); |
| 976 | } |
| 977 | |
| 978 | // Turns the existing reference description into a unified plan description, |
| 979 | // with 2 audio tracks and 3 video tracks. |
| 980 | void MakeUnifiedPlanDescription() { |
| 981 | // Audio track 2. |
| 982 | AudioContentDescription* audio_desc_2 = CreateAudioContentDescription(); |
| 983 | StreamParams audio_track_2; |
| 984 | audio_track_2.id = kAudioTrackId2; |
| 985 | audio_track_2.cname = kStream2Cname; |
| 986 | audio_track_2.sync_label = kStreamLabel2; |
| 987 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 988 | audio_desc_2->AddStream(audio_track_2); |
| 989 | desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2); |
| 990 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 991 | kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)))); |
| 992 | |
| 993 | // Video track 2, in stream 2. |
| 994 | VideoContentDescription* video_desc_2 = CreateVideoContentDescription(); |
| 995 | StreamParams video_track_2; |
| 996 | video_track_2.id = kVideoTrackId2; |
| 997 | video_track_2.cname = kStream2Cname; |
| 998 | video_track_2.sync_label = kStreamLabel2; |
| 999 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 1000 | video_desc_2->AddStream(video_track_2); |
| 1001 | desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2); |
| 1002 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1003 | kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)))); |
| 1004 | |
| 1005 | // Video track 3, in stream 2. |
| 1006 | VideoContentDescription* video_desc_3 = CreateVideoContentDescription(); |
| 1007 | StreamParams video_track_3; |
| 1008 | video_track_3.id = kVideoTrackId3; |
| 1009 | video_track_3.cname = kStream2Cname; |
| 1010 | video_track_3.sync_label = kStreamLabel2; |
| 1011 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 1012 | video_desc_3->AddStream(video_track_3); |
| 1013 | desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3); |
| 1014 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1015 | kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)))); |
| 1016 | |
| 1017 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1018 | jdesc_.session_version())); |
| 1019 | } |
| 1020 | |
| 1021 | // Creates an audio content description with no streams, and some default |
| 1022 | // configuration. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1023 | AudioContentDescription* CreateAudioContentDescription() { |
| 1024 | AudioContentDescription* audio = new AudioContentDescription(); |
| 1025 | audio->set_rtcp_mux(true); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 1026 | audio->set_rtcp_reduced_size(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1027 | audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32", |
| 1028 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32", |
| 1029 | "dummy_session_params")); |
| 1030 | audio->set_protocol(cricket::kMediaProtocolSavpf); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1031 | AudioCodec opus(111, "opus", 48000, 0, 2, 3); |
| 1032 | audio->AddCodec(opus); |
| 1033 | audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2)); |
| 1034 | audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1035 | return audio; |
| 1036 | } |
| 1037 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1038 | // Creates a video content description with no streams, and some default |
| 1039 | // configuration. |
| 1040 | VideoContentDescription* CreateVideoContentDescription() { |
| 1041 | VideoContentDescription* video = new VideoContentDescription(); |
| 1042 | video->AddCrypto(CryptoParams( |
| 1043 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 1044 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", "")); |
| 1045 | video->set_protocol(cricket::kMediaProtocolSavpf); |
| 1046 | video->AddCodec( |
| 1047 | VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName, |
| 1048 | JsepSessionDescription::kMaxVideoCodecWidth, |
| 1049 | JsepSessionDescription::kMaxVideoCodecHeight, |
| 1050 | JsepSessionDescription::kDefaultVideoCodecFramerate, |
| 1051 | JsepSessionDescription::kDefaultVideoCodecPreference)); |
| 1052 | return video; |
| 1053 | } |
| 1054 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1055 | template <class MCD> |
| 1056 | void CompareMediaContentDescription(const MCD* cd1, |
| 1057 | const MCD* cd2) { |
| 1058 | // type |
| 1059 | EXPECT_EQ(cd1->type(), cd1->type()); |
| 1060 | |
| 1061 | // content direction |
| 1062 | EXPECT_EQ(cd1->direction(), cd2->direction()); |
| 1063 | |
| 1064 | // rtcp_mux |
| 1065 | EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux()); |
| 1066 | |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 1067 | // rtcp_reduced_size |
| 1068 | EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size()); |
| 1069 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1070 | // cryptos |
| 1071 | EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size()); |
| 1072 | if (cd1->cryptos().size() != cd2->cryptos().size()) { |
| 1073 | ADD_FAILURE(); |
| 1074 | return; |
| 1075 | } |
| 1076 | for (size_t i = 0; i< cd1->cryptos().size(); ++i) { |
| 1077 | const CryptoParams c1 = cd1->cryptos().at(i); |
| 1078 | const CryptoParams c2 = cd2->cryptos().at(i); |
| 1079 | EXPECT_TRUE(c1.Matches(c2)); |
| 1080 | EXPECT_EQ(c1.key_params, c2.key_params); |
| 1081 | EXPECT_EQ(c1.session_params, c2.session_params); |
| 1082 | } |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1083 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1084 | // protocol |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1085 | // Use an equivalence class here, for old and new versions of the |
| 1086 | // protocol description. |
| 1087 | if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 1088 | || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp |
| 1089 | || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) { |
| 1090 | const bool cd2_is_also_dtls_sctp = |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1091 | cd2->protocol() == cricket::kMediaProtocolDtlsSctp |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 1092 | || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp |
| 1093 | || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp; |
| 1094 | EXPECT_TRUE(cd2_is_also_dtls_sctp); |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1095 | } else { |
| 1096 | EXPECT_EQ(cd1->protocol(), cd2->protocol()); |
| 1097 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1098 | |
| 1099 | // codecs |
| 1100 | EXPECT_EQ(cd1->codecs(), cd2->codecs()); |
| 1101 | |
| 1102 | // bandwidth |
| 1103 | EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth()); |
| 1104 | |
| 1105 | // streams |
| 1106 | EXPECT_EQ(cd1->streams(), cd2->streams()); |
| 1107 | |
| 1108 | // extmap |
| 1109 | ASSERT_EQ(cd1->rtp_header_extensions().size(), |
| 1110 | cd2->rtp_header_extensions().size()); |
| 1111 | for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) { |
| 1112 | const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i); |
| 1113 | const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i); |
| 1114 | EXPECT_EQ(ext1.uri, ext2.uri); |
| 1115 | EXPECT_EQ(ext1.id, ext2.id); |
| 1116 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | |
| 1120 | void CompareSessionDescription(const SessionDescription& desc1, |
| 1121 | const SessionDescription& desc2) { |
| 1122 | // Compare content descriptions. |
| 1123 | if (desc1.contents().size() != desc2.contents().size()) { |
| 1124 | ADD_FAILURE(); |
| 1125 | return; |
| 1126 | } |
| 1127 | for (size_t i = 0 ; i < desc1.contents().size(); ++i) { |
| 1128 | const cricket::ContentInfo& c1 = desc1.contents().at(i); |
| 1129 | const cricket::ContentInfo& c2 = desc2.contents().at(i); |
| 1130 | // content name |
| 1131 | EXPECT_EQ(c1.name, c2.name); |
| 1132 | // content type |
| 1133 | // Note, ASSERT will return from the function, but will not stop the test. |
| 1134 | ASSERT_EQ(c1.type, c2.type); |
| 1135 | |
| 1136 | ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2)); |
| 1137 | if (IsAudioContent(&c1)) { |
| 1138 | const AudioContentDescription* acd1 = |
| 1139 | static_cast<const AudioContentDescription*>(c1.description); |
| 1140 | const AudioContentDescription* acd2 = |
| 1141 | static_cast<const AudioContentDescription*>(c2.description); |
| 1142 | CompareMediaContentDescription<AudioContentDescription>(acd1, acd2); |
| 1143 | } |
| 1144 | |
| 1145 | ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2)); |
| 1146 | if (IsVideoContent(&c1)) { |
| 1147 | const VideoContentDescription* vcd1 = |
| 1148 | static_cast<const VideoContentDescription*>(c1.description); |
| 1149 | const VideoContentDescription* vcd2 = |
| 1150 | static_cast<const VideoContentDescription*>(c2.description); |
| 1151 | CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2); |
| 1152 | } |
| 1153 | |
| 1154 | ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2)); |
| 1155 | if (IsDataContent(&c1)) { |
| 1156 | const DataContentDescription* dcd1 = |
| 1157 | static_cast<const DataContentDescription*>(c1.description); |
| 1158 | const DataContentDescription* dcd2 = |
| 1159 | static_cast<const DataContentDescription*>(c2.description); |
| 1160 | CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | // group |
| 1165 | const cricket::ContentGroups groups1 = desc1.groups(); |
| 1166 | const cricket::ContentGroups groups2 = desc2.groups(); |
| 1167 | EXPECT_EQ(groups1.size(), groups1.size()); |
| 1168 | if (groups1.size() != groups2.size()) { |
| 1169 | ADD_FAILURE(); |
| 1170 | return; |
| 1171 | } |
| 1172 | for (size_t i = 0; i < groups1.size(); ++i) { |
| 1173 | const cricket::ContentGroup group1 = groups1.at(i); |
| 1174 | const cricket::ContentGroup group2 = groups2.at(i); |
| 1175 | EXPECT_EQ(group1.semantics(), group2.semantics()); |
| 1176 | const cricket::ContentNames names1 = group1.content_names(); |
| 1177 | const cricket::ContentNames names2 = group2.content_names(); |
| 1178 | EXPECT_EQ(names1.size(), names2.size()); |
| 1179 | if (names1.size() != names2.size()) { |
| 1180 | ADD_FAILURE(); |
| 1181 | return; |
| 1182 | } |
| 1183 | cricket::ContentNames::const_iterator iter1 = names1.begin(); |
| 1184 | cricket::ContentNames::const_iterator iter2 = names2.begin(); |
| 1185 | while (iter1 != names1.end()) { |
| 1186 | EXPECT_EQ(*iter1++, *iter2++); |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | // transport info |
| 1191 | const cricket::TransportInfos transports1 = desc1.transport_infos(); |
| 1192 | const cricket::TransportInfos transports2 = desc2.transport_infos(); |
| 1193 | EXPECT_EQ(transports1.size(), transports2.size()); |
| 1194 | if (transports1.size() != transports2.size()) { |
| 1195 | ADD_FAILURE(); |
| 1196 | return; |
| 1197 | } |
| 1198 | for (size_t i = 0; i < transports1.size(); ++i) { |
| 1199 | const cricket::TransportInfo transport1 = transports1.at(i); |
| 1200 | const cricket::TransportInfo transport2 = transports2.at(i); |
| 1201 | EXPECT_EQ(transport1.content_name, transport2.content_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1202 | EXPECT_EQ(transport1.description.ice_ufrag, |
| 1203 | transport2.description.ice_ufrag); |
| 1204 | EXPECT_EQ(transport1.description.ice_pwd, |
| 1205 | transport2.description.ice_pwd); |
| 1206 | if (transport1.description.identity_fingerprint) { |
| 1207 | EXPECT_EQ(*transport1.description.identity_fingerprint, |
| 1208 | *transport2.description.identity_fingerprint); |
| 1209 | } else { |
| 1210 | EXPECT_EQ(transport1.description.identity_fingerprint.get(), |
| 1211 | transport2.description.identity_fingerprint.get()); |
| 1212 | } |
| 1213 | EXPECT_EQ(transport1.description.transport_options, |
| 1214 | transport2.description.transport_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1215 | } |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1216 | |
| 1217 | // global attributes |
| 1218 | EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1221 | bool CompareSessionDescription( |
| 1222 | const JsepSessionDescription& desc1, |
| 1223 | const JsepSessionDescription& desc2) { |
| 1224 | EXPECT_EQ(desc1.session_id(), desc2.session_id()); |
| 1225 | EXPECT_EQ(desc1.session_version(), desc2.session_version()); |
| 1226 | CompareSessionDescription(*desc1.description(), *desc2.description()); |
| 1227 | if (desc1.number_of_mediasections() != desc2.number_of_mediasections()) |
| 1228 | return false; |
| 1229 | for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) { |
| 1230 | const IceCandidateCollection* cc1 = desc1.candidates(i); |
| 1231 | const IceCandidateCollection* cc2 = desc2.candidates(i); |
| 1232 | if (cc1->count() != cc2->count()) |
| 1233 | return false; |
| 1234 | for (size_t j = 0; j < cc1->count(); ++j) { |
| 1235 | const IceCandidateInterface* c1 = cc1->at(j); |
| 1236 | const IceCandidateInterface* c2 = cc2->at(j); |
| 1237 | EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid()); |
| 1238 | EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index()); |
| 1239 | EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate())); |
| 1240 | } |
| 1241 | } |
| 1242 | return true; |
| 1243 | } |
| 1244 | |
| 1245 | // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing |
| 1246 | // them with invalid keywords so that the parser will just ignore them. |
| 1247 | bool RemoveCandidateUfragPwd(std::string* sdp) { |
| 1248 | const char ice_ufrag[] = "a=ice-ufrag"; |
| 1249 | const char ice_ufragx[] = "a=xice-ufrag"; |
| 1250 | const char ice_pwd[] = "a=ice-pwd"; |
| 1251 | const char ice_pwdx[] = "a=xice-pwd"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1252 | rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1253 | ice_ufragx, strlen(ice_ufragx), sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1254 | rtc::replace_substrs(ice_pwd, strlen(ice_pwd), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1255 | ice_pwdx, strlen(ice_pwdx), sdp); |
| 1256 | return true; |
| 1257 | } |
| 1258 | |
| 1259 | // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|. |
| 1260 | bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index, |
| 1261 | const std::string& ufrag, const std::string& pwd) { |
| 1262 | std::string content_name; |
| 1263 | if (mline_index == 0) { |
| 1264 | content_name = kAudioContentName; |
| 1265 | } else if (mline_index == 1) { |
| 1266 | content_name = kVideoContentName; |
| 1267 | } else { |
| 1268 | ASSERT(false); |
| 1269 | } |
| 1270 | TransportInfo transport_info( |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 1271 | content_name, TransportDescription(ufrag, pwd)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1272 | SessionDescription* desc = |
| 1273 | const_cast<SessionDescription*>(jdesc->description()); |
| 1274 | desc->RemoveTransportInfoByName(content_name); |
| 1275 | EXPECT_TRUE(desc->AddTransportInfo(transport_info)); |
| 1276 | for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) { |
| 1277 | const IceCandidateCollection* cc = jdesc_.candidates(i); |
| 1278 | for (size_t j = 0; j < cc->count(); ++j) { |
| 1279 | if (cc->at(j)->sdp_mline_index() == mline_index) { |
| 1280 | const_cast<Candidate&>(cc->at(j)->candidate()).set_username( |
| 1281 | ufrag); |
| 1282 | const_cast<Candidate&>(cc->at(j)->candidate()).set_password( |
| 1283 | pwd); |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | return true; |
| 1288 | } |
| 1289 | |
| 1290 | void AddIceOptions(const std::string& content_name, |
| 1291 | const std::vector<std::string>& transport_options) { |
| 1292 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1293 | cricket::TransportInfo transport_info = |
| 1294 | *(desc_.GetTransportInfoByName(content_name)); |
| 1295 | desc_.RemoveTransportInfoByName(content_name); |
| 1296 | transport_info.description.transport_options = transport_options; |
| 1297 | desc_.AddTransportInfo(transport_info); |
| 1298 | } |
| 1299 | |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1300 | void SetIceUfragPwd(const std::string& content_name, |
| 1301 | const std::string& ice_ufrag, |
| 1302 | const std::string& ice_pwd) { |
| 1303 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1304 | cricket::TransportInfo transport_info = |
| 1305 | *(desc_.GetTransportInfoByName(content_name)); |
| 1306 | desc_.RemoveTransportInfoByName(content_name); |
| 1307 | transport_info.description.ice_ufrag = ice_ufrag; |
| 1308 | transport_info.description.ice_pwd = ice_pwd; |
| 1309 | desc_.AddTransportInfo(transport_info); |
| 1310 | } |
| 1311 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1312 | void AddFingerprint() { |
| 1313 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 1314 | desc_.RemoveTransportInfoByName(kVideoContentName); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1315 | rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1316 | kIdentityDigest, |
| 1317 | sizeof(kIdentityDigest)); |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1318 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1319 | kAudioContentName, |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1320 | TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice, |
| 1321 | cricket::ICEMODE_FULL, |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1322 | cricket::CONNECTIONROLE_NONE, &fingerprint)))); |
| 1323 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1324 | kVideoContentName, |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1325 | TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, |
| 1326 | cricket::ICEMODE_FULL, |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1327 | cricket::CONNECTIONROLE_NONE, &fingerprint)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | void AddExtmap() { |
| 1331 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1332 | audio_desc_->Copy()); |
| 1333 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1334 | video_desc_->Copy()); |
| 1335 | audio_desc_->AddRtpHeaderExtension( |
| 1336 | RtpHeaderExtension(kExtmapUri, kExtmapId)); |
| 1337 | video_desc_->AddRtpHeaderExtension( |
| 1338 | RtpHeaderExtension(kExtmapUri, kExtmapId)); |
| 1339 | desc_.RemoveContentByName(kAudioContentName); |
| 1340 | desc_.RemoveContentByName(kVideoContentName); |
| 1341 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 1342 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
| 1343 | } |
| 1344 | |
| 1345 | void RemoveCryptos() { |
| 1346 | audio_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1347 | video_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1348 | } |
| 1349 | |
| 1350 | bool TestSerializeDirection(cricket::MediaContentDirection direction) { |
| 1351 | audio_desc_->set_direction(direction); |
| 1352 | video_desc_->set_direction(direction); |
| 1353 | std::string new_sdp = kSdpFullString; |
| 1354 | ReplaceDirection(direction, &new_sdp); |
| 1355 | |
| 1356 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1357 | jdesc_.session_id(), |
| 1358 | jdesc_.session_version())) { |
| 1359 | return false; |
| 1360 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1361 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1362 | EXPECT_EQ(new_sdp, message); |
| 1363 | return true; |
| 1364 | } |
| 1365 | |
| 1366 | bool TestSerializeRejected(bool audio_rejected, bool video_rejected) { |
| 1367 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1368 | audio_desc_->Copy()); |
| 1369 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1370 | video_desc_->Copy()); |
| 1371 | desc_.RemoveContentByName(kAudioContentName); |
| 1372 | desc_.RemoveContentByName(kVideoContentName); |
| 1373 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1374 | audio_desc_); |
| 1375 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1376 | video_desc_); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1377 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1378 | audio_rejected ? "" : kPwdVoice); |
| 1379 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1380 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1381 | |
| 1382 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1383 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1384 | |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1385 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1386 | if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1387 | kSessionVersion)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1388 | return false; |
| 1389 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1390 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1391 | EXPECT_EQ(new_sdp, message); |
| 1392 | return true; |
| 1393 | } |
| 1394 | |
| 1395 | void AddSctpDataChannel() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1396 | rtc::scoped_ptr<DataContentDescription> data( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1397 | new DataContentDescription()); |
| 1398 | data_desc_ = data.get(); |
| 1399 | data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1400 | DataCodec codec(cricket::kGoogleSctpDataCodecId, |
| 1401 | cricket::kGoogleSctpDataCodecName, 0); |
| 1402 | codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort); |
| 1403 | data_desc_->AddCodec(codec); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1404 | desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release()); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1405 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1406 | kDataContentName, TransportDescription(kUfragData, kPwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | void AddRtpDataChannel() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1410 | rtc::scoped_ptr<DataContentDescription> data( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1411 | new DataContentDescription()); |
| 1412 | data_desc_ = data.get(); |
| 1413 | |
| 1414 | data_desc_->AddCodec(DataCodec(101, "google-data", 1)); |
| 1415 | StreamParams data_stream; |
| 1416 | data_stream.id = kDataChannelMsid; |
| 1417 | data_stream.cname = kDataChannelCname; |
| 1418 | data_stream.sync_label = kDataChannelLabel; |
| 1419 | data_stream.ssrcs.push_back(kDataChannelSsrc); |
| 1420 | data_desc_->AddStream(data_stream); |
| 1421 | data_desc_->AddCrypto(CryptoParams( |
| 1422 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 1423 | "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", "")); |
| 1424 | data_desc_->set_protocol(cricket::kMediaProtocolSavpf); |
| 1425 | desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release()); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1426 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1427 | kDataContentName, TransportDescription(kUfragData, kPwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | bool TestDeserializeDirection(cricket::MediaContentDirection direction) { |
| 1431 | std::string new_sdp = kSdpFullString; |
| 1432 | ReplaceDirection(direction, &new_sdp); |
| 1433 | JsepSessionDescription new_jdesc(kDummyString); |
| 1434 | |
| 1435 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1436 | |
| 1437 | audio_desc_->set_direction(direction); |
| 1438 | video_desc_->set_direction(direction); |
| 1439 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1440 | jdesc_.session_id(), |
| 1441 | jdesc_.session_version())) { |
| 1442 | return false; |
| 1443 | } |
| 1444 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1445 | return true; |
| 1446 | } |
| 1447 | |
| 1448 | bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1449 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1450 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1451 | JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1452 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1453 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1454 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1455 | audio_desc_->Copy()); |
| 1456 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1457 | video_desc_->Copy()); |
| 1458 | desc_.RemoveContentByName(kAudioContentName); |
| 1459 | desc_.RemoveContentByName(kVideoContentName); |
| 1460 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1461 | audio_desc_); |
| 1462 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1463 | video_desc_); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1464 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1465 | audio_rejected ? "" : kPwdVoice); |
| 1466 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1467 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1468 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1469 | if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1470 | jdesc_.session_version())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1471 | return false; |
| 1472 | } |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1473 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1474 | return true; |
| 1475 | } |
| 1476 | |
| 1477 | void TestDeserializeExtmap(bool session_level, bool media_level) { |
| 1478 | AddExtmap(); |
| 1479 | JsepSessionDescription new_jdesc("dummy"); |
| 1480 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 1481 | jdesc_.session_id(), |
| 1482 | jdesc_.session_version())); |
| 1483 | JsepSessionDescription jdesc_with_extmap("dummy"); |
| 1484 | std::string sdp_with_extmap = kSdpString; |
| 1485 | if (session_level) { |
| 1486 | InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute, |
| 1487 | &sdp_with_extmap); |
| 1488 | } |
| 1489 | if (media_level) { |
| 1490 | InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute, |
| 1491 | &sdp_with_extmap); |
| 1492 | InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute, |
| 1493 | &sdp_with_extmap); |
| 1494 | } |
| 1495 | // The extmap can't be present at the same time in both session level and |
| 1496 | // media level. |
| 1497 | if (session_level && media_level) { |
| 1498 | SdpParseError error; |
| 1499 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap, |
| 1500 | &jdesc_with_extmap, &error)); |
| 1501 | EXPECT_NE(std::string::npos, error.description.find("a=extmap")); |
| 1502 | } else { |
| 1503 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap)); |
| 1504 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc)); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | void VerifyCodecParameter(const cricket::CodecParameterMap& params, |
| 1509 | const std::string& name, int expected_value) { |
| 1510 | cricket::CodecParameterMap::const_iterator found = params.find(name); |
| 1511 | ASSERT_TRUE(found != params.end()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1512 | EXPECT_EQ(found->second, rtc::ToString<int>(expected_value)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | void TestDeserializeCodecParams(const CodecParams& params, |
| 1516 | JsepSessionDescription* jdesc_output) { |
| 1517 | std::string sdp = |
| 1518 | "v=0\r\n" |
| 1519 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1520 | "s=-\r\n" |
| 1521 | "t=0 0\r\n" |
| 1522 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1523 | // this parser, and will be added to the SDP when serializing a session |
| 1524 | // description. |
| 1525 | "a=msid-semantic: WMS\r\n" |
| 1526 | // Pl type 111 preferred. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 1527 | "m=audio 9 RTP/SAVPF 111 104 103\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1528 | // Pltype 111 listed before 103 and 104 in the map. |
| 1529 | "a=rtpmap:111 opus/48000/2\r\n" |
| 1530 | // Pltype 103 listed before 104. |
| 1531 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 1532 | "a=rtpmap:104 ISAC/32000\r\n" |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1533 | "a=fmtp:111 0-15,66,70\r\n" |
| 1534 | "a=fmtp:111 "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1535 | std::ostringstream os; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 1536 | os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1537 | << "; sprop-stereo=" << params.sprop_stereo |
| 1538 | << "; useinbandfec=" << params.useinband |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 1539 | << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1540 | << "a=ptime:" << params.ptime << "\r\n" |
| 1541 | << "a=maxptime:" << params.max_ptime << "\r\n"; |
| 1542 | sdp += os.str(); |
| 1543 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1544 | os.clear(); |
| 1545 | os.str(""); |
| 1546 | // Pl type 100 preferred. |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 1547 | os << "m=video 9 RTP/SAVPF 99 95\r\n" |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1548 | << "a=rtpmap:99 VP8/90000\r\n" |
| 1549 | << "a=rtpmap:95 RTX/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 1550 | << "a=fmtp:95 apt=99;\r\n"; |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1551 | sdp += os.str(); |
| 1552 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1553 | // Deserialize |
| 1554 | SdpParseError error; |
| 1555 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1556 | |
| 1557 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1558 | ASSERT_TRUE(ac != NULL); |
| 1559 | const AudioContentDescription* acd = |
| 1560 | static_cast<const AudioContentDescription*>(ac->description); |
| 1561 | ASSERT_FALSE(acd->codecs().empty()); |
| 1562 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1563 | EXPECT_EQ("opus", opus.name); |
| 1564 | EXPECT_EQ(111, opus.id); |
| 1565 | VerifyCodecParameter(opus.params, "minptime", params.min_ptime); |
| 1566 | VerifyCodecParameter(opus.params, "stereo", params.stereo); |
| 1567 | VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo); |
| 1568 | VerifyCodecParameter(opus.params, "useinbandfec", params.useinband); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1569 | VerifyCodecParameter(opus.params, "maxaveragebitrate", |
| 1570 | params.maxaveragebitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1571 | for (size_t i = 0; i < acd->codecs().size(); ++i) { |
| 1572 | cricket::AudioCodec codec = acd->codecs()[i]; |
| 1573 | VerifyCodecParameter(codec.params, "ptime", params.ptime); |
| 1574 | VerifyCodecParameter(codec.params, "maxptime", params.max_ptime); |
| 1575 | if (codec.name == "ISAC") { |
| 1576 | if (codec.clockrate == 16000) { |
| 1577 | EXPECT_EQ(32000, codec.bitrate); |
| 1578 | } else { |
| 1579 | EXPECT_EQ(56000, codec.bitrate); |
| 1580 | } |
| 1581 | } |
| 1582 | } |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1583 | |
| 1584 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description()); |
| 1585 | ASSERT_TRUE(vc != NULL); |
| 1586 | const VideoContentDescription* vcd = |
| 1587 | static_cast<const VideoContentDescription*>(vc->description); |
| 1588 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1589 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1590 | EXPECT_EQ("VP8", vp8.name); |
| 1591 | EXPECT_EQ(99, vp8.id); |
| 1592 | cricket::VideoCodec rtx = vcd->codecs()[1]; |
| 1593 | EXPECT_EQ("RTX", rtx.name); |
| 1594 | EXPECT_EQ(95, rtx.id); |
| 1595 | VerifyCodecParameter(rtx.params, "apt", vp8.id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output, |
| 1599 | bool use_wildcard) { |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1600 | std::string sdp_session_and_audio = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1601 | "v=0\r\n" |
| 1602 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1603 | "s=-\r\n" |
| 1604 | "t=0 0\r\n" |
| 1605 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1606 | // this parser, and will be added to the SDP when serializing a session |
| 1607 | // description. |
| 1608 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 1609 | "m=audio 9 RTP/SAVPF 111\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1610 | "a=rtpmap:111 opus/48000/2\r\n"; |
| 1611 | std::string sdp_video = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1612 | "m=video 3457 RTP/SAVPF 101\r\n" |
| 1613 | "a=rtpmap:101 VP8/90000\r\n" |
| 1614 | "a=rtcp-fb:101 nack\r\n" |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1615 | "a=rtcp-fb:101 nack pli\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1616 | "a=rtcp-fb:101 goog-remb\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1617 | std::ostringstream os; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1618 | os << sdp_session_and_audio; |
| 1619 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n"; |
| 1620 | os << sdp_video; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1621 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n"; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1622 | std::string sdp = os.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1623 | // Deserialize |
| 1624 | SdpParseError error; |
| 1625 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1626 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1627 | ASSERT_TRUE(ac != NULL); |
| 1628 | const AudioContentDescription* acd = |
| 1629 | static_cast<const AudioContentDescription*>(ac->description); |
| 1630 | ASSERT_FALSE(acd->codecs().empty()); |
| 1631 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1632 | EXPECT_EQ(111, opus.id); |
| 1633 | EXPECT_TRUE(opus.HasFeedbackParam( |
| 1634 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1635 | cricket::kParamValueEmpty))); |
| 1636 | |
| 1637 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description()); |
| 1638 | ASSERT_TRUE(vc != NULL); |
| 1639 | const VideoContentDescription* vcd = |
| 1640 | static_cast<const VideoContentDescription*>(vc->description); |
| 1641 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1642 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1643 | EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName, |
| 1644 | vp8.name.c_str()); |
| 1645 | EXPECT_EQ(101, vp8.id); |
| 1646 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1647 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1648 | cricket::kParamValueEmpty))); |
| 1649 | EXPECT_TRUE(vp8.HasFeedbackParam( |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1650 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1651 | cricket::kRtcpFbNackParamPli))); |
| 1652 | EXPECT_TRUE(vp8.HasFeedbackParam( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1653 | cricket::FeedbackParam(cricket::kRtcpFbParamRemb, |
| 1654 | cricket::kParamValueEmpty))); |
| 1655 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1656 | cricket::FeedbackParam(cricket::kRtcpFbParamCcm, |
| 1657 | cricket::kRtcpFbCcmParamFir))); |
| 1658 | } |
| 1659 | |
| 1660 | // Two SDP messages can mean the same thing but be different strings, e.g. |
| 1661 | // some of the lines can be serialized in different order. |
| 1662 | // However, a deserialized description can be compared field by field and has |
| 1663 | // no order. If deserializer has already been tested, serializing then |
| 1664 | // deserializing and comparing JsepSessionDescription will test |
| 1665 | // the serializer sufficiently. |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1666 | void TestSerialize(const JsepSessionDescription& jdesc, |
| 1667 | bool unified_plan_sdp) { |
| 1668 | std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1669 | JsepSessionDescription jdesc_output_des(kDummyString); |
| 1670 | SdpParseError error; |
| 1671 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); |
| 1672 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); |
| 1673 | } |
| 1674 | |
| 1675 | protected: |
| 1676 | SessionDescription desc_; |
| 1677 | AudioContentDescription* audio_desc_; |
| 1678 | VideoContentDescription* video_desc_; |
| 1679 | DataContentDescription* data_desc_; |
| 1680 | Candidates candidates_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1681 | rtc::scoped_ptr<IceCandidateInterface> jcandidate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1682 | JsepSessionDescription jdesc_; |
| 1683 | }; |
| 1684 | |
| 1685 | void TestMismatch(const std::string& string1, const std::string& string2) { |
| 1686 | int position = 0; |
| 1687 | for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { |
| 1688 | if (string1.c_str()[i] != string2.c_str()[i]) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1689 | position = static_cast<int>(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1690 | break; |
| 1691 | } |
| 1692 | } |
| 1693 | EXPECT_EQ(0, position) << "Strings mismatch at the " << position |
| 1694 | << " character\n" |
| 1695 | << " 1: " << string1.substr(position, 20) << "\n" |
| 1696 | << " 2: " << string2.substr(position, 20) << "\n"; |
| 1697 | } |
| 1698 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1699 | TEST_F(WebRtcSdpTest, SerializeSessionDescription) { |
| 1700 | // SessionDescription with desc and candidates. |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1701 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1702 | TestMismatch(std::string(kSdpFullString), message); |
| 1703 | } |
| 1704 | |
| 1705 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) { |
| 1706 | JsepSessionDescription jdesc_empty(kDummyString); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1707 | EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1710 | // This tests serialization of SDP with only IPv6 candidates and verifies that |
| 1711 | // IPv6 is used as default address in c line according to preference. |
| 1712 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) { |
| 1713 | // Only test 1 m line. |
| 1714 | desc_.RemoveContentByName("video_content_name"); |
| 1715 | // Stun has a high preference than local host. |
| 1716 | cricket::Candidate candidate1( |
| 1717 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1718 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1719 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1720 | cricket::Candidate candidate2( |
| 1721 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1722 | rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| 1723 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1724 | JsepSessionDescription jdesc(kDummyString); |
| 1725 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1726 | |
| 1727 | // Only add the candidates to audio m line. |
| 1728 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1729 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1730 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1731 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1732 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1733 | |
| 1734 | // Audio line should have a c line like this one. |
| 1735 | EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos); |
| 1736 | // Shouldn't have a IP4 c line. |
| 1737 | EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| 1738 | } |
| 1739 | |
| 1740 | // This tests serialization of SDP with both IPv4 and IPv6 candidates and |
| 1741 | // verifies that IPv4 is used as default address in c line even if the |
| 1742 | // preference of IPv4 is lower. |
| 1743 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) { |
| 1744 | // Only test 1 m line. |
| 1745 | desc_.RemoveContentByName("video_content_name"); |
| 1746 | cricket::Candidate candidate_v4( |
| 1747 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1748 | rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "", |
| 1749 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1750 | cricket::Candidate candidate_v6( |
| 1751 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1752 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1753 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1754 | JsepSessionDescription jdesc(kDummyString); |
| 1755 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1756 | |
| 1757 | // Only add the candidates to audio m line. |
| 1758 | JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4); |
| 1759 | JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6); |
| 1760 | ASSERT_TRUE(jdesc.AddCandidate(&jice_v4)); |
| 1761 | ASSERT_TRUE(jdesc.AddCandidate(&jice_v6)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1762 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1763 | |
| 1764 | // Audio line should have a c line like this one. |
| 1765 | EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos); |
| 1766 | // Shouldn't have a IP6 c line. |
| 1767 | EXPECT_EQ(message.find("c=IN IP6"), std::string::npos); |
| 1768 | } |
| 1769 | |
| 1770 | // This tests serialization of SDP with both UDP and TCP candidates and |
| 1771 | // verifies that UDP is used as default address in c line even if the |
| 1772 | // preference of UDP is lower. |
| 1773 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) { |
| 1774 | // Only test 1 m line. |
| 1775 | desc_.RemoveContentByName("video_content_name"); |
| 1776 | // Stun has a high preference than local host. |
| 1777 | cricket::Candidate candidate1( |
| 1778 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1779 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1780 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1781 | cricket::Candidate candidate2( |
| 1782 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1783 | rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority, |
| 1784 | "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration, |
| 1785 | kCandidateFoundation1); |
| 1786 | JsepSessionDescription jdesc(kDummyString); |
| 1787 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1788 | |
| 1789 | // Only add the candidates to audio m line. |
| 1790 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1791 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1792 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1793 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1794 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1795 | |
| 1796 | // Audio line should have a c line like this one. |
| 1797 | EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"), |
| 1798 | std::string::npos); |
| 1799 | // Shouldn't have a IP4 c line. |
| 1800 | EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| 1801 | } |
| 1802 | |
| 1803 | // This tests serialization of SDP with only TCP candidates and verifies that |
| 1804 | // null IPv4 is used as default address in c line. |
| 1805 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) { |
| 1806 | // Only test 1 m line. |
| 1807 | desc_.RemoveContentByName("video_content_name"); |
| 1808 | // Stun has a high preference than local host. |
| 1809 | cricket::Candidate candidate1( |
| 1810 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1811 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1812 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1813 | cricket::Candidate candidate2( |
| 1814 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1815 | rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| 1816 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1817 | JsepSessionDescription jdesc(kDummyString); |
| 1818 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1819 | |
| 1820 | // Only add the candidates to audio m line. |
| 1821 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1822 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1823 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1824 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1825 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1826 | |
| 1827 | // Audio line should have a c line like this one when no any default exists. |
| 1828 | EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos); |
| 1829 | } |
| 1830 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1831 | // This tests serialization of SDP with a=crypto and a=fingerprint, as would be |
| 1832 | // the case in a DTLS offer. |
| 1833 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) { |
| 1834 | AddFingerprint(); |
| 1835 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1836 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1837 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1838 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1839 | |
| 1840 | std::string sdp_with_fingerprint = kSdpString; |
| 1841 | InjectAfter(kAttributeIcePwdVoice, |
| 1842 | kFingerprint, &sdp_with_fingerprint); |
| 1843 | InjectAfter(kAttributeIcePwdVideo, |
| 1844 | kFingerprint, &sdp_with_fingerprint); |
| 1845 | |
| 1846 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1847 | } |
| 1848 | |
| 1849 | // This tests serialization of SDP with a=fingerprint with no a=crypto, as would |
| 1850 | // be the case in a DTLS answer. |
| 1851 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) { |
| 1852 | AddFingerprint(); |
| 1853 | RemoveCryptos(); |
| 1854 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1855 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1856 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1857 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1858 | |
| 1859 | std::string sdp_with_fingerprint = kSdpString; |
| 1860 | Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint); |
| 1861 | Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint); |
| 1862 | InjectAfter(kAttributeIcePwdVoice, |
| 1863 | kFingerprint, &sdp_with_fingerprint); |
| 1864 | InjectAfter(kAttributeIcePwdVideo, |
| 1865 | kFingerprint, &sdp_with_fingerprint); |
| 1866 | |
| 1867 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1868 | } |
| 1869 | |
| 1870 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { |
| 1871 | // JsepSessionDescription with desc but without candidates. |
| 1872 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1873 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1874 | kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1875 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1876 | EXPECT_EQ(std::string(kSdpString), message); |
| 1877 | } |
| 1878 | |
| 1879 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) { |
| 1880 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1881 | group.AddContentName(kAudioContentName); |
| 1882 | group.AddContentName(kVideoContentName); |
| 1883 | desc_.AddGroup(group); |
| 1884 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1885 | jdesc_.session_id(), |
| 1886 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1887 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1888 | std::string sdp_with_bundle = kSdpFullString; |
| 1889 | InjectAfter(kSessionTime, |
| 1890 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 1891 | &sdp_with_bundle); |
| 1892 | EXPECT_EQ(sdp_with_bundle, message); |
| 1893 | } |
| 1894 | |
| 1895 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) { |
| 1896 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 1897 | GetFirstVideoContent(&desc_)->description); |
| 1898 | vcd->set_bandwidth(100 * 1000); |
| 1899 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 1900 | GetFirstAudioContent(&desc_)->description); |
| 1901 | acd->set_bandwidth(50 * 1000); |
| 1902 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1903 | jdesc_.session_id(), |
| 1904 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1905 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1906 | std::string sdp_with_bandwidth = kSdpFullString; |
wu@webrtc.org | 4c3e991 | 2014-07-16 21:03:13 +0000 | [diff] [blame] | 1907 | InjectAfter("c=IN IP4 74.125.224.39\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1908 | "b=AS:100\r\n", |
| 1909 | &sdp_with_bandwidth); |
wu@webrtc.org | 4c3e991 | 2014-07-16 21:03:13 +0000 | [diff] [blame] | 1910 | InjectAfter("c=IN IP4 74.125.127.126\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1911 | "b=AS:50\r\n", |
| 1912 | &sdp_with_bandwidth); |
| 1913 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 1914 | } |
| 1915 | |
| 1916 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) { |
| 1917 | std::vector<std::string> transport_options; |
| 1918 | transport_options.push_back(kIceOption1); |
| 1919 | transport_options.push_back(kIceOption3); |
| 1920 | AddIceOptions(kAudioContentName, transport_options); |
| 1921 | transport_options.clear(); |
| 1922 | transport_options.push_back(kIceOption2); |
| 1923 | transport_options.push_back(kIceOption3); |
| 1924 | AddIceOptions(kVideoContentName, transport_options); |
| 1925 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1926 | jdesc_.session_id(), |
| 1927 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1928 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1929 | std::string sdp_with_ice_options = kSdpFullString; |
| 1930 | InjectAfter(kAttributeIcePwdVoice, |
| 1931 | "a=ice-options:iceoption1 iceoption3\r\n", |
| 1932 | &sdp_with_ice_options); |
| 1933 | InjectAfter(kAttributeIcePwdVideo, |
| 1934 | "a=ice-options:iceoption2 iceoption3\r\n", |
| 1935 | &sdp_with_ice_options); |
| 1936 | EXPECT_EQ(sdp_with_ice_options, message); |
| 1937 | } |
| 1938 | |
| 1939 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) { |
| 1940 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY)); |
| 1941 | } |
| 1942 | |
| 1943 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) { |
| 1944 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY)); |
| 1945 | } |
| 1946 | |
| 1947 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) { |
| 1948 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE)); |
| 1949 | } |
| 1950 | |
| 1951 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) { |
| 1952 | EXPECT_TRUE(TestSerializeRejected(true, false)); |
| 1953 | } |
| 1954 | |
| 1955 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) { |
| 1956 | EXPECT_TRUE(TestSerializeRejected(false, true)); |
| 1957 | } |
| 1958 | |
| 1959 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) { |
| 1960 | EXPECT_TRUE(TestSerializeRejected(true, true)); |
| 1961 | } |
| 1962 | |
| 1963 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) { |
| 1964 | AddRtpDataChannel(); |
| 1965 | JsepSessionDescription jsep_desc(kDummyString); |
| 1966 | |
| 1967 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1968 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1969 | |
| 1970 | std::string expected_sdp = kSdpString; |
| 1971 | expected_sdp.append(kSdpRtpDataChannelString); |
| 1972 | EXPECT_EQ(expected_sdp, message); |
| 1973 | } |
| 1974 | |
| 1975 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) { |
| 1976 | AddSctpDataChannel(); |
| 1977 | JsepSessionDescription jsep_desc(kDummyString); |
| 1978 | |
| 1979 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1980 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1981 | |
| 1982 | std::string expected_sdp = kSdpString; |
| 1983 | expected_sdp.append(kSdpSctpDataChannelString); |
| 1984 | EXPECT_EQ(message, expected_sdp); |
| 1985 | } |
| 1986 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1987 | TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) { |
| 1988 | AddSctpDataChannel(); |
| 1989 | JsepSessionDescription jsep_desc(kDummyString); |
| 1990 | |
| 1991 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1992 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 1993 | jsep_desc.description()->GetContentDescriptionByName(kDataContentName)); |
| 1994 | |
| 1995 | const int kNewPort = 1234; |
| 1996 | cricket::DataCodec codec( |
| 1997 | cricket::kGoogleSctpDataCodecId, cricket::kGoogleSctpDataCodecName, 0); |
| 1998 | codec.SetParam(cricket::kCodecParamPort, kNewPort); |
| 1999 | dcdesc->AddOrReplaceCodec(codec); |
| 2000 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2001 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2002 | |
| 2003 | std::string expected_sdp = kSdpString; |
| 2004 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2005 | |
| 2006 | char default_portstr[16]; |
| 2007 | char new_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2008 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2009 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2010 | rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort); |
| 2011 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2012 | new_portstr, strlen(new_portstr), |
| 2013 | &expected_sdp); |
| 2014 | |
| 2015 | EXPECT_EQ(expected_sdp, message); |
| 2016 | } |
| 2017 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2018 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) { |
| 2019 | AddRtpDataChannel(); |
| 2020 | data_desc_->set_bandwidth(100*1000); |
| 2021 | JsepSessionDescription jsep_desc(kDummyString); |
| 2022 | |
| 2023 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2024 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2025 | |
| 2026 | std::string expected_sdp = kSdpString; |
| 2027 | expected_sdp.append(kSdpRtpDataChannelString); |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2028 | // Serializing data content shouldn't ignore bandwidth settings. |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 2029 | 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] | 2030 | "b=AS:100\r\n", |
| 2031 | &expected_sdp); |
| 2032 | EXPECT_EQ(expected_sdp, message); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2035 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { |
| 2036 | AddExtmap(); |
| 2037 | JsepSessionDescription desc_with_extmap("dummy"); |
| 2038 | ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(), |
| 2039 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2040 | std::string message = webrtc::SdpSerialize(desc_with_extmap, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2041 | |
| 2042 | std::string sdp_with_extmap = kSdpString; |
| 2043 | InjectAfter("a=mid:audio_content_name\r\n", |
| 2044 | kExtmap, &sdp_with_extmap); |
| 2045 | InjectAfter("a=mid:video_content_name\r\n", |
| 2046 | kExtmap, &sdp_with_extmap); |
| 2047 | |
| 2048 | EXPECT_EQ(sdp_with_extmap, message); |
| 2049 | } |
| 2050 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2051 | TEST_F(WebRtcSdpTest, SerializeCandidates) { |
| 2052 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); |
wu@webrtc.org | ec9f5fb | 2014-06-24 17:05:10 +0000 | [diff] [blame] | 2053 | EXPECT_EQ(std::string(kRawCandidate), message); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2054 | |
| 2055 | Candidate candidate_with_ufrag(candidates_.front()); |
| 2056 | candidate_with_ufrag.set_username("ABC"); |
| 2057 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, |
| 2058 | candidate_with_ufrag)); |
| 2059 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2060 | EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2061 | |
| 2062 | Candidate candidate_with_network_info(candidates_.front()); |
| 2063 | candidate_with_network_info.set_network_id(1); |
| 2064 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2065 | candidate_with_network_info)); |
| 2066 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2067 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message); |
| 2068 | candidate_with_network_info.set_network_cost(999); |
| 2069 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2070 | candidate_with_network_info)); |
| 2071 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2072 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999", |
| 2073 | message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2076 | // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing |
| 2077 | // RFC 6544. |
mallinath@webrtc.org | e999bd0 | 2014-08-13 06:05:55 +0000 | [diff] [blame] | 2078 | TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2079 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2080 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2081 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2082 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2083 | candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
| 2084 | rtc::scoped_ptr<IceCandidateInterface> jcandidate( |
| 2085 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
| 2086 | |
| 2087 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
| 2088 | EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
| 2089 | } |
| 2090 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2091 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
| 2092 | JsepSessionDescription jdesc(kDummyString); |
| 2093 | // Deserialize |
| 2094 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 2095 | // Verify |
| 2096 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2097 | } |
| 2098 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2099 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) { |
| 2100 | JsepSessionDescription jdesc(kDummyString); |
| 2101 | const char kSdpWithoutMline[] = |
| 2102 | "v=0\r\n" |
| 2103 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2104 | "s=-\r\n" |
| 2105 | "t=0 0\r\n" |
| 2106 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"; |
| 2107 | // Deserialize |
| 2108 | EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc)); |
| 2109 | EXPECT_EQ(0u, jdesc.description()->contents().size()); |
| 2110 | } |
| 2111 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2112 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
| 2113 | JsepSessionDescription jdesc(kDummyString); |
| 2114 | std::string sdp_without_carriage_return = kSdpFullString; |
| 2115 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 2116 | // Deserialize |
| 2117 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 2118 | // Verify |
| 2119 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2120 | } |
| 2121 | |
| 2122 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 2123 | // SessionDescription with desc but without candidates. |
| 2124 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 2125 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), |
| 2126 | kSessionId, kSessionVersion)); |
| 2127 | JsepSessionDescription new_jdesc(kDummyString); |
| 2128 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 2129 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 2130 | } |
| 2131 | |
| 2132 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 2133 | static const char kSdpNoRtpmapString[] = |
| 2134 | "v=0\r\n" |
| 2135 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2136 | "s=-\r\n" |
| 2137 | "t=0 0\r\n" |
| 2138 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 2139 | // 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] | 2140 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2141 | // The rtpmap line for static payload codec is optional. |
| 2142 | "a=rtpmap:18 G729/16000\r\n" |
| 2143 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2144 | |
| 2145 | JsepSessionDescription jdesc(kDummyString); |
| 2146 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2147 | cricket::AudioContentDescription* audio = |
| 2148 | static_cast<AudioContentDescription*>( |
| 2149 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2150 | AudioCodecs ref_codecs; |
| 2151 | // The codecs in the AudioContentDescription will be sorted by preference. |
| 2152 | ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3)); |
| 2153 | ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2)); |
| 2154 | ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1)); |
| 2155 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 2156 | } |
| 2157 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2158 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) { |
| 2159 | static const char kSdpNoRtpmapString[] = |
| 2160 | "v=0\r\n" |
| 2161 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2162 | "s=-\r\n" |
| 2163 | "t=0 0\r\n" |
| 2164 | "m=audio 49232 RTP/AVP 18 103\r\n" |
| 2165 | "a=fmtp:18 annexb=yes\r\n" |
| 2166 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2167 | |
| 2168 | JsepSessionDescription jdesc(kDummyString); |
| 2169 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2170 | cricket::AudioContentDescription* audio = |
| 2171 | static_cast<AudioContentDescription*>( |
| 2172 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2173 | |
| 2174 | cricket::AudioCodec g729 = audio->codecs()[0]; |
| 2175 | EXPECT_EQ("G729", g729.name); |
| 2176 | EXPECT_EQ(8000, g729.clockrate); |
| 2177 | EXPECT_EQ(18, g729.id); |
| 2178 | cricket::CodecParameterMap::iterator found = |
| 2179 | g729.params.find("annexb"); |
| 2180 | ASSERT_TRUE(found != g729.params.end()); |
| 2181 | EXPECT_EQ(found->second, "yes"); |
| 2182 | |
| 2183 | cricket::AudioCodec isac = audio->codecs()[1]; |
| 2184 | EXPECT_EQ("ISAC", isac.name); |
| 2185 | EXPECT_EQ(103, isac.id); |
| 2186 | EXPECT_EQ(16000, isac.clockrate); |
| 2187 | } |
| 2188 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2189 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 2190 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 2191 | // Add a DTLS a=fingerprint attribute to our session description. |
| 2192 | AddFingerprint(); |
| 2193 | JsepSessionDescription new_jdesc(kDummyString); |
| 2194 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 2195 | jdesc_.session_id(), |
| 2196 | jdesc_.session_version())); |
| 2197 | |
| 2198 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 2199 | std::string sdp_with_fingerprint = kSdpString; |
| 2200 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2201 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 2202 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 2203 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 2204 | } |
| 2205 | |
| 2206 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
| 2207 | JsepSessionDescription jdesc_with_bundle(kDummyString); |
| 2208 | std::string sdp_with_bundle = kSdpFullString; |
| 2209 | InjectAfter(kSessionTime, |
| 2210 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 2211 | &sdp_with_bundle); |
| 2212 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 2213 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 2214 | group.AddContentName(kAudioContentName); |
| 2215 | group.AddContentName(kVideoContentName); |
| 2216 | desc_.AddGroup(group); |
| 2217 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2218 | jdesc_.session_id(), |
| 2219 | jdesc_.session_version())); |
| 2220 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 2221 | } |
| 2222 | |
| 2223 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
| 2224 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2225 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2226 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 2227 | "b=AS:100\r\n", |
| 2228 | &sdp_with_bandwidth); |
| 2229 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 2230 | "b=AS:50\r\n", |
| 2231 | &sdp_with_bandwidth); |
| 2232 | EXPECT_TRUE( |
| 2233 | SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2234 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2235 | GetFirstVideoContent(&desc_)->description); |
| 2236 | vcd->set_bandwidth(100 * 1000); |
| 2237 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 2238 | GetFirstAudioContent(&desc_)->description); |
| 2239 | acd->set_bandwidth(50 * 1000); |
| 2240 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2241 | jdesc_.session_id(), |
| 2242 | jdesc_.session_version())); |
| 2243 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2244 | } |
| 2245 | |
| 2246 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
| 2247 | JsepSessionDescription jdesc_with_ice_options(kDummyString); |
| 2248 | std::string sdp_with_ice_options = kSdpFullString; |
| 2249 | InjectAfter(kSessionTime, |
| 2250 | "a=ice-options:iceoption3\r\n", |
| 2251 | &sdp_with_ice_options); |
| 2252 | InjectAfter(kAttributeIcePwdVoice, |
| 2253 | "a=ice-options:iceoption1\r\n", |
| 2254 | &sdp_with_ice_options); |
| 2255 | InjectAfter(kAttributeIcePwdVideo, |
| 2256 | "a=ice-options:iceoption2\r\n", |
| 2257 | &sdp_with_ice_options); |
| 2258 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 2259 | std::vector<std::string> transport_options; |
| 2260 | transport_options.push_back(kIceOption3); |
| 2261 | transport_options.push_back(kIceOption1); |
| 2262 | AddIceOptions(kAudioContentName, transport_options); |
| 2263 | transport_options.clear(); |
| 2264 | transport_options.push_back(kIceOption3); |
| 2265 | transport_options.push_back(kIceOption2); |
| 2266 | AddIceOptions(kVideoContentName, transport_options); |
| 2267 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2268 | jdesc_.session_id(), |
| 2269 | jdesc_.session_version())); |
| 2270 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 2271 | } |
| 2272 | |
| 2273 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 2274 | // Remove the original ice-ufrag and ice-pwd |
| 2275 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString); |
| 2276 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 2277 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 2278 | // Add session level ufrag and pwd |
| 2279 | InjectAfter(kSessionTime, |
| 2280 | "a=ice-pwd:session+level+icepwd\r\n" |
| 2281 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 2282 | &sdp_with_ufrag_pwd); |
| 2283 | // Add media level ufrag and pwd for audio |
| 2284 | InjectAfter("a=mid:audio_content_name\r\n", |
| 2285 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 2286 | &sdp_with_ufrag_pwd); |
| 2287 | // Update the candidate ufrag and pwd to the expected ones. |
| 2288 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, |
| 2289 | "media+level+iceufrag", "media+level+icepwd")); |
| 2290 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, |
| 2291 | "session+level+iceufrag", "session+level+icepwd")); |
| 2292 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 2293 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 2294 | } |
| 2295 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2296 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
| 2297 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY)); |
| 2298 | } |
| 2299 | |
| 2300 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
| 2301 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY)); |
| 2302 | } |
| 2303 | |
| 2304 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
| 2305 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE)); |
| 2306 | } |
| 2307 | |
| 2308 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 2309 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 2310 | } |
| 2311 | |
| 2312 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 2313 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 2314 | } |
| 2315 | |
| 2316 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 2317 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 2318 | } |
| 2319 | |
| 2320 | // Tests that we can still handle the sdp uses mslabel and label instead of |
| 2321 | // msid for backward compatibility. |
| 2322 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2323 | jdesc_.description()->set_msid_supported(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2324 | JsepSessionDescription jdesc(kDummyString); |
| 2325 | std::string sdp_without_msid = kSdpFullString; |
| 2326 | Replace("msid", "xmsid", &sdp_without_msid); |
| 2327 | // Deserialize |
| 2328 | EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc)); |
| 2329 | // Verify |
| 2330 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2331 | } |
| 2332 | |
| 2333 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 2334 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2335 | |
| 2336 | std::string sdp = kSdpOneCandidate; |
| 2337 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2338 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2339 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2340 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2341 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2342 | |
| 2343 | // Candidate line without generation extension. |
| 2344 | sdp = kSdpOneCandidate; |
| 2345 | Replace(" generation 2", "", &sdp); |
| 2346 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2347 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2348 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2349 | Candidate expected = jcandidate_->candidate(); |
| 2350 | expected.set_generation(0); |
| 2351 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2352 | |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2353 | // Candidate with network id and/or cost. |
| 2354 | sdp = kSdpOneCandidate; |
| 2355 | Replace(" generation 2", " generation 2 network-id 2", &sdp); |
| 2356 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2357 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2358 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2359 | expected = jcandidate_->candidate(); |
| 2360 | expected.set_network_id(2); |
| 2361 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2362 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
| 2363 | // Add network cost |
| 2364 | Replace(" network-id 2", " network-id 2 network-cost 9", &sdp); |
| 2365 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2366 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2367 | EXPECT_EQ(9, jcandidate.candidate().network_cost()); |
| 2368 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2369 | sdp = kSdpTcpActiveCandidate; |
| 2370 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2371 | // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2372 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2373 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2374 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2375 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2376 | rtc::scoped_ptr<IceCandidateInterface> jcandidate_template( |
| 2377 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
| 2378 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent( |
| 2379 | jcandidate_template->candidate())); |
| 2380 | sdp = kSdpTcpPassiveCandidate; |
| 2381 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2382 | sdp = kSdpTcpSOCandidate; |
| 2383 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | // This test verifies the deserialization of candidate-attribute |
| 2387 | // as per RFC 5245. Candiate-attribute will be of the format |
| 2388 | // candidate:<blah>. This format will be used when candidates |
| 2389 | // are trickled. |
| 2390 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 2391 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2392 | |
| 2393 | std::string candidate_attribute = kRawCandidate; |
| 2394 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2395 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2396 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2397 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2398 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 2399 | |
| 2400 | // Candidate line without generation extension. |
| 2401 | candidate_attribute = kRawCandidate; |
| 2402 | Replace(" generation 2", "", &candidate_attribute); |
| 2403 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2404 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2405 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2406 | Candidate expected = jcandidate_->candidate(); |
| 2407 | expected.set_generation(0); |
| 2408 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2409 | |
| 2410 | // Candidate line without candidate: |
| 2411 | candidate_attribute = kRawCandidate; |
| 2412 | Replace("candidate:", "", &candidate_attribute); |
| 2413 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2414 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2415 | // Candidate line with IPV6 address. |
| 2416 | EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate)); |
| 2417 | } |
| 2418 | |
| 2419 | // This test verifies that the deserialization of an invalid candidate string |
| 2420 | // fails. |
| 2421 | TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) { |
| 2422 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2423 | |
| 2424 | std::string candidate_attribute = kRawCandidate; |
| 2425 | candidate_attribute.replace(0, 1, "x"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2426 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2427 | |
| 2428 | candidate_attribute = kSdpOneCandidate; |
| 2429 | candidate_attribute.replace(0, 1, "x"); |
| 2430 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2431 | |
| 2432 | candidate_attribute = kRawCandidate; |
| 2433 | candidate_attribute.append("\r\n"); |
| 2434 | candidate_attribute.append(kRawCandidate); |
| 2435 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2436 | |
| 2437 | EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) { |
| 2441 | AddRtpDataChannel(); |
| 2442 | JsepSessionDescription jdesc(kDummyString); |
| 2443 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2444 | |
| 2445 | std::string sdp_with_data = kSdpString; |
| 2446 | sdp_with_data.append(kSdpRtpDataChannelString); |
| 2447 | JsepSessionDescription jdesc_output(kDummyString); |
| 2448 | |
| 2449 | // Deserialize |
| 2450 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2451 | // Verify |
| 2452 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2453 | } |
| 2454 | |
| 2455 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
| 2456 | AddSctpDataChannel(); |
| 2457 | JsepSessionDescription jdesc(kDummyString); |
| 2458 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2459 | |
| 2460 | std::string sdp_with_data = kSdpString; |
| 2461 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2462 | JsepSessionDescription jdesc_output(kDummyString); |
| 2463 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2464 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString). |
| 2465 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2466 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2467 | |
| 2468 | // Verify with UDP/DTLS/SCTP. |
| 2469 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2470 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2471 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2472 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2473 | |
| 2474 | // Verify with TCP/DTLS/SCTP. |
| 2475 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2476 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2477 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2478 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2479 | } |
| 2480 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2481 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { |
| 2482 | AddSctpDataChannel(); |
| 2483 | JsepSessionDescription jdesc(kDummyString); |
| 2484 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2485 | |
| 2486 | std::string sdp_with_data = kSdpString; |
| 2487 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2488 | JsepSessionDescription jdesc_output(kDummyString); |
| 2489 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2490 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort). |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2491 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2492 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2493 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2494 | // Verify with UDP/DTLS/SCTP. |
| 2495 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2496 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2497 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2498 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2499 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2500 | // Verify with TCP/DTLS/SCTP. |
| 2501 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2502 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2503 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2504 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2505 | } |
| 2506 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 2507 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { |
| 2508 | AddSctpDataChannel(); |
| 2509 | JsepSessionDescription jdesc(kDummyString); |
| 2510 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2511 | |
| 2512 | std::string sdp_with_data = kSdpString; |
| 2513 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
| 2514 | JsepSessionDescription jdesc_output(kDummyString); |
| 2515 | |
| 2516 | // Verify with DTLS/SCTP. |
| 2517 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2518 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2519 | |
| 2520 | // Verify with UDP/DTLS/SCTP. |
| 2521 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2522 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2523 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2524 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2525 | |
| 2526 | // Verify with TCP/DTLS/SCTP. |
| 2527 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2528 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
| 2529 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2530 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2531 | } |
| 2532 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2533 | // Test to check the behaviour if sctp-port is specified |
| 2534 | // on the m= line and in a=sctp-port. |
| 2535 | TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { |
| 2536 | AddSctpDataChannel(); |
| 2537 | JsepSessionDescription jdesc(kDummyString); |
| 2538 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2539 | |
| 2540 | std::string sdp_with_data = kSdpString; |
| 2541 | // Append m= attributes |
| 2542 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2543 | // Append a=sctp-port attribute |
| 2544 | sdp_with_data.append("a=sctp-port 5000\r\n"); |
| 2545 | JsepSessionDescription jdesc_output(kDummyString); |
| 2546 | |
| 2547 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2548 | } |
| 2549 | |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 +0000 | [diff] [blame] | 2550 | // For crbug/344475. |
| 2551 | TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { |
| 2552 | std::string sdp_with_data = kSdpString; |
| 2553 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2554 | // Remove the "\n" at the end. |
| 2555 | sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); |
| 2556 | JsepSessionDescription jdesc_output(kDummyString); |
| 2557 | |
| 2558 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2559 | // No crash is a pass. |
| 2560 | } |
| 2561 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2562 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) { |
| 2563 | AddSctpDataChannel(); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2564 | const uint16_t kUnusualSctpPort = 9556; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2565 | char default_portstr[16]; |
| 2566 | char unusual_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2567 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2568 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2569 | rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2570 | kUnusualSctpPort); |
| 2571 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2572 | // First setup the expected JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2573 | JsepSessionDescription jdesc(kDummyString); |
| 2574 | // take our pre-built session description and change the SCTP port. |
| 2575 | cricket::SessionDescription* mutant = desc_.Copy(); |
| 2576 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 2577 | mutant->GetContentDescriptionByName(kDataContentName)); |
| 2578 | std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 2579 | EXPECT_EQ(1U, codecs.size()); |
| 2580 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2581 | codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2582 | dcdesc->set_codecs(codecs); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2583 | |
| 2584 | // note: mutant's owned by jdesc now. |
| 2585 | ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion)); |
| 2586 | mutant = NULL; |
| 2587 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2588 | // Then get the deserialized JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2589 | std::string sdp_with_data = kSdpString; |
| 2590 | sdp_with_data.append(kSdpSctpDataChannelString); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2591 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2592 | unusual_portstr, strlen(unusual_portstr), |
| 2593 | &sdp_with_data); |
| 2594 | JsepSessionDescription jdesc_output(kDummyString); |
| 2595 | |
| 2596 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2597 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2598 | |
| 2599 | // We need to test the deserialized JsepSessionDescription from |
| 2600 | // kSdpSctpDataChannelStringWithSctpPort for |
| 2601 | // draft-ietf-mmusic-sctp-sdp-07 |
| 2602 | // a=sctp-port |
| 2603 | sdp_with_data = kSdpString; |
| 2604 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2605 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
| 2606 | unusual_portstr, strlen(unusual_portstr), |
| 2607 | &sdp_with_data); |
| 2608 | |
| 2609 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2610 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2613 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) { |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2614 | // We want to test that deserializing data content limits bandwidth |
| 2615 | // settings (it should never be greater than the default). |
| 2616 | // This should prevent someone from using unlimited data bandwidth through |
| 2617 | // JS and "breaking the Internet". |
| 2618 | // See: https://code.google.com/p/chromium/issues/detail?id=280726 |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2619 | std::string sdp_with_bandwidth = kSdpString; |
| 2620 | sdp_with_bandwidth.append(kSdpRtpDataChannelString); |
| 2621 | InjectAfter("a=mid:data_content_name\r\n", |
| 2622 | "b=AS:100\r\n", |
| 2623 | &sdp_with_bandwidth); |
| 2624 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2625 | |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2626 | EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2627 | } |
| 2628 | |
| 2629 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { |
| 2630 | AddSctpDataChannel(); |
| 2631 | JsepSessionDescription jdesc(kDummyString); |
| 2632 | DataContentDescription* dcd = static_cast<DataContentDescription*>( |
| 2633 | GetFirstDataContent(&desc_)->description); |
| 2634 | dcd->set_bandwidth(100 * 1000); |
| 2635 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2636 | |
| 2637 | std::string sdp_with_bandwidth = kSdpString; |
| 2638 | sdp_with_bandwidth.append(kSdpSctpDataChannelString); |
| 2639 | InjectAfter("a=mid:data_content_name\r\n", |
| 2640 | "b=AS:100\r\n", |
| 2641 | &sdp_with_bandwidth); |
| 2642 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2643 | |
| 2644 | // SCTP has congestion control, so we shouldn't limit the bandwidth |
| 2645 | // as we do for RTP. |
| 2646 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2647 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 2648 | } |
| 2649 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2650 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { |
| 2651 | TestDeserializeExtmap(true, false); |
| 2652 | } |
| 2653 | |
| 2654 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
| 2655 | TestDeserializeExtmap(false, true); |
| 2656 | } |
| 2657 | |
| 2658 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
| 2659 | TestDeserializeExtmap(true, true); |
| 2660 | } |
| 2661 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2662 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { |
| 2663 | JsepSessionDescription jdesc(kDummyString); |
| 2664 | std::string sdp = kSdpFullString; |
| 2665 | sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. |
| 2666 | // Deserialize |
| 2667 | SdpParseError error; |
| 2668 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2669 | 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] | 2670 | EXPECT_EQ(lastline, error.line); |
| 2671 | EXPECT_EQ("Invalid SDP line.", error.description); |
| 2672 | } |
| 2673 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2674 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 2675 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2676 | std::string new_sdp = kSdpOneCandidate; |
| 2677 | Replace("udp", "unsupported_transport", &new_sdp); |
| 2678 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2679 | new_sdp = kSdpOneCandidate; |
| 2680 | Replace("udp", "uDP", &new_sdp); |
| 2681 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2682 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2683 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2684 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2685 | } |
| 2686 | |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2687 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2688 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2689 | EXPECT_TRUE( |
| 2690 | SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2691 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2692 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2693 | Candidate ref_candidate = jcandidate_->candidate(); |
| 2694 | ref_candidate.set_username("user_rtp"); |
| 2695 | ref_candidate.set_password("password_rtp"); |
| 2696 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 2697 | } |
| 2698 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2699 | TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) { |
| 2700 | JsepSessionDescription jdesc(kDummyString); |
| 2701 | |
| 2702 | // Deserialize |
| 2703 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
| 2704 | |
| 2705 | // Verify |
| 2706 | cricket::AudioContentDescription* audio = |
| 2707 | static_cast<AudioContentDescription*>( |
| 2708 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2709 | EXPECT_TRUE(audio->conference_mode()); |
| 2710 | |
| 2711 | cricket::VideoContentDescription* video = |
| 2712 | static_cast<VideoContentDescription*>( |
| 2713 | jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO)); |
| 2714 | EXPECT_TRUE(video->conference_mode()); |
| 2715 | } |
| 2716 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2717 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 2718 | const char kSdpDestroyer[] = "!@#$%^&"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2719 | const char kSdpEmptyType[] = " =candidate"; |
| 2720 | const char kSdpEqualAsPlus[] = "a+candidate"; |
| 2721 | const char kSdpSpaceAfterEqual[] = "a= candidate"; |
| 2722 | const char kSdpUpperType[] = "A=candidate"; |
| 2723 | const char kSdpEmptyLine[] = ""; |
| 2724 | const char kSdpMissingValue[] = "a="; |
| 2725 | |
| 2726 | const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2727 | "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] | 2728 | const char kSdpExtraField[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2729 | "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] | 2730 | const char kSdpMissingSpace[] = "a=fingerprint:sha-1" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2731 | "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] | 2732 | // MD5 is not allowed in fingerprints. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2733 | const char kSdpMd5[] = "a=fingerprint:md5 " |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2734 | "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] | 2735 | |
| 2736 | // Broken session description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2737 | ExpectParseFailure("v=", kSdpDestroyer); |
| 2738 | ExpectParseFailure("o=", kSdpDestroyer); |
| 2739 | ExpectParseFailure("s=-", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2740 | // Broken time description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2741 | ExpectParseFailure("t=", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2742 | |
| 2743 | // Broken media description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2744 | ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39"); |
| 2745 | ExpectParseFailure("m=video", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2746 | |
| 2747 | // Invalid lines |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2748 | ExpectParseFailure("a=candidate", kSdpEmptyType); |
| 2749 | ExpectParseFailure("a=candidate", kSdpEqualAsPlus); |
| 2750 | ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual); |
| 2751 | ExpectParseFailure("a=candidate", kSdpUpperType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2752 | |
| 2753 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 2754 | // because it's orthogonal to what we are replacing and hence |
| 2755 | // safe. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2756 | ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint); |
| 2757 | ExpectParseFailure("a=sendrecv", kSdpExtraField); |
| 2758 | ExpectParseFailure("a=sendrecv", kSdpMissingSpace); |
| 2759 | ExpectParseFailure("a=sendrecv", kSdpMd5); |
| 2760 | |
| 2761 | // Empty Line |
| 2762 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine); |
| 2763 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) { |
| 2767 | // ssrc |
| 2768 | ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue"); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2769 | 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] | 2770 | // crypto |
| 2771 | ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue "); |
| 2772 | // rtpmap |
| 2773 | ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue "); |
| 2774 | ExpectParseFailure("opus/48000/2", "opus/badvalue/2"); |
| 2775 | ExpectParseFailure("opus/48000/2", "opus/48000/badvalue"); |
| 2776 | // candidate |
| 2777 | ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432"); |
| 2778 | ExpectParseFailure("1 udp 2130706432", "1 udp badvalue"); |
| 2779 | ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue"); |
| 2780 | ExpectParseFailure("rport 2346", "rport badvalue"); |
| 2781 | ExpectParseFailure("rport 2346 generation 2", |
| 2782 | "rport 2346 generation badvalue"); |
| 2783 | // m line |
| 2784 | ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104", |
| 2785 | "m=audio 2345 RTP/SAVPF 111 badvalue 104"); |
| 2786 | |
| 2787 | // bandwidth |
| 2788 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2789 | "b=AS:badvalue\r\n", |
| 2790 | "b=AS:badvalue"); |
| 2791 | // rtcp-fb |
| 2792 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2793 | "a=rtcp-fb:badvalue nack\r\n", |
| 2794 | "a=rtcp-fb:badvalue nack"); |
| 2795 | // extmap |
| 2796 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2797 | "a=extmap:badvalue http://example.com\r\n", |
| 2798 | "a=extmap:badvalue http://example.com"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
| 2802 | JsepSessionDescription jdesc_output(kDummyString); |
| 2803 | |
| 2804 | const char kSdpWithReorderedPlTypesString[] = |
| 2805 | "v=0\r\n" |
| 2806 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2807 | "s=-\r\n" |
| 2808 | "t=0 0\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 2809 | "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] | 2810 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 2811 | // in the map. |
| 2812 | "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] | 2813 | "a=rtpmap:104 ISAC/32000\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2814 | |
| 2815 | // Deserialize |
| 2816 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 2817 | |
| 2818 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description()); |
| 2819 | ASSERT_TRUE(ac != NULL); |
| 2820 | const AudioContentDescription* acd = |
| 2821 | static_cast<const AudioContentDescription*>(ac->description); |
| 2822 | ASSERT_FALSE(acd->codecs().empty()); |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2823 | EXPECT_EQ("ISAC", acd->codecs()[0].name); |
| 2824 | EXPECT_EQ(32000, acd->codecs()[0].clockrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2825 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 2826 | } |
| 2827 | |
| 2828 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
| 2829 | JsepSessionDescription jdesc_output(kDummyString); |
| 2830 | CodecParams params; |
| 2831 | params.max_ptime = 40; |
| 2832 | params.ptime = 30; |
| 2833 | params.min_ptime = 10; |
| 2834 | params.sprop_stereo = 1; |
| 2835 | params.stereo = 1; |
| 2836 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2837 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2838 | TestDeserializeCodecParams(params, &jdesc_output); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2839 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 2843 | const bool kUseWildcard = false; |
| 2844 | JsepSessionDescription jdesc_output(kDummyString); |
| 2845 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2846 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 2850 | const bool kUseWildcard = true; |
| 2851 | JsepSessionDescription jdesc_output(kDummyString); |
| 2852 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2853 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
| 2857 | JsepSessionDescription jdesc_output(kDummyString); |
| 2858 | |
| 2859 | const char kSdpWithFmtpString[] = |
| 2860 | "v=0\r\n" |
| 2861 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2862 | "s=-\r\n" |
| 2863 | "t=0 0\r\n" |
| 2864 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2865 | "a=rtpmap:120 VP8/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2866 | "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n"; |
| 2867 | |
| 2868 | // Deserialize |
| 2869 | SdpParseError error; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 2870 | EXPECT_TRUE( |
| 2871 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2872 | |
| 2873 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2874 | ASSERT_TRUE(vc != NULL); |
| 2875 | const VideoContentDescription* vcd = |
| 2876 | static_cast<const VideoContentDescription*>(vc->description); |
| 2877 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2878 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2879 | EXPECT_EQ("VP8", vp8.name); |
| 2880 | EXPECT_EQ(120, vp8.id); |
| 2881 | cricket::CodecParameterMap::iterator found = |
| 2882 | vp8.params.find("x-google-min-bitrate"); |
| 2883 | ASSERT_TRUE(found != vp8.params.end()); |
| 2884 | EXPECT_EQ(found->second, "10"); |
| 2885 | found = vp8.params.find("x-google-max-quantization"); |
| 2886 | ASSERT_TRUE(found != vp8.params.end()); |
| 2887 | EXPECT_EQ(found->second, "40"); |
| 2888 | } |
| 2889 | |
| 2890 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) { |
| 2891 | JsepSessionDescription jdesc_output(kDummyString); |
| 2892 | |
| 2893 | const char kSdpWithFmtpString[] = |
| 2894 | "v=0\r\n" |
| 2895 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2896 | "s=-\r\n" |
| 2897 | "t=0 0\r\n" |
| 2898 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2899 | "a=rtpmap:120 VP8/90000\r\n" |
| 2900 | "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] | 2901 | |
| 2902 | // Deserialize |
| 2903 | SdpParseError error; |
| 2904 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, |
| 2905 | &error)); |
| 2906 | |
| 2907 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2908 | ASSERT_TRUE(vc != NULL); |
| 2909 | const VideoContentDescription* vcd = |
| 2910 | static_cast<const VideoContentDescription*>(vc->description); |
| 2911 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2912 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2913 | EXPECT_EQ("VP8", vp8.name); |
| 2914 | EXPECT_EQ(120, vp8.id); |
| 2915 | cricket::CodecParameterMap::iterator found = |
| 2916 | vp8.params.find("x-google-min-bitrate"); |
| 2917 | ASSERT_TRUE(found != vp8.params.end()); |
| 2918 | EXPECT_EQ(found->second, "10"); |
| 2919 | found = vp8.params.find("x-google-max-quantization"); |
| 2920 | ASSERT_TRUE(found != vp8.params.end()); |
| 2921 | EXPECT_EQ(found->second, "40"); |
| 2922 | } |
| 2923 | |
| 2924 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
| 2925 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2926 | GetFirstVideoContent(&desc_)->description); |
| 2927 | |
| 2928 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 2929 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 2930 | vcd->set_codecs(codecs); |
| 2931 | |
| 2932 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2933 | jdesc_.session_id(), |
| 2934 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2935 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2936 | std::string sdp_with_fmtp = kSdpFullString; |
| 2937 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
| 2938 | "a=fmtp:120 x-google-min-bitrate=10\r\n", |
| 2939 | &sdp_with_fmtp); |
| 2940 | EXPECT_EQ(sdp_with_fmtp, message); |
| 2941 | } |
| 2942 | |
| 2943 | TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) { |
| 2944 | JsepSessionDescription jdesc_with_icelite(kDummyString); |
| 2945 | std::string sdp_with_icelite = kSdpFullString; |
| 2946 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2947 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 2948 | const cricket::TransportInfo* tinfo1 = |
| 2949 | desc->GetTransportInfoByName("audio_content_name"); |
| 2950 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 2951 | const cricket::TransportInfo* tinfo2 = |
| 2952 | desc->GetTransportInfoByName("video_content_name"); |
| 2953 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
| 2954 | InjectAfter(kSessionTime, |
| 2955 | "a=ice-lite\r\n", |
| 2956 | &sdp_with_icelite); |
| 2957 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2958 | desc = jdesc_with_icelite.description(); |
| 2959 | const cricket::TransportInfo* atinfo = |
| 2960 | desc->GetTransportInfoByName("audio_content_name"); |
| 2961 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 2962 | const cricket::TransportInfo* vtinfo = |
| 2963 | desc->GetTransportInfoByName("video_content_name"); |
| 2964 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
| 2965 | } |
| 2966 | |
| 2967 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 2968 | // correctly in the output SDP. |
| 2969 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 2970 | std::string sdp_with_data = kSdpString; |
| 2971 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
| 2972 | JsepSessionDescription jdesc_output(kDummyString); |
| 2973 | |
| 2974 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2975 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2976 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2977 | |
| 2978 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 2979 | AddFingerprint(); |
| 2980 | TransportInfo audio_transport_info = |
| 2981 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 2982 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2983 | audio_transport_info.description.connection_role); |
| 2984 | audio_transport_info.description.connection_role = |
| 2985 | cricket::CONNECTIONROLE_ACTIVE; |
| 2986 | |
| 2987 | TransportInfo video_transport_info = |
| 2988 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 2989 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2990 | video_transport_info.description.connection_role); |
| 2991 | video_transport_info.description.connection_role = |
| 2992 | cricket::CONNECTIONROLE_ACTIVE; |
| 2993 | |
| 2994 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 2995 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 2996 | |
| 2997 | desc_.AddTransportInfo(audio_transport_info); |
| 2998 | desc_.AddTransportInfo(video_transport_info); |
| 2999 | |
| 3000 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 3001 | jdesc_.session_id(), |
| 3002 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3003 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 3004 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3005 | |
| 3006 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
| 3007 | InjectAfter(kAttributeIcePwdVoice, |
| 3008 | kFingerprint, &sdp_with_dtlssetup); |
| 3009 | InjectAfter(kAttributeIcePwdVideo, |
| 3010 | kFingerprint, &sdp_with_dtlssetup); |
| 3011 | // Now adding |setup| attribute. |
| 3012 | InjectAfter(kFingerprint, |
| 3013 | "a=setup:active\r\n", &sdp_with_dtlssetup); |
| 3014 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 3015 | } |
| 3016 | |
| 3017 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) { |
| 3018 | JsepSessionDescription jdesc_with_dtlssetup(kDummyString); |
| 3019 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3020 | InjectAfter(kSessionTime, |
| 3021 | "a=setup:actpass\r\n", |
| 3022 | &sdp_with_dtlssetup); |
| 3023 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 3024 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 3025 | const cricket::TransportInfo* atinfo = |
| 3026 | desc->GetTransportInfoByName("audio_content_name"); |
| 3027 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3028 | atinfo->description.connection_role); |
| 3029 | const cricket::TransportInfo* vtinfo = |
| 3030 | desc->GetTransportInfoByName("video_content_name"); |
| 3031 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3032 | vtinfo->description.connection_role); |
| 3033 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3034 | |
| 3035 | // Verifies that the order of the serialized m-lines follows the order of the |
| 3036 | // ContentInfo in SessionDescription, and vise versa for deserialization. |
| 3037 | TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) { |
| 3038 | JsepSessionDescription jdesc(kDummyString); |
| 3039 | const std::string media_content_sdps[3] = { |
| 3040 | kSdpAudioString, |
| 3041 | kSdpVideoString, |
| 3042 | kSdpSctpDataChannelString |
| 3043 | }; |
| 3044 | const cricket::MediaType media_types[3] = { |
| 3045 | cricket::MEDIA_TYPE_AUDIO, |
| 3046 | cricket::MEDIA_TYPE_VIDEO, |
| 3047 | cricket::MEDIA_TYPE_DATA |
| 3048 | }; |
| 3049 | |
| 3050 | // Verifies all 6 permutations. |
| 3051 | for (size_t i = 0; i < 6; ++i) { |
| 3052 | size_t media_content_in_sdp[3]; |
| 3053 | // The index of the first media content. |
| 3054 | media_content_in_sdp[0] = i / 2; |
| 3055 | // The index of the second media content. |
| 3056 | media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3; |
| 3057 | // The index of the third media content. |
| 3058 | media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3; |
| 3059 | |
| 3060 | std::string sdp_string = kSdpSessionString; |
| 3061 | for (size_t i = 0; i < 3; ++i) |
| 3062 | sdp_string += media_content_sdps[media_content_in_sdp[i]]; |
| 3063 | |
| 3064 | EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc)); |
| 3065 | cricket::SessionDescription* desc = jdesc.description(); |
| 3066 | EXPECT_EQ(3u, desc->contents().size()); |
| 3067 | |
| 3068 | for (size_t i = 0; i < 3; ++i) { |
| 3069 | const cricket::MediaContentDescription* mdesc = |
| 3070 | static_cast<const cricket::MediaContentDescription*>( |
| 3071 | desc->contents()[i].description); |
| 3072 | EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 3073 | } |
| 3074 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3075 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3076 | EXPECT_EQ(sdp_string, serialized_sdp); |
| 3077 | } |
| 3078 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3079 | |
| 3080 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) { |
| 3081 | MakePlanBDescription(); |
| 3082 | |
| 3083 | JsepSessionDescription deserialized_description(kDummyString); |
| 3084 | EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description)); |
| 3085 | |
| 3086 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3087 | } |
| 3088 | |
| 3089 | TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) { |
| 3090 | MakePlanBDescription(); |
| 3091 | TestSerialize(jdesc_, false); |
| 3092 | } |
| 3093 | |
Taylor Brandstetter | 5de6b75 | 2016-03-09 17:02:30 -0800 | [diff] [blame] | 3094 | // Some WebRTC endpoints include the msid in both the Plan B and Unified Plan |
| 3095 | // ways, to make SDP that's compatible with both Plan B and Unified Plan (to |
| 3096 | // some extent). If we parse this, the Plan B msid attribute (which is more |
| 3097 | // specific, since it's at the SSRC level) should take priority. |
| 3098 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) { |
| 3099 | MakePlanBDescription(); |
| 3100 | |
| 3101 | JsepSessionDescription deserialized_description(kDummyString); |
| 3102 | EXPECT_TRUE( |
| 3103 | SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description)); |
| 3104 | |
| 3105 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3106 | } |
| 3107 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3108 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) { |
| 3109 | MakeUnifiedPlanDescription(); |
| 3110 | |
| 3111 | JsepSessionDescription deserialized_description(kDummyString); |
| 3112 | EXPECT_TRUE( |
| 3113 | SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); |
| 3114 | |
| 3115 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3116 | } |
| 3117 | |
| 3118 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { |
| 3119 | MakeUnifiedPlanDescription(); |
| 3120 | TestSerialize(jdesc_, true); |
| 3121 | } |