henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 11 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | #include <set> |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 16 | #include "webrtc/api/jsepsessiondescription.h" |
| 17 | #ifdef WEBRTC_ANDROID |
| 18 | #include "webrtc/api/test/androidtestinitializer.h" |
| 19 | #endif |
| 20 | #include "webrtc/api/webrtcsdp.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 21 | #include "webrtc/base/gunit.h" |
| 22 | #include "webrtc/base/logging.h" |
| 23 | #include "webrtc/base/messagedigest.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 24 | #include "webrtc/base/sslfingerprint.h" |
| 25 | #include "webrtc/base/stringencode.h" |
| 26 | #include "webrtc/base/stringutils.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 27 | #include "webrtc/media/base/mediaconstants.h" |
hta | a6b9944 | 2016-04-12 10:29:17 -0700 | [diff] [blame] | 28 | #include "webrtc/media/engine/webrtcvideoengine2.h" |
| 29 | #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 30 | #include "webrtc/p2p/base/p2pconstants.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 31 | #include "webrtc/pc/mediasession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | |
| 33 | using cricket::AudioCodec; |
| 34 | using cricket::AudioContentDescription; |
| 35 | using cricket::Candidate; |
| 36 | using cricket::ContentInfo; |
| 37 | using cricket::CryptoParams; |
| 38 | using cricket::ContentGroup; |
| 39 | using cricket::DataCodec; |
| 40 | using cricket::DataContentDescription; |
| 41 | using cricket::ICE_CANDIDATE_COMPONENT_RTCP; |
| 42 | using cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 43 | using cricket::kFecSsrcGroupSemantics; |
| 44 | using cricket::LOCAL_PORT_TYPE; |
| 45 | using cricket::NS_JINGLE_DRAFT_SCTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | using cricket::NS_JINGLE_RTP; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | using cricket::RELAY_PORT_TYPE; |
| 48 | using cricket::SessionDescription; |
| 49 | using cricket::StreamParams; |
| 50 | using cricket::STUN_PORT_TYPE; |
| 51 | using cricket::TransportDescription; |
| 52 | using cricket::TransportInfo; |
| 53 | using cricket::VideoCodec; |
| 54 | using cricket::VideoContentDescription; |
| 55 | using webrtc::IceCandidateCollection; |
| 56 | using webrtc::IceCandidateInterface; |
| 57 | using webrtc::JsepIceCandidate; |
| 58 | using webrtc::JsepSessionDescription; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 59 | using webrtc::RtpExtension; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | using webrtc::SdpParseError; |
| 61 | using webrtc::SessionDescriptionInterface; |
| 62 | |
| 63 | typedef std::vector<AudioCodec> AudioCodecs; |
| 64 | typedef std::vector<Candidate> Candidates; |
| 65 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 66 | static const uint32_t kDefaultSctpPort = 5000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | static const char kSessionTime[] = "t=0 0\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 68 | static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 69 | static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 71 | static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 73 | static const uint32_t kCandidateGeneration = 2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | static const char kCandidateFoundation1[] = "a0+B/1"; |
| 75 | static const char kCandidateFoundation2[] = "a0+B/2"; |
| 76 | static const char kCandidateFoundation3[] = "a0+B/3"; |
| 77 | static const char kCandidateFoundation4[] = "a0+B/4"; |
| 78 | static const char kAttributeCryptoVoice[] = |
| 79 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 80 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 81 | "dummy_session_params\r\n"; |
| 82 | static const char kAttributeCryptoVideo[] = |
| 83 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 84 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"; |
| 85 | static const char kFingerprint[] = "a=fingerprint:sha-1 " |
| 86 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"; |
| 87 | static const int kExtmapId = 1; |
| 88 | static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime"; |
| 89 | static const char kExtmap[] = |
| 90 | "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n"; |
| 91 | static const char kExtmapWithDirectionAndAttribute[] = |
| 92 | "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n"; |
| 93 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 94 | static const uint8_t kIdentityDigest[] = { |
| 95 | 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02, |
| 96 | 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | |
lally@webrtc.org | 3480728 | 2015-02-24 20:19:39 +0000 | [diff] [blame] | 98 | static const char kDtlsSctp[] = "DTLS/SCTP"; |
| 99 | static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; |
| 100 | static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 101 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | struct CodecParams { |
| 103 | int max_ptime; |
| 104 | int ptime; |
| 105 | int min_ptime; |
| 106 | int sprop_stereo; |
| 107 | int stereo; |
| 108 | int useinband; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 109 | int maxaveragebitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 112 | // TODO(deadbeef): In these reference strings, use "a=fingerprint" by default |
| 113 | // instead of "a=crypto", and have an explicit test for adding "a=crypto". |
| 114 | // Currently it's the other way around. |
| 115 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | // Reference sdp string |
| 117 | static const char kSdpFullString[] = |
| 118 | "v=0\r\n" |
| 119 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 120 | "s=-\r\n" |
| 121 | "t=0 0\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 122 | "a=msid-semantic: WMS local_stream_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 124 | "c=IN IP4 74.125.127.126\r\n" |
| 125 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 126 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 127 | "generation 2\r\n" |
| 128 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 129 | "generation 2\r\n" |
| 130 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 131 | "generation 2\r\n" |
| 132 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 133 | "generation 2\r\n" |
| 134 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 135 | "raddr 192.168.1.5 rport 2346 " |
| 136 | "generation 2\r\n" |
| 137 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 138 | "raddr 192.168.1.5 rport 2348 " |
| 139 | "generation 2\r\n" |
| 140 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 141 | "a=mid:audio_content_name\r\n" |
| 142 | "a=sendrecv\r\n" |
| 143 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 144 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 146 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 147 | "dummy_session_params\r\n" |
| 148 | "a=rtpmap:111 opus/48000/2\r\n" |
| 149 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 150 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 151 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 152 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 153 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 154 | "a=ssrc:1 label:audio_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 156 | "c=IN IP4 74.125.224.39\r\n" |
| 157 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 158 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 159 | "generation 2\r\n" |
| 160 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 161 | "generation 2\r\n" |
| 162 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 163 | "generation 2\r\n" |
| 164 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 165 | "generation 2\r\n" |
| 166 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 167 | "generation 2\r\n" |
| 168 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 169 | "generation 2\r\n" |
| 170 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 171 | "a=mid:video_content_name\r\n" |
| 172 | "a=sendrecv\r\n" |
| 173 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 174 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 175 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 176 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 178 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 179 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 180 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 181 | "a=ssrc:3 cname:stream_1_cname\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 182 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 184 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | |
| 186 | // SDP reference string without the candidates. |
| 187 | static const char kSdpString[] = |
| 188 | "v=0\r\n" |
| 189 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 190 | "s=-\r\n" |
| 191 | "t=0 0\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 192 | "a=msid-semantic: WMS local_stream_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 193 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 194 | "c=IN IP4 0.0.0.0\r\n" |
| 195 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 197 | "a=mid:audio_content_name\r\n" |
| 198 | "a=sendrecv\r\n" |
| 199 | "a=rtcp-mux\r\n" |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 200 | "a=rtcp-rsize\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 202 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 203 | "dummy_session_params\r\n" |
| 204 | "a=rtpmap:111 opus/48000/2\r\n" |
| 205 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 206 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 208 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 209 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 210 | "a=ssrc:1 label:audio_track_id_1\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 211 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 212 | "c=IN IP4 0.0.0.0\r\n" |
| 213 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 214 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 215 | "a=mid:video_content_name\r\n" |
| 216 | "a=sendrecv\r\n" |
| 217 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 218 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 219 | "a=rtpmap:120 VP8/90000\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 220 | "a=ssrc-group:FEC 2 3\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 222 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 223 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 224 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 225 | "a=ssrc:3 cname:stream_1_cname\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 226 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 228 | "a=ssrc:3 label:video_track_id_1\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | |
| 230 | static const char kSdpRtpDataChannelString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 231 | "m=application 9 RTP/SAVPF 101\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 232 | "c=IN IP4 0.0.0.0\r\n" |
| 233 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | "a=ice-ufrag:ufrag_data\r\n" |
| 235 | "a=ice-pwd:pwd_data\r\n" |
| 236 | "a=mid:data_content_name\r\n" |
| 237 | "a=sendrecv\r\n" |
| 238 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 239 | "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5\r\n" |
| 240 | "a=rtpmap:101 google-data/90000\r\n" |
| 241 | "a=ssrc:10 cname:data_channel_cname\r\n" |
| 242 | "a=ssrc:10 msid:data_channel data_channeld0\r\n" |
| 243 | "a=ssrc:10 mslabel:data_channel\r\n" |
| 244 | "a=ssrc:10 label:data_channeld0\r\n"; |
| 245 | |
| 246 | static const char kSdpSctpDataChannelString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 247 | "m=application 9 DTLS/SCTP 5000\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 248 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 249 | "a=ice-ufrag:ufrag_data\r\n" |
| 250 | "a=ice-pwd:pwd_data\r\n" |
| 251 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 252 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | |
lally@webrtc.org | ec97c65 | 2015-02-24 20:18:48 +0000 | [diff] [blame] | 254 | // draft-ietf-mmusic-sctp-sdp-12 |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 255 | static const char kSdpSctpDataChannelStringWithSctpPort[] = |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 256 | "m=application 9 DTLS/SCTP webrtc-datachannel\r\n" |
| 257 | "a=max-message-size=100000\r\n" |
| 258 | "a=sctp-port 5000\r\n" |
| 259 | "c=IN IP4 0.0.0.0\r\n" |
| 260 | "a=ice-ufrag:ufrag_data\r\n" |
| 261 | "a=ice-pwd:pwd_data\r\n" |
| 262 | "a=mid:data_content_name\r\n"; |
| 263 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 264 | static const char kSdpSctpDataChannelStringWithSctpColonPort[] = |
| 265 | "m=application 9 DTLS/SCTP webrtc-datachannel\r\n" |
| 266 | "a=max-message-size=100000\r\n" |
| 267 | "a=sctp-port:5000\r\n" |
| 268 | "c=IN IP4 0.0.0.0\r\n" |
| 269 | "a=ice-ufrag:ufrag_data\r\n" |
| 270 | "a=ice-pwd:pwd_data\r\n" |
| 271 | "a=mid:data_content_name\r\n"; |
| 272 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 273 | static const char kSdpSctpDataChannelWithCandidatesString[] = |
| 274 | "m=application 2345 DTLS/SCTP 5000\r\n" |
| 275 | "c=IN IP4 74.125.127.126\r\n" |
| 276 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 277 | "generation 2\r\n" |
| 278 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 279 | "generation 2\r\n" |
| 280 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 281 | "raddr 192.168.1.5 rport 2346 " |
| 282 | "generation 2\r\n" |
| 283 | "a=ice-ufrag:ufrag_data\r\n" |
| 284 | "a=ice-pwd:pwd_data\r\n" |
| 285 | "a=mid:data_content_name\r\n" |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 286 | "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 288 | static const char kSdpConferenceString[] = |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 289 | "v=0\r\n" |
| 290 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 291 | "s=-\r\n" |
| 292 | "t=0 0\r\n" |
| 293 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 294 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 295 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 296 | "a=x-google-flag:conference\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 297 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 298 | "c=IN IP4 0.0.0.0\r\n" |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 299 | "a=x-google-flag:conference\r\n"; |
| 300 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 301 | static const char kSdpSessionString[] = |
| 302 | "v=0\r\n" |
| 303 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 304 | "s=-\r\n" |
| 305 | "t=0 0\r\n" |
| 306 | "a=msid-semantic: WMS local_stream\r\n"; |
| 307 | |
| 308 | static const char kSdpAudioString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 309 | "m=audio 9 RTP/SAVPF 111\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 310 | "c=IN IP4 0.0.0.0\r\n" |
| 311 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 312 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 313 | "a=mid:audio_content_name\r\n" |
| 314 | "a=sendrecv\r\n" |
| 315 | "a=rtpmap:111 opus/48000/2\r\n" |
| 316 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 317 | "a=ssrc:1 msid:local_stream audio_track_id_1\r\n" |
| 318 | "a=ssrc:1 mslabel:local_stream\r\n" |
| 319 | "a=ssrc:1 label:audio_track_id_1\r\n"; |
| 320 | |
| 321 | static const char kSdpVideoString[] = |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 322 | "m=video 9 RTP/SAVPF 120\r\n" |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 323 | "c=IN IP4 0.0.0.0\r\n" |
| 324 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 325 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 326 | "a=mid:video_content_name\r\n" |
| 327 | "a=sendrecv\r\n" |
| 328 | "a=rtpmap:120 VP8/90000\r\n" |
| 329 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 330 | "a=ssrc:2 msid:local_stream video_track_id_1\r\n" |
| 331 | "a=ssrc:2 mslabel:local_stream\r\n" |
| 332 | "a=ssrc:2 label:video_track_id_1\r\n"; |
| 333 | |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 334 | // Reference sdp string using bundle-only. |
| 335 | static const char kBundleOnlySdpFullString[] = |
| 336 | "v=0\r\n" |
| 337 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 338 | "s=-\r\n" |
| 339 | "t=0 0\r\n" |
| 340 | "a=group:BUNDLE audio_content_name video_content_name\r\n" |
| 341 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 342 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 343 | "c=IN IP4 74.125.127.126\r\n" |
| 344 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 345 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 346 | "generation 2\r\n" |
| 347 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 348 | "generation 2\r\n" |
| 349 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 350 | "generation 2\r\n" |
| 351 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 352 | "generation 2\r\n" |
| 353 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 354 | "raddr 192.168.1.5 rport 2346 " |
| 355 | "generation 2\r\n" |
| 356 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 357 | "raddr 192.168.1.5 rport 2348 " |
| 358 | "generation 2\r\n" |
| 359 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 360 | "a=mid:audio_content_name\r\n" |
| 361 | "a=sendrecv\r\n" |
| 362 | "a=rtcp-mux\r\n" |
| 363 | "a=rtcp-rsize\r\n" |
| 364 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 365 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 366 | "dummy_session_params\r\n" |
| 367 | "a=rtpmap:111 opus/48000/2\r\n" |
| 368 | "a=rtpmap:103 ISAC/16000\r\n" |
| 369 | "a=rtpmap:104 ISAC/32000\r\n" |
| 370 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 371 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 372 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 373 | "a=ssrc:1 label:audio_track_id_1\r\n" |
| 374 | "m=video 0 RTP/SAVPF 120\r\n" |
| 375 | "c=IN IP4 0.0.0.0\r\n" |
| 376 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 377 | "a=bundle-only\r\n" |
| 378 | "a=mid:video_content_name\r\n" |
| 379 | "a=sendrecv\r\n" |
| 380 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 381 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 382 | "a=rtpmap:120 VP8/90000\r\n" |
| 383 | "a=ssrc-group:FEC 2 3\r\n" |
| 384 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 385 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 386 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 387 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 388 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 389 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 390 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 391 | "a=ssrc:3 label:video_track_id_1\r\n"; |
| 392 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 393 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 394 | // tracks. |
| 395 | static const char kPlanBSdpFullString[] = |
| 396 | "v=0\r\n" |
| 397 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 398 | "s=-\r\n" |
| 399 | "t=0 0\r\n" |
| 400 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 401 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 402 | "c=IN IP4 74.125.127.126\r\n" |
| 403 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 404 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 405 | "generation 2\r\n" |
| 406 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 407 | "generation 2\r\n" |
| 408 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 409 | "generation 2\r\n" |
| 410 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 411 | "generation 2\r\n" |
| 412 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 413 | "raddr 192.168.1.5 rport 2346 " |
| 414 | "generation 2\r\n" |
| 415 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 416 | "raddr 192.168.1.5 rport 2348 " |
| 417 | "generation 2\r\n" |
| 418 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 419 | "a=mid:audio_content_name\r\n" |
| 420 | "a=sendrecv\r\n" |
| 421 | "a=rtcp-mux\r\n" |
| 422 | "a=rtcp-rsize\r\n" |
| 423 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 424 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 425 | "dummy_session_params\r\n" |
| 426 | "a=rtpmap:111 opus/48000/2\r\n" |
| 427 | "a=rtpmap:103 ISAC/16000\r\n" |
| 428 | "a=rtpmap:104 ISAC/32000\r\n" |
| 429 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 430 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 431 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 432 | "a=ssrc:1 label:audio_track_id_1\r\n" |
| 433 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 434 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
| 435 | "a=ssrc:4 mslabel:local_stream_2\r\n" |
| 436 | "a=ssrc:4 label:audio_track_id_2\r\n" |
| 437 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 438 | "c=IN IP4 74.125.224.39\r\n" |
| 439 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 440 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 441 | "generation 2\r\n" |
| 442 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 443 | "generation 2\r\n" |
| 444 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 445 | "generation 2\r\n" |
| 446 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 447 | "generation 2\r\n" |
| 448 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 449 | "generation 2\r\n" |
| 450 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 451 | "generation 2\r\n" |
| 452 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 453 | "a=mid:video_content_name\r\n" |
| 454 | "a=sendrecv\r\n" |
| 455 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 456 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 457 | "a=rtpmap:120 VP8/90000\r\n" |
| 458 | "a=ssrc-group:FEC 2 3\r\n" |
| 459 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 460 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 461 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 462 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 463 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 464 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 465 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 466 | "a=ssrc:3 label:video_track_id_1\r\n" |
| 467 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 468 | "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n" |
| 469 | "a=ssrc:5 mslabel:local_stream_2\r\n" |
| 470 | "a=ssrc:5 label:video_track_id_2\r\n" |
| 471 | "a=ssrc:6 cname:stream_2_cname\r\n" |
| 472 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n" |
| 473 | "a=ssrc:6 mslabel:local_stream_2\r\n" |
| 474 | "a=ssrc:6 label:video_track_id_3\r\n"; |
| 475 | |
Taylor Brandstetter | 5de6b75 | 2016-03-09 17:02:30 -0800 | [diff] [blame] | 476 | // Plan B SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 477 | // tracks, but with the unified plan "a=msid" attribute. |
| 478 | static const char kPlanBSdpFullStringWithMsid[] = |
| 479 | "v=0\r\n" |
| 480 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 481 | "s=-\r\n" |
| 482 | "t=0 0\r\n" |
| 483 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n" |
| 484 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 485 | "c=IN IP4 74.125.127.126\r\n" |
| 486 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 487 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 488 | "generation 2\r\n" |
| 489 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 490 | "generation 2\r\n" |
| 491 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 492 | "generation 2\r\n" |
| 493 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 494 | "generation 2\r\n" |
| 495 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 496 | "raddr 192.168.1.5 rport 2346 " |
| 497 | "generation 2\r\n" |
| 498 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 499 | "raddr 192.168.1.5 rport 2348 " |
| 500 | "generation 2\r\n" |
| 501 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 502 | "a=mid:audio_content_name\r\n" |
| 503 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 504 | "a=sendrecv\r\n" |
| 505 | "a=rtcp-mux\r\n" |
| 506 | "a=rtcp-rsize\r\n" |
| 507 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 508 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 509 | "dummy_session_params\r\n" |
| 510 | "a=rtpmap:111 opus/48000/2\r\n" |
| 511 | "a=rtpmap:103 ISAC/16000\r\n" |
| 512 | "a=rtpmap:104 ISAC/32000\r\n" |
| 513 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 514 | "a=ssrc:1 msid:local_stream_1 audio_track_id_1\r\n" |
| 515 | "a=ssrc:1 mslabel:local_stream_1\r\n" |
| 516 | "a=ssrc:1 label:audio_track_id_1\r\n" |
| 517 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 518 | "a=ssrc:4 msid:local_stream_2 audio_track_id_2\r\n" |
| 519 | "a=ssrc:4 mslabel:local_stream_2\r\n" |
| 520 | "a=ssrc:4 label:audio_track_id_2\r\n" |
| 521 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 522 | "c=IN IP4 74.125.224.39\r\n" |
| 523 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 524 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 525 | "generation 2\r\n" |
| 526 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 527 | "generation 2\r\n" |
| 528 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 529 | "generation 2\r\n" |
| 530 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 531 | "generation 2\r\n" |
| 532 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 533 | "generation 2\r\n" |
| 534 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 535 | "generation 2\r\n" |
| 536 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 537 | "a=mid:video_content_name\r\n" |
| 538 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 539 | "a=sendrecv\r\n" |
| 540 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 541 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 542 | "a=rtpmap:120 VP8/90000\r\n" |
| 543 | "a=ssrc-group:FEC 2 3\r\n" |
| 544 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 545 | "a=ssrc:2 msid:local_stream_1 video_track_id_1\r\n" |
| 546 | "a=ssrc:2 mslabel:local_stream_1\r\n" |
| 547 | "a=ssrc:2 label:video_track_id_1\r\n" |
| 548 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 549 | "a=ssrc:3 msid:local_stream_1 video_track_id_1\r\n" |
| 550 | "a=ssrc:3 mslabel:local_stream_1\r\n" |
| 551 | "a=ssrc:3 label:video_track_id_1\r\n" |
| 552 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 553 | "a=ssrc:5 msid:local_stream_2 video_track_id_2\r\n" |
| 554 | "a=ssrc:5 mslabel:local_stream_2\r\n" |
| 555 | "a=ssrc:5 label:video_track_id_2\r\n" |
| 556 | "a=ssrc:6 cname:stream_2_cname\r\n" |
| 557 | "a=ssrc:6 msid:local_stream_2 video_track_id_3\r\n" |
| 558 | "a=ssrc:6 mslabel:local_stream_2\r\n" |
| 559 | "a=ssrc:6 label:video_track_id_3\r\n"; |
| 560 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 561 | // Unified Plan SDP reference string, with 2 streams, 2 audio tracks and 3 video |
| 562 | // tracks. |
| 563 | static const char kUnifiedPlanSdpFullString[] = |
| 564 | "v=0\r\n" |
| 565 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 566 | "s=-\r\n" |
| 567 | "t=0 0\r\n" |
| 568 | "a=msid-semantic: WMS local_stream_1\r\n" |
| 569 | // Audio track 1, stream 1 (with candidates). |
| 570 | "m=audio 2345 RTP/SAVPF 111 103 104\r\n" |
| 571 | "c=IN IP4 74.125.127.126\r\n" |
| 572 | "a=rtcp:2347 IN IP4 74.125.127.126\r\n" |
| 573 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 574 | "generation 2\r\n" |
| 575 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1235 typ host " |
| 576 | "generation 2\r\n" |
| 577 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1238 typ host " |
| 578 | "generation 2\r\n" |
| 579 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1239 typ host " |
| 580 | "generation 2\r\n" |
| 581 | "a=candidate:a0+B/3 1 udp 2130706432 74.125.127.126 2345 typ srflx " |
| 582 | "raddr 192.168.1.5 rport 2346 " |
| 583 | "generation 2\r\n" |
| 584 | "a=candidate:a0+B/3 2 udp 2130706432 74.125.127.126 2347 typ srflx " |
| 585 | "raddr 192.168.1.5 rport 2348 " |
| 586 | "generation 2\r\n" |
| 587 | "a=ice-ufrag:ufrag_voice\r\na=ice-pwd:pwd_voice\r\n" |
| 588 | "a=mid:audio_content_name\r\n" |
| 589 | "a=msid:local_stream_1 audio_track_id_1\r\n" |
| 590 | "a=sendrecv\r\n" |
| 591 | "a=rtcp-mux\r\n" |
| 592 | "a=rtcp-rsize\r\n" |
| 593 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 594 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 595 | "dummy_session_params\r\n" |
| 596 | "a=rtpmap:111 opus/48000/2\r\n" |
| 597 | "a=rtpmap:103 ISAC/16000\r\n" |
| 598 | "a=rtpmap:104 ISAC/32000\r\n" |
| 599 | "a=ssrc:1 cname:stream_1_cname\r\n" |
| 600 | // Video track 1, stream 1 (with candidates). |
| 601 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 602 | "c=IN IP4 74.125.224.39\r\n" |
| 603 | "a=rtcp:3456 IN IP4 74.125.224.39\r\n" |
| 604 | "a=candidate:a0+B/1 2 udp 2130706432 192.168.1.5 1236 typ host " |
| 605 | "generation 2\r\n" |
| 606 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1237 typ host " |
| 607 | "generation 2\r\n" |
| 608 | "a=candidate:a0+B/2 2 udp 2130706432 ::1 1240 typ host " |
| 609 | "generation 2\r\n" |
| 610 | "a=candidate:a0+B/2 1 udp 2130706432 ::1 1241 typ host " |
| 611 | "generation 2\r\n" |
| 612 | "a=candidate:a0+B/4 2 udp 2130706432 74.125.224.39 3456 typ relay " |
| 613 | "generation 2\r\n" |
| 614 | "a=candidate:a0+B/4 1 udp 2130706432 74.125.224.39 3457 typ relay " |
| 615 | "generation 2\r\n" |
| 616 | "a=ice-ufrag:ufrag_video\r\na=ice-pwd:pwd_video\r\n" |
| 617 | "a=mid:video_content_name\r\n" |
| 618 | "a=msid:local_stream_1 video_track_id_1\r\n" |
| 619 | "a=sendrecv\r\n" |
| 620 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 621 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 622 | "a=rtpmap:120 VP8/90000\r\n" |
| 623 | "a=ssrc-group:FEC 2 3\r\n" |
| 624 | "a=ssrc:2 cname:stream_1_cname\r\n" |
| 625 | "a=ssrc:3 cname:stream_1_cname\r\n" |
| 626 | // Audio track 2, stream 2. |
| 627 | "m=audio 9 RTP/SAVPF 111 103 104\r\n" |
| 628 | "c=IN IP4 0.0.0.0\r\n" |
| 629 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 630 | "a=ice-ufrag:ufrag_voice_2\r\na=ice-pwd:pwd_voice_2\r\n" |
| 631 | "a=mid:audio_content_name_2\r\n" |
| 632 | "a=msid:local_stream_2 audio_track_id_2\r\n" |
| 633 | "a=sendrecv\r\n" |
| 634 | "a=rtcp-mux\r\n" |
| 635 | "a=rtcp-rsize\r\n" |
| 636 | "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 637 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 638 | "dummy_session_params\r\n" |
| 639 | "a=rtpmap:111 opus/48000/2\r\n" |
| 640 | "a=rtpmap:103 ISAC/16000\r\n" |
| 641 | "a=rtpmap:104 ISAC/32000\r\n" |
| 642 | "a=ssrc:4 cname:stream_2_cname\r\n" |
| 643 | // Video track 2, stream 2. |
| 644 | "m=video 9 RTP/SAVPF 120\r\n" |
| 645 | "c=IN IP4 0.0.0.0\r\n" |
| 646 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 647 | "a=ice-ufrag:ufrag_video_2\r\na=ice-pwd:pwd_video_2\r\n" |
| 648 | "a=mid:video_content_name_2\r\n" |
| 649 | "a=msid:local_stream_2 video_track_id_2\r\n" |
| 650 | "a=sendrecv\r\n" |
| 651 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 652 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 653 | "a=rtpmap:120 VP8/90000\r\n" |
| 654 | "a=ssrc:5 cname:stream_2_cname\r\n" |
| 655 | // Video track 3, stream 2. |
| 656 | "m=video 9 RTP/SAVPF 120\r\n" |
| 657 | "c=IN IP4 0.0.0.0\r\n" |
| 658 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 659 | "a=ice-ufrag:ufrag_video_3\r\na=ice-pwd:pwd_video_3\r\n" |
| 660 | "a=mid:video_content_name_3\r\n" |
| 661 | "a=msid:local_stream_2 video_track_id_3\r\n" |
| 662 | "a=sendrecv\r\n" |
| 663 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 664 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n" |
| 665 | "a=rtpmap:120 VP8/90000\r\n" |
| 666 | "a=ssrc:6 cname:stream_2_cname\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 667 | |
| 668 | // One candidate reference string as per W3c spec. |
| 669 | // candidate:<blah> not a=candidate:<blah>CRLF |
| 670 | static const char kRawCandidate[] = |
| 671 | "candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host generation 2"; |
| 672 | // One candidate reference string. |
| 673 | static const char kSdpOneCandidate[] = |
| 674 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host " |
| 675 | "generation 2\r\n"; |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 676 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 677 | static const char kSdpTcpActiveCandidate[] = |
| 678 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 679 | "tcptype active generation 2"; |
| 680 | static const char kSdpTcpPassiveCandidate[] = |
| 681 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 682 | "tcptype passive generation 2"; |
| 683 | static const char kSdpTcpSOCandidate[] = |
| 684 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 685 | "tcptype so generation 2"; |
| 686 | static const char kSdpTcpInvalidCandidate[] = |
| 687 | "candidate:a0+B/1 1 tcp 2130706432 192.168.1.5 9 typ host " |
| 688 | "tcptype invalid generation 2"; |
| 689 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 690 | // One candidate reference string with IPV6 address. |
| 691 | static const char kRawIPV6Candidate[] = |
| 692 | "candidate:a0+B/1 1 udp 2130706432 " |
| 693 | "abcd::abcd::abcd::abcd::abcd::abcd::abcd::abcd 1234 typ host generation 2"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 694 | |
| 695 | // One candidate reference string. |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 696 | static const char kSdpOneCandidateWithUfragPwd[] = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 697 | "a=candidate:a0+B/1 1 udp 2130706432 192.168.1.5 1234 typ host network_name" |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 698 | " eth0 ufrag user_rtp pwd password_rtp generation 2\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 699 | |
| 700 | // Session id and version |
| 701 | static const char kSessionId[] = "18446744069414584320"; |
| 702 | static const char kSessionVersion[] = "18446462598732840960"; |
| 703 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 704 | // ICE options. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 705 | static const char kIceOption1[] = "iceoption1"; |
| 706 | static const char kIceOption2[] = "iceoption2"; |
| 707 | static const char kIceOption3[] = "iceoption3"; |
| 708 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 709 | // ICE ufrags/passwords. |
| 710 | static const char kUfragVoice[] = "ufrag_voice"; |
| 711 | static const char kPwdVoice[] = "pwd_voice"; |
| 712 | static const char kUfragVideo[] = "ufrag_video"; |
| 713 | static const char kPwdVideo[] = "pwd_video"; |
| 714 | static const char kUfragData[] = "ufrag_data"; |
| 715 | static const char kPwdData[] = "pwd_data"; |
| 716 | |
| 717 | // Extra ufrags/passwords for extra unified plan m= sections. |
| 718 | static const char kUfragVoice2[] = "ufrag_voice_2"; |
| 719 | static const char kPwdVoice2[] = "pwd_voice_2"; |
| 720 | static const char kUfragVideo2[] = "ufrag_video_2"; |
| 721 | static const char kPwdVideo2[] = "pwd_video_2"; |
| 722 | static const char kUfragVideo3[] = "ufrag_video_3"; |
| 723 | static const char kPwdVideo3[] = "pwd_video_3"; |
| 724 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 725 | // Content name |
| 726 | static const char kAudioContentName[] = "audio_content_name"; |
| 727 | static const char kVideoContentName[] = "video_content_name"; |
| 728 | static const char kDataContentName[] = "data_content_name"; |
| 729 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 730 | // Extra content names for extra unified plan m= sections. |
| 731 | static const char kAudioContentName2[] = "audio_content_name_2"; |
| 732 | static const char kVideoContentName2[] = "video_content_name_2"; |
| 733 | static const char kVideoContentName3[] = "video_content_name_3"; |
| 734 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 735 | // MediaStream 1 |
| 736 | static const char kStreamLabel1[] = "local_stream_1"; |
| 737 | static const char kStream1Cname[] = "stream_1_cname"; |
| 738 | static const char kAudioTrackId1[] = "audio_track_id_1"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 739 | static const uint32_t kAudioTrack1Ssrc = 1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 740 | static const char kVideoTrackId1[] = "video_track_id_1"; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 741 | static const uint32_t kVideoTrack1Ssrc1 = 2; |
| 742 | static const uint32_t kVideoTrack1Ssrc2 = 3; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 743 | |
| 744 | // MediaStream 2 |
| 745 | static const char kStreamLabel2[] = "local_stream_2"; |
| 746 | static const char kStream2Cname[] = "stream_2_cname"; |
| 747 | static const char kAudioTrackId2[] = "audio_track_id_2"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 748 | static const uint32_t kAudioTrack2Ssrc = 4; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 749 | static const char kVideoTrackId2[] = "video_track_id_2"; |
| 750 | static const uint32_t kVideoTrack2Ssrc = 5; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 751 | static const char kVideoTrackId3[] = "video_track_id_3"; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 752 | static const uint32_t kVideoTrack3Ssrc = 6; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 753 | |
| 754 | // DataChannel |
| 755 | static const char kDataChannelLabel[] = "data_channel"; |
| 756 | static const char kDataChannelMsid[] = "data_channeld0"; |
| 757 | static const char kDataChannelCname[] = "data_channel_cname"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 758 | static const uint32_t kDataChannelSsrc = 10; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 759 | |
| 760 | // Candidate |
| 761 | static const char kDummyMid[] = "dummy_mid"; |
| 762 | static const int kDummyIndex = 123; |
| 763 | |
| 764 | // Misc |
| 765 | static const char kDummyString[] = "dummy"; |
| 766 | |
| 767 | // Helper functions |
| 768 | |
| 769 | static bool SdpDeserialize(const std::string& message, |
| 770 | JsepSessionDescription* jdesc) { |
| 771 | return webrtc::SdpDeserialize(message, jdesc, NULL); |
| 772 | } |
| 773 | |
| 774 | static bool SdpDeserializeCandidate(const std::string& message, |
| 775 | JsepIceCandidate* candidate) { |
| 776 | return webrtc::SdpDeserializeCandidate(message, candidate, NULL); |
| 777 | } |
| 778 | |
| 779 | // Add some extra |newlines| to the |message| after |line|. |
| 780 | static void InjectAfter(const std::string& line, |
| 781 | const std::string& newlines, |
| 782 | std::string* message) { |
| 783 | const std::string tmp = line + newlines; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 784 | rtc::replace_substrs(line.c_str(), line.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 785 | tmp.c_str(), tmp.length(), message); |
| 786 | } |
| 787 | |
| 788 | static void Replace(const std::string& line, |
| 789 | const std::string& newlines, |
| 790 | std::string* message) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 791 | rtc::replace_substrs(line.c_str(), line.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 792 | newlines.c_str(), newlines.length(), message); |
| 793 | } |
| 794 | |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 795 | // Expect fail to parase |bad_sdp| and expect |bad_part| be part of the error |
| 796 | // message. |
| 797 | static void ExpectParseFailure(const std::string& bad_sdp, |
| 798 | const std::string& bad_part) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 799 | JsepSessionDescription desc(kDummyString); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 800 | SdpParseError error; |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 801 | bool ret = webrtc::SdpDeserialize(bad_sdp, &desc, &error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 802 | EXPECT_FALSE(ret); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 803 | EXPECT_NE(std::string::npos, error.line.find(bad_part.c_str())); |
| 804 | } |
| 805 | |
| 806 | // Expect fail to parse kSdpFullString if replace |good_part| with |bad_part|. |
| 807 | static void ExpectParseFailure(const char* good_part, const char* bad_part) { |
| 808 | std::string bad_sdp = kSdpFullString; |
| 809 | Replace(good_part, bad_part, &bad_sdp); |
| 810 | ExpectParseFailure(bad_sdp, bad_part); |
| 811 | } |
| 812 | |
| 813 | // Expect fail to parse kSdpFullString if add |newlines| after |injectpoint|. |
| 814 | static void ExpectParseFailureWithNewLines(const std::string& injectpoint, |
| 815 | const std::string& newlines, |
| 816 | const std::string& bad_part) { |
| 817 | std::string bad_sdp = kSdpFullString; |
| 818 | InjectAfter(injectpoint, newlines, &bad_sdp); |
| 819 | ExpectParseFailure(bad_sdp, bad_part); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static void ReplaceDirection(cricket::MediaContentDirection direction, |
| 823 | std::string* message) { |
| 824 | std::string new_direction; |
| 825 | switch (direction) { |
| 826 | case cricket::MD_INACTIVE: |
| 827 | new_direction = "a=inactive"; |
| 828 | break; |
| 829 | case cricket::MD_SENDONLY: |
| 830 | new_direction = "a=sendonly"; |
| 831 | break; |
| 832 | case cricket::MD_RECVONLY: |
| 833 | new_direction = "a=recvonly"; |
| 834 | break; |
| 835 | case cricket::MD_SENDRECV: |
| 836 | default: |
| 837 | new_direction = "a=sendrecv"; |
| 838 | break; |
| 839 | } |
| 840 | Replace("a=sendrecv", new_direction, message); |
| 841 | } |
| 842 | |
| 843 | static void ReplaceRejected(bool audio_rejected, bool video_rejected, |
| 844 | std::string* message) { |
| 845 | if (audio_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 846 | Replace("m=audio 9", "m=audio 0", message); |
| 847 | Replace(kAttributeIceUfragVoice, "", message); |
| 848 | Replace(kAttributeIcePwdVoice, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 849 | } |
| 850 | if (video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 851 | Replace("m=video 9", "m=video 0", message); |
| 852 | Replace(kAttributeIceUfragVideo, "", message); |
| 853 | Replace(kAttributeIcePwdVideo, "", message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | |
| 857 | // WebRtcSdpTest |
| 858 | |
| 859 | class WebRtcSdpTest : public testing::Test { |
| 860 | public: |
| 861 | WebRtcSdpTest() |
| 862 | : jdesc_(kDummyString) { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 863 | #ifdef WEBRTC_ANDROID |
| 864 | webrtc::InitializeAndroidObjects(); |
| 865 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 866 | // AudioContentDescription |
| 867 | audio_desc_ = CreateAudioContentDescription(); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 868 | StreamParams audio_stream; |
| 869 | audio_stream.id = kAudioTrackId1; |
| 870 | audio_stream.cname = kStream1Cname; |
| 871 | audio_stream.sync_label = kStreamLabel1; |
| 872 | audio_stream.ssrcs.push_back(kAudioTrack1Ssrc); |
| 873 | audio_desc_->AddStream(audio_stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 874 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 875 | |
| 876 | // VideoContentDescription |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 877 | video_desc_ = CreateVideoContentDescription(); |
| 878 | StreamParams video_stream; |
| 879 | video_stream.id = kVideoTrackId1; |
| 880 | video_stream.cname = kStream1Cname; |
| 881 | video_stream.sync_label = kStreamLabel1; |
| 882 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc1); |
| 883 | video_stream.ssrcs.push_back(kVideoTrack1Ssrc2); |
| 884 | cricket::SsrcGroup ssrc_group(kFecSsrcGroupSemantics, video_stream.ssrcs); |
| 885 | video_stream.ssrc_groups.push_back(ssrc_group); |
| 886 | video_desc_->AddStream(video_stream); |
| 887 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 888 | |
| 889 | // TransportInfo |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 890 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 891 | kAudioContentName, TransportDescription(kUfragVoice, kPwdVoice)))); |
| 892 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 893 | kVideoContentName, TransportDescription(kUfragVideo, kPwdVideo)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 894 | |
| 895 | // v4 host |
| 896 | int port = 1234; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 897 | rtc::SocketAddress address("192.168.1.5", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 898 | Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 899 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 900 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 902 | Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 903 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 904 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 905 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 906 | Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 907 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 908 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 909 | address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 910 | Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 911 | kCandidatePriority, "", "", LOCAL_PORT_TYPE, |
| 912 | kCandidateGeneration, kCandidateFoundation1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 913 | |
| 914 | // v6 host |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 915 | rtc::SocketAddress v6_address("::1", port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 916 | cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 917 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 918 | cricket::LOCAL_PORT_TYPE, |
| 919 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 920 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 921 | cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 922 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 923 | cricket::LOCAL_PORT_TYPE, |
| 924 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 925 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 926 | cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 927 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 928 | cricket::LOCAL_PORT_TYPE, |
| 929 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 930 | v6_address.SetPort(port++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 931 | cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 932 | v6_address, kCandidatePriority, "", "", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 933 | cricket::LOCAL_PORT_TYPE, |
| 934 | kCandidateGeneration, kCandidateFoundation2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 935 | |
| 936 | // stun |
| 937 | int port_stun = 2345; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 938 | rtc::SocketAddress address_stun("74.125.127.126", port_stun++); |
| 939 | rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 940 | cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 941 | address_stun, kCandidatePriority, "", "", |
| 942 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 943 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 944 | candidate9.set_related_address(rel_address_stun); |
| 945 | |
| 946 | address_stun.SetPort(port_stun++); |
| 947 | rel_address_stun.SetPort(port_stun++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 948 | cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 949 | address_stun, kCandidatePriority, "", "", |
| 950 | STUN_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 951 | kCandidateFoundation3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 952 | candidate10.set_related_address(rel_address_stun); |
| 953 | |
| 954 | // relay |
| 955 | int port_relay = 3456; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 956 | rtc::SocketAddress address_relay("74.125.224.39", port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 957 | cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp", |
| 958 | address_relay, kCandidatePriority, "", "", |
| 959 | cricket::RELAY_PORT_TYPE, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 960 | kCandidateGeneration, kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 961 | address_relay.SetPort(port_relay++); |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 962 | cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 963 | address_relay, kCandidatePriority, "", "", |
| 964 | RELAY_PORT_TYPE, kCandidateGeneration, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 965 | kCandidateFoundation4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 966 | |
| 967 | // voice |
| 968 | candidates_.push_back(candidate1); |
| 969 | candidates_.push_back(candidate2); |
| 970 | candidates_.push_back(candidate5); |
| 971 | candidates_.push_back(candidate6); |
| 972 | candidates_.push_back(candidate9); |
| 973 | candidates_.push_back(candidate10); |
| 974 | |
| 975 | // video |
| 976 | candidates_.push_back(candidate3); |
| 977 | candidates_.push_back(candidate4); |
| 978 | candidates_.push_back(candidate7); |
| 979 | candidates_.push_back(candidate8); |
| 980 | candidates_.push_back(candidate11); |
| 981 | candidates_.push_back(candidate12); |
| 982 | |
| 983 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), |
| 984 | 0, candidate1)); |
| 985 | |
| 986 | // Set up JsepSessionDescription. |
| 987 | jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion); |
| 988 | std::string mline_id; |
| 989 | int mline_index = 0; |
| 990 | for (size_t i = 0; i< candidates_.size(); ++i) { |
| 991 | // In this test, the audio m line index will be 0, and the video m line |
| 992 | // will be 1. |
| 993 | bool is_video = (i > 5); |
| 994 | mline_id = is_video ? "video_content_name" : "audio_content_name"; |
| 995 | mline_index = is_video ? 1 : 0; |
| 996 | JsepIceCandidate jice(mline_id, |
| 997 | mline_index, |
| 998 | candidates_.at(i)); |
| 999 | jdesc_.AddCandidate(&jice); |
| 1000 | } |
| 1001 | } |
| 1002 | |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 1003 | // Turns the existing reference description into a description using |
| 1004 | // a=bundle-only. This means no transport attributes and a 0 port value on |
| 1005 | // the m= sections not associated with the BUNDLE-tag. |
| 1006 | void MakeBundleOnlyDescription() { |
| 1007 | // Remove video candidates. JsepSessionDescription doesn't make it |
| 1008 | // simple. |
| 1009 | const IceCandidateCollection* video_candidates_collection = |
| 1010 | jdesc_.candidates(1); |
| 1011 | ASSERT_NE(nullptr, video_candidates_collection); |
| 1012 | std::vector<cricket::Candidate> video_candidates; |
| 1013 | for (size_t i = 0; i < video_candidates_collection->count(); ++i) { |
| 1014 | cricket::Candidate c = video_candidates_collection->at(i)->candidate(); |
| 1015 | c.set_transport_name("video_content_name"); |
| 1016 | video_candidates.push_back(c); |
| 1017 | } |
| 1018 | jdesc_.RemoveCandidates(video_candidates); |
| 1019 | |
| 1020 | // And the rest of the transport attributes. |
| 1021 | desc_.transport_infos()[1].description.ice_ufrag.clear(); |
| 1022 | desc_.transport_infos()[1].description.ice_pwd.clear(); |
| 1023 | desc_.transport_infos()[1].description.connection_role = |
| 1024 | cricket::CONNECTIONROLE_NONE; |
| 1025 | |
| 1026 | // Set bundle-only flag. |
| 1027 | desc_.contents()[1].bundle_only = true; |
| 1028 | |
| 1029 | // Add BUNDLE group. |
| 1030 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1031 | group.AddContentName(kAudioContentName); |
| 1032 | group.AddContentName(kVideoContentName); |
| 1033 | desc_.AddGroup(group); |
| 1034 | |
| 1035 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1036 | jdesc_.session_version())); |
| 1037 | } |
| 1038 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1039 | // Turns the existing reference description into a plan B description, |
| 1040 | // with 2 audio tracks and 3 video tracks. |
| 1041 | void MakePlanBDescription() { |
| 1042 | audio_desc_ = static_cast<AudioContentDescription*>(audio_desc_->Copy()); |
| 1043 | video_desc_ = static_cast<VideoContentDescription*>(video_desc_->Copy()); |
| 1044 | |
| 1045 | StreamParams audio_track_2; |
| 1046 | audio_track_2.id = kAudioTrackId2; |
| 1047 | audio_track_2.cname = kStream2Cname; |
| 1048 | audio_track_2.sync_label = kStreamLabel2; |
| 1049 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1050 | audio_desc_->AddStream(audio_track_2); |
| 1051 | |
| 1052 | StreamParams video_track_2; |
| 1053 | video_track_2.id = kVideoTrackId2; |
| 1054 | video_track_2.cname = kStream2Cname; |
| 1055 | video_track_2.sync_label = kStreamLabel2; |
| 1056 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 1057 | video_desc_->AddStream(video_track_2); |
| 1058 | |
| 1059 | StreamParams video_track_3; |
| 1060 | video_track_3.id = kVideoTrackId3; |
| 1061 | video_track_3.cname = kStream2Cname; |
| 1062 | video_track_3.sync_label = kStreamLabel2; |
| 1063 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 1064 | video_desc_->AddStream(video_track_3); |
| 1065 | |
| 1066 | desc_.RemoveContentByName(kAudioContentName); |
| 1067 | desc_.RemoveContentByName(kVideoContentName); |
| 1068 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 1069 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
| 1070 | |
| 1071 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1072 | jdesc_.session_version())); |
| 1073 | } |
| 1074 | |
| 1075 | // Turns the existing reference description into a unified plan description, |
| 1076 | // with 2 audio tracks and 3 video tracks. |
| 1077 | void MakeUnifiedPlanDescription() { |
| 1078 | // Audio track 2. |
| 1079 | AudioContentDescription* audio_desc_2 = CreateAudioContentDescription(); |
| 1080 | StreamParams audio_track_2; |
| 1081 | audio_track_2.id = kAudioTrackId2; |
| 1082 | audio_track_2.cname = kStream2Cname; |
| 1083 | audio_track_2.sync_label = kStreamLabel2; |
| 1084 | audio_track_2.ssrcs.push_back(kAudioTrack2Ssrc); |
| 1085 | audio_desc_2->AddStream(audio_track_2); |
| 1086 | desc_.AddContent(kAudioContentName2, NS_JINGLE_RTP, audio_desc_2); |
| 1087 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1088 | kAudioContentName2, TransportDescription(kUfragVoice2, kPwdVoice2)))); |
| 1089 | |
| 1090 | // Video track 2, in stream 2. |
| 1091 | VideoContentDescription* video_desc_2 = CreateVideoContentDescription(); |
| 1092 | StreamParams video_track_2; |
| 1093 | video_track_2.id = kVideoTrackId2; |
| 1094 | video_track_2.cname = kStream2Cname; |
| 1095 | video_track_2.sync_label = kStreamLabel2; |
| 1096 | video_track_2.ssrcs.push_back(kVideoTrack2Ssrc); |
| 1097 | video_desc_2->AddStream(video_track_2); |
| 1098 | desc_.AddContent(kVideoContentName2, NS_JINGLE_RTP, video_desc_2); |
| 1099 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1100 | kVideoContentName2, TransportDescription(kUfragVideo2, kPwdVideo2)))); |
| 1101 | |
| 1102 | // Video track 3, in stream 2. |
| 1103 | VideoContentDescription* video_desc_3 = CreateVideoContentDescription(); |
| 1104 | StreamParams video_track_3; |
| 1105 | video_track_3.id = kVideoTrackId3; |
| 1106 | video_track_3.cname = kStream2Cname; |
| 1107 | video_track_3.sync_label = kStreamLabel2; |
| 1108 | video_track_3.ssrcs.push_back(kVideoTrack3Ssrc); |
| 1109 | video_desc_3->AddStream(video_track_3); |
| 1110 | desc_.AddContent(kVideoContentName3, NS_JINGLE_RTP, video_desc_3); |
| 1111 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1112 | kVideoContentName3, TransportDescription(kUfragVideo3, kPwdVideo3)))); |
| 1113 | |
| 1114 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1115 | jdesc_.session_version())); |
| 1116 | } |
| 1117 | |
| 1118 | // Creates an audio content description with no streams, and some default |
| 1119 | // configuration. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1120 | AudioContentDescription* CreateAudioContentDescription() { |
| 1121 | AudioContentDescription* audio = new AudioContentDescription(); |
| 1122 | audio->set_rtcp_mux(true); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 1123 | audio->set_rtcp_reduced_size(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1124 | audio->AddCrypto(CryptoParams(1, "AES_CM_128_HMAC_SHA1_32", |
| 1125 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32", |
| 1126 | "dummy_session_params")); |
| 1127 | audio->set_protocol(cricket::kMediaProtocolSavpf); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1128 | AudioCodec opus(111, "opus", 48000, 0, 2); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1129 | audio->AddCodec(opus); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1130 | audio->AddCodec(AudioCodec(103, "ISAC", 16000, 32000, 1)); |
| 1131 | audio->AddCodec(AudioCodec(104, "ISAC", 32000, 56000, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1132 | return audio; |
| 1133 | } |
| 1134 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1135 | // Creates a video content description with no streams, and some default |
| 1136 | // configuration. |
| 1137 | VideoContentDescription* CreateVideoContentDescription() { |
| 1138 | VideoContentDescription* video = new VideoContentDescription(); |
| 1139 | video->AddCrypto(CryptoParams( |
| 1140 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 1141 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32", "")); |
| 1142 | video->set_protocol(cricket::kMediaProtocolSavpf); |
| 1143 | video->AddCodec( |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 1144 | VideoCodec(120, JsepSessionDescription::kDefaultVideoCodecName)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1145 | return video; |
| 1146 | } |
| 1147 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1148 | template <class MCD> |
| 1149 | void CompareMediaContentDescription(const MCD* cd1, |
| 1150 | const MCD* cd2) { |
| 1151 | // type |
| 1152 | EXPECT_EQ(cd1->type(), cd1->type()); |
| 1153 | |
| 1154 | // content direction |
| 1155 | EXPECT_EQ(cd1->direction(), cd2->direction()); |
| 1156 | |
| 1157 | // rtcp_mux |
| 1158 | EXPECT_EQ(cd1->rtcp_mux(), cd2->rtcp_mux()); |
| 1159 | |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 1160 | // rtcp_reduced_size |
| 1161 | EXPECT_EQ(cd1->rtcp_reduced_size(), cd2->rtcp_reduced_size()); |
| 1162 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1163 | // cryptos |
| 1164 | EXPECT_EQ(cd1->cryptos().size(), cd2->cryptos().size()); |
| 1165 | if (cd1->cryptos().size() != cd2->cryptos().size()) { |
| 1166 | ADD_FAILURE(); |
| 1167 | return; |
| 1168 | } |
| 1169 | for (size_t i = 0; i< cd1->cryptos().size(); ++i) { |
| 1170 | const CryptoParams c1 = cd1->cryptos().at(i); |
| 1171 | const CryptoParams c2 = cd2->cryptos().at(i); |
| 1172 | EXPECT_TRUE(c1.Matches(c2)); |
| 1173 | EXPECT_EQ(c1.key_params, c2.key_params); |
| 1174 | EXPECT_EQ(c1.session_params, c2.session_params); |
| 1175 | } |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1176 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1177 | // protocol |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1178 | // Use an equivalence class here, for old and new versions of the |
| 1179 | // protocol description. |
| 1180 | if (cd1->protocol() == cricket::kMediaProtocolDtlsSctp |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 1181 | || cd1->protocol() == cricket::kMediaProtocolUdpDtlsSctp |
| 1182 | || cd1->protocol() == cricket::kMediaProtocolTcpDtlsSctp) { |
| 1183 | const bool cd2_is_also_dtls_sctp = |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1184 | cd2->protocol() == cricket::kMediaProtocolDtlsSctp |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 1185 | || cd2->protocol() == cricket::kMediaProtocolUdpDtlsSctp |
| 1186 | || cd2->protocol() == cricket::kMediaProtocolTcpDtlsSctp; |
| 1187 | EXPECT_TRUE(cd2_is_also_dtls_sctp); |
lally@webrtc.org | d7b6165 | 2015-02-24 20:18:55 +0000 | [diff] [blame] | 1188 | } else { |
| 1189 | EXPECT_EQ(cd1->protocol(), cd2->protocol()); |
| 1190 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1191 | |
| 1192 | // codecs |
| 1193 | EXPECT_EQ(cd1->codecs(), cd2->codecs()); |
| 1194 | |
| 1195 | // bandwidth |
| 1196 | EXPECT_EQ(cd1->bandwidth(), cd2->bandwidth()); |
| 1197 | |
| 1198 | // streams |
| 1199 | EXPECT_EQ(cd1->streams(), cd2->streams()); |
| 1200 | |
| 1201 | // extmap |
| 1202 | ASSERT_EQ(cd1->rtp_header_extensions().size(), |
| 1203 | cd2->rtp_header_extensions().size()); |
| 1204 | for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1205 | const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); |
| 1206 | const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1207 | EXPECT_EQ(ext1.uri, ext2.uri); |
| 1208 | EXPECT_EQ(ext1.id, ext2.id); |
| 1209 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | void CompareSessionDescription(const SessionDescription& desc1, |
| 1214 | const SessionDescription& desc2) { |
| 1215 | // Compare content descriptions. |
| 1216 | if (desc1.contents().size() != desc2.contents().size()) { |
| 1217 | ADD_FAILURE(); |
| 1218 | return; |
| 1219 | } |
| 1220 | for (size_t i = 0 ; i < desc1.contents().size(); ++i) { |
| 1221 | const cricket::ContentInfo& c1 = desc1.contents().at(i); |
| 1222 | const cricket::ContentInfo& c2 = desc2.contents().at(i); |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 1223 | // ContentInfo properties. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1224 | EXPECT_EQ(c1.name, c2.name); |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 1225 | EXPECT_EQ(c1.type, c2.type); |
| 1226 | EXPECT_EQ(c1.rejected, c2.rejected); |
| 1227 | EXPECT_EQ(c1.bundle_only, c2.bundle_only); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1228 | |
| 1229 | ASSERT_EQ(IsAudioContent(&c1), IsAudioContent(&c2)); |
| 1230 | if (IsAudioContent(&c1)) { |
| 1231 | const AudioContentDescription* acd1 = |
| 1232 | static_cast<const AudioContentDescription*>(c1.description); |
| 1233 | const AudioContentDescription* acd2 = |
| 1234 | static_cast<const AudioContentDescription*>(c2.description); |
| 1235 | CompareMediaContentDescription<AudioContentDescription>(acd1, acd2); |
| 1236 | } |
| 1237 | |
| 1238 | ASSERT_EQ(IsVideoContent(&c1), IsVideoContent(&c2)); |
| 1239 | if (IsVideoContent(&c1)) { |
| 1240 | const VideoContentDescription* vcd1 = |
| 1241 | static_cast<const VideoContentDescription*>(c1.description); |
| 1242 | const VideoContentDescription* vcd2 = |
| 1243 | static_cast<const VideoContentDescription*>(c2.description); |
| 1244 | CompareMediaContentDescription<VideoContentDescription>(vcd1, vcd2); |
| 1245 | } |
| 1246 | |
| 1247 | ASSERT_EQ(IsDataContent(&c1), IsDataContent(&c2)); |
| 1248 | if (IsDataContent(&c1)) { |
| 1249 | const DataContentDescription* dcd1 = |
| 1250 | static_cast<const DataContentDescription*>(c1.description); |
| 1251 | const DataContentDescription* dcd2 = |
| 1252 | static_cast<const DataContentDescription*>(c2.description); |
| 1253 | CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | // group |
| 1258 | const cricket::ContentGroups groups1 = desc1.groups(); |
| 1259 | const cricket::ContentGroups groups2 = desc2.groups(); |
| 1260 | EXPECT_EQ(groups1.size(), groups1.size()); |
| 1261 | if (groups1.size() != groups2.size()) { |
| 1262 | ADD_FAILURE(); |
| 1263 | return; |
| 1264 | } |
| 1265 | for (size_t i = 0; i < groups1.size(); ++i) { |
| 1266 | const cricket::ContentGroup group1 = groups1.at(i); |
| 1267 | const cricket::ContentGroup group2 = groups2.at(i); |
| 1268 | EXPECT_EQ(group1.semantics(), group2.semantics()); |
| 1269 | const cricket::ContentNames names1 = group1.content_names(); |
| 1270 | const cricket::ContentNames names2 = group2.content_names(); |
| 1271 | EXPECT_EQ(names1.size(), names2.size()); |
| 1272 | if (names1.size() != names2.size()) { |
| 1273 | ADD_FAILURE(); |
| 1274 | return; |
| 1275 | } |
| 1276 | cricket::ContentNames::const_iterator iter1 = names1.begin(); |
| 1277 | cricket::ContentNames::const_iterator iter2 = names2.begin(); |
| 1278 | while (iter1 != names1.end()) { |
| 1279 | EXPECT_EQ(*iter1++, *iter2++); |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | // transport info |
| 1284 | const cricket::TransportInfos transports1 = desc1.transport_infos(); |
| 1285 | const cricket::TransportInfos transports2 = desc2.transport_infos(); |
| 1286 | EXPECT_EQ(transports1.size(), transports2.size()); |
| 1287 | if (transports1.size() != transports2.size()) { |
| 1288 | ADD_FAILURE(); |
| 1289 | return; |
| 1290 | } |
| 1291 | for (size_t i = 0; i < transports1.size(); ++i) { |
| 1292 | const cricket::TransportInfo transport1 = transports1.at(i); |
| 1293 | const cricket::TransportInfo transport2 = transports2.at(i); |
| 1294 | EXPECT_EQ(transport1.content_name, transport2.content_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1295 | EXPECT_EQ(transport1.description.ice_ufrag, |
| 1296 | transport2.description.ice_ufrag); |
| 1297 | EXPECT_EQ(transport1.description.ice_pwd, |
| 1298 | transport2.description.ice_pwd); |
| 1299 | if (transport1.description.identity_fingerprint) { |
| 1300 | EXPECT_EQ(*transport1.description.identity_fingerprint, |
| 1301 | *transport2.description.identity_fingerprint); |
| 1302 | } else { |
| 1303 | EXPECT_EQ(transport1.description.identity_fingerprint.get(), |
| 1304 | transport2.description.identity_fingerprint.get()); |
| 1305 | } |
| 1306 | EXPECT_EQ(transport1.description.transport_options, |
| 1307 | transport2.description.transport_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1308 | } |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1309 | |
| 1310 | // global attributes |
| 1311 | EXPECT_EQ(desc1.msid_supported(), desc2.msid_supported()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1314 | bool CompareSessionDescription( |
| 1315 | const JsepSessionDescription& desc1, |
| 1316 | const JsepSessionDescription& desc2) { |
| 1317 | EXPECT_EQ(desc1.session_id(), desc2.session_id()); |
| 1318 | EXPECT_EQ(desc1.session_version(), desc2.session_version()); |
| 1319 | CompareSessionDescription(*desc1.description(), *desc2.description()); |
| 1320 | if (desc1.number_of_mediasections() != desc2.number_of_mediasections()) |
| 1321 | return false; |
| 1322 | for (size_t i = 0; i < desc1.number_of_mediasections(); ++i) { |
| 1323 | const IceCandidateCollection* cc1 = desc1.candidates(i); |
| 1324 | const IceCandidateCollection* cc2 = desc2.candidates(i); |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 1325 | if (cc1->count() != cc2->count()) { |
| 1326 | ADD_FAILURE(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1327 | return false; |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 1328 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1329 | for (size_t j = 0; j < cc1->count(); ++j) { |
| 1330 | const IceCandidateInterface* c1 = cc1->at(j); |
| 1331 | const IceCandidateInterface* c2 = cc2->at(j); |
| 1332 | EXPECT_EQ(c1->sdp_mid(), c2->sdp_mid()); |
| 1333 | EXPECT_EQ(c1->sdp_mline_index(), c2->sdp_mline_index()); |
| 1334 | EXPECT_TRUE(c1->candidate().IsEquivalent(c2->candidate())); |
| 1335 | } |
| 1336 | } |
| 1337 | return true; |
| 1338 | } |
| 1339 | |
| 1340 | // Disable the ice-ufrag and ice-pwd in given |sdp| message by replacing |
| 1341 | // them with invalid keywords so that the parser will just ignore them. |
| 1342 | bool RemoveCandidateUfragPwd(std::string* sdp) { |
| 1343 | const char ice_ufrag[] = "a=ice-ufrag"; |
| 1344 | const char ice_ufragx[] = "a=xice-ufrag"; |
| 1345 | const char ice_pwd[] = "a=ice-pwd"; |
| 1346 | const char ice_pwdx[] = "a=xice-pwd"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1347 | rtc::replace_substrs(ice_ufrag, strlen(ice_ufrag), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1348 | ice_ufragx, strlen(ice_ufragx), sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1349 | rtc::replace_substrs(ice_pwd, strlen(ice_pwd), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1350 | ice_pwdx, strlen(ice_pwdx), sdp); |
| 1351 | return true; |
| 1352 | } |
| 1353 | |
| 1354 | // Update the candidates in |jdesc| to use the given |ufrag| and |pwd|. |
| 1355 | bool UpdateCandidateUfragPwd(JsepSessionDescription* jdesc, int mline_index, |
| 1356 | const std::string& ufrag, const std::string& pwd) { |
| 1357 | std::string content_name; |
| 1358 | if (mline_index == 0) { |
| 1359 | content_name = kAudioContentName; |
| 1360 | } else if (mline_index == 1) { |
| 1361 | content_name = kVideoContentName; |
| 1362 | } else { |
| 1363 | ASSERT(false); |
| 1364 | } |
| 1365 | TransportInfo transport_info( |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 1366 | content_name, TransportDescription(ufrag, pwd)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1367 | SessionDescription* desc = |
| 1368 | const_cast<SessionDescription*>(jdesc->description()); |
| 1369 | desc->RemoveTransportInfoByName(content_name); |
| 1370 | EXPECT_TRUE(desc->AddTransportInfo(transport_info)); |
| 1371 | for (size_t i = 0; i < jdesc_.number_of_mediasections(); ++i) { |
| 1372 | const IceCandidateCollection* cc = jdesc_.candidates(i); |
| 1373 | for (size_t j = 0; j < cc->count(); ++j) { |
| 1374 | if (cc->at(j)->sdp_mline_index() == mline_index) { |
| 1375 | const_cast<Candidate&>(cc->at(j)->candidate()).set_username( |
| 1376 | ufrag); |
| 1377 | const_cast<Candidate&>(cc->at(j)->candidate()).set_password( |
| 1378 | pwd); |
| 1379 | } |
| 1380 | } |
| 1381 | } |
| 1382 | return true; |
| 1383 | } |
| 1384 | |
| 1385 | void AddIceOptions(const std::string& content_name, |
| 1386 | const std::vector<std::string>& transport_options) { |
| 1387 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1388 | cricket::TransportInfo transport_info = |
| 1389 | *(desc_.GetTransportInfoByName(content_name)); |
| 1390 | desc_.RemoveTransportInfoByName(content_name); |
| 1391 | transport_info.description.transport_options = transport_options; |
| 1392 | desc_.AddTransportInfo(transport_info); |
| 1393 | } |
| 1394 | |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1395 | void SetIceUfragPwd(const std::string& content_name, |
| 1396 | const std::string& ice_ufrag, |
| 1397 | const std::string& ice_pwd) { |
| 1398 | ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 1399 | cricket::TransportInfo transport_info = |
| 1400 | *(desc_.GetTransportInfoByName(content_name)); |
| 1401 | desc_.RemoveTransportInfoByName(content_name); |
| 1402 | transport_info.description.ice_ufrag = ice_ufrag; |
| 1403 | transport_info.description.ice_pwd = ice_pwd; |
| 1404 | desc_.AddTransportInfo(transport_info); |
| 1405 | } |
| 1406 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1407 | void AddFingerprint() { |
| 1408 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 1409 | desc_.RemoveTransportInfoByName(kVideoContentName); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1410 | rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1411 | kIdentityDigest, |
| 1412 | sizeof(kIdentityDigest)); |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1413 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1414 | kAudioContentName, |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1415 | TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice, |
| 1416 | cricket::ICEMODE_FULL, |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1417 | cricket::CONNECTIONROLE_NONE, &fingerprint)))); |
| 1418 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1419 | kVideoContentName, |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1420 | TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, |
| 1421 | cricket::ICEMODE_FULL, |
deadbeef | 46eed76 | 2016-01-28 13:24:37 -0800 | [diff] [blame] | 1422 | cricket::CONNECTIONROLE_NONE, &fingerprint)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | void AddExtmap() { |
| 1426 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1427 | audio_desc_->Copy()); |
| 1428 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1429 | video_desc_->Copy()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1430 | audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); |
| 1431 | video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1432 | desc_.RemoveContentByName(kAudioContentName); |
| 1433 | desc_.RemoveContentByName(kVideoContentName); |
| 1434 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); |
| 1435 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); |
| 1436 | } |
| 1437 | |
| 1438 | void RemoveCryptos() { |
| 1439 | audio_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1440 | video_desc_->set_cryptos(std::vector<CryptoParams>()); |
| 1441 | } |
| 1442 | |
| 1443 | bool TestSerializeDirection(cricket::MediaContentDirection direction) { |
| 1444 | audio_desc_->set_direction(direction); |
| 1445 | video_desc_->set_direction(direction); |
| 1446 | std::string new_sdp = kSdpFullString; |
| 1447 | ReplaceDirection(direction, &new_sdp); |
| 1448 | |
| 1449 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1450 | jdesc_.session_id(), |
| 1451 | jdesc_.session_version())) { |
| 1452 | return false; |
| 1453 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1454 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1455 | EXPECT_EQ(new_sdp, message); |
| 1456 | return true; |
| 1457 | } |
| 1458 | |
| 1459 | bool TestSerializeRejected(bool audio_rejected, bool video_rejected) { |
| 1460 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1461 | audio_desc_->Copy()); |
| 1462 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1463 | video_desc_->Copy()); |
| 1464 | desc_.RemoveContentByName(kAudioContentName); |
| 1465 | desc_.RemoveContentByName(kVideoContentName); |
| 1466 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1467 | audio_desc_); |
| 1468 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1469 | video_desc_); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1470 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1471 | audio_rejected ? "" : kPwdVoice); |
| 1472 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1473 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1474 | |
| 1475 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1476 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1477 | |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1478 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1479 | if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1480 | kSessionVersion)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1481 | return false; |
| 1482 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1483 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1484 | EXPECT_EQ(new_sdp, message); |
| 1485 | return true; |
| 1486 | } |
| 1487 | |
| 1488 | void AddSctpDataChannel() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1489 | std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1490 | data_desc_ = data.get(); |
| 1491 | data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); |
solenberg | 9fa4975 | 2016-10-08 13:02:44 -0700 | [diff] [blame] | 1492 | DataCodec codec(cricket::kGoogleSctpDataCodecPlType, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1493 | cricket::kGoogleSctpDataCodecName); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1494 | codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort); |
| 1495 | data_desc_->AddCodec(codec); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1496 | desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release()); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1497 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1498 | kDataContentName, TransportDescription(kUfragData, kPwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | void AddRtpDataChannel() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1502 | std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1503 | data_desc_ = data.get(); |
| 1504 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1505 | data_desc_->AddCodec(DataCodec(101, "google-data")); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1506 | StreamParams data_stream; |
| 1507 | data_stream.id = kDataChannelMsid; |
| 1508 | data_stream.cname = kDataChannelCname; |
| 1509 | data_stream.sync_label = kDataChannelLabel; |
| 1510 | data_stream.ssrcs.push_back(kDataChannelSsrc); |
| 1511 | data_desc_->AddStream(data_stream); |
| 1512 | data_desc_->AddCrypto(CryptoParams( |
| 1513 | 1, "AES_CM_128_HMAC_SHA1_80", |
| 1514 | "inline:FvLcvU2P3ZWmQxgPAgcDu7Zl9vftYElFOjEzhWs5", "")); |
| 1515 | data_desc_->set_protocol(cricket::kMediaProtocolSavpf); |
| 1516 | desc_.AddContent(kDataContentName, NS_JINGLE_RTP, data.release()); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1517 | EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
| 1518 | kDataContentName, TransportDescription(kUfragData, kPwdData)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | bool TestDeserializeDirection(cricket::MediaContentDirection direction) { |
| 1522 | std::string new_sdp = kSdpFullString; |
| 1523 | ReplaceDirection(direction, &new_sdp); |
| 1524 | JsepSessionDescription new_jdesc(kDummyString); |
| 1525 | |
| 1526 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1527 | |
| 1528 | audio_desc_->set_direction(direction); |
| 1529 | video_desc_->set_direction(direction); |
| 1530 | if (!jdesc_.Initialize(desc_.Copy(), |
| 1531 | jdesc_.session_id(), |
| 1532 | jdesc_.session_version())) { |
| 1533 | return false; |
| 1534 | } |
| 1535 | EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1536 | return true; |
| 1537 | } |
| 1538 | |
| 1539 | bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1540 | std::string new_sdp = kSdpString; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1541 | ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1542 | JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1543 | EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1544 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1545 | audio_desc_ = static_cast<AudioContentDescription*>( |
| 1546 | audio_desc_->Copy()); |
| 1547 | video_desc_ = static_cast<VideoContentDescription*>( |
| 1548 | video_desc_->Copy()); |
| 1549 | desc_.RemoveContentByName(kAudioContentName); |
| 1550 | desc_.RemoveContentByName(kVideoContentName); |
| 1551 | desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1552 | audio_desc_); |
| 1553 | desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1554 | video_desc_); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1555 | SetIceUfragPwd(kAudioContentName, audio_rejected ? "" : kUfragVoice, |
| 1556 | audio_rejected ? "" : kPwdVoice); |
| 1557 | SetIceUfragPwd(kVideoContentName, video_rejected ? "" : kUfragVideo, |
| 1558 | video_rejected ? "" : kPwdVideo); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1559 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1560 | if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1561 | jdesc_.session_version())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1562 | return false; |
| 1563 | } |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1564 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1565 | return true; |
| 1566 | } |
| 1567 | |
| 1568 | void TestDeserializeExtmap(bool session_level, bool media_level) { |
| 1569 | AddExtmap(); |
| 1570 | JsepSessionDescription new_jdesc("dummy"); |
| 1571 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 1572 | jdesc_.session_id(), |
| 1573 | jdesc_.session_version())); |
| 1574 | JsepSessionDescription jdesc_with_extmap("dummy"); |
| 1575 | std::string sdp_with_extmap = kSdpString; |
| 1576 | if (session_level) { |
| 1577 | InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute, |
| 1578 | &sdp_with_extmap); |
| 1579 | } |
| 1580 | if (media_level) { |
| 1581 | InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute, |
| 1582 | &sdp_with_extmap); |
| 1583 | InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute, |
| 1584 | &sdp_with_extmap); |
| 1585 | } |
| 1586 | // The extmap can't be present at the same time in both session level and |
| 1587 | // media level. |
| 1588 | if (session_level && media_level) { |
| 1589 | SdpParseError error; |
| 1590 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap, |
| 1591 | &jdesc_with_extmap, &error)); |
| 1592 | EXPECT_NE(std::string::npos, error.description.find("a=extmap")); |
| 1593 | } else { |
| 1594 | EXPECT_TRUE(SdpDeserialize(sdp_with_extmap, &jdesc_with_extmap)); |
| 1595 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_extmap, new_jdesc)); |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | void VerifyCodecParameter(const cricket::CodecParameterMap& params, |
| 1600 | const std::string& name, int expected_value) { |
| 1601 | cricket::CodecParameterMap::const_iterator found = params.find(name); |
| 1602 | ASSERT_TRUE(found != params.end()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1603 | EXPECT_EQ(found->second, rtc::ToString<int>(expected_value)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | void TestDeserializeCodecParams(const CodecParams& params, |
| 1607 | JsepSessionDescription* jdesc_output) { |
| 1608 | std::string sdp = |
| 1609 | "v=0\r\n" |
| 1610 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1611 | "s=-\r\n" |
| 1612 | "t=0 0\r\n" |
| 1613 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1614 | // this parser, and will be added to the SDP when serializing a session |
| 1615 | // description. |
| 1616 | "a=msid-semantic: WMS\r\n" |
| 1617 | // Pl type 111 preferred. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 1618 | "m=audio 9 RTP/SAVPF 111 104 103\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1619 | // Pltype 111 listed before 103 and 104 in the map. |
| 1620 | "a=rtpmap:111 opus/48000/2\r\n" |
| 1621 | // Pltype 103 listed before 104. |
| 1622 | "a=rtpmap:103 ISAC/16000\r\n" |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 1623 | "a=rtpmap:104 ISAC/32000\r\n" |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1624 | "a=fmtp:111 0-15,66,70\r\n" |
| 1625 | "a=fmtp:111 "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1626 | std::ostringstream os; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 1627 | os << "minptime=" << params.min_ptime << "; stereo=" << params.stereo |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 1628 | << "; sprop-stereo=" << params.sprop_stereo |
| 1629 | << "; useinbandfec=" << params.useinband |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 1630 | << "; maxaveragebitrate=" << params.maxaveragebitrate << "\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1631 | << "a=ptime:" << params.ptime << "\r\n" |
| 1632 | << "a=maxptime:" << params.max_ptime << "\r\n"; |
| 1633 | sdp += os.str(); |
| 1634 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1635 | os.clear(); |
| 1636 | os.str(""); |
| 1637 | // Pl type 100 preferred. |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 1638 | os << "m=video 9 RTP/SAVPF 99 95\r\n" |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1639 | << "a=rtpmap:99 VP8/90000\r\n" |
| 1640 | << "a=rtpmap:95 RTX/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 1641 | << "a=fmtp:95 apt=99;\r\n"; |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1642 | sdp += os.str(); |
| 1643 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1644 | // Deserialize |
| 1645 | SdpParseError error; |
| 1646 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1647 | |
| 1648 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1649 | ASSERT_TRUE(ac != NULL); |
| 1650 | const AudioContentDescription* acd = |
| 1651 | static_cast<const AudioContentDescription*>(ac->description); |
| 1652 | ASSERT_FALSE(acd->codecs().empty()); |
| 1653 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1654 | EXPECT_EQ("opus", opus.name); |
| 1655 | EXPECT_EQ(111, opus.id); |
| 1656 | VerifyCodecParameter(opus.params, "minptime", params.min_ptime); |
| 1657 | VerifyCodecParameter(opus.params, "stereo", params.stereo); |
| 1658 | VerifyCodecParameter(opus.params, "sprop-stereo", params.sprop_stereo); |
| 1659 | VerifyCodecParameter(opus.params, "useinbandfec", params.useinband); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1660 | VerifyCodecParameter(opus.params, "maxaveragebitrate", |
| 1661 | params.maxaveragebitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1662 | for (size_t i = 0; i < acd->codecs().size(); ++i) { |
| 1663 | cricket::AudioCodec codec = acd->codecs()[i]; |
| 1664 | VerifyCodecParameter(codec.params, "ptime", params.ptime); |
| 1665 | VerifyCodecParameter(codec.params, "maxptime", params.max_ptime); |
| 1666 | if (codec.name == "ISAC") { |
| 1667 | if (codec.clockrate == 16000) { |
| 1668 | EXPECT_EQ(32000, codec.bitrate); |
| 1669 | } else { |
| 1670 | EXPECT_EQ(56000, codec.bitrate); |
| 1671 | } |
| 1672 | } |
| 1673 | } |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 1674 | |
| 1675 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description()); |
| 1676 | ASSERT_TRUE(vc != NULL); |
| 1677 | const VideoContentDescription* vcd = |
| 1678 | static_cast<const VideoContentDescription*>(vc->description); |
| 1679 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1680 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1681 | EXPECT_EQ("VP8", vp8.name); |
| 1682 | EXPECT_EQ(99, vp8.id); |
| 1683 | cricket::VideoCodec rtx = vcd->codecs()[1]; |
| 1684 | EXPECT_EQ("RTX", rtx.name); |
| 1685 | EXPECT_EQ(95, rtx.id); |
| 1686 | VerifyCodecParameter(rtx.params, "apt", vp8.id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output, |
| 1690 | bool use_wildcard) { |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1691 | std::string sdp_session_and_audio = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1692 | "v=0\r\n" |
| 1693 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 1694 | "s=-\r\n" |
| 1695 | "t=0 0\r\n" |
| 1696 | // Include semantics for WebRTC Media Streams since it is supported by |
| 1697 | // this parser, and will be added to the SDP when serializing a session |
| 1698 | // description. |
| 1699 | "a=msid-semantic: WMS\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 1700 | "m=audio 9 RTP/SAVPF 111\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1701 | "a=rtpmap:111 opus/48000/2\r\n"; |
| 1702 | std::string sdp_video = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1703 | "m=video 3457 RTP/SAVPF 101\r\n" |
| 1704 | "a=rtpmap:101 VP8/90000\r\n" |
| 1705 | "a=rtcp-fb:101 nack\r\n" |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1706 | "a=rtcp-fb:101 nack pli\r\n" |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1707 | "a=rtcp-fb:101 goog-remb\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1708 | std::ostringstream os; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1709 | os << sdp_session_and_audio; |
| 1710 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n"; |
| 1711 | os << sdp_video; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1712 | os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n"; |
jlmiller@webrtc.org | a744a28 | 2015-02-18 21:37:46 +0000 | [diff] [blame] | 1713 | std::string sdp = os.str(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1714 | // Deserialize |
| 1715 | SdpParseError error; |
| 1716 | EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error)); |
| 1717 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output->description()); |
| 1718 | ASSERT_TRUE(ac != NULL); |
| 1719 | const AudioContentDescription* acd = |
| 1720 | static_cast<const AudioContentDescription*>(ac->description); |
| 1721 | ASSERT_FALSE(acd->codecs().empty()); |
| 1722 | cricket::AudioCodec opus = acd->codecs()[0]; |
| 1723 | EXPECT_EQ(111, opus.id); |
| 1724 | EXPECT_TRUE(opus.HasFeedbackParam( |
| 1725 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1726 | cricket::kParamValueEmpty))); |
| 1727 | |
| 1728 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output->description()); |
| 1729 | ASSERT_TRUE(vc != NULL); |
| 1730 | const VideoContentDescription* vcd = |
| 1731 | static_cast<const VideoContentDescription*>(vc->description); |
| 1732 | ASSERT_FALSE(vcd->codecs().empty()); |
| 1733 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 1734 | EXPECT_STREQ(webrtc::JsepSessionDescription::kDefaultVideoCodecName, |
| 1735 | vp8.name.c_str()); |
| 1736 | EXPECT_EQ(101, vp8.id); |
| 1737 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1738 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1739 | cricket::kParamValueEmpty))); |
| 1740 | EXPECT_TRUE(vp8.HasFeedbackParam( |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1741 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1742 | cricket::kRtcpFbNackParamPli))); |
| 1743 | EXPECT_TRUE(vp8.HasFeedbackParam( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1744 | cricket::FeedbackParam(cricket::kRtcpFbParamRemb, |
| 1745 | cricket::kParamValueEmpty))); |
| 1746 | EXPECT_TRUE(vp8.HasFeedbackParam( |
| 1747 | cricket::FeedbackParam(cricket::kRtcpFbParamCcm, |
| 1748 | cricket::kRtcpFbCcmParamFir))); |
| 1749 | } |
| 1750 | |
| 1751 | // Two SDP messages can mean the same thing but be different strings, e.g. |
| 1752 | // some of the lines can be serialized in different order. |
| 1753 | // However, a deserialized description can be compared field by field and has |
| 1754 | // no order. If deserializer has already been tested, serializing then |
| 1755 | // deserializing and comparing JsepSessionDescription will test |
| 1756 | // the serializer sufficiently. |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1757 | void TestSerialize(const JsepSessionDescription& jdesc, |
| 1758 | bool unified_plan_sdp) { |
| 1759 | std::string message = webrtc::SdpSerialize(jdesc, unified_plan_sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1760 | JsepSessionDescription jdesc_output_des(kDummyString); |
| 1761 | SdpParseError error; |
| 1762 | EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); |
| 1763 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); |
| 1764 | } |
| 1765 | |
| 1766 | protected: |
| 1767 | SessionDescription desc_; |
| 1768 | AudioContentDescription* audio_desc_; |
| 1769 | VideoContentDescription* video_desc_; |
| 1770 | DataContentDescription* data_desc_; |
| 1771 | Candidates candidates_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1772 | std::unique_ptr<IceCandidateInterface> jcandidate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1773 | JsepSessionDescription jdesc_; |
| 1774 | }; |
| 1775 | |
| 1776 | void TestMismatch(const std::string& string1, const std::string& string2) { |
| 1777 | int position = 0; |
| 1778 | for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { |
| 1779 | if (string1.c_str()[i] != string2.c_str()[i]) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1780 | position = static_cast<int>(i); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1781 | break; |
| 1782 | } |
| 1783 | } |
| 1784 | EXPECT_EQ(0, position) << "Strings mismatch at the " << position |
| 1785 | << " character\n" |
| 1786 | << " 1: " << string1.substr(position, 20) << "\n" |
| 1787 | << " 2: " << string2.substr(position, 20) << "\n"; |
| 1788 | } |
| 1789 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1790 | TEST_F(WebRtcSdpTest, SerializeSessionDescription) { |
| 1791 | // SessionDescription with desc and candidates. |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1792 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1793 | TestMismatch(std::string(kSdpFullString), message); |
| 1794 | } |
| 1795 | |
| 1796 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionEmpty) { |
| 1797 | JsepSessionDescription jdesc_empty(kDummyString); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1798 | EXPECT_EQ("", webrtc::SdpSerialize(jdesc_empty, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1801 | // This tests serialization of SDP with only IPv6 candidates and verifies that |
| 1802 | // IPv6 is used as default address in c line according to preference. |
| 1803 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIPv6Only) { |
| 1804 | // Only test 1 m line. |
| 1805 | desc_.RemoveContentByName("video_content_name"); |
| 1806 | // Stun has a high preference than local host. |
| 1807 | cricket::Candidate candidate1( |
| 1808 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1809 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1810 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1811 | cricket::Candidate candidate2( |
| 1812 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1813 | rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| 1814 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1815 | JsepSessionDescription jdesc(kDummyString); |
| 1816 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1817 | |
| 1818 | // Only add the candidates to audio m line. |
| 1819 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1820 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1821 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1822 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1823 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1824 | |
| 1825 | // Audio line should have a c line like this one. |
| 1826 | EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos); |
| 1827 | // Shouldn't have a IP4 c line. |
| 1828 | EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| 1829 | } |
| 1830 | |
| 1831 | // This tests serialization of SDP with both IPv4 and IPv6 candidates and |
| 1832 | // verifies that IPv4 is used as default address in c line even if the |
| 1833 | // preference of IPv4 is lower. |
| 1834 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothIPFamilies) { |
| 1835 | // Only test 1 m line. |
| 1836 | desc_.RemoveContentByName("video_content_name"); |
| 1837 | cricket::Candidate candidate_v4( |
| 1838 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1839 | rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "", |
| 1840 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1841 | cricket::Candidate candidate_v6( |
| 1842 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1843 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1844 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1845 | JsepSessionDescription jdesc(kDummyString); |
| 1846 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1847 | |
| 1848 | // Only add the candidates to audio m line. |
| 1849 | JsepIceCandidate jice_v4("audio_content_name", 0, candidate_v4); |
| 1850 | JsepIceCandidate jice_v6("audio_content_name", 0, candidate_v6); |
| 1851 | ASSERT_TRUE(jdesc.AddCandidate(&jice_v4)); |
| 1852 | ASSERT_TRUE(jdesc.AddCandidate(&jice_v6)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1853 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1854 | |
| 1855 | // Audio line should have a c line like this one. |
| 1856 | EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos); |
| 1857 | // Shouldn't have a IP6 c line. |
| 1858 | EXPECT_EQ(message.find("c=IN IP6"), std::string::npos); |
| 1859 | } |
| 1860 | |
| 1861 | // This tests serialization of SDP with both UDP and TCP candidates and |
| 1862 | // verifies that UDP is used as default address in c line even if the |
| 1863 | // preference of UDP is lower. |
| 1864 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBothProtocols) { |
| 1865 | // Only test 1 m line. |
| 1866 | desc_.RemoveContentByName("video_content_name"); |
| 1867 | // Stun has a high preference than local host. |
| 1868 | cricket::Candidate candidate1( |
| 1869 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1870 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1871 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1872 | cricket::Candidate candidate2( |
| 1873 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| 1874 | rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority, |
| 1875 | "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration, |
| 1876 | kCandidateFoundation1); |
| 1877 | JsepSessionDescription jdesc(kDummyString); |
| 1878 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1879 | |
| 1880 | // Only add the candidates to audio m line. |
| 1881 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1882 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1883 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1884 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1885 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1886 | |
| 1887 | // Audio line should have a c line like this one. |
| 1888 | EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"), |
| 1889 | std::string::npos); |
| 1890 | // Shouldn't have a IP4 c line. |
| 1891 | EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| 1892 | } |
| 1893 | |
| 1894 | // This tests serialization of SDP with only TCP candidates and verifies that |
| 1895 | // null IPv4 is used as default address in c line. |
| 1896 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithTCPOnly) { |
| 1897 | // Only test 1 m line. |
| 1898 | desc_.RemoveContentByName("video_content_name"); |
| 1899 | // Stun has a high preference than local host. |
| 1900 | cricket::Candidate candidate1( |
| 1901 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1902 | rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| 1903 | cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1904 | cricket::Candidate candidate2( |
| 1905 | cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| 1906 | rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| 1907 | cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1); |
| 1908 | JsepSessionDescription jdesc(kDummyString); |
| 1909 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 1910 | |
| 1911 | // Only add the candidates to audio m line. |
| 1912 | JsepIceCandidate jice1("audio_content_name", 0, candidate1); |
| 1913 | JsepIceCandidate jice2("audio_content_name", 0, candidate2); |
| 1914 | ASSERT_TRUE(jdesc.AddCandidate(&jice1)); |
| 1915 | ASSERT_TRUE(jdesc.AddCandidate(&jice2)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1916 | std::string message = webrtc::SdpSerialize(jdesc, false); |
guoweis@webrtc.org | 57ac2c8 | 2015-02-06 00:45:13 +0000 | [diff] [blame] | 1917 | |
| 1918 | // Audio line should have a c line like this one when no any default exists. |
| 1919 | EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos); |
| 1920 | } |
| 1921 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1922 | // This tests serialization of SDP with a=crypto and a=fingerprint, as would be |
| 1923 | // the case in a DTLS offer. |
| 1924 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprint) { |
| 1925 | AddFingerprint(); |
| 1926 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1927 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1928 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1929 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1930 | |
| 1931 | std::string sdp_with_fingerprint = kSdpString; |
| 1932 | InjectAfter(kAttributeIcePwdVoice, |
| 1933 | kFingerprint, &sdp_with_fingerprint); |
| 1934 | InjectAfter(kAttributeIcePwdVideo, |
| 1935 | kFingerprint, &sdp_with_fingerprint); |
| 1936 | |
| 1937 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1938 | } |
| 1939 | |
| 1940 | // This tests serialization of SDP with a=fingerprint with no a=crypto, as would |
| 1941 | // be the case in a DTLS answer. |
| 1942 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithFingerprintNoCryptos) { |
| 1943 | AddFingerprint(); |
| 1944 | RemoveCryptos(); |
| 1945 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 1946 | ASSERT_TRUE(jdesc_with_fingerprint.Initialize(desc_.Copy(), |
| 1947 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1948 | std::string message = webrtc::SdpSerialize(jdesc_with_fingerprint, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1949 | |
| 1950 | std::string sdp_with_fingerprint = kSdpString; |
| 1951 | Replace(kAttributeCryptoVoice, "", &sdp_with_fingerprint); |
| 1952 | Replace(kAttributeCryptoVideo, "", &sdp_with_fingerprint); |
| 1953 | InjectAfter(kAttributeIcePwdVoice, |
| 1954 | kFingerprint, &sdp_with_fingerprint); |
| 1955 | InjectAfter(kAttributeIcePwdVideo, |
| 1956 | kFingerprint, &sdp_with_fingerprint); |
| 1957 | |
| 1958 | EXPECT_EQ(sdp_with_fingerprint, message); |
| 1959 | } |
| 1960 | |
| 1961 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { |
| 1962 | // JsepSessionDescription with desc but without candidates. |
| 1963 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
deadbeef | 3f7219b | 2015-12-28 15:17:14 -0800 | [diff] [blame] | 1964 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1965 | kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1966 | std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1967 | EXPECT_EQ(std::string(kSdpString), message); |
| 1968 | } |
| 1969 | |
| 1970 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) { |
| 1971 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1972 | group.AddContentName(kAudioContentName); |
| 1973 | group.AddContentName(kVideoContentName); |
| 1974 | desc_.AddGroup(group); |
| 1975 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1976 | jdesc_.session_id(), |
| 1977 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1978 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1979 | std::string sdp_with_bundle = kSdpFullString; |
| 1980 | InjectAfter(kSessionTime, |
| 1981 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 1982 | &sdp_with_bundle); |
| 1983 | EXPECT_EQ(sdp_with_bundle, message); |
| 1984 | } |
| 1985 | |
| 1986 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBandwidth) { |
| 1987 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 1988 | GetFirstVideoContent(&desc_)->description); |
| 1989 | vcd->set_bandwidth(100 * 1000); |
| 1990 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 1991 | GetFirstAudioContent(&desc_)->description); |
| 1992 | acd->set_bandwidth(50 * 1000); |
| 1993 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 1994 | jdesc_.session_id(), |
| 1995 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 1996 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1997 | std::string sdp_with_bandwidth = kSdpFullString; |
wu@webrtc.org | 4c3e991 | 2014-07-16 21:03:13 +0000 | [diff] [blame] | 1998 | InjectAfter("c=IN IP4 74.125.224.39\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1999 | "b=AS:100\r\n", |
| 2000 | &sdp_with_bandwidth); |
wu@webrtc.org | 4c3e991 | 2014-07-16 21:03:13 +0000 | [diff] [blame] | 2001 | InjectAfter("c=IN IP4 74.125.127.126\r\n", |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2002 | "b=AS:50\r\n", |
| 2003 | &sdp_with_bandwidth); |
| 2004 | EXPECT_EQ(sdp_with_bandwidth, message); |
| 2005 | } |
| 2006 | |
| 2007 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithIceOptions) { |
| 2008 | std::vector<std::string> transport_options; |
| 2009 | transport_options.push_back(kIceOption1); |
| 2010 | transport_options.push_back(kIceOption3); |
| 2011 | AddIceOptions(kAudioContentName, transport_options); |
| 2012 | transport_options.clear(); |
| 2013 | transport_options.push_back(kIceOption2); |
| 2014 | transport_options.push_back(kIceOption3); |
| 2015 | AddIceOptions(kVideoContentName, transport_options); |
| 2016 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2017 | jdesc_.session_id(), |
| 2018 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2019 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2020 | std::string sdp_with_ice_options = kSdpFullString; |
| 2021 | InjectAfter(kAttributeIcePwdVoice, |
| 2022 | "a=ice-options:iceoption1 iceoption3\r\n", |
| 2023 | &sdp_with_ice_options); |
| 2024 | InjectAfter(kAttributeIcePwdVideo, |
| 2025 | "a=ice-options:iceoption2 iceoption3\r\n", |
| 2026 | &sdp_with_ice_options); |
| 2027 | EXPECT_EQ(sdp_with_ice_options, message); |
| 2028 | } |
| 2029 | |
| 2030 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRecvOnlyContent) { |
| 2031 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_RECVONLY)); |
| 2032 | } |
| 2033 | |
| 2034 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSendOnlyContent) { |
| 2035 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_SENDONLY)); |
| 2036 | } |
| 2037 | |
| 2038 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithInactiveContent) { |
| 2039 | EXPECT_TRUE(TestSerializeDirection(cricket::MD_INACTIVE)); |
| 2040 | } |
| 2041 | |
| 2042 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioRejected) { |
| 2043 | EXPECT_TRUE(TestSerializeRejected(true, false)); |
| 2044 | } |
| 2045 | |
| 2046 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithVideoRejected) { |
| 2047 | EXPECT_TRUE(TestSerializeRejected(false, true)); |
| 2048 | } |
| 2049 | |
| 2050 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithAudioVideoRejected) { |
| 2051 | EXPECT_TRUE(TestSerializeRejected(true, true)); |
| 2052 | } |
| 2053 | |
| 2054 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithRtpDataChannel) { |
| 2055 | AddRtpDataChannel(); |
| 2056 | JsepSessionDescription jsep_desc(kDummyString); |
| 2057 | |
| 2058 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2059 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2060 | |
| 2061 | std::string expected_sdp = kSdpString; |
| 2062 | expected_sdp.append(kSdpRtpDataChannelString); |
| 2063 | EXPECT_EQ(expected_sdp, message); |
| 2064 | } |
| 2065 | |
| 2066 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithSctpDataChannel) { |
| 2067 | AddSctpDataChannel(); |
| 2068 | JsepSessionDescription jsep_desc(kDummyString); |
| 2069 | |
| 2070 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2071 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2072 | |
| 2073 | std::string expected_sdp = kSdpString; |
| 2074 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2075 | EXPECT_EQ(message, expected_sdp); |
| 2076 | } |
| 2077 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2078 | TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) { |
| 2079 | AddSctpDataChannel(); |
| 2080 | JsepSessionDescription jsep_desc(kDummyString); |
| 2081 | |
| 2082 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2083 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 2084 | jsep_desc.description()->GetContentDescriptionByName(kDataContentName)); |
| 2085 | |
| 2086 | const int kNewPort = 1234; |
solenberg | 9fa4975 | 2016-10-08 13:02:44 -0700 | [diff] [blame] | 2087 | cricket::DataCodec codec(cricket::kGoogleSctpDataCodecPlType, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 2088 | cricket::kGoogleSctpDataCodecName); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2089 | codec.SetParam(cricket::kCodecParamPort, kNewPort); |
| 2090 | dcdesc->AddOrReplaceCodec(codec); |
| 2091 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2092 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2093 | |
| 2094 | std::string expected_sdp = kSdpString; |
| 2095 | expected_sdp.append(kSdpSctpDataChannelString); |
| 2096 | |
| 2097 | char default_portstr[16]; |
| 2098 | char new_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2099 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2100 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2101 | rtc::sprintfn(new_portstr, sizeof(new_portstr), "%d", kNewPort); |
| 2102 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2103 | new_portstr, strlen(new_portstr), |
| 2104 | &expected_sdp); |
| 2105 | |
| 2106 | EXPECT_EQ(expected_sdp, message); |
| 2107 | } |
| 2108 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2109 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithDataChannelAndBandwidth) { |
| 2110 | AddRtpDataChannel(); |
| 2111 | data_desc_->set_bandwidth(100*1000); |
| 2112 | JsepSessionDescription jsep_desc(kDummyString); |
| 2113 | |
| 2114 | ASSERT_TRUE(jsep_desc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2115 | std::string message = webrtc::SdpSerialize(jsep_desc, false); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2116 | |
| 2117 | std::string expected_sdp = kSdpString; |
| 2118 | expected_sdp.append(kSdpRtpDataChannelString); |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2119 | // Serializing data content shouldn't ignore bandwidth settings. |
perkj@webrtc.org | d105cc8 | 2014-11-07 11:22:06 +0000 | [diff] [blame] | 2120 | InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n", |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2121 | "b=AS:100\r\n", |
| 2122 | &expected_sdp); |
| 2123 | EXPECT_EQ(expected_sdp, message); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2126 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { |
| 2127 | AddExtmap(); |
| 2128 | JsepSessionDescription desc_with_extmap("dummy"); |
| 2129 | ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(), |
| 2130 | kSessionId, kSessionVersion)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2131 | std::string message = webrtc::SdpSerialize(desc_with_extmap, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2132 | |
| 2133 | std::string sdp_with_extmap = kSdpString; |
| 2134 | InjectAfter("a=mid:audio_content_name\r\n", |
| 2135 | kExtmap, &sdp_with_extmap); |
| 2136 | InjectAfter("a=mid:video_content_name\r\n", |
| 2137 | kExtmap, &sdp_with_extmap); |
| 2138 | |
| 2139 | EXPECT_EQ(sdp_with_extmap, message); |
| 2140 | } |
| 2141 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2142 | TEST_F(WebRtcSdpTest, SerializeCandidates) { |
| 2143 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); |
wu@webrtc.org | ec9f5fb | 2014-06-24 17:05:10 +0000 | [diff] [blame] | 2144 | EXPECT_EQ(std::string(kRawCandidate), message); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2145 | |
| 2146 | Candidate candidate_with_ufrag(candidates_.front()); |
| 2147 | candidate_with_ufrag.set_username("ABC"); |
| 2148 | jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, |
| 2149 | candidate_with_ufrag)); |
| 2150 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2151 | EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2152 | |
| 2153 | Candidate candidate_with_network_info(candidates_.front()); |
| 2154 | candidate_with_network_info.set_network_id(1); |
| 2155 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2156 | candidate_with_network_info)); |
| 2157 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2158 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message); |
| 2159 | candidate_with_network_info.set_network_cost(999); |
| 2160 | jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0, |
| 2161 | candidate_with_network_info)); |
| 2162 | message = webrtc::SdpSerializeCandidate(*jcandidate_); |
| 2163 | EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999", |
| 2164 | message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2167 | // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing |
| 2168 | // RFC 6544. |
mallinath@webrtc.org | e999bd0 | 2014-08-13 06:05:55 +0000 | [diff] [blame] | 2169 | TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2170 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2171 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2172 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2173 | kCandidateFoundation1); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2174 | candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2175 | std::unique_ptr<IceCandidateInterface> jcandidate( |
| 2176 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2177 | |
| 2178 | std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
| 2179 | EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
| 2180 | } |
| 2181 | |
hta | a6b9944 | 2016-04-12 10:29:17 -0700 | [diff] [blame] | 2182 | TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2183 | cricket::VideoCodec h264_codec("H264"); |
| 2184 | h264_codec.SetParam("profile-level-id", "42e01f"); |
| 2185 | h264_codec.SetParam("level-asymmetry-allowed", "1"); |
| 2186 | h264_codec.SetParam("packetization-mode", "1"); |
| 2187 | video_desc_->AddCodec(h264_codec); |
| 2188 | |
hta | a6b9944 | 2016-04-12 10:29:17 -0700 | [diff] [blame] | 2189 | jdesc_.Initialize(desc_.Copy(), kSessionId, kSessionVersion); |
| 2190 | |
| 2191 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
| 2192 | size_t after_pt = message.find(" H264/90000"); |
| 2193 | ASSERT_NE(after_pt, std::string::npos); |
| 2194 | size_t before_pt = message.rfind("a=rtpmap:", after_pt); |
| 2195 | ASSERT_NE(before_pt, std::string::npos); |
| 2196 | before_pt += strlen("a=rtpmap:"); |
| 2197 | std::string pt = message.substr(before_pt, after_pt - before_pt); |
| 2198 | // TODO(hta): Check if payload type |pt| occurs in the m=video line. |
| 2199 | std::string to_find = "a=fmtp:" + pt + " "; |
| 2200 | size_t fmtp_pos = message.find(to_find); |
| 2201 | ASSERT_NE(std::string::npos, fmtp_pos) << "Failed to find " << to_find; |
| 2202 | size_t fmtp_endpos = message.find("\n", fmtp_pos); |
| 2203 | ASSERT_NE(std::string::npos, fmtp_endpos); |
| 2204 | std::string fmtp_value = message.substr(fmtp_pos, fmtp_endpos); |
| 2205 | EXPECT_NE(std::string::npos, fmtp_value.find("level-asymmetry-allowed=1")); |
| 2206 | EXPECT_NE(std::string::npos, fmtp_value.find("packetization-mode=1")); |
| 2207 | EXPECT_NE(std::string::npos, fmtp_value.find("profile-level-id=42e01f")); |
hta | 62a216e | 2016-04-15 11:02:14 -0700 | [diff] [blame] | 2208 | // Check that there are no spaces after semicolons. |
| 2209 | // https://bugs.webrtc.org/5793 |
| 2210 | EXPECT_EQ(std::string::npos, fmtp_value.find("; ")); |
hta | a6b9944 | 2016-04-12 10:29:17 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2213 | TEST_F(WebRtcSdpTest, DeserializeSessionDescription) { |
| 2214 | JsepSessionDescription jdesc(kDummyString); |
| 2215 | // Deserialize |
| 2216 | EXPECT_TRUE(SdpDeserialize(kSdpFullString, &jdesc)); |
| 2217 | // Verify |
| 2218 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2219 | } |
| 2220 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2221 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMline) { |
| 2222 | JsepSessionDescription jdesc(kDummyString); |
| 2223 | const char kSdpWithoutMline[] = |
| 2224 | "v=0\r\n" |
| 2225 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2226 | "s=-\r\n" |
| 2227 | "t=0 0\r\n" |
| 2228 | "a=msid-semantic: WMS local_stream_1 local_stream_2\r\n"; |
| 2229 | // Deserialize |
| 2230 | EXPECT_TRUE(SdpDeserialize(kSdpWithoutMline, &jdesc)); |
| 2231 | EXPECT_EQ(0u, jdesc.description()->contents().size()); |
| 2232 | } |
| 2233 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2234 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCarriageReturn) { |
| 2235 | JsepSessionDescription jdesc(kDummyString); |
| 2236 | std::string sdp_without_carriage_return = kSdpFullString; |
| 2237 | Replace("\r\n", "\n", &sdp_without_carriage_return); |
| 2238 | // Deserialize |
| 2239 | EXPECT_TRUE(SdpDeserialize(sdp_without_carriage_return, &jdesc)); |
| 2240 | // Verify |
| 2241 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2242 | } |
| 2243 | |
| 2244 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutCandidates) { |
| 2245 | // SessionDescription with desc but without candidates. |
| 2246 | JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 2247 | ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), |
| 2248 | kSessionId, kSessionVersion)); |
| 2249 | JsepSessionDescription new_jdesc(kDummyString); |
| 2250 | EXPECT_TRUE(SdpDeserialize(kSdpString, &new_jdesc)); |
| 2251 | EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 2252 | } |
| 2253 | |
| 2254 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmap) { |
| 2255 | static const char kSdpNoRtpmapString[] = |
| 2256 | "v=0\r\n" |
| 2257 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2258 | "s=-\r\n" |
| 2259 | "t=0 0\r\n" |
| 2260 | "m=audio 49232 RTP/AVP 0 18 103\r\n" |
| 2261 | // Codec that doesn't appear in the m= line will be ignored. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2262 | "a=rtpmap:104 ISAC/32000\r\n" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2263 | // The rtpmap line for static payload codec is optional. |
| 2264 | "a=rtpmap:18 G729/16000\r\n" |
| 2265 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2266 | |
| 2267 | JsepSessionDescription jdesc(kDummyString); |
| 2268 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2269 | cricket::AudioContentDescription* audio = |
| 2270 | static_cast<AudioContentDescription*>( |
| 2271 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2272 | AudioCodecs ref_codecs; |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 2273 | // The codecs in the AudioContentDescription should be in the same order as |
| 2274 | // the payload types (<fmt>s) on the m= line. |
| 2275 | ref_codecs.push_back(AudioCodec(0, "PCMU", 8000, 0, 1)); |
| 2276 | ref_codecs.push_back(AudioCodec(18, "G729", 16000, 0, 1)); |
| 2277 | ref_codecs.push_back(AudioCodec(103, "ISAC", 16000, 32000, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2278 | EXPECT_EQ(ref_codecs, audio->codecs()); |
| 2279 | } |
| 2280 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2281 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutRtpmapButWithFmtp) { |
| 2282 | static const char kSdpNoRtpmapString[] = |
| 2283 | "v=0\r\n" |
| 2284 | "o=- 11 22 IN IP4 127.0.0.1\r\n" |
| 2285 | "s=-\r\n" |
| 2286 | "t=0 0\r\n" |
| 2287 | "m=audio 49232 RTP/AVP 18 103\r\n" |
| 2288 | "a=fmtp:18 annexb=yes\r\n" |
| 2289 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 2290 | |
| 2291 | JsepSessionDescription jdesc(kDummyString); |
| 2292 | EXPECT_TRUE(SdpDeserialize(kSdpNoRtpmapString, &jdesc)); |
| 2293 | cricket::AudioContentDescription* audio = |
| 2294 | static_cast<AudioContentDescription*>( |
| 2295 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2296 | |
| 2297 | cricket::AudioCodec g729 = audio->codecs()[0]; |
| 2298 | EXPECT_EQ("G729", g729.name); |
| 2299 | EXPECT_EQ(8000, g729.clockrate); |
| 2300 | EXPECT_EQ(18, g729.id); |
| 2301 | cricket::CodecParameterMap::iterator found = |
| 2302 | g729.params.find("annexb"); |
| 2303 | ASSERT_TRUE(found != g729.params.end()); |
| 2304 | EXPECT_EQ(found->second, "yes"); |
| 2305 | |
| 2306 | cricket::AudioCodec isac = audio->codecs()[1]; |
| 2307 | EXPECT_EQ("ISAC", isac.name); |
| 2308 | EXPECT_EQ(103, isac.id); |
| 2309 | EXPECT_EQ(16000, isac.clockrate); |
| 2310 | } |
| 2311 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2312 | // Ensure that we can deserialize SDP with a=fingerprint properly. |
| 2313 | TEST_F(WebRtcSdpTest, DeserializeJsepSessionDescriptionWithFingerprint) { |
| 2314 | // Add a DTLS a=fingerprint attribute to our session description. |
| 2315 | AddFingerprint(); |
| 2316 | JsepSessionDescription new_jdesc(kDummyString); |
| 2317 | ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 2318 | jdesc_.session_id(), |
| 2319 | jdesc_.session_version())); |
| 2320 | |
| 2321 | JsepSessionDescription jdesc_with_fingerprint(kDummyString); |
| 2322 | std::string sdp_with_fingerprint = kSdpString; |
| 2323 | InjectAfter(kAttributeIcePwdVoice, kFingerprint, &sdp_with_fingerprint); |
| 2324 | InjectAfter(kAttributeIcePwdVideo, kFingerprint, &sdp_with_fingerprint); |
| 2325 | EXPECT_TRUE(SdpDeserialize(sdp_with_fingerprint, &jdesc_with_fingerprint)); |
| 2326 | EXPECT_TRUE(CompareSessionDescription(jdesc_with_fingerprint, new_jdesc)); |
| 2327 | } |
| 2328 | |
| 2329 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBundle) { |
| 2330 | JsepSessionDescription jdesc_with_bundle(kDummyString); |
| 2331 | std::string sdp_with_bundle = kSdpFullString; |
| 2332 | InjectAfter(kSessionTime, |
| 2333 | "a=group:BUNDLE audio_content_name video_content_name\r\n", |
| 2334 | &sdp_with_bundle); |
| 2335 | EXPECT_TRUE(SdpDeserialize(sdp_with_bundle, &jdesc_with_bundle)); |
| 2336 | ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 2337 | group.AddContentName(kAudioContentName); |
| 2338 | group.AddContentName(kVideoContentName); |
| 2339 | desc_.AddGroup(group); |
| 2340 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2341 | jdesc_.session_id(), |
| 2342 | jdesc_.session_version())); |
| 2343 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bundle)); |
| 2344 | } |
| 2345 | |
| 2346 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithBandwidth) { |
| 2347 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2348 | std::string sdp_with_bandwidth = kSdpFullString; |
| 2349 | InjectAfter("a=mid:video_content_name\r\na=sendrecv\r\n", |
| 2350 | "b=AS:100\r\n", |
| 2351 | &sdp_with_bandwidth); |
| 2352 | InjectAfter("a=mid:audio_content_name\r\na=sendrecv\r\n", |
| 2353 | "b=AS:50\r\n", |
| 2354 | &sdp_with_bandwidth); |
| 2355 | EXPECT_TRUE( |
| 2356 | SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2357 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 2358 | GetFirstVideoContent(&desc_)->description); |
| 2359 | vcd->set_bandwidth(100 * 1000); |
| 2360 | AudioContentDescription* acd = static_cast<AudioContentDescription*>( |
| 2361 | GetFirstAudioContent(&desc_)->description); |
| 2362 | acd->set_bandwidth(50 * 1000); |
| 2363 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2364 | jdesc_.session_id(), |
| 2365 | jdesc_.session_version())); |
| 2366 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_bandwidth)); |
| 2367 | } |
| 2368 | |
| 2369 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithIceOptions) { |
| 2370 | JsepSessionDescription jdesc_with_ice_options(kDummyString); |
| 2371 | std::string sdp_with_ice_options = kSdpFullString; |
| 2372 | InjectAfter(kSessionTime, |
| 2373 | "a=ice-options:iceoption3\r\n", |
| 2374 | &sdp_with_ice_options); |
| 2375 | InjectAfter(kAttributeIcePwdVoice, |
| 2376 | "a=ice-options:iceoption1\r\n", |
| 2377 | &sdp_with_ice_options); |
| 2378 | InjectAfter(kAttributeIcePwdVideo, |
| 2379 | "a=ice-options:iceoption2\r\n", |
| 2380 | &sdp_with_ice_options); |
| 2381 | EXPECT_TRUE(SdpDeserialize(sdp_with_ice_options, &jdesc_with_ice_options)); |
| 2382 | std::vector<std::string> transport_options; |
| 2383 | transport_options.push_back(kIceOption3); |
| 2384 | transport_options.push_back(kIceOption1); |
| 2385 | AddIceOptions(kAudioContentName, transport_options); |
| 2386 | transport_options.clear(); |
| 2387 | transport_options.push_back(kIceOption3); |
| 2388 | transport_options.push_back(kIceOption2); |
| 2389 | AddIceOptions(kVideoContentName, transport_options); |
| 2390 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 2391 | jdesc_.session_id(), |
| 2392 | jdesc_.session_version())); |
| 2393 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ice_options)); |
| 2394 | } |
| 2395 | |
| 2396 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithUfragPwd) { |
| 2397 | // Remove the original ice-ufrag and ice-pwd |
| 2398 | JsepSessionDescription jdesc_with_ufrag_pwd(kDummyString); |
| 2399 | std::string sdp_with_ufrag_pwd = kSdpFullString; |
| 2400 | EXPECT_TRUE(RemoveCandidateUfragPwd(&sdp_with_ufrag_pwd)); |
| 2401 | // Add session level ufrag and pwd |
| 2402 | InjectAfter(kSessionTime, |
| 2403 | "a=ice-pwd:session+level+icepwd\r\n" |
| 2404 | "a=ice-ufrag:session+level+iceufrag\r\n", |
| 2405 | &sdp_with_ufrag_pwd); |
| 2406 | // Add media level ufrag and pwd for audio |
| 2407 | InjectAfter("a=mid:audio_content_name\r\n", |
| 2408 | "a=ice-pwd:media+level+icepwd\r\na=ice-ufrag:media+level+iceufrag\r\n", |
| 2409 | &sdp_with_ufrag_pwd); |
| 2410 | // Update the candidate ufrag and pwd to the expected ones. |
| 2411 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 0, |
| 2412 | "media+level+iceufrag", "media+level+icepwd")); |
| 2413 | EXPECT_TRUE(UpdateCandidateUfragPwd(&jdesc_, 1, |
| 2414 | "session+level+iceufrag", "session+level+icepwd")); |
| 2415 | EXPECT_TRUE(SdpDeserialize(sdp_with_ufrag_pwd, &jdesc_with_ufrag_pwd)); |
| 2416 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc_with_ufrag_pwd)); |
| 2417 | } |
| 2418 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2419 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRecvOnlyContent) { |
| 2420 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_RECVONLY)); |
| 2421 | } |
| 2422 | |
| 2423 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSendOnlyContent) { |
| 2424 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_SENDONLY)); |
| 2425 | } |
| 2426 | |
| 2427 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInactiveContent) { |
| 2428 | EXPECT_TRUE(TestDeserializeDirection(cricket::MD_INACTIVE)); |
| 2429 | } |
| 2430 | |
| 2431 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudio) { |
| 2432 | EXPECT_TRUE(TestDeserializeRejected(true, false)); |
| 2433 | } |
| 2434 | |
| 2435 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedVideo) { |
| 2436 | EXPECT_TRUE(TestDeserializeRejected(false, true)); |
| 2437 | } |
| 2438 | |
| 2439 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithRejectedAudioVideo) { |
| 2440 | EXPECT_TRUE(TestDeserializeRejected(true, true)); |
| 2441 | } |
| 2442 | |
| 2443 | // Tests that we can still handle the sdp uses mslabel and label instead of |
| 2444 | // msid for backward compatibility. |
| 2445 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutMsid) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2446 | jdesc_.description()->set_msid_supported(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2447 | JsepSessionDescription jdesc(kDummyString); |
| 2448 | std::string sdp_without_msid = kSdpFullString; |
| 2449 | Replace("msid", "xmsid", &sdp_without_msid); |
| 2450 | // Deserialize |
| 2451 | EXPECT_TRUE(SdpDeserialize(sdp_without_msid, &jdesc)); |
| 2452 | // Verify |
| 2453 | EXPECT_TRUE(CompareSessionDescription(jdesc_, jdesc)); |
| 2454 | } |
| 2455 | |
| 2456 | TEST_F(WebRtcSdpTest, DeserializeCandidate) { |
| 2457 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2458 | |
| 2459 | std::string sdp = kSdpOneCandidate; |
| 2460 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2461 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2462 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2463 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2464 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2465 | |
| 2466 | // Candidate line without generation extension. |
| 2467 | sdp = kSdpOneCandidate; |
| 2468 | Replace(" generation 2", "", &sdp); |
| 2469 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2470 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2471 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2472 | Candidate expected = jcandidate_->candidate(); |
| 2473 | expected.set_generation(0); |
| 2474 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2475 | |
honghaiz | a0c44ea | 2016-03-23 16:07:48 -0700 | [diff] [blame] | 2476 | // Candidate with network id and/or cost. |
| 2477 | sdp = kSdpOneCandidate; |
| 2478 | Replace(" generation 2", " generation 2 network-id 2", &sdp); |
| 2479 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2480 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2481 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2482 | expected = jcandidate_->candidate(); |
| 2483 | expected.set_network_id(2); |
| 2484 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2485 | EXPECT_EQ(0, jcandidate.candidate().network_cost()); |
| 2486 | // Add network cost |
| 2487 | Replace(" network-id 2", " network-id 2 network-cost 9", &sdp); |
| 2488 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2489 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2490 | EXPECT_EQ(9, jcandidate.candidate().network_cost()); |
| 2491 | |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2492 | sdp = kSdpTcpActiveCandidate; |
| 2493 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2494 | // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
guoweis@webrtc.org | 61c1247 | 2015-01-15 06:53:07 +0000 | [diff] [blame] | 2495 | Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 2496 | rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
| 2497 | "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
| 2498 | kCandidateFoundation1); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2499 | std::unique_ptr<IceCandidateInterface> jcandidate_template( |
| 2500 | new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
mallinath@webrtc.org | 2d60c5e | 2014-08-08 22:29:20 +0000 | [diff] [blame] | 2501 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent( |
| 2502 | jcandidate_template->candidate())); |
| 2503 | sdp = kSdpTcpPassiveCandidate; |
| 2504 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
| 2505 | sdp = kSdpTcpSOCandidate; |
| 2506 | EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | // This test verifies the deserialization of candidate-attribute |
| 2510 | // as per RFC 5245. Candiate-attribute will be of the format |
| 2511 | // candidate:<blah>. This format will be used when candidates |
| 2512 | // are trickled. |
| 2513 | TEST_F(WebRtcSdpTest, DeserializeRawCandidateAttribute) { |
| 2514 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2515 | |
| 2516 | std::string candidate_attribute = kRawCandidate; |
| 2517 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2518 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2519 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2520 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2521 | EXPECT_EQ(2u, jcandidate.candidate().generation()); |
| 2522 | |
| 2523 | // Candidate line without generation extension. |
| 2524 | candidate_attribute = kRawCandidate; |
| 2525 | Replace(" generation 2", "", &candidate_attribute); |
| 2526 | EXPECT_TRUE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2527 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2528 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2529 | Candidate expected = jcandidate_->candidate(); |
| 2530 | expected.set_generation(0); |
| 2531 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
| 2532 | |
| 2533 | // Candidate line without candidate: |
| 2534 | candidate_attribute = kRawCandidate; |
| 2535 | Replace("candidate:", "", &candidate_attribute); |
| 2536 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2537 | |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2538 | // Candidate line with IPV6 address. |
| 2539 | EXPECT_TRUE(SdpDeserializeCandidate(kRawIPV6Candidate, &jcandidate)); |
| 2540 | } |
| 2541 | |
| 2542 | // This test verifies that the deserialization of an invalid candidate string |
| 2543 | // fails. |
| 2544 | TEST_F(WebRtcSdpTest, DeserializeInvalidCandidiate) { |
| 2545 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2546 | |
| 2547 | std::string candidate_attribute = kRawCandidate; |
| 2548 | candidate_attribute.replace(0, 1, "x"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2549 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
jiayl@webrtc.org | 7ec3f9f | 2014-08-08 23:09:15 +0000 | [diff] [blame] | 2550 | |
| 2551 | candidate_attribute = kSdpOneCandidate; |
| 2552 | candidate_attribute.replace(0, 1, "x"); |
| 2553 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2554 | |
| 2555 | candidate_attribute = kRawCandidate; |
| 2556 | candidate_attribute.append("\r\n"); |
| 2557 | candidate_attribute.append(kRawCandidate); |
| 2558 | EXPECT_FALSE(SdpDeserializeCandidate(candidate_attribute, &jcandidate)); |
| 2559 | |
| 2560 | EXPECT_FALSE(SdpDeserializeCandidate(kSdpTcpInvalidCandidate, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannels) { |
| 2564 | AddRtpDataChannel(); |
| 2565 | JsepSessionDescription jdesc(kDummyString); |
| 2566 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2567 | |
| 2568 | std::string sdp_with_data = kSdpString; |
| 2569 | sdp_with_data.append(kSdpRtpDataChannelString); |
| 2570 | JsepSessionDescription jdesc_output(kDummyString); |
| 2571 | |
| 2572 | // Deserialize |
| 2573 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2574 | // Verify |
| 2575 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2576 | } |
| 2577 | |
| 2578 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannels) { |
| 2579 | AddSctpDataChannel(); |
| 2580 | JsepSessionDescription jdesc(kDummyString); |
| 2581 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2582 | |
| 2583 | std::string sdp_with_data = kSdpString; |
| 2584 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2585 | JsepSessionDescription jdesc_output(kDummyString); |
| 2586 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2587 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelString). |
| 2588 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2589 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2590 | |
| 2591 | // Verify with UDP/DTLS/SCTP. |
| 2592 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2593 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2594 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2595 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2596 | |
| 2597 | // Verify with TCP/DTLS/SCTP. |
| 2598 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2599 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2600 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2601 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2602 | } |
| 2603 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2604 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) { |
| 2605 | AddSctpDataChannel(); |
| 2606 | JsepSessionDescription jdesc(kDummyString); |
| 2607 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2608 | |
| 2609 | std::string sdp_with_data = kSdpString; |
| 2610 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2611 | JsepSessionDescription jdesc_output(kDummyString); |
| 2612 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2613 | // Verify with DTLS/SCTP (already in kSdpSctpDataChannelStringWithSctpPort). |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2614 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2615 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2616 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2617 | // Verify with UDP/DTLS/SCTP. |
| 2618 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2619 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2620 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2621 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2622 | |
lally@webrtc.org | 3630085 | 2015-02-24 20:19:35 +0000 | [diff] [blame] | 2623 | // Verify with TCP/DTLS/SCTP. |
| 2624 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2625 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
lally@webrtc.org | c7848b7 | 2015-02-24 20:19:26 +0000 | [diff] [blame] | 2626 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2627 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2628 | } |
| 2629 | |
lally | 69f5760 | 2015-10-08 10:15:04 -0700 | [diff] [blame] | 2630 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { |
| 2631 | AddSctpDataChannel(); |
| 2632 | JsepSessionDescription jdesc(kDummyString); |
| 2633 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2634 | |
| 2635 | std::string sdp_with_data = kSdpString; |
| 2636 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort); |
| 2637 | JsepSessionDescription jdesc_output(kDummyString); |
| 2638 | |
| 2639 | // Verify with DTLS/SCTP. |
| 2640 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2641 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2642 | |
| 2643 | // Verify with UDP/DTLS/SCTP. |
| 2644 | sdp_with_data.replace(sdp_with_data.find(kDtlsSctp), |
| 2645 | strlen(kDtlsSctp), kUdpDtlsSctp); |
| 2646 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2647 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2648 | |
| 2649 | // Verify with TCP/DTLS/SCTP. |
| 2650 | sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp), |
| 2651 | strlen(kUdpDtlsSctp), kTcpDtlsSctp); |
| 2652 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2653 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
| 2654 | } |
| 2655 | |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2656 | // Test to check the behaviour if sctp-port is specified |
| 2657 | // on the m= line and in a=sctp-port. |
| 2658 | TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) { |
| 2659 | AddSctpDataChannel(); |
| 2660 | JsepSessionDescription jdesc(kDummyString); |
| 2661 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2662 | |
| 2663 | std::string sdp_with_data = kSdpString; |
| 2664 | // Append m= attributes |
| 2665 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2666 | // Append a=sctp-port attribute |
| 2667 | sdp_with_data.append("a=sctp-port 5000\r\n"); |
| 2668 | JsepSessionDescription jdesc_output(kDummyString); |
| 2669 | |
| 2670 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2671 | } |
| 2672 | |
henrike@webrtc.org | 571df2d | 2014-02-19 23:04:26 +0000 | [diff] [blame] | 2673 | // For crbug/344475. |
| 2674 | TEST_F(WebRtcSdpTest, DeserializeSdpWithCorruptedSctpDataChannels) { |
| 2675 | std::string sdp_with_data = kSdpString; |
| 2676 | sdp_with_data.append(kSdpSctpDataChannelString); |
| 2677 | // Remove the "\n" at the end. |
| 2678 | sdp_with_data = sdp_with_data.substr(0, sdp_with_data.size() - 1); |
| 2679 | JsepSessionDescription jdesc_output(kDummyString); |
| 2680 | |
| 2681 | EXPECT_FALSE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2682 | // No crash is a pass. |
| 2683 | } |
| 2684 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2685 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelAndNewPort) { |
| 2686 | AddSctpDataChannel(); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2687 | const uint16_t kUnusualSctpPort = 9556; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2688 | char default_portstr[16]; |
| 2689 | char unusual_portstr[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2690 | rtc::sprintfn(default_portstr, sizeof(default_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2691 | kDefaultSctpPort); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2692 | rtc::sprintfn(unusual_portstr, sizeof(unusual_portstr), "%d", |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2693 | kUnusualSctpPort); |
| 2694 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2695 | // First setup the expected JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2696 | JsepSessionDescription jdesc(kDummyString); |
| 2697 | // take our pre-built session description and change the SCTP port. |
| 2698 | cricket::SessionDescription* mutant = desc_.Copy(); |
| 2699 | DataContentDescription* dcdesc = static_cast<DataContentDescription*>( |
| 2700 | mutant->GetContentDescriptionByName(kDataContentName)); |
| 2701 | std::vector<cricket::DataCodec> codecs(dcdesc->codecs()); |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 2702 | EXPECT_EQ(1U, codecs.size()); |
solenberg | 9fa4975 | 2016-10-08 13:02:44 -0700 | [diff] [blame] | 2703 | EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, codecs[0].id); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2704 | codecs[0].SetParam(cricket::kCodecParamPort, kUnusualSctpPort); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2705 | dcdesc->set_codecs(codecs); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2706 | |
| 2707 | // note: mutant's owned by jdesc now. |
| 2708 | ASSERT_TRUE(jdesc.Initialize(mutant, kSessionId, kSessionVersion)); |
| 2709 | mutant = NULL; |
| 2710 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2711 | // Then get the deserialized JsepSessionDescription. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2712 | std::string sdp_with_data = kSdpString; |
| 2713 | sdp_with_data.append(kSdpSctpDataChannelString); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2714 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2715 | unusual_portstr, strlen(unusual_portstr), |
| 2716 | &sdp_with_data); |
| 2717 | JsepSessionDescription jdesc_output(kDummyString); |
| 2718 | |
| 2719 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2720 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
jiayl@webrtc.org | ddb85ab | 2014-09-05 16:31:56 +0000 | [diff] [blame] | 2721 | |
| 2722 | // We need to test the deserialized JsepSessionDescription from |
| 2723 | // kSdpSctpDataChannelStringWithSctpPort for |
| 2724 | // draft-ietf-mmusic-sctp-sdp-07 |
| 2725 | // a=sctp-port |
| 2726 | sdp_with_data = kSdpString; |
| 2727 | sdp_with_data.append(kSdpSctpDataChannelStringWithSctpPort); |
| 2728 | rtc::replace_substrs(default_portstr, strlen(default_portstr), |
| 2729 | unusual_portstr, strlen(unusual_portstr), |
| 2730 | &sdp_with_data); |
| 2731 | |
| 2732 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
| 2733 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output)); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2736 | TEST_F(WebRtcSdpTest, DeserializeSdpWithRtpDataChannelsAndBandwidth) { |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2737 | // We want to test that deserializing data content limits bandwidth |
| 2738 | // settings (it should never be greater than the default). |
| 2739 | // This should prevent someone from using unlimited data bandwidth through |
| 2740 | // JS and "breaking the Internet". |
| 2741 | // See: https://code.google.com/p/chromium/issues/detail?id=280726 |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2742 | std::string sdp_with_bandwidth = kSdpString; |
| 2743 | sdp_with_bandwidth.append(kSdpRtpDataChannelString); |
| 2744 | InjectAfter("a=mid:data_content_name\r\n", |
| 2745 | "b=AS:100\r\n", |
| 2746 | &sdp_with_bandwidth); |
| 2747 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2748 | |
Peter Thatcher | c0c3a86 | 2015-06-24 15:31:25 -0700 | [diff] [blame] | 2749 | EXPECT_FALSE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
| 2750 | } |
| 2751 | |
| 2752 | TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsAndBandwidth) { |
| 2753 | AddSctpDataChannel(); |
| 2754 | JsepSessionDescription jdesc(kDummyString); |
| 2755 | DataContentDescription* dcd = static_cast<DataContentDescription*>( |
| 2756 | GetFirstDataContent(&desc_)->description); |
| 2757 | dcd->set_bandwidth(100 * 1000); |
| 2758 | ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion)); |
| 2759 | |
| 2760 | std::string sdp_with_bandwidth = kSdpString; |
| 2761 | sdp_with_bandwidth.append(kSdpSctpDataChannelString); |
| 2762 | InjectAfter("a=mid:data_content_name\r\n", |
| 2763 | "b=AS:100\r\n", |
| 2764 | &sdp_with_bandwidth); |
| 2765 | JsepSessionDescription jdesc_with_bandwidth(kDummyString); |
| 2766 | |
| 2767 | // SCTP has congestion control, so we shouldn't limit the bandwidth |
| 2768 | // as we do for RTP. |
| 2769 | EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2770 | EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); |
| 2771 | } |
| 2772 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2773 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { |
| 2774 | TestDeserializeExtmap(true, false); |
| 2775 | } |
| 2776 | |
| 2777 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { |
| 2778 | TestDeserializeExtmap(false, true); |
| 2779 | } |
| 2780 | |
| 2781 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { |
| 2782 | TestDeserializeExtmap(true, true); |
| 2783 | } |
| 2784 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2785 | TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { |
| 2786 | JsepSessionDescription jdesc(kDummyString); |
| 2787 | std::string sdp = kSdpFullString; |
| 2788 | sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. |
| 2789 | // Deserialize |
| 2790 | SdpParseError error; |
| 2791 | EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2792 | const std::string lastline = "a=ssrc:3 label:video_track_id_1"; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2793 | EXPECT_EQ(lastline, error.line); |
| 2794 | EXPECT_EQ("Invalid SDP line.", error.description); |
| 2795 | } |
| 2796 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2797 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithDifferentTransport) { |
| 2798 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
| 2799 | std::string new_sdp = kSdpOneCandidate; |
| 2800 | Replace("udp", "unsupported_transport", &new_sdp); |
| 2801 | EXPECT_FALSE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2802 | new_sdp = kSdpOneCandidate; |
| 2803 | Replace("udp", "uDP", &new_sdp); |
| 2804 | EXPECT_TRUE(SdpDeserializeCandidate(new_sdp, &jcandidate)); |
| 2805 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2806 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2807 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate())); |
| 2808 | } |
| 2809 | |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2810 | TEST_F(WebRtcSdpTest, DeserializeCandidateWithUfragPwd) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2811 | JsepIceCandidate jcandidate(kDummyMid, kDummyIndex); |
honghaiz | a54a080 | 2015-12-16 18:37:23 -0800 | [diff] [blame] | 2812 | EXPECT_TRUE( |
| 2813 | SdpDeserializeCandidate(kSdpOneCandidateWithUfragPwd, &jcandidate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2814 | EXPECT_EQ(kDummyMid, jcandidate.sdp_mid()); |
| 2815 | EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index()); |
| 2816 | Candidate ref_candidate = jcandidate_->candidate(); |
| 2817 | ref_candidate.set_username("user_rtp"); |
| 2818 | ref_candidate.set_password("password_rtp"); |
| 2819 | EXPECT_TRUE(jcandidate.candidate().IsEquivalent(ref_candidate)); |
| 2820 | } |
| 2821 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 2822 | TEST_F(WebRtcSdpTest, DeserializeSdpWithConferenceFlag) { |
| 2823 | JsepSessionDescription jdesc(kDummyString); |
| 2824 | |
| 2825 | // Deserialize |
| 2826 | EXPECT_TRUE(SdpDeserialize(kSdpConferenceString, &jdesc)); |
| 2827 | |
| 2828 | // Verify |
| 2829 | cricket::AudioContentDescription* audio = |
| 2830 | static_cast<AudioContentDescription*>( |
| 2831 | jdesc.description()->GetContentDescriptionByName(cricket::CN_AUDIO)); |
| 2832 | EXPECT_TRUE(audio->conference_mode()); |
| 2833 | |
| 2834 | cricket::VideoContentDescription* video = |
| 2835 | static_cast<VideoContentDescription*>( |
| 2836 | jdesc.description()->GetContentDescriptionByName(cricket::CN_VIDEO)); |
| 2837 | EXPECT_TRUE(video->conference_mode()); |
| 2838 | } |
| 2839 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2840 | TEST_F(WebRtcSdpTest, DeserializeBrokenSdp) { |
| 2841 | const char kSdpDestroyer[] = "!@#$%^&"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2842 | const char kSdpEmptyType[] = " =candidate"; |
| 2843 | const char kSdpEqualAsPlus[] = "a+candidate"; |
| 2844 | const char kSdpSpaceAfterEqual[] = "a= candidate"; |
| 2845 | const char kSdpUpperType[] = "A=candidate"; |
| 2846 | const char kSdpEmptyLine[] = ""; |
| 2847 | const char kSdpMissingValue[] = "a="; |
| 2848 | |
| 2849 | const char kSdpBrokenFingerprint[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2850 | "4AAD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2851 | const char kSdpExtraField[] = "a=fingerprint:sha-1 " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2852 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB XXX"; |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2853 | const char kSdpMissingSpace[] = "a=fingerprint:sha-1" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2854 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB"; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2855 | // MD5 is not allowed in fingerprints. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2856 | const char kSdpMd5[] = "a=fingerprint:md5 " |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2857 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2858 | |
| 2859 | // Broken session description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2860 | ExpectParseFailure("v=", kSdpDestroyer); |
| 2861 | ExpectParseFailure("o=", kSdpDestroyer); |
| 2862 | ExpectParseFailure("s=-", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2863 | // Broken time description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2864 | ExpectParseFailure("t=", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2865 | |
| 2866 | // Broken media description |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2867 | ExpectParseFailure("m=audio", "c=IN IP4 74.125.224.39"); |
| 2868 | ExpectParseFailure("m=video", kSdpDestroyer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2869 | |
| 2870 | // Invalid lines |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2871 | ExpectParseFailure("a=candidate", kSdpEmptyType); |
| 2872 | ExpectParseFailure("a=candidate", kSdpEqualAsPlus); |
| 2873 | ExpectParseFailure("a=candidate", kSdpSpaceAfterEqual); |
| 2874 | ExpectParseFailure("a=candidate", kSdpUpperType); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2875 | |
| 2876 | // Bogus fingerprint replacing a=sendrev. We selected this attribute |
| 2877 | // because it's orthogonal to what we are replacing and hence |
| 2878 | // safe. |
decurtis@webrtc.org | 8af1104 | 2015-01-07 19:15:51 +0000 | [diff] [blame] | 2879 | ExpectParseFailure("a=sendrecv", kSdpBrokenFingerprint); |
| 2880 | ExpectParseFailure("a=sendrecv", kSdpExtraField); |
| 2881 | ExpectParseFailure("a=sendrecv", kSdpMissingSpace); |
| 2882 | ExpectParseFailure("a=sendrecv", kSdpMd5); |
| 2883 | |
| 2884 | // Empty Line |
| 2885 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpEmptyLine); |
| 2886 | ExpectParseFailure("a=rtcp:2347 IN IP4 74.125.127.126", kSdpMissingValue); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | TEST_F(WebRtcSdpTest, DeserializeSdpWithInvalidAttributeValue) { |
| 2890 | // ssrc |
| 2891 | ExpectParseFailure("a=ssrc:1", "a=ssrc:badvalue"); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2892 | ExpectParseFailure("a=ssrc-group:FEC 2 3", "a=ssrc-group:FEC badvalue 3"); |
wu@webrtc.org | 5e760e7 | 2014-04-02 23:19:09 +0000 | [diff] [blame] | 2893 | // crypto |
| 2894 | ExpectParseFailure("a=crypto:1 ", "a=crypto:badvalue "); |
| 2895 | // rtpmap |
| 2896 | ExpectParseFailure("a=rtpmap:111 ", "a=rtpmap:badvalue "); |
| 2897 | ExpectParseFailure("opus/48000/2", "opus/badvalue/2"); |
| 2898 | ExpectParseFailure("opus/48000/2", "opus/48000/badvalue"); |
| 2899 | // candidate |
| 2900 | ExpectParseFailure("1 udp 2130706432", "badvalue udp 2130706432"); |
| 2901 | ExpectParseFailure("1 udp 2130706432", "1 udp badvalue"); |
| 2902 | ExpectParseFailure("192.168.1.5 1234", "192.168.1.5 badvalue"); |
| 2903 | ExpectParseFailure("rport 2346", "rport badvalue"); |
| 2904 | ExpectParseFailure("rport 2346 generation 2", |
| 2905 | "rport 2346 generation badvalue"); |
| 2906 | // m line |
| 2907 | ExpectParseFailure("m=audio 2345 RTP/SAVPF 111 103 104", |
| 2908 | "m=audio 2345 RTP/SAVPF 111 badvalue 104"); |
| 2909 | |
| 2910 | // bandwidth |
| 2911 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2912 | "b=AS:badvalue\r\n", |
| 2913 | "b=AS:badvalue"); |
| 2914 | // rtcp-fb |
| 2915 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2916 | "a=rtcp-fb:badvalue nack\r\n", |
| 2917 | "a=rtcp-fb:badvalue nack"); |
| 2918 | // extmap |
| 2919 | ExpectParseFailureWithNewLines("a=mid:video_content_name\r\n", |
| 2920 | "a=extmap:badvalue http://example.com\r\n", |
| 2921 | "a=extmap:badvalue http://example.com"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | TEST_F(WebRtcSdpTest, DeserializeSdpWithReorderedPltypes) { |
| 2925 | JsepSessionDescription jdesc_output(kDummyString); |
| 2926 | |
| 2927 | const char kSdpWithReorderedPlTypesString[] = |
| 2928 | "v=0\r\n" |
| 2929 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2930 | "s=-\r\n" |
| 2931 | "t=0 0\r\n" |
pthatcher@webrtc.org | c9d6d14 | 2014-10-23 23:37:22 +0000 | [diff] [blame] | 2932 | "m=audio 9 RTP/SAVPF 104 103\r\n" // Pl type 104 preferred. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2933 | "a=rtpmap:111 opus/48000/2\r\n" // Pltype 111 listed before 103 and 104 |
| 2934 | // in the map. |
| 2935 | "a=rtpmap:103 ISAC/16000\r\n" // Pltype 103 listed before 104 in the map. |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2936 | "a=rtpmap:104 ISAC/32000\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2937 | |
| 2938 | // Deserialize |
| 2939 | EXPECT_TRUE(SdpDeserialize(kSdpWithReorderedPlTypesString, &jdesc_output)); |
| 2940 | |
| 2941 | const ContentInfo* ac = GetFirstAudioContent(jdesc_output.description()); |
| 2942 | ASSERT_TRUE(ac != NULL); |
| 2943 | const AudioContentDescription* acd = |
| 2944 | static_cast<const AudioContentDescription*>(ac->description); |
| 2945 | ASSERT_FALSE(acd->codecs().empty()); |
minyue@webrtc.org | f9b5c1b | 2015-02-17 12:36:41 +0000 | [diff] [blame] | 2946 | EXPECT_EQ("ISAC", acd->codecs()[0].name); |
| 2947 | EXPECT_EQ(32000, acd->codecs()[0].clockrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2948 | EXPECT_EQ(104, acd->codecs()[0].id); |
| 2949 | } |
| 2950 | |
| 2951 | TEST_F(WebRtcSdpTest, DeserializeSerializeCodecParams) { |
| 2952 | JsepSessionDescription jdesc_output(kDummyString); |
| 2953 | CodecParams params; |
| 2954 | params.max_ptime = 40; |
| 2955 | params.ptime = 30; |
| 2956 | params.min_ptime = 10; |
| 2957 | params.sprop_stereo = 1; |
| 2958 | params.stereo = 1; |
| 2959 | params.useinband = 1; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2960 | params.maxaveragebitrate = 128000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2961 | TestDeserializeCodecParams(params, &jdesc_output); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2962 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFb) { |
| 2966 | const bool kUseWildcard = false; |
| 2967 | JsepSessionDescription jdesc_output(kDummyString); |
| 2968 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2969 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | TEST_F(WebRtcSdpTest, DeserializeSerializeRtcpFbWildcard) { |
| 2973 | const bool kUseWildcard = true; |
| 2974 | JsepSessionDescription jdesc_output(kDummyString); |
| 2975 | TestDeserializeRtcpFb(&jdesc_output, kUseWildcard); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 2976 | TestSerialize(jdesc_output, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtp) { |
| 2980 | JsepSessionDescription jdesc_output(kDummyString); |
| 2981 | |
| 2982 | const char kSdpWithFmtpString[] = |
| 2983 | "v=0\r\n" |
| 2984 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 2985 | "s=-\r\n" |
| 2986 | "t=0 0\r\n" |
| 2987 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 2988 | "a=rtpmap:120 VP8/90000\r\n" |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2989 | "a=fmtp:120 x-google-min-bitrate=10;x-google-max-quantization=40\r\n"; |
| 2990 | |
| 2991 | // Deserialize |
| 2992 | SdpParseError error; |
Donald Curtis | 144d018 | 2015-05-15 13:14:24 -0700 | [diff] [blame] | 2993 | EXPECT_TRUE( |
| 2994 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 2995 | |
| 2996 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 2997 | ASSERT_TRUE(vc != NULL); |
| 2998 | const VideoContentDescription* vcd = |
| 2999 | static_cast<const VideoContentDescription*>(vc->description); |
| 3000 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3001 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 3002 | EXPECT_EQ("VP8", vp8.name); |
| 3003 | EXPECT_EQ(120, vp8.id); |
| 3004 | cricket::CodecParameterMap::iterator found = |
| 3005 | vp8.params.find("x-google-min-bitrate"); |
| 3006 | ASSERT_TRUE(found != vp8.params.end()); |
| 3007 | EXPECT_EQ(found->second, "10"); |
| 3008 | found = vp8.params.find("x-google-max-quantization"); |
| 3009 | ASSERT_TRUE(found != vp8.params.end()); |
| 3010 | EXPECT_EQ(found->second, "40"); |
| 3011 | } |
| 3012 | |
johan | 2d8d23e | 2016-06-03 01:22:42 -0700 | [diff] [blame] | 3013 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSprops) { |
| 3014 | JsepSessionDescription jdesc_output(kDummyString); |
| 3015 | |
| 3016 | const char kSdpWithFmtpString[] = |
| 3017 | "v=0\r\n" |
| 3018 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3019 | "s=-\r\n" |
| 3020 | "t=0 0\r\n" |
| 3021 | "m=video 49170 RTP/AVP 98\r\n" |
| 3022 | "a=rtpmap:98 H264/90000\r\n" |
| 3023 | "a=fmtp:98 profile-level-id=42A01E; " |
| 3024 | "sprop-parameter-sets=Z0IACpZTBYmI,aMljiA==\r\n"; |
| 3025 | |
| 3026 | // Deserialize. |
| 3027 | SdpParseError error; |
| 3028 | EXPECT_TRUE( |
| 3029 | webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, &error)); |
| 3030 | |
| 3031 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 3032 | ASSERT_TRUE(vc != NULL); |
| 3033 | const VideoContentDescription* vcd = |
| 3034 | static_cast<const VideoContentDescription*>(vc->description); |
| 3035 | ASSERT_TRUE(vcd != NULL); |
| 3036 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3037 | cricket::VideoCodec h264 = vcd->codecs()[0]; |
| 3038 | EXPECT_EQ("H264", h264.name); |
| 3039 | EXPECT_EQ(98, h264.id); |
| 3040 | cricket::CodecParameterMap::const_iterator found = |
| 3041 | h264.params.find("profile-level-id"); |
| 3042 | ASSERT_TRUE(found != h264.params.end()); |
| 3043 | EXPECT_EQ(found->second, "42A01E"); |
| 3044 | found = h264.params.find("sprop-parameter-sets"); |
| 3045 | ASSERT_TRUE(found != h264.params.end()); |
| 3046 | EXPECT_EQ(found->second, "Z0IACpZTBYmI,aMljiA=="); |
| 3047 | } |
| 3048 | |
Donald Curtis | 0e07f92 | 2015-05-15 09:21:23 -0700 | [diff] [blame] | 3049 | TEST_F(WebRtcSdpTest, DeserializeVideoFmtpWithSpace) { |
| 3050 | JsepSessionDescription jdesc_output(kDummyString); |
| 3051 | |
| 3052 | const char kSdpWithFmtpString[] = |
| 3053 | "v=0\r\n" |
| 3054 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3055 | "s=-\r\n" |
| 3056 | "t=0 0\r\n" |
| 3057 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3058 | "a=rtpmap:120 VP8/90000\r\n" |
| 3059 | "a=fmtp:120 x-google-min-bitrate=10; x-google-max-quantization=40\r\n"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3060 | |
| 3061 | // Deserialize |
| 3062 | SdpParseError error; |
| 3063 | EXPECT_TRUE(webrtc::SdpDeserialize(kSdpWithFmtpString, &jdesc_output, |
| 3064 | &error)); |
| 3065 | |
| 3066 | const ContentInfo* vc = GetFirstVideoContent(jdesc_output.description()); |
| 3067 | ASSERT_TRUE(vc != NULL); |
| 3068 | const VideoContentDescription* vcd = |
| 3069 | static_cast<const VideoContentDescription*>(vc->description); |
| 3070 | ASSERT_FALSE(vcd->codecs().empty()); |
| 3071 | cricket::VideoCodec vp8 = vcd->codecs()[0]; |
| 3072 | EXPECT_EQ("VP8", vp8.name); |
| 3073 | EXPECT_EQ(120, vp8.id); |
| 3074 | cricket::CodecParameterMap::iterator found = |
| 3075 | vp8.params.find("x-google-min-bitrate"); |
| 3076 | ASSERT_TRUE(found != vp8.params.end()); |
| 3077 | EXPECT_EQ(found->second, "10"); |
| 3078 | found = vp8.params.find("x-google-max-quantization"); |
| 3079 | ASSERT_TRUE(found != vp8.params.end()); |
| 3080 | EXPECT_EQ(found->second, "40"); |
| 3081 | } |
| 3082 | |
| 3083 | TEST_F(WebRtcSdpTest, SerializeVideoFmtp) { |
| 3084 | VideoContentDescription* vcd = static_cast<VideoContentDescription*>( |
| 3085 | GetFirstVideoContent(&desc_)->description); |
| 3086 | |
| 3087 | cricket::VideoCodecs codecs = vcd->codecs(); |
| 3088 | codecs[0].params["x-google-min-bitrate"] = "10"; |
| 3089 | vcd->set_codecs(codecs); |
| 3090 | |
| 3091 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 3092 | jdesc_.session_id(), |
| 3093 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3094 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3095 | std::string sdp_with_fmtp = kSdpFullString; |
| 3096 | InjectAfter("a=rtpmap:120 VP8/90000\r\n", |
| 3097 | "a=fmtp:120 x-google-min-bitrate=10\r\n", |
| 3098 | &sdp_with_fmtp); |
| 3099 | EXPECT_EQ(sdp_with_fmtp, message); |
| 3100 | } |
| 3101 | |
| 3102 | TEST_F(WebRtcSdpTest, DeserializeSdpWithIceLite) { |
| 3103 | JsepSessionDescription jdesc_with_icelite(kDummyString); |
| 3104 | std::string sdp_with_icelite = kSdpFullString; |
| 3105 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 3106 | cricket::SessionDescription* desc = jdesc_with_icelite.description(); |
| 3107 | const cricket::TransportInfo* tinfo1 = |
| 3108 | desc->GetTransportInfoByName("audio_content_name"); |
| 3109 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo1->description.ice_mode); |
| 3110 | const cricket::TransportInfo* tinfo2 = |
| 3111 | desc->GetTransportInfoByName("video_content_name"); |
| 3112 | EXPECT_EQ(cricket::ICEMODE_FULL, tinfo2->description.ice_mode); |
| 3113 | InjectAfter(kSessionTime, |
| 3114 | "a=ice-lite\r\n", |
| 3115 | &sdp_with_icelite); |
| 3116 | EXPECT_TRUE(SdpDeserialize(sdp_with_icelite, &jdesc_with_icelite)); |
| 3117 | desc = jdesc_with_icelite.description(); |
| 3118 | const cricket::TransportInfo* atinfo = |
| 3119 | desc->GetTransportInfoByName("audio_content_name"); |
| 3120 | EXPECT_EQ(cricket::ICEMODE_LITE, atinfo->description.ice_mode); |
| 3121 | const cricket::TransportInfo* vtinfo = |
| 3122 | desc->GetTransportInfoByName("video_content_name"); |
| 3123 | EXPECT_EQ(cricket::ICEMODE_LITE, vtinfo->description.ice_mode); |
| 3124 | } |
| 3125 | |
| 3126 | // Verifies that the candidates in the input SDP are parsed and serialized |
| 3127 | // correctly in the output SDP. |
| 3128 | TEST_F(WebRtcSdpTest, RoundTripSdpWithSctpDataChannelsWithCandidates) { |
| 3129 | std::string sdp_with_data = kSdpString; |
| 3130 | sdp_with_data.append(kSdpSctpDataChannelWithCandidatesString); |
| 3131 | JsepSessionDescription jdesc_output(kDummyString); |
| 3132 | |
| 3133 | EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output)); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3134 | EXPECT_EQ(sdp_with_data, webrtc::SdpSerialize(jdesc_output, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3135 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 3136 | |
| 3137 | TEST_F(WebRtcSdpTest, SerializeDtlsSetupAttribute) { |
| 3138 | AddFingerprint(); |
| 3139 | TransportInfo audio_transport_info = |
| 3140 | *(desc_.GetTransportInfoByName(kAudioContentName)); |
| 3141 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3142 | audio_transport_info.description.connection_role); |
| 3143 | audio_transport_info.description.connection_role = |
| 3144 | cricket::CONNECTIONROLE_ACTIVE; |
| 3145 | |
| 3146 | TransportInfo video_transport_info = |
| 3147 | *(desc_.GetTransportInfoByName(kVideoContentName)); |
| 3148 | EXPECT_EQ(cricket::CONNECTIONROLE_NONE, |
| 3149 | video_transport_info.description.connection_role); |
| 3150 | video_transport_info.description.connection_role = |
| 3151 | cricket::CONNECTIONROLE_ACTIVE; |
| 3152 | |
| 3153 | desc_.RemoveTransportInfoByName(kAudioContentName); |
| 3154 | desc_.RemoveTransportInfoByName(kVideoContentName); |
| 3155 | |
| 3156 | desc_.AddTransportInfo(audio_transport_info); |
| 3157 | desc_.AddTransportInfo(video_transport_info); |
| 3158 | |
| 3159 | ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| 3160 | jdesc_.session_id(), |
| 3161 | jdesc_.session_version())); |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3162 | std::string message = webrtc::SdpSerialize(jdesc_, false); |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 3163 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3164 | |
| 3165 | // Fingerprint attribute is necessary to add DTLS setup attribute. |
| 3166 | InjectAfter(kAttributeIcePwdVoice, |
| 3167 | kFingerprint, &sdp_with_dtlssetup); |
| 3168 | InjectAfter(kAttributeIcePwdVideo, |
| 3169 | kFingerprint, &sdp_with_dtlssetup); |
| 3170 | // Now adding |setup| attribute. |
| 3171 | InjectAfter(kFingerprint, |
| 3172 | "a=setup:active\r\n", &sdp_with_dtlssetup); |
| 3173 | EXPECT_EQ(sdp_with_dtlssetup, message); |
| 3174 | } |
| 3175 | |
| 3176 | TEST_F(WebRtcSdpTest, DeserializeDtlsSetupAttribute) { |
| 3177 | JsepSessionDescription jdesc_with_dtlssetup(kDummyString); |
| 3178 | std::string sdp_with_dtlssetup = kSdpFullString; |
| 3179 | InjectAfter(kSessionTime, |
| 3180 | "a=setup:actpass\r\n", |
| 3181 | &sdp_with_dtlssetup); |
| 3182 | EXPECT_TRUE(SdpDeserialize(sdp_with_dtlssetup, &jdesc_with_dtlssetup)); |
| 3183 | cricket::SessionDescription* desc = jdesc_with_dtlssetup.description(); |
| 3184 | const cricket::TransportInfo* atinfo = |
| 3185 | desc->GetTransportInfoByName("audio_content_name"); |
| 3186 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3187 | atinfo->description.connection_role); |
| 3188 | const cricket::TransportInfo* vtinfo = |
| 3189 | desc->GetTransportInfoByName("video_content_name"); |
| 3190 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTPASS, |
| 3191 | vtinfo->description.connection_role); |
| 3192 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3193 | |
| 3194 | // Verifies that the order of the serialized m-lines follows the order of the |
| 3195 | // ContentInfo in SessionDescription, and vise versa for deserialization. |
| 3196 | TEST_F(WebRtcSdpTest, MediaContentOrderMaintainedRoundTrip) { |
| 3197 | JsepSessionDescription jdesc(kDummyString); |
| 3198 | const std::string media_content_sdps[3] = { |
| 3199 | kSdpAudioString, |
| 3200 | kSdpVideoString, |
| 3201 | kSdpSctpDataChannelString |
| 3202 | }; |
| 3203 | const cricket::MediaType media_types[3] = { |
| 3204 | cricket::MEDIA_TYPE_AUDIO, |
| 3205 | cricket::MEDIA_TYPE_VIDEO, |
| 3206 | cricket::MEDIA_TYPE_DATA |
| 3207 | }; |
| 3208 | |
| 3209 | // Verifies all 6 permutations. |
| 3210 | for (size_t i = 0; i < 6; ++i) { |
| 3211 | size_t media_content_in_sdp[3]; |
| 3212 | // The index of the first media content. |
| 3213 | media_content_in_sdp[0] = i / 2; |
| 3214 | // The index of the second media content. |
| 3215 | media_content_in_sdp[1] = (media_content_in_sdp[0] + i % 2 + 1) % 3; |
| 3216 | // The index of the third media content. |
| 3217 | media_content_in_sdp[2] = (media_content_in_sdp[0] + (i + 1) % 2 + 1) % 3; |
| 3218 | |
| 3219 | std::string sdp_string = kSdpSessionString; |
| 3220 | for (size_t i = 0; i < 3; ++i) |
| 3221 | sdp_string += media_content_sdps[media_content_in_sdp[i]]; |
| 3222 | |
| 3223 | EXPECT_TRUE(SdpDeserialize(sdp_string, &jdesc)); |
| 3224 | cricket::SessionDescription* desc = jdesc.description(); |
| 3225 | EXPECT_EQ(3u, desc->contents().size()); |
| 3226 | |
| 3227 | for (size_t i = 0; i < 3; ++i) { |
| 3228 | const cricket::MediaContentDescription* mdesc = |
| 3229 | static_cast<const cricket::MediaContentDescription*>( |
| 3230 | desc->contents()[i].description); |
| 3231 | EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 3232 | } |
| 3233 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3234 | std::string serialized_sdp = webrtc::SdpSerialize(jdesc, false); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 3235 | EXPECT_EQ(sdp_string, serialized_sdp); |
| 3236 | } |
| 3237 | } |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3238 | |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 3239 | TEST_F(WebRtcSdpTest, DeserializeBundleOnlyAttribute) { |
| 3240 | MakeBundleOnlyDescription(); |
| 3241 | JsepSessionDescription deserialized_description(kDummyString); |
deadbeef | 12771a1 | 2017-01-03 13:53:47 -0800 | [diff] [blame^] | 3242 | ASSERT_TRUE( |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 3243 | SdpDeserialize(kBundleOnlySdpFullString, &deserialized_description)); |
| 3244 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3245 | } |
| 3246 | |
deadbeef | 12771a1 | 2017-01-03 13:53:47 -0800 | [diff] [blame^] | 3247 | // The semantics of "a=bundle-only" are only defined when it's used in |
| 3248 | // combination with a 0 port on the m= line. We should ignore it if used with a |
| 3249 | // nonzero port. |
| 3250 | TEST_F(WebRtcSdpTest, IgnoreBundleOnlyWithNonzeroPort) { |
| 3251 | // Make the base bundle-only description but unset the bundle-only flag. |
| 3252 | MakeBundleOnlyDescription(); |
| 3253 | jdesc_.description()->contents()[1].bundle_only = false; |
| 3254 | |
| 3255 | std::string modified_sdp = kBundleOnlySdpFullString; |
| 3256 | Replace("m=video 0", "m=video 9", &modified_sdp); |
| 3257 | JsepSessionDescription deserialized_description(kDummyString); |
| 3258 | ASSERT_TRUE(SdpDeserialize(modified_sdp, &deserialized_description)); |
| 3259 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | TEST_F(WebRtcSdpTest, SerializeBundleOnlyAttribute) { |
| 3263 | MakeBundleOnlyDescription(); |
| 3264 | TestSerialize(jdesc_, false); |
| 3265 | } |
| 3266 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3267 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescription) { |
| 3268 | MakePlanBDescription(); |
| 3269 | |
| 3270 | JsepSessionDescription deserialized_description(kDummyString); |
| 3271 | EXPECT_TRUE(SdpDeserialize(kPlanBSdpFullString, &deserialized_description)); |
| 3272 | |
| 3273 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3274 | } |
| 3275 | |
| 3276 | TEST_F(WebRtcSdpTest, SerializePlanBSessionDescription) { |
| 3277 | MakePlanBDescription(); |
| 3278 | TestSerialize(jdesc_, false); |
| 3279 | } |
| 3280 | |
Taylor Brandstetter | 5de6b75 | 2016-03-09 17:02:30 -0800 | [diff] [blame] | 3281 | // Some WebRTC endpoints include the msid in both the Plan B and Unified Plan |
| 3282 | // ways, to make SDP that's compatible with both Plan B and Unified Plan (to |
| 3283 | // some extent). If we parse this, the Plan B msid attribute (which is more |
| 3284 | // specific, since it's at the SSRC level) should take priority. |
| 3285 | TEST_F(WebRtcSdpTest, DeserializePlanBSessionDescriptionWithMsid) { |
| 3286 | MakePlanBDescription(); |
| 3287 | |
| 3288 | JsepSessionDescription deserialized_description(kDummyString); |
| 3289 | EXPECT_TRUE( |
| 3290 | SdpDeserialize(kPlanBSdpFullStringWithMsid, &deserialized_description)); |
| 3291 | |
| 3292 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3293 | } |
| 3294 | |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 3295 | TEST_F(WebRtcSdpTest, DeserializeUnifiedPlanSessionDescription) { |
| 3296 | MakeUnifiedPlanDescription(); |
| 3297 | |
| 3298 | JsepSessionDescription deserialized_description(kDummyString); |
| 3299 | EXPECT_TRUE( |
| 3300 | SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); |
| 3301 | |
| 3302 | EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
| 3303 | } |
| 3304 | |
| 3305 | TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { |
| 3306 | MakeUnifiedPlanDescription(); |
| 3307 | TestSerialize(jdesc_, true); |
| 3308 | } |
deadbeef | 7e146cb | 2016-09-28 10:04:34 -0700 | [diff] [blame] | 3309 | |
| 3310 | // Regression test for heap overflow bug: |
| 3311 | // https://bugs.chromium.org/p/chromium/issues/detail?id=647916 |
| 3312 | TEST_F(WebRtcSdpTest, DeserializeSctpPortInVideoDescription) { |
| 3313 | JsepSessionDescription jdesc_output(kDummyString); |
| 3314 | |
| 3315 | // The issue occurs when the sctp-port attribute is found in a video |
| 3316 | // description. The actual heap overflow occurs when parsing the fmtp line. |
| 3317 | const char kSdpWithSctpPortInVideoDescription[] = |
| 3318 | "v=0\r\n" |
| 3319 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3320 | "s=-\r\n" |
| 3321 | "t=0 0\r\n" |
| 3322 | "m=video 9 UDP/DTLS/SCTP 120\r\n" |
| 3323 | "a=sctp-port 5000\r\n" |
| 3324 | "a=fmtp:108 foo=10\r\n"; |
| 3325 | |
| 3326 | ExpectParseFailure(std::string(kSdpWithSctpPortInVideoDescription), |
| 3327 | "sctp-port"); |
| 3328 | } |
deadbeef | b236257 | 2016-12-13 16:37:06 -0800 | [diff] [blame] | 3329 | |
| 3330 | // Regression test for integer overflow bug: |
| 3331 | // https://bugs.chromium.org/p/chromium/issues/detail?id=648071 |
| 3332 | TEST_F(WebRtcSdpTest, DeserializeLargeBandwidthLimit) { |
| 3333 | JsepSessionDescription jdesc_output(kDummyString); |
| 3334 | |
| 3335 | // Bandwidth attribute is the max signed 32-bit int, which will get |
| 3336 | // multiplied by 1000 and cause int overflow if not careful. |
| 3337 | const char kSdpWithLargeBandwidth[] = |
| 3338 | "v=0\r\n" |
| 3339 | "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" |
| 3340 | "s=-\r\n" |
| 3341 | "t=0 0\r\n" |
| 3342 | "m=video 3457 RTP/SAVPF 120\r\n" |
| 3343 | "b=AS:2147483647\r\n" |
| 3344 | "foo=fail\r\n"; |
| 3345 | |
| 3346 | ExpectParseFailure(std::string(kSdpWithLargeBandwidth), "foo=fail"); |
| 3347 | } |