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

Side by Side Diff: webrtc/api/peerconnection.cc

Issue 1871993002: Only generate one CNAME per PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Renaming: cname -> rtcp_cname. Modified the peerconnectioninterface unit tests. Created 4 years, 7 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
« no previous file with comments | « webrtc/api/peerconnection.h ('k') | webrtc/api/peerconnectioninterface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Number of tokens must be preset when TURN uri has transport param. 59 // Number of tokens must be preset when TURN uri has transport param.
60 static const size_t kTurnTransportTokensNum = 2; 60 static const size_t kTurnTransportTokensNum = 2;
61 // The default stun port. 61 // The default stun port.
62 static const int kDefaultStunPort = 3478; 62 static const int kDefaultStunPort = 3478;
63 static const int kDefaultStunTlsPort = 5349; 63 static const int kDefaultStunTlsPort = 5349;
64 static const char kTransport[] = "transport"; 64 static const char kTransport[] = "transport";
65 65
66 // NOTE: Must be in the same order as the ServiceType enum. 66 // NOTE: Must be in the same order as the ServiceType enum.
67 static const char* kValidIceServiceTypes[] = {"stun", "stuns", "turn", "turns"}; 67 static const char* kValidIceServiceTypes[] = {"stun", "stuns", "turn", "turns"};
68 68
69 // The length of RTCP CNAMEs.
70 static const int kRtcpCnameLength = 16;
71
69 // NOTE: A loop below assumes that the first value of this enum is 0 and all 72 // NOTE: A loop below assumes that the first value of this enum is 0 and all
70 // other values are incremental. 73 // other values are incremental.
71 enum ServiceType { 74 enum ServiceType {
72 STUN = 0, // Indicates a STUN server. 75 STUN = 0, // Indicates a STUN server.
73 STUNS, // Indicates a STUN server used with a TLS session. 76 STUNS, // Indicates a STUN server used with a TLS session.
74 TURN, // Indicates a TURN server 77 TURN, // Indicates a TURN server
75 TURNS, // Indicates a TURN server used with a TLS session. 78 TURNS, // Indicates a TURN server used with a TLS session.
76 INVALID, // Unknown. 79 INVALID, // Unknown.
77 }; 80 };
78 static_assert(INVALID == arraysize(kValidIceServiceTypes), 81 static_assert(INVALID == arraysize(kValidIceServiceTypes),
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, streamid, 373 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, streamid,
371 sync_label); 374 sync_label);
372 } 375 }
373 } 376 }
374 } 377 }
375 378
376 } // namespace 379 } // namespace
377 380
378 namespace webrtc { 381 namespace webrtc {
379 382
383 // Generate a RTCP CNAME when a PeerConnection is created.
384 std::string GenerateRtcpCname() {
385 std::string cname;
386 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) {
387 LOG(LS_ERROR) << "Failed to generate CNAME.";
388 RTC_DCHECK(false);
389 }
390 return cname;
391 }
392
380 bool ExtractMediaSessionOptions( 393 bool ExtractMediaSessionOptions(
381 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, 394 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
382 bool is_offer, 395 bool is_offer,
383 cricket::MediaSessionOptions* session_options) { 396 cricket::MediaSessionOptions* session_options) {
384 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; 397 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
385 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || 398 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) ||
386 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { 399 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) {
387 return false; 400 return false;
388 } 401 }
389 402
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 514 }
502 515
503 PeerConnection::PeerConnection(PeerConnectionFactory* factory) 516 PeerConnection::PeerConnection(PeerConnectionFactory* factory)
504 : factory_(factory), 517 : factory_(factory),
505 observer_(NULL), 518 observer_(NULL),
506 uma_observer_(NULL), 519 uma_observer_(NULL),
507 signaling_state_(kStable), 520 signaling_state_(kStable),
508 ice_state_(kIceNew), 521 ice_state_(kIceNew),
509 ice_connection_state_(kIceConnectionNew), 522 ice_connection_state_(kIceConnectionNew),
510 ice_gathering_state_(kIceGatheringNew), 523 ice_gathering_state_(kIceGatheringNew),
524 rtcp_cname_(GenerateRtcpCname()),
511 local_streams_(StreamCollection::Create()), 525 local_streams_(StreamCollection::Create()),
512 remote_streams_(StreamCollection::Create()) {} 526 remote_streams_(StreamCollection::Create()) {}
513 527
514 PeerConnection::~PeerConnection() { 528 PeerConnection::~PeerConnection() {
515 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); 529 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection");
516 RTC_DCHECK(signaling_thread()->IsCurrent()); 530 RTC_DCHECK(signaling_thread()->IsCurrent());
517 // Need to detach RTP senders/receivers from WebRtcSession, 531 // Need to detach RTP senders/receivers from WebRtcSession,
518 // since it's about to be destroyed. 532 // since it's about to be destroyed.
519 for (const auto& sender : senders_) { 533 for (const auto& sender : senders_) {
520 sender->Stop(); 534 sender->Stop();
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 !remote_video_tracks_.empty(); 1510 !remote_video_tracks_.empty();
1497 } 1511 }
1498 session_options->bundle_enabled = 1512 session_options->bundle_enabled =
1499 session_options->bundle_enabled && 1513 session_options->bundle_enabled &&
1500 (session_options->has_audio() || session_options->has_video() || 1514 (session_options->has_audio() || session_options->has_video() ||
1501 session_options->has_data()); 1515 session_options->has_data());
1502 1516
1503 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { 1517 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) {
1504 session_options->data_channel_type = cricket::DCT_SCTP; 1518 session_options->data_channel_type = cricket::DCT_SCTP;
1505 } 1519 }
1520
1521 session_options->rtcp_cname = rtcp_cname_;
1506 return true; 1522 return true;
1507 } 1523 }
1508 1524
1509 void PeerConnection::FinishOptionsForAnswer( 1525 void PeerConnection::FinishOptionsForAnswer(
1510 cricket::MediaSessionOptions* session_options) { 1526 cricket::MediaSessionOptions* session_options) {
1511 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of 1527 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of
1512 // ContentInfos. 1528 // ContentInfos.
1513 if (session_->remote_description()) { 1529 if (session_->remote_description()) {
1514 // Initialize the transport_options map. 1530 // Initialize the transport_options map.
1515 for (const cricket::ContentInfo& content : 1531 for (const cricket::ContentInfo& content :
(...skipping 17 matching lines...) Expand all
1533 } 1549 }
1534 1550
1535 bool PeerConnection::GetOptionsForAnswer( 1551 bool PeerConnection::GetOptionsForAnswer(
1536 const MediaConstraintsInterface* constraints, 1552 const MediaConstraintsInterface* constraints,
1537 cricket::MediaSessionOptions* session_options) { 1553 cricket::MediaSessionOptions* session_options) {
1538 session_options->recv_audio = false; 1554 session_options->recv_audio = false;
1539 session_options->recv_video = false; 1555 session_options->recv_video = false;
1540 if (!ParseConstraintsForAnswer(constraints, session_options)) { 1556 if (!ParseConstraintsForAnswer(constraints, session_options)) {
1541 return false; 1557 return false;
1542 } 1558 }
1559 session_options->rtcp_cname = rtcp_cname_;
1560
1543 FinishOptionsForAnswer(session_options); 1561 FinishOptionsForAnswer(session_options);
1544 return true; 1562 return true;
1545 } 1563 }
1546 1564
1547 bool PeerConnection::GetOptionsForAnswer( 1565 bool PeerConnection::GetOptionsForAnswer(
1548 const RTCOfferAnswerOptions& options, 1566 const RTCOfferAnswerOptions& options,
1549 cricket::MediaSessionOptions* session_options) { 1567 cricket::MediaSessionOptions* session_options) {
1550 session_options->recv_audio = false; 1568 session_options->recv_audio = false;
1551 session_options->recv_video = false; 1569 session_options->recv_video = false;
1552 if (!ExtractMediaSessionOptions(options, false, session_options)) { 1570 if (!ExtractMediaSessionOptions(options, false, session_options)) {
1553 return false; 1571 return false;
1554 } 1572 }
1573 session_options->rtcp_cname = rtcp_cname_;
1574
1555 FinishOptionsForAnswer(session_options); 1575 FinishOptionsForAnswer(session_options);
1556 return true; 1576 return true;
1557 } 1577 }
1558 1578
1559 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { 1579 void PeerConnection::RemoveTracks(cricket::MediaType media_type) {
1560 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); 1580 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type);
1561 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, 1581 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false,
1562 media_type, nullptr); 1582 media_type, nullptr);
1563 } 1583 }
1564 1584
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2059 for (const auto& channel : sctp_data_channels_) { 2079 for (const auto& channel : sctp_data_channels_) {
2060 if (channel->id() == sid) { 2080 if (channel->id() == sid) {
2061 return channel; 2081 return channel;
2062 } 2082 }
2063 } 2083 }
2064 return nullptr; 2084 return nullptr;
2065 } 2085 }
2066 2086
2067 } // namespace webrtc 2087 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.h ('k') | webrtc/api/peerconnectioninterface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698