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

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

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

Powered by Google App Engine
This is Rietveld 408576698