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