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