summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2022-11-23 06:02:40 -0600
committerAndreas Kling <kling@serenityos.org>2022-11-30 08:28:30 +0100
commit0df5c1f32f32ec520648e824cbe5d14a69deec97 (patch)
treec8f50c57a4f13dae92ccf701ba3974893104b6ce
parent90f16c78fa3c03f80802f62c176b1a3d00353374 (diff)
downloadserenity-0df5c1f32f32ec520648e824cbe5d14a69deec97.zip
LibVideo/VP9: Move loop filter parameters to FrameContext
-rw-r--r--Userland/Libraries/LibVideo/VP9/Context.h6
-rw-r--r--Userland/Libraries/LibVideo/VP9/Parser.cpp48
-rw-r--r--Userland/Libraries/LibVideo/VP9/Parser.h9
3 files changed, 34 insertions, 29 deletions
diff --git a/Userland/Libraries/LibVideo/VP9/Context.h b/Userland/Libraries/LibVideo/VP9/Context.h
index 1319a95a00..f0808bd509 100644
--- a/Userland/Libraries/LibVideo/VP9/Context.h
+++ b/Userland/Libraries/LibVideo/VP9/Context.h
@@ -305,6 +305,12 @@ public:
bool high_precision_motion_vectors_allowed { false };
InterpolationFilter interpolation_filter { InterpolationFilter::Switchable };
+ u8 loop_filter_level { 0 };
+ u8 loop_filter_sharpness { 0 };
+ bool loop_filter_delta_enabled { false };
+ Array<i8, MAX_REF_FRAMES> loop_filter_reference_deltas;
+ Array<i8, 2> loop_filter_mode_deltas;
+
u16 header_size_in_bytes { 0 };
private:
diff --git a/Userland/Libraries/LibVideo/VP9/Parser.cpp b/Userland/Libraries/LibVideo/VP9/Parser.cpp
index 4d9fad65d6..b77b6217f7 100644
--- a/Userland/Libraries/LibVideo/VP9/Parser.cpp
+++ b/Userland/Libraries/LibVideo/VP9/Parser.cpp
@@ -107,6 +107,8 @@ DecoderErrorOr<FrameContext> Parser::parse_frame(ReadonlyBytes frame_data)
m_previous_frame_size = frame_context.size();
m_previous_show_frame = frame_context.shows_a_frame();
m_previous_color_config = frame_context.color_config;
+ m_previous_loop_filter_ref_deltas = frame_context.loop_filter_reference_deltas;
+ m_previous_loop_filter_mode_deltas = frame_context.loop_filter_mode_deltas;
return frame_context;
}
@@ -159,7 +161,6 @@ DecoderErrorOr<FrameContext> Parser::uncompressed_header()
return DecoderError::corrupted("uncompressed_header: Profile 3 reserved bit was non-zero"sv);
if (TRY_READ(m_bit_stream->read_bit())) {
- m_loop_filter_level = 0;
frame_context.set_existing_frame_to_show(TRY_READ(m_bit_stream->read_bits(3)));
return frame_context;
}
@@ -259,7 +260,7 @@ DecoderErrorOr<FrameContext> Parser::uncompressed_header()
frame_context.should_replace_probability_context = should_replace_probability_context;
frame_context.probability_context_index = probability_context_index;
- TRY(loop_filter_params());
+ TRY(loop_filter_params(frame_context));
TRY(quantization_params());
TRY(segmentation_params());
TRY(tile_info(frame_context));
@@ -393,23 +394,26 @@ DecoderErrorOr<InterpolationFilter> Parser::read_interpolation_filter()
return literal_to_type[TRY_READ(m_bit_stream->read_bits(2))];
}
-DecoderErrorOr<void> Parser::loop_filter_params()
+DecoderErrorOr<void> Parser::loop_filter_params(FrameContext& frame_context)
{
- m_loop_filter_level = TRY_READ(m_bit_stream->read_bits(6));
- m_loop_filter_sharpness = TRY_READ(m_bit_stream->read_bits(3));
- m_loop_filter_delta_enabled = TRY_READ(m_bit_stream->read_bit());
- if (m_loop_filter_delta_enabled) {
- if (TRY_READ(m_bit_stream->read_bit())) {
- for (auto& loop_filter_ref_delta : m_loop_filter_ref_deltas) {
- if (TRY_READ(m_bit_stream->read_bit()))
- loop_filter_ref_delta = TRY_READ(m_bit_stream->read_s(6));
- }
- for (auto& loop_filter_mode_delta : m_loop_filter_mode_deltas) {
- if (TRY_READ(m_bit_stream->read_bit()))
- loop_filter_mode_delta = TRY_READ(m_bit_stream->read_s(6));
- }
+ frame_context.loop_filter_level = TRY_READ(m_bit_stream->read_bits(6));
+ frame_context.loop_filter_sharpness = TRY_READ(m_bit_stream->read_bits(3));
+ frame_context.loop_filter_delta_enabled = TRY_READ(m_bit_stream->read_bit());
+
+ auto reference_deltas = m_previous_loop_filter_ref_deltas;
+ auto mode_deltas = m_previous_loop_filter_mode_deltas;
+ if (frame_context.loop_filter_delta_enabled && TRY_READ(m_bit_stream->read_bit())) {
+ for (auto& loop_filter_ref_delta : reference_deltas) {
+ if (TRY_READ(m_bit_stream->read_bit()))
+ loop_filter_ref_delta = TRY_READ(m_bit_stream->read_s(6));
+ }
+ for (auto& loop_filter_mode_delta : mode_deltas) {
+ if (TRY_READ(m_bit_stream->read_bit()))
+ loop_filter_mode_delta = TRY_READ(m_bit_stream->read_s(6));
}
}
+ frame_context.loop_filter_reference_deltas = reference_deltas;
+ frame_context.loop_filter_mode_deltas = mode_deltas;
return {};
}
@@ -524,13 +528,11 @@ void Parser::setup_past_independence()
}
m_previous_block_contexts.reset();
m_segmentation_abs_or_delta_update = false;
- m_loop_filter_delta_enabled = true;
- m_loop_filter_ref_deltas[IntraFrame] = 1;
- m_loop_filter_ref_deltas[LastFrame] = 0;
- m_loop_filter_ref_deltas[GoldenFrame] = -1;
- m_loop_filter_ref_deltas[AltRefFrame] = -1;
- for (auto& loop_filter_mode_delta : m_loop_filter_mode_deltas)
- loop_filter_mode_delta = 0;
+ m_previous_loop_filter_ref_deltas[IntraFrame] = 1;
+ m_previous_loop_filter_ref_deltas[LastFrame] = 0;
+ m_previous_loop_filter_ref_deltas[GoldenFrame] = -1;
+ m_previous_loop_filter_ref_deltas[AltRefFrame] = -1;
+ m_previous_loop_filter_mode_deltas.fill(0);
m_probability_tables->reset_probs();
}
diff --git a/Userland/Libraries/LibVideo/VP9/Parser.h b/Userland/Libraries/LibVideo/VP9/Parser.h
index 0898a47641..d5f3d06c25 100644
--- a/Userland/Libraries/LibVideo/VP9/Parser.h
+++ b/Userland/Libraries/LibVideo/VP9/Parser.h
@@ -64,7 +64,7 @@ private:
DecoderErrorOr<Gfx::Size<u32>> parse_render_size(Gfx::Size<u32> frame_size);
DecoderErrorOr<void> compute_image_size(FrameContext&);
DecoderErrorOr<InterpolationFilter> read_interpolation_filter();
- DecoderErrorOr<void> loop_filter_params();
+ DecoderErrorOr<void> loop_filter_params(FrameContext&);
DecoderErrorOr<void> quantization_params();
DecoderErrorOr<i8> read_delta_q();
DecoderErrorOr<void> segmentation_params();
@@ -141,14 +141,13 @@ private:
Gfx::Point<size_t> get_decoded_point_for_plane(FrameContext const&, u32 row, u32 column, u8 plane);
Gfx::Size<size_t> get_decoded_size_for_plane(FrameContext const&, u8 plane);
- u8 m_loop_filter_level { 0 };
- u8 m_loop_filter_sharpness { 0 };
- bool m_loop_filter_delta_enabled { false };
bool m_is_first_compute_image_size_invoke { true };
Gfx::Size<u32> m_previous_frame_size { 0, 0 };
bool m_previous_show_frame { false };
ColorConfig m_previous_color_config;
FrameType m_previous_frame_type { FrameType::KeyFrame };
+ Array<i8, MAX_REF_FRAMES> m_previous_loop_filter_ref_deltas;
+ Array<i8, 2> m_previous_loop_filter_mode_deltas;
u8 m_base_q_idx { 0 };
i8 m_delta_q_y_dc { 0 };
i8 m_delta_q_uv_dc { 0 };
@@ -164,8 +163,6 @@ private:
bool m_segmentation_abs_or_delta_update { false };
u16 m_tile_cols_log2 { 0 };
u16 m_tile_rows_log2 { 0 };
- i8 m_loop_filter_ref_deltas[MAX_REF_FRAMES];
- i8 m_loop_filter_mode_deltas[2];
// FIXME: Move above and left contexts to structs
Array<Vector<bool>, 3> m_above_nonzero_context;