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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "content/renderer/media/media_stream_constraints_util.h" | |
13 #include "content/renderer/media/media_stream_dependency_factory.h" | 14 #include "content/renderer/media/media_stream_dependency_factory.h" |
14 #include "content/renderer/media/media_stream_video_track.h" | 15 #include "content/renderer/media/media_stream_video_track.h" |
15 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 16 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b | 20 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b |
20 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio"; | 21 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio"; |
21 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio"; | 22 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio"; |
22 const char MediaStreamVideoSource::kMaxWidth[] = "maxWidth"; | 23 const char MediaStreamVideoSource::kMaxWidth[] = "maxWidth"; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 FilterFormatsByConstraint(optional[i], false, ¤t_candidates); | 197 FilterFormatsByConstraint(optional[i], false, ¤t_candidates); |
197 if (!current_candidates.empty()) { | 198 if (!current_candidates.empty()) { |
198 candidates = current_candidates; | 199 candidates = current_candidates; |
199 } | 200 } |
200 } | 201 } |
201 | 202 |
202 // We have done as good as we can to filter the supported resolutions. | 203 // We have done as good as we can to filter the supported resolutions. |
203 return candidates; | 204 return candidates; |
204 } | 205 } |
205 | 206 |
206 bool GetConstraintValue(const blink::WebMediaConstraints& constraints, | |
207 bool mandatory, const blink::WebString& name, | |
208 int* value) { | |
209 blink::WebString value_str; | |
210 bool ret = mandatory ? | |
211 constraints.getMandatoryConstraintValue(name, value_str) : | |
212 constraints.getOptionalConstraintValue(name, value_str); | |
213 if (ret) | |
214 base::StringToInt(value_str.utf8(), value); | |
215 return ret; | |
216 } | |
217 | |
218 // Retrieve the desired max width and height from |constraints|. | 207 // Retrieve the desired max width and height from |constraints|. |
219 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints, | 208 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints, |
220 int* desired_width, int* desired_height) { | 209 int* desired_width, int* desired_height) { |
221 bool mandatory = GetConstraintValue(constraints, true, | 210 GetConstraintValue(constraints, MediaStreamVideoSource::kMaxWidth, |
222 MediaStreamVideoSource::kMaxWidth, | |
223 desired_width); | |
224 mandatory |= GetConstraintValue(constraints, true, | |
225 MediaStreamVideoSource::kMaxHeight, | |
226 desired_height); | |
227 if (mandatory) | |
228 return; | |
229 | |
230 GetConstraintValue(constraints, false, MediaStreamVideoSource::kMaxWidth, | |
231 desired_width); | 211 desired_width); |
232 GetConstraintValue(constraints, false, MediaStreamVideoSource::kMaxHeight, | 212 GetConstraintValue(constraints, MediaStreamVideoSource::kMaxHeight, |
perkj_chrome
2014/04/14 12:15:19
this is an unwanted behaviour change.
Ie- if wit
no longer working on chromium
2014/04/14 14:40:50
I changed it back and added a comment to explain.
| |
233 desired_height); | 213 desired_height); |
234 } | 214 } |
235 | 215 |
236 const media::VideoCaptureFormat& GetBestFormatBasedOnArea( | 216 const media::VideoCaptureFormat& GetBestFormatBasedOnArea( |
237 const media::VideoCaptureFormats& formats, | 217 const media::VideoCaptureFormats& formats, |
238 int area) { | 218 int area) { |
239 media::VideoCaptureFormats::const_iterator it = formats.begin(); | 219 media::VideoCaptureFormats::const_iterator it = formats.begin(); |
240 media::VideoCaptureFormats::const_iterator best_it = formats.begin(); | 220 media::VideoCaptureFormats::const_iterator best_it = formats.begin(); |
241 int best_diff = std::numeric_limits<int>::max(); | 221 int best_diff = std::numeric_limits<int>::max(); |
242 for (; it != formats.end(); ++it) { | 222 for (; it != formats.end(); ++it) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 tracks_.push_back(track); | 301 tracks_.push_back(track); |
322 | 302 |
323 requested_constraints_.push_back( | 303 requested_constraints_.push_back( |
324 RequestedConstraints(constraints, callback)); | 304 RequestedConstraints(constraints, callback)); |
325 | 305 |
326 switch (state_) { | 306 switch (state_) { |
327 case NEW: { | 307 case NEW: { |
328 // Tab capture and Screen capture needs the maximum requested height | 308 // Tab capture and Screen capture needs the maximum requested height |
329 // and width to decide on the resolution. | 309 // and width to decide on the resolution. |
330 int max_requested_width = 0; | 310 int max_requested_width = 0; |
331 GetConstraintValue(constraints, true, kMaxWidth, &max_requested_width); | 311 GetMandatoryConstraintValue(constraints, kMaxWidth, &max_requested_width); |
332 | 312 |
333 int max_requested_height = 0; | 313 int max_requested_height = 0; |
334 GetConstraintValue(constraints, true, kMaxHeight, &max_requested_height); | 314 GetMandatoryConstraintValue(constraints, kMaxHeight, |
315 &max_requested_height); | |
335 | 316 |
336 state_ = RETRIEVING_CAPABILITIES; | 317 state_ = RETRIEVING_CAPABILITIES; |
337 GetCurrentSupportedFormats(max_requested_width, | 318 GetCurrentSupportedFormats(max_requested_width, |
338 max_requested_height); | 319 max_requested_height); |
339 | 320 |
340 break; | 321 break; |
341 } | 322 } |
342 case STARTING: | 323 case STARTING: |
343 case RETRIEVING_CAPABILITIES: { | 324 case RETRIEVING_CAPABILITIES: { |
344 // The |callback| will be triggered once the source has started or | 325 // The |callback| will be triggered once the source has started or |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 MediaStreamVideoSource::RequestedConstraints::RequestedConstraints( | 511 MediaStreamVideoSource::RequestedConstraints::RequestedConstraints( |
531 const blink::WebMediaConstraints& constraints, | 512 const blink::WebMediaConstraints& constraints, |
532 const ConstraintsCallback& callback) | 513 const ConstraintsCallback& callback) |
533 : constraints(constraints), callback(callback) { | 514 : constraints(constraints), callback(callback) { |
534 } | 515 } |
535 | 516 |
536 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { | 517 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { |
537 } | 518 } |
538 | 519 |
539 } // namespace content | 520 } // namespace content |
OLD | NEW |