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