From cbff7c386a820a5ab9e12c3228957b91959bc6c6 Mon Sep 17 00:00:00 2001 From: FalseHonesty Date: Sat, 26 Jun 2021 16:28:25 -0400 Subject: LibVideo/VP9: Refactor how above & left contexts are stored & cleared These make more sense as Vectors, and it makes it much easier to manage their sizing. --- Userland/Libraries/LibVideo/VP9/Decoder.cpp | 45 +++++++++++------------------ Userland/Libraries/LibVideo/VP9/Decoder.h | 17 ++++++----- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/Userland/Libraries/LibVideo/VP9/Decoder.cpp b/Userland/Libraries/LibVideo/VP9/Decoder.cpp index 8511dad917..447521ed00 100644 --- a/Userland/Libraries/LibVideo/VP9/Decoder.cpp +++ b/Userland/Libraries/LibVideo/VP9/Decoder.cpp @@ -719,20 +719,25 @@ bool Decoder::decode_tiles() return true; } -template -void clear_context(T* context, size_t size) +void Decoder::clear_context(Vector& context, size_t size) { - if (!(*context)) - *context = static_cast(malloc(size)); - else - __builtin_memset(*context, 0, size); + context.resize_and_keep_capacity(size); + __builtin_memset(context.data(), 0, sizeof(u8) * size); +} + +void Decoder::clear_context(Vector>& context, size_t outer_size, size_t inner_size) +{ + if (context.size() < outer_size) + context.resize(outer_size); + for (auto& sub_vector : context) + clear_context(sub_vector, inner_size); } bool Decoder::clear_above_context() { - clear_context(&m_above_nonzero_context, sizeof(u8) * 3 * m_mi_cols * 2); - clear_context(&m_above_seg_pred_context, sizeof(u8) * m_mi_cols); - clear_context(&m_above_partition_context, sizeof(u8) * m_sb64_cols * 8); + clear_context(m_above_nonzero_context, 2 * m_mi_cols, 3); + clear_context(m_above_seg_pred_context, m_mi_cols); + clear_context(m_above_partition_context, m_sb64_cols * 8); return true; } @@ -758,9 +763,9 @@ bool Decoder::decode_tile() bool Decoder::clear_left_context() { - clear_context(&m_left_nonzero_context, sizeof(u8) * 3 * m_mi_rows * 2); - clear_context(&m_left_seg_pred_context, sizeof(u8) * m_mi_rows); - clear_context(&m_left_partition_context, sizeof(u8) * m_sb64_rows * 8); + clear_context(m_left_nonzero_context, 2 * m_mi_rows, 3); + clear_context(m_left_seg_pred_context, m_mi_rows); + clear_context(m_left_partition_context, m_sb64_rows * 8); return true; } @@ -1125,20 +1130,4 @@ void Decoder::dump_info() dbgln("Interpolation filter: {}", (u8)m_interpolation_filter); } -Decoder::~Decoder() -{ - if (m_above_nonzero_context) - free(m_above_nonzero_context); - if (m_left_nonzero_context) - free(m_left_nonzero_context); - if (m_above_seg_pred_context) - free(m_above_seg_pred_context); - if (m_left_seg_pred_context) - free(m_left_seg_pred_context); - if (m_above_partition_context) - free(m_above_partition_context); - if (m_left_partition_context) - free(m_left_partition_context); -} - } diff --git a/Userland/Libraries/LibVideo/VP9/Decoder.h b/Userland/Libraries/LibVideo/VP9/Decoder.h index fa57eed26b..f10709bd21 100644 --- a/Userland/Libraries/LibVideo/VP9/Decoder.h +++ b/Userland/Libraries/LibVideo/VP9/Decoder.h @@ -21,7 +21,6 @@ class Decoder { public: Decoder(); - ~Decoder(); bool parse_frame(ByteBuffer const&); void dump_info(); @@ -40,6 +39,10 @@ private: return StudioSwing; } + /* Utilities */ + void clear_context(Vector& context, size_t size); + void clear_context(Vector>& context, size_t outer_size, size_t inner_size); + /* (6.2) Uncompressed Header Syntax */ bool uncompressed_header(); bool frame_sync_code(); @@ -158,12 +161,12 @@ private: i8 m_loop_filter_ref_deltas[MAX_REF_FRAMES]; i8 m_loop_filter_mode_deltas[2]; - u8** m_above_nonzero_context { nullptr }; - u8** m_left_nonzero_context { nullptr }; - u8* m_above_seg_pred_context { nullptr }; - u8* m_left_seg_pred_context { nullptr }; - u8* m_above_partition_context { nullptr }; - u8* m_left_partition_context { nullptr }; + Vector> m_above_nonzero_context; + Vector> m_left_nonzero_context; + Vector m_above_seg_pred_context; + Vector m_left_seg_pred_context; + Vector m_above_partition_context; + Vector m_left_partition_context; u32 m_mi_row_start { 0 }; u32 m_mi_row_end { 0 }; u32 m_mi_col_start { 0 }; -- cgit v1.2.3