From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- third_party/libwebrtc/stats/rtc_stats_report.cc | 140 ++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 third_party/libwebrtc/stats/rtc_stats_report.cc (limited to 'third_party/libwebrtc/stats/rtc_stats_report.cc') diff --git a/third_party/libwebrtc/stats/rtc_stats_report.cc b/third_party/libwebrtc/stats/rtc_stats_report.cc new file mode 100644 index 0000000000..f6fbd8c44d --- /dev/null +++ b/third_party/libwebrtc/stats/rtc_stats_report.cc @@ -0,0 +1,140 @@ +/* + * Copyright 2016 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. + */ + +#include "api/stats/rtc_stats_report.h" + +#include +#include + +#include "rtc_base/checks.h" +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { + +RTCStatsReport::ConstIterator::ConstIterator( + const rtc::scoped_refptr& report, + StatsMap::const_iterator it) + : report_(report), it_(it) {} + +RTCStatsReport::ConstIterator::ConstIterator(ConstIterator&& other) = default; + +RTCStatsReport::ConstIterator::~ConstIterator() {} + +RTCStatsReport::ConstIterator& RTCStatsReport::ConstIterator::operator++() { + ++it_; + return *this; +} + +RTCStatsReport::ConstIterator& RTCStatsReport::ConstIterator::operator++(int) { + return ++(*this); +} + +const RTCStats& RTCStatsReport::ConstIterator::operator*() const { + return *it_->second.get(); +} + +const RTCStats* RTCStatsReport::ConstIterator::operator->() const { + return it_->second.get(); +} + +bool RTCStatsReport::ConstIterator::operator==( + const RTCStatsReport::ConstIterator& other) const { + return it_ == other.it_; +} + +bool RTCStatsReport::ConstIterator::operator!=( + const RTCStatsReport::ConstIterator& other) const { + return !(*this == other); +} + +rtc::scoped_refptr RTCStatsReport::Create( + int64_t timestamp_us) { + return rtc::scoped_refptr(new RTCStatsReport(timestamp_us)); +} + +rtc::scoped_refptr RTCStatsReport::Create(Timestamp timestamp) { + return rtc::scoped_refptr(new RTCStatsReport(timestamp)); +} + +RTCStatsReport::RTCStatsReport(int64_t timestamp_us) + : RTCStatsReport(Timestamp::Micros(timestamp_us)) {} + +RTCStatsReport::RTCStatsReport(Timestamp timestamp) : timestamp_(timestamp) {} + +rtc::scoped_refptr RTCStatsReport::Copy() const { + rtc::scoped_refptr copy = Create(timestamp_); + for (auto it = stats_.begin(); it != stats_.end(); ++it) { + copy->AddStats(it->second->copy()); + } + return copy; +} + +void RTCStatsReport::AddStats(std::unique_ptr stats) { +#if RTC_DCHECK_IS_ON + auto result = +#endif + stats_.insert(std::make_pair(std::string(stats->id()), std::move(stats))); +#if RTC_DCHECK_IS_ON + RTC_DCHECK(result.second) + << "A stats object with ID \"" << result.first->second->id() << "\" is " + << "already present in this stats report."; +#endif +} + +const RTCStats* RTCStatsReport::Get(const std::string& id) const { + StatsMap::const_iterator it = stats_.find(id); + if (it != stats_.cend()) + return it->second.get(); + return nullptr; +} + +std::unique_ptr RTCStatsReport::Take(const std::string& id) { + StatsMap::iterator it = stats_.find(id); + if (it == stats_.end()) + return nullptr; + std::unique_ptr stats = std::move(it->second); + stats_.erase(it); + return stats; +} + +void RTCStatsReport::TakeMembersFrom(rtc::scoped_refptr other) { + for (StatsMap::iterator it = other->stats_.begin(); it != other->stats_.end(); + ++it) { + AddStats(std::unique_ptr(it->second.release())); + } + other->stats_.clear(); +} + +RTCStatsReport::ConstIterator RTCStatsReport::begin() const { + return ConstIterator(rtc::scoped_refptr(this), + stats_.cbegin()); +} + +RTCStatsReport::ConstIterator RTCStatsReport::end() const { + return ConstIterator(rtc::scoped_refptr(this), + stats_.cend()); +} + +std::string RTCStatsReport::ToJson() const { + if (begin() == end()) { + return ""; + } + rtc::StringBuilder sb; + sb << "["; + const char* separator = ""; + for (ConstIterator it = begin(); it != end(); ++it) { + sb << separator << it->ToJson(); + separator = ","; + } + sb << "]"; + return sb.Release(); +} + +} // namespace webrtc -- cgit v1.2.3