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

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

Issue 1224623014: Refactor ParseArrayGeometry to use standard Chromium facilities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CONTEXT_EXPORT on declaration... Created 5 years, 4 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_audio_processor_options.cc
diff --git a/content/renderer/media/media_stream_audio_processor_options.cc b/content/renderer/media/media_stream_audio_processor_options.cc
index b48b100c921ba97ee4e5de15201ae8dd905af40d..1f875f9525e0d89317c614bd20c6ec6dd659cbae 100644
--- a/content/renderer/media/media_stream_audio_processor_options.cc
+++ b/content/renderer/media/media_stream_audio_processor_options.cc
@@ -10,6 +10,8 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/common/media/media_stream_options.h"
#include "content/renderer/media/media_stream_constraints_util.h"
@@ -389,4 +391,36 @@ void GetAecStats(webrtc::EchoCancellation* echo_cancellation,
}
}
+CONTENT_EXPORT std::vector<webrtc::Point> ParseArrayGeometry(
+ const std::string& geometry_string) {
+ const auto& tokens =
+ base::SplitString(geometry_string, base::kWhitespaceASCII,
+ base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ std::vector<webrtc::Point> geometry;
+ if (tokens.size() < 3 || tokens.size() % 3 != 0) {
+ LOG(ERROR) << "Malformed geometry string: " << geometry_string;
+ return geometry;
+ }
+
+ std::vector<float> float_tokens;
+ float_tokens.reserve(tokens.size());
+ for (const auto& token : tokens) {
+ double float_token;
+ if (!base::StringToDouble(token, &float_token)) {
+ LOG(ERROR) << "Unable to convert token=" << token
+ << " to double from geometry string: " << geometry_string;
+ return geometry;
+ }
+ float_tokens.push_back(float_token);
+ }
+
+ geometry.reserve(float_tokens.size() / 3);
+ for (size_t i = 0; i < float_tokens.size(); i += 3) {
+ geometry.push_back(webrtc::Point(float_tokens[i + 0], float_tokens[i + 1],
+ float_tokens[i + 2]));
+ }
+
+ return geometry;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698