Chromium Code Reviews| 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(const Params& default_params) | |
| 26 : default_params_(default_params) { | |
| 27 ON_CALL(*this, Create(_)).WillByDefault(Invoke( | |
| 28 this, &MockWavReaderFactory::CreateMock)); | |
| 29 } | |
| 30 | |
| 31 MockWavReaderFactory::MockWavReaderFactory( | |
| 32 const Params& default_params, | |
| 33 const std::map<std::string, const Params>& params) | |
| 34 : MockWavReaderFactory(default_params) { | |
| 35 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
| |
| 36 } | |
| 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 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.
| |
| 45 | |
| 46 // If not found, use default parameters. | |
| 47 if (it == audiotrack_names_params_.end()) { | |
| 48 LOG(LS_VERBOSE) << "using default parameters for " << filepath; | |
| 49 return std::unique_ptr<WavReaderInterface>( | |
| 50 new MockWavReader(default_params_.sample_rate, | |
| 51 default_params_.num_channels, | |
| 52 default_params_.num_samples)); | |
| 53 } | |
| 54 | |
| 55 // Found, use the audiotrack-specific parameters. | |
| 56 LOG(LS_VERBOSE) << "using ad-hoc parameters for " << filepath; | |
| 57 LOG(LS_VERBOSE) << "sample_rate " << it->second.sample_rate; | |
| 58 LOG(LS_VERBOSE) << "num_channels " << it->second.num_channels; | |
| 59 LOG(LS_VERBOSE) << "num_samples " << it->second.num_samples; | |
| 60 return std::unique_ptr<WavReaderInterface>( | |
| 61 new MockWavReader(it->second.sample_rate, | |
| 62 it->second.num_channels, | |
| 63 it->second.num_samples)); | |
| 64 } | |
| 65 | |
| 21 } // namespace conversational_speech | 66 } // namespace conversational_speech |
| 22 } // namespace test | 67 } // namespace test |
| 23 } // namespace webrtc | 68 } // namespace webrtc |
| OLD | NEW |