| OLD | NEW |
| 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 Loading... |
| 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 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints, | 38 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints, |
| 39 int* desired_width, int* desired_height) { | 39 int* desired_width, int* desired_height) { |
| 40 *desired_width = std::numeric_limits<int>::max(); | 40 *desired_width = std::numeric_limits<int>::max(); |
| 41 *desired_height = std::numeric_limits<int>::max(); | 41 *desired_height = std::numeric_limits<int>::max(); |
| 42 | 42 |
| 43 const auto& basic_constraints = constraints.basic(); | 43 const auto& basic_constraints = constraints.basic(); |
| 44 if (basic_constraints.width.hasMax() || basic_constraints.height.hasMax()) { | 44 |
| 45 if (basic_constraints.width.hasMax() || basic_constraints.height.hasMax() || |
| 46 basic_constraints.width.hasExact() || |
| 47 basic_constraints.height.hasExact()) { |
| 45 if (basic_constraints.width.hasMax()) | 48 if (basic_constraints.width.hasMax()) |
| 46 *desired_width = basic_constraints.width.max(); | 49 *desired_width = basic_constraints.width.max(); |
| 47 if (basic_constraints.height.hasMax()) | 50 if (basic_constraints.height.hasMax()) |
| 48 *desired_height = basic_constraints.height.max(); | 51 *desired_height = basic_constraints.height.max(); |
| 52 // Exact constraints override max constraints if both are specified. |
| 53 // Specifying both in the same structure is meaningless. |
| 54 if (basic_constraints.width.hasExact()) |
| 55 *desired_width = basic_constraints.width.exact(); |
| 56 if (basic_constraints.height.hasExact()) |
| 57 *desired_height = basic_constraints.height.exact(); |
| 49 return; | 58 return; |
| 50 } | 59 } |
| 51 | 60 |
| 52 for (const auto& constraint_set : constraints.advanced()) { | 61 for (const auto& constraint_set : constraints.advanced()) { |
| 53 if (constraint_set.width.hasMax()) | 62 if (constraint_set.width.hasMax()) |
| 54 *desired_width = constraint_set.width.max(); | 63 *desired_width = constraint_set.width.max(); |
| 55 if (constraint_set.height.hasMax()) | 64 if (constraint_set.height.hasMax()) |
| 56 *desired_height = constraint_set.height.max(); | 65 *desired_height = constraint_set.height.max(); |
| 66 if (constraint_set.width.hasExact()) |
| 67 *desired_width = constraint_set.width.exact(); |
| 68 if (constraint_set.height.hasExact()) |
| 69 *desired_height = constraint_set.height.exact(); |
| 57 } | 70 } |
| 58 } | 71 } |
| 59 | 72 |
| 60 // Retrieve the desired max and min aspect ratio from |constraints|. If not set, | 73 // 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 | 74 // the |min_aspect_ratio| is set to 0 and |max_aspect_ratio| is set to |
| 62 // std::numeric_limits<double>::max(); | 75 // std::numeric_limits<double>::max(); |
| 63 // If either min or max aspect ratio is set as a mandatory constraint, the | 76 // If either min or max aspect ratio is set as a mandatory constraint, the |
| 64 // optional constraints are not checked. | 77 // optional constraints are not checked. |
| 65 void GetDesiredMinAndMaxAspectRatio( | 78 void GetDesiredMinAndMaxAspectRatio( |
| 66 const blink::WebMediaConstraints& constraints, | 79 const blink::WebMediaConstraints& constraints, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 DCHECK(format != NULL); | 117 DCHECK(format != NULL); |
| 105 | 118 |
| 106 if (!format->IsValid()) | 119 if (!format->IsValid()) |
| 107 return false; | 120 return false; |
| 108 | 121 |
| 109 // The width and height are matched based on cropping occuring later: | 122 // 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). | 123 // 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). | 124 // max width/height just has to be > 0 (we can crop anything too large). |
| 112 if ((constraints.width.hasMin() && | 125 if ((constraints.width.hasMin() && |
| 113 constraints.width.min() > format->frame_size.width()) || | 126 constraints.width.min() > format->frame_size.width()) || |
| 114 (constraints.width.hasMax() && constraints.width.max() <= 0)) { | 127 (constraints.width.hasMax() && constraints.width.max() <= 0) || |
| 128 (constraints.width.hasExact() && |
| 129 constraints.width.exact() > format->frame_size.width())) { |
| 115 *failing_constraint_name = constraints.width.name(); | 130 *failing_constraint_name = constraints.width.name(); |
| 116 } else if ((constraints.height.hasMin() && | 131 } else if ((constraints.height.hasMin() && |
| 117 constraints.height.min() > format->frame_size.height()) || | 132 constraints.height.min() > format->frame_size.height()) || |
| 118 (constraints.height.hasMax() && constraints.height.max() <= 0)) { | 133 (constraints.height.hasMax() && constraints.height.max() <= 0) || |
| 134 (constraints.height.hasExact() && |
| 135 constraints.height.exact() > format->frame_size.height())) { |
| 119 *failing_constraint_name = constraints.height.name(); | 136 *failing_constraint_name = constraints.height.name(); |
| 120 } else if (!constraints.frameRate.matches(format->frame_rate)) { | 137 } else if (!constraints.frameRate.matches(format->frame_rate)) { |
| 121 if (constraints.frameRate.hasMax()) { | 138 if (constraints.frameRate.hasMax()) { |
| 122 const double value = constraints.frameRate.max(); | 139 const double value = constraints.frameRate.max(); |
| 123 // TODO(hta): Check if handling of max = 0.0 is relevant. | 140 // 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) | 141 // (old handling was to set rate to 1.0 if 0.0 was specified) |
| 125 if (constraints.frameRate.matches(value)) { | 142 if (constraints.frameRate.matches(value)) { |
| 126 format->frame_rate = | 143 format->frame_rate = |
| 127 (format->frame_rate > value) ? value : format->frame_rate; | 144 (format->frame_rate > value) ? value : format->frame_rate; |
| 128 return true; | 145 return true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 142 void FilterFormatsByConstraints( | 159 void FilterFormatsByConstraints( |
| 143 const blink::WebMediaTrackConstraintSet& constraints, | 160 const blink::WebMediaTrackConstraintSet& constraints, |
| 144 media::VideoCaptureFormats* formats, | 161 media::VideoCaptureFormats* formats, |
| 145 std::string* failing_constraint_name) { | 162 std::string* failing_constraint_name) { |
| 146 media::VideoCaptureFormats::iterator format_it = formats->begin(); | 163 media::VideoCaptureFormats::iterator format_it = formats->begin(); |
| 147 while (format_it != formats->end()) { | 164 while (format_it != formats->end()) { |
| 148 // Modify |format_it| to fulfill the constraint if possible. | 165 // Modify |format_it| to fulfill the constraint if possible. |
| 149 // Delete it otherwise. | 166 // Delete it otherwise. |
| 150 if (!UpdateFormatForConstraints(constraints, &(*format_it), | 167 if (!UpdateFormatForConstraints(constraints, &(*format_it), |
| 151 failing_constraint_name)) { | 168 failing_constraint_name)) { |
| 169 DVLOG(2) << "Format filter: Discarding format " |
| 170 << format_it->frame_size.width() << "x" |
| 171 << format_it->frame_size.height() << "@" |
| 172 << format_it->frame_rate; |
| 152 format_it = formats->erase(format_it); | 173 format_it = formats->erase(format_it); |
| 153 } else { | 174 } else { |
| 154 ++format_it; | 175 ++format_it; |
| 155 } | 176 } |
| 156 } | 177 } |
| 157 } | 178 } |
| 158 | 179 |
| 159 // Returns the media::VideoCaptureFormats that matches |constraints|. | 180 // Returns the media::VideoCaptureFormats that matches |constraints|. |
| 160 // If the return value is empty, and the reason is a specific constraint, | 181 // If the return value is empty, and the reason is a specific constraint, |
| 161 // |unsatisfied_constraint| returns the name of the constraint. | 182 // |unsatisfied_constraint| returns the name of the constraint. |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 callback(callback) { | 590 callback(callback) { |
| 570 } | 591 } |
| 571 | 592 |
| 572 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( | 593 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( |
| 573 const TrackDescriptor& other) = default; | 594 const TrackDescriptor& other) = default; |
| 574 | 595 |
| 575 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() { | 596 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() { |
| 576 } | 597 } |
| 577 | 598 |
| 578 } // namespace content | 599 } // namespace content |
| OLD | NEW |