Index: webrtc/api/mediaconstraintsinterface.cc |
diff --git a/webrtc/api/mediaconstraintsinterface.cc b/webrtc/api/mediaconstraintsinterface.cc |
index b0a68b15b0b31b75ea754e62647d5510413dbe21..af258917e7acd6f6ce942706f0607caf0f5e5d42 100644 |
--- a/webrtc/api/mediaconstraintsinterface.cc |
+++ b/webrtc/api/mediaconstraintsinterface.cc |
@@ -10,6 +10,7 @@ |
#include "webrtc/api/mediaconstraintsinterface.h" |
+#include "webrtc/api/peerconnectioninterface.h" |
#include "webrtc/base/stringencode.h" |
namespace webrtc { |
@@ -118,8 +119,30 @@ bool FindConstraint(const MediaConstraintsInterface* constraints, |
return false; |
} |
if (constraints->GetMandatory().FindFirst(key, &string_value)) { |
- if (mandatory_constraints) |
+ if (mandatory_constraints) { |
++*mandatory_constraints; |
+ } |
+ return rtc::FromString(string_value, value); |
+ } |
+ if (constraints->GetOptional().FindFirst(key, &string_value)) { |
+ return rtc::FromString(string_value, value); |
+ } |
+ return false; |
+} |
+ |
+// As above, but for integers. |
+bool FindConstraint(const MediaConstraintsInterface* constraints, |
+ const std::string& key, |
+ int* value, |
+ size_t* mandatory_constraints) { |
+ std::string string_value; |
+ if (!constraints) { |
+ return false; |
+ } |
+ if (constraints->GetMandatory().FindFirst(key, &string_value)) { |
+ if (mandatory_constraints) { |
+ ++*mandatory_constraints; |
+ } |
return rtc::FromString(string_value, value); |
} |
if (constraints->GetOptional().FindFirst(key, &string_value)) { |
@@ -128,4 +151,66 @@ bool FindConstraint(const MediaConstraintsInterface* constraints, |
return false; |
} |
+void ConstraintToOptionalBool(const MediaConstraintsInterface* constraints, |
perkj_webrtc
2016/03/04 08:44:36
nit: move to anonymous ns.
hta-webrtc
2016/03/04 09:54:47
Done.
|
+ const std::string& key, |
+ rtc::Optional<bool>* value_out) { |
+ bool value; |
+ bool present = FindConstraint(constraints, key, &value, nullptr); |
+ if (present) { |
+ *value_out = rtc::Optional<bool>(value); |
+ } |
+} |
+ |
+void ConstraintToOptionalInt(const MediaConstraintsInterface* constraints, |
perkj_webrtc
2016/03/04 08:44:36
nit: move to anonymous ns.
hta-webrtc
2016/03/04 09:54:47
Done.
|
+ const std::string& key, |
+ rtc::Optional<int>* value_out) { |
+ int value; |
+ bool present = FindConstraint(constraints, key, &value, nullptr); |
+ if (present) { |
+ *value_out = rtc::Optional<int>(value); |
+ } |
+} |
+ |
+void CopyConstraintsIntoRtcConfiguration( |
+ const MediaConstraintsInterface* constraints, |
+ PeerConnectionInterface::RTCConfiguration* configuration) { |
+ // Copy info from constraints into configuration, if present. |
+ if (!constraints) { |
+ return; |
+ } |
+ |
+ bool value; |
+ 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; |
+ } |
+ // Find Suspend Below Min Bitrate constraint. |
+ ConstraintToOptionalBool( |
+ constraints, |
+ MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, |
+ &configuration->suspend_below_min_bitrate); |
+ ConstraintToOptionalInt(constraints, |
+ MediaConstraintsInterface::kScreencastMinBitrate, |
+ &configuration->screencast_min_bitrate); |
+ ConstraintToOptionalBool(constraints, |
+ MediaConstraintsInterface::kCombinedAudioVideoBwe, |
+ &configuration->combined_audio_video_bwe); |
+ ConstraintToOptionalBool(constraints, |
+ MediaConstraintsInterface::kEnableDtlsSrtp, |
+ &configuration->enable_dtls_srtp); |
+} |
+ |
} // namespace webrtc |