From dbf5416a80df0713d2d08efacc54c286d3ff42f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Tue, 18 Feb 2020 15:00:35 +0100 Subject: [PATCH] Delete header file rtc_base/memory/aligned_array.h Move definition of AlignedArray to the only code using it, the test-only LappedTransform class, and delete unused methods. Bug: webrtc:6424, webrtc:9577 Change-Id: I1bb5f57400f7217345b7ec7376235ad4c4bae858 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168701 Reviewed-by: Karl Wiberg Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#30576} --- common_audio/BUILD.gn | 1 - .../audio_coding/codecs/opus/test/BUILD.gn | 2 +- .../codecs/opus/test/lapped_transform.h | 45 ++++++++++- rtc_base/memory/BUILD.gn | 10 --- rtc_base/memory/aligned_array.h | 80 ------------------- rtc_base/memory/aligned_array_unittest.cc | 60 -------------- 6 files changed, 45 insertions(+), 153 deletions(-) delete mode 100644 rtc_base/memory/aligned_array.h delete mode 100644 rtc_base/memory/aligned_array_unittest.cc diff --git a/common_audio/BUILD.gn b/common_audio/BUILD.gn index 8fc46898fb..48bd9068fe 100644 --- a/common_audio/BUILD.gn +++ b/common_audio/BUILD.gn @@ -51,7 +51,6 @@ rtc_library("common_audio") { "../rtc_base:gtest_prod", "../rtc_base:rtc_base_approved", "../rtc_base:sanitizer", - "../rtc_base/memory:aligned_array", "../rtc_base/memory:aligned_malloc", "../rtc_base/system:arch", "../rtc_base/system:file_wrapper", diff --git a/modules/audio_coding/codecs/opus/test/BUILD.gn b/modules/audio_coding/codecs/opus/test/BUILD.gn index ca9c4c4d4f..32eb6ad195 100644 --- a/modules/audio_coding/codecs/opus/test/BUILD.gn +++ b/modules/audio_coding/codecs/opus/test/BUILD.gn @@ -30,7 +30,7 @@ if (rtc_include_tests) { "../../../../../common_audio", "../../../../../common_audio:common_audio_c", "../../../../../rtc_base:checks", - "../../../../../rtc_base/memory:aligned_array", + "../../../../../rtc_base/memory:aligned_malloc", ] } diff --git a/modules/audio_coding/codecs/opus/test/lapped_transform.h b/modules/audio_coding/codecs/opus/test/lapped_transform.h index e42d9e3500..3620df3831 100644 --- a/modules/audio_coding/codecs/opus/test/lapped_transform.h +++ b/modules/audio_coding/codecs/opus/test/lapped_transform.h @@ -16,10 +16,53 @@ #include "common_audio/real_fourier.h" #include "modules/audio_coding/codecs/opus/test/blocker.h" -#include "rtc_base/memory/aligned_array.h" +#include "rtc_base/memory/aligned_malloc.h" namespace webrtc { +// Wrapper class for aligned arrays. Every row (and the first dimension) are +// aligned to the given byte alignment. +template +class AlignedArray { + public: + AlignedArray(size_t rows, size_t cols, size_t alignment) + : rows_(rows), cols_(cols) { + RTC_CHECK_GT(alignment, 0); + head_row_ = + static_cast(AlignedMalloc(rows_ * sizeof(*head_row_), alignment)); + for (size_t i = 0; i < rows_; ++i) { + head_row_[i] = static_cast( + AlignedMalloc(cols_ * sizeof(**head_row_), alignment)); + } + } + + ~AlignedArray() { + for (size_t i = 0; i < rows_; ++i) { + AlignedFree(head_row_[i]); + } + AlignedFree(head_row_); + } + + T* const* Array() { return head_row_; } + + const T* const* Array() const { return head_row_; } + + T* Row(size_t row) { + RTC_CHECK_LE(row, rows_); + return head_row_[row]; + } + + const T* Row(size_t row) const { + RTC_CHECK_LE(row, rows_); + return head_row_[row]; + } + + private: + size_t rows_; + size_t cols_; + T** head_row_; +}; + // Helper class for audio processing modules which operate on frequency domain // input derived from the windowed time domain audio stream. // diff --git a/rtc_base/memory/BUILD.gn b/rtc_base/memory/BUILD.gn index 0dcd88f958..aa905c6f70 100644 --- a/rtc_base/memory/BUILD.gn +++ b/rtc_base/memory/BUILD.gn @@ -12,14 +12,6 @@ if (is_android) { import("//build/config/android/rules.gni") } -rtc_source_set("aligned_array") { - sources = [ "aligned_array.h" ] - deps = [ - ":aligned_malloc", - "..:checks", - ] -} - rtc_library("aligned_malloc") { sources = [ "aligned_malloc.cc", @@ -45,12 +37,10 @@ rtc_library("fifo_buffer") { rtc_library("unittests") { testonly = true sources = [ - "aligned_array_unittest.cc", "aligned_malloc_unittest.cc", "fifo_buffer_unittest.cc", ] deps = [ - ":aligned_array", ":aligned_malloc", ":fifo_buffer", "../../test:test_support", diff --git a/rtc_base/memory/aligned_array.h b/rtc_base/memory/aligned_array.h deleted file mode 100644 index c67d87d404..0000000000 --- a/rtc_base/memory/aligned_array.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2014 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. - */ - -#ifndef RTC_BASE_MEMORY_ALIGNED_ARRAY_H_ -#define RTC_BASE_MEMORY_ALIGNED_ARRAY_H_ - -#include - -#include "rtc_base/checks.h" -#include "rtc_base/memory/aligned_malloc.h" - -namespace webrtc { - -// Wrapper class for aligned arrays. Every row (and the first dimension) are -// aligned to the given byte alignment. -template -class AlignedArray { - public: - AlignedArray(size_t rows, size_t cols, size_t alignment) - : rows_(rows), cols_(cols) { - RTC_CHECK_GT(alignment, 0); - head_row_ = - static_cast(AlignedMalloc(rows_ * sizeof(*head_row_), alignment)); - for (size_t i = 0; i < rows_; ++i) { - head_row_[i] = static_cast( - AlignedMalloc(cols_ * sizeof(**head_row_), alignment)); - } - } - - ~AlignedArray() { - for (size_t i = 0; i < rows_; ++i) { - AlignedFree(head_row_[i]); - } - AlignedFree(head_row_); - } - - T* const* Array() { return head_row_; } - - const T* const* Array() const { return head_row_; } - - T* Row(size_t row) { - RTC_CHECK_LE(row, rows_); - return head_row_[row]; - } - - const T* Row(size_t row) const { - RTC_CHECK_LE(row, rows_); - return head_row_[row]; - } - - T& At(size_t row, size_t col) { - RTC_CHECK_LE(col, cols_); - return Row(row)[col]; - } - - const T& At(size_t row, size_t col) const { - RTC_CHECK_LE(col, cols_); - return Row(row)[col]; - } - - size_t rows() const { return rows_; } - - size_t cols() const { return cols_; } - - private: - size_t rows_; - size_t cols_; - T** head_row_; -}; - -} // namespace webrtc - -#endif // RTC_BASE_MEMORY_ALIGNED_ARRAY_H_ diff --git a/rtc_base/memory/aligned_array_unittest.cc b/rtc_base/memory/aligned_array_unittest.cc deleted file mode 100644 index 81fd468a92..0000000000 --- a/rtc_base/memory/aligned_array_unittest.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2014 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. - */ - -#include "rtc_base/memory/aligned_array.h" - -#include - -#include "test/gtest.h" - -namespace { - -bool IsAligned(const void* ptr, size_t alignment) { - return reinterpret_cast(ptr) % alignment == 0; -} - -} // namespace - -namespace webrtc { - -TEST(AlignedArrayTest, CheckAlignment) { - AlignedArray arr(10, 7, 128); - ASSERT_TRUE(IsAligned(arr.Array(), 128)); - for (size_t i = 0; i < 10; ++i) { - ASSERT_TRUE(IsAligned(arr.Row(i), 128)); - ASSERT_EQ(arr.Row(i), arr.Array()[i]); - } -} - -TEST(AlignedArrayTest, CheckOverlap) { - AlignedArray arr(10, 7, 128); - - for (size_t i = 0; i < 10; ++i) { - for (size_t j = 0; j < 7; ++j) { - arr.At(i, j) = 20 * i + j; - } - } - - for (size_t i = 0; i < 10; ++i) { - for (size_t j = 0; j < 7; ++j) { - ASSERT_EQ(arr.At(i, j), 20 * i + j); - ASSERT_EQ(arr.Row(i)[j], 20 * i + j); - ASSERT_EQ(arr.Array()[i][j], 20 * i + j); - } - } -} - -TEST(AlignedArrayTest, CheckRowsCols) { - AlignedArray arr(10, 7, 128); - ASSERT_EQ(arr.rows(), 10u); - ASSERT_EQ(arr.cols(), 7u); -} - -} // namespace webrtc