Truly independent web browser
LibMedia+LibMediaCodecs: Send decoded video frames with their storage
Zaggy1024daf1bfaa888b
diff --git a/Libraries/LibMedia/RemoteVideoDecoder.cpp b/Libraries/LibMedia/RemoteVideoDecoder.cppindex db14170c3c7..431f238d531 100644--- a/Libraries/LibMedia/RemoteVideoDecoder.cpp+++ b/Libraries/LibMedia/RemoteVideoDecoder.cpp@@ -43,8 +43,7 @@ struct EventLoopThread {// Shared by a decoder with the connection that routes its server's answers to it.struct RemoteVideoDecoder::State : public AtomicRefCounted<State> {struct Output {- NonnullRefPtr<PooledVideoFrameSlot> slot;- VideoFrameHandle handle;+ NonnullRefPtr<VideoFrame> frame;};// A coded frame the server has yet to answer, whose data occupies its range of the ring until then.@@ -65,13 +64,12 @@ struct RemoteVideoDecoder::State : public AtomicRefCounted<State> {return count;}- // The outputs are returned to be dropped after the mutex is released, since releasing their slots takes it.+ // The outputs are returned to be dropped after the mutex is released, since releasing their frames takes it.[[nodiscard]] Vector<Output> forget_server_while_locked(){connection_was_lost = true;connection = {};auto forgotten_outputs = move(outputs);- relay_pools.clear();server_is_waiting_for_storage = false;submissions_in_flight.clear();failure.clear();@@ -90,7 +88,6 @@ struct RemoteVideoDecoder::State : public AtomicRefCounted<State> {bool decoder_was_destroyed { false };Vector<Output> outputs;- HashMap<VideoFramePoolID, NonnullRefPtr<VideoFrameRelayPool>> relay_pools;Vector<SubmissionInFlight> submissions_in_flight;Optional<DecoderError> failure;bool drained { false };@@ -102,7 +99,7 @@ struct RemoteVideoDecoder::State : public AtomicRefCounted<State> {// Set once before any frame is submitted, and called after the mutex is released.Function<void()> storage_freed_callback;- // Set while the server waits for a slot to be released, which our caller is then answered TryAgain for. The server+ // Set while the server waits for a frame to be released, which our caller is then answered TryAgain for. The server// reports nothing else while it waits, so anything it reports for the generation it waited in ends the wait too.bool server_is_waiting_for_storage { false };@@ -113,10 +110,10 @@ struct RemoteVideoDecoder::State : public AtomicRefCounted<State> {}// Returns whether the server was waiting for this release, so that the storage freed callback must be called.- [[nodiscard]] bool release_slot_to_server_while_locked(VideoFramePoolID pool_id, u32 slot_index)+ [[nodiscard]] bool release_frame_to_server_while_locked(u64 frame_id){connection.with_target([&](auto& connection) {- connection.async_release_frame(pool_id, slot_index);+ connection.async_release_frame(frame_id);});return clear_server_wait_for_storage_while_locked();}@@ -397,69 +394,41 @@ private:shutdown();}- virtual void video_frame_slot_announced(u64 decoder_id, VideoFramePoolID pool_id, u32 slot_index, Core::AnonymousBuffer slot_buffer, RefPtr<VideoSurface> surface) override+ virtual void frame_decoded(u64 decoder_id, u32 generation, u64 frame_id, VideoFrameMetadata metadata, Core::AnonymousBuffer pixel_buffer, RefPtr<VideoSurface> surface) override{- Optional<Error> misbehavior;- with_decoder(decoder_id, [&](RemoteVideoDecoder::State& state) -> CallerWakeup {- RefPtr<VideoFrameRelayPool> relay_pool;- if (auto existing_relay_pool = state.relay_pools.get(pool_id); existing_relay_pool.has_value())- relay_pool = *existing_relay_pool;- if (!relay_pool) {- // A pool can outlive the server it came from, whose replacement must not count its releases.- auto relay_pool_or_error = VideoFrameRelayPool::create([state = NonnullRefPtr { state }, decoder_id, pool_id](u32 released_slot_index) {- auto server_was_waiting_for_storage = false;- {- MutexLocker locker { state->mutex };- if (state->decoder_id != decoder_id)- return;- server_was_waiting_for_storage = state->release_slot_to_server_while_locked(pool_id, released_slot_index);- }- if (server_was_waiting_for_storage && state->storage_freed_callback)- state->storage_freed_callback();- });- if (relay_pool_or_error.is_error()) {- state.failure = DecoderError::with_description(DecoderErrorCategory::Memory, "Could not create a pool to relay decoded video frames"sv);- return { .has_something_to_take = true };- }- relay_pool = relay_pool_or_error.release_value();- state.relay_pools.set(pool_id, *relay_pool);+ auto state = find_decoder(decoder_id);+ if (!state) {+ async_release_frame(frame_id);+ return;+ }++ // A frame can outlive the server it came from, whose replacement must not hear of its release.+ auto release_to_server = [state, decoder_id, frame_id] {+ auto server_was_waiting_for_storage = false;+ {+ MutexLocker locker { state->mutex };+ if (state->decoder_id != decoder_id)+ return;+ server_was_waiting_for_storage = state->release_frame_to_server_while_locked(frame_id);}- if (auto result = relay_pool->set_slot_storage(slot_index, move(slot_buffer), move(surface)); result.is_error())- misbehavior = result.release_error();- return {};- });- if (misbehavior.has_value())- disconnect_misbehaving_server("unusable slot"sv, *misbehavior);- }+ if (server_was_waiting_for_storage && state->storage_freed_callback)+ state->storage_freed_callback();+ };+ auto frame_or_error = create_received_video_frame(metadata, move(pixel_buffer), move(surface), 0, move(release_to_server));+ if (frame_or_error.is_error()) {+ disconnect_misbehaving_server("unusable frame"sv, frame_or_error.release_error());+ return;+ }- virtual void frame_decoded(u64 decoder_id, u32 generation, VideoFrameHandle handle) override- {- Optional<Error> misbehavior;- auto decoder_is_known = with_decoder(decoder_id, [&](RemoteVideoDecoder::State& state) -> CallerWakeup {- // A frame that nobody wants anymore is returned to the server right away.+ // A frame nobody takes is dropped after the mutex is released, since releasing it takes the mutex.+ RefPtr<VideoFrame> frame = frame_or_error.release_value();+ with_decoder(decoder_id, [&](RemoteVideoDecoder::State& state) -> CallerWakeup {if (generation != state.generation)- return { .storage_was_freed = state.release_slot_to_server_while_locked(handle.pool_id, handle.slot_index) };- auto storage_was_freed = state.clear_server_wait_for_storage_while_locked();- auto relay_pool = state.relay_pools.get(handle.pool_id);- if (!relay_pool.has_value()) {- misbehavior = Error::from_string_literal("The frame is in a pool that was never announced");- return {};- }- auto slot_or_error = (*relay_pool)->try_adopt_published_slot(handle.slot_index, handle.slot_acquisition_id);- if (slot_or_error.is_error()) {- misbehavior = slot_or_error.release_error();return {};- }- state.outputs.append({ slot_or_error.release_value(), handle });+ auto storage_was_freed = state.clear_server_wait_for_storage_while_locked();+ state.outputs.append({ frame.release_nonnull() });return { .has_something_to_take = true, .storage_was_freed = storage_was_freed };});- if (misbehavior.has_value()) {- disconnect_misbehaving_server("unusable frame"sv, *misbehavior);- return;- }- // A decoder that is gone has no use for the frame either.- if (!decoder_is_known)- async_release_frame(handle.pool_id, handle.slot_index);}virtual void decoder_waiting_for_storage(u64 decoder_id, u32 generation) override@@ -569,7 +538,6 @@ RemoteVideoDecoder::~RemoteVideoDecoder()decoder_id = m_state->decoder_id;outputs = move(m_state->outputs);m_state->decoder_was_destroyed = true;- m_state->relay_pools.clear();m_state->output_arrived_callback = nullptr;}connection.with_target([&](auto& connection) {@@ -767,12 +735,12 @@ DecoderErrorOr<NonnullRefPtr<VideoFrame>> RemoteVideoDecoder::take_next_output(C}}- auto const& handle = output->handle;+ auto const& frame = output->frame;auto cicp = container_cicp;- cicp.adopt_specified_values(handle.cicp);+ cicp.adopt_specified_values(frame->cicp());return DECODER_TRY_ALLOC(try_make_ref_counted<VideoFrame>(- handle.timestamp, handle.duration, handle.size.to_type<u32>(),- handle.bit_depth, handle.subsampling, cicp, move(output->slot)));+ frame->timestamp(), frame->duration(), frame->size(),+ frame->bit_depth(), frame->subsampling(), cicp, frame->backing_storage()));}void RemoteVideoDecoder::flush()diff --git a/Libraries/LibMedia/RemoteVideoDecoder.h b/Libraries/LibMedia/RemoteVideoDecoder.hindex 9e3d1cedf5c..0b57e11cd17 100644--- a/Libraries/LibMedia/RemoteVideoDecoder.h+++ b/Libraries/LibMedia/RemoteVideoDecoder.h@@ -24,8 +24,7 @@ namespace Media {// Decodes in the VideoDecoderServer. Coded frames are written to a shared-memory ring and submitted without waiting,// and the server answers each one once it has consumed it. Output is waited for once the current generation's frames// the server has yet to answer reach the maximum in flight, unless the server waits for one of its slots to be-// released here, which is answered with TryAgain. Decoded frames stay in the server's slots, which this process holds-// and lends onward until it releases them.+// released here, which is answered with TryAgain.//// If the server is lost, or answers nothing for too long while it is waited on, the next call reports// NeedsResubmission, and the coded frames submitted after it, starting from a keyframe, go to a new server. A decoderdiff --git a/Libraries/LibMediaCodecs/VideoDecoderClient.ipc b/Libraries/LibMediaCodecs/VideoDecoderClient.ipcindex 4feedef3947..4ea58b62d8e 100644--- a/Libraries/LibMediaCodecs/VideoDecoderClient.ipc+++ b/Libraries/LibMediaCodecs/VideoDecoderClient.ipc@@ -5,10 +5,7 @@endpoint VideoDecoderClient{- // Each new buffer backing a slot is announced once, before the first frame that refers to it.- video_frame_slot_announced(u64 decoder_id, Media::VideoFramePoolID pool_id, u32 slot_index, Core::AnonymousBuffer slot_buffer, RefPtr<Media::VideoSurface> surface) =|- // The decoder keeps the frame's slot until the client releases it.- frame_decoded(u64 decoder_id, u32 generation, Media::VideoFrameHandle handle) =|+ frame_decoded(u64 decoder_id, u32 generation, u64 frame_id, Media::VideoFrameMetadata metadata, Core::AnonymousBuffer pixel_buffer, RefPtr<Media::VideoSurface> surface) =|coded_frame_consumed(u64 decoder_id) =|decoder_failed(u64 decoder_id, u32 generation, Media::DecoderError error) =|decoder_drained(u64 decoder_id, u32 generation) =|diff --git a/Libraries/LibMediaCodecs/VideoDecoderServer.ipc b/Libraries/LibMediaCodecs/VideoDecoderServer.ipcindex 633ff7dca77..ea4b32b6efd 100644--- a/Libraries/LibMediaCodecs/VideoDecoderServer.ipc+++ b/Libraries/LibMediaCodecs/VideoDecoderServer.ipc@@ -22,5 +22,5 @@ endpoint VideoDecoderServersignal_end_of_stream(u64 decoder_id, u32 generation) =|flush(u64 decoder_id, u32 generation) =|- release_frame(Media::VideoFramePoolID pool_id, u32 slot_index) =|+ release_frame(u64 frame_id) =|}diff --git a/Libraries/LibMediaCodecs/VideoDecoderServerConnection.cpp b/Libraries/LibMediaCodecs/VideoDecoderServerConnection.cppindex b41d1cd6aca..ee16d9b00ad 100644--- a/Libraries/LibMediaCodecs/VideoDecoderServerConnection.cpp+++ b/Libraries/LibMediaCodecs/VideoDecoderServerConnection.cpp@@ -289,24 +289,17 @@ private:void send_frame(NonnullRefPtr<VideoFrame> frame){- auto const* pool_slot = frame->pool_slot();- VERIFY(pool_slot != nullptr);- auto& ledger = pool_slot->ledger();- auto slot_index = pool_slot->slot_index();- auto handle = VideoFrameHandle::for_frame(*frame);-- auto& announced_buffer_ids = m_announced_buffer_ids_by_pool.ensure(ledger.id());- auto announced_buffer_id = announced_buffer_ids.get(slot_index);- auto needs_announcement = !announced_buffer_id.has_value() || *announced_buffer_id != pool_slot->allocated_buffer_id();- announced_buffer_ids.set(slot_index, pool_slot->allocated_buffer_id());+ auto metadata = VideoFrameMetadata::for_frame(*frame);+ auto surface = frame->surface();+ Core::AnonymousBuffer pixel_buffer;+ if (!surface)+ pixel_buffer = frame->pixel_buffer();auto should_close_connection = false;m_connection.with_target([&](auto& connection) {- if (needs_announcement)- connection.async_video_frame_slot_announced(m_decoder_id, ledger.id(), slot_index, ledger.slot_buffer(slot_index), ledger.slot_surface(slot_index));// The frame is held before the client hears of it, so that its release cannot arrive first.- connection.hold_frame_until_released(move(frame));- connection.async_frame_decoded(m_decoder_id, m_generation, handle);+ auto frame_id = connection.hold_frame_until_released(move(frame));+ connection.async_frame_decoded(m_decoder_id, m_generation, frame_id, metadata, move(pixel_buffer), move(surface));should_close_connection = connection.should_close_after_decoding_frame();});if (should_close_connection)@@ -346,7 +339,6 @@ private:// The latest submission's, which output the decoder finishes later is taken with as well.Optional<AK::Duration> m_output_target;Core::AnonymousBuffer m_ring;- HashMap<VideoFramePoolID, HashMap<u32, u64>> m_announced_buffer_ids_by_pool;};VideoDecoderServerConnection::VideoDecoderServerConnection(NonnullOwnPtr<IPC::Transport> transport, ReadonlySpan<VideoDecoderRegistration> hosted_decoders)@@ -369,12 +361,12 @@ void VideoDecoderServerConnection::die()entry.value->exit_and_join();m_sessions.clear();- HashMap<HeldSlot, Vector<NonnullRefPtr<VideoFrame>>, HeldSlotTraits> held_frames_by_slot;+ HashMap<u64, NonnullRefPtr<VideoFrame>> held_frames;{MutexLocker locker { m_held_frames_mutex };- held_frames_by_slot = move(m_held_frames_by_slot);+ held_frames = move(m_held_frames);}- held_frames_by_slot.clear();+ held_frames.clear();if (on_death)on_death();@@ -453,28 +445,22 @@ void VideoDecoderServerConnection::flush(u64 decoder_id, u32 generation)(*session)->enqueue(DecoderSession::Flush { generation });}-void VideoDecoderServerConnection::release_frame(VideoFramePoolID pool_id, u32 slot_index)+void VideoDecoderServerConnection::release_frame(u64 frame_id){// The frame is dropped outside the lock, since freeing its slot wakes the decoder thread that may be taking it.- RefPtr<VideoFrame> frame;+ Optional<NonnullRefPtr<VideoFrame>> frame;{MutexLocker locker { m_held_frames_mutex };- auto held_frames = m_held_frames_by_slot.find({ pool_id, slot_index });- if (held_frames == m_held_frames_by_slot.end())- return;- frame = held_frames->value.take_last();- if (held_frames->value.is_empty())- m_held_frames_by_slot.remove(held_frames);+ frame = m_held_frames.take(frame_id);}}-void VideoDecoderServerConnection::hold_frame_until_released(NonnullRefPtr<VideoFrame> frame)+u64 VideoDecoderServerConnection::hold_frame_until_released(NonnullRefPtr<VideoFrame> frame){- auto const* pool_slot = frame->pool_slot();- VERIFY(pool_slot != nullptr);- HeldSlot slot { pool_slot->ledger().id(), pool_slot->slot_index() };MutexLocker locker { m_held_frames_mutex };- m_held_frames_by_slot.ensure(slot).append(move(frame));+ auto frame_id = m_next_held_frame_id++;+ m_held_frames.set(frame_id, move(frame));+ return frame_id;}bool VideoDecoderServerConnection::should_close_after_decoding_frame()diff --git a/Libraries/LibMediaCodecs/VideoDecoderServerConnection.h b/Libraries/LibMediaCodecs/VideoDecoderServerConnection.hindex 6894e34f6a2..628118dcd5a 100644--- a/Libraries/LibMediaCodecs/VideoDecoderServerConnection.h+++ b/Libraries/LibMediaCodecs/VideoDecoderServerConnection.h@@ -22,8 +22,7 @@namespace Media {// The decoding end of the connection between a VideoDecoderServer and its client, hosting the decoders it is given in-// priority order. Each decoder the client creates runs on a thread of its own, reading the coded frames submitted to-// it out of a shared-memory ring. Every frame handed out of a slot stays held here until the client releases it.+// priority order.class MEDIACODECS_API VideoDecoderServerConnection final: public IPC::ConnectionFromClient<VideoDecoderClientEndpoint, VideoDecoderServerEndpoint>, public ThreadSafeWeakable<VideoDecoderServerConnection> {@@ -52,28 +51,19 @@ private:virtual void submit_coded_frame(u64 decoder_id, u32 generation, u64 ring_offset, u64 size, AK::Duration presentation_timestamp, AK::Duration decode_timestamp, AK::Duration duration, FrameFlags flags, Optional<ByteBuffer> new_codec_configuration, DecodeIntent intent, Optional<AK::Duration> output_target) override;virtual void signal_end_of_stream(u64 decoder_id, u32 generation) override;virtual void flush(u64 decoder_id, u32 generation) override;- virtual void release_frame(VideoFramePoolID pool_id, u32 slot_index) override;+ virtual void release_frame(u64 frame_id) override;- // Called from the decoder threads.- void hold_frame_until_released(NonnullRefPtr<VideoFrame>);+ // Callable from the decoder threads.+ u64 hold_frame_until_released(NonnullRefPtr<VideoFrame>);bool should_close_after_decoding_frame();- struct HeldSlot {- VideoFramePoolID pool_id;- u32 slot_index { 0 };-- bool operator==(HeldSlot const&) const = default;- };- struct HeldSlotTraits : public DefaultTraits<HeldSlot> {- static unsigned hash(HeldSlot const& slot) { return pair_int_hash(u64_hash(slot.pool_id.value()), slot.slot_index); }- };-Core::EventLoop& m_event_loop;ReadonlySpan<VideoDecoderRegistration> const m_hosted_decoders;HashMap<u64, NonnullRefPtr<DecoderSession>> m_sessions;Mutex m_held_frames_mutex;- HashMap<HeldSlot, Vector<NonnullRefPtr<VideoFrame>>, HeldSlotTraits> m_held_frames_by_slot;+ HashMap<u64, NonnullRefPtr<VideoFrame>> m_held_frames;+ u64 m_next_held_frame_id { 1 };Atomic<u32> m_frames_until_close { 0 };};diff --git a/Libraries/LibMediaCodecs/VideoFrame.h b/Libraries/LibMediaCodecs/VideoFrame.hindex 21059ef23cf..ff0b227b996 100644--- a/Libraries/LibMediaCodecs/VideoFrame.h+++ b/Libraries/LibMediaCodecs/VideoFrame.h@@ -69,6 +69,7 @@ public:// Converts the pixels to RGBA in memory, wherever they are, if this process can read them.ErrorOr<NonnullRefPtr<Gfx::Bitmap>> to_bitmap() const;+ BackingStorage const& backing_storage() const { return m_backing_storage; }PooledVideoFrameSlot const* pool_slot() const;ReceivedVideoFrameStorage const* received_storage() const;diff --git a/Libraries/LibMediaCodecs/VideoFramePool.cpp b/Libraries/LibMediaCodecs/VideoFramePool.cppindex f28f72d0a61..098a0fdebf9 100644--- a/Libraries/LibMediaCodecs/VideoFramePool.cpp+++ b/Libraries/LibMediaCodecs/VideoFramePool.cpp@@ -247,7 +247,6 @@ void VideoFrameEntryLedger::release_hold(u32 slot_index)if (m_slot_freed_callback)m_slot_freed_callback();- did_free_slot(slot_index);}Core::AnonymousBuffer VideoFrameEntryLedger::slot_buffer(u32 slot_index) const@@ -350,79 +349,6 @@ ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> VideoFrameSurfacePool::try_adopt_acreturn try_adopt_slot(acquired_slot.index, acquired_slot.slot_acquisition_id, acquired_slot.allocated_buffer_id);}-ErrorOr<NonnullRefPtr<VideoFrameRelayPool>> VideoFrameRelayPool::create(AdoptionReleasedCallback adoption_released_callback)-{- return adopt_nonnull_ref_or_enomem(new (nothrow) VideoFrameRelayPool(move(adoption_released_callback)));-}--VideoFrameRelayPool::VideoFrameRelayPool(AdoptionReleasedCallback adoption_released_callback)- : m_adoption_released_callback(move(adoption_released_callback))-{-}--ErrorOr<void> VideoFrameRelayPool::set_slot_storage(u32 slot_index, Core::AnonymousBuffer buffer, RefPtr<VideoSurface> surface)-{- if (slot_index >= MAX_SLOT_COUNT)- return Error::from_string_literal("Relayed video frame slot index is out of range");- if (!buffer.is_valid() || buffer.size() < slot_data_offset())- return Error::from_string_literal("Relayed video frame slot buffer is too small");-- MutexLocker locker { m_mutex };- while (m_slots.size() <= slot_index) {- TRY(m_adoption_counts_by_slot.try_append(0));- TRY(m_slots.try_append({}));- }- auto& slot = m_slots[slot_index];- if (slot.hold_count != 0)- return Error::from_string_literal("Relayed video frame slot was replaced while held");- slot.buffer = move(buffer);- slot.surface = move(surface);- slot.allocated_buffer_id++;- return {};-}--ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> VideoFrameRelayPool::try_adopt_published_slot(u32 slot_index, u64 slot_acquisition_id)-{- u64 allocated_buffer_id = 0;- {- MutexLocker locker { m_mutex };- if (slot_index >= m_slots.size())- return Error::from_string_literal("Relayed video frame refers to a slot that was never announced");- auto& slot = m_slots[slot_index];- if (!slot.buffer.is_valid())- return Error::from_string_literal("Relayed video frame refers to a slot that has no buffer");- if (slot.hold_count != 0) {- if (slot.last_slot_acquisition_id != slot_acquisition_id)- return Error::from_string_literal("Relayed video frame refers to a slot that is still held for an earlier acquisition");- slot.hold_count++;- } else {- if (slot_header(slot.buffer).slot_acquisition_id.load(AK::MemoryOrder::memory_order_acquire) != slot_acquisition_id)- return Error::from_string_literal("Relayed video frame does not match its slot's published acquisition");- begin_hold_while_locked(slot, slot_acquisition_id);- }- m_adoption_counts_by_slot[slot_index]++;- allocated_buffer_id = slot.allocated_buffer_id;- }- return try_adopt_slot(slot_index, slot_acquisition_id, allocated_buffer_id);-}--void VideoFrameRelayPool::drop_slot_storage_while_locked(Slot& slot)-{- slot.buffer = {};- slot.surface = nullptr;-}--void VideoFrameRelayPool::did_free_slot(u32 slot_index)-{- u32 adoption_count = 0;- {- MutexLocker locker { m_mutex };- adoption_count = exchange(m_adoption_counts_by_slot[slot_index], 0u);- }- for (u32 adoption = 0; adoption < adoption_count; adoption++)- m_adoption_released_callback(slot_index);-}-ReceivedVideoFrameStorage::ReceivedVideoFrameStorage(Core::AnonymousBuffer pixel_buffer, RefPtr<VideoSurface> surface, u64 sender_id, Function<void()> on_release): m_pixel_buffer(move(pixel_buffer)), m_surface(move(surface))diff --git a/Libraries/LibMediaCodecs/VideoFramePool.h b/Libraries/LibMediaCodecs/VideoFramePool.hindex e35795b7149..47e247081c2 100644--- a/Libraries/LibMediaCodecs/VideoFramePool.h+++ b/Libraries/LibMediaCodecs/VideoFramePool.h@@ -69,8 +69,6 @@ protected:Optional<u32> try_grow_while_locked();virtual void drop_slot_storage_while_locked(Slot&) = 0;- // Runs after the slot freed callback, from the same thread.- virtual void did_free_slot(u32) { }u32 held_slot_count_while_locked() const;void publish_acquisition_while_locked(Slot&);@@ -150,35 +148,6 @@ private:HashMap<u32, u32> m_slot_indices_by_surface_id;};-// Mirrors a pool in another process, whose frames this process holds and lends onward as its own. The other process-// publishes each acquisition in the slot's buffer and holds the slot once for each frame it hands out of it, until-// this pool releases that hold, so this pool tracks holds without publishing anything. Holds taken here beyond the-// adoptions, by lending a frame onward, are this process's own, so they are not released to the other process.-class MEDIACODECS_API VideoFrameRelayPool final : public VideoFrameEntryLedger {-public:- static constexpr u32 MAX_SLOT_COUNT = max(VideoFramePool::MAX_SLOT_COUNT, VideoFrameSurfacePool::MAX_SLOT_COUNT);-- // Called once for each adoption of a slot, once the slot is no longer held here at all.- using AdoptionReleasedCallback = Function<void(u32 slot_index)>;- static ErrorOr<NonnullRefPtr<VideoFrameRelayPool>> create(AdoptionReleasedCallback);-- // Takes a new buffer for a slot, as the other process announces it. Fails if the slot is still held.- ErrorOr<void> set_slot_storage(u32 slot_index, Core::AnonymousBuffer, RefPtr<VideoSurface>);- // Holds a slot for an acquisition the other process published in the slot's buffer, or holds it once more for- // the acquisition it is already held for.- ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> try_adopt_published_slot(u32 slot_index, u64 slot_acquisition_id);--private:- explicit VideoFrameRelayPool(AdoptionReleasedCallback);-- virtual void drop_slot_storage_while_locked(Slot&) override;- virtual void did_free_slot(u32 slot_index) override;-- AdoptionReleasedCallback m_adoption_released_callback;- // How many times each slot was adopted since it was last free, indexed like the slots.- Vector<u32> m_adoption_counts_by_slot;-};-// A strong reference to a slot in a frame pool to be used within a single process.class PooledVideoFrameSlot : public AtomicRefCounted<PooledVideoFrameSlot> {public:diff --git a/Tests/LibMedia/TestVideoFramePool.cpp b/Tests/LibMedia/TestVideoFramePool.cppindex a3e0c94dcc2..7d292686d1d 100644--- a/Tests/LibMedia/TestVideoFramePool.cpp+++ b/Tests/LibMedia/TestVideoFramePool.cpp@@ -429,32 +429,6 @@ TEST_CASE(handles_that_could_not_have_been_decoded_are_refused_over_ipc)EXPECT(decoder.decode<Media::VideoFrameHandle>().is_error());}-// A frame shown a second time arrives as a second hold on the acquisition its slot is already held for, which must-// not be mistaken for a slot given away while held.-TEST_CASE(relay_pool_holds_a_slot_again_for_the_acquisition_it_already_holds)-{- auto source_pool = MUST(Media::VideoFramePool::create());- auto acquired = source_pool->try_acquire(resolved_frame_byte_count()).release_value();-- auto release_count = 0u;- auto relay_pool = MUST(Media::VideoFrameRelayPool::create([&](u32) { release_count++; }));- MUST(relay_pool->set_slot_storage(acquired.index, source_pool->slot_buffer(acquired.index), nullptr));-- RefPtr<Media::PooledVideoFrameSlot> first_hold = MUST(relay_pool->try_adopt_published_slot(acquired.index, acquired.slot_acquisition_id));- RefPtr<Media::PooledVideoFrameSlot> second_hold = MUST(relay_pool->try_adopt_published_slot(acquired.index, acquired.slot_acquisition_id));- EXPECT(relay_pool->try_adopt_published_slot(acquired.index, acquired.slot_acquisition_id + 1).is_error());- // A frame lent onward holds the slot as well, which the other process never hears of.- relay_pool->add_hold(acquired.index);-- first_hold = nullptr;- EXPECT_EQ(release_count, 0u);- second_hold = nullptr;- EXPECT_EQ(release_count, 0u);- // The other process holds the slot once per frame, so each of those holds is released to it once the slot is free.- relay_pool->release_hold(acquired.index);- EXPECT_EQ(release_count, 2u);-}-#if defined(AK_OS_MACOS) || defined(AK_OS_LINUX)// Stands in for what a decoder gives with a surface to keep its pixels in place, counting how many are alive.