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