From ae009083696b291a6fada63972dcad26041f28df Mon Sep 17 00:00:00 2001 From: Sungtak Lee Date: Wed, 17 Jan 2024 21:35:23 +0000 Subject: [PATCH 1/2] media.bufferpool2: Support receiver side initated buffer transfer Bug: 254050314 Change-Id: I4c1b49e3bb99b8dbdccc44e5e1562833a585d454 --- .../media/bufferpool2/IClientManager.aidl | 1 + .../media/bufferpool2/IClientManager.aidl | 20 ++++++++++++++++++- .../bufferpool/aidl/default/ClientManager.cpp | 8 ++++++++ .../include/bufferpool2/ClientManager.h | 5 +++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/media/bufferpool/aidl/aidl_api/android.hardware.media.bufferpool2/current/android/hardware/media/bufferpool2/IClientManager.aidl b/media/bufferpool/aidl/aidl_api/android.hardware.media.bufferpool2/current/android/hardware/media/bufferpool2/IClientManager.aidl index 5899a403a6..298cb13ec3 100644 --- a/media/bufferpool/aidl/aidl_api/android.hardware.media.bufferpool2/current/android/hardware/media/bufferpool2/IClientManager.aidl +++ b/media/bufferpool/aidl/aidl_api/android.hardware.media.bufferpool2/current/android/hardware/media/bufferpool2/IClientManager.aidl @@ -35,6 +35,7 @@ package android.hardware.media.bufferpool2; @VintfStability interface IClientManager { android.hardware.media.bufferpool2.IClientManager.Registration registerSender(in android.hardware.media.bufferpool2.IAccessor bufferPool); + android.hardware.media.bufferpool2.IClientManager.Registration registerPassiveSender(in android.hardware.media.bufferpool2.IAccessor bufferPool); @VintfStability parcelable Registration { long connectionId; diff --git a/media/bufferpool/aidl/android/hardware/media/bufferpool2/IClientManager.aidl b/media/bufferpool/aidl/android/hardware/media/bufferpool2/IClientManager.aidl index a3054cb131..2bc77bcd68 100644 --- a/media/bufferpool/aidl/android/hardware/media/bufferpool2/IClientManager.aidl +++ b/media/bufferpool/aidl/android/hardware/media/bufferpool2/IClientManager.aidl @@ -40,7 +40,8 @@ interface IClientManager { /** * Sets up a buffer receiving communication node for the specified * buffer pool. A manager must create a IConnection to the buffer - * pool if it does not already have a connection. + * pool if it does not already have a connection. To transfer buffers + * using the interface, the sender must initiates transfer. * * @param bufferPool a buffer pool which is specified with the IAccessor. * The specified buffer pool is the owner of received buffers. @@ -52,4 +53,21 @@ interface IClientManager { * ResultStatus::CRITICAL_ERROR - Other errors. */ Registration registerSender(in IAccessor bufferPool); + + /** + * Sets up a buffer receiving communication node for the specified + * buffer pool. A manager must create a IConnection to the buffer + * pool if it does not already have a connection. To transfer buffers + * using the interface, the receiver must initiates transfer(on demand). + * + * @param bufferPool a buffer pool which is specified with the IAccessor. + * The specified buffer pool is the owner of received buffers. + * @return the Id of the communication node to the buffer pool. + * This id is used in FMQ to notify IAccessor that a buffer has been + * sent to that connection during transfers. + * @throws ServiceSpecificException with one of the following values: + * ResultStatus::NO_MEMORY - Memory allocation failure occurred. + * ResultStatus::CRITICAL_ERROR - Other errors. + */ + Registration registerPassiveSender(in IAccessor bufferPool); } diff --git a/media/bufferpool/aidl/default/ClientManager.cpp b/media/bufferpool/aidl/default/ClientManager.cpp index de1db50cd1..138790d650 100644 --- a/media/bufferpool/aidl/default/ClientManager.cpp +++ b/media/bufferpool/aidl/default/ClientManager.cpp @@ -422,6 +422,14 @@ void ClientManager::Impl::cleanUp(bool clearCache) { return ::ndk::ScopedAStatus::ok(); } +::ndk::ScopedAStatus ClientManager::registerPassiveSender( + const std::shared_ptr& in_bufferPool, Registration* _aidl_return) { + // TODO + (void) in_bufferPool; + (void) _aidl_return; + return ::ndk::ScopedAStatus::fromServiceSpecificError(ResultStatus::NOT_FOUND); +} + // Methods for local use. std::shared_ptr ClientManager::sInstance; std::mutex ClientManager::sInstanceLock; diff --git a/media/bufferpool/aidl/default/include/bufferpool2/ClientManager.h b/media/bufferpool/aidl/default/include/bufferpool2/ClientManager.h index bff75ba597..4b0916f3b8 100644 --- a/media/bufferpool/aidl/default/include/bufferpool2/ClientManager.h +++ b/media/bufferpool/aidl/default/include/bufferpool2/ClientManager.h @@ -34,6 +34,11 @@ struct ClientManager : public BnClientManager { ::aidl::android::hardware::media::bufferpool2::IClientManager::Registration* _aidl_return) override; + ::ndk::ScopedAStatus registerPassiveSender( + const std::shared_ptr& in_bufferPool, + ::aidl::android::hardware::media::bufferpool2::IClientManager::Registration* _aidl_return) + override; + /** Gets an instance. */ static std::shared_ptr getInstance(); From 140f3e8c718adbcd483ca40d2c6ab1754fe52bc1 Mon Sep 17 00:00:00 2001 From: Sungtak Lee Date: Wed, 17 Jan 2024 22:19:28 +0000 Subject: [PATCH 2/2] media c2.aidl: Add IPooledGraphicBufferAllocator support Support media.bufferpool2 based output graphic buffer allocator. Bug: 254050314 Change-Id: I7f21f08582d09b76e9222e002e02a8d8794f08b5 --- .../android/hardware/media/c2/IComponent.aidl | 14 +++- .../c2/IPooledGraphicBufferAllocator.aidl | 49 ++++++++++++ .../android/hardware/media/c2/IComponent.aidl | 27 +++++-- .../c2/IPooledGraphicBufferAllocator.aidl | 77 +++++++++++++++++++ 4 files changed, 158 insertions(+), 9 deletions(-) create mode 100644 media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl create mode 100644 media/c2/aidl/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl diff --git a/media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IComponent.aidl b/media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IComponent.aidl index 4439bc5e43..0a7e3c4b53 100644 --- a/media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IComponent.aidl +++ b/media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IComponent.aidl @@ -51,12 +51,18 @@ interface IComponent { long blockPoolId; android.hardware.media.c2.IConfigurable configurable; } - parcelable C2AidlGbAllocator { - android.hardware.media.c2.IGraphicBufferAllocator igba; + parcelable GbAllocator { ParcelFileDescriptor waitableFd; + android.hardware.media.c2.IGraphicBufferAllocator igba; } - union BlockPoolAllocator { + parcelable PooledGbAllocator { + ParcelFileDescriptor waitableFd; + long receiverId; + android.hardware.media.c2.IPooledGraphicBufferAllocator ipgba; + } + parcelable BlockPoolAllocator { int allocatorId; - android.hardware.media.c2.IComponent.C2AidlGbAllocator allocator; + @nullable android.hardware.media.c2.IComponent.GbAllocator gbAllocator; + @nullable android.hardware.media.c2.IComponent.PooledGbAllocator pooledGbAllocator; } } diff --git a/media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl b/media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl new file mode 100644 index 0000000000..1a8c66d1db --- /dev/null +++ b/media/c2/aidl/aidl_api/android.hardware.media.c2/current/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.media.c2; +@VintfStability +interface IPooledGraphicBufferAllocator { + android.hardware.media.c2.IPooledGraphicBufferAllocator.Allocation allocate(in android.hardware.media.c2.IPooledGraphicBufferAllocator.Description desc); + boolean deallocate(in int id); + parcelable Allocation { + int bufferId; + @nullable ParcelFileDescriptor fence; + } + parcelable Description { + int widthPixels; + int heightPixels; + int format; + long usage; + } +} diff --git a/media/c2/aidl/android/hardware/media/c2/IComponent.aidl b/media/c2/aidl/android/hardware/media/c2/IComponent.aidl index 6bd30b483a..6bcb5ff0ea 100644 --- a/media/c2/aidl/android/hardware/media/c2/IComponent.aidl +++ b/media/c2/aidl/android/hardware/media/c2/IComponent.aidl @@ -23,6 +23,7 @@ import android.hardware.media.c2.IGraphicBufferAllocator; import android.hardware.media.c2.IInputSink; import android.hardware.media.c2.IInputSurface; import android.hardware.media.c2.IInputSurfaceConnection; +import android.hardware.media.c2.IPooledGraphicBufferAllocator; import android.hardware.media.c2.WorkBundle; import android.os.ParcelFileDescriptor; @@ -56,20 +57,36 @@ interface IComponent { * graphic blocks. the waitable fd is used to create a specific type of * C2Fence which can be used for waiting until to allocate is not blocked. */ - parcelable C2AidlGbAllocator { - IGraphicBufferAllocator igba; + parcelable GbAllocator { ParcelFileDescriptor waitableFd; + IGraphicBufferAllocator igba; } + /** + * C2AIDL allocator interface based on media.bufferpool2 along with a waitable fd. + * + * The interface is used from a specific type of C2BlockPool to allocate + * graphic blocks. the waitable fd is used to create a specific type of + * C2Fence which can be used for waiting until to allocate is not blocked. + * receiverId is id of receiver IConnection of media.bufferpool2. + */ + parcelable PooledGbAllocator { + ParcelFileDescriptor waitableFd; + long receiverId; + IPooledGraphicBufferAllocator ipgba; + } + + /** * Allocator for C2BlockPool. * * C2BlockPool will use a C2Allocator which is specified by an id. - * or C2AIDL allocator interface directly. + * Based on allocator id, allocator is specified. */ - union BlockPoolAllocator { + parcelable BlockPoolAllocator { int allocatorId; - C2AidlGbAllocator allocator; + @nullable GbAllocator gbAllocator; + @nullable PooledGbAllocator pooledGbAllocator; } /** diff --git a/media/c2/aidl/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl b/media/c2/aidl/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl new file mode 100644 index 0000000000..b599d52419 --- /dev/null +++ b/media/c2/aidl/android/hardware/media/c2/IPooledGraphicBufferAllocator.aidl @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.media.c2; + +import android.os.ParcelFileDescriptor; + +/** + * Interface for decoder output buffer allocator for HAL process + * + * A graphic buffer for decoder output is allocated by the interface. + */ +@VintfStability +interface IPooledGraphicBufferAllocator { + /** + * A graphic buffer allocation. + * + * bufferId is id of buffer from a media.bufferpool2. The buffer is + * android.hardware.HardwareBuffer. + * fence is provided in order to signal readiness of the buffer I/O inside + * underlying Graphics subsystem. This is called a sync fence throughout Android framework. + */ + parcelable Allocation { + int bufferId; + @nullable ParcelFileDescriptor fence; + } + + /** + * Parameters for a graphic buffer allocation. + * + * Refer to AHardwareBuffer_Desc(libnativewindow) for details. + */ + parcelable Description { + int widthPixels; + int heightPixels; + int format; // AHardwareBuffer_Format + long usage; // AHardwareBuffer_UsageFlags + } + + /** + * Allocate a graphic buffer. + * deallocate() must be called after the allocated buffer is no longer needed. + * + * @param desc Allocation parameters. + * @return an id of a buffer, the id is created from media.bufferpool2 in order for + * caching and recycling, + * If underlying allocator is blocked, c2::Status::Blocked will be returned. + * Waitable fd must be obtained using the ndk object locally. The waitable fd must + * be passed to the receiver during BlockPool creation request via AIDL. + * @throws ServiceSpecificException with one of the following values: + * - `c2::Status::BAD_STATE` - The client is not in running states. + * - `c2::Status::BLOCKED` - Underlying graphics system is blocked. + * - `c2::Status::CORRUPTED` - Some unknown error occurred. + */ + Allocation allocate(in Description desc); + + /** + * De-allocate a graphic buffer by graphic buffer's unique id. + * + * @param id buffer id. + * @return {@code true} when de-allocate happened, {@code false} otherwise. + */ + boolean deallocate(in int id); +}