diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/array_2d.h | 2 | ||||
-rw-r--r-- | src/utils/block_parameters_holder.cc | 56 | ||||
-rw-r--r-- | src/utils/block_parameters_holder.h | 37 | ||||
-rw-r--r-- | src/utils/common.h | 5 | ||||
-rw-r--r-- | src/utils/constants.h | 46 | ||||
-rw-r--r-- | src/utils/cpu.cc | 2 | ||||
-rw-r--r-- | src/utils/cpu.h | 2 | ||||
-rw-r--r-- | src/utils/dynamic_buffer.h | 2 | ||||
-rw-r--r-- | src/utils/libgav1_utils.cmake | 2 | ||||
-rw-r--r-- | src/utils/logging.cc | 2 | ||||
-rw-r--r-- | src/utils/logging.h | 20 | ||||
-rw-r--r-- | src/utils/memory.h | 2 | ||||
-rw-r--r-- | src/utils/parameter_tree.cc | 133 | ||||
-rw-r--r-- | src/utils/parameter_tree.h | 113 | ||||
-rw-r--r-- | src/utils/raw_bit_reader.h | 2 | ||||
-rw-r--r-- | src/utils/threadpool.cc | 20 | ||||
-rw-r--r-- | src/utils/types.h | 24 |
17 files changed, 140 insertions, 330 deletions
diff --git a/src/utils/array_2d.h b/src/utils/array_2d.h index 2df6241..df2da9f 100644 --- a/src/utils/array_2d.h +++ b/src/utils/array_2d.h @@ -120,7 +120,7 @@ class Array2D { const T* operator[](int row) const { return data_view_[row]; } private: - std::unique_ptr<T[]> data_ = nullptr; + std::unique_ptr<T[]> data_; size_t allocated_size_ = 0; size_t size_ = 0; Array2DView<T> data_view_; diff --git a/src/utils/block_parameters_holder.cc b/src/utils/block_parameters_holder.cc index 3ccdb9b..3bb9f1e 100644 --- a/src/utils/block_parameters_holder.cc +++ b/src/utils/block_parameters_holder.cc @@ -19,53 +19,29 @@ #include "src/utils/common.h" #include "src/utils/constants.h" #include "src/utils/logging.h" -#include "src/utils/parameter_tree.h" #include "src/utils/types.h" namespace libgav1 { -namespace { - -// Returns the number of super block rows/columns for |value4x4| where value4x4 -// is either rows4x4 or columns4x4. -int RowsOrColumns4x4ToSuperBlocks(int value4x4, bool use_128x128_superblock) { - return use_128x128_superblock ? DivideBy128(MultiplyBy4(value4x4) + 127) - : DivideBy64(MultiplyBy4(value4x4) + 63); -} - -} // namespace - -bool BlockParametersHolder::Reset(int rows4x4, int columns4x4, - bool use_128x128_superblock) { +bool BlockParametersHolder::Reset(int rows4x4, int columns4x4) { rows4x4_ = rows4x4; columns4x4_ = columns4x4; - use_128x128_superblock_ = use_128x128_superblock; - if (!block_parameters_cache_.Reset(rows4x4_, columns4x4_)) { - LIBGAV1_DLOG(ERROR, "block_parameters_cache_.Reset() failed."); - return false; - } - const int rows = - RowsOrColumns4x4ToSuperBlocks(rows4x4_, use_128x128_superblock_); - const int columns = - RowsOrColumns4x4ToSuperBlocks(columns4x4_, use_128x128_superblock_); - const BlockSize sb_size = - use_128x128_superblock_ ? kBlock128x128 : kBlock64x64; - const int multiplier = kNum4x4BlocksWide[sb_size]; - if (!trees_.Reset(rows, columns, /*zero_initialize=*/false)) { - LIBGAV1_DLOG(ERROR, "trees_.Reset() failed."); - return false; - } - for (int i = 0; i < rows; ++i) { - for (int j = 0; j < columns; ++j) { - trees_[i][j] = - ParameterTree::Create(i * multiplier, j * multiplier, sb_size); - if (trees_[i][j] == nullptr) { - LIBGAV1_DLOG(ERROR, "Allocation of trees_[%d][%d] failed.", i, j); - return false; - } - } + index_ = 0; + return block_parameters_cache_.Reset(rows4x4_, columns4x4_) && + block_parameters_.Resize(rows4x4_ * columns4x4_); +} + +BlockParameters* BlockParametersHolder::Get(int row4x4, int column4x4, + BlockSize block_size) { + const size_t index = index_.fetch_add(1, std::memory_order_relaxed); + if (index >= block_parameters_.size()) return nullptr; + auto& bp = block_parameters_.get()[index]; + if (bp == nullptr) { + bp.reset(new (std::nothrow) BlockParameters); + if (bp == nullptr) return nullptr; } - return true; + FillCache(row4x4, column4x4, block_size, bp.get()); + return bp.get(); } void BlockParametersHolder::FillCache(int row4x4, int column4x4, diff --git a/src/utils/block_parameters_holder.h b/src/utils/block_parameters_holder.h index 35543c3..ca36907 100644 --- a/src/utils/block_parameters_holder.h +++ b/src/utils/block_parameters_holder.h @@ -17,18 +17,18 @@ #ifndef LIBGAV1_SRC_UTILS_BLOCK_PARAMETERS_HOLDER_H_ #define LIBGAV1_SRC_UTILS_BLOCK_PARAMETERS_HOLDER_H_ +#include <atomic> #include <memory> #include "src/utils/array_2d.h" #include "src/utils/compiler_attributes.h" #include "src/utils/constants.h" -#include "src/utils/parameter_tree.h" +#include "src/utils/dynamic_buffer.h" #include "src/utils/types.h" namespace libgav1 { -// Holds a 2D array of |ParameterTree| objects. Each tree stores the parameters -// corresponding to a superblock. +// Holds the BlockParameters pointers to each 4x4 block in the frame. class BlockParametersHolder { public: BlockParametersHolder() = default; @@ -37,10 +37,13 @@ class BlockParametersHolder { BlockParametersHolder(const BlockParametersHolder&) = delete; BlockParametersHolder& operator=(const BlockParametersHolder&) = delete; - // If |use_128x128_superblock| is true, 128x128 superblocks will be used, - // otherwise 64x64 superblocks will be used. - LIBGAV1_MUST_USE_RESULT bool Reset(int rows4x4, int columns4x4, - bool use_128x128_superblock); + LIBGAV1_MUST_USE_RESULT bool Reset(int rows4x4, int columns4x4); + + // Returns a pointer to a BlockParameters object that can be used safely until + // the next call to Reset(). Returns nullptr on memory allocation failure. It + // also fills the cache matrix for the block starting at |row4x4|, |column4x4| + // of size |block_size| with the returned pointer. + BlockParameters* Get(int row4x4, int column4x4, BlockSize block_size); // Finds the BlockParameters corresponding to |row4x4| and |column4x4|. This // is done as a simple look up of the |block_parameters_cache_| matrix. @@ -59,20 +62,24 @@ class BlockParametersHolder { int columns4x4() const { return columns4x4_; } - // Returns the ParameterTree corresponding to superblock starting at (|row|, - // |column|). - ParameterTree* Tree(int row, int column) { return trees_[row][column].get(); } + private: + // Needs access to FillCache for testing Cdef. + template <int bitdepth, typename Pixel> + friend class PostFilterApplyCdefTest; - // Fills the cache matrix for the block starting at |row4x4|, |column4x4| of - // size |block_size| with the pointer |bp|. void FillCache(int row4x4, int column4x4, BlockSize block_size, BlockParameters* bp); - private: int rows4x4_ = 0; int columns4x4_ = 0; - bool use_128x128_superblock_ = false; - Array2D<std::unique_ptr<ParameterTree>> trees_; + + // Owns the memory of BlockParameters pointers for the entire frame. It can + // hold upto |rows4x4_| * |columns4x4_| objects. Each object will be allocated + // on demand and re-used across frames. + DynamicBuffer<std::unique_ptr<BlockParameters>> block_parameters_; + + // Points to the next available index of |block_parameters_|. + std::atomic<int> index_; // This is a 2d array of size |rows4x4_| * |columns4x4_|. This is filled in by // FillCache() and used by Find() to perform look ups using exactly one look diff --git a/src/utils/common.h b/src/utils/common.h index ae43c2b..2e599f0 100644 --- a/src/utils/common.h +++ b/src/utils/common.h @@ -30,7 +30,6 @@ #include <cassert> #include <cstddef> #include <cstdint> -#include <cstdlib> #include <cstring> #include <type_traits> @@ -131,7 +130,7 @@ inline int CountLeadingZeros(uint64_t n) { #if defined(HAVE_BITSCANREVERSE64) const unsigned char bit_set = _BitScanReverse64(&first_set_bit, static_cast<unsigned __int64>(n)); -#else // !defined(HAVE_BITSCANREVERSE64) +#else // !defined(HAVE_BITSCANREVERSE64) const auto n_hi = static_cast<unsigned long>(n >> 32); // NOLINT(runtime/int) if (n_hi != 0) { const unsigned char bit_set = _BitScanReverse(&first_set_bit, n_hi); @@ -376,7 +375,7 @@ constexpr bool IsDirectionalMode(PredictionMode mode) { // behavior and result apply to other CPUs' SIMD instructions. inline int GetRelativeDistance(const unsigned int a, const unsigned int b, const unsigned int order_hint_shift_bits) { - const int diff = a - b; + const int diff = static_cast<int>(a) - static_cast<int>(b); assert(order_hint_shift_bits <= 31); if (order_hint_shift_bits == 0) { assert(a == 0); diff --git a/src/utils/constants.h b/src/utils/constants.h index 34cf56d..a2076c5 100644 --- a/src/utils/constants.h +++ b/src/utils/constants.h @@ -629,6 +629,52 @@ inline const char* ToString(const LoopRestorationType type) { abort(); } +inline const char* ToString(const TransformSize size) { + switch (size) { + case kTransformSize4x4: + return "kTransformSize4x4"; + case kTransformSize4x8: + return "kTransformSize4x8"; + case kTransformSize4x16: + return "kTransformSize4x16"; + case kTransformSize8x4: + return "kTransformSize8x4"; + case kTransformSize8x8: + return "kTransformSize8x8"; + case kTransformSize8x16: + return "kTransformSize8x16"; + case kTransformSize8x32: + return "kTransformSize8x32"; + case kTransformSize16x4: + return "kTransformSize16x4"; + case kTransformSize16x8: + return "kTransformSize16x8"; + case kTransformSize16x16: + return "kTransformSize16x16"; + case kTransformSize16x32: + return "kTransformSize16x32"; + case kTransformSize16x64: + return "kTransformSize16x64"; + case kTransformSize32x8: + return "kTransformSize32x8"; + case kTransformSize32x16: + return "kTransformSize32x16"; + case kTransformSize32x32: + return "kTransformSize32x32"; + case kTransformSize32x64: + return "kTransformSize32x64"; + case kTransformSize64x16: + return "kTransformSize64x16"; + case kTransformSize64x32: + return "kTransformSize64x32"; + case kTransformSize64x64: + return "kTransformSize64x64"; + case kNumTransformSizes: + return "kNumTransformSizes"; + } + abort(); +} + inline const char* ToString(const TransformType type) { switch (type) { case kTransformTypeDctDct: diff --git a/src/utils/cpu.cc b/src/utils/cpu.cc index a6b7057..b3c51da 100644 --- a/src/utils/cpu.cc +++ b/src/utils/cpu.cc @@ -39,7 +39,7 @@ uint64_t Xgetbv() { __asm__ volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(ecx)); return (static_cast<uint64_t>(edx) << 32) | eax; } -#else // _MSC_VER +#else // _MSC_VER void CpuId(int leaf, uint32_t info[4]) { __cpuidex(reinterpret_cast<int*>(info), leaf, 0 /*ecx=subleaf*/); } diff --git a/src/utils/cpu.h b/src/utils/cpu.h index 630b251..aefc2df 100644 --- a/src/utils/cpu.h +++ b/src/utils/cpu.h @@ -38,7 +38,7 @@ namespace libgav1 { #if !defined(LIBGAV1_ENABLE_AVX2) #define LIBGAV1_ENABLE_AVX2 1 #endif // !defined(LIBGAV1_ENABLE_AVX2) -#else // !LIBGAV1_ENABLE_SSE4_1 +#else // !LIBGAV1_ENABLE_SSE4_1 // Disable AVX2 when SSE4.1 is disabled as it may rely on shared components. #undef LIBGAV1_ENABLE_AVX2 #define LIBGAV1_ENABLE_AVX2 0 diff --git a/src/utils/dynamic_buffer.h b/src/utils/dynamic_buffer.h index b51345a..40ece26 100644 --- a/src/utils/dynamic_buffer.h +++ b/src/utils/dynamic_buffer.h @@ -46,6 +46,8 @@ class DynamicBuffer { return true; } + size_t size() const { return size_; } + private: std::unique_ptr<T[]> buffer_; size_t size_ = 0; diff --git a/src/utils/libgav1_utils.cmake b/src/utils/libgav1_utils.cmake index 8b6ec4b..587ca5d 100644 --- a/src/utils/libgav1_utils.cmake +++ b/src/utils/libgav1_utils.cmake @@ -39,8 +39,6 @@ list(APPEND libgav1_utils_sources "${libgav1_source}/utils/logging.cc" "${libgav1_source}/utils/logging.h" "${libgav1_source}/utils/memory.h" - "${libgav1_source}/utils/parameter_tree.cc" - "${libgav1_source}/utils/parameter_tree.h" "${libgav1_source}/utils/queue.h" "${libgav1_source}/utils/raw_bit_reader.cc" "${libgav1_source}/utils/raw_bit_reader.h" diff --git a/src/utils/logging.cc b/src/utils/logging.cc index 9a43c22..26e3e15 100644 --- a/src/utils/logging.cc +++ b/src/utils/logging.cc @@ -56,7 +56,7 @@ void Log(LogSeverity severity, const char* file, int line, const char* format, va_end(ap); fprintf(stderr, "\n"); } -#else // !LIBGAV1_ENABLE_LOGGING +#else // !LIBGAV1_ENABLE_LOGGING void Log(LogSeverity /*severity*/, const char* /*file*/, int /*line*/, const char* /*format*/, ...) {} #endif // LIBGAV1_ENABLE_LOGGING diff --git a/src/utils/logging.h b/src/utils/logging.h index 48928db..473aebd 100644 --- a/src/utils/logging.h +++ b/src/utils/logging.h @@ -35,13 +35,13 @@ // setting LIBGAV1_ENABLE_LOGGING. // Severity is given as an all-caps version of enum LogSeverity with the // leading 'k' removed: LIBGAV1_DLOG(INFO, "..."); -#define LIBGAV1_DLOG(severity, ...) \ - do { \ - constexpr const char* libgav1_logging_internal_basename = \ - ::libgav1::internal::Basename(__FILE__, sizeof(__FILE__) - 1); \ - ::libgav1::internal::Log(LIBGAV1_LOGGING_INTERNAL_##severity, \ - libgav1_logging_internal_basename, __LINE__, \ - __VA_ARGS__); \ +#define LIBGAV1_DLOG(severity, ...) \ + do { \ + constexpr const char* libgav1_logging_internal_basename = \ + libgav1::internal::Basename(__FILE__, sizeof(__FILE__) - 1); \ + libgav1::internal::Log(LIBGAV1_LOGGING_INTERNAL_##severity, \ + libgav1_logging_internal_basename, __LINE__, \ + __VA_ARGS__); \ } while (0) #else #define LIBGAV1_DLOG(severity, ...) \ @@ -49,10 +49,10 @@ } while (0) #endif // LIBGAV1_ENABLE_LOGGING -#define LIBGAV1_LOGGING_INTERNAL_ERROR ::libgav1::internal::LogSeverity::kError +#define LIBGAV1_LOGGING_INTERNAL_ERROR libgav1::internal::LogSeverity::kError #define LIBGAV1_LOGGING_INTERNAL_WARNING \ - ::libgav1::internal::LogSeverity::kWarning -#define LIBGAV1_LOGGING_INTERNAL_INFO ::libgav1::internal::LogSeverity::kInfo + libgav1::internal::LogSeverity::kWarning +#define LIBGAV1_LOGGING_INTERNAL_INFO libgav1::internal::LogSeverity::kInfo namespace libgav1 { namespace internal { diff --git a/src/utils/memory.h b/src/utils/memory.h index 219a83f..a8da53b 100644 --- a/src/utils/memory.h +++ b/src/utils/memory.h @@ -71,7 +71,7 @@ inline void* AlignedAlloc(size_t alignment, size_t size) { // more convenient to use memalign(). Unlike glibc, Android does not consider // memalign() an obsolete function. return memalign(alignment, size); -#else // !defined(__ANDROID__) +#else // !defined(__ANDROID__) void* ptr = nullptr; // posix_memalign requires that the requested alignment be at least // sizeof(void*). In this case, fall back on malloc which should return diff --git a/src/utils/parameter_tree.cc b/src/utils/parameter_tree.cc deleted file mode 100644 index 9426ce6..0000000 --- a/src/utils/parameter_tree.cc +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2019 The libgav1 Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/utils/parameter_tree.h" - -#include <cassert> -#include <memory> -#include <new> - -#include "src/utils/common.h" -#include "src/utils/constants.h" -#include "src/utils/logging.h" -#include "src/utils/types.h" - -namespace libgav1 { - -// static -std::unique_ptr<ParameterTree> ParameterTree::Create(int row4x4, int column4x4, - BlockSize block_size, - bool is_leaf) { - std::unique_ptr<ParameterTree> tree( - new (std::nothrow) ParameterTree(row4x4, column4x4, block_size)); - if (tree != nullptr && is_leaf && !tree->SetPartitionType(kPartitionNone)) { - tree = nullptr; - } - return tree; -} - -bool ParameterTree::SetPartitionType(Partition partition) { - assert(!partition_type_set_); - partition_ = partition; - partition_type_set_ = true; - const int block_width4x4 = kNum4x4BlocksWide[block_size_]; - const int half_block4x4 = block_width4x4 >> 1; - const int quarter_block4x4 = half_block4x4 >> 1; - const BlockSize sub_size = kSubSize[partition][block_size_]; - const BlockSize split_size = kSubSize[kPartitionSplit][block_size_]; - assert(partition == kPartitionNone || sub_size != kBlockInvalid); - switch (partition) { - case kPartitionNone: - parameters_.reset(new (std::nothrow) BlockParameters()); - return parameters_ != nullptr; - case kPartitionHorizontal: - children_[0] = ParameterTree::Create(row4x4_, column4x4_, sub_size, true); - children_[1] = ParameterTree::Create(row4x4_ + half_block4x4, column4x4_, - sub_size, true); - return children_[0] != nullptr && children_[1] != nullptr; - case kPartitionVertical: - children_[0] = ParameterTree::Create(row4x4_, column4x4_, sub_size, true); - children_[1] = ParameterTree::Create(row4x4_, column4x4_ + half_block4x4, - sub_size, true); - return children_[0] != nullptr && children_[1] != nullptr; - case kPartitionSplit: - children_[0] = - ParameterTree::Create(row4x4_, column4x4_, sub_size, false); - children_[1] = ParameterTree::Create(row4x4_, column4x4_ + half_block4x4, - sub_size, false); - children_[2] = ParameterTree::Create(row4x4_ + half_block4x4, column4x4_, - sub_size, false); - children_[3] = ParameterTree::Create( - row4x4_ + half_block4x4, column4x4_ + half_block4x4, sub_size, false); - return children_[0] != nullptr && children_[1] != nullptr && - children_[2] != nullptr && children_[3] != nullptr; - case kPartitionHorizontalWithTopSplit: - assert(split_size != kBlockInvalid); - children_[0] = - ParameterTree::Create(row4x4_, column4x4_, split_size, true); - children_[1] = ParameterTree::Create(row4x4_, column4x4_ + half_block4x4, - split_size, true); - children_[2] = ParameterTree::Create(row4x4_ + half_block4x4, column4x4_, - sub_size, true); - return children_[0] != nullptr && children_[1] != nullptr && - children_[2] != nullptr; - case kPartitionHorizontalWithBottomSplit: - assert(split_size != kBlockInvalid); - children_[0] = ParameterTree::Create(row4x4_, column4x4_, sub_size, true); - children_[1] = ParameterTree::Create(row4x4_ + half_block4x4, column4x4_, - split_size, true); - children_[2] = - ParameterTree::Create(row4x4_ + half_block4x4, - column4x4_ + half_block4x4, split_size, true); - return children_[0] != nullptr && children_[1] != nullptr && - children_[2] != nullptr; - case kPartitionVerticalWithLeftSplit: - assert(split_size != kBlockInvalid); - children_[0] = - ParameterTree::Create(row4x4_, column4x4_, split_size, true); - children_[1] = ParameterTree::Create(row4x4_ + half_block4x4, column4x4_, - split_size, true); - children_[2] = ParameterTree::Create(row4x4_, column4x4_ + half_block4x4, - sub_size, true); - return children_[0] != nullptr && children_[1] != nullptr && - children_[2] != nullptr; - case kPartitionVerticalWithRightSplit: - assert(split_size != kBlockInvalid); - children_[0] = ParameterTree::Create(row4x4_, column4x4_, sub_size, true); - children_[1] = ParameterTree::Create(row4x4_, column4x4_ + half_block4x4, - split_size, true); - children_[2] = - ParameterTree::Create(row4x4_ + half_block4x4, - column4x4_ + half_block4x4, split_size, true); - return children_[0] != nullptr && children_[1] != nullptr && - children_[2] != nullptr; - case kPartitionHorizontal4: - for (int i = 0; i < 4; ++i) { - children_[i] = ParameterTree::Create(row4x4_ + i * quarter_block4x4, - column4x4_, sub_size, true); - if (children_[i] == nullptr) return false; - } - return true; - default: - assert(partition == kPartitionVertical4); - for (int i = 0; i < 4; ++i) { - children_[i] = ParameterTree::Create( - row4x4_, column4x4_ + i * quarter_block4x4, sub_size, true); - if (children_[i] == nullptr) return false; - } - return true; - } -} - -} // namespace libgav1 diff --git a/src/utils/parameter_tree.h b/src/utils/parameter_tree.h deleted file mode 100644 index 935f3eb..0000000 --- a/src/utils/parameter_tree.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2019 The libgav1 Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LIBGAV1_SRC_UTILS_PARAMETER_TREE_H_ -#define LIBGAV1_SRC_UTILS_PARAMETER_TREE_H_ - -#include <cassert> -#include <memory> - -#include "src/utils/common.h" -#include "src/utils/compiler_attributes.h" -#include "src/utils/constants.h" -#include "src/utils/memory.h" -#include "src/utils/types.h" - -namespace libgav1 { - -class ParameterTree : public Allocable { - public: - // Creates a parameter tree to store the parameters of a block of size - // |block_size| starting at coordinates |row4x4| and |column4x4|. If |is_leaf| - // is set to true, the memory will be allocated for the BlockParameters for - // this node. Otherwise, no memory will be allocated. If |is_leaf| is set to - // false, |block_size| must be a square block, i.e., - // kBlockWidthPixels[block_size] must be equal to - // kBlockHeightPixels[block_size]. - static std::unique_ptr<ParameterTree> Create(int row4x4, int column4x4, - BlockSize block_size, - bool is_leaf = false); - - // Move only (not Copyable). - ParameterTree(ParameterTree&& other) = default; - ParameterTree& operator=(ParameterTree&& other) = default; - ParameterTree(const ParameterTree&) = delete; - ParameterTree& operator=(const ParameterTree&) = delete; - - // Set the partition type of the current node to |partition|. - // if (partition == kPartitionNone) { - // Memory will be allocated for the BlockParameters for this node. - // } else if (partition != kPartitionSplit) { - // The appropriate child nodes will be populated and memory will be - // allocated for the BlockParameters of the children. - // } else { - // The appropriate child nodes will be populated but they are considered to - // be hanging, i.e., future calls to SetPartitionType() on the child nodes - // will have to set them or their descendants to a terminal type. - // } - // This function must be called only once per node. - LIBGAV1_MUST_USE_RESULT bool SetPartitionType(Partition partition); - - // Basic getters. - int row4x4() const { return row4x4_; } - int column4x4() const { return column4x4_; } - BlockSize block_size() const { return block_size_; } - Partition partition() const { return partition_; } - ParameterTree* children(int index) const { - assert(index < 4); - return children_[index].get(); - } - // Returns the BlockParameters object of the current node if one exists. - // Otherwise returns nullptr. This function will return a valid - // BlockParameters object only for leaf nodes. - BlockParameters* parameters() const { return parameters_.get(); } - - private: - ParameterTree(int row4x4, int column4x4, BlockSize block_size) - : row4x4_(row4x4), column4x4_(column4x4), block_size_(block_size) {} - - Partition partition_ = kPartitionNone; - std::unique_ptr<BlockParameters> parameters_ = nullptr; - int row4x4_ = -1; - int column4x4_ = -1; - BlockSize block_size_ = kBlockInvalid; - bool partition_type_set_ = false; - - // Child values are defined as follows for various partition types: - // * Horizontal: 0 top partition; 1 bottom partition; 2 nullptr; 3 nullptr; - // * Vertical: 0 left partition; 1 right partition; 2 nullptr; 3 nullptr; - // * Split: 0 top-left partition; 1 top-right partition; 2; bottom-left - // partition; 3 bottom-right partition; - // * HorizontalWithTopSplit: 0 top-left partition; 1 top-right partition; 2 - // bottom partition; 3 nullptr; - // * HorizontalWithBottomSplit: 0 top partition; 1 bottom-left partition; 2 - // bottom-right partition; 3 nullptr; - // * VerticalWithLeftSplit: 0 top-left partition; 1 bottom-left partition; 2 - // right partition; 3 nullptr; - // * VerticalWithRightSplit: 0 left-partition; 1 top-right partition; 2 - // bottom-right partition; 3 nullptr; - // * Horizontal4: 0 top partition; 1 second top partition; 2 third top - // partition; 3 bottom partition; - // * Vertical4: 0 left partition; 1 second left partition; 2 third left - // partition; 3 right partition; - std::unique_ptr<ParameterTree> children_[4] = {}; - - friend class ParameterTreeTest; -}; - -} // namespace libgav1 - -#endif // LIBGAV1_SRC_UTILS_PARAMETER_TREE_H_ diff --git a/src/utils/raw_bit_reader.h b/src/utils/raw_bit_reader.h index 76e7bfa..7d8ce8f 100644 --- a/src/utils/raw_bit_reader.h +++ b/src/utils/raw_bit_reader.h @@ -38,7 +38,7 @@ class RawBitReader : public BitReader, public Allocable { size_t* value); // le(n) in the spec. bool ReadUnsignedLeb128(size_t* value); // leb128() in the spec. // Reads a variable length unsigned number and stores it in |*value|. On a - // successful return, |*value| is in the range of 0 to UINT32_MAX − 1, + // successful return, |*value| is in the range of 0 to UINT32_MAX - 1, // inclusive. bool ReadUvlc(uint32_t* value); // uvlc() in the spec. bool Finished() const; diff --git a/src/utils/threadpool.cc b/src/utils/threadpool.cc index 8c8f4fe..a3099e1 100644 --- a/src/utils/threadpool.cc +++ b/src/utils/threadpool.cc @@ -37,17 +37,21 @@ #include <chrono> // NOLINT (unapproved c++11 header) #endif +// Define the GetTid() function, a wrapper for the gettid() system call in +// Linux. +#if defined(__ANDROID__) +static pid_t GetTid() { return gettid(); } +#elif defined(__GLIBC__) // The glibc wrapper for the gettid() system call was added in glibc 2.30. // Emulate it for older versions of glibc. -#if defined(__GLIBC_PREREQ) -#if !__GLIBC_PREREQ(2, 30) - +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30) +static pid_t GetTid() { return gettid(); } +#else // Older than glibc 2.30 #include <sys/syscall.h> -static pid_t gettid() { return static_cast<pid_t>(syscall(SYS_gettid)); } - -#endif -#endif // defined(__GLIBC_PREREQ) +static pid_t GetTid() { return static_cast<pid_t>(syscall(SYS_gettid)); } +#endif // glibc 2.30 or later. +#endif // defined(__GLIBC__) namespace libgav1 { @@ -216,7 +220,7 @@ void ThreadPool::WorkerThread::SetupName() { // If the |name| buffer is longer than 16 bytes, pthread_setname_np fails // with error 34 (ERANGE) on Android. char name[16]; - pid_t id = gettid(); + pid_t id = GetTid(); int rv = snprintf(name, sizeof(name), "%s/%" PRId64, pool_->name_prefix_, static_cast<int64_t>(id)); assert(rv >= 0); diff --git a/src/utils/types.h b/src/utils/types.h index 374f06b..eba13b7 100644 --- a/src/utils/types.h +++ b/src/utils/types.h @@ -18,6 +18,7 @@ #define LIBGAV1_SRC_UTILS_TYPES_H_ #include <array> +#include <cstddef> #include <cstdint> #include <memory> @@ -512,6 +513,10 @@ struct ObuFrameHeader { Delta delta_lf; // A valid value of reference_frame_index[i] is in the range [0, 7]. -1 // indicates an invalid value. + // + // NOTE: When the frame is an intra frame (frame_type is kFrameKey or + // kFrameIntraOnly), reference_frame_index is not used and may be + // uninitialized. int8_t reference_frame_index[kNumInterReferenceFrameTypes]; // The ref_order_hint[ i ] syntax element in the uncompressed header. // Specifies the expected output order hint for each reference frame. @@ -521,5 +526,24 @@ struct ObuFrameHeader { FilmGrainParams film_grain_params; }; +// Structure used for traversing the partition tree. +struct PartitionTreeNode { + PartitionTreeNode() = default; + PartitionTreeNode(int row4x4, int column4x4, BlockSize block_size) + : row4x4(row4x4), column4x4(column4x4), block_size(block_size) {} + int row4x4 = -1; + int column4x4 = -1; + BlockSize block_size = kBlockInvalid; +}; + +// Structure used for storing the transform parameters in a superblock. +struct TransformParameters { + TransformParameters() = default; + TransformParameters(TransformType type, int non_zero_coeff_count) + : type(type), non_zero_coeff_count(non_zero_coeff_count) {} + TransformType type; + int non_zero_coeff_count; +}; + } // namespace libgav1 #endif // LIBGAV1_SRC_UTILS_TYPES_H_ |