| 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 #include "webrtc/base/protobuf_utils.h" | 23 #include "webrtc/base/protobuf_utils.h" |
| 24 #include "webrtc/base/safe_minmax.h" | 24 #include "webrtc/base/safe_minmax.h" |
| 25 #include "webrtc/base/task_queue.h" |
| 26 #include "webrtc/base/thread.h" |
| 25 #include "webrtc/common_audio/include/audio_util.h" | 27 #include "webrtc/common_audio/include/audio_util.h" |
| 26 #include "webrtc/common_audio/resampler/include/push_resampler.h" | 28 #include "webrtc/common_audio/resampler/include/push_resampler.h" |
| 27 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 29 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
| 28 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 30 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 31 #include "webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h" |
| 29 #include "webrtc/modules/audio_processing/audio_processing_impl.h" | 32 #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
| 30 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" | 33 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" |
| 31 #include "webrtc/modules/audio_processing/common.h" | 34 #include "webrtc/modules/audio_processing/common.h" |
| 32 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 35 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 33 #include "webrtc/modules/audio_processing/level_controller/level_controller_cons
tants.h" | 36 #include "webrtc/modules/audio_processing/level_controller/level_controller_cons
tants.h" |
| 34 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 37 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
| 35 #include "webrtc/modules/audio_processing/test/test_utils.h" | 38 #include "webrtc/modules/audio_processing/test/test_utils.h" |
| 36 #include "webrtc/modules/include/module_common_types.h" | 39 #include "webrtc/modules/include/module_common_types.h" |
| 37 #include "webrtc/system_wrappers/include/event_wrapper.h" | 40 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 38 #include "webrtc/system_wrappers/include/trace.h" | 41 #include "webrtc/system_wrappers/include/trace.h" |
| (...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 apm_->echo_cancellation()->set_stream_drift_samples(0); | 1705 apm_->echo_cancellation()->set_stream_drift_samples(0); |
| 1703 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1706 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
| 1704 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy)); | 1707 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy)); |
| 1705 } | 1708 } |
| 1706 | 1709 |
| 1707 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1710 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1708 void ApmTest::ProcessDebugDump(const std::string& in_filename, | 1711 void ApmTest::ProcessDebugDump(const std::string& in_filename, |
| 1709 const std::string& out_filename, | 1712 const std::string& out_filename, |
| 1710 Format format, | 1713 Format format, |
| 1711 int max_size_bytes) { | 1714 int max_size_bytes) { |
| 1715 rtc::TaskQueue worker_queue("ApmTest_worker_queue"); |
| 1712 FILE* in_file = fopen(in_filename.c_str(), "rb"); | 1716 FILE* in_file = fopen(in_filename.c_str(), "rb"); |
| 1713 ASSERT_TRUE(in_file != NULL); | 1717 ASSERT_TRUE(in_file != NULL); |
| 1714 audioproc::Event event_msg; | 1718 audioproc::Event event_msg; |
| 1715 bool first_init = true; | 1719 bool first_init = true; |
| 1716 | 1720 |
| 1717 while (ReadMessageFromFile(in_file, &event_msg)) { | 1721 while (ReadMessageFromFile(in_file, &event_msg)) { |
| 1718 if (event_msg.type() == audioproc::Event::INIT) { | 1722 if (event_msg.type() == audioproc::Event::INIT) { |
| 1719 const audioproc::Init msg = event_msg.init(); | 1723 const audioproc::Init msg = event_msg.init(); |
| 1720 int reverse_sample_rate = msg.sample_rate(); | 1724 int reverse_sample_rate = msg.sample_rate(); |
| 1721 if (msg.has_reverse_sample_rate()) { | 1725 if (msg.has_reverse_sample_rate()) { |
| 1722 reverse_sample_rate = msg.reverse_sample_rate(); | 1726 reverse_sample_rate = msg.reverse_sample_rate(); |
| 1723 } | 1727 } |
| 1724 int output_sample_rate = msg.sample_rate(); | 1728 int output_sample_rate = msg.sample_rate(); |
| 1725 if (msg.has_output_sample_rate()) { | 1729 if (msg.has_output_sample_rate()) { |
| 1726 output_sample_rate = msg.output_sample_rate(); | 1730 output_sample_rate = msg.output_sample_rate(); |
| 1727 } | 1731 } |
| 1728 | 1732 |
| 1729 Init(msg.sample_rate(), | 1733 Init(msg.sample_rate(), |
| 1730 output_sample_rate, | 1734 output_sample_rate, |
| 1731 reverse_sample_rate, | 1735 reverse_sample_rate, |
| 1732 msg.num_input_channels(), | 1736 msg.num_input_channels(), |
| 1733 msg.num_output_channels(), | 1737 msg.num_output_channels(), |
| 1734 msg.num_reverse_channels(), | 1738 msg.num_reverse_channels(), |
| 1735 false); | 1739 false); |
| 1736 if (first_init) { | 1740 if (first_init) { |
| 1737 // StartDebugRecording() writes an additional init message. Don't start | 1741 // AttachAecDump() writes an additional init message. Don't start |
| 1738 // recording until after the first init to avoid the extra message. | 1742 // recording until after the first init to avoid the extra message. |
| 1739 EXPECT_NOERR( | 1743 auto aec_dump = |
| 1740 apm_->StartDebugRecording(out_filename.c_str(), max_size_bytes)); | 1744 AecDumpFactory::Create(out_filename, max_size_bytes, &worker_queue); |
| 1745 EXPECT_TRUE(aec_dump); |
| 1746 apm_->AttachAecDump(std::move(aec_dump)); |
| 1741 first_init = false; | 1747 first_init = false; |
| 1742 } | 1748 } |
| 1743 | 1749 |
| 1744 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) { | 1750 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) { |
| 1745 const audioproc::ReverseStream msg = event_msg.reverse_stream(); | 1751 const audioproc::ReverseStream msg = event_msg.reverse_stream(); |
| 1746 | 1752 |
| 1747 if (msg.channel_size() > 0) { | 1753 if (msg.channel_size() > 0) { |
| 1748 ASSERT_EQ(revframe_->num_channels_, | 1754 ASSERT_EQ(revframe_->num_channels_, |
| 1749 static_cast<size_t>(msg.channel_size())); | 1755 static_cast<size_t>(msg.channel_size())); |
| 1750 for (int i = 0; i < msg.channel_size(); ++i) { | 1756 for (int i = 0; i < msg.channel_size(); ++i) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1787 memcpy(frame_->mutable_data(), msg.input_data().data(), | 1793 memcpy(frame_->mutable_data(), msg.input_data().data(), |
| 1788 msg.input_data().size()); | 1794 msg.input_data().size()); |
| 1789 if (format == kFloatFormat) { | 1795 if (format == kFloatFormat) { |
| 1790 // We're using an int16 input file; convert to float. | 1796 // We're using an int16 input file; convert to float. |
| 1791 ConvertToFloat(*frame_, float_cb_.get()); | 1797 ConvertToFloat(*frame_, float_cb_.get()); |
| 1792 } | 1798 } |
| 1793 } | 1799 } |
| 1794 ProcessStreamChooser(format); | 1800 ProcessStreamChooser(format); |
| 1795 } | 1801 } |
| 1796 } | 1802 } |
| 1797 EXPECT_NOERR(apm_->StopDebugRecording()); | 1803 apm_->DetachAecDump(); |
| 1798 fclose(in_file); | 1804 fclose(in_file); |
| 1799 } | 1805 } |
| 1800 | 1806 |
| 1801 void ApmTest::VerifyDebugDumpTest(Format format) { | 1807 void ApmTest::VerifyDebugDumpTest(Format format) { |
| 1802 const std::string in_filename = test::ResourcePath("ref03", "aecdump"); | 1808 const std::string in_filename = test::ResourcePath("ref03", "aecdump"); |
| 1803 std::string format_string; | 1809 std::string format_string; |
| 1804 switch (format) { | 1810 switch (format) { |
| 1805 case kIntFormat: | 1811 case kIntFormat: |
| 1806 format_string = "_int"; | 1812 format_string = "_int"; |
| 1807 break; | 1813 break; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 VerifyDebugDumpTest(kIntFormat); | 1873 VerifyDebugDumpTest(kIntFormat); |
| 1868 } | 1874 } |
| 1869 | 1875 |
| 1870 TEST_F(ApmTest, VerifyDebugDumpFloat) { | 1876 TEST_F(ApmTest, VerifyDebugDumpFloat) { |
| 1871 VerifyDebugDumpTest(kFloatFormat); | 1877 VerifyDebugDumpTest(kFloatFormat); |
| 1872 } | 1878 } |
| 1873 #endif | 1879 #endif |
| 1874 | 1880 |
| 1875 // TODO(andrew): expand test to verify output. | 1881 // TODO(andrew): expand test to verify output. |
| 1876 TEST_F(ApmTest, DebugDump) { | 1882 TEST_F(ApmTest, DebugDump) { |
| 1883 rtc::TaskQueue worker_queue("ApmTest_worker_queue"); |
| 1877 const std::string filename = | 1884 const std::string filename = |
| 1878 test::TempFilename(test::OutputPath(), "debug_aec"); | 1885 test::TempFilename(test::OutputPath(), "debug_aec"); |
| 1879 EXPECT_EQ(apm_->kNullPointerError, | 1886 { |
| 1880 apm_->StartDebugRecording(static_cast<const char*>(NULL), -1)); | 1887 auto aec_dump = AecDumpFactory::Create("", -1, &worker_queue); |
| 1888 EXPECT_FALSE(aec_dump); |
| 1889 } |
| 1881 | 1890 |
| 1882 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1891 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1883 // Stopping without having started should be OK. | 1892 // Stopping without having started should be OK. |
| 1884 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1893 apm_->DetachAecDump(); |
| 1885 | 1894 |
| 1886 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(filename.c_str(), -1)); | 1895 auto aec_dump = AecDumpFactory::Create(filename, -1, &worker_queue); |
| 1896 EXPECT_TRUE(aec_dump); |
| 1897 apm_->AttachAecDump(std::move(aec_dump)); |
| 1887 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1898 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
| 1888 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); | 1899 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); |
| 1889 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1900 apm_->DetachAecDump(); |
| 1890 | 1901 |
| 1891 // Verify the file has been written. | 1902 // Verify the file has been written. |
| 1892 FILE* fid = fopen(filename.c_str(), "r"); | 1903 FILE* fid = fopen(filename.c_str(), "r"); |
| 1893 ASSERT_TRUE(fid != NULL); | 1904 ASSERT_TRUE(fid != NULL); |
| 1894 | 1905 |
| 1895 // Clean it up. | 1906 // Clean it up. |
| 1896 ASSERT_EQ(0, fclose(fid)); | 1907 ASSERT_EQ(0, fclose(fid)); |
| 1897 ASSERT_EQ(0, remove(filename.c_str())); | 1908 ASSERT_EQ(0, remove(filename.c_str())); |
| 1898 #else | 1909 #else |
| 1899 EXPECT_EQ(apm_->kUnsupportedFunctionError, | |
| 1900 apm_->StartDebugRecording(filename.c_str(), -1)); | |
| 1901 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); | |
| 1902 | |
| 1903 // Verify the file has NOT been written. | 1910 // Verify the file has NOT been written. |
| 1904 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL); | 1911 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL); |
| 1905 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1912 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1906 } | 1913 } |
| 1907 | 1914 |
| 1908 // TODO(andrew): expand test to verify output. | 1915 // TODO(andrew): expand test to verify output. |
| 1909 TEST_F(ApmTest, DebugDumpFromFileHandle) { | 1916 TEST_F(ApmTest, DebugDumpFromFileHandle) { |
| 1910 FILE* fid = NULL; | 1917 rtc::TaskQueue worker_queue("ApmTest_worker_queue"); |
| 1911 EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid, -1)); | 1918 |
| 1912 const std::string filename = | 1919 const std::string filename = |
| 1913 test::TempFilename(test::OutputPath(), "debug_aec"); | 1920 test::TempFilename(test::OutputPath(), "debug_aec"); |
| 1914 fid = fopen(filename.c_str(), "w"); | 1921 FILE* fid = fopen(filename.c_str(), "w"); |
| 1915 ASSERT_TRUE(fid); | 1922 ASSERT_TRUE(fid); |
| 1916 | 1923 |
| 1917 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1924 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1918 // Stopping without having started should be OK. | 1925 // Stopping without having started should be OK. |
| 1919 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1926 apm_->DetachAecDump(); |
| 1920 | 1927 |
| 1921 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid, -1)); | 1928 auto aec_dump = AecDumpFactory::Create(fid, -1, &worker_queue); |
| 1929 EXPECT_TRUE(aec_dump); |
| 1930 apm_->AttachAecDump(std::move(aec_dump)); |
| 1922 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); | 1931 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_)); |
| 1923 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1932 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
| 1924 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); | 1933 apm_->DetachAecDump(); |
| 1925 | 1934 |
| 1926 // Verify the file has been written. | 1935 // Verify the file has been written. |
| 1927 fid = fopen(filename.c_str(), "r"); | 1936 fid = fopen(filename.c_str(), "r"); |
| 1928 ASSERT_TRUE(fid != NULL); | 1937 ASSERT_TRUE(fid != NULL); |
| 1929 | 1938 |
| 1930 // Clean it up. | 1939 // Clean it up. |
| 1931 ASSERT_EQ(0, fclose(fid)); | 1940 ASSERT_EQ(0, fclose(fid)); |
| 1932 ASSERT_EQ(0, remove(filename.c_str())); | 1941 ASSERT_EQ(0, remove(filename.c_str())); |
| 1933 #else | 1942 #else |
| 1934 EXPECT_EQ(apm_->kUnsupportedFunctionError, | |
| 1935 apm_->StartDebugRecording(fid, -1)); | |
| 1936 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); | |
| 1937 | |
| 1938 ASSERT_EQ(0, fclose(fid)); | 1943 ASSERT_EQ(0, fclose(fid)); |
| 1939 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1944 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1940 } | 1945 } |
| 1941 | 1946 |
| 1942 TEST_F(ApmTest, FloatAndIntInterfacesGiveSimilarResults) { | 1947 TEST_F(ApmTest, FloatAndIntInterfacesGiveSimilarResults) { |
| 1943 audioproc::OutputData ref_data; | 1948 audioproc::OutputData ref_data; |
| 1944 OpenFileAndReadMessage(ref_filename_, &ref_data); | 1949 OpenFileAndReadMessage(ref_filename_, &ref_data); |
| 1945 | 1950 |
| 1946 Config config; | 1951 Config config; |
| 1947 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); | 1952 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2881 // TODO(peah): Remove the testing for | 2886 // TODO(peah): Remove the testing for |
| 2882 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | 2887 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ |
| 2883 // is instead used to activate the level controller. | 2888 // is instead used to activate the level controller. |
| 2884 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | 2889 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); |
| 2885 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | 2890 EXPECT_NEAR(kTargetLcPeakLeveldBFS, |
| 2886 apm->config_.level_controller.initial_peak_level_dbfs, | 2891 apm->config_.level_controller.initial_peak_level_dbfs, |
| 2887 std::numeric_limits<float>::epsilon()); | 2892 std::numeric_limits<float>::epsilon()); |
| 2888 } | 2893 } |
| 2889 | 2894 |
| 2890 } // namespace webrtc | 2895 } // namespace webrtc |
| OLD | NEW |