static Optional<IntConstraint> createIntConstraint(const Dictionary& mediaTrackConstraintSet, const String& name, MediaConstraintType type, ConstraintSetType constraintSetType) { auto constraint = IntConstraint(name, type); // Dictionary constraint value. Dictionary dictionaryValue; if (mediaTrackConstraintSet.get(name, dictionaryValue) && !dictionaryValue.isUndefinedOrNull()) { int minValue; if (dictionaryValue.get("min", minValue)) constraint.setMin(minValue); int maxValue; if (dictionaryValue.get("max", maxValue)) constraint.setMax(maxValue); int exactValue; if (dictionaryValue.get("exact", exactValue)) constraint.setExact(exactValue); int idealValue; if (dictionaryValue.get("ideal", idealValue)) constraint.setIdeal(idealValue); if (constraint.isEmpty()) { LOG(Media, "createIntConstraint() - ignoring long constraint '%s' with dictionary value since it has no valid or supported key/value pairs.", name.utf8().data()); return Nullopt; } return WTFMove(constraint); } // Scalar constraint value. int value; if (mediaTrackConstraintSet.get(name, value)) { if (constraintSetType == ConstraintSetType::Mandatory) constraint.setIdeal(value); else constraint.setExact(value); return WTFMove(constraint); } // Invalid constraint value. LOG(Media, "createIntConstraint() - ignoring long constraint '%s' since it has neither a dictionary nor scalar value.", name.utf8().data()); return Nullopt; }
void NetworkMap::apply(MapDefinition* md, const String& name) { if (!md->getDefault().empty()) setDefault(md->getDefault()); if (!(md->getWildcards().find(name) == md->getWildcards().end())) setDefault(md->getWildcards().find(name)->second); for (std::map<StringPair, String>::const_iterator it = md->getExact().begin(), end = md->getExact().end(); it != end; ++it) { if (it->first.first == name) setExact(it->first.second, it->second); if (it->first.second == name) setExact(it->first.first, it->second); } }
static Optional<StringConstraint> createStringConstraint(const Dictionary& mediaTrackConstraintSet, const String& name, MediaConstraintType type, ConstraintSetType constraintSetType) { auto constraint = StringConstraint(name, type); // Dictionary constraint value. Dictionary dictionaryValue; if (mediaTrackConstraintSet.get(name, dictionaryValue) && !dictionaryValue.isUndefinedOrNull()) { ArrayValue exactArrayValue; if (dictionaryValue.get("exact", exactArrayValue) && !exactArrayValue.isUndefinedOrNull()) initializeStringConstraintWithList(constraint, &StringConstraint::appendExact, exactArrayValue); else { String exactStringValue; if (dictionaryValue.get("exact", exactStringValue)) constraint.setExact(exactStringValue); } ArrayValue idealArrayValue; if (dictionaryValue.get("ideal", idealArrayValue) && !idealArrayValue.isUndefinedOrNull()) initializeStringConstraintWithList(constraint, &StringConstraint::appendIdeal, idealArrayValue); else { String idealStringValue; if (!dictionaryValue.get("ideal", idealStringValue)) constraint.setIdeal(idealStringValue); } if (constraint.isEmpty()) { LOG(Media, "createStringConstraint() - ignoring string constraint '%s' with dictionary value since it has no valid or supported key/value pairs.", name.utf8().data()); return Nullopt; } return WTFMove(constraint); } // Array constraint value. ArrayValue arrayValue; if (mediaTrackConstraintSet.get(name, arrayValue) && !arrayValue.isUndefinedOrNull()) { initializeStringConstraintWithList(constraint, &StringConstraint::appendIdeal, arrayValue); if (constraint.isEmpty()) { LOG(Media, "createStringConstraint() - ignoring string constraint '%s' with array value since it is empty.", name.utf8().data()); return Nullopt; } return WTFMove(constraint); } // Scalar constraint value. String value; if (mediaTrackConstraintSet.get(name, value)) { if (constraintSetType == ConstraintSetType::Mandatory) constraint.setIdeal(value); else constraint.setExact(value); return WTFMove(constraint); } // Invalid constraint value. LOG(Media, "createStringConstraint() - ignoring string constraint '%s' since it has neither a dictionary nor sequence nor scalar value.", name.utf8().data()); return Nullopt; }