Skip to content

Truly independent web browser

LibMedia: Re-seek video to EOS if no output was requested

Zaggy1024bc5b4ab93a82
diff --git a/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp b/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp
index 07ced50df60..3d40e68e9f0 100644
--- a/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp
+++ b/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp
@@ -588,7 +588,7 @@ bool DecodedVideoProducer::ThreadData::handle_seek()
// If we've reached EOS without producing any output, restart the seek targeting the last frame
// we saw to produce just that last frame.
- if (!has_clamped_target && last_frame == nullptr && !decoding_for_output && greatest_coded_timestamp > AK::Duration::zero()) {
+ if (!has_clamped_target && !decoding_for_output && greatest_coded_timestamp > AK::Duration::zero()) {
auto locker = take_lock();
if (m_seek_id == seek_id) {
has_clamped_target = true;
diff --git a/Tests/LibMedia/TestDecodedVideoProducer.cpp b/Tests/LibMedia/TestDecodedVideoProducer.cpp
index ef73c15501a..75bc3074e95 100644
--- a/Tests/LibMedia/TestDecodedVideoProducer.cpp
+++ b/Tests/LibMedia/TestDecodedVideoProducer.cpp
@@ -281,6 +281,42 @@ TEST_CASE(a_seek_past_the_consumed_last_frame_re_emits_it)
}
}
+// A decoder keeps frames meant for output across a seek that leaves the demuxer where it was, and a seek past the
+// end has none of its own to offer instead, so those must not pass for the last frame.
+TEST_CASE(a_seek_past_the_end_during_playback_lands_on_the_last_frame)
+{
+ auto& loop = never_destroyed_event_loop();
+
+ AK::Duration last_sample_timestamp;
+ {
+ auto [demuxer, track] = demuxer_and_video_track_for("./vp9_in_webm.webm"sv);
+ TRY_OR_FAIL(demuxer->create_context_for_track(track));
+ while (true) {
+ auto sample = demuxer->get_next_sample_for_track(track);
+ if (sample.is_error())
+ break;
+ last_sample_timestamp = sample.value().presentation_timestamp();
+ }
+ }
+
+ auto producer = create_started_producer(loop, "./vp9_in_webm.webm"sv);
+ auto time_limit = AK::Duration::from_seconds(5);
+ // Decoding has to be underway for the decoder to hold frames meant for output when the seek arrives.
+ for (size_t frame_count = 0; frame_count < 3; frame_count++) {
+ if (take_frame_within_time_limit(*producer, loop, time_limit) == nullptr) {
+ FAIL(ByteString::formatted("Timed out waiting for frame {}", frame_count));
+ return;
+ }
+ }
+
+ producer->seek(last_sample_timestamp + AK::Duration::from_seconds(10));
+ auto frame = take_frame_within_time_limit(*producer, loop, time_limit);
+ if (frame == nullptr)
+ FAIL("Timed out waiting for the seek past the end to resolve");
+ else
+ EXPECT_EQ(frame->timestamp(), last_sample_timestamp);
+}
+
TEST_CASE(a_codec_change_drains_the_previous_decoder)
{
auto& loop = never_destroyed_event_loop();