OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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_video_content.h" | 5 #include "content/renderer/media/media_stream_constraints_util_video_content.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "content/renderer/media/media_stream_constraints_util_sets.h" | 11 #include "content/renderer/media/media_stream_constraints_util_sets.h" |
12 #include "content/renderer/media/media_stream_video_source.h" | 12 #include "content/renderer/media/media_stream_video_source.h" |
13 #include "media/base/limits.h" | 13 #include "media/base/limits.h" |
14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
15 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 // TODO(guidou): Change default width and height to larger values. See | 19 const int kDefaultScreenCastWidth = 2880; |
20 // http://crbug.com/257097. | 20 const int kDefaultScreenCastHeight = 1800; |
21 const int kDefaultScreenCastWidth = MediaStreamVideoSource::kDefaultWidth; | 21 const double kDefaultScreenCastAspectRatio = |
22 const int kDefaultScreenCastHeight = MediaStreamVideoSource::kDefaultHeight; | 22 static_cast<double>(kDefaultScreenCastWidth) / kDefaultScreenCastHeight; |
23 const double kDefaultScreenCastFrameRate = | 23 const double kDefaultScreenCastFrameRate = |
24 MediaStreamVideoSource::kDefaultFrameRate; | 24 MediaStreamVideoSource::kDefaultFrameRate; |
25 const int kMinScreenCastDimension = 1; | 25 const int kMinScreenCastDimension = 1; |
26 const int kMaxScreenCastDimension = media::limits::kMaxDimension - 1; | 26 const int kMaxScreenCastDimension = media::limits::kMaxDimension - 1; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 using Point = ResolutionSet::Point; | 30 using Point = ResolutionSet::Point; |
31 using StringSet = DiscreteSet<std::string>; | 31 using StringSet = DiscreteSet<std::string>; |
32 using BoolSet = DiscreteSet<bool>; | 32 using BoolSet = DiscreteSet<bool>; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 // A non-universal BoolSet can have at most one element. | 218 // A non-universal BoolSet can have at most one element. |
219 return base::Optional<bool>(candidates.FirstElement()); | 219 return base::Optional<bool>(candidates.FirstElement()); |
220 } | 220 } |
221 | 221 |
222 VideoCaptureSettings SelectResultFromCandidates( | 222 VideoCaptureSettings SelectResultFromCandidates( |
223 const VideoContentCaptureCandidates& candidates, | 223 const VideoContentCaptureCandidates& candidates, |
224 const blink::WebMediaTrackConstraintSet& basic_constraint_set) { | 224 const blink::WebMediaTrackConstraintSet& basic_constraint_set) { |
225 std::string device_id = SelectDeviceIDFromCandidates(candidates.device_id_set, | 225 std::string device_id = SelectDeviceIDFromCandidates(candidates.device_id_set, |
226 basic_constraint_set); | 226 basic_constraint_set); |
| 227 // If a maximum width or height is explicitly given, use them as default. |
| 228 // If only one of them is given, use the default aspect ratio to determine the |
| 229 // other default value. |
227 // TODO(guidou): Use native screen-capture resolution as default. | 230 // TODO(guidou): Use native screen-capture resolution as default. |
228 // http://crbug.com/257097 | 231 // http://crbug.com/257097 |
| 232 int default_height = kDefaultScreenCastHeight; |
| 233 int default_width = kDefaultScreenCastWidth; |
| 234 bool has_explicit_max_height = |
| 235 candidates.resolution_set.max_height() < kMaxScreenCastDimension; |
| 236 bool has_explicit_max_width = |
| 237 candidates.resolution_set.max_width() < kMaxScreenCastDimension; |
| 238 if (has_explicit_max_height && has_explicit_max_width) { |
| 239 default_height = candidates.resolution_set.max_height(); |
| 240 default_width = candidates.resolution_set.max_width(); |
| 241 } else if (has_explicit_max_height) { |
| 242 default_height = candidates.resolution_set.max_height(); |
| 243 default_width = static_cast<int>( |
| 244 std::round(default_height * kDefaultScreenCastAspectRatio)); |
| 245 } else if (has_explicit_max_width) { |
| 246 default_width = candidates.resolution_set.max_width(); |
| 247 default_height = static_cast<int>( |
| 248 std::round(default_width / kDefaultScreenCastAspectRatio)); |
| 249 } |
229 media::VideoCaptureParams capture_params = | 250 media::VideoCaptureParams capture_params = |
230 SelectVideoCaptureParamsFromCandidates( | 251 SelectVideoCaptureParamsFromCandidates(candidates, basic_constraint_set, |
231 candidates, basic_constraint_set, kDefaultScreenCastHeight, | 252 default_height, default_width, |
232 kDefaultScreenCastWidth, kDefaultScreenCastFrameRate); | 253 kDefaultScreenCastFrameRate); |
233 | 254 |
234 base::Optional<bool> noise_reduction = SelectNoiseReductionFromCandidates( | 255 base::Optional<bool> noise_reduction = SelectNoiseReductionFromCandidates( |
235 candidates.noise_reduction_set, basic_constraint_set); | 256 candidates.noise_reduction_set, basic_constraint_set); |
236 | 257 |
237 auto track_adapter_settings = SelectVideoTrackAdapterSettings( | 258 auto track_adapter_settings = SelectVideoTrackAdapterSettings( |
238 basic_constraint_set, candidates.resolution_set, | 259 basic_constraint_set, candidates.resolution_set, |
239 candidates.frame_rate_set, capture_params.requested_format); | 260 candidates.frame_rate_set, capture_params.requested_format); |
240 | 261 |
241 return VideoCaptureSettings(std::move(device_id), capture_params, | 262 return VideoCaptureSettings(std::move(device_id), capture_params, |
242 noise_reduction, track_adapter_settings, | 263 noise_reduction, track_adapter_settings, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 candidates.Intersection(advanced_candidates); | 306 candidates.Intersection(advanced_candidates); |
286 if (!intersection.IsEmpty()) | 307 if (!intersection.IsEmpty()) |
287 candidates = std::move(intersection); | 308 candidates = std::move(intersection); |
288 } | 309 } |
289 | 310 |
290 DCHECK(!candidates.IsEmpty()); | 311 DCHECK(!candidates.IsEmpty()); |
291 return SelectResultFromCandidates(candidates, constraints.basic()); | 312 return SelectResultFromCandidates(candidates, constraints.basic()); |
292 } | 313 } |
293 | 314 |
294 } // namespace content | 315 } // namespace content |
OLD | NEW |