Truly independent web browser
LibMediaCodecs: Remove what announcing frame storage needed
Zaggy1024153987a85809
diff --git a/Libraries/LibMedia/PlaybackManager.h b/Libraries/LibMedia/PlaybackManager.hindex 448411bbdde..ca7dd9d13dd 100644--- a/Libraries/LibMedia/PlaybackManager.h+++ b/Libraries/LibMedia/PlaybackManager.h@@ -33,7 +33,7 @@#include <LibMedia/Track.h>#include <LibMedia/VideoSinkHandle.h>#include <LibMediaCodecs/DecoderError.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>namespace Media {diff --git a/Libraries/LibMedia/RemoteVideoDecoder.cpp b/Libraries/LibMedia/RemoteVideoDecoder.cppindex 431f238d531..eec02100b08 100644--- a/Libraries/LibMedia/RemoteVideoDecoder.cpp+++ b/Libraries/LibMedia/RemoteVideoDecoder.cpp@@ -19,7 +19,7 @@#include <LibMediaCodecs/VideoDecoderClientEndpoint.h>#include <LibMediaCodecs/VideoDecoderServerEndpoint.h>#include <LibMediaCodecs/VideoFrame.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMediaCodecs/VideoFramePool.h>#include <LibThreading/Thread.h>diff --git a/Libraries/LibMedia/Sinks/RemoteVideoSink.h b/Libraries/LibMedia/Sinks/RemoteVideoSink.hindex 3eae771c28e..f7fbfaf050a 100644--- a/Libraries/LibMedia/Sinks/RemoteVideoSink.h+++ b/Libraries/LibMedia/Sinks/RemoteVideoSink.h@@ -15,7 +15,7 @@#include <LibMedia/Forward.h>#include <LibMedia/MediaTime.h>#include <LibMedia/Sinks/VideoSink.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMediaCodecs/VideoSurface.h>#include <LibThreading/Forward.h>diff --git a/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipc b/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipcindex 5d644860d0e..dd0acf7ba60 100644--- a/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipc+++ b/Libraries/LibMedia/VideoPresentation/VideoPresentationClient.ipc@@ -1,7 +1,7 @@#include <LibMedia/InvalidateHeldData.h>#include <LibMedia/MediaTime.h>#include <LibMedia/PipelineStatus.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMediaCodecs/VideoSurface.h>endpoint VideoPresentationClient {diff --git a/Libraries/LibMediaCodecs/CMakeLists.txt b/Libraries/LibMediaCodecs/CMakeLists.txtindex 495ac6dc07b..de7d4161fb2 100644--- a/Libraries/LibMediaCodecs/CMakeLists.txt+++ b/Libraries/LibMediaCodecs/CMakeLists.txt@@ -18,7 +18,7 @@ set(SOURCESVideoDecoderRegistry.cppVideoDecoderServerConnection.cppVideoFrame.cpp- VideoFrameHandle.cpp+ VideoFrameMetadata.cppVideoFramePool.cppVideoSurface.cpp)diff --git a/Libraries/LibMediaCodecs/Subsampling.h b/Libraries/LibMediaCodecs/Subsampling.hindex 86b73577ea7..aef80791fb9 100644--- a/Libraries/LibMediaCodecs/Subsampling.h+++ b/Libraries/LibMediaCodecs/Subsampling.h@@ -6,8 +6,6 @@#pragma once-#include <AK/Optional.h>-#include <AK/SharedMemoryValue.h>#include <LibGfx/Size.h>namespace Media {@@ -52,19 +50,3 @@ private:};}--template<>-struct AK::SharedMemoryCodec<Media::Subsampling> {- struct Representation {- u8 x { 0 };- u8 y { 0 };- };-- static constexpr Representation encode(Media::Subsampling value) { return { value.x(), value.y() }; }- static constexpr Optional<Media::Subsampling> decode(Representation representation)- {- if (representation.x > 1 || representation.y > 1)- return {};- return Media::Subsampling { representation.x == 1, representation.y == 1 };- }-};diff --git a/Libraries/LibMediaCodecs/VideoDecoderClient.ipc b/Libraries/LibMediaCodecs/VideoDecoderClient.ipcindex 4ea58b62d8e..63741222e7a 100644--- a/Libraries/LibMediaCodecs/VideoDecoderClient.ipc+++ b/Libraries/LibMediaCodecs/VideoDecoderClient.ipc@@ -1,6 +1,6 @@#include <LibCore/AnonymousBuffer.h>#include <LibMediaCodecs/DecoderError.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMediaCodecs/VideoSurface.h>endpoint VideoDecoderClientdiff --git a/Libraries/LibMediaCodecs/VideoDecoderServer.ipc b/Libraries/LibMediaCodecs/VideoDecoderServer.ipcindex ea4b32b6efd..a498a78a480 100644--- a/Libraries/LibMediaCodecs/VideoDecoderServer.ipc+++ b/Libraries/LibMediaCodecs/VideoDecoderServer.ipc@@ -6,7 +6,7 @@#include <LibMediaCodecs/DecoderCapabilities.h>#include <LibMediaCodecs/FrameFlags.h>#include <LibMediaCodecs/VideoDecoder.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>endpoint VideoDecoderServer{diff --git a/Libraries/LibMediaCodecs/VideoDecoderServerConnection.h b/Libraries/LibMediaCodecs/VideoDecoderServerConnection.hindex 628118dcd5a..8cfd5250627 100644--- a/Libraries/LibMediaCodecs/VideoDecoderServerConnection.h+++ b/Libraries/LibMediaCodecs/VideoDecoderServerConnection.h@@ -17,7 +17,7 @@#include <LibMediaCodecs/VideoDecoderClientEndpoint.h>#include <LibMediaCodecs/VideoDecoderRegistry.h>#include <LibMediaCodecs/VideoDecoderServerEndpoint.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>namespace Media {diff --git a/Libraries/LibMediaCodecs/VideoFrameHandle.cpp b/Libraries/LibMediaCodecs/VideoFrameMetadata.cppsimilarity index 57%rename from Libraries/LibMediaCodecs/VideoFrameHandle.cpprename to Libraries/LibMediaCodecs/VideoFrameMetadata.cppindex a54bfaf7166..caf98dd9613 100644--- a/Libraries/LibMediaCodecs/VideoFrameHandle.cpp+++ b/Libraries/LibMediaCodecs/VideoFrameMetadata.cpp@@ -12,7 +12,7 @@#include <LibMediaCodecs/VideoFrame.h>#include <LibMediaCodecs/VideoFramePool.h>-#include "VideoFrameHandle.h"+#include "VideoFrameMetadata.h"namespace Media {@@ -66,41 +66,6 @@ VideoFrameMetadata VideoFrameMetadata::for_frame(VideoFrame const& frame)};}-bool VideoFrameHandle::is_valid() const-{- return metadata().is_valid();-}--VideoFrameMetadata VideoFrameHandle::metadata() const-{- return VideoFrameMetadata {- .timestamp = timestamp.value(),- .duration = duration.value(),- .size = size,- .bit_depth = bit_depth,- .subsampling = subsampling.value(),- .cicp = cicp,- };-}--VideoFrameHandle VideoFrameHandle::for_frame(VideoFrame const& frame)-{- auto const* pool_slot = frame.pool_slot();- VERIFY(pool_slot != nullptr);-- return VideoFrameHandle {- .pool_id = pool_slot->ledger().id(),- .slot_index = pool_slot->slot_index(),- .slot_acquisition_id = pool_slot->slot_acquisition_id(),- .timestamp = frame.timestamp(),- .duration = frame.duration(),- .size = frame.size().to_type<int>(),- .bit_depth = frame.bit_depth(),- .subsampling = frame.subsampling(),- .cicp = frame.cicp(),- };-}-}namespace IPC {@@ -136,41 +101,4 @@ ErrorOr<Media::VideoFrameMetadata> decode(Decoder& decoder)return metadata;}-template<>-ErrorOr<void> encode(Encoder& encoder, Media::VideoFrameHandle const& handle)-{- TRY(encoder.encode(handle.pool_id));- TRY(encoder.encode(handle.slot_index));- TRY(encoder.encode(handle.slot_acquisition_id));- TRY(encoder.encode(handle.timestamp.value()));- TRY(encoder.encode(handle.duration.value()));- TRY(encoder.encode(handle.size));- TRY(encoder.encode(handle.bit_depth));- TRY(encoder.encode(handle.subsampling.value().x()));- TRY(encoder.encode(handle.subsampling.value().y()));- TRY(encoder.encode(handle.cicp));- return {};-}--template<>-ErrorOr<Media::VideoFrameHandle> decode(Decoder& decoder)-{- Media::VideoFrameHandle handle;- handle.pool_id = TRY(decoder.decode<Media::VideoFramePoolID>());- handle.slot_index = TRY(decoder.decode<u32>());- handle.slot_acquisition_id = TRY(decoder.decode<u64>());- handle.timestamp = TRY(decoder.decode<AK::Duration>());- handle.duration = TRY(decoder.decode<AK::Duration>());- handle.size = TRY(decoder.decode<Gfx::IntSize>());- handle.bit_depth = TRY(decoder.decode<u8>());- handle.subsampling = Media::Subsampling {- TRY(decoder.decode<bool>()),- TRY(decoder.decode<bool>()),- };- handle.cicp = TRY(decoder.decode<Media::CodingIndependentCodePoints>());- if (!handle.is_valid())- return Error::from_string_literal("Video frame handle describes a frame that could not have been decoded");- return handle;-}-}diff --git a/Libraries/LibMediaCodecs/VideoFrameHandle.h b/Libraries/LibMediaCodecs/VideoFrameMetadata.hsimilarity index 59%rename from Libraries/LibMediaCodecs/VideoFrameHandle.hrename to Libraries/LibMediaCodecs/VideoFrameMetadata.hindex 7585368c988..0ee5f6378e2 100644--- a/Libraries/LibMediaCodecs/VideoFrameHandle.h+++ b/Libraries/LibMediaCodecs/VideoFrameMetadata.h@@ -6,8 +6,6 @@#pragma once-#include <AK/DistinctNumeric.h>-#include <AK/SharedMemoryValue.h>#include <AK/Time.h>#include <LibGfx/Size.h>#include <LibIPC/Forward.h>@@ -19,8 +17,6 @@namespace Media {-AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, VideoFramePoolID);-// Everything about a decoded frame that a consumer in another process needs to present it, apart from its pixels.struct MEDIACODECS_API VideoFrameMetadata {static VideoFrameMetadata for_frame(VideoFrame const&);@@ -37,30 +33,9 @@ struct MEDIACODECS_API VideoFrameMetadata {CodingIndependentCodePoints cicp;};-// References a frame in a previously-announced pool slot buffer, along with the metadata needed-// to present it. The receiving process resolves it against its mapping of that slot's buffer,-// validating the slot acquisition ID.-struct MEDIACODECS_API VideoFrameHandle {- static VideoFrameHandle for_frame(VideoFrame const&);-- bool is_valid() const;-- VideoFrameMetadata metadata() const;-- VideoFramePoolID pool_id { 0 };- u32 slot_index { 0 };- u64 slot_acquisition_id { 0 };- SharedMemoryValue<AK::Duration> timestamp;- SharedMemoryValue<AK::Duration> duration;- Gfx::IntSize size;- u8 bit_depth { 0 };- SharedMemoryValue<Subsampling> subsampling;- CodingIndependentCodePoints cicp;-};-// How a frame's planes lay out within a pool slot's bytes, aligned for cache- and// SIMD-friendly plane bases. Both the producer writing a decoded frame into a slot and a-// consumer resolving a handle against the slot's buffer derive the same layout.+// consumer reading the frame from the slot's buffer derive the same layout.struct FramePlaneLayout {size_t y_size { 0 };size_t u_offset { 0 };@@ -82,10 +57,4 @@ MEDIACODECS_API ErrorOr<void> encode(Encoder&, Media::VideoFrameMetadata const&)template<>MEDIACODECS_API ErrorOr<Media::VideoFrameMetadata> decode(Decoder&);-template<>-MEDIACODECS_API ErrorOr<void> encode(Encoder&, Media::VideoFrameHandle const&);--template<>-MEDIACODECS_API ErrorOr<Media::VideoFrameHandle> decode(Decoder&);-}diff --git a/Libraries/LibMediaCodecs/VideoFramePool.cpp b/Libraries/LibMediaCodecs/VideoFramePool.cppindex 098a0fdebf9..bf9990dcd99 100644--- a/Libraries/LibMediaCodecs/VideoFramePool.cpp+++ b/Libraries/LibMediaCodecs/VideoFramePool.cpp@@ -4,8 +4,6 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <AK/Atomic.h>-#include <AK/Checked.h>#include <AK/Debug.h>#include <LibGfx/YUVData.h>#include <LibMediaCodecs/VideoFrame.h>@@ -15,42 +13,11 @@namespace Media {-namespace {--constexpr size_t SLOT_DATA_ALIGNMENT = 64;--VideoFramePoolID allocate_pool_id()-{- static Atomic<u64> s_next_id { 1 };- return VideoFramePoolID { s_next_id.fetch_add(1, AK::MemoryOrder::memory_order_relaxed) };-}--struct SlotHeader {- Atomic<u64, AK::MemoryOrder::memory_order_relaxed> slot_acquisition_id { 0 };-};--constexpr size_t slot_data_offset()-{- return align_up_to(sizeof(SlotHeader), SLOT_DATA_ALIGNMENT);-}--SlotHeader& slot_header(Core::AnonymousBuffer& buffer)-{- return *reinterpret_cast<SlotHeader*>(buffer.data<u8>());-}--}-ErrorOr<NonnullRefPtr<VideoFramePool>> VideoFramePool::create(size_t byte_budget){return adopt_nonnull_ref_or_enomem(new (nothrow) VideoFramePool(byte_budget));}-VideoFrameEntryLedger::VideoFrameEntryLedger()- : m_id(allocate_pool_id())-{-}-VideoFrameEntryLedger::~VideoFrameEntryLedger() = default;void VideoFrameEntryLedger::set_slot_freed_callback(Function<void()> slot_freed_callback)@@ -79,7 +46,7 @@ Optional<VideoFramePool::AcquiredSlot> VideoFramePool::try_acquire(size_t byte_ccontinue;if (!free_slot_index.has_value())free_slot_index = index;- if (slot.buffer.is_valid() && slot.buffer.size() - slot_data_offset() == byte_count) {+ if (slot.buffer.is_valid() && slot.buffer.size() == byte_count) {reusable_slot_index = index;break;}@@ -99,12 +66,7 @@ Optional<VideoFramePool::AcquiredSlot> VideoFramePool::try_acquire(size_t byte_c}chosen_slot = &m_slots[*free_slot_index];- Checked<size_t> checked_buffer_size = byte_count;- checked_buffer_size += slot_data_offset();- if (checked_buffer_size.has_overflow())- return {};- auto buffer_size = checked_buffer_size.value();-+ auto buffer_size = byte_count;auto allocated_bytes_after = m_allocated_bytes - chosen_slot->buffer.size() + buffer_size;if (allocated_bytes_after > m_byte_budget) {if (held_slot_count_while_locked() >= MIN_SLOT_COUNT) {@@ -119,41 +81,29 @@ Optional<VideoFramePool::AcquiredSlot> VideoFramePool::try_acquire(size_t byte_creturn {};drop_slot_storage_while_locked(*chosen_slot);chosen_slot->buffer = buffer_result.release_value();- chosen_slot->allocated_buffer_id++;- new (chosen_slot->buffer.data<void>()) SlotHeader;m_allocated_bytes += chosen_slot->buffer.size();}- publish_acquisition_while_locked(*chosen_slot);+ begin_hold_while_locked(*chosen_slot);free_excess_buffers_while_locked();auto slot_index = static_cast<u32>(chosen_slot - m_slots.data());return AcquiredSlot {.index = slot_index,- .slot_acquisition_id = chosen_slot->last_slot_acquisition_id,- .allocated_buffer_id = chosen_slot->allocated_buffer_id,- .bytes = { chosen_slot->buffer.data<u8>() + slot_data_offset(), byte_count },+ .bytes = { chosen_slot->buffer.data<u8>(), byte_count },};}ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> VideoFramePool::try_adopt_acquired_slot(AcquiredSlot const& acquired_slot){- return try_adopt_slot(acquired_slot.index, acquired_slot.slot_acquisition_id, acquired_slot.allocated_buffer_id);+ return try_adopt_slot(acquired_slot.index);}-void VideoFrameEntryLedger::begin_hold_while_locked(Slot& slot, u64 slot_acquisition_id)+void VideoFrameEntryLedger::begin_hold_while_locked(Slot& slot){m_shed_storage_on_release = false;slot.hold_count = 1;- slot.last_slot_acquisition_id = slot_acquisition_id;-}--void VideoFrameEntryLedger::publish_acquisition_while_locked(Slot& slot)-{- begin_hold_while_locked(slot, slot.last_slot_acquisition_id + 1);- slot_header(slot.buffer).slot_acquisition_id.store(slot.last_slot_acquisition_id);- AK::atomic_thread_fence(AK::MemoryOrder::memory_order_seq_cst);}Optional<u32> VideoFrameEntryLedger::try_grow_while_locked()@@ -170,9 +120,9 @@ RefPtr<VideoSurface> VideoFrameEntryLedger::slot_surface(u32 slot_index) constreturn m_slots[slot_index].surface;}-ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> VideoFrameEntryLedger::try_adopt_slot(u32 slot_index, u64 slot_acquisition_id, u64 allocated_buffer_id)+ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> VideoFrameEntryLedger::try_adopt_slot(u32 slot_index){- auto slot_result = try_make_ref_counted<PooledVideoFrameSlot>(*this, slot_index, slot_acquisition_id, allocated_buffer_id);+ auto slot_result = try_make_ref_counted<PooledVideoFrameSlot>(*this, slot_index);if (slot_result.is_error())release_hold(slot_index);return slot_result;@@ -229,8 +179,9 @@ void VideoFrameEntryLedger::add_hold(u32 slot_index)void VideoFrameEntryLedger::release_hold(u32 slot_index){- // The contents go outside the lock, and before the decoder hears that the slot is free, so that it finds the- // surface free to decode into again by the time it looks.+ // The surface and its contents go outside the lock, and before the decoder hears that the slot is free, so that it+ // finds the surface free to decode into again by the time it looks.+ RefPtr<VideoSurface> released_surface;RefPtr<VideoSurfaceContents> released_contents;{MutexLocker locker { m_mutex };@@ -238,12 +189,13 @@ void VideoFrameEntryLedger::release_hold(u32 slot_index)VERIFY(slot.hold_count > 0);if (--slot.hold_count > 0)return;- // The slot keeps the surface itself, to recognize it by when the decoder hands it back.+ released_surface = move(slot.surface);released_contents = move(slot.contents);if (m_shed_storage_on_release)drop_slot_storage_while_locked(slot);}released_contents = nullptr;+ released_surface = nullptr;if (m_slot_freed_callback)m_slot_freed_callback();@@ -271,82 +223,31 @@ Optional<VideoFrameSurfacePool::AcquiredSlot> VideoFrameSurfacePool::try_acquire{MutexLocker locker { m_mutex };- auto slot_index = m_slot_indices_by_surface_id.get(surface->id()).copy();-- if (slot_index.has_value() && m_slots[*slot_index].hold_count != 0) {- // The surface's pixels have not changed while it was held, so the contents already held are the same ones.- auto& held_slot = m_slots[*slot_index];- held_slot.hold_count++;- return AcquiredSlot {- .index = *slot_index,- .slot_acquisition_id = held_slot.last_slot_acquisition_id,- .allocated_buffer_id = held_slot.allocated_buffer_id,- };- }-- if (held_slot_count_while_locked() >= MAX_HELD_SLOT_COUNT)- return {};-- if (!slot_index.has_value()) {- Optional<u32> unused_slot_index;- Optional<u32> evictable_slot_index;- for (u32 index = 0; index < m_slots.size(); index++) {- auto const& slot = m_slots[index];- if (slot.hold_count != 0)- continue;- if (slot.surface == nullptr) {- unused_slot_index = index;- break;- }- if (!evictable_slot_index.has_value() || slot.last_slot_acquisition_id < m_slots[*evictable_slot_index].last_slot_acquisition_id)- evictable_slot_index = index;+ Optional<u32> free_slot_index;+ for (u32 index = 0; index < m_slots.size(); index++) {+ if (m_slots[index].hold_count == 0) {+ free_slot_index = index;+ break;}-- if (!unused_slot_index.has_value() && m_slots.size() < MAX_SLOT_COUNT)- unused_slot_index = try_grow_while_locked();- // A full pool gives up the surface identity it is least likely to be handed again.- if (!unused_slot_index.has_value())- unused_slot_index = evictable_slot_index;- if (!unused_slot_index.has_value())- return {};-- auto buffer_result = Core::AnonymousBuffer::create_with_size(slot_data_offset());- if (buffer_result.is_error())+ }+ if (!free_slot_index.has_value()) {+ if (m_slots.size() >= MAX_HELD_SLOT_COUNT)return {};- if (m_slot_indices_by_surface_id.try_set(surface->id(), *unused_slot_index).is_error())+ free_slot_index = try_grow_while_locked();+ if (!free_slot_index.has_value())return {};-- auto& unused_slot = m_slots[*unused_slot_index];- drop_slot_storage_while_locked(unused_slot);- unused_slot.buffer = buffer_result.release_value();- new (unused_slot.buffer.data<void>()) SlotHeader;- unused_slot.allocated_buffer_id++;- slot_index = unused_slot_index;}- auto& slot = m_slots[*slot_index];+ auto& slot = m_slots[free_slot_index.value()];slot.surface = surface;slot.contents = move(contents);- publish_acquisition_while_locked(slot);-- return AcquiredSlot {- .index = *slot_index,- .slot_acquisition_id = slot.last_slot_acquisition_id,- .allocated_buffer_id = slot.allocated_buffer_id,- };-}--void VideoFrameSurfacePool::drop_slot_storage_while_locked(Slot& slot)-{- if (slot.surface == nullptr)- return;- m_slot_indices_by_surface_id.remove(slot.surface->id());- slot.surface = nullptr;+ begin_hold_while_locked(slot);+ return AcquiredSlot { .index = free_slot_index.value() };}ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> VideoFrameSurfacePool::try_adopt_acquired_slot(AcquiredSlot const& acquired_slot){- return try_adopt_slot(acquired_slot.index, acquired_slot.slot_acquisition_id, acquired_slot.allocated_buffer_id);+ return try_adopt_slot(acquired_slot.index);}ReceivedVideoFrameStorage::ReceivedVideoFrameStorage(Core::AnonymousBuffer pixel_buffer, RefPtr<VideoSurface> surface, u64 sender_id, Function<void()> on_release)@@ -365,15 +266,14 @@ ReceivedVideoFrameStorage::~ReceivedVideoFrameStorage()ErrorOr<Gfx::YUVData> yuv_data_in_slot_buffer(Core::AnonymousBuffer const& slot_buffer, Gfx::IntSize size, u8 bit_depth, Subsampling subsampling, CodingIndependentCodePoints const& cicp){- if (!slot_buffer.is_valid() || slot_buffer.size() <= slot_data_offset())- return Error::from_string_literal("Invalid video frame slot buffer");+ if (!slot_buffer.is_valid() || slot_buffer.size() == 0)+ return Error::from_string_literal("Invalid video frame buffer");auto layout = TRY(frame_plane_layout(size, bit_depth, subsampling));- auto capacity = slot_buffer.size() - slot_data_offset();- if (layout.total_byte_count > capacity)- return Error::from_string_literal("Video frame format does not fit its slot");+ if (layout.total_byte_count > slot_buffer.size())+ return Error::from_string_literal("Video frame format does not fit its buffer");- auto bytes = Bytes { const_cast<u8*>(slot_buffer.data<u8 const>()) + slot_data_offset(), capacity };+ auto bytes = Bytes { const_cast<u8*>(slot_buffer.data<u8 const>()), slot_buffer.size() };return Gfx::YUVData::create(size, bit_depth, subsampling, cicp, bytes.slice(0, layout.y_size), bytes.slice(layout.u_offset, layout.u_size), bytes.slice(layout.v_offset, layout.v_size));}diff --git a/Libraries/LibMediaCodecs/VideoFramePool.h b/Libraries/LibMediaCodecs/VideoFramePool.hindex 47e247081c2..065f6880002 100644--- a/Libraries/LibMediaCodecs/VideoFramePool.h+++ b/Libraries/LibMediaCodecs/VideoFramePool.h@@ -8,7 +8,6 @@#include <AK/AtomicRefCounted.h>#include <AK/Function.h>-#include <AK/HashMap.h>#include <AK/Mutex.h>#include <AK/NonnullRefPtr.h>#include <AK/Optional.h>@@ -16,22 +15,18 @@#include <LibCore/AnonymousBuffer.h>#include <LibGfx/YUVData.h>#include <LibMediaCodecs/Export.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMediaCodecs/VideoSurface.h>namespace Media {class PooledVideoFrameSlot;-// The identity and lifetime bookkeeping shared by every kind of frame pool. Each slot owns a shared-memory buffer-// beginning with the acquisition ID that a remote consumer validates its handle against; what follows the ID is the-// pool's business.+// The lifetime bookkeeping shared by every kind of frame pool: each slot stays held while any frame stored in it is.class MEDIACODECS_API VideoFrameEntryLedger : public AtomicRefCounted<VideoFrameEntryLedger> {public:virtual ~VideoFrameEntryLedger();- VideoFramePoolID id() const { return m_id; }-// The callback runs on whichever thread frees a slot, without the ledger's lock held, and may run concurrently// with itself when separate slots are freed at once.void set_slot_freed_callback(Function<void()>);@@ -50,42 +45,36 @@ public:RefPtr<VideoSurface> slot_surface(u32 slot_index) const;protected:- VideoFrameEntryLedger();+ VideoFrameEntryLedger() = default;- ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> try_adopt_slot(u32 slot_index, u64 slot_acquisition_id, u64 allocated_buffer_id);+ ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> try_adopt_slot(u32 slot_index);struct Slot {Core::AnonymousBuffer buffer;- // A slot keeps its surface once it has one, so that the decoder handing the same one back is recognized.- // Only a held slot has contents, which the decoder gave with the surface and which go with the last hold.+ // Only a held slot has a surface, and the contents the decoder gave with it, which go with the last hold.RefPtr<VideoSurface> surface;RefPtr<VideoSurfaceContents> contents;- u64 last_slot_acquisition_id { 0 };- u64 allocated_buffer_id { 0 };u32 hold_count { 0 };};// Appends a slot with no payload, for a pool that has no free slot to reuse.Optional<u32> try_grow_while_locked();- virtual void drop_slot_storage_while_locked(Slot&) = 0;+ virtual void drop_slot_storage_while_locked(Slot&) { }u32 held_slot_count_while_locked() const;- void publish_acquisition_while_locked(Slot&);- void begin_hold_while_locked(Slot&, u64 slot_acquisition_id);+ void begin_hold_while_locked(Slot&);mutable Mutex m_mutex;Vector<Slot> m_slots;private:- VideoFramePoolID const m_id;Function<void()> m_slot_freed_callback;bool m_shed_storage_on_release { false };};-// A pool of shared-memory framebuffers that are allocated on demand up to a limited budget. Each slot's buffer fd must-// be transmitted over IPC before it can be used, but once that has happened, it will be reused until a different size-// is needed.+// A pool of shared-memory framebuffers that are allocated on demand up to a limited budget. A slot's buffer is reused+// until a different size is needed.class MEDIACODECS_API VideoFramePool final : public VideoFrameEntryLedger {public:static constexpr u32 MIN_SLOT_COUNT = 4;@@ -96,8 +85,6 @@ public:struct AcquiredSlot {u32 index { 0 };- u64 slot_acquisition_id { 0 };- u64 allocated_buffer_id { 0 };Bytes bytes;};// Gets a free slot with the requested capacity if it is available, reallocating the buffer if needed.@@ -117,45 +104,32 @@ private:size_t m_allocated_bytes { 0 };};-// A pool of surfaces produced by a hardware decoder. The decoder allocates and recycles them, so this pool tracks-// their identity and lifetime rather than their memory. Each slot stands for one surface, and the decoder recycles-// more surfaces than it can have held at once, so the pool remembers more slots than it lets be held. The held slot-// count is what bounds how many frames a hardware decoder may have in flight, since the platform's own allocator will-// keep handing out surfaces indefinitely.+// A pool of surfaces produced by a hardware decoder. The decoder allocates and recycles them, so this pool only holds+// each surface for as long as a frame decoded into it is held. The held slot count is what bounds how many frames a+// hardware decoder may have in flight, since the platform's own allocator will keep handing out surfaces indefinitely.class MEDIACODECS_API VideoFrameSurfacePool final : public VideoFrameEntryLedger {public:static constexpr u32 MAX_HELD_SLOT_COUNT = 8;- static constexpr u32 MAX_SLOT_COUNT = 32;static ErrorOr<NonnullRefPtr<VideoFrameSurfacePool>> create();struct AcquiredSlot {u32 index { 0 };- u64 slot_acquisition_id { 0 };- u64 allocated_buffer_id { 0 };};- // Gets the slot already representing this surface, or a free one, so that a recycled surface keeps its identity.- // A surface handed back while its slot is still held, as a frame shown a second time is, gets another hold on- // the acquisition it already has, and the contents given with it are dropped in favor of the ones held.+ // Gets a free slot for the surface, holding it and the contents the decoder gave with it.Optional<AcquiredSlot> try_acquire(NonnullRefPtr<VideoSurface> const&, NonnullRefPtr<VideoSurfaceContents>);ErrorOr<NonnullRefPtr<PooledVideoFrameSlot>> try_adopt_acquired_slot(AcquiredSlot const&);private:VideoFrameSurfacePool() = default;-- void drop_slot_storage_while_locked(Slot&) override;-- HashMap<u32, u32> m_slot_indices_by_surface_id;};// A strong reference to a slot in a frame pool to be used within a single process.class PooledVideoFrameSlot : public AtomicRefCounted<PooledVideoFrameSlot> {public:- PooledVideoFrameSlot(NonnullRefPtr<VideoFrameEntryLedger> ledger, u32 slot_index, u64 slot_acquisition_id, u64 allocated_buffer_id)+ PooledVideoFrameSlot(NonnullRefPtr<VideoFrameEntryLedger> ledger, u32 slot_index): m_ledger(move(ledger)), m_slot_index(slot_index)- , m_slot_acquisition_id(slot_acquisition_id)- , m_allocated_buffer_id(allocated_buffer_id){}@@ -166,14 +140,10 @@ public:VideoFrameEntryLedger& ledger() const { return m_ledger; }u32 slot_index() const { return m_slot_index; }- u64 slot_acquisition_id() const { return m_slot_acquisition_id; }- u64 allocated_buffer_id() const { return m_allocated_buffer_id; }private:NonnullRefPtr<VideoFrameEntryLedger> m_ledger;u32 m_slot_index { 0 };- u64 m_slot_acquisition_id { 0 };- u64 m_allocated_buffer_id { 0 };};// The storage a frame received from another process arrived with, held until the frame is released. Exactly one of the@@ -195,7 +165,7 @@ private:Function<void()> m_on_release;};-// Views the planes laid out within a slot's buffer, failing if they do not fit its capacity.+// Views the planes laid out within a frame's buffer, failing if they do not fit its capacity.MEDIACODECS_API ErrorOr<Gfx::YUVData> yuv_data_in_slot_buffer(Core::AnonymousBuffer const&, Gfx::IntSize, u8 bit_depth, Subsampling, CodingIndependentCodePoints const&);// Builds a frame from the storage another process sent along with its metadata, checking that the storage can holddiff --git a/Libraries/LibMediaCodecs/WindowsMediaFoundation/WindowsMediaFoundationVideoDecoder.cpp b/Libraries/LibMediaCodecs/WindowsMediaFoundation/WindowsMediaFoundationVideoDecoder.cppindex 6c7ef26d4c4..bdcc8982a98 100644--- a/Libraries/LibMediaCodecs/WindowsMediaFoundation/WindowsMediaFoundationVideoDecoder.cpp+++ b/Libraries/LibMediaCodecs/WindowsMediaFoundation/WindowsMediaFoundationVideoDecoder.cpp@@ -18,7 +18,7 @@#include <LibMediaCodecs/Codecs/NALUnit.h>#include <LibMediaCodecs/CodedFrame.h>#include <LibMediaCodecs/VideoFrame.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMediaCodecs/WindowsMediaFoundation/WindowsMediaFoundation.h>#include <LibMediaCodecs/WindowsMediaFoundation/WindowsMediaFoundationVideoDecoder.h>#include <LibThreading/Thread.h>diff --git a/Services/MediaServer/MediaClient.ipc b/Services/MediaServer/MediaClient.ipcindex ca9f2adacb7..86eec9bbddc 100644--- a/Services/MediaServer/MediaClient.ipc+++ b/Services/MediaServer/MediaClient.ipc@@ -11,7 +11,7 @@#include <LibMedia/PlaybackStates/PlaybackState.h>#include <LibMedia/TimeRanges.h>#include <LibMedia/Track.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMedia/VideoSinkHandle.h>endpoint MediaClientdiff --git a/Tests/LibMedia/TestVideoFramePool.cpp b/Tests/LibMedia/TestVideoFramePool.cppindex 7d292686d1d..59cb0b8d382 100644--- a/Tests/LibMedia/TestVideoFramePool.cpp+++ b/Tests/LibMedia/TestVideoFramePool.cpp@@ -15,7 +15,7 @@#include <LibIPC/Encoder.h>#include <LibMediaCodecs/Limits.h>#include <LibMediaCodecs/VideoFrame.h>-#include <LibMediaCodecs/VideoFrameHandle.h>+#include <LibMediaCodecs/VideoFrameMetadata.h>#include <LibMediaCodecs/VideoFramePool.h>#include <LibMediaCodecs/VideoSurface.h>#include <LibTest/TestCase.h>@@ -30,8 +30,7 @@ static NonnullRefPtr<Media::VideoFramePool> make_pool(Function<void()> slot_freereturn pool;}-// The size of one allocated slot buffer, including its header, as observed through the pool's-// byte accounting.+// The size of one allocated slot buffer, as observed through the pool's byte accounting.static size_t measured_slot_buffer_size(size_t byte_count){auto pool = make_pool();@@ -48,26 +47,6 @@ static size_t resolved_frame_byte_count()return MUST(Media::frame_plane_layout(RESOLVED_FRAME_SIZE, RESOLVED_FRAME_BIT_DEPTH, RESOLVED_FRAME_SUBSAMPLING)).total_byte_count;}-static Media::VideoFrameHandle make_handle(Media::VideoFramePool const& pool, Media::VideoFramePool::AcquiredSlot const& slot)-{- return Media::VideoFrameHandle {- .pool_id = pool.id(),- .slot_index = slot.index,- .slot_acquisition_id = slot.slot_acquisition_id,- .timestamp = AK::Duration::from_milliseconds(40),- .duration = AK::Duration::from_milliseconds(20),- .size = RESOLVED_FRAME_SIZE,- .bit_depth = RESOLVED_FRAME_BIT_DEPTH,- .subsampling = RESOLVED_FRAME_SUBSAMPLING,- .cicp = {- Media::ColorPrimaries::BT709,- Media::TransferCharacteristics::BT709,- Media::MatrixCoefficients::BT709,- Media::VideoFullRangeFlag::Full,- },- };-}-static Media::VideoFrameMetadata make_metadata(){return Media::VideoFrameMetadata {@@ -104,23 +83,6 @@ TEST_CASE(acquire_exhaustion_and_release)EXPECT(pool->try_acquire(FRAME_BYTE_COUNT).has_value());}-TEST_CASE(slot_acquisition_ids_increment_per_acquire)-{- auto pool = make_pool();- auto first = pool->try_acquire(FRAME_BYTE_COUNT).release_value();- pool->release_hold(first.index);-- // Acquire until the same slot comes around again.- for (u32 i = 0; i < Media::VideoFramePool::MAX_SLOT_COUNT; i++) {- auto reacquired = pool->try_acquire(FRAME_BYTE_COUNT).release_value();- if (reacquired.index == first.index) {- EXPECT_EQ(reacquired.slot_acquisition_id, first.slot_acquisition_id + 1);- return;- }- }- FAIL("Released slot was never reacquired");-}-TEST_CASE(holds_prevent_recycling){auto pool = make_pool();@@ -153,23 +115,12 @@ TEST_CASE(buffers_are_reused_on_exact_capacity_match)auto reacquired = pool->try_acquire(FRAME_BYTE_COUNT).release_value();EXPECT_EQ(reacquired.index, first.index);EXPECT_EQ(pool->allocated_byte_count(), allocated_after_first);- EXPECT_EQ(reacquired.slot_acquisition_id, first.slot_acquisition_id + 1);pool->release_hold(reacquired.index);- // Give every slot a buffer so that a larger frame must replace one.- Array<u64, Media::VideoFramePool::MAX_SLOT_COUNT> last_slot_acquisition_ids {};- Vector<Media::VideoFramePool::AcquiredSlot> slots;- for (u32 i = 0; i < Media::VideoFramePool::MAX_SLOT_COUNT; i++)- slots.append(pool->try_acquire(FRAME_BYTE_COUNT).release_value());- for (auto const& acquired : slots) {- last_slot_acquisition_ids[acquired.index] = acquired.slot_acquisition_id;- pool->release_hold(acquired.index);- }-- // The replacement keeps the slot's acquisition ID monotonic across buffers.+ // A different byte count needs a buffer of its own.auto larger = pool->try_acquire(FRAME_BYTE_COUNT * 2).release_value();EXPECT(pool->allocated_byte_count() > allocated_after_first);- EXPECT_EQ(larger.slot_acquisition_id, last_slot_acquisition_ids[larger.index] + 1);+ pool->release_hold(larger.index);}TEST_CASE(budget_always_allows_the_liveness_floor)@@ -226,10 +177,6 @@ TEST_CASE(shed_storage_frees_all_but_held_slots)pool->release_hold(held.index);EXPECT_EQ(pool->allocated_byte_count(), 0u);EXPECT_EQ(frame->yuv_data()->y_data()[0], 0x42);-- // Acquiring again allocates fresh with a monotonic acquisition ID.- auto fresh = pool->try_acquire(FRAME_BYTE_COUNT).release_value();- EXPECT(fresh.slot_acquisition_id > held.slot_acquisition_id || fresh.index != held.index);}TEST_CASE(acquisition_ends_shedding_of_held_buffers)@@ -327,11 +274,6 @@ TEST_CASE(slot_freed_callback_wakes_a_waiting_acquirer)EXPECT_EQ(acquired_index.load(), released_index);}-TEST_CASE(pool_ids_are_unique)-{- EXPECT_NE(make_pool()->id(), make_pool()->id());-}-TEST_CASE(received_frames_read_their_buffer_and_release_it_once_dropped){auto pool = make_pool();@@ -413,22 +355,6 @@ TEST_CASE(metadata_that_could_not_have_been_decoded_is_refused_over_ipc)EXPECT(decoder.decode<Media::VideoFrameMetadata>().is_error());}-TEST_CASE(handles_that_could_not_have_been_decoded_are_refused_over_ipc)-{- auto pool = make_pool();- auto slot = pool->try_acquire(resolved_frame_byte_count()).release_value();- auto handle = make_handle(pool, slot);- handle.bit_depth = 13;-- IPC::MessageBuffer message;- IPC::Encoder encoder { message };- MUST(encoder.encode(handle));- Queue<IPC::Attachment> attachments;- FixedMemoryStream stream { message.data().span() };- IPC::Decoder decoder { stream, attachments };- EXPECT(decoder.decode<Media::VideoFrameHandle>().is_error());-}-#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.@@ -467,22 +393,9 @@ static NonnullRefPtr<Media::VideoSurfaceContents> make_contents()return make_contents(s_unwatched_live_count);}-TEST_CASE(surface_pool_keeps_a_recycled_surface_on_its_slot)-{- auto pool = MUST(Media::VideoFrameSurfacePool::create());- auto surface = make_surface();-- auto first = pool->try_acquire(surface, make_contents()).value();- pool->release_hold(first.index);- auto second = pool->try_acquire(surface, make_contents()).value();-- // Announcement is keyed on the slot's buffer generation, so a recycled surface must not appear to be a new one.- EXPECT_EQ(second.index, first.index);- EXPECT_EQ(second.allocated_buffer_id, first.allocated_buffer_id);- EXPECT_NE(second.slot_acquisition_id, first.slot_acquisition_id);-}--TEST_CASE(surface_pool_drops_the_contents_with_the_last_hold)+// The decoder recycles surfaces it is no longer kept from using, and may free them after a while, so the pool lets go+// of a surface and its contents along with its last hold.+TEST_CASE(surface_pool_lets_go_of_a_surface_with_its_last_hold){Atomic<u32> live_contents { 0 };auto pool = MUST(Media::VideoFrameSurfacePool::create());@@ -495,61 +408,15 @@ TEST_CASE(surface_pool_drops_the_contents_with_the_last_hold)pool->release_hold(first.index);EXPECT_EQ(live_contents.load(), 1u);- // The decoder is free to decode into the surface again, which the slot recognizes it for having done because- // it kept the surface through the release.pool->release_hold(first.index);EXPECT_EQ(live_contents.load(), 0u);+ EXPECT_EQ(surface->ref_count(), 1u);+ // A surface handed back while it is still held, as when a frame is shown a second time, takes a slot of its own.auto second = pool->try_acquire(surface, make_contents(live_contents)).value();- EXPECT_EQ(live_contents.load(), 1u);- EXPECT_EQ(second.index, first.index);- EXPECT_EQ(second.allocated_buffer_id, first.allocated_buffer_id);-}--// A decoder can hand a surface back while it is held, as when a frame is shown a second time. The pixels are the-// ones the slot already keeps, so the frame joins the acquisition instead of starting one.-TEST_CASE(surface_pool_holds_a_held_surface_again_when_it_is_handed_back)-{- Atomic<u32> live_contents { 0 };- auto pool = MUST(Media::VideoFrameSurfacePool::create());- auto surface = make_surface();-- auto first = pool->try_acquire(surface, make_contents(live_contents)).value();auto again = pool->try_acquire(surface, make_contents(live_contents)).value();- EXPECT_EQ(again.index, first.index);- EXPECT_EQ(again.slot_acquisition_id, first.slot_acquisition_id);- EXPECT_EQ(live_contents.load(), 1u);-- pool->release_hold(first.index);- EXPECT_EQ(live_contents.load(), 1u);- pool->release_hold(first.index);- EXPECT_EQ(live_contents.load(), 0u);-}--TEST_CASE(shed_storage_releases_surfaces_as_their_holds_run_out)-{- Atomic<u32> live_contents { 0 };- auto pool = MUST(Media::VideoFrameSurfacePool::create());- auto held_surface = make_surface();- auto free_surface = make_surface();-- auto held = pool->try_acquire(held_surface, make_contents(live_contents)).value();- auto freed = pool->try_acquire(free_surface, make_contents(live_contents)).value();- pool->release_hold(freed.index);-- pool->shed_storage();-- // Nothing but this test refers to a surface the pool has let go of, while the held one's pixels are still kept.- EXPECT_EQ(free_surface->ref_count(), 1u);- EXPECT_EQ(live_contents.load(), 1u);-- pool->release_hold(held.index);- EXPECT_EQ(held_surface->ref_count(), 1u);- EXPECT_EQ(live_contents.load(), 0u);-- // The identities went with them, so a surface the pool held through the shed is a stranger to it again.- auto reacquired = pool->try_acquire(held_surface, make_contents(live_contents)).value();- EXPECT_NE(reacquired.allocated_buffer_id, held.allocated_buffer_id);+ EXPECT_NE(again.index, second.index);+ EXPECT_EQ(live_contents.load(), 2u);}TEST_CASE(surface_pool_gives_distinct_surfaces_distinct_slots)@@ -579,73 +446,13 @@ TEST_CASE(surface_pool_refuses_to_exceed_its_held_slot_count)auto surface_too_many = make_surface();EXPECT(!pool->try_acquire(surface_too_many, make_contents()).has_value());-- // A held surface handed back again takes no further slot.- EXPECT(pool->try_acquire(surfaces.first(), make_contents()).has_value());- pool->release_hold(0);+ // A held surface handed back again counts as another frame in flight.+ EXPECT(!pool->try_acquire(surfaces.first(), make_contents()).has_value());pool->release_hold(0);EXPECT(pool->try_acquire(surface_too_many, make_contents()).has_value());}-TEST_CASE(surface_pool_remembers_more_surfaces_than_it_lets_be_held)-{- auto pool = MUST(Media::VideoFrameSurfacePool::create());-- // Decoders cycle through more surfaces than may be held at once, and each one should be announced only once.- static constexpr u32 decoder_surface_count = Media::VideoFrameSurfacePool::MAX_HELD_SLOT_COUNT * 2 + 1;- static_assert(decoder_surface_count <= Media::VideoFrameSurfacePool::MAX_SLOT_COUNT);- Vector<NonnullRefPtr<Media::VideoSurface>> surfaces;- for (u32 index = 0; index < decoder_surface_count; index++)- surfaces.append(make_surface());-- Vector<Media::VideoFrameSurfacePool::AcquiredSlot> first_cycle_acquisitions;- Queue<u32> held_slot_indices;- for (u32 cycle = 0; cycle < 3; cycle++) {- for (u32 index = 0; index < decoder_surface_count; index++) {- if (held_slot_indices.size() == Media::VideoFrameSurfacePool::MAX_HELD_SLOT_COUNT)- pool->release_hold(held_slot_indices.dequeue());- auto acquired = pool->try_acquire(surfaces[index], make_contents()).value();- held_slot_indices.enqueue(acquired.index);- if (cycle == 0) {- first_cycle_acquisitions.append(acquired);- continue;- }- EXPECT_EQ(acquired.index, first_cycle_acquisitions[index].index);- EXPECT_EQ(acquired.allocated_buffer_id, first_cycle_acquisitions[index].allocated_buffer_id);- }- }-}--TEST_CASE(surface_pool_evicts_the_least_recently_acquired_identity_when_full)-{- auto pool = MUST(Media::VideoFrameSurfacePool::create());-- Vector<NonnullRefPtr<Media::VideoSurface>> surfaces;- Vector<Media::VideoFrameSurfacePool::AcquiredSlot> acquisitions;- for (u32 index = 0; index < Media::VideoFrameSurfacePool::MAX_SLOT_COUNT; index++) {- surfaces.append(make_surface());- acquisitions.append(pool->try_acquire(surfaces.last(), make_contents()).value());- pool->release_hold(acquisitions.last().index);- }-- // Every slot remembers a surface, so a surface the pool has never seen has to displace one of them.- auto new_surface = make_surface();- auto acquired = pool->try_acquire(new_surface, make_contents()).value();- EXPECT_EQ(acquired.index, acquisitions.first().index);- EXPECT_NE(acquired.allocated_buffer_id, acquisitions.first().allocated_buffer_id);- pool->release_hold(acquired.index);-- // The surface that was displaced is a stranger again, while the ones still on their slots are not.- auto reacquired_evicted = pool->try_acquire(surfaces.first(), make_contents()).value();- EXPECT_NE(reacquired_evicted.allocated_buffer_id, acquisitions.first().allocated_buffer_id);- pool->release_hold(reacquired_evicted.index);-- auto reacquired_kept = pool->try_acquire(surfaces.last(), make_contents()).value();- EXPECT_EQ(reacquired_kept.index, acquisitions.last().index);- EXPECT_EQ(reacquired_kept.allocated_buffer_id, acquisitions.last().allocated_buffer_id);-}-# ifdef AK_OS_MACOSTEST_CASE(surface_slots_survive_a_mach_port_round_trip){diff --git a/Tests/LibMedia/TestVideoToolboxDecode.cpp b/Tests/LibMedia/TestVideoToolboxDecode.cppindex 5efe34eb31c..87b2a791fa8 100644--- a/Tests/LibMedia/TestVideoToolboxDecode.cpp+++ b/Tests/LibMedia/TestVideoToolboxDecode.cpp@@ -4,7 +4,6 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <AK/HashMap.h>#include <AK/HashTable.h>#include <LibMedia/DemuxerRegistry.h>#include <LibMediaCodecs/CodecParameters.h>@@ -139,39 +138,6 @@ TEST_CASE(surfaces_are_not_reused_while_their_frames_are_held)}}-TEST_CASE(a_recycled_surface_does_not_cost_a_fresh_announcement)-{- auto decoding = open_decoding("./vp9_in_webm.webm"sv, Media::CodecID::VP9);-- // A consumer is told about a slot whenever its buffer generation moves, so this counts what it would hear.- HashTable<u32> distinct_surface_ids;- HashMap<u32, u64> announced_buffer_id_by_slot;- size_t announcements = 0;- size_t frame_count = 0;-- while (frame_count < 24) {- auto frame_result = decoding.next_frame();- if (frame_result.is_error() && decoding_is_unavailable(frame_result.error()))- return;- auto frame = TRY_OR_FAIL(move(frame_result));- auto const* slot = frame->pool_slot();- EXPECT_NE(slot, nullptr);-- auto announced = announced_buffer_id_by_slot.get(slot->slot_index());- if (!announced.has_value() || *announced != slot->allocated_buffer_id()) {- announcements++;- announced_buffer_id_by_slot.set(slot->slot_index(), slot->allocated_buffer_id());- }- distinct_surface_ids.set(frame->surface()->id());- frame_count++;- }-- // Releasing a frame lets the media engine decode into its surface again, and the slot that kept hold of that- // surface recognizes it, so a surface costs one announcement however many frames it carries.- EXPECT(distinct_surface_ids.size() < frame_count);- EXPECT(announcements <= distinct_surface_ids.size());-}-TEST_CASE(storage_runs_out_while_every_frame_is_held){auto decoding = open_decoding("./vp9_in_webm.webm"sv, Media::CodecID::VP9);