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

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: remove public kDefaultFailedConstraintName. Use empty string instead. 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 // Note that Chromium performs constraint resolution in two steps. First, a
hta - Chromium 2017/02/02 00:32:39 "Note that" adds no information. Remove it.
Guido Urdaneta 2017/02/02 11:35:39 Done.
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
hta - Chromium 2017/02/02 00:32:39 different -> difference
Guido Urdaneta 2017/02/02 11:35:39 Done.
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|.
110 // If there are no candidates, this function returns a result without valid
111 // settings and with an empty string in |failed_constraint_name|.
112 // The criteria to decide if a valid candidate is better than another one are as
113 // follows:
114 // 1. Given advanced constraint sets A[0],A[1]...,A[n], candidate C1 is better
115 // than candidate C2 if C1 supports the first advanced set for which C1's
116 // support is different than C2's support.
117 // Examples:
118 // * One advanced set, C1 supports it, and C2 does not. C1 is better.
119 // * Two sets. C1 supports both, C2 supports only the first. C1 is better.
120 // * Three sets. C1 supports the first and second set. C2 supports the first
121 // and third set. C1 is better.
122 // 2. Candidate C1 is better than C2 if C1 has a smaller fitness distance than
123 // C2. The fitness distance depends on the ability of the candidate to
124 // support ideal values in the basic constraint set. This is the final
125 // criterion defined in the spec.
126 // 3. Candidate C1 is better than C2 if C1 has a lower custom distance from
127 // from the basic constraint set. This custom distance is implementation
128 // defined and is composed of various constraint-specific custom distances.
129 // For example, if the constraint set specifies a resolution of exactly
130 // 1000x1000 for a track, then a candidate with a resolution of 1200x1200
131 // is better than a candidate with a resolution of 2000x2000. Both settings
132 // satisfy the constraint set because cropping can be used to produce the
133 // track setting of 1000x1000, but 1200x1200 is considered better because it
134 // has lower resource usage. The same criteria applies for each advanced
135 // constraint set.
136 // 4. Candidate C1 is better than C2 if its native settings have a smaller
137 // fitness distance. For example, if the ideal resolution is 1000x1000 and C1
138 // has a native resolution of 1200x1200, while C2 has a native resolution of
139 // 2000x2000, then C1 is better because it can support the ideal value with
140 // lower resource usage. Both C1 and C2 are better than a candidate C3 with
141 // a native resolution of 999x999, since C3 has a nonzero distance to the
142 // ideal value and thus has worse fitness according to step 2, even if C3's
143 // native fitness is better than C1's and C2's.
144 // 5. Candidate C1 is better than C2 if its settings are closer to certain
145 // default settings that include the device ID, power-line frequency,
146 // resolution, and frame rate, in that order. Note that there is no default
147 // facing mode or aspect ratio.
148 VideoCaptureSourceSelectionResult CONTENT_EXPORT
149 SelectVideoCaptureSourceSettings(const VideoCaptureCapabilities& capabilities,
150 const blink::WebMediaConstraints& constraints);
151
152 } // namespace content
153
154 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698