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); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2063 | // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing |
| 2064 | // RFC 6544. |
mallinath@webrtc.org | e999bd0 | 2014-08-13 06:05:55 +0000 | [diff] [blame] | 2065 | TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2066 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2067 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2068 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2069 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2070 | candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
| 2071 | rtc::scoped_ptr<IceCandidateInterface> jcandidate( |
| 2072 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
| 2073 | |
| 2074 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
| 2075 | EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
| 2076 | } |
| 2077 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2078 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
| 2079 | JsepSessionDescription jdesc(kDummyString); |
| 2080 | // Deserialize |
| 2081 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 2082 | // Verify |
| 2083 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2084 | } |
| 2085 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2086 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) { |
| 2087 | JsepSessionDescription jdesc(kDummyString); |
| 2088 | const char kSdpWithoutMline[] = |
| 2089 | "v=0\r\n" |
| 2090 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2091 | "s=-\r\n" |
| 2092 | "t=0 0\r\n" |
| 2093 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"; |
| 2094 | // Deserialize |
| 2095 | EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc)); |
| 2096 | EXPECT_EQ(0u, jdesc.description()->contents().size()); |
| 2097 | } |
| 2098 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2099 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
| 2100 | JsepSessionDescription jdesc(kDummyString); |
| 2101 | std::string sdp_without_carriage_return = kSdpFullString; |
| 2102 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 2103 | // Deserialize |
| 2104 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 2105 | // Verify |
| 2106 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2107 | } |
| 2108 | |
| 2109 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 2110 | // SessionDescription with desc but without candidates. |
| 2111 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 2112 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), |
| 2113 | kSessionId, kSessionVersion)); |
| 2114 | JsepSessionDescription new_jdesc(kDummyString); |
| 2115 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 2116 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 2117 | } |
| 2118 | |
| 2119 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 2120 | static const char kSdpNoRtpmapString[] = |
| 2121 | "v=0\r\n" |
| 2122 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2123 | "s=-\r\n" |
| 2124 | "t=0 0\r\n" |
| 2125 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 2126 | // 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] | 2127 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2128 | // The rtpmap line for static payload codec is optional. |
| 2129 | "a=rtpmap:18 G729/16000\r\n" |
| 2130 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2131 | |
| 2132 | JsepSessionDescription jdesc(kDummyString); |
| 2133 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2134 | cricket::AudioContentDescription* audio = |
| 2135 | static_cast<AudioContentDescription*>( |
| 2136 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2137 | AudioCodecs ref_codecs; |
| 2138 | // The codecs in the AudioContentDescription will be sorted by preference. |
| 2139 | ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3)); |
| 2140 | ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2)); |
| 2141 | ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1)); |
| 2142 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 2143 | } |
| 2144 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2145 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) { |
| 2146 | static const char kSdpNoRtpmapString[] = |
| 2147 | "v=0\r\n" |
| 2148 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2149 | "s=-\r\n" |
| 2150 | "t=0 0\r\n" |
| 2151 | "m=audio 49232 RTP/AVP 18 103\r\n" |
| 2152 | "a=fmtp:18 annexb=yes\r\n" |
| 2153 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2154 | |
| 2155 | JsepSessionDescription jdesc(kDummyString); |
| 2156 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2157 | cricket::AudioContentDescription* audio = |
| 2158 | static_cast<AudioContentDescription*>( |
| 2159 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2160 | |
| 2161 | cricket::AudioCodec g729 = audio->codecs()[0]; |
| 2162 | EXPECT_EQ("G729", g729.name); |
| 2163 | EXPECT_EQ(8000, g729.clockrate); |
| 2164 | EXPECT_EQ(18, g729.id); |
| 2165 | cricket::CodecParameterMap::iterator found = |
| 2166 | g729.params.find("annexb"); |
| 2167 | ASSERT_TRUE(found != g729.params.end()); |
| 2168 | EXPECT_EQ(found->second, "yes"); |
| 2169 | |
| 2170 | cricket::AudioCodec isac = audio->codecs()[1]; |
| 2171 | EXPECT_EQ("ISAC", isac.name); |
| 2172 | EXPECT_EQ(103, isac.id); |
| 2173 | EXPECT_EQ(16000, isac.clockrate); |
| 2174 | } |
| 2175 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2176 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 2177 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 2178 | // Add a DTLS a=fingerprint attribute to our session description. |
| 2179 | AddFingerprint(); |
| 2180 | JsepSessionDescription new_jdesc(kDummyString); |
| 2181 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 2182 | jdesc_.session_id(), |
| 2183 | jdesc_.session_version())); |
| 2184 | |
| 2185 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 2186 | std::string sdp_with_fingerprint = kSdpString; |
| 2187 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2188 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 2189 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 2190 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 2191 | } |
| 2192 | |
| 2193 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
| 2194 | JsepSessionDescription jdesc_with_bundle(kDummyString); |
| 2195 | std::string sdp_with_bundle = kSdpFullString; |
| 2196 | InjectAfter(kSessionTime, |
| 2197 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 2198 | &sdp_with_bundle); |
| 2199 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 2200 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 2201 | group.AddContentName(kAudioContentName); |
| 2202 | group.AddContentName(kVideoContentName); |
| 2203 | desc_.AddGroup(group); |
| 2204 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2205 | jdesc_.session_id(), |
| 2206 | jdesc_.session_version())); |
| 2207 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 2208 | } |
| 2209 | |
| 2210 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
| 2211 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2212 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2213 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 2214 | "b=AS:100\r\n", |
| 2215 | &sdp_with_bandwidth); |
| 2216 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 2217 | "b=AS:50\r\n", |
| 2218 | &sdp_with_bandwidth); |
| 2219 | EXPECT_TRUE( |
| 2220 | SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2221 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2222 | GetFirstVideoContent(&desc_)->description); |
| 2223 | vcd->set_bandwidth(100 * 1000); |
| 2224 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 2225 | GetFirstAudioContent(&desc_)->description); |
| 2226 | acd->set_bandwidth(50 * 1000); |
| 2227 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2228 | jdesc_.session_id(), |
| 2229 | jdesc_.session_version())); |
| 2230 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2231 | } |
| 2232 | |
| 2233 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
| 2234 | JsepSessionDescription jdesc_with_ice_options(kDummyString); |
| 2235 | std::string sdp_with_ice_options = kSdpFullString; |
| 2236 | InjectAfter(kSessionTime, |
| 2237 | "a=ice-options:iceoption3\r\n", |
| 2238 | &sdp_with_ice_options); |
| 2239 | InjectAfter(kAttributeIcePwdVoice, |
| 2240 | "a=ice-options:iceoption1\r\n", |
| 2241 | &sdp_with_ice_options); |
| 2242 | InjectAfter(kAttributeIcePwdVideo, |
| 2243 | "a=ice-options:iceoption2\r\n", |
| 2244 | &sdp_with_ice_options); |
| 2245 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 2246 | std::vector<std::string> transport_options; |
| 2247 | transport_options.push_back(kIceOption3); |
| 2248 | transport_options.push_back(kIceOption1); |
| 2249 | AddIceOptions(kAudioContentName, transport_options); |
| 2250 | transport_options.clear(); |
| 2251 | transport_options.push_back(kIceOption3); |
| 2252 | transport_options.push_back(kIceOption2); |
| 2253 | AddIceOptions(kVideoContentName, transport_options); |
| 2254 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2255 | jdesc_.session_id(), |
| 2256 | jdesc_.session_version())); |
| 2257 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 2258 | } |
| 2259 | |
| 2260 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 2261 | // Remove the original ice-ufrag and ice-pwd |
| 2262 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString); |
| 2263 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 2264 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 2265 | // Add session level ufrag and pwd |
| 2266 | InjectAfter(kSessionTime, |
| 2267 | "a=ice-pwd:session+level+icepwd\r\n" |
| 2268 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 2269 | &sdp_with_ufrag_pwd); |
| 2270 | // Add media level ufrag and pwd for audio |
| 2271 | InjectAfter("a=mid:audio_content_name\r\n", |
| 2272 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 2273 | &sdp_with_ufrag_pwd); |
| 2274 | // Update the candidate ufrag and pwd to the expected ones. |
| 2275 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, |
| 2276 | "media+level+iceufrag", "media+level+icepwd")); |
| 2277 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, |
| 2278 | "session+level+iceufrag", "session+level+icepwd")); |
| 2279 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 2280 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 2281 | } |
| 2282 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2283 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
| 2284 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY)); |
| 2285 | } |
| 2286 | |
| 2287 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
| 2288 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY)); |
| 2289 | } |
| 2290 | |
| 2291 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
| 2292 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE)); |
| 2293 | } |
| 2294 | |
| 2295 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 2296 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 2297 | } |
| 2298 | |
| 2299 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 2300 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 2301 | } |
| 2302 | |
| 2303 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 2304 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 2305 | } |
| 2306 | |
| 2307 | // Tests that we can still handle the sdp uses mslabel and label instead of |
| 2308 | // msid for backward compatibility. |
| 2309 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2310 | jdesc_.description()->set_msid_supported(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2311 | JsepSessionDescription jdesc(kDummyString); |
| 2312 | std::string sdp_without_msid = kSdpFullString; |
| 2313 | Replace("msid", "xmsid", &sdp_without_msid); |
| 2314 | // Deserialize |
| 2315 | EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc)); |
| 2316 | // Verify |
| 2317 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2318 | } |
| 2319 | |
| 2320 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 2321 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2322 | |
| 2323 | std::string sdp = kSdpOneCandidate; |
| 2324 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2325 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2326 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2327 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2328 | |
| 2329 | // Candidate line without generation extension. |
| 2330 | sdp = kSdpOneCandidate; |
| 2331 | Replace(" generation 2", "", &sdp); |
| 2332 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2333 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2334 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2335 | Candidate expected = jcandidate_->candidate(); |
| 2336 | expected.set_generation(0); |
| 2337 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2338 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2339 | sdp = kSdpTcpActiveCandidate; |
| 2340 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2341 | // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2342 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2343 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2344 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2345 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2346 | rtc::scoped_ptr<IceCandidateInterface> jcandidate_template( |
| 2347 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
| 2348 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent( |
| 2349 | jcandidate_template->candidate())); |
| 2350 | sdp = kSdpTcpPassiveCandidate; |
| 2351 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2352 | sdp = kSdpTcpSOCandidate; |
| 2353 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | // This test verifies the deserialization of candidate-attribute |
| 2357 | // as per RFC 5245. Candiate-attribute will be of the format |
| 2358 | // candidate:<blah>. This format will be used when candidates |
| 2359 | // are trickled. |
| 2360 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 2361 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2362 | |
| 2363 | std::string candidate_attribute = kRawCandidate; |
| 2364 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2365 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2366 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2367 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2368 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 2369 | |
| 2370 | // Candidate line without generation extension. |
| 2371 | candidate_attribute = kRawCandidate; |
| 2372 | Replace(" generation 2", "", &candidate_attribute); |
| 2373 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2374 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2375 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2376 | Candidate expected = jcandidate_->candidate(); |
| 2377 | expected.set_generation(0); |
| 2378 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2379 | |
| 2380 | // Candidate line without candidate: |
| 2381 | candidate_attribute = kRawCandidate; |
| 2382 | Replace("candidate:", "", &candidate_attribute); |
| 2383 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2384 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2385 | // Candidate line with IPV6 address. |
| 2386 | EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate)); |
| 2387 | } |
| 2388 | |
| 2389 | // This test verifies that the deserialization of an invalid candidate string |
| 2390 | // fails. |
| 2391 | TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) { |
| 2392 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2393 | |
| 2394 | std::string candidate_attribute = kRawCandidate; |
| 2395 | candidate_attribute.replace(0, 1, "x"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2396 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2397 | |
| 2398 | candidate_attribute = kSdpOneCandidate; |
| 2399 | candidate_attribute.replace(0, 1, "x"); |
| 2400 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2401 | |
| 2402 | candidate_attribute = kRawCandidate; |
| 2403 | candidate_attribute.append("\r\n"); |
| 2404 | candidate_attribute.append(kRawCandidate); |
| 2405 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2406 | |
| 2407 | EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) { |
| 2411 | AddRtpDataChannel(); |
| 2412 | JsepSessionDescription jdesc(kDummyString); |
| 2413 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2414 | |
| 2415 | std::string sdp_with_data = kSdpString; |
| 2416 | sdp_with_data.append(kSdpRtpDataChannelString); |
| 2417 | JsepSessionDescription jdesc_output(kDummyString); |
| 2418 | |
| 2419 | // Deserialize |
| 2420 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2421 | // Verify |
| 2422 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2423 | } |
| 2424 | |
| 2425 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
| 2426 | AddSctpDataChannel(); |
| 2427 | JsepSessionDescription jdesc(kDummyString); |
| 2428 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2429 | |
| 2430 | std::string sdp_with_data = kSdpString; |
| 2431 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2432 | JsepSessionDescription jdesc_output(kDummyString); |
| 2433 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2434 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString). |
| 2435 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2436 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2437 | |
| 2438 | // Verify with UDP/DTLS/SCTP. |
| 2439 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2440 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2441 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2442 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2443 | |
| 2444 | // Verify with TCP/DTLS/SCTP. |
| 2445 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2446 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2447 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2448 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2449 | } |
| 2450 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2451 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { |
| 2452 | AddSctpDataChannel(); |
| 2453 | JsepSessionDescription jdesc(kDummyString); |
| 2454 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2455 | |
| 2456 | std::string sdp_with_data = kSdpString; |
| 2457 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2458 | JsepSessionDescription jdesc_output(kDummyString); |
| 2459 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2460 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort). |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2461 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2462 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2463 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2464 | // Verify with UDP/DTLS/SCTP. |
| 2465 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2466 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2467 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2468 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2469 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2470 | // Verify with TCP/DTLS/SCTP. |
| 2471 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2472 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2473 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2474 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2475 | } |
| 2476 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 2477 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { |
| 2478 | AddSctpDataChannel(); |
| 2479 | JsepSessionDescription jdesc(kDummyString); |
| 2480 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2481 | |
| 2482 | std::string sdp_with_data = kSdpString; |
| 2483 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
| 2484 | JsepSessionDescription jdesc_output(kDummyString); |
| 2485 | |
| 2486 | // Verify with DTLS/SCTP. |
| 2487 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2488 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2489 | |
| 2490 | // Verify with UDP/DTLS/SCTP. |
| 2491 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2492 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2493 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2494 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2495 | |
| 2496 | // Verify with TCP/DTLS/SCTP. |
| 2497 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2498 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
| 2499 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2500 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2501 | } |
| 2502 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2503 | // Test to check the behaviour if sctp-port is specified |
| 2504 | // on the m= line and in a=sctp-port. |
| 2505 | TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { |
| 2506 | AddSctpDataChannel(); |
| 2507 | JsepSessionDescription jdesc(kDummyString); |
| 2508 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2509 | |
| 2510 | std::string sdp_with_data = kSdpString; |
| 2511 | // Append m= attributes |
| 2512 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2513 | // Append a=sctp-port attribute |
| 2514 | sdp_with_data.append("a=sctp-port 5000\r\n"); |
| 2515 | JsepSessionDescription jdesc_output(kDummyString); |
| 2516 | |
| 2517 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2518 | } |
| 2519 | |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 +0000 | [diff] [blame] | 2520 | // For crbug/344475. |
| 2521 | TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { |
| 2522 | std::string sdp_with_data = kSdpString; |
| 2523 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2524 | // Remove the "\n" at the end. |
| 2525 | sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); |
| 2526 | JsepSessionDescription jdesc_output(kDummyString); |
| 2527 | |
| 2528 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2529 | // No crash is a pass. |
| 2530 | } |
| 2531 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2532 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) { |
| 2533 | AddSctpDataChannel(); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2534 | const uint16_t kUnusualSctpPort = 9556; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2535 | char default_portstr[16]; |
| 2536 | char unusual_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2537 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2538 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2539 | rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2540 | kUnusualSctpPort); |
| 2541 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2542 | // First setup the expected JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2543 | JsepSessionDescription jdesc(kDummyString); |
| 2544 | // take our pre-built session description and change the SCTP port. |
| 2545 | cricket::SessionDescription* mutant = desc_.Copy(); |
| 2546 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 2547 | mutant->GetContentDescriptionByName(kDataContentName)); |
| 2548 | std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 2549 | EXPECT_EQ(1U, codecs.size()); |
| 2550 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2551 | codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2552 | dcdesc->set_codecs(codecs); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2553 | |
| 2554 | // note: mutant's owned by jdesc now. |
| 2555 | ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion)); |
| 2556 | mutant = NULL; |
| 2557 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2558 | // Then get the deserialized JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2559 | std::string sdp_with_data = kSdpString; |
| 2560 | sdp_with_data.append(kSdpSctpDataChannelString); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2561 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2562 | unusual_portstr, strlen(unusual_portstr), |
| 2563 | &sdp_with_data); |
| 2564 | JsepSessionDescription jdesc_output(kDummyString); |
| 2565 | |
| 2566 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2567 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2568 | |
| 2569 | // We need to test the deserialized JsepSessionDescription from |
| 2570 | // kSdpSctpDataChannelStringWithSctpPort for |
| 2571 | // draft-ietf-mmusic-sctp-sdp-07 |
| 2572 | // a=sctp-port |
| 2573 | sdp_with_data = kSdpString; |
| 2574 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2575 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
| 2576 | unusual_portstr, strlen(unusual_portstr), |
| 2577 | &sdp_with_data); |
| 2578 | |
| 2579 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2580 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2583 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) { |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2584 | // We want to test that deserializing data content limits bandwidth |
| 2585 | // settings (it should never be greater than the default). |
| 2586 | // This should prevent someone from using unlimited data bandwidth through |
| 2587 | // JS and "breaking the Internet". |
| 2588 | // See: https://code.google.com/p/chromium/issues/detail?id=280726 |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2589 | std::string sdp_with_bandwidth = kSdpString; |
| 2590 | sdp_with_bandwidth.append(kSdpRtpDataChannelString); |
| 2591 | InjectAfter("a=mid:data_content_name\r\n", |
| 2592 | "b=AS:100\r\n", |
| 2593 | &sdp_with_bandwidth); |
| 2594 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2595 | |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2596 | EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2597 | } |
| 2598 | |
| 2599 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { |
| 2600 | AddSctpDataChannel(); |
| 2601 | JsepSessionDescription jdesc(kDummyString); |
| 2602 | DataContentDescription* dcd = static_cast<DataContentDescription*>( |
| 2603 | GetFirstDataContent(&desc_)->description); |
| 2604 | dcd->set_bandwidth(100 * 1000); |
| 2605 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2606 | |
| 2607 | std::string sdp_with_bandwidth = kSdpString; |
| 2608 | sdp_with_bandwidth.append(kSdpSctpDataChannelString); |
| 2609 | InjectAfter("a=mid:data_content_name\r\n", |
| 2610 | "b=AS:100\r\n", |
| 2611 | &sdp_with_bandwidth); |
| 2612 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2613 | |
| 2614 | // SCTP has congestion control, so we shouldn't limit the bandwidth |
| 2615 | // as we do for RTP. |
| 2616 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2617 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 2618 | } |
| 2619 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2620 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { |
| 2621 | TestDeserializeExtmap(true, false); |
| 2622 | } |
| 2623 | |
| 2624 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
| 2625 | TestDeserializeExtmap(false, true); |
| 2626 | } |
| 2627 | |
| 2628 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
| 2629 | TestDeserializeExtmap(true, true); |
| 2630 | } |
| 2631 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2632 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { |
| 2633 | JsepSessionDescription jdesc(kDummyString); |
| 2634 | std::string sdp = kSdpFullString; |
| 2635 | sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. |
| 2636 | // Deserialize |
| 2637 | SdpParseError error; |
| 2638 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2639 | 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] | 2640 | EXPECT_EQ(lastline, error.line); |
| 2641 | EXPECT_EQ("Invalid SDP line.", error.description); |
| 2642 | } |
| 2643 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2644 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 2645 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2646 | std::string new_sdp = kSdpOneCandidate; |
| 2647 | Replace("udp", "unsupported_transport", &new_sdp); |
| 2648 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2649 | new_sdp = kSdpOneCandidate; |
| 2650 | Replace("udp", "uDP", &new_sdp); |
| 2651 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2652 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2653 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2654 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2655 | } |
| 2656 | |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2657 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2658 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2659 | EXPECT_TRUE( |
| 2660 | SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2661 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2662 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2663 | Candidate ref_candidate = jcandidate_->candidate(); |
| 2664 | ref_candidate.set_username("user_rtp"); |
| 2665 | ref_candidate.set_password("password_rtp"); |
| 2666 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 2667 | } |
| 2668 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2669 | TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) { |
| 2670 | JsepSessionDescription jdesc(kDummyString); |
| 2671 | |
| 2672 | // Deserialize |
| 2673 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
| 2674 | |
| 2675 | // Verify |
| 2676 | cricket::AudioContentDescription* audio = |
| 2677 | static_cast<AudioContentDescription*>( |
| 2678 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2679 | EXPECT_TRUE(audio->conference_mode()); |
| 2680 | |
| 2681 | cricket::VideoContentDescription* video = |
| 2682 | static_cast<VideoContentDescription*>( |
| 2683 | jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO)); |
| 2684 | EXPECT_TRUE(video->conference_mode()); |
| 2685 | } |
| 2686 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2687 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 2688 | const char kSdpDestroyer[] = "!@#$%^&"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2689 | const char kSdpEmptyType[] = " =candidate"; |
| 2690 | const char kSdpEqualAsPlus[] = "a+candidate"; |
| 2691 | const char kSdpSpaceAfterEqual[] = "a= candidate"; |
| 2692 | const char kSdpUpperType[] = "A=candidate"; |
| 2693 | const char kSdpEmptyLine[] = ""; |
| 2694 | const char kSdpMissingValue[] = "a="; |
| 2695 | |
| 2696 | const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2697 | "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] | 2698 | const char kSdpExtraField[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2699 | "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] | 2700 | const char kSdpMissingSpace[] = "a=fingerprint:sha-1" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2701 | "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] | 2702 | // MD5 is not allowed in fingerprints. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2703 | const char kSdpMd5[] = "a=fingerprint:md5 " |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2704 | "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] | 2705 | |
| 2706 | // Broken session description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2707 | ExpectParseFailure("v=", kSdpDestroyer); |
| 2708 | ExpectParseFailure("o=", kSdpDestroyer); |
| 2709 | ExpectParseFailure("s=-", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2710 | // Broken time description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2711 | ExpectParseFailure("t=", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2712 | |
| 2713 | // Broken media description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2714 | ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39"); |
| 2715 | ExpectParseFailure("m=video", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2716 | |
| 2717 | // Invalid lines |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2718 | ExpectParseFailure("a=candidate", kSdpEmptyType); |
| 2719 | ExpectParseFailure("a=candidate", kSdpEqualAsPlus); |
| 2720 | ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual); |
| 2721 | ExpectParseFailure("a=candidate", kSdpUpperType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2722 | |
| 2723 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 2724 | // because it's orthogonal to what we are replacing and hence |
| 2725 | // safe. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2726 | ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint); |
| 2727 | ExpectParseFailure("a=sendrecv", kSdpExtraField); |
| 2728 | ExpectParseFailure("a=sendrecv", kSdpMissingSpace); |
| 2729 | ExpectParseFailure("a=sendrecv", kSdpMd5); |
| 2730 | |
| 2731 | // Empty Line |
| 2732 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine); |
| 2733 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) { |
| 2737 | // ssrc |
| 2738 | ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue"); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2739 | 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] | 2740 | // crypto |
| 2741 | ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue "); |
| 2742 | // rtpmap |
| 2743 | ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue "); |
| 2744 | ExpectParseFailure("opus/48000/2", "opus/badvalue/2"); |
| 2745 | ExpectParseFailure("opus/48000/2", "opus/48000/badvalue"); |
| 2746 | // candidate |
| 2747 | ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432"); |
| 2748 | ExpectParseFailure("1 udp 2130706432", "1 udp badvalue"); |
| 2749 | ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue"); |
| 2750 | ExpectParseFailure("rport 2346", "rport badvalue"); |
| 2751 | ExpectParseFailure("rport 2346 generation 2", |
| 2752 | "rport 2346 generation badvalue"); |
| 2753 | // m line |
| 2754 | ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104", |
| 2755 | "m=audio 2345 RTP/SAVPF 111 badvalue 104"); |
| 2756 | |
| 2757 | // bandwidth |
| 2758 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2759 | "b=AS:badvalue\r\n", |
| 2760 | "b=AS:badvalue"); |
| 2761 | // rtcp-fb |
| 2762 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2763 | "a=rtcp-fb:badvalue nack\r\n", |
| 2764 | "a=rtcp-fb:badvalue nack"); |
| 2765 | // extmap |
| 2766 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2767 | "a=extmap:badvalue http://example.com\r\n", |
| 2768 | "a=extmap:badvalue http://example.com"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
| 2772 | JsepSessionDescription jdesc_output(kDummyString); |
| 2773 | |
| 2774 | const char kSdpWithReorderedPlTypesString[] = |
| 2775 | "v=0\r\n" |
| 2776 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2777 | "s=-\r\n" |
| 2778 | "t=0 0\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 2779 | "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] | 2780 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 2781 | // in the map. |
| 2782 | "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] | 2783 | "a=rtpmap:104 ISAC/32000\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2784 | |
| 2785 | // Deserialize |
| 2786 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 2787 | |
| 2788 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description()); |
| 2789 | ASSERT_TRUE(ac != NULL); |
| 2790 | const AudioContentDescription* acd = |
| 2791 | static_cast<const AudioContentDescription*>(ac->description); |
| 2792 | ASSERT_FALSE(acd->codecs().empty()); |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2793 | EXPECT_EQ("ISAC", acd->codecs()[0].name); |
| 2794 | EXPECT_EQ(32000, acd->codecs()[0].clockrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2795 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 2796 | } |
| 2797 | |
| 2798 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
| 2799 | JsepSessionDescription jdesc_output(kDummyString); |
| 2800 | CodecParams params; |
| 2801 | params.max_ptime = 40; |
| 2802 | params.ptime = 30; |
| 2803 | params.min_ptime = 10; |
| 2804 | params.sprop_stereo = 1; |
| 2805 | params.stereo = 1; |
| 2806 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2807 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2808 | TestDeserializeCodecParams(params, &jdesc_output); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2809 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 2813 | const bool kUseWildcard = false; |
| 2814 | JsepSessionDescription jdesc_output(kDummyString); |
| 2815 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2816 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 2820 | const bool kUseWildcard = true; |
| 2821 | JsepSessionDescription jdesc_output(kDummyString); |
| 2822 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2823 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
| 2827 | JsepSessionDescription jdesc_output(kDummyString); |
| 2828 | |
| 2829 | const char kSdpWithFmtpString[] = |
| 2830 | "v=0\r\n" |
| 2831 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2832 | "s=-\r\n" |
| 2833 | "t=0 0\r\n" |
| 2834 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2835 | "a=rtpmap:120 VP8/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2836 | "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n"; |
| 2837 | |
| 2838 | // Deserialize |
| 2839 | SdpParseError error; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 2840 | EXPECT_TRUE( |
| 2841 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2842 | |
| 2843 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2844 | ASSERT_TRUE(vc != NULL); |
| 2845 | const VideoContentDescription* vcd = |
| 2846 | static_cast<const VideoContentDescription*>(vc->description); |
| 2847 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2848 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2849 | EXPECT_EQ("VP8", vp8.name); |
| 2850 | EXPECT_EQ(120, vp8.id); |
| 2851 | cricket::CodecParameterMap::iterator found = |
| 2852 | vp8.params.find("x-google-min-bitrate"); |
| 2853 | ASSERT_TRUE(found != vp8.params.end()); |
| 2854 | EXPECT_EQ(found->second, "10"); |
| 2855 | found = vp8.params.find("x-google-max-quantization"); |
| 2856 | ASSERT_TRUE(found != vp8.params.end()); |
| 2857 | EXPECT_EQ(found->second, "40"); |
| 2858 | } |
| 2859 | |
| 2860 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) { |
| 2861 | JsepSessionDescription jdesc_output(kDummyString); |
| 2862 | |
| 2863 | const char kSdpWithFmtpString[] = |
| 2864 | "v=0\r\n" |
| 2865 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2866 | "s=-\r\n" |
| 2867 | "t=0 0\r\n" |
| 2868 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2869 | "a=rtpmap:120 VP8/90000\r\n" |
| 2870 | "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] | 2871 | |
| 2872 | // Deserialize |
| 2873 | SdpParseError error; |
| 2874 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, |
| 2875 | &error)); |
| 2876 | |
| 2877 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2878 | ASSERT_TRUE(vc != NULL); |
| 2879 | const VideoContentDescription* vcd = |
| 2880 | static_cast<const VideoContentDescription*>(vc->description); |
| 2881 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2882 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2883 | EXPECT_EQ("VP8", vp8.name); |
| 2884 | EXPECT_EQ(120, vp8.id); |
| 2885 | cricket::CodecParameterMap::iterator found = |
| 2886 | vp8.params.find("x-google-min-bitrate"); |
| 2887 | ASSERT_TRUE(found != vp8.params.end()); |
| 2888 | EXPECT_EQ(found->second, "10"); |
| 2889 | found = vp8.params.find("x-google-max-quantization"); |
| 2890 | ASSERT_TRUE(found != vp8.params.end()); |
| 2891 | EXPECT_EQ(found->second, "40"); |
| 2892 | } |
| 2893 | |
| 2894 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
| 2895 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2896 | GetFirstVideoContent(&desc_)->description); |
| 2897 | |
| 2898 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 2899 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 2900 | vcd->set_codecs(codecs); |
| 2901 | |
| 2902 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2903 | jdesc_.session_id(), |
| 2904 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2905 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2906 | std::string sdp_with_fmtp = kSdpFullString; |
| 2907 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
| 2908 | "a=fmtp:120 x-google-min-bitrate=10\r\n", |
| 2909 | &sdp_with_fmtp); |
| 2910 | EXPECT_EQ(sdp_with_fmtp, message); |
| 2911 | } |
| 2912 | |
| 2913 | TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) { |
| 2914 | JsepSessionDescription jdesc_with_icelite(kDummyString); |
| 2915 | std::string sdp_with_icelite = kSdpFullString; |
| 2916 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2917 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 2918 | const cricket::TransportInfo* tinfo1 = |
| 2919 | desc->GetTransportInfoByName("audio_content_name"); |
| 2920 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 2921 | const cricket::TransportInfo* tinfo2 = |
| 2922 | desc->GetTransportInfoByName("video_content_name"); |
| 2923 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
| 2924 | InjectAfter(kSessionTime, |
| 2925 | "a=ice-lite\r\n", |
| 2926 | &sdp_with_icelite); |
| 2927 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2928 | desc = jdesc_with_icelite.description(); |
| 2929 | const cricket::TransportInfo* atinfo = |
| 2930 | desc->GetTransportInfoByName("audio_content_name"); |
| 2931 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 2932 | const cricket::TransportInfo* vtinfo = |
| 2933 | desc->GetTransportInfoByName("video_content_name"); |
| 2934 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
| 2935 | } |
| 2936 | |
| 2937 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 2938 | // correctly in the output SDP. |
| 2939 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 2940 | std::string sdp_with_data = kSdpString; |
| 2941 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
| 2942 | JsepSessionDescription jdesc_output(kDummyString); |
| 2943 | |
| 2944 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2945 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2946 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2947 | |
| 2948 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 2949 | AddFingerprint(); |
| 2950 | TransportInfo audio_transport_info = |
| 2951 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 2952 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2953 | audio_transport_info.description.connection_role); |
| 2954 | audio_transport_info.description.connection_role = |
| 2955 | cricket::CONNECTIONROLE_ACTIVE; |
| 2956 | |
| 2957 | TransportInfo video_transport_info = |
| 2958 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 2959 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2960 | video_transport_info.description.connection_role); |
| 2961 | video_transport_info.description.connection_role = |
| 2962 | cricket::CONNECTIONROLE_ACTIVE; |
| 2963 | |
| 2964 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 2965 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 2966 | |
| 2967 | desc_.AddTransportInfo(audio_transport_info); |
| 2968 | desc_.AddTransportInfo(video_transport_info); |
| 2969 | |
| 2970 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2971 | jdesc_.session_id(), |
| 2972 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2973 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2974 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 2975 | |
| 2976 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
| 2977 | InjectAfter(kAttributeIcePwdVoice, |
| 2978 | kFingerprint, &sdp_with_dtlssetup); |
| 2979 | InjectAfter(kAttributeIcePwdVideo, |
| 2980 | kFingerprint, &sdp_with_dtlssetup); |
| 2981 | // Now adding |setup| attribute. |
| 2982 | InjectAfter(kFingerprint, |
| 2983 | "a=setup:active\r\n", &sdp_with_dtlssetup); |
| 2984 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 2985 | } |
| 2986 | |
| 2987 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) { |
| 2988 | JsepSessionDescription jdesc_with_dtlssetup(kDummyString); |
| 2989 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 2990 | InjectAfter(kSessionTime, |
| 2991 | "a=setup:actpass\r\n", |
| 2992 | &sdp_with_dtlssetup); |
| 2993 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 2994 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 2995 | const cricket::TransportInfo* atinfo = |
| 2996 | desc->GetTransportInfoByName("audio_content_name"); |
| 2997 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 2998 | atinfo->description.connection_role); |
| 2999 | const cricket::TransportInfo* vtinfo = |
| 3000 | desc->GetTransportInfoByName("video_content_name"); |
| 3001 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3002 | vtinfo->description.connection_role); |
| 3003 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3004 | |
| 3005 | // Verifies that the order of the serialized m-lines follows the order of the |
| 3006 | // ContentInfo in SessionDescription, and vise versa for deserialization. |
| 3007 | TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) { |
| 3008 | JsepSessionDescription jdesc(kDummyString); |
| 3009 | const std::string media_content_sdps[3] = { |
| 3010 | kSdpAudioString, |
| 3011 | kSdpVideoString, |
| 3012 | kSdpSctpDataChannelString |
| 3013 | }; |
| 3014 | const cricket::MediaType media_types[3] = { |
| 3015 | cricket::MEDIA_TYPE_AUDIO, |
| 3016 | cricket::MEDIA_TYPE_VIDEO, |
| 3017 | cricket::MEDIA_TYPE_DATA |
| 3018 | }; |
| 3019 | |
| 3020 | // Verifies all 6 permutations. |
| 3021 | for (size_t i = 0; i < 6; ++i) { |
| 3022 | size_t media_content_in_sdp[3]; |
| 3023 | // The index of the first media content. |
| 3024 | media_content_in_sdp[0] = i / 2; |
| 3025 | // The index of the second media content. |
| 3026 | media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3; |
| 3027 | // The index of the third media content. |
| 3028 | media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3; |
| 3029 | |
| 3030 | std::string sdp_string = kSdpSessionString; |
| 3031 | for (size_t i = 0; i < 3; ++i) |
| 3032 | sdp_string += media_content_sdps[media_content_in_sdp[i]]; |
| 3033 | |
| 3034 | EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc)); |
| 3035 | cricket::SessionDescription* desc = jdesc.description(); |
| 3036 | EXPECT_EQ(3u, desc->contents().size()); |
| 3037 | |
| 3038 | for (size_t i = 0; i < 3; ++i) { |
| 3039 | const cricket::MediaContentDescription* mdesc = |
| 3040 | static_cast<const cricket::MediaContentDescription*>( |
| 3041 | desc->contents()[i].description); |
| 3042 | EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 3043 | } |
| 3044 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3045 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3046 | EXPECT_EQ(sdp_string, serialized_sdp); |
| 3047 | } |
| 3048 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3049 | |
| 3050 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) { |
| 3051 | MakePlanBDescription(); |
| 3052 | |
| 3053 | JsepSessionDescription deserialized_description(kDummyString); |
| 3054 | EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description)); |
| 3055 | |
| 3056 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3057 | } |
| 3058 | |
| 3059 | TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) { |
| 3060 | MakePlanBDescription(); |
| 3061 | TestSerialize(jdesc_, false); |
| 3062 | } |
| 3063 | |
Taylor Brandstetter | 5de6b75 | 2016-03-09 17:02:30 -0800 | [diff] [blame^] | 3064 | // Some WebRTC endpoints include the msid in both the Plan B and Unified Plan |
| 3065 | // ways, to make SDP that's compatible with both Plan B and Unified Plan (to |
| 3066 | // some extent). If we parse this, the Plan B msid attribute (which is more |
| 3067 | // specific, since it's at the SSRC level) should take priority. |
| 3068 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) { |
| 3069 | MakePlanBDescription(); |
| 3070 | |
| 3071 | JsepSessionDescription deserialized_description(kDummyString); |
| 3072 | EXPECT_TRUE( |
| 3073 | SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description)); |
| 3074 | |
| 3075 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3076 | } |
| 3077 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3078 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) { |
| 3079 | MakeUnifiedPlanDescription(); |
| 3080 | |
| 3081 | JsepSessionDescription deserialized_description(kDummyString); |
| 3082 | EXPECT_TRUE( |
| 3083 | SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); |
| 3084 | |
| 3085 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3086 | } |
| 3087 | |
| 3088 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { |
| 3089 | MakeUnifiedPlanDescription(); |
| 3090 | TestSerialize(jdesc_, true); |
| 3091 | } |