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