From 396972bb695d14ac76a6fdd007c4578fc2d3a5cd Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Thu, 24 Nov 2022 21:53:24 -0600 Subject: [PATCH] LibVideo/VP9: Retain adjacent block contexts storage between frames Re-allocating the storage is unnecessary, since the size will rarely change during playback. --- Userland/Libraries/LibVideo/VP9/Context.h | 7 ++++++- Userland/Libraries/LibVideo/VP9/Parser.cpp | 5 ++++- Userland/Libraries/LibVideo/VP9/Parser.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibVideo/VP9/Context.h b/Userland/Libraries/LibVideo/VP9/Context.h index 69e6f06080..9e8d10a2af 100644 --- a/Userland/Libraries/LibVideo/VP9/Context.h +++ b/Userland/Libraries/LibVideo/VP9/Context.h @@ -253,6 +253,11 @@ struct ColorConfig { struct FrameContext { public: + FrameContext(Vector2D& contexts) + : m_block_contexts(contexts) + { + } + u8 profile { 0 }; FrameType type { FrameType::KeyFrame }; @@ -338,7 +343,7 @@ private: // arrays instead. // I think should also apply to other fields that are only accessed relative to the current block. Worth looking // into how much of this context needs to be stored for the whole frame vs a row or column from the current tile. - Vector2D m_block_contexts; + Vector2D& m_block_contexts; }; struct TileContext { diff --git a/Userland/Libraries/LibVideo/VP9/Parser.cpp b/Userland/Libraries/LibVideo/VP9/Parser.cpp index fc735d1f55..34f5950a9f 100644 --- a/Userland/Libraries/LibVideo/VP9/Parser.cpp +++ b/Userland/Libraries/LibVideo/VP9/Parser.cpp @@ -147,7 +147,10 @@ DecoderErrorOr Parser::read_color_range() /* (6.2) */ DecoderErrorOr Parser::uncompressed_header() { - FrameContext frame_context; + // NOTE: m_reusable_frame_block_contexts does not need to retain any data between frame decodes. + // This is only stored so that we don't need to allocate a frame's block contexts on each + // call to this function, since it will rarely change sizes. + FrameContext frame_context { m_reusable_frame_block_contexts }; frame_context.color_config = m_previous_color_config; auto frame_marker = TRY_READ(m_bit_stream->read_bits(2)); diff --git a/Userland/Libraries/LibVideo/VP9/Parser.h b/Userland/Libraries/LibVideo/VP9/Parser.h index 9a2c513383..b572508530 100644 --- a/Userland/Libraries/LibVideo/VP9/Parser.h +++ b/Userland/Libraries/LibVideo/VP9/Parser.h @@ -175,6 +175,7 @@ private: ReferenceFramePair m_comp_var_ref; bool m_use_prev_frame_mvs; + Vector2D m_reusable_frame_block_contexts; Vector2D m_previous_block_contexts; // Indexed by ReferenceFrame enum. u8 m_mode_context[4] { INVALID_CASE };