Commit 42f379d3 authored by Devlin's avatar Devlin Committed by Commit Bot

Revert "SelectSettings algorithm for audio constraints."

This reverts commit 51e98fac.

Reason for revert: New tests (MediaStreamConstraintsUtilAudioTest.ValidGeometry) are failing:
https://luci-logdog.appspot.com/v/?s=chromium%2Fbb%2Fchromium.win%2FWin7_Tests__dbg__1_%2F60774%2F%2B%2Frecipes%2Fsteps%2Fcontent_unittests%2F0%2Flogs%2FMediaStreamConstraintsUtilAudioTest.ValidGeometry__x2f_0%2F0

Original change's description:
> SelectSettings algorithm for audio constraints.
> 
> This is intended to be used in getUserMedia to implement spec-compliant
> audio constraints processing.
> 
> BUG=657733
> 
> Change-Id: Ida1bc5561b16b0c5ac1628c19c71fb8f0b5a33fd
> Reviewed-on: https://chromium-review.googlesource.com/517782
> Commit-Queue: Guido Urdaneta <guidou@chromium.org>
> Reviewed-by: Jochen Eisinger <jochen@chromium.org>
> Reviewed-by: Henrik Boström <hbos@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#478607}

TBR=miu@chromium.org,hbos@chromium.org,guidou@chromium.org,jochen@chromium.org
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
BUG=657733

Change-Id: I9c9e9f6a9b0ad464c550443e273409feb4bd6ec7
Reviewed-on: https://chromium-review.googlesource.com/531126Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478643}
parent 87779825
......@@ -603,8 +603,6 @@ target(link_target_type, "renderer") {
"media/media_stream_center.h",
"media/media_stream_constraints_util.cc",
"media/media_stream_constraints_util.h",
"media/media_stream_constraints_util_audio.cc",
"media/media_stream_constraints_util_audio.h",
"media/media_stream_constraints_util_sets.cc",
"media/media_stream_constraints_util_sets.h",
"media/media_stream_constraints_util_video_content.cc",
......
......@@ -275,17 +275,6 @@ std::string MediaAudioConstraints::GetGoogArrayGeometry() const {
return "";
}
AudioProcessingProperties::AudioProcessingProperties() = default;
AudioProcessingProperties::AudioProcessingProperties(
const AudioProcessingProperties& other) = default;
AudioProcessingProperties& AudioProcessingProperties::operator=(
const AudioProcessingProperties& other) = default;
AudioProcessingProperties::AudioProcessingProperties(
AudioProcessingProperties&& other) = default;
AudioProcessingProperties& AudioProcessingProperties::operator=(
AudioProcessingProperties&& other) = default;
AudioProcessingProperties::~AudioProcessingProperties() = default;
EchoInformation::EchoInformation()
: delay_stats_time_ms_(0),
echo_frames_received_(false),
......
......@@ -6,14 +6,12 @@
#define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_
#include <string>
#include <vector>
#include "base/files/file.h"
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "content/public/common/media_stream_request.h"
#include "media/base/audio_point.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
#include "third_party/webrtc/api/mediastreaminterface.h"
#include "third_party/webrtc/media/base/mediachannel.h"
......@@ -32,7 +30,6 @@ using webrtc::AudioProcessing;
// A helper class to parse audio constraints from a blink::WebMediaConstraints
// object.
// TODO(guidou): Remove this class. http://crbug.com/706408
class CONTENT_EXPORT MediaAudioConstraints {
public:
// Constraint keys used by audio processing.
......@@ -97,38 +94,6 @@ class CONTENT_EXPORT MediaAudioConstraints {
bool default_audio_processing_constraint_value_;
};
// Simple struct with audio-processing properties. Will substitute
// MediaAudioConstraints once the old constraints-processing algorithm is
// removed. http://crbug.com/706408
struct CONTENT_EXPORT AudioProcessingProperties {
// Creates an AudioProcessingProperties object with fields initialized to
// their default values.
AudioProcessingProperties();
AudioProcessingProperties(const AudioProcessingProperties& other);
AudioProcessingProperties& operator=(const AudioProcessingProperties& other);
AudioProcessingProperties(AudioProcessingProperties&& other);
AudioProcessingProperties& operator=(AudioProcessingProperties&& other);
~AudioProcessingProperties();
bool enable_sw_echo_cancellation = true;
bool disable_hw_echo_cancellation = false;
bool goog_audio_mirroring = false;
bool goog_auto_gain_control = true;
bool goog_experimental_echo_cancellation =
#if defined(OS_ANDROID)
false;
#else
true;
#endif
bool goog_typing_noise_detection = true;
bool goog_noise_suppression = true;
bool goog_experimental_noise_suppression = true;
bool goog_beamforming = true;
bool goog_highpass_filter = true;
bool goog_experimental_auto_gain_control = true;
std::vector<media::Point> goog_array_geometry;
};
// A helper class to log echo information in general and Echo Cancellation
// quality in particular.
class CONTENT_EXPORT EchoInformation {
......
......@@ -104,9 +104,7 @@ bool ScanConstraintsForMinValue(const blink::WebMediaConstraints& constraints,
VideoCaptureSettings::VideoCaptureSettings() : VideoCaptureSettings("") {}
VideoCaptureSettings::VideoCaptureSettings(const char* failed_constraint_name)
: failed_constraint_name_(failed_constraint_name) {
DCHECK(failed_constraint_name_);
}
: failed_constraint_name_(failed_constraint_name) {}
VideoCaptureSettings::VideoCaptureSettings(
std::string device_id,
......@@ -142,37 +140,6 @@ VideoCaptureSettings& VideoCaptureSettings::operator=(
VideoCaptureSettings& VideoCaptureSettings::operator=(
VideoCaptureSettings&& other) = default;
AudioCaptureSettings::AudioCaptureSettings() : AudioCaptureSettings("") {}
AudioCaptureSettings::AudioCaptureSettings(const char* failed_constraint_name)
: failed_constraint_name_(failed_constraint_name) {
DCHECK(failed_constraint_name_);
}
AudioCaptureSettings::AudioCaptureSettings(
std::string device_id,
const media::AudioParameters& audio_parameters,
bool enable_hotword,
bool disable_local_echo,
bool enable_automatic_output_device_selection,
const AudioProcessingProperties& audio_processing_properties)
: failed_constraint_name_(nullptr),
device_id_(std::move(device_id)),
audio_parameters_(audio_parameters),
hotword_enabled_(enable_hotword),
disable_local_echo_(disable_local_echo),
render_to_associated_sink_(enable_automatic_output_device_selection),
audio_processing_properties_(audio_processing_properties) {}
AudioCaptureSettings::AudioCaptureSettings(const AudioCaptureSettings& other) =
default;
AudioCaptureSettings& AudioCaptureSettings::operator=(
const AudioCaptureSettings& other) = default;
AudioCaptureSettings::AudioCaptureSettings(AudioCaptureSettings&& other) =
default;
AudioCaptureSettings& AudioCaptureSettings::operator=(
AudioCaptureSettings&& other) = default;
bool GetConstraintValueAsBoolean(
const blink::WebMediaConstraints& constraints,
const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker,
......@@ -244,25 +211,6 @@ rtc::Optional<bool> ConstraintToOptional(
return rtc::Optional<bool>();
}
std::string GetMediaStreamSource(
const blink::WebMediaConstraints& constraints) {
std::string source;
if (constraints.Basic().media_stream_source.HasIdeal() &&
constraints.Basic().media_stream_source.Exact().size() > 0) {
source = constraints.Basic().media_stream_source.Ideal()[0].Utf8();
}
if (constraints.Basic().media_stream_source.HasExact() &&
constraints.Basic().media_stream_source.Exact().size() > 0) {
source = constraints.Basic().media_stream_source.Exact()[0].Utf8();
}
return source;
}
bool IsDeviceCapture(const blink::WebMediaConstraints& constraints) {
return GetMediaStreamSource(constraints).empty();
}
VideoTrackAdapterSettings SelectVideoTrackAdapterSettings(
const blink::WebMediaTrackConstraintSet& basic_constraint_set,
const ResolutionSet& resolution_set,
......@@ -302,26 +250,4 @@ VideoTrackAdapterSettings SelectVideoTrackAdapterSettings(
track_max_aspect_ratio, track_max_frame_rate, expected_native_size);
}
double NumericConstraintFitnessDistance(double value1, double value2) {
if (std::fabs(value1 - value2) <= blink::DoubleConstraint::kConstraintEpsilon)
return 0.0;
return std::fabs(value1 - value2) /
std::max(std::fabs(value1), std::fabs(value2));
}
double StringConstraintFitnessDistance(
const blink::WebString& value,
const blink::StringConstraint& constraint) {
if (!constraint.HasIdeal())
return 0.0;
for (auto& ideal_value : constraint.Ideal()) {
if (value == ideal_value)
return 0.0;
}
return 1.0;
}
} // namespace content
......@@ -10,7 +10,6 @@
#include "base/logging.h"
#include "content/common/content_export.h"
#include "content/common/media/media_devices.mojom.h"
#include "content/renderer/media/media_stream_audio_processor_options.h"
#include "content/renderer/media/video_track_adapter.h"
#include "media/capture/video_capture_types.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
......@@ -51,9 +50,6 @@ class NumericRangeSet;
// * min_frame_rate and max_frame_rate: used to control frame refreshes in
// screen-capture tracks sent to a peer connection. Derived from the
// frameRate constraint.
// If SelectSettings fails, the HasValue() method returns false and
// failed_constraint_name() returns the name of one of the (possibly multiple)
// constraints that could not be satisfied.
class CONTENT_EXPORT VideoCaptureSettings {
public:
// Creates an object without value and with an empty failed constraint name.
......@@ -61,8 +57,8 @@ class CONTENT_EXPORT VideoCaptureSettings {
// Creates an object without value and with the given
// |failed_constraint_name|. Does not take ownership of
// |failed_constraint_name|, so it must point to a string that remains
// accessible. |failed_constraint_name| must be non-null.
// |failed_constraint_name|, so it must be null or point to a string that
// remains accessible.
explicit VideoCaptureSettings(const char* failed_constraint_name);
// Creates an object with the given values.
......@@ -144,95 +140,6 @@ class CONTENT_EXPORT VideoCaptureSettings {
base::Optional<double> max_frame_rate_;
};
// This class represents the output the SelectSettings algorithm for audio
// constraints (see https://w3c.github.io/mediacapture-main/#dfn-selectsettings)
// The input to SelectSettings is a user-supplied constraints object, and its
// output is a set of implementation-specific settings that are used to
// configure other Chromium objects such as sources, tracks and sinks so that
// they work in the way indicated by the specification. AudioCaptureSettings may
// also be used to implement other constraints-related functionality, such as
// the getSettings() function.
// The following fields are used to control MediaStreamVideoSource objects:
// * device_id: used for device selection and obtained from the deviceId
// * device_parameters: these are the hardware parameters for the device
// selected by SelectSettings. They can be used to verify that the
// parameters with which the audio stream is actually created corresponds
// to what SelectSettings selected. It can also be used to implement
// getSettings() for device-related properties such as sampleRate and
// channelCount.
// The following fields are used to control various audio features:
// * hotword_enabled
// * disable_local_echo
// * render_to_associated_sink
// The audio_properties field is used to control the audio-processing module,
// which provides features such as software-based echo cancellation.
// If SelectSettings fails, the HasValue() method returns false and
// failed_constraint_name() returns the name of one of the (possibly multiple)
// constraints that could not be satisfied.
class CONTENT_EXPORT AudioCaptureSettings {
public:
// Creates an object without value and with an empty failed constraint name.
AudioCaptureSettings();
// Creates an object without value and with the given
// |failed_constraint_name|. Does not take ownership of
// |failed_constraint_name|, so it must point to a string that remains
// accessible. |failed_constraint_name| must be non-null.
explicit AudioCaptureSettings(const char* failed_constraint_name);
// Creates an object with the given values.
explicit AudioCaptureSettings(
std::string device_id,
const media::AudioParameters& audio_parameters,
bool enable_hotword,
bool disable_local_echo,
bool enable_automatic_output_device_selection,
const AudioProcessingProperties& audio_processing_properties);
AudioCaptureSettings(const AudioCaptureSettings& other);
AudioCaptureSettings& operator=(const AudioCaptureSettings& other);
AudioCaptureSettings(AudioCaptureSettings&& other);
AudioCaptureSettings& operator=(AudioCaptureSettings&& other);
bool HasValue() const { return failed_constraint_name_ == nullptr; }
// Accessors.
const char* failed_constraint_name() const { return failed_constraint_name_; }
const std::string& device_id() const {
DCHECK(HasValue());
return device_id_;
}
// This field is meaningless in content capture.
const media::AudioParameters& device_parameters() const {
DCHECK(HasValue());
return audio_parameters_;
}
bool hotword_enabled() const {
DCHECK(HasValue());
return hotword_enabled_;
}
bool disable_local_echo() const {
DCHECK(HasValue());
return disable_local_echo_;
}
bool render_to_associated_sink() const {
DCHECK(HasValue());
return render_to_associated_sink_;
}
AudioProcessingProperties audio_processing_properties() const {
DCHECK(HasValue());
return audio_processing_properties_;
}
private:
const char* failed_constraint_name_;
std::string device_id_;
media::AudioParameters audio_parameters_;
bool hotword_enabled_;
bool disable_local_echo_;
bool render_to_associated_sink_;
AudioProcessingProperties audio_processing_properties_;
};
// Method to get boolean value of constraint with |name| from constraints.
// Returns true if the constraint is specified in either mandatory or optional
// constraints.
......@@ -313,22 +220,6 @@ auto ConstraintMin(const ConstraintType& constraint)
return constraint.HasExact() ? constraint.Exact() : constraint.Min();
}
// If |value| is outside the range of |constraint|, returns the name of the
// failed constraint. Otherwise, returns nullptr. The return value converts to
// bool in the expected way.
template <typename NumericConstraintType, typename ValueType>
const char* IsOutsideConstraintRange(NumericConstraintType constraint,
ValueType value) {
return (ConstraintHasMin(constraint) && value < ConstraintMin(constraint)) ||
(ConstraintHasMax(constraint) &&
value > ConstraintMax(constraint))
? constraint.GetName()
: nullptr;
}
std::string GetMediaStreamSource(const blink::WebMediaConstraints& constraints);
bool IsDeviceCapture(const blink::WebMediaConstraints& constraints);
// This function selects track settings from a set of candidate resolutions and
// frame rates, given the source video-capture format and ideal values.
// The output are settings for a VideoTrackAdapter, which can adjust the
......@@ -358,17 +249,6 @@ VideoTrackAdapterSettings CONTENT_EXPORT SelectVideoTrackAdapterSettings(
const media::VideoCaptureFormat& source_format,
bool expect_source_native_size);
// Generic distance function between two values for numeric constraints. Based
// on the fitness-distance function described in
// https://w3c.github.io/mediacapture-main/#dfn-fitness-distance
double NumericConstraintFitnessDistance(double value1, double value2);
// Fitness distance between |value| and |constraint|.
// Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance.
double StringConstraintFitnessDistance(
const blink::WebString& value,
const blink::StringConstraint& constraint);
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_AUDIO_H_
#define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_AUDIO_H_
#include <string>
#include <vector>
#include "content/common/content_export.h"
#include "content/common/media/media_devices.mojom.h"
#include "content/renderer/media/media_stream_constraints_util.h"
namespace blink {
class WebMediaConstraints;
}
namespace content {
using AudioDeviceCaptureCapabilities =
std::vector<::mojom::AudioInputDeviceCapabilitiesPtr>;
// This function implements the SelectSettings algorithm for audio tracks as
// described in https://w3c.github.io/mediacapture-main/#dfn-selectsettings
// The algorithm starts with a set containing all possible candidate settings
// based on hardware capabilities (passed via the |capabilities| parameter) and
// supported values for properties not involved in device selection. Candidates
// that do not support the basic constraint set from |constraints| are removed.
// If the set of candidates is empty after this step, the function returns an
// AudioCaptureSettings object without value and whose failed_constraint_name()
// method returns the name of one of the (possibly many) constraints that could
// not be satisfied or an empty string if the set of candidates was initially
// empty (e.g., if there are no devices in the system).
// After the basic constraint set is applied, advanced constraint sets are
// applied. If no candidates can satisfy an advanced set, the advanced set is
// ignored, otherwise the candidates that cannot satisfy the advanced set are
// removed.
// Once all constraint sets are applied, the result is selected from the
// remaining candidates by giving preference to candidates closest to the ideal
// values specified in the basic constraint set, or using default
// implementation-specific values.
// The result includes the following properties:
// * Device. A device is chosen using the device_id, sample_rate, sample_size,
// and channel_count constraints. If multiple devices satisfy the constraints
// preference is given to the default device (system defined or chosen by
// user preferences). If the default device is not included in the valid
// candidates, the first valid device in the list obtained by querying the
// system capabilities is chosen. For content capture, no real audio input
// devices are used and the sample_rate, sample_size and channel_count
// constraints are ignored. In content capture, the deviceId constraint is
// supported and is interpreted by the system as a string that indicates,
// for example, which tab to capture. Validation for that "device" ID is
// performed by the getUserMedia implementation. To decide between content
// or device capture, the value of the special media_stream_source constraint
// is used.
// * Audio features: the hotword_enabled, disable_local_echo and
// render_to_associated_sink constraints can be used to enable the
// corresponding audio feature. If not specified, their default value is
// false.
// * Audio processing. The remaining constraints are used to control audio
// processing. This is how audio-processing properties are set for device
// capture(see the content::AudioProcessingProperties struct) :
// - enable_sw_echo_cancellation: If the selected device has hardware echo
// cancellation, software echo cancellation is disabled regardless of
// any constraint values. Otherwise, it is enabled by default unless
// either the echo_cancellation or the goog_echo_cancellation constraint
// has a final value of false after applying all constraint sets. Note
// that if these constraints have contradictory values, SelectSettings
// fails and returns no value.
// - disable_hw_echo_cancellation: For devices that have hardware echo
// cancellation, the feature is disabled if the echo_cancellation or
// goog_echo_cancellation constraints have a final value of false.
// - goog_audio_mirroring: This property is mapped directly from the final
// value of the goog_audio_mirroring constraint. If no value is
// explicitly specified, the default value is false.
// The remaining audio-processing properties are directly mapped from the
// final value of the corresponding constraints. If no value is explicitly
// specified, the default value is the same as the final value of the
// echo_cancellation constraint. If the echo_cancellation constraint is
// not explicitly specified, the default value is implementation defined
// (see content::AudioProcessingProperties).
// For content capture the rules are the same, but all properties are false
// by default, regardless of the value of the echo_cancellation constraint.
// Note that it is important to distinguish between audio properties and
// constraints. Constraints are an input to SelectSettings, while properties
// are part of the output. The value for most boolean properties comes
// directly from a corresponding boolean constraint, but this is not true for
// all constraints and properties. For example, the echo_cancellation and
// goog_echo_cancellation constraints are not directly mapped to any
// property, but they, together with hardware characteristics, influence the
// enabling and disabling of software and hardware echo cancellation.
// Moreover, the echo_cancellation constraint influences most other
// audio-processing properties for which no explicit value is provided in
// their corresponding constraints.
AudioCaptureSettings CONTENT_EXPORT
SelectSettingsAudioCapture(const AudioDeviceCaptureCapabilities& capabilities,
const blink::WebMediaConstraints& constraints);
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_AUDIO_H_
......@@ -533,24 +533,4 @@ ResolutionSet ResolutionSet::FromConstraintSet(
MaxAspectRatioFromConstraint(constraint_set.aspect_ratio));
}
DiscreteSet<std::string> StringSetFromConstraint(
const blink::StringConstraint& constraint) {
if (!constraint.HasExact())
return DiscreteSet<std::string>::UniversalSet();
std::vector<std::string> elements;
for (const auto& entry : constraint.Exact())
elements.push_back(entry.Ascii());
return DiscreteSet<std::string>(std::move(elements));
}
DiscreteSet<bool> BoolSetFromConstraint(
const blink::BooleanConstraint& constraint) {
if (!constraint.HasExact())
return DiscreteSet<bool>::UniversalSet();
return DiscreteSet<bool>({constraint.Exact()});
}
} // namespace content
......@@ -7,7 +7,6 @@
#include <algorithm>
#include <limits>
#include <string>
#include <utility>
#include <vector>
......@@ -72,12 +71,9 @@ class NumericRangeSet {
// is application defined (e.g., it could be all possible boolean values, all
// possible strings of length N, or anything that suits a particular
// application).
// TODO(guidou): Rename this class. http://crbug.com/731166
template <typename T>
class DiscreteSet {
public:
// Creates a universal set.
DiscreteSet() : is_universal_(true) {}
// Creates a set containing the elements in |elements|.
// It is the responsibility of the caller to ensure that |elements| is not
// equivalent to the universal set and that |elements| has no repeated
......@@ -131,25 +127,16 @@ class DiscreteSet {
return elements_[0];
}
// Returns a reference to the list of elements in the set.
// Behavior is undefined if the set is universal.
const std::vector<T>& elements() const {
DCHECK(!is_universal_);
return elements_;
}
bool is_universal() const { return is_universal_; }
private:
// Creates a universal set.
DiscreteSet() : is_universal_(true) {}
bool is_universal_;
std::vector<T> elements_;
};
DiscreteSet<std::string> StringSetFromConstraint(
const blink::StringConstraint& constraint);
DiscreteSet<bool> BoolSetFromConstraint(
const blink::BooleanConstraint& constraint);
// This class represents a set of (height, width) screen resolution candidates
// determined by width, height and aspect-ratio constraints.
// This class supports widths and heights from 0 to kMaxDimension, both
......
......@@ -45,6 +45,7 @@ using Point = ResolutionSet::Point;
using StringSet = DiscreteSet<std::string>;
using BoolSet = DiscreteSet<bool>;
constexpr double kMinScreenCastAspectRatio =
static_cast<double>(kMinScreenCastDimension) /
static_cast<double>(kMaxScreenCastDimension);
......@@ -52,6 +53,24 @@ constexpr double kMaxScreenCastAspectRatio =
static_cast<double>(kMaxScreenCastDimension) /
static_cast<double>(kMinScreenCastDimension);
StringSet StringSetFromConstraint(const blink::StringConstraint& constraint) {
if (!constraint.HasExact())
return StringSet::UniversalSet();
std::vector<std::string> elements;
for (const auto& entry : constraint.Exact())
elements.push_back(entry.Ascii());
return StringSet(std::move(elements));
}
BoolSet BoolSetFromConstraint(const blink::BooleanConstraint& constraint) {
if (!constraint.HasExact())
return BoolSet::UniversalSet();
return BoolSet({constraint.Exact()});
}
using DoubleRangeSet = NumericRangeSet<double>;
class VideoContentCaptureCandidates {
......@@ -60,7 +79,9 @@ class VideoContentCaptureCandidates {
: has_explicit_max_height_(false),
has_explicit_max_width_(false),
has_explicit_min_frame_rate_(false),
has_explicit_max_frame_rate_(false) {}
has_explicit_max_frame_rate_(false),
device_id_set_(StringSet::UniversalSet()),
noise_reduction_set_(BoolSet::UniversalSet()) {}
explicit VideoContentCaptureCandidates(
const blink::WebMediaTrackConstraintSet& constraint_set)
: resolution_set_(ResolutionSet::FromConstraintSet(constraint_set)),
......
......@@ -189,6 +189,17 @@ VideoCaptureSettings ComputeVideoDeviceCaptureSettings(
constrained_format.constrained_frame_rate().Max());
}
// Generic distance function between two numeric values. Based on the fitness
// distance function described in
// https://w3c.github.io/mediacapture-main/#dfn-fitness-distance
double Distance(double value1, double value2) {
if (std::fabs(value1 - value2) <= blink::DoubleConstraint::kConstraintEpsilon)
return 0.0;
return std::fabs(value1 - value2) /
std::max(std::fabs(value1), std::fabs(value2));
}
// Returns a pair with the minimum and maximum aspect ratios supported by the
// candidate format |constrained_format|, subject to given width and height
// constraints.
......@@ -273,8 +284,7 @@ double ResolutionConstraintSourceDistance(
// If the source value exceeds the maximum requested, penalize.
if (constraint_has_max && native_source_value > constraint_max)
return NumericConstraintFitnessDistance(native_source_value,
constraint_max);
return Distance(native_source_value, constraint_max);
return 0.0;
}
......@@ -316,8 +326,7 @@ double FrameRateConstraintSourceDistance(
// Compute the cost using the native rate.
if (constraint_has_max &&
constrained_format.native_frame_rate() > constraint_max)
return NumericConstraintFitnessDistance(
constrained_format.native_frame_rate(), constraint_max);
return Distance(constrained_format.native_frame_rate(), constraint_max);
return 0.0;
}
......@@ -491,6 +500,22 @@ double CandidateSourceDistance(
failed_constraint_name);
}
// Returns the fitness distance between |value| and |constraint|.
// Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance.
double StringConstraintFitnessDistance(
const blink::WebString& value,
const blink::StringConstraint& constraint) {
if (!constraint.HasIdeal())
return 0.0;
for (auto& ideal_value : constraint.Ideal()) {
if (value == ideal_value)
return 0.0;
}
return 1.0;
}
// Returns the fitness distance between |value| and |constraint| for
// resolution constraints (i.e., width and height).
// Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance.
......@@ -505,7 +530,7 @@ double ResolutionConstraintFitnessDistance(
if (value >= constraint.Ideal())
return 0.0;
return NumericConstraintFitnessDistance(value, constraint.Ideal());
return Distance(value, constraint.Ideal());
}
// Returns the fitness distance between |value| and |constraint| for
......@@ -515,9 +540,7 @@ double ResolutionConstraintFitnessDistance(
double ResolutionConstraintNativeFitnessDistance(
long value,
const blink::LongConstraint& constraint) {
return constraint.HasIdeal()
? NumericConstraintFitnessDistance(value, constraint.Ideal())
: 0.0;
return constraint.HasIdeal() ? Distance(value, constraint.Ideal()) : 0.0;
}
// Returns the fitness distance between a source resolution settings
......@@ -543,15 +566,13 @@ double AspectRatioConstraintFitnessDistance(
if (max_source_aspect_ratio <
aspect_ratio_constraint.Ideal() -
blink::DoubleConstraint::kConstraintEpsilon) {
return NumericConstraintFitnessDistance(max_source_aspect_ratio,
aspect_ratio_constraint.Ideal());
return Distance(max_source_aspect_ratio, aspect_ratio_constraint.Ideal());
}
if (min_source_aspect_ratio >
aspect_ratio_constraint.Ideal() +
blink::DoubleConstraint::kConstraintEpsilon) {
return NumericConstraintFitnessDistance(min_source_aspect_ratio,
aspect_ratio_constraint.Ideal());
return Distance(min_source_aspect_ratio, aspect_ratio_constraint.Ideal());
}
// Otherwise, the ideal aspect ratio can be supported and the fitness is 0.
......@@ -574,7 +595,7 @@ double FrameRateConstraintFitnessDistance(
return 0.0;
}
return NumericConstraintFitnessDistance(value, constraint.Ideal());
return Distance(value, constraint.Ideal());
}
// Returns the fitness distance between |value| and |constraint| for the
......@@ -584,9 +605,7 @@ double FrameRateConstraintFitnessDistance(
double FrameRateConstraintNativeFitnessDistance(
double value,
const blink::DoubleConstraint& constraint) {
return constraint.HasIdeal()
? NumericConstraintFitnessDistance(value, constraint.Ideal())
: 0.0;
return constraint.HasIdeal() ? Distance(value, constraint.Ideal()) : 0.0;
}
// Returns the fitness distance between |value| and |constraint| for the
......@@ -716,17 +735,15 @@ void AppendDistanceFromDefault(
double resolution_distance =
candidate_area == kDefaultResolutionArea
? 0.0
: NumericConstraintFitnessDistance(candidate_area,
kDefaultResolutionArea);
: Distance(candidate_area, kDefaultResolutionArea);
distance_vector->push_back(resolution_distance);
// Prefer a frame rate close to the default.
double frame_rate_distance =
candidate.format().frame_rate == MediaStreamVideoSource::kDefaultFrameRate
? 0.0
: NumericConstraintFitnessDistance(
candidate.format().frame_rate,
MediaStreamVideoSource::kDefaultFrameRate);
: Distance(candidate.format().frame_rate,
MediaStreamVideoSource::kDefaultFrameRate);
distance_vector->push_back(frame_rate_distance);
}
......
......@@ -1631,7 +1631,6 @@ test("content_unittests") {
"../renderer/media/media_devices_event_dispatcher_unittest.cc",
"../renderer/media/media_stream_audio_processor_unittest.cc",
"../renderer/media/media_stream_audio_unittest.cc",
"../renderer/media/media_stream_constraints_util_audio_unittest.cc",
"../renderer/media/media_stream_constraints_util_sets_unittest.cc",
"../renderer/media/media_stream_constraints_util_unittest.cc",
"../renderer/media/media_stream_constraints_util_video_content_unittest.cc",
......
......@@ -31,15 +31,14 @@
#ifndef WebMediaConstraints_h
#define WebMediaConstraints_h
#include <string>
#include <vector>
#include "WebCommon.h"
#include "WebNonCopyable.h"
#include "WebPrivatePtr.h"
#include "WebString.h"
#include "WebVector.h"
#include <vector>
namespace blink {
class WebMediaConstraintsPrivate;
......@@ -168,8 +167,6 @@ class BLINK_PLATFORM_EXPORT StringConstraint : public BaseConstraint {
void SetExact(const WebVector<WebString>& exact) { exact_.Assign(exact); }
void SetIdeal(const WebString& ideal) { ideal_.Assign(&ideal, 1); }
void SetIdeal(const WebVector<WebString>& ideal) { ideal_.Assign(ideal); }
bool Matches(WebString value) const;
......
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