adopt absl::string_view in logging/

Bug: webrtc:13579
Change-Id: Ibc5fa7842d52321d61cc4cdd4770635af737ddff
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267170
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37533}
This commit is contained in:
Ali Tofigh 2022-07-15 00:44:02 +02:00 committed by WebRTC LUCI CQ
parent 90133b3d3f
commit 277766f55e
20 changed files with 100 additions and 56 deletions

View file

@ -71,6 +71,7 @@ rtc_library("rtc_stream_config") {
"../api:rtp_headers", "../api:rtp_headers",
"../api:rtp_parameters", "../api:rtp_parameters",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
} }
rtc_library("rtc_event_pacing") { rtc_library("rtc_event_pacing") {
@ -376,7 +377,10 @@ if (rtc_enable_protobuf) {
"../rtc_base:timeutils", "../rtc_base:timeutils",
"../rtc_base/system:no_unique_address", "../rtc_base/system:no_unique_address",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] absl_deps = [
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
]
} }
} }
@ -459,6 +463,7 @@ if (rtc_enable_protobuf) {
] ]
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
} }
@ -523,6 +528,7 @@ if (rtc_enable_protobuf) {
] ]
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
} }
@ -545,6 +551,7 @@ if (rtc_enable_protobuf) {
"//third_party/abseil-cpp/absl/flags:parse", "//third_party/abseil-cpp/absl/flags:parse",
"//third_party/abseil-cpp/absl/flags:usage", "//third_party/abseil-cpp/absl/flags:usage",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
} }

View file

@ -16,6 +16,7 @@
#include <utility> #include <utility>
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "logging/rtc_event_log/encoder/bit_writer.h" #include "logging/rtc_event_log/encoder/bit_writer.h"
#include "logging/rtc_event_log/encoder/var_int.h" #include "logging/rtc_event_log/encoder/var_int.h"
#include "rtc_base/bit_buffer.h" #include "rtc_base/bit_buffer.h"
@ -554,7 +555,7 @@ class FixedLengthDeltaDecoder final {
// bitstream. Note that this does NOT imply that stream is valid, and will // bitstream. Note that this does NOT imply that stream is valid, and will
// be decoded successfully. It DOES imply that all other decoder classes // be decoded successfully. It DOES imply that all other decoder classes
// will fail to decode this input, though. // will fail to decode this input, though.
static bool IsSuitableDecoderFor(const std::string& input); static bool IsSuitableDecoderFor(absl::string_view input);
// Assuming that `input` is the result of fixed-size delta-encoding // Assuming that `input` is the result of fixed-size delta-encoding
// that took place with the same value to `base` and over `num_of_deltas` // that took place with the same value to `base` and over `num_of_deltas`
@ -562,7 +563,7 @@ class FixedLengthDeltaDecoder final {
// If an error occurs (can happen if `input` is corrupt), an empty // If an error occurs (can happen if `input` is corrupt), an empty
// vector will be returned. // vector will be returned.
static std::vector<absl::optional<uint64_t>> DecodeDeltas( static std::vector<absl::optional<uint64_t>> DecodeDeltas(
const std::string& input, absl::string_view input,
absl::optional<uint64_t> base, absl::optional<uint64_t> base,
size_t num_of_deltas); size_t num_of_deltas);
@ -579,7 +580,7 @@ class FixedLengthDeltaDecoder final {
// the entire stream is free of error. Rather, only the encoding header is // the entire stream is free of error. Rather, only the encoding header is
// examined and guaranteed. // examined and guaranteed.
static std::unique_ptr<FixedLengthDeltaDecoder> Create( static std::unique_ptr<FixedLengthDeltaDecoder> Create(
const std::string& input, absl::string_view input,
absl::optional<uint64_t> base, absl::optional<uint64_t> base,
size_t num_of_deltas); size_t num_of_deltas);
@ -624,7 +625,7 @@ class FixedLengthDeltaDecoder final {
const size_t num_of_deltas_; const size_t num_of_deltas_;
}; };
bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(const std::string& input) { bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(absl::string_view input) {
BitstreamReader reader(input); BitstreamReader reader(input);
uint64_t encoding_type_bits = reader.ReadBits(kBitsInHeaderForEncodingType); uint64_t encoding_type_bits = reader.ReadBits(kBitsInHeaderForEncodingType);
if (!reader.Ok()) { if (!reader.Ok()) {
@ -639,7 +640,7 @@ bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(const std::string& input) {
} }
std::vector<absl::optional<uint64_t>> FixedLengthDeltaDecoder::DecodeDeltas( std::vector<absl::optional<uint64_t>> FixedLengthDeltaDecoder::DecodeDeltas(
const std::string& input, absl::string_view input,
absl::optional<uint64_t> base, absl::optional<uint64_t> base,
size_t num_of_deltas) { size_t num_of_deltas) {
auto decoder = FixedLengthDeltaDecoder::Create(input, base, num_of_deltas); auto decoder = FixedLengthDeltaDecoder::Create(input, base, num_of_deltas);
@ -651,7 +652,7 @@ std::vector<absl::optional<uint64_t>> FixedLengthDeltaDecoder::DecodeDeltas(
} }
std::unique_ptr<FixedLengthDeltaDecoder> FixedLengthDeltaDecoder::Create( std::unique_ptr<FixedLengthDeltaDecoder> FixedLengthDeltaDecoder::Create(
const std::string& input, absl::string_view input,
absl::optional<uint64_t> base, absl::optional<uint64_t> base,
size_t num_of_deltas) { size_t num_of_deltas) {
BitstreamReader reader(input); BitstreamReader reader(input);
@ -804,7 +805,7 @@ std::string EncodeDeltas(absl::optional<uint64_t> base,
} }
std::vector<absl::optional<uint64_t>> DecodeDeltas( std::vector<absl::optional<uint64_t>> DecodeDeltas(
const std::string& input, absl::string_view input,
absl::optional<uint64_t> base, absl::optional<uint64_t> base,
size_t num_of_deltas) { size_t num_of_deltas) {
RTC_DCHECK_GT(num_of_deltas, 0); // Allows empty vector to indicate error. RTC_DCHECK_GT(num_of_deltas, 0); // Allows empty vector to indicate error.

View file

@ -17,6 +17,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
namespace webrtc { namespace webrtc {
@ -39,7 +40,7 @@ std::string EncodeDeltas(absl::optional<uint64_t> base,
// vector, which signals an error. // vector, which signals an error.
// TODO(eladalon): Split into optional and non-optional variants (efficiency). // TODO(eladalon): Split into optional and non-optional variants (efficiency).
std::vector<absl::optional<uint64_t>> DecodeDeltas( std::vector<absl::optional<uint64_t>> DecodeDeltas(
const std::string& input, absl::string_view input,
absl::optional<uint64_t> base, absl::optional<uint64_t> base,
size_t num_of_deltas); size_t num_of_deltas);

View file

@ -14,6 +14,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "api/rtp_headers.h" #include "api/rtp_headers.h"
#include "api/units/timestamp.h" #include "api/units/timestamp.h"
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h" #include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
@ -79,7 +80,7 @@ struct LoggedRtpPacketOutgoing {
struct LoggedRtcpPacket { struct LoggedRtcpPacket {
LoggedRtcpPacket(Timestamp timestamp, const std::vector<uint8_t>& packet) LoggedRtcpPacket(Timestamp timestamp, const std::vector<uint8_t>& packet)
: timestamp(timestamp), raw_data(packet) {} : timestamp(timestamp), raw_data(packet) {}
LoggedRtcpPacket(Timestamp timestamp, const std::string& packet) LoggedRtcpPacket(Timestamp timestamp, absl::string_view packet)
: timestamp(timestamp), raw_data(packet.size()) { : timestamp(timestamp), raw_data(packet.size()) {
memcpy(raw_data.data(), packet.data(), packet.size()); memcpy(raw_data.data(), packet.data(), packet.size());
} }
@ -100,7 +101,7 @@ struct LoggedRtcpPacketIncoming {
LoggedRtcpPacketIncoming(Timestamp timestamp, LoggedRtcpPacketIncoming(Timestamp timestamp,
const std::vector<uint8_t>& packet) const std::vector<uint8_t>& packet)
: rtcp(timestamp, packet) {} : rtcp(timestamp, packet) {}
LoggedRtcpPacketIncoming(Timestamp timestamp, const std::string& packet) LoggedRtcpPacketIncoming(Timestamp timestamp, absl::string_view packet)
: rtcp(timestamp, packet) {} : rtcp(timestamp, packet) {}
int64_t log_time_us() const { return rtcp.timestamp.us(); } int64_t log_time_us() const { return rtcp.timestamp.us(); }
@ -114,7 +115,7 @@ struct LoggedRtcpPacketOutgoing {
LoggedRtcpPacketOutgoing(Timestamp timestamp, LoggedRtcpPacketOutgoing(Timestamp timestamp,
const std::vector<uint8_t>& packet) const std::vector<uint8_t>& packet)
: rtcp(timestamp, packet) {} : rtcp(timestamp, packet) {}
LoggedRtcpPacketOutgoing(Timestamp timestamp, const std::string& packet) LoggedRtcpPacketOutgoing(Timestamp timestamp, absl::string_view packet)
: rtcp(timestamp, packet) {} : rtcp(timestamp, packet) {}
int64_t log_time_us() const { return rtcp.timestamp.us(); } int64_t log_time_us() const { return rtcp.timestamp.us(); }

View file

@ -14,6 +14,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "logging/rtc_event_log/events/rtc_event_field_encoding.h" #include "logging/rtc_event_log/events/rtc_event_field_encoding.h"
// TODO(terelius): Compared to a generic 'Status' class, this // TODO(terelius): Compared to a generic 'Status' class, this
@ -29,8 +30,8 @@ class RtcEventLogParseStatus {
public: public:
static RtcEventLogParseStatus Success() { return RtcEventLogParseStatus(); } static RtcEventLogParseStatus Success() { return RtcEventLogParseStatus(); }
static RtcEventLogParseStatus Error(std::string error, static RtcEventLogParseStatus Error(absl::string_view error,
std::string file, absl::string_view file,
int line) { int line) {
return RtcEventLogParseStatus(error, file, line); return RtcEventLogParseStatus(error, file, line);
} }
@ -44,8 +45,11 @@ class RtcEventLogParseStatus {
private: private:
RtcEventLogParseStatus() : error_() {} RtcEventLogParseStatus() : error_() {}
RtcEventLogParseStatus(std::string error, std::string file, int line) RtcEventLogParseStatus(absl::string_view error,
: error_(error + " (" + file + ": " + std::to_string(line) + ")") {} absl::string_view file,
int line)
: error_(std::string(error) + " (" + std::string(file) + ": " +
std::to_string(line) + ")") {}
std::string error_; std::string error_;
}; };
@ -74,15 +78,17 @@ class RtcEventLogParseStatusOr {
return value_; return value_;
} }
static RtcEventLogParseStatusOr Error(std::string error, static RtcEventLogParseStatusOr Error(absl::string_view error,
std::string file, absl::string_view file,
int line) { int line) {
return RtcEventLogParseStatusOr(error, file, line); return RtcEventLogParseStatusOr(error, file, line);
} }
private: private:
RtcEventLogParseStatusOr() : status_() {} RtcEventLogParseStatusOr() : status_() {}
RtcEventLogParseStatusOr(std::string error, std::string file, int line) RtcEventLogParseStatusOr(absl::string_view error,
absl::string_view file,
int line)
: status_(error, file, line), value_() {} : status_(error, file, line), value_() {}
RtcEventLogParseStatus status_; RtcEventLogParseStatus status_;

View file

@ -12,6 +12,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "absl/strings/string_view.h"
#include "api/rtc_event_log/rtc_event.h" #include "api/rtc_event_log/rtc_event.h"
#include "logging/rtc_event_log/encoder/var_int.h" #include "logging/rtc_event_log/encoder/var_int.h"
#include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h" #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h"
@ -158,7 +159,7 @@ class RtcTestEvent final : public RtcEvent {
absl::optional<int32_t> optional_signed32, absl::optional<int32_t> optional_signed32,
absl::optional<int64_t> optional_signed64, absl::optional<int64_t> optional_signed64,
uint32_t wrapping21, uint32_t wrapping21,
std::string string) absl::string_view string)
: b_(b), : b_(b),
signed32_(signed32), signed32_(signed32),
unsigned32_(unsigned32), unsigned32_(unsigned32),
@ -255,7 +256,7 @@ class RtcEventFieldTest : public ::testing::Test {
} }
} }
void PrintBytes(const std::string& s) { void PrintBytes(absl::string_view s) {
for (auto c : s) { for (auto c : s) {
fprintf(stderr, "%d ", static_cast<uint8_t>(c)); fprintf(stderr, "%d ", static_cast<uint8_t>(c));
} }

View file

@ -21,6 +21,7 @@
#include "absl/flags/parse.h" #include "absl/flags/parse.h"
#include "absl/flags/usage.h" #include "absl/flags/usage.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/array_view.h" #include "api/array_view.h"
#include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log/rtc_event_log.h"
@ -75,7 +76,7 @@ using MediaType = webrtc::ParsedRtcEventLog::MediaType;
// The empty string must be validated as true, because it is the default value // The empty string must be validated as true, because it is the default value
// of the command-line flag. In this case, no value is written to the output // of the command-line flag. In this case, no value is written to the output
// variable. // variable.
absl::optional<uint32_t> ParseSsrc(std::string str) { absl::optional<uint32_t> ParseSsrc(absl::string_view str) {
// If the input string starts with 0x or 0X it indicates a hexadecimal number. // If the input string starts with 0x or 0X it indicates a hexadecimal number.
uint32_t ssrc; uint32_t ssrc;
auto read_mode = std::dec; auto read_mode = std::dec;
@ -84,7 +85,7 @@ absl::optional<uint32_t> ParseSsrc(std::string str) {
read_mode = std::hex; read_mode = std::hex;
str = str.substr(2); str = str.substr(2);
} }
std::stringstream ss(str); std::stringstream ss(std::string{str});
ss >> read_mode >> ssrc; ss >> read_mode >> ssrc;
if (str.empty() || (!ss.fail() && ss.eof())) if (str.empty() || (!ss.fail() && ss.eof()))
return ssrc; return ssrc;

View file

@ -16,6 +16,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/task_queue/queued_task.h" #include "api/task_queue/queued_task.h"
#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_base.h"
@ -230,8 +231,8 @@ void RtcEventLogImpl::LogEventsFromMemoryToOutput() {
} }
void RtcEventLogImpl::WriteConfigsAndHistoryToOutput( void RtcEventLogImpl::WriteConfigsAndHistoryToOutput(
const std::string& encoded_configs, absl::string_view encoded_configs,
const std::string& encoded_history) { absl::string_view encoded_history) {
// This function is used to merge the strings instead of calling the output // This function is used to merge the strings instead of calling the output
// object twice with small strings. The function also avoids copying any // object twice with small strings. The function also avoids copying any
// strings in the typical case where there are no config events. // strings in the typical case where there are no config events.
@ -240,7 +241,11 @@ void RtcEventLogImpl::WriteConfigsAndHistoryToOutput(
} else if (encoded_history.empty()) { } else if (encoded_history.empty()) {
WriteToOutput(encoded_configs); // Very unusual case. WriteToOutput(encoded_configs); // Very unusual case.
} else { } else {
WriteToOutput(encoded_configs + encoded_history); std::string s;
s.reserve(encoded_configs.size() + encoded_history.size());
s.append(encoded_configs.data(), encoded_configs.size());
s.append(encoded_history.data(), encoded_history.size());
WriteToOutput(s);
} }
} }
@ -257,7 +262,7 @@ void RtcEventLogImpl::StopLoggingInternal() {
StopOutput(); StopOutput();
} }
void RtcEventLogImpl::WriteToOutput(const std::string& output_string) { void RtcEventLogImpl::WriteToOutput(absl::string_view output_string) {
RTC_DCHECK(event_output_ && event_output_->IsActive()); RTC_DCHECK(event_output_ && event_output_->IsActive());
if (!event_output_->Write(output_string)) { if (!event_output_->Write(output_string)) {
RTC_LOG(LS_ERROR) << "Failed to write RTC event to output."; RTC_LOG(LS_ERROR) << "Failed to write RTC event to output.";

View file

@ -17,6 +17,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/rtc_event_log/rtc_event.h" #include "api/rtc_event_log/rtc_event.h"
#include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log/rtc_event_log.h"
@ -54,10 +55,10 @@ class RtcEventLogImpl final : public RtcEventLog {
void StopOutput() RTC_RUN_ON(task_queue_); void StopOutput() RTC_RUN_ON(task_queue_);
void WriteConfigsAndHistoryToOutput(const std::string& encoded_configs, void WriteConfigsAndHistoryToOutput(absl::string_view encoded_configs,
const std::string& encoded_history) absl::string_view encoded_history)
RTC_RUN_ON(task_queue_); RTC_RUN_ON(task_queue_);
void WriteToOutput(const std::string& output_string) RTC_RUN_ON(task_queue_); void WriteToOutput(absl::string_view output_string) RTC_RUN_ON(task_queue_);
void StopLoggingInternal() RTC_RUN_ON(task_queue_); void StopLoggingInternal() RTC_RUN_ON(task_queue_);

View file

@ -19,6 +19,7 @@
#include <utility> #include <utility>
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/network_state_predictor.h" #include "api/network_state_predictor.h"
#include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log/rtc_event_log.h"
@ -1114,7 +1115,7 @@ void ParsedRtcEventLog::Clear() {
} }
ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseFile( ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseFile(
const std::string& filename) { absl::string_view filename) {
FileWrapper file = FileWrapper::OpenReadOnly(filename); FileWrapper file = FileWrapper::OpenReadOnly(filename);
if (!file.is_open()) { if (!file.is_open()) {
RTC_LOG(LS_WARNING) << "Could not open file " << filename RTC_LOG(LS_WARNING) << "Could not open file " << filename
@ -1140,12 +1141,12 @@ ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseFile(
} }
ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseString( ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseString(
const std::string& s) { absl::string_view s) {
return ParseStream(s); return ParseStream(s);
} }
ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseStream( ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseStream(
const std::string& s) { absl::string_view s) {
Clear(); Clear();
ParseStatus status = ParseStreamInternal(s); ParseStatus status = ParseStreamInternal(s);

View file

@ -18,6 +18,7 @@
#include <vector> #include <vector>
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
#include "absl/strings/string_view.h"
#include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log/rtc_event_log.h"
#include "call/video_receive_stream.h" #include "call/video_receive_stream.h"
#include "call/video_send_stream.h" #include "call/video_send_stream.h"
@ -379,13 +380,13 @@ class ParsedRtcEventLog {
void Clear(); void Clear();
// Reads an RtcEventLog file and returns success if parsing was successful. // Reads an RtcEventLog file and returns success if parsing was successful.
ParseStatus ParseFile(const std::string& file_name); ParseStatus ParseFile(absl::string_view file_name);
// Reads an RtcEventLog from a string and returns success if successful. // Reads an RtcEventLog from a string and returns success if successful.
ParseStatus ParseString(const std::string& s); ParseStatus ParseString(absl::string_view s);
// Reads an RtcEventLog from an string and returns success if successful. // Reads an RtcEventLog from an string and returns success if successful.
ParseStatus ParseStream(const std::string& s); ParseStatus ParseStream(absl::string_view s);
MediaType GetMediaType(uint32_t ssrc, PacketDirection direction) const; MediaType GetMediaType(uint32_t ssrc, PacketDirection direction) const;

View file

@ -21,6 +21,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/array_view.h" #include "api/array_view.h"
#include "api/network_state_predictor.h" #include "api/network_state_predictor.h"
@ -81,7 +82,7 @@ void ShuffleInPlace(Random* prng, rtc::ArrayView<T> array) {
} }
absl::optional<int> GetExtensionId(const std::vector<RtpExtension>& extensions, absl::optional<int> GetExtensionId(const std::vector<RtpExtension>& extensions,
const std::string& uri) { absl::string_view uri) {
for (const auto& extension : extensions) { for (const auto& extension : extensions) {
if (extension.uri == uri) if (extension.uri == uri)
return extension.id; return extension.id;

View file

@ -10,6 +10,8 @@
#include "logging/rtc_event_log/rtc_stream_config.h" #include "logging/rtc_event_log/rtc_stream_config.h"
#include "absl/strings/string_view.h"
namespace webrtc { namespace webrtc {
namespace rtclog { namespace rtclog {
@ -30,7 +32,7 @@ bool StreamConfig::operator!=(const StreamConfig& other) const {
return !(*this == other); return !(*this == other);
} }
StreamConfig::Codec::Codec(const std::string& payload_name, StreamConfig::Codec::Codec(absl::string_view payload_name,
int payload_type, int payload_type,
int rtx_payload_type) int rtx_payload_type)
: payload_name(payload_name), : payload_name(payload_name),

View file

@ -16,6 +16,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "api/rtp_headers.h" #include "api/rtp_headers.h"
#include "api/rtp_parameters.h" #include "api/rtp_parameters.h"
@ -41,7 +42,7 @@ struct StreamConfig {
RtcpMode rtcp_mode = RtcpMode::kReducedSize; RtcpMode rtcp_mode = RtcpMode::kReducedSize;
struct Codec { struct Codec {
Codec(const std::string& payload_name, Codec(absl::string_view payload_name,
int payload_type, int payload_type,
int rtx_payload_type); int rtx_payload_type);

View file

@ -28,5 +28,8 @@ rtc_library("log_writer") {
"../../rtc_base:stringutils", "../../rtc_base:stringutils",
"../../test:fileutils", "../../test:fileutils",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] absl_deps = [
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
]
} }

View file

@ -11,6 +11,7 @@
#include <memory> #include <memory>
#include "absl/strings/string_view.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "test/testsupport/file_utils.h" #include "test/testsupport/file_utils.h"
@ -18,8 +19,8 @@
namespace webrtc { namespace webrtc {
namespace webrtc_impl { namespace webrtc_impl {
FileLogWriter::FileLogWriter(std::string file_path) FileLogWriter::FileLogWriter(absl::string_view file_path)
: out_(std::fopen(file_path.c_str(), "wb")) { : out_(std::fopen(std::string(file_path).c_str(), "wb")) {
RTC_CHECK(out_ != nullptr) RTC_CHECK(out_ != nullptr)
<< "Failed to open file: '" << file_path << "' for writing."; << "Failed to open file: '" << file_path << "' for writing.";
} }
@ -46,7 +47,7 @@ void FileLogWriter::Flush() {
} // namespace webrtc_impl } // namespace webrtc_impl
FileLogWriterFactory::FileLogWriterFactory(std::string base_path) FileLogWriterFactory::FileLogWriterFactory(absl::string_view base_path)
: base_path_(base_path) { : base_path_(base_path) {
for (size_t i = 0; i < base_path.size(); ++i) { for (size_t i = 0; i < base_path.size(); ++i) {
if (base_path[i] == '/') if (base_path[i] == '/')
@ -57,7 +58,8 @@ FileLogWriterFactory::FileLogWriterFactory(std::string base_path)
FileLogWriterFactory::~FileLogWriterFactory() {} FileLogWriterFactory::~FileLogWriterFactory() {}
std::unique_ptr<RtcEventLogOutput> FileLogWriterFactory::Create( std::unique_ptr<RtcEventLogOutput> FileLogWriterFactory::Create(
std::string filename) { absl::string_view filename) {
return std::make_unique<webrtc_impl::FileLogWriter>(base_path_ + filename); return std::make_unique<webrtc_impl::FileLogWriter>(base_path_ +
std::string(filename));
} }
} // namespace webrtc } // namespace webrtc

View file

@ -15,13 +15,14 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "test/logging/log_writer.h" #include "test/logging/log_writer.h"
namespace webrtc { namespace webrtc {
namespace webrtc_impl { namespace webrtc_impl {
class FileLogWriter final : public RtcEventLogOutput { class FileLogWriter final : public RtcEventLogOutput {
public: public:
explicit FileLogWriter(std::string file_path); explicit FileLogWriter(absl::string_view file_path);
~FileLogWriter() final; ~FileLogWriter() final;
bool IsActive() const override; bool IsActive() const override;
bool Write(absl::string_view value) override; bool Write(absl::string_view value) override;
@ -33,10 +34,11 @@ class FileLogWriter final : public RtcEventLogOutput {
} // namespace webrtc_impl } // namespace webrtc_impl
class FileLogWriterFactory final : public LogWriterFactoryInterface { class FileLogWriterFactory final : public LogWriterFactoryInterface {
public: public:
explicit FileLogWriterFactory(std::string base_path); explicit FileLogWriterFactory(absl::string_view base_path);
~FileLogWriterFactory() final; ~FileLogWriterFactory() final;
std::unique_ptr<RtcEventLogOutput> Create(std::string filename) override; std::unique_ptr<RtcEventLogOutput> Create(
absl::string_view filename) override;
private: private:
const std::string base_path_; const std::string base_path_;

View file

@ -9,16 +9,18 @@
*/ */
#include "test/logging/log_writer.h" #include "test/logging/log_writer.h"
#include "absl/strings/string_view.h"
namespace webrtc { namespace webrtc {
LogWriterFactoryAddPrefix::LogWriterFactoryAddPrefix( LogWriterFactoryAddPrefix::LogWriterFactoryAddPrefix(
LogWriterFactoryInterface* base, LogWriterFactoryInterface* base,
std::string prefix) absl::string_view prefix)
: base_factory_(base), prefix_(prefix) {} : base_factory_(base), prefix_(prefix) {}
std::unique_ptr<RtcEventLogOutput> LogWriterFactoryAddPrefix::Create( std::unique_ptr<RtcEventLogOutput> LogWriterFactoryAddPrefix::Create(
std::string filename) { absl::string_view filename) {
return base_factory_->Create(prefix_ + filename); return base_factory_->Create(prefix_ + std::string(filename));
} }
} // namespace webrtc } // namespace webrtc

View file

@ -16,6 +16,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "absl/strings/string_view.h"
#include "api/rtc_event_log_output.h" #include "api/rtc_event_log_output.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
@ -42,15 +43,17 @@ inline void LogWriteFormat(RtcEventLogOutput* out_, const char* fmt, ...) {
class LogWriterFactoryInterface { class LogWriterFactoryInterface {
public: public:
virtual std::unique_ptr<RtcEventLogOutput> Create(std::string filename) = 0; virtual std::unique_ptr<RtcEventLogOutput> Create(
absl::string_view filename) = 0;
virtual ~LogWriterFactoryInterface() = default; virtual ~LogWriterFactoryInterface() = default;
}; };
class LogWriterFactoryAddPrefix : public LogWriterFactoryInterface { class LogWriterFactoryAddPrefix : public LogWriterFactoryInterface {
public: public:
LogWriterFactoryAddPrefix(LogWriterFactoryInterface* base, LogWriterFactoryAddPrefix(LogWriterFactoryInterface* base,
std::string prefix); absl::string_view prefix);
std::unique_ptr<RtcEventLogOutput> Create(std::string filename) override; std::unique_ptr<RtcEventLogOutput> Create(
absl::string_view filename) override;
private: private:
LogWriterFactoryInterface* const base_factory_; LogWriterFactoryInterface* const base_factory_;

View file

@ -11,6 +11,7 @@
#include <memory> #include <memory>
#include "absl/strings/string_view.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
@ -19,7 +20,7 @@ namespace {
class MemoryLogWriter final : public RtcEventLogOutput { class MemoryLogWriter final : public RtcEventLogOutput {
public: public:
explicit MemoryLogWriter(std::map<std::string, std::string>* target, explicit MemoryLogWriter(std::map<std::string, std::string>* target,
std::string filename) absl::string_view filename)
: target_(target), filename_(filename) {} : target_(target), filename_(filename) {}
~MemoryLogWriter() final { target_->insert({filename_, std::move(buffer_)}); } ~MemoryLogWriter() final { target_->insert({filename_, std::move(buffer_)}); }
bool IsActive() const override { return true; } bool IsActive() const override { return true; }
@ -40,7 +41,8 @@ class MemoryLogWriterFactory final : public LogWriterFactoryInterface {
explicit MemoryLogWriterFactory(std::map<std::string, std::string>* target) explicit MemoryLogWriterFactory(std::map<std::string, std::string>* target)
: target_(target) {} : target_(target) {}
~MemoryLogWriterFactory() override {} ~MemoryLogWriterFactory() override {}
std::unique_ptr<RtcEventLogOutput> Create(std::string filename) override { std::unique_ptr<RtcEventLogOutput> Create(
absl::string_view filename) override {
return std::make_unique<MemoryLogWriter>(target_, filename); return std::make_unique<MemoryLogWriter>(target_, filename);
} }