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