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

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

Issue 1413483003: 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: Initial version Created 5 years, 2 months 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 if (max_size_bytes != -1) {
1745 EXPECT_NOERR(
1746 apm_->StartDebugRecording(out_filename.c_str(), max_size_bytes));
1747 } else {
1748 EXPECT_NOERR(apm_->StartDebugRecording(out_filename.c_str()));
1749 }
1743 first_init = false; 1750 first_init = false;
1744 } 1751 }
1745 1752
1746 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) { 1753 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) {
1747 const audioproc::ReverseStream msg = event_msg.reverse_stream(); 1754 const audioproc::ReverseStream msg = event_msg.reverse_stream();
1748 1755
1749 if (msg.channel_size() > 0) { 1756 if (msg.channel_size() > 0) {
1750 ASSERT_EQ(revframe_->num_channels_, msg.channel_size()); 1757 ASSERT_EQ(revframe_->num_channels_, msg.channel_size());
1751 for (int i = 0; i < msg.channel_size(); ++i) { 1758 for (int i = 0; i < msg.channel_size(); ++i) {
1752 memcpy(revfloat_cb_->channels()[i], 1759 memcpy(revfloat_cb_->channels()[i],
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 format_string = "_int"; 1812 format_string = "_int";
1806 break; 1813 break;
1807 case kFloatFormat: 1814 case kFloatFormat:
1808 format_string = "_float"; 1815 format_string = "_float";
1809 break; 1816 break;
1810 } 1817 }
1811 const std::string ref_filename = test::TempFilename( 1818 const std::string ref_filename = test::TempFilename(
1812 test::OutputPath(), std::string("ref") + format_string + "_aecdump"); 1819 test::OutputPath(), std::string("ref") + format_string + "_aecdump");
1813 const std::string out_filename = test::TempFilename( 1820 const std::string out_filename = test::TempFilename(
1814 test::OutputPath(), std::string("out") + format_string + "_aecdump"); 1821 test::OutputPath(), std::string("out") + format_string + "_aecdump");
1822 const std::string limited_filename = test::TempFilename(
1823 test::OutputPath(), std::string("limited") + format_string + "_aecdump");
1824 const size_t logging_limit_bytes = 100000;
1815 EnableAllComponents(); 1825 EnableAllComponents();
1816 ProcessDebugDump(in_filename, ref_filename, format); 1826 ProcessDebugDump(in_filename, ref_filename, format, -1);
1817 ProcessDebugDump(ref_filename, out_filename, format); 1827 ProcessDebugDump(ref_filename, out_filename, format, -1);
1828 ProcessDebugDump(ref_filename, limited_filename, format, logging_limit_bytes);
1818 1829
1819 FILE* ref_file = fopen(ref_filename.c_str(), "rb"); 1830 FILE* ref_file = fopen(ref_filename.c_str(), "rb");
1820 FILE* out_file = fopen(out_filename.c_str(), "rb"); 1831 FILE* out_file = fopen(out_filename.c_str(), "rb");
1832 FILE* limited_file = fopen(limited_filename.c_str(), "rb");
1821 ASSERT_TRUE(ref_file != NULL); 1833 ASSERT_TRUE(ref_file != NULL);
1822 ASSERT_TRUE(out_file != NULL); 1834 ASSERT_TRUE(out_file != NULL);
1835 ASSERT_TRUE(limited_file != NULL);
1823 rtc::scoped_ptr<uint8_t[]> ref_bytes; 1836 rtc::scoped_ptr<uint8_t[]> ref_bytes;
1824 rtc::scoped_ptr<uint8_t[]> out_bytes; 1837 rtc::scoped_ptr<uint8_t[]> out_bytes;
1838 rtc::scoped_ptr<uint8_t[]> limited_bytes;
1825 1839
1826 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes); 1840 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes);
1827 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes); 1841 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes);
1842 size_t limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes);
1828 size_t bytes_read = 0; 1843 size_t bytes_read = 0;
1844 size_t bytes_read_limited = 0;
1829 while (ref_size > 0 && out_size > 0) { 1845 while (ref_size > 0 && out_size > 0) {
1830 bytes_read += ref_size; 1846 bytes_read += ref_size;
1847 bytes_read_limited += limited_size;
1831 EXPECT_EQ(ref_size, out_size); 1848 EXPECT_EQ(ref_size, out_size);
1849 EXPECT_GE(ref_size, limited_size);
1832 EXPECT_EQ(0, memcmp(ref_bytes.get(), out_bytes.get(), ref_size)); 1850 EXPECT_EQ(0, memcmp(ref_bytes.get(), out_bytes.get(), ref_size));
1851 EXPECT_EQ(0, memcmp(ref_bytes.get(), limited_bytes.get(), limited_size));
1833 ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes); 1852 ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes);
1834 out_size = ReadMessageBytesFromFile(out_file, &out_bytes); 1853 out_size = ReadMessageBytesFromFile(out_file, &out_bytes);
1854 limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes);
1835 } 1855 }
1836 EXPECT_GT(bytes_read, 0u); 1856 EXPECT_GT(bytes_read, 0u);
1857 EXPECT_GT(bytes_read_limited, 0u);
1858 EXPECT_LE(bytes_read_limited, logging_limit_bytes);
hlundin-webrtc 2015/10/30 08:02:21 Should you maybe test that the actual file size en
ivoc 2015/11/05 13:14:46 I added an appropriate lower bound.
1837 EXPECT_NE(0, feof(ref_file)); 1859 EXPECT_NE(0, feof(ref_file));
1838 EXPECT_NE(0, feof(out_file)); 1860 EXPECT_NE(0, feof(out_file));
1861 EXPECT_NE(0, feof(limited_file));
1839 ASSERT_EQ(0, fclose(ref_file)); 1862 ASSERT_EQ(0, fclose(ref_file));
1840 ASSERT_EQ(0, fclose(out_file)); 1863 ASSERT_EQ(0, fclose(out_file));
1864 ASSERT_EQ(0, fclose(limited_file));
1841 remove(ref_filename.c_str()); 1865 remove(ref_filename.c_str());
1842 remove(out_filename.c_str()); 1866 remove(out_filename.c_str());
1867 remove(limited_filename.c_str());
1843 } 1868 }
1844 1869
1845 TEST_F(ApmTest, VerifyDebugDumpInt) { 1870 TEST_F(ApmTest, VerifyDebugDumpInt) {
1846 VerifyDebugDumpTest(kIntFormat); 1871 VerifyDebugDumpTest(kIntFormat);
1847 } 1872 }
1848 1873
1849 TEST_F(ApmTest, VerifyDebugDumpFloat) { 1874 TEST_F(ApmTest, VerifyDebugDumpFloat) {
1850 VerifyDebugDumpTest(kFloatFormat); 1875 VerifyDebugDumpTest(kFloatFormat);
1851 } 1876 }
1852 #endif 1877 #endif
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
2747 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20), 2772 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20),
2748 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); 2773 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0)));
2749 #endif 2774 #endif
2750 2775
2751 // TODO(henrike): re-implement functionality lost when removing the old main 2776 // TODO(henrike): re-implement functionality lost when removing the old main
2752 // function. See 2777 // function. See
2753 // https://code.google.com/p/webrtc/issues/detail?id=1981 2778 // https://code.google.com/p/webrtc/issues/detail?id=1981
2754 2779
2755 } // namespace 2780 } // namespace
2756 } // namespace webrtc 2781 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698