1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:47:34 +00:00

LibVideo/VP9: Convert the Parser to use AK/BitStream.h

This doesn't appear to have had a measurable impact on performance,
and behavior is the same.

With the tiles using independent BooleanDecoders with their own
backing BitStreams, we're even one step closer to threaded tiles!
This commit is contained in:
Zaggy1024 2023-02-11 19:35:26 -06:00 committed by Linus Groh
parent 6f39c44160
commit fb0c226da3
10 changed files with 499 additions and 581 deletions

View file

@ -8,11 +8,14 @@
#pragma once
#include <AK/Array.h>
#include <AK/BitStream.h>
#include <AK/Error.h>
#include <AK/FixedArray.h>
#include <AK/MemoryStream.h>
#include <LibGfx/Size.h>
#include <LibVideo/Color/CodingIndependentCodePoints.h>
#include "BooleanDecoder.h"
#include "ContextStorage.h"
#include "Enums.h"
#include "LookupTables.h"
@ -29,11 +32,20 @@ enum class FrameShowMode {
struct FrameContext {
public:
FrameContext(Vector2D<FrameBlockContext>& contexts)
: m_block_contexts(contexts)
FrameContext(ReadonlyBytes data,
Vector2D<FrameBlockContext>& contexts)
: stream(data)
, bit_stream(MaybeOwned<Stream>(stream))
, m_block_contexts(contexts)
{
}
FrameContext(FrameContext const&) = delete;
FrameContext(FrameContext&&) = default;
FixedMemoryStream stream;
BigEndianInputBitStream bit_stream;
u8 profile { 0 };
FrameType type { FrameType::KeyFrame };
@ -175,14 +187,18 @@ static NonZeroTokensView create_non_zero_tokens_view(NonZeroTokens& non_zero_tok
struct TileContext {
public:
static ErrorOr<TileContext> try_create(FrameContext& frame_context, u32 rows_start, u32 rows_end, u32 columns_start, u32 columns_end, PartitionContextView above_partition_context, NonZeroTokensView above_non_zero_tokens, SegmentationPredictionContextView above_segmentation_ids)
static ErrorOr<TileContext> try_create(FrameContext& frame_context, u32 tile_size, u32 rows_start, u32 rows_end, u32 columns_start, u32 columns_end, PartitionContextView above_partition_context, NonZeroTokensView above_non_zero_tokens, SegmentationPredictionContextView above_segmentation_ids)
{
auto width = columns_end - columns_start;
auto height = rows_end - rows_start;
auto context_view = frame_context.m_block_contexts.view(rows_start, columns_start, height, width);
auto bit_stream = TRY(try_make<BigEndianInputBitStream>(TRY(try_make<FixedMemoryStream>(frame_context.stream))));
auto decoder = TRY(BooleanDecoder::initialize(move(bit_stream), tile_size));
return TileContext {
frame_context,
move(decoder),
rows_start,
rows_end,
columns_start,
@ -200,6 +216,7 @@ public:
Vector2D<FrameBlockContext> const& frame_block_contexts() const { return frame_context.block_contexts(); }
FrameContext const& frame_context;
BooleanDecoder decoder;
u32 rows_start { 0 };
u32 rows_end { 0 };
u32 columns_start { 0 };
@ -231,6 +248,7 @@ struct BlockContext {
return BlockContext {
.frame_context = tile_context.frame_context,
.tile_context = tile_context,
.decoder = tile_context.decoder,
.row = row,
.column = column,
.size = size,
@ -246,6 +264,7 @@ struct BlockContext {
FrameContext const& frame_context;
TileContext const& tile_context;
BooleanDecoder& decoder;
u32 row { 0 };
u32 column { 0 };
BlockSubsize size;