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}
This commit is contained in:
@ -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)) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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()) {
|
||||
|
@ -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) {
|
||||
|
@ -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");
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user