1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 18:45:08 +00:00
Commit graph

45 commits

Author SHA1 Message Date
Zaggy1024
fb0c226da3 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!
2023-02-13 00:22:23 +00:00
Zaggy1024
42606c87e3 LibVideo/VP9: Move TreeSelection class to TreeParser.cpp
The class no longer needs to be defined in the header, as it is only
used in static functions.
2023-01-24 14:55:51 +00:00
Zaggy1024
71aac25635 LibVideo/VP9: Move partitioning contexts to TileContext
Like the non-zero tokens and segmentation IDs, these can be moved into
the tile decoding loop for above context and allocated by TileContext
for left context.
2022-11-30 08:28:30 +01:00
Zaggy1024
2f043a0bd4 LibVideo/VP9: Move the above non-zero tokens context into decode_tiles
We can store this context in the stack of Parser::decode_tiles and use
spans to give access to the sections of the context for each tile and
subsequently each block.
2022-11-30 08:28:30 +01:00
Zaggy1024
4e7e9d8479 LibVideo/VP9: Move the left non-zero tokens context to TileContext
The array containing the vertical line of bools indicating whether non-
zero tokens were decoded in each sub-block is moved to TileContext, and
a span of the valid range for a block to read and write to is created
when we construct a BlockContext.
2022-11-30 08:28:30 +01:00
Zaggy1024
06082d310f LibVideo/VP9: Split/clean up the token tree-parsing context function
Since the context information for parsing residual tokens changes based
on whether we're parsing the first coefficient or subsequent ones, the
TreeParser::get_tokens_context function was split into two new ones to
allow them to read more cleanly. All variables now have meaningful
names to aid in readability as well.

The math used in the function for the first token was changed to
be more friendly to tile- or block-specific coordinates to facilitate
range-restricted Spans of the above and left context arrays.
2022-11-30 08:28:30 +01:00
Zaggy1024
316dad7bf7 LibVideo/VP9: Remove m_tokens and m_token_cache from Parser
Only the residual tokens array needs to be kept for the transforms to
use after all the tokens have been parsed. The token cache is able to
be kept in the stack only for the duration of the token parsing loop.
2022-11-30 08:28:30 +01:00
Zaggy1024
f6e645a153 LibVideo/VP9: Rename TX(Mode|Size) to Transform(Mode|Size) 2022-11-30 08:28:30 +01:00
Zaggy1024
f4af6714d2 LibVideo/VP9: Move persistent context storage to a different header
Moving these to another header allows Parser.h to include less context
structs/classes that were previously in Context.h.

This change will also allow consolidating some common calculations into
Context.h, since we won't be polluting the VP9 namespace as much. There
are quite a few duplicate calculations for block size, transform size,
number of horizontal and vertical sub-blocks per block, all of which
could be moved to Context.h to allow for code deduplication and more
semantic code where those calculations are needed.
2022-11-30 08:28:30 +01:00
Zaggy1024
facb779b99 LibVideo/VP9: Replace (DCT|ADST)_(DCT_ADST) with struct TransformSet
Those previous constants were only set and used to select the first and
second transforms done by the Decoder class. By turning it into a
struct, we can make the code a bit more legible while keeping those
transform modes the same size as before or smaller.
2022-11-30 08:28:30 +01:00
Zaggy1024
062da60443 LibVideo/VP9: Convert token scan order indices to u16
They are directly taken from lookup tables that only need that bit
precision, so may as well shrink them.
2022-11-30 08:28:30 +01:00
Zaggy1024
fedbc12c4d LibVideo/VP9: Move segmentation parameters to FrameContext
Note that some of the previous segmentation feature settings must be
preserved when a frame is decoded that doesn't use segmentation.

This change also allowed a few functions in Decoder to be made static.
2022-11-30 08:28:30 +01:00
Zaggy1024
f4761dab09 LibVideo/VP9: Index inter-frame references with named fields or an enum
Previously, we were using size_t, often coerced from bool or u8, to
index reference pairs. Now, they must either be taken directly from
named fields or indexed using the `ReferenceIndex` enum with options
`primary` and `secondary`. With a more explicit method of indexing
these, the compiler can aid in using reference pairs correctly, and
fuzzers may be able to detect undefined behavior more easily.
2022-11-30 08:28:30 +01:00
Zaggy1024
44413c31a9 LibVideo/VP9: Store data used between decode_block calls in a struct
All state that needed to persist between calls to decode_block was
previously stored in plain Vector fields. This moves them into a struct
which sets a more explicit lifetime on that data. It may be possible to
store this data on the stack of a function with the appropriate
lifetime now that it is split into its own struct.
2022-11-30 08:28:30 +01:00
Zaggy1024
e379223633 LibVideo/VP9: Don't store the default_intra_mode in a field
The default intra prediction mode was only used to set the sub-block
modes and the y prediction mode. Instead of storing it in a field, with
the sub modes are stored in an Array, we can just pull the last element
to set the y mode.
2022-11-30 08:28:30 +01:00
Zaggy1024
907816e629 LibVideo: Create TokensContext struct for token parsing parameters
With the addition of this struct, both the bool to determine if coefs
should be parsed and the token parse itself can take specific
parameters.

This is the last step in parameterizing all the tree parsing, so the
old functions in TreeParser are now unused. This patch is very
satisfying :^)

There's still more work to be done to clean up how the parameters are
passed from Parser, but that's work for another day.
2022-11-12 10:17:27 -07:00
Zaggy1024
e906bcc696 LibVideo: Parameterize all tree parsing for motion vectors in VP9 2022-11-12 10:17:27 -07:00
Zaggy1024
84f1aed40a LibVideo: Parameterize parsing single reference frame selection in VP9 2022-11-12 10:17:27 -07:00
Zaggy1024
37fab851f1 LibVideo: Parameterize parsing compound references in the VP9 decoder 2022-11-12 10:17:27 -07:00
Zaggy1024
dd18c42643 LibVideo: Parameterize compound mode parsing in the VP9 decoder 2022-11-12 10:17:27 -07:00
Zaggy1024
372a4ea8c1 LibVideo: Parameterize parsing if a block is inter predicted in VP9 2022-11-12 10:17:27 -07:00
Zaggy1024
93caa1e19d LibVideo: Parameterize TXSize parsing for the VP9 decoder 2022-11-12 10:17:27 -07:00
Zaggy1024
cc735a7001 LibVideo: Parameterize coefficient skip parsing for VP9 2022-11-12 10:17:27 -07:00
Zaggy1024
10ba956066 LibVideo: Parameterize segment ID parsing for the VP9 decoder 2022-11-12 10:17:27 -07:00
Zaggy1024
568e2fc1f2 LibVideo: Parameterize interpolation filter parsing for the VP9 decoder 2022-11-12 10:17:27 -07:00
Zaggy1024
cbb8a3f0f4 LibVideo: Parameterize inter mode parsing in the VP9 decoder 2022-11-12 10:17:27 -07:00
Zaggy1024
540ef22b95 LibVideo: Parameterize UV mode parsing in the VP9 decoder 2022-11-12 10:17:27 -07:00
Zaggy1024
858915ab3a LibVideo: Parameterize intra prediction mode parsing for VP9 2022-11-12 10:17:27 -07:00
Zaggy1024
1b66aa3cad LibVideo: Parameterize parsing the default UV prediction mode for VP9 2022-11-12 10:17:27 -07:00
Zaggy1024
c6ecad63d0 LibVideo: Parameterize parsing of the default VP9 intra mode tree 2022-11-12 10:17:27 -07:00
Zaggy1024
6192a33e79 LibVideo: Move parsing of Partition to its own TreeParser function
This adds a tree-parsing function that can be called statically from
specific trees' implementations in TreeParser, of which Partition is
the first. This way, all calls to tree parses will take the context
they need to be able to select a tree and probabilities, which will
allow removal of the state dependence in TreeParser on fields from
itself and Parser.
2022-11-12 10:17:27 -07:00
Zaggy1024
03738aa006 LibVideo: Implement block parsing for inter frames
This gets the decoder closer to fully parsing the second frame without
any errors. It will still be unable to output an inter-predicted frame.
The lack of output causes VideoPlayer to crash if it attempts to read
the buffers for frame 1, so it is still limited to the first frame.
2022-10-09 20:32:40 -06:00
Zaggy1024
1514004cd5 LibVideo: Implement VP9 intra-predicted frame decoding
The first keyframe of the test video can be decoded with these changes.

Raw memory allocations in the Parser have been replaced with Vector or
Array to avoid memory leaks and OOBs.
2022-10-09 20:32:40 -06:00
Zaggy1024
b37ea6b414 LibVideo: Allow bit stream reads to throw errors
Errors are propagated to the user of the decoder so that they can be
aware of specific places where a read failed.
2022-10-09 20:32:40 -06:00
FalseHonesty
074fbd1b06 LibVideo/VP9: Implement parsing Token and MoreCoefs trees
These elements were being used in the new tokens implementation, so
support for them in the TreeParser has been added.

Additionally, this uncovered a bug where the nonzero contexts were
being cleared with the wrong size.
2021-07-10 21:28:56 +02:00
FalseHonesty
aa27ca1b16 LibVideo/VP9: Implement token parsing (6.4.24-6.4.26)
Note that this now requires a couple new syntax types to be parsed
in the TreeParser, so a follow-up commit will implement that behavior.
2021-07-10 21:28:56 +02:00
FalseHonesty
514559f074 LibVideo/VP9: Rename Decoder -> Parser & create an actual Decoder class
The class that was previously named Decoder handled section 6.X.X of
the spec, which actually deals with parsing out the syntax of the data,
not the actual decoding logic which is specified in section 8.X.X.
The new Decoder class will be in charge of owning and running the
Parser, as well as implementing all of the decoding behavior.
2021-07-10 21:28:56 +02:00
FalseHonesty
91572a49c4 LibVideo/VP9: Specify which spec section defines certain behaviors 2021-07-10 21:28:56 +02:00
FalseHonesty
e4f015ce3d LibVideo/VP9: Implement more TreeParser probability calculations
Now TreeParser has mostly complete probability calculation
implementations for all currently used syntax elements. Some of these
calculation methods aren't actually finished because they use data
we have yet to parse in the Decoder, but they're close to finished.
2021-07-10 21:28:56 +02:00
FalseHonesty
988e17ed05 LibVideo: Migrate to east-const style & apply other minor fixes
This patch brings all of LibVideo up to the east-const style in the
project. Additionally, it applies a few fixes from the reviews in #8170
that referred to older LibVideo code.
2021-06-30 11:03:51 +02:00
FalseHonesty
42fdaa7f60 LibVideo/VP9: Implement most of inter_frame_mode_info (6.4.11-6.4.14) 2021-06-30 11:03:51 +02:00
FalseHonesty
741677b992 LibVideo/VP9: Refactor how TreeParser accesses decoder data
The TreeParser requires information about a lot of the decoder's
current state in order to parse syntax tree elements correctly, so
there has to be some communication between the Decoder and the
TreeParser. Previously, the Decoder would copy its state to the
TreeParser when it changed, however, this was a poor choice. Now,
the TreeParser simply has a reference to its owning Decoder, and
accesses its state directly.
2021-06-30 11:03:51 +02:00
FalseHonesty
375dbad144 LibVideo/VP9: Begin decoding VP9 blocks 2021-06-30 11:03:51 +02:00
FalseHonesty
2ce4155b42 LibVideo/VP9: Successfully parse partition syntax element 2021-06-30 11:03:51 +02:00
FalseHonesty
7ff6315246 LibVideo/VP9: Begin creating a tree parser to parse syntax elements 2021-06-30 11:03:51 +02:00