Skip to content

Truly independent web browser

LibMedia+Tests: Ensure that a video-only suspend resumes itself

Zaggy1024be8bf2b0310c
diff --git a/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp b/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
index 84472a7e96c..a03825ceb80 100644
--- a/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
+++ b/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
@@ -52,6 +52,11 @@ ErrorOr<void> DisplayingVideoSink::connect_input(NonnullRefPtr<VideoProducer> co
input->set_wake_handler([this] {
if (m_input->peek().status == PipelineStatus::Suspended) {
m_next_frame = nullptr;
+ // A ticking sink's update resumes the input if the time is moving, and reports the suspension otherwise.
+ if (m_is_ticking) {
+ update(MonotonicTime::now());
+ return;
+ }
dispatch_state_if_changed(PipelineStatus::Suspended);
return;
}
diff --git a/Tests/LibMedia/TestRemoteVideoNode.cpp b/Tests/LibMedia/TestRemoteVideoNode.cpp
index cce3918ac44..b72d0420451 100644
--- a/Tests/LibMedia/TestRemoteVideoNode.cpp
+++ b/Tests/LibMedia/TestRemoteVideoNode.cpp
@@ -21,10 +21,12 @@
#include <LibMedia/DemuxerRegistry.h>
#include <LibMedia/IncrementallyPopulatedStream.h>
#include <LibMedia/MediaTime.h>
+#include <LibMedia/MonotonicMediaClock.h>
#include <LibMedia/PlaybackManager.h>
#include <LibMedia/Producers/DecodedVideoProducer.h>
#include <LibMedia/Producers/RemoteVideoProducer.h>
#include <LibMedia/Sinks/AudioOutputFactory.h>
+#include <LibMedia/Sinks/DisplayingVideoSink.h>
#include <LibMedia/Sinks/RemoteVideoSink.h>
#include <LibMedia/Track.h>
#include <LibMedia/VideoPresentation/VideoPresentationClientConnection.h>
@@ -648,6 +650,32 @@ TEST_CASE(consumer_releases_queued_frames_on_suspension)
EXPECT_EQ(output.status, PipelineStatus::Suspended);
}
+// The clock resuming reaches a sink as a wake from its consumer. If the consumer suspended while the clock stood still,
+// that wake is the sink's only chance to resume it, or no frame is shown again.
+TEST_CASE(sink_resumes_a_suspended_consumer_when_the_clock_resumes)
+{
+ auto& loop = never_destroyed_event_loop();
+ auto pool = MUST(VideoFramePool::create());
+ size_t upstream_seeks = 0;
+ auto consumer = RemoteVideoProducer::create(make_consumer_delegates(upstream_seeks));
+ auto clock = MUST(MonotonicMediaClock::try_create());
+ auto sink = MUST(DisplayingVideoSink::try_create(clock->time_reader()));
+ MUST(sink->connect_input(consumer));
+ EXPECT_EQ(upstream_seeks, 1u);
+
+ consumer->receive_frame(1, 1, create_received_frame(*pool, AK::Duration::zero()));
+ EXPECT(sink->current_frame() != nullptr);
+
+ consumer->receive_status(PipelineStatus::Suspended, 1);
+ loop.pump(Core::EventLoop::WaitMode::PollForEvents);
+ EXPECT_EQ(upstream_seeks, 1u);
+
+ clock->resume();
+ consumer->notify_clock_resumed();
+ EXPECT_EQ(upstream_seeks, 2u);
+ sink->disconnect_input(consumer);
+}
+
// Frames lent under a seek the consumer has moved past are released as they arrive, and so are frames past the
// queue's limit, so that a peer cannot make the consumer hold its storage without end.
TEST_CASE(consumer_releases_frames_it_does_not_queue)