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. |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 399 | static const char kSdpOneCandidateWithUfragPwd[] = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name" |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 401 | " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 1730 | |
| 1731 | Candidate candidate_with_ufrag(candidates_.front()); |
| 1732 | candidate_with_ufrag.set_username("ABC"); |
| 1733 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, |
| 1734 | candidate_with_ufrag)); |
| 1735 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 1736 | EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 1739 | // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing |
| 1740 | // RFC 6544. |
mallinath@webrtc.org | e999bd0 | 2014-08-13 06:05:55 +0000 | [diff] [blame] | 1741 | TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 1742 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1743 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 1744 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 1745 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 1746 | candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
| 1747 | rtc::scoped_ptr<IceCandidateInterface> jcandidate( |
| 1748 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
| 1749 | |
| 1750 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
| 1751 | EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
| 1752 | } |
| 1753 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1754 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
| 1755 | JsepSessionDescription jdesc(kDummyString); |
| 1756 | // Deserialize |
| 1757 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 1758 | // Verify |
| 1759 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 1760 | } |
| 1761 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1762 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) { |
| 1763 | JsepSessionDescription jdesc(kDummyString); |
| 1764 | const char kSdpWithoutMline[] = |
| 1765 | "v=0\r\n" |
| 1766 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1767 | "s=-\r\n" |
| 1768 | "t=0 0\r\n" |
| 1769 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"; |
| 1770 | // Deserialize |
| 1771 | EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc)); |
| 1772 | EXPECT_EQ(0u, jdesc.description()->contents().size()); |
| 1773 | } |
| 1774 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1775 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
| 1776 | JsepSessionDescription jdesc(kDummyString); |
| 1777 | std::string sdp_without_carriage_return = kSdpFullString; |
| 1778 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 1779 | // Deserialize |
| 1780 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 1781 | // Verify |
| 1782 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 1783 | } |
| 1784 | |
| 1785 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 1786 | // SessionDescription with desc but without candidates. |
| 1787 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1788 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), |
| 1789 | kSessionId, kSessionVersion)); |
| 1790 | JsepSessionDescription new_jdesc(kDummyString); |
| 1791 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 1792 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 1793 | } |
| 1794 | |
| 1795 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 1796 | static const char kSdpNoRtpmapString[] = |
| 1797 | "v=0\r\n" |
| 1798 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 1799 | "s=-\r\n" |
| 1800 | "t=0 0\r\n" |
| 1801 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 1802 | // 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] | 1803 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1804 | // The rtpmap line for static payload codec is optional. |
| 1805 | "a=rtpmap:18 G729/16000\r\n" |
| 1806 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 1807 | |
| 1808 | JsepSessionDescription jdesc(kDummyString); |
| 1809 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 1810 | cricket::AudioContentDescription* audio = |
| 1811 | static_cast<AudioContentDescription*>( |
| 1812 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 1813 | AudioCodecs ref_codecs; |
| 1814 | // The codecs in the AudioContentDescription will be sorted by preference. |
| 1815 | ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3)); |
| 1816 | ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2)); |
| 1817 | ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1)); |
| 1818 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 1819 | } |
| 1820 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1821 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) { |
| 1822 | static const char kSdpNoRtpmapString[] = |
| 1823 | "v=0\r\n" |
| 1824 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 1825 | "s=-\r\n" |
| 1826 | "t=0 0\r\n" |
| 1827 | "m=audio 49232 RTP/AVP 18 103\r\n" |
| 1828 | "a=fmtp:18 annexb=yes\r\n" |
| 1829 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 1830 | |
| 1831 | JsepSessionDescription jdesc(kDummyString); |
| 1832 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 1833 | cricket::AudioContentDescription* audio = |
| 1834 | static_cast<AudioContentDescription*>( |
| 1835 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 1836 | |
| 1837 | cricket::AudioCodec g729 = audio->codecs()[0]; |
| 1838 | EXPECT_EQ("G729", g729.name); |
| 1839 | EXPECT_EQ(8000, g729.clockrate); |
| 1840 | EXPECT_EQ(18, g729.id); |
| 1841 | cricket::CodecParameterMap::iterator found = |
| 1842 | g729.params.find("annexb"); |
| 1843 | ASSERT_TRUE(found != g729.params.end()); |
| 1844 | EXPECT_EQ(found->second, "yes"); |
| 1845 | |
| 1846 | cricket::AudioCodec isac = audio->codecs()[1]; |
| 1847 | EXPECT_EQ("ISAC", isac.name); |
| 1848 | EXPECT_EQ(103, isac.id); |
| 1849 | EXPECT_EQ(16000, isac.clockrate); |
| 1850 | } |
| 1851 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1852 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 1853 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 1854 | // Add a DTLS a=fingerprint attribute to our session description. |
| 1855 | AddFingerprint(); |
| 1856 | JsepSessionDescription new_jdesc(kDummyString); |
| 1857 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 1858 | jdesc_.session_id(), |
| 1859 | jdesc_.session_version())); |
| 1860 | |
| 1861 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1862 | std::string sdp_with_fingerprint = kSdpString; |
| 1863 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 1864 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 1865 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 1866 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 1867 | } |
| 1868 | |
| 1869 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
| 1870 | JsepSessionDescription jdesc_with_bundle(kDummyString); |
| 1871 | std::string sdp_with_bundle = kSdpFullString; |
| 1872 | InjectAfter(kSessionTime, |
| 1873 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 1874 | &sdp_with_bundle); |
| 1875 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 1876 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1877 | group.AddContentName(kAudioContentName); |
| 1878 | group.AddContentName(kVideoContentName); |
| 1879 | desc_.AddGroup(group); |
| 1880 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1881 | jdesc_.session_id(), |
| 1882 | jdesc_.session_version())); |
| 1883 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 1884 | } |
| 1885 | |
| 1886 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
| 1887 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 1888 | std::string sdp_with_bandwidth = kSdpFullString; |
| 1889 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 1890 | "b=AS:100\r\n", |
| 1891 | &sdp_with_bandwidth); |
| 1892 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 1893 | "b=AS:50\r\n", |
| 1894 | &sdp_with_bandwidth); |
| 1895 | EXPECT_TRUE( |
| 1896 | SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 1897 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 1898 | GetFirstVideoContent(&desc_)->description); |
| 1899 | vcd->set_bandwidth(100 * 1000); |
| 1900 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 1901 | GetFirstAudioContent(&desc_)->description); |
| 1902 | acd->set_bandwidth(50 * 1000); |
| 1903 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1904 | jdesc_.session_id(), |
| 1905 | jdesc_.session_version())); |
| 1906 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 1907 | } |
| 1908 | |
| 1909 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
| 1910 | JsepSessionDescription jdesc_with_ice_options(kDummyString); |
| 1911 | std::string sdp_with_ice_options = kSdpFullString; |
| 1912 | InjectAfter(kSessionTime, |
| 1913 | "a=ice-options:iceoption3\r\n", |
| 1914 | &sdp_with_ice_options); |
| 1915 | InjectAfter(kAttributeIcePwdVoice, |
| 1916 | "a=ice-options:iceoption1\r\n", |
| 1917 | &sdp_with_ice_options); |
| 1918 | InjectAfter(kAttributeIcePwdVideo, |
| 1919 | "a=ice-options:iceoption2\r\n", |
| 1920 | &sdp_with_ice_options); |
| 1921 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 1922 | std::vector<std::string> transport_options; |
| 1923 | transport_options.push_back(kIceOption3); |
| 1924 | transport_options.push_back(kIceOption1); |
| 1925 | AddIceOptions(kAudioContentName, transport_options); |
| 1926 | transport_options.clear(); |
| 1927 | transport_options.push_back(kIceOption3); |
| 1928 | transport_options.push_back(kIceOption2); |
| 1929 | AddIceOptions(kVideoContentName, transport_options); |
| 1930 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1931 | jdesc_.session_id(), |
| 1932 | jdesc_.session_version())); |
| 1933 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 1934 | } |
| 1935 | |
| 1936 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 1937 | // Remove the original ice-ufrag and ice-pwd |
| 1938 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString); |
| 1939 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 1940 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 1941 | // Add session level ufrag and pwd |
| 1942 | InjectAfter(kSessionTime, |
| 1943 | "a=ice-pwd:session+level+icepwd\r\n" |
| 1944 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 1945 | &sdp_with_ufrag_pwd); |
| 1946 | // Add media level ufrag and pwd for audio |
| 1947 | InjectAfter("a=mid:audio_content_name\r\n", |
| 1948 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 1949 | &sdp_with_ufrag_pwd); |
| 1950 | // Update the candidate ufrag and pwd to the expected ones. |
| 1951 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, |
| 1952 | "media+level+iceufrag", "media+level+icepwd")); |
| 1953 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, |
| 1954 | "session+level+iceufrag", "session+level+icepwd")); |
| 1955 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 1956 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 1957 | } |
| 1958 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1959 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
| 1960 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY)); |
| 1961 | } |
| 1962 | |
| 1963 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
| 1964 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY)); |
| 1965 | } |
| 1966 | |
| 1967 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
| 1968 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE)); |
| 1969 | } |
| 1970 | |
| 1971 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 1972 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 1973 | } |
| 1974 | |
| 1975 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 1976 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 1977 | } |
| 1978 | |
| 1979 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 1980 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 1981 | } |
| 1982 | |
| 1983 | // Tests that we can still handle the sdp uses mslabel and label instead of |
| 1984 | // msid for backward compatibility. |
| 1985 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1986 | jdesc_.description()->set_msid_supported(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1987 | JsepSessionDescription jdesc(kDummyString); |
| 1988 | std::string sdp_without_msid = kSdpFullString; |
| 1989 | Replace("msid", "xmsid", &sdp_without_msid); |
| 1990 | // Deserialize |
| 1991 | EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc)); |
| 1992 | // Verify |
| 1993 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 1994 | } |
| 1995 | |
| 1996 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 1997 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 1998 | |
| 1999 | std::string sdp = kSdpOneCandidate; |
| 2000 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2001 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2002 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2003 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2004 | |
| 2005 | // Candidate line without generation extension. |
| 2006 | sdp = kSdpOneCandidate; |
| 2007 | Replace(" generation 2", "", &sdp); |
| 2008 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2009 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2010 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2011 | Candidate expected = jcandidate_->candidate(); |
| 2012 | expected.set_generation(0); |
| 2013 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2014 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2015 | sdp = kSdpTcpActiveCandidate; |
| 2016 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2017 | // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2018 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2019 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2020 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2021 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2022 | rtc::scoped_ptr<IceCandidateInterface> jcandidate_template( |
| 2023 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
| 2024 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent( |
| 2025 | jcandidate_template->candidate())); |
| 2026 | sdp = kSdpTcpPassiveCandidate; |
| 2027 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2028 | sdp = kSdpTcpSOCandidate; |
| 2029 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | // This test verifies the deserialization of candidate-attribute |
| 2033 | // as per RFC 5245. Candiate-attribute will be of the format |
| 2034 | // candidate:<blah>. This format will be used when candidates |
| 2035 | // are trickled. |
| 2036 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 2037 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2038 | |
| 2039 | std::string candidate_attribute = kRawCandidate; |
| 2040 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2041 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2042 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2043 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2044 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 2045 | |
| 2046 | // Candidate line without generation extension. |
| 2047 | candidate_attribute = kRawCandidate; |
| 2048 | Replace(" generation 2", "", &candidate_attribute); |
| 2049 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2050 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2051 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2052 | Candidate expected = jcandidate_->candidate(); |
| 2053 | expected.set_generation(0); |
| 2054 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2055 | |
| 2056 | // Candidate line without candidate: |
| 2057 | candidate_attribute = kRawCandidate; |
| 2058 | Replace("candidate:", "", &candidate_attribute); |
| 2059 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2060 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2061 | // Candidate line with IPV6 address. |
| 2062 | EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate)); |
| 2063 | } |
| 2064 | |
| 2065 | // This test verifies that the deserialization of an invalid candidate string |
| 2066 | // fails. |
| 2067 | TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) { |
| 2068 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2069 | |
| 2070 | std::string candidate_attribute = kRawCandidate; |
| 2071 | candidate_attribute.replace(0, 1, "x"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2072 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2073 | |
| 2074 | candidate_attribute = kSdpOneCandidate; |
| 2075 | candidate_attribute.replace(0, 1, "x"); |
| 2076 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2077 | |
| 2078 | candidate_attribute = kRawCandidate; |
| 2079 | candidate_attribute.append("\r\n"); |
| 2080 | candidate_attribute.append(kRawCandidate); |
| 2081 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2082 | |
| 2083 | EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) { |
| 2087 | AddRtpDataChannel(); |
| 2088 | JsepSessionDescription jdesc(kDummyString); |
| 2089 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2090 | |
| 2091 | std::string sdp_with_data = kSdpString; |
| 2092 | sdp_with_data.append(kSdpRtpDataChannelString); |
| 2093 | JsepSessionDescription jdesc_output(kDummyString); |
| 2094 | |
| 2095 | // Deserialize |
| 2096 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2097 | // Verify |
| 2098 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2099 | } |
| 2100 | |
| 2101 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
| 2102 | AddSctpDataChannel(); |
| 2103 | JsepSessionDescription jdesc(kDummyString); |
| 2104 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2105 | |
| 2106 | std::string sdp_with_data = kSdpString; |
| 2107 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2108 | JsepSessionDescription jdesc_output(kDummyString); |
| 2109 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2110 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString). |
| 2111 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2112 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2113 | |
| 2114 | // Verify with UDP/DTLS/SCTP. |
| 2115 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2116 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2117 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2118 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2119 | |
| 2120 | // Verify with TCP/DTLS/SCTP. |
| 2121 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2122 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2123 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2124 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2125 | } |
| 2126 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2127 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { |
| 2128 | AddSctpDataChannel(); |
| 2129 | JsepSessionDescription jdesc(kDummyString); |
| 2130 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2131 | |
| 2132 | std::string sdp_with_data = kSdpString; |
| 2133 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2134 | JsepSessionDescription jdesc_output(kDummyString); |
| 2135 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2136 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort). |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2137 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2138 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2139 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2140 | // Verify with UDP/DTLS/SCTP. |
| 2141 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2142 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2143 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2144 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2145 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2146 | // Verify with TCP/DTLS/SCTP. |
| 2147 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2148 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2149 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2150 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2151 | } |
| 2152 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 2153 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { |
| 2154 | AddSctpDataChannel(); |
| 2155 | JsepSessionDescription jdesc(kDummyString); |
| 2156 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2157 | |
| 2158 | std::string sdp_with_data = kSdpString; |
| 2159 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
| 2160 | JsepSessionDescription jdesc_output(kDummyString); |
| 2161 | |
| 2162 | // Verify with DTLS/SCTP. |
| 2163 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2164 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2165 | |
| 2166 | // Verify with UDP/DTLS/SCTP. |
| 2167 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2168 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2169 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2170 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2171 | |
| 2172 | // Verify with TCP/DTLS/SCTP. |
| 2173 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2174 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
| 2175 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2176 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2177 | } |
| 2178 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2179 | // Test to check the behaviour if sctp-port is specified |
| 2180 | // on the m= line and in a=sctp-port. |
| 2181 | TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { |
| 2182 | AddSctpDataChannel(); |
| 2183 | JsepSessionDescription jdesc(kDummyString); |
| 2184 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2185 | |
| 2186 | std::string sdp_with_data = kSdpString; |
| 2187 | // Append m= attributes |
| 2188 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2189 | // Append a=sctp-port attribute |
| 2190 | sdp_with_data.append("a=sctp-port 5000\r\n"); |
| 2191 | JsepSessionDescription jdesc_output(kDummyString); |
| 2192 | |
| 2193 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2194 | } |
| 2195 | |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 +0000 | [diff] [blame] | 2196 | // For crbug/344475. |
| 2197 | TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { |
| 2198 | std::string sdp_with_data = kSdpString; |
| 2199 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2200 | // Remove the "\n" at the end. |
| 2201 | sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); |
| 2202 | JsepSessionDescription jdesc_output(kDummyString); |
| 2203 | |
| 2204 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2205 | // No crash is a pass. |
| 2206 | } |
| 2207 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2208 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) { |
| 2209 | AddSctpDataChannel(); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2210 | const uint16_t kUnusualSctpPort = 9556; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2211 | char default_portstr[16]; |
| 2212 | char unusual_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2213 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2214 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2215 | rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2216 | kUnusualSctpPort); |
| 2217 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2218 | // First setup the expected JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2219 | JsepSessionDescription jdesc(kDummyString); |
| 2220 | // take our pre-built session description and change the SCTP port. |
| 2221 | cricket::SessionDescription* mutant = desc_.Copy(); |
| 2222 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 2223 | mutant->GetContentDescriptionByName(kDataContentName)); |
| 2224 | std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 2225 | EXPECT_EQ(1U, codecs.size()); |
| 2226 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, codecs[0].id); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2227 | codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2228 | dcdesc->set_codecs(codecs); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2229 | |
| 2230 | // note: mutant's owned by jdesc now. |
| 2231 | ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion)); |
| 2232 | mutant = NULL; |
| 2233 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2234 | // Then get the deserialized JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2235 | std::string sdp_with_data = kSdpString; |
| 2236 | sdp_with_data.append(kSdpSctpDataChannelString); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2237 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2238 | unusual_portstr, strlen(unusual_portstr), |
| 2239 | &sdp_with_data); |
| 2240 | JsepSessionDescription jdesc_output(kDummyString); |
| 2241 | |
| 2242 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2243 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2244 | |
| 2245 | // We need to test the deserialized JsepSessionDescription from |
| 2246 | // kSdpSctpDataChannelStringWithSctpPort for |
| 2247 | // draft-ietf-mmusic-sctp-sdp-07 |
| 2248 | // a=sctp-port |
| 2249 | sdp_with_data = kSdpString; |
| 2250 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2251 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
| 2252 | unusual_portstr, strlen(unusual_portstr), |
| 2253 | &sdp_with_data); |
| 2254 | |
| 2255 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2256 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2259 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) { |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2260 | // We want to test that deserializing data content limits bandwidth |
| 2261 | // settings (it should never be greater than the default). |
| 2262 | // This should prevent someone from using unlimited data bandwidth through |
| 2263 | // JS and "breaking the Internet". |
| 2264 | // See: https://code.google.com/p/chromium/issues/detail?id=280726 |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2265 | std::string sdp_with_bandwidth = kSdpString; |
| 2266 | sdp_with_bandwidth.append(kSdpRtpDataChannelString); |
| 2267 | InjectAfter("a=mid:data_content_name\r\n", |
| 2268 | "b=AS:100\r\n", |
| 2269 | &sdp_with_bandwidth); |
| 2270 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2271 | |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2272 | EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2273 | } |
| 2274 | |
| 2275 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { |
| 2276 | AddSctpDataChannel(); |
| 2277 | JsepSessionDescription jdesc(kDummyString); |
| 2278 | DataContentDescription* dcd = static_cast<DataContentDescription*>( |
| 2279 | GetFirstDataContent(&desc_)->description); |
| 2280 | dcd->set_bandwidth(100 * 1000); |
| 2281 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2282 | |
| 2283 | std::string sdp_with_bandwidth = kSdpString; |
| 2284 | sdp_with_bandwidth.append(kSdpSctpDataChannelString); |
| 2285 | InjectAfter("a=mid:data_content_name\r\n", |
| 2286 | "b=AS:100\r\n", |
| 2287 | &sdp_with_bandwidth); |
| 2288 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2289 | |
| 2290 | // SCTP has congestion control, so we shouldn't limit the bandwidth |
| 2291 | // as we do for RTP. |
| 2292 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2293 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 2294 | } |
| 2295 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2296 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { |
| 2297 | TestDeserializeExtmap(true, false); |
| 2298 | } |
| 2299 | |
| 2300 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
| 2301 | TestDeserializeExtmap(false, true); |
| 2302 | } |
| 2303 | |
| 2304 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
| 2305 | TestDeserializeExtmap(true, true); |
| 2306 | } |
| 2307 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2308 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { |
| 2309 | JsepSessionDescription jdesc(kDummyString); |
| 2310 | std::string sdp = kSdpFullString; |
| 2311 | sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. |
| 2312 | // Deserialize |
| 2313 | SdpParseError error; |
| 2314 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); |
| 2315 | const std::string lastline = "a=ssrc:6 label:video_track_id_3"; |
| 2316 | EXPECT_EQ(lastline, error.line); |
| 2317 | EXPECT_EQ("Invalid SDP line.", error.description); |
| 2318 | } |
| 2319 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2320 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 2321 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2322 | std::string new_sdp = kSdpOneCandidate; |
| 2323 | Replace("udp", "unsupported_transport", &new_sdp); |
| 2324 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2325 | new_sdp = kSdpOneCandidate; |
| 2326 | Replace("udp", "uDP", &new_sdp); |
| 2327 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2328 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2329 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2330 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2331 | } |
| 2332 | |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2333 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2334 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2335 | EXPECT_TRUE( |
| 2336 | SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2337 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2338 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2339 | Candidate ref_candidate = jcandidate_->candidate(); |
| 2340 | ref_candidate.set_username("user_rtp"); |
| 2341 | ref_candidate.set_password("password_rtp"); |
| 2342 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 2343 | } |
| 2344 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2345 | TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) { |
| 2346 | JsepSessionDescription jdesc(kDummyString); |
| 2347 | |
| 2348 | // Deserialize |
| 2349 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
| 2350 | |
| 2351 | // Verify |
| 2352 | cricket::AudioContentDescription* audio = |
| 2353 | static_cast<AudioContentDescription*>( |
| 2354 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2355 | EXPECT_TRUE(audio->conference_mode()); |
| 2356 | |
| 2357 | cricket::VideoContentDescription* video = |
| 2358 | static_cast<VideoContentDescription*>( |
| 2359 | jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO)); |
| 2360 | EXPECT_TRUE(video->conference_mode()); |
| 2361 | } |
| 2362 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2363 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 2364 | const char kSdpDestroyer[] = "!@#$%^&"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2365 | const char kSdpEmptyType[] = " =candidate"; |
| 2366 | const char kSdpEqualAsPlus[] = "a+candidate"; |
| 2367 | const char kSdpSpaceAfterEqual[] = "a= candidate"; |
| 2368 | const char kSdpUpperType[] = "A=candidate"; |
| 2369 | const char kSdpEmptyLine[] = ""; |
| 2370 | const char kSdpMissingValue[] = "a="; |
| 2371 | |
| 2372 | const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2373 | "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] | 2374 | const char kSdpExtraField[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2375 | "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] | 2376 | const char kSdpMissingSpace[] = "a=fingerprint:sha-1" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2377 | "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] | 2378 | // MD5 is not allowed in fingerprints. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2379 | const char kSdpMd5[] = "a=fingerprint:md5 " |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2380 | "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] | 2381 | |
| 2382 | // Broken session description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2383 | ExpectParseFailure("v=", kSdpDestroyer); |
| 2384 | ExpectParseFailure("o=", kSdpDestroyer); |
| 2385 | ExpectParseFailure("s=-", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2386 | // Broken time description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2387 | ExpectParseFailure("t=", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2388 | |
| 2389 | // Broken media description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2390 | ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39"); |
| 2391 | ExpectParseFailure("m=video", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2392 | |
| 2393 | // Invalid lines |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2394 | ExpectParseFailure("a=candidate", kSdpEmptyType); |
| 2395 | ExpectParseFailure("a=candidate", kSdpEqualAsPlus); |
| 2396 | ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual); |
| 2397 | ExpectParseFailure("a=candidate", kSdpUpperType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2398 | |
| 2399 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 2400 | // because it's orthogonal to what we are replacing and hence |
| 2401 | // safe. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2402 | ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint); |
| 2403 | ExpectParseFailure("a=sendrecv", kSdpExtraField); |
| 2404 | ExpectParseFailure("a=sendrecv", kSdpMissingSpace); |
| 2405 | ExpectParseFailure("a=sendrecv", kSdpMd5); |
| 2406 | |
| 2407 | // Empty Line |
| 2408 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine); |
| 2409 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) { |
| 2413 | // ssrc |
| 2414 | ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue"); |
| 2415 | ExpectParseFailure("a=ssrc-group:FEC 5 6", "a=ssrc-group:FEC badvalue 6"); |
| 2416 | // crypto |
| 2417 | ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue "); |
| 2418 | // rtpmap |
| 2419 | ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue "); |
| 2420 | ExpectParseFailure("opus/48000/2", "opus/badvalue/2"); |
| 2421 | ExpectParseFailure("opus/48000/2", "opus/48000/badvalue"); |
| 2422 | // candidate |
| 2423 | ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432"); |
| 2424 | ExpectParseFailure("1 udp 2130706432", "1 udp badvalue"); |
| 2425 | ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue"); |
| 2426 | ExpectParseFailure("rport 2346", "rport badvalue"); |
| 2427 | ExpectParseFailure("rport 2346 generation 2", |
| 2428 | "rport 2346 generation badvalue"); |
| 2429 | // m line |
| 2430 | ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104", |
| 2431 | "m=audio 2345 RTP/SAVPF 111 badvalue 104"); |
| 2432 | |
| 2433 | // bandwidth |
| 2434 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2435 | "b=AS:badvalue\r\n", |
| 2436 | "b=AS:badvalue"); |
| 2437 | // rtcp-fb |
| 2438 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2439 | "a=rtcp-fb:badvalue nack\r\n", |
| 2440 | "a=rtcp-fb:badvalue nack"); |
| 2441 | // extmap |
| 2442 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2443 | "a=extmap:badvalue http://example.com\r\n", |
| 2444 | "a=extmap:badvalue http://example.com"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
| 2448 | JsepSessionDescription jdesc_output(kDummyString); |
| 2449 | |
| 2450 | const char kSdpWithReorderedPlTypesString[] = |
| 2451 | "v=0\r\n" |
| 2452 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2453 | "s=-\r\n" |
| 2454 | "t=0 0\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 2455 | "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] | 2456 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 2457 | // in the map. |
| 2458 | "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] | 2459 | "a=rtpmap:104 ISAC/32000\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2460 | |
| 2461 | // Deserialize |
| 2462 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 2463 | |
| 2464 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description()); |
| 2465 | ASSERT_TRUE(ac != NULL); |
| 2466 | const AudioContentDescription* acd = |
| 2467 | static_cast<const AudioContentDescription*>(ac->description); |
| 2468 | ASSERT_FALSE(acd->codecs().empty()); |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2469 | EXPECT_EQ("ISAC", acd->codecs()[0].name); |
| 2470 | EXPECT_EQ(32000, acd->codecs()[0].clockrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2471 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 2472 | } |
| 2473 | |
| 2474 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
| 2475 | JsepSessionDescription jdesc_output(kDummyString); |
| 2476 | CodecParams params; |
| 2477 | params.max_ptime = 40; |
| 2478 | params.ptime = 30; |
| 2479 | params.min_ptime = 10; |
| 2480 | params.sprop_stereo = 1; |
| 2481 | params.stereo = 1; |
| 2482 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2483 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2484 | TestDeserializeCodecParams(params, &jdesc_output); |
| 2485 | TestSerialize(jdesc_output); |
| 2486 | } |
| 2487 | |
| 2488 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 2489 | const bool kUseWildcard = false; |
| 2490 | JsepSessionDescription jdesc_output(kDummyString); |
| 2491 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
| 2492 | TestSerialize(jdesc_output); |
| 2493 | } |
| 2494 | |
| 2495 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 2496 | const bool kUseWildcard = true; |
| 2497 | JsepSessionDescription jdesc_output(kDummyString); |
| 2498 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
| 2499 | TestSerialize(jdesc_output); |
| 2500 | } |
| 2501 | |
| 2502 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
| 2503 | JsepSessionDescription jdesc_output(kDummyString); |
| 2504 | |
| 2505 | const char kSdpWithFmtpString[] = |
| 2506 | "v=0\r\n" |
| 2507 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2508 | "s=-\r\n" |
| 2509 | "t=0 0\r\n" |
| 2510 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2511 | "a=rtpmap:120 VP8/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2512 | "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n"; |
| 2513 | |
| 2514 | // Deserialize |
| 2515 | SdpParseError error; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 2516 | EXPECT_TRUE( |
| 2517 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2518 | |
| 2519 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2520 | ASSERT_TRUE(vc != NULL); |
| 2521 | const VideoContentDescription* vcd = |
| 2522 | static_cast<const VideoContentDescription*>(vc->description); |
| 2523 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2524 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2525 | EXPECT_EQ("VP8", vp8.name); |
| 2526 | EXPECT_EQ(120, vp8.id); |
| 2527 | cricket::CodecParameterMap::iterator found = |
| 2528 | vp8.params.find("x-google-min-bitrate"); |
| 2529 | ASSERT_TRUE(found != vp8.params.end()); |
| 2530 | EXPECT_EQ(found->second, "10"); |
| 2531 | found = vp8.params.find("x-google-max-quantization"); |
| 2532 | ASSERT_TRUE(found != vp8.params.end()); |
| 2533 | EXPECT_EQ(found->second, "40"); |
| 2534 | } |
| 2535 | |
| 2536 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) { |
| 2537 | JsepSessionDescription jdesc_output(kDummyString); |
| 2538 | |
| 2539 | const char kSdpWithFmtpString[] = |
| 2540 | "v=0\r\n" |
| 2541 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2542 | "s=-\r\n" |
| 2543 | "t=0 0\r\n" |
| 2544 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2545 | "a=rtpmap:120 VP8/90000\r\n" |
| 2546 | "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] | 2547 | |
| 2548 | // Deserialize |
| 2549 | SdpParseError error; |
| 2550 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, |
| 2551 | &error)); |
| 2552 | |
| 2553 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2554 | ASSERT_TRUE(vc != NULL); |
| 2555 | const VideoContentDescription* vcd = |
| 2556 | static_cast<const VideoContentDescription*>(vc->description); |
| 2557 | ASSERT_FALSE(vcd->codecs().empty()); |
| 2558 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 2559 | EXPECT_EQ("VP8", vp8.name); |
| 2560 | EXPECT_EQ(120, vp8.id); |
| 2561 | cricket::CodecParameterMap::iterator found = |
| 2562 | vp8.params.find("x-google-min-bitrate"); |
| 2563 | ASSERT_TRUE(found != vp8.params.end()); |
| 2564 | EXPECT_EQ(found->second, "10"); |
| 2565 | found = vp8.params.find("x-google-max-quantization"); |
| 2566 | ASSERT_TRUE(found != vp8.params.end()); |
| 2567 | EXPECT_EQ(found->second, "40"); |
| 2568 | } |
| 2569 | |
| 2570 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
| 2571 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2572 | GetFirstVideoContent(&desc_)->description); |
| 2573 | |
| 2574 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 2575 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 2576 | vcd->set_codecs(codecs); |
| 2577 | |
| 2578 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2579 | jdesc_.session_id(), |
| 2580 | jdesc_.session_version())); |
| 2581 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 2582 | std::string sdp_with_fmtp = kSdpFullString; |
| 2583 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
| 2584 | "a=fmtp:120 x-google-min-bitrate=10\r\n", |
| 2585 | &sdp_with_fmtp); |
| 2586 | EXPECT_EQ(sdp_with_fmtp, message); |
| 2587 | } |
| 2588 | |
| 2589 | TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) { |
| 2590 | JsepSessionDescription jdesc_with_icelite(kDummyString); |
| 2591 | std::string sdp_with_icelite = kSdpFullString; |
| 2592 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2593 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 2594 | const cricket::TransportInfo* tinfo1 = |
| 2595 | desc->GetTransportInfoByName("audio_content_name"); |
| 2596 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 2597 | const cricket::TransportInfo* tinfo2 = |
| 2598 | desc->GetTransportInfoByName("video_content_name"); |
| 2599 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
| 2600 | InjectAfter(kSessionTime, |
| 2601 | "a=ice-lite\r\n", |
| 2602 | &sdp_with_icelite); |
| 2603 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 2604 | desc = jdesc_with_icelite.description(); |
| 2605 | const cricket::TransportInfo* atinfo = |
| 2606 | desc->GetTransportInfoByName("audio_content_name"); |
| 2607 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 2608 | const cricket::TransportInfo* vtinfo = |
| 2609 | desc->GetTransportInfoByName("video_content_name"); |
| 2610 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
| 2611 | } |
| 2612 | |
| 2613 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 2614 | // correctly in the output SDP. |
| 2615 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 2616 | std::string sdp_with_data = kSdpString; |
| 2617 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
| 2618 | JsepSessionDescription jdesc_output(kDummyString); |
| 2619 | |
| 2620 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2621 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output)); |
| 2622 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 2623 | |
| 2624 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 2625 | AddFingerprint(); |
| 2626 | TransportInfo audio_transport_info = |
| 2627 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 2628 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2629 | audio_transport_info.description.connection_role); |
| 2630 | audio_transport_info.description.connection_role = |
| 2631 | cricket::CONNECTIONROLE_ACTIVE; |
| 2632 | |
| 2633 | TransportInfo video_transport_info = |
| 2634 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 2635 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2636 | video_transport_info.description.connection_role); |
| 2637 | video_transport_info.description.connection_role = |
| 2638 | cricket::CONNECTIONROLE_ACTIVE; |
| 2639 | |
| 2640 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 2641 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 2642 | |
| 2643 | desc_.AddTransportInfo(audio_transport_info); |
| 2644 | desc_.AddTransportInfo(video_transport_info); |
| 2645 | |
| 2646 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2647 | jdesc_.session_id(), |
| 2648 | jdesc_.session_version())); |
| 2649 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 2650 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 2651 | |
| 2652 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
| 2653 | InjectAfter(kAttributeIcePwdVoice, |
| 2654 | kFingerprint, &sdp_with_dtlssetup); |
| 2655 | InjectAfter(kAttributeIcePwdVideo, |
| 2656 | kFingerprint, &sdp_with_dtlssetup); |
| 2657 | // Now adding |setup| attribute. |
| 2658 | InjectAfter(kFingerprint, |
| 2659 | "a=setup:active\r\n", &sdp_with_dtlssetup); |
| 2660 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 2661 | } |
| 2662 | |
| 2663 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) { |
| 2664 | JsepSessionDescription jdesc_with_dtlssetup(kDummyString); |
| 2665 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 2666 | InjectAfter(kSessionTime, |
| 2667 | "a=setup:actpass\r\n", |
| 2668 | &sdp_with_dtlssetup); |
| 2669 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 2670 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 2671 | const cricket::TransportInfo* atinfo = |
| 2672 | desc->GetTransportInfoByName("audio_content_name"); |
| 2673 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 2674 | atinfo->description.connection_role); |
| 2675 | const cricket::TransportInfo* vtinfo = |
| 2676 | desc->GetTransportInfoByName("video_content_name"); |
| 2677 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 2678 | vtinfo->description.connection_role); |
| 2679 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2680 | |
| 2681 | // Verifies that the order of the serialized m-lines follows the order of the |
| 2682 | // ContentInfo in SessionDescription, and vise versa for deserialization. |
| 2683 | TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) { |
| 2684 | JsepSessionDescription jdesc(kDummyString); |
| 2685 | const std::string media_content_sdps[3] = { |
| 2686 | kSdpAudioString, |
| 2687 | kSdpVideoString, |
| 2688 | kSdpSctpDataChannelString |
| 2689 | }; |
| 2690 | const cricket::MediaType media_types[3] = { |
| 2691 | cricket::MEDIA_TYPE_AUDIO, |
| 2692 | cricket::MEDIA_TYPE_VIDEO, |
| 2693 | cricket::MEDIA_TYPE_DATA |
| 2694 | }; |
| 2695 | |
| 2696 | // Verifies all 6 permutations. |
| 2697 | for (size_t i = 0; i < 6; ++i) { |
| 2698 | size_t media_content_in_sdp[3]; |
| 2699 | // The index of the first media content. |
| 2700 | media_content_in_sdp[0] = i / 2; |
| 2701 | // The index of the second media content. |
| 2702 | media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3; |
| 2703 | // The index of the third media content. |
| 2704 | media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3; |
| 2705 | |
| 2706 | std::string sdp_string = kSdpSessionString; |
| 2707 | for (size_t i = 0; i < 3; ++i) |
| 2708 | sdp_string += media_content_sdps[media_content_in_sdp[i]]; |
| 2709 | |
| 2710 | EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc)); |
| 2711 | cricket::SessionDescription* desc = jdesc.description(); |
| 2712 | EXPECT_EQ(3u, desc->contents().size()); |
| 2713 | |
| 2714 | for (size_t i = 0; i < 3; ++i) { |
| 2715 | const cricket::MediaContentDescription* mdesc = |
| 2716 | static_cast<const cricket::MediaContentDescription*>( |
| 2717 | desc->contents()[i].description); |
| 2718 | EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 2719 | } |
| 2720 | |
| 2721 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc); |
| 2722 | EXPECT_EQ(sdp_string, serialized_sdp); |
| 2723 | } |
| 2724 | } |