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

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

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 msg->set_instant(output.instant); 225 msg->set_instant(output.instant);
226 msg->set_average(output.average); 226 msg->set_average(output.average);
227 msg->set_maximum(output.maximum); 227 msg->set_maximum(output.maximum);
228 msg->set_minimum(output.minimum); 228 msg->set_minimum(output.minimum);
229 } 229 }
230 #endif 230 #endif
231 231
232 void OpenFileAndWriteMessage(const std::string filename, 232 void OpenFileAndWriteMessage(const std::string filename,
233 const ::google::protobuf::MessageLite& msg) { 233 const ::google::protobuf::MessageLite& msg) {
234 FILE* file = fopen(filename.c_str(), "wb"); 234 FILE* file = fopen(filename.c_str(), "wb");
235 ASSERT_TRUE(file != NULL); 235 ASSERT_TRUE(file != nullptr);
236 236
237 int32_t size = msg.ByteSize(); 237 int32_t size = msg.ByteSize();
238 ASSERT_GT(size, 0); 238 ASSERT_GT(size, 0);
239 std::unique_ptr<uint8_t[]> array(new uint8_t[size]); 239 std::unique_ptr<uint8_t[]> array(new uint8_t[size]);
240 ASSERT_TRUE(msg.SerializeToArray(array.get(), size)); 240 ASSERT_TRUE(msg.SerializeToArray(array.get(), size));
241 241
242 ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file)); 242 ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file));
243 ASSERT_EQ(static_cast<size_t>(size), 243 ASSERT_EQ(static_cast<size_t>(size),
244 fwrite(array.get(), sizeof(array[0]), size, file)); 244 fwrite(array.get(), sizeof(array[0]), size, file));
245 fclose(file); 245 fclose(file);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 295 }
296 296
297 void ClearTempFiles() { 297 void ClearTempFiles() {
298 for (auto& kv : temp_filenames) 298 for (auto& kv : temp_filenames)
299 remove(kv.second.c_str()); 299 remove(kv.second.c_str());
300 } 300 }
301 301
302 void OpenFileAndReadMessage(std::string filename, 302 void OpenFileAndReadMessage(std::string filename,
303 ::google::protobuf::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 != nullptr);
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.
314 // 314 //
315 // |int_data| and |float_data| are just temporary space that must be 315 // |int_data| and |float_data| are just temporary space that must be
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 int output_sample_rate_hz_; 403 int output_sample_rate_hz_;
404 size_t num_output_channels_; 404 size_t num_output_channels_;
405 FILE* far_file_; 405 FILE* far_file_;
406 FILE* near_file_; 406 FILE* near_file_;
407 FILE* out_file_; 407 FILE* out_file_;
408 }; 408 };
409 409
410 ApmTest::ApmTest() 410 ApmTest::ApmTest()
411 : output_path_(test::OutputPath()), 411 : output_path_(test::OutputPath()),
412 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE) 412 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
413 ref_filename_(test::ResourcePath("audio_processing/output_data_fixed", 413 ref_filename_(
414 "pb")), 414 test::ResourcePath("audio_processing/output_data_fixed", "pb")),
415 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) 415 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
416 #if defined(WEBRTC_MAC) 416 #if defined(WEBRTC_MAC)
417 // A different file for Mac is needed because on this platform the AEC 417 // A different file for Mac is needed because on this platform the AEC
418 // constant |kFixedDelayMs| value is 20 and not 50 as it is on the rest. 418 // constant |kFixedDelayMs| value is 20 and not 50 as it is on the rest.
419 ref_filename_(test::ResourcePath("audio_processing/output_data_mac", 419 ref_filename_(
420 "pb")), 420 test::ResourcePath("audio_processing/output_data_mac", "pb")),
421 #else 421 #else
422 ref_filename_(test::ResourcePath("audio_processing/output_data_float", 422 ref_filename_(
423 "pb")), 423 test::ResourcePath("audio_processing/output_data_float", "pb")),
424 #endif 424 #endif
425 #endif 425 #endif
426 frame_(NULL), 426 frame_(nullptr),
427 revframe_(NULL), 427 revframe_(nullptr),
428 output_sample_rate_hz_(0), 428 output_sample_rate_hz_(0),
429 num_output_channels_(0), 429 num_output_channels_(0),
430 far_file_(NULL), 430 far_file_(nullptr),
431 near_file_(NULL), 431 near_file_(nullptr),
432 out_file_(NULL) { 432 out_file_(nullptr) {
433 Config config; 433 Config config;
434 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); 434 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
435 apm_.reset(AudioProcessing::Create(config)); 435 apm_.reset(AudioProcessing::Create(config));
436 } 436 }
437 437
438 void ApmTest::SetUp() { 438 void ApmTest::SetUp() {
439 ASSERT_TRUE(apm_.get() != NULL); 439 ASSERT_TRUE(apm_.get() != nullptr);
440 440
441 frame_ = new AudioFrame(); 441 frame_ = new AudioFrame();
442 revframe_ = new AudioFrame(); 442 revframe_ = new AudioFrame();
443 443
444 Init(32000, 32000, 32000, 2, 2, 2, false); 444 Init(32000, 32000, 32000, 2, 2, 2, false);
445 } 445 }
446 446
447 void ApmTest::TearDown() { 447 void ApmTest::TearDown() {
448 if (frame_) { 448 if (frame_) {
449 delete frame_; 449 delete frame_;
450 } 450 }
451 frame_ = NULL; 451 frame_ = nullptr;
452 452
453 if (revframe_) { 453 if (revframe_) {
454 delete revframe_; 454 delete revframe_;
455 } 455 }
456 revframe_ = NULL; 456 revframe_ = nullptr;
457 457
458 if (far_file_) { 458 if (far_file_) {
459 ASSERT_EQ(0, fclose(far_file_)); 459 ASSERT_EQ(0, fclose(far_file_));
460 } 460 }
461 far_file_ = NULL; 461 far_file_ = nullptr;
462 462
463 if (near_file_) { 463 if (near_file_) {
464 ASSERT_EQ(0, fclose(near_file_)); 464 ASSERT_EQ(0, fclose(near_file_));
465 } 465 }
466 near_file_ = NULL; 466 near_file_ = nullptr;
467 467
468 if (out_file_) { 468 if (out_file_) {
469 ASSERT_EQ(0, fclose(out_file_)); 469 ASSERT_EQ(0, fclose(out_file_));
470 } 470 }
471 out_file_ = NULL; 471 out_file_ = nullptr;
472 } 472 }
473 473
474 void ApmTest::Init(AudioProcessing* ap) { 474 void ApmTest::Init(AudioProcessing* ap) {
475 ASSERT_EQ(kNoErr, 475 ASSERT_EQ(kNoErr,
476 ap->Initialize( 476 ap->Initialize(
477 {{{frame_->sample_rate_hz_, frame_->num_channels_}, 477 {{{frame_->sample_rate_hz_, frame_->num_channels_},
478 {output_sample_rate_hz_, num_output_channels_}, 478 {output_sample_rate_hz_, num_output_channels_},
479 {revframe_->sample_rate_hz_, revframe_->num_channels_}, 479 {revframe_->sample_rate_hz_, revframe_->num_channels_},
480 {revframe_->sample_rate_hz_, revframe_->num_channels_}}})); 480 {revframe_->sample_rate_hz_, revframe_->num_channels_}}}));
481 } 481 }
(...skipping 11 matching lines...) Expand all
493 493
494 SetContainerFormat(reverse_sample_rate_hz, num_reverse_channels, revframe_, 494 SetContainerFormat(reverse_sample_rate_hz, num_reverse_channels, revframe_,
495 &revfloat_cb_); 495 &revfloat_cb_);
496 Init(apm_.get()); 496 Init(apm_.get());
497 497
498 if (far_file_) { 498 if (far_file_) {
499 ASSERT_EQ(0, fclose(far_file_)); 499 ASSERT_EQ(0, fclose(far_file_));
500 } 500 }
501 std::string filename = ResourceFilePath("far", sample_rate_hz); 501 std::string filename = ResourceFilePath("far", sample_rate_hz);
502 far_file_ = fopen(filename.c_str(), "rb"); 502 far_file_ = fopen(filename.c_str(), "rb");
503 ASSERT_TRUE(far_file_ != NULL) << "Could not open file " << 503 ASSERT_TRUE(far_file_ != nullptr) << "Could not open file " << filename
504 filename << "\n"; 504 << "\n";
505 505
506 if (near_file_) { 506 if (near_file_) {
507 ASSERT_EQ(0, fclose(near_file_)); 507 ASSERT_EQ(0, fclose(near_file_));
508 } 508 }
509 filename = ResourceFilePath("near", sample_rate_hz); 509 filename = ResourceFilePath("near", sample_rate_hz);
510 near_file_ = fopen(filename.c_str(), "rb"); 510 near_file_ = fopen(filename.c_str(), "rb");
511 ASSERT_TRUE(near_file_ != NULL) << "Could not open file " << 511 ASSERT_TRUE(near_file_ != nullptr) << "Could not open file " << filename
512 filename << "\n"; 512 << "\n";
513 513
514 if (open_output_file) { 514 if (open_output_file) {
515 if (out_file_) { 515 if (out_file_) {
516 ASSERT_EQ(0, fclose(out_file_)); 516 ASSERT_EQ(0, fclose(out_file_));
517 } 517 }
518 filename = OutputFilePath( 518 filename = OutputFilePath(
519 "out", sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz, 519 "out", sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz,
520 reverse_sample_rate_hz, num_input_channels, num_output_channels, 520 reverse_sample_rate_hz, num_input_channels, num_output_channels,
521 num_reverse_channels, num_reverse_channels, kForward); 521 num_reverse_channels, num_reverse_channels, kForward);
522 out_file_ = fopen(filename.c_str(), "wb"); 522 out_file_ = fopen(filename.c_str(), "wb");
523 ASSERT_TRUE(out_file_ != NULL) << "Could not open file " << 523 ASSERT_TRUE(out_file_ != nullptr) << "Could not open file " << filename
524 filename << "\n"; 524 << "\n";
525 } 525 }
526 } 526 }
527 527
528 void ApmTest::EnableAllComponents() { 528 void ApmTest::EnableAllComponents() {
529 EnableAllAPComponents(apm_.get()); 529 EnableAllAPComponents(apm_.get());
530 } 530 }
531 531
532 bool ApmTest::ReadFrame(FILE* file, AudioFrame* frame, 532 bool ApmTest::ReadFrame(FILE* file, AudioFrame* frame,
533 ChannelBuffer<float>* cb) { 533 ChannelBuffer<float>* cb) {
534 // The files always contain stereo audio. 534 // The files always contain stereo audio.
(...skipping 13 matching lines...) Expand all
548 frame->samples_per_channel_); 548 frame->samples_per_channel_);
549 } 549 }
550 550
551 if (cb) { 551 if (cb) {
552 ConvertToFloat(*frame, cb); 552 ConvertToFloat(*frame, cb);
553 } 553 }
554 return true; 554 return true;
555 } 555 }
556 556
557 bool ApmTest::ReadFrame(FILE* file, AudioFrame* frame) { 557 bool ApmTest::ReadFrame(FILE* file, AudioFrame* frame) {
558 return ReadFrame(file, frame, NULL); 558 return ReadFrame(file, frame, nullptr);
559 } 559 }
560 560
561 // If the end of the file has been reached, rewind it and attempt to read the 561 // If the end of the file has been reached, rewind it and attempt to read the
562 // frame again. 562 // frame again.
563 void ApmTest::ReadFrameWithRewind(FILE* file, AudioFrame* frame, 563 void ApmTest::ReadFrameWithRewind(FILE* file, AudioFrame* frame,
564 ChannelBuffer<float>* cb) { 564 ChannelBuffer<float>* cb) {
565 if (!ReadFrame(near_file_, frame_, cb)) { 565 if (!ReadFrame(near_file_, frame_, cb)) {
566 rewind(near_file_); 566 rewind(near_file_);
567 ASSERT_TRUE(ReadFrame(near_file_, frame_, cb)); 567 ASSERT_TRUE(ReadFrame(near_file_, frame_, cb));
568 } 568 }
569 } 569 }
570 570
571 void ApmTest::ReadFrameWithRewind(FILE* file, AudioFrame* frame) { 571 void ApmTest::ReadFrameWithRewind(FILE* file, AudioFrame* frame) {
572 ReadFrameWithRewind(file, frame, NULL); 572 ReadFrameWithRewind(file, frame, nullptr);
573 } 573 }
574 574
575 void ApmTest::ProcessWithDefaultStreamParameters(AudioFrame* frame) { 575 void ApmTest::ProcessWithDefaultStreamParameters(AudioFrame* frame) {
576 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0)); 576 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
577 apm_->echo_cancellation()->set_stream_drift_samples(0); 577 apm_->echo_cancellation()->set_stream_drift_samples(0);
578 EXPECT_EQ(apm_->kNoError, 578 EXPECT_EQ(apm_->kNoError,
579 apm_->gain_control()->set_stream_analog_level(127)); 579 apm_->gain_control()->set_stream_analog_level(127));
580 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame)); 580 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame));
581 } 581 }
582 582
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 EXPECT_EQ(apm_->kNotEnabledError, apm_->echo_cancellation()->GetDelayMetrics( 954 EXPECT_EQ(apm_->kNotEnabledError, apm_->echo_cancellation()->GetDelayMetrics(
955 &median, &std, &poor_fraction)); 955 &median, &std, &poor_fraction));
956 956
957 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true)); 957 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
958 EXPECT_TRUE(apm_->echo_cancellation()->is_enabled()); 958 EXPECT_TRUE(apm_->echo_cancellation()->is_enabled());
959 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(false)); 959 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(false));
960 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled()); 960 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled());
961 961
962 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true)); 962 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
963 EXPECT_TRUE(apm_->echo_cancellation()->is_enabled()); 963 EXPECT_TRUE(apm_->echo_cancellation()->is_enabled());
964 EXPECT_TRUE(apm_->echo_cancellation()->aec_core() != NULL); 964 EXPECT_TRUE(apm_->echo_cancellation()->aec_core() != nullptr);
965 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(false)); 965 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(false));
966 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled()); 966 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled());
967 EXPECT_FALSE(apm_->echo_cancellation()->aec_core() != NULL); 967 EXPECT_FALSE(apm_->echo_cancellation()->aec_core() != nullptr);
968 } 968 }
969 969
970 TEST_F(ApmTest, DISABLED_EchoCancellationReportsCorrectDelays) { 970 TEST_F(ApmTest, DISABLED_EchoCancellationReportsCorrectDelays) {
971 // TODO(bjornv): Fix this test to work with DA-AEC. 971 // TODO(bjornv): Fix this test to work with DA-AEC.
972 // Enable AEC only. 972 // Enable AEC only.
973 EXPECT_EQ(apm_->kNoError, 973 EXPECT_EQ(apm_->kNoError,
974 apm_->echo_cancellation()->enable_drift_compensation(false)); 974 apm_->echo_cancellation()->enable_drift_compensation(false));
975 EXPECT_EQ(apm_->kNoError, 975 EXPECT_EQ(apm_->kNoError,
976 apm_->echo_cancellation()->enable_metrics(false)); 976 apm_->echo_cancellation()->enable_metrics(false));
977 EXPECT_EQ(apm_->kNoError, 977 EXPECT_EQ(apm_->kNoError,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 EXPECT_FALSE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); 1071 EXPECT_FALSE(apm_->echo_control_mobile()->is_comfort_noise_enabled());
1072 EXPECT_EQ(apm_->kNoError, 1072 EXPECT_EQ(apm_->kNoError,
1073 apm_->echo_control_mobile()->enable_comfort_noise(true)); 1073 apm_->echo_control_mobile()->enable_comfort_noise(true));
1074 EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); 1074 EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled());
1075 // Set and get echo path 1075 // Set and get echo path
1076 const size_t echo_path_size = 1076 const size_t echo_path_size =
1077 apm_->echo_control_mobile()->echo_path_size_bytes(); 1077 apm_->echo_control_mobile()->echo_path_size_bytes();
1078 std::unique_ptr<char[]> echo_path_in(new char[echo_path_size]); 1078 std::unique_ptr<char[]> echo_path_in(new char[echo_path_size]);
1079 std::unique_ptr<char[]> echo_path_out(new char[echo_path_size]); 1079 std::unique_ptr<char[]> echo_path_out(new char[echo_path_size]);
1080 EXPECT_EQ(apm_->kNullPointerError, 1080 EXPECT_EQ(apm_->kNullPointerError,
1081 apm_->echo_control_mobile()->SetEchoPath(NULL, echo_path_size)); 1081 apm_->echo_control_mobile()->SetEchoPath(nullptr, echo_path_size));
1082 EXPECT_EQ(apm_->kNullPointerError, 1082 EXPECT_EQ(apm_->kNullPointerError,
1083 apm_->echo_control_mobile()->GetEchoPath(NULL, echo_path_size)); 1083 apm_->echo_control_mobile()->GetEchoPath(nullptr, echo_path_size));
1084 EXPECT_EQ(apm_->kBadParameterError, 1084 EXPECT_EQ(apm_->kBadParameterError,
1085 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), 1)); 1085 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), 1));
1086 EXPECT_EQ(apm_->kNoError, 1086 EXPECT_EQ(apm_->kNoError,
1087 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), 1087 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(),
1088 echo_path_size)); 1088 echo_path_size));
1089 for (size_t i = 0; i < echo_path_size; i++) { 1089 for (size_t i = 0; i < echo_path_size; i++) {
1090 echo_path_in[i] = echo_path_out[i] + 1; 1090 echo_path_in[i] = echo_path_out[i] + 1;
1091 } 1091 }
1092 EXPECT_EQ(apm_->kBadParameterError, 1092 EXPECT_EQ(apm_->kBadParameterError,
1093 apm_->echo_control_mobile()->SetEchoPath(echo_path_in.get(), 1)); 1093 apm_->echo_control_mobile()->SetEchoPath(echo_path_in.get(), 1));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 AudioProcessing::Create(config, beamformer)); 1305 AudioProcessing::Create(config, beamformer));
1306 EXPECT_EQ(kNoErr, apm->gain_control()->Enable(true)); 1306 EXPECT_EQ(kNoErr, apm->gain_control()->Enable(true));
1307 ChannelBuffer<float> src_buf(kSamplesPerChannel, kNumInputChannels); 1307 ChannelBuffer<float> src_buf(kSamplesPerChannel, kNumInputChannels);
1308 ChannelBuffer<float> dest_buf(kSamplesPerChannel, kNumOutputChannels); 1308 ChannelBuffer<float> dest_buf(kSamplesPerChannel, kNumOutputChannels);
1309 const size_t max_length = kSamplesPerChannel * std::max(kNumInputChannels, 1309 const size_t max_length = kSamplesPerChannel * std::max(kNumInputChannels,
1310 kNumOutputChannels); 1310 kNumOutputChannels);
1311 std::unique_ptr<int16_t[]> int_data(new int16_t[max_length]); 1311 std::unique_ptr<int16_t[]> int_data(new int16_t[max_length]);
1312 std::unique_ptr<float[]> float_data(new float[max_length]); 1312 std::unique_ptr<float[]> float_data(new float[max_length]);
1313 std::string filename = ResourceFilePath("far", kSampleRateHz); 1313 std::string filename = ResourceFilePath("far", kSampleRateHz);
1314 FILE* far_file = fopen(filename.c_str(), "rb"); 1314 FILE* far_file = fopen(filename.c_str(), "rb");
1315 ASSERT_TRUE(far_file != NULL) << "Could not open file " << filename << "\n"; 1315 ASSERT_TRUE(far_file != nullptr) << "Could not open file " << filename
1316 << "\n";
1316 const int kDefaultVolume = apm->gain_control()->stream_analog_level(); 1317 const int kDefaultVolume = apm->gain_control()->stream_analog_level();
1317 const int kDefaultCompressionGain = 1318 const int kDefaultCompressionGain =
1318 apm->gain_control()->compression_gain_db(); 1319 apm->gain_control()->compression_gain_db();
1319 bool is_target = false; 1320 bool is_target = false;
1320 EXPECT_CALL(*beamformer, is_target_present()) 1321 EXPECT_CALL(*beamformer, is_target_present())
1321 .WillRepeatedly(testing::ReturnPointee(&is_target)); 1322 .WillRepeatedly(testing::ReturnPointee(&is_target));
1322 for (size_t i = 0; i < kNumChunks; ++i) { 1323 for (size_t i = 0; i < kNumChunks; ++i) {
1323 ASSERT_TRUE(ReadChunk(far_file, 1324 ASSERT_TRUE(ReadChunk(far_file,
1324 int_data.get(), 1325 int_data.get(),
1325 float_data.get(), 1326 float_data.get(),
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); 1701 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1701 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy)); 1702 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy));
1702 } 1703 }
1703 1704
1704 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1705 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1705 void ApmTest::ProcessDebugDump(const std::string& in_filename, 1706 void ApmTest::ProcessDebugDump(const std::string& in_filename,
1706 const std::string& out_filename, 1707 const std::string& out_filename,
1707 Format format, 1708 Format format,
1708 int max_size_bytes) { 1709 int max_size_bytes) {
1709 FILE* in_file = fopen(in_filename.c_str(), "rb"); 1710 FILE* in_file = fopen(in_filename.c_str(), "rb");
1710 ASSERT_TRUE(in_file != NULL); 1711 ASSERT_TRUE(in_file != nullptr);
1711 audioproc::Event event_msg; 1712 audioproc::Event event_msg;
1712 bool first_init = true; 1713 bool first_init = true;
1713 1714
1714 while (ReadMessageFromFile(in_file, &event_msg)) { 1715 while (ReadMessageFromFile(in_file, &event_msg)) {
1715 if (event_msg.type() == audioproc::Event::INIT) { 1716 if (event_msg.type() == audioproc::Event::INIT) {
1716 const audioproc::Init msg = event_msg.init(); 1717 const audioproc::Init msg = event_msg.init();
1717 int reverse_sample_rate = msg.sample_rate(); 1718 int reverse_sample_rate = msg.sample_rate();
1718 if (msg.has_reverse_sample_rate()) { 1719 if (msg.has_reverse_sample_rate()) {
1719 reverse_sample_rate = msg.reverse_sample_rate(); 1720 reverse_sample_rate = msg.reverse_sample_rate();
1720 } 1721 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 // We expect at least this many bytes in the created logfile. 1816 // We expect at least this many bytes in the created logfile.
1816 const size_t logging_expected_bytes = 95000; 1817 const size_t logging_expected_bytes = 95000;
1817 EnableAllComponents(); 1818 EnableAllComponents();
1818 ProcessDebugDump(in_filename, ref_filename, format, -1); 1819 ProcessDebugDump(in_filename, ref_filename, format, -1);
1819 ProcessDebugDump(ref_filename, out_filename, format, -1); 1820 ProcessDebugDump(ref_filename, out_filename, format, -1);
1820 ProcessDebugDump(ref_filename, limited_filename, format, logging_limit_bytes); 1821 ProcessDebugDump(ref_filename, limited_filename, format, logging_limit_bytes);
1821 1822
1822 FILE* ref_file = fopen(ref_filename.c_str(), "rb"); 1823 FILE* ref_file = fopen(ref_filename.c_str(), "rb");
1823 FILE* out_file = fopen(out_filename.c_str(), "rb"); 1824 FILE* out_file = fopen(out_filename.c_str(), "rb");
1824 FILE* limited_file = fopen(limited_filename.c_str(), "rb"); 1825 FILE* limited_file = fopen(limited_filename.c_str(), "rb");
1825 ASSERT_TRUE(ref_file != NULL); 1826 ASSERT_TRUE(ref_file != nullptr);
1826 ASSERT_TRUE(out_file != NULL); 1827 ASSERT_TRUE(out_file != nullptr);
1827 ASSERT_TRUE(limited_file != NULL); 1828 ASSERT_TRUE(limited_file != nullptr);
1828 std::unique_ptr<uint8_t[]> ref_bytes; 1829 std::unique_ptr<uint8_t[]> ref_bytes;
1829 std::unique_ptr<uint8_t[]> out_bytes; 1830 std::unique_ptr<uint8_t[]> out_bytes;
1830 std::unique_ptr<uint8_t[]> limited_bytes; 1831 std::unique_ptr<uint8_t[]> limited_bytes;
1831 1832
1832 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes); 1833 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes);
1833 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes); 1834 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes);
1834 size_t limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes); 1835 size_t limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes);
1835 size_t bytes_read = 0; 1836 size_t bytes_read = 0;
1836 size_t bytes_read_limited = 0; 1837 size_t bytes_read_limited = 0;
1837 while (ref_size > 0 && out_size > 0) { 1838 while (ref_size > 0 && out_size > 0) {
(...skipping 28 matching lines...) Expand all
1866 TEST_F(ApmTest, VerifyDebugDumpFloat) { 1867 TEST_F(ApmTest, VerifyDebugDumpFloat) {
1867 VerifyDebugDumpTest(kFloatFormat); 1868 VerifyDebugDumpTest(kFloatFormat);
1868 } 1869 }
1869 #endif 1870 #endif
1870 1871
1871 // TODO(andrew): expand test to verify output. 1872 // TODO(andrew): expand test to verify output.
1872 TEST_F(ApmTest, DebugDump) { 1873 TEST_F(ApmTest, DebugDump) {
1873 const std::string filename = 1874 const std::string filename =
1874 test::TempFilename(test::OutputPath(), "debug_aec"); 1875 test::TempFilename(test::OutputPath(), "debug_aec");
1875 EXPECT_EQ(apm_->kNullPointerError, 1876 EXPECT_EQ(apm_->kNullPointerError,
1876 apm_->StartDebugRecording(static_cast<const char*>(NULL), -1)); 1877 apm_->StartDebugRecording(static_cast<const char*>(nullptr), -1));
1877 1878
1878 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1879 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1879 // Stopping without having started should be OK. 1880 // Stopping without having started should be OK.
1880 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1881 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1881 1882
1882 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(filename.c_str(), -1)); 1883 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(filename.c_str(), -1));
1883 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); 1884 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1884 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); 1885 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_));
1885 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1886 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1886 1887
1887 // Verify the file has been written. 1888 // Verify the file has been written.
1888 FILE* fid = fopen(filename.c_str(), "r"); 1889 FILE* fid = fopen(filename.c_str(), "r");
1889 ASSERT_TRUE(fid != NULL); 1890 ASSERT_TRUE(fid != nullptr);
1890 1891
1891 // Clean it up. 1892 // Clean it up.
1892 ASSERT_EQ(0, fclose(fid)); 1893 ASSERT_EQ(0, fclose(fid));
1893 ASSERT_EQ(0, remove(filename.c_str())); 1894 ASSERT_EQ(0, remove(filename.c_str()));
1894 #else 1895 #else
1895 EXPECT_EQ(apm_->kUnsupportedFunctionError, 1896 EXPECT_EQ(apm_->kUnsupportedFunctionError,
1896 apm_->StartDebugRecording(filename.c_str(), -1)); 1897 apm_->StartDebugRecording(filename.c_str(), -1));
1897 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); 1898 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording());
1898 1899
1899 // Verify the file has NOT been written. 1900 // Verify the file has NOT been written.
1900 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL); 1901 ASSERT_TRUE(fopen(filename.c_str(), "r") == nullptr);
1901 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1902 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1902 } 1903 }
1903 1904
1904 // TODO(andrew): expand test to verify output. 1905 // TODO(andrew): expand test to verify output.
1905 TEST_F(ApmTest, DebugDumpFromFileHandle) { 1906 TEST_F(ApmTest, DebugDumpFromFileHandle) {
1906 FILE* fid = NULL; 1907 FILE* fid = nullptr;
1907 EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid, -1)); 1908 EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid, -1));
1908 const std::string filename = 1909 const std::string filename =
1909 test::TempFilename(test::OutputPath(), "debug_aec"); 1910 test::TempFilename(test::OutputPath(), "debug_aec");
1910 fid = fopen(filename.c_str(), "w"); 1911 fid = fopen(filename.c_str(), "w");
1911 ASSERT_TRUE(fid); 1912 ASSERT_TRUE(fid);
1912 1913
1913 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1914 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1914 // Stopping without having started should be OK. 1915 // Stopping without having started should be OK.
1915 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1916 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1916 1917
1917 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid, -1)); 1918 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid, -1));
1918 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); 1919 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_));
1919 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); 1920 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1920 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1921 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1921 1922
1922 // Verify the file has been written. 1923 // Verify the file has been written.
1923 fid = fopen(filename.c_str(), "r"); 1924 fid = fopen(filename.c_str(), "r");
1924 ASSERT_TRUE(fid != NULL); 1925 ASSERT_TRUE(fid != nullptr);
1925 1926
1926 // Clean it up. 1927 // Clean it up.
1927 ASSERT_EQ(0, fclose(fid)); 1928 ASSERT_EQ(0, fclose(fid));
1928 ASSERT_EQ(0, remove(filename.c_str())); 1929 ASSERT_EQ(0, remove(filename.c_str()));
1929 #else 1930 #else
1930 EXPECT_EQ(apm_->kUnsupportedFunctionError, 1931 EXPECT_EQ(apm_->kUnsupportedFunctionError,
1931 apm_->StartDebugRecording(fid, -1)); 1932 apm_->StartDebugRecording(fid, -1));
1932 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); 1933 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording());
1933 1934
1934 ASSERT_EQ(0, fclose(fid)); 1935 ASSERT_EQ(0, fclose(fid));
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 num_reverse_input_channels, 2454 num_reverse_input_channels,
2454 num_reverse_output_channels, kForward).c_str(), 2455 num_reverse_output_channels, kForward).c_str(),
2455 "wb"); 2456 "wb");
2456 FILE* rev_out_file = 2457 FILE* rev_out_file =
2457 fopen(OutputFilePath(output_file_prefix, input_rate, output_rate, 2458 fopen(OutputFilePath(output_file_prefix, input_rate, output_rate,
2458 reverse_input_rate, reverse_output_rate, 2459 reverse_input_rate, reverse_output_rate,
2459 num_input_channels, num_output_channels, 2460 num_input_channels, num_output_channels,
2460 num_reverse_input_channels, 2461 num_reverse_input_channels,
2461 num_reverse_output_channels, kReverse).c_str(), 2462 num_reverse_output_channels, kReverse).c_str(),
2462 "wb"); 2463 "wb");
2463 ASSERT_TRUE(far_file != NULL); 2464 ASSERT_TRUE(far_file != nullptr);
2464 ASSERT_TRUE(near_file != NULL); 2465 ASSERT_TRUE(near_file != nullptr);
2465 ASSERT_TRUE(out_file != NULL); 2466 ASSERT_TRUE(out_file != nullptr);
2466 ASSERT_TRUE(rev_out_file != NULL); 2467 ASSERT_TRUE(rev_out_file != nullptr);
2467 2468
2468 ChannelBuffer<float> fwd_cb(SamplesFromRate(input_rate), 2469 ChannelBuffer<float> fwd_cb(SamplesFromRate(input_rate),
2469 num_input_channels); 2470 num_input_channels);
2470 ChannelBuffer<float> rev_cb(SamplesFromRate(reverse_input_rate), 2471 ChannelBuffer<float> rev_cb(SamplesFromRate(reverse_input_rate),
2471 num_reverse_input_channels); 2472 num_reverse_input_channels);
2472 ChannelBuffer<float> out_cb(SamplesFromRate(output_rate), 2473 ChannelBuffer<float> out_cb(SamplesFromRate(output_rate),
2473 num_output_channels); 2474 num_output_channels);
2474 ChannelBuffer<float> rev_out_cb(SamplesFromRate(reverse_output_rate), 2475 ChannelBuffer<float> rev_out_cb(SamplesFromRate(reverse_output_rate),
2475 num_reverse_output_channels); 2476 num_reverse_output_channels);
2476 2477
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2593 cf[i].num_output, cf[i].num_reverse_input, 2594 cf[i].num_output, cf[i].num_reverse_input,
2594 cf[i].num_reverse_output, file_direction).c_str(), 2595 cf[i].num_reverse_output, file_direction).c_str(),
2595 "rb"); 2596 "rb");
2596 // The reference files always have matching input and output channels. 2597 // The reference files always have matching input and output channels.
2597 FILE* ref_file = fopen( 2598 FILE* ref_file = fopen(
2598 OutputFilePath("ref", ref_rate, ref_rate, ref_rate, ref_rate, 2599 OutputFilePath("ref", ref_rate, ref_rate, ref_rate, ref_rate,
2599 cf[i].num_output, cf[i].num_output, 2600 cf[i].num_output, cf[i].num_output,
2600 cf[i].num_reverse_output, cf[i].num_reverse_output, 2601 cf[i].num_reverse_output, cf[i].num_reverse_output,
2601 file_direction).c_str(), 2602 file_direction).c_str(),
2602 "rb"); 2603 "rb");
2603 ASSERT_TRUE(out_file != NULL); 2604 ASSERT_TRUE(out_file != nullptr);
2604 ASSERT_TRUE(ref_file != NULL); 2605 ASSERT_TRUE(ref_file != nullptr);
2605 2606
2606 const size_t ref_length = SamplesFromRate(ref_rate) * out_num; 2607 const size_t ref_length = SamplesFromRate(ref_rate) * out_num;
2607 const size_t out_length = SamplesFromRate(out_rate) * out_num; 2608 const size_t out_length = SamplesFromRate(out_rate) * out_num;
2608 // Data from the reference file. 2609 // Data from the reference file.
2609 std::unique_ptr<float[]> ref_data(new float[ref_length]); 2610 std::unique_ptr<float[]> ref_data(new float[ref_length]);
2610 // Data from the output file. 2611 // Data from the output file.
2611 std::unique_ptr<float[]> out_data(new float[out_length]); 2612 std::unique_ptr<float[]> out_data(new float[out_length]);
2612 // Data from the resampled output, in case the reference and output rates 2613 // Data from the resampled output, in case the reference and output rates
2613 // don't match. 2614 // don't match.
2614 std::unique_ptr<float[]> cmp_data(new float[ref_length]); 2615 std::unique_ptr<float[]> cmp_data(new float[ref_length]);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 // TODO(peah): Remove the testing for 2878 // TODO(peah): Remove the testing for
2878 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ 2879 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2879 // is instead used to activate the level controller. 2880 // is instead used to activate the level controller.
2880 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); 2881 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2881 EXPECT_NEAR(kTargetLcPeakLeveldBFS, 2882 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2882 apm->config_.level_controller.initial_peak_level_dbfs, 2883 apm->config_.level_controller.initial_peak_level_dbfs,
2883 std::numeric_limits<float>::epsilon()); 2884 std::numeric_limits<float>::epsilon());
2884 } 2885 }
2885 2886
2886 } // namespace webrtc 2887 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698