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