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