Commit f25eeff1 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Specialize media_constraints::DiscreteSet<bool>::is_universal()

It is easy to produce explicit universal cases for discrete sets of
boolean values since there are only to possible values.
This CL adds an specialization so that the common case of a set with
{true,false} is considered universal.
This helps simplify some of the constraints processing code for audio,
which contains many boolean properties.

Bug: 731170
Change-Id: Ie7cd41a161f9de93fbc13273d44d2cccaa217522
Reviewed-on: https://chromium-review.googlesource.com/c/1299004Reviewed-by: default avatarHenrik Boström <hbos@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603056}
parent 102efe32
...@@ -165,6 +165,13 @@ class DiscreteSet { ...@@ -165,6 +165,13 @@ class DiscreteSet {
std::vector<T> elements_; std::vector<T> elements_;
}; };
// Special case for DiscreteSet<bool> where it is easy to produce an explicit
// set that contains all possible elements.
template <>
inline bool DiscreteSet<bool>::is_universal() const {
return Contains(true) && Contains(false);
}
DiscreteSet<std::string> StringSetFromConstraint( DiscreteSet<std::string> StringSetFromConstraint(
const blink::StringConstraint& constraint); const blink::StringConstraint& constraint);
DiscreteSet<bool> BoolSetFromConstraint( DiscreteSet<bool> BoolSetFromConstraint(
......
...@@ -1265,6 +1265,10 @@ TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetBool) { ...@@ -1265,6 +1265,10 @@ TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetBool) {
set = BoolSet({true}); set = BoolSet({true});
intersection = set.Intersection(BoolSet({false})); intersection = set.Intersection(BoolSet({false}));
EXPECT_TRUE(intersection.IsEmpty()); EXPECT_TRUE(intersection.IsEmpty());
// Explicit universal set.
set = BoolSet({true, false});
EXPECT_TRUE(set.is_universal());
} }
} // namespace media_constraints } // namespace media_constraints
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment