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

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

Issue 1541633002: Reland "Added option to specify a maximum file size when recording an AEC dump." (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix to prevent Chrome from breaking. Created 5 years 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 AudioProcessing::Error expected_return); 381 AudioProcessing::Error expected_return);
382 void TestChangingReverseChannels(int num_rev_channels, 382 void TestChangingReverseChannels(int num_rev_channels,
383 AudioProcessing::Error expected_return); 383 AudioProcessing::Error expected_return);
384 void RunQuantizedVolumeDoesNotGetStuckTest(int sample_rate); 384 void RunQuantizedVolumeDoesNotGetStuckTest(int sample_rate);
385 void RunManualVolumeChangeIsPossibleTest(int sample_rate); 385 void RunManualVolumeChangeIsPossibleTest(int sample_rate);
386 void StreamParametersTest(Format format); 386 void StreamParametersTest(Format format);
387 int ProcessStreamChooser(Format format); 387 int ProcessStreamChooser(Format format);
388 int AnalyzeReverseStreamChooser(Format format); 388 int AnalyzeReverseStreamChooser(Format format);
389 void ProcessDebugDump(const std::string& in_filename, 389 void ProcessDebugDump(const std::string& in_filename,
390 const std::string& out_filename, 390 const std::string& out_filename,
391 Format format); 391 Format format,
392 int max_size_bytes);
392 void VerifyDebugDumpTest(Format format); 393 void VerifyDebugDumpTest(Format format);
393 394
394 const std::string output_path_; 395 const std::string output_path_;
395 const std::string ref_path_; 396 const std::string ref_path_;
396 const std::string ref_filename_; 397 const std::string ref_filename_;
397 rtc::scoped_ptr<AudioProcessing> apm_; 398 rtc::scoped_ptr<AudioProcessing> apm_;
398 AudioFrame* frame_; 399 AudioFrame* frame_;
399 AudioFrame* revframe_; 400 AudioFrame* revframe_;
400 rtc::scoped_ptr<ChannelBuffer<float> > float_cb_; 401 rtc::scoped_ptr<ChannelBuffer<float> > float_cb_;
401 rtc::scoped_ptr<ChannelBuffer<float> > revfloat_cb_; 402 rtc::scoped_ptr<ChannelBuffer<float> > revfloat_cb_;
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 frame_copy.CopyFrom(*frame_); 1705 frame_copy.CopyFrom(*frame_);
1705 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0)); 1706 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
1706 apm_->echo_cancellation()->set_stream_drift_samples(0); 1707 apm_->echo_cancellation()->set_stream_drift_samples(0);
1707 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); 1708 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1708 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy)); 1709 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy));
1709 } 1710 }
1710 1711
1711 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1712 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1712 void ApmTest::ProcessDebugDump(const std::string& in_filename, 1713 void ApmTest::ProcessDebugDump(const std::string& in_filename,
1713 const std::string& out_filename, 1714 const std::string& out_filename,
1714 Format format) { 1715 Format format,
1716 int max_size_bytes) {
1715 FILE* in_file = fopen(in_filename.c_str(), "rb"); 1717 FILE* in_file = fopen(in_filename.c_str(), "rb");
1716 ASSERT_TRUE(in_file != NULL); 1718 ASSERT_TRUE(in_file != NULL);
1717 audioproc::Event event_msg; 1719 audioproc::Event event_msg;
1718 bool first_init = true; 1720 bool first_init = true;
1719 1721
1720 while (ReadMessageFromFile(in_file, &event_msg)) { 1722 while (ReadMessageFromFile(in_file, &event_msg)) {
1721 if (event_msg.type() == audioproc::Event::INIT) { 1723 if (event_msg.type() == audioproc::Event::INIT) {
1722 const audioproc::Init msg = event_msg.init(); 1724 const audioproc::Init msg = event_msg.init();
1723 int reverse_sample_rate = msg.sample_rate(); 1725 int reverse_sample_rate = msg.sample_rate();
1724 if (msg.has_reverse_sample_rate()) { 1726 if (msg.has_reverse_sample_rate()) {
1725 reverse_sample_rate = msg.reverse_sample_rate(); 1727 reverse_sample_rate = msg.reverse_sample_rate();
1726 } 1728 }
1727 int output_sample_rate = msg.sample_rate(); 1729 int output_sample_rate = msg.sample_rate();
1728 if (msg.has_output_sample_rate()) { 1730 if (msg.has_output_sample_rate()) {
1729 output_sample_rate = msg.output_sample_rate(); 1731 output_sample_rate = msg.output_sample_rate();
1730 } 1732 }
1731 1733
1732 Init(msg.sample_rate(), 1734 Init(msg.sample_rate(),
1733 output_sample_rate, 1735 output_sample_rate,
1734 reverse_sample_rate, 1736 reverse_sample_rate,
1735 msg.num_input_channels(), 1737 msg.num_input_channels(),
1736 msg.num_output_channels(), 1738 msg.num_output_channels(),
1737 msg.num_reverse_channels(), 1739 msg.num_reverse_channels(),
1738 false); 1740 false);
1739 if (first_init) { 1741 if (first_init) {
1740 // StartDebugRecording() writes an additional init message. Don't start 1742 // StartDebugRecording() writes an additional init message. Don't start
1741 // recording until after the first init to avoid the extra message. 1743 // recording until after the first init to avoid the extra message.
1742 EXPECT_NOERR(apm_->StartDebugRecording(out_filename.c_str())); 1744 EXPECT_NOERR(
1745 apm_->StartDebugRecording(out_filename.c_str(), max_size_bytes));
1743 first_init = false; 1746 first_init = false;
1744 } 1747 }
1745 1748
1746 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) { 1749 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) {
1747 const audioproc::ReverseStream msg = event_msg.reverse_stream(); 1750 const audioproc::ReverseStream msg = event_msg.reverse_stream();
1748 1751
1749 if (msg.channel_size() > 0) { 1752 if (msg.channel_size() > 0) {
1750 ASSERT_EQ(revframe_->num_channels_, msg.channel_size()); 1753 ASSERT_EQ(revframe_->num_channels_, msg.channel_size());
1751 for (int i = 0; i < msg.channel_size(); ++i) { 1754 for (int i = 0; i < msg.channel_size(); ++i) {
1752 memcpy(revfloat_cb_->channels()[i], 1755 memcpy(revfloat_cb_->channels()[i],
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 format_string = "_int"; 1808 format_string = "_int";
1806 break; 1809 break;
1807 case kFloatFormat: 1810 case kFloatFormat:
1808 format_string = "_float"; 1811 format_string = "_float";
1809 break; 1812 break;
1810 } 1813 }
1811 const std::string ref_filename = test::TempFilename( 1814 const std::string ref_filename = test::TempFilename(
1812 test::OutputPath(), std::string("ref") + format_string + "_aecdump"); 1815 test::OutputPath(), std::string("ref") + format_string + "_aecdump");
1813 const std::string out_filename = test::TempFilename( 1816 const std::string out_filename = test::TempFilename(
1814 test::OutputPath(), std::string("out") + format_string + "_aecdump"); 1817 test::OutputPath(), std::string("out") + format_string + "_aecdump");
1818 const std::string limited_filename = test::TempFilename(
1819 test::OutputPath(), std::string("limited") + format_string + "_aecdump");
1820 const size_t logging_limit_bytes = 100000;
1821 // We expect at least this many bytes in the created logfile.
1822 const size_t logging_expected_bytes = 95000;
1815 EnableAllComponents(); 1823 EnableAllComponents();
1816 ProcessDebugDump(in_filename, ref_filename, format); 1824 ProcessDebugDump(in_filename, ref_filename, format, -1);
1817 ProcessDebugDump(ref_filename, out_filename, format); 1825 ProcessDebugDump(ref_filename, out_filename, format, -1);
1826 ProcessDebugDump(ref_filename, limited_filename, format, logging_limit_bytes);
1818 1827
1819 FILE* ref_file = fopen(ref_filename.c_str(), "rb"); 1828 FILE* ref_file = fopen(ref_filename.c_str(), "rb");
1820 FILE* out_file = fopen(out_filename.c_str(), "rb"); 1829 FILE* out_file = fopen(out_filename.c_str(), "rb");
1830 FILE* limited_file = fopen(limited_filename.c_str(), "rb");
1821 ASSERT_TRUE(ref_file != NULL); 1831 ASSERT_TRUE(ref_file != NULL);
1822 ASSERT_TRUE(out_file != NULL); 1832 ASSERT_TRUE(out_file != NULL);
1833 ASSERT_TRUE(limited_file != NULL);
1823 rtc::scoped_ptr<uint8_t[]> ref_bytes; 1834 rtc::scoped_ptr<uint8_t[]> ref_bytes;
1824 rtc::scoped_ptr<uint8_t[]> out_bytes; 1835 rtc::scoped_ptr<uint8_t[]> out_bytes;
1836 rtc::scoped_ptr<uint8_t[]> limited_bytes;
1825 1837
1826 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes); 1838 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes);
1827 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes); 1839 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes);
1840 size_t limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes);
1828 size_t bytes_read = 0; 1841 size_t bytes_read = 0;
1842 size_t bytes_read_limited = 0;
1829 while (ref_size > 0 && out_size > 0) { 1843 while (ref_size > 0 && out_size > 0) {
1830 bytes_read += ref_size; 1844 bytes_read += ref_size;
1845 bytes_read_limited += limited_size;
1831 EXPECT_EQ(ref_size, out_size); 1846 EXPECT_EQ(ref_size, out_size);
1847 EXPECT_GE(ref_size, limited_size);
1832 EXPECT_EQ(0, memcmp(ref_bytes.get(), out_bytes.get(), ref_size)); 1848 EXPECT_EQ(0, memcmp(ref_bytes.get(), out_bytes.get(), ref_size));
1849 EXPECT_EQ(0, memcmp(ref_bytes.get(), limited_bytes.get(), limited_size));
1833 ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes); 1850 ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes);
1834 out_size = ReadMessageBytesFromFile(out_file, &out_bytes); 1851 out_size = ReadMessageBytesFromFile(out_file, &out_bytes);
1852 limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes);
1835 } 1853 }
1836 EXPECT_GT(bytes_read, 0u); 1854 EXPECT_GT(bytes_read, 0u);
1855 EXPECT_GT(bytes_read_limited, logging_expected_bytes);
1856 EXPECT_LE(bytes_read_limited, logging_limit_bytes);
1837 EXPECT_NE(0, feof(ref_file)); 1857 EXPECT_NE(0, feof(ref_file));
1838 EXPECT_NE(0, feof(out_file)); 1858 EXPECT_NE(0, feof(out_file));
1859 EXPECT_NE(0, feof(limited_file));
1839 ASSERT_EQ(0, fclose(ref_file)); 1860 ASSERT_EQ(0, fclose(ref_file));
1840 ASSERT_EQ(0, fclose(out_file)); 1861 ASSERT_EQ(0, fclose(out_file));
1862 ASSERT_EQ(0, fclose(limited_file));
1841 remove(ref_filename.c_str()); 1863 remove(ref_filename.c_str());
1842 remove(out_filename.c_str()); 1864 remove(out_filename.c_str());
1865 remove(limited_filename.c_str());
1843 } 1866 }
1844 1867
1845 TEST_F(ApmTest, VerifyDebugDumpInt) { 1868 TEST_F(ApmTest, VerifyDebugDumpInt) {
1846 VerifyDebugDumpTest(kIntFormat); 1869 VerifyDebugDumpTest(kIntFormat);
1847 } 1870 }
1848 1871
1849 TEST_F(ApmTest, VerifyDebugDumpFloat) { 1872 TEST_F(ApmTest, VerifyDebugDumpFloat) {
1850 VerifyDebugDumpTest(kFloatFormat); 1873 VerifyDebugDumpTest(kFloatFormat);
1851 } 1874 }
1852 #endif 1875 #endif
1853 1876
1854 // TODO(andrew): expand test to verify output. 1877 // TODO(andrew): expand test to verify output.
1855 TEST_F(ApmTest, DebugDump) { 1878 TEST_F(ApmTest, DebugDump) {
1856 const std::string filename = 1879 const std::string filename =
1857 test::TempFilename(test::OutputPath(), "debug_aec"); 1880 test::TempFilename(test::OutputPath(), "debug_aec");
1858 EXPECT_EQ(apm_->kNullPointerError, 1881 EXPECT_EQ(apm_->kNullPointerError,
1859 apm_->StartDebugRecording(static_cast<const char*>(NULL))); 1882 apm_->StartDebugRecording(static_cast<const char*>(NULL), -1));
1860 1883
1861 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1884 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1862 // Stopping without having started should be OK. 1885 // Stopping without having started should be OK.
1863 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1886 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1864 1887
1865 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(filename.c_str())); 1888 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(filename.c_str(), -1));
1866 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); 1889 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1867 EXPECT_EQ(apm_->kNoError, apm_->AnalyzeReverseStream(revframe_)); 1890 EXPECT_EQ(apm_->kNoError, apm_->AnalyzeReverseStream(revframe_));
1868 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1891 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1869 1892
1870 // Verify the file has been written. 1893 // Verify the file has been written.
1871 FILE* fid = fopen(filename.c_str(), "r"); 1894 FILE* fid = fopen(filename.c_str(), "r");
1872 ASSERT_TRUE(fid != NULL); 1895 ASSERT_TRUE(fid != NULL);
1873 1896
1874 // Clean it up. 1897 // Clean it up.
1875 ASSERT_EQ(0, fclose(fid)); 1898 ASSERT_EQ(0, fclose(fid));
1876 ASSERT_EQ(0, remove(filename.c_str())); 1899 ASSERT_EQ(0, remove(filename.c_str()));
1877 #else 1900 #else
1878 EXPECT_EQ(apm_->kUnsupportedFunctionError, 1901 EXPECT_EQ(apm_->kUnsupportedFunctionError,
1879 apm_->StartDebugRecording(filename.c_str())); 1902 apm_->StartDebugRecording(filename.c_str(), -1));
1880 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); 1903 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording());
1881 1904
1882 // Verify the file has NOT been written. 1905 // Verify the file has NOT been written.
1883 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL); 1906 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL);
1884 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1907 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1885 } 1908 }
1886 1909
1887 // TODO(andrew): expand test to verify output. 1910 // TODO(andrew): expand test to verify output.
1888 TEST_F(ApmTest, DebugDumpFromFileHandle) { 1911 TEST_F(ApmTest, DebugDumpFromFileHandle) {
1889 FILE* fid = NULL; 1912 FILE* fid = NULL;
1890 EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid)); 1913 EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid, -1));
1891 const std::string filename = 1914 const std::string filename =
1892 test::TempFilename(test::OutputPath(), "debug_aec"); 1915 test::TempFilename(test::OutputPath(), "debug_aec");
1893 fid = fopen(filename.c_str(), "w"); 1916 fid = fopen(filename.c_str(), "w");
1894 ASSERT_TRUE(fid); 1917 ASSERT_TRUE(fid);
1895 1918
1896 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1919 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1897 // Stopping without having started should be OK. 1920 // Stopping without having started should be OK.
1898 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1921 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1899 1922
1900 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid)); 1923 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid, -1));
1901 EXPECT_EQ(apm_->kNoError, apm_->AnalyzeReverseStream(revframe_)); 1924 EXPECT_EQ(apm_->kNoError, apm_->AnalyzeReverseStream(revframe_));
1902 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); 1925 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1903 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording()); 1926 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1904 1927
1905 // Verify the file has been written. 1928 // Verify the file has been written.
1906 fid = fopen(filename.c_str(), "r"); 1929 fid = fopen(filename.c_str(), "r");
1907 ASSERT_TRUE(fid != NULL); 1930 ASSERT_TRUE(fid != NULL);
1908 1931
1909 // Clean it up. 1932 // Clean it up.
1910 ASSERT_EQ(0, fclose(fid)); 1933 ASSERT_EQ(0, fclose(fid));
1911 ASSERT_EQ(0, remove(filename.c_str())); 1934 ASSERT_EQ(0, remove(filename.c_str()));
1912 #else 1935 #else
1913 EXPECT_EQ(apm_->kUnsupportedFunctionError, 1936 EXPECT_EQ(apm_->kUnsupportedFunctionError,
1914 apm_->StartDebugRecording(fid)); 1937 apm_->StartDebugRecording(fid, -1));
1915 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording()); 1938 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording());
1916 1939
1917 ASSERT_EQ(0, fclose(fid)); 1940 ASSERT_EQ(0, fclose(fid));
1918 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1941 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1919 } 1942 }
1920 1943
1921 TEST_F(ApmTest, FloatAndIntInterfacesGiveSimilarResults) { 1944 TEST_F(ApmTest, FloatAndIntInterfacesGiveSimilarResults) {
1922 audioproc::OutputData ref_data; 1945 audioproc::OutputData ref_data;
1923 OpenFileAndReadMessage(ref_filename_, &ref_data); 1946 OpenFileAndReadMessage(ref_filename_, &ref_data);
1924 1947
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), 2766 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35),
2744 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), 2767 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0),
2745 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), 2768 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20),
2746 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), 2769 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20),
2747 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20), 2770 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20),
2748 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); 2771 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0)));
2749 #endif 2772 #endif
2750 2773
2751 } // namespace 2774 } // namespace
2752 } // namespace webrtc 2775 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698