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

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

Issue 2231863004: Add "exact" constraint evaluation to video picker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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_video_source.h" 5 #include "content/renderer/media/media_stream_video_source.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
(...skipping 15 matching lines...) Expand all
26 }; 26 };
27 27
28 // Returns true if |constraint| has mandatory constraints. 28 // Returns true if |constraint| has mandatory constraints.
29 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) { 29 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) {
30 return constraints.basic().hasMandatory(); 30 return constraints.basic().hasMandatory();
31 } 31 }
32 32
33 // Retrieve the desired max width and height from |constraints|. If not set, 33 // Retrieve the desired max width and height from |constraints|. If not set,
34 // the |desired_width| and |desired_height| are set to 34 // the |desired_width| and |desired_height| are set to
35 // std::numeric_limits<int>::max(); 35 // std::numeric_limits<int>::max();
36 // If either max width or height is set as a mandatory constraint, the optional 36 // If either max or exact width or height is set as a mandatory constraint,
37 // constraints are not checked. 37 // the advanced constraints are not checked.
38 //
Guido Urdaneta 2016/08/11 09:25:01 nit: is this empty line with "//" intentional
hta - Chromium 2016/08/11 11:18:18 No. Removed.
38 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints, 39 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints,
39 int* desired_width, int* desired_height) { 40 int* desired_width, int* desired_height) {
40 *desired_width = std::numeric_limits<int>::max(); 41 *desired_width = std::numeric_limits<int>::max();
41 *desired_height = std::numeric_limits<int>::max(); 42 *desired_height = std::numeric_limits<int>::max();
42 43
43 const auto& basic_constraints = constraints.basic(); 44 const auto& basic_constraints = constraints.basic();
45 if (basic_constraints.width.hasExact() ||
46 basic_constraints.height.hasExact()) {
Guido Urdaneta 2016/08/11 09:25:01 what if it has exact width and max height, but no
hta - Chromium 2016/08/11 11:18:18 That is a correct question to ask. I merged the tw
47 if (basic_constraints.width.hasExact())
48 *desired_width = basic_constraints.width.exact();
49 if (basic_constraints.height.hasExact())
50 *desired_height = basic_constraints.height.exact();
51 return;
52 }
53
44 if (basic_constraints.width.hasMax() || basic_constraints.height.hasMax()) { 54 if (basic_constraints.width.hasMax() || basic_constraints.height.hasMax()) {
45 if (basic_constraints.width.hasMax()) 55 if (basic_constraints.width.hasMax())
46 *desired_width = basic_constraints.width.max(); 56 *desired_width = basic_constraints.width.max();
47 if (basic_constraints.height.hasMax()) 57 if (basic_constraints.height.hasMax())
48 *desired_height = basic_constraints.height.max(); 58 *desired_height = basic_constraints.height.max();
49 return; 59 return;
50 } 60 }
51 61
52 for (const auto& constraint_set : constraints.advanced()) { 62 for (const auto& constraint_set : constraints.advanced()) {
53 if (constraint_set.width.hasMax()) 63 if (constraint_set.width.hasMax())
54 *desired_width = constraint_set.width.max(); 64 *desired_width = constraint_set.width.max();
55 if (constraint_set.height.hasMax()) 65 if (constraint_set.height.hasMax())
56 *desired_height = constraint_set.height.max(); 66 *desired_height = constraint_set.height.max();
67 if (constraint_set.width.hasExact())
68 *desired_width = constraint_set.width.exact();
69 if (constraint_set.height.hasExact())
70 *desired_height = constraint_set.height.exact();
57 } 71 }
58 } 72 }
59 73
60 // Retrieve the desired max and min aspect ratio from |constraints|. If not set, 74 // Retrieve the desired max and min aspect ratio from |constraints|. If not set,
61 // the |min_aspect_ratio| is set to 0 and |max_aspect_ratio| is set to 75 // the |min_aspect_ratio| is set to 0 and |max_aspect_ratio| is set to
62 // std::numeric_limits<double>::max(); 76 // std::numeric_limits<double>::max();
63 // If either min or max aspect ratio is set as a mandatory constraint, the 77 // If either min or max aspect ratio is set as a mandatory constraint, the
64 // optional constraints are not checked. 78 // optional constraints are not checked.
65 void GetDesiredMinAndMaxAspectRatio( 79 void GetDesiredMinAndMaxAspectRatio(
66 const blink::WebMediaConstraints& constraints, 80 const blink::WebMediaConstraints& constraints,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 DCHECK(format != NULL); 118 DCHECK(format != NULL);
105 119
106 if (!format->IsValid()) 120 if (!format->IsValid())
107 return false; 121 return false;
108 122
109 // The width and height are matched based on cropping occuring later: 123 // The width and height are matched based on cropping occuring later:
110 // min width/height has to be >= the size of the frame (no upscale). 124 // min width/height has to be >= the size of the frame (no upscale).
111 // max width/height just has to be > 0 (we can crop anything too large). 125 // max width/height just has to be > 0 (we can crop anything too large).
112 if ((constraints.width.hasMin() && 126 if ((constraints.width.hasMin() &&
113 constraints.width.min() > format->frame_size.width()) || 127 constraints.width.min() > format->frame_size.width()) ||
114 (constraints.width.hasMax() && constraints.width.max() <= 0)) { 128 (constraints.width.hasMax() && constraints.width.max() <= 0) ||
129 (constraints.width.hasExact() &&
130 constraints.width.exact() != format->frame_size.width())) {
115 *failing_constraint_name = constraints.width.name(); 131 *failing_constraint_name = constraints.width.name();
116 } else if ((constraints.height.hasMin() && 132 } else if ((constraints.height.hasMin() &&
117 constraints.height.min() > format->frame_size.height()) || 133 constraints.height.min() > format->frame_size.height()) ||
118 (constraints.height.hasMax() && constraints.height.max() <= 0)) { 134 (constraints.height.hasMax() && constraints.height.max() <= 0) ||
135 (constraints.height.hasExact() &&
136 constraints.height.exact() != format->frame_size.height())) {
119 *failing_constraint_name = constraints.height.name(); 137 *failing_constraint_name = constraints.height.name();
120 } else if (!constraints.frameRate.matches(format->frame_rate)) { 138 } else if (!constraints.frameRate.matches(format->frame_rate)) {
121 if (constraints.frameRate.hasMax()) { 139 if (constraints.frameRate.hasMax()) {
122 const double value = constraints.frameRate.max(); 140 const double value = constraints.frameRate.max();
123 // TODO(hta): Check if handling of max = 0.0 is relevant. 141 // TODO(hta): Check if handling of max = 0.0 is relevant.
124 // (old handling was to set rate to 1.0 if 0.0 was specified) 142 // (old handling was to set rate to 1.0 if 0.0 was specified)
125 if (constraints.frameRate.matches(value)) { 143 if (constraints.frameRate.matches(value)) {
126 format->frame_rate = 144 format->frame_rate =
127 (format->frame_rate > value) ? value : format->frame_rate; 145 (format->frame_rate > value) ? value : format->frame_rate;
128 return true; 146 return true;
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 callback(callback) { 587 callback(callback) {
570 } 588 }
571 589
572 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( 590 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor(
573 const TrackDescriptor& other) = default; 591 const TrackDescriptor& other) = default;
574 592
575 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() { 593 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() {
576 } 594 }
577 595
578 } // namespace content 596 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698