2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Unit tests for Expand class.
|
|
|
|
|
|
2014-06-09 08:10:28 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/expand.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2016-09-28 17:42:01 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
Revert of Safe numeric library: base/numerics (copied from Chromium) (patchset #11 id:250001 of https://codereview.webrtc.org/1753293002/ )
Reason for revert:
Looks like the Chrome iOS build is broken because of these two changes. So I'm going to have to revert. Here's the error:
https://build.chromium.org/p/tryserver.chromium.mac/builders/ios_rel_device_ninja/builds/185624/steps/compile/logs/stdio
FAILED: rm -f arch/libsafe_numerics.arm64.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.arm64.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
FAILED: rm -f arch/libsafe_numerics.armv7.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.armv7.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
ninja: build stopped: subcommand failed.
Original issue's description:
> Safe numeric library added: base/numerics (copied from Chromium)
>
> This copies the contents (unittest excluded) of base/numerics in
> chromium to base/numerics in webrtc. Files added:
> - safe_conversions.h
> - safe_conversions_impl.h
> - safe_math.h
> - safe_math_impl.h
>
> A really old version of safe_conversions[_impl].h previously existed in
> base/, this has been deleted and sources using it have been updated
> to include the new base/numerics/safe_converions.h.
>
> This CL also adds a DEPS file to webrtc/base.
>
> NOPRESUBMIT=True
> BUG=webrtc:5548, webrtc:5623
>
> Committed: https://crrev.com/de1c81b2d2196be611674aa6019b9db3a9329042
> Cr-Commit-Position: refs/heads/master@{#11907}
TBR=kjellander@webrtc.org,kwiberg@webrtc.org,tina.legrand@webrtc.org,hbos@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5548, webrtc:5623
Review URL: https://codereview.webrtc.org/1792613002 .
Cr-Commit-Position: refs/heads/master@{#11965}
2016-03-11 17:12:32 -08:00
|
|
|
#include "webrtc/base/safe_conversions.h"
|
2015-08-18 14:58:09 +02:00
|
|
|
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
2014-06-09 08:10:28 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/background_noise.h"
|
|
|
|
|
#include "webrtc/modules/audio_coding/neteq/random_vector.h"
|
2015-08-18 14:58:09 +02:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/statistics_calculator.h"
|
2014-06-09 08:10:28 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
|
2015-08-18 14:58:09 +02:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
|
|
|
|
|
#include "webrtc/test/testsupport/fileutils.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
TEST(Expand, CreateAndDestroy) {
|
|
|
|
|
int fs = 8000;
|
|
|
|
|
size_t channels = 1;
|
|
|
|
|
BackgroundNoise bgn(channels);
|
|
|
|
|
SyncBuffer sync_buffer(1, 1000);
|
|
|
|
|
RandomVector random_vector;
|
2015-08-18 14:58:09 +02:00
|
|
|
StatisticsCalculator statistics;
|
|
|
|
|
Expand expand(&bgn, &sync_buffer, &random_vector, &statistics, fs, channels);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-14 10:18:45 +00:00
|
|
|
TEST(Expand, CreateUsingFactory) {
|
|
|
|
|
int fs = 8000;
|
|
|
|
|
size_t channels = 1;
|
|
|
|
|
BackgroundNoise bgn(channels);
|
|
|
|
|
SyncBuffer sync_buffer(1, 1000);
|
|
|
|
|
RandomVector random_vector;
|
2015-08-18 14:58:09 +02:00
|
|
|
StatisticsCalculator statistics;
|
2014-01-14 10:18:45 +00:00
|
|
|
ExpandFactory expand_factory;
|
2015-08-18 14:58:09 +02:00
|
|
|
Expand* expand = expand_factory.Create(&bgn, &sync_buffer, &random_vector,
|
|
|
|
|
&statistics, fs, channels);
|
2014-01-14 10:18:45 +00:00
|
|
|
EXPECT_TRUE(expand != NULL);
|
|
|
|
|
delete expand;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 14:58:09 +02:00
|
|
|
namespace {
|
|
|
|
|
class FakeStatisticsCalculator : public StatisticsCalculator {
|
|
|
|
|
public:
|
|
|
|
|
void LogDelayedPacketOutageEvent(int outage_duration_ms) override {
|
|
|
|
|
last_outage_duration_ms_ = outage_duration_ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int last_outage_duration_ms() const { return last_outage_duration_ms_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int last_outage_duration_ms_ = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// This is the same size that is given to the SyncBuffer object in NetEq.
|
|
|
|
|
const size_t kNetEqSyncBufferLengthMs = 720;
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
class ExpandTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
ExpandTest()
|
|
|
|
|
: input_file_(test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
|
|
|
|
|
32000),
|
|
|
|
|
test_sample_rate_hz_(32000),
|
|
|
|
|
num_channels_(1),
|
|
|
|
|
background_noise_(num_channels_),
|
|
|
|
|
sync_buffer_(num_channels_,
|
|
|
|
|
kNetEqSyncBufferLengthMs * test_sample_rate_hz_ / 1000),
|
|
|
|
|
expand_(&background_noise_,
|
|
|
|
|
&sync_buffer_,
|
|
|
|
|
&random_vector_,
|
|
|
|
|
&statistics_,
|
|
|
|
|
test_sample_rate_hz_,
|
|
|
|
|
num_channels_) {
|
|
|
|
|
WebRtcSpl_Init();
|
|
|
|
|
input_file_.set_output_rate_hz(test_sample_rate_hz_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
// Fast-forward the input file until there is speech (about 1.1 second into
|
|
|
|
|
// the file).
|
|
|
|
|
const size_t speech_start_samples =
|
|
|
|
|
static_cast<size_t>(test_sample_rate_hz_ * 1.1f);
|
|
|
|
|
ASSERT_TRUE(input_file_.Seek(speech_start_samples));
|
|
|
|
|
|
|
|
|
|
// Pre-load the sync buffer with speech data.
|
2016-05-10 19:55:56 +02:00
|
|
|
std::unique_ptr<int16_t[]> temp(new int16_t[sync_buffer_.Size()]);
|
|
|
|
|
ASSERT_TRUE(input_file_.Read(sync_buffer_.Size(), temp.get()));
|
|
|
|
|
sync_buffer_.Channel(0).OverwriteAt(temp.get(), sync_buffer_.Size(), 0);
|
2015-08-18 14:58:09 +02:00
|
|
|
ASSERT_EQ(1u, num_channels_) << "Fix: Must populate all channels.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test::ResampleInputAudioFile input_file_;
|
|
|
|
|
int test_sample_rate_hz_;
|
|
|
|
|
size_t num_channels_;
|
|
|
|
|
BackgroundNoise background_noise_;
|
|
|
|
|
SyncBuffer sync_buffer_;
|
|
|
|
|
RandomVector random_vector_;
|
|
|
|
|
FakeStatisticsCalculator statistics_;
|
|
|
|
|
Expand expand_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// This test calls the expand object to produce concealment data a few times,
|
|
|
|
|
// and then ends by calling SetParametersForNormalAfterExpand. This simulates
|
|
|
|
|
// the situation where the packet next up for decoding was just delayed, not
|
|
|
|
|
// lost.
|
|
|
|
|
TEST_F(ExpandTest, DelayedPacketOutage) {
|
|
|
|
|
AudioMultiVector output(num_channels_);
|
|
|
|
|
size_t sum_output_len_samples = 0;
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
|
EXPECT_EQ(0, expand_.Process(&output));
|
|
|
|
|
EXPECT_GT(output.Size(), 0u);
|
|
|
|
|
sum_output_len_samples += output.Size();
|
|
|
|
|
EXPECT_EQ(0, statistics_.last_outage_duration_ms());
|
|
|
|
|
}
|
|
|
|
|
expand_.SetParametersForNormalAfterExpand();
|
|
|
|
|
// Convert |sum_output_len_samples| to milliseconds.
|
|
|
|
|
EXPECT_EQ(rtc::checked_cast<int>(sum_output_len_samples /
|
|
|
|
|
(test_sample_rate_hz_ / 1000)),
|
|
|
|
|
statistics_.last_outage_duration_ms());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This test is similar to DelayedPacketOutage, but ends by calling
|
|
|
|
|
// SetParametersForMergeAfterExpand. This simulates the situation where the
|
|
|
|
|
// packet next up for decoding was actually lost (or at least a later packet
|
|
|
|
|
// arrived before it).
|
|
|
|
|
TEST_F(ExpandTest, LostPacketOutage) {
|
|
|
|
|
AudioMultiVector output(num_channels_);
|
|
|
|
|
size_t sum_output_len_samples = 0;
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
|
EXPECT_EQ(0, expand_.Process(&output));
|
|
|
|
|
EXPECT_GT(output.Size(), 0u);
|
|
|
|
|
sum_output_len_samples += output.Size();
|
|
|
|
|
EXPECT_EQ(0, statistics_.last_outage_duration_ms());
|
|
|
|
|
}
|
|
|
|
|
expand_.SetParametersForMergeAfterExpand();
|
|
|
|
|
EXPECT_EQ(0, statistics_.last_outage_duration_ms());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This test is similar to the DelayedPacketOutage test above, but with the
|
|
|
|
|
// difference that Expand::Reset() is called after 5 calls to Expand::Process().
|
|
|
|
|
// This should reset the statistics, and will in the end lead to an outage of
|
|
|
|
|
// 5 periods instead of 10.
|
|
|
|
|
TEST_F(ExpandTest, CheckOutageStatsAfterReset) {
|
|
|
|
|
AudioMultiVector output(num_channels_);
|
|
|
|
|
size_t sum_output_len_samples = 0;
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
|
EXPECT_EQ(0, expand_.Process(&output));
|
|
|
|
|
EXPECT_GT(output.Size(), 0u);
|
|
|
|
|
sum_output_len_samples += output.Size();
|
|
|
|
|
if (i == 5) {
|
|
|
|
|
expand_.Reset();
|
|
|
|
|
sum_output_len_samples = 0;
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(0, statistics_.last_outage_duration_ms());
|
|
|
|
|
}
|
|
|
|
|
expand_.SetParametersForNormalAfterExpand();
|
|
|
|
|
// Convert |sum_output_len_samples| to milliseconds.
|
|
|
|
|
EXPECT_EQ(rtc::checked_cast<int>(sum_output_len_samples /
|
|
|
|
|
(test_sample_rate_hz_ / 1000)),
|
|
|
|
|
statistics_.last_outage_duration_ms());
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-10 05:54:35 -07:00
|
|
|
namespace {
|
|
|
|
|
// Runs expand until Muted() returns true. Times out after 1000 calls.
|
|
|
|
|
void ExpandUntilMuted(size_t num_channels, Expand* expand) {
|
|
|
|
|
EXPECT_FALSE(expand->Muted()) << "Instance is muted from the start";
|
|
|
|
|
AudioMultiVector output(num_channels);
|
|
|
|
|
int num_calls = 0;
|
|
|
|
|
while (!expand->Muted()) {
|
|
|
|
|
ASSERT_LT(num_calls++, 1000) << "Test timed out";
|
|
|
|
|
EXPECT_EQ(0, expand->Process(&output));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
// Verifies that Muted() returns true after a long expand period. Also verifies
|
|
|
|
|
// that Muted() is reset to false after calling Reset(),
|
|
|
|
|
// SetParametersForMergeAfterExpand() and SetParametersForNormalAfterExpand().
|
|
|
|
|
TEST_F(ExpandTest, Muted) {
|
|
|
|
|
ExpandUntilMuted(num_channels_, &expand_);
|
|
|
|
|
expand_.Reset();
|
|
|
|
|
EXPECT_FALSE(expand_.Muted()); // Should be back to unmuted.
|
|
|
|
|
|
|
|
|
|
ExpandUntilMuted(num_channels_, &expand_);
|
|
|
|
|
expand_.SetParametersForMergeAfterExpand();
|
|
|
|
|
EXPECT_FALSE(expand_.Muted()); // Should be back to unmuted.
|
|
|
|
|
|
|
|
|
|
expand_.Reset(); // Must reset in order to start a new expand period.
|
|
|
|
|
ExpandUntilMuted(num_channels_, &expand_);
|
|
|
|
|
expand_.SetParametersForNormalAfterExpand();
|
|
|
|
|
EXPECT_FALSE(expand_.Muted()); // Should be back to unmuted.
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// TODO(hlundin): Write more tests.
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|