Migrate WebRTC test infra to ABSL_FLAG.

This is the last CL required to migrate WebRTC to ABSL_FLAG, rtc::Flag
will be removed soon after this one lands.

Bug: webrtc:10616
Change-Id: I2807cec39e28a2737d2c49e2dc23f2a6f98d08f0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/145727
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28606}
This commit is contained in:
Mirko Bonadei
2019-07-18 13:44:12 +02:00
committed by Commit Bot
parent 63741c7fa1
commit 2ab97f6f8e
48 changed files with 1959 additions and 1705 deletions

View File

@ -1593,10 +1593,10 @@ if (rtc_include_tests) {
":neteq_test_tools",
"../../api/audio_codecs:builtin_audio_decoder_factory",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
"../../test:fileutils",
"../../test:test_support",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
]
}
@ -1617,7 +1617,7 @@ if (rtc_include_tests) {
"../../api/audio_codecs/ilbc:audio_encoder_ilbc",
"../../api/audio_codecs/isac:audio_encoder_isac",
"../../api/audio_codecs/opus:audio_encoder_opus",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:safe_conversions",
]
sources = [
@ -1669,7 +1669,6 @@ if (rtc_include_tests) {
":neteq",
":neteq_test_tools",
":pcm16b",
"../../rtc_base:rtc_base_approved",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
@ -1691,6 +1690,7 @@ if (rtc_include_tests) {
"../../rtc_base:rtc_base_approved",
"../../test:test_main",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
]
}
@ -1704,8 +1704,10 @@ if (rtc_include_tests) {
deps = [
":neteq",
":neteq_test_support",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:checks",
"../../test:test_support",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
]
}
@ -1726,6 +1728,7 @@ if (rtc_include_tests) {
"../../test:fileutils",
"../../test:test_main",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
]
}
@ -1743,6 +1746,7 @@ if (rtc_include_tests) {
"../../rtc_base:rtc_base_approved",
"../../test:test_main",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
]
}
@ -1762,6 +1766,7 @@ if (rtc_include_tests) {
"../../test:fileutils",
"../../test:test_main",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
]
}
@ -1781,6 +1786,7 @@ if (rtc_include_tests) {
"../../test:fileutils",
"../../test:test_main",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
]
}
@ -2047,6 +2053,7 @@ if (rtc_include_tests) {
"codecs/opus/test",
"codecs/opus/test:test_unittest",
"//testing/gtest",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional",
]

View File

@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include "absl/flags/flag.h"
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
@ -40,9 +41,6 @@
#include "test/gtest.h"
#include "test/testsupport/file_utils.h"
// This must come after test/gtest.h
#include "rtc_base/flags.h" // NOLINT(build/include)
#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT
RTC_PUSH_IGNORING_WUNDEF()
#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
@ -53,7 +51,7 @@ RTC_PUSH_IGNORING_WUNDEF()
RTC_POP_IGNORING_WUNDEF()
#endif
WEBRTC_DEFINE_bool(gen_ref, false, "Generate reference files.");
ABSL_FLAG(bool, gen_ref, false, "Generate reference files.");
namespace webrtc {
@ -470,7 +468,7 @@ TEST_F(NetEqDecodingTest, MAYBE_TestBitExactness) {
"3689c9f0ab9e50cefab3e44c37c3d7aa0de82ca4");
DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum,
FLAG_gen_ref);
absl::GetFlag(FLAGS_gen_ref));
}
#if !defined(WEBRTC_IOS) && defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \
@ -499,7 +497,7 @@ TEST_F(NetEqDecodingTest, MAYBE_TestOpusBitExactness) {
"0b3d34baffaf651812ffaf06ea1b5ce45ea1c47a");
DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum,
FLAG_gen_ref);
absl::GetFlag(FLAGS_gen_ref));
}
#if !defined(WEBRTC_IOS) && defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \
@ -523,7 +521,7 @@ TEST_F(NetEqDecodingTest, MAYBE_TestOpusDtxBitExactness) {
"bab58dc587d956f326056d7340c96eb9d2d3cc21";
DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum,
FLAG_gen_ref);
absl::GetFlag(FLAGS_gen_ref));
}
// Use fax mode to avoid time-scaling. This is to simplify the testing of

View File

@ -10,13 +10,15 @@
#include <memory>
#include "absl/flags/flag.h"
#include "modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "rtc_base/checks.h"
#include "rtc_base/flags.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "test/testsupport/file_utils.h"
ABSL_FLAG(int, frame_size_ms, 20, "Codec frame size (milliseconds).");
using ::testing::InitGoogleTest;
namespace webrtc {
@ -24,28 +26,27 @@ namespace test {
namespace {
static const int kInputSampleRateKhz = 8;
static const int kOutputSampleRateKhz = 8;
WEBRTC_DEFINE_int(frame_size_ms, 20, "Codec frame size (milliseconds).");
} // namespace
class NetEqIlbcQualityTest : public NetEqQualityTest {
protected:
NetEqIlbcQualityTest()
: NetEqQualityTest(FLAG_frame_size_ms,
: NetEqQualityTest(absl::GetFlag(FLAGS_frame_size_ms),
kInputSampleRateKhz,
kOutputSampleRateKhz,
SdpAudioFormat("ilbc", 8000, 1)) {
// Flag validation
RTC_CHECK(FLAG_frame_size_ms == 20 || FLAG_frame_size_ms == 30 ||
FLAG_frame_size_ms == 40 || FLAG_frame_size_ms == 60)
RTC_CHECK(absl::GetFlag(FLAGS_frame_size_ms) == 20 ||
absl::GetFlag(FLAGS_frame_size_ms) == 30 ||
absl::GetFlag(FLAGS_frame_size_ms) == 40 ||
absl::GetFlag(FLAGS_frame_size_ms) == 60)
<< "Invalid frame size, should be 20, 30, 40, or 60 ms.";
}
void SetUp() override {
ASSERT_EQ(1u, channels_) << "iLBC supports only mono audio.";
AudioEncoderIlbcConfig config;
config.frame_size_ms = FLAG_frame_size_ms;
config.frame_size_ms = absl::GetFlag(FLAGS_frame_size_ms);
encoder_.reset(new AudioEncoderIlbcImpl(config, 102));
NetEqQualityTest::SetUp();
}

View File

@ -8,9 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "absl/flags/flag.h"
#include "modules/audio_coding/codecs/isac/fix/include/isacfix.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "rtc_base/flags.h"
ABSL_FLAG(int, bit_rate_kbps, 32, "Target bit rate (kbps).");
using ::testing::InitGoogleTest;
@ -20,9 +22,6 @@ namespace {
static const int kIsacBlockDurationMs = 30;
static const int kIsacInputSamplingKhz = 16;
static const int kIsacOutputSamplingKhz = 16;
WEBRTC_DEFINE_int(bit_rate_kbps, 32, "Target bit rate (kbps).");
} // namespace
class NetEqIsacQualityTest : public NetEqQualityTest {
@ -46,9 +45,10 @@ NetEqIsacQualityTest::NetEqIsacQualityTest()
kIsacOutputSamplingKhz,
SdpAudioFormat("isac", 16000, 1)),
isac_encoder_(NULL),
bit_rate_kbps_(FLAG_bit_rate_kbps) {
bit_rate_kbps_(absl::GetFlag(FLAGS_bit_rate_kbps)) {
// Flag validation
RTC_CHECK(FLAG_bit_rate_kbps >= 10 && FLAG_bit_rate_kbps <= 32)
RTC_CHECK(absl::GetFlag(FLAGS_bit_rate_kbps) >= 10 &&
absl::GetFlag(FLAGS_bit_rate_kbps) <= 32)
<< "Invalid bit rate, should be between 10 and 32 kbps.";
}

View File

@ -8,10 +8,30 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "absl/flags/flag.h"
#include "modules/audio_coding/codecs/opus/opus_inst.h"
#include "modules/audio_coding/codecs/opus/opus_interface.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "rtc_base/flags.h"
ABSL_FLAG(int, bit_rate_kbps, 32, "Target bit rate (kbps).");
ABSL_FLAG(int,
complexity,
10,
"Complexity: 0 ~ 10 -- defined as in Opus"
"specification.");
ABSL_FLAG(int, maxplaybackrate, 48000, "Maximum playback rate (Hz).");
ABSL_FLAG(int, application, 0, "Application mode: 0 -- VOIP, 1 -- Audio.");
ABSL_FLAG(int, reported_loss_rate, 10, "Reported percentile of packet loss.");
ABSL_FLAG(bool, fec, false, "Enable FEC for encoding (-nofec to disable).");
ABSL_FLAG(bool, dtx, false, "Enable DTX for encoding (-nodtx to disable).");
ABSL_FLAG(int, sub_packets, 1, "Number of sub packets to repacketize.");
using ::testing::InitGoogleTest;
@ -21,28 +41,6 @@ namespace {
static const int kOpusBlockDurationMs = 20;
static const int kOpusSamplingKhz = 48;
WEBRTC_DEFINE_int(bit_rate_kbps, 32, "Target bit rate (kbps).");
WEBRTC_DEFINE_int(complexity,
10,
"Complexity: 0 ~ 10 -- defined as in Opus"
"specification.");
WEBRTC_DEFINE_int(maxplaybackrate, 48000, "Maximum playback rate (Hz).");
WEBRTC_DEFINE_int(application, 0, "Application mode: 0 -- VOIP, 1 -- Audio.");
WEBRTC_DEFINE_int(reported_loss_rate,
10,
"Reported percentile of packet loss.");
WEBRTC_DEFINE_bool(fec, false, "Enable FEC for encoding (-nofec to disable).");
WEBRTC_DEFINE_bool(dtx, false, "Enable DTX for encoding (-nodtx to disable).");
WEBRTC_DEFINE_int(sub_packets, 1, "Number of sub packets to repacketize.");
} // namespace
class NetEqOpusQualityTest : public NetEqQualityTest {
@ -70,7 +68,7 @@ class NetEqOpusQualityTest : public NetEqQualityTest {
};
NetEqOpusQualityTest::NetEqOpusQualityTest()
: NetEqQualityTest(kOpusBlockDurationMs * FLAG_sub_packets,
: NetEqQualityTest(kOpusBlockDurationMs * absl::GetFlag(FLAGS_sub_packets),
kOpusSamplingKhz,
kOpusSamplingKhz,
SdpAudioFormat("opus", 48000, 2)),
@ -78,27 +76,32 @@ NetEqOpusQualityTest::NetEqOpusQualityTest()
repacketizer_(NULL),
sub_block_size_samples_(
static_cast<size_t>(kOpusBlockDurationMs * kOpusSamplingKhz)),
bit_rate_kbps_(FLAG_bit_rate_kbps),
fec_(FLAG_fec),
dtx_(FLAG_dtx),
complexity_(FLAG_complexity),
maxplaybackrate_(FLAG_maxplaybackrate),
target_loss_rate_(FLAG_reported_loss_rate),
sub_packets_(FLAG_sub_packets) {
bit_rate_kbps_(absl::GetFlag(FLAGS_bit_rate_kbps)),
fec_(absl::GetFlag(FLAGS_fec)),
dtx_(absl::GetFlag(FLAGS_dtx)),
complexity_(absl::GetFlag(FLAGS_complexity)),
maxplaybackrate_(absl::GetFlag(FLAGS_maxplaybackrate)),
target_loss_rate_(absl::GetFlag(FLAGS_reported_loss_rate)),
sub_packets_(absl::GetFlag(FLAGS_sub_packets)) {
// Flag validation
RTC_CHECK(FLAG_bit_rate_kbps >= 6 && FLAG_bit_rate_kbps <= 510)
RTC_CHECK(absl::GetFlag(FLAGS_bit_rate_kbps) >= 6 &&
absl::GetFlag(FLAGS_bit_rate_kbps) <= 510)
<< "Invalid bit rate, should be between 6 and 510 kbps.";
RTC_CHECK(FLAG_complexity >= -1 && FLAG_complexity <= 10)
RTC_CHECK(absl::GetFlag(FLAGS_complexity) >= -1 &&
absl::GetFlag(FLAGS_complexity) <= 10)
<< "Invalid complexity setting, should be between 0 and 10.";
RTC_CHECK(FLAG_application == 0 || FLAG_application == 1)
RTC_CHECK(absl::GetFlag(FLAGS_application) == 0 ||
absl::GetFlag(FLAGS_application) == 1)
<< "Invalid application mode, should be 0 or 1.";
RTC_CHECK(FLAG_reported_loss_rate >= 0 && FLAG_reported_loss_rate <= 100)
RTC_CHECK(absl::GetFlag(FLAGS_reported_loss_rate) >= 0 &&
absl::GetFlag(FLAGS_reported_loss_rate) <= 100)
<< "Invalid packet loss percentile, should be between 0 and 100.";
RTC_CHECK(FLAG_sub_packets >= 1 && FLAG_sub_packets <= 3)
RTC_CHECK(absl::GetFlag(FLAGS_sub_packets) >= 1 &&
absl::GetFlag(FLAGS_sub_packets) <= 3)
<< "Invalid number of sub packets, should be between 1 and 3.";
// Redefine decoder type if input is stereo.
@ -106,7 +109,7 @@ NetEqOpusQualityTest::NetEqOpusQualityTest()
audio_format_ = SdpAudioFormat(
"opus", 48000, 2, std::map<std::string, std::string>{{"stereo", "1"}});
}
application_ = FLAG_application;
application_ = absl::GetFlag(FLAGS_application);
}
void NetEqOpusQualityTest::SetUp() {

View File

@ -10,13 +10,15 @@
#include <memory>
#include "absl/flags/flag.h"
#include "modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "rtc_base/checks.h"
#include "rtc_base/flags.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "test/testsupport/file_utils.h"
ABSL_FLAG(int, frame_size_ms, 20, "Codec frame size (milliseconds).");
using ::testing::InitGoogleTest;
namespace webrtc {
@ -24,27 +26,25 @@ namespace test {
namespace {
static const int kInputSampleRateKhz = 48;
static const int kOutputSampleRateKhz = 48;
WEBRTC_DEFINE_int(frame_size_ms, 20, "Codec frame size (milliseconds).");
} // namespace
class NetEqPcm16bQualityTest : public NetEqQualityTest {
protected:
NetEqPcm16bQualityTest()
: NetEqQualityTest(FLAG_frame_size_ms,
: NetEqQualityTest(absl::GetFlag(FLAGS_frame_size_ms),
kInputSampleRateKhz,
kOutputSampleRateKhz,
SdpAudioFormat("l16", 48000, 1)) {
// Flag validation
RTC_CHECK(FLAG_frame_size_ms >= 10 && FLAG_frame_size_ms <= 60 &&
(FLAG_frame_size_ms % 10) == 0)
RTC_CHECK(absl::GetFlag(FLAGS_frame_size_ms) >= 10 &&
absl::GetFlag(FLAGS_frame_size_ms) <= 60 &&
(absl::GetFlag(FLAGS_frame_size_ms) % 10) == 0)
<< "Invalid frame size, should be 10, 20, ..., 60 ms.";
}
void SetUp() override {
AudioEncoderPcm16B::Config config;
config.frame_size_ms = FLAG_frame_size_ms;
config.frame_size_ms = absl::GetFlag(FLAGS_frame_size_ms);
config.sample_rate_hz = 48000;
config.num_channels = channels_;
encoder_.reset(new AudioEncoderPcm16B(config));

View File

@ -10,13 +10,15 @@
#include <memory>
#include "absl/flags/flag.h"
#include "modules/audio_coding/codecs/g711/audio_encoder_pcm.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "rtc_base/checks.h"
#include "rtc_base/flags.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "test/testsupport/file_utils.h"
ABSL_FLAG(int, frame_size_ms, 20, "Codec frame size (milliseconds).");
using ::testing::InitGoogleTest;
namespace webrtc {
@ -24,28 +26,26 @@ namespace test {
namespace {
static const int kInputSampleRateKhz = 8;
static const int kOutputSampleRateKhz = 8;
WEBRTC_DEFINE_int(frame_size_ms, 20, "Codec frame size (milliseconds).");
} // namespace
class NetEqPcmuQualityTest : public NetEqQualityTest {
protected:
NetEqPcmuQualityTest()
: NetEqQualityTest(FLAG_frame_size_ms,
: NetEqQualityTest(absl::GetFlag(FLAGS_frame_size_ms),
kInputSampleRateKhz,
kOutputSampleRateKhz,
SdpAudioFormat("pcmu", 8000, 1)) {
// Flag validation
RTC_CHECK(FLAG_frame_size_ms >= 10 && FLAG_frame_size_ms <= 60 &&
(FLAG_frame_size_ms % 10) == 0)
RTC_CHECK(absl::GetFlag(FLAGS_frame_size_ms) >= 10 &&
absl::GetFlag(FLAGS_frame_size_ms) <= 60 &&
(absl::GetFlag(FLAGS_frame_size_ms) % 10) == 0)
<< "Invalid frame size, should be 10, 20, ..., 60 ms.";
}
void SetUp() override {
ASSERT_EQ(1u, channels_) << "PCMu supports only mono audio.";
AudioEncoderPcmU::Config config;
config.frame_size_ms = FLAG_frame_size_ms;
config.frame_size_ms = absl::GetFlag(FLAGS_frame_size_ms);
encoder_.reset(new AudioEncoderPcmU(config));
NetEqQualityTest::SetUp();
}

View File

@ -11,18 +11,21 @@
#include <stdio.h>
#include <iostream>
#include <vector>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "modules/audio_coding/neteq/tools/neteq_performance_test.h"
#include "rtc_base/flags.h"
#include "rtc_base/checks.h"
// Define command line flags.
WEBRTC_DEFINE_int(runtime_ms, 10000, "Simulated runtime in ms.");
WEBRTC_DEFINE_int(lossrate, 10, "Packet lossrate; drop every N packets.");
WEBRTC_DEFINE_float(drift, 0.1f, "Clockdrift factor.");
WEBRTC_DEFINE_bool(help, false, "Print this message.");
ABSL_FLAG(int, runtime_ms, 10000, "Simulated runtime in ms.");
ABSL_FLAG(int, lossrate, 10, "Packet lossrate; drop every N packets.");
ABSL_FLAG(float, drift, 0.1f, "Clockdrift factor.");
int main(int argc, char* argv[]) {
std::string program_name = argv[0];
std::vector<char*> args = absl::ParseCommandLine(argc, argv);
std::string program_name = args[0];
std::string usage =
"Tool for measuring the speed of NetEq.\n"
"Usage: " +
@ -32,21 +35,18 @@ int main(int argc, char* argv[]) {
" --lossrate=N drop every N packets; default is 10\n"
" --drift=F clockdrift factor between 0.0 and 1.0; "
"default is 0.1\n";
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
argc != 1) {
if (args.size() != 1) {
printf("%s", usage.c_str());
if (FLAG_help) {
rtc::FlagList::Print(nullptr, false);
return 0;
}
return 1;
}
RTC_CHECK_GT(FLAG_runtime_ms, 0);
RTC_CHECK_GE(FLAG_lossrate, 0);
RTC_CHECK(FLAG_drift >= 0.0 && FLAG_drift < 1.0);
RTC_CHECK_GT(absl::GetFlag(FLAGS_runtime_ms), 0);
RTC_CHECK_GE(absl::GetFlag(FLAGS_lossrate), 0);
RTC_CHECK(absl::GetFlag(FLAGS_drift) >= 0.0 &&
absl::GetFlag(FLAGS_drift) < 1.0);
int64_t result = webrtc::test::NetEqPerformanceTest::Run(
FLAG_runtime_ms, FLAG_lossrate, FLAG_drift);
absl::GetFlag(FLAGS_runtime_ms), absl::GetFlag(FLAGS_lossrate),
absl::GetFlag(FLAGS_drift));
if (result <= 0) {
std::cout << "There was an error" << std::endl;
return -1;

View File

@ -14,12 +14,75 @@
#include <cmath>
#include "absl/flags/flag.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "modules/audio_coding/neteq/tools/output_audio_file.h"
#include "modules/audio_coding/neteq/tools/output_wav_file.h"
#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
#include "rtc_base/checks.h"
#include "test/testsupport/file_utils.h"
const std::string& DefaultInFilename() {
static const std::string path =
::webrtc::test::ResourcePath("audio_coding/speech_mono_16kHz", "pcm");
return path;
}
const std::string& DefaultOutFilename() {
static const std::string path =
::webrtc::test::OutputPath() + "neteq_quality_test_out.pcm";
return path;
}
ABSL_FLAG(
std::string,
in_filename,
DefaultInFilename(),
"Filename for input audio (specify sample rate with --input_sample_rate, "
"and channels with --channels).");
ABSL_FLAG(int, input_sample_rate, 16000, "Sample rate of input file in Hz.");
ABSL_FLAG(int, channels, 1, "Number of channels in input audio.");
ABSL_FLAG(std::string,
out_filename,
DefaultOutFilename(),
"Name of output audio file.");
ABSL_FLAG(
int,
runtime_ms,
10000,
"Simulated runtime (milliseconds). -1 will consume the complete file.");
ABSL_FLAG(int, packet_loss_rate, 10, "Percentile of packet loss.");
ABSL_FLAG(int,
random_loss_mode,
::webrtc::test::kUniformLoss,
"Random loss mode: 0--no loss, 1--uniform loss, 2--Gilbert Elliot "
"loss, 3--fixed loss.");
ABSL_FLAG(int,
burst_length,
30,
"Burst length in milliseconds, only valid for Gilbert Elliot loss.");
ABSL_FLAG(float, drift_factor, 0.0, "Time drift factor.");
ABSL_FLAG(int,
preload_packets,
1,
"Preload the buffer with this many packets.");
ABSL_FLAG(std::string,
loss_events,
"",
"List of loss events time and duration separated by comma: "
"<first_event_time> <first_event_duration>, <second_event_time> "
"<second_event_duration>, ...");
namespace webrtc {
namespace test {
@ -28,17 +91,6 @@ const int kOutputSizeMs = 10;
const int kInitSeed = 0x12345678;
const int kPacketLossTimeUnitMs = 10;
const std::string& DefaultInFilename() {
static const std::string path =
ResourcePath("audio_coding/speech_mono_16kHz", "pcm");
return path;
}
const std::string& DefaultOutFilename() {
static const std::string path = OutputPath() + "neteq_quality_test_out.pcm";
return path;
}
// Common validator for file names.
static bool ValidateFilename(const std::string& value, bool is_output) {
if (!is_output) {
@ -53,51 +105,6 @@ static bool ValidateFilename(const std::string& value, bool is_output) {
return true;
}
WEBRTC_DEFINE_string(
in_filename,
DefaultInFilename().c_str(),
"Filename for input audio (specify sample rate with --input_sample_rate, "
"and channels with --channels).");
WEBRTC_DEFINE_int(input_sample_rate, 16000, "Sample rate of input file in Hz.");
WEBRTC_DEFINE_int(channels, 1, "Number of channels in input audio.");
WEBRTC_DEFINE_string(out_filename,
DefaultOutFilename().c_str(),
"Name of output audio file.");
WEBRTC_DEFINE_int(
runtime_ms,
10000,
"Simulated runtime (milliseconds). -1 will consume the complete file.");
WEBRTC_DEFINE_int(packet_loss_rate, 10, "Percentile of packet loss.");
WEBRTC_DEFINE_int(
random_loss_mode,
kUniformLoss,
"Random loss mode: 0--no loss, 1--uniform loss, 2--Gilbert Elliot "
"loss, 3--fixed loss.");
WEBRTC_DEFINE_int(
burst_length,
30,
"Burst length in milliseconds, only valid for Gilbert Elliot loss.");
WEBRTC_DEFINE_float(drift_factor, 0.0, "Time drift factor.");
WEBRTC_DEFINE_int(preload_packets,
1,
"Preload the buffer with this many packets.");
WEBRTC_DEFINE_string(
loss_events,
"",
"List of loss events time and duration separated by comma: "
"<first_event_time> <first_event_duration>, <second_event_time> "
"<second_event_duration>, ...");
// ProbTrans00Solver() is to calculate the transition probability from no-loss
// state to itself in a modified Gilbert Elliot packet loss model. The result is
// to achieve the target packet loss rate |loss_rate|, when a packet is not
@ -148,11 +155,11 @@ NetEqQualityTest::NetEqQualityTest(
const SdpAudioFormat& format,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory)
: audio_format_(format),
channels_(static_cast<size_t>(FLAG_channels)),
channels_(absl::GetFlag(FLAGS_channels)),
decoded_time_ms_(0),
decodable_time_ms_(0),
drift_factor_(FLAG_drift_factor),
packet_loss_rate_(FLAG_packet_loss_rate),
drift_factor_(absl::GetFlag(FLAGS_drift_factor)),
packet_loss_rate_(absl::GetFlag(FLAGS_packet_loss_rate)),
block_duration_ms_(block_duration_ms),
in_sampling_khz_(in_sampling_khz),
out_sampling_khz_(out_sampling_khz),
@ -160,45 +167,50 @@ NetEqQualityTest::NetEqQualityTest(
static_cast<size_t>(in_sampling_khz_ * block_duration_ms_)),
payload_size_bytes_(0),
max_payload_bytes_(0),
in_file_(new ResampleInputAudioFile(FLAG_in_filename,
FLAG_input_sample_rate,
in_sampling_khz * 1000,
FLAG_runtime_ms > 0)),
in_file_(
new ResampleInputAudioFile(absl::GetFlag(FLAGS_in_filename),
absl::GetFlag(FLAGS_input_sample_rate),
in_sampling_khz * 1000,
absl::GetFlag(FLAGS_runtime_ms) > 0)),
rtp_generator_(
new RtpGenerator(in_sampling_khz_, 0, 0, decodable_time_ms_)),
total_payload_size_bytes_(0) {
// Flag validation
RTC_CHECK(ValidateFilename(FLAG_in_filename, false))
RTC_CHECK(ValidateFilename(absl::GetFlag(FLAGS_in_filename), false))
<< "Invalid input filename.";
RTC_CHECK(FLAG_input_sample_rate == 8000 || FLAG_input_sample_rate == 16000 ||
FLAG_input_sample_rate == 32000 || FLAG_input_sample_rate == 48000)
RTC_CHECK(absl::GetFlag(FLAGS_input_sample_rate) == 8000 ||
absl::GetFlag(FLAGS_input_sample_rate) == 16000 ||
absl::GetFlag(FLAGS_input_sample_rate) == 32000 ||
absl::GetFlag(FLAGS_input_sample_rate) == 48000)
<< "Invalid sample rate should be 8000, 16000, 32000 or 48000 Hz.";
RTC_CHECK_EQ(FLAG_channels, 1)
RTC_CHECK_EQ(absl::GetFlag(FLAGS_channels), 1)
<< "Invalid number of channels, current support only 1.";
RTC_CHECK(ValidateFilename(FLAG_out_filename, true))
RTC_CHECK(ValidateFilename(absl::GetFlag(FLAGS_out_filename), true))
<< "Invalid output filename.";
RTC_CHECK(FLAG_packet_loss_rate >= 0 && FLAG_packet_loss_rate <= 100)
RTC_CHECK(absl::GetFlag(FLAGS_packet_loss_rate) >= 0 &&
absl::GetFlag(FLAGS_packet_loss_rate) <= 100)
<< "Invalid packet loss percentile, should be between 0 and 100.";
RTC_CHECK(FLAG_random_loss_mode >= 0 && FLAG_random_loss_mode < kLastLossMode)
RTC_CHECK(absl::GetFlag(FLAGS_random_loss_mode) >= 0 &&
absl::GetFlag(FLAGS_random_loss_mode) < kLastLossMode)
<< "Invalid random packet loss mode, should be between 0 and "
<< kLastLossMode - 1 << ".";
RTC_CHECK_GE(FLAG_burst_length, kPacketLossTimeUnitMs)
RTC_CHECK_GE(absl::GetFlag(FLAGS_burst_length), kPacketLossTimeUnitMs)
<< "Invalid burst length, should be greater than or equal to "
<< kPacketLossTimeUnitMs << " ms.";
RTC_CHECK_GT(FLAG_drift_factor, -0.1)
RTC_CHECK_GT(absl::GetFlag(FLAGS_drift_factor), -0.1)
<< "Invalid drift factor, should be greater than -0.1.";
RTC_CHECK_GE(FLAG_preload_packets, 0)
RTC_CHECK_GE(absl::GetFlag(FLAGS_preload_packets), 0)
<< "Invalid number of packets to preload; must be non-negative.";
const std::string out_filename = FLAG_out_filename;
const std::string out_filename = absl::GetFlag(FLAGS_out_filename);
const std::string log_filename = out_filename + ".log";
log_file_.open(log_filename.c_str(), std::ofstream::out);
RTC_CHECK(log_file_.is_open());
@ -283,7 +295,7 @@ void NetEqQualityTest::SetUp() {
rtp_generator_->set_drift_factor(drift_factor_);
int units = block_duration_ms_ / kPacketLossTimeUnitMs;
switch (FLAG_random_loss_mode) {
switch (absl::GetFlag(FLAGS_random_loss_mode)) {
case kUniformLoss: {
// |unit_loss_rate| is the packet loss rate for each unit time interval
// (kPacketLossTimeUnitMs). Since a packet loss event is generated if any
@ -297,8 +309,8 @@ void NetEqQualityTest::SetUp() {
break;
}
case kGilbertElliotLoss: {
// |FLAG_burst_length| should be integer times of kPacketLossTimeUnitMs.
ASSERT_EQ(0, FLAG_burst_length % kPacketLossTimeUnitMs);
// |FLAGS_burst_length| should be integer times of kPacketLossTimeUnitMs.
ASSERT_EQ(0, absl::GetFlag(FLAGS_burst_length) % kPacketLossTimeUnitMs);
// We do not allow 100 percent packet loss in Gilbert Elliot model, which
// makes no sense.
@ -316,14 +328,15 @@ void NetEqQualityTest::SetUp() {
// prob_trans_00 ^ (units - 1) = (loss_rate - 1) / prob_trans_10 *
// prob_trans_00 + (1 - loss_rate) * (1 + 1 / prob_trans_10).
double loss_rate = 0.01f * packet_loss_rate_;
double prob_trans_10 = 1.0f * kPacketLossTimeUnitMs / FLAG_burst_length;
double prob_trans_10 =
1.0f * kPacketLossTimeUnitMs / absl::GetFlag(FLAGS_burst_length);
double prob_trans_00 = ProbTrans00Solver(units, loss_rate, prob_trans_10);
loss_model_.reset(
new GilbertElliotLoss(1.0f - prob_trans_10, 1.0f - prob_trans_00));
break;
}
case kFixedLoss: {
std::istringstream loss_events_stream(FLAG_loss_events);
std::istringstream loss_events_stream(absl::GetFlag(FLAGS_loss_events));
std::string loss_event_string;
std::set<FixedLossEvent, FixedLossEventCmp> loss_events;
while (std::getline(loss_events_stream, loss_event_string, ',')) {
@ -415,15 +428,18 @@ int NetEqQualityTest::DecodeBlock() {
void NetEqQualityTest::Simulate() {
int audio_size_samples;
bool end_of_input = false;
int runtime_ms = FLAG_runtime_ms >= 0 ? FLAG_runtime_ms : INT_MAX;
int runtime_ms = absl::GetFlag(FLAGS_runtime_ms) >= 0
? absl::GetFlag(FLAGS_runtime_ms)
: INT_MAX;
while (!end_of_input && decoded_time_ms_ < runtime_ms) {
// Preload the buffer if needed.
while (decodable_time_ms_ - FLAG_preload_packets * block_duration_ms_ <
while (decodable_time_ms_ -
absl::GetFlag(FLAGS_preload_packets) * block_duration_ms_ <
decoded_time_ms_) {
if (!in_file_->Read(in_size_samples_ * channels_, &in_data_[0])) {
end_of_input = true;
ASSERT_TRUE(end_of_input && FLAG_runtime_ms < 0);
ASSERT_TRUE(end_of_input && absl::GetFlag(FLAGS_runtime_ms) < 0);
break;
}
payload_.Clear();
@ -438,8 +454,8 @@ void NetEqQualityTest::Simulate() {
}
}
Log() << "Average bit rate was "
<< 8.0f * total_payload_size_bytes_ / FLAG_runtime_ms << " kbps"
<< std::endl;
<< 8.0f * total_payload_size_bytes_ / absl::GetFlag(FLAGS_runtime_ms)
<< " kbps" << std::endl;
}
} // namespace test

View File

@ -19,7 +19,6 @@
#include "modules/audio_coding/neteq/tools/audio_sink.h"
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "modules/audio_coding/neteq/tools/rtp_generator.h"
#include "rtc_base/flags.h"
#include "test/gtest.h"
namespace webrtc {

View File

@ -39,7 +39,6 @@
#include "modules/audio_coding/neteq/tools/output_wav_file.h"
#include "modules/audio_coding/neteq/tools/rtp_file_source.h"
#include "rtc_base/checks.h"
#include "rtc_base/flags.h"
#include "rtc_base/ref_counted_object.h"
#include "test/function_audio_decoder_factory.h"
#include "test/testsupport/file_utils.h"

View File

@ -18,7 +18,6 @@
#include "absl/flags/parse.h"
#include "modules/audio_coding/neteq/tools/packet.h"
#include "modules/audio_coding/neteq/tools/rtp_file_source.h"
#include "rtc_base/flags.h"
ABSL_FLAG(int, red, 117, "RTP payload type for RED");
ABSL_FLAG(int,

View File

@ -35,7 +35,6 @@
#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
#include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "rtc_base/flags.h"
#include "rtc_base/numerics/safe_conversions.h"
ABSL_FLAG(bool, list_codecs, false, "Enumerate all codecs");