OLD | NEW |
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 <<<<<<< HEAD |
| 24 ||||||| parent of 6d4e36d05... aec-dumper and null-aec-dumper. Most parts are im
plemented. |
| 25 #include "webrtc/base/protobuf_utils.h" |
| 26 ======= |
| 27 #include "webrtc/base/task_queue.h" |
| 28 #include "webrtc/base/thread.h" |
| 29 >>>>>>> 6d4e36d05... aec-dumper and null-aec-dumper. Most parts are implemented. |
23 #include "webrtc/common_audio/include/audio_util.h" | 30 #include "webrtc/common_audio/include/audio_util.h" |
24 #include "webrtc/common_audio/resampler/include/push_resampler.h" | 31 #include "webrtc/common_audio/resampler/include/push_resampler.h" |
25 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 32 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
26 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 33 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
27 #include "webrtc/modules/audio_processing/audio_processing_impl.h" | 34 #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
28 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" | 35 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" |
29 #include "webrtc/modules/audio_processing/common.h" | 36 #include "webrtc/modules/audio_processing/common.h" |
30 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 37 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
31 #include "webrtc/modules/audio_processing/level_controller/level_controller_cons
tants.h" | 38 #include "webrtc/modules/audio_processing/level_controller/level_controller_cons
tants.h" |
32 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 39 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 int output_sample_rate_hz_; | 410 int output_sample_rate_hz_; |
404 size_t num_output_channels_; | 411 size_t num_output_channels_; |
405 FILE* far_file_; | 412 FILE* far_file_; |
406 FILE* near_file_; | 413 FILE* near_file_; |
407 FILE* out_file_; | 414 FILE* out_file_; |
408 }; | 415 }; |
409 | 416 |
410 ApmTest::ApmTest() | 417 ApmTest::ApmTest() |
411 : output_path_(test::OutputPath()), | 418 : output_path_(test::OutputPath()), |
412 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE) | 419 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE) |
413 ref_filename_(test::ResourcePath("audio_processing/output_data_fixed", | 420 ref_filename_( |
414 "pb")), | 421 test::ResourcePath("audio_processing/output_data_fixed", "pb")), |
415 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) | 422 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) |
416 #if defined(WEBRTC_MAC) | 423 #if defined(WEBRTC_MAC) |
417 // A different file for Mac is needed because on this platform the AEC | 424 // 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. | 425 // constant |kFixedDelayMs| value is 20 and not 50 as it is on the rest. |
419 ref_filename_(test::ResourcePath("audio_processing/output_data_mac", | 426 ref_filename_( |
420 "pb")), | 427 test::ResourcePath("audio_processing/output_data_mac", "pb")), |
421 #else | 428 #else |
422 ref_filename_(test::ResourcePath("audio_processing/output_data_float", | 429 ref_filename_( |
423 "pb")), | 430 test::ResourcePath("audio_processing/output_data_float", "pb")), |
424 #endif | 431 #endif |
425 #endif | 432 #endif |
426 frame_(NULL), | 433 frame_(NULL), |
427 revframe_(NULL), | 434 revframe_(NULL), |
428 output_sample_rate_hz_(0), | 435 output_sample_rate_hz_(0), |
429 num_output_channels_(0), | 436 num_output_channels_(0), |
430 far_file_(NULL), | 437 far_file_(NULL), |
431 near_file_(NULL), | 438 near_file_(NULL), |
432 out_file_(NULL) { | 439 out_file_(NULL) { |
433 Config config; | 440 Config config; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 581 |
575 void ApmTest::ProcessWithDefaultStreamParameters(AudioFrame* frame) { | 582 void ApmTest::ProcessWithDefaultStreamParameters(AudioFrame* frame) { |
576 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0)); | 583 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0)); |
577 apm_->echo_cancellation()->set_stream_drift_samples(0); | 584 apm_->echo_cancellation()->set_stream_drift_samples(0); |
578 EXPECT_EQ(apm_->kNoError, | 585 EXPECT_EQ(apm_->kNoError, |
579 apm_->gain_control()->set_stream_analog_level(127)); | 586 apm_->gain_control()->set_stream_analog_level(127)); |
580 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame)); | 587 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame)); |
581 } | 588 } |
582 | 589 |
583 int ApmTest::ProcessStreamChooser(Format format) { | 590 int ApmTest::ProcessStreamChooser(Format format) { |
| 591 rtc::Thread::Current()->SleepMs(1); |
584 if (format == kIntFormat) { | 592 if (format == kIntFormat) { |
585 return apm_->ProcessStream(frame_); | 593 return apm_->ProcessStream(frame_); |
586 } | 594 } |
587 return apm_->ProcessStream(float_cb_->channels(), | 595 return apm_->ProcessStream(float_cb_->channels(), |
588 frame_->samples_per_channel_, | 596 frame_->samples_per_channel_, |
589 frame_->sample_rate_hz_, | 597 frame_->sample_rate_hz_, |
590 LayoutFromChannels(frame_->num_channels_), | 598 LayoutFromChannels(frame_->num_channels_), |
591 output_sample_rate_hz_, | 599 output_sample_rate_hz_, |
592 LayoutFromChannels(num_output_channels_), | 600 LayoutFromChannels(num_output_channels_), |
593 float_cb_->channels()); | 601 float_cb_->channels()); |
594 } | 602 } |
595 | 603 |
596 int ApmTest::AnalyzeReverseStreamChooser(Format format) { | 604 int ApmTest::AnalyzeReverseStreamChooser(Format format) { |
| 605 rtc::Thread::Current()->SleepMs(1); |
597 if (format == kIntFormat) { | 606 if (format == kIntFormat) { |
598 return apm_->ProcessReverseStream(revframe_); | 607 return apm_->ProcessReverseStream(revframe_); |
599 } | 608 } |
600 return apm_->AnalyzeReverseStream( | 609 return apm_->AnalyzeReverseStream( |
601 revfloat_cb_->channels(), | 610 revfloat_cb_->channels(), |
602 revframe_->samples_per_channel_, | 611 revframe_->samples_per_channel_, |
603 revframe_->sample_rate_hz_, | 612 revframe_->sample_rate_hz_, |
604 LayoutFromChannels(revframe_->num_channels_)); | 613 LayoutFromChannels(revframe_->num_channels_)); |
605 } | 614 } |
606 | 615 |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 apm_->echo_cancellation()->set_stream_drift_samples(0); | 1708 apm_->echo_cancellation()->set_stream_drift_samples(0); |
1700 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1709 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
1701 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy)); | 1710 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy)); |
1702 } | 1711 } |
1703 | 1712 |
1704 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1713 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
1705 void ApmTest::ProcessDebugDump(const std::string& in_filename, | 1714 void ApmTest::ProcessDebugDump(const std::string& in_filename, |
1706 const std::string& out_filename, | 1715 const std::string& out_filename, |
1707 Format format, | 1716 Format format, |
1708 int max_size_bytes) { | 1717 int max_size_bytes) { |
| 1718 rtc::TaskQueue worker_queue("ApmTest_worker_queue"); |
1709 FILE* in_file = fopen(in_filename.c_str(), "rb"); | 1719 FILE* in_file = fopen(in_filename.c_str(), "rb"); |
1710 ASSERT_TRUE(in_file != NULL); | 1720 ASSERT_TRUE(in_file != NULL); |
1711 audioproc::Event event_msg; | 1721 audioproc::Event event_msg; |
1712 bool first_init = true; | 1722 bool first_init = true; |
1713 | 1723 |
1714 while (ReadMessageFromFile(in_file, &event_msg)) { | 1724 while (ReadMessageFromFile(in_file, &event_msg)) { |
1715 if (event_msg.type() == audioproc::Event::INIT) { | 1725 if (event_msg.type() == audioproc::Event::INIT) { |
1716 const audioproc::Init msg = event_msg.init(); | 1726 const audioproc::Init msg = event_msg.init(); |
1717 int reverse_sample_rate = msg.sample_rate(); | 1727 int reverse_sample_rate = msg.sample_rate(); |
1718 if (msg.has_reverse_sample_rate()) { | 1728 if (msg.has_reverse_sample_rate()) { |
1719 reverse_sample_rate = msg.reverse_sample_rate(); | 1729 reverse_sample_rate = msg.reverse_sample_rate(); |
1720 } | 1730 } |
1721 int output_sample_rate = msg.sample_rate(); | 1731 int output_sample_rate = msg.sample_rate(); |
1722 if (msg.has_output_sample_rate()) { | 1732 if (msg.has_output_sample_rate()) { |
1723 output_sample_rate = msg.output_sample_rate(); | 1733 output_sample_rate = msg.output_sample_rate(); |
1724 } | 1734 } |
1725 | 1735 |
1726 Init(msg.sample_rate(), | 1736 Init(msg.sample_rate(), |
1727 output_sample_rate, | 1737 output_sample_rate, |
1728 reverse_sample_rate, | 1738 reverse_sample_rate, |
1729 msg.num_input_channels(), | 1739 msg.num_input_channels(), |
1730 msg.num_output_channels(), | 1740 msg.num_output_channels(), |
1731 msg.num_reverse_channels(), | 1741 msg.num_reverse_channels(), |
1732 false); | 1742 false); |
1733 if (first_init) { | 1743 if (first_init) { |
1734 // StartDebugRecording() writes an additional init message. Don't start | 1744 // StartDebugRecording() writes an additional init message. Don't start |
1735 // recording until after the first init to avoid the extra message. | 1745 // recording until after the first init to avoid the extra message. |
1736 EXPECT_NOERR( | 1746 EXPECT_NOERR(apm_->StartDebugRecording(out_filename.c_str(), |
1737 apm_->StartDebugRecording(out_filename.c_str(), max_size_bytes)); | 1747 max_size_bytes, &worker_queue)); |
1738 first_init = false; | 1748 first_init = false; |
1739 } | 1749 } |
1740 | 1750 |
1741 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) { | 1751 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) { |
1742 const audioproc::ReverseStream msg = event_msg.reverse_stream(); | 1752 const audioproc::ReverseStream msg = event_msg.reverse_stream(); |
1743 | 1753 |
1744 if (msg.channel_size() > 0) { | 1754 if (msg.channel_size() > 0) { |
1745 ASSERT_EQ(revframe_->num_channels_, | 1755 ASSERT_EQ(revframe_->num_channels_, |
1746 static_cast<size_t>(msg.channel_size())); | 1756 static_cast<size_t>(msg.channel_size())); |
1747 for (int i = 0; i < msg.channel_size(); ++i) { | 1757 for (int i = 0; i < msg.channel_size(); ++i) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 VerifyDebugDumpTest(kIntFormat); | 1873 VerifyDebugDumpTest(kIntFormat); |
1864 } | 1874 } |
1865 | 1875 |
1866 TEST_F(ApmTest, VerifyDebugDumpFloat) { | 1876 TEST_F(ApmTest, VerifyDebugDumpFloat) { |
1867 VerifyDebugDumpTest(kFloatFormat); | 1877 VerifyDebugDumpTest(kFloatFormat); |
1868 } | 1878 } |
1869 #endif | 1879 #endif |
1870 | 1880 |
1871 // TODO(andrew): expand test to verify output. | 1881 // TODO(andrew): expand test to verify output. |
1872 TEST_F(ApmTest, DebugDump) { | 1882 TEST_F(ApmTest, DebugDump) { |
| 1883 rtc::TaskQueue worker_queue("ApmTest_worker_queue"); |
1873 const std::string filename = | 1884 const std::string filename = |
1874 test::TempFilename(test::OutputPath(), "debug_aec"); | 1885 test::TempFilename(test::OutputPath(), "debug_aec"); |
1875 EXPECT_EQ(apm_->kNullPointerError, | |
1876 apm_->StartDebugRecording(static_cast<const char*>(NULL), -1)); | |
1877 | 1886 |
1878 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1887 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
1879 // Stopping without having started should be OK. | 1888 // Stopping without having started should be OK. |
1880 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1889 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); |
1881 | 1890 |
1882 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(filename.c_str(), -1)); | 1891 EXPECT_EQ(apm_->kNoError, |
| 1892 apm_->StartDebugRecording(filename.c_str(), -1, &worker_queue)); |
1883 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1893 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
1884 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); | 1894 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); |
1885 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1895 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); |
1886 | 1896 |
1887 // Verify the file has been written. | 1897 // Verify the file has been written. |
1888 FILE* fid = fopen(filename.c_str(), "r"); | 1898 FILE* fid = fopen(filename.c_str(), "r"); |
1889 ASSERT_TRUE(fid != NULL); | 1899 ASSERT_TRUE(fid != NULL); |
1890 | 1900 |
1891 // Clean it up. | 1901 // Clean it up. |
1892 ASSERT_EQ(0, fclose(fid)); | 1902 ASSERT_EQ(0, fclose(fid)); |
1893 ASSERT_EQ(0, remove(filename.c_str())); | 1903 ASSERT_EQ(0, remove(filename.c_str())); |
1894 #else | 1904 #else |
1895 EXPECT_EQ(apm_->kUnsupportedFunctionError, | 1905 EXPECT_EQ(apm_->kUnsupportedFunctionError, |
1896 apm_->StartDebugRecording(filename.c_str(), -1)); | 1906 apm_->StartDebugRecording(filename.c_str(), -1)); |
1897 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); | 1907 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); |
1898 | 1908 |
1899 // Verify the file has NOT been written. | 1909 // Verify the file has NOT been written. |
1900 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL); | 1910 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL); |
1901 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1911 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1902 } | 1912 } |
1903 | 1913 |
1904 // TODO(andrew): expand test to verify output. | 1914 // TODO(andrew): expand test to verify output. |
1905 TEST_F(ApmTest, DebugDumpFromFileHandle) { | 1915 TEST_F(ApmTest, DebugDumpFromFileHandle) { |
1906 FILE* fid = NULL; | 1916 rtc::TaskQueue worker_queue("ApmTest_worker_queue"); |
1907 EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid, -1)); | |
1908 const std::string filename = | 1917 const std::string filename = |
1909 test::TempFilename(test::OutputPath(), "debug_aec"); | 1918 test::TempFilename(test::OutputPath(), "debug_aec"); |
1910 fid = fopen(filename.c_str(), "w"); | 1919 FILE* fid = fopen(filename.c_str(), "w"); |
1911 ASSERT_TRUE(fid); | 1920 ASSERT_TRUE(fid); |
1912 | 1921 |
1913 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1922 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
1914 // Stopping without having started should be OK. | 1923 // Stopping without having started should be OK. |
1915 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1924 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); |
1916 | 1925 |
1917 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid, -1)); | 1926 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid, -1, &worker_queue)); |
1918 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); | 1927 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); |
1919 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1928 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
1920 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1929 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); |
1921 | 1930 |
1922 // Verify the file has been written. | 1931 // Verify the file has been written. |
1923 fid = fopen(filename.c_str(), "r"); | 1932 fid = fopen(filename.c_str(), "r"); |
1924 ASSERT_TRUE(fid != NULL); | 1933 ASSERT_TRUE(fid != NULL); |
1925 | 1934 |
1926 // Clean it up. | 1935 // Clean it up. |
1927 ASSERT_EQ(0, fclose(fid)); | 1936 ASSERT_EQ(0, fclose(fid)); |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2877 // TODO(peah): Remove the testing for | 2886 // TODO(peah): Remove the testing for |
2878 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | 2887 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ |
2879 // is instead used to activate the level controller. | 2888 // is instead used to activate the level controller. |
2880 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | 2889 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); |
2881 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | 2890 EXPECT_NEAR(kTargetLcPeakLeveldBFS, |
2882 apm->config_.level_controller.initial_peak_level_dbfs, | 2891 apm->config_.level_controller.initial_peak_level_dbfs, |
2883 std::numeric_limits<float>::epsilon()); | 2892 std::numeric_limits<float>::epsilon()); |
2884 } | 2893 } |
2885 | 2894 |
2886 } // namespace webrtc | 2895 } // namespace webrtc |
OLD | NEW |