Skip to content

Truly independent web browser

Tests/LibMedia: Seek again when the suspension-resume case resuspends

sideshowbarkerb5168aba5ba8
diff --git a/Tests/LibMedia/TestDecodedAudioProducer.cpp b/Tests/LibMedia/TestDecodedAudioProducer.cpp
index 09f81e34e6a..36ec5755cff 100644
--- a/Tests/LibMedia/TestDecodedAudioProducer.cpp
+++ b/Tests/LibMedia/TestDecodedAudioProducer.cpp
@@ -339,5 +339,5 @@ TEST_CASE(audio_producer_auto_suspends_and_resumes_only_from_a_seek)
}));
// A seek resumes decoding and wakes the waiting consumer.
- EXPECT(seek_to_resume_and_pump_until_woken_with_data(loop, *producer, AK::Duration::zero()));
+ EXPECT(seek_to_resume_and_pump_until_woken_with_data(loop, *producer, AK::Duration::zero()).has_value());
}
diff --git a/Tests/LibMedia/TestDecodedVideoProducer.cpp b/Tests/LibMedia/TestDecodedVideoProducer.cpp
index c4f69a611b3..c325bfe9bbc 100644
--- a/Tests/LibMedia/TestDecodedVideoProducer.cpp
+++ b/Tests/LibMedia/TestDecodedVideoProducer.cpp
@@ -1144,14 +1144,16 @@ TEST_CASE(resuming_from_suspension_partway_into_a_group_of_pictures_moves_the_de
auto target = AK::Duration::from_microseconds((target_sample_start + target_sample_end) / 2);
auto forced_seek_count_before_resuming = demuxer->forced_seek_count();
- producer->seek(target);
- auto frame = take_frame_within_time_limit(*producer, loop, time_limit);
- if (frame == nullptr) {
+ size_t seek_count = 0;
+ auto output = seek_to_resume_and_pump_until_woken_with_data(loop, *producer, target, seek_count);
+ if (!output.has_value()) {
FAIL("Timed out waiting for the seek to resolve");
return;
}
- EXPECT_EQ(frame->timestamp(), samples[target_index].timestamp);
- EXPECT_EQ(demuxer->forced_seek_count(), forced_seek_count_before_resuming + 1);
+ producer->consume();
+ EXPECT_EQ(output->frame->timestamp(), samples[target_index].timestamp);
+ // The producer can suspend again before the test peeks, so each seek that resumes it forces one demuxer seek.
+ EXPECT_EQ(demuxer->forced_seek_count(), forced_seek_count_before_resuming + seek_count);
}
// The frames a decoder produced before it lost its state are still good, so they stay available while decoding
@@ -1566,7 +1568,7 @@ TEST_CASE(video_producer_auto_suspends_and_resumes_only_from_a_seek)
EXPECT_EQ(producer->peek().status, Media::PipelineStatus::Suspended);
// A seek resumes decoding and wakes the waiting consumer.
- EXPECT(seek_to_resume_and_pump_until_woken_with_data(loop, *producer, AK::Duration::zero()));
+ EXPECT(seek_to_resume_and_pump_until_woken_with_data(loop, *producer, AK::Duration::zero()).has_value());
}
TEST_CASE(video_producer_suspends_while_frames_are_held_and_wakes_the_consumer)
diff --git a/Tests/LibMedia/TestMediaCommon.h b/Tests/LibMedia/TestMediaCommon.h
index 94459a44191..997b7dbfc78 100644
--- a/Tests/LibMedia/TestMediaCommon.h
+++ b/Tests/LibMedia/TestMediaCommon.h
@@ -234,23 +234,38 @@ static inline bool has_data_or_already_suspended(Media::PipelineStatus status)
// A stalled test thread can leave the producer idle long enough to suspend again before it peeks, and a consumer that
// sees a suspension must seek again. These resume from a seek as such a consumer would.
+// Returns the output that showed the data, since the producer can suspend again and drop it before another peek.
+// seek_count counts the seeks issued, the first included.
template<typename Producer>
-static inline bool seek_to_resume_and_pump_until_woken_with_data(Core::EventLoop& loop, Producer& producer, AK::Duration timestamp)
+static inline auto seek_to_resume_and_pump_until_woken_with_data(Core::EventLoop& loop, Producer& producer, AK::Duration timestamp, size_t& seek_count)
{
+ Optional<decltype(producer.peek())> output_with_data;
bool woken = false;
producer.set_wake_handler([&] { woken = true; });
producer.seek(timestamp);
- auto resumed = pump_until(loop, [&] {
+ seek_count = 1;
+ pump_until(loop, [&] {
if (!woken)
return false;
woken = false;
- auto status = producer.peek().status;
- if (status == Media::PipelineStatus::Suspended) {
+ auto output = producer.peek();
+ if (output.status == Media::PipelineStatus::Suspended) {
producer.seek(timestamp);
+ seek_count++;
return false;
}
- return status == Media::PipelineStatus::HaveData;
+ if (output.status != Media::PipelineStatus::HaveData)
+ return false;
+ output_with_data = move(output);
+ return true;
});
producer.set_wake_handler(nullptr);
- return resumed;
+ return output_with_data;
+}
+
+template<typename Producer>
+static inline auto seek_to_resume_and_pump_until_woken_with_data(Core::EventLoop& loop, Producer& producer, AK::Duration timestamp)
+{
+ size_t seek_count = 0;
+ return seek_to_resume_and_pump_until_woken_with_data(loop, producer, timestamp, seek_count);
}