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