OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" | |
12 | |
13 #include <fstream> | |
14 #include <iostream> | |
15 #include <utility> | |
16 | |
17 #include "webrtc/base/stringencode.h" | |
18 | |
19 namespace webrtc { | |
20 namespace test { | |
21 namespace conversational_speech { | |
22 | |
23 bool Timing::Turn::operator ==(const Turn &b) const { | |
24 return b.speaker_name == speaker_name && | |
25 b.audiotrack_file_name == audiotrack_file_name && | |
26 b.offset == offset; | |
27 } | |
28 | |
29 Timing::Timing() {} | |
30 | |
31 Timing::~Timing() { | |
32 Clear(); | |
kwiberg-webrtc
2017/03/16 14:10:08
Not necessary, right?
AleBzk
2017/03/20 14:25:28
Acknowledged.
| |
33 } | |
34 | |
35 void Timing::Clear() { | |
36 // TODO(alessiob): check if pointers to Turn instances must be explicitly | |
37 // deleted (I assume not). | |
kwiberg-webrtc
2017/03/16 14:10:09
No, unique_ptr will delete the thing it owns---tha
AleBzk
2017/03/20 14:25:28
Acknowledged.
| |
38 turns_.clear(); | |
39 } | |
40 | |
41 void Timing::AppendTurn(std::unique_ptr<Timing::Turn> turn) { | |
42 turns_.push_back(std::move(turn)); | |
43 } | |
44 | |
45 void Timing::Load(const std::string& timing_filepath) { | |
46 std::string line; | |
47 | |
48 // Line parser. | |
49 auto parse_line_ = [&line]() { | |
50 std::vector<std::string> fields; | |
51 rtc::split(line, ' ', &fields); | |
52 RTC_CHECK_EQ(fields.size(), 3); | |
53 return std::unique_ptr<Timing::Turn>(new Turn( | |
54 fields[0], fields[1], std::atol(fields[2].c_str()))); | |
55 }; | |
56 | |
57 // Parse lines. | |
58 std::ifstream infile(timing_filepath); | |
59 while (std::getline(infile, line)) { | |
60 if (line.empty()) | |
61 continue; | |
62 AppendTurn(parse_line_()); | |
kwiberg-webrtc
2017/03/16 14:10:09
Pass line as an argument here, instead of capturin
AleBzk
2017/03/20 14:25:28
Done.
| |
63 } | |
64 infile.close(); | |
65 } | |
66 | |
67 void Timing::Save(const std::string& timing_filepath) const { | |
68 std::ofstream outfile(timing_filepath); | |
69 // TODO(alessio): check if file open for writing. | |
70 for (const auto& turn : turns_) { | |
71 outfile << turn->speaker_name << " " << turn->audiotrack_file_name | |
72 << " " << turn->offset << std::endl; | |
73 } | |
74 outfile.close(); | |
75 } | |
76 | |
77 const std::vector<std::unique_ptr<Timing::Turn>>& Timing::turns() const { | |
78 // TODO(alessiob): not sure if this is the best way to return, maybe we can | |
79 // return an iterator. | |
kwiberg-webrtc
2017/03/16 14:10:09
This is fine. You could also return an ArrayView<s
AleBzk
2017/03/20 14:25:28
I'm new with ArrayView, I guess you refer to the o
kwiberg-webrtc
2017/03/21 22:35:14
Yes. (I wrote it, so if you have questions or comp
| |
80 return turns_; | |
81 } | |
82 | |
83 std::size_t Timing::Size() const { | |
84 return turns_.size(); | |
85 } | |
kwiberg-webrtc
2017/03/16 14:10:08
Is this necessary? Callers can do .turns().size().
AleBzk
2017/03/20 14:25:28
Removed
| |
86 | |
87 } // namespace conversational_speech | |
88 } // namespace test | |
89 } // namespace webrtc | |
OLD | NEW |