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

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

Issue 1717583002: Non-constraint interfaces for all constrainable interfaces (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Review comments Created 4 years, 9 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/webrtcsession.h ('k') | webrtc/api/webrtcsession_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
11 #include "webrtc/api/webrtcsession.h" 11 #include "webrtc/api/webrtcsession.h"
12 12
13 #include <limits.h> 13 #include <limits.h>
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <set> 16 #include <set>
17 #include <utility> 17 #include <utility>
18 #include <vector> 18 #include <vector>
19 19
20 #include "webrtc/api/jsepicecandidate.h" 20 #include "webrtc/api/jsepicecandidate.h"
21 #include "webrtc/api/jsepsessiondescription.h" 21 #include "webrtc/api/jsepsessiondescription.h"
22 #include "webrtc/api/mediaconstraintsinterface.h"
23 #include "webrtc/api/peerconnectioninterface.h" 22 #include "webrtc/api/peerconnectioninterface.h"
24 #include "webrtc/api/sctputils.h" 23 #include "webrtc/api/sctputils.h"
25 #include "webrtc/api/webrtcsessiondescriptionfactory.h" 24 #include "webrtc/api/webrtcsessiondescriptionfactory.h"
26 #include "webrtc/audio_sink.h" 25 #include "webrtc/audio_sink.h"
27 #include "webrtc/base/basictypes.h" 26 #include "webrtc/base/basictypes.h"
28 #include "webrtc/base/checks.h" 27 #include "webrtc/base/checks.h"
29 #include "webrtc/base/helpers.h" 28 #include "webrtc/base/helpers.h"
30 #include "webrtc/base/logging.h" 29 #include "webrtc/base/logging.h"
31 #include "webrtc/base/stringencode.h" 30 #include "webrtc/base/stringencode.h"
32 #include "webrtc/base/stringutils.h" 31 #include "webrtc/base/stringutils.h"
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 const std::string& desc) { 414 const std::string& desc) {
416 std::ostringstream ret; 415 std::ostringstream ret;
417 ret << error << " " << desc; 416 ret << error << " " << desc;
418 return ret.str(); 417 return ret.str();
419 } 418 }
420 419
421 static std::string MakeTdErrorString(const std::string& desc) { 420 static std::string MakeTdErrorString(const std::string& desc) {
422 return MakeErrorString(kPushDownTDFailed, desc); 421 return MakeErrorString(kPushDownTDFailed, desc);
423 } 422 }
424 423
425 // Set |option| to the highest-priority value of |key| in the optional
426 // constraints if the key is found and has a valid value.
427 template <typename T>
428 static void SetOptionFromOptionalConstraint(
429 const MediaConstraintsInterface* constraints,
430 const std::string& key,
431 rtc::Optional<T>* option) {
432 if (!constraints) {
433 return;
434 }
435 std::string string_value;
436 T value;
437 if (constraints->GetOptional().FindFirst(key, &string_value)) {
438 if (rtc::FromString(string_value, &value)) {
439 *option = rtc::Optional<T>(value);
440 }
441 }
442 }
443
444 uint32_t ConvertIceTransportTypeToCandidateFilter( 424 uint32_t ConvertIceTransportTypeToCandidateFilter(
445 PeerConnectionInterface::IceTransportsType type) { 425 PeerConnectionInterface::IceTransportsType type) {
446 switch (type) { 426 switch (type) {
447 case PeerConnectionInterface::kNone: 427 case PeerConnectionInterface::kNone:
448 return cricket::CF_NONE; 428 return cricket::CF_NONE;
449 case PeerConnectionInterface::kRelay: 429 case PeerConnectionInterface::kRelay:
450 return cricket::CF_RELAY; 430 return cricket::CF_RELAY;
451 case PeerConnectionInterface::kNoHost: 431 case PeerConnectionInterface::kNoHost:
452 return (cricket::CF_ALL & ~cricket::CF_HOST); 432 return (cricket::CF_ALL & ~cricket::CF_HOST);
453 case PeerConnectionInterface::kAll: 433 case PeerConnectionInterface::kAll:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 SignalDataChannelDestroyed(); 519 SignalDataChannelDestroyed();
540 channel_manager_->DestroyDataChannel(data_channel_.release()); 520 channel_manager_->DestroyDataChannel(data_channel_.release());
541 } 521 }
542 SignalDestroyed(); 522 SignalDestroyed();
543 523
544 LOG(LS_INFO) << "Session: " << id() << " is destroyed."; 524 LOG(LS_INFO) << "Session: " << id() << " is destroyed.";
545 } 525 }
546 526
547 bool WebRtcSession::Initialize( 527 bool WebRtcSession::Initialize(
548 const PeerConnectionFactoryInterface::Options& options, 528 const PeerConnectionFactoryInterface::Options& options,
549 const MediaConstraintsInterface* constraints,
550 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, 529 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
551 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { 530 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
552 bundle_policy_ = rtc_configuration.bundle_policy; 531 bundle_policy_ = rtc_configuration.bundle_policy;
553 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; 532 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy;
554 transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); 533 transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version);
555 534
556 // Obtain a certificate from RTCConfiguration if any were provided (optional). 535 // Obtain a certificate from RTCConfiguration if any were provided (optional).
557 rtc::scoped_refptr<rtc::RTCCertificate> certificate; 536 rtc::scoped_refptr<rtc::RTCCertificate> certificate;
558 if (!rtc_configuration.certificates.empty()) { 537 if (!rtc_configuration.certificates.empty()) {
559 // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of 538 // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of
560 // just picking the first one. The decision should be made based on the DTLS 539 // just picking the first one. The decision should be made based on the DTLS
561 // handshake. The DTLS negotiations need to know about all certificates. 540 // handshake. The DTLS negotiations need to know about all certificates.
562 certificate = rtc_configuration.certificates[0]; 541 certificate = rtc_configuration.certificates[0];
563 } 542 }
564 543
565 SetIceConfig(ParseIceConfig(rtc_configuration)); 544 SetIceConfig(ParseIceConfig(rtc_configuration));
566 545
567 // TODO(perkj): Take |constraints| into consideration. Return false if not all
568 // mandatory constraints can be fulfilled. Note that |constraints|
569 // can be null.
570 bool value;
571
572 if (options.disable_encryption) { 546 if (options.disable_encryption) {
573 dtls_enabled_ = false; 547 dtls_enabled_ = false;
574 } else { 548 } else {
575 // Enable DTLS by default if we have an identity store or a certificate. 549 // Enable DTLS by default if we have an identity store or a certificate.
576 dtls_enabled_ = (dtls_identity_store || certificate); 550 dtls_enabled_ = (dtls_identity_store || certificate);
577 // |constraints| can override the default |dtls_enabled_| value. 551 // |rtc_configuration| can override the default |dtls_enabled_| value.
578 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableDtlsSrtp, 552 if (rtc_configuration.enable_dtls_srtp) {
579 &value, nullptr)) { 553 dtls_enabled_ = *(rtc_configuration.enable_dtls_srtp);
580 dtls_enabled_ = value;
581 } 554 }
582 } 555 }
583 556
584 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. 557 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set.
585 // It takes precendence over the disable_sctp_data_channels 558 // It takes precendence over the disable_sctp_data_channels
586 // PeerConnectionFactoryInterface::Options. 559 // PeerConnectionFactoryInterface::Options.
587 if (FindConstraint( 560 if (rtc_configuration.enable_rtp_data_channel) {
588 constraints, MediaConstraintsInterface::kEnableRtpDataChannels,
589 &value, NULL) && value) {
590 LOG(LS_INFO) << "Allowing RTP data engine.";
591 data_channel_type_ = cricket::DCT_RTP; 561 data_channel_type_ = cricket::DCT_RTP;
592 } else { 562 } else {
593 // DTLS has to be enabled to use SCTP. 563 // DTLS has to be enabled to use SCTP.
594 if (!options.disable_sctp_data_channels && dtls_enabled_) { 564 if (!options.disable_sctp_data_channels && dtls_enabled_) {
595 LOG(LS_INFO) << "Allowing SCTP data engine.";
596 data_channel_type_ = cricket::DCT_SCTP; 565 data_channel_type_ = cricket::DCT_SCTP;
597 } 566 }
598 } 567 }
599 568
600 SetOptionFromOptionalConstraint(constraints, 569 video_options_.screencast_min_bitrate_kbps =
601 MediaConstraintsInterface::kScreencastMinBitrate, 570 rtc_configuration.screencast_min_bitrate;
602 &video_options_.screencast_min_bitrate_kbps); 571 audio_options_.combined_audio_video_bwe =
603 572 rtc_configuration.combined_audio_video_bwe;
604 SetOptionFromOptionalConstraint(constraints,
605 MediaConstraintsInterface::kCombinedAudioVideoBwe,
606 &audio_options_.combined_audio_video_bwe);
607 573
608 audio_options_.audio_jitter_buffer_max_packets = 574 audio_options_.audio_jitter_buffer_max_packets =
609 rtc::Optional<int>(rtc_configuration.audio_jitter_buffer_max_packets); 575 rtc::Optional<int>(rtc_configuration.audio_jitter_buffer_max_packets);
610 576
611 audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>( 577 audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>(
612 rtc_configuration.audio_jitter_buffer_fast_accelerate); 578 rtc_configuration.audio_jitter_buffer_fast_accelerate);
613 579
614 if (!dtls_enabled_) { 580 if (!dtls_enabled_) {
615 // Construct with DTLS disabled. 581 // Construct with DTLS disabled.
616 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( 582 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 657
692 void WebRtcSession::CreateOffer( 658 void WebRtcSession::CreateOffer(
693 CreateSessionDescriptionObserver* observer, 659 CreateSessionDescriptionObserver* observer,
694 const PeerConnectionInterface::RTCOfferAnswerOptions& options, 660 const PeerConnectionInterface::RTCOfferAnswerOptions& options,
695 const cricket::MediaSessionOptions& session_options) { 661 const cricket::MediaSessionOptions& session_options) {
696 webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); 662 webrtc_session_desc_factory_->CreateOffer(observer, options, session_options);
697 } 663 }
698 664
699 void WebRtcSession::CreateAnswer( 665 void WebRtcSession::CreateAnswer(
700 CreateSessionDescriptionObserver* observer, 666 CreateSessionDescriptionObserver* observer,
701 const MediaConstraintsInterface* constraints,
702 const cricket::MediaSessionOptions& session_options) { 667 const cricket::MediaSessionOptions& session_options) {
703 webrtc_session_desc_factory_->CreateAnswer(observer, constraints, 668 webrtc_session_desc_factory_->CreateAnswer(observer, session_options);
704 session_options);
705 } 669 }
706 670
707 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, 671 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc,
708 std::string* err_desc) { 672 std::string* err_desc) {
709 ASSERT(signaling_thread()->IsCurrent()); 673 ASSERT(signaling_thread()->IsCurrent());
710 674
711 // Takes the ownership of |desc| regardless of the result. 675 // Takes the ownership of |desc| regardless of the result.
712 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); 676 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc);
713 677
714 // Validate SDP. 678 // Validate SDP.
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 } 2077 }
2114 } 2078 }
2115 2079
2116 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, 2080 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel,
2117 const rtc::SentPacket& sent_packet) { 2081 const rtc::SentPacket& sent_packet) {
2118 RTC_DCHECK(worker_thread()->IsCurrent()); 2082 RTC_DCHECK(worker_thread()->IsCurrent());
2119 media_controller_->call_w()->OnSentPacket(sent_packet); 2083 media_controller_->call_w()->OnSentPacket(sent_packet);
2120 } 2084 }
2121 2085
2122 } // namespace webrtc 2086 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession.h ('k') | webrtc/api/webrtcsession_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698