From d50ab3015e600f348602cb7649ff5a3ce100b1ca Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Wed, 28 Jan 2026 13:32:42 -0600 Subject: [PATCH] Tests: Test seeking in Matroska files with and without cues --- Tests/LibMedia/TestParseMatroska.cpp | 46 ++++++++++++++++++ .../test-matroska-seeking-without-cues.mkv | Bin 0 -> 191 bytes Tests/LibMedia/test-matroska-seeking.mkv | Bin 0 -> 235 bytes 3 files changed, 46 insertions(+) create mode 100644 Tests/LibMedia/test-matroska-seeking-without-cues.mkv create mode 100644 Tests/LibMedia/test-matroska-seeking.mkv diff --git a/Tests/LibMedia/TestParseMatroska.cpp b/Tests/LibMedia/TestParseMatroska.cpp index af5bbb88bf..d35dbafd44 100644 --- a/Tests/LibMedia/TestParseMatroska.cpp +++ b/Tests/LibMedia/TestParseMatroska.cpp @@ -202,3 +202,49 @@ TEST_CASE(ebml_lacing) EXPECT_EQ(frames7[1].size(), 1u); EXPECT_EQ(frames7[2].size(), 8u); } + +TEST_CASE(seeking) +{ + auto test_files = { + "./test-matroska-seeking.mkv"sv, + "./test-matroska-seeking-without-cues.mkv"sv, + }; + + for (auto test_file : test_files) { + auto file = MUST(Core::File::open(test_file, Core::File::OpenMode::Read)); + auto stream = Media::IncrementallyPopulatedStream::create_from_buffer(MUST(file->read_until_eof())); + auto matroska_reader = MUST(Media::Matroska::Reader::from_stream(stream->create_cursor())); + u64 video_track = 0; + MUST(matroska_reader.for_each_track_of_type(Media::Matroska::TrackEntry::TrackType::Video, [&](Media::Matroska::TrackEntry const& track_entry) -> Media::DecoderErrorOr { + video_track = track_entry.track_number(); + return IterationDecision::Break; + })); + EXPECT_EQ(video_track, 1u); + + auto iterator = MUST(matroska_reader.create_sample_iterator(stream->create_cursor(), video_track)); + + auto first_block = MUST(iterator.next_block()); + EXPECT_EQ(first_block.timestamp().to_milliseconds(), 0); + EXPECT(first_block.only_keyframes()); + + iterator = MUST(matroska_reader.seek_to_random_access_point(iterator, AK::Duration::from_milliseconds(150))); + auto block_after_forward_seek = MUST(iterator.next_block()); + EXPECT_EQ(block_after_forward_seek.timestamp().to_milliseconds(), 100); + EXPECT(block_after_forward_seek.only_keyframes()); + + iterator = MUST(matroska_reader.seek_to_random_access_point(iterator, AK::Duration::from_milliseconds(220))); + auto block_at_200 = MUST(iterator.next_block()); + EXPECT_EQ(block_at_200.timestamp().to_milliseconds(), 200); + EXPECT(block_at_200.only_keyframes()); + + iterator = MUST(matroska_reader.seek_to_random_access_point(iterator, AK::Duration::from_milliseconds(50))); + auto block_at_0 = MUST(iterator.next_block()); + EXPECT_EQ(block_at_0.timestamp().to_milliseconds(), 0); + EXPECT(block_at_0.only_keyframes()); + + iterator = MUST(matroska_reader.seek_to_random_access_point(iterator, AK::Duration::from_milliseconds(100))); + auto block_exact_100 = MUST(iterator.next_block()); + EXPECT_EQ(block_exact_100.timestamp().to_milliseconds(), 100); + EXPECT(block_exact_100.only_keyframes()); + } +} diff --git a/Tests/LibMedia/test-matroska-seeking-without-cues.mkv b/Tests/LibMedia/test-matroska-seeking-without-cues.mkv new file mode 100644 index 0000000000000000000000000000000000000000..8711da3ffef346b7adc05475e055a4834f1f5d21 GIT binary patch literal 191 zcmb1gy}!8Msi`A3v7{)!I6Kj)y^%#CxFOwPsi^15w5eLxH#YM-IruiTl%y7yggb&M zv5MJ}kiULEDB#fnALP^3K~z7d~%fSlrRbz|g?J z$ixg{DKZEM3JHT)P7Df)O3F}GDG*f#hDOE^RSu3$&Ja}rfkD9_Rnwn0o`9%INK8tG Ks46HdDh2@Kbw^$R literal 0 HcmV?d00001 diff --git a/Tests/LibMedia/test-matroska-seeking.mkv b/Tests/LibMedia/test-matroska-seeking.mkv new file mode 100644 index 0000000000000000000000000000000000000000..4d725e2de8b9fcd76a8024d3d49249c2944671ba GIT binary patch literal 235 zcmb1gy}!8Msi`A3v7{)!I6Kj)y^%#CxFOx)qNwM}w5eLxH#YM-IruiTl%y7yggb&M zv5MJ}kiULEDB#fnALP^3K~z7d~%fSlrRbz|g?J z$ixg{DKZEM3JHT)P7Df)O3F}GDG*f#hDOE^RSu3$&Ja}rfkD9_Rnwn0o`9%INK8tG os46HdDwYY}oxOZ__vS{1?QP#189z4Kf;cHqPBMsd0?O$G0A9#o0RR91 literal 0 HcmV?d00001