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