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}
This commit is contained in:
@ -58,7 +58,6 @@ rtc_library("common_audio") {
|
|||||||
"../system_wrappers",
|
"../system_wrappers",
|
||||||
"../system_wrappers:cpu_features_api",
|
"../system_wrappers:cpu_features_api",
|
||||||
"third_party/fft4g",
|
"third_party/fft4g",
|
||||||
"//third_party/abseil-cpp/absl/container:inlined_vector",
|
|
||||||
"//third_party/abseil-cpp/absl/types:optional",
|
"//third_party/abseil-cpp/absl/types:optional",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -40,6 +40,11 @@ class PushResampler {
|
|||||||
int src_sample_rate_hz_;
|
int src_sample_rate_hz_;
|
||||||
int dst_sample_rate_hz_;
|
int dst_sample_rate_hz_;
|
||||||
size_t num_channels_;
|
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 {
|
struct ChannelResampler {
|
||||||
std::unique_ptr<PushSincResampler> resampler;
|
std::unique_ptr<PushSincResampler> resampler;
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "absl/container/inlined_vector.h"
|
|
||||||
#include "common_audio/include/audio_util.h"
|
#include "common_audio/include/audio_util.h"
|
||||||
#include "common_audio/resampler/push_sinc_resampler.h"
|
#include "common_audio/resampler/push_sinc_resampler.h"
|
||||||
#include "rtc_base/checks.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_resampler->destination.resize(dst_size_10ms_mono);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channel_data_array_.resize(num_channels_);
|
||||||
|
|
||||||
return 0;
|
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 src_length_mono = src_length / num_channels_;
|
||||||
const size_t dst_capacity_mono = dst_capacity / num_channels_;
|
const size_t dst_capacity_mono = dst_capacity / num_channels_;
|
||||||
|
|
||||||
absl::InlinedVector<T*, 8> source_pointers;
|
for (size_t ch = 0; ch < num_channels_; ++ch) {
|
||||||
for (auto& resampler : channel_resamplers_) {
|
channel_data_array_[ch] = channel_resamplers_[ch].source.data();
|
||||||
source_pointers.push_back(resampler.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;
|
size_t dst_length_mono = 0;
|
||||||
|
|
||||||
@ -136,12 +136,11 @@ int PushResampler<T>::Resample(const T* src,
|
|||||||
dst_capacity_mono);
|
dst_capacity_mono);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::InlinedVector<T*, 8> destination_pointers;
|
for (size_t ch = 0; ch < num_channels_; ++ch) {
|
||||||
for (auto& resampler : channel_resamplers_) {
|
channel_data_array_[ch] = channel_resamplers_[ch].destination.data();
|
||||||
destination_pointers.push_back(resampler.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_);
|
return static_cast<int>(dst_length_mono * num_channels_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user