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 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 // Note that Chromium performs constraint resolution in two steps. First, a | |
90 // source and its settings are selected; then a track is created, connected to | |
91 // the source, and finally the track settings are selected. This function | |
92 // implements an algorithm for the first step. | |
93 // Sources are not a user-visible concept, so the spec only specifies an | |
94 // algorithm for track settings. | |
95 // This algorithm for sources is compatible with the spec algorithm for tracks, | |
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 different between a source and a track with regards to the spec | |
100 // algorithm is that a source supports a range of values for various | |
101 // constraints while a track supports a single value. For example, cropping | |
102 // 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 value 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 value and a null |failed_constraint_name|. | |
chfremer
2017/01/31 18:23:00
What about the case where no devices are present a
Guido Urdaneta
2017/01/31 20:10:27
Added documentation and extra test for this case.
| |
110 // The criteria to decide if a valid candidate is better than another one are as | |
111 // follows: | |
112 // 1. Given advanced constraint sets A[0],A[1]...,A[n], candidate C1 is better | |
113 // than candidate C2 if C1 supports the first advanced set for which C1's | |
114 // support is different than C2's support. | |
115 // Examples: | |
116 // * One advanced set, C1 supports it, and C2 does not. C1 is better. | |
117 // * Two sets. C1 supports both, C2 supports only the first. C1 is better. | |
118 // * Three sets. C1 supports the first and second set. C2 supports the first | |
119 // and third set. C1 is better. | |
120 // 2. Candidate C1 is better than C2 if C1 has a smaller fitness distance than | |
121 // C2. The fitness distance depends on the ability of the candidate to | |
122 // support ideal values in the basic constraint set. This is the final | |
123 // criterion defined in the spec. | |
124 // 3. Candidate C1 is better than C2 if C1 has a lower custom distance from | |
125 // from the basic constraint set. This custom distance is implementation | |
126 // defined and is composed of various constraint-specific custom distances. | |
127 // For example, if the constraint set specifies a resolution of exactly | |
128 // 1000x1000 for a track, then a candidate with a resolution of 1200x1200 | |
129 // is better than a candidate with a resolution of 2000x2000. Both settings | |
130 // satisfy the constraint set because cropping can be used to produce the | |
131 // track setting of 1000x1000, but 1200x1200 is considered better because it | |
132 // has lower resource usage. The same criteria applies for each advanced | |
133 // constraint set. | |
134 // 4. Candidate C1 is better than C2 if its native settings have a smaller | |
135 // fitness distance. For example, if the ideal resolution is 1000x1000 and C1 | |
136 // has a native resolution of 1200x1200, while C2 has a native resolution of | |
137 // 2000x2000, then C1 is better because it can support the ideal value with | |
138 // lower resource usage. Both C1 and C2 are better than a candidate C3 with | |
139 // a native resolution of 999x999, since C3 has a nonzero distance to the | |
140 // ideal value and thus has worse fitness according to step 2, even if C3's | |
141 // native fitness is better than C1's and C2's. | |
142 // 5. Candidate C1 is better than C2 if its settings are closer to certain | |
143 // default settings that include the device ID, power-line frequency, | |
144 // resolution, and frame rate, in that order. Note that there is no default | |
145 // facing mode or aspect ratio. | |
146 VideoCaptureSourceSelectionResult CONTENT_EXPORT | |
147 SelectVideoCaptureSourceSettings(const VideoCaptureCapabilities& capabilities, | |
148 const blink::WebMediaConstraints& constraints); | |
chfremer
2017/01/31 18:23:00
This algorithm performs three steps.
1. It determi
Guido Urdaneta
2017/01/31 20:10:27
I think this is a good idea for the future, if we
| |
149 | |
150 } // namespace content | |
151 | |
152 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_SOURCE_H_ | |
OLD | NEW |