aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules
diff options
context:
space:
mode:
authorHenrik Lundin <henrik.lundin@webrtc.org>2015-12-10 16:24:39 +0100
committerHenrik Lundin <henrik.lundin@webrtc.org>2015-12-10 15:24:50 +0000
commit4d68208a2089bfb7c9bf87f06722033a9e82a2a3 (patch)
tree498cef1ef4aeb903796c59cbd3c8e89ab539a262 /webrtc/modules
parentc490e01bd1bd4a0d754ed5f746b95ac03136346f (diff)
downloadwebrtc-4d68208a2089bfb7c9bf87f06722033a9e82a2a3.tar.gz
Reduce the runtime of some ACM tests in modules_tests
By reducing the length of the audio input, the total runtime of $ out/Debug/modules_tests --gtest_filter=AudioCodingModuleTest.* is reduced by more than 10x, when run single-threaded. The PCMFile helper class is extended with a FastForward method (to skip initial silence in the test files) and a limiter on how much to read. BUG=webrtc:2463 R=ivoc@webrtc.org Review URL: https://codereview.webrtc.org/1513223002 . Cr-Commit-Position: refs/heads/master@{#10973}
Diffstat (limited to 'webrtc/modules')
-rw-r--r--webrtc/modules/audio_coding/test/EncodeDecodeTest.cc4
-rw-r--r--webrtc/modules/audio_coding/test/PCMFile.cc19
-rw-r--r--webrtc/modules/audio_coding/test/PCMFile.h12
-rw-r--r--webrtc/modules/audio_coding/test/TestAllCodecs.cc6
-rw-r--r--webrtc/modules/audio_coding/test/TestRedFec.cc4
-rw-r--r--webrtc/modules/audio_coding/test/TestStereo.cc8
-rw-r--r--webrtc/modules/audio_coding/test/TestVADDTX.cc5
-rw-r--r--webrtc/modules/audio_coding/test/iSACTest.cc4
-rw-r--r--webrtc/modules/audio_coding/test/opus_test.cc8
9 files changed, 65 insertions, 5 deletions
diff --git a/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc b/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc
index ef45705e20..e0222afbe0 100644
--- a/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc
+++ b/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc
@@ -63,6 +63,10 @@ void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream,
if (channels == 2) {
_pcmFile.ReadStereo(true);
}
+ // Set test length to 500 ms (50 blocks of 10 ms each).
+ _pcmFile.SetNum10MsBlocksToRead(50);
+ // Fast-forward 1 second (100 blocks) since the file starts with silence.
+ _pcmFile.FastForward(100);
// Set the codec for the current test.
if ((testMode == 0) || (testMode == 1)) {
diff --git a/webrtc/modules/audio_coding/test/PCMFile.cc b/webrtc/modules/audio_coding/test/PCMFile.cc
index 0466e0222c..9289d73baa 100644
--- a/webrtc/modules/audio_coding/test/PCMFile.cc
+++ b/webrtc/modules/audio_coding/test/PCMFile.cc
@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "PCMFile.h"
+#include "webrtc/modules/audio_coding/test/PCMFile.h"
#include <ctype.h>
#include <stdio.h>
@@ -137,6 +137,9 @@ int32_t PCMFile::Read10MsData(AudioFrame& audio_frame) {
audio_frame.num_channels_ = channels;
audio_frame.timestamp_ = timestamp_;
timestamp_ += samples_10ms_;
+ ++blocks_read_;
+ if (num_10ms_blocks_to_read_ && blocks_read_ >= *num_10ms_blocks_to_read_)
+ end_of_file_ = true;
return samples_10ms_;
}
@@ -182,11 +185,21 @@ void PCMFile::Write10MsData(int16_t* playout_buffer, size_t length_smpls) {
void PCMFile::Close() {
fclose(pcm_file_);
pcm_file_ = NULL;
+ blocks_read_ = 0;
+}
+
+void PCMFile::FastForward(int num_10ms_blocks) {
+ const int channels = read_stereo_ ? 2 : 1;
+ long num_bytes_to_move =
+ num_10ms_blocks * sizeof(int16_t) * samples_10ms_ * channels;
+ int error = fseek(pcm_file_, num_bytes_to_move, SEEK_CUR);
+ RTC_DCHECK_EQ(error, 0);
}
void PCMFile::Rewind() {
rewind(pcm_file_);
end_of_file_ = false;
+ blocks_read_ = 0;
}
bool PCMFile::Rewinded() {
@@ -201,4 +214,8 @@ void PCMFile::ReadStereo(bool is_stereo) {
read_stereo_ = is_stereo;
}
+void PCMFile::SetNum10MsBlocksToRead(int value) {
+ num_10ms_blocks_to_read_ = rtc::Optional<int>(value);
+}
+
} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/test/PCMFile.h b/webrtc/modules/audio_coding/test/PCMFile.h
index 9365180208..840933a1bd 100644
--- a/webrtc/modules/audio_coding/test/PCMFile.h
+++ b/webrtc/modules/audio_coding/test/PCMFile.h
@@ -16,6 +16,7 @@
#include <string>
+#include "webrtc/base/optional.h"
#include "webrtc/modules/include/module_common_types.h"
#include "webrtc/typedefs.h"
@@ -45,12 +46,21 @@ class PCMFile {
bool EndOfFile() const {
return end_of_file_;
}
+ // Moves forward the specified number of 10 ms blocks. If a limit has been set
+ // with SetNum10MsBlocksToRead, fast-forwarding does not count towards this
+ // limit.
+ void FastForward(int num_10ms_blocks);
void Rewind();
static int16_t ChooseFile(std::string* file_name, int16_t max_len,
uint16_t* frequency_hz);
bool Rewinded();
void SaveStereo(bool is_stereo = true);
void ReadStereo(bool is_stereo = true);
+ // If set, the reading will stop after the specified number of blocks have
+ // been read. When that has happened, EndOfFile() will return true. Calling
+ // Rewind() will reset the counter and start over.
+ void SetNum10MsBlocksToRead(int value);
+
private:
FILE* pcm_file_;
uint16_t samples_10ms_;
@@ -61,6 +71,8 @@ class PCMFile {
uint32_t timestamp_;
bool read_stereo_;
bool save_stereo_;
+ rtc::Optional<int> num_10ms_blocks_to_read_;
+ int blocks_read_ = 0;
};
} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/test/TestAllCodecs.cc b/webrtc/modules/audio_coding/test/TestAllCodecs.cc
index 21ce7c11aa..bacfd37188 100644
--- a/webrtc/modules/audio_coding/test/TestAllCodecs.cc
+++ b/webrtc/modules/audio_coding/test/TestAllCodecs.cc
@@ -422,8 +422,12 @@ void TestAllCodecs::Run(TestPack* channel) {
uint32_t timestamp_diff;
channel->reset_payload_size();
int error_count = 0;
-
int counter = 0;
+ // Set test length to 500 ms (50 blocks of 10 ms each).
+ infile_a_.SetNum10MsBlocksToRead(50);
+ // Fast-forward 1 second (100 blocks) since the file starts with silence.
+ infile_a_.FastForward(100);
+
while (!infile_a_.EndOfFile()) {
// Add 10 msec to ACM.
infile_a_.Read10MsData(audio_frame);
diff --git a/webrtc/modules/audio_coding/test/TestRedFec.cc b/webrtc/modules/audio_coding/test/TestRedFec.cc
index d54402657f..a1bdc04e53 100644
--- a/webrtc/modules/audio_coding/test/TestRedFec.cc
+++ b/webrtc/modules/audio_coding/test/TestRedFec.cc
@@ -453,6 +453,10 @@ int16_t TestRedFec::RegisterSendCodec(char side, const char* codecName,
void TestRedFec::Run() {
AudioFrame audioFrame;
int32_t outFreqHzB = _outFileB.SamplingFrequency();
+ // Set test length to 500 ms (50 blocks of 10 ms each).
+ _inFileA.SetNum10MsBlocksToRead(50);
+ // Fast-forward 1 second (100 blocks) since the file starts with silence.
+ _inFileA.FastForward(100);
while (!_inFileA.EndOfFile()) {
EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
diff --git a/webrtc/modules/audio_coding/test/TestStereo.cc b/webrtc/modules/audio_coding/test/TestStereo.cc
index 19f027b058..9bf560d323 100644
--- a/webrtc/modules/audio_coding/test/TestStereo.cc
+++ b/webrtc/modules/audio_coding/test/TestStereo.cc
@@ -735,6 +735,12 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
int error_count = 0;
int variable_bytes = 0;
int variable_packets = 0;
+ // Set test length to 500 ms (50 blocks of 10 ms each).
+ in_file_mono_->SetNum10MsBlocksToRead(50);
+ in_file_stereo_->SetNum10MsBlocksToRead(50);
+ // Fast-forward 1 second (100 blocks) since the files start with silence.
+ in_file_stereo_->FastForward(100);
+ in_file_mono_->FastForward(100);
while (1) {
// Simulate packet loss by setting |packet_loss_| to "true" in
@@ -800,7 +806,7 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
// such as Opus.
if (variable_packets > 0) {
variable_bytes /= variable_packets;
- EXPECT_NEAR(variable_bytes, pack_size_bytes_, 3);
+ EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
}
if (in_file_mono_->EndOfFile()) {
diff --git a/webrtc/modules/audio_coding/test/TestVADDTX.cc b/webrtc/modules/audio_coding/test/TestVADDTX.cc
index 98b1224762..a7d2c2134b 100644
--- a/webrtc/modules/audio_coding/test/TestVADDTX.cc
+++ b/webrtc/modules/audio_coding/test/TestVADDTX.cc
@@ -87,6 +87,11 @@ void TestVadDtx::Run(std::string in_filename, int frequency, int channels,
PCMFile in_file;
in_file.Open(in_filename, frequency, "rb");
in_file.ReadStereo(channels > 1);
+ // Set test length to 1000 ms (100 blocks of 10 ms each).
+ in_file.SetNum10MsBlocksToRead(100);
+ // Fast-forward both files 500 ms (50 blocks). The first second of the file is
+ // silence, but we want to keep half of that to test silence periods.
+ in_file.FastForward(50);
PCMFile out_file;
if (append) {
diff --git a/webrtc/modules/audio_coding/test/iSACTest.cc b/webrtc/modules/audio_coding/test/iSACTest.cc
index 09744b13c6..9f223fb81f 100644
--- a/webrtc/modules/audio_coding/test/iSACTest.cc
+++ b/webrtc/modules/audio_coding/test/iSACTest.cc
@@ -117,6 +117,10 @@ void ISACTest::Setup() {
EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
_inFileA.Open(file_name_swb_, 32000, "rb");
+ // Set test length to 500 ms (50 blocks of 10 ms each).
+ _inFileA.SetNum10MsBlocksToRead(50);
+ // Fast-forward 1 second (100 blocks) since the files start with silence.
+ _inFileA.FastForward(100);
std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
_outFileA.Open(fileNameA, 32000, "wb");
diff --git a/webrtc/modules/audio_coding/test/opus_test.cc b/webrtc/modules/audio_coding/test/opus_test.cc
index 3372a2a4a0..a68db910f5 100644
--- a/webrtc/modules/audio_coding/test/opus_test.cc
+++ b/webrtc/modules/audio_coding/test/opus_test.cc
@@ -235,8 +235,12 @@ void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate,
kOpusComplexity5));
#endif
- // Make sure the runtime is less than 60 seconds to pass Android test.
- for (size_t audio_length = 0; audio_length < 10000; audio_length += 10) {
+ // Fast-forward 1 second (100 blocks) since the files start with silence.
+ in_file_stereo_.FastForward(100);
+ in_file_mono_.FastForward(100);
+
+ // Limit the runtime to 1000 blocks of 10 ms each.
+ for (size_t audio_length = 0; audio_length < 1000; audio_length += 10) {
bool lost_packet = false;
// Get 10 msec of audio.