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