mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 12:05:00 +00:00

The Demuxer class was changed to return errors for more functions so that all of the underlying reading can be done lazily. Other than that, the demuxer interface is unchanged, and only the underlying reader was modified. The MatroskaDocument class is no more, and MatroskaReader's getter functions replace it. Every MatroskaReader getter beyond the Segment element's position is parsed lazily from the file as needed. This means that all getter functions can return DecoderErrors which must be handled by callers.
51 lines
1.5 KiB
C++
51 lines
1.5 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_reader = MUST(Video::Matroska::Reader::from_file(path));
|
|
u64 video_track = 0;
|
|
MUST(matroska_reader.for_each_track_of_type(Video::Matroska::TrackEntry::TrackType::Video, [&](Video::Matroska::TrackEntry const& track_entry) -> Video::DecoderErrorOr<IterationDecision> {
|
|
video_track = track_entry.track_number();
|
|
return IterationDecision::Break;
|
|
}));
|
|
VERIFY(video_track != 0);
|
|
|
|
auto iterator = MUST(matroska_reader.create_sample_iterator(video_track));
|
|
size_t frame_count = 0;
|
|
Video::VP9::Decoder vp9_decoder;
|
|
|
|
while (frame_count <= expected_frame_count) {
|
|
auto block_result = iterator.next_block();
|
|
if (block_result.is_error() && block_result.error().category() == Video::DecoderErrorCategory::EndOfStream) {
|
|
VERIFY(frame_count == expected_frame_count);
|
|
return;
|
|
}
|
|
|
|
auto block = block_result.release_value();
|
|
for (auto const& frame : block.frames()) {
|
|
MUST(vp9_decoder.receive_sample(frame));
|
|
frame_count++;
|
|
}
|
|
}
|
|
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
|
|
TEST_CASE(webm_in_vp9)
|
|
{
|
|
decode_video("./vp9_in_webm.webm"sv, 25);
|
|
}
|
|
|
|
BENCHMARK_CASE(vp9_4k)
|
|
{
|
|
decode_video("./vp9_4k.webm"sv, 2);
|
|
}
|