mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
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.
This commit is contained in:
parent
91572a49c4
commit
cbff7c386a
Notes:
sideshowbarker
2024-07-18 09:23:49 +09:00
Author: https://github.com/FalseHonesty Commit: https://github.com/SerenityOS/serenity/commit/cbff7c386a8 Pull-request: https://github.com/SerenityOS/serenity/pull/8349 Reviewed-by: https://github.com/Lubrsi
|
@ -719,20 +719,25 @@ bool Decoder::decode_tiles()
|
|||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void clear_context(T* context, size_t size)
|
||||
void Decoder::clear_context(Vector<u8>& context, size_t size)
|
||||
{
|
||||
if (!(*context))
|
||||
*context = static_cast<T>(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<Vector<u8>>& 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<u8>& context, size_t size);
|
||||
void clear_context(Vector<Vector<u8>>& 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<Vector<u8>> m_above_nonzero_context;
|
||||
Vector<Vector<u8>> m_left_nonzero_context;
|
||||
Vector<u8> m_above_seg_pred_context;
|
||||
Vector<u8> m_left_seg_pred_context;
|
||||
Vector<u8> m_above_partition_context;
|
||||
Vector<u8> m_left_partition_context;
|
||||
u32 m_mi_row_start { 0 };
|
||||
u32 m_mi_row_end { 0 };
|
||||
u32 m_mi_col_start { 0 };
|
||||
|
|
Loading…
Reference in a new issue