OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavrea
der_factory.h" | 11 #include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavrea
der_factory.h" |
12 | 12 |
| 13 #include "webrtc/base/logging.h" |
| 14 #include "webrtc/base/pathutils.h" |
| 15 #include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavrea
der.h" |
| 16 #include "webrtc/test/gmock.h" |
| 17 |
13 namespace webrtc { | 18 namespace webrtc { |
14 namespace test { | 19 namespace test { |
15 namespace conversational_speech { | 20 namespace conversational_speech { |
16 | 21 |
17 MockWavReaderFactory::MockWavReaderFactory() = default; | 22 using testing::_; |
| 23 using testing::Invoke; |
| 24 |
| 25 MockWavReaderFactory::MockWavReaderFactory( |
| 26 const Params& default_params, |
| 27 const std::map<std::string, const Params>& params) |
| 28 : default_params_(default_params), |
| 29 audiotrack_names_params_(params) { |
| 30 ON_CALL(*this, Create(_)).WillByDefault(Invoke( |
| 31 this, &MockWavReaderFactory::CreateMock)); |
| 32 } |
| 33 |
| 34 MockWavReaderFactory::MockWavReaderFactory(const Params& default_params) |
| 35 : MockWavReaderFactory(default_params, |
| 36 std::map<std::string, const Params>{}) {} |
18 | 37 |
19 MockWavReaderFactory::~MockWavReaderFactory() = default; | 38 MockWavReaderFactory::~MockWavReaderFactory() = default; |
20 | 39 |
| 40 std::unique_ptr<WavReaderInterface> MockWavReaderFactory::CreateMock( |
| 41 const std::string& filepath) { |
| 42 // Search the parameters corresponding to filepath. |
| 43 const rtc::Pathname audiotrack_file_path(filepath); |
| 44 const auto it = audiotrack_names_params_.find( |
| 45 audiotrack_file_path.filename()); |
| 46 |
| 47 // If not found, use default parameters. |
| 48 if (it == audiotrack_names_params_.end()) { |
| 49 LOG(LS_VERBOSE) << "using default parameters for " << filepath; |
| 50 return std::unique_ptr<WavReaderInterface>( |
| 51 new MockWavReader(default_params_.sample_rate, |
| 52 default_params_.num_channels, |
| 53 default_params_.num_samples)); |
| 54 } |
| 55 |
| 56 // Found, use the audiotrack-specific parameters. |
| 57 LOG(LS_VERBOSE) << "using ad-hoc parameters for " << filepath; |
| 58 LOG(LS_VERBOSE) << "sample_rate " << it->second.sample_rate; |
| 59 LOG(LS_VERBOSE) << "num_channels " << it->second.num_channels; |
| 60 LOG(LS_VERBOSE) << "num_samples " << it->second.num_samples; |
| 61 return std::unique_ptr<WavReaderInterface>( |
| 62 new MockWavReader(it->second.sample_rate, |
| 63 it->second.num_channels, |
| 64 it->second.num_samples)); |
| 65 } |
| 66 |
21 } // namespace conversational_speech | 67 } // namespace conversational_speech |
22 } // namespace test | 68 } // namespace test |
23 } // namespace webrtc | 69 } // namespace webrtc |
OLD | NEW |