Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | |
| 10 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/common/media/media_devices.mojom.h" | |
| 13 #include "content/renderer/media/video_track_adapter.h" | |
| 14 #include "media/capture/video_capture_types.h" | |
| 11 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 15 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 12 #include "third_party/webrtc/base/optional.h" | 16 #include "third_party/webrtc/base/optional.h" |
| 13 | 17 |
| 14 namespace content { | 18 namespace content { |
| 15 | 19 |
| 20 class ResolutionSet; | |
| 21 template <typename T> | |
| 22 class NumericRangeSet; | |
| 23 | |
| 24 class CONTENT_EXPORT VideoCaptureSettings { | |
| 25 public: | |
| 26 // Creates a result without value and with an empty failed constraint name. | |
| 27 VideoCaptureSettings(); | |
| 28 | |
| 29 // Creates a result without value and with the given |failed_constraint_name|. | |
| 30 // Does not take ownership of |failed_constraint_name|, so it must be null or | |
| 31 // point to a string that remains accessible. | |
| 32 explicit VideoCaptureSettings(const char* failed_constraint_name); | |
| 33 | |
| 34 // Creates a result with the given values. | |
| 35 VideoCaptureSettings(std::string device_id, | |
| 36 ::mojom::FacingMode facing_mode_, | |
| 37 media::VideoCaptureParams capture_params_, | |
| 38 base::Optional<bool> noise_reduction_, | |
| 39 const VideoTrackAdapterSettings& track_adapter_settings, | |
| 40 double min_frame_rate); | |
| 41 | |
| 42 VideoCaptureSettings(const VideoCaptureSettings& other); | |
| 43 VideoCaptureSettings& operator=(const VideoCaptureSettings& other); | |
| 44 VideoCaptureSettings(VideoCaptureSettings&& other); | |
| 45 VideoCaptureSettings& operator=(VideoCaptureSettings&& other); | |
| 46 ~VideoCaptureSettings(); | |
| 47 | |
| 48 bool HasValue() const { return failed_constraint_name_ == nullptr; } | |
| 49 | |
| 50 // Convenience accessors for fields embedded in |capture_params_|. | |
| 51 const media::VideoCaptureFormat& Format() const { | |
| 52 return capture_params_.requested_format; | |
| 53 } | |
| 54 int Width() const { | |
| 55 DCHECK(HasValue()); | |
| 56 return capture_params_.requested_format.frame_size.width(); | |
| 57 } | |
| 58 int Height() const { | |
| 59 DCHECK(HasValue()); | |
| 60 return capture_params_.requested_format.frame_size.height(); | |
| 61 } | |
| 62 float FrameRate() const { | |
| 63 DCHECK(HasValue()); | |
| 64 return capture_params_.requested_format.frame_rate; | |
| 65 } | |
| 66 media::ResolutionChangePolicy ResolutionChangePolicy() const { | |
| 67 DCHECK(HasValue()); | |
| 68 return capture_params_.resolution_change_policy; | |
| 69 } | |
| 70 media::PowerLineFrequency PowerLineFrequency() const { | |
| 71 DCHECK(HasValue()); | |
| 72 return capture_params_.power_line_frequency; | |
| 73 } | |
| 74 | |
| 75 // Other accessors. | |
| 76 const char* failed_constraint_name() const { return failed_constraint_name_; } | |
| 77 | |
| 78 const std::string& device_id() const { | |
| 79 DCHECK(HasValue()); | |
| 80 return device_id_; | |
| 81 } | |
| 82 ::mojom::FacingMode facing_mode() const { | |
| 83 DCHECK(HasValue()); | |
| 84 return facing_mode_; | |
| 85 } | |
| 86 const media::VideoCaptureParams& capture_params() const { | |
| 87 DCHECK(HasValue()); | |
| 88 return capture_params_; | |
| 89 } | |
| 90 const base::Optional<bool>& noise_reduction() const { | |
| 91 DCHECK(HasValue()); | |
| 92 return noise_reduction_; | |
| 93 } | |
| 94 const VideoTrackAdapterSettings& track_adapter_settings() const { | |
| 95 DCHECK(HasValue()); | |
| 96 return track_adapter_settings_; | |
| 97 } | |
| 98 double min_frame_rate() const { | |
| 99 DCHECK(HasValue()); | |
| 100 return min_frame_rate_; | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 const char* failed_constraint_name_; | |
| 105 std::string device_id_; | |
| 106 ::mojom::FacingMode facing_mode_; | |
| 107 media::VideoCaptureParams capture_params_; | |
| 108 base::Optional<bool> noise_reduction_; | |
| 109 VideoTrackAdapterSettings track_adapter_settings_; | |
|
hbos_chromium
2017/03/28 12:52:53
VideoCaptureParams has w,h,fps.
VideoTrackAdapterS
Guido Urdaneta
2017/03/28 18:35:43
It can be quite confusing. Added a detailed commen
hbos_chromium
2017/03/29 14:54:53
Acknowledged.
| |
| 110 double min_frame_rate_; | |
| 111 }; | |
| 112 | |
| 16 // Method to get boolean value of constraint with |name| from constraints. | 113 // Method to get boolean value of constraint with |name| from constraints. |
| 17 // Returns true if the constraint is specified in either mandatory or optional | 114 // Returns true if the constraint is specified in either mandatory or optional |
| 18 // constraints. | 115 // constraints. |
| 19 bool CONTENT_EXPORT GetConstraintValueAsBoolean( | 116 bool CONTENT_EXPORT GetConstraintValueAsBoolean( |
| 20 const blink::WebMediaConstraints& constraints, | 117 const blink::WebMediaConstraints& constraints, |
| 21 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, | 118 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, |
| 22 bool* value); | 119 bool* value); |
| 23 | 120 |
| 24 // Method to get int value of constraint with |name| from constraints. | 121 // Method to get int value of constraint with |name| from constraints. |
| 25 // Returns true if the constraint is specified in either mandatory or Optional | 122 // Returns true if the constraint is specified in either mandatory or Optional |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 return constraint.hasExact() ? constraint.exact() : constraint.max(); | 183 return constraint.hasExact() ? constraint.exact() : constraint.max(); |
| 87 } | 184 } |
| 88 | 185 |
| 89 template <typename ConstraintType> | 186 template <typename ConstraintType> |
| 90 auto ConstraintMin(const ConstraintType& constraint) | 187 auto ConstraintMin(const ConstraintType& constraint) |
| 91 -> decltype(constraint.min()) { | 188 -> decltype(constraint.min()) { |
| 92 DCHECK(ConstraintHasMin(constraint)); | 189 DCHECK(ConstraintHasMin(constraint)); |
| 93 return constraint.hasExact() ? constraint.exact() : constraint.min(); | 190 return constraint.hasExact() ? constraint.exact() : constraint.min(); |
| 94 } | 191 } |
| 95 | 192 |
| 193 // This function selects track settings from a set of candidate resolutions and | |
| 194 // frame rates, given the source video-capture format and ideal values. | |
| 195 // The output are settings for a VideoTrackAdapter, which can adjust the | |
| 196 // resolution and frame rate of the source, and consist of maximum (or | |
| 197 // target) width, height and frame rate, and minimum and maximum aspect ratio. | |
| 198 // * Minimum and maximum aspect ratios are taken from |resolution_set| and are | |
| 199 // not affected by ideal values. | |
| 200 // * The selected frame rate is always the value within the |frame_rate_set| | |
| 201 // range that is closest to the ideal frame rate (or the source frame rate | |
| 202 // if no ideal is supplied). If the chosen frame rate is greater than or equal | |
| 203 // to the source's frame rate, a value of 0.0 is returned, which means that | |
| 204 // there will be no frame-rate adjustment. | |
|
hbos_chromium
2017/03/28 12:52:53
Should Optional be used instead of 0.0?
Guido Urdaneta
2017/03/28 18:35:43
No. It is the way it is because that is how VideoT
hbos_chromium
2017/03/29 14:54:53
Acknowledged.
| |
| 205 // * Width and height are selected using the | |
| 206 // ResolutionSet::SelectClosestPointToIdeal function, using ideal values from | |
| 207 // |basic_constraint_set| and using the source's width and height as the | |
| 208 // default resolution. The width and height returned by | |
| 209 // SelectClosestPointToIdeal are rounded to the nearest int. For more details, | |
| 210 // see the documentation for ResolutionSet::SelectClosestPointToIdeal. | |
| 211 // Note that this function ignores the min/max/exact values from | |
| 212 // |basic_constraint_set|. Only its ideal values are used. | |
| 213 // This function has undefined behavior if any of |resolution_set| or | |
| 214 // |frame_rate_set| are empty. | |
|
hbos_chromium
2017/03/28 12:52:53
Undefined behavior? Why not DCHECK that they aren'
Guido Urdaneta
2017/03/28 18:35:43
They are DCHECKed, and this is a way to document i
hbos_chromium
2017/03/29 14:54:53
Acknowledged.
| |
| 215 VideoTrackAdapterSettings CONTENT_EXPORT SelectVideoTrackAdapterSettings( | |
|
hbos_chromium
2017/03/28 12:52:53
Why do we express the desired result settings as a
Guido Urdaneta
2017/03/28 18:35:43
Because that's the way VideoTrackAdapter works.
I
hbos_chromium
2017/03/29 14:54:53
Acknowledged.
| |
| 216 const blink::WebMediaTrackConstraintSet& basic_constraint_set, | |
| 217 const ResolutionSet& resolution_set, | |
| 218 const NumericRangeSet<double>& frame_rate_set, | |
| 219 const media::VideoCaptureFormat& source_format); | |
| 220 | |
| 96 } // namespace content | 221 } // namespace content |
| 97 | 222 |
| 98 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_ | 223 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_ |
| OLD | NEW |