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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 if (stream->AddTrack(track)) { | 420 if (stream->AddTrack(track)) { |
421 return track; | 421 return track; |
422 } | 422 } |
423 return nullptr; | 423 return nullptr; |
424 } | 424 } |
425 | 425 |
426 rtc::Thread* signaling_thread_; | 426 rtc::Thread* signaling_thread_; |
427 cricket::ChannelManager* channel_manager_; | 427 cricket::ChannelManager* channel_manager_; |
428 }; | 428 }; |
429 | 429 |
430 bool ConvertRtcOptionsForOffer( | 430 bool ConvertRtcOptionsForOffer( |
perkj_webrtc
2016/03/02 14:46:26
suggest rename to ConvertToMediaSessionOptions and
hta - Chromium
2016/03/03 11:51:03
ExtractMediaSessionOptions. Calling it a conversio
| |
431 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 431 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
432 cricket::MediaSessionOptions* session_options) { | 432 cricket::MediaSessionOptions* session_options) { |
433 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; | 433 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
434 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || | 434 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || |
435 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { | 435 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { |
436 return false; | 436 return false; |
437 } | 437 } |
438 | 438 |
439 if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) { | 439 if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) { |
440 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); | 440 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); |
441 } | 441 } |
442 if (rtc_options.offer_to_receive_video != RTCOfferAnswerOptions::kUndefined) { | 442 if (rtc_options.offer_to_receive_video != RTCOfferAnswerOptions::kUndefined) { |
443 session_options->recv_video = (rtc_options.offer_to_receive_video > 0); | 443 session_options->recv_video = (rtc_options.offer_to_receive_video > 0); |
444 } | 444 } |
445 | 445 |
446 session_options->vad_enabled = rtc_options.voice_activity_detection; | 446 session_options->vad_enabled = rtc_options.voice_activity_detection; |
447 session_options->bundle_enabled = rtc_options.use_rtp_mux; | 447 session_options->bundle_enabled = rtc_options.use_rtp_mux; |
448 for (auto& kv : session_options->transport_options) { | 448 for (auto& kv : session_options->transport_options) { |
449 kv.second.ice_restart = rtc_options.ice_restart; | 449 kv.second.ice_restart = rtc_options.ice_restart; |
450 } | 450 } |
451 | 451 |
452 return true; | 452 return true; |
453 } | 453 } |
454 | 454 |
455 bool ConvertRtcOptionsForAnswer( | |
456 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | |
457 cricket::MediaSessionOptions* session_options) { | |
458 return ConvertRtcOptionsForOffer(rtc_options, session_options); | |
459 } | |
460 | |
455 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, | 461 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
456 cricket::MediaSessionOptions* session_options) { | 462 cricket::MediaSessionOptions* session_options) { |
457 bool value = false; | 463 bool value = false; |
458 size_t mandatory_constraints_satisfied = 0; | 464 size_t mandatory_constraints_satisfied = 0; |
459 | 465 |
460 // kOfferToReceiveAudio defaults to true according to spec. | 466 // kOfferToReceiveAudio defaults to true according to spec. |
461 if (!FindConstraint(constraints, | 467 if (!FindConstraint(constraints, |
462 MediaConstraintsInterface::kOfferToReceiveAudio, &value, | 468 MediaConstraintsInterface::kOfferToReceiveAudio, &value, |
463 &mandatory_constraints_satisfied) || | 469 &mandatory_constraints_satisfied) || |
464 value) { | 470 value) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 // since it's about to be destroyed. | 564 // since it's about to be destroyed. |
559 for (const auto& sender : senders_) { | 565 for (const auto& sender : senders_) { |
560 sender->Stop(); | 566 sender->Stop(); |
561 } | 567 } |
562 for (const auto& receiver : receivers_) { | 568 for (const auto& receiver : receivers_) { |
563 receiver->Stop(); | 569 receiver->Stop(); |
564 } | 570 } |
565 } | 571 } |
566 | 572 |
567 bool PeerConnection::Initialize( | 573 bool PeerConnection::Initialize( |
574 const cricket::MediaConfig& media_config, | |
568 const PeerConnectionInterface::RTCConfiguration& configuration, | 575 const PeerConnectionInterface::RTCConfiguration& configuration, |
569 const MediaConstraintsInterface* constraints, | |
570 rtc::scoped_ptr<cricket::PortAllocator> allocator, | 576 rtc::scoped_ptr<cricket::PortAllocator> allocator, |
571 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 577 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
572 PeerConnectionObserver* observer) { | 578 PeerConnectionObserver* observer) { |
573 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 579 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
574 RTC_DCHECK(observer != nullptr); | 580 RTC_DCHECK(observer != nullptr); |
575 if (!observer) { | 581 if (!observer) { |
576 return false; | 582 return false; |
577 } | 583 } |
578 observer_ = observer; | 584 observer_ = observer; |
579 | 585 |
580 port_allocator_ = std::move(allocator); | 586 port_allocator_ = std::move(allocator); |
581 | 587 |
582 cricket::ServerAddresses stun_servers; | 588 cricket::ServerAddresses stun_servers; |
583 std::vector<cricket::RelayServerConfig> turn_servers; | 589 std::vector<cricket::RelayServerConfig> turn_servers; |
584 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { | 590 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { |
585 return false; | 591 return false; |
586 } | 592 } |
587 port_allocator_->SetIceServers(stun_servers, turn_servers); | 593 port_allocator_->SetIceServers(stun_servers, turn_servers); |
588 | 594 |
589 // To handle both internal and externally created port allocator, we will | 595 // To handle both internal and externally created port allocator, we will |
590 // enable BUNDLE here. | 596 // enable BUNDLE here. |
591 int portallocator_flags = port_allocator_->flags(); | 597 int portallocator_flags = port_allocator_->flags(); |
592 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 598 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
593 cricket::PORTALLOCATOR_ENABLE_IPV6; | 599 cricket::PORTALLOCATOR_ENABLE_IPV6; |
594 bool value; | 600 // If the disable-IPv6 flag was specified, we'll not override it |
595 // If IPv6 flag was specified, we'll not override it by experiment. | 601 // by experiment. |
596 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, | 602 if (configuration.disable_ipv6) { |
597 &value, nullptr)) { | 603 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
598 if (!value) { | |
599 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | |
600 } | |
601 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == | 604 } else if (webrtc::field_trial::FindFullName("WebRTC-IPv6Default") == |
602 "Disabled") { | 605 "Disabled") { |
603 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); | 606 portallocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6); |
604 } | 607 } |
605 | 608 |
606 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { | 609 if (configuration.tcp_candidate_policy == kTcpCandidatePolicyDisabled) { |
607 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; | 610 portallocator_flags |= cricket::PORTALLOCATOR_DISABLE_TCP; |
608 LOG(LS_INFO) << "TCP candidates are disabled."; | 611 LOG(LS_INFO) << "TCP candidates are disabled."; |
609 } | 612 } |
610 | 613 |
611 port_allocator_->set_flags(portallocator_flags); | 614 port_allocator_->set_flags(portallocator_flags); |
612 // No step delay is used while allocating ports. | 615 // No step delay is used while allocating ports. |
613 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | 616 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
614 | 617 |
615 // We rely on default values when constraints aren't found. | |
616 cricket::MediaConfig media_config; | |
617 | |
618 media_config.video.disable_prerenderer_smoothing = | |
619 configuration.disable_prerenderer_smoothing; | |
620 | |
621 // Find DSCP constraint. | |
622 FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, | |
623 &media_config.enable_dscp, NULL); | |
624 // Find constraint for cpu overuse detection. | |
625 FindConstraint(constraints, MediaConstraintsInterface::kCpuOveruseDetection, | |
626 &media_config.video.enable_cpu_overuse_detection, NULL); | |
627 | |
628 // Find Suspend Below Min Bitrate constraint. | |
629 FindConstraint(constraints, | |
630 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, | |
631 &media_config.video.suspend_below_min_bitrate, NULL); | |
632 | |
633 media_controller_.reset(factory_->CreateMediaController(media_config)); | 618 media_controller_.reset(factory_->CreateMediaController(media_config)); |
634 | 619 |
635 remote_stream_factory_.reset(new RemoteMediaStreamFactory( | 620 remote_stream_factory_.reset(new RemoteMediaStreamFactory( |
636 factory_->signaling_thread(), media_controller_->channel_manager())); | 621 factory_->signaling_thread(), media_controller_->channel_manager())); |
637 | 622 |
638 session_.reset( | 623 session_.reset( |
639 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), | 624 new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), |
640 factory_->worker_thread(), port_allocator_.get())); | 625 factory_->worker_thread(), port_allocator_.get())); |
641 stats_.reset(new StatsCollector(this)); | 626 stats_.reset(new StatsCollector(this)); |
642 | 627 |
643 // Initialize the WebRtcSession. It creates transport channels etc. | 628 // Initialize the WebRtcSession. It creates transport channels etc. |
644 if (!session_->Initialize(factory_->options(), constraints, | 629 if (!session_->Initialize(factory_->options(), std::move(dtls_identity_store), |
645 std::move(dtls_identity_store), configuration)) { | 630 configuration)) { |
646 return false; | 631 return false; |
647 } | 632 } |
648 | 633 |
649 // Register PeerConnection as receiver of local ice candidates. | 634 // Register PeerConnection as receiver of local ice candidates. |
650 // All the callbacks will be posted to the application from PeerConnection. | 635 // All the callbacks will be posted to the application from PeerConnection. |
651 session_->RegisterIceObserver(this); | 636 session_->RegisterIceObserver(this); |
652 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); | 637 session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
653 session_->SignalVoiceChannelDestroyed.connect( | 638 session_->SignalVoiceChannelDestroyed.connect( |
654 this, &PeerConnection::OnVoiceChannelDestroyed); | 639 this, &PeerConnection::OnVoiceChannelDestroyed); |
655 session_->SignalVideoChannelDestroyed.connect( | 640 session_->SignalVideoChannelDestroyed.connect( |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 } | 984 } |
1000 | 985 |
1001 cricket::MediaSessionOptions session_options; | 986 cricket::MediaSessionOptions session_options; |
1002 if (!GetOptionsForAnswer(constraints, &session_options)) { | 987 if (!GetOptionsForAnswer(constraints, &session_options)) { |
1003 std::string error = "CreateAnswer called with invalid constraints."; | 988 std::string error = "CreateAnswer called with invalid constraints."; |
1004 LOG(LS_ERROR) << error; | 989 LOG(LS_ERROR) << error; |
1005 PostCreateSessionDescriptionFailure(observer, error); | 990 PostCreateSessionDescriptionFailure(observer, error); |
1006 return; | 991 return; |
1007 } | 992 } |
1008 | 993 |
1009 session_->CreateAnswer(observer, constraints, session_options); | 994 session_->CreateAnswer(observer, session_options); |
995 } | |
996 | |
997 void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, | |
998 const RTCOfferAnswerOptions& options) { | |
999 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); | |
1000 if (!VERIFY(observer != nullptr)) { | |
1001 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; | |
1002 return; | |
1003 } | |
1004 | |
1005 cricket::MediaSessionOptions session_options; | |
1006 if (!GetOptionsForAnswer(options, &session_options)) { | |
1007 std::string error = "CreateAnswer called with invalid options."; | |
1008 LOG(LS_ERROR) << error; | |
1009 PostCreateSessionDescriptionFailure(observer, error); | |
1010 return; | |
1011 } | |
1012 | |
1013 session_->CreateAnswer(observer, session_options); | |
1010 } | 1014 } |
1011 | 1015 |
1012 void PeerConnection::SetLocalDescription( | 1016 void PeerConnection::SetLocalDescription( |
1013 SetSessionDescriptionObserver* observer, | 1017 SetSessionDescriptionObserver* observer, |
1014 SessionDescriptionInterface* desc) { | 1018 SessionDescriptionInterface* desc) { |
1015 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); | 1019 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); |
1016 if (!VERIFY(observer != nullptr)) { | 1020 if (!VERIFY(observer != nullptr)) { |
1017 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; | 1021 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; |
1018 return; | 1022 return; |
1019 } | 1023 } |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 session_options->bundle_enabled && | 1535 session_options->bundle_enabled && |
1532 (session_options->has_audio() || session_options->has_video() || | 1536 (session_options->has_audio() || session_options->has_video() || |
1533 session_options->has_data()); | 1537 session_options->has_data()); |
1534 | 1538 |
1535 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { | 1539 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { |
1536 session_options->data_channel_type = cricket::DCT_SCTP; | 1540 session_options->data_channel_type = cricket::DCT_SCTP; |
1537 } | 1541 } |
1538 return true; | 1542 return true; |
1539 } | 1543 } |
1540 | 1544 |
1541 bool PeerConnection::GetOptionsForAnswer( | 1545 void PeerConnection::FinishOptionsForAnswer( |
1542 const MediaConstraintsInterface* constraints, | |
1543 cricket::MediaSessionOptions* session_options) { | 1546 cricket::MediaSessionOptions* session_options) { |
1544 session_options->recv_audio = false; | |
1545 session_options->recv_video = false; | |
1546 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of | 1547 // TODO(deadbeef): Once we have transceivers, enumerate them here instead of |
1547 // ContentInfos. | 1548 // ContentInfos. |
1548 if (session_->remote_description()) { | 1549 if (session_->remote_description()) { |
1549 // Initialize the transport_options map. | 1550 // Initialize the transport_options map. |
1550 for (const cricket::ContentInfo& content : | 1551 for (const cricket::ContentInfo& content : |
1551 session_->remote_description()->description()->contents()) { | 1552 session_->remote_description()->description()->contents()) { |
1552 session_options->transport_options[content.name] = | 1553 session_options->transport_options[content.name] = |
1553 cricket::TransportOptions(); | 1554 cricket::TransportOptions(); |
1554 } | 1555 } |
1555 } | 1556 } |
1556 if (!ParseConstraintsForAnswer(constraints, session_options)) { | |
1557 return false; | |
1558 } | |
1559 | |
1560 AddSendStreams(session_options, senders_, rtp_data_channels_); | 1557 AddSendStreams(session_options, senders_, rtp_data_channels_); |
1561 session_options->bundle_enabled = | 1558 session_options->bundle_enabled = |
1562 session_options->bundle_enabled && | 1559 session_options->bundle_enabled && |
1563 (session_options->has_audio() || session_options->has_video() || | 1560 (session_options->has_audio() || session_options->has_video() || |
1564 session_options->has_data()); | 1561 session_options->has_data()); |
1565 | 1562 |
1566 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1563 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
1567 // are not signaled in the SDP so does not go through that path and must be | 1564 // are not signaled in the SDP so does not go through that path and must be |
1568 // handled here. | 1565 // handled here. |
1569 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1566 if (session_->data_channel_type() == cricket::DCT_SCTP) { |
1570 session_options->data_channel_type = cricket::DCT_SCTP; | 1567 session_options->data_channel_type = cricket::DCT_SCTP; |
1571 } | 1568 } |
1569 } | |
1570 | |
1571 bool PeerConnection::GetOptionsForAnswer( | |
1572 const MediaConstraintsInterface* constraints, | |
1573 cricket::MediaSessionOptions* session_options) { | |
1574 session_options->recv_audio = false; | |
1575 session_options->recv_video = false; | |
1576 if (!ParseConstraintsForAnswer(constraints, session_options)) { | |
1577 return false; | |
1578 } | |
1579 FinishOptionsForAnswer(session_options); | |
1572 return true; | 1580 return true; |
1573 } | 1581 } |
1574 | 1582 |
1583 bool PeerConnection::GetOptionsForAnswer( | |
1584 const RTCOfferAnswerOptions& options, | |
1585 cricket::MediaSessionOptions* session_options) { | |
1586 session_options->recv_audio = false; | |
1587 session_options->recv_video = false; | |
1588 if (!ConvertRtcOptionsForAnswer(options, session_options)) { | |
1589 return false; | |
1590 } | |
1591 FinishOptionsForAnswer(session_options); | |
1592 return true; | |
1593 } | |
1594 | |
1575 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { | 1595 void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
1576 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); | 1596 UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
1577 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, | 1597 UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, |
1578 media_type, nullptr); | 1598 media_type, nullptr); |
1579 } | 1599 } |
1580 | 1600 |
1581 void PeerConnection::UpdateRemoteStreamsList( | 1601 void PeerConnection::UpdateRemoteStreamsList( |
1582 const cricket::StreamParamsVec& streams, | 1602 const cricket::StreamParamsVec& streams, |
1583 bool default_track_needed, | 1603 bool default_track_needed, |
1584 cricket::MediaType media_type, | 1604 cricket::MediaType media_type, |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2098 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2118 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
2099 for (const auto& channel : sctp_data_channels_) { | 2119 for (const auto& channel : sctp_data_channels_) { |
2100 if (channel->id() == sid) { | 2120 if (channel->id() == sid) { |
2101 return channel; | 2121 return channel; |
2102 } | 2122 } |
2103 } | 2123 } |
2104 return nullptr; | 2124 return nullptr; |
2105 } | 2125 } |
2106 | 2126 |
2107 } // namespace webrtc | 2127 } // namespace webrtc |
OLD | NEW |