henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2011, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include <set> |
| 29 | #include <string> |
| 30 | #include <vector> |
| 31 | |
| 32 | #include "talk/app/webrtc/jsepsessiondescription.h" |
| 33 | #include "talk/app/webrtc/webrtcsdp.h" |
| 34 | #include "talk/base/gunit.h" |
| 35 | #include "talk/base/logging.h" |
| 36 | #include "talk/base/messagedigest.h" |
| 37 | #include "talk/base/scoped_ptr.h" |
| 38 | #include "talk/base/sslfingerprint.h" |
| 39 | #include "talk/base/stringencode.h" |
| 40 | #include "talk/base/stringutils.h" |
| 41 | #include "talk/media/base/constants.h" |
| 42 | #include "talk/p2p/base/constants.h" |
| 43 | #include "talk/session/media/mediasession.h" |
| 44 | |
| 45 | using cricket::AudioCodec; |
| 46 | using cricket::AudioContentDescription; |
| 47 | using cricket::Candidate; |
| 48 | using cricket::ContentInfo; |
| 49 | using cricket::CryptoParams; |
| 50 | using cricket::ContentGroup; |
| 51 | using cricket::DataCodec; |
| 52 | using cricket::DataContentDescription; |
| 53 | using cricket::ICE_CANDIDATE_COMPONENT_RTCP; |
| 54 | using cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 55 | using cricket::kFecSsrcGroupSemantics; |
| 56 | using cricket::LOCAL_PORT_TYPE; |
| 57 | using cricket::NS_JINGLE_DRAFT_SCTP; |
| 58 | using cricket::NS_JINGLE_ICE_UDP; |
| 59 | using cricket::NS_JINGLE_RTP; |
| 60 | using cricket::RtpHeaderExtension; |
| 61 | using cricket::RELAY_PORT_TYPE; |
| 62 | using cricket::SessionDescription; |
| 63 | using cricket::StreamParams; |
| 64 | using cricket::STUN_PORT_TYPE; |
| 65 | using cricket::TransportDescription; |
| 66 | using cricket::TransportInfo; |
| 67 | using cricket::VideoCodec; |
| 68 | using cricket::VideoContentDescription; |
| 69 | using webrtc::IceCandidateCollection; |
| 70 | using webrtc::IceCandidateInterface; |
| 71 | using webrtc::JsepIceCandidate; |
| 72 | using webrtc::JsepSessionDescription; |
| 73 | using webrtc::SdpParseError; |
| 74 | using webrtc::SessionDescriptionInterface; |
| 75 | |
| 76 | typedef std::vector<AudioCodec> AudioCodecs; |
| 77 | typedef std::vector<Candidate> Candidates; |
| 78 | |
| 79 | static const char kSessionTime[] = "t=0 0\r\n"; |
| 80 | static const uint32 kCandidatePriority = 2130706432U; // pref = 1.0 |
| 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"; |
| 89 | static const uint32 kCandidateGeneration = 2; |
| 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 | |
| 110 | static const uint8 kIdentityDigest[] = {0x4A, 0xAD, 0xB9, 0xB1, |
| 111 | 0x3F, 0x82, 0x18, 0x3B, |
| 112 | 0x54, 0x02, 0x12, 0xDF, |
| 113 | 0x3E, 0x5D, 0x49, 0x6B, |
| 114 | 0x19, 0xE5, 0x7C, 0xAB}; |
| 115 | |
| 116 | struct CodecParams { |
| 117 | int max_ptime; |
| 118 | int ptime; |
| 119 | int min_ptime; |
| 120 | int sprop_stereo; |
| 121 | int stereo; |
| 122 | int useinband; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 123 | int maxaveragebitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | // Reference sdp string |
| 127 | static const char kSdpFullString[] = |
| 128 | "v=0\r\n" |
| 129 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 130 | "s=-\r\n" |
| 131 | "t=0 0\r\n" |
| 132 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 133 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 134 | "c=IN IP4 74.125.127.126\r\n" |
| 135 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 136 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 137 | "generation 2\r\n" |
| 138 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 139 | "generation 2\r\n" |
| 140 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 141 | "generation 2\r\n" |
| 142 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 143 | "generation 2\r\n" |
| 144 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 145 | "raddr 192.168.1.5 rport 2346 " |
| 146 | "generation 2\r\n" |
| 147 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 148 | "raddr 192.168.1.5 rport 2348 " |
| 149 | "generation 2\r\n" |
| 150 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 151 | "a=mid:audio_content_name\r\n" |
| 152 | "a=sendrecv\r\n" |
| 153 | "a=rtcp-mux\r\n" |
| 154 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 155 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 156 | "dummy_session_params\r\n" |
| 157 | "a=rtpmap:111 opus/48000/2\r\n" |
| 158 | "a=rtpmap:103 ISAC/16000\r\n" |
| 159 | "a=rtpmap:104 CELT/32000/2\r\n" |
| 160 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 161 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 162 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 163 | "a=ssrc:1 label:audio_track_id_1\r\n" |
| 164 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 165 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
| 166 | "a=ssrc:4 mslabel:local_stream_2\r\n" |
| 167 | "a=ssrc:4 label:audio_track_id_2\r\n" |
| 168 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 169 | "c=IN IP4 74.125.224.39\r\n" |
| 170 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 171 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 172 | "generation 2\r\n" |
| 173 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 174 | "generation 2\r\n" |
| 175 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 176 | "generation 2\r\n" |
| 177 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 178 | "generation 2\r\n" |
| 179 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 180 | "generation 2\r\n" |
| 181 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 182 | "generation 2\r\n" |
| 183 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 184 | "a=mid:video_content_name\r\n" |
| 185 | "a=sendrecv\r\n" |
| 186 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 187 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 188 | "a=rtpmap:120 VP8/90000\r\n" |
| 189 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 190 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 191 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 192 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 193 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 194 | "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n" |
| 195 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 196 | "a=ssrc:3 label:video_track_id_2\r\n" |
| 197 | "a=ssrc-group:FEC 5 6\r\n" |
| 198 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 199 | "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n" |
| 200 | "a=ssrc:5 mslabel:local_stream_2\r\n" |
| 201 | "a=ssrc:5 label:video_track_id_3\r\n" |
| 202 | "a=ssrc:6 cname:stream_2_cname\r\n" |
| 203 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n" |
| 204 | "a=ssrc:6 mslabel:local_stream_2\r\n" |
| 205 | "a=ssrc:6 label:video_track_id_3\r\n"; |
| 206 | |
| 207 | // SDP reference string without the candidates. |
| 208 | static const char kSdpString[] = |
| 209 | "v=0\r\n" |
| 210 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 211 | "s=-\r\n" |
| 212 | "t=0 0\r\n" |
| 213 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 214 | "m=audio 1 RTP/SAVPF 111 103 104\r\n" |
| 215 | "c=IN IP4 0.0.0.0\r\n" |
| 216 | "a=rtcp:1 IN IP4 0.0.0.0\r\n" |
| 217 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 218 | "a=mid:audio_content_name\r\n" |
| 219 | "a=sendrecv\r\n" |
| 220 | "a=rtcp-mux\r\n" |
| 221 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 222 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 223 | "dummy_session_params\r\n" |
| 224 | "a=rtpmap:111 opus/48000/2\r\n" |
| 225 | "a=rtpmap:103 ISAC/16000\r\n" |
| 226 | "a=rtpmap:104 CELT/32000/2\r\n" |
| 227 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 228 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 229 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 230 | "a=ssrc:1 label:audio_track_id_1\r\n" |
| 231 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 232 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
| 233 | "a=ssrc:4 mslabel:local_stream_2\r\n" |
| 234 | "a=ssrc:4 label:audio_track_id_2\r\n" |
| 235 | "m=video 1 RTP/SAVPF 120\r\n" |
| 236 | "c=IN IP4 0.0.0.0\r\n" |
| 237 | "a=rtcp:1 IN IP4 0.0.0.0\r\n" |
| 238 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 239 | "a=mid:video_content_name\r\n" |
| 240 | "a=sendrecv\r\n" |
| 241 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 242 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 243 | "a=rtpmap:120 VP8/90000\r\n" |
| 244 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 245 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 246 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 247 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 248 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 249 | "a=ssrc:3 msid:local_stream_1 video_track_id_2\r\n" |
| 250 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 251 | "a=ssrc:3 label:video_track_id_2\r\n" |
| 252 | "a=ssrc-group:FEC 5 6\r\n" |
| 253 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 254 | "a=ssrc:5 msid:local_stream_2 video_track_id_3\r\n" |
| 255 | "a=ssrc:5 mslabel:local_stream_2\r\n" |
| 256 | "a=ssrc:5 label:video_track_id_3\r\n" |
| 257 | "a=ssrc:6 cname:stream_2_cname\r\n" |
| 258 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n" |
| 259 | "a=ssrc:6 mslabel:local_stream_2\r\n" |
| 260 | "a=ssrc:6 label:video_track_id_3\r\n"; |
| 261 | |
| 262 | static const char kSdpRtpDataChannelString[] = |
| 263 | "m=application 1 RTP/SAVPF 101\r\n" |
| 264 | "c=IN IP4 0.0.0.0\r\n" |
| 265 | "a=rtcp:1 IN IP4 0.0.0.0\r\n" |
| 266 | "a=ice-ufrag:ufrag_data\r\n" |
| 267 | "a=ice-pwd:pwd_data\r\n" |
| 268 | "a=mid:data_content_name\r\n" |
| 269 | "a=sendrecv\r\n" |
| 270 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 271 | "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n" |
| 272 | "a=rtpmap:101 google-data/90000\r\n" |
| 273 | "a=ssrc:10 cname:data_channel_cname\r\n" |
| 274 | "a=ssrc:10 msid:data_channel data_channeld0\r\n" |
| 275 | "a=ssrc:10 mslabel:data_channel\r\n" |
| 276 | "a=ssrc:10 label:data_channeld0\r\n"; |
| 277 | |
| 278 | static const char kSdpSctpDataChannelString[] = |
| 279 | "m=application 1 DTLS/SCTP 5000\r\n" |
| 280 | "c=IN IP4 0.0.0.0\r\n" |
| 281 | "a=ice-ufrag:ufrag_data\r\n" |
| 282 | "a=ice-pwd:pwd_data\r\n" |
| 283 | "a=mid:data_content_name\r\n" |
| 284 | "a=fmtp:5000 protocol=webrtc-datachannel; streams=10\r\n"; |
| 285 | |
| 286 | static const char kSdpSctpDataChannelWithCandidatesString[] = |
| 287 | "m=application 2345 DTLS/SCTP 5000\r\n" |
| 288 | "c=IN IP4 74.125.127.126\r\n" |
| 289 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 290 | "generation 2\r\n" |
| 291 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 292 | "generation 2\r\n" |
| 293 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 294 | "raddr 192.168.1.5 rport 2346 " |
| 295 | "generation 2\r\n" |
| 296 | "a=ice-ufrag:ufrag_data\r\n" |
| 297 | "a=ice-pwd:pwd_data\r\n" |
| 298 | "a=mid:data_content_name\r\n" |
| 299 | "a=fmtp:5000 protocol=webrtc-datachannel; streams=10\r\n"; |
| 300 | |
| 301 | |
| 302 | // One candidate reference string as per W3c spec. |
| 303 | // candidate:<blah> not a=candidate:<blah>CRLF |
| 304 | static const char kRawCandidate[] = |
| 305 | "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2"; |
| 306 | // One candidate reference string. |
| 307 | static const char kSdpOneCandidate[] = |
| 308 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 309 | "generation 2\r\n"; |
| 310 | |
| 311 | // One candidate reference string. |
| 312 | static const char kSdpOneCandidateOldFormat[] = |
| 313 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name" |
| 314 | " eth0 username user_rtp password password_rtp generation 2\r\n"; |
| 315 | |
| 316 | // Session id and version |
| 317 | static const char kSessionId[] = "18446744069414584320"; |
| 318 | static const char kSessionVersion[] = "18446462598732840960"; |
| 319 | |
| 320 | // Ice options |
| 321 | static const char kIceOption1[] = "iceoption1"; |
| 322 | static const char kIceOption2[] = "iceoption2"; |
| 323 | static const char kIceOption3[] = "iceoption3"; |
| 324 | |
| 325 | // Content name |
| 326 | static const char kAudioContentName[] = "audio_content_name"; |
| 327 | static const char kVideoContentName[] = "video_content_name"; |
| 328 | static const char kDataContentName[] = "data_content_name"; |
| 329 | |
| 330 | // MediaStream 1 |
| 331 | static const char kStreamLabel1[] = "local_stream_1"; |
| 332 | static const char kStream1Cname[] = "stream_1_cname"; |
| 333 | static const char kAudioTrackId1[] = "audio_track_id_1"; |
| 334 | static const uint32 kAudioTrack1Ssrc = 1; |
| 335 | static const char kVideoTrackId1[] = "video_track_id_1"; |
| 336 | static const uint32 kVideoTrack1Ssrc = 2; |
| 337 | static const char kVideoTrackId2[] = "video_track_id_2"; |
| 338 | static const uint32 kVideoTrack2Ssrc = 3; |
| 339 | |
| 340 | // MediaStream 2 |
| 341 | static const char kStreamLabel2[] = "local_stream_2"; |
| 342 | static const char kStream2Cname[] = "stream_2_cname"; |
| 343 | static const char kAudioTrackId2[] = "audio_track_id_2"; |
| 344 | static const uint32 kAudioTrack2Ssrc = 4; |
| 345 | static const char kVideoTrackId3[] = "video_track_id_3"; |
| 346 | static const uint32 kVideoTrack3Ssrc = 5; |
| 347 | static const uint32 kVideoTrack4Ssrc = 6; |
| 348 | |
| 349 | // DataChannel |
| 350 | static const char kDataChannelLabel[] = "data_channel"; |
| 351 | static const char kDataChannelMsid[] = "data_channeld0"; |
| 352 | static const char kDataChannelCname[] = "data_channel_cname"; |
| 353 | static const uint32 kDataChannelSsrc = 10; |
| 354 | |
| 355 | // Candidate |
| 356 | static const char kDummyMid[] = "dummy_mid"; |
| 357 | static const int kDummyIndex = 123; |
| 358 | |
| 359 | // Misc |
| 360 | static const char kDummyString[] = "dummy"; |
| 361 | |
| 362 | // Helper functions |
| 363 | |
| 364 | static bool SdpDeserialize(const std::string& message, |
| 365 | JsepSessionDescription* jdesc) { |
| 366 | return webrtc::SdpDeserialize(message, jdesc, NULL); |
| 367 | } |
| 368 | |
| 369 | static bool SdpDeserializeCandidate(const std::string& message, |
| 370 | JsepIceCandidate* candidate) { |
| 371 | return webrtc::SdpDeserializeCandidate(message, candidate, NULL); |
| 372 | } |
| 373 | |
| 374 | // Add some extra |newlines| to the |message| after |line|. |
| 375 | static void InjectAfter(const std::string& line, |
| 376 | const std::string& newlines, |
| 377 | std::string* message) { |
| 378 | const std::string tmp = line + newlines; |
| 379 | talk_base::replace_substrs(line.c_str(), line.length(), |
| 380 | tmp.c_str(), tmp.length(), message); |
| 381 | } |
| 382 | |
| 383 | static void Replace(const std::string& line, |
| 384 | const std::string& newlines, |
| 385 | std::string* message) { |
| 386 | talk_base::replace_substrs(line.c_str(), line.length(), |
| 387 | newlines.c_str(), newlines.length(), message); |
| 388 | } |
| 389 | |
| 390 | static void ReplaceAndTryToParse(const char* search, const char* replace) { |
| 391 | JsepSessionDescription desc(kDummyString); |
| 392 | std::string sdp = kSdpFullString; |
| 393 | Replace(search, replace, &sdp); |
| 394 | SdpParseError error; |
| 395 | bool ret = webrtc::SdpDeserialize(sdp, &desc, &error); |
| 396 | EXPECT_FALSE(ret); |
| 397 | EXPECT_NE(std::string::npos, error.line.find(replace)); |
| 398 | } |
| 399 | |
| 400 | static void ReplaceDirection(cricket::MediaContentDirection direction, |
| 401 | std::string* message) { |
| 402 | std::string new_direction; |
| 403 | switch (direction) { |
| 404 | case cricket::MD_INACTIVE: |
| 405 | new_direction = "a=inactive"; |
| 406 | break; |
| 407 | case cricket::MD_SENDONLY: |
| 408 | new_direction = "a=sendonly"; |
| 409 | break; |
| 410 | case cricket::MD_RECVONLY: |
| 411 | new_direction = "a=recvonly"; |
| 412 | break; |
| 413 | case cricket::MD_SENDRECV: |
| 414 | default: |
| 415 | new_direction = "a=sendrecv"; |
| 416 | break; |
| 417 | } |
| 418 | Replace("a=sendrecv", new_direction, message); |
| 419 | } |
| 420 | |
| 421 | static void ReplaceRejected(bool audio_rejected, bool video_rejected, |
| 422 | std::string* message) { |
| 423 | if (audio_rejected) { |
| 424 | Replace("m=audio 2345", "m=audio 0", message); |
| 425 | } |
| 426 | if (video_rejected) { |
| 427 | Replace("m=video 3457", "m=video 0", message); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | // WebRtcSdpTest |
| 432 | |
| 433 | class WebRtcSdpTest : public testing::Test { |
| 434 | public: |
| 435 | WebRtcSdpTest() |
| 436 | : jdesc_(kDummyString) { |
| 437 | // AudioContentDescription |
| 438 | audio_desc_ = CreateAudioContentDescription(); |
| 439 | AudioCodec opus(111, "opus", 48000, 0, 2, 3); |
| 440 | audio_desc_->AddCodec(opus); |
| 441 | audio_desc_->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1, 2)); |
| 442 | audio_desc_->AddCodec(AudioCodec(104, "CELT", 32000, 0, 2, 1)); |
| 443 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 444 | |
| 445 | // VideoContentDescription |
| 446 | talk_base::scoped_ptr<VideoContentDescription> video( |
| 447 | new VideoContentDescription()); |
| 448 | video_desc_ = video.get(); |
| 449 | StreamParams video_stream1; |
| 450 | video_stream1.id = kVideoTrackId1; |
| 451 | video_stream1.cname = kStream1Cname; |
| 452 | video_stream1.sync_label = kStreamLabel1; |
| 453 | video_stream1.ssrcs.push_back(kVideoTrack1Ssrc); |
| 454 | video->AddStream(video_stream1); |
| 455 | StreamParams video_stream2; |
| 456 | video_stream2.id = kVideoTrackId2; |
| 457 | video_stream2.cname = kStream1Cname; |
| 458 | video_stream2.sync_label = kStreamLabel1; |
| 459 | video_stream2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 460 | video->AddStream(video_stream2); |
| 461 | StreamParams video_stream3; |
| 462 | video_stream3.id = kVideoTrackId3; |
| 463 | video_stream3.cname = kStream2Cname; |
| 464 | video_stream3.sync_label = kStreamLabel2; |
| 465 | video_stream3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 466 | video_stream3.ssrcs.push_back(kVideoTrack4Ssrc); |
| 467 | cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream3.ssrcs); |
| 468 | video_stream3.ssrc_groups.push_back(ssrc_group); |
| 469 | video->AddStream(video_stream3); |
| 470 | video->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_80", |
| 471 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", "")); |
| 472 | video->set_protocol(cricket::kMediaProtocolSavpf); |
| 473 | video->AddCodec(VideoCodec( |
| 474 | 120, |
| 475 | JsepSessionDescription::kDefaultVideoCodecName, |
| 476 | JsepSessionDescription::kMaxVideoCodecWidth, |
| 477 | JsepSessionDescription::kMaxVideoCodecHeight, |
| 478 | JsepSessionDescription::kDefaultVideoCodecFramerate, |
| 479 | JsepSessionDescription::kDefaultVideoCodecPreference)); |
| 480 | |
| 481 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, |
| 482 | video.release()); |
| 483 | |
| 484 | // TransportInfo |
| 485 | EXPECT_TRUE(desc_.AddTransportInfo( |
| 486 | TransportInfo(kAudioContentName, |
| 487 | TransportDescription(NS_JINGLE_ICE_UDP, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 488 | kCandidateUfragVoice, |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 489 | kCandidatePwdVoice)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | EXPECT_TRUE(desc_.AddTransportInfo( |
| 491 | TransportInfo(kVideoContentName, |
| 492 | TransportDescription(NS_JINGLE_ICE_UDP, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 493 | kCandidateUfragVideo, |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 494 | kCandidatePwdVideo)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 495 | |
| 496 | // v4 host |
| 497 | int port = 1234; |
| 498 | talk_base::SocketAddress address("192.168.1.5", port++); |
| 499 | Candidate candidate1( |
| 500 | "", ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority, |
| 501 | "", "", LOCAL_PORT_TYPE, |
| 502 | "", kCandidateGeneration, kCandidateFoundation1); |
| 503 | address.SetPort(port++); |
| 504 | Candidate candidate2( |
| 505 | "", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, kCandidatePriority, |
| 506 | "", "", LOCAL_PORT_TYPE, |
| 507 | "", kCandidateGeneration, kCandidateFoundation1); |
| 508 | address.SetPort(port++); |
| 509 | Candidate candidate3( |
| 510 | "", ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, kCandidatePriority, |
| 511 | "", "", LOCAL_PORT_TYPE, |
| 512 | "", kCandidateGeneration, kCandidateFoundation1); |
| 513 | address.SetPort(port++); |
| 514 | Candidate candidate4( |
| 515 | "", ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority, |
| 516 | "", "", LOCAL_PORT_TYPE, |
| 517 | "", kCandidateGeneration, kCandidateFoundation1); |
| 518 | |
| 519 | // v6 host |
| 520 | talk_base::SocketAddress v6_address("::1", port++); |
| 521 | cricket::Candidate candidate5( |
| 522 | "", cricket::ICE_CANDIDATE_COMPONENT_RTP, |
| 523 | "udp", v6_address, kCandidatePriority, |
| 524 | "", "", cricket::LOCAL_PORT_TYPE, |
| 525 | "", kCandidateGeneration, kCandidateFoundation2); |
| 526 | v6_address.SetPort(port++); |
| 527 | cricket::Candidate candidate6( |
| 528 | "", cricket::ICE_CANDIDATE_COMPONENT_RTCP, |
| 529 | "udp", v6_address, kCandidatePriority, |
| 530 | "", "", cricket::LOCAL_PORT_TYPE, |
| 531 | "", kCandidateGeneration, kCandidateFoundation2); |
| 532 | v6_address.SetPort(port++); |
| 533 | cricket::Candidate candidate7( |
| 534 | "", cricket::ICE_CANDIDATE_COMPONENT_RTCP, |
| 535 | "udp", v6_address, kCandidatePriority, |
| 536 | "", "", cricket::LOCAL_PORT_TYPE, |
| 537 | "", kCandidateGeneration, kCandidateFoundation2); |
| 538 | v6_address.SetPort(port++); |
| 539 | cricket::Candidate candidate8( |
| 540 | "", cricket::ICE_CANDIDATE_COMPONENT_RTP, |
| 541 | "udp", v6_address, kCandidatePriority, |
| 542 | "", "", cricket::LOCAL_PORT_TYPE, |
| 543 | "", kCandidateGeneration, kCandidateFoundation2); |
| 544 | |
| 545 | // stun |
| 546 | int port_stun = 2345; |
| 547 | talk_base::SocketAddress address_stun("74.125.127.126", port_stun++); |
| 548 | talk_base::SocketAddress rel_address_stun("192.168.1.5", port_stun++); |
| 549 | cricket::Candidate candidate9 |
| 550 | ("", cricket::ICE_CANDIDATE_COMPONENT_RTP, |
| 551 | "udp", address_stun, kCandidatePriority, |
| 552 | "", "", STUN_PORT_TYPE, |
| 553 | "", kCandidateGeneration, kCandidateFoundation3); |
| 554 | candidate9.set_related_address(rel_address_stun); |
| 555 | |
| 556 | address_stun.SetPort(port_stun++); |
| 557 | rel_address_stun.SetPort(port_stun++); |
| 558 | cricket::Candidate candidate10( |
| 559 | "", cricket::ICE_CANDIDATE_COMPONENT_RTCP, |
| 560 | "udp", address_stun, kCandidatePriority, |
| 561 | "", "", STUN_PORT_TYPE, |
| 562 | "", kCandidateGeneration, kCandidateFoundation3); |
| 563 | candidate10.set_related_address(rel_address_stun); |
| 564 | |
| 565 | // relay |
| 566 | int port_relay = 3456; |
| 567 | talk_base::SocketAddress address_relay("74.125.224.39", port_relay++); |
| 568 | cricket::Candidate candidate11( |
| 569 | "", cricket::ICE_CANDIDATE_COMPONENT_RTCP, |
| 570 | "udp", address_relay, kCandidatePriority, |
| 571 | "", "", |
| 572 | cricket::RELAY_PORT_TYPE, "", |
| 573 | kCandidateGeneration, kCandidateFoundation4); |
| 574 | address_relay.SetPort(port_relay++); |
| 575 | cricket::Candidate candidate12( |
| 576 | "", cricket::ICE_CANDIDATE_COMPONENT_RTP, |
| 577 | "udp", address_relay, kCandidatePriority, |
| 578 | "", "", |
| 579 | RELAY_PORT_TYPE, "", |
| 580 | kCandidateGeneration, kCandidateFoundation4); |
| 581 | |
| 582 | // voice |
| 583 | candidates_.push_back(candidate1); |
| 584 | candidates_.push_back(candidate2); |
| 585 | candidates_.push_back(candidate5); |
| 586 | candidates_.push_back(candidate6); |
| 587 | candidates_.push_back(candidate9); |
| 588 | candidates_.push_back(candidate10); |
| 589 | |
| 590 | // video |
| 591 | candidates_.push_back(candidate3); |
| 592 | candidates_.push_back(candidate4); |
| 593 | candidates_.push_back(candidate7); |
| 594 | candidates_.push_back(candidate8); |
| 595 | candidates_.push_back(candidate11); |
| 596 | candidates_.push_back(candidate12); |
| 597 | |
| 598 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), |
| 599 | 0, candidate1)); |
| 600 | |
| 601 | // Set up JsepSessionDescription. |
| 602 | jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion); |
| 603 | std::string mline_id; |
| 604 | int mline_index = 0; |
| 605 | for (size_t i = 0; i< candidates_.size(); ++i) { |
| 606 | // In this test, the audio m line index will be 0, and the video m line |
| 607 | // will be 1. |
| 608 | bool is_video = (i > 5); |
| 609 | mline_id = is_video ? "video_content_name" : "audio_content_name"; |
| 610 | mline_index = is_video ? 1 : 0; |
| 611 | JsepIceCandidate jice(mline_id, |
| 612 | mline_index, |
| 613 | candidates_.at(i)); |
| 614 | jdesc_.AddCandidate(&jice); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | AudioContentDescription* CreateAudioContentDescription() { |
| 619 | AudioContentDescription* audio = new AudioContentDescription(); |
| 620 | audio->set_rtcp_mux(true); |
| 621 | StreamParams audio_stream1; |
| 622 | audio_stream1.id = kAudioTrackId1; |
| 623 | audio_stream1.cname = kStream1Cname; |
| 624 | audio_stream1.sync_label = kStreamLabel1; |
| 625 | audio_stream1.ssrcs.push_back(kAudioTrack1Ssrc); |
| 626 | audio->AddStream(audio_stream1); |
| 627 | StreamParams audio_stream2; |
| 628 | audio_stream2.id = kAudioTrackId2; |
| 629 | audio_stream2.cname = kStream2Cname; |
| 630 | audio_stream2.sync_label = kStreamLabel2; |
| 631 | audio_stream2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 632 | audio->AddStream(audio_stream2); |
| 633 | audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32", |
| 634 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32", |
| 635 | "dummy_session_params")); |
| 636 | audio->set_protocol(cricket::kMediaProtocolSavpf); |
| 637 | return audio; |
| 638 | } |
| 639 | |
| 640 | template <class MCD> |
| 641 | void CompareMediaContentDescription(const MCD* cd1, |
| 642 | const MCD* cd2) { |
| 643 | // type |
| 644 | EXPECT_EQ(cd1->type(), cd1->type()); |
| 645 | |
| 646 | // content direction |
| 647 | EXPECT_EQ(cd1->direction(), cd2->direction()); |
| 648 | |
| 649 | // rtcp_mux |
| 650 | EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux()); |
| 651 | |
| 652 | // cryptos |
| 653 | EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size()); |
| 654 | if (cd1->cryptos().size() != cd2->cryptos().size()) { |
| 655 | ADD_FAILURE(); |
| 656 | return; |
| 657 | } |
| 658 | for (size_t i = 0; i< cd1->cryptos().size(); ++i) { |
| 659 | const CryptoParams c1 = cd1->cryptos().at(i); |
| 660 | const CryptoParams c2 = cd2->cryptos().at(i); |
| 661 | EXPECT_TRUE(c1.Matches(c2)); |
| 662 | EXPECT_EQ(c1.key_params, c2.key_params); |
| 663 | EXPECT_EQ(c1.session_params, c2.session_params); |
| 664 | } |
| 665 | // protocol |
| 666 | EXPECT_EQ(cd1->protocol(), cd2->protocol()); |
| 667 | |
| 668 | // codecs |
| 669 | EXPECT_EQ(cd1->codecs(), cd2->codecs()); |
| 670 | |
| 671 | // bandwidth |
| 672 | EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth()); |
| 673 | |
| 674 | // streams |
| 675 | EXPECT_EQ(cd1->streams(), cd2->streams()); |
| 676 | |
| 677 | // extmap |
| 678 | ASSERT_EQ(cd1->rtp_header_extensions().size(), |
| 679 | cd2->rtp_header_extensions().size()); |
| 680 | for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) { |
| 681 | const RtpHeaderExtension ext1 = cd1->rtp_header_extensions().at(i); |
| 682 | const RtpHeaderExtension ext2 = cd2->rtp_header_extensions().at(i); |
| 683 | EXPECT_EQ(ext1.uri, ext2.uri); |
| 684 | EXPECT_EQ(ext1.id, ext2.id); |
| 685 | } |
| 686 | |
| 687 | // buffered mode latency |
| 688 | EXPECT_EQ(cd1->buffered_mode_latency(), cd2->buffered_mode_latency()); |
| 689 | } |
| 690 | |
| 691 | |
| 692 | void CompareSessionDescription(const SessionDescription& desc1, |
| 693 | const SessionDescription& desc2) { |
| 694 | // Compare content descriptions. |
| 695 | if (desc1.contents().size() != desc2.contents().size()) { |
| 696 | ADD_FAILURE(); |
| 697 | return; |
| 698 | } |
| 699 | for (size_t i = 0 ; i < desc1.contents().size(); ++i) { |
| 700 | const cricket::ContentInfo& c1 = desc1.contents().at(i); |
| 701 | const cricket::ContentInfo& c2 = desc2.contents().at(i); |
| 702 | // content name |
| 703 | EXPECT_EQ(c1.name, c2.name); |
| 704 | // content type |
| 705 | // Note, ASSERT will return from the function, but will not stop the test. |
| 706 | ASSERT_EQ(c1.type, c2.type); |
| 707 | |
| 708 | ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2)); |
| 709 | if (IsAudioContent(&c1)) { |
| 710 | const AudioContentDescription* acd1 = |
| 711 | static_cast<const AudioContentDescription*>(c1.description); |
| 712 | const AudioContentDescription* acd2 = |
| 713 | static_cast<const AudioContentDescription*>(c2.description); |
| 714 | CompareMediaContentDescription<AudioContentDescription>(acd1, acd2); |
| 715 | } |
| 716 | |
| 717 | ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2)); |
| 718 | if (IsVideoContent(&c1)) { |
| 719 | const VideoContentDescription* vcd1 = |
| 720 | static_cast<const VideoContentDescription*>(c1.description); |
| 721 | const VideoContentDescription* vcd2 = |
| 722 | static_cast<const VideoContentDescription*>(c2.description); |
| 723 | CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2); |
| 724 | } |
| 725 | |
| 726 | ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2)); |
| 727 | if (IsDataContent(&c1)) { |
| 728 | const DataContentDescription* dcd1 = |
| 729 | static_cast<const DataContentDescription*>(c1.description); |
| 730 | const DataContentDescription* dcd2 = |
| 731 | static_cast<const DataContentDescription*>(c2.description); |
| 732 | CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | // group |
| 737 | const cricket::ContentGroups groups1 = desc1.groups(); |
| 738 | const cricket::ContentGroups groups2 = desc2.groups(); |
| 739 | EXPECT_EQ(groups1.size(), groups1.size()); |
| 740 | if (groups1.size() != groups2.size()) { |
| 741 | ADD_FAILURE(); |
| 742 | return; |
| 743 | } |
| 744 | for (size_t i = 0; i < groups1.size(); ++i) { |
| 745 | const cricket::ContentGroup group1 = groups1.at(i); |
| 746 | const cricket::ContentGroup group2 = groups2.at(i); |
| 747 | EXPECT_EQ(group1.semantics(), group2.semantics()); |
| 748 | const cricket::ContentNames names1 = group1.content_names(); |
| 749 | const cricket::ContentNames names2 = group2.content_names(); |
| 750 | EXPECT_EQ(names1.size(), names2.size()); |
| 751 | if (names1.size() != names2.size()) { |
| 752 | ADD_FAILURE(); |
| 753 | return; |
| 754 | } |
| 755 | cricket::ContentNames::const_iterator iter1 = names1.begin(); |
| 756 | cricket::ContentNames::const_iterator iter2 = names2.begin(); |
| 757 | while (iter1 != names1.end()) { |
| 758 | EXPECT_EQ(*iter1++, *iter2++); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | // transport info |
| 763 | const cricket::TransportInfos transports1 = desc1.transport_infos(); |
| 764 | const cricket::TransportInfos transports2 = desc2.transport_infos(); |
| 765 | EXPECT_EQ(transports1.size(), transports2.size()); |
| 766 | if (transports1.size() != transports2.size()) { |
| 767 | ADD_FAILURE(); |
| 768 | return; |
| 769 | } |
| 770 | for (size_t i = 0; i < transports1.size(); ++i) { |
| 771 | const cricket::TransportInfo transport1 = transports1.at(i); |
| 772 | const cricket::TransportInfo transport2 = transports2.at(i); |
| 773 | EXPECT_EQ(transport1.content_name, transport2.content_name); |
| 774 | EXPECT_EQ(transport1.description.transport_type, |
| 775 | transport2.description.transport_type); |
| 776 | EXPECT_EQ(transport1.description.ice_ufrag, |
| 777 | transport2.description.ice_ufrag); |
| 778 | EXPECT_EQ(transport1.description.ice_pwd, |
| 779 | transport2.description.ice_pwd); |
| 780 | if (transport1.description.identity_fingerprint) { |
| 781 | EXPECT_EQ(*transport1.description.identity_fingerprint, |
| 782 | *transport2.description.identity_fingerprint); |
| 783 | } else { |
| 784 | EXPECT_EQ(transport1.description.identity_fingerprint.get(), |
| 785 | transport2.description.identity_fingerprint.get()); |
| 786 | } |
| 787 | EXPECT_EQ(transport1.description.transport_options, |
| 788 | transport2.description.transport_options); |
| 789 | EXPECT_TRUE(CompareCandidates(transport1.description.candidates, |
| 790 | transport2.description.candidates)); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | bool CompareCandidates(const Candidates& cs1, const Candidates& cs2) { |
| 795 | EXPECT_EQ(cs1.size(), cs2.size()); |
| 796 | if (cs1.size() != cs2.size()) |
| 797 | return false; |
| 798 | for (size_t i = 0; i< cs1.size(); ++i) { |
| 799 | const Candidate c1 = cs1.at(i); |
| 800 | const Candidate c2 = cs2.at(i); |
| 801 | EXPECT_TRUE(c1.IsEquivalent(c2)); |
| 802 | } |
| 803 | return true; |
| 804 | } |
| 805 | |
| 806 | bool CompareSessionDescription( |
| 807 | const JsepSessionDescription& desc1, |
| 808 | const JsepSessionDescription& desc2) { |
| 809 | EXPECT_EQ(desc1.session_id(), desc2.session_id()); |
| 810 | EXPECT_EQ(desc1.session_version(), desc2.session_version()); |
| 811 | CompareSessionDescription(*desc1.description(), *desc2.description()); |
| 812 | if (desc1.number_of_mediasections() != desc2.number_of_mediasections()) |
| 813 | return false; |
| 814 | for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) { |
| 815 | const IceCandidateCollection* cc1 = desc1.candidates(i); |
| 816 | const IceCandidateCollection* cc2 = desc2.candidates(i); |
| 817 | if (cc1->count() != cc2->count()) |
| 818 | return false; |
| 819 | for (size_t j = 0; j < cc1->count(); ++j) { |
| 820 | const IceCandidateInterface* c1 = cc1->at(j); |
| 821 | const IceCandidateInterface* c2 = cc2->at(j); |
| 822 | EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid()); |
| 823 | EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index()); |
| 824 | EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate())); |
| 825 | } |
| 826 | } |
| 827 | return true; |
| 828 | } |
| 829 | |
| 830 | // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing |
| 831 | // them with invalid keywords so that the parser will just ignore them. |
| 832 | bool RemoveCandidateUfragPwd(std::string* sdp) { |
| 833 | const char ice_ufrag[] = "a=ice-ufrag"; |
| 834 | const char ice_ufragx[] = "a=xice-ufrag"; |
| 835 | const char ice_pwd[] = "a=ice-pwd"; |
| 836 | const char ice_pwdx[] = "a=xice-pwd"; |
| 837 | talk_base::replace_substrs(ice_ufrag, strlen(ice_ufrag), |
| 838 | ice_ufragx, strlen(ice_ufragx), sdp); |
| 839 | talk_base::replace_substrs(ice_pwd, strlen(ice_pwd), |
| 840 | ice_pwdx, strlen(ice_pwdx), sdp); |
| 841 | return true; |
| 842 | } |
| 843 | |
| 844 | // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|. |
| 845 | bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index, |
| 846 | const std::string& ufrag, const std::string& pwd) { |
| 847 | std::string content_name; |
| 848 | if (mline_index == 0) { |
| 849 | content_name = kAudioContentName; |
| 850 | } else if (mline_index == 1) { |
| 851 | content_name = kVideoContentName; |
| 852 | } else { |
| 853 | ASSERT(false); |
| 854 | } |
| 855 | TransportInfo transport_info( |
| 856 | content_name, TransportDescription(NS_JINGLE_ICE_UDP, |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 857 | ufrag, pwd)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 858 | SessionDescription* desc = |
| 859 | const_cast<SessionDescription*>(jdesc->description()); |
| 860 | desc->RemoveTransportInfoByName(content_name); |
| 861 | EXPECT_TRUE(desc->AddTransportInfo(transport_info)); |
| 862 | for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) { |
| 863 | const IceCandidateCollection* cc = jdesc_.candidates(i); |
| 864 | for (size_t j = 0; j < cc->count(); ++j) { |
| 865 | if (cc->at(j)->sdp_mline_index() == mline_index) { |
| 866 | const_cast<Candidate&>(cc->at(j)->candidate()).set_username( |
| 867 | ufrag); |
| 868 | const_cast<Candidate&>(cc->at(j)->candidate()).set_password( |
| 869 | pwd); |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | return true; |
| 874 | } |
| 875 | |
| 876 | void AddIceOptions(const std::string& content_name, |
| 877 | const std::vector<std::string>& transport_options) { |
| 878 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 879 | cricket::TransportInfo transport_info = |
| 880 | *(desc_.GetTransportInfoByName(content_name)); |
| 881 | desc_.RemoveTransportInfoByName(content_name); |
| 882 | transport_info.description.transport_options = transport_options; |
| 883 | desc_.AddTransportInfo(transport_info); |
| 884 | } |
| 885 | |
| 886 | void AddFingerprint() { |
| 887 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 888 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 889 | talk_base::SSLFingerprint fingerprint(talk_base::DIGEST_SHA_1, |
| 890 | kIdentityDigest, |
| 891 | sizeof(kIdentityDigest)); |
| 892 | EXPECT_TRUE(desc_.AddTransportInfo( |
| 893 | TransportInfo(kAudioContentName, |
| 894 | TransportDescription(NS_JINGLE_ICE_UDP, |
| 895 | std::vector<std::string>(), |
| 896 | kCandidateUfragVoice, |
| 897 | kCandidatePwdVoice, |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 898 | cricket::ICEMODE_FULL, |
| 899 | cricket::CONNECTIONROLE_NONE, |
| 900 | &fingerprint, Candidates())))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | EXPECT_TRUE(desc_.AddTransportInfo( |
| 902 | TransportInfo(kVideoContentName, |
| 903 | TransportDescription(NS_JINGLE_ICE_UDP, |
| 904 | std::vector<std::string>(), |
| 905 | kCandidateUfragVideo, |
| 906 | kCandidatePwdVideo, |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 907 | cricket::ICEMODE_FULL, |
| 908 | cricket::CONNECTIONROLE_NONE, |
| 909 | &fingerprint, Candidates())))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | void AddExtmap() { |
| 913 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 914 | audio_desc_->Copy()); |
| 915 | video_desc_ = static_cast<VideoContentDescription*>( |
| 916 | video_desc_->Copy()); |
| 917 | audio_desc_->AddRtpHeaderExtension( |
| 918 | RtpHeaderExtension(kExtmapUri, kExtmapId)); |
| 919 | video_desc_->AddRtpHeaderExtension( |
| 920 | RtpHeaderExtension(kExtmapUri, kExtmapId)); |
| 921 | desc_.RemoveContentByName(kAudioContentName); |
| 922 | desc_.RemoveContentByName(kVideoContentName); |
| 923 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 924 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
| 925 | } |
| 926 | |
| 927 | void RemoveCryptos() { |
| 928 | audio_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 929 | video_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 930 | } |
| 931 | |
| 932 | bool TestSerializeDirection(cricket::MediaContentDirection direction) { |
| 933 | audio_desc_->set_direction(direction); |
| 934 | video_desc_->set_direction(direction); |
| 935 | std::string new_sdp = kSdpFullString; |
| 936 | ReplaceDirection(direction, &new_sdp); |
| 937 | |
| 938 | if (!jdesc_.Initialize(desc_.Copy(), |
| 939 | jdesc_.session_id(), |
| 940 | jdesc_.session_version())) { |
| 941 | return false; |
| 942 | } |
| 943 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 944 | EXPECT_EQ(new_sdp, message); |
| 945 | return true; |
| 946 | } |
| 947 | |
| 948 | bool TestSerializeRejected(bool audio_rejected, bool video_rejected) { |
| 949 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 950 | audio_desc_->Copy()); |
| 951 | video_desc_ = static_cast<VideoContentDescription*>( |
| 952 | video_desc_->Copy()); |
| 953 | desc_.RemoveContentByName(kAudioContentName); |
| 954 | desc_.RemoveContentByName(kVideoContentName); |
| 955 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 956 | audio_desc_); |
| 957 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 958 | video_desc_); |
| 959 | std::string new_sdp = kSdpFullString; |
| 960 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 961 | |
| 962 | if (!jdesc_.Initialize(desc_.Copy(), |
| 963 | jdesc_.session_id(), |
| 964 | jdesc_.session_version())) { |
| 965 | return false; |
| 966 | } |
| 967 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 968 | EXPECT_EQ(new_sdp, message); |
| 969 | return true; |
| 970 | } |
| 971 | |
| 972 | void AddSctpDataChannel() { |
| 973 | talk_base::scoped_ptr<DataContentDescription> data( |
| 974 | new DataContentDescription()); |
| 975 | data_desc_ = data.get(); |
| 976 | data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); |
| 977 | desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release()); |
| 978 | EXPECT_TRUE(desc_.AddTransportInfo( |
| 979 | TransportInfo(kDataContentName, |
| 980 | TransportDescription(NS_JINGLE_ICE_UDP, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 981 | kCandidateUfragData, |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 982 | kCandidatePwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | void AddRtpDataChannel() { |
| 986 | talk_base::scoped_ptr<DataContentDescription> data( |
| 987 | new DataContentDescription()); |
| 988 | data_desc_ = data.get(); |
| 989 | |
| 990 | data_desc_->AddCodec(DataCodec(101, "google-data", 1)); |
| 991 | StreamParams data_stream; |
| 992 | data_stream.id = kDataChannelMsid; |
| 993 | data_stream.cname = kDataChannelCname; |
| 994 | data_stream.sync_label = kDataChannelLabel; |
| 995 | data_stream.ssrcs.push_back(kDataChannelSsrc); |
| 996 | data_desc_->AddStream(data_stream); |
| 997 | data_desc_->AddCrypto(CryptoParams( |
| 998 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 999 | "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", "")); |
| 1000 | data_desc_->set_protocol(cricket::kMediaProtocolSavpf); |
| 1001 | desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release()); |
| 1002 | EXPECT_TRUE(desc_.AddTransportInfo( |
| 1003 | TransportInfo(kDataContentName, |
| 1004 | TransportDescription(NS_JINGLE_ICE_UDP, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1005 | kCandidateUfragData, |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 1006 | kCandidatePwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | bool TestDeserializeDirection(cricket::MediaContentDirection direction) { |
| 1010 | std::string new_sdp = kSdpFullString; |
| 1011 | ReplaceDirection(direction, &new_sdp); |
| 1012 | JsepSessionDescription new_jdesc(kDummyString); |
| 1013 | |
| 1014 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1015 | |
| 1016 | audio_desc_->set_direction(direction); |
| 1017 | video_desc_->set_direction(direction); |
| 1018 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1019 | jdesc_.session_id(), |
| 1020 | jdesc_.session_version())) { |
| 1021 | return false; |
| 1022 | } |
| 1023 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
| 1027 | bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { |
| 1028 | std::string new_sdp = kSdpFullString; |
| 1029 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1030 | JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer); |
| 1031 | |
| 1032 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1033 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1034 | audio_desc_->Copy()); |
| 1035 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1036 | video_desc_->Copy()); |
| 1037 | desc_.RemoveContentByName(kAudioContentName); |
| 1038 | desc_.RemoveContentByName(kVideoContentName); |
| 1039 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1040 | audio_desc_); |
| 1041 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1042 | video_desc_); |
| 1043 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1044 | jdesc_.session_id(), |
| 1045 | jdesc_.session_version())) { |
| 1046 | return false; |
| 1047 | } |
| 1048 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1049 | return true; |
| 1050 | } |
| 1051 | |
| 1052 | void TestDeserializeExtmap(bool session_level, bool media_level) { |
| 1053 | AddExtmap(); |
| 1054 | JsepSessionDescription new_jdesc("dummy"); |
| 1055 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 1056 | jdesc_.session_id(), |
| 1057 | jdesc_.session_version())); |
| 1058 | JsepSessionDescription jdesc_with_extmap("dummy"); |
| 1059 | std::string sdp_with_extmap = kSdpString; |
| 1060 | if (session_level) { |
| 1061 | InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute, |
| 1062 | &sdp_with_extmap); |
| 1063 | } |
| 1064 | if (media_level) { |
| 1065 | InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute, |
| 1066 | &sdp_with_extmap); |
| 1067 | InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute, |
| 1068 | &sdp_with_extmap); |
| 1069 | } |
| 1070 | // The extmap can't be present at the same time in both session level and |
| 1071 | // media level. |
| 1072 | if (session_level && media_level) { |
| 1073 | SdpParseError error; |
| 1074 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap, |
| 1075 | &jdesc_with_extmap, &error)); |
| 1076 | EXPECT_NE(std::string::npos, error.description.find("a=extmap")); |
| 1077 | } else { |
| 1078 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap)); |
| 1079 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc)); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | void VerifyCodecParameter(const cricket::CodecParameterMap& params, |
| 1084 | const std::string& name, int expected_value) { |
| 1085 | cricket::CodecParameterMap::const_iterator found = params.find(name); |
| 1086 | ASSERT_TRUE(found != params.end()); |
| 1087 | EXPECT_EQ(found->second, talk_base::ToString<int>(expected_value)); |
| 1088 | } |
| 1089 | |
| 1090 | void TestDeserializeCodecParams(const CodecParams& params, |
| 1091 | JsepSessionDescription* jdesc_output) { |
| 1092 | std::string sdp = |
| 1093 | "v=0\r\n" |
| 1094 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1095 | "s=-\r\n" |
| 1096 | "t=0 0\r\n" |
| 1097 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1098 | // this parser, and will be added to the SDP when serializing a session |
| 1099 | // description. |
| 1100 | "a=msid-semantic: WMS\r\n" |
| 1101 | // Pl type 111 preferred. |
| 1102 | "m=audio 1 RTP/SAVPF 111 104 103 102\r\n" |
| 1103 | // Pltype 111 listed before 103 and 104 in the map. |
| 1104 | "a=rtpmap:111 opus/48000/2\r\n" |
| 1105 | // Pltype 103 listed before 104. |
| 1106 | "a=rtpmap:103 ISAC/16000\r\n" |
| 1107 | "a=rtpmap:104 CELT/32000/2\r\n" |
| 1108 | "a=rtpmap:102 ISAC/32000/1\r\n" |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1109 | "a=fmtp:111 0-15,66,70\r\n" |
| 1110 | "a=fmtp:111 "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1111 | std::ostringstream os; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1112 | os << "minptime=" << params.min_ptime |
| 1113 | << "; stereo=" << params.stereo |
| 1114 | << "; sprop-stereo=" << params.sprop_stereo |
| 1115 | << "; useinbandfec=" << params.useinband |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1116 | << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1117 | << "a=ptime:" << params.ptime << "\r\n" |
| 1118 | << "a=maxptime:" << params.max_ptime << "\r\n"; |
| 1119 | sdp += os.str(); |
| 1120 | |
| 1121 | // Deserialize |
| 1122 | SdpParseError error; |
| 1123 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1124 | |
| 1125 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1126 | ASSERT_TRUE(ac != NULL); |
| 1127 | const AudioContentDescription* acd = |
| 1128 | static_cast<const AudioContentDescription*>(ac->description); |
| 1129 | ASSERT_FALSE(acd->codecs().empty()); |
| 1130 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1131 | EXPECT_EQ("opus", opus.name); |
| 1132 | EXPECT_EQ(111, opus.id); |
| 1133 | VerifyCodecParameter(opus.params, "minptime", params.min_ptime); |
| 1134 | VerifyCodecParameter(opus.params, "stereo", params.stereo); |
| 1135 | VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo); |
| 1136 | VerifyCodecParameter(opus.params, "useinbandfec", params.useinband); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1137 | VerifyCodecParameter(opus.params, "maxaveragebitrate", |
| 1138 | params.maxaveragebitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1139 | for (size_t i = 0; i < acd->codecs().size(); ++i) { |
| 1140 | cricket::AudioCodec codec = acd->codecs()[i]; |
| 1141 | VerifyCodecParameter(codec.params, "ptime", params.ptime); |
| 1142 | VerifyCodecParameter(codec.params, "maxptime", params.max_ptime); |
| 1143 | if (codec.name == "ISAC") { |
| 1144 | if (codec.clockrate == 16000) { |
| 1145 | EXPECT_EQ(32000, codec.bitrate); |
| 1146 | } else { |
| 1147 | EXPECT_EQ(56000, codec.bitrate); |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output, |
| 1154 | bool use_wildcard) { |
| 1155 | std::string sdp = |
| 1156 | "v=0\r\n" |
| 1157 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1158 | "s=-\r\n" |
| 1159 | "t=0 0\r\n" |
| 1160 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1161 | // this parser, and will be added to the SDP when serializing a session |
| 1162 | // description. |
| 1163 | "a=msid-semantic: WMS\r\n" |
| 1164 | "m=audio 1 RTP/SAVPF 111\r\n" |
| 1165 | "a=rtpmap:111 opus/48000/2\r\n" |
| 1166 | "a=rtcp-fb:111 nack\r\n" |
| 1167 | "m=video 3457 RTP/SAVPF 101\r\n" |
| 1168 | "a=rtpmap:101 VP8/90000\r\n" |
| 1169 | "a=rtcp-fb:101 nack\r\n" |
| 1170 | "a=rtcp-fb:101 goog-remb\r\n" |
| 1171 | "a=rtcp-fb:101 ccm fir\r\n"; |
| 1172 | std::ostringstream os; |
| 1173 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n"; |
| 1174 | sdp += os.str(); |
| 1175 | // Deserialize |
| 1176 | SdpParseError error; |
| 1177 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1178 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1179 | ASSERT_TRUE(ac != NULL); |
| 1180 | const AudioContentDescription* acd = |
| 1181 | static_cast<const AudioContentDescription*>(ac->description); |
| 1182 | ASSERT_FALSE(acd->codecs().empty()); |
| 1183 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1184 | EXPECT_EQ(111, opus.id); |
| 1185 | EXPECT_TRUE(opus.HasFeedbackParam( |
| 1186 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1187 | cricket::kParamValueEmpty))); |
| 1188 | |
| 1189 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description()); |
| 1190 | ASSERT_TRUE(vc != NULL); |
| 1191 | const VideoContentDescription* vcd = |
| 1192 | static_cast<const VideoContentDescription*>(vc->description); |
| 1193 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1194 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1195 | EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName, |
| 1196 | vp8.name.c_str()); |
| 1197 | EXPECT_EQ(101, vp8.id); |
| 1198 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1199 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1200 | cricket::kParamValueEmpty))); |
| 1201 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1202 | cricket::FeedbackParam(cricket::kRtcpFbParamRemb, |
| 1203 | cricket::kParamValueEmpty))); |
| 1204 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1205 | cricket::FeedbackParam(cricket::kRtcpFbParamCcm, |
| 1206 | cricket::kRtcpFbCcmParamFir))); |
| 1207 | } |
| 1208 | |
| 1209 | // Two SDP messages can mean the same thing but be different strings, e.g. |
| 1210 | // some of the lines can be serialized in different order. |
| 1211 | // However, a deserialized description can be compared field by field and has |
| 1212 | // no order. If deserializer has already been tested, serializing then |
| 1213 | // deserializing and comparing JsepSessionDescription will test |
| 1214 | // the serializer sufficiently. |
| 1215 | void TestSerialize(const JsepSessionDescription& jdesc) { |
| 1216 | std::string message = webrtc::SdpSerialize(jdesc); |
| 1217 | JsepSessionDescription jdesc_output_des(kDummyString); |
| 1218 | SdpParseError error; |
| 1219 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); |
| 1220 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); |
| 1221 | } |
| 1222 | |
| 1223 | protected: |
| 1224 | SessionDescription desc_; |
| 1225 | AudioContentDescription* audio_desc_; |
| 1226 | VideoContentDescription* video_desc_; |
| 1227 | DataContentDescription* data_desc_; |
| 1228 | Candidates candidates_; |
| 1229 | talk_base::scoped_ptr<IceCandidateInterface> jcandidate_; |
| 1230 | JsepSessionDescription jdesc_; |
| 1231 | }; |
| 1232 | |
| 1233 | void TestMismatch(const std::string& string1, const std::string& string2) { |
| 1234 | int position = 0; |
| 1235 | for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { |
| 1236 | if (string1.c_str()[i] != string2.c_str()[i]) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1237 | position = static_cast<int>(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1238 | break; |
| 1239 | } |
| 1240 | } |
| 1241 | EXPECT_EQ(0, position) << "Strings mismatch at the " << position |
| 1242 | << " character\n" |
| 1243 | << " 1: " << string1.substr(position, 20) << "\n" |
| 1244 | << " 2: " << string2.substr(position, 20) << "\n"; |
| 1245 | } |
| 1246 | |
| 1247 | std::string GetLine(const std::string& message, |
| 1248 | const std::string& session_description_name) { |
| 1249 | size_t start = message.find(session_description_name); |
| 1250 | if (std::string::npos == start) { |
| 1251 | return ""; |
| 1252 | } |
| 1253 | size_t stop = message.find("\r\n", start); |
| 1254 | if (std::string::npos == stop) { |
| 1255 | return ""; |
| 1256 | } |
| 1257 | if (stop <= start) { |
| 1258 | return ""; |
| 1259 | } |
| 1260 | return message.substr(start, stop - start); |
| 1261 | } |
| 1262 | |
| 1263 | TEST_F(WebRtcSdpTest, SerializeSessionDescription) { |
| 1264 | // SessionDescription with desc and candidates. |
| 1265 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 1266 | TestMismatch(std::string(kSdpFullString), message); |
| 1267 | } |
| 1268 | |
| 1269 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) { |
| 1270 | JsepSessionDescription jdesc_empty(kDummyString); |
| 1271 | EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty)); |
| 1272 | } |
| 1273 | |
| 1274 | // This tests serialization of SDP with a=crypto and a=fingerprint, as would be |
| 1275 | // the case in a DTLS offer. |
| 1276 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) { |
| 1277 | AddFingerprint(); |
| 1278 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1279 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1280 | kSessionId, kSessionVersion)); |
| 1281 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint); |
| 1282 | |
| 1283 | std::string sdp_with_fingerprint = kSdpString; |
| 1284 | InjectAfter(kAttributeIcePwdVoice, |
| 1285 | kFingerprint, &sdp_with_fingerprint); |
| 1286 | InjectAfter(kAttributeIcePwdVideo, |
| 1287 | kFingerprint, &sdp_with_fingerprint); |
| 1288 | |
| 1289 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1290 | } |
| 1291 | |
| 1292 | // This tests serialization of SDP with a=fingerprint with no a=crypto, as would |
| 1293 | // be the case in a DTLS answer. |
| 1294 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) { |
| 1295 | AddFingerprint(); |
| 1296 | RemoveCryptos(); |
| 1297 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1298 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1299 | kSessionId, kSessionVersion)); |
| 1300 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint); |
| 1301 | |
| 1302 | std::string sdp_with_fingerprint = kSdpString; |
| 1303 | Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint); |
| 1304 | Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint); |
| 1305 | InjectAfter(kAttributeIcePwdVoice, |
| 1306 | kFingerprint, &sdp_with_fingerprint); |
| 1307 | InjectAfter(kAttributeIcePwdVideo, |
| 1308 | kFingerprint, &sdp_with_fingerprint); |
| 1309 | |
| 1310 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1311 | } |
| 1312 | |
| 1313 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { |
| 1314 | // JsepSessionDescription with desc but without candidates. |
| 1315 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1316 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), |
| 1317 | kSessionId, kSessionVersion)); |
| 1318 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates); |
| 1319 | EXPECT_EQ(std::string(kSdpString), message); |
| 1320 | } |
| 1321 | |
| 1322 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) { |
| 1323 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1324 | group.AddContentName(kAudioContentName); |
| 1325 | group.AddContentName(kVideoContentName); |
| 1326 | desc_.AddGroup(group); |
| 1327 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1328 | jdesc_.session_id(), |
| 1329 | jdesc_.session_version())); |
| 1330 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 1331 | std::string sdp_with_bundle = kSdpFullString; |
| 1332 | InjectAfter(kSessionTime, |
| 1333 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 1334 | &sdp_with_bundle); |
| 1335 | EXPECT_EQ(sdp_with_bundle, message); |
| 1336 | } |
| 1337 | |
| 1338 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) { |
| 1339 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 1340 | GetFirstVideoContent(&desc_)->description); |
| 1341 | vcd->set_bandwidth(100 * 1000); |
| 1342 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 1343 | GetFirstAudioContent(&desc_)->description); |
| 1344 | acd->set_bandwidth(50 * 1000); |
| 1345 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1346 | jdesc_.session_id(), |
| 1347 | jdesc_.session_version())); |
| 1348 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 1349 | std::string sdp_with_bandwidth = kSdpFullString; |
| 1350 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 1351 | "b=AS:100\r\n", |
| 1352 | &sdp_with_bandwidth); |
| 1353 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 1354 | "b=AS:50\r\n", |
| 1355 | &sdp_with_bandwidth); |
| 1356 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 1357 | } |
| 1358 | |
| 1359 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) { |
| 1360 | std::vector<std::string> transport_options; |
| 1361 | transport_options.push_back(kIceOption1); |
| 1362 | transport_options.push_back(kIceOption3); |
| 1363 | AddIceOptions(kAudioContentName, transport_options); |
| 1364 | transport_options.clear(); |
| 1365 | transport_options.push_back(kIceOption2); |
| 1366 | transport_options.push_back(kIceOption3); |
| 1367 | AddIceOptions(kVideoContentName, transport_options); |
| 1368 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1369 | jdesc_.session_id(), |
| 1370 | jdesc_.session_version())); |
| 1371 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 1372 | std::string sdp_with_ice_options = kSdpFullString; |
| 1373 | InjectAfter(kAttributeIcePwdVoice, |
| 1374 | "a=ice-options:iceoption1 iceoption3\r\n", |
| 1375 | &sdp_with_ice_options); |
| 1376 | InjectAfter(kAttributeIcePwdVideo, |
| 1377 | "a=ice-options:iceoption2 iceoption3\r\n", |
| 1378 | &sdp_with_ice_options); |
| 1379 | EXPECT_EQ(sdp_with_ice_options, message); |
| 1380 | } |
| 1381 | |
| 1382 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) { |
| 1383 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY)); |
| 1384 | } |
| 1385 | |
| 1386 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) { |
| 1387 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY)); |
| 1388 | } |
| 1389 | |
| 1390 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) { |
| 1391 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE)); |
| 1392 | } |
| 1393 | |
| 1394 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) { |
| 1395 | EXPECT_TRUE(TestSerializeRejected(true, false)); |
| 1396 | } |
| 1397 | |
| 1398 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) { |
| 1399 | EXPECT_TRUE(TestSerializeRejected(false, true)); |
| 1400 | } |
| 1401 | |
| 1402 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) { |
| 1403 | EXPECT_TRUE(TestSerializeRejected(true, true)); |
| 1404 | } |
| 1405 | |
| 1406 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) { |
| 1407 | AddRtpDataChannel(); |
| 1408 | JsepSessionDescription jsep_desc(kDummyString); |
| 1409 | |
| 1410 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1411 | std::string message = webrtc::SdpSerialize(jsep_desc); |
| 1412 | |
| 1413 | std::string expected_sdp = kSdpString; |
| 1414 | expected_sdp.append(kSdpRtpDataChannelString); |
| 1415 | EXPECT_EQ(expected_sdp, message); |
| 1416 | } |
| 1417 | |
| 1418 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) { |
| 1419 | AddSctpDataChannel(); |
| 1420 | JsepSessionDescription jsep_desc(kDummyString); |
| 1421 | |
| 1422 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1423 | std::string message = webrtc::SdpSerialize(jsep_desc); |
| 1424 | |
| 1425 | std::string expected_sdp = kSdpString; |
| 1426 | expected_sdp.append(kSdpSctpDataChannelString); |
| 1427 | EXPECT_EQ(message, expected_sdp); |
| 1428 | } |
| 1429 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame^] | 1430 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) { |
| 1431 | AddRtpDataChannel(); |
| 1432 | data_desc_->set_bandwidth(100*1000); |
| 1433 | JsepSessionDescription jsep_desc(kDummyString); |
| 1434 | |
| 1435 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1436 | std::string message = webrtc::SdpSerialize(jsep_desc); |
| 1437 | |
| 1438 | std::string expected_sdp = kSdpString; |
| 1439 | expected_sdp.append(kSdpRtpDataChannelString); |
| 1440 | // We want to test that serializing data content ignores bandwidth |
| 1441 | // settings (it should always be the default). Thus, we don't do |
| 1442 | // the following: |
| 1443 | // InjectAfter("a=mid:data_content_name\r\n", |
| 1444 | // "b=AS:100\r\n", |
| 1445 | // &expected_sdp); |
| 1446 | EXPECT_EQ(message, expected_sdp); |
| 1447 | } |
| 1448 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1449 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { |
| 1450 | AddExtmap(); |
| 1451 | JsepSessionDescription desc_with_extmap("dummy"); |
| 1452 | ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(), |
| 1453 | kSessionId, kSessionVersion)); |
| 1454 | std::string message = webrtc::SdpSerialize(desc_with_extmap); |
| 1455 | |
| 1456 | std::string sdp_with_extmap = kSdpString; |
| 1457 | InjectAfter("a=mid:audio_content_name\r\n", |
| 1458 | kExtmap, &sdp_with_extmap); |
| 1459 | InjectAfter("a=mid:video_content_name\r\n", |
| 1460 | kExtmap, &sdp_with_extmap); |
| 1461 | |
| 1462 | EXPECT_EQ(sdp_with_extmap, message); |
| 1463 | } |
| 1464 | |
| 1465 | |
| 1466 | TEST_F(WebRtcSdpTest, SerializeCandidates) { |
| 1467 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 1468 | EXPECT_EQ(std::string(kSdpOneCandidate), message); |
| 1469 | } |
| 1470 | |
| 1471 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
| 1472 | JsepSessionDescription jdesc(kDummyString); |
| 1473 | // Deserialize |
| 1474 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 1475 | // Verify |
| 1476 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 1477 | } |
| 1478 | |
| 1479 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
| 1480 | JsepSessionDescription jdesc(kDummyString); |
| 1481 | std::string sdp_without_carriage_return = kSdpFullString; |
| 1482 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 1483 | // Deserialize |
| 1484 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 1485 | // Verify |
| 1486 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 1487 | } |
| 1488 | |
| 1489 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 1490 | // SessionDescription with desc but without candidates. |
| 1491 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1492 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), |
| 1493 | kSessionId, kSessionVersion)); |
| 1494 | JsepSessionDescription new_jdesc(kDummyString); |
| 1495 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 1496 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 1497 | } |
| 1498 | |
| 1499 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 1500 | static const char kSdpNoRtpmapString[] = |
| 1501 | "v=0\r\n" |
| 1502 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 1503 | "s=-\r\n" |
| 1504 | "t=0 0\r\n" |
| 1505 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 1506 | // Codec that doesn't appear in the m= line will be ignored. |
| 1507 | "a=rtpmap:104 CELT/32000/2\r\n" |
| 1508 | // The rtpmap line for static payload codec is optional. |
| 1509 | "a=rtpmap:18 G729/16000\r\n" |
| 1510 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 1511 | |
| 1512 | JsepSessionDescription jdesc(kDummyString); |
| 1513 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 1514 | cricket::AudioContentDescription* audio = |
| 1515 | static_cast<AudioContentDescription*>( |
| 1516 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 1517 | AudioCodecs ref_codecs; |
| 1518 | // The codecs in the AudioContentDescription will be sorted by preference. |
| 1519 | ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1, 3)); |
| 1520 | ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1, 2)); |
| 1521 | ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1, 1)); |
| 1522 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 1523 | } |
| 1524 | |
| 1525 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 1526 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 1527 | // Add a DTLS a=fingerprint attribute to our session description. |
| 1528 | AddFingerprint(); |
| 1529 | JsepSessionDescription new_jdesc(kDummyString); |
| 1530 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 1531 | jdesc_.session_id(), |
| 1532 | jdesc_.session_version())); |
| 1533 | |
| 1534 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1535 | std::string sdp_with_fingerprint = kSdpString; |
| 1536 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 1537 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 1538 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 1539 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 1540 | } |
| 1541 | |
| 1542 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
| 1543 | JsepSessionDescription jdesc_with_bundle(kDummyString); |
| 1544 | std::string sdp_with_bundle = kSdpFullString; |
| 1545 | InjectAfter(kSessionTime, |
| 1546 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 1547 | &sdp_with_bundle); |
| 1548 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 1549 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1550 | group.AddContentName(kAudioContentName); |
| 1551 | group.AddContentName(kVideoContentName); |
| 1552 | desc_.AddGroup(group); |
| 1553 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1554 | jdesc_.session_id(), |
| 1555 | jdesc_.session_version())); |
| 1556 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 1557 | } |
| 1558 | |
| 1559 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
| 1560 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 1561 | std::string sdp_with_bandwidth = kSdpFullString; |
| 1562 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 1563 | "b=AS:100\r\n", |
| 1564 | &sdp_with_bandwidth); |
| 1565 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 1566 | "b=AS:50\r\n", |
| 1567 | &sdp_with_bandwidth); |
| 1568 | EXPECT_TRUE( |
| 1569 | SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 1570 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 1571 | GetFirstVideoContent(&desc_)->description); |
| 1572 | vcd->set_bandwidth(100 * 1000); |
| 1573 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 1574 | GetFirstAudioContent(&desc_)->description); |
| 1575 | acd->set_bandwidth(50 * 1000); |
| 1576 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1577 | jdesc_.session_id(), |
| 1578 | jdesc_.session_version())); |
| 1579 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 1580 | } |
| 1581 | |
| 1582 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
| 1583 | JsepSessionDescription jdesc_with_ice_options(kDummyString); |
| 1584 | std::string sdp_with_ice_options = kSdpFullString; |
| 1585 | InjectAfter(kSessionTime, |
| 1586 | "a=ice-options:iceoption3\r\n", |
| 1587 | &sdp_with_ice_options); |
| 1588 | InjectAfter(kAttributeIcePwdVoice, |
| 1589 | "a=ice-options:iceoption1\r\n", |
| 1590 | &sdp_with_ice_options); |
| 1591 | InjectAfter(kAttributeIcePwdVideo, |
| 1592 | "a=ice-options:iceoption2\r\n", |
| 1593 | &sdp_with_ice_options); |
| 1594 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 1595 | std::vector<std::string> transport_options; |
| 1596 | transport_options.push_back(kIceOption3); |
| 1597 | transport_options.push_back(kIceOption1); |
| 1598 | AddIceOptions(kAudioContentName, transport_options); |
| 1599 | transport_options.clear(); |
| 1600 | transport_options.push_back(kIceOption3); |
| 1601 | transport_options.push_back(kIceOption2); |
| 1602 | AddIceOptions(kVideoContentName, transport_options); |
| 1603 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1604 | jdesc_.session_id(), |
| 1605 | jdesc_.session_version())); |
| 1606 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 1607 | } |
| 1608 | |
| 1609 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 1610 | // Remove the original ice-ufrag and ice-pwd |
| 1611 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString); |
| 1612 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 1613 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 1614 | // Add session level ufrag and pwd |
| 1615 | InjectAfter(kSessionTime, |
| 1616 | "a=ice-pwd:session+level+icepwd\r\n" |
| 1617 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 1618 | &sdp_with_ufrag_pwd); |
| 1619 | // Add media level ufrag and pwd for audio |
| 1620 | InjectAfter("a=mid:audio_content_name\r\n", |
| 1621 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 1622 | &sdp_with_ufrag_pwd); |
| 1623 | // Update the candidate ufrag and pwd to the expected ones. |
| 1624 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, |
| 1625 | "media+level+iceufrag", "media+level+icepwd")); |
| 1626 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, |
| 1627 | "session+level+iceufrag", "session+level+icepwd")); |
| 1628 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 1629 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 1630 | } |
| 1631 | |
| 1632 | |
| 1633 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
| 1634 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY)); |
| 1635 | } |
| 1636 | |
| 1637 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
| 1638 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY)); |
| 1639 | } |
| 1640 | |
| 1641 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
| 1642 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE)); |
| 1643 | } |
| 1644 | |
| 1645 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 1646 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 1647 | } |
| 1648 | |
| 1649 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 1650 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 1651 | } |
| 1652 | |
| 1653 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 1654 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 1655 | } |
| 1656 | |
| 1657 | // Tests that we can still handle the sdp uses mslabel and label instead of |
| 1658 | // msid for backward compatibility. |
| 1659 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) { |
| 1660 | JsepSessionDescription jdesc(kDummyString); |
| 1661 | std::string sdp_without_msid = kSdpFullString; |
| 1662 | Replace("msid", "xmsid", &sdp_without_msid); |
| 1663 | // Deserialize |
| 1664 | EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc)); |
| 1665 | // Verify |
| 1666 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 1667 | } |
| 1668 | |
| 1669 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 1670 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 1671 | |
| 1672 | std::string sdp = kSdpOneCandidate; |
| 1673 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 1674 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 1675 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 1676 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 1677 | |
| 1678 | // Candidate line without generation extension. |
| 1679 | sdp = kSdpOneCandidate; |
| 1680 | Replace(" generation 2", "", &sdp); |
| 1681 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 1682 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 1683 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 1684 | Candidate expected = jcandidate_->candidate(); |
| 1685 | expected.set_generation(0); |
| 1686 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 1687 | |
| 1688 | // Multiple candidate lines. |
| 1689 | // Only the first line will be deserialized. The rest will be ignored. |
| 1690 | sdp = kSdpOneCandidate; |
| 1691 | sdp.append("a=candidate:1 2 tcp 1234 192.168.1.100 5678 typ host\r\n"); |
| 1692 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 1693 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 1694 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 1695 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 1696 | } |
| 1697 | |
| 1698 | // This test verifies the deserialization of candidate-attribute |
| 1699 | // as per RFC 5245. Candiate-attribute will be of the format |
| 1700 | // candidate:<blah>. This format will be used when candidates |
| 1701 | // are trickled. |
| 1702 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 1703 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 1704 | |
| 1705 | std::string candidate_attribute = kRawCandidate; |
| 1706 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 1707 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 1708 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 1709 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 1710 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 1711 | |
| 1712 | // Candidate line without generation extension. |
| 1713 | candidate_attribute = kRawCandidate; |
| 1714 | Replace(" generation 2", "", &candidate_attribute); |
| 1715 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 1716 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 1717 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 1718 | Candidate expected = jcandidate_->candidate(); |
| 1719 | expected.set_generation(0); |
| 1720 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 1721 | |
| 1722 | // Candidate line without candidate: |
| 1723 | candidate_attribute = kRawCandidate; |
| 1724 | Replace("candidate:", "", &candidate_attribute); |
| 1725 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 1726 | |
| 1727 | // Concatenating additional candidate. Expecting deserialization to fail. |
| 1728 | candidate_attribute = kRawCandidate; |
| 1729 | candidate_attribute.append("candidate:1 2 udp 1234 192.168.1.1 typ host"); |
| 1730 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 1731 | } |
| 1732 | |
| 1733 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) { |
| 1734 | AddRtpDataChannel(); |
| 1735 | JsepSessionDescription jdesc(kDummyString); |
| 1736 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1737 | |
| 1738 | std::string sdp_with_data = kSdpString; |
| 1739 | sdp_with_data.append(kSdpRtpDataChannelString); |
| 1740 | JsepSessionDescription jdesc_output(kDummyString); |
| 1741 | |
| 1742 | // Deserialize |
| 1743 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 1744 | // Verify |
| 1745 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 1746 | } |
| 1747 | |
| 1748 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
| 1749 | AddSctpDataChannel(); |
| 1750 | JsepSessionDescription jdesc(kDummyString); |
| 1751 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1752 | |
| 1753 | std::string sdp_with_data = kSdpString; |
| 1754 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 1755 | JsepSessionDescription jdesc_output(kDummyString); |
| 1756 | |
| 1757 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 1758 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 1759 | } |
| 1760 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame^] | 1761 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) { |
| 1762 | AddRtpDataChannel(); |
| 1763 | JsepSessionDescription jdesc(kDummyString); |
| 1764 | // We want to test that deserializing data content ignores bandwidth |
| 1765 | // settings (it should always be the default). Thus, we don't do |
| 1766 | // the following: |
| 1767 | // DataContentDescription* dcd = static_cast<DataContentDescription*>( |
| 1768 | // GetFirstDataContent(&desc_)->description); |
| 1769 | // dcd->set_bandwidth(100 * 1000); |
| 1770 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1771 | |
| 1772 | std::string sdp_with_bandwidth = kSdpString; |
| 1773 | sdp_with_bandwidth.append(kSdpRtpDataChannelString); |
| 1774 | InjectAfter("a=mid:data_content_name\r\n", |
| 1775 | "b=AS:100\r\n", |
| 1776 | &sdp_with_bandwidth); |
| 1777 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 1778 | |
| 1779 | EXPECT_TRUE( |
| 1780 | SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 1781 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 1782 | } |
| 1783 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1784 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { |
| 1785 | TestDeserializeExtmap(true, false); |
| 1786 | } |
| 1787 | |
| 1788 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
| 1789 | TestDeserializeExtmap(false, true); |
| 1790 | } |
| 1791 | |
| 1792 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
| 1793 | TestDeserializeExtmap(true, true); |
| 1794 | } |
| 1795 | |
| 1796 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 1797 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 1798 | std::string new_sdp = kSdpOneCandidate; |
| 1799 | Replace("udp", "unsupported_transport", &new_sdp); |
| 1800 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 1801 | new_sdp = kSdpOneCandidate; |
| 1802 | Replace("udp", "uDP", &new_sdp); |
| 1803 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 1804 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 1805 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 1806 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 1807 | } |
| 1808 | |
| 1809 | TEST_F(WebRtcSdpTest, DeserializeCandidateOldFormat) { |
| 1810 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 1811 | EXPECT_TRUE(SdpDeserializeCandidate(kSdpOneCandidateOldFormat,&jcandidate)); |
| 1812 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 1813 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 1814 | Candidate ref_candidate = jcandidate_->candidate(); |
| 1815 | ref_candidate.set_username("user_rtp"); |
| 1816 | ref_candidate.set_password("password_rtp"); |
| 1817 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 1818 | } |
| 1819 | |
| 1820 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 1821 | const char kSdpDestroyer[] = "!@#$%^&"; |
| 1822 | const char kSdpInvalidLine1[] = " =candidate"; |
| 1823 | const char kSdpInvalidLine2[] = "a+candidate"; |
| 1824 | const char kSdpInvalidLine3[] = "a= candidate"; |
| 1825 | // Broken fingerprint. |
| 1826 | const char kSdpInvalidLine4[] = "a=fingerprint:sha-1 " |
| 1827 | "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
| 1828 | // Extra field. |
| 1829 | const char kSdpInvalidLine5[] = "a=fingerprint:sha-1 " |
| 1830 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX"; |
| 1831 | // Missing space. |
| 1832 | const char kSdpInvalidLine6[] = "a=fingerprint:sha-1" |
| 1833 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
| 1834 | |
| 1835 | // Broken session description |
| 1836 | ReplaceAndTryToParse("v=", kSdpDestroyer); |
| 1837 | ReplaceAndTryToParse("o=", kSdpDestroyer); |
| 1838 | ReplaceAndTryToParse("s=-", kSdpDestroyer); |
| 1839 | // Broken time description |
| 1840 | ReplaceAndTryToParse("t=", kSdpDestroyer); |
| 1841 | |
| 1842 | // Broken media description |
| 1843 | ReplaceAndTryToParse("m=video", kSdpDestroyer); |
| 1844 | |
| 1845 | // Invalid lines |
| 1846 | ReplaceAndTryToParse("a=candidate", kSdpInvalidLine1); |
| 1847 | ReplaceAndTryToParse("a=candidate", kSdpInvalidLine2); |
| 1848 | ReplaceAndTryToParse("a=candidate", kSdpInvalidLine3); |
| 1849 | |
| 1850 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 1851 | // because it's orthogonal to what we are replacing and hence |
| 1852 | // safe. |
| 1853 | ReplaceAndTryToParse("a=sendrecv", kSdpInvalidLine4); |
| 1854 | ReplaceAndTryToParse("a=sendrecv", kSdpInvalidLine5); |
| 1855 | ReplaceAndTryToParse("a=sendrecv", kSdpInvalidLine6); |
| 1856 | } |
| 1857 | |
| 1858 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
| 1859 | JsepSessionDescription jdesc_output(kDummyString); |
| 1860 | |
| 1861 | const char kSdpWithReorderedPlTypesString[] = |
| 1862 | "v=0\r\n" |
| 1863 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1864 | "s=-\r\n" |
| 1865 | "t=0 0\r\n" |
| 1866 | "m=audio 1 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred. |
| 1867 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 1868 | // in the map. |
| 1869 | "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map. |
| 1870 | "a=rtpmap:104 CELT/32000/2\r\n"; |
| 1871 | |
| 1872 | // Deserialize |
| 1873 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 1874 | |
| 1875 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description()); |
| 1876 | ASSERT_TRUE(ac != NULL); |
| 1877 | const AudioContentDescription* acd = |
| 1878 | static_cast<const AudioContentDescription*>(ac->description); |
| 1879 | ASSERT_FALSE(acd->codecs().empty()); |
| 1880 | EXPECT_EQ("CELT", acd->codecs()[0].name); |
| 1881 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 1882 | } |
| 1883 | |
| 1884 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
| 1885 | JsepSessionDescription jdesc_output(kDummyString); |
| 1886 | CodecParams params; |
| 1887 | params.max_ptime = 40; |
| 1888 | params.ptime = 30; |
| 1889 | params.min_ptime = 10; |
| 1890 | params.sprop_stereo = 1; |
| 1891 | params.stereo = 1; |
| 1892 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1893 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1894 | TestDeserializeCodecParams(params, &jdesc_output); |
| 1895 | TestSerialize(jdesc_output); |
| 1896 | } |
| 1897 | |
| 1898 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 1899 | const bool kUseWildcard = false; |
| 1900 | JsepSessionDescription jdesc_output(kDummyString); |
| 1901 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
| 1902 | TestSerialize(jdesc_output); |
| 1903 | } |
| 1904 | |
| 1905 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 1906 | const bool kUseWildcard = true; |
| 1907 | JsepSessionDescription jdesc_output(kDummyString); |
| 1908 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
| 1909 | TestSerialize(jdesc_output); |
| 1910 | } |
| 1911 | |
| 1912 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
| 1913 | JsepSessionDescription jdesc_output(kDummyString); |
| 1914 | |
| 1915 | const char kSdpWithFmtpString[] = |
| 1916 | "v=0\r\n" |
| 1917 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1918 | "s=-\r\n" |
| 1919 | "t=0 0\r\n" |
| 1920 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 1921 | "a=rtpmap:120 VP8/90000\r\n" |
| 1922 | "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n"; |
| 1923 | |
| 1924 | // Deserialize |
| 1925 | SdpParseError error; |
| 1926 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, |
| 1927 | &error)); |
| 1928 | |
| 1929 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 1930 | ASSERT_TRUE(vc != NULL); |
| 1931 | const VideoContentDescription* vcd = |
| 1932 | static_cast<const VideoContentDescription*>(vc->description); |
| 1933 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1934 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1935 | EXPECT_EQ("VP8", vp8.name); |
| 1936 | EXPECT_EQ(120, vp8.id); |
| 1937 | cricket::CodecParameterMap::iterator found = |
| 1938 | vp8.params.find("x-google-min-bitrate"); |
| 1939 | ASSERT_TRUE(found != vp8.params.end()); |
| 1940 | EXPECT_EQ(found->second, "10"); |
| 1941 | found = vp8.params.find("x-google-max-quantization"); |
| 1942 | ASSERT_TRUE(found != vp8.params.end()); |
| 1943 | EXPECT_EQ(found->second, "40"); |
| 1944 | } |
| 1945 | |
| 1946 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
| 1947 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 1948 | GetFirstVideoContent(&desc_)->description); |
| 1949 | |
| 1950 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 1951 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 1952 | vcd->set_codecs(codecs); |
| 1953 | |
| 1954 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1955 | jdesc_.session_id(), |
| 1956 | jdesc_.session_version())); |
| 1957 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 1958 | std::string sdp_with_fmtp = kSdpFullString; |
| 1959 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
| 1960 | "a=fmtp:120 x-google-min-bitrate=10\r\n", |
| 1961 | &sdp_with_fmtp); |
| 1962 | EXPECT_EQ(sdp_with_fmtp, message); |
| 1963 | } |
| 1964 | |
| 1965 | TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) { |
| 1966 | JsepSessionDescription jdesc_with_icelite(kDummyString); |
| 1967 | std::string sdp_with_icelite = kSdpFullString; |
| 1968 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 1969 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 1970 | const cricket::TransportInfo* tinfo1 = |
| 1971 | desc->GetTransportInfoByName("audio_content_name"); |
| 1972 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 1973 | const cricket::TransportInfo* tinfo2 = |
| 1974 | desc->GetTransportInfoByName("video_content_name"); |
| 1975 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
| 1976 | InjectAfter(kSessionTime, |
| 1977 | "a=ice-lite\r\n", |
| 1978 | &sdp_with_icelite); |
| 1979 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 1980 | desc = jdesc_with_icelite.description(); |
| 1981 | const cricket::TransportInfo* atinfo = |
| 1982 | desc->GetTransportInfoByName("audio_content_name"); |
| 1983 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 1984 | const cricket::TransportInfo* vtinfo = |
| 1985 | desc->GetTransportInfoByName("video_content_name"); |
| 1986 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
| 1987 | } |
| 1988 | |
| 1989 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 1990 | // correctly in the output SDP. |
| 1991 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 1992 | std::string sdp_with_data = kSdpString; |
| 1993 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
| 1994 | JsepSessionDescription jdesc_output(kDummyString); |
| 1995 | |
| 1996 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 1997 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output)); |
| 1998 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 1999 | |
| 2000 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 2001 | AddFingerprint(); |
| 2002 | TransportInfo audio_transport_info = |
| 2003 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 2004 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2005 | audio_transport_info.description.connection_role); |
| 2006 | audio_transport_info.description.connection_role = |
| 2007 | cricket::CONNECTIONROLE_ACTIVE; |
| 2008 | |
| 2009 | TransportInfo video_transport_info = |
| 2010 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 2011 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 2012 | video_transport_info.description.connection_role); |
| 2013 | video_transport_info.description.connection_role = |
| 2014 | cricket::CONNECTIONROLE_ACTIVE; |
| 2015 | |
| 2016 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 2017 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 2018 | |
| 2019 | desc_.AddTransportInfo(audio_transport_info); |
| 2020 | desc_.AddTransportInfo(video_transport_info); |
| 2021 | |
| 2022 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2023 | jdesc_.session_id(), |
| 2024 | jdesc_.session_version())); |
| 2025 | std::string message = webrtc::SdpSerialize(jdesc_); |
| 2026 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 2027 | |
| 2028 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
| 2029 | InjectAfter(kAttributeIcePwdVoice, |
| 2030 | kFingerprint, &sdp_with_dtlssetup); |
| 2031 | InjectAfter(kAttributeIcePwdVideo, |
| 2032 | kFingerprint, &sdp_with_dtlssetup); |
| 2033 | // Now adding |setup| attribute. |
| 2034 | InjectAfter(kFingerprint, |
| 2035 | "a=setup:active\r\n", &sdp_with_dtlssetup); |
| 2036 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 2037 | } |
| 2038 | |
| 2039 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) { |
| 2040 | JsepSessionDescription jdesc_with_dtlssetup(kDummyString); |
| 2041 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 2042 | InjectAfter(kSessionTime, |
| 2043 | "a=setup:actpass\r\n", |
| 2044 | &sdp_with_dtlssetup); |
| 2045 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 2046 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 2047 | const cricket::TransportInfo* atinfo = |
| 2048 | desc->GetTransportInfoByName("audio_content_name"); |
| 2049 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 2050 | atinfo->description.connection_role); |
| 2051 | const cricket::TransportInfo* vtinfo = |
| 2052 | desc->GetTransportInfoByName("video_content_name"); |
| 2053 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 2054 | vtinfo->description.connection_role); |
| 2055 | } |