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