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