1- /*
2- * If not stated otherwise in this file or this component's LICENSE file the
3- * following copyright and licenses apply:
1+ /* *
2+ * If not stated otherwise in this file or this component's LICENSE
3+ * file the following copyright and licenses apply:
44 *
5- * Copyright 2024 RDK Management
5+ * Copyright 2025 RDK Management
66 *
7- * Licensed under the Apache License, Version 2.0 (the " License" );
8- * you may not use this file except in compliance with the License.
9- * You may obtain a copy of the License at
7+ * Licensed under the Apache License, Version 2.0 (the License);
8+ * you may not use this file except in compliance with the License.
9+ * You may obtain a copy of the License at
1010 *
11- * http://www.apache.org/licenses/LICENSE-2.0
11+ * http://www.apache.org/licenses/LICENSE-2.0
1212 *
13- * Unless required by applicable law or agreed to in writing, software
14- * distributed under the License is distributed on an " AS IS" BASIS,
15- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16- * See the License for the specific language governing permissions and
17- * limitations under the License.
13+ * Unless required by applicable law or agreed to in writing, software
14+ * distributed under the License is distributed on an AS IS BASIS,
15+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ * See the License for the specific language governing permissions and
17+ * limitations under the License.
1818 */
1919
20- #ifndef _IAVBUFFERHELPER_H_
21- #define _IAVBUFFERHELPER_H_
20+ #ifndef _AVBUFFERHELPER_H_
21+ #define _AVBUFFERHELPER_H_
2222
23- #include < stdint.h>
23+ #ifdef __cplusplus
24+ extern " C" {
25+ #endif
2426
25- using namespace com ::rdk::hal;
26- using namespace com ::rdk::hal::avbuffer;
2727
28- /* *
29- * @class IAVBufferHelper
30- * @brief Pure virtual interface for AV buffer helpers.
31- *
32- * This interface defines the API contract for managing buffer handles
33- * in AV pipelines where memory is shared between processes.
34- * It is typically used in pipelines where pipeline elements
35- * are implemented as AIDL HAL components communicating across process boundaries.
36- *
37- * Implementations of this interface are responsible for:
38- * - Mapping a memory handle into process address space
39- * - Unmapping a previously mapped handle
40- * - Writing data into secure buffers
41- * - Copying data between secure buffers
42- *
43- * Vendors must provide an implementation of this interface appropriate
44- * to their platform. Depending on the architecture, this may involve:
45- * - Interacting with a buffer manager service (via AIDL, sockets, or vendor-specific transport)
46- * - Using platform-specific buffer types (DMABUF, ION, TEE-secure buffers)
47- * - Enforcing security / DRM constraints when writing or copying buffers
48- *
49- * A default implementation (`AVBufferHelper`) is typically provided as reference.
50- * Vendors can choose to subclass `AVBufferHelper` or provide a fully custom
51- * implementation of `IAVBufferHelper`.
52- *
53- * NOTE ON SINGLETON ACCESS:
54- * - The interface itself does not provide a static getInstance().
55- * - The default implementation (`AVBufferHelper`) provides a static getInstance()
56- * to simplify usage in typical pipeline nodes.
57- * - If a vendor supplies a custom implementation, they should provide their own
58- * singleton access mechanism or factory registration as appropriate.
59- */
28+ #ifdef __cplusplus
29+ } // extern "C"
30+ #endif
31+
32+ #include < cstdint>
33+
34+ using namespace std ;
35+
6036class IAVBufferHelper
6137{
6238public:
63- /* *
64- * @struct CopyMap
65- * @brief Defines the offsets and size for a memory copy operation.
66- */
67- struct CopyMap
68- {
69- uint32_t src_offset; /* *< The offset from the source handle where copying begins. */
70- uint32_t dst_offset; /* *< The offset in the destination handle where data will be copied. */
71- uint32_t size; /* *< The amount of data to copy, in bytes. */
39+ struct CopyMap {
40+ uint32_t src_offset;
41+ uint32_t dst_offset;
42+ uint32_t size;
7243 };
7344
45+
46+ // helper functions for mapping and unmapping memory from handles
47+ // used in the client code outside of the LinearBufferMgr class
7448 /* *
75- * @brief Destroys the `IAVBufferHelper` object.
49+ * @brief Map memory from the given handle.
50+ * @param handle The handle to map memory from.
51+ * @param[out] size The size of the mapped data
7652 */
77- virtual ~IAVBufferHelper () {}
53+ virtual void * mapHandle ( uint64_t handle, uint32_t * size) = 0;
7854
7955 /* *
80- * @brief Maps memory from a given handle.
81- *
82- * This function is used by client code outside the `LinearBufferMgr` class to
83- * map memory from a specified handle.
84- *
85- * @param[in] handle The handle to map memory from.
86- * @param[out] size A pointer to a `uint32_t` that will be populated with the size of the mapped data.
87- *
88- * @returns A pointer to the mapped memory address, or `nullptr` if the mapping fails.
56+ * @brief Unmap memory from the given handle.
57+ * @param handle The handle to unmap memory from.
58+ * @return True if the memory was successfully unmapped, false otherwise.
8959 */
90- virtual void * mapHandle (uint64_t handle, uint32_t *size ) = 0;
60+ virtual bool unmapHandle (uint64_t handle) = 0;
9161
9262 /* *
93- * @brief Unmaps memory from a given handle.
94- *
95- * @param[in] handle The handle to unmap memory from.
96- *
97- * @retval true If the memory was successfully unmapped.
98- * @retval false If the memory could not be unmapped (e.g., invalid handle).
63+ * @brief Get the size of the memory mapped to the given handle.
64+ * @param handle The handle to get the size from.
65+ * @return The size of the memory mapped to the handle.
9966 */
100- virtual bool unmapHandle (uint64_t handle) = 0;
67+ virtual uint32_t getAllocationSize (uint64_t handle) = 0;
10168
10269 /* *
103- * @brief Writes data from unsecure memory into a secure buffer.
70+ * @brief Write data from unsecure memory into a secure buffer.
71+ * @param handle The handle to write data into.
72+ * @param data The data to write.
73+ * @param size The size of the data to write.
10474 *
105- * @param[in] handle The handle of the secure buffer to write data into.
106- * @param[in] data A pointer to the unsecure data to write.
107- * @param[in] size The size of the data to write, in bytes.
108- *
109- * @retval true If the data was successfully written.
110- * @retval false If the data could not be written (e.g., invalid handle, insufficient space).
75+ * @return True if the data was successfully written, false otherwise.
11176 */
112- virtual bool writeSecureHandle (uint64_t handle, void * data, uint32_t size) = 0;
77+ virtual bool writeSecureHandle (uint64_t handle, void * data, uint32_t size) { return false ; }
11378
11479 /* *
115- * @brief Copies data from one secure buffer to another.
116- *
117- * @param[in] handleTo The handle of the destination secure buffer.
118- * @param[in] handleFrom The handle of the source secure buffer.
119- * @param[in] map The `CopyMap` structure specifying the offsets and size for the copy operation.
120- * @param[in] mapSize The number of indexes in the map.
80+ * @brief Copy data from one secure buffer to another.
81+ * @param handleTo The handle to copy data to.
82+ * @param handleFrom The handle to copy data from.
83+ * @param CopyMap The map of offsets and sizes to copy.
84+ * @param mapSize The number if indexes in the map.
12185 *
122- * @retval true If the data was successfully copied.
123- * @retval false If the data could not be copied (e.g., invalid handles, overlapping regions).
86+ * @return True if the data was successfully copied, false otherwise.
12487 */
125- virtual bool copySecureHandleWithMap (uint64_t handleTo, uint64_t handleFrom, CopyMap map, uint32_t mapSize) = 0;
88+ virtual bool copySecureHandleWithMap (uint64_t handleTo, uint64_t handleFrom, CopyMap map, uint32_t mapSize) { return false ; }
12689};
12790
128- #endif // _IAVBUFFERHELPER_H_
91+ // Factory function to get an instance of the AVBufferHelper
92+ IAVBufferHelper* getAVBufferHelperInstance ();
93+
94+ #endif // _AVBUFFERHELPER_H_
0 commit comments