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