Chromium Code Reviews| Index: content/renderer/media/media_stream_constraints_util.cc |
| diff --git a/content/renderer/media/media_stream_constraints_util.cc b/content/renderer/media/media_stream_constraints_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..718cb484c8f41abd1e75119d06ab460a3994d164 |
| --- /dev/null |
| +++ b/content/renderer/media/media_stream_constraints_util.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/media/media_stream_constraints_util.h" |
| + |
| +#include <sstream> |
| + |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| +#include "third_party/WebKit/public/platform/WebString.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +// Convert a string ("true", "false") to a boolean. |
| +bool FromString(const std::string& string, bool* value) { |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
nit: FromString doesn't quite describe what the fu
no longer working on chromium
2014/05/02 12:24:02
changed it to ConvertStringToBoolean, is it ok?
tommi (sloooow) - chröme
2014/05/03 10:26:28
Yes thanks. that's very clear.
|
| + std::istringstream iss(string); |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
using istringstream here is complete overkill!
jus
no longer working on chromium
2014/05/02 12:24:02
That is what libjingle is using. I discussed this
tommi (sloooow) - chröme
2014/05/03 10:26:28
Well, imho istringstream here is overkill and if y
no longer working on chromium
2014/05/05 12:55:56
I agree with you, done with changing it to using s
|
| + iss >> std::boolalpha >> *value; |
| + return !iss.fail(); |
| +} |
| + |
| +} // namespace |
| + |
| +bool GetConstraintValue(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + bool* value) { |
| + return GetMandatoryConstraintValue(constraints, key, value) || |
| + GetOptionalConstraintValue(constraints, key, value); |
| +} |
| + |
| +bool GetConstraintValue(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + int* value) { |
| + return GetMandatoryConstraintValue(constraints, key, value) || |
| + GetOptionalConstraintValue(constraints, key, value); |
| +} |
| + |
| +bool GetConstraintValue(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + std::string* value) { |
| + blink::WebString value_str; |
| + if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), |
| + value_str) && |
| + !constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), |
| + value_str)) { |
| + return false; |
| + } |
| + |
| + *value = value_str.utf8(); |
| + return true; |
| +} |
| + |
| +bool GetMandatoryConstraintValue(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + bool* value) { |
| + blink::WebString value_str; |
| + if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), |
| + value_str)) { |
| + return false; |
| + } |
| + |
| + return FromString(value_str.utf8(), value); |
| +} |
| + |
| +bool GetMandatoryConstraintValue(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + int* value) { |
| + blink::WebString value_str; |
| + if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), |
| + value_str)) { |
| + return false; |
| + } |
| + |
| + return base::StringToInt(value_str.utf8(), value); |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
StringToInt?
no longer working on chromium
2014/05/02 12:24:02
Yes, I think I have already answered this question
|
| +} |
| + |
| +bool GetOptionalConstraintValue(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + bool* value) { |
| + blink::WebString value_str; |
| + if (!constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), |
| + value_str)) { |
| + return false; |
| + } |
| + |
| + return FromString(value_str.utf8(), value); |
| +} |
| + |
| +bool GetOptionalConstraintValue(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + int* value) { |
| + blink::WebString value_str; |
| + if (!constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), |
| + value_str)) { |
| + return false; |
| + } |
| + |
| + return base::StringToInt(value_str.utf8(), value); |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
StringToInt?
no longer working on chromium
2014/05/02 12:24:02
Ditto.
|
| +} |
| + |
| +} // namespace content |