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