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..2dd21dadf1895d77e2d99394bbdd97fabd2841cc 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,60 @@ |
#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, |
+ const std::map<std::string, const Params>& params) |
+ : default_params_(default_params), |
+ audiotrack_names_params_(params) { |
+ ON_CALL(*this, Create(_)).WillByDefault(Invoke( |
+ this, &MockWavReaderFactory::CreateMock)); |
+} |
+ |
+MockWavReaderFactory::MockWavReaderFactory(const Params& default_params) |
+ : MockWavReaderFactory(default_params, |
+ std::map<std::string, const Params>{}) {} |
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); |
+ const auto it = audiotrack_names_params_.find( |
+ audiotrack_file_path.filename()); |
+ |
+ // 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 |