Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_unittest.cc

Issue 2747863003: Loosening the coupling between WebRTC and //third_party/protobuf (Closed)
Patch Set: Rebasing Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 <math.h> 11 #include <math.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <limits> 15 #include <limits>
16 #include <memory> 16 #include <memory>
17 #include <queue> 17 #include <queue>
18 18
19 #include "webrtc/base/arraysize.h" 19 #include "webrtc/base/arraysize.h"
20 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
21 #include "webrtc/base/gtest_prod_util.h" 21 #include "webrtc/base/gtest_prod_util.h"
22 #include "webrtc/base/ignore_wundef.h" 22 #include "webrtc/base/ignore_wundef.h"
23 #include "webrtc/base/protobuf_utils.h"
23 #include "webrtc/common_audio/include/audio_util.h" 24 #include "webrtc/common_audio/include/audio_util.h"
24 #include "webrtc/common_audio/resampler/include/push_resampler.h" 25 #include "webrtc/common_audio/resampler/include/push_resampler.h"
25 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" 26 #include "webrtc/common_audio/resampler/push_sinc_resampler.h"
26 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 27 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
27 #include "webrtc/modules/audio_processing/audio_processing_impl.h" 28 #include "webrtc/modules/audio_processing/audio_processing_impl.h"
28 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h " 29 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h "
29 #include "webrtc/modules/audio_processing/common.h" 30 #include "webrtc/modules/audio_processing/common.h"
30 #include "webrtc/modules/audio_processing/include/audio_processing.h" 31 #include "webrtc/modules/audio_processing/include/audio_processing.h"
31 #include "webrtc/modules/audio_processing/level_controller/level_controller_cons tants.h" 32 #include "webrtc/modules/audio_processing/level_controller/level_controller_cons tants.h"
32 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" 33 #include "webrtc/modules/audio_processing/test/protobuf_utils.h"
(...skipping 18 matching lines...) Expand all
51 // TODO(ekmeyerson): Switch to using StreamConfig and ProcessingConfig where 52 // TODO(ekmeyerson): Switch to using StreamConfig and ProcessingConfig where
52 // applicable. 53 // applicable.
53 54
54 // TODO(bjornv): This is not feasible until the functionality has been 55 // TODO(bjornv): This is not feasible until the functionality has been
55 // re-implemented; see comment at the bottom of this file. For now, the user has 56 // re-implemented; see comment at the bottom of this file. For now, the user has
56 // to hard code the |write_ref_data| value. 57 // to hard code the |write_ref_data| value.
57 // When false, this will compare the output data with the results stored to 58 // When false, this will compare the output data with the results stored to
58 // file. This is the typical case. When the file should be updated, it can 59 // file. This is the typical case. When the file should be updated, it can
59 // be set to true with the command-line switch --write_ref_data. 60 // be set to true with the command-line switch --write_ref_data.
60 bool write_ref_data = false; 61 bool write_ref_data = false;
61 const google::protobuf::int32 kChannels[] = {1, 2}; 62 const int32_t kChannels[] = {1, 2};
62 const int kSampleRates[] = {8000, 16000, 32000, 48000}; 63 const int kSampleRates[] = {8000, 16000, 32000, 48000};
63 64
64 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE) 65 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
65 // Android doesn't support 48kHz. 66 // Android doesn't support 48kHz.
66 const int kProcessSampleRates[] = {8000, 16000, 32000}; 67 const int kProcessSampleRates[] = {8000, 16000, 32000};
67 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) 68 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
68 const int kProcessSampleRates[] = {8000, 16000, 32000, 48000}; 69 const int kProcessSampleRates[] = {8000, 16000, 32000, 48000};
69 #endif 70 #endif
70 71
71 enum StreamDirection { kForward = 0, kReverse }; 72 enum StreamDirection { kForward = 0, kReverse };
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 void WriteStatsMessage(const AudioProcessing::Statistic& output, 224 void WriteStatsMessage(const AudioProcessing::Statistic& output,
224 audioproc::Test::Statistic* msg) { 225 audioproc::Test::Statistic* msg) {
225 msg->set_instant(output.instant); 226 msg->set_instant(output.instant);
226 msg->set_average(output.average); 227 msg->set_average(output.average);
227 msg->set_maximum(output.maximum); 228 msg->set_maximum(output.maximum);
228 msg->set_minimum(output.minimum); 229 msg->set_minimum(output.minimum);
229 } 230 }
230 #endif 231 #endif
231 232
232 void OpenFileAndWriteMessage(const std::string filename, 233 void OpenFileAndWriteMessage(const std::string filename,
233 const ::google::protobuf::MessageLite& msg) { 234 const MessageLite& msg) {
234 FILE* file = fopen(filename.c_str(), "wb"); 235 FILE* file = fopen(filename.c_str(), "wb");
235 ASSERT_TRUE(file != NULL); 236 ASSERT_TRUE(file != NULL);
236 237
237 int32_t size = msg.ByteSize(); 238 int32_t size = msg.ByteSize();
238 ASSERT_GT(size, 0); 239 ASSERT_GT(size, 0);
239 std::unique_ptr<uint8_t[]> array(new uint8_t[size]); 240 std::unique_ptr<uint8_t[]> array(new uint8_t[size]);
240 ASSERT_TRUE(msg.SerializeToArray(array.get(), size)); 241 ASSERT_TRUE(msg.SerializeToArray(array.get(), size));
241 242
242 ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file)); 243 ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file));
243 ASSERT_EQ(static_cast<size_t>(size), 244 ASSERT_EQ(static_cast<size_t>(size),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (temp_filenames[filename].empty()) 293 if (temp_filenames[filename].empty())
293 temp_filenames[filename] = test::TempFilename(test::OutputPath(), filename); 294 temp_filenames[filename] = test::TempFilename(test::OutputPath(), filename);
294 return temp_filenames[filename]; 295 return temp_filenames[filename];
295 } 296 }
296 297
297 void ClearTempFiles() { 298 void ClearTempFiles() {
298 for (auto& kv : temp_filenames) 299 for (auto& kv : temp_filenames)
299 remove(kv.second.c_str()); 300 remove(kv.second.c_str());
300 } 301 }
301 302
302 void OpenFileAndReadMessage(std::string filename, 303 void OpenFileAndReadMessage(std::string filename, MessageLite* msg) {
303 ::google::protobuf::MessageLite* msg) {
304 FILE* file = fopen(filename.c_str(), "rb"); 304 FILE* file = fopen(filename.c_str(), "rb");
305 ASSERT_TRUE(file != NULL); 305 ASSERT_TRUE(file != NULL);
306 ReadMessageFromFile(file, msg); 306 ReadMessageFromFile(file, msg);
307 fclose(file); 307 fclose(file);
308 } 308 }
309 309
310 // Reads a 10 ms chunk of int16 interleaved audio from the given (assumed 310 // Reads a 10 ms chunk of int16 interleaved audio from the given (assumed
311 // stereo) file, converts to deinterleaved float (optionally downmixing) and 311 // stereo) file, converts to deinterleaved float (optionally downmixing) and
312 // returns the result in |cb|. Returns false if the file ended (or on error) and 312 // returns the result in |cb|. Returns false if the file ended (or on error) and
313 // true otherwise. 313 // true otherwise.
(...skipping 2563 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 // TODO(peah): Remove the testing for 2877 // TODO(peah): Remove the testing for
2878 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ 2878 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2879 // is instead used to activate the level controller. 2879 // is instead used to activate the level controller.
2880 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); 2880 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2881 EXPECT_NEAR(kTargetLcPeakLeveldBFS, 2881 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2882 apm->config_.level_controller.initial_peak_level_dbfs, 2882 apm->config_.level_controller.initial_peak_level_dbfs,
2883 std::numeric_limits<float>::epsilon()); 2883 std::numeric_limits<float>::epsilon());
2884 } 2884 }
2885 2885
2886 } // namespace webrtc 2886 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/audio_processing_impl.cc ('k') | webrtc/modules/audio_processing/test/protobuf_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698