Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: content/renderer/media/media_stream_constraints_util.h

Issue 2777703002: Introduce SelectSettings algorithm for MediaStream video tracks. (Closed)
Patch Set: static asserts Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/media/media_stream_constraints_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This class represents the output the SelectSettings algorithm for video
25 // constraints (see https://w3c.github.io/mediacapture-main/#dfn-selectsettings)
26 // The input to SelectSettings is a user-supplied constraints object, and its
27 // output is a set of implementation-specific settings that are used to
28 // configure other Chromium objects such as sources, tracks and sinks so that
29 // they work in the way indicated by the specification. VideoCaptureSettings may
30 // also be used to implement other constraints-related functionality, such as
31 // the getSettings() function.
32 // The following fields are used to control MediaStreamVideoSource objects:
33 // * device_id: used for device selection and obtained from the deviceId
34 // * capture_params: used to initialize video capture. Its values are obtained
35 // from the width, height, aspectRatio, frame_rate, googPowerLineFrequency,
36 // and googNoiseReduction constraints.
37 // The following fields are used to control MediaStreamVideoTrack objects:
38 // * track_adapter_settings: All track objects use a VideoTrackAdapter object
39 // that may perform cropping and frame-rate adjustment. This field contains
40 // the adapter settings suitable for the track the constraints are being
41 // to. These settings are derived from the width, height, aspectRatio and
42 // frameRate constraints.
43 // Some MediaStreamVideoSink objects (e.g. MediaStreamVideoWebRtcSink) require
44 // configuration derived from constraints that cannot be obtained from the
45 // source and track settings indicated above. The following fields are used
46 // to configure sinks:
47 // * noise_reduction: used to control noise reduction for a screen-capture
48 // track sent to a peer connection. Derive from the googNoiseReduction
49 // constraint.
50 // * min_frame_rate: used to control frame refreshes in screen-capture tracks
51 // sent to a peer connection. Derived from the frameRate constraint.
52 class CONTENT_EXPORT VideoCaptureSettings {
53 public:
54 // Creates an object without value and with an empty failed constraint name.
55 VideoCaptureSettings();
56
57 // Creates an object without value and with the given
58 // |failed_constraint_name|. Does not take ownership of
59 // |failed_constraint_name|, so it must be null or point to a string that
60 // remains accessible.
61 explicit VideoCaptureSettings(const char* failed_constraint_name);
62
63 // Creates an object with the given values.
64 VideoCaptureSettings(std::string device_id,
65 media::VideoCaptureParams capture_params_,
66 base::Optional<bool> noise_reduction_,
67 const VideoTrackAdapterSettings& track_adapter_settings,
68 double min_frame_rate);
69
70 VideoCaptureSettings(const VideoCaptureSettings& other);
71 VideoCaptureSettings& operator=(const VideoCaptureSettings& other);
72 VideoCaptureSettings(VideoCaptureSettings&& other);
73 VideoCaptureSettings& operator=(VideoCaptureSettings&& other);
74 ~VideoCaptureSettings();
75
76 bool HasValue() const { return failed_constraint_name_ == nullptr; }
77
78 // Convenience accessors for fields embedded in |capture_params_|.
79 const media::VideoCaptureFormat& Format() const {
80 return capture_params_.requested_format;
81 }
82 int Width() const {
83 DCHECK(HasValue());
84 return capture_params_.requested_format.frame_size.width();
85 }
86 int Height() const {
87 DCHECK(HasValue());
88 return capture_params_.requested_format.frame_size.height();
89 }
90 float FrameRate() const {
91 DCHECK(HasValue());
92 return capture_params_.requested_format.frame_rate;
93 }
94 media::ResolutionChangePolicy ResolutionChangePolicy() const {
95 DCHECK(HasValue());
96 return capture_params_.resolution_change_policy;
97 }
98 media::PowerLineFrequency PowerLineFrequency() const {
99 DCHECK(HasValue());
100 return capture_params_.power_line_frequency;
101 }
102
103 // Other accessors.
104 const char* failed_constraint_name() const { return failed_constraint_name_; }
105
106 const std::string& device_id() const {
107 DCHECK(HasValue());
108 return device_id_;
109 }
110 const media::VideoCaptureParams& capture_params() const {
111 DCHECK(HasValue());
112 return capture_params_;
113 }
114 const base::Optional<bool>& noise_reduction() const {
115 DCHECK(HasValue());
116 return noise_reduction_;
117 }
118 const VideoTrackAdapterSettings& track_adapter_settings() const {
119 DCHECK(HasValue());
120 return track_adapter_settings_;
121 }
122 double min_frame_rate() const {
123 DCHECK(HasValue());
124 return min_frame_rate_;
125 }
126
127 private:
128 const char* failed_constraint_name_;
129 std::string device_id_;
130 media::VideoCaptureParams capture_params_;
131 base::Optional<bool> noise_reduction_;
132 VideoTrackAdapterSettings track_adapter_settings_;
133 double min_frame_rate_;
134 };
135
16 // Method to get boolean value of constraint with |name| from constraints. 136 // Method to get boolean value of constraint with |name| from constraints.
17 // Returns true if the constraint is specified in either mandatory or optional 137 // Returns true if the constraint is specified in either mandatory or optional
18 // constraints. 138 // constraints.
19 bool CONTENT_EXPORT GetConstraintValueAsBoolean( 139 bool CONTENT_EXPORT GetConstraintValueAsBoolean(
20 const blink::WebMediaConstraints& constraints, 140 const blink::WebMediaConstraints& constraints,
21 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, 141 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker,
22 bool* value); 142 bool* value);
23 143
24 // Method to get int value of constraint with |name| from constraints. 144 // Method to get int value of constraint with |name| from constraints.
25 // Returns true if the constraint is specified in either mandatory or Optional 145 // Returns true if the constraint is specified in either mandatory or Optional
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return constraint.hasExact() ? constraint.exact() : constraint.max(); 206 return constraint.hasExact() ? constraint.exact() : constraint.max();
87 } 207 }
88 208
89 template <typename ConstraintType> 209 template <typename ConstraintType>
90 auto ConstraintMin(const ConstraintType& constraint) 210 auto ConstraintMin(const ConstraintType& constraint)
91 -> decltype(constraint.min()) { 211 -> decltype(constraint.min()) {
92 DCHECK(ConstraintHasMin(constraint)); 212 DCHECK(ConstraintHasMin(constraint));
93 return constraint.hasExact() ? constraint.exact() : constraint.min(); 213 return constraint.hasExact() ? constraint.exact() : constraint.min();
94 } 214 }
95 215
216 // This function selects track settings from a set of candidate resolutions and
217 // frame rates, given the source video-capture format and ideal values.
218 // The output are settings for a VideoTrackAdapter, which can adjust the
219 // resolution and frame rate of the source, and consist of maximum (or
220 // target) width, height and frame rate, and minimum and maximum aspect ratio.
221 // * Minimum and maximum aspect ratios are taken from |resolution_set| and are
222 // not affected by ideal values.
223 // * The selected frame rate is always the value within the |frame_rate_set|
224 // range that is closest to the ideal frame rate (or the source frame rate
225 // if no ideal is supplied). If the chosen frame rate is greater than or equal
226 // to the source's frame rate, a value of 0.0 is returned, which means that
227 // there will be no frame-rate adjustment.
228 // * Width and height are selected using the
229 // ResolutionSet::SelectClosestPointToIdeal function, using ideal values from
230 // |basic_constraint_set| and using the source's width and height as the
231 // default resolution. The width and height returned by
232 // SelectClosestPointToIdeal are rounded to the nearest int. For more details,
233 // see the documentation for ResolutionSet::SelectClosestPointToIdeal.
234 // Note that this function ignores the min/max/exact values from
235 // |basic_constraint_set|. Only its ideal values are used.
236 // This function has undefined behavior if any of |resolution_set| or
237 // |frame_rate_set| are empty.
238 VideoTrackAdapterSettings CONTENT_EXPORT SelectVideoTrackAdapterSettings(
239 const blink::WebMediaTrackConstraintSet& basic_constraint_set,
240 const ResolutionSet& resolution_set,
241 const NumericRangeSet<double>& frame_rate_set,
242 const media::VideoCaptureFormat& source_format);
243
96 } // namespace content 244 } // namespace content
97 245
98 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_ 246 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/media_stream_constraints_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698