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