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