diff --git a/api/mediastreaminterface.cc b/api/mediastreaminterface.cc index 6f08a0caf1..e36d5cb83b 100644 --- a/api/mediastreaminterface.cc +++ b/api/mediastreaminterface.cc @@ -17,34 +17,6 @@ namespace webrtc { const char MediaStreamTrackInterface::kVideoKind[] = "video"; const char MediaStreamTrackInterface::kAudioKind[] = "audio"; -void AudioProcessorInterface::GetStats(AudioProcessorStats* /*stats*/) { - RTC_NOTREACHED() << "Old-style GetStats() is called but it has no " - << "implementation."; - RTC_LOG(LS_ERROR) << "Old-style GetStats() is called but it has no " - << "implementation."; -} - -// TODO(ivoc): Remove this when the function becomes pure virtual. -AudioProcessorInterface::AudioProcessorStatistics -AudioProcessorInterface::GetStats(bool /*has_remote_tracks*/) { - AudioProcessorStats stats; - GetStats(&stats); - AudioProcessorStatistics new_stats; - new_stats.apm_statistics.divergent_filter_fraction = - stats.aec_divergent_filter_fraction; - new_stats.apm_statistics.delay_median_ms = stats.echo_delay_median_ms; - new_stats.apm_statistics.delay_standard_deviation_ms = - stats.echo_delay_std_ms; - new_stats.apm_statistics.echo_return_loss = stats.echo_return_loss; - new_stats.apm_statistics.echo_return_loss_enhancement = - stats.echo_return_loss_enhancement; - new_stats.apm_statistics.residual_echo_likelihood = - stats.residual_echo_likelihood; - new_stats.apm_statistics.residual_echo_likelihood_recent_max = - stats.residual_echo_likelihood_recent_max; - return new_stats; -} - VideoTrackInterface::ContentHint VideoTrackInterface::content_hint() const { return ContentHint::kNone; } diff --git a/api/mediastreaminterface.h b/api/mediastreaminterface.h index 2eb2f31d4f..30f8f71602 100644 --- a/api/mediastreaminterface.h +++ b/api/mediastreaminterface.h @@ -213,47 +213,17 @@ class AudioSourceInterface : public MediaSourceInterface { // statistics. class AudioProcessorInterface : public rtc::RefCountInterface { public: - // Deprecated, use AudioProcessorStatistics instead. - // TODO(ivoc): Remove this when all implementations have switched to the new - // GetStats function. See b/67926135. - struct AudioProcessorStats { - AudioProcessorStats() - : typing_noise_detected(false), - echo_return_loss(0), - echo_return_loss_enhancement(0), - echo_delay_median_ms(0), - echo_delay_std_ms(0), - residual_echo_likelihood(0.0f), - residual_echo_likelihood_recent_max(0.0f), - aec_divergent_filter_fraction(0.0) {} - ~AudioProcessorStats() {} - - bool typing_noise_detected; - int echo_return_loss; - int echo_return_loss_enhancement; - int echo_delay_median_ms; - int echo_delay_std_ms; - float residual_echo_likelihood; - float residual_echo_likelihood_recent_max; - float aec_divergent_filter_fraction; - }; - // This struct maintains the optionality of the stats, and will replace the - // regular stats struct when all users have been updated. struct AudioProcessorStatistics { bool typing_noise_detected = false; AudioProcessingStats apm_statistics; }; - // Get audio processor statistics. - virtual void GetStats(AudioProcessorStats* stats); - // Get audio processor statistics. The |has_remote_tracks| argument should be // set if there are active remote tracks (this would usually be true during // a call). If there are no remote tracks some of the stats will not be set by // the AudioProcessor, because they only make sense if there is at least one // remote track. - // TODO(ivoc): Make pure virtual when all implementions are updated. - virtual AudioProcessorStatistics GetStats(bool has_remote_tracks); + virtual AudioProcessorStatistics GetStats(bool has_remote_tracks) = 0; protected: ~AudioProcessorInterface() override = default; diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc index 876911c846..9712d42d22 100644 --- a/modules/audio_processing/audio_processing_impl.cc +++ b/modules/audio_processing/audio_processing_impl.cc @@ -1589,63 +1589,6 @@ void AudioProcessingImpl::DetachPlayoutAudioGenerator() { // Delete audio generator, if one is attached. } -AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics() { - residual_echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f); - echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f); - echo_return_loss_enhancement.Set(-100.0f, -100.0f, -100.0f, -100.0f); - a_nlp.Set(-100.0f, -100.0f, -100.0f, -100.0f); -} - -AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics( - const AudioProcessingStatistics& other) = default; - -AudioProcessing::AudioProcessingStatistics::~AudioProcessingStatistics() = - default; - -// TODO(ivoc): Remove this when GetStatistics() becomes pure virtual. -AudioProcessing::AudioProcessingStatistics AudioProcessing::GetStatistics() - const { - return AudioProcessingStatistics(); -} - -// TODO(ivoc): Remove this when GetStatistics() becomes pure virtual. -AudioProcessingStats AudioProcessing::GetStatistics( - bool has_remote_tracks) const { - return AudioProcessingStats(); -} - -AudioProcessing::AudioProcessingStatistics AudioProcessingImpl::GetStatistics() - const { - AudioProcessingStatistics stats; - EchoCancellationImpl::Metrics metrics; - rtc::CritScope cs_capture(&crit_capture_); - if (private_submodules_->echo_controller) { - auto ec_metrics = private_submodules_->echo_controller->GetMetrics(); - float erl = static_cast(ec_metrics.echo_return_loss); - float erle = static_cast(ec_metrics.echo_return_loss_enhancement); - // Instant value will also be used for min, max and average. - stats.echo_return_loss.Set(erl, erl, erl, erl); - stats.echo_return_loss_enhancement.Set(erle, erle, erle, erle); - } else if (private_submodules_->echo_cancellation->GetMetrics(&metrics) == - Error::kNoError) { - stats.a_nlp.Set(metrics.a_nlp); - stats.divergent_filter_fraction = metrics.divergent_filter_fraction; - stats.echo_return_loss.Set(metrics.echo_return_loss); - stats.echo_return_loss_enhancement.Set( - metrics.echo_return_loss_enhancement); - stats.residual_echo_return_loss.Set(metrics.residual_echo_return_loss); - } - RTC_DCHECK(private_submodules_->echo_detector); - auto ed_metrics = private_submodules_->echo_detector->GetMetrics(); - stats.residual_echo_likelihood = ed_metrics.echo_likelihood; - stats.residual_echo_likelihood_recent_max = - ed_metrics.echo_likelihood_recent_max; - private_submodules_->echo_cancellation->GetDelayMetrics( - &stats.delay_median, &stats.delay_standard_deviation, - &stats.fraction_poor_delays); - return stats; -} - AudioProcessingStats AudioProcessingImpl::GetStatistics( bool has_remote_tracks) const { AudioProcessingStats stats; diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h index 45b6c5729c..e376a7423e 100644 --- a/modules/audio_processing/audio_processing_impl.h +++ b/modules/audio_processing/audio_processing_impl.h @@ -109,7 +109,6 @@ class AudioProcessingImpl : public AudioProcessing { bool was_stream_delay_set() const override RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); - AudioProcessingStatistics GetStatistics() const override; AudioProcessingStats GetStatistics(bool has_remote_tracks) const override; // Methods returning pointers to APM submodules. diff --git a/modules/audio_processing/echo_cancellation_impl.h b/modules/audio_processing/echo_cancellation_impl.h index 72c7e52a77..a8b43a8cd6 100644 --- a/modules/audio_processing/echo_cancellation_impl.h +++ b/modules/audio_processing/echo_cancellation_impl.h @@ -83,17 +83,23 @@ class EchoCancellationImpl { // P_a: Internal signal power at the point before the AEC's non-linear // processor. struct Metrics { + struct Statistic { + int instant = 0; // Instantaneous value. + int average = 0; // Long-term average. + int maximum = 0; // Long-term maximum. + int minimum = 0; // Long-term minimum. + }; // RERL = ERL + ERLE - AudioProcessing::Statistic residual_echo_return_loss; + Statistic residual_echo_return_loss; // ERL = 10log_10(P_far / P_echo) - AudioProcessing::Statistic echo_return_loss; + Statistic echo_return_loss; // ERLE = 10log_10(P_echo / P_out) - AudioProcessing::Statistic echo_return_loss_enhancement; + Statistic echo_return_loss_enhancement; // (Pre non-linear processing suppression) A_NLP = 10log_10(P_echo / P_a) - AudioProcessing::Statistic a_nlp; + Statistic a_nlp; // Fraction of time that the AEC linear filter is divergent, in a 1-second // non-overlapped aggregation window. diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h index e428516567..bd4a18e613 100644 --- a/modules/audio_processing/include/audio_processing.h +++ b/modules/audio_processing/include/audio_processing.h @@ -520,78 +520,12 @@ class AudioProcessing : public rtc::RefCountInterface { // specific member variables are reset. virtual void UpdateHistogramsOnCallEnd() = 0; - // TODO(ivoc): Remove when the calling code no longer uses the old Statistics - // API. - struct Statistic { - int instant = 0; // Instantaneous value. - int average = 0; // Long-term average. - int maximum = 0; // Long-term maximum. - int minimum = 0; // Long-term minimum. - }; - - struct Stat { - void Set(const Statistic& other) { - Set(other.instant, other.average, other.maximum, other.minimum); - } - void Set(float instant, float average, float maximum, float minimum) { - instant_ = instant; - average_ = average; - maximum_ = maximum; - minimum_ = minimum; - } - float instant() const { return instant_; } - float average() const { return average_; } - float maximum() const { return maximum_; } - float minimum() const { return minimum_; } - - private: - float instant_ = 0.0f; // Instantaneous value. - float average_ = 0.0f; // Long-term average. - float maximum_ = 0.0f; // Long-term maximum. - float minimum_ = 0.0f; // Long-term minimum. - }; - - struct RTC_EXPORT AudioProcessingStatistics { - AudioProcessingStatistics(); - AudioProcessingStatistics(const AudioProcessingStatistics& other); - ~AudioProcessingStatistics(); - - // AEC Statistics. - // RERL = ERL + ERLE - Stat residual_echo_return_loss; - // ERL = 10log_10(P_far / P_echo) - Stat echo_return_loss; - // ERLE = 10log_10(P_echo / P_out) - Stat echo_return_loss_enhancement; - // (Pre non-linear processing suppression) A_NLP = 10log_10(P_echo / P_a) - Stat a_nlp; - // Fraction of time that the AEC linear filter is divergent, in a 1-second - // non-overlapped aggregation window. - float divergent_filter_fraction = -1.0f; - - // The delay metrics consists of the delay median and standard deviation. It - // also consists of the fraction of delay estimates that can make the echo - // cancellation perform poorly. The values are aggregated until the first - // call to |GetStatistics()| and afterwards aggregated and updated every - // second. Note that if there are several clients pulling metrics from - // |GetStatistics()| during a session the first call from any of them will - // change to one second aggregation window for all. - int delay_median = -1; - int delay_standard_deviation = -1; - float fraction_poor_delays = -1.0f; - - // Residual echo detector likelihood. - float residual_echo_likelihood = -1.0f; - // Maximum residual echo likelihood from the last time period. - float residual_echo_likelihood_recent_max = -1.0f; - }; - - // TODO(ivoc): Make this pure virtual when all subclasses have been updated. - virtual AudioProcessingStatistics GetStatistics() const; - - // This returns the stats as optionals and it will replace the regular - // GetStatistics. - virtual AudioProcessingStats GetStatistics(bool has_remote_tracks) const; + // Get audio processing statistics. The |has_remote_tracks| argument should be + // set if there are active remote tracks (this would usually be true during + // a call). If there are no remote tracks some of the stats will not be set by + // AudioProcessing, because they only make sense if there is at least one + // remote track. + virtual AudioProcessingStats GetStatistics(bool has_remote_tracks) const = 0; // These provide access to the component interfaces and should never return // NULL. The pointers will be valid for the lifetime of the APM instance. diff --git a/modules/audio_processing/include/mock_audio_processing.h b/modules/audio_processing/include/mock_audio_processing.h index 767af0a7b0..f00a16d5e2 100644 --- a/modules/audio_processing/include/mock_audio_processing.h +++ b/modules/audio_processing/include/mock_audio_processing.h @@ -172,7 +172,6 @@ class MockAudioProcessing : public testing::NiceMock { MOCK_METHOD0(DetachPlayoutAudioGenerator, void()); MOCK_METHOD0(UpdateHistogramsOnCallEnd, void()); - MOCK_CONST_METHOD0(GetStatistics, AudioProcessingStatistics()); MOCK_CONST_METHOD1(GetStatistics, AudioProcessingStats(bool)); virtual MockGainControl* gain_control() const { return gain_control_.get(); } virtual MockLevelEstimator* level_estimator() const { diff --git a/modules/audio_processing/test/audio_processing_simulator.cc b/modules/audio_processing/test/audio_processing_simulator.cc index aae936389b..b0d4f04a82 100644 --- a/modules/audio_processing/test/audio_processing_simulator.cc +++ b/modules/audio_processing/test/audio_processing_simulator.cc @@ -209,9 +209,9 @@ void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { } if (residual_echo_likelihood_graph_writer_.is_open()) { - auto stats = ap_->GetStatistics(); - residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood - << ", "; + auto stats = ap_->GetStatistics(true /*has_remote_tracks*/); + residual_echo_likelihood_graph_writer_ + << stats.residual_echo_likelihood.value_or(-1.f) << ", "; } ++num_process_stream_calls_; diff --git a/pc/statscollector_unittest.cc b/pc/statscollector_unittest.cc index cbd7cc37dd..4a4be413d9 100644 --- a/pc/statscollector_unittest.cc +++ b/pc/statscollector_unittest.cc @@ -57,14 +57,6 @@ class FakeAudioProcessor : public AudioProcessorInterface { ~FakeAudioProcessor() {} private: - void GetStats(AudioProcessorInterface::AudioProcessorStats* stats) override { - stats->typing_noise_detected = true; - stats->echo_return_loss = 2; - stats->echo_return_loss_enhancement = 3; - stats->echo_delay_median_ms = 4; - stats->echo_delay_std_ms = 6; - } - AudioProcessorInterface::AudioProcessorStatistics GetStats( bool has_recv_streams) override { AudioProcessorStatistics stats; @@ -108,14 +100,6 @@ class FakeAudioProcessorWithInitValue : public AudioProcessorInterface { ~FakeAudioProcessorWithInitValue() {} private: - void GetStats(AudioProcessorInterface::AudioProcessorStats* stats) override { - stats->typing_noise_detected = false; - stats->echo_return_loss = -100; - stats->echo_return_loss_enhancement = -100; - stats->echo_delay_median_ms = -1; - stats->echo_delay_std_ms = -1; - } - AudioProcessorInterface::AudioProcessorStatistics GetStats( bool /*has_recv_streams*/) override { AudioProcessorStatistics stats; @@ -1568,7 +1552,7 @@ TEST_P(StatsCollectorTrackTest, GetStatsAfterRemoveAudioStream) { // Verifies the values in the track report, no value will be changed by the // AudioTrackInterface::GetSignalValue() and - // AudioProcessorInterface::AudioProcessorStats::GetStats(); + // AudioProcessorInterface::GetStats(); VerifyVoiceSenderInfoReport(report, voice_sender_info); } diff --git a/test/fuzzers/audio_processing_fuzzer_helper.cc b/test/fuzzers/audio_processing_fuzzer_helper.cc index 073ab17bd9..dec4e1f05e 100644 --- a/test/fuzzers/audio_processing_fuzzer_helper.cc +++ b/test/fuzzers/audio_processing_fuzzer_helper.cc @@ -130,10 +130,8 @@ void FuzzAudioProcessing(test::FuzzDataHelper* fuzz_data, } } - // Make calls to stats gathering functions to cover these - // codeways. - static_cast(apm->GetStatistics()); - static_cast(apm->GetStatistics(true)); + // Cover stats gathering code paths. + static_cast(apm->GetStatistics(true /*has_remote_tracks*/)); static_cast(apm->UpdateHistogramsOnCallEnd()); RTC_DCHECK_NE(apm_return_code, AudioProcessing::kBadDataLengthError);