| Index: content/renderer/media/media_stream_constraints_util.h
 | 
| diff --git a/content/renderer/media/media_stream_constraints_util.h b/content/renderer/media/media_stream_constraints_util.h
 | 
| index 1c666a34f6cbfc0c7dac5a16bfd536efe4327ae2..4c238a53c3199641081f7548a024ce2de178a0ab 100644
 | 
| --- a/content/renderer/media/media_stream_constraints_util.h
 | 
| +++ b/content/renderer/media/media_stream_constraints_util.h
 | 
| @@ -10,6 +10,7 @@
 | 
|  #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"
 | 
| @@ -50,6 +51,9 @@ 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.
 | 
| @@ -57,8 +61,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 be null or point to a string that
 | 
| -  // remains accessible.
 | 
| +  // |failed_constraint_name|, so it must point to a string that remains
 | 
| +  // accessible. |failed_constraint_name| must be non-null.
 | 
|    explicit VideoCaptureSettings(const char* failed_constraint_name);
 | 
|  
 | 
|    // Creates an object with the given values.
 | 
| @@ -140,6 +144,95 @@ 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.
 | 
| @@ -220,6 +313,22 @@ 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
 | 
| @@ -249,6 +358,17 @@ 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_
 | 
| 
 |