Adopt absl::string_view in modules/audio_coding/

Bug: webrtc:13579
Change-Id: Ifec66fb6ba9724d18539de7245a358c2d13c7939
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/268547
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37573}
This commit is contained in:
Ali Tofigh
2022-07-20 12:53:07 +02:00
committed by WebRTC LUCI CQ
parent 761072f68e
commit 714e3cbb48
63 changed files with 234 additions and 152 deletions

View File

@ -18,6 +18,7 @@
#include <utility>
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "api/audio_codecs/audio_decoder.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@ -39,7 +40,7 @@ DecoderDatabase::DecoderInfo::DecoderInfo(
const SdpAudioFormat& audio_format,
absl::optional<AudioCodecPairId> codec_pair_id,
AudioDecoderFactory* factory,
const std::string& codec_name)
absl::string_view codec_name)
: name_(codec_name),
audio_format_(audio_format),
codec_pair_id_(codec_pair_id),
@ -71,14 +72,10 @@ AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const {
return decoder_.get();
}
bool DecoderDatabase::DecoderInfo::IsType(const char* name) const {
bool DecoderDatabase::DecoderInfo::IsType(absl::string_view name) const {
return absl::EqualsIgnoreCase(audio_format_.name, name);
}
bool DecoderDatabase::DecoderInfo::IsType(const std::string& name) const {
return IsType(name.c_str());
}
absl::optional<DecoderDatabase::DecoderInfo::CngDecoder>
DecoderDatabase::DecoderInfo::CngDecoder::Create(const SdpAudioFormat& format) {
if (absl::EqualsIgnoreCase(format.name, "CN")) {

View File

@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_format.h"
#include "api/scoped_refptr.h"
@ -41,7 +42,7 @@ class DecoderDatabase {
DecoderInfo(const SdpAudioFormat& audio_format,
absl::optional<AudioCodecPairId> codec_pair_id,
AudioDecoderFactory* factory,
const std::string& codec_name);
absl::string_view codec_name);
explicit DecoderInfo(const SdpAudioFormat& audio_format,
absl::optional<AudioCodecPairId> codec_pair_id,
AudioDecoderFactory* factory = nullptr);
@ -80,9 +81,7 @@ class DecoderDatabase {
bool IsRed() const { return subtype_ == Subtype::kRed; }
// Returns true if the decoder's format is named `name`.
bool IsType(const char* name) const;
// Returns true if the decoder's format is named `name`.
bool IsType(const std::string& name) const;
bool IsType(absl::string_view name) const;
const std::string& get_name() const { return name_; }

View File

@ -9,6 +9,7 @@
#include "modules/audio_coding/neteq/expand_uma_logger.h"
#include "absl/strings/string_view.h"
#include "rtc_base/checks.h"
#include "system_wrappers/include/metrics.h"
@ -22,7 +23,7 @@ std::unique_ptr<TickTimer::Countdown> GetNewCountdown(
}
} // namespace
ExpandUmaLogger::ExpandUmaLogger(std::string uma_name,
ExpandUmaLogger::ExpandUmaLogger(absl::string_view uma_name,
int logging_period_s,
const TickTimer* tick_timer)
: uma_name_(uma_name),

View File

@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/neteq/tick_timer.h"
@ -29,7 +30,7 @@ namespace webrtc {
// object that outlives the one constructed.
class ExpandUmaLogger {
public:
ExpandUmaLogger(std::string uma_name,
ExpandUmaLogger(absl::string_view uma_name,
int logging_period_s,
const TickTimer* tick_timer);

View File

@ -14,6 +14,7 @@
#include <algorithm>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/delay_manager.h"
#include "rtc_base/checks.h"
#include "rtc_base/numerics/safe_conversions.h"
@ -38,7 +39,7 @@ constexpr int kInterruptionLenMs = 150;
const size_t StatisticsCalculator::kLenWaitingTimes;
StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger(
const std::string& uma_name,
absl::string_view uma_name,
int report_interval_ms,
int max_value)
: uma_name_(uma_name),
@ -64,7 +65,7 @@ void StatisticsCalculator::PeriodicUmaLogger::LogToUma(int value) const {
}
StatisticsCalculator::PeriodicUmaCount::PeriodicUmaCount(
const std::string& uma_name,
absl::string_view uma_name,
int report_interval_ms,
int max_value)
: PeriodicUmaLogger(uma_name, report_interval_ms, max_value) {}
@ -87,7 +88,7 @@ void StatisticsCalculator::PeriodicUmaCount::Reset() {
}
StatisticsCalculator::PeriodicUmaAverage::PeriodicUmaAverage(
const std::string& uma_name,
absl::string_view uma_name,
int report_interval_ms,
int max_value)
: PeriodicUmaLogger(uma_name, report_interval_ms, max_value) {}

View File

@ -14,6 +14,7 @@
#include <deque>
#include <string>
#include "absl/strings/string_view.h"
#include "api/neteq/neteq.h"
namespace webrtc {
@ -126,7 +127,7 @@ class StatisticsCalculator {
class PeriodicUmaLogger {
public:
PeriodicUmaLogger(const std::string& uma_name,
PeriodicUmaLogger(absl::string_view uma_name,
int report_interval_ms,
int max_value);
virtual ~PeriodicUmaLogger();
@ -145,7 +146,7 @@ class StatisticsCalculator {
class PeriodicUmaCount final : public PeriodicUmaLogger {
public:
PeriodicUmaCount(const std::string& uma_name,
PeriodicUmaCount(absl::string_view uma_name,
int report_interval_ms,
int max_value);
~PeriodicUmaCount() override;
@ -161,7 +162,7 @@ class StatisticsCalculator {
class PeriodicUmaAverage final : public PeriodicUmaLogger {
public:
PeriodicUmaAverage(const std::string& uma_name,
PeriodicUmaAverage(absl::string_view uma_name,
int report_interval_ms,
int max_value);
~PeriodicUmaAverage() override;

View File

@ -10,6 +10,7 @@
#include "modules/audio_coding/neteq/test/neteq_decoding_test.h"
#include "absl/strings/string_view.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/rtp_headers.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
@ -93,7 +94,7 @@ void NetEqDecodingTest::SetUp() {
void NetEqDecodingTest::TearDown() {}
void NetEqDecodingTest::OpenInputFile(const std::string& rtp_file) {
void NetEqDecodingTest::OpenInputFile(absl::string_view rtp_file) {
rtp_source_.reset(test::RtpFileSource::Create(rtp_file));
}
@ -131,9 +132,9 @@ void NetEqDecodingTest::Process() {
}
void NetEqDecodingTest::DecodeAndCompare(
const std::string& rtp_file,
const std::string& output_checksum,
const std::string& network_stats_checksum,
absl::string_view rtp_file,
absl::string_view output_checksum,
absl::string_view network_stats_checksum,
bool gen_ref) {
OpenInputFile(rtp_file);

View File

@ -15,6 +15,7 @@
#include <set>
#include <string>
#include "absl/strings/string_view.h"
#include "api/audio/audio_frame.h"
#include "api/neteq/neteq.h"
#include "api/rtp_headers.h"
@ -39,12 +40,12 @@ class NetEqDecodingTest : public ::testing::Test {
NetEqDecodingTest();
virtual void SetUp();
virtual void TearDown();
void OpenInputFile(const std::string& rtp_file);
void OpenInputFile(absl::string_view rtp_file);
void Process();
void DecodeAndCompare(const std::string& rtp_file,
const std::string& output_checksum,
const std::string& network_stats_checksum,
void DecodeAndCompare(absl::string_view rtp_file,
absl::string_view output_checksum,
absl::string_view network_stats_checksum,
bool gen_ref);
static void PopulateRtpInfo(int frame_index,

View File

@ -106,8 +106,8 @@ NetEqOpusQualityTest::NetEqOpusQualityTest()
// Redefine decoder type if input is stereo.
if (channels_ > 1) {
audio_format_ = SdpAudioFormat(
"opus", 48000, 2, std::map<std::string, std::string>{{"stereo", "1"}});
audio_format_ = SdpAudioFormat("opus", 48000, 2,
SdpAudioFormat::Parameters{{"stereo", "1"}});
}
application_ = absl::GetFlag(FLAGS_application);
}

View File

@ -50,7 +50,7 @@ void Convert(const webrtc::NetEqNetworkStatistics& stats_raw,
void AddMessage(FILE* file,
rtc::MessageDigest* digest,
const std::string& message) {
absl::string_view message) {
int32_t size = message.length();
if (file)
ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file));
@ -64,11 +64,11 @@ void AddMessage(FILE* file,
#endif // WEBRTC_NETEQ_UNITTEST_BITEXACT
ResultSink::ResultSink(const std::string& output_file)
ResultSink::ResultSink(absl::string_view output_file)
: output_fp_(nullptr),
digest_(rtc::MessageDigestFactory::Create(rtc::DIGEST_SHA_1)) {
if (!output_file.empty()) {
output_fp_ = fopen(output_file.c_str(), "wb");
output_fp_ = fopen(std::string(output_file).c_str(), "wb");
EXPECT_TRUE(output_fp_ != NULL);
}
}
@ -91,7 +91,7 @@ void ResultSink::AddResult(const NetEqNetworkStatistics& stats_raw) {
#endif // WEBRTC_NETEQ_UNITTEST_BITEXACT
}
void ResultSink::VerifyChecksum(const std::string& checksum) {
void ResultSink::VerifyChecksum(absl::string_view checksum) {
std::string buffer;
buffer.resize(digest_->Size());
digest_->Finish(buffer.data(), buffer.size());
@ -100,7 +100,7 @@ void ResultSink::VerifyChecksum(const std::string& checksum) {
EXPECT_EQ(checksum, result);
} else {
// Check result is one the '|'-separated checksums.
EXPECT_NE(checksum.find(result), std::string::npos)
EXPECT_NE(checksum.find(result), absl::string_view::npos)
<< result << " should be one of these:\n"
<< checksum;
}

View File

@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "api/neteq/neteq.h"
#include "rtc_base/message_digest.h"
@ -22,7 +23,7 @@ namespace webrtc {
class ResultSink {
public:
explicit ResultSink(const std::string& output_file);
explicit ResultSink(absl::string_view output_file);
~ResultSink();
template <typename T>
@ -30,7 +31,7 @@ class ResultSink {
void AddResult(const NetEqNetworkStatistics& stats);
void VerifyChecksum(const std::string& ref_check_sum);
void VerifyChecksum(absl::string_view ref_check_sum);
private:
FILE* output_fp_;

View File

@ -13,13 +13,15 @@
#include <stdio.h>
#include <string.h>
#include "absl/strings/string_view.h"
namespace webrtc {
namespace test {
bool AudioLoop::Init(const std::string file_name,
bool AudioLoop::Init(absl::string_view file_name,
size_t max_loop_length_samples,
size_t block_length_samples) {
FILE* fp = fopen(file_name.c_str(), "rb");
FILE* fp = fopen(std::string(file_name).c_str(), "rb");
if (!fp)
return false;

View File

@ -14,6 +14,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
namespace webrtc {
@ -36,7 +37,7 @@ class AudioLoop {
// greater. Otherwise, the loop length is the same as the file length.
// The audio will be delivered in blocks of `block_length_samples`.
// Returns false if the initialization failed, otherwise true.
bool Init(std::string file_name,
bool Init(absl::string_view file_name,
size_t max_loop_length_samples,
size_t block_length_samples);

View File

@ -10,14 +10,15 @@
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "absl/strings/string_view.h"
#include "rtc_base/checks.h"
namespace webrtc {
namespace test {
InputAudioFile::InputAudioFile(const std::string file_name, bool loop_at_end)
InputAudioFile::InputAudioFile(absl::string_view file_name, bool loop_at_end)
: loop_at_end_(loop_at_end) {
fp_ = fopen(file_name.c_str(), "rb");
fp_ = fopen(std::string(file_name).c_str(), "rb");
RTC_DCHECK(fp_) << file_name << " could not be opened.";
}

View File

@ -15,13 +15,15 @@
#include <string>
#include "absl/strings/string_view.h"
namespace webrtc {
namespace test {
// Class for handling a looping input audio file.
class InputAudioFile {
public:
explicit InputAudioFile(std::string file_name, bool loop_at_end = true);
explicit InputAudioFile(absl::string_view file_name, bool loop_at_end = true);
virtual ~InputAudioFile();

View File

@ -68,7 +68,7 @@ void PrintDelays(const NetEqDelayAnalyzer::Delays& delays,
absl::string_view var_name_x,
absl::string_view var_name_y,
std::ofstream& output,
const std::string& terminator = "") {
absl::string_view terminator = "") {
output << var_name_x << " = [ ";
for (const std::pair<int64_t, float>& delay : delays) {
output << (delay.first - ref_time_ms) / 1000.f << ", ";
@ -185,7 +185,7 @@ void NetEqDelayAnalyzer::CreateGraphs(Delays* arrival_delay_ms,
}
void NetEqDelayAnalyzer::CreateMatlabScript(
const std::string& script_name) const {
absl::string_view script_name) const {
Delays arrival_delay_ms;
Delays corrected_arrival_delay_ms;
Delays playout_delay_ms;
@ -198,7 +198,7 @@ void NetEqDelayAnalyzer::CreateMatlabScript(
const int64_t ref_time_ms = arrival_delay_ms.front().first;
// Create an output file stream to Matlab script file.
std::ofstream output(script_name);
std::ofstream output(std::string{script_name});
PrintDelays(corrected_arrival_delay_ms, ref_time_ms, kArrivalDelayX,
kArrivalDelayY, output, ";");
@ -241,7 +241,7 @@ void NetEqDelayAnalyzer::CreateMatlabScript(
}
void NetEqDelayAnalyzer::CreatePythonScript(
const std::string& script_name) const {
absl::string_view script_name) const {
Delays arrival_delay_ms;
Delays corrected_arrival_delay_ms;
Delays playout_delay_ms;
@ -254,7 +254,7 @@ void NetEqDelayAnalyzer::CreatePythonScript(
const int64_t ref_time_ms = arrival_delay_ms.front().first;
// Create an output file stream to the python script file.
std::ofstream output(script_name);
std::ofstream output(std::string{script_name});
// Necessary includes
output << "import numpy as np" << std::endl;

View File

@ -16,6 +16,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "modules/audio_coding/neteq/tools/neteq_input.h"
#include "modules/audio_coding/neteq/tools/neteq_test.h"
@ -45,12 +46,12 @@ class NetEqDelayAnalyzer : public test::NetEqPostInsertPacket,
// Creates a matlab script with file name script_name. When executed in
// Matlab, the script will generate graphs with the same timing information
// as provided by CreateGraphs.
void CreateMatlabScript(const std::string& script_name) const;
void CreateMatlabScript(absl::string_view script_name) const;
// Creates a python script with file name `script_name`. When executed in
// Python, the script will generate graphs with the same timing information
// as provided by CreateGraphs.
void CreatePythonScript(const std::string& script_name) const;
void CreatePythonScript(absl::string_view script_name) const;
private:
struct TimingData {

View File

@ -13,6 +13,7 @@
#include <limits>
#include <memory>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/tools/rtc_event_log_source.h"
#include "rtc_base/checks.h"
@ -20,7 +21,7 @@ namespace webrtc {
namespace test {
NetEqEventLogInput* NetEqEventLogInput::CreateFromFile(
const std::string& file_name,
absl::string_view file_name,
absl::optional<uint32_t> ssrc_filter) {
auto event_log_src =
RtcEventLogSource::CreateFromFile(file_name, ssrc_filter);
@ -31,7 +32,7 @@ NetEqEventLogInput* NetEqEventLogInput::CreateFromFile(
}
NetEqEventLogInput* NetEqEventLogInput::CreateFromString(
const std::string& file_contents,
absl::string_view file_contents,
absl::optional<uint32_t> ssrc_filter) {
auto event_log_src =
RtcEventLogSource::CreateFromString(file_contents, ssrc_filter);

View File

@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@ -28,10 +29,10 @@ class RtcEventLogSource;
class NetEqEventLogInput final : public NetEqPacketSourceInput {
public:
static NetEqEventLogInput* CreateFromFile(
const std::string& file_name,
absl::string_view file_name,
absl::optional<uint32_t> ssrc_filter);
static NetEqEventLogInput* CreateFromString(
const std::string& file_contents,
absl::string_view file_contents,
absl::optional<uint32_t> ssrc_filter);
absl::optional<int64_t> NextOutputEventTime() const override;

View File

@ -13,6 +13,7 @@
#include <algorithm>
#include <limits>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/tools/rtp_file_source.h"
#include "rtc_base/checks.h"
@ -58,7 +59,7 @@ std::unique_ptr<NetEqInput::PacketData> NetEqPacketSourceInput::PopPacket() {
return packet_data;
}
NetEqRtpDumpInput::NetEqRtpDumpInput(const std::string& file_name,
NetEqRtpDumpInput::NetEqRtpDumpInput(absl::string_view file_name,
const RtpHeaderExtensionMap& hdr_ext_map,
absl::optional<uint32_t> ssrc_filter)
: source_(RtpFileSource::Create(file_name, ssrc_filter)) {

View File

@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "modules/audio_coding/neteq/tools/neteq_input.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@ -48,7 +49,7 @@ class NetEqPacketSourceInput : public NetEqInput {
// Implementation of NetEqPacketSourceInput to be used with an RtpFileSource.
class NetEqRtpDumpInput final : public NetEqPacketSourceInput {
public:
NetEqRtpDumpInput(const std::string& file_name,
NetEqRtpDumpInput(absl::string_view file_name,
const RtpHeaderExtensionMap& hdr_ext_map,
absl::optional<uint32_t> ssrc_filter);

View File

@ -15,6 +15,7 @@
#include <cmath>
#include "absl/flags/flag.h"
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "modules/audio_coding/neteq/tools/output_audio_file.h"
@ -105,13 +106,13 @@ const int kInitSeed = 0x12345678;
const int kPacketLossTimeUnitMs = 10;
// Common validator for file names.
static bool ValidateFilename(const std::string& value, bool is_output) {
static bool ValidateFilename(absl::string_view value, bool is_output) {
if (!is_output) {
RTC_CHECK_NE(value.substr(value.find_last_of('.') + 1), "wav")
<< "WAV file input is not supported";
}
FILE* fid =
is_output ? fopen(value.c_str(), "wb") : fopen(value.c_str(), "rb");
FILE* fid = is_output ? fopen(std::string(value).c_str(), "wb")
: fopen(std::string(value).c_str(), "rb");
if (fid == nullptr)
return false;
fclose(fid);

View File

@ -159,7 +159,7 @@ namespace {
// Parses the input string for a valid SSRC (at the start of the string). If a
// valid SSRC is found, it is written to the output variable `ssrc`, and true is
// returned. Otherwise, false is returned.
bool ParseSsrc(const std::string& str, uint32_t* ssrc) {
bool ParseSsrc(absl::string_view str, uint32_t* ssrc) {
if (str.empty())
return true;
int base = 10;
@ -168,12 +168,13 @@ bool ParseSsrc(const std::string& str, uint32_t* ssrc) {
base = 16;
errno = 0;
char* end_ptr;
unsigned long value = strtoul(str.c_str(), &end_ptr, base); // NOLINT
std::string str_str = std::string(str);
unsigned long value = strtoul(str_str.c_str(), &end_ptr, base); // NOLINT
if (value == ULONG_MAX && errno == ERANGE)
return false; // Value out of range for unsigned long.
if (sizeof(unsigned long) > sizeof(uint32_t) && value > 0xFFFFFFFF) // NOLINT
return false; // Value out of range for uint32_t.
if (end_ptr - str.c_str() < static_cast<ptrdiff_t>(str.length()))
if (end_ptr - str_str.c_str() < static_cast<ptrdiff_t>(str.length()))
return false; // Part of the string was not parsed.
*ssrc = static_cast<uint32_t>(value);
return true;
@ -196,15 +197,15 @@ bool ValidatePayloadType(int value) {
return false;
}
bool ValidateSsrcValue(const std::string& str) {
bool ValidateSsrcValue(absl::string_view str) {
uint32_t dummy_ssrc;
if (ParseSsrc(str, &dummy_ssrc)) // Value is ok.
return true;
printf("Invalid SSRC: %s\n", str.c_str());
printf("Invalid SSRC: %.*s\n", static_cast<int>(str.size()), str.data());
return false;
}
void PrintCodecMappingEntry(const char* codec, int flag) {
void PrintCodecMappingEntry(absl::string_view codec, int flag) {
std::cout << codec << ": " << flag << std::endl;
}

View File

@ -15,13 +15,15 @@
#include <utility>
#include "absl/strings/string_view.h"
namespace webrtc {
namespace test {
NetEqStatsPlotter::NetEqStatsPlotter(bool make_matlab_plot,
bool make_python_plot,
bool show_concealment_events,
std::string base_file_name)
absl::string_view base_file_name)
: make_matlab_plot_(make_matlab_plot),
make_python_plot_(make_python_plot),
show_concealment_events_(show_concealment_events),

View File

@ -14,6 +14,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
#include "modules/audio_coding/neteq/tools/neteq_stats_getter.h"
#include "modules/audio_coding/neteq/tools/neteq_test.h"
@ -26,7 +27,7 @@ class NetEqStatsPlotter : public NetEqSimulationEndedCallback {
NetEqStatsPlotter(bool make_matlab_plot,
bool make_python_plot,
bool show_concealment_events,
std::string base_file_name);
absl::string_view base_file_name);
void SimulationEnded(int64_t simulation_time_ms) override;

View File

@ -22,6 +22,7 @@
#include <string>
#include <utility>
#include "absl/strings/string_view.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/neteq/neteq.h"
#include "modules/audio_coding/neteq/tools/audio_sink.h"
@ -108,7 +109,7 @@ NetEqTestFactory::Config::Config(const Config& other) = default;
NetEqTestFactory::Config::~Config() = default;
std::unique_ptr<NetEqTest> NetEqTestFactory::InitializeTestFromString(
const std::string& input_string,
absl::string_view input_string,
NetEqFactory* factory,
const Config& config) {
std::unique_ptr<NetEqInput> input(
@ -121,7 +122,7 @@ std::unique_ptr<NetEqTest> NetEqTestFactory::InitializeTestFromString(
}
std::unique_ptr<NetEqTest> NetEqTestFactory::InitializeTestFromFile(
const std::string& input_file_name,
absl::string_view input_file_name,
NetEqFactory* factory,
const Config& config) {
// Gather RTP header extensions in a map.

View File

@ -14,6 +14,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "modules/audio_coding/neteq/tools/neteq_test.h"
#include "test/field_trial.h"
@ -146,11 +147,11 @@ class NetEqTestFactory {
};
std::unique_ptr<NetEqTest> InitializeTestFromFile(
const std::string& input_filename,
absl::string_view input_filename,
NetEqFactory* neteq_factory,
const Config& config);
std::unique_ptr<NetEqTest> InitializeTestFromString(
const std::string& input_string,
absl::string_view input_string,
NetEqFactory* neteq_factory,
const Config& config);

View File

@ -15,6 +15,7 @@
#include <string>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/tools/audio_sink.h"
namespace webrtc {
@ -24,8 +25,8 @@ class OutputAudioFile : public AudioSink {
public:
// Creates an OutputAudioFile, opening a file named `file_name` for writing.
// The file format is 16-bit signed host-endian PCM.
explicit OutputAudioFile(const std::string& file_name) {
out_file_ = fopen(file_name.c_str(), "wb");
explicit OutputAudioFile(absl::string_view file_name) {
out_file_ = fopen(std::string(file_name).c_str(), "wb");
}
virtual ~OutputAudioFile() {

View File

@ -13,6 +13,7 @@
#include <string>
#include "absl/strings/string_view.h"
#include "common_audio/wav_file.h"
#include "modules/audio_coding/neteq/tools/audio_sink.h"
@ -23,7 +24,7 @@ class OutputWavFile : public AudioSink {
public:
// Creates an OutputWavFile, opening a file named `file_name` for writing.
// The output file is a PCM encoded wav file.
OutputWavFile(const std::string& file_name,
OutputWavFile(absl::string_view file_name,
int sample_rate_hz,
int num_channels = 1)
: wav_writer_(file_name, sample_rate_hz, num_channels) {}

View File

@ -13,6 +13,7 @@
#include <string>
#include "absl/strings/string_view.h"
#include "common_audio/resampler/include/resampler.h"
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
@ -22,13 +23,13 @@ namespace test {
// Class for handling a looping input audio file with resampling.
class ResampleInputAudioFile : public InputAudioFile {
public:
ResampleInputAudioFile(const std::string file_name,
ResampleInputAudioFile(absl::string_view file_name,
int file_rate_hz,
bool loop_at_end = true)
: InputAudioFile(file_name, loop_at_end),
file_rate_hz_(file_rate_hz),
output_rate_hz_(-1) {}
ResampleInputAudioFile(const std::string file_name,
ResampleInputAudioFile(absl::string_view file_name,
int file_rate_hz,
int output_rate_hz,
bool loop_at_end = true)

View File

@ -18,6 +18,7 @@
#include <set>
#include <utility>
#include "absl/strings/string_view.h"
#include "logging/rtc_event_log/rtc_event_processor.h"
#include "modules/audio_coding/neteq/tools/packet.h"
#include "rtc_base/checks.h"
@ -38,7 +39,7 @@ bool ShouldSkipStream(ParsedRtcEventLog::MediaType media_type,
} // namespace
std::unique_ptr<RtcEventLogSource> RtcEventLogSource::CreateFromFile(
const std::string& file_name,
absl::string_view file_name,
absl::optional<uint32_t> ssrc_filter) {
auto source = std::unique_ptr<RtcEventLogSource>(new RtcEventLogSource());
ParsedRtcEventLog parsed_log;
@ -57,7 +58,7 @@ std::unique_ptr<RtcEventLogSource> RtcEventLogSource::CreateFromFile(
}
std::unique_ptr<RtcEventLogSource> RtcEventLogSource::CreateFromString(
const std::string& file_contents,
absl::string_view file_contents,
absl::optional<uint32_t> ssrc_filter) {
auto source = std::unique_ptr<RtcEventLogSource>(new RtcEventLogSource());
ParsedRtcEventLog parsed_log;

View File

@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "logging/rtc_event_log/rtc_event_log_parser.h"
#include "modules/audio_coding/neteq/tools/packet_source.h"
@ -33,11 +34,11 @@ class RtcEventLogSource : public PacketSource {
// Creates an RtcEventLogSource reading from `file_name`. If the file cannot
// be opened, or has the wrong format, NULL will be returned.
static std::unique_ptr<RtcEventLogSource> CreateFromFile(
const std::string& file_name,
absl::string_view file_name,
absl::optional<uint32_t> ssrc_filter);
// Same as above, but uses a string with the file contents.
static std::unique_ptr<RtcEventLogSource> CreateFromString(
const std::string& file_contents,
absl::string_view file_contents,
absl::optional<uint32_t> ssrc_filter);
virtual ~RtcEventLogSource();

View File

@ -11,6 +11,8 @@
#include "modules/audio_coding/neteq/tools/rtp_file_source.h"
#include <string.h>
#include "absl/strings/string_view.h"
#ifndef WIN32
#include <netinet/in.h>
#endif
@ -24,20 +26,20 @@
namespace webrtc {
namespace test {
RtpFileSource* RtpFileSource::Create(const std::string& file_name,
RtpFileSource* RtpFileSource::Create(absl::string_view file_name,
absl::optional<uint32_t> ssrc_filter) {
RtpFileSource* source = new RtpFileSource(ssrc_filter);
RTC_CHECK(source->OpenFile(file_name));
return source;
}
bool RtpFileSource::ValidRtpDump(const std::string& file_name) {
bool RtpFileSource::ValidRtpDump(absl::string_view file_name) {
std::unique_ptr<RtpFileReader> temp_file(
RtpFileReader::Create(RtpFileReader::kRtpDump, file_name));
return !!temp_file;
}
bool RtpFileSource::ValidPcap(const std::string& file_name) {
bool RtpFileSource::ValidPcap(absl::string_view file_name) {
std::unique_ptr<RtpFileReader> temp_file(
RtpFileReader::Create(RtpFileReader::kPcap, file_name));
return !!temp_file;
@ -81,7 +83,7 @@ RtpFileSource::RtpFileSource(absl::optional<uint32_t> ssrc_filter)
: PacketSource(),
ssrc_filter_(ssrc_filter) {}
bool RtpFileSource::OpenFile(const std::string& file_name) {
bool RtpFileSource::OpenFile(absl::string_view file_name) {
rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kRtpDump, file_name));
if (rtp_reader_)
return true;

View File

@ -16,6 +16,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "modules/audio_coding/neteq/tools/packet_source.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@ -31,12 +32,12 @@ class RtpFileSource : public PacketSource {
// Creates an RtpFileSource reading from `file_name`. If the file cannot be
// opened, or has the wrong format, NULL will be returned.
static RtpFileSource* Create(
const std::string& file_name,
absl::string_view file_name,
absl::optional<uint32_t> ssrc_filter = absl::nullopt);
// Checks whether a files is a valid RTP dump or PCAP (Wireshark) file.
static bool ValidRtpDump(const std::string& file_name);
static bool ValidPcap(const std::string& file_name);
static bool ValidRtpDump(absl::string_view file_name);
static bool ValidPcap(absl::string_view file_name);
~RtpFileSource() override;
@ -55,7 +56,7 @@ class RtpFileSource : public PacketSource {
explicit RtpFileSource(absl::optional<uint32_t> ssrc_filter);
bool OpenFile(const std::string& file_name);
bool OpenFile(absl::string_view file_name);
std::unique_ptr<RtpFileReader> rtp_reader_;
const absl::optional<uint32_t> ssrc_filter_;