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