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

Side by Side Diff: media/audio/point.cc

Issue 1907973003: media: Move audio_parameters and audio_point to media/base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
« no previous file with comments | « media/audio/point.h ('k') | media/audio/point_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/audio/point.h"
6
7 #include <stddef.h>
8
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h"
14
15 namespace media {
16
17 std::string PointsToString(const std::vector<Point>& points) {
18 std::string points_string;
19 if (!points.empty()) {
20 for (size_t i = 0; i < points.size() - 1; ++i) {
21 points_string.append(points[i].ToString());
22 points_string.append(", ");
23 }
24 points_string.append(points.back().ToString());
25 }
26 return points_string;
27 }
28
29 std::vector<Point> ParsePointsFromString(const std::string& points_string) {
30 std::vector<Point> points;
31 if (points_string.empty())
32 return points;
33
34 const auto& tokens =
35 base::SplitString(points_string, base::kWhitespaceASCII,
36 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
37 if (tokens.size() < 3 || tokens.size() % 3 != 0) {
38 LOG(ERROR) << "Malformed points string: " << points_string;
39 return points;
40 }
41
42 std::vector<float> float_tokens;
43 float_tokens.reserve(tokens.size());
44 for (const auto& token : tokens) {
45 double float_token;
46 if (!base::StringToDouble(token, &float_token)) {
47 LOG(ERROR) << "Unable to convert token=" << token
48 << " to double from points string: " << points_string;
49 return points;
50 }
51 float_tokens.push_back(float_token);
52 }
53
54 points.reserve(float_tokens.size() / 3);
55 for (size_t i = 0; i < float_tokens.size(); i += 3) {
56 points.push_back(
57 Point(float_tokens[i + 0], float_tokens[i + 1], float_tokens[i + 2]));
58 }
59
60 return points;
61 }
62
63 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/point.h ('k') | media/audio/point_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698