1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00
serenity/Tests/LibVideo/TestVP9Decode.cpp
Zaggy1024 9cf7e8c5aa LibVideo: Reorganize demuxer file hierarchy and rename Matroska files
As new demuxers are added, this will get quite full of files, so it'll
be good to have a separate folder for these.

To avoid too many chained namespaces, the Containers subdirectory is
not also a namespace, but the Matroska folder is for the sake of
separating the multiple classes for parsed information entering the
Video namespace.
2022-11-25 23:28:39 +01:00

48 lines
1.6 KiB
C++

/*
* Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <LibVideo/Containers/Matroska/Reader.h>
#include <LibVideo/VP9/Decoder.h>
static void decode_video(StringView path, size_t expected_frame_count)
{
auto matroska_document = Video::Matroska::Reader::parse_matroska_from_file(path);
VERIFY(matroska_document);
auto video_track_optional = matroska_document->track_for_track_type(Video::Matroska::TrackEntry::TrackType::Video);
VERIFY(video_track_optional.has_value());
auto video_track_entry = video_track_optional.value();
size_t frame_count = 0;
size_t cluster_index, block_index, frame_index;
Video::VP9::Decoder vp9_decoder;
for (cluster_index = 0; cluster_index < matroska_document->clusters().size(); cluster_index++) {
auto const& cluster = matroska_document->clusters()[cluster_index];
for (block_index = 0; block_index < cluster.blocks().size(); block_index++) {
auto const& block = cluster.blocks()[block_index];
if (block.track_number() != video_track_entry.track_number())
continue;
for (frame_index = 0; frame_index < block.frames().size(); frame_index++) {
MUST(vp9_decoder.receive_sample(block.frames()[frame_index]));
frame_count++;
}
}
}
VERIFY(frame_count == expected_frame_count);
}
TEST_CASE(webm_in_vp9)
{
decode_video("./vp9_in_webm.webm"sv, 25);
}
BENCHMARK_CASE(vp9_4k)
{
decode_video("./vp9_4k.webm"sv, 2);
}