aboutsummaryrefslogtreecommitdiff
path: root/common_audio
diff options
context:
space:
mode:
authorPer Åhgren <peah@webrtc.org>2019-12-11 10:57:13 +0100
committerCommit Bot <commit-bot@chromium.org>2019-12-11 13:16:37 +0000
commit3fdb3cbc6aeed9d2598f076a6740374c11d4c06f (patch)
treed0ed8ab6fbbdd2528dd5e674d91a59139c79148e /common_audio
parent375eff4f0404b08aeadc36140f7c0415a4247080 (diff)
downloadwebrtc-3fdb3cbc6aeed9d2598f076a6740374c11d4c06f.tar.gz
Remove potential real-time reallocation in PushResampler
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 <peah@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30059}
Diffstat (limited to 'common_audio')
-rw-r--r--common_audio/BUILD.gn1
-rw-r--r--common_audio/resampler/include/push_resampler.h5
-rw-r--r--common_audio/resampler/push_resampler.cc17
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<T*> channel_data_array_;
struct ChannelResampler {
std::unique_ptr<PushSincResampler> 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 <memory>
-#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<T>::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<T>::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<T*, 8> 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<T>::Resample(const T* src,
dst_capacity_mono);
}
- absl::InlinedVector<T*, 8> 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<int>(dst_length_mono * num_channels_);
}