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

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

Issue 2668023002: Spec-compatible algorithm for selecting video source and settings. (Closed)
Patch Set: address hbos' comments Created 3 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_SOURCE_H_
7
8 #include <iosfwd>
9 #include <string>
10 #include <vector>
11
12 #include "content/common/content_export.h"
13 #include "content/common/media/media_devices.mojom.h"
14 #include "media/capture/video_capture_types.h"
15
16 namespace blink {
17 class WebString;
18 class WebMediaConstraints;
19 }
20
21 namespace content {
22
23 struct CONTENT_EXPORT VideoCaptureCapabilities {
24 VideoCaptureCapabilities();
25 VideoCaptureCapabilities(VideoCaptureCapabilities&& other);
26 ~VideoCaptureCapabilities();
27 VideoCaptureCapabilities& operator=(VideoCaptureCapabilities&& other);
28
29 // Each field is independent of each other.
30 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> device_capabilities;
31 std::vector<media::PowerLineFrequency> power_line_capabilities;
32 };
33
34 class CONTENT_EXPORT VideoCaptureSourceSettings {
35 public:
36 VideoCaptureSourceSettings();
37 VideoCaptureSourceSettings(const VideoCaptureSourceSettings& other);
38 VideoCaptureSourceSettings(VideoCaptureSourceSettings&& other);
39 VideoCaptureSourceSettings(const std::string& device_id,
40 const media::VideoCaptureFormat& format,
41 ::mojom::FacingMode facing_mode,
42 media::PowerLineFrequency power_line_frequency);
43 ~VideoCaptureSourceSettings();
44 VideoCaptureSourceSettings& operator=(
45 const VideoCaptureSourceSettings& other);
46 VideoCaptureSourceSettings& operator=(VideoCaptureSourceSettings&& other);
47
48 // Accessors for easier interaction with blink constraint classes.
49 blink::WebString GetFacingMode() const;
50 long GetPowerLineFrequency() const;
51 long GetWidth() const;
52 long GetHeight() const;
53 double GetFrameRate() const;
54 blink::WebString GetDeviceId() const;
55
56 const media::VideoCaptureFormat& format() const { return format_; }
57 const std::string& device_id() const { return device_id_; }
58 ::mojom::FacingMode facing_mode() const { return facing_mode_; }
59 media::PowerLineFrequency power_line_frequency() const {
60 return power_line_frequency_;
61 }
62
63 private:
64 std::string device_id_;
65 media::VideoCaptureFormat format_;
66 ::mojom::FacingMode facing_mode_;
67 media::PowerLineFrequency power_line_frequency_;
68 };
69
70 struct CONTENT_EXPORT VideoCaptureSourceSelectionResult {
71 VideoCaptureSourceSelectionResult();
72 VideoCaptureSourceSelectionResult(
73 const VideoCaptureSourceSelectionResult& other);
74 VideoCaptureSourceSelectionResult(VideoCaptureSourceSelectionResult&& other);
75 ~VideoCaptureSourceSelectionResult();
76 VideoCaptureSourceSelectionResult& operator=(
77 const VideoCaptureSourceSelectionResult& other);
78 VideoCaptureSourceSelectionResult& operator=(
79 VideoCaptureSourceSelectionResult&& other);
80
81 bool has_value() const { return failed_constraint_name == nullptr; }
82
83 VideoCaptureSourceSettings settings;
84 const char* failed_constraint_name;
85 };
86
87 // This function performs source and source-settings selection based on
88 // the given |capabilities| and |constraints|.
89 // Chromium performs constraint resolution in two steps. First, a source and its
90 // settings are selected; then a track is created, connected to the source, and
91 // finally the track settings are selected. This function implements an
92 // algorithm for the first step. Sources are not a user-visible concept, so the
93 // spec only specifies an algorithm for track settings.
94 // This algorithm for sources is compatible with the spec algorithm for tracks,
95 // as defined in https://w3c.github.io/mediacapture-main/#dfn-selectsettings,
96 // but it is customized to account for differences between sources and tracks,
97 // and to break ties when multiple source settings are equally good according to
98 // the spec algorithm.
99 // The main difference between a source and a track with regards to the spec
100 // algorithm is that a candidate source can support a range of values for some
101 // constraints while a candidate track supports a single value. For example,
102 // cropping allows a source with native resolution AxB to support the range of
103 // resolutions from 1x1 to AxB.
104 // Only candidates that satisfy the basic constraint set are valid. If no
105 // candidate can satisfy the basic constraint set, this function returns
106 // a result without a valid |settings| field and with the name of a failed
107 // constraint in field |failed_constraint_name|. If at least one candidate that
108 // satisfies the basic constraint set can be found, this function returns a
109 // result with a valid |settings| field and a null |failed_constraint_name|.
110 // If there are no candidates at all, this function returns a result with an
111 // empty string in |failed_constraint_name| and without a valid |settings|
112 // field.
113 // The criteria to decide if a valid candidate is better than another one are as
114 // follows:
115 // 1. Given advanced constraint sets A[0],A[1]...,A[n], candidate C1 is better
116 // than candidate C2 if C1 supports the first advanced set for which C1's
117 // support is different than C2's support.
118 // Examples:
119 // * One advanced set, C1 supports it, and C2 does not. C1 is better.
120 // * Two sets, C1 supports both, C2 supports only the first. C1 is better.
121 // * Three sets, C1 supports the first and second set, C2 supports the first
122 // and third set. C1 is better.
123 // 2. C1 is better than C2 if C1 has a smaller fitness distance than C2. The
124 // fitness distance depends on the ability of the candidate to support ideal
125 // values in the basic constraint set. This is the final criterion defined in
126 // the spec.
127 // 3. C1 is better than C2 if C1 has a lower Chromium-specific custom distance
128 // from the basic constraint set. This custom distance is the sum of various
129 // constraint-specific custom distances.
130 // For example, if the constraint set specifies a resolution of exactly
131 // 1000x1000 for a track, then a candidate with a resolution of 1200x1200
132 // is better than a candidate with a resolution of 2000x2000. Both settings
133 // satisfy the constraint set because cropping can be used to produce the
134 // track setting of 1000x1000, but 1200x1200 is considered better because it
135 // has lower resource usage. The same criteria applies for each advanced
136 // constraint set.
137 // 4. C1 is better than C2 if its native settings have a smaller fitness
138 // distance. For example, if the ideal resolution is 1000x1000 and C1 has a
139 // native resolution of 1200x1200, while C2 has a native resolution of
140 // 2000x2000, then C1 is better because it can support the ideal value with
141 // lower resource usage. Both C1 and C2 are better than a candidate C3 with
142 // a native resolution of 999x999, since C3 has a nonzero distance to the
143 // ideal value and thus has worse fitness according to step 2, even if C3's
144 // native fitness is better than C1's and C2's.
145 // 5. C1 is better than C2 if its settings are closer to certain default
146 // settings that include the device ID, power-line frequency, resolution, and
147 // frame rate, in that order. Note that there is no default facing mode or
148 // aspect ratio.
149 VideoCaptureSourceSelectionResult CONTENT_EXPORT
150 SelectVideoCaptureSourceSettings(const VideoCaptureCapabilities& capabilities,
151 const blink::WebMediaConstraints& constraints);
152
153 } // namespace content
154
155 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_SOURCE_H_
OLDNEW
« no previous file with comments | « content/renderer/BUILD.gn ('k') | content/renderer/media/media_stream_constraints_util_video_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698