Chromium Code Reviews| 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 |