Skip to content

Truly independent web browser

LibMedia+LibWeb+Compositor: Set video sink ticking via the pipeline

Zaggy102460d4bc05eea8
diff --git a/Libraries/LibMedia/PlaybackManager.cpp b/Libraries/LibMedia/PlaybackManager.cpp
index 0a8367223ce..b6a5d8f78fa 100644
--- a/Libraries/LibMedia/PlaybackManager.cpp
+++ b/Libraries/LibMedia/PlaybackManager.cpp
@@ -542,6 +542,7 @@ void PlaybackManager::attach_video_sink(VideoTrackData& track_data, NonnullRefPt
});
track_data.producer->set_checkpoint(m_latest_checkpoint.load(AK::MemoryOrder::memory_order_relaxed));
MUST(video_sink->connect_input(track_data.producer));
+ video_sink->set_ticking(track_data.ticking);
track_data.video_sink = move(video_sink);
update_pipeline_state();
dispatch_buffered_ranges_change();
@@ -611,6 +612,8 @@ void PlaybackManager::set_video_sink_ticking(VideoSinkHandle handle, bool tickin
if (track_data.ticking == ticking)
return;
track_data.ticking = ticking;
+ if (track_data.video_sink)
+ track_data.video_sink->set_ticking(ticking);
manager->update_pipeline_state();
}
diff --git a/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp b/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
index 67f3d038bc3..a4ac3dbbe9f 100644
--- a/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
+++ b/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
@@ -306,8 +306,12 @@ void DisplayingVideoSink::notify_clock_resumed()
void DisplayingVideoSink::set_ticking(bool ticking)
{
auto was_ticking = exchange(m_is_ticking, ticking);
- if (ticking && !was_ticking)
+ if (ticking == was_ticking)
+ return;
+ if (ticking)
seek_back_to_current_time();
+ if (m_on_ticking_changed)
+ m_on_ticking_changed();
}
void DisplayingVideoSink::seek_back_to_current_time()
diff --git a/Libraries/LibMedia/Sinks/DisplayingVideoSink.h b/Libraries/LibMedia/Sinks/DisplayingVideoSink.h
index cfbf0d98b42..f0c18f2abdc 100644
--- a/Libraries/LibMedia/Sinks/DisplayingVideoSink.h
+++ b/Libraries/LibMedia/Sinks/DisplayingVideoSink.h
@@ -50,8 +50,9 @@ public:
virtual void seek(AK::Duration timestamp, InvalidateHeldData = InvalidateHeldData::No) override;
virtual void notify_clock_resumed() override;
- void set_ticking(bool);
+ virtual void set_ticking(bool) override;
bool is_ticking() const { return m_is_ticking; }
+ void set_on_ticking_changed(Function<void()> handler) { m_on_ticking_changed = move(handler); }
DisplayingVideoSinkUpdateResult update(MonotonicTime now);
RefPtr<VideoFrame> current_frame() const;
@@ -90,6 +91,7 @@ private:
Gfx::Size<u32> m_last_dispatched_size;
Function<void()> m_on_present_needed;
+ Function<void()> m_on_ticking_changed;
bool m_last_update_may_require_updates { false };
};
diff --git a/Libraries/LibMedia/Sinks/RemoteVideoSink.cpp b/Libraries/LibMedia/Sinks/RemoteVideoSink.cpp
index 2c674a39bdb..ebd050bef2d 100644
--- a/Libraries/LibMedia/Sinks/RemoteVideoSink.cpp
+++ b/Libraries/LibMedia/Sinks/RemoteVideoSink.cpp
@@ -27,6 +27,7 @@ public:
void notify_clock_resumed() const;
void transmit_seek(InvalidateHeldData) const;
void transmit_time_reader(MediaTimeReader const&) const;
+ void transmit_ticking(bool) const;
void seek_upstream(AK::Duration timestamp, InvalidateHeldData, u64 newest_received_lend_id);
void seek_input_directly(AK::Duration timestamp);
void start_input();
@@ -82,6 +83,7 @@ ErrorOr<NonnullRefPtr<RemoteVideoSink>> RemoteVideoSink::create(Delegates delega
VERIFY(delegates.notify_clock_resumed);
VERIFY(delegates.transmit_seek);
VERIFY(delegates.transmit_time_reader);
+ VERIFY(delegates.transmit_ticking);
auto thread_data = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ThreadData(move(delegates))));
auto sink = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) RemoteVideoSink(thread_data)));
auto thread = Threading::Thread::construct("Video Pump"sv, [thread_data]() -> intptr_t {
@@ -113,6 +115,7 @@ void RemoteVideoSink::seek(AK::Duration timestamp, InvalidateHeldData invalidate
m_thread_data->transmit_seek(invalidate_held_data);
}
void RemoteVideoSink::notify_clock_resumed() { m_thread_data->notify_clock_resumed(); }
+void RemoteVideoSink::set_ticking(bool ticking) { m_thread_data->transmit_ticking(ticking); }
void RemoteVideoSink::seek_upstream(AK::Duration timestamp, InvalidateHeldData invalidate_held_data, u64 newest_received_lend_id) { m_thread_data->seek_upstream(timestamp, invalidate_held_data, newest_received_lend_id); }
void RemoteVideoSink::set_time_reader(MediaTimeReader time_reader)
@@ -189,6 +192,11 @@ void RemoteVideoSink::ThreadData::transmit_time_reader(MediaTimeReader const& ti
m_delegates.transmit_time_reader(time_reader);
}
+void RemoteVideoSink::ThreadData::transmit_ticking(bool ticking) const
+{
+ m_delegates.transmit_ticking(ticking);
+}
+
Vector<NonnullRefPtr<VideoFrame>> RemoteVideoSink::ThreadData::frames_lent_after_holding(u64 newest_received_lend_id, AK::Duration timestamp) const
{
// A frame lent again for an earlier seek is lent twice.
diff --git a/Libraries/LibMedia/Sinks/RemoteVideoSink.h b/Libraries/LibMedia/Sinks/RemoteVideoSink.h
index 1aea507a9a4..84b45cfa97e 100644
--- a/Libraries/LibMedia/Sinks/RemoteVideoSink.h
+++ b/Libraries/LibMedia/Sinks/RemoteVideoSink.h
@@ -45,6 +45,7 @@ public:
Function<void(InvalidateHeldData)> transmit_seek;
// Relays a replacement time reader (e.g. after audio is disabled) to the consumer; the initial one rides video_edge_ready.
Function<void(MediaTimeReader const&)> transmit_time_reader;
+ Function<void(bool)> transmit_ticking;
};
static ErrorOr<NonnullRefPtr<RemoteVideoSink>> create(Delegates);
@@ -55,6 +56,7 @@ public:
virtual void seek(AK::Duration timestamp, InvalidateHeldData = InvalidateHeldData::No) override;
virtual void notify_clock_resumed() override;
+ virtual void set_ticking(bool) override;
// The newest received lend ID is the last one the consumer had seen when it asked for the seek.
void seek_upstream(AK::Duration timestamp, InvalidateHeldData, u64 newest_received_lend_id);
virtual void set_time_reader(MediaTimeReader) override;
diff --git a/Libraries/LibMedia/Sinks/VideoSink.h b/Libraries/LibMedia/Sinks/VideoSink.h
index a38ad25a82b..db58f61101c 100644
--- a/Libraries/LibMedia/Sinks/VideoSink.h
+++ b/Libraries/LibMedia/Sinks/VideoSink.h
@@ -27,6 +27,8 @@ public:
virtual void seek(AK::Duration timestamp, InvalidateHeldData = InvalidateHeldData::No) = 0;
virtual void notify_clock_resumed() = 0;
+ // Whether the sink follows the clock.
+ virtual void set_ticking(bool) = 0;
virtual void set_time_reader(MediaTimeReader) = 0;
virtual void set_state_change_handler(PipelineStateChangeHandler) = 0;
diff --git a/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipc b/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipc
index 18968f7c2e1..dce05f77465 100644
--- a/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipc
+++ b/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipc
@@ -13,4 +13,5 @@ endpoint VideoPresentationClient {
edge_status_changed(u64 edge_id, Media::PipelineStatus status, u32 seek_id, Media::PipelineCheckpoint checkpoint) =|
notify_clock_resumed(u64 edge_id) =|
seek_sink(u64 edge_id, u32 requested_seek_id, Media::InvalidateHeldData invalidate_held_data) =|
+ set_sink_ticking(u64 edge_id, bool ticking) =|
}
diff --git a/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.cpp b/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.cpp
index 883a24c683b..e9e07260833 100644
--- a/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.cpp
+++ b/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.cpp
@@ -40,7 +40,7 @@ ErrorOr<void> VideoPresentationClientConnection::create_edge(VideoSinkHandle han
if (m_edge_states.size() >= MAX_EDGE_COUNT)
return Error::from_string_literal("Too many video edges");
auto edge_id = m_next_edge_id++;
- m_edge_states.set(edge_id, EdgeState { .handle = handle, .on_ready = move(on_ready), .consumer = nullptr, .sink = nullptr, .time_reader = {}, .sender_id = allocate_sender_id(), .expected_requested_seek_id = 0 });
+ m_edge_states.set(edge_id, EdgeState { .handle = handle, .on_ready = move(on_ready), .consumer = nullptr, .sink = nullptr, .time_reader = {}, .sender_id = allocate_sender_id(), .expected_requested_seek_id = 0, .ticking = {} });
async_create_video_edge(handle, edge_id);
return {};
}
@@ -102,9 +102,22 @@ void VideoPresentationClientConnection::video_edge_ready(u64 edge_id, MediaTimeR
edge_state->consumer = consumer;
edge_state->sink = sink;
+ auto ticking = edge_state->ticking;
auto on_ready = move(edge_state->on_ready);
if (on_ready)
on_ready(sink);
+ if (ticking.has_value())
+ sink->set_ticking(*ticking);
+}
+
+void VideoPresentationClientConnection::set_sink_ticking(u64 edge_id, bool ticking)
+{
+ auto edge_state = m_edge_states.get(edge_id);
+ if (!edge_state.has_value())
+ return;
+ edge_state->ticking = ticking;
+ if (edge_state->sink)
+ edge_state->sink->set_ticking(ticking);
}
void VideoPresentationClientConnection::update_edge_time_reader(u64 edge_id, MediaTimeReader time_reader)
diff --git a/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.h b/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.h
index 256e4185e31..3e057a546be 100644
--- a/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.h
+++ b/Libraries/LibMedia/VideoPresentation/VideoPresentationClientConnection.h
@@ -50,6 +50,7 @@ private:
virtual void edge_status_changed(u64 edge_id, Media::PipelineStatus status, u32 seek_id, Media::PipelineCheckpoint checkpoint) override;
virtual void notify_clock_resumed(u64 edge_id) override;
virtual void seek_sink(u64 edge_id, u32 requested_seek_id, InvalidateHeldData) override;
+ virtual void set_sink_ticking(u64 edge_id, bool ticking) override;
struct EdgeState {
VideoSinkHandle handle;
@@ -59,6 +60,8 @@ private:
Optional<MediaTimeReader> time_reader;
u64 sender_id { 0 };
u32 expected_requested_seek_id { 0 };
+ // Ticking that arrived before the sink did.
+ Optional<bool> ticking;
};
HashMap<u64, EdgeState> m_edge_states;
diff --git a/Libraries/LibMedia/VideoPresentation/VideoPresentationServerConnection.cpp b/Libraries/LibMedia/VideoPresentation/VideoPresentationServerConnection.cpp
index 8e3cfd46a98..5abcfa5b51c 100644
--- a/Libraries/LibMedia/VideoPresentation/VideoPresentationServerConnection.cpp
+++ b/Libraries/LibMedia/VideoPresentation/VideoPresentationServerConnection.cpp
@@ -104,6 +104,14 @@ void VideoPresentationServerConnection::create_registered_video_edge(VideoSinkHa
connection.async_update_edge_time_reader(edge_id, time_reader);
});
};
+ delegates.transmit_ticking = [weak_connection, edge_id](bool ticking) {
+ weak_connection.with_target([&](auto& connection) {
+ VERIFY(connection.m_owner_thread_id.is_current_thread());
+ if (!connection.m_edge_states.contains(edge_id))
+ return;
+ connection.async_set_sink_ticking(edge_id, ticking);
+ });
+ };
auto remote_edge_or_error = PlaybackManager::create_video_edge({}, video_sink_handle, move(delegates));
if (remote_edge_or_error.is_error()) {
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index ea1fd139d81..5848c7291e0 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -354,13 +354,6 @@ void CompositorConnection::release_video_frame_hold(Media::VideoSinkHandle video
async_release_video_frame_hold(video_sink_handle, generation);
}
-void CompositorConnection::set_video_sink_ticking(Media::VideoSinkHandle video_sink_handle, bool should_tick)
-{
- if (!can_send_message_to_compositor())
- return;
- async_set_video_sink_ticking(video_sink_handle, should_tick);
-}
-
RefPtr<IPC::ThreadSafeMessagePoster> CompositorConnection::poster_while_compositor_is_reachable()
{
if (!can_send_message_to_compositor())
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.h
index 51ed94fb3b6..9ee4a05b8c1 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -69,7 +69,6 @@ public:
void add_video_sink(Media::VideoSinkHandle, NonnullRefPtr<Compositing::VideoFramePresentationPage>);
void remove_video_sink(Media::VideoSinkHandle);
void release_video_frame_hold(Media::VideoSinkHandle, u64 generation);
- void set_video_sink_ticking(Media::VideoSinkHandle, bool should_tick);
RefPtr<IPC::ThreadSafeMessagePoster> poster_while_compositor_is_reachable();
bool post_canvas_2d_stream_batch_fonts_and_image_frames(ReadonlySpan<Gfx::Font const*>, ReadonlySpan<Gfx::DecodedImageFrame const*>);
void did_fail_to_post_canvas_2d_message();
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cpp
index dbecd259d82..a01489edf5d 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp
@@ -43,11 +43,6 @@ bool CompositorContextHandle::ready_for_frame()
return m_host.compositor_connection();
}
-void CompositorContextHandle::set_video_sink_ticking(Media::VideoSinkHandle video_sink_handle, bool should_tick)
-{
- m_host.set_video_sink_ticking(video_sink_handle, should_tick);
-}
-
void CompositorContextHandle::invalidate_keyboard_scroll_state(u64 generation)
{
m_host.invalidate_keyboard_scroll_state(m_context_id, generation);
@@ -304,12 +299,6 @@ void CompositorHost::remove_video_sink(Media::VideoSinkHandle video_sink_handle)
connection->remove_video_sink(video_sink_handle);
}
-void CompositorHost::set_video_sink_ticking(Media::VideoSinkHandle video_sink_handle, bool should_tick)
-{
- if (auto* connection = compositor_connection())
- connection->set_video_sink_ticking(video_sink_handle, should_tick);
-}
-
Compositing::VideoFrameHold::ReleaseThroughCompositor CompositorHost::video_frame_hold_releaser_for_current_connection() const
{
auto* connection = compositor_connection();
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.h b/Libraries/LibWeb/Compositor/CompositorHost.h
index 4405da51422..b55d32098e3 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.h
+++ b/Libraries/LibWeb/Compositor/CompositorHost.h
@@ -88,7 +88,6 @@ public:
void set_parent_context(Optional<Web::CompositorContextId>);
void stop_presenting_to_client();
- void set_video_sink_ticking(Media::VideoSinkHandle, bool should_tick);
void invalidate_wheel_event_listener_state(u64 generation);
void invalidate_keyboard_scroll_state(u64 generation);
Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventRouting);
@@ -165,7 +164,6 @@ public:
// Returns whether a compositor heard of the sink, which one that connects later will not have.
[[nodiscard]] bool add_video_sink(Media::VideoSinkHandle, NonnullRefPtr<Compositing::VideoFramePresentationPage>);
void remove_video_sink(Media::VideoSinkHandle);
- void set_video_sink_ticking(Media::VideoSinkHandle, bool should_tick);
Compositing::VideoFrameHold::ReleaseThroughCompositor video_frame_hold_releaser_for_current_connection() const;
void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);
void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 31883e52cea..05b39e97c75 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -3243,8 +3243,6 @@ void HTMLMediaElement::sync_video_sink_ticking(DocumentWasLaidOut document_was_l
if (m_playback_manager)
m_playback_manager->set_video_sink_ticking(*handle, should_tick);
- if (auto navigable = document().navigable(); navigable && navigable->has_compositor_context())
- navigable->compositor_context().set_video_sink_ticking(*handle, should_tick);
}
// Visible documents re-evaluate sink ticking in each rendering update, once layout has settled. Hidden documents skip
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.h
index af8f90d7876..98a9e7d2386 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h
@@ -340,7 +340,7 @@ private:
virtual bool is_shown_elsewhere() const { return false; }
virtual HTMLMediaElement& media_element_for_controls() { return *this; }
- // Mirrors what PlaybackManager and the compositor were last told; a freshly reserved sink is assumed to tick.
+ // Mirrors what PlaybackManager was last told; a freshly reserved sink is assumed to tick.
mutable bool m_video_sink_is_ticking { true };
void note_frame_captured() const;
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 5283b3247cc..45ecd824a5d 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -380,22 +380,18 @@ void CompositorState::remove_video_sink(CompositorStateWebContentClient& client,
client.release_video_edge(handle);
}
-void CompositorState::set_video_sink_ticking(CompositorStateWebContentClient& client, Media::VideoSinkHandle handle, bool should_tick)
+void CompositorState::video_sink_ticking_changed(CompositorStateWebContentClient& client, Media::VideoSinkHandle handle)
{
auto* sink_state = video_sink_state(client, handle);
- if (!sink_state)
+ if (!sink_state || !sink_state->sink)
return;
- sink_state->should_tick = should_tick;
- if (sink_state->sink)
- sink_state->sink->set_ticking(should_tick);
- if (should_tick && sink_state->sink)
+ if (sink_state->sink->is_ticking())
present_contexts_drawing_video_sink(client, handle);
update_unpainted_video_update_scheduling();
}
-// The client decides this and we apply it, so that the two processes can never disagree about whether a sink is
-// ticked. All we add is that a sink with no edge yet cannot be ticked, which can only delay ticking rather than
-// stop it, and resolves as soon as the edge is created.
+// The sink's owner decides on ticking, and the sink hears of it across its edge. A sink with no edge yet cannot be
+// ticked, which can only delay ticking rather than stop it.
bool CompositorState::video_sink_updates_are_needed(VideoSinkState const& sink_state)
{
return sink_state.sink != nullptr && sink_state.sink->is_ticking();
@@ -407,7 +403,9 @@ void CompositorState::on_video_sink_ready(CompositorStateWebContentClient& clien
if (!sink_state)
return;
sink_state->sink = sink;
- sink->set_ticking(sink_state->should_tick);
+ sink->set_on_ticking_changed([this, &client, handle] {
+ video_sink_ticking_changed(client, handle);
+ });
sink->set_on_present_needed([this, &client, handle] {
if (auto* sink_state = video_sink_state(client, handle); sink_state && sink_state->sink)
client.video_sink_presented_frame(handle, sink_state->sink->current_frame(), sink_state->sink->take_frame_counts());
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index ced82e6e6db..78ebe008c95 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -122,7 +122,6 @@ public:
// For a presentation channel that arrives after the sinks did, or that replaces the one their edges were on.
void create_video_edges(CompositorStateWebContentClient&);
void remove_video_sink(CompositorStateWebContentClient&, Media::VideoSinkHandle);
- void set_video_sink_ticking(CompositorStateWebContentClient&, Media::VideoSinkHandle, bool should_tick);
void on_video_sink_ready(CompositorStateWebContentClient&, Media::VideoSinkHandle, NonnullRefPtr<Media::DisplayingVideoSink> const&);
void add_animated_image(CompositorStateWebContentClient&, Compositing::ImageFrameResourceId, AnimatedImage::Description);
void remove_animated_image(CompositorStateWebContentClient&, Compositing::ImageFrameResourceId);
@@ -309,10 +308,10 @@ private:
struct VideoSinkState {
RefPtr<Media::DisplayingVideoSink> sink;
- bool should_tick { true };
bool requires_updates { false };
};
VideoSinkState* video_sink_state(CompositorStateWebContentClient&, Media::VideoSinkHandle);
+ void video_sink_ticking_changed(CompositorStateWebContentClient&, Media::VideoSinkHandle);
// The frame that a video sink of the client shows now, which is null for a sink that the client does not have or
// that shows none.
RefPtr<Media::VideoFrame> current_video_frame(CompositorStateWebContentClient&, Media::VideoSinkHandle);
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index c9aaee8f363..e1d68dc72bd 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -22,7 +22,6 @@ endpoint CompositorWebContentServer
add_video_sink(Media::VideoSinkHandle video_sink_handle, NonnullRefPtr<Compositing::VideoFramePresentationPage> presentation_page) =|
remove_video_sink(Media::VideoSinkHandle video_sink_handle) =|
release_video_frame_hold(Media::VideoSinkHandle video_sink_handle, u64 generation) =|
- set_video_sink_ticking(Media::VideoSinkHandle video_sink_handle, bool should_tick) =|
// A channel to the image decoder of this WebContent, which the frames of its animated images come through.
connect_to_image_decoder(IPC::TransportHandle handle) =|
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index 75c0ef12924..87d78aacc44 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -165,11 +165,6 @@ void ConnectionFromWebContent::video_sink_counted_frames(Media::VideoSinkHandle
m_video_frame_holds.add_frame_counts(video_sink_handle, new_frame_counts);
}
-void ConnectionFromWebContent::set_video_sink_ticking(Media::VideoSinkHandle video_sink_handle, bool should_tick)
-{
- m_compositor_state->set_video_sink_ticking(*this, video_sink_handle, should_tick);
-}
-
void ConnectionFromWebContent::create_video_edge(Media::VideoSinkHandle video_sink_handle)
{
if (!m_video_presentation_connection)
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index b412f207c9a..d554e84814f 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -54,7 +54,6 @@ private:
virtual void add_video_sink(Media::VideoSinkHandle, NonnullRefPtr<Compositing::VideoFramePresentationPage>) override;
virtual void remove_video_sink(Media::VideoSinkHandle) override;
virtual void release_video_frame_hold(Media::VideoSinkHandle, u64 generation) override;
- virtual void set_video_sink_ticking(Media::VideoSinkHandle, bool should_tick) override;
virtual void set_parent_context(Web::CompositorContextId, Optional<Web::CompositorContextId>) override;
virtual void stop_presenting_to_client(Web::CompositorContextId) override;
virtual void destroy_context(Web::CompositorContextId) override;
diff --git a/Tests/LibMedia/TestRemoteVideoNode.cpp b/Tests/LibMedia/TestRemoteVideoNode.cpp
index 8752dcf220b..0b97edd3871 100644
--- a/Tests/LibMedia/TestRemoteVideoNode.cpp
+++ b/Tests/LibMedia/TestRemoteVideoNode.cpp
@@ -181,6 +181,7 @@ void wire_full_node(VideoEdgeTestHarness& harness, NonnullRefPtr<VideoProducer>
sink_delegates.notify_clock_resumed = [] { };
sink_delegates.transmit_seek = [](InvalidateHeldData) { };
sink_delegates.transmit_time_reader = [](MediaTimeReader const&) { };
+ sink_delegates.transmit_ticking = [](bool) { };
harness.sink = MUST(RemoteVideoSink::create(move(sink_delegates)));
RemoteVideoProducer::Delegates consumer_delegates;
@@ -264,6 +265,7 @@ NonnullRefPtr<RemoteVideoSink> make_recorded_sink(LentFrameRecorder& recorder)
delegates.notify_clock_resumed = [] { };
delegates.transmit_seek = [](InvalidateHeldData) { };
delegates.transmit_time_reader = [](MediaTimeReader const&) { };
+ delegates.transmit_ticking = [](bool) { };
return MUST(RemoteVideoSink::create(move(delegates)));
}
@@ -529,6 +531,46 @@ TEST_CASE(video_presentation_server_releases_playback_edge_when_connection_dies)
EXPECT(!manager->track_is_enabled(track));
}
+// The playback manager decides on ticking for a sink, and the sink hears of it across its edge, both of a decision made
+// before the edge existed and of later ones.
+TEST_CASE(video_presentation_edge_carries_the_ticking_decision_to_its_sink)
+{
+ auto& loop = never_destroyed_event_loop();
+
+ auto manager = PlaybackManager::create(Media::AudioOutputFactory::create_null());
+ bool metadata_parsed = false;
+ manager->add_media_source(create_demuxer(load_test_file(TEST_CLIP)))->when_resolved([&](auto&) {
+ metadata_parsed = true;
+ });
+ if (!spin_until(loop, [&] { return metadata_parsed; })) {
+ FAIL("Timed out waiting for metadata");
+ return;
+ }
+ if (manager->video_tracks().is_empty()) {
+ FAIL("Expected a video track");
+ return;
+ }
+
+ auto handle = manager->reserve_video_sink_handle(manager->video_tracks()[0]);
+ PlaybackManager::set_video_sink_ticking(handle, false);
+
+ auto paired = MUST(IPC::Transport::create_paired());
+ auto server = VideoPresentationServerConnection::construct(move(paired.local));
+ auto client = adopt_ref(*new VideoPresentationClientConnection(MUST(paired.remote_handle.create_transport())));
+ RefPtr<DisplayingVideoSink> sink;
+ MUST(client->create_edge(handle, [&](NonnullRefPtr<DisplayingVideoSink> ready_sink) {
+ sink = move(ready_sink);
+ }));
+ EXPECT(spin_until(loop, [&] { return sink && !sink->is_ticking(); }));
+
+ PlaybackManager::set_video_sink_ticking(handle, true);
+ EXPECT(spin_until(loop, [&] { return sink->is_ticking(); }));
+ PlaybackManager::set_video_sink_ticking(handle, false);
+ EXPECT(spin_until(loop, [&] { return !sink->is_ticking(); }));
+
+ server->shutdown();
+}
+
// Each edge keeps the frames it is lent, so a client that asks for edges without end is refused past the limit, until
// it releases one.
TEST_CASE(video_presentation_client_limits_its_edges)