mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
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:
parent
90133b3d3f
commit
277766f55e
20 changed files with 100 additions and 56 deletions
|
@ -71,6 +71,7 @@ rtc_library("rtc_stream_config") {
|
|||
"../api:rtp_headers",
|
||||
"../api:rtp_parameters",
|
||||
]
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||
}
|
||||
|
||||
rtc_library("rtc_event_pacing") {
|
||||
|
@ -376,7 +377,10 @@ if (rtc_enable_protobuf) {
|
|||
"../rtc_base:timeutils",
|
||||
"../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 = [
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
@ -523,6 +528,7 @@ if (rtc_enable_protobuf) {
|
|||
]
|
||||
absl_deps = [
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//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:usage",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <utility>
|
||||
|
||||
#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/var_int.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
|
||||
// be decoded successfully. It DOES imply that all other decoder classes
|
||||
// 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
|
||||
// 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
|
||||
// vector will be returned.
|
||||
static std::vector<absl::optional<uint64_t>> DecodeDeltas(
|
||||
const std::string& input,
|
||||
absl::string_view input,
|
||||
absl::optional<uint64_t> base,
|
||||
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
|
||||
// examined and guaranteed.
|
||||
static std::unique_ptr<FixedLengthDeltaDecoder> Create(
|
||||
const std::string& input,
|
||||
absl::string_view input,
|
||||
absl::optional<uint64_t> base,
|
||||
size_t num_of_deltas);
|
||||
|
||||
|
@ -624,7 +625,7 @@ class FixedLengthDeltaDecoder final {
|
|||
const size_t num_of_deltas_;
|
||||
};
|
||||
|
||||
bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(const std::string& input) {
|
||||
bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(absl::string_view input) {
|
||||
BitstreamReader reader(input);
|
||||
uint64_t encoding_type_bits = reader.ReadBits(kBitsInHeaderForEncodingType);
|
||||
if (!reader.Ok()) {
|
||||
|
@ -639,7 +640,7 @@ bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(const std::string& input) {
|
|||
}
|
||||
|
||||
std::vector<absl::optional<uint64_t>> FixedLengthDeltaDecoder::DecodeDeltas(
|
||||
const std::string& input,
|
||||
absl::string_view input,
|
||||
absl::optional<uint64_t> base,
|
||||
size_t 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(
|
||||
const std::string& input,
|
||||
absl::string_view input,
|
||||
absl::optional<uint64_t> base,
|
||||
size_t num_of_deltas) {
|
||||
BitstreamReader reader(input);
|
||||
|
@ -804,7 +805,7 @@ std::string EncodeDeltas(absl::optional<uint64_t> base,
|
|||
}
|
||||
|
||||
std::vector<absl::optional<uint64_t>> DecodeDeltas(
|
||||
const std::string& input,
|
||||
absl::string_view input,
|
||||
absl::optional<uint64_t> base,
|
||||
size_t num_of_deltas) {
|
||||
RTC_DCHECK_GT(num_of_deltas, 0); // Allows empty vector to indicate error.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
@ -39,7 +40,7 @@ std::string EncodeDeltas(absl::optional<uint64_t> base,
|
|||
// vector, which signals an error.
|
||||
// TODO(eladalon): Split into optional and non-optional variants (efficiency).
|
||||
std::vector<absl::optional<uint64_t>> DecodeDeltas(
|
||||
const std::string& input,
|
||||
absl::string_view input,
|
||||
absl::optional<uint64_t> base,
|
||||
size_t num_of_deltas);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/rtp_headers.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
||||
|
@ -79,7 +80,7 @@ struct LoggedRtpPacketOutgoing {
|
|||
struct LoggedRtcpPacket {
|
||||
LoggedRtcpPacket(Timestamp timestamp, const std::vector<uint8_t>& 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()) {
|
||||
memcpy(raw_data.data(), packet.data(), packet.size());
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ struct LoggedRtcpPacketIncoming {
|
|||
LoggedRtcpPacketIncoming(Timestamp timestamp,
|
||||
const std::vector<uint8_t>& packet)
|
||||
: rtcp(timestamp, packet) {}
|
||||
LoggedRtcpPacketIncoming(Timestamp timestamp, const std::string& packet)
|
||||
LoggedRtcpPacketIncoming(Timestamp timestamp, absl::string_view packet)
|
||||
: rtcp(timestamp, packet) {}
|
||||
|
||||
int64_t log_time_us() const { return rtcp.timestamp.us(); }
|
||||
|
@ -114,7 +115,7 @@ struct LoggedRtcpPacketOutgoing {
|
|||
LoggedRtcpPacketOutgoing(Timestamp timestamp,
|
||||
const std::vector<uint8_t>& packet)
|
||||
: rtcp(timestamp, packet) {}
|
||||
LoggedRtcpPacketOutgoing(Timestamp timestamp, const std::string& packet)
|
||||
LoggedRtcpPacketOutgoing(Timestamp timestamp, absl::string_view packet)
|
||||
: rtcp(timestamp, packet) {}
|
||||
|
||||
int64_t log_time_us() const { return rtcp.timestamp.us(); }
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_field_encoding.h"
|
||||
|
||||
// TODO(terelius): Compared to a generic 'Status' class, this
|
||||
|
@ -29,8 +30,8 @@ class RtcEventLogParseStatus {
|
|||
|
||||
public:
|
||||
static RtcEventLogParseStatus Success() { return RtcEventLogParseStatus(); }
|
||||
static RtcEventLogParseStatus Error(std::string error,
|
||||
std::string file,
|
||||
static RtcEventLogParseStatus Error(absl::string_view error,
|
||||
absl::string_view file,
|
||||
int line) {
|
||||
return RtcEventLogParseStatus(error, file, line);
|
||||
}
|
||||
|
@ -44,8 +45,11 @@ class RtcEventLogParseStatus {
|
|||
|
||||
private:
|
||||
RtcEventLogParseStatus() : error_() {}
|
||||
RtcEventLogParseStatus(std::string error, std::string file, int line)
|
||||
: error_(error + " (" + file + ": " + std::to_string(line) + ")") {}
|
||||
RtcEventLogParseStatus(absl::string_view error,
|
||||
absl::string_view file,
|
||||
int line)
|
||||
: error_(std::string(error) + " (" + std::string(file) + ": " +
|
||||
std::to_string(line) + ")") {}
|
||||
|
||||
std::string error_;
|
||||
};
|
||||
|
@ -74,15 +78,17 @@ class RtcEventLogParseStatusOr {
|
|||
return value_;
|
||||
}
|
||||
|
||||
static RtcEventLogParseStatusOr Error(std::string error,
|
||||
std::string file,
|
||||
static RtcEventLogParseStatusOr Error(absl::string_view error,
|
||||
absl::string_view file,
|
||||
int line) {
|
||||
return RtcEventLogParseStatusOr(error, file, line);
|
||||
}
|
||||
|
||||
private:
|
||||
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_() {}
|
||||
|
||||
RtcEventLogParseStatus status_;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/rtc_event_log/rtc_event.h"
|
||||
#include "logging/rtc_event_log/encoder/var_int.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<int64_t> optional_signed64,
|
||||
uint32_t wrapping21,
|
||||
std::string string)
|
||||
absl::string_view string)
|
||||
: b_(b),
|
||||
signed32_(signed32),
|
||||
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) {
|
||||
fprintf(stderr, "%d ", static_cast<uint8_t>(c));
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "absl/flags/parse.h"
|
||||
#include "absl/flags/usage.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.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
|
||||
// of the command-line flag. In this case, no value is written to the output
|
||||
// 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.
|
||||
uint32_t ssrc;
|
||||
auto read_mode = std::dec;
|
||||
|
@ -84,7 +85,7 @@ absl::optional<uint32_t> ParseSsrc(std::string str) {
|
|||
read_mode = std::hex;
|
||||
str = str.substr(2);
|
||||
}
|
||||
std::stringstream ss(str);
|
||||
std::stringstream ss(std::string{str});
|
||||
ss >> read_mode >> ssrc;
|
||||
if (str.empty() || (!ss.fail() && ss.eof()))
|
||||
return ssrc;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/task_queue/queued_task.h"
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
|
@ -230,8 +231,8 @@ void RtcEventLogImpl::LogEventsFromMemoryToOutput() {
|
|||
}
|
||||
|
||||
void RtcEventLogImpl::WriteConfigsAndHistoryToOutput(
|
||||
const std::string& encoded_configs,
|
||||
const std::string& encoded_history) {
|
||||
absl::string_view encoded_configs,
|
||||
absl::string_view encoded_history) {
|
||||
// This function is used to merge the strings instead of calling the output
|
||||
// object twice with small strings. The function also avoids copying any
|
||||
// strings in the typical case where there are no config events.
|
||||
|
@ -240,7 +241,11 @@ void RtcEventLogImpl::WriteConfigsAndHistoryToOutput(
|
|||
} else if (encoded_history.empty()) {
|
||||
WriteToOutput(encoded_configs); // Very unusual case.
|
||||
} 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();
|
||||
}
|
||||
|
||||
void RtcEventLogImpl::WriteToOutput(const std::string& output_string) {
|
||||
void RtcEventLogImpl::WriteToOutput(absl::string_view output_string) {
|
||||
RTC_DCHECK(event_output_ && event_output_->IsActive());
|
||||
if (!event_output_->Write(output_string)) {
|
||||
RTC_LOG(LS_ERROR) << "Failed to write RTC event to output.";
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/rtc_event_log/rtc_event.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 WriteConfigsAndHistoryToOutput(const std::string& encoded_configs,
|
||||
const std::string& encoded_history)
|
||||
void WriteConfigsAndHistoryToOutput(absl::string_view encoded_configs,
|
||||
absl::string_view encoded_history)
|
||||
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_);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <utility>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/network_state_predictor.h"
|
||||
#include "api/rtc_event_log/rtc_event_log.h"
|
||||
|
@ -1114,7 +1115,7 @@ void ParsedRtcEventLog::Clear() {
|
|||
}
|
||||
|
||||
ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseFile(
|
||||
const std::string& filename) {
|
||||
absl::string_view filename) {
|
||||
FileWrapper file = FileWrapper::OpenReadOnly(filename);
|
||||
if (!file.is_open()) {
|
||||
RTC_LOG(LS_WARNING) << "Could not open file " << filename
|
||||
|
@ -1140,12 +1141,12 @@ ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseFile(
|
|||
}
|
||||
|
||||
ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseString(
|
||||
const std::string& s) {
|
||||
absl::string_view s) {
|
||||
return ParseStream(s);
|
||||
}
|
||||
|
||||
ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseStream(
|
||||
const std::string& s) {
|
||||
absl::string_view s) {
|
||||
Clear();
|
||||
ParseStatus status = ParseStreamInternal(s);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/rtc_event_log/rtc_event_log.h"
|
||||
#include "call/video_receive_stream.h"
|
||||
#include "call/video_send_stream.h"
|
||||
|
@ -379,13 +380,13 @@ class ParsedRtcEventLog {
|
|||
void Clear();
|
||||
|
||||
// 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.
|
||||
ParseStatus ParseString(const std::string& s);
|
||||
ParseStatus ParseString(absl::string_view s);
|
||||
|
||||
// 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;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.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,
|
||||
const std::string& uri) {
|
||||
absl::string_view uri) {
|
||||
for (const auto& extension : extensions) {
|
||||
if (extension.uri == uri)
|
||||
return extension.id;
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "logging/rtc_event_log/rtc_stream_config.h"
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace rtclog {
|
||||
|
||||
|
@ -30,7 +32,7 @@ bool StreamConfig::operator!=(const StreamConfig& other) const {
|
|||
return !(*this == other);
|
||||
}
|
||||
|
||||
StreamConfig::Codec::Codec(const std::string& payload_name,
|
||||
StreamConfig::Codec::Codec(absl::string_view payload_name,
|
||||
int payload_type,
|
||||
int rtx_payload_type)
|
||||
: payload_name(payload_name),
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/rtp_headers.h"
|
||||
#include "api/rtp_parameters.h"
|
||||
|
||||
|
@ -41,7 +42,7 @@ struct StreamConfig {
|
|||
RtcpMode rtcp_mode = RtcpMode::kReducedSize;
|
||||
|
||||
struct Codec {
|
||||
Codec(const std::string& payload_name,
|
||||
Codec(absl::string_view payload_name,
|
||||
int payload_type,
|
||||
int rtx_payload_type);
|
||||
|
||||
|
|
|
@ -28,5 +28,8 @@ rtc_library("log_writer") {
|
|||
"../../rtc_base:stringutils",
|
||||
"../../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",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "test/testsupport/file_utils.h"
|
||||
|
@ -18,8 +19,8 @@
|
|||
namespace webrtc {
|
||||
namespace webrtc_impl {
|
||||
|
||||
FileLogWriter::FileLogWriter(std::string file_path)
|
||||
: out_(std::fopen(file_path.c_str(), "wb")) {
|
||||
FileLogWriter::FileLogWriter(absl::string_view file_path)
|
||||
: out_(std::fopen(std::string(file_path).c_str(), "wb")) {
|
||||
RTC_CHECK(out_ != nullptr)
|
||||
<< "Failed to open file: '" << file_path << "' for writing.";
|
||||
}
|
||||
|
@ -46,7 +47,7 @@ void FileLogWriter::Flush() {
|
|||
|
||||
} // namespace webrtc_impl
|
||||
|
||||
FileLogWriterFactory::FileLogWriterFactory(std::string base_path)
|
||||
FileLogWriterFactory::FileLogWriterFactory(absl::string_view base_path)
|
||||
: base_path_(base_path) {
|
||||
for (size_t i = 0; i < base_path.size(); ++i) {
|
||||
if (base_path[i] == '/')
|
||||
|
@ -57,7 +58,8 @@ FileLogWriterFactory::FileLogWriterFactory(std::string base_path)
|
|||
FileLogWriterFactory::~FileLogWriterFactory() {}
|
||||
|
||||
std::unique_ptr<RtcEventLogOutput> FileLogWriterFactory::Create(
|
||||
std::string filename) {
|
||||
return std::make_unique<webrtc_impl::FileLogWriter>(base_path_ + filename);
|
||||
absl::string_view filename) {
|
||||
return std::make_unique<webrtc_impl::FileLogWriter>(base_path_ +
|
||||
std::string(filename));
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -15,13 +15,14 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "test/logging/log_writer.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace webrtc_impl {
|
||||
class FileLogWriter final : public RtcEventLogOutput {
|
||||
public:
|
||||
explicit FileLogWriter(std::string file_path);
|
||||
explicit FileLogWriter(absl::string_view file_path);
|
||||
~FileLogWriter() final;
|
||||
bool IsActive() const override;
|
||||
bool Write(absl::string_view value) override;
|
||||
|
@ -33,10 +34,11 @@ class FileLogWriter final : public RtcEventLogOutput {
|
|||
} // namespace webrtc_impl
|
||||
class FileLogWriterFactory final : public LogWriterFactoryInterface {
|
||||
public:
|
||||
explicit FileLogWriterFactory(std::string base_path);
|
||||
explicit FileLogWriterFactory(absl::string_view base_path);
|
||||
~FileLogWriterFactory() final;
|
||||
|
||||
std::unique_ptr<RtcEventLogOutput> Create(std::string filename) override;
|
||||
std::unique_ptr<RtcEventLogOutput> Create(
|
||||
absl::string_view filename) override;
|
||||
|
||||
private:
|
||||
const std::string base_path_;
|
||||
|
|
|
@ -9,16 +9,18 @@
|
|||
*/
|
||||
#include "test/logging/log_writer.h"
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
LogWriterFactoryAddPrefix::LogWriterFactoryAddPrefix(
|
||||
LogWriterFactoryInterface* base,
|
||||
std::string prefix)
|
||||
absl::string_view prefix)
|
||||
: base_factory_(base), prefix_(prefix) {}
|
||||
|
||||
std::unique_ptr<RtcEventLogOutput> LogWriterFactoryAddPrefix::Create(
|
||||
std::string filename) {
|
||||
return base_factory_->Create(prefix_ + filename);
|
||||
absl::string_view filename) {
|
||||
return base_factory_->Create(prefix_ + std::string(filename));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/rtc_event_log_output.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
|
@ -42,15 +43,17 @@ inline void LogWriteFormat(RtcEventLogOutput* out_, const char* fmt, ...) {
|
|||
|
||||
class LogWriterFactoryInterface {
|
||||
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;
|
||||
};
|
||||
|
||||
class LogWriterFactoryAddPrefix : public LogWriterFactoryInterface {
|
||||
public:
|
||||
LogWriterFactoryAddPrefix(LogWriterFactoryInterface* base,
|
||||
std::string prefix);
|
||||
std::unique_ptr<RtcEventLogOutput> Create(std::string filename) override;
|
||||
absl::string_view prefix);
|
||||
std::unique_ptr<RtcEventLogOutput> Create(
|
||||
absl::string_view filename) override;
|
||||
|
||||
private:
|
||||
LogWriterFactoryInterface* const base_factory_;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
|
@ -19,7 +20,7 @@ namespace {
|
|||
class MemoryLogWriter final : public RtcEventLogOutput {
|
||||
public:
|
||||
explicit MemoryLogWriter(std::map<std::string, std::string>* target,
|
||||
std::string filename)
|
||||
absl::string_view filename)
|
||||
: target_(target), filename_(filename) {}
|
||||
~MemoryLogWriter() final { target_->insert({filename_, std::move(buffer_)}); }
|
||||
bool IsActive() const override { return true; }
|
||||
|
@ -40,7 +41,8 @@ class MemoryLogWriterFactory final : public LogWriterFactoryInterface {
|
|||
explicit MemoryLogWriterFactory(std::map<std::string, std::string>* target)
|
||||
: target_(target) {}
|
||||
~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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue