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