Commit graph

109 commits

Author SHA1 Message Date
Zaggy1024
7514e49c17 LibVideo: Make all VP9 block intermediates stack-allocated arrays
This has two benefits:
- I observed a ~34% decrease in decoding time running TestVP9Decode.
- Removing all of these silly Vector fields helps simplify the code
  relationships between all the functions in Decoder.cpp. It'll also be
  much easier to make these static with template specializations, if
  that turns out to be worthy performance improvement.
2022-11-25 02:44:18 +03:30
Zaggy1024
87aed17a46 VideoPlayer: Make PlaybackManager use OwnPtr
VideoPlayerWidget was keeping a reference to PlaybackManager when
changing files, so the old and new managers would both send frames to
be presented at the same time, causing it to flicker back and forth
between the two videos. However, PlaybackManager no longer relies on
event bubbling to pass events to its parent. By changing it to send
events directly to an Object, it can avoid being ref counted, so that
it will get destroyed with its containing object and stop sending
events.
2022-11-14 10:05:56 +00:00
Zaggy1024
9dc622475e LibVideo: Rename parse_tree_new to parse_tree in VP9/TreeParser.cpp
It is now the only function used to parse the binary trees in the VP9
decoder.
2022-11-12 10:17:27 -07: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
fce7639c90 LibVideo: Put motion vector or reference frame pairs in a struct
Since these two types are often passed around as a pair, it's easier to
handle them with a simple pair struct, at least for now. Once things
are fully being passed around as parameters wherever possible, it may
be good to change this type for something more generalized.
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
69e6feaf32 LibVideo: Add const getters to VP9/ProbabilityTables.h 2022-11-12 10:17:27 -07:00
Zaggy1024
17e1b205a4 LibVideo: Use the BlockSubsize enum where appropriate in the VP9 parser 2022-11-12 10:17:27 -07:00
Zaggy1024
981997c039 LibVideo: Combine VP9's Intra- and InterMode enums into PredictionMode
The two different mode sets are stored in single fields, and the
underlying values didn't overlap, so there was no reason to keep them
separate.

The enum is now an enum class as well, to enforce that almost all uses
of the enum are named. The only case where underlying values are used
is in lookup tables, but it may be worth abstracting that as well to
make array bounds more clear.
2022-11-12 10:17:27 -07:00
Zaggy1024
1c6d0a9777 LibVideo: Use Gfx::Size for VP9 frame sizes
Frame sizes will now be represented by Gfx::Size instead of storing
width and height separately.
2022-11-12 10:17:27 -07:00
Zaggy1024
40b0bb0914 LibVideo: Change all Span<u8 const> to ReadonlyBytes 2022-11-12 10:17:27 -07:00
Zaggy1024
72ed286e16 LibVideo: Allow the VP9 decoder to queue multiple frames
Frames will now be queued for retrieval by the user of the decoder.
When the end of the current queue is reached, a DecoderError of
category NeedsMoreInput will be emitted, allowing the caller to react
by displaying what was previously retrieved for sending more samples.
2022-11-12 10:17:27 -07:00
Zaggy1024
993385f18d LibVideo: Rename VP9's ReferenceFrame enum to ReferenceFrameType 2022-11-12 10:17:27 -07:00
Zaggy1024
6b392cef9c LibVideo: Treat BT.601/709/2020 input transfer characteristics as sRGB
I've realized that it probably makes more sense to change the input
transfer characteristics to treat these as sRGB since color conversion
in linear converted from BT.709 doesn't really make sense. If content
creation applications expect media players to display BT.709 without
conversions, this means they expect applications to treat it as sRGB,
since that's what most displays use. That most likely also means they
process it as sRGB internally, meaning we should do the same for our
color primaries conversion.
2022-11-11 11:34:03 +01:00
Zaggy1024
6f28c8deb0 LibVideo: Remove control codes from DecoderError location information 2022-11-10 12:32:55 +03:30
Zaggy1024
18a6a1dd10 LibVideo: Handle corrupted video errors without spamming dialogs
No longer will the video player explode with error dialogs that then
lock the user out of closing them.

To avoid issues where the playback state becomes invalid when an error
occurs, I've made all decoder errors pass through the frame queue.
This way, when a video is corrupted, there should be no chance that the
playback state becomes invalid due to setting the state to Corrupted
in the event handler while a presentation event is still pending.
Or at least I think that was what caused some issues I was seeing :^)

This system should be a lot more robust if any future errors need to be
handled.
2022-11-10 12:32:55 +03:30
Nico Weber
6911c5545c Everywhere: Fix a few comment typos 2022-11-09 16:00:32 +00:00
Tim Schumacher
ce2f1b845f Everywhere: Mark dependencies of most targets as PRIVATE
Otherwise, we end up propagating those dependencies into targets that
link against that library, which creates unnecessary link-time
dependencies.

Also included are changes to readd now missing dependencies to tools
that actually need them.
2022-11-01 14:49:09 +00:00
Zaggy1024
353e1c2b4d LibVideo: Add PlaybackManager to load and decode videos
This file will be the basis for abstracting away the out-of-thread or
later out-of-process decoding from applications displaying videos. For
now, the demuxer is hardcoded to be MatroskaParser, since that is all
we support so far. The demuxer should later be selected based on the
file header.

The playback and decoding are currently all done on one thread using
timers. The design of the code is such that adding threading should
be trivial, at least based on an earlier version of the code. For now,
though, it's better that this runs in one thread, as the multithreaded
approach causes the Video Player to lock up permanently after a few
frames are decoded.
2022-10-31 14:47:13 +01:00
Zaggy1024
0a4def1208 LibVideo: Abstract media container format demuxing
This creates an abstract Demuxer class to allow multiple container
container formats to be easily used by video playback systems.
2022-10-31 14:47:13 +01:00
Zaggy1024
3a2f6c700d LibVideo: Parse the duration of Matroska files 2022-10-31 14:47:13 +01:00
Zaggy1024
2b4b6c5613 LibVideo: Make VP9::Decoder a subclass of a new abstract VideoDecoder
This will allow other decoders to be used in place of VP9::Decoder when
new video decoders are implemented, such as AV1.
2022-10-31 14:47:13 +01:00
Zaggy1024
3720f66bb1 LibVideo: Set CodingIndependentCodePoints in its member functions
This moves the setting of code points in CICP structs to member
functions completely so that the code having to set these code points
can be much cleaner.
2022-10-31 14:47:13 +01:00
Zaggy1024
074f771b59 LibVideo: Add VideoFrame class for decoded video frames
The class is virtual and has one subclass, SubsampledYUVFrame, which
is used by the VP9 decoder to return a single frame. The
output_to_bitmap(Bitmap&) function can be used to set pixels on an
existing bitmap of the correct size to the RGB values that
should be displayed. The to_bitmap() function will allocate a new bitmap
and fill it using output_to_bitmap.

This new class also implements bilinear scaling of the subsampled U and
V planes so that subsampled videos' colors will appear smoother.
2022-10-31 14:47:13 +01:00
Zaggy1024
91fbfe1773 LibVideo: Make DecoderError getters const 2022-10-31 00:02:52 +01:00
Zaggy1024
b87398341b LibVideo: Add CICP parsing to MatroskaReader
This will allow correct independent code points to be selected from VP9
in WebM, since the VP9 bitstream does not specify them independently.
2022-10-25 11:06:11 +02:00
Zaggy1024
cd127b65c3 LibVideo: Implement CICP color space conversion
This adds a struct called CodingIndependentCodePoints and related enums
that are used by video codecs to define its color space that frames
must be converted from when displaying a video.

Pre-multiplied matrices and lookup tables are stored to avoid most of
the floating point division and exponentiation in the conversion.
2022-10-25 11:06:11 +02:00
Andrew Kaster
290d3449e0 LibVideo: Hide debug message behind MATROSKA_DEBUG
This clutters fuzzer output if enabled.
2022-10-13 11:25:03 +02:00
Andrew Kaster
bf014c4d20 LibVideo: Check parsed superframe sizes when decoding VP9 frames
Make sure that the next parsed superframe size will not overflow the
chunk data before splitting it out to decode a frame.
2022-10-13 11:25:03 +02:00
Andrew Kaster
9d3074f72f LibVideo: Always check byte length before reading first byte in Streamer
The check was missing at the front of
MatroskaReader::Streamer::read_variable_size_integer, causing assertions
on malformed input streams.
2022-10-13 11:25:03 +02:00
Zaggy1024
41cb705b47 LibVideo: Allow the VP9 decoder to decode ultra high resolution video
Previously, some integer overflows and truncations were causing parsing
errors for 4K videos, with those fixed it can fully decode 8K video.

This adds a test to ensure that 4K video will continue to be decoded.

Note: There seems to be unexpectedly high memory usage while decoding
them, causing 8K video to require more than a gigabyte of RAM. (!!!)
2022-10-12 00:54:31 -06:00
Zaggy1024
0c07bed89c LibVideo: Initialize VP9 BitStream's reservoir field
Leaving it uninitialized could lead to undefined behavior.
2022-10-10 11:04:39 +01:00
Zaggy1024
63ba01cad2 LibVideo: Remove unnecessary dbgln calls
Debug prints are expensive, so doing them every frame seems excessive
now that the decoder is completely functional on some test videos.
2022-10-09 20:32:40 -06:00
Zaggy1024
7dcd5ed206 LibVideo: Make probability tables save to the specified index
Previously, saved probability tables were being inserted, causing the
Vector to increase in size when it should say fixed at a size of 4. This
changes the Vector to an Array<T, 4> which will default-initalize and
allow assigning to any index without previously setting size.
2022-10-09 20:32:40 -06:00
Zaggy1024
7d27273dc7 LibVideo: Ensure that syntax element counts don't overflow
Integer overflow could sometimes occur due to counts going above 255,
where the values should instead be clamped at their maximum to avoid
wrapping to 0.
2022-10-09 20:32:40 -06:00
Zaggy1024
7c87a8e302 LibVideo: Prevent decode_block from saving motion vectors out of bounds
This fixes an issue causing frame 3 of the test video to fail to parse
because a reference vector was incorrectly within the range for a high
precision delta vector read.
2022-10-09 20:32:40 -06:00