Chromium Code Reviews| Index: webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader_factory.cc |
| diff --git a/webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader_factory.cc b/webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader_factory.cc |
| index 1097639527b92891f36b8ab3618a3594118c8e1e..b8b700c6056d3244ac8e9d69a5c39d1b90e59661 100644 |
| --- a/webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader_factory.cc |
| +++ b/webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader_factory.cc |
| @@ -10,14 +10,59 @@ |
| #include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader_factory.h" |
| +#include "webrtc/base/logging.h" |
| +#include "webrtc/base/pathutils.h" |
| +#include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavreader.h" |
| +#include "webrtc/test/gmock.h" |
| + |
| namespace webrtc { |
| namespace test { |
| namespace conversational_speech { |
| -MockWavReaderFactory::MockWavReaderFactory() = default; |
| +using testing::_; |
| +using testing::Invoke; |
| + |
| +MockWavReaderFactory::MockWavReaderFactory(const Params& default_params) |
| + : default_params_(default_params) { |
| + ON_CALL(*this, Create(_)).WillByDefault(Invoke( |
| + this, &MockWavReaderFactory::CreateMock)); |
| +} |
| + |
| +MockWavReaderFactory::MockWavReaderFactory( |
| + const Params& default_params, |
| + const std::map<std::string, const Params>& params) |
| + : MockWavReaderFactory(default_params) { |
| + audiotrack_names_params_.insert(params.begin(), params.end()); |
|
hlundin-webrtc
2017/04/06 08:10:04
You should be able to use the copy constructor, an
AleBzk
2017/04/06 16:42:42
If I'm correct, we have two options:
1) instead of
hlundin-webrtc
2017/04/07 10:24:09
I wonder if we are talking about different things.
AleBzk
2017/04/07 11:37:06
Yes, then I understood correctly your point.
I alr
hlundin-webrtc
2017/04/07 11:54:18
Do like this:
Let the member be a mutable variable
|
| +} |
| MockWavReaderFactory::~MockWavReaderFactory() = default; |
| +std::unique_ptr<WavReaderInterface> MockWavReaderFactory::CreateMock( |
| + const std::string& filepath) { |
| + // Search the parameters corresponding to filepath. |
| + const rtc::Pathname audiotrack_file_path(filepath); |
| + auto it = audiotrack_names_params_.find(audiotrack_file_path.filename()); |
|
hlundin-webrtc
2017/04/06 08:10:04
const auto it?
AleBzk
2017/04/06 16:42:42
Done.
|
| + |
| + // If not found, use default parameters. |
| + if (it == audiotrack_names_params_.end()) { |
| + LOG(LS_VERBOSE) << "using default parameters for " << filepath; |
| + return std::unique_ptr<WavReaderInterface>( |
| + new MockWavReader(default_params_.sample_rate, |
| + default_params_.num_channels, |
| + default_params_.num_samples)); |
| + } |
| + |
| + // Found, use the audiotrack-specific parameters. |
| + LOG(LS_VERBOSE) << "using ad-hoc parameters for " << filepath; |
| + LOG(LS_VERBOSE) << "sample_rate " << it->second.sample_rate; |
| + LOG(LS_VERBOSE) << "num_channels " << it->second.num_channels; |
| + LOG(LS_VERBOSE) << "num_samples " << it->second.num_samples; |
| + return std::unique_ptr<WavReaderInterface>( |
| + new MockWavReader(it->second.sample_rate, |
| + it->second.num_channels, |
| + it->second.num_samples)); |
| +} |
| + |
| } // namespace conversational_speech |
| } // namespace test |
| } // namespace webrtc |