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

Unified Diff: content/renderer/media/media_stream_constraints_util.cc

Issue 227743004: Added a kEchoCancellation constraint to turn off the audio processing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: addressed Tommi's comments. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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..de1856e28ecee52ab715ed6bd9f667abb348d2f4
--- /dev/null
+++ b/content/renderer/media/media_stream_constraints_util.cc
@@ -0,0 +1,107 @@
+// 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 "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 ConvertStringToBoolean(const std::string& string, bool* value) {
+ static const char kValueTrue[] = "true";
+ static const char kValueFalse[] = "false";
+
+ *value = (string == kValueTrue);
+ return *value || (string == kValueFalse);
+}
+
+} // namespace
+
+bool GetConstraintValueAsBoolean(const blink::WebMediaConstraints& constraints,
+ const std::string& key,
+ bool* value) {
+ return GetMandatoryConstraintValueAsBoolean(constraints, key, value) ||
+ GetOptionalConstraintValueAsBoolean(constraints, key, value);
+}
+
+bool GetConstraintValueAsInteger(const blink::WebMediaConstraints& constraints,
+ const std::string& key,
+ int* value) {
+ return GetMandatoryConstraintValueAsInteger(constraints, key, value) ||
+ GetOptionalConstraintValueAsInteger(constraints, key, value);
+}
+
+bool GetConstraintValueAsString(const blink::WebMediaConstraints& constraints,
+ const std::string& key,
+ std::string* value) {
+ blink::WebString value_str;
+ base::string16 key_16 = base::UTF8ToUTF16(key);
+ if (!constraints.getMandatoryConstraintValue(key_16, value_str) &&
+ !constraints.getOptionalConstraintValue(key_16, value_str)) {
+ return false;
+ }
+
+ *value = value_str.utf8();
+ return true;
+}
+
+bool GetMandatoryConstraintValueAsBoolean(
+ 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 ConvertStringToBoolean(value_str.utf8(), value);
+}
+
+bool GetMandatoryConstraintValueAsInteger(
+ 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);
perkj_chrome 2014/05/08 13:42:24 Humm - you are aware that there is a difference be
no longer working on chromium 2014/05/12 14:39:09 Added a GetMandatoryConstraintValueAsBoolean(key)
+}
+
+bool GetOptionalConstraintValueAsBoolean(
+ 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 ConvertStringToBoolean(value_str.utf8(), value);
+}
+
+bool GetOptionalConstraintValueAsInteger(
+ 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);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698