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

Unified Diff: webrtc/api/mediaconstraintsinterface.cc

Issue 1717583002: Non-constraint interfaces for all constrainable interfaces (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removing a TODO Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/api/mediaconstraintsinterface.cc
diff --git a/webrtc/api/mediaconstraintsinterface.cc b/webrtc/api/mediaconstraintsinterface.cc
index b0a68b15b0b31b75ea754e62647d5510413dbe21..d5f266aaf0f641de4585752d223a78c340e606da 100644
--- a/webrtc/api/mediaconstraintsinterface.cc
+++ b/webrtc/api/mediaconstraintsinterface.cc
@@ -128,4 +128,46 @@ bool FindConstraint(const MediaConstraintsInterface* constraints,
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)
perkj_webrtc 2016/03/01 08:41:26 nit : {}
hta-webrtc 2016/03/02 09:33:40 Done (here and in existing code above).
+ ++*mandatory_constraints;
+ return rtc::FromString(string_value, value);
+ }
+ if (constraints->GetOptional().FindFirst(key, &string_value)) {
+ return rtc::FromString(string_value, value);
+ }
+ return false;
+}
+
+rtc::Optional<bool> ConstraintToOptionalBool(
+ const MediaConstraintsInterface* constraints,
+ const std::string& key) {
+ bool value;
+ bool present = FindConstraint(constraints, key, &value, nullptr);
+ if (present) {
+ return rtc::Optional<bool>(value);
+ }
+ return rtc::Optional<bool>();
+}
+
+rtc::Optional<int> ConstraintToOptionalInt(
+ const MediaConstraintsInterface* constraints,
+ const std::string& key) {
+ int value;
+ bool present = FindConstraint(constraints, key, &value, nullptr);
+ if (present) {
+ return rtc::Optional<int>(value);
+ }
+ return rtc::Optional<int>();
+}
+
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698