2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/statistics_calculator.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <string.h> // memset
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2015-08-25 13:08:04 +02:00
|
|
|
#include <algorithm>
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2022-07-20 12:53:07 +02:00
|
|
|
#include "absl/strings/string_view.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/delay_manager.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
2017-11-22 10:42:26 +01:00
|
|
|
#include "rtc_base/numerics/safe_conversions.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/metrics.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2017-05-05 05:04:16 -07:00
|
|
|
namespace {
|
|
|
|
|
size_t AddIntToSizeTWithLowerCap(int a, size_t b) {
|
|
|
|
|
const size_t ret = b + a;
|
|
|
|
|
// If a + b is negative, resulting in a negative wrap, cap it to zero instead.
|
|
|
|
|
static_assert(sizeof(size_t) >= sizeof(int),
|
|
|
|
|
"int must not be wider than size_t for this to work");
|
|
|
|
|
return (a < 0 && ret > b) ? 0 : ret;
|
|
|
|
|
}
|
2019-04-26 09:47:07 +02:00
|
|
|
|
|
|
|
|
constexpr int kInterruptionLenMs = 150;
|
2017-05-05 05:04:16 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
2015-09-17 00:24:34 -07:00
|
|
|
// Allocating the static const so that it can be passed by reference to
|
|
|
|
|
// RTC_DCHECK.
|
2015-08-25 13:08:04 +02:00
|
|
|
const size_t StatisticsCalculator::kLenWaitingTimes;
|
|
|
|
|
|
2015-08-19 10:46:50 +02:00
|
|
|
StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger(
|
2022-07-20 12:53:07 +02:00
|
|
|
absl::string_view uma_name,
|
2015-08-19 10:46:50 +02:00
|
|
|
int report_interval_ms,
|
|
|
|
|
int max_value)
|
|
|
|
|
: uma_name_(uma_name),
|
|
|
|
|
report_interval_ms_(report_interval_ms),
|
|
|
|
|
max_value_(max_value),
|
|
|
|
|
timer_(0) {}
|
|
|
|
|
|
|
|
|
|
StatisticsCalculator::PeriodicUmaLogger::~PeriodicUmaLogger() = default;
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::PeriodicUmaLogger::AdvanceClock(int step_ms) {
|
|
|
|
|
timer_ += step_ms;
|
|
|
|
|
if (timer_ < report_interval_ms_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LogToUma(Metric());
|
|
|
|
|
Reset();
|
|
|
|
|
timer_ -= report_interval_ms_;
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK_GE(timer_, 0);
|
2015-08-19 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::PeriodicUmaLogger::LogToUma(int value) const {
|
2015-12-21 01:46:20 -08:00
|
|
|
RTC_HISTOGRAM_COUNTS_SPARSE(uma_name_, value, 1, max_value_, 50);
|
2015-08-19 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatisticsCalculator::PeriodicUmaCount::PeriodicUmaCount(
|
2022-07-20 12:53:07 +02:00
|
|
|
absl::string_view uma_name,
|
2015-08-19 10:46:50 +02:00
|
|
|
int report_interval_ms,
|
|
|
|
|
int max_value)
|
|
|
|
|
: PeriodicUmaLogger(uma_name, report_interval_ms, max_value) {}
|
|
|
|
|
|
|
|
|
|
StatisticsCalculator::PeriodicUmaCount::~PeriodicUmaCount() {
|
|
|
|
|
// Log the count for the current (incomplete) interval.
|
|
|
|
|
LogToUma(Metric());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::PeriodicUmaCount::RegisterSample() {
|
|
|
|
|
++counter_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int StatisticsCalculator::PeriodicUmaCount::Metric() const {
|
|
|
|
|
return counter_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::PeriodicUmaCount::Reset() {
|
|
|
|
|
counter_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatisticsCalculator::PeriodicUmaAverage::PeriodicUmaAverage(
|
2022-07-20 12:53:07 +02:00
|
|
|
absl::string_view uma_name,
|
2015-08-19 10:46:50 +02:00
|
|
|
int report_interval_ms,
|
|
|
|
|
int max_value)
|
|
|
|
|
: PeriodicUmaLogger(uma_name, report_interval_ms, max_value) {}
|
|
|
|
|
|
|
|
|
|
StatisticsCalculator::PeriodicUmaAverage::~PeriodicUmaAverage() {
|
|
|
|
|
// Log the average for the current (incomplete) interval.
|
|
|
|
|
LogToUma(Metric());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::PeriodicUmaAverage::RegisterSample(int value) {
|
|
|
|
|
sum_ += value;
|
|
|
|
|
++counter_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int StatisticsCalculator::PeriodicUmaAverage::Metric() const {
|
2016-02-09 00:35:53 -08:00
|
|
|
return counter_ == 0 ? 0 : static_cast<int>(sum_ / counter_);
|
2015-08-19 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::PeriodicUmaAverage::Reset() {
|
|
|
|
|
sum_ = 0.0;
|
|
|
|
|
counter_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 11:21:43 +00:00
|
|
|
StatisticsCalculator::StatisticsCalculator(TickTimer* tick_timer)
|
2013-01-29 12:09:21 +00:00
|
|
|
: preemptive_samples_(0),
|
|
|
|
|
accelerate_samples_(0),
|
2015-02-18 10:01:53 +00:00
|
|
|
expanded_speech_samples_(0),
|
2013-01-29 12:09:21 +00:00
|
|
|
expanded_noise_samples_(0),
|
2014-10-08 12:10:53 +00:00
|
|
|
timestamps_since_last_report_(0),
|
2015-08-19 10:46:50 +02:00
|
|
|
secondary_decoded_samples_(0),
|
2017-08-23 15:59:38 +02:00
|
|
|
discarded_secondary_packets_(0),
|
2015-08-19 10:46:50 +02:00
|
|
|
delayed_packet_outage_counter_(
|
|
|
|
|
"WebRTC.Audio.DelayedPacketOutageEventsPerMinute",
|
|
|
|
|
60000, // 60 seconds report interval.
|
|
|
|
|
100),
|
|
|
|
|
excess_buffer_delay_("WebRTC.Audio.AverageExcessBufferDelayMs",
|
|
|
|
|
60000, // 60 seconds report interval.
|
2018-10-16 16:55:52 +02:00
|
|
|
1000),
|
|
|
|
|
buffer_full_counter_("WebRTC.Audio.JitterBufferFullPerMinute",
|
|
|
|
|
60000, // 60 seconds report interval.
|
2024-09-30 11:21:43 +00:00
|
|
|
100),
|
|
|
|
|
expand_uma_logger_("WebRTC.Audio.ExpandRatePercent",
|
|
|
|
|
10, // Report once every 10 s.
|
|
|
|
|
tick_timer),
|
|
|
|
|
speech_expand_uma_logger_("WebRTC.Audio.SpeechExpandRatePercent",
|
|
|
|
|
10, // Report once every 10 s.
|
|
|
|
|
tick_timer) {}
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-08-25 13:08:04 +02:00
|
|
|
StatisticsCalculator::~StatisticsCalculator() = default;
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
void StatisticsCalculator::Reset() {
|
|
|
|
|
preemptive_samples_ = 0;
|
|
|
|
|
accelerate_samples_ = 0;
|
2015-02-18 10:01:53 +00:00
|
|
|
expanded_speech_samples_ = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
expanded_noise_samples_ = 0;
|
2015-02-17 10:17:09 +00:00
|
|
|
secondary_decoded_samples_ = 0;
|
2017-08-23 15:59:38 +02:00
|
|
|
discarded_secondary_packets_ = 0;
|
2015-08-25 13:08:04 +02:00
|
|
|
waiting_times_.clear();
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::ResetMcu() {
|
2014-10-08 12:10:53 +00:00
|
|
|
timestamps_since_last_report_ = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-18 09:28:20 +02:00
|
|
|
void StatisticsCalculator::ExpandedVoiceSamples(size_t num_samples,
|
|
|
|
|
bool is_new_concealment_event) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-18 10:01:53 +00:00
|
|
|
expanded_speech_samples_ += num_samples;
|
2018-02-07 18:46:33 +01:00
|
|
|
ConcealedSamplesCorrection(rtc::dchecked_cast<int>(num_samples), true);
|
2017-09-18 09:28:20 +02:00
|
|
|
lifetime_stats_.concealment_events += is_new_concealment_event;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-18 09:28:20 +02:00
|
|
|
void StatisticsCalculator::ExpandedNoiseSamples(size_t num_samples,
|
|
|
|
|
bool is_new_concealment_event) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-29 12:09:21 +00:00
|
|
|
expanded_noise_samples_ += num_samples;
|
2018-02-07 18:46:33 +01:00
|
|
|
ConcealedSamplesCorrection(rtc::dchecked_cast<int>(num_samples), false);
|
2017-09-18 09:28:20 +02:00
|
|
|
lifetime_stats_.concealment_events += is_new_concealment_event;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 05:04:16 -07:00
|
|
|
void StatisticsCalculator::ExpandedVoiceSamplesCorrection(int num_samples) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-05 05:04:16 -07:00
|
|
|
expanded_speech_samples_ =
|
|
|
|
|
AddIntToSizeTWithLowerCap(num_samples, expanded_speech_samples_);
|
2018-02-07 18:46:33 +01:00
|
|
|
ConcealedSamplesCorrection(num_samples, true);
|
2017-05-05 05:04:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::ExpandedNoiseSamplesCorrection(int num_samples) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-05 05:04:16 -07:00
|
|
|
expanded_noise_samples_ =
|
|
|
|
|
AddIntToSizeTWithLowerCap(num_samples, expanded_noise_samples_);
|
2018-02-07 18:46:33 +01:00
|
|
|
ConcealedSamplesCorrection(num_samples, false);
|
2017-09-25 12:22:46 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-26 09:47:07 +02:00
|
|
|
void StatisticsCalculator::DecodedOutputPlayed() {
|
|
|
|
|
decoded_output_played_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::EndExpandEvent(int fs_hz) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-26 09:47:07 +02:00
|
|
|
RTC_DCHECK_GE(lifetime_stats_.concealed_samples,
|
|
|
|
|
concealed_samples_at_event_end_);
|
|
|
|
|
const int event_duration_ms =
|
|
|
|
|
1000 *
|
|
|
|
|
(lifetime_stats_.concealed_samples - concealed_samples_at_event_end_) /
|
|
|
|
|
fs_hz;
|
|
|
|
|
if (event_duration_ms >= kInterruptionLenMs && decoded_output_played_) {
|
|
|
|
|
lifetime_stats_.interruption_count++;
|
|
|
|
|
lifetime_stats_.total_interruption_duration_ms += event_duration_ms;
|
2019-11-21 09:34:29 +01:00
|
|
|
RTC_HISTOGRAM_COUNTS("WebRTC.Audio.AudioInterruptionMs", event_duration_ms,
|
|
|
|
|
/*min=*/150, /*max=*/5000, /*bucket_count=*/50);
|
2019-04-26 09:47:07 +02:00
|
|
|
}
|
|
|
|
|
concealed_samples_at_event_end_ = lifetime_stats_.concealed_samples;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 18:46:33 +01:00
|
|
|
void StatisticsCalculator::ConcealedSamplesCorrection(int num_samples,
|
|
|
|
|
bool is_voice) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-25 12:22:46 +02:00
|
|
|
if (num_samples < 0) {
|
|
|
|
|
// Store negative correction to subtract from future positive additions.
|
|
|
|
|
// See also the function comment in the header file.
|
|
|
|
|
concealed_samples_correction_ -= num_samples;
|
2019-04-24 14:06:24 +02:00
|
|
|
if (!is_voice) {
|
|
|
|
|
silent_concealed_samples_correction_ -= num_samples;
|
2018-02-07 18:46:33 +01:00
|
|
|
}
|
2017-09-25 12:22:46 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const size_t canceled_out =
|
|
|
|
|
std::min(static_cast<size_t>(num_samples), concealed_samples_correction_);
|
|
|
|
|
concealed_samples_correction_ -= canceled_out;
|
|
|
|
|
lifetime_stats_.concealed_samples += num_samples - canceled_out;
|
2018-02-07 18:46:33 +01:00
|
|
|
|
2019-04-24 14:06:24 +02:00
|
|
|
if (!is_voice) {
|
|
|
|
|
const size_t silent_canceled_out = std::min(
|
|
|
|
|
static_cast<size_t>(num_samples), silent_concealed_samples_correction_);
|
|
|
|
|
silent_concealed_samples_correction_ -= silent_canceled_out;
|
|
|
|
|
lifetime_stats_.silent_concealed_samples +=
|
|
|
|
|
num_samples - silent_canceled_out;
|
2018-02-07 18:46:33 +01:00
|
|
|
}
|
2017-05-05 05:04:16 -07:00
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
void StatisticsCalculator::PreemptiveExpandedSamples(size_t num_samples) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-29 12:09:21 +00:00
|
|
|
preemptive_samples_ += num_samples;
|
2018-09-13 14:39:55 +02:00
|
|
|
operations_and_state_.preemptive_samples += num_samples;
|
2019-04-24 14:06:24 +02:00
|
|
|
lifetime_stats_.inserted_samples_for_deceleration += num_samples;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
void StatisticsCalculator::AcceleratedSamples(size_t num_samples) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-29 12:09:21 +00:00
|
|
|
accelerate_samples_ += num_samples;
|
2018-09-13 14:39:55 +02:00
|
|
|
operations_and_state_.accelerate_samples += num_samples;
|
2019-04-24 14:06:24 +02:00
|
|
|
lifetime_stats_.removed_samples_for_acceleration += num_samples;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 20:31:51 +02:00
|
|
|
void StatisticsCalculator::GeneratedNoiseSamples(size_t num_samples) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-04-18 20:31:51 +02:00
|
|
|
lifetime_stats_.generated_noise_samples += num_samples;
|
|
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
void StatisticsCalculator::PacketsDiscarded(size_t num_packets) {
|
2022-05-25 22:00:14 +02:00
|
|
|
lifetime_stats_.packets_discarded += num_packets;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-23 15:59:38 +02:00
|
|
|
void StatisticsCalculator::SecondaryPacketsDiscarded(size_t num_packets) {
|
|
|
|
|
discarded_secondary_packets_ += num_packets;
|
2019-04-24 14:06:24 +02:00
|
|
|
lifetime_stats_.fec_packets_discarded += num_packets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::SecondaryPacketsReceived(size_t num_packets) {
|
|
|
|
|
lifetime_stats_.fec_packets_received += num_packets;
|
2017-08-23 15:59:38 +02:00
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
void StatisticsCalculator::IncreaseCounter(size_t num_samples, int fs_hz) {
|
2024-10-02 09:25:29 +00:00
|
|
|
if (!decoded_output_played_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const int time_step_ms =
|
|
|
|
|
rtc::CheckedDivExact(static_cast<int>(1000 * num_samples), fs_hz);
|
2015-08-19 10:46:50 +02:00
|
|
|
delayed_packet_outage_counter_.AdvanceClock(time_step_ms);
|
|
|
|
|
excess_buffer_delay_.AdvanceClock(time_step_ms);
|
2018-10-16 16:55:52 +02:00
|
|
|
buffer_full_counter_.AdvanceClock(time_step_ms);
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
timestamps_since_last_report_ += static_cast<uint32_t>(num_samples);
|
2014-10-08 12:10:53 +00:00
|
|
|
if (timestamps_since_last_report_ >
|
2013-01-29 12:09:21 +00:00
|
|
|
static_cast<uint32_t>(fs_hz * kMaxReportPeriod)) {
|
2014-10-08 12:10:53 +00:00
|
|
|
timestamps_since_last_report_ = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
2017-08-24 17:15:13 -07:00
|
|
|
lifetime_stats_.total_samples_received += num_samples;
|
2024-09-30 11:21:43 +00:00
|
|
|
expand_uma_logger_.UpdateSampleCounter(lifetime_stats_.concealed_samples,
|
|
|
|
|
fs_hz);
|
2024-10-02 09:25:29 +00:00
|
|
|
uint64_t speech_concealed_samples = 0;
|
|
|
|
|
if (lifetime_stats_.concealed_samples >
|
|
|
|
|
lifetime_stats_.silent_concealed_samples) {
|
|
|
|
|
speech_concealed_samples = lifetime_stats_.concealed_samples -
|
|
|
|
|
lifetime_stats_.silent_concealed_samples;
|
|
|
|
|
}
|
|
|
|
|
speech_expand_uma_logger_.UpdateSampleCounter(speech_concealed_samples,
|
|
|
|
|
fs_hz);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 10:05:31 +02:00
|
|
|
void StatisticsCalculator::JitterBufferDelay(size_t num_samples,
|
|
|
|
|
uint64_t waiting_time_ms,
|
|
|
|
|
uint64_t target_delay_ms,
|
|
|
|
|
uint64_t unlimited_target_delay_ms,
|
|
|
|
|
uint64_t processing_delay_us) {
|
2017-10-02 12:00:34 +02:00
|
|
|
lifetime_stats_.jitter_buffer_delay_ms += waiting_time_ms * num_samples;
|
2020-03-11 11:18:54 +01:00
|
|
|
lifetime_stats_.jitter_buffer_target_delay_ms +=
|
|
|
|
|
target_delay_ms * num_samples;
|
2022-07-19 16:33:10 +02:00
|
|
|
lifetime_stats_.jitter_buffer_minimum_delay_ms +=
|
|
|
|
|
unlimited_target_delay_ms * num_samples;
|
2019-01-15 15:46:29 +01:00
|
|
|
lifetime_stats_.jitter_buffer_emitted_count += num_samples;
|
2024-06-04 10:05:31 +02:00
|
|
|
lifetime_stats_.total_processing_delay_us +=
|
|
|
|
|
num_samples * processing_delay_us;
|
2017-10-02 12:00:34 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
void StatisticsCalculator::SecondaryDecodedSamples(int num_samples) {
|
|
|
|
|
secondary_decoded_samples_ += num_samples;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 11:43:42 +02:00
|
|
|
void StatisticsCalculator::FlushedPacketBuffer() {
|
|
|
|
|
operations_and_state_.packet_buffer_flushes++;
|
2018-10-16 16:55:52 +02:00
|
|
|
buffer_full_counter_.RegisterSample();
|
2018-09-27 11:43:42 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-05 16:59:03 +01:00
|
|
|
void StatisticsCalculator::ReceivedPacket() {
|
|
|
|
|
++lifetime_stats_.jitter_buffer_packets_received;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatisticsCalculator::RelativePacketArrivalDelay(size_t delay_ms) {
|
|
|
|
|
lifetime_stats_.relative_packet_arrival_delay_ms += delay_ms;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 12:52:16 +01:00
|
|
|
void StatisticsCalculator::LogDelayedPacketOutageEvent(int num_samples,
|
|
|
|
|
int fs_hz) {
|
|
|
|
|
int outage_duration_ms = num_samples / (fs_hz / 1000);
|
2016-03-07 01:52:59 -08:00
|
|
|
RTC_HISTOGRAM_COUNTS("WebRTC.Audio.DelayedPacketOutageEventMs",
|
|
|
|
|
outage_duration_ms, 1 /* min */, 2000 /* max */,
|
|
|
|
|
100 /* bucket count */);
|
2015-08-19 10:46:50 +02:00
|
|
|
delayed_packet_outage_counter_.RegisterSample();
|
2018-11-27 12:52:16 +01:00
|
|
|
lifetime_stats_.delayed_packet_outage_samples += num_samples;
|
2023-04-25 21:01:15 +02:00
|
|
|
++lifetime_stats_.delayed_packet_outage_events;
|
2015-08-18 14:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
void StatisticsCalculator::StoreWaitingTime(int waiting_time_ms) {
|
2015-08-19 10:46:50 +02:00
|
|
|
excess_buffer_delay_.RegisterSample(waiting_time_ms);
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK_LE(waiting_times_.size(), kLenWaitingTimes);
|
2015-08-27 13:41:02 -07:00
|
|
|
if (waiting_times_.size() == kLenWaitingTimes) {
|
2015-08-25 13:08:04 +02:00
|
|
|
// Erase first value.
|
|
|
|
|
waiting_times_.pop_front();
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
2015-08-25 13:08:04 +02:00
|
|
|
waiting_times_.push_back(waiting_time_ms);
|
2018-09-13 14:39:55 +02:00
|
|
|
operations_and_state_.last_waiting_time_ms = waiting_time_ms;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-14 10:47:50 +02:00
|
|
|
void StatisticsCalculator::GetNetworkStatistics(size_t samples_per_packet,
|
2013-01-29 12:09:21 +00:00
|
|
|
NetEqNetworkStatistics* stats) {
|
2017-09-25 12:30:58 +02:00
|
|
|
RTC_DCHECK(stats);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2014-10-08 12:10:53 +00:00
|
|
|
stats->accelerate_rate =
|
|
|
|
|
CalculateQ14Ratio(accelerate_samples_, timestamps_since_last_report_);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2014-10-08 12:10:53 +00:00
|
|
|
stats->preemptive_rate =
|
|
|
|
|
CalculateQ14Ratio(preemptive_samples_, timestamps_since_last_report_);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2014-10-08 12:10:53 +00:00
|
|
|
stats->expand_rate =
|
2015-02-18 10:01:53 +00:00
|
|
|
CalculateQ14Ratio(expanded_speech_samples_ + expanded_noise_samples_,
|
2014-10-08 12:10:53 +00:00
|
|
|
timestamps_since_last_report_);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-02-18 10:01:53 +00:00
|
|
|
stats->speech_expand_rate = CalculateQ14Ratio(expanded_speech_samples_,
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
timestamps_since_last_report_);
|
2015-02-18 10:01:53 +00:00
|
|
|
|
2015-02-17 10:17:09 +00:00
|
|
|
stats->secondary_decoded_rate = CalculateQ14Ratio(
|
|
|
|
|
secondary_decoded_samples_, timestamps_since_last_report_);
|
|
|
|
|
|
2017-08-23 15:59:38 +02:00
|
|
|
const size_t discarded_secondary_samples =
|
|
|
|
|
discarded_secondary_packets_ * samples_per_packet;
|
|
|
|
|
stats->secondary_discarded_rate =
|
|
|
|
|
CalculateQ14Ratio(discarded_secondary_samples,
|
2017-08-28 13:01:45 -07:00
|
|
|
static_cast<uint32_t>(discarded_secondary_samples +
|
|
|
|
|
secondary_decoded_samples_));
|
2017-08-23 15:59:38 +02:00
|
|
|
|
2015-08-25 13:08:04 +02:00
|
|
|
if (waiting_times_.size() == 0) {
|
|
|
|
|
stats->mean_waiting_time_ms = -1;
|
|
|
|
|
stats->median_waiting_time_ms = -1;
|
|
|
|
|
stats->min_waiting_time_ms = -1;
|
|
|
|
|
stats->max_waiting_time_ms = -1;
|
|
|
|
|
} else {
|
|
|
|
|
std::sort(waiting_times_.begin(), waiting_times_.end());
|
|
|
|
|
// Find mid-point elements. If the size is odd, the two values
|
2021-07-28 20:00:17 +02:00
|
|
|
// `middle_left` and `middle_right` will both be the one middle element; if
|
2015-08-25 13:08:04 +02:00
|
|
|
// the size is even, they will be the the two neighboring elements at the
|
|
|
|
|
// middle of the list.
|
|
|
|
|
const int middle_left = waiting_times_[(waiting_times_.size() - 1) / 2];
|
|
|
|
|
const int middle_right = waiting_times_[waiting_times_.size() / 2];
|
|
|
|
|
// Calculate the average of the two. (Works also for odd sizes.)
|
|
|
|
|
stats->median_waiting_time_ms = (middle_left + middle_right) / 2;
|
|
|
|
|
stats->min_waiting_time_ms = waiting_times_.front();
|
|
|
|
|
stats->max_waiting_time_ms = waiting_times_.back();
|
|
|
|
|
double sum = 0;
|
|
|
|
|
for (auto time : waiting_times_) {
|
|
|
|
|
sum += time;
|
|
|
|
|
}
|
|
|
|
|
stats->mean_waiting_time_ms = static_cast<int>(sum / waiting_times_.size());
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Reset counters.
|
|
|
|
|
ResetMcu();
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 17:15:13 -07:00
|
|
|
NetEqLifetimeStatistics StatisticsCalculator::GetLifetimeStatistics() const {
|
|
|
|
|
return lifetime_stats_;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 14:39:55 +02:00
|
|
|
NetEqOperationsAndState StatisticsCalculator::GetOperationsAndState() const {
|
|
|
|
|
return operations_and_state_;
|
|
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
uint16_t StatisticsCalculator::CalculateQ14Ratio(size_t numerator,
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
uint32_t denominator) {
|
2013-01-29 12:09:21 +00:00
|
|
|
if (numerator == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (numerator < denominator) {
|
|
|
|
|
// Ratio must be smaller than 1 in Q14.
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_LT((numerator << 14) / denominator, (1 << 14));
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
return static_cast<uint16_t>((numerator << 14) / denominator);
|
2013-01-29 12:09:21 +00:00
|
|
|
} else {
|
|
|
|
|
// Will not produce a ratio larger than 1, since this is probably an error.
|
|
|
|
|
return 1 << 14;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|