Chromium Code Reviews| Index: webrtc/modules/audio_processing/test/conversational_speech/timing.cc |
| diff --git a/webrtc/modules/audio_processing/test/conversational_speech/timing.cc b/webrtc/modules/audio_processing/test/conversational_speech/timing.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..83c99047ac1c726c5931808fa1d9bee5f1350f57 |
| --- /dev/null |
| +++ b/webrtc/modules/audio_processing/test/conversational_speech/timing.cc |
| @@ -0,0 +1,89 @@ |
| +/* |
| + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" |
| + |
| +#include <fstream> |
| +#include <iostream> |
| +#include <utility> |
| + |
| +#include "webrtc/base/stringencode.h" |
| + |
| +namespace webrtc { |
| +namespace test { |
| +namespace conversational_speech { |
| + |
| +bool Timing::Turn::operator ==(const Turn &b) const { |
| + return b.speaker_name == speaker_name && |
| + b.audiotrack_file_name == audiotrack_file_name && |
| + b.offset == offset; |
| +} |
| + |
| +Timing::Timing() {} |
| + |
| +Timing::~Timing() { |
| + Clear(); |
|
kwiberg-webrtc
2017/03/16 14:10:08
Not necessary, right?
AleBzk
2017/03/20 14:25:28
Acknowledged.
|
| +} |
| + |
| +void Timing::Clear() { |
| + // TODO(alessiob): check if pointers to Turn instances must be explicitly |
| + // 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.
|
| + turns_.clear(); |
| +} |
| + |
| +void Timing::AppendTurn(std::unique_ptr<Timing::Turn> turn) { |
| + turns_.push_back(std::move(turn)); |
| +} |
| + |
| +void Timing::Load(const std::string& timing_filepath) { |
| + std::string line; |
| + |
| + // Line parser. |
| + auto parse_line_ = [&line]() { |
| + std::vector<std::string> fields; |
| + rtc::split(line, ' ', &fields); |
| + RTC_CHECK_EQ(fields.size(), 3); |
| + return std::unique_ptr<Timing::Turn>(new Turn( |
| + fields[0], fields[1], std::atol(fields[2].c_str()))); |
| + }; |
| + |
| + // Parse lines. |
| + std::ifstream infile(timing_filepath); |
| + while (std::getline(infile, line)) { |
| + if (line.empty()) |
| + continue; |
| + 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.
|
| + } |
| + infile.close(); |
| +} |
| + |
| +void Timing::Save(const std::string& timing_filepath) const { |
| + std::ofstream outfile(timing_filepath); |
| + // TODO(alessio): check if file open for writing. |
| + for (const auto& turn : turns_) { |
| + outfile << turn->speaker_name << " " << turn->audiotrack_file_name |
| + << " " << turn->offset << std::endl; |
| + } |
| + outfile.close(); |
| +} |
| + |
| +const std::vector<std::unique_ptr<Timing::Turn>>& Timing::turns() const { |
| + // TODO(alessiob): not sure if this is the best way to return, maybe we can |
| + // 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
|
| + return turns_; |
| +} |
| + |
| +std::size_t Timing::Size() const { |
| + return turns_.size(); |
| +} |
|
kwiberg-webrtc
2017/03/16 14:10:08
Is this necessary? Callers can do .turns().size().
AleBzk
2017/03/20 14:25:28
Removed
|
| + |
| +} // namespace conversational_speech |
| +} // namespace test |
| +} // namespace webrtc |