Commit Graph

43643 Commits

Author SHA1 Message Date
Andreas Kling
3821f35e4e Meta: Add Gregory Bertilson to the contributors list :^) 2022-11-30 10:12:11 +01:00
Zaggy1024
b1c7bbc4ba LibVideo/VP9: Make get_tile_offset static and remove magic numbers
This can use the new utility functions for converting units now.
2022-11-30 08:28:30 +01:00
Zaggy1024
f5ea6c89df LibVideo/VP9: Put reference frames into a struct 2022-11-30 08:28:30 +01:00
Zaggy1024
e6b696fe24 LibVideo/VP9: Remove now-unused clear_context function from Parser 2022-11-30 08:28:30 +01: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
720fc5a853 LibVideo/VP9: Use unit conversion functions in BlockContext
This should make things in there seem a little less magical :^)
2022-11-30 08:28:30 +01:00
Zaggy1024
1fe22f2141 LibVideo/VP9: Move segmentation id prediction context to TileContext
These can also be stored in the same places as the non-zero tokens
contexts.
2022-11-30 08:28:30 +01:00
Zaggy1024
9df72080a1 LibVideo/VP9: Add FIXME about implementation of tiled decoding 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
3667f9bf2c LibVideo/VP9: Store m_mode_context in BlockContext
This is set by motion vector selection to later be used by inter block
info parsing.
2022-11-30 08:28:30 +01:00
Zaggy1024
b5cce5a448 LibVideo/VP9: Move the m_use_prev_frame_mvs field to FrameContext 2022-11-30 08:28:30 +01:00
Zaggy1024
6ffb0844a1 LibVideo/VP9: Remove the m_use_hp field from Parser
This one is entirely scoped to the motion vector parsing function and
its individual component read function.
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
a4f14f220d LibVideo/VP9: Fully qualify all reference frame type enum values
Since the enum is used as an index to arrays, it unfortunately can't
be converted to an enum class, but at least we can make sure to use it
with the qualified enum name to make things a bit clearer.
2022-11-30 08:28:30 +01:00
Zaggy1024
db9f1a18f8 LibVideo/VP9: Convert TransformMode to an enum class
TXModeSelect was also renamed to plain Select, since the qualified name
will be TransformMode::Select.
2022-11-30 08:28:30 +01:00
Zaggy1024
c33d6fb028 LibVideo/VP9: Change all names containing tx_size to transform_size 2022-11-30 08:28:30 +01:00
Zaggy1024
1a2d8ac40c LibVideo/VP9: Prefix TransformSize with Transform_ instead of TX_ 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
f898a00eb3 LibVideo/VP9: Specify more units in Parser::residual()
Previously, the variables were named similarly to the names in spec
which aren't very human-readable. This adds some utility functions for
dimensional unit conversions and names the variables in residual()
based on their units.

References to 4x4 blocks were also renamed to call them sub-blocks
instead, since unit conversion functions would not be able to begin
with "4x4_blocks".
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
b6f41fe7d9 LibVideo/VP9: Pass the sub-block transform type around as a parameter
The sub-block transform types set and then used in a very small scope,
so now it is just stored in a variable and passed to the two functions
that need it, Parser::tokens() and Decoder::reconstruct().
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
d82dc14bd9 LibVideo/VP9: Use a bitwise enum for motion vector joint selection
The motion vector joints enum is set up so that the first bit indicates
that a vector should have a non-zero value in the column, and the
second bit indicates a non-zero value for the row. Taking advantage of
this makes the code a bit more legible.
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
3af4deba6d LibVideo/VP9: Move reference frame type fields to FrameContext 2022-11-30 08:28:30 +01:00
Zaggy1024
b966f9d811 LibVideo/VP9: Move the transform mode field from Parser to FrameContext 2022-11-30 08:28:30 +01:00
Zaggy1024
396972bb69 LibVideo/VP9: Retain adjacent block contexts storage between frames
Re-allocating the storage is unnecessary, since the size will rarely
change during playback.
2022-11-30 08:28:30 +01:00
Zaggy1024
ea7a6f343b LibVideo/VP9: Select and read motion vectors without fields in Parser
Candidate vector selections are only used to calculate the new vectors
for the current block, so we only need to keep those for the duration
of the inter_block_mode_info() call.

Candidate vectors are now stored in BlockMotionVectorCandidates, which
contains the fields necessary to choose the vector to use to sample
from the selected reference frame.

Most functions related to motion vectors were renamed to more verbose
but meaningful names.
2022-11-30 08:28:30 +01:00
Zaggy1024
368687a74f LibVideo/VP9: Store tile counts in FrameContext
The log2 of tile counts in the horizontal and vertical dimensions are
now stored in the FrameContext struct to be kept only as long as they
are needed.
2022-11-30 08:28:30 +01:00
Zaggy1024
6533c5f6a8 LibVideo/VP9: Move more block fields into the BlockContext struct
This includes the segment IDs, transform block sizes, prediction modes,
sub-block counts, interpolation filters and sub-block motion vectors.
2022-11-30 08:28:30 +01:00
Zaggy1024
f4e835635f LibVideo/VP9: Move quantizer indices into FrameContext
This also renames (most?) of the related quantizer functions and
variables to make more sense. I haven't determined what AC/DC stands
for here, but it may be just an arbitrary naming scheme for the first
and subsequent coefficients used to quantize the residuals for a block.
2022-11-30 08:28:30 +01:00
Zaggy1024
0df5c1f32f LibVideo/VP9: Move loop filter parameters to FrameContext 2022-11-30 08:28:30 +01:00
Zaggy1024
90f16c78fa LibVideo/VP9: Move fields set in uncompressed_header() to FrameContext 2022-11-30 08:28:30 +01:00
Zaggy1024
40bc987fe3 LibVideo/VP9: Store color config in the frame context
The color config is reused for most inter predicted frames, so we use a
struct ColorConfig to store the config from intra frames, and put it in
a field in Parser to copy from when an inter frame without color config
is encountered.
2022-11-30 08:28:30 +01:00
Zaggy1024
9f573264ea LibVideo/VP9: Add a FIXME to keep render_and_frame_size_different
The flag should be used to determine whether the pixel aspect ratio
should be updated when frame/render sizes change in the bitstream.
2022-11-30 08:28:30 +01:00
Zaggy1024
3259c99cab LibVideo/VP9: Choose whether/how to show new frames using an enum
There are three mutually exclusive frame-showing states:
- Show no new frame, only store the frame as a reference.
- Show a newly decoded frame.
- Show frame from the reference frame store.
Since they are mutually exclusive, using an enum rather than two bools
makes more sense.
2022-11-30 08:28:30 +01:00
Zaggy1024
befcd479ae LibVideo/VP9: Add Frame, Tile and Block context structs
These are used to pass context needed for decoding, with mutability
scoped only to the sections that the function receiving the contexts
needs to modify. This allows lifetimes of data to be more explicit
rather than being stored in fields, as well as preventing tile threads
from modifying outside their allowed bounds.
2022-11-30 08:28:30 +01:00
Zaggy1024
448a8b8efb LibVideo/VP9: Create Vector2DView to limit writable ranges of contexts 2022-11-30 08:28:30 +01:00
Zaggy1024
9da432f4d6 LibVideo/VP9: Remove m_eob_total field from parser
The field was only used once to track whether residual tokens were
present in the block. Parser::tokens() now returns a bool indicating
whether they were present.
2022-11-30 08:28:30 +01:00
Zaggy1024
10d207959d LibVideo/VP9: Remove m_mi_row and col fields from the parser
These are now passed as parameters to each function that uses them.
These will later be moved to a struct to further reduce the amount of
parameters that get passed around.

Above and left per-frame block contexts are now also parameters passed
to the functions that use them instead of being retrieved when needed
from a field. This will allow them to be more easily moved to a tile-
specific context later.
2022-11-30 08:28:30 +01:00
Zaggy1024
4a4aa697d9 LibVideo/VP9: Use a struct for block context to keep between frames
There are three fields that we need to store from FrameBlockContext to
keep between frames, which are used to parse for those same fields for
the next frame.
2022-11-30 08:28:30 +01:00
Zaggy1024
5275a1101e LibVideo/VP9: Remove dump_frame_info() function from Decoder
The function serves no purpose now, any debug information we want to
pull from the decoder should be instead accessed by some other yet to
be created interface.
2022-11-30 08:28:30 +01:00
Zaggy1024
0638c5d2b8 LibVideo/VP9: Use a class to store 2D context information 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
9b6ab1d4e5 LibVideo/VP9: Change fields within decode_partition() to variables 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