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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { | 436 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { |
| 437 LOG(LS_ERROR) << "Failed to generate CNAME."; | 437 LOG(LS_ERROR) << "Failed to generate CNAME."; |
| 438 RTC_DCHECK(false); | 438 RTC_DCHECK(false); |
| 439 } | 439 } |
| 440 return cname; | 440 return cname; |
| 441 } | 441 } |
| 442 | 442 |
| 443 bool ExtractMediaSessionOptions( | 443 bool ExtractMediaSessionOptions( |
| 444 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 444 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 445 bool is_offer, | 445 bool is_offer, |
| 446 bool ice_renomination, | |
| 446 cricket::MediaSessionOptions* session_options) { | 447 cricket::MediaSessionOptions* session_options) { |
| 447 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; | 448 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 448 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || | 449 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || |
| 449 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { | 450 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { |
| 450 return false; | 451 return false; |
| 451 } | 452 } |
| 452 | 453 |
| 453 // If constraints don't prevent us, we always accept video. | 454 // If constraints don't prevent us, we always accept video. |
| 454 if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) { | 455 if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) { |
| 455 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); | 456 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); |
| 456 } else { | 457 } else { |
| 457 session_options->recv_audio = true; | 458 session_options->recv_audio = true; |
| 458 } | 459 } |
| 459 // For offers, we only offer video if we have it or it's forced by options. | 460 // For offers, we only offer video if we have it or it's forced by options. |
| 460 // For answers, we will always accept video (if offered). | 461 // For answers, we will always accept video (if offered). |
| 461 if (rtc_options.offer_to_receive_video != RTCOfferAnswerOptions::kUndefined) { | 462 if (rtc_options.offer_to_receive_video != RTCOfferAnswerOptions::kUndefined) { |
| 462 session_options->recv_video = (rtc_options.offer_to_receive_video > 0); | 463 session_options->recv_video = (rtc_options.offer_to_receive_video > 0); |
| 463 } else if (is_offer) { | 464 } else if (is_offer) { |
| 464 session_options->recv_video = false; | 465 session_options->recv_video = false; |
| 465 } else { | 466 } else { |
| 466 session_options->recv_video = true; | 467 session_options->recv_video = true; |
| 467 } | 468 } |
| 468 | 469 |
| 469 session_options->vad_enabled = rtc_options.voice_activity_detection; | 470 session_options->vad_enabled = rtc_options.voice_activity_detection; |
| 470 session_options->bundle_enabled = rtc_options.use_rtp_mux; | 471 session_options->bundle_enabled = rtc_options.use_rtp_mux; |
| 472 // Add transport options so that ice_renomination can be set properly to the | |
| 473 // respective transport option. | |
| 474 if (session_options->transport_options.empty()) { | |
| 475 std::vector<std::string> content_names = { | |
| 476 cricket::CN_AUDIO, cricket::CN_VIDEO, cricket::CN_DATA}; | |
|
Taylor Brandstetter
2016/08/17 22:01:59
This won't work interoperably. The offer could con
honghaiz3
2016/08/19 18:42:00
I don't think that would work.
When we initialize
Taylor Brandstetter
2016/08/20 00:52:13
Sorry, I just noticed that GetOptionsForOffer *doe
honghaiz3
2016/08/22 18:46:44
Done.
| |
| 477 for (auto& content_name : content_names) { | |
| 478 session_options->transport_options[content_name] = | |
| 479 cricket::TransportOptions(); | |
| 480 } | |
| 481 } | |
| 471 for (auto& kv : session_options->transport_options) { | 482 for (auto& kv : session_options->transport_options) { |
| 472 kv.second.ice_restart = rtc_options.ice_restart; | 483 kv.second.ice_restart = rtc_options.ice_restart; |
| 484 kv.second.ice_renomination = ice_renomination; | |
| 473 } | 485 } |
| 474 | 486 |
| 475 return true; | 487 return true; |
| 476 } | 488 } |
| 477 | 489 |
| 478 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, | 490 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
| 479 cricket::MediaSessionOptions* session_options) { | 491 cricket::MediaSessionOptions* session_options) { |
| 480 bool value = false; | 492 bool value = false; |
| 481 size_t mandatory_constraints_satisfied = 0; | 493 size_t mandatory_constraints_satisfied = 0; |
| 482 | 494 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 506 } | 518 } |
| 507 | 519 |
| 508 if (FindConstraint(constraints, MediaConstraintsInterface::kUseRtpMux, &value, | 520 if (FindConstraint(constraints, MediaConstraintsInterface::kUseRtpMux, &value, |
| 509 &mandatory_constraints_satisfied)) { | 521 &mandatory_constraints_satisfied)) { |
| 510 session_options->bundle_enabled = value; | 522 session_options->bundle_enabled = value; |
| 511 } else { | 523 } else { |
| 512 // kUseRtpMux defaults to true according to spec. | 524 // kUseRtpMux defaults to true according to spec. |
| 513 session_options->bundle_enabled = true; | 525 session_options->bundle_enabled = true; |
| 514 } | 526 } |
| 515 | 527 |
| 516 bool ice_restart = false; | |
| 517 if (FindConstraint(constraints, MediaConstraintsInterface::kIceRestart, | |
| 518 &value, &mandatory_constraints_satisfied)) { | |
| 519 // kIceRestart defaults to false according to spec. | |
| 520 ice_restart = true; | |
| 521 } | |
| 522 for (auto& kv : session_options->transport_options) { | |
| 523 kv.second.ice_restart = ice_restart; | |
| 524 } | |
| 525 | |
| 526 if (!constraints) { | 528 if (!constraints) { |
| 527 return true; | 529 return true; |
| 528 } | 530 } |
| 529 return mandatory_constraints_satisfied == constraints->GetMandatory().size(); | 531 return mandatory_constraints_satisfied == constraints->GetMandatory().size(); |
| 530 } | 532 } |
| 531 | 533 |
| 532 bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, | 534 bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, |
| 533 cricket::ServerAddresses* stun_servers, | 535 cricket::ServerAddresses* stun_servers, |
| 534 std::vector<cricket::RelayServerConfig>* turn_servers) { | 536 std::vector<cricket::RelayServerConfig>* turn_servers) { |
| 535 for (const webrtc::PeerConnectionInterface::IceServer& server : servers) { | 537 for (const webrtc::PeerConnectionInterface::IceServer& server : servers) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 | 626 |
| 625 session_.reset(new WebRtcSession( | 627 session_.reset(new WebRtcSession( |
| 626 media_controller_.get(), factory_->network_thread(), | 628 media_controller_.get(), factory_->network_thread(), |
| 627 factory_->worker_thread(), factory_->signaling_thread(), | 629 factory_->worker_thread(), factory_->signaling_thread(), |
| 628 port_allocator_.get(), | 630 port_allocator_.get(), |
| 629 std::unique_ptr<cricket::TransportController>( | 631 std::unique_ptr<cricket::TransportController>( |
| 630 factory_->CreateTransportController(port_allocator_.get())))); | 632 factory_->CreateTransportController(port_allocator_.get())))); |
| 631 | 633 |
| 632 stats_.reset(new StatsCollector(this)); | 634 stats_.reset(new StatsCollector(this)); |
| 633 | 635 |
| 636 ice_renomination_ = configuration.ice_renomination; | |
| 637 | |
| 634 // Initialize the WebRtcSession. It creates transport channels etc. | 638 // Initialize the WebRtcSession. It creates transport channels etc. |
| 635 if (!session_->Initialize(factory_->options(), std::move(cert_generator), | 639 if (!session_->Initialize(factory_->options(), std::move(cert_generator), |
| 636 configuration)) { | 640 configuration)) { |
| 637 return false; | 641 return false; |
| 638 } | 642 } |
| 639 | 643 |
| 640 // Register PeerConnection as receiver of local ice candidates. | 644 // Register PeerConnection as receiver of local ice candidates. |
| 641 // All the callbacks will be posted to the application from PeerConnection. | 645 // All the callbacks will be posted to the application from PeerConnection. |
| 642 session_->RegisterIceObserver(this); | 646 session_->RegisterIceObserver(this); |
| 643 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); | 647 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1253 if (!network_thread()->Invoke<bool>( | 1257 if (!network_thread()->Invoke<bool>( |
| 1254 RTC_FROM_HERE, | 1258 RTC_FROM_HERE, |
| 1255 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this, | 1259 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this, |
| 1256 configuration))) { | 1260 configuration))) { |
| 1257 return false; | 1261 return false; |
| 1258 } | 1262 } |
| 1259 } | 1263 } |
| 1260 | 1264 |
| 1261 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... | 1265 // TODO(deadbeef): Shouldn't have to hop to the worker thread twice... |
| 1262 session_->SetIceConfig(session_->ParseIceConfig(configuration)); | 1266 session_->SetIceConfig(session_->ParseIceConfig(configuration)); |
| 1267 | |
| 1268 ice_renomination_ = configuration.ice_renomination; | |
| 1263 return true; | 1269 return true; |
| 1264 } | 1270 } |
| 1265 | 1271 |
| 1266 bool PeerConnection::AddIceCandidate( | 1272 bool PeerConnection::AddIceCandidate( |
| 1267 const IceCandidateInterface* ice_candidate) { | 1273 const IceCandidateInterface* ice_candidate) { |
| 1268 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); | 1274 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); |
| 1269 if (IsClosed()) { | 1275 if (IsClosed()) { |
| 1270 return false; | 1276 return false; |
| 1271 } | 1277 } |
| 1272 return session_->ProcessIceMessage(ice_candidate); | 1278 return session_->ProcessIceMessage(ice_candidate); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 1611 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 1606 cricket::MediaSessionOptions* session_options) { | 1612 cricket::MediaSessionOptions* session_options) { |
| 1607 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1613 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
| 1608 // ContentInfos. | 1614 // ContentInfos. |
| 1609 if (session_->local_description()) { | 1615 if (session_->local_description()) { |
| 1610 for (const cricket::ContentInfo& content : | 1616 for (const cricket::ContentInfo& content : |
| 1611 session_->local_description()->description()->contents()) { | 1617 session_->local_description()->description()->contents()) { |
| 1612 session_options->transport_options[content.name] = | 1618 session_options->transport_options[content.name] = |
| 1613 cricket::TransportOptions(); | 1619 cricket::TransportOptions(); |
| 1614 } | 1620 } |
| 1615 } | 1621 } |
|
Taylor Brandstetter
2016/08/20 00:52:13
Here's where I think it would make sense to add th
| |
| 1616 if (!ExtractMediaSessionOptions(rtc_options, true, session_options)) { | 1622 if (!ExtractMediaSessionOptions(rtc_options, true, ice_renomination_, |
| 1623 session_options)) { | |
| 1617 return false; | 1624 return false; |
| 1618 } | 1625 } |
| 1619 | 1626 |
| 1620 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1627 AddSendStreams(session_options, senders_, rtp_data_channels_); |
| 1621 // Offer to receive audio/video if the constraint is not set and there are | 1628 // Offer to receive audio/video if the constraint is not set and there are |
| 1622 // send streams, or we're currently receiving. | 1629 // send streams, or we're currently receiving. |
| 1623 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { | 1630 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { |
| 1624 session_options->recv_audio = | 1631 session_options->recv_audio = |
| 1625 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || | 1632 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || |
| 1626 !remote_audio_tracks_.empty(); | 1633 !remote_audio_tracks_.empty(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1642 // people won't try to use them. | 1649 // people won't try to use them. |
| 1643 if (HasDataChannels() && session_->data_channel_type() != cricket::DCT_RTP) { | 1650 if (HasDataChannels() && session_->data_channel_type() != cricket::DCT_RTP) { |
| 1644 session_options->data_channel_type = session_->data_channel_type(); | 1651 session_options->data_channel_type = session_->data_channel_type(); |
| 1645 } | 1652 } |
| 1646 | 1653 |
| 1647 session_options->rtcp_cname = rtcp_cname_; | 1654 session_options->rtcp_cname = rtcp_cname_; |
| 1648 session_options->crypto_options = factory_->options().crypto_options; | 1655 session_options->crypto_options = factory_->options().crypto_options; |
| 1649 return true; | 1656 return true; |
| 1650 } | 1657 } |
| 1651 | 1658 |
| 1659 void PeerConnection::InitializeOptionsForAnswer( | |
| 1660 cricket::MediaSessionOptions* session_options) { | |
| 1661 session_options->recv_audio = false; | |
| 1662 session_options->recv_video = false; | |
| 1663 if (session_->remote_description()) { | |
| 1664 // Initialize the transport_options map. | |
| 1665 for (const cricket::ContentInfo& content : | |
| 1666 session_->remote_description()->description()->contents()) { | |
| 1667 cricket::TransportOptions options; | |
| 1668 options.ice_renomination = ice_renomination_; | |
| 1669 session_options->transport_options[content.name] = options; | |
| 1670 } | |
| 1671 } | |
| 1672 } | |
| 1673 | |
| 1652 void PeerConnection::FinishOptionsForAnswer( | 1674 void PeerConnection::FinishOptionsForAnswer( |
| 1653 cricket::MediaSessionOptions* session_options) { | 1675 cricket::MediaSessionOptions* session_options) { |
| 1654 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1676 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
| 1655 // ContentInfos. | 1677 // ContentInfos. |
| 1656 if (session_->remote_description()) { | |
| 1657 // Initialize the transport_options map. | |
| 1658 for (const cricket::ContentInfo& content : | |
| 1659 session_->remote_description()->description()->contents()) { | |
| 1660 session_options->transport_options[content.name] = | |
| 1661 cricket::TransportOptions(); | |
| 1662 } | |
| 1663 } | |
| 1664 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1678 AddSendStreams(session_options, senders_, rtp_data_channels_); |
| 1665 session_options->bundle_enabled = | 1679 session_options->bundle_enabled = |
| 1666 session_options->bundle_enabled && | 1680 session_options->bundle_enabled && |
| 1667 (session_options->has_audio() || session_options->has_video() || | 1681 (session_options->has_audio() || session_options->has_video() || |
| 1668 session_options->has_data()); | 1682 session_options->has_data()); |
| 1669 | 1683 |
| 1670 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1684 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
| 1671 // are not signaled in the SDP so does not go through that path and must be | 1685 // are not signaled in the SDP so does not go through that path and must be |
| 1672 // handled here. | 1686 // handled here. |
| 1673 // Intentionally unset the data channel type for RTP data channel. Otherwise | 1687 // Intentionally unset the data channel type for RTP data channel. Otherwise |
| 1674 // the RTP data channels would be successfully negotiated by default and the | 1688 // the RTP data channels would be successfully negotiated by default and the |
| 1675 // unit tests in WebRtcDataBrowserTest will fail when building with chromium. | 1689 // unit tests in WebRtcDataBrowserTest will fail when building with chromium. |
| 1676 // We want to leave RTP data channels broken, so people won't try to use them. | 1690 // We want to leave RTP data channels broken, so people won't try to use them. |
| 1677 if (session_->data_channel_type() != cricket::DCT_RTP) { | 1691 if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 1678 session_options->data_channel_type = session_->data_channel_type(); | 1692 session_options->data_channel_type = session_->data_channel_type(); |
| 1679 } | 1693 } |
| 1680 session_options->crypto_options = factory_->options().crypto_options; | 1694 session_options->crypto_options = factory_->options().crypto_options; |
| 1681 } | 1695 } |
| 1682 | 1696 |
| 1683 bool PeerConnection::GetOptionsForAnswer( | 1697 bool PeerConnection::GetOptionsForAnswer( |
| 1684 const MediaConstraintsInterface* constraints, | 1698 const MediaConstraintsInterface* constraints, |
| 1685 cricket::MediaSessionOptions* session_options) { | 1699 cricket::MediaSessionOptions* session_options) { |
| 1686 session_options->recv_audio = false; | 1700 InitializeOptionsForAnswer(session_options); |
| 1687 session_options->recv_video = false; | |
| 1688 if (!ParseConstraintsForAnswer(constraints, session_options)) { | 1701 if (!ParseConstraintsForAnswer(constraints, session_options)) { |
| 1689 return false; | 1702 return false; |
| 1690 } | 1703 } |
| 1691 session_options->rtcp_cname = rtcp_cname_; | 1704 session_options->rtcp_cname = rtcp_cname_; |
| 1692 | 1705 |
| 1693 FinishOptionsForAnswer(session_options); | 1706 FinishOptionsForAnswer(session_options); |
| 1694 return true; | 1707 return true; |
| 1695 } | 1708 } |
| 1696 | 1709 |
| 1697 bool PeerConnection::GetOptionsForAnswer( | 1710 bool PeerConnection::GetOptionsForAnswer( |
| 1698 const RTCOfferAnswerOptions& options, | 1711 const RTCOfferAnswerOptions& options, |
| 1699 cricket::MediaSessionOptions* session_options) { | 1712 cricket::MediaSessionOptions* session_options) { |
| 1700 session_options->recv_audio = false; | 1713 InitializeOptionsForAnswer(session_options); |
| 1701 session_options->recv_video = false; | 1714 if (!ExtractMediaSessionOptions(options, false, ice_renomination_, |
| 1702 if (!ExtractMediaSessionOptions(options, false, session_options)) { | 1715 session_options)) { |
| 1703 return false; | 1716 return false; |
| 1704 } | 1717 } |
| 1705 session_options->rtcp_cname = rtcp_cname_; | 1718 session_options->rtcp_cname = rtcp_cname_; |
| 1706 | 1719 |
| 1707 FinishOptionsForAnswer(session_options); | 1720 FinishOptionsForAnswer(session_options); |
| 1708 return true; | 1721 return true; |
| 1709 } | 1722 } |
| 1710 | 1723 |
| 1711 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { | 1724 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
| 1712 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); | 1725 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2323 | 2336 |
| 2324 bool PeerConnection::StartRtcEventLog_w(rtc::PlatformFile file, | 2337 bool PeerConnection::StartRtcEventLog_w(rtc::PlatformFile file, |
| 2325 int64_t max_size_bytes) { | 2338 int64_t max_size_bytes) { |
| 2326 return media_controller_->call_w()->StartEventLog(file, max_size_bytes); | 2339 return media_controller_->call_w()->StartEventLog(file, max_size_bytes); |
| 2327 } | 2340 } |
| 2328 | 2341 |
| 2329 void PeerConnection::StopRtcEventLog_w() { | 2342 void PeerConnection::StopRtcEventLog_w() { |
| 2330 media_controller_->call_w()->StopEventLog(); | 2343 media_controller_->call_w()->StopEventLog(); |
| 2331 } | 2344 } |
| 2332 } // namespace webrtc | 2345 } // namespace webrtc |
| OLD | NEW |