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

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

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
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 #include "content/renderer/media/media_stream_constraints_util.h" 5 #include "content/renderer/media/media_stream_constraints_util.h"
6 6
7 #include <algorithm>
8 #include <utility>
9
7 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/renderer/media/media_stream_constraints_util_sets.h"
9 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
10 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
11 15
12 namespace content { 16 namespace content {
13 17
14 namespace { 18 namespace {
15 19
16 template <typename P, typename T> 20 template <typename P, typename T>
17 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints, 21 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints,
18 P picker, 22 P picker,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 if (the_field.hasExact()) { 88 if (the_field.hasExact()) {
85 *value = the_field.exact(); 89 *value = the_field.exact();
86 return true; 90 return true;
87 } 91 }
88 } 92 }
89 return false; 93 return false;
90 } 94 }
91 95
92 } // namespace 96 } // namespace
93 97
98 VideoCaptureSettings::VideoCaptureSettings() : VideoCaptureSettings("") {}
99
100 VideoCaptureSettings::VideoCaptureSettings(const char* failed_constraint_name)
101 : failed_constraint_name_(failed_constraint_name) {}
102
103 VideoCaptureSettings::VideoCaptureSettings(
104 std::string device_id,
105 media::VideoCaptureParams capture_params,
106 base::Optional<bool> noise_reduction,
107 const VideoTrackAdapterSettings& track_adapter_settings,
108 double min_frame_rate)
109 : failed_constraint_name_(nullptr),
110 device_id_(std::move(device_id)),
111 capture_params_(capture_params),
112 noise_reduction_(noise_reduction),
113 track_adapter_settings_(track_adapter_settings),
114 min_frame_rate_(min_frame_rate) {
115 DCHECK_LE(min_frame_rate_, capture_params.requested_format.frame_rate);
116 DCHECK_LE(track_adapter_settings.max_width,
117 capture_params.requested_format.frame_size.width());
118 DCHECK_LE(track_adapter_settings.max_height,
119 capture_params.requested_format.frame_size.height());
120 DCHECK_LT(track_adapter_settings.max_frame_rate,
121 capture_params.requested_format.frame_rate);
122 }
123
124 VideoCaptureSettings::VideoCaptureSettings(const VideoCaptureSettings& other) =
125 default;
126 VideoCaptureSettings::VideoCaptureSettings(VideoCaptureSettings&& other) =
127 default;
128 VideoCaptureSettings::~VideoCaptureSettings() = default;
129 VideoCaptureSettings& VideoCaptureSettings::operator=(
130 const VideoCaptureSettings& other) = default;
131 VideoCaptureSettings& VideoCaptureSettings::operator=(
132 VideoCaptureSettings&& other) = default;
133
94 bool GetConstraintValueAsBoolean( 134 bool GetConstraintValueAsBoolean(
95 const blink::WebMediaConstraints& constraints, 135 const blink::WebMediaConstraints& constraints,
96 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, 136 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker,
97 bool* value) { 137 bool* value) {
98 return ScanConstraintsForExactValue(constraints, picker, value); 138 return ScanConstraintsForExactValue(constraints, picker, value);
99 } 139 }
100 140
101 bool GetConstraintValueAsInteger( 141 bool GetConstraintValueAsInteger(
102 const blink::WebMediaConstraints& constraints, 142 const blink::WebMediaConstraints& constraints,
103 const blink::LongConstraint blink::WebMediaTrackConstraintSet::*picker, 143 const blink::LongConstraint blink::WebMediaTrackConstraintSet::*picker,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 rtc::Optional<bool> ConstraintToOptional( 195 rtc::Optional<bool> ConstraintToOptional(
156 const blink::WebMediaConstraints& constraints, 196 const blink::WebMediaConstraints& constraints,
157 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { 197 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) {
158 bool value; 198 bool value;
159 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { 199 if (GetConstraintValueAsBoolean(constraints, picker, &value)) {
160 return rtc::Optional<bool>(value); 200 return rtc::Optional<bool>(value);
161 } 201 }
162 return rtc::Optional<bool>(); 202 return rtc::Optional<bool>();
163 } 203 }
164 204
205 VideoTrackAdapterSettings SelectVideoTrackAdapterSettings(
206 const blink::WebMediaTrackConstraintSet& basic_constraint_set,
207 const ResolutionSet& resolution_set,
208 const NumericRangeSet<double>& frame_rate_set,
209 const media::VideoCaptureFormat& source_format) {
210 ResolutionSet::Point resolution = resolution_set.SelectClosestPointToIdeal(
211 basic_constraint_set, source_format.frame_size.height(),
212 source_format.frame_size.width());
213 int track_max_height = static_cast<int>(std::round(resolution.height()));
214 int track_max_width = static_cast<int>(std::round(resolution.width()));
215 double track_min_aspect_ratio =
216 std::max(resolution_set.min_aspect_ratio(),
217 static_cast<double>(resolution_set.min_width()) /
218 static_cast<double>(resolution_set.max_height()));
219 double track_max_aspect_ratio =
220 std::min(resolution_set.max_aspect_ratio(),
221 static_cast<double>(resolution_set.max_width()) /
222 static_cast<double>(resolution_set.min_height()));
223 double track_max_frame_rate = frame_rate_set.Max();
224 if (basic_constraint_set.frameRate.hasIdeal()) {
225 track_max_frame_rate = std::min(
226 track_max_frame_rate,
227 std::max(basic_constraint_set.frameRate.ideal(), frame_rate_set.Min()));
228 }
229 // VideoTrackAdapter uses a frame rate of 0.0 to disable frame-rate
230 // adjustment.
231 if (track_max_frame_rate >= source_format.frame_rate)
232 track_max_frame_rate = 0.0;
233
234 return VideoTrackAdapterSettings(
235 track_max_width, track_max_height, track_min_aspect_ratio,
236 track_max_aspect_ratio, track_max_frame_rate);
237 }
238
165 } // namespace content 239 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_constraints_util.h ('k') | content/renderer/media/media_stream_constraints_util_sets.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698