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/array_view.h" | |
18 #include "webrtc/base/stringencode.h" | |
19 | |
20 namespace webrtc { | |
21 namespace test { | |
22 namespace conversational_speech { | |
23 | |
24 bool Timing::Turn::operator ==(const Turn &b) const { | |
25 return b.speaker_name == speaker_name && | |
26 b.audiotrack_file_name == audiotrack_file_name && | |
27 b.offset == offset; | |
28 } | |
29 | |
30 Timing::Timing() {} | |
31 | |
32 Timing::Timing(std::initializer_list<Timing::Turn> il) : Timing() { | |
33 for (auto turn : il) { | |
34 AppendTurn(turn); | |
35 } | |
kwiberg-webrtc
2017/03/21 22:35:15
Can't you pass the initializer_list directly to tu
AleBzk
2017/03/22 10:07:22
Acknowledged.
| |
36 } | |
37 | |
38 Timing::~Timing() {} | |
39 | |
40 void Timing::Clear() { | |
41 // TODO(alessiob): check if pointers to Turn instances must be explicitly | |
42 // deleted (I assume not). | |
kwiberg-webrtc
2017/03/21 22:35:15
Comment no longer applicable.
AleBzk
2017/03/22 10:07:22
Acknowledged.
| |
43 turns_.clear(); | |
44 } | |
45 | |
46 void Timing::AppendTurn(Timing::Turn turn) { | |
47 turns_.push_back(turn); | |
48 } | |
49 | |
50 void Timing::Load(const std::string& timing_filepath) { | |
51 // Line parser. | |
52 auto parse_line_ = [](const std::string& line) { | |
53 std::vector<std::string> fields; | |
54 rtc::split(line, ' ', &fields); | |
55 RTC_CHECK_EQ(fields.size(), 3); | |
56 return Timing::Turn(fields[0], fields[1], std::atol(fields[2].c_str())); | |
57 }; | |
58 | |
59 // Parse lines. | |
60 std::string line; | |
61 std::ifstream infile(timing_filepath); | |
62 while (std::getline(infile, line)) { | |
63 if (line.empty()) | |
64 continue; | |
65 AppendTurn(parse_line_(line)); | |
66 } | |
67 infile.close(); | |
68 } | |
69 | |
70 void Timing::Save(const std::string& timing_filepath) const { | |
71 std::ofstream outfile(timing_filepath); | |
72 // TODO(alessio): check if file open for writing. | |
73 for (const auto& turn : turns_) { | |
74 outfile << turn.speaker_name << " " << turn.audiotrack_file_name | |
75 << " " << turn.offset << std::endl; | |
76 } | |
77 outfile.close(); | |
78 } | |
79 | |
80 rtc::ArrayView<const Timing::Turn> Timing::turns() const { | |
81 return turns_; | |
82 } | |
83 | |
84 } // namespace conversational_speech | |
85 } // namespace test | |
86 } // namespace webrtc | |
OLD | NEW |