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

Use namespace for MediaStream constraint utility set types

These utility sets are very specific to constraints processing, but they
have generic-looking names such as DiscreteSet and NumericRangeSet,
which might cause issues if actually generic sets with those names want
to be added elsewhere.

Bug: 731166
Change-Id: I5a5fcec7d1a83417b007621b496b22acba509352
Reviewed-on: https://chromium-review.googlesource.com/1101201
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarHenrik Boström <hbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569409}
parent 6ab180d2
......@@ -256,12 +256,13 @@ bool IsDeviceCapture(const blink::WebMediaConstraints& constraints) {
VideoTrackAdapterSettings SelectVideoTrackAdapterSettings(
const blink::WebMediaTrackConstraintSet& basic_constraint_set,
const ResolutionSet& resolution_set,
const NumericRangeSet<double>& frame_rate_set,
const media_constraints::ResolutionSet& resolution_set,
const media_constraints::NumericRangeSet<double>& frame_rate_set,
const media::VideoCaptureFormat& source_format) {
ResolutionSet::Point resolution = resolution_set.SelectClosestPointToIdeal(
basic_constraint_set, source_format.frame_size.height(),
source_format.frame_size.width());
media_constraints::ResolutionSet::Point resolution =
resolution_set.SelectClosestPointToIdeal(
basic_constraint_set, source_format.frame_size.height(),
source_format.frame_size.width());
int track_max_height = static_cast<int>(std::round(resolution.height()));
int track_max_width = static_cast<int>(std::round(resolution.width()));
double track_min_aspect_ratio =
......
......@@ -19,9 +19,11 @@
namespace content {
namespace media_constraints {
class ResolutionSet;
template <typename T>
class NumericRangeSet;
} // namespace media_constraints
// This class represents the output the SelectSettings algorithm for video
// constraints (see https://w3c.github.io/mediacapture-main/#dfn-selectsettings)
......@@ -350,8 +352,8 @@ bool IsDeviceCapture(const blink::WebMediaConstraints& constraints);
// |frame_rate_set| are empty.
VideoTrackAdapterSettings CONTENT_EXPORT SelectVideoTrackAdapterSettings(
const blink::WebMediaTrackConstraintSet& basic_constraint_set,
const ResolutionSet& resolution_set,
const NumericRangeSet<double>& frame_rate_set,
const media_constraints::ResolutionSet& resolution_set,
const media_constraints::NumericRangeSet<double>& frame_rate_set,
const media::VideoCaptureFormat& source_format);
// Generic distance function between two values for numeric constraints. Based
......
......@@ -24,6 +24,9 @@ namespace content {
namespace {
template <class T>
using DiscreteSet = media_constraints::DiscreteSet<T>;
enum BoolConstraint {
// Constraints not related to audio processing.
HOTWORD_ENABLED,
......@@ -310,29 +313,31 @@ class SingleDeviceCandidateSet {
void ApplyConstraintSet(
const blink::WebMediaTrackConstraintSet& constraint_set) {
device_id_set_ = device_id_set_.Intersection(
StringSetFromConstraint(constraint_set.device_id));
media_constraints::StringSetFromConstraint(constraint_set.device_id));
if (device_id_set_.IsEmpty()) {
failed_constraint_name_ = constraint_set.device_id.GetName();
return;
}
group_id_set_ = group_id_set_.Intersection(
StringSetFromConstraint(constraint_set.group_id));
media_constraints::StringSetFromConstraint(constraint_set.group_id));
if (group_id_set_.IsEmpty()) {
failed_constraint_name_ = constraint_set.group_id.GetName();
return;
}
goog_array_geometry_set_ = goog_array_geometry_set_.Intersection(
StringSetFromConstraint(constraint_set.goog_array_geometry));
media_constraints::StringSetFromConstraint(
constraint_set.goog_array_geometry));
if (goog_array_geometry_set_.IsEmpty()) {
failed_constraint_name_ = constraint_set.goog_array_geometry.GetName();
return;
}
for (size_t i = 0; i < NUM_BOOL_CONSTRAINTS; ++i) {
bool_sets_[i] = bool_sets_[i].Intersection(
BoolSetFromConstraint(constraint_set.*kBlinkBoolConstraintFields[i]));
bool_sets_[i] =
bool_sets_[i].Intersection(media_constraints::BoolSetFromConstraint(
constraint_set.*kBlinkBoolConstraintFields[i]));
if (bool_sets_[i].IsEmpty()) {
failed_constraint_name_ =
(constraint_set.*kBlinkBoolConstraintFields[i]).GetName();
......@@ -352,7 +357,8 @@ class SingleDeviceCandidateSet {
}
echo_cancellation_type_set_ = echo_cancellation_type_set_.Intersection(
StringSetFromConstraint(constraint_set.echo_cancellation_type));
media_constraints::StringSetFromConstraint(
constraint_set.echo_cancellation_type));
if (echo_cancellation_type_set_.IsEmpty()) {
failed_constraint_name_ = constraint_set.echo_cancellation_type.GetName();
return;
......
......@@ -10,6 +10,7 @@
#include "third_party/blink/public/platform/web_media_constraints.h"
namespace content {
namespace media_constraints {
using Point = ResolutionSet::Point;
......@@ -553,4 +554,5 @@ DiscreteSet<bool> BoolSetFromConstraint(
return DiscreteSet<bool>({constraint.Exact()});
}
} // namespace media_constraints
} // namespace content
......@@ -22,6 +22,7 @@ struct WebMediaTrackConstraintSet;
}
namespace content {
namespace media_constraints {
// This class template represents a set of candidates suitable for a numeric
// range-based constraint.
......@@ -392,6 +393,7 @@ class CONTENT_EXPORT ResolutionSet {
ResolutionSet::Point CONTENT_EXPORT operator*(double d,
const ResolutionSet::Point& p);
} // namespace media_constraints
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_CONSTRAINTS_UTIL_SETS_H_
......@@ -12,6 +12,7 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
namespace media_constraints {
using Point = ResolutionSet::Point;
......@@ -1266,4 +1267,5 @@ TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetBool) {
EXPECT_TRUE(intersection.IsEmpty());
}
} // namespace media_constraints
} // namespace content
......@@ -29,7 +29,8 @@ namespace content {
class MediaStreamConstraintsUtilTest : public testing::Test {
protected:
using DoubleRangeSet = NumericRangeSet<double>;
using DoubleRangeSet = media_constraints::NumericRangeSet<double>;
using ResolutionSet = media_constraints::ResolutionSet;
};
TEST_F(MediaStreamConstraintsUtilTest, BooleanConstraints) {
......
......@@ -39,9 +39,11 @@ const double kDefaultScreenCastFrameRate =
namespace {
using ResolutionSet = media_constraints::ResolutionSet;
using Point = ResolutionSet::Point;
using StringSet = DiscreteSet<std::string>;
using BoolSet = DiscreteSet<bool>;
using StringSet = media_constraints::DiscreteSet<std::string>;
using BoolSet = media_constraints::DiscreteSet<bool>;
using DoubleRangeSet = media_constraints::NumericRangeSet<double>;
constexpr double kMinScreenCastAspectRatio =
static_cast<double>(kMinScreenCastDimension) /
......@@ -50,7 +52,6 @@ constexpr double kMaxScreenCastAspectRatio =
static_cast<double>(kMaxScreenCastDimension) /
static_cast<double>(kMinScreenCastDimension);
using DoubleRangeSet = NumericRangeSet<double>;
class VideoContentCaptureCandidates {
public:
......@@ -69,9 +70,10 @@ class VideoContentCaptureCandidates {
DoubleRangeSet::FromConstraint(constraint_set.frame_rate,
0.0,
kMaxScreenCastFrameRate)),
device_id_set_(StringSetFromConstraint(constraint_set.device_id)),
noise_reduction_set_(
BoolSetFromConstraint(constraint_set.goog_noise_reduction)) {}
device_id_set_(media_constraints::StringSetFromConstraint(
constraint_set.device_id)),
noise_reduction_set_(media_constraints::BoolSetFromConstraint(
constraint_set.goog_noise_reduction)) {}
VideoContentCaptureCandidates(VideoContentCaptureCandidates&& other) =
default;
......
......@@ -21,6 +21,9 @@ namespace content {
namespace {
using ResolutionSet = media_constraints::ResolutionSet;
using DoubleRangeSet = media_constraints::NumericRangeSet<double>;
// Number of default settings to be used as final tie-breaking criteria for
// settings that are equally good at satisfying constraints:
// device ID, power-line frequency, noise reduction, resolution and frame rate.
......@@ -125,7 +128,7 @@ class ConstrainedFormat {
const ResolutionSet& constrained_resolution() const {
return constrained_resolution_;
}
const NumericRangeSet<double>& constrained_frame_rate() const {
const DoubleRangeSet& constrained_frame_rate() const {
return constrained_frame_rate_;
}
......@@ -153,9 +156,8 @@ class ConstrainedFormat {
auto resolution_intersection = constrained_resolution_.Intersection(
ResolutionSet::FromConstraintSet(constraint_set));
auto frame_rate_intersection = constrained_frame_rate_.Intersection(
NumericRangeSet<double>::FromConstraint(
constraint_set.frame_rate, 0.0,
media::limits::kMaxFramesPerSecond));
DoubleRangeSet::FromConstraint(constraint_set.frame_rate, 0.0,
media::limits::kMaxFramesPerSecond));
if (resolution_intersection.IsEmpty() ||
frame_rate_intersection.IsEmpty() ||
frame_rate_intersection.Min().value_or(0.0) > native_frame_rate_) {
......@@ -173,7 +175,7 @@ class ConstrainedFormat {
long native_width_;
double native_frame_rate_;
ResolutionSet constrained_resolution_;
NumericRangeSet<double> constrained_frame_rate_;
DoubleRangeSet constrained_frame_rate_;
};
VideoCaptureSettings ComputeVideoDeviceCaptureSettings(
......
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