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