From 3fdb3cbc6aeed9d2598f076a6740374c11d4c06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Wed, 11 Dec 2019 10:57:13 +0100 Subject: [PATCH] Remove potential real-time reallocation in PushResampler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL removes the use of absl::InlineVector in the PushResampler which causes real-time reallocations for setups with more than 8 channels. As part of the CL, it also removes one dependency on absl for the common_audio module. Bug: webrtc:11197 Change-Id: I0788ee9a0f3d08b91bb18caa65f660fb52368a97 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161729 Commit-Queue: Per Ã…hgren Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#30059} --- common_audio/BUILD.gn | 1 - common_audio/resampler/include/push_resampler.h | 5 +++++ common_audio/resampler/push_resampler.cc | 17 ++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/common_audio/BUILD.gn b/common_audio/BUILD.gn index 7170000740..8b18fcbf92 100644 --- a/common_audio/BUILD.gn +++ b/common_audio/BUILD.gn @@ -58,7 +58,6 @@ rtc_library("common_audio") { "../system_wrappers", "../system_wrappers:cpu_features_api", "third_party/fft4g", - "//third_party/abseil-cpp/absl/container:inlined_vector", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/common_audio/resampler/include/push_resampler.h b/common_audio/resampler/include/push_resampler.h index 232ad2a79f..3da67120f0 100644 --- a/common_audio/resampler/include/push_resampler.h +++ b/common_audio/resampler/include/push_resampler.h @@ -40,6 +40,11 @@ class PushResampler { int src_sample_rate_hz_; int dst_sample_rate_hz_; size_t num_channels_; + // Vector that is needed to provide the proper inputs and outputs to the + // interleave/de-interleave methods used in Resample. This needs to be + // heap-allocated on the state to support an arbitrary number of channels + // without doing run-time heap-allocations in the Resample method. + std::vector channel_data_array_; struct ChannelResampler { std::unique_ptr resampler; diff --git a/common_audio/resampler/push_resampler.cc b/common_audio/resampler/push_resampler.cc index 17b876b6b2..d7aa8d7613 100644 --- a/common_audio/resampler/push_resampler.cc +++ b/common_audio/resampler/push_resampler.cc @@ -15,7 +15,6 @@ #include -#include "absl/container/inlined_vector.h" #include "common_audio/include/audio_util.h" #include "common_audio/resampler/push_sinc_resampler.h" #include "rtc_base/checks.h" @@ -100,6 +99,8 @@ int PushResampler::InitializeIfNeeded(int src_sample_rate_hz, channel_resampler->destination.resize(dst_size_10ms_mono); } + channel_data_array_.resize(num_channels_); + return 0; } @@ -121,12 +122,11 @@ int PushResampler::Resample(const T* src, const size_t src_length_mono = src_length / num_channels_; const size_t dst_capacity_mono = dst_capacity / num_channels_; - absl::InlinedVector source_pointers; - for (auto& resampler : channel_resamplers_) { - source_pointers.push_back(resampler.source.data()); + for (size_t ch = 0; ch < num_channels_; ++ch) { + channel_data_array_[ch] = channel_resamplers_[ch].source.data(); } - Deinterleave(src, src_length_mono, num_channels_, source_pointers.data()); + Deinterleave(src, src_length_mono, num_channels_, channel_data_array_.data()); size_t dst_length_mono = 0; @@ -136,12 +136,11 @@ int PushResampler::Resample(const T* src, dst_capacity_mono); } - absl::InlinedVector destination_pointers; - for (auto& resampler : channel_resamplers_) { - destination_pointers.push_back(resampler.destination.data()); + for (size_t ch = 0; ch < num_channels_; ++ch) { + channel_data_array_[ch] = channel_resamplers_[ch].destination.data(); } - Interleave(destination_pointers.data(), dst_length_mono, num_channels_, dst); + Interleave(channel_data_array_.data(), dst_length_mono, num_channels_, dst); return static_cast(dst_length_mono * num_channels_); }