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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 const int MediaStreamVideoSource::kDefaultWidth = 640; | 42 const int MediaStreamVideoSource::kDefaultWidth = 640; |
43 const int MediaStreamVideoSource::kDefaultHeight = 480; | 43 const int MediaStreamVideoSource::kDefaultHeight = 480; |
44 const int MediaStreamVideoSource::kDefaultFrameRate = 30; | 44 const int MediaStreamVideoSource::kDefaultFrameRate = 30; |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 // Google-specific key prefix. Constraints with this prefix are ignored if they | 48 // Google-specific key prefix. Constraints with this prefix are ignored if they |
49 // are unknown. | 49 // are unknown. |
50 const char kGooglePrefix[] = "goog"; | 50 const char kGooglePrefix[] = "goog"; |
51 | 51 |
52 // MediaStreamVideoSource supports cropping of video frames but only up to | |
53 // kMaxCropFactor. Ie - if a constraint is set to maxHeight 360, an original | |
54 // input frame height of max 360 * kMaxCropFactor pixels is accepted. | |
55 const int kMaxCropFactor = 2; | |
56 | |
57 // Returns true if |constraint| has mandatory constraints. | 52 // Returns true if |constraint| has mandatory constraints. |
58 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) { | 53 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) { |
59 blink::WebVector<blink::WebMediaConstraint> mandatory_constraints; | 54 blink::WebVector<blink::WebMediaConstraint> mandatory_constraints; |
60 constraints.getMandatoryConstraints(mandatory_constraints); | 55 constraints.getMandatoryConstraints(mandatory_constraints); |
61 return !mandatory_constraints.isEmpty(); | 56 return !mandatory_constraints.isEmpty(); |
62 } | 57 } |
63 | 58 |
64 // Retrieve the desired max width and height from |constraints|. If not set, | 59 // Retrieve the desired max width and height from |constraints|. If not set, |
65 // the |desired_width| and |desired_height| are set to | 60 // the |desired_width| and |desired_height| are set to |
66 // std::numeric_limits<int>::max(); | 61 // std::numeric_limits<int>::max(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 159 |
165 int value; | 160 int value; |
166 if (!base::StringToInt(constraint_value, &value)) { | 161 if (!base::StringToInt(constraint_value, &value)) { |
167 DLOG(WARNING) << "Can't parse MediaStream constraint. Name:" | 162 DLOG(WARNING) << "Can't parse MediaStream constraint. Name:" |
168 << constraint_name << " Value:" << constraint_value; | 163 << constraint_name << " Value:" << constraint_value; |
169 return false; | 164 return false; |
170 } | 165 } |
171 if (constraint_name == MediaStreamVideoSource::kMinWidth) { | 166 if (constraint_name == MediaStreamVideoSource::kMinWidth) { |
172 return (value <= format->frame_size.width()); | 167 return (value <= format->frame_size.width()); |
173 } else if (constraint_name == MediaStreamVideoSource::kMaxWidth) { | 168 } else if (constraint_name == MediaStreamVideoSource::kMaxWidth) { |
174 return (value * kMaxCropFactor >= format->frame_size.width()); | 169 return value > 0; |
mcasas
2014/05/30 13:31:58
Shouldn't we:
return value > kMinimumPossibleFrame
| |
175 } else if (constraint_name == MediaStreamVideoSource::kMinHeight) { | 170 } else if (constraint_name == MediaStreamVideoSource::kMinHeight) { |
176 return (value <= format->frame_size.height()); | 171 return (value <= format->frame_size.height()); |
177 } else if (constraint_name == MediaStreamVideoSource::kMaxHeight) { | 172 } else if (constraint_name == MediaStreamVideoSource::kMaxHeight) { |
178 return (value * kMaxCropFactor >= format->frame_size.height()); | 173 return value > 0; |
mcasas
2014/05/30 13:31:58
return value > kMaximumPossibleFrameWidth?
(Assum
| |
179 } else if (constraint_name == MediaStreamVideoSource::kMinFrameRate) { | 174 } else if (constraint_name == MediaStreamVideoSource::kMinFrameRate) { |
180 return (value <= format->frame_rate); | 175 return (value <= format->frame_rate); |
181 } else if (constraint_name == MediaStreamVideoSource::kMaxFrameRate) { | 176 } else if (constraint_name == MediaStreamVideoSource::kMaxFrameRate) { |
182 if (value == 0) { | 177 if (value == 0) { |
183 // The frame rate is set by constraint. | 178 // The frame rate is set by constraint. |
184 // Don't allow 0 as frame rate if it is a mandatory constraint. | 179 // Don't allow 0 as frame rate if it is a mandatory constraint. |
185 // Set the frame rate to 1 if it is not mandatory. | 180 // Set the frame rate to 1 if it is not mandatory. |
186 if (mandatory) { | 181 if (mandatory) { |
187 return false; | 182 return false; |
188 } else { | 183 } else { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 : track(track), | 569 : track(track), |
575 frame_callback(frame_callback), | 570 frame_callback(frame_callback), |
576 constraints(constraints), | 571 constraints(constraints), |
577 callback(callback) { | 572 callback(callback) { |
578 } | 573 } |
579 | 574 |
580 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { | 575 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { |
581 } | 576 } |
582 | 577 |
583 } // namespace content | 578 } // namespace content |
OLD | NEW |