Bump to WebRTC M131 release

Ongoing fixes and improvements, transient suppressor is gone. Also,
dropping isac because it doesn't seem to be useful, and is just build
system deadweight now.

Upstream references:

  Version: 131.0.6778.200
  WebRTC: 79aff54b0fa9238ce3518dd9eaf9610cd6f22e82
  Chromium: 2a19506ad24af755f2a215a4c61f775393e0db42
This commit is contained in:
Arun Raghavan
2024-12-24 19:32:07 -05:00
parent 8bdb53d91c
commit b5c48b97f6
263 changed files with 4628 additions and 20416 deletions

File diff suppressed because it is too large Load Diff

View File

@ -55,11 +55,14 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg);
#include <string>
#include "absl/meta/type_traits.h"
#include "absl/strings/has_absl_stringify.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "api/scoped_refptr.h"
#include "rtc_base/numerics/safe_compare.h"
#include "rtc_base/system/inline.h"
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/type_traits.h"
// The macros here print a message to stderr and abort under various
// conditions. All will accept additional stream messages. For example:
@ -215,9 +218,10 @@ inline decltype(MakeVal(std::declval<absl::underlying_type_t<T>>())) MakeVal(
return {static_cast<absl::underlying_type_t<T>>(x)};
}
template <typename T, decltype(ToLogString(std::declval<T>()))* = nullptr>
template <typename T,
std::enable_if_t<absl::HasAbslStringify<T>::value>* = nullptr>
ToStringVal MakeVal(const T& x) {
return {ToLogString(x)};
return {absl::StrCat(x)};
}
// Ephemeral type that represents the result of the logging << operator.

View File

@ -19,8 +19,8 @@ rtc_library("flat_containers_internal") {
deps = [
"..:checks",
"../system:no_unique_address",
"//third_party/abseil-cpp/absl/algorithm:container",
]
absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ]
visibility = [ ":*" ]
}
@ -52,5 +52,4 @@ rtc_library("unittests") {
"//testing/gmock:gmock",
"//testing/gtest:gtest",
]
absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ]
}

View File

@ -21,7 +21,8 @@
#error "Must define either WEBRTC_WIN or WEBRTC_POSIX."
#endif
#include "absl/types/optional.h"
#include <optional>
#include "rtc_base/checks.h"
#include "rtc_base/synchronization/yield_policy.h"
#include "rtc_base/system/warn_current_thread_is_deadlocked.h"
@ -148,27 +149,26 @@ bool Event::Wait(TimeDelta give_up_after, TimeDelta warn_after) {
// Instant when we'll log a warning message (because we've been waiting so
// long it might be a bug), but not yet give up waiting. nullopt if we
// shouldn't log a warning.
const absl::optional<timespec> warn_ts =
warn_after >= give_up_after
? absl::nullopt
: absl::make_optional(GetTimespec(warn_after));
const std::optional<timespec> warn_ts =
warn_after >= give_up_after ? std::nullopt
: std::make_optional(GetTimespec(warn_after));
// Instant when we'll stop waiting and return an error. nullopt if we should
// never give up.
const absl::optional<timespec> give_up_ts =
const std::optional<timespec> give_up_ts =
give_up_after.IsPlusInfinity()
? absl::nullopt
: absl::make_optional(GetTimespec(give_up_after));
? std::nullopt
: std::make_optional(GetTimespec(give_up_after));
ScopedYieldPolicy::YieldExecution();
pthread_mutex_lock(&event_mutex_);
// Wait for `event_cond_` to trigger and `event_status_` to be set, with the
// given timeout (or without a timeout if none is given).
const auto wait = [&](const absl::optional<timespec> timeout_ts) {
const auto wait = [&](const std::optional<timespec> timeout_ts) {
int error = 0;
while (!event_status_ && error == 0) {
if (timeout_ts == absl::nullopt) {
if (timeout_ts == std::nullopt) {
error = pthread_cond_wait(&event_cond_, &event_mutex_);
} else {
#if USE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP
@ -184,7 +184,7 @@ bool Event::Wait(TimeDelta give_up_after, TimeDelta warn_after) {
};
int error;
if (warn_ts == absl::nullopt) {
if (warn_ts == std::nullopt) {
error = wait(give_up_ts);
} else {
error = wait(warn_ts);

View File

@ -58,6 +58,8 @@ class Event {
// TODO(bugs.webrtc.org/14366): Consider removing this redundant alias.
static constexpr webrtc::TimeDelta kForever =
webrtc::TimeDelta::PlusInfinity();
static constexpr webrtc::TimeDelta kDefaultWarnDuration =
webrtc::TimeDelta::Seconds(3);
Event();
Event(bool manual_reset, bool initially_signaled);
@ -83,7 +85,7 @@ class Event {
// Waits with the given timeout and a reasonable default warning timeout.
bool Wait(webrtc::TimeDelta give_up_after) {
return Wait(give_up_after, give_up_after.IsPlusInfinity()
? webrtc::TimeDelta::Seconds(3)
? kDefaultWarnDuration
: kForever);
}

View File

@ -7,11 +7,19 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/event_tracer.h"
#include <stdio.h>
#include "rtc_base/trace_event.h"
#if defined(RTC_USE_PERFETTO)
#include "rtc_base/trace_categories.h"
#include "third_party/perfetto/include/perfetto/tracing/tracing.h"
#else
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <atomic>
@ -28,21 +36,27 @@
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
// This is a guesstimate that should be enough in most cases.
static const size_t kEventLoggerArgsStrBufferInitialSize = 256;
static const size_t kTraceArgBufferLength = 32;
#endif
namespace webrtc {
namespace {
#if !defined(RTC_USE_PERFETTO)
GetCategoryEnabledPtr g_get_category_enabled_ptr = nullptr;
AddTraceEventPtr g_add_trace_event_ptr = nullptr;
#endif
} // namespace
#if defined(RTC_USE_PERFETTO)
void RegisterPerfettoTrackEvents() {
if (perfetto::Tracing::IsInitialized()) {
webrtc::TrackEvent::Register();
}
}
#else
void SetupEventTracer(GetCategoryEnabledPtr get_category_enabled_ptr,
AddTraceEventPtr add_trace_event_ptr) {
g_get_category_enabled_ptr = get_category_enabled_ptr;
@ -73,9 +87,28 @@ void EventTracer::AddTraceEvent(char phase,
arg_names, arg_types, arg_values, flags);
}
}
#endif
} // namespace webrtc
#if defined(RTC_USE_PERFETTO)
// TODO(bugs.webrtc.org/15917): Implement for perfetto.
namespace rtc::tracing {
void SetupInternalTracer(bool enable_all_categories) {}
bool StartInternalCapture(absl::string_view filename) {
return false;
}
void StartInternalCaptureToFile(FILE* file) {}
void StopInternalCapture() {}
void ShutdownInternalTracer() {}
} // namespace rtc::tracing
#else
// This is a guesstimate that should be enough in most cases.
static const size_t kEventLoggerArgsStrBufferInitialSize = 256;
static const size_t kTraceArgBufferLength = 32;
namespace rtc {
namespace tracing {
namespace {
@ -96,7 +129,7 @@ class EventLogger final {
const unsigned char* arg_types,
const unsigned long long* arg_values,
uint64_t timestamp,
int pid,
int /* pid */,
rtc::PlatformThreadId thread_id) {
std::vector<TraceArg> args(num_args);
for (int i = 0; i < num_args; ++i) {
@ -206,12 +239,14 @@ class EventLogger final {
// Finally start, everything should be set up now.
logging_thread_ =
PlatformThread::SpawnJoinable([this] { Log(); }, "EventTracingThread");
TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start");
TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start",
TRACE_EVENT_SCOPE_GLOBAL);
}
void Stop() {
RTC_DCHECK(thread_checker_.IsCurrent());
TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop");
TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop",
TRACE_EVENT_SCOPE_GLOBAL);
// Try to stop. Abort if we're not currently logging.
int one = 1;
if (g_event_logging_active.compare_exchange_strong(one, 0))
@ -344,12 +379,12 @@ const unsigned char* InternalEnableAllCategories(const char* name) {
void InternalAddTraceEvent(char phase,
const unsigned char* category_enabled,
const char* name,
unsigned long long id,
unsigned long long /* id */,
int num_args,
const char** arg_names,
const unsigned char* arg_types,
const unsigned long long* arg_values,
unsigned char flags) {
unsigned char /* flags */) {
// Fast path for when event tracing is inactive.
if (g_event_logging_active.load() == 0)
return;
@ -410,3 +445,5 @@ void ShutdownInternalTracer() {
} // namespace tracing
} // namespace rtc
#endif // defined(RTC_USE_PERFETTO)

View File

@ -8,6 +8,9 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_EVENT_TRACER_H_
#define RTC_BASE_EVENT_TRACER_H_
// This file defines the interface for event tracing in WebRTC.
//
// Event log handlers are set through SetupEventTracer(). User of this API will
@ -23,9 +26,6 @@
//
// Parameters for the above two functions are described in trace_event.h.
#ifndef RTC_BASE_EVENT_TRACER_H_
#define RTC_BASE_EVENT_TRACER_H_
#include <stdio.h>
#include "absl/strings/string_view.h"
@ -33,6 +33,9 @@
namespace webrtc {
#if defined(RTC_USE_PERFETTO)
void RegisterPerfettoTrackEvents();
#else
typedef const unsigned char* (*GetCategoryEnabledPtr)(const char* name);
typedef void (*AddTraceEventPtr)(char phase,
const unsigned char* category_enabled,
@ -67,19 +70,19 @@ class EventTracer {
const unsigned long long* arg_values,
unsigned char flags);
};
#endif
} // namespace webrtc
namespace rtc {
namespace tracing {
namespace rtc::tracing {
// Set up internal event tracer.
// TODO(webrtc:15917): Implement for perfetto.
RTC_EXPORT void SetupInternalTracer(bool enable_all_categories = true);
RTC_EXPORT bool StartInternalCapture(absl::string_view filename);
RTC_EXPORT void StartInternalCaptureToFile(FILE* file);
RTC_EXPORT void StopInternalCapture();
// Make sure we run this, this will tear down the internal tracing.
RTC_EXPORT void ShutdownInternalTracer();
} // namespace tracing
} // namespace rtc
} // namespace rtc::tracing
#endif // RTC_BASE_EVENT_TRACER_H_

View File

@ -60,7 +60,7 @@ void ParseFieldTrial(
while (!tail.empty()) {
size_t key_end = tail.find_first_of(",:");
absl::string_view key = tail.substr(0, key_end);
absl::optional<std::string> opt_value;
std::optional<std::string> opt_value;
if (key_end == absl::string_view::npos) {
tail = "";
} else if (tail[key_end] == ':') {
@ -112,17 +112,17 @@ void ParseFieldTrial(
}
template <>
absl::optional<bool> ParseTypedParameter<bool>(absl::string_view str) {
std::optional<bool> ParseTypedParameter<bool>(absl::string_view str) {
if (str == "true" || str == "1") {
return true;
} else if (str == "false" || str == "0") {
return false;
}
return absl::nullopt;
return std::nullopt;
}
template <>
absl::optional<double> ParseTypedParameter<double>(absl::string_view str) {
std::optional<double> ParseTypedParameter<double>(absl::string_view str) {
double value;
char unit[2]{0, 0};
if (sscanf(std::string(str).c_str(), "%lf%1s", &value, unit) >= 1) {
@ -130,56 +130,56 @@ absl::optional<double> ParseTypedParameter<double>(absl::string_view str) {
return value / 100;
return value;
} else {
return absl::nullopt;
return std::nullopt;
}
}
template <>
absl::optional<int> ParseTypedParameter<int>(absl::string_view str) {
std::optional<int> ParseTypedParameter<int>(absl::string_view str) {
int64_t value;
if (sscanf(std::string(str).c_str(), "%" SCNd64, &value) == 1) {
if (rtc::IsValueInRangeForNumericType<int, int64_t>(value)) {
return static_cast<int>(value);
}
}
return absl::nullopt;
return std::nullopt;
}
template <>
absl::optional<unsigned> ParseTypedParameter<unsigned>(absl::string_view str) {
std::optional<unsigned> ParseTypedParameter<unsigned>(absl::string_view str) {
int64_t value;
if (sscanf(std::string(str).c_str(), "%" SCNd64, &value) == 1) {
if (rtc::IsValueInRangeForNumericType<unsigned, int64_t>(value)) {
return static_cast<unsigned>(value);
}
}
return absl::nullopt;
return std::nullopt;
}
template <>
absl::optional<std::string> ParseTypedParameter<std::string>(
std::optional<std::string> ParseTypedParameter<std::string>(
absl::string_view str) {
return std::string(str);
}
template <>
absl::optional<absl::optional<bool>> ParseTypedParameter<absl::optional<bool>>(
std::optional<std::optional<bool>> ParseTypedParameter<std::optional<bool>>(
absl::string_view str) {
return ParseOptionalParameter<bool>(str);
}
template <>
absl::optional<absl::optional<int>> ParseTypedParameter<absl::optional<int>>(
std::optional<std::optional<int>> ParseTypedParameter<std::optional<int>>(
absl::string_view str) {
return ParseOptionalParameter<int>(str);
}
template <>
absl::optional<absl::optional<unsigned>>
ParseTypedParameter<absl::optional<unsigned>>(absl::string_view str) {
std::optional<std::optional<unsigned>>
ParseTypedParameter<std::optional<unsigned>>(absl::string_view str) {
return ParseOptionalParameter<unsigned>(str);
}
template <>
absl::optional<absl::optional<double>>
ParseTypedParameter<absl::optional<double>>(absl::string_view str) {
std::optional<std::optional<double>> ParseTypedParameter<std::optional<double>>(
absl::string_view str) {
return ParseOptionalParameter<double>(str);
}
@ -197,10 +197,10 @@ webrtc::FieldTrialFlag::operator bool() const {
return value_;
}
bool FieldTrialFlag::Parse(absl::optional<std::string> str_value) {
bool FieldTrialFlag::Parse(std::optional<std::string> str_value) {
// Only set the flag if there is no argument provided.
if (str_value) {
absl::optional<bool> opt_value = ParseTypedParameter<bool>(*str_value);
std::optional<bool> opt_value = ParseTypedParameter<bool>(*str_value);
if (!opt_value)
return false;
value_ = *opt_value;
@ -224,14 +224,14 @@ AbstractFieldTrialEnum::AbstractFieldTrialEnum(const AbstractFieldTrialEnum&) =
default;
AbstractFieldTrialEnum::~AbstractFieldTrialEnum() = default;
bool AbstractFieldTrialEnum::Parse(absl::optional<std::string> str_value) {
bool AbstractFieldTrialEnum::Parse(std::optional<std::string> str_value) {
if (str_value) {
auto it = enum_mapping_.find(*str_value);
if (it != enum_mapping_.end()) {
value_ = it->second;
return true;
}
absl::optional<int> value = ParseTypedParameter<int>(*str_value);
std::optional<int> value = ParseTypedParameter<int>(*str_value);
if (value.has_value() &&
(valid_values_.find(*value) != valid_values_.end())) {
value_ = *value;

View File

@ -14,12 +14,12 @@
#include <initializer_list>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
// Field trial parser functionality. Provides funcitonality to parse field trial
// argument strings in key:value format. Each parameter is described using
@ -51,7 +51,7 @@ class FieldTrialParameterInterface {
std::initializer_list<FieldTrialParameterInterface*> fields,
absl::string_view trial_string);
void MarkAsUsed() { used_ = true; }
virtual bool Parse(absl::optional<std::string> str_value) = 0;
virtual bool Parse(std::optional<std::string> str_value) = 0;
virtual void ParseDone() {}
@ -68,10 +68,10 @@ void ParseFieldTrial(
std::initializer_list<FieldTrialParameterInterface*> fields,
absl::string_view trial_string);
// Specialize this in code file for custom types. Should return absl::nullopt if
// Specialize this in code file for custom types. Should return std::nullopt if
// the given string cannot be properly parsed.
template <typename T>
absl::optional<T> ParseTypedParameter(absl::string_view);
std::optional<T> ParseTypedParameter(absl::string_view);
// This class uses the ParseTypedParameter function to implement a parameter
// implementation with an enforced default value.
@ -87,9 +87,9 @@ class FieldTrialParameter : public FieldTrialParameterInterface {
void SetForTest(T value) { value_ = value; }
protected:
bool Parse(absl::optional<std::string> str_value) override {
bool Parse(std::optional<std::string> str_value) override {
if (str_value) {
absl::optional<T> value = ParseTypedParameter<T>(*str_value);
std::optional<T> value = ParseTypedParameter<T>(*str_value);
if (value.has_value()) {
value_ = value.value();
return true;
@ -110,8 +110,8 @@ class FieldTrialConstrained : public FieldTrialParameterInterface {
public:
FieldTrialConstrained(absl::string_view key,
T default_value,
absl::optional<T> lower_limit,
absl::optional<T> upper_limit)
std::optional<T> lower_limit,
std::optional<T> upper_limit)
: FieldTrialParameterInterface(key),
value_(default_value),
lower_limit_(lower_limit),
@ -121,9 +121,9 @@ class FieldTrialConstrained : public FieldTrialParameterInterface {
const T* operator->() const { return &value_; }
protected:
bool Parse(absl::optional<std::string> str_value) override {
bool Parse(std::optional<std::string> str_value) override {
if (str_value) {
absl::optional<T> value = ParseTypedParameter<T>(*str_value);
std::optional<T> value = ParseTypedParameter<T>(*str_value);
if (value && (!lower_limit_ || *value >= *lower_limit_) &&
(!upper_limit_ || *value <= *upper_limit_)) {
value_ = *value;
@ -135,8 +135,8 @@ class FieldTrialConstrained : public FieldTrialParameterInterface {
private:
T value_;
absl::optional<T> lower_limit_;
absl::optional<T> upper_limit_;
std::optional<T> lower_limit_;
std::optional<T> upper_limit_;
};
class AbstractFieldTrialEnum : public FieldTrialParameterInterface {
@ -148,7 +148,7 @@ class AbstractFieldTrialEnum : public FieldTrialParameterInterface {
AbstractFieldTrialEnum(const AbstractFieldTrialEnum&);
protected:
bool Parse(absl::optional<std::string> str_value) override;
bool Parse(std::optional<std::string> str_value) override;
protected:
int value_;
@ -181,35 +181,35 @@ class FieldTrialEnum : public AbstractFieldTrialEnum {
};
// This class uses the ParseTypedParameter function to implement an optional
// parameter implementation that can default to absl::nullopt.
// parameter implementation that can default to std::nullopt.
template <typename T>
class FieldTrialOptional : public FieldTrialParameterInterface {
public:
explicit FieldTrialOptional(absl::string_view key)
: FieldTrialParameterInterface(key) {}
FieldTrialOptional(absl::string_view key, absl::optional<T> default_value)
FieldTrialOptional(absl::string_view key, std::optional<T> default_value)
: FieldTrialParameterInterface(key), value_(default_value) {}
absl::optional<T> GetOptional() const { return value_; }
std::optional<T> GetOptional() const { return value_; }
const T& Value() const { return value_.value(); }
const T& operator*() const { return value_.value(); }
const T* operator->() const { return &value_.value(); }
explicit operator bool() const { return value_.has_value(); }
protected:
bool Parse(absl::optional<std::string> str_value) override {
bool Parse(std::optional<std::string> str_value) override {
if (str_value) {
absl::optional<T> value = ParseTypedParameter<T>(*str_value);
std::optional<T> value = ParseTypedParameter<T>(*str_value);
if (!value.has_value())
return false;
value_ = value.value();
} else {
value_ = absl::nullopt;
value_ = std::nullopt;
}
return true;
}
private:
absl::optional<T> value_;
std::optional<T> value_;
};
// Equivalent to a FieldTrialParameter<bool> in the case that both key and value
@ -223,47 +223,46 @@ class FieldTrialFlag : public FieldTrialParameterInterface {
explicit operator bool() const;
protected:
bool Parse(absl::optional<std::string> str_value) override;
bool Parse(std::optional<std::string> str_value) override;
private:
bool value_;
};
template <typename T>
absl::optional<absl::optional<T>> ParseOptionalParameter(
absl::string_view str) {
std::optional<std::optional<T>> ParseOptionalParameter(absl::string_view str) {
if (str.empty())
return absl::optional<T>();
return std::optional<T>();
auto parsed = ParseTypedParameter<T>(str);
if (parsed.has_value())
return parsed;
return absl::nullopt;
return std::nullopt;
}
template <>
absl::optional<bool> ParseTypedParameter<bool>(absl::string_view str);
std::optional<bool> ParseTypedParameter<bool>(absl::string_view str);
template <>
absl::optional<double> ParseTypedParameter<double>(absl::string_view str);
std::optional<double> ParseTypedParameter<double>(absl::string_view str);
template <>
absl::optional<int> ParseTypedParameter<int>(absl::string_view str);
std::optional<int> ParseTypedParameter<int>(absl::string_view str);
template <>
absl::optional<unsigned> ParseTypedParameter<unsigned>(absl::string_view str);
std::optional<unsigned> ParseTypedParameter<unsigned>(absl::string_view str);
template <>
absl::optional<std::string> ParseTypedParameter<std::string>(
std::optional<std::string> ParseTypedParameter<std::string>(
absl::string_view str);
template <>
absl::optional<absl::optional<bool>> ParseTypedParameter<absl::optional<bool>>(
std::optional<std::optional<bool>> ParseTypedParameter<std::optional<bool>>(
absl::string_view str);
template <>
absl::optional<absl::optional<int>> ParseTypedParameter<absl::optional<int>>(
std::optional<std::optional<int>> ParseTypedParameter<std::optional<int>>(
absl::string_view str);
template <>
absl::optional<absl::optional<unsigned>>
ParseTypedParameter<absl::optional<unsigned>>(absl::string_view str);
std::optional<std::optional<unsigned>>
ParseTypedParameter<std::optional<unsigned>>(absl::string_view str);
template <>
absl::optional<absl::optional<double>>
ParseTypedParameter<absl::optional<double>>(absl::string_view str);
std::optional<std::optional<double>> ParseTypedParameter<std::optional<double>>(
absl::string_view str);
// Accepts true, false, else parsed with sscanf %i, true if != 0.
extern template class FieldTrialParameter<bool>;

View File

@ -21,7 +21,7 @@
// RTC_LOG(sev) logs the given stream at severity "sev", which must be a
// compile-time constant of the LoggingSeverity type, without the namespace
// prefix.
// RTC_LOG_IF(sev, condition) logs the given stream at severitye "sev" if
// RTC_LOG_IF(sev, condition) logs the given stream at severity "sev" if
// "condition" is true.
// RTC_LOG_V(sev) Like RTC_LOG(), but sev is a run-time variable of the
// LoggingSeverity type (basically, it just doesn't prepend the namespace).
@ -51,6 +51,7 @@
#include <errno.h>
#include <atomic>
#include <optional>
#include <sstream> // no-presubmit-check TODO(webrtc:8982)
#include <string>
#include <type_traits>
@ -58,12 +59,14 @@
#include "absl/base/attributes.h"
#include "absl/meta/type_traits.h"
#include "absl/strings/has_absl_stringify.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/units/timestamp.h"
#include "rtc_base/platform_thread_types.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/system/inline.h"
#include "rtc_base/type_traits.h"
#if !defined(NDEBUG) || defined(DLOG_ALWAYS_ON)
#define RTC_DLOG_IS_ON 1
@ -118,7 +121,7 @@ class LogLineRef {
absl::string_view message() const { return message_; }
absl::string_view filename() const { return filename_; }
int line() const { return line_; }
absl::optional<PlatformThreadId> thread_id() const { return thread_id_; }
std::optional<PlatformThreadId> thread_id() const { return thread_id_; }
webrtc::Timestamp timestamp() const { return timestamp_; }
absl::string_view tag() const { return tag_; }
LoggingSeverity severity() const { return severity_; }
@ -134,7 +137,7 @@ class LogLineRef {
void set_message(std::string message) { message_ = std::move(message); }
void set_filename(absl::string_view filename) { filename_ = filename; }
void set_line(int line) { line_ = line; }
void set_thread_id(absl::optional<PlatformThreadId> thread_id) {
void set_thread_id(std::optional<PlatformThreadId> thread_id) {
thread_id_ = thread_id;
}
void set_timestamp(webrtc::Timestamp timestamp) { timestamp_ = timestamp; }
@ -144,7 +147,7 @@ class LogLineRef {
std::string message_;
absl::string_view filename_;
int line_ = 0;
absl::optional<PlatformThreadId> thread_id_;
std::optional<PlatformThreadId> thread_id_;
webrtc::Timestamp timestamp_ = webrtc::Timestamp::MinusInfinity();
// The default Android debug output tag.
absl::string_view tag_ = "libjingle";
@ -282,6 +285,7 @@ inline Val<LogArgType::kULongLong, unsigned long long> MakeVal(
inline Val<LogArgType::kDouble, double> MakeVal(double x) {
return {x};
}
inline Val<LogArgType::kLongDouble, long double> MakeVal(long double x) {
return {x};
}
@ -327,33 +331,25 @@ inline Val<LogArgType::kLogMetadataTag, LogMetadataTag> MakeVal(
}
#endif
template <typename T, class = void>
struct has_to_log_string : std::false_type {};
template <typename T>
struct has_to_log_string<T,
absl::enable_if_t<std::is_convertible<
decltype(ToLogString(std::declval<T>())),
std::string>::value>> : std::true_type {};
template <typename T, absl::enable_if_t<has_to_log_string<T>::value>* = nullptr>
template <typename T,
std::enable_if_t<absl::HasAbslStringify<T>::value>* = nullptr>
ToStringVal MakeVal(const T& x) {
return {ToLogString(x)};
return {absl::StrCat(x)};
}
// Handle arbitrary types other than the above by falling back to stringstream.
// TODO(bugs.webrtc.org/9278): Get rid of this overload when callers don't need
// it anymore. No in-tree caller does, but some external callers still do.
template <
typename T,
typename T1 = absl::decay_t<T>,
absl::enable_if_t<std::is_class<T1>::value &&
!std::is_same<T1, std::string>::value &&
!std::is_same<T1, LogMetadata>::value &&
!has_to_log_string<T1>::value &&
template <typename T,
typename T1 = absl::decay_t<T>,
std::enable_if_t<std::is_class<T1>::value && //
!std::is_same<T1, std::string>::value && //
!std::is_same<T1, LogMetadata>::value && //
!absl::HasAbslStringify<T1>::value &&
#ifdef WEBRTC_ANDROID
!std::is_same<T1, LogMetadataTag>::value &&
!std::is_same<T1, LogMetadataTag>::value && //
#endif
!std::is_same<T1, LogMetadataErr>::value>* = nullptr>
!std::is_same<T1, LogMetadataErr>::value>* = nullptr>
ToStringVal MakeVal(const T& x) {
std::ostringstream os; // no-presubmit-check TODO(webrtc:8982)
os << x;
@ -376,18 +372,7 @@ class LogStreamer;
template <>
class LogStreamer<> final {
public:
template <typename U,
typename V = decltype(MakeVal(std::declval<U>())),
absl::enable_if_t<std::is_arithmetic<U>::value ||
std::is_enum<U>::value>* = nullptr>
RTC_FORCE_INLINE LogStreamer<V> operator<<(U arg) const {
return LogStreamer<V>(MakeVal(arg), this);
}
template <typename U,
typename V = decltype(MakeVal(std::declval<U>())),
absl::enable_if_t<!std::is_arithmetic<U>::value &&
!std::is_enum<U>::value>* = nullptr>
template <typename U, typename V = decltype(MakeVal(std::declval<U>()))>
RTC_FORCE_INLINE LogStreamer<V> operator<<(const U& arg) const {
return LogStreamer<V>(MakeVal(arg), this);
}
@ -407,18 +392,7 @@ class LogStreamer<T, Ts...> final {
RTC_FORCE_INLINE LogStreamer(T arg, const LogStreamer<Ts...>* prior)
: arg_(arg), prior_(prior) {}
template <typename U,
typename V = decltype(MakeVal(std::declval<U>())),
absl::enable_if_t<std::is_arithmetic<U>::value ||
std::is_enum<U>::value>* = nullptr>
RTC_FORCE_INLINE LogStreamer<V, T, Ts...> operator<<(U arg) const {
return LogStreamer<V, T, Ts...>(MakeVal(arg), this);
}
template <typename U,
typename V = decltype(MakeVal(std::declval<U>())),
absl::enable_if_t<!std::is_arithmetic<U>::value &&
!std::is_enum<U>::value>* = nullptr>
template <typename U, typename V = decltype(MakeVal(std::declval<U>()))>
RTC_FORCE_INLINE LogStreamer<V, T, Ts...> operator<<(const U& arg) const {
return LogStreamer<V, T, Ts...>(MakeVal(arg), this);
}

View File

@ -33,10 +33,12 @@ rtc_library("fifo_buffer") {
"fifo_buffer.h",
]
deps = [
"..:macromagic",
"..:stream",
"..:threading",
"../../api:array_view",
"../../api:sequence_checker",
"../../api/task_queue:pending_task_safety_flag",
"../synchronization:mutex",
]
}

View File

@ -35,7 +35,6 @@
#include <stdint.h>
#include <type_traits>
#include <utility>
#include "rtc_base/type_traits.h"

View File

@ -76,6 +76,7 @@
#ifndef RTC_BASE_NUMERICS_SAFE_MINMAX_H_
#define RTC_BASE_NUMERICS_SAFE_MINMAX_H_
#include <cstdint>
#include <limits>
#include <type_traits>

View File

@ -41,8 +41,10 @@ bool SetPriority(ThreadPriority priority) {
#if defined(WEBRTC_WIN)
return SetThreadPriority(GetCurrentThread(),
Win32PriorityFromThreadPriority(priority)) != FALSE;
#elif defined(__native_client__) || defined(WEBRTC_FUCHSIA)
// Setting thread priorities is not supported in NaCl or Fuchsia.
#elif defined(__native_client__) || defined(WEBRTC_FUCHSIA) || \
(defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__))
// Setting thread priorities is not supported in NaCl, Fuchsia or Emscripten
// without pthreads.
return true;
#elif defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
// TODO(tommi): Switch to the same mechanism as Chromium uses for changing
@ -111,14 +113,14 @@ PlatformThread::PlatformThread(Handle handle, bool joinable)
PlatformThread::PlatformThread(PlatformThread&& rhs)
: handle_(rhs.handle_), joinable_(rhs.joinable_) {
rhs.handle_ = absl::nullopt;
rhs.handle_ = std::nullopt;
}
PlatformThread& PlatformThread::operator=(PlatformThread&& rhs) {
Finalize();
handle_ = rhs.handle_;
joinable_ = rhs.joinable_;
rhs.handle_ = absl::nullopt;
rhs.handle_ = std::nullopt;
return *this;
}
@ -142,7 +144,7 @@ PlatformThread PlatformThread::SpawnDetached(
/*joinable=*/false);
}
absl::optional<PlatformThread::Handle> PlatformThread::GetHandle() const {
std::optional<PlatformThread::Handle> PlatformThread::GetHandle() const {
return handle_;
}
@ -165,7 +167,7 @@ void PlatformThread::Finalize() {
if (joinable_)
RTC_CHECK_EQ(0, pthread_join(*handle_, nullptr));
#endif
handle_ = absl::nullopt;
handle_ = std::nullopt;
}
PlatformThread PlatformThread::SpawnThread(

View File

@ -17,8 +17,9 @@
#include <pthread.h>
#endif
#include <optional>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "rtc_base/platform_thread_types.h"
namespace rtc {
@ -97,7 +98,7 @@ class PlatformThread final {
ThreadAttributes attributes = ThreadAttributes());
// Returns the base platform thread handle of this thread.
absl::optional<Handle> GetHandle() const;
std::optional<Handle> GetHandle() const;
#if defined(WEBRTC_WIN)
// Queue a Windows APC function that runs when the thread is alertable.
@ -111,7 +112,7 @@ class PlatformThread final {
ThreadAttributes attributes,
bool joinable);
absl::optional<Handle> handle_;
std::optional<Handle> handle_;
bool joinable_ = false;
};

View File

@ -62,9 +62,14 @@ class RTC_SCOPED_LOCKABLE RaceCheckerScopeDoNothing {
} // namespace internal
} // namespace rtc
#define RTC_CHECK_RUNS_SERIALIZED(x) \
rtc::internal::RaceCheckerScope race_checker(x); \
RTC_CHECK(!race_checker.RaceDetected())
#define RTC_CHECK_RUNS_SERIALIZED(x) RTC_CHECK_RUNS_SERIALIZED_NEXT(x, __LINE__)
#define RTC_CHECK_RUNS_SERIALIZED_NEXT(x, suffix) \
RTC_CHECK_RUNS_SERIALIZED_IMPL(x, suffix)
#define RTC_CHECK_RUNS_SERIALIZED_IMPL(x, suffix) \
rtc::internal::RaceCheckerScope race_checker##suffix(x); \
RTC_CHECK(!race_checker##suffix.RaceDetected())
#if RTC_DCHECK_IS_ON
#define RTC_DCHECK_RUNS_SERIALIZED(x) \

View File

@ -10,57 +10,19 @@
#ifndef RTC_BASE_REF_COUNT_H_
#define RTC_BASE_REF_COUNT_H_
// Transition file for backwards compatibility with source code
// that includes the non-API file.
#include "api/ref_count.h"
namespace rtc {
// Refcounted objects should implement the following informal interface:
//
// void AddRef() const ;
// RefCountReleaseStatus Release() const;
//
// You may access members of a reference-counted object, including the AddRef()
// and Release() methods, only if you already own a reference to it, or if
// you're borrowing someone else's reference. (A newly created object is a
// special case: the reference count is zero on construction, and the code that
// creates the object should immediately call AddRef(), bringing the reference
// count from zero to one, e.g., by constructing an rtc::scoped_refptr).
//
// AddRef() creates a new reference to the object.
//
// Release() releases a reference to the object; the caller now has one less
// reference than before the call. Returns kDroppedLastRef if the number of
// references dropped to zero because of this (in which case the object destroys
// itself). Otherwise, returns kOtherRefsRemained, to signal that at the precise
// time the caller's reference was dropped, other references still remained (but
// if other threads own references, this may of course have changed by the time
// Release() returns).
//
// The caller of Release() must treat it in the same way as a delete operation:
// Regardless of the return value from Release(), the caller mustn't access the
// object. The object might still be alive, due to references held by other
// users of the object, but the object can go away at any time, e.g., as the
// result of another thread calling Release().
//
// Calling AddRef() and Release() manually is discouraged. It's recommended to
// use rtc::scoped_refptr to manage all pointers to reference counted objects.
// Note that rtc::scoped_refptr depends on compile-time duck-typing; formally
// implementing the below RefCountInterface is not required.
enum class RefCountReleaseStatus { kDroppedLastRef, kOtherRefsRemained };
// Interfaces where refcounting is part of the public api should
// inherit this abstract interface. The implementation of these
// methods is usually provided by the RefCountedObject template class,
// applied as a leaf in the inheritance tree.
class RefCountInterface {
public:
virtual void AddRef() const = 0;
virtual RefCountReleaseStatus Release() const = 0;
// Non-public destructor, because Release() has exclusive responsibility for
// destroying the object.
protected:
virtual ~RefCountInterface() {}
};
// TODO(bugs.webrtc.org/15622): Deprecate and remove these aliases.
using RefCountInterface [[deprecated("Use webrtc::RefCountInterface")]] =
webrtc::RefCountInterface;
using RefCountReleaseStatus
[[deprecated("Use webrtc::RefCountReleaseStatus")]] =
webrtc::RefCountReleaseStatus;
} // namespace rtc

View File

@ -14,7 +14,7 @@
#include "rtc_base/ref_count.h"
#include "rtc_base/ref_counter.h"
namespace rtc {
namespace webrtc {
template <class T>
class RefCountedObject : public T {
@ -84,6 +84,59 @@ class FinalRefCountedObject final : public T {
mutable webrtc::webrtc_impl::RefCounter ref_count_{0};
};
} // namespace webrtc
// Backwards compatibe aliases.
// TODO: https://issues.webrtc.org/42225969 - deprecate and remove.
namespace rtc {
// Because there are users of this template that use "friend
// rtc::RefCountedObject<>" to give access to a private destructor, some
// indirection is needed; "friend" declarations cannot span an "using"
// declaration. Since a templated class on top of a templated class can't access
// the subclass' protected members, we duplicate the entire class instead.
template <class T>
class RefCountedObject : public T {
public:
RefCountedObject() {}
RefCountedObject(const RefCountedObject&) = delete;
RefCountedObject& operator=(const RefCountedObject&) = delete;
template <class P0>
explicit RefCountedObject(P0&& p0) : T(std::forward<P0>(p0)) {}
template <class P0, class P1, class... Args>
RefCountedObject(P0&& p0, P1&& p1, Args&&... args)
: T(std::forward<P0>(p0),
std::forward<P1>(p1),
std::forward<Args>(args)...) {}
void AddRef() const override { ref_count_.IncRef(); }
webrtc::RefCountReleaseStatus Release() const override {
const auto status = ref_count_.DecRef();
if (status == webrtc::RefCountReleaseStatus::kDroppedLastRef) {
delete this;
}
return status;
}
// Return whether the reference count is one. If the reference count is used
// in the conventional way, a reference count of 1 implies that the current
// thread owns the reference and no other thread shares it. This call
// performs the test for a reference count of one, and performs the memory
// barrier needed for the owning thread to act on the object, knowing that it
// has exclusive access to the object.
virtual bool HasOneRef() const { return ref_count_.HasOneRef(); }
protected:
~RefCountedObject() override {}
mutable webrtc::webrtc_impl::RefCounter ref_count_{0};
};
template <typename T>
using FinalRefCountedObject = webrtc::FinalRefCountedObject<T>;
} // namespace rtc
#endif // RTC_BASE_REF_COUNTED_OBJECT_H_

View File

@ -34,7 +34,7 @@ class RefCounter {
// Otherwise, returns kOtherRefsRemained (note that in case of multithreading,
// some other caller may have dropped the last reference by the time this call
// returns; all we know is that we didn't do it).
rtc::RefCountReleaseStatus DecRef() {
RefCountReleaseStatus DecRef() {
// Use release-acquire barrier to ensure all actions on the protected
// resource are finished before the resource can be freed.
// When ref_count_after_subtract > 0, this function require
@ -47,8 +47,8 @@ class RefCounter {
int ref_count_after_subtract =
ref_count_.fetch_sub(1, std::memory_order_acq_rel) - 1;
return ref_count_after_subtract == 0
? rtc::RefCountReleaseStatus::kDroppedLastRef
: rtc::RefCountReleaseStatus::kOtherRefsRemained;
? RefCountReleaseStatus::kDroppedLastRef
: RefCountReleaseStatus::kOtherRefsRemained;
}
// Return whether the reference count is one. If the reference count is used

View File

@ -187,88 +187,19 @@ std::vector<absl::string_view> split(absl::string_view source, char delimiter) {
return fields;
}
std::string ToString(const bool b) {
template <>
std::string ToString(bool b) {
return b ? "true" : "false";
}
std::string ToString(absl::string_view s) {
return std::string(s);
}
std::string ToString(const char* s) {
return std::string(s);
}
std::string ToString(const short s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%hd", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const unsigned short s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%hu", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const int s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%d", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const unsigned int s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%u", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const long int s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%ld", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const unsigned long int s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%lu", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const long long int s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%lld", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const unsigned long long int s) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%llu", s);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const double d) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%g", d);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const long double d) {
template <>
std::string ToString(long double d) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%Lg", d);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
std::string ToString(const void* const p) {
char buf[32];
const int len = std::snprintf(&buf[0], arraysize(buf), "%p", p);
RTC_DCHECK_LE(len, arraysize(buf));
return std::string(&buf[0], len);
}
bool FromString(absl::string_view s, bool* b) {
if (s == "false") {
*b = false;

View File

@ -13,12 +13,13 @@
#include <stddef.h>
#include <optional>
#include <string>
#include <type_traits>
#include <vector>
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/string_to_number.h"
@ -62,28 +63,32 @@ bool tokenize_first(absl::string_view source,
std::string* token,
std::string* rest);
// Convert arbitrary values to/from a string.
// TODO(jonasolsson): Remove these when absl::StrCat becomes available.
template <typename T,
typename std::enable_if<
!std::is_pointer<T>::value ||
std::is_convertible<T, const char*>::value>::type* = nullptr>
std::string ToString(T value) {
return {absl::StrCat(value)};
}
// Versions that behave differently from StrCat
template <>
std::string ToString(bool b);
std::string ToString(absl::string_view s);
// The const char* overload is needed for correct overload resolution because of
// the const void* version of ToString() below.
std::string ToString(const char* s);
std::string ToString(short s);
std::string ToString(unsigned short s);
std::string ToString(int s);
std::string ToString(unsigned int s);
std::string ToString(long int s);
std::string ToString(unsigned long int s);
std::string ToString(long long int s);
std::string ToString(unsigned long long int s);
std::string ToString(double t);
// Versions not supported by StrCat:
template <>
std::string ToString(long double t);
std::string ToString(const void* p);
template <typename T,
typename std::enable_if<
std::is_pointer<T>::value &&
!std::is_convertible<T, const char*>::value>::type* = nullptr>
std::string ToString(T p) {
char buf[32];
const int len = std::snprintf(&buf[0], std::size(buf), "%p", p);
RTC_DCHECK_LE(len, std::size(buf));
return std::string(&buf[0], len);
}
template <typename T,
typename std::enable_if<std::is_arithmetic<T>::value &&
@ -91,7 +96,7 @@ template <typename T,
int>::type = 0>
static bool FromString(absl::string_view s, T* t) {
RTC_DCHECK(t);
absl::optional<T> result = StringToNumber<T>(s);
std::optional<T> result = StringToNumber<T>(s);
if (result)
*t = *result;

View File

@ -20,9 +20,9 @@
namespace rtc {
namespace string_to_number_internal {
absl::optional<signed_type> ParseSigned(absl::string_view str, int base) {
std::optional<signed_type> ParseSigned(absl::string_view str, int base) {
if (str.empty())
return absl::nullopt;
return std::nullopt;
if (isdigit(static_cast<unsigned char>(str[0])) || str[0] == '-') {
std::string str_str(str);
@ -35,12 +35,12 @@ absl::optional<signed_type> ParseSigned(absl::string_view str, int base) {
return value;
}
}
return absl::nullopt;
return std::nullopt;
}
absl::optional<unsigned_type> ParseUnsigned(absl::string_view str, int base) {
std::optional<unsigned_type> ParseUnsigned(absl::string_view str, int base) {
if (str.empty())
return absl::nullopt;
return std::nullopt;
if (isdigit(static_cast<unsigned char>(str[0])) || str[0] == '-') {
std::string str_str(str);
@ -58,7 +58,7 @@ absl::optional<unsigned_type> ParseUnsigned(absl::string_view str, int base) {
return value;
}
}
return absl::nullopt;
return std::nullopt;
}
template <typename T>
@ -80,12 +80,12 @@ inline long double StrToT(const char* str, char** str_end) {
}
template <typename T>
absl::optional<T> ParseFloatingPoint(absl::string_view str) {
std::optional<T> ParseFloatingPoint(absl::string_view str) {
if (str.empty())
return absl::nullopt;
return std::nullopt;
if (str[0] == '\0')
return absl::nullopt;
return std::nullopt;
std::string str_str(str);
char* end = nullptr;
errno = 0;
@ -93,12 +93,12 @@ absl::optional<T> ParseFloatingPoint(absl::string_view str) {
if (end == str_str.c_str() + str_str.size() && errno == 0) {
return value;
}
return absl::nullopt;
return std::nullopt;
}
template absl::optional<float> ParseFloatingPoint(absl::string_view str);
template absl::optional<double> ParseFloatingPoint(absl::string_view str);
template absl::optional<long double> ParseFloatingPoint(absl::string_view str);
template std::optional<float> ParseFloatingPoint(absl::string_view str);
template std::optional<double> ParseFloatingPoint(absl::string_view str);
template std::optional<long double> ParseFloatingPoint(absl::string_view str);
} // namespace string_to_number_internal
} // namespace rtc

View File

@ -12,11 +12,11 @@
#define RTC_BASE_STRING_TO_NUMBER_H_
#include <limits>
#include <optional>
#include <string>
#include <type_traits>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
namespace rtc {
@ -27,7 +27,7 @@ namespace rtc {
// are disabled in WebRTC.
//
// Integers are parsed using:
// absl::optional<int-type> StringToNumber(absl::string_view str,
// std::optional<int-type> StringToNumber(absl::string_view str,
// int base = 10);
//
// These functions parse a value from the beginning of a string into one of the
@ -44,16 +44,16 @@ namespace string_to_number_internal {
using unsigned_type = unsigned long long; // NOLINT(runtime/int)
using signed_type = long long; // NOLINT(runtime/int)
absl::optional<signed_type> ParseSigned(absl::string_view str, int base);
absl::optional<unsigned_type> ParseUnsigned(absl::string_view str, int base);
std::optional<signed_type> ParseSigned(absl::string_view str, int base);
std::optional<unsigned_type> ParseUnsigned(absl::string_view str, int base);
template <typename T>
absl::optional<T> ParseFloatingPoint(absl::string_view str);
std::optional<T> ParseFloatingPoint(absl::string_view str);
} // namespace string_to_number_internal
template <typename T>
typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value,
absl::optional<T>>::type
std::optional<T>>::type
StringToNumber(absl::string_view str, int base = 10) {
using string_to_number_internal::signed_type;
static_assert(
@ -62,36 +62,36 @@ StringToNumber(absl::string_view str, int base = 10) {
std::numeric_limits<T>::lowest() >=
std::numeric_limits<signed_type>::lowest(),
"StringToNumber only supports signed integers as large as long long int");
absl::optional<signed_type> value =
std::optional<signed_type> value =
string_to_number_internal::ParseSigned(str, base);
if (value && *value >= std::numeric_limits<T>::lowest() &&
*value <= std::numeric_limits<T>::max()) {
return static_cast<T>(*value);
}
return absl::nullopt;
return std::nullopt;
}
template <typename T>
typename std::enable_if<std::is_integral<T>::value &&
std::is_unsigned<T>::value,
absl::optional<T>>::type
std::optional<T>>::type
StringToNumber(absl::string_view str, int base = 10) {
using string_to_number_internal::unsigned_type;
static_assert(std::numeric_limits<T>::max() <=
std::numeric_limits<unsigned_type>::max(),
"StringToNumber only supports unsigned integers as large as "
"unsigned long long int");
absl::optional<unsigned_type> value =
std::optional<unsigned_type> value =
string_to_number_internal::ParseUnsigned(str, base);
if (value && *value <= std::numeric_limits<T>::max()) {
return static_cast<T>(*value);
}
return absl::nullopt;
return std::nullopt;
}
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value,
absl::optional<T>>::type
std::optional<T>>::type
StringToNumber(absl::string_view str, int base = 10) {
static_assert(
std::numeric_limits<T>::max() <= std::numeric_limits<long double>::max(),

View File

@ -36,15 +36,18 @@ rtc_source_set("mutex") {
"..:macromagic",
"..:platform_thread_types",
"../system:no_unique_address",
"//third_party/abseil-cpp/absl/base:core_headers",
]
absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ]
if (rtc_use_absl_mutex) {
absl_deps += [ "//third_party/abseil-cpp/absl/synchronization" ]
deps += [ "//third_party/abseil-cpp/absl/synchronization" ]
}
}
rtc_library("sequence_checker_internal") {
visibility = [ "../../api:sequence_checker" ]
visibility = [
"../../api:rtc_api_unittests",
"../../api:sequence_checker",
]
sources = [
"sequence_checker_internal.cc",
"sequence_checker_internal.h",
@ -65,8 +68,8 @@ rtc_library("yield_policy") {
"yield_policy.cc",
"yield_policy.h",
]
deps = [ "..:checks" ]
absl_deps = [
deps = [
"..:checks",
"//third_party/abseil-cpp/absl/base:config",
"//third_party/abseil-cpp/absl/base:core_headers",
]

View File

@ -76,8 +76,8 @@ class RTC_LOCKABLE MutexImpl final {
}
private:
// Use two separate primitive types, rather than absl::optional, since the
// data race described below might invalidate absl::optional invariants.
// Use two separate primitive types, rather than std::optional, since the
// data race described below might invalidate std::optional invariants.
bool is_owned_ = false;
pthread_t latest_owner_ = pthread_self();
#endif

View File

@ -29,8 +29,8 @@ rtc_library("file_wrapper") {
"..:checks",
"..:criticalsection",
"..:safe_conversions",
"//third_party/abseil-cpp/absl/strings:string_view",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
if (rtc_include_tests) {

View File

@ -14,6 +14,7 @@
#include <cerrno>
#include <cstdint>
#include <optional>
#include <string>
#include "absl/strings/string_view.h"
@ -81,20 +82,20 @@ bool FileWrapper::SeekTo(int64_t position) {
return fseek(file_, rtc::checked_cast<long>(position), SEEK_SET) == 0;
}
long FileWrapper::FileSize() {
std::optional<size_t> FileWrapper::FileSize() {
if (file_ == nullptr)
return -1;
return std::nullopt;
long original_position = ftell(file_);
if (original_position < 0)
return -1;
return std::nullopt;
int seek_error = fseek(file_, 0, SEEK_END);
if (seek_error)
return -1;
return std::nullopt;
long file_size = ftell(file_);
seek_error = fseek(file_, original_position, SEEK_SET);
if (seek_error)
return -1;
return file_size;
return std::nullopt;
return rtc::checked_cast<size_t>(file_size);
}
bool FileWrapper::Flush() {

View File

@ -14,8 +14,8 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdint.h>
#include <optional>
#include <string>
#include "absl/strings/string_view.h"
@ -90,7 +90,7 @@ class FileWrapper final {
// Returns the file size or -1 if a size could not be determined.
// (A file size might not exists for non-seekable files or file-like
// objects, for example /dev/tty on unix.)
long FileSize();
std::optional<size_t> FileSize();
// Returns number of bytes read. Short count indicates EOF or error.
size_t Read(void* buf, size_t length);

View File

@ -129,11 +129,11 @@ int64_t TmToSeconds(const tm& tm);
// system time is changed, e.g., by some other process calling
// settimeofday. Always use rtc::TimeMicros(), not this function, for
// measuring time intervals and timeouts.
int64_t TimeUTCMicros();
RTC_EXPORT int64_t TimeUTCMicros();
// Return the number of milliseconds since January 1, 1970, UTC.
// See above.
int64_t TimeUTCMillis();
RTC_EXPORT int64_t TimeUTCMillis();
} // namespace rtc

View File

@ -1,25 +1,48 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file under third_party_mods/chromium or at:
// http://src.chromium.org/svn/trunk/src/LICENSE
/*
* Copyright (c) 2024 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_TRACE_EVENT_H_
#define RTC_BASE_TRACE_EVENT_H_
#include <string>
#include "rtc_base/event_tracer.h"
#if defined(TRACE_EVENT0)
#error "Another copy of trace_event.h has already been included."
#endif
#if defined(RTC_DISABLE_TRACE_EVENTS)
#define RTC_TRACE_EVENTS_ENABLED 0
#else
#define RTC_TRACE_EVENTS_ENABLED 1
#endif
// IWYU pragma: begin_exports
#if defined(RTC_USE_PERFETTO)
#include "rtc_base/trace_categories.h"
#include "third_party/perfetto/include/perfetto/tracing/event_context.h"
#include "third_party/perfetto/include/perfetto/tracing/track.h"
#include "third_party/perfetto/include/perfetto/tracing/track_event_args.h"
#endif
// IWYU pragma: end_exports
#if !defined(RTC_USE_PERFETTO)
#include <string>
#include "rtc_base/event_tracer.h"
#define RTC_NOOP() \
do { \
} while (0)
// TODO(b/42226290): Add implementation for these events with Perfetto.
#define TRACE_EVENT_BEGIN(category, name, ...) RTC_NOOP();
#define TRACE_EVENT_END(category, ...) RTC_NOOP();
#define TRACE_EVENT(category, name, ...) RTC_NOOP();
#define TRACE_EVENT_INSTANT(category, name, ...) RTC_NOOP();
#define TRACE_EVENT_CATEGORY_ENABLED(category) RTC_NOOP();
#define TRACE_COUNTER(category, track, ...) RTC_NOOP();
// Type values for identifying types in the TraceValue union.
#define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
#define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
@ -29,6 +52,10 @@
#define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
#define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
#if defined(TRACE_EVENT0)
#error "Another copy of trace_event.h has already been included."
#endif
#if RTC_TRACE_EVENTS_ENABLED
// Extracted from Chromium's src/base/debug/trace_event.h.
@ -127,21 +154,6 @@
// application. In Chrome's case, navigating to about:tracing will turn on
// tracing and display data collected across all active processes.
//
//
// Memory scoping note:
// Tracing copies the pointers, not the string content, of the strings passed
// in for category, name, and arg_names. Thus, the following code will
// cause problems:
// char* str = strdup("impprtantName");
// TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD!
// free(str); // Trace system now has dangling pointer
//
// To avoid this issue with the `name` and `arg_name` parameters, use the
// TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead.
// Notes: The category must always be in a long-lived char* (i.e. static const).
// The `arg_values`, when used, are always deep copied with the _COPY
// macros.
//
// When are string argument values copied:
// const char* arg_values are only referenced by default:
// TRACE_EVENT1("category", "name",
@ -185,32 +197,27 @@
INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val, \
arg2_name, arg2_val)
// Enum reflecting the scope of an INSTANT event. Must fit within
// TRACE_EVENT_FLAG_SCOPE_MASK.
static constexpr uint8_t TRACE_EVENT_SCOPE_GLOBAL = 0u << 2;
static constexpr uint8_t TRACE_EVENT_SCOPE_PROCESS = 1u << 2;
static constexpr uint8_t TRACE_EVENT_SCOPE_THREAD = 2u << 2;
// Records a single event called "name" immediately, with 0, 1 or 2
// associated arguments. If the category is not enabled, then this
// does nothing.
// - category and name strings must have application lifetime (statics or
// literals). They may not include " chars.
#define TRACE_EVENT_INSTANT0(category, name) \
#define TRACE_EVENT_INSTANT0(category, name, scope) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
TRACE_EVENT_FLAG_NONE)
#define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
#define TRACE_EVENT_INSTANT1(category, name, scope, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
#define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, arg2_name, \
arg2_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
arg2_name, arg2_val)
#define TRACE_EVENT_COPY_INSTANT0(category, name) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
#define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
#define TRACE_EVENT_INSTANT2(category, name, scope, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \
TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
arg2_name, arg2_val)
// Records a single BEGIN event called "name" immediately, with 0, 1 or 2
@ -229,17 +236,6 @@
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \
TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
arg2_name, arg2_val)
#define TRACE_EVENT_COPY_BEGIN0(category, name) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \
TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
#define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
arg2_name, arg2_val)
// Records a single END event for "name" immediately. If the category
// is not enabled, then this does nothing.
@ -256,17 +252,6 @@
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \
TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
arg2_name, arg2_val)
#define TRACE_EVENT_COPY_END0(category, name) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \
TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
#define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, arg2_name, \
arg2_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \
TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
arg2_name, arg2_val)
// Records the value of a counter called "name" immediately. Value
// must be representable as a 32 bit integer.
@ -276,10 +261,6 @@
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, \
TRACE_EVENT_FLAG_NONE, "value", \
static_cast<int>(value))
#define TRACE_COPY_COUNTER1(category, name, value) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, \
TRACE_EVENT_FLAG_COPY, "value", \
static_cast<int>(value))
// Records the values of a multi-parted counter called "name" immediately.
// The UI will treat value1 and value2 as parts of a whole, displaying their
@ -292,12 +273,6 @@
TRACE_EVENT_FLAG_NONE, value1_name, \
static_cast<int>(value1_val), value2_name, \
static_cast<int>(value2_val))
#define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \
value2_name, value2_val) \
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, \
TRACE_EVENT_FLAG_COPY, value1_name, \
static_cast<int>(value1_val), value2_name, \
static_cast<int>(value2_val))
// Records the value of a counter called "name" immediately. Value
// must be representable as a 32 bit integer.
@ -311,10 +286,6 @@
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, \
id, TRACE_EVENT_FLAG_NONE, "value", \
static_cast<int>(value))
#define TRACE_COPY_COUNTER_ID1(category, name, id, value) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, \
id, TRACE_EVENT_FLAG_COPY, "value", \
static_cast<int>(value))
// Records the values of a multi-parted counter called "name" immediately.
// The UI will treat value1 and value2 as parts of a whole, displaying their
@ -331,12 +302,6 @@
id, TRACE_EVENT_FLAG_NONE, value1_name, \
static_cast<int>(value1_val), value2_name, \
static_cast<int>(value2_val))
#define TRACE_COPY_COUNTER_ID2(category, name, id, value1_name, value1_val, \
value2_name, value2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, \
id, TRACE_EVENT_FLAG_COPY, value1_name, \
static_cast<int>(value1_val), value2_name, \
static_cast<int>(value2_val))
// Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
// associated arguments. If the category is not enabled, then this
@ -367,40 +332,20 @@
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
arg1_val, arg2_name, arg2_val)
#define TRACE_EVENT_COPY_ASYNC_BEGIN0(category, name, id) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val)
#define TRACE_EVENT_COPY_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val, arg2_name, arg2_val)
// Records a single ASYNC_STEP event for `step` immediately. If the category
// is not enabled, then this does nothing. The `name` and `id` must match the
// ASYNC_BEGIN event above. The `step` param identifies this step within the
// async event. This should be called at the beginning of the next phase of an
// asynchronous operation.
#define TRACE_EVENT_ASYNC_STEP0(category, name, id, step) \
#define TRACE_EVENT_ASYNC_STEP_INTO0(category, name, id, step) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \
name, id, TRACE_EVENT_FLAG_NONE, "step", \
step)
#define TRACE_EVENT_ASYNC_STEP1(category, name, id, step, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \
name, id, TRACE_EVENT_FLAG_NONE, "step", \
step, arg1_name, arg1_val)
#define TRACE_EVENT_COPY_ASYNC_STEP0(category, name, id, step) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \
name, id, TRACE_EVENT_FLAG_COPY, "step", \
step)
#define TRACE_EVENT_COPY_ASYNC_STEP1(category, name, id, step, arg1_name, \
#define TRACE_EVENT_ASYNC_STEP_INTO1(category, name, id, step, arg1_name, \
arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \
name, id, TRACE_EVENT_FLAG_COPY, "step", \
name, id, TRACE_EVENT_FLAG_NONE, "step", \
step, arg1_name, arg1_val)
// Records a single ASYNC_END event for "name" immediately. If the category
@ -417,112 +362,6 @@
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \
name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
arg1_val, arg2_name, arg2_val)
#define TRACE_EVENT_COPY_ASYNC_END0(category, name, id) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \
name, id, TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_ASYNC_END1(category, name, id, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \
name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val)
#define TRACE_EVENT_COPY_ASYNC_END2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \
name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val, arg2_name, arg2_val)
// Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2
// associated arguments. If the category is not enabled, then this
// does nothing.
// - category and name strings must have application lifetime (statics or
// literals). They may not include " chars.
// - `id` is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW
// events are considered to match if their category, name and id values all
// match. `id` must either be a pointer or an integer value up to 64 bits. If
// it's a pointer, the bits will be xored with a hash of the process ID so
// that the same pointer on two different processes will not collide.
// FLOW events are different from ASYNC events in how they are drawn by the
// tracing UI. A FLOW defines asynchronous data flow, such as posting a task
// (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be
// drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar
// to ASYNC, a FLOW can consist of multiple phases. The first phase is defined
// by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP
// macros. When the operation completes, call FLOW_END. An async operation can
// span threads and processes, but all events in that operation must use the
// same `name` and `id`. Each event can have its own args.
#define TRACE_EVENT_FLOW_BEGIN0(category, name, id) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_NONE)
#define TRACE_EVENT_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
arg1_val)
#define TRACE_EVENT_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
arg1_val, arg2_name, arg2_val)
#define TRACE_EVENT_COPY_FLOW_BEGIN0(category, name, id) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val)
#define TRACE_EVENT_COPY_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \
name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val, arg2_name, arg2_val)
// Records a single FLOW_STEP event for `step` immediately. If the category
// is not enabled, then this does nothing. The `name` and `id` must match the
// FLOW_BEGIN event above. The `step` param identifies this step within the
// async event. This should be called at the beginning of the next phase of an
// asynchronous operation.
#define TRACE_EVENT_FLOW_STEP0(category, name, id, step) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \
name, id, TRACE_EVENT_FLAG_NONE, "step", \
step)
#define TRACE_EVENT_FLOW_STEP1(category, name, id, step, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \
name, id, TRACE_EVENT_FLAG_NONE, "step", \
step, arg1_name, arg1_val)
#define TRACE_EVENT_COPY_FLOW_STEP0(category, name, id, step) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \
name, id, TRACE_EVENT_FLAG_COPY, "step", \
step)
#define TRACE_EVENT_COPY_FLOW_STEP1(category, name, id, step, arg1_name, \
arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \
name, id, TRACE_EVENT_FLAG_COPY, "step", \
step, arg1_name, arg1_val)
// Records a single FLOW_END event for "name" immediately. If the category
// is not enabled, then this does nothing.
#define TRACE_EVENT_FLOW_END0(category, name, id) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \
id, TRACE_EVENT_FLAG_NONE)
#define TRACE_EVENT_FLOW_END1(category, name, id, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \
id, TRACE_EVENT_FLAG_NONE, arg1_name, \
arg1_val)
#define TRACE_EVENT_FLOW_END2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \
id, TRACE_EVENT_FLAG_NONE, arg1_name, \
arg1_val, arg2_name, arg2_val)
#define TRACE_EVENT_COPY_FLOW_END0(category, name, id) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \
id, TRACE_EVENT_FLAG_COPY)
#define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \
id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val)
#define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \
id, TRACE_EVENT_FLAG_COPY, arg1_name, \
arg1_val, arg2_name, arg2_val)
////////////////////////////////////////////////////////////////////////////////
// Implementation specific tracing API definitions.
@ -630,15 +469,11 @@
#define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S')
#define TRACE_EVENT_PHASE_ASYNC_STEP ('T')
#define TRACE_EVENT_PHASE_ASYNC_END ('F')
#define TRACE_EVENT_PHASE_FLOW_BEGIN ('s')
#define TRACE_EVENT_PHASE_FLOW_STEP ('t')
#define TRACE_EVENT_PHASE_FLOW_END ('f')
#define TRACE_EVENT_PHASE_METADATA ('M')
#define TRACE_EVENT_PHASE_COUNTER ('C')
// Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
#define TRACE_EVENT_FLAG_NONE (static_cast<unsigned char>(0))
#define TRACE_EVENT_FLAG_COPY (static_cast<unsigned char>(1 << 0))
#define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned char>(1 << 1))
#define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned char>(1 << 2))
@ -898,18 +733,13 @@ class TraceEndOnScopeClose {
} // namespace trace_event_internal
} // namespace webrtc
#else
////////////////////////////////////////////////////////////////////////////////
// This section defines no-op alternatives to the tracing macros when
// RTC_DISABLE_TRACE_EVENTS is defined.
#define RTC_NOOP() \
do { \
} while (0)
#define TRACE_STR_COPY(str) RTC_NOOP()
#define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name
#define TRACE_ID_MANGLE(id) 0
@ -919,18 +749,12 @@ class TraceEndOnScopeClose {
#define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_INSTANT0(category, name) RTC_NOOP()
#define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) RTC_NOOP()
#define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, arg2_name, \
arg2_val) \
#define TRACE_EVENT_INSTANT0(category, name, scope) RTC_NOOP()
#define TRACE_EVENT_INSTANT1(category, name, scope, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_INSTANT0(category, name) RTC_NOOP()
#define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \
arg2_name, arg2_val) \
#define TRACE_EVENT_INSTANT2(category, name, scope, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_BEGIN0(category, name) RTC_NOOP()
@ -938,42 +762,24 @@ class TraceEndOnScopeClose {
#define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, arg2_name, \
arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_BEGIN0(category, name) RTC_NOOP()
#define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) RTC_NOOP()
#define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_END0(category, name) RTC_NOOP()
#define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) RTC_NOOP()
#define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, arg2_name, \
arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_END0(category, name) RTC_NOOP()
#define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) RTC_NOOP()
#define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, arg2_name, \
arg2_val) \
RTC_NOOP()
#define TRACE_COUNTER1(category, name, value) RTC_NOOP()
#define TRACE_COPY_COUNTER1(category, name, value) RTC_NOOP()
#define TRACE_COUNTER2(category, name, value1_name, value1_val, value2_name, \
value2_val) \
RTC_NOOP()
#define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \
value2_name, value2_val) \
RTC_NOOP()
#define TRACE_COUNTER_ID1(category, name, id, value) RTC_NOOP()
#define TRACE_COPY_COUNTER_ID1(category, name, id, value) RTC_NOOP()
#define TRACE_COUNTER_ID2(category, name, id, value1_name, value1_val, \
value2_name, value2_val) \
RTC_NOOP()
#define TRACE_COPY_COUNTER_ID2(category, name, id, value1_name, value1_val, \
value2_name, value2_val) \
RTC_NOOP()
#define TRACE_EVENT_ASYNC_BEGIN0(category, name, id) RTC_NOOP()
#define TRACE_EVENT_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \
@ -981,18 +787,9 @@ class TraceEndOnScopeClose {
#define TRACE_EVENT_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_BEGIN0(category, name, id) RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_ASYNC_STEP0(category, name, id, step) RTC_NOOP()
#define TRACE_EVENT_ASYNC_STEP1(category, name, id, step, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_STEP0(category, name, id, step) RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_STEP1(category, name, id, step, arg1_name, \
#define TRACE_EVENT_ASYNC_STEP_INTO0(category, name, id, step) RTC_NOOP()
#define TRACE_EVENT_ASYNC_STEP_INTO1(category, name, id, step, arg1_name, \
arg1_val) \
RTC_NOOP()
@ -1002,51 +799,12 @@ class TraceEndOnScopeClose {
#define TRACE_EVENT_ASYNC_END2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_END0(category, name, id) RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_END1(category, name, id, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_ASYNC_END2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_FLOW_BEGIN0(category, name, id) RTC_NOOP()
#define TRACE_EVENT_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_BEGIN0(category, name, id) RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_FLOW_STEP0(category, name, id, step) RTC_NOOP()
#define TRACE_EVENT_FLOW_STEP1(category, name, id, step, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_STEP0(category, name, id, step) RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_STEP1(category, name, id, step, arg1_name, \
arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_FLOW_END0(category, name, id) RTC_NOOP()
#define TRACE_EVENT_FLOW_END1(category, name, id, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_FLOW_END2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_END0(category, name, id) RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \
RTC_NOOP()
#define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \
arg2_name, arg2_val) \
RTC_NOOP()
#define TRACE_EVENT_API_GET_CATEGORY_ENABLED ""
#define TRACE_EVENT_API_ADD_TRACE_EVENT RTC_NOOP()
#endif // RTC_TRACE_EVENTS_ENABLED
#endif // RTC_USE_PERFETTO
#endif // RTC_BASE_TRACE_EVENT_H_

View File

@ -12,6 +12,7 @@
#define RTC_BASE_TYPE_TRAITS_H_
#include <cstddef>
#include <string>
#include <type_traits>
namespace rtc {

View File

@ -110,7 +110,6 @@ class UnitBase {
} else if (value == -std::numeric_limits<T>::infinity()) {
return MinusInfinity();
} else {
RTC_DCHECK(!std::isnan(value));
return FromValue(rtc::dchecked_cast<int64_t>(value));
}
}