diff --git a/webrtc/api/mediaconstraintsinterface.cc b/webrtc/api/mediaconstraintsinterface.cc index af258917e7..a567870186 100644 --- a/webrtc/api/mediaconstraintsinterface.cc +++ b/webrtc/api/mediaconstraintsinterface.cc @@ -179,29 +179,23 @@ void CopyConstraintsIntoRtcConfiguration( return; } - bool value; + bool enable_ipv6; if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, - &value, nullptr)) { - if (!value) { - configuration->disable_ipv6 = true; - } - } - ConstraintToOptionalBool(constraints, MediaConstraintsInterface::kEnableDscp, - &configuration->enable_dscp); - ConstraintToOptionalBool(constraints, - MediaConstraintsInterface::kCpuOveruseDetection, - &configuration->cpu_overuse_detection); - if (FindConstraint(constraints, - MediaConstraintsInterface::kEnableRtpDataChannels, &value, - NULL) && - value) { - configuration->enable_rtp_data_channel = true; + &enable_ipv6, nullptr)) { + configuration->disable_ipv6 = !enable_ipv6; } + FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, + &configuration->media_config.enable_dscp, nullptr); + FindConstraint( + constraints, MediaConstraintsInterface::kCpuOveruseDetection, + &configuration->media_config.video.enable_cpu_overuse_detection, nullptr); + FindConstraint(constraints, MediaConstraintsInterface::kEnableRtpDataChannels, + &configuration->enable_rtp_data_channel, nullptr); // Find Suspend Below Min Bitrate constraint. - ConstraintToOptionalBool( - constraints, - MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, - &configuration->suspend_below_min_bitrate); + FindConstraint(constraints, + MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, + &configuration->media_config.video.suspend_below_min_bitrate, + nullptr); ConstraintToOptionalInt(constraints, MediaConstraintsInterface::kScreencastMinBitrate, &configuration->screencast_min_bitrate); diff --git a/webrtc/api/mediaconstraintsinterface_unittest.cc b/webrtc/api/mediaconstraintsinterface_unittest.cc index 07338c15e8..dcf4bb7fde 100644 --- a/webrtc/api/mediaconstraintsinterface_unittest.cc +++ b/webrtc/api/mediaconstraintsinterface_unittest.cc @@ -17,11 +17,24 @@ namespace webrtc { namespace { +// Checks all settings touched by CopyConstraintsIntoRtcConfiguration, +// plus audio_jitter_buffer_max_packets. bool Matches(const PeerConnectionInterface::RTCConfiguration& a, const PeerConnectionInterface::RTCConfiguration& b) { - return a.audio_jitter_buffer_max_packets == + return a.disable_ipv6 == b.disable_ipv6 && + a.audio_jitter_buffer_max_packets == b.audio_jitter_buffer_max_packets && - a.disable_prerenderer_smoothing == b.disable_prerenderer_smoothing; + a.enable_rtp_data_channel == b.enable_rtp_data_channel && + a.screencast_min_bitrate == b.screencast_min_bitrate && + a.combined_audio_video_bwe == b.combined_audio_video_bwe && + a.enable_dtls_srtp == b.enable_dtls_srtp && + a.media_config.enable_dscp == b.media_config.enable_dscp && + a.media_config.video.enable_cpu_overuse_detection == + b.media_config.video.enable_cpu_overuse_detection && + a.media_config.video.disable_prerenderer_smoothing == + b.media_config.video.disable_prerenderer_smoothing && + a.media_config.video.suspend_below_min_bitrate == + b.media_config.video.suspend_below_min_bitrate; } TEST(MediaConstraintsInterface, CopyConstraintsIntoRtcConfiguration) { diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc index b2b8062ca8..70a386ec14 100644 --- a/webrtc/api/peerconnection.cc +++ b/webrtc/api/peerconnection.cc @@ -525,7 +525,6 @@ PeerConnection::~PeerConnection() { } bool PeerConnection::Initialize( - const cricket::MediaConfig& media_config, const PeerConnectionInterface::RTCConfiguration& configuration, rtc::scoped_ptr allocator, rtc::scoped_ptr dtls_identity_store, @@ -569,7 +568,8 @@ bool PeerConnection::Initialize( // No step delay is used while allocating ports. port_allocator_->set_step_delay(cricket::kMinimumStepDelay); - media_controller_.reset(factory_->CreateMediaController(media_config)); + media_controller_.reset( + factory_->CreateMediaController(configuration.media_config)); session_.reset( new WebRtcSession(media_controller_.get(), factory_->signaling_thread(), diff --git a/webrtc/api/peerconnection.h b/webrtc/api/peerconnection.h index d1676733d5..1574af60c5 100644 --- a/webrtc/api/peerconnection.h +++ b/webrtc/api/peerconnection.h @@ -68,7 +68,6 @@ class PeerConnection : public PeerConnectionInterface, explicit PeerConnection(PeerConnectionFactory* factory); bool Initialize( - const cricket::MediaConfig& media_config, const PeerConnectionInterface::RTCConfiguration& configuration, rtc::scoped_ptr allocator, rtc::scoped_ptr dtls_identity_store, diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc index c3c120ce7a..8e1ece6c65 100644 --- a/webrtc/api/peerconnectionfactory.cc +++ b/webrtc/api/peerconnectionfactory.cc @@ -286,24 +286,8 @@ PeerConnectionFactory::CreatePeerConnection( rtc::scoped_refptr pc( new rtc::RefCountedObject(this)); - // We rely on default values when constraints aren't found. - cricket::MediaConfig media_config; - media_config.video.disable_prerenderer_smoothing = - configuration.disable_prerenderer_smoothing; - if (configuration.enable_dscp) { - media_config.enable_dscp = *(configuration.enable_dscp); - } - if (configuration.cpu_overuse_detection) { - media_config.video.enable_cpu_overuse_detection = - *(configuration.cpu_overuse_detection); - } - if (configuration.suspend_below_min_bitrate) { - media_config.video.suspend_below_min_bitrate = - *(configuration.suspend_below_min_bitrate); - } - - if (!pc->Initialize(media_config, configuration, std::move(allocator), + if (!pc->Initialize(configuration, std::move(allocator), std::move(dtls_identity_store), observer)) { return nullptr; } diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index 9259275b86..59bc160014 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/api/peerconnectioninterface.h @@ -70,6 +70,7 @@ #include "webrtc/base/rtccertificate.h" #include "webrtc/base/socketaddress.h" #include "webrtc/base/sslstreamadapter.h" +#include "webrtc/media/base/mediachannel.h" #include "webrtc/p2p/base/portallocator.h" namespace rtc { @@ -222,6 +223,11 @@ class PeerConnectionInterface : public rtc::RefCountInterface { }; // TODO(hbos): Change into class with private data and public getters. + // TODO(nisse): In particular, accessing fields directly from an + // application is brittle, since the organization mirrors the + // organization of the implementation, which isn't stable. So we + // need getters and setters at least for fields which applications + // are interested in. struct RTCConfiguration { // This struct is subject to reorganization, both for naming // consistency, and to group settings to match where they are used @@ -229,28 +235,33 @@ class PeerConnectionInterface : public rtc::RefCountInterface { // methods for all settings which are of interest to applications, // Chrome in particular. - bool dscp() { return enable_dscp.value_or(false); } - void set_dscp(bool enable) { enable_dscp = rtc::Optional(enable); } + bool dscp() { return media_config.enable_dscp; } + void set_dscp(bool enable) { media_config.enable_dscp = enable; } // TODO(nisse): The corresponding flag in MediaConfig and // elsewhere should be renamed enable_cpu_adaptation. - bool cpu_adaptation() { return cpu_overuse_detection.value_or(true); } + bool cpu_adaptation() { + return media_config.video.enable_cpu_overuse_detection; + } void set_cpu_adaptation(bool enable) { - cpu_overuse_detection = rtc::Optional(enable); + media_config.video.enable_cpu_overuse_detection = enable; } - // TODO(nisse): Currently no getter method, since it collides with - // the flag itself. Add when the flag is moved to MediaConfig. + bool suspend_below_min_bitrate() { + return media_config.video.suspend_below_min_bitrate; + } void set_suspend_below_min_bitrate(bool enable) { - suspend_below_min_bitrate = rtc::Optional(enable); + media_config.video.suspend_below_min_bitrate = enable; } // TODO(nisse): The negation in the corresponding MediaConfig // attribute is inconsistent, and it should be renamed at some // point. - bool prerenderer_smoothing() { return !disable_prerenderer_smoothing; } + bool prerenderer_smoothing() { + return !media_config.video.disable_prerenderer_smoothing; + } void set_prerenderer_smoothing(bool enable) { - disable_prerenderer_smoothing = !enable; + media_config.video.disable_prerenderer_smoothing = !enable; } static const int kUndefined = -1; @@ -271,16 +282,13 @@ class PeerConnectionInterface : public rtc::RefCountInterface { int ice_backup_candidate_pair_ping_interval; // ms ContinualGatheringPolicy continual_gathering_policy; std::vector> certificates; - bool disable_prerenderer_smoothing; bool prioritize_most_likely_ice_candidate_pairs; + struct cricket::MediaConfig media_config; // Flags corresponding to values set by constraint flags. // rtc::Optional flags can be "missing", in which case the webrtc // default applies. bool disable_ipv6; - rtc::Optional enable_dscp; bool enable_rtp_data_channel; - rtc::Optional cpu_overuse_detection; - rtc::Optional suspend_below_min_bitrate; rtc::Optional screencast_min_bitrate; rtc::Optional combined_audio_video_bwe; rtc::Optional enable_dtls_srtp; @@ -294,7 +302,6 @@ class PeerConnectionInterface : public rtc::RefCountInterface { ice_connection_receiving_timeout(kUndefined), ice_backup_candidate_pair_ping_interval(kUndefined), continual_gathering_policy(GATHER_ONCE), - disable_prerenderer_smoothing(false), prioritize_most_likely_ice_candidate_pairs(false), disable_ipv6(false), enable_rtp_data_channel(false) {}