| 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_constraints_util.h" | 5 #include "content/renderer/media/media_stream_constraints_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 9 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 10 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 template <typename P, typename T> | 16 template <typename P, typename T> |
| 17 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints, | 17 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints, |
| 18 P picker, | 18 P picker, |
| 19 T* value) { | 19 T* value) { |
| 20 DCHECK(!constraints.isNull()); |
| 20 const auto& the_field = constraints.basic().*picker; | 21 const auto& the_field = constraints.basic().*picker; |
| 21 if (the_field.hasExact()) { | 22 if (the_field.hasExact()) { |
| 22 *value = the_field.exact(); | 23 *value = the_field.exact(); |
| 23 return true; | 24 return true; |
| 24 } | 25 } |
| 25 for (const auto& advanced_constraint : constraints.advanced()) { | 26 for (const auto& advanced_constraint : constraints.advanced()) { |
| 26 const auto& the_field = advanced_constraint.*picker; | 27 const auto& the_field = advanced_constraint.*picker; |
| 27 if (the_field.hasExact()) { | 28 if (the_field.hasExact()) { |
| 28 *value = the_field.exact(); | 29 *value = the_field.exact(); |
| 29 return true; | 30 return true; |
| 30 } | 31 } |
| 31 } | 32 } |
| 32 return false; | 33 return false; |
| 33 } | 34 } |
| 34 | 35 |
| 35 template <typename P, typename T> | 36 template <typename P, typename T> |
| 36 bool ScanConstraintsForMaxValue(const blink::WebMediaConstraints& constraints, | 37 bool ScanConstraintsForMaxValue(const blink::WebMediaConstraints& constraints, |
| 37 P picker, | 38 P picker, |
| 38 T* value) { | 39 T* value) { |
| 40 DCHECK(!constraints.isNull()); |
| 39 const auto& the_field = constraints.basic().*picker; | 41 const auto& the_field = constraints.basic().*picker; |
| 40 if (the_field.hasMax()) { | 42 if (the_field.hasMax()) { |
| 41 *value = the_field.max(); | 43 *value = the_field.max(); |
| 42 return true; | 44 return true; |
| 43 } | 45 } |
| 44 if (the_field.hasExact()) { | 46 if (the_field.hasExact()) { |
| 45 *value = the_field.exact(); | 47 *value = the_field.exact(); |
| 46 return true; | 48 return true; |
| 47 } | 49 } |
| 48 for (const auto& advanced_constraint : constraints.advanced()) { | 50 for (const auto& advanced_constraint : constraints.advanced()) { |
| 49 const auto& the_field = advanced_constraint.*picker; | 51 const auto& the_field = advanced_constraint.*picker; |
| 50 if (the_field.hasMax()) { | 52 if (the_field.hasMax()) { |
| 51 *value = the_field.max(); | 53 *value = the_field.max(); |
| 52 return true; | 54 return true; |
| 53 } | 55 } |
| 54 if (the_field.hasExact()) { | 56 if (the_field.hasExact()) { |
| 55 *value = the_field.exact(); | 57 *value = the_field.exact(); |
| 56 return true; | 58 return true; |
| 57 } | 59 } |
| 58 } | 60 } |
| 59 return false; | 61 return false; |
| 60 } | 62 } |
| 61 | 63 |
| 62 template <typename P, typename T> | 64 template <typename P, typename T> |
| 63 bool ScanConstraintsForMinValue(const blink::WebMediaConstraints& constraints, | 65 bool ScanConstraintsForMinValue(const blink::WebMediaConstraints& constraints, |
| 64 P picker, | 66 P picker, |
| 65 T* value) { | 67 T* value) { |
| 68 DCHECK(!constraints.isNull()); |
| 66 const auto& the_field = constraints.basic().*picker; | 69 const auto& the_field = constraints.basic().*picker; |
| 67 if (the_field.hasMin()) { | 70 if (the_field.hasMin()) { |
| 68 *value = the_field.min(); | 71 *value = the_field.min(); |
| 69 return true; | 72 return true; |
| 70 } | 73 } |
| 71 if (the_field.hasExact()) { | 74 if (the_field.hasExact()) { |
| 72 *value = the_field.exact(); | 75 *value = the_field.exact(); |
| 73 return true; | 76 return true; |
| 74 } | 77 } |
| 75 for (const auto& advanced_constraint : constraints.advanced()) { | 78 for (const auto& advanced_constraint : constraints.advanced()) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const blink::WebMediaConstraints& constraints, | 156 const blink::WebMediaConstraints& constraints, |
| 154 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { | 157 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { |
| 155 bool value; | 158 bool value; |
| 156 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { | 159 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { |
| 157 return rtc::Optional<bool>(value); | 160 return rtc::Optional<bool>(value); |
| 158 } | 161 } |
| 159 return rtc::Optional<bool>(); | 162 return rtc::Optional<bool>(); |
| 160 } | 163 } |
| 161 | 164 |
| 162 } // namespace content | 165 } // namespace content |
| OLD | NEW |