Revert "[Stats] Add value_or() and migrate from ValueOrDefault()."

This reverts commit 9e4a97bb02.

Reason for revert: Breaks downstream project

Original change's description:
> [Stats] Add value_or() and migrate from ValueOrDefault().
>
> Yet another prerequisite for replacing RTCStatsMember<T> with
> absl::optional<T>, but this looks like the last one.
>
> Bug: webrtc:15164
> Change-Id: I2cde51e8c8c951f71b48ccd45e07146091a99616
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/334647
> Commit-Queue: Henrik Boström <hbos@webrtc.org>
> Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#41541}

Bug: webrtc:15164
Change-Id: I89af6470c82d07981d8d064aa6ff8b50fae42b12
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/334801
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41548}
This commit is contained in:
Mirko Bonadei 2024-01-17 14:37:31 +00:00 committed by WebRTC LUCI CQ
parent d257cb7333
commit 111e381822
8 changed files with 34 additions and 34 deletions

View file

@ -101,14 +101,9 @@ class RTCStatsMember : public RTCStatsMemberInterface {
std::string ValueToString() const override; std::string ValueToString() const override;
std::string ValueToJson() const override; std::string ValueToJson() const override;
template <typename U>
inline T value_or(U default_value) const {
return value_.value_or(default_value);
}
// TODO(https://crbug.com/webrtc/15164): Migrate to value_or() and delete.
template <typename U> template <typename U>
inline T ValueOrDefault(U default_value) const { inline T ValueOrDefault(U default_value) const {
return value_or(default_value); return value_.value_or(default_value);
} }
// Assignment operators. // Assignment operators.

View file

@ -1191,7 +1191,7 @@ TEST_F(PeerConnectionEncodingsIntegrationTest,
ASSERT_EQ(outbound_rtps.size(), 1u); ASSERT_EQ(outbound_rtps.size(), 1u);
std::string codec_name = GetCurrentCodecMimeType(report, *outbound_rtps[0]); std::string codec_name = GetCurrentCodecMimeType(report, *outbound_rtps[0]);
EXPECT_STRCASEEQ(("video/" + vp9->name).c_str(), codec_name.c_str()); EXPECT_STRCASEEQ(("video/" + vp9->name).c_str(), codec_name.c_str());
EXPECT_EQ(outbound_rtps[0]->scalability_mode.value_or(""), "L3T3"); EXPECT_EQ(outbound_rtps[0]->scalability_mode.ValueOrDefault(""), "L3T3");
} }
TEST_F(PeerConnectionEncodingsIntegrationTest, TEST_F(PeerConnectionEncodingsIntegrationTest,

View file

@ -638,7 +638,7 @@ class RTCStatsReportVerifier {
inbound_stream.header_bytes_received); inbound_stream.header_bytes_received);
verifier.TestAttributeIsDefined( verifier.TestAttributeIsDefined(
inbound_stream.last_packet_received_timestamp); inbound_stream.last_packet_received_timestamp);
if (inbound_stream.frames_received.value_or(0) > 0) { if (inbound_stream.frames_received.ValueOrDefault(0) > 0) {
verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.frame_width); verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.frame_width);
verifier.TestAttributeIsNonNegative<uint32_t>( verifier.TestAttributeIsNonNegative<uint32_t>(
inbound_stream.frame_height); inbound_stream.frame_height);

View file

@ -47,22 +47,24 @@ void DefaultAudioQualityAnalyzer::OnStatsReports(
} }
StatsSample sample; StatsSample sample;
sample.total_samples_received = stat->total_samples_received.value_or(0ul); sample.total_samples_received =
sample.concealed_samples = stat->concealed_samples.value_or(0ul); stat->total_samples_received.ValueOrDefault(0ul);
sample.concealed_samples = stat->concealed_samples.ValueOrDefault(0ul);
sample.removed_samples_for_acceleration = sample.removed_samples_for_acceleration =
stat->removed_samples_for_acceleration.value_or(0ul); stat->removed_samples_for_acceleration.ValueOrDefault(0ul);
sample.inserted_samples_for_deceleration = sample.inserted_samples_for_deceleration =
stat->inserted_samples_for_deceleration.value_or(0ul); stat->inserted_samples_for_deceleration.ValueOrDefault(0ul);
sample.silent_concealed_samples = sample.silent_concealed_samples =
stat->silent_concealed_samples.value_or(0ul); stat->silent_concealed_samples.ValueOrDefault(0ul);
sample.jitter_buffer_delay = sample.jitter_buffer_delay =
TimeDelta::Seconds(stat->jitter_buffer_delay.value_or(0.)); TimeDelta::Seconds(stat->jitter_buffer_delay.ValueOrDefault(0.));
sample.jitter_buffer_target_delay = sample.jitter_buffer_target_delay =
TimeDelta::Seconds(stat->jitter_buffer_target_delay.value_or(0.)); TimeDelta::Seconds(stat->jitter_buffer_target_delay.ValueOrDefault(0.));
sample.jitter_buffer_emitted_count = sample.jitter_buffer_emitted_count =
stat->jitter_buffer_emitted_count.value_or(0ul); stat->jitter_buffer_emitted_count.ValueOrDefault(0ul);
sample.total_samples_duration = stat->total_samples_duration.value_or(0.); sample.total_samples_duration =
sample.total_audio_energy = stat->total_audio_energy.value_or(0.); stat->total_samples_duration.ValueOrDefault(0.);
sample.total_audio_energy = stat->total_audio_energy.ValueOrDefault(0.);
TrackIdStreamInfoMap::StreamInfo stream_info = TrackIdStreamInfoMap::StreamInfo stream_info =
analyzer_helper_->GetStreamInfoFromTrackId(*stat->track_identifier); analyzer_helper_->GetStreamInfoFromTrackId(*stat->track_identifier);

View file

@ -81,10 +81,10 @@ void VideoQualityMetricsReporter::OnStatsReports(
sample.sample_time = s->timestamp(); sample.sample_time = s->timestamp();
} }
sample.retransmitted_bytes_sent += sample.retransmitted_bytes_sent +=
DataSize::Bytes(s->retransmitted_bytes_sent.value_or(0ul)); DataSize::Bytes(s->retransmitted_bytes_sent.ValueOrDefault(0ul));
sample.bytes_sent += DataSize::Bytes(s->bytes_sent.value_or(0ul)); sample.bytes_sent += DataSize::Bytes(s->bytes_sent.ValueOrDefault(0ul));
sample.header_bytes_sent += sample.header_bytes_sent +=
DataSize::Bytes(s->header_bytes_sent.value_or(0ul)); DataSize::Bytes(s->header_bytes_sent.ValueOrDefault(0ul));
} }
MutexLock lock(&video_bwe_stats_lock_); MutexLock lock(&video_bwe_stats_lock_);

View file

@ -47,7 +47,7 @@ void CrossMediaMetricsReporter::OnStatsReports(
std::map<std::string, std::vector<const RTCInboundRtpStreamStats*>> std::map<std::string, std::vector<const RTCInboundRtpStreamStats*>>
sync_group_stats; sync_group_stats;
for (const auto& stat : inbound_stats) { for (const auto& stat : inbound_stats) {
if (stat->estimated_playout_timestamp.value_or(0.) > 0 && if (stat->estimated_playout_timestamp.ValueOrDefault(0.) > 0 &&
stat->track_identifier.is_defined()) { stat->track_identifier.is_defined()) {
sync_group_stats[reporter_helper_ sync_group_stats[reporter_helper_
->GetStreamInfoFromTrackId(*stat->track_identifier) ->GetStreamInfoFromTrackId(*stat->track_identifier)

View file

@ -79,14 +79,15 @@ void NetworkQualityMetricsReporter::OnStatsReports(
auto inbound_stats = report->GetStatsOfType<RTCInboundRtpStreamStats>(); auto inbound_stats = report->GetStatsOfType<RTCInboundRtpStreamStats>();
for (const auto& stat : inbound_stats) { for (const auto& stat : inbound_stats) {
payload_received += payload_received +=
DataSize::Bytes(stat->bytes_received.value_or(0ul) + DataSize::Bytes(stat->bytes_received.ValueOrDefault(0ul) +
stat->header_bytes_received.value_or(0ul)); stat->header_bytes_received.ValueOrDefault(0ul));
} }
auto outbound_stats = report->GetStatsOfType<RTCOutboundRtpStreamStats>(); auto outbound_stats = report->GetStatsOfType<RTCOutboundRtpStreamStats>();
for (const auto& stat : outbound_stats) { for (const auto& stat : outbound_stats) {
payload_sent += DataSize::Bytes(stat->bytes_sent.value_or(0ul) + payload_sent +=
stat->header_bytes_sent.value_or(0ul)); DataSize::Bytes(stat->bytes_sent.ValueOrDefault(0ul) +
stat->header_bytes_sent.ValueOrDefault(0ul));
} }
MutexLock lock(&lock_); MutexLock lock(&lock_);

View file

@ -299,23 +299,25 @@ void StatsBasedNetworkQualityMetricsReporter::OnStatsReports(
auto inbound_stats = report->GetStatsOfType<RTCInboundRtpStreamStats>(); auto inbound_stats = report->GetStatsOfType<RTCInboundRtpStreamStats>();
for (const auto& stat : inbound_stats) { for (const auto& stat : inbound_stats) {
cur_stats.payload_received += cur_stats.payload_received +=
DataSize::Bytes(stat->bytes_received.value_or(0ul) + DataSize::Bytes(stat->bytes_received.ValueOrDefault(0ul) +
stat->header_bytes_received.value_or(0ul)); stat->header_bytes_received.ValueOrDefault(0ul));
} }
auto outbound_stats = report->GetStatsOfType<RTCOutboundRtpStreamStats>(); auto outbound_stats = report->GetStatsOfType<RTCOutboundRtpStreamStats>();
for (const auto& stat : outbound_stats) { for (const auto& stat : outbound_stats) {
cur_stats.payload_sent += DataSize::Bytes( cur_stats.payload_sent +=
stat->bytes_sent.value_or(0ul) + stat->header_bytes_sent.value_or(0ul)); DataSize::Bytes(stat->bytes_sent.ValueOrDefault(0ul) +
stat->header_bytes_sent.ValueOrDefault(0ul));
} }
auto candidate_pairs_stats = report->GetStatsOfType<RTCTransportStats>(); auto candidate_pairs_stats = report->GetStatsOfType<RTCTransportStats>();
for (const auto& stat : candidate_pairs_stats) { for (const auto& stat : candidate_pairs_stats) {
cur_stats.total_received += cur_stats.total_received +=
DataSize::Bytes(stat->bytes_received.value_or(0ul)); DataSize::Bytes(stat->bytes_received.ValueOrDefault(0ul));
cur_stats.total_sent += DataSize::Bytes(stat->bytes_sent.value_or(0ul)); cur_stats.total_sent +=
cur_stats.packets_received += stat->packets_received.value_or(0ul); DataSize::Bytes(stat->bytes_sent.ValueOrDefault(0ul));
cur_stats.packets_sent += stat->packets_sent.value_or(0ul); cur_stats.packets_received += stat->packets_received.ValueOrDefault(0ul);
cur_stats.packets_sent += stat->packets_sent.ValueOrDefault(0ul);
} }
MutexLock lock(&mutex_); MutexLock lock(&mutex_);