Truly independent web browser
LibMedia+Tests: Bridge runs of decodable frames in ISOBMFFDemuxer
Zaggy1024b78698855efb
diff --git a/Libraries/LibMedia/Containers/ISOBMFF/ISOBMFFDemuxer.cpp b/Libraries/LibMedia/Containers/ISOBMFF/ISOBMFFDemuxer.cppindex 3a509b210a8..0c91aa61c13 100644--- a/Libraries/LibMedia/Containers/ISOBMFF/ISOBMFFDemuxer.cpp+++ b/Libraries/LibMedia/Containers/ISOBMFF/ISOBMFFDemuxer.cpp@@ -81,7 +81,13 @@ void ISOBMFFDemuxer::start_scan()TimeRanges buffered;AK::Duration duration;auto iterator = SampleIterator::create(payload.cursor, payload.movie, id, payload.movie_end);- bool can_decode = false;+ // Available samples from a sync sample onward in decode order are playable through their latest end.+ Optional<TimeRanges::Range> decodable_run;+ auto end_decodable_run = [&] {+ if (decodable_run.has_value() && decodable_run->end > decodable_run->start)+ buffered.add_range(decodable_run->start, decodable_run->end);+ decodable_run.clear();+ };bool last_sample_available = false;bool track_reached_end = availability.closing_bytes_are_available();if (!iterator.is_error()) {@@ -101,13 +107,16 @@ void ISOBMFFDemuxer::start_scan()return sample.data_position >= range.start && sample.data_position <= range.end && sample.data_size <= range.end - sample.data_position;});last_sample_available = available;- if (!available)- can_decode = false;+ if (!available) {+ end_decodable_run();+ continue;+ }+ if (decodable_run.has_value())+ decodable_run->end = max(decodable_run->end, end);else if (sample.is_sync_sample)- can_decode = true;- if (available && can_decode)- buffered.add_range(max(sample.presentation_timestamp, AK::Duration::zero()), end);+ decodable_run = TimeRanges::Range { max(sample.presentation_timestamp, AK::Duration::zero()), end };}+ end_decodable_run();} else {track_reached_end = false;}diff --git a/Tests/LibMedia/TestBufferedRanges.cpp b/Tests/LibMedia/TestBufferedRanges.cppindex 856309e49e4..b1663bc2093 100644--- a/Tests/LibMedia/TestBufferedRanges.cpp+++ b/Tests/LibMedia/TestBufferedRanges.cpp@@ -206,6 +206,13 @@ static Array fixtures {{ 256 * KiB, AK::Duration::from_milliseconds(71'866) + AK::Duration::from_time_units(1024, 1, 44100), AK::Duration::from_milliseconds(74'884) },{ 320 * KiB, AK::Duration::from_milliseconds(90'116) + AK::Duration::from_time_units(1024, 1, 44100), AK::Duration::from_milliseconds(94'853) },},+ // Millisecond-rounded timestamps on reordered frames leave 1 ms holes between the samples' presentation+ // intervals, so these ranges only stay whole if the samples' availability decides them.+ Fixture {+ "buffered-ranges/ms_rounded_b_frames.mp4"sv,+ { 5236, 29040, 19008, 24000 },+ { 6614, 54072, 18000, 24000 },+ },};TEST_CASE(complete_files_are_fully_buffered)diff --git a/Tests/LibMedia/buffered-ranges/ms_rounded_b_frames.mp4 b/Tests/LibMedia/buffered-ranges/ms_rounded_b_frames.mp4new file mode 100644index 00000000000..4955a112b8eBinary files /dev/null and b/Tests/LibMedia/buffered-ranges/ms_rounded_b_frames.mp4 differ