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

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

Issue 2790823002: Spec compliant video constraints for getUserMedia behind flag. (Closed)
Patch Set: rebase Created 3 years, 8 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_constraints_util.h" 5 #include "content/renderer/media/media_stream_constraints_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/renderer/media/media_stream_constraints_util_sets.h" 12 #include "content/renderer/media/media_stream_constraints_util_sets.h"
13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
14 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 namespace { 18 namespace {
19 19
20 template <typename P, typename T> 20 template <typename P, typename T>
21 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints, 21 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints,
22 P picker, 22 P picker,
23 T* value) { 23 T* value) {
24 DCHECK(!constraints.isNull()); 24 if (constraints.isNull())
25 return false;
26
25 const auto& the_field = constraints.basic().*picker; 27 const auto& the_field = constraints.basic().*picker;
26 if (the_field.hasExact()) { 28 if (the_field.hasExact()) {
27 *value = the_field.exact(); 29 *value = the_field.exact();
28 return true; 30 return true;
29 } 31 }
30 for (const auto& advanced_constraint : constraints.advanced()) { 32 for (const auto& advanced_constraint : constraints.advanced()) {
31 const auto& the_field = advanced_constraint.*picker; 33 const auto& the_field = advanced_constraint.*picker;
32 if (the_field.hasExact()) { 34 if (the_field.hasExact()) {
33 *value = the_field.exact(); 35 *value = the_field.exact();
34 return true; 36 return true;
35 } 37 }
36 } 38 }
37 return false; 39 return false;
38 } 40 }
39 41
40 template <typename P, typename T> 42 template <typename P, typename T>
41 bool ScanConstraintsForMaxValue(const blink::WebMediaConstraints& constraints, 43 bool ScanConstraintsForMaxValue(const blink::WebMediaConstraints& constraints,
42 P picker, 44 P picker,
43 T* value) { 45 T* value) {
44 DCHECK(!constraints.isNull()); 46 if (constraints.isNull())
47 return false;
48
45 const auto& the_field = constraints.basic().*picker; 49 const auto& the_field = constraints.basic().*picker;
46 if (the_field.hasMax()) { 50 if (the_field.hasMax()) {
47 *value = the_field.max(); 51 *value = the_field.max();
48 return true; 52 return true;
49 } 53 }
50 if (the_field.hasExact()) { 54 if (the_field.hasExact()) {
51 *value = the_field.exact(); 55 *value = the_field.exact();
52 return true; 56 return true;
53 } 57 }
54 for (const auto& advanced_constraint : constraints.advanced()) { 58 for (const auto& advanced_constraint : constraints.advanced()) {
55 const auto& the_field = advanced_constraint.*picker; 59 const auto& the_field = advanced_constraint.*picker;
56 if (the_field.hasMax()) { 60 if (the_field.hasMax()) {
57 *value = the_field.max(); 61 *value = the_field.max();
58 return true; 62 return true;
59 } 63 }
60 if (the_field.hasExact()) { 64 if (the_field.hasExact()) {
61 *value = the_field.exact(); 65 *value = the_field.exact();
62 return true; 66 return true;
63 } 67 }
64 } 68 }
65 return false; 69 return false;
66 } 70 }
67 71
68 template <typename P, typename T> 72 template <typename P, typename T>
69 bool ScanConstraintsForMinValue(const blink::WebMediaConstraints& constraints, 73 bool ScanConstraintsForMinValue(const blink::WebMediaConstraints& constraints,
70 P picker, 74 P picker,
71 T* value) { 75 T* value) {
72 DCHECK(!constraints.isNull()); 76 if (constraints.isNull())
77 return false;
78
73 const auto& the_field = constraints.basic().*picker; 79 const auto& the_field = constraints.basic().*picker;
74 if (the_field.hasMin()) { 80 if (the_field.hasMin()) {
75 *value = the_field.min(); 81 *value = the_field.min();
76 return true; 82 return true;
77 } 83 }
78 if (the_field.hasExact()) { 84 if (the_field.hasExact()) {
79 *value = the_field.exact(); 85 *value = the_field.exact();
80 return true; 86 return true;
81 } 87 }
82 for (const auto& advanced_constraint : constraints.advanced()) { 88 for (const auto& advanced_constraint : constraints.advanced()) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // adjustment. 236 // adjustment.
231 if (track_max_frame_rate >= source_format.frame_rate) 237 if (track_max_frame_rate >= source_format.frame_rate)
232 track_max_frame_rate = 0.0; 238 track_max_frame_rate = 0.0;
233 239
234 return VideoTrackAdapterSettings( 240 return VideoTrackAdapterSettings(
235 track_max_width, track_max_height, track_min_aspect_ratio, 241 track_max_width, track_max_height, track_min_aspect_ratio,
236 track_max_aspect_ratio, track_max_frame_rate); 242 track_max_aspect_ratio, track_max_frame_rate);
237 } 243 }
238 244
239 } // namespace content 245 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_center.cc ('k') | content/renderer/media/media_stream_video_capturer_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698