Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: webrtc/pc/mediasession.cc

Issue 2254003002: Fixing off-by-one error with max SCTP id. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removing unneeded parentheses. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 10 matching lines...) Expand all
21 #include "webrtc/base/base64.h" 21 #include "webrtc/base/base64.h"
22 #include "webrtc/base/helpers.h" 22 #include "webrtc/base/helpers.h"
23 #include "webrtc/base/logging.h" 23 #include "webrtc/base/logging.h"
24 #include "webrtc/base/stringutils.h" 24 #include "webrtc/base/stringutils.h"
25 #include "webrtc/media/base/cryptoparams.h" 25 #include "webrtc/media/base/cryptoparams.h"
26 #include "webrtc/media/base/mediaconstants.h" 26 #include "webrtc/media/base/mediaconstants.h"
27 #include "webrtc/p2p/base/p2pconstants.h" 27 #include "webrtc/p2p/base/p2pconstants.h"
28 #include "webrtc/pc/channelmanager.h" 28 #include "webrtc/pc/channelmanager.h"
29 #include "webrtc/pc/srtpfilter.h" 29 #include "webrtc/pc/srtpfilter.h"
30 30
31 #ifdef HAVE_SCTP
32 #include "webrtc/media/sctp/sctpdataengine.h"
33 #else
34 static const uint32_t kMaxSctpSid = 1023;
35 #endif
36
37 namespace { 31 namespace {
38 const char kInline[] = "inline:"; 32 const char kInline[] = "inline:";
39 33
40 void GetSupportedCryptoSuiteNames(void (*func)(const rtc::CryptoOptions&, 34 void GetSupportedCryptoSuiteNames(void (*func)(const rtc::CryptoOptions&,
41 std::vector<int>*), 35 std::vector<int>*),
42 const rtc::CryptoOptions& crypto_options, 36 const rtc::CryptoOptions& crypto_options,
43 std::vector<std::string>* names) { 37 std::vector<std::string>* names) {
44 #ifdef HAVE_SRTP 38 #ifdef HAVE_SRTP
45 std::vector<int> crypto_suites; 39 std::vector<int> crypto_suites;
46 func(crypto_options, &crypto_suites); 40 func(crypto_options, &crypto_suites);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 for (int i = 0; i < num_ssrcs; i++) { 269 for (int i = 0; i < num_ssrcs; i++) {
276 uint32_t candidate; 270 uint32_t candidate;
277 do { 271 do {
278 candidate = rtc::CreateRandomNonZeroId(); 272 candidate = rtc::CreateRandomNonZeroId();
279 } while (GetStreamBySsrc(params_vec, candidate) || 273 } while (GetStreamBySsrc(params_vec, candidate) ||
280 std::count(ssrcs->begin(), ssrcs->end(), candidate) > 0); 274 std::count(ssrcs->begin(), ssrcs->end(), candidate) > 0);
281 ssrcs->push_back(candidate); 275 ssrcs->push_back(candidate);
282 } 276 }
283 } 277 }
284 278
285 // Returns false if we exhaust the range of SIDs.
286 static bool GenerateSctpSid(const StreamParamsVec& params_vec, uint32_t* sid) {
287 if (params_vec.size() > kMaxSctpSid) {
288 LOG(LS_WARNING) <<
289 "Could not generate an SCTP SID: too many SCTP streams.";
290 return false;
291 }
292 while (true) {
293 uint32_t candidate = rtc::CreateRandomNonZeroId() % kMaxSctpSid;
294 if (!GetStreamBySsrc(params_vec, candidate)) {
295 *sid = candidate;
296 return true;
297 }
298 }
299 }
300
301 static bool GenerateSctpSids(const StreamParamsVec& params_vec,
302 std::vector<uint32_t>* sids) {
303 uint32_t sid;
304 if (!GenerateSctpSid(params_vec, &sid)) {
305 LOG(LS_WARNING) << "Could not generated an SCTP SID.";
306 return false;
307 }
308 sids->push_back(sid);
309 return true;
310 }
311
312 // Finds all StreamParams of all media types and attach them to stream_params. 279 // Finds all StreamParams of all media types and attach them to stream_params.
313 static void GetCurrentStreamParams(const SessionDescription* sdesc, 280 static void GetCurrentStreamParams(const SessionDescription* sdesc,
314 StreamParamsVec* stream_params) { 281 StreamParamsVec* stream_params) {
315 if (!sdesc) 282 if (!sdesc)
316 return; 283 return;
317 284
318 const ContentInfos& contents = sdesc->contents(); 285 const ContentInfos& contents = sdesc->contents();
319 for (ContentInfos::const_iterator content = contents.begin(); 286 for (ContentInfos::const_iterator content = contents.begin();
320 content != contents.end(); ++content) { 287 content != contents.end(); ++content) {
321 if (!IsMediaContent(&*content)) { 288 if (!IsMediaContent(&*content)) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 414
448 // Adds a StreamParams for each Stream in Streams with media type 415 // Adds a StreamParams for each Stream in Streams with media type
449 // media_type to content_description. 416 // media_type to content_description.
450 // |current_params| - All currently known StreamParams of any media type. 417 // |current_params| - All currently known StreamParams of any media type.
451 template <class C> 418 template <class C>
452 static bool AddStreamParams(MediaType media_type, 419 static bool AddStreamParams(MediaType media_type,
453 const MediaSessionOptions& options, 420 const MediaSessionOptions& options,
454 StreamParamsVec* current_streams, 421 StreamParamsVec* current_streams,
455 MediaContentDescriptionImpl<C>* content_description, 422 MediaContentDescriptionImpl<C>* content_description,
456 const bool add_legacy_stream) { 423 const bool add_legacy_stream) {
424 // SCTP streams are not negotiated using SDP/ContentDescriptions.
425 if (IsSctp(content_description)) {
426 return true;
427 }
428
457 const bool include_rtx_streams = 429 const bool include_rtx_streams =
458 ContainsRtxCodec(content_description->codecs()); 430 ContainsRtxCodec(content_description->codecs());
459 431
460 const MediaSessionOptions::Streams& streams = options.streams; 432 const MediaSessionOptions::Streams& streams = options.streams;
461 if (streams.empty() && add_legacy_stream) { 433 if (streams.empty() && add_legacy_stream) {
462 // TODO(perkj): Remove this legacy stream when all apps use StreamParams. 434 // TODO(perkj): Remove this legacy stream when all apps use StreamParams.
463 std::vector<uint32_t> ssrcs; 435 std::vector<uint32_t> ssrcs;
464 if (IsSctp(content_description)) { 436 int num_ssrcs = include_rtx_streams ? 2 : 1;
465 GenerateSctpSids(*current_streams, &ssrcs); 437 GenerateSsrcs(*current_streams, num_ssrcs, &ssrcs);
466 } else {
467 int num_ssrcs = include_rtx_streams ? 2 : 1;
468 GenerateSsrcs(*current_streams, num_ssrcs, &ssrcs);
469 }
470 if (include_rtx_streams) { 438 if (include_rtx_streams) {
471 content_description->AddLegacyStream(ssrcs[0], ssrcs[1]); 439 content_description->AddLegacyStream(ssrcs[0], ssrcs[1]);
472 content_description->set_multistream(true); 440 content_description->set_multistream(true);
473 } else { 441 } else {
474 content_description->AddLegacyStream(ssrcs[0]); 442 content_description->AddLegacyStream(ssrcs[0]);
475 } 443 }
476 return true; 444 return true;
477 } 445 }
478 446
479 MediaSessionOptions::Streams::const_iterator stream_it; 447 MediaSessionOptions::Streams::const_iterator stream_it;
480 for (stream_it = streams.begin(); 448 for (stream_it = streams.begin();
481 stream_it != streams.end(); ++stream_it) { 449 stream_it != streams.end(); ++stream_it) {
482 if (stream_it->type != media_type) 450 if (stream_it->type != media_type)
483 continue; // Wrong media type. 451 continue; // Wrong media type.
484 452
485 const StreamParams* param = 453 const StreamParams* param =
486 GetStreamByIds(*current_streams, "", stream_it->id); 454 GetStreamByIds(*current_streams, "", stream_it->id);
487 // groupid is empty for StreamParams generated using 455 // groupid is empty for StreamParams generated using
488 // MediaSessionDescriptionFactory. 456 // MediaSessionDescriptionFactory.
489 if (!param) { 457 if (!param) {
490 // This is a new stream. 458 // This is a new stream.
491 std::vector<uint32_t> ssrcs; 459 std::vector<uint32_t> ssrcs;
492 if (IsSctp(content_description)) { 460 GenerateSsrcs(*current_streams, stream_it->num_sim_layers, &ssrcs);
493 GenerateSctpSids(*current_streams, &ssrcs);
494 } else {
495 GenerateSsrcs(*current_streams, stream_it->num_sim_layers, &ssrcs);
496 }
497 StreamParams stream_param; 461 StreamParams stream_param;
498 stream_param.id = stream_it->id; 462 stream_param.id = stream_it->id;
499 // Add the generated ssrc. 463 // Add the generated ssrc.
500 for (size_t i = 0; i < ssrcs.size(); ++i) { 464 for (size_t i = 0; i < ssrcs.size(); ++i) {
501 stream_param.ssrcs.push_back(ssrcs[i]); 465 stream_param.ssrcs.push_back(ssrcs[i]);
502 } 466 }
503 if (stream_it->num_sim_layers > 1) { 467 if (stream_it->num_sim_layers > 1) {
504 SsrcGroup group(kSimSsrcGroupSemantics, stream_param.ssrcs); 468 SsrcGroup group(kSimSsrcGroupSemantics, stream_param.ssrcs);
505 stream_param.ssrc_groups.push_back(group); 469 stream_param.ssrc_groups.push_back(group);
506 } 470 }
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); 2158 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO));
2195 } 2159 }
2196 2160
2197 DataContentDescription* GetFirstDataContentDescription( 2161 DataContentDescription* GetFirstDataContentDescription(
2198 SessionDescription* sdesc) { 2162 SessionDescription* sdesc) {
2199 return static_cast<DataContentDescription*>( 2163 return static_cast<DataContentDescription*>(
2200 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); 2164 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA));
2201 } 2165 }
2202 2166
2203 } // namespace cricket 2167 } // namespace cricket
OLDNEW
« webrtc/media/sctp/sctpdataengine.h ('K') | « webrtc/media/sctp/sctpdataengine_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698