Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 CNAMEs. | |
| 70 static const int kCnameLength = 16; | |
|
pthatcher1
2016/05/05 18:50:51
Can you call this kRtcpCnameLength and RTCP CNAME
Zhi Huang
2016/05/06 01:36:53
Done.
| |
| 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 Loading... | |
| 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 CNAME when a PeerConnection is created. | |
| 384 std::string GenerateCname() { | |
|
pthatcher1
2016/05/05 18:50:51
Can you call this GenerateRtcpCname() and use "RTC
Zhi Huang
2016/05/06 01:36:53
Done.
| |
| 385 std::string cname; | |
| 386 if (!rtc::CreateRandomString(kCnameLength, &cname)) { | |
| 387 LOG(LS_ERROR) << "Failed to generate CNAME."; | |
|
pthatcher1
2016/05/05 18:50:51
We should probably RTC_DCHECK(false) here as well.
Zhi Huang
2016/05/06 01:36:53
Right. This is a point I should not overlook.
| |
| 388 } | |
| 389 return cname; | |
| 390 } | |
| 391 | |
| 380 bool ExtractMediaSessionOptions( | 392 bool ExtractMediaSessionOptions( |
| 381 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 393 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 382 bool is_offer, | 394 bool is_offer, |
| 383 cricket::MediaSessionOptions* session_options) { | 395 cricket::MediaSessionOptions* session_options) { |
| 384 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; | 396 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 385 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || | 397 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || |
| 386 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { | 398 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { |
| 387 return false; | 399 return false; |
| 388 } | 400 } |
| 389 | 401 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 } | 513 } |
| 502 | 514 |
| 503 PeerConnection::PeerConnection(PeerConnectionFactory* factory) | 515 PeerConnection::PeerConnection(PeerConnectionFactory* factory) |
| 504 : factory_(factory), | 516 : factory_(factory), |
| 505 observer_(NULL), | 517 observer_(NULL), |
| 506 uma_observer_(NULL), | 518 uma_observer_(NULL), |
| 507 signaling_state_(kStable), | 519 signaling_state_(kStable), |
| 508 ice_state_(kIceNew), | 520 ice_state_(kIceNew), |
| 509 ice_connection_state_(kIceConnectionNew), | 521 ice_connection_state_(kIceConnectionNew), |
| 510 ice_gathering_state_(kIceGatheringNew), | 522 ice_gathering_state_(kIceGatheringNew), |
| 523 cname_(GenerateCname()), | |
| 511 local_streams_(StreamCollection::Create()), | 524 local_streams_(StreamCollection::Create()), |
| 512 remote_streams_(StreamCollection::Create()) {} | 525 remote_streams_(StreamCollection::Create()) {} |
| 513 | 526 |
| 514 PeerConnection::~PeerConnection() { | 527 PeerConnection::~PeerConnection() { |
| 515 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); | 528 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); |
| 516 RTC_DCHECK(signaling_thread()->IsCurrent()); | 529 RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 517 // Need to detach RTP senders/receivers from WebRtcSession, | 530 // Need to detach RTP senders/receivers from WebRtcSession, |
| 518 // since it's about to be destroyed. | 531 // since it's about to be destroyed. |
| 519 for (const auto& sender : senders_) { | 532 for (const auto& sender : senders_) { |
| 520 sender->Stop(); | 533 sender->Stop(); |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 !remote_video_tracks_.empty(); | 1509 !remote_video_tracks_.empty(); |
| 1497 } | 1510 } |
| 1498 session_options->bundle_enabled = | 1511 session_options->bundle_enabled = |
| 1499 session_options->bundle_enabled && | 1512 session_options->bundle_enabled && |
| 1500 (session_options->has_audio() || session_options->has_video() || | 1513 (session_options->has_audio() || session_options->has_video() || |
| 1501 session_options->has_data()); | 1514 session_options->has_data()); |
| 1502 | 1515 |
| 1503 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { | 1516 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { |
| 1504 session_options->data_channel_type = cricket::DCT_SCTP; | 1517 session_options->data_channel_type = cricket::DCT_SCTP; |
| 1505 } | 1518 } |
| 1519 | |
| 1520 session_options->cname = cname_; | |
| 1506 return true; | 1521 return true; |
| 1507 } | 1522 } |
| 1508 | 1523 |
| 1509 void PeerConnection::FinishOptionsForAnswer( | 1524 void PeerConnection::FinishOptionsForAnswer( |
| 1510 cricket::MediaSessionOptions* session_options) { | 1525 cricket::MediaSessionOptions* session_options) { |
| 1511 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1526 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
| 1512 // ContentInfos. | 1527 // ContentInfos. |
| 1513 if (session_->remote_description()) { | 1528 if (session_->remote_description()) { |
| 1514 // Initialize the transport_options map. | 1529 // Initialize the transport_options map. |
| 1515 for (const cricket::ContentInfo& content : | 1530 for (const cricket::ContentInfo& content : |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1533 } | 1548 } |
| 1534 | 1549 |
| 1535 bool PeerConnection::GetOptionsForAnswer( | 1550 bool PeerConnection::GetOptionsForAnswer( |
| 1536 const MediaConstraintsInterface* constraints, | 1551 const MediaConstraintsInterface* constraints, |
| 1537 cricket::MediaSessionOptions* session_options) { | 1552 cricket::MediaSessionOptions* session_options) { |
| 1538 session_options->recv_audio = false; | 1553 session_options->recv_audio = false; |
| 1539 session_options->recv_video = false; | 1554 session_options->recv_video = false; |
| 1540 if (!ParseConstraintsForAnswer(constraints, session_options)) { | 1555 if (!ParseConstraintsForAnswer(constraints, session_options)) { |
| 1541 return false; | 1556 return false; |
| 1542 } | 1557 } |
| 1558 session_options->cname = cname_; | |
| 1559 | |
| 1543 FinishOptionsForAnswer(session_options); | 1560 FinishOptionsForAnswer(session_options); |
| 1544 return true; | 1561 return true; |
| 1545 } | 1562 } |
| 1546 | 1563 |
| 1547 bool PeerConnection::GetOptionsForAnswer( | 1564 bool PeerConnection::GetOptionsForAnswer( |
| 1548 const RTCOfferAnswerOptions& options, | 1565 const RTCOfferAnswerOptions& options, |
| 1549 cricket::MediaSessionOptions* session_options) { | 1566 cricket::MediaSessionOptions* session_options) { |
| 1550 session_options->recv_audio = false; | 1567 session_options->recv_audio = false; |
| 1551 session_options->recv_video = false; | 1568 session_options->recv_video = false; |
| 1552 if (!ExtractMediaSessionOptions(options, false, session_options)) { | 1569 if (!ExtractMediaSessionOptions(options, false, session_options)) { |
| 1553 return false; | 1570 return false; |
| 1554 } | 1571 } |
| 1572 session_options->cname = cname_; | |
| 1573 | |
| 1555 FinishOptionsForAnswer(session_options); | 1574 FinishOptionsForAnswer(session_options); |
| 1556 return true; | 1575 return true; |
| 1557 } | 1576 } |
| 1558 | 1577 |
| 1559 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { | 1578 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
| 1560 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); | 1579 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
| 1561 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, | 1580 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, |
| 1562 media_type, nullptr); | 1581 media_type, nullptr); |
| 1563 } | 1582 } |
| 1564 | 1583 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2058 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2077 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
| 2059 for (const auto& channel : sctp_data_channels_) { | 2078 for (const auto& channel : sctp_data_channels_) { |
| 2060 if (channel->id() == sid) { | 2079 if (channel->id() == sid) { |
| 2061 return channel; | 2080 return channel; |
| 2062 } | 2081 } |
| 2063 } | 2082 } |
| 2064 return nullptr; | 2083 return nullptr; |
| 2065 } | 2084 } |
| 2066 | 2085 |
| 2067 } // namespace webrtc | 2086 } // namespace webrtc |
| OLD | NEW |