diff --git a/en/device_api/hdi/.gitignore b/en/device_api/hdi/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/en/device_api/hdi/codec/codec_callback_if.h b/en/device_api/hdi/codec/codec_callback_if.h new file mode 100644 index 0000000000000000000000000000000000000000..c1bd20b95e2a689008393991dc2e68ea03a7ef10 --- /dev/null +++ b/en/device_api/hdi/codec/codec_callback_if.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +/** + * @addtogroup Codec + * @{ + * + * @brief Defines APIs related to the Codec module. + * + * The Codec module provides APIs for initializing the custom data and audio and video codecs, setting codec parameters, and controlling and transferring data. + * + * @since 3.1 + */ + +/** + * @file codec_callback_if.h + * + * @brief Defines the callbacks used to report codec events and processing results of the input and output buffers. + * + * + * + * @since 3.1 + */ + +#ifndef CODEC_CALLBACK_TYPE_H +#define CODEC_CALLBACK_TYPE_H + +#include +#include +#include "codec_component_type.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Defines the callbacks of the Codec module. + * + * The following callbacks are provided: + * 1. Callback used to report component error events, command completion events, and port setting events. For details, see {@link EventHandler}. + * 2. Callback invoked when the input port processes data in the buffer. For details, see {@link EmptyBufferDone}. + * 3. Callback invoked when the output port fills data into the buffer. For details, see {@link FillBufferDone}. + * The callbacks are registered by using: + * 1. {@link CreateComponent} when a component is created. + * 2. {@link SetCallbacks} when the component is in the OMX_StateLoaded state. + */ +struct CodecCallbackType { + struct HdfRemoteService *remote; + + /** + * @brief Reports an event, such as an error, a command completion event, and port setting changes + * during the running of a component. + * + * When eEvent is OMX_EventCmdComplete, eventData is null, and data1 is OMX_COMMANDTYPE, + * data1 indicates a state if data1 is OMX_CommandStateSet and indicates a port in other cases. + * If eEvent is OMX_EventError, data1 indicates an error code and data2 and eventData are both 0. + * If eEvent is OMX_EventMark, data1 and data2 are both 0 and eventData points to the mark. + * When eEvent is OMX_EventPortSettingsChanged, data1 indicates a port and data2 and eventData are 0. + * When eEvent is OMX_EventBufferFlag, data1 indicates a port, data2 indicates a flag, and eventData is 0. + * When eEvent is OMX_EventResourcesAcquired or OMX_EventDynamicResourcesAvailable, the values of data1, data2, and eventData are 0. + * + * @param self Indicates the pointer to the callback to be invoked. + * @param appData Indicates the pointer to the upper-layer instance passed to the callback. + * @param appDataLen Indicates the length of appData, in bytes. + * @param eEvent Indicates the type of events to report. For details, see {@link OMX_EVENTTYPE}. + * @param data1 Indicates data 1 carried in the event. + * @param data2 Indicates data 2 carried in the event. + * @param eventData Indicates the pointer to the data carried in the event. + * @param eventDataLen Indicates the length of eventData, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*EventHandler)(struct CodecCallbackType *self, int8_t *appData, uint32_t appDataLen, + enum OMX_EVENTTYPE eEvent, uint32_t data1, uint32_t data2, int8_t *eventData, uint32_t eventDataLen); + + /** + * @brief Reports an event indicating that the encoding or decoding in the input buffer is complete. + * + * + * + * @param self Indicates the pointer to the callback to be invoked. + * @param appData Indicates the pointer to the upper-layer instance passed to the callback. + * @param appDataLen Indicates the length of appData, in bytes. + * @param buffer Indicates the pointer to the input buffer {@link OmxCodecBuffer} that has data processed. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*EmptyBufferDone)(struct CodecCallbackType *self, int8_t *appData, + uint32_t appDataLen, const struct OmxCodecBuffer *buffer); + + /** + * @brief Reports an event indicating that the output buffer is filled. + * + * + * + * @param self Indicates the pointer to the callback to be invoked. + * @param appData Indicates the pointer to the upper-layer instance passed to the callback. + * @param appDataLen Indicates the length of appData, in bytes. + * @param buffer Indicates the pointer to the buffer {@link OmxCodecBuffer} that has data filled. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*FillBufferDone)(struct CodecCallbackType *self, int8_t* appData, + uint32_t appDataLen, struct OmxCodecBuffer* buffer); +}; + +/** + * @brief Instantiates a CodecCallbackType object. + * + * @param remote Indicates the pointer to the HdfRemoteService. + * + * @return Returns the CodecCallbackType object instantiated. + */ +struct CodecCallbackType *CodecCallbackTypeGet(struct HdfRemoteService *remote); + +/** + * @brief Releases a CodecCallbackType instance. + * + * @param instance Indicates the pointer to the CodecCallbackType instance to release. + */ +void CodecCallbackTypeRelease(struct CodecCallbackType *instance); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // CODEC_CALLBACK_TYPE_H diff --git a/en/device_api/hdi/codec/codec_component_if.h b/en/device_api/hdi/codec/codec_component_if.h new file mode 100644 index 0000000000000000000000000000000000000000..6df0f6e38679011b7564b8962b64c8cfcaab4748 --- /dev/null +++ b/en/device_api/hdi/codec/codec_component_if.h @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +/** + * @addtogroup Codec + * @{ + * + * @brief Defines APIs related to the Codec module. + * + * The Codec module provides APIs for initializing the custom data and audio and video codecs, setting codec parameters, and controlling and transferring data. + * + * @since 3.1 + */ + +/** + * @file codec_component_if.h + * + * @brief Defines the APIs for codec components. + * + * The APIs can be used to obtain component information, send commands to components, set component parameters, and control and transfer buffer data. + * + * @since 3.1 + */ + +#ifndef CODEC_COMPONENT_H +#define CODEC_COMPONENT_H + +#include "codec_callback_if.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Defines the APIs for codec components. + * + * The APIs can be used to: + * Obtain the component version. + * Obtain and set component parameters. + * Send a command to a component to obtain the component status. + * Set a callback. + * Set or release the buffer used by a component. + * Process the input and output buffers for encoding and decoding. + * For details, see the description of the APIs. + */ +struct CodecComponentType { + /** + * @brief Obtains the version of a codec component. + * + * + * + * @param self Indicates the pointer to the target codec component. + * @param compName Indicates the pointer to the component name. + * @param compVersion Indicates the pointer to the OMX component version. For details, see {@link OMX_VERSIONTYPE}. + * @param specVersion Indicates the pointer to the version information of the specifications based on which the component is built. For details, see {@link OMX_VERSIONTYPE}. + * @param compUUID Indicates the pointer to the UUID that uniquely identifies the component. + * @param compUUIDLen Indicates the length of compUUID, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*GetComponentVersion)(struct CodecComponentType *self, char *compName, + union OMX_VERSIONTYPE *compVersion, union OMX_VERSIONTYPE *specVersion, + uint8_t *compUUID, uint32_t compUUIDLen); + + /** + * @brief Sends a command to a component. + * + * If the command is used to set status, a callback will be invoked to return the result. There is no event reporting for other commands. + * + * @param self Indicates the pointer to the target codec component. + * @param cmd Indicates the command to be executed by the component. For details, see {@link OMX_COMMANDTYPE}. + * @param param Indicates the parameters to be carried in the command. + * If cmd is OMX_CommandStateSet, see {@link OMX_STATETYPE} for the value of param. + * If cmd is OMX_CommandFlush, OMX_CommandPortDisable, OMX_CommandPortEnable, or OMX_CommandMarkBuffer, param specifies the target port. + * @param cmdData Indicates the pointer to OMX_MARKTYPE if cmd is OMX_CommandMarkBuffer. + * @param cmdDataLen Indicates the length of cmdData, in bytes. + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*SendCommand)(struct CodecComponentType *self, enum OMX_COMMANDTYPE cmd, uint32_t param, + int8_t *cmdData, uint32_t cmdDataLen); + + /** + * @brief Obtains parameter settings of a component. + * + * When a component is in a state other than OMX_StateInvalid, you can call this API to obtain component parameters. + * + * @param self Indicates the pointer to the target codec component. + * @param paramIndex Indicates the index of the structure to fill. For details, see {@link OMX_INDEXTYPE}. + * @param paramStruct Indicates the pointer to the structure, allocated by the application, to be filled by the component. + * @param paramStructLen Indicates the length of paramStruct, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*GetParameter)(struct CodecComponentType *self, uint32_t paramIndex, int8_t *paramStruct, + uint32_t paramStructLen); + + /** + * @brief Sets parameters for a component. + * + * This API can be used to set component parameters when the component is in the OMX_StateLoaded or OMX_StateWaitForResources state or the port is disabled. + * + * @param self Indicates the pointer to the target codec component. + * @param index Indicates the index of the structure to set. For details, see {@link OMX_INDEXTYPE}. + * @param paramStruct Indicates the pointer to the structure allocated by the application for component initialization. + * @param paramStructLen Indicates the length of paramStruct, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*SetParameter)(struct CodecComponentType *self, uint32_t index, int8_t *paramStruct, + uint32_t paramStructLen); + + /** + * @brief Obtains the configuration of a component. + * + * This API can be used to obtain the component configuration after a component is loaded. + * + * @param self Indicates the pointer to the target codec component. + * @param index Indicates the index of the structure to fill. For details, see {@link OMX_INDEXTYPE}. + * @param cfgStruct Indicates the pointer to the structure, allocated by the application, to be filled by the component. + * @param cfgStructLen Indicates the length of cfgStruct, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*GetConfig)(struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen); + + /** + * @brief Sets the component parameters. + * + * This API can be used to set a component after it is loaded. + * + * @param self Indicates the pointer to the target codec component. + * @param index Indicates the index of the structure to set. For details, see {@link OMX_INDEXTYPE}. + * @param cfgStruct Indicates the pointer to the structure allocated by the application for component initialization. + * @param cfgStructLen Indicates the length of cfgStruct, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*SetConfig)(struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen); + + /** + * @brief Obtains the extended index of a component based on a given string. + * + * This API converts an extended string into an Openmax IL structure index. + * + * @param self Indicates the pointer to the target codec component. + * @param paramName Indicates the pointer to the string to be converted. + * @param indexType Indicates the pointer to the configuration index converted from the given paramName. For details, see {@link OMX_INDEXTYPE}. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*GetExtensionIndex)(struct CodecComponentType *self, const char *paramName, uint32_t *indexType); + + /** + * @brief Obtains component status. + * + * For details about component status, see {@link OMX_STATETYPE}. + * + * @param self Indicates the pointer to the target codec component. + * @param state Indicates the pointer to the status obtained. For more details, see {@link OMX_STATETYPE}. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*GetState)(struct CodecComponentType *self, enum OMX_STATETYPE *state); + + /** + * @brief Sets tunnel communication for a component. + * + * When a component is in the OMX_StateLoaded state, you can call this API to set tunnel communication if the component supports tunnel transmission. + * + * @param self Indicates the pointer to the target codec component. + * @param port Indicates the port to set for the component. + * @param tunneledComp Indicates the tunnel handle of the component. + * @param tunneledPort Indicates the port to be used for tunnel communication. + * @param tunnelSetup Indicates the pointer to the tunnel structure set. For details, see {@link OMX_TUNNELSETUPTYPE}. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*ComponentTunnelRequest)(struct CodecComponentType *self, uint32_t port, + int32_t tunneledComp, uint32_t tunneledPort, struct OMX_TUNNELSETUPTYPE *tunnelSetup); + + /** + * @brief Specify the buffer of the component port. + * + * This API is used when: + * The component is in the OMX_StateLoaded state, and has sent a request for changing the state to OMX_StateIdle. + * The component is in the OMX_StateWaitForResources state, the required resources are available, and the component is ready to enter the OMX_StateIdle state. + * The component is in the OMX_StateExecuting, OMX_StatePause, or OMX_StateIdle state on a disabled port. + * + * @param self Indicates the pointer to the target codec component. + * @param portIndex Indicates the port of the component. + * @param buffer Indicates the pointer to the buffer to use. For details, see {@link OmxCodecBuffer}. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*UseBuffer)(struct CodecComponentType *self, uint32_t portIndex, struct OmxCodecBuffer *buffer); + + /** + * @brief Requests a port buffer from the component. + * + * This API is used to request a new buffer from a component when: + * The component is in the OMX_StateLoaded state and has sent a request for changing the state to OMX_StateIdle. + * The component is in the OMX_StateWaitForResources state, the required resources are available, and the component is ready to enter the OMX_StateIdle state. + * The component is in the OMX_StateExecuting, OMX_StatePause, or OMX_StateIdle state on a disabled port. + * + * @param self Indicates the pointer to the target codec component. + * @param buffer Indicates the pointer to the buffer requested. For details, see {@link OmxCodecBuffer}. + * @param portIndex Indicates the port of the component. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*AllocateBuffer)(struct CodecComponentType *self, struct OmxCodecBuffer *buffer, uint32_t portIndex); + + /** + * @brief Releases a buffer. + * + * This API is used to release a buffer when: + * The component is in the OMX_StateIdle state and has sent a request for changing the state to OMX_StateLoaded. + * The component is in the OMX_StateExecuting, OMX_StatePause, or OMX_StateIdle state on a disabled port. + * This API can be called at any time. However, if it is not called in any of the previous conditions, the component may report an OMX_ErrorPortUnpopulated event. + * + * @param self Indicates the pointer to the target codec component. + * @param portIndex Indicates the port of the component. + * @param buffer Indicates the pointer to the buffer to release. For details, see {@link OmxCodecBuffer}. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*FreeBuffer)(struct CodecComponentType *self, uint32_t portIndex, const struct OmxCodecBuffer *buffer); + + /** + * @brief Specify the buffer to be emptied by a component. + * + * This API should be called when the component is in the OMX_StateExecuting or OMX_StatePause state. + * + * @param self Indicates the pointer to the target codec component. + * @param buffer Indicates the pointer to the {@link OmxCodecBuffer} structure. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*EmptyThisBuffer)(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer); + + /** + * @brief Specify the buffer to be filled with the encoding and decoding output by a component. + * + * This API should be called when the component is in the OMX_StateExecuting or OMX_StatePause state. + * + * @param self Indicates the pointer to the target codec component. + * @param buffer Indicates the pointer to the {@link OmxCodecBuffer} structure. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*FillThisBuffer)(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer); + + /** + * @brief Set a callback for the codec component. + * + * This API is called to report an event or report available input or output information when the component is in the OMX_StateLoaded state. + * + * @param self Indicates the pointer to the target codec component. + * @param callback Indicates the pointer to the {@link CodecCallbackType} object. + * @param appData Indicates the pointer to the value defined by the application. The value is returned by the callback. + * @param appDataLen Indicates the length of appData, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*SetCallbacks)(struct CodecComponentType *self, struct CodecCallbackType *callback, + int8_t *appData, uint32_t appDataLen); + + /** + * @brief Deinitializes a component. + * + * This API can be called to close a component in the OMX_StateLoaded state. + * + * @param self Indicates the pointer to the codec component to close. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*ComponentDeInit)(struct CodecComponentType *self); + + /** + * @brief Uses the space allocated by EGL. + * + * This API is used when: + * The component is in the OMX_StateLoaded state and has sent a request for changing the state to OMX_StateIdle. + * The component is in the OMX_StateWaitForResources state, the required resources are available, and the component is ready to enter the OMX_StateIdle state. + * The component is in the OMX_StateExecuting, OMX_StatePause, or OMX_StateIdle state on a disabled port. + * + * @param self Indicates the pointer to the target codec component. + * @param buffer Indicates the pointer to the {@link OmxCodecBuffer} structure. + * @param portIndex Indicates the port of the component. + * @param eglImage Indicates the pointer to the image provided by EGL. + * @param eglImageLen Indicates the length of eglImage, in bytes. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*UseEglImage)(struct CodecComponentType *self, struct OmxCodecBuffer *buffer, uint32_t portIndex, + int8_t *eglImage, uint32_t eglImageLen); + + /** + * @brief Obtains the component role. + * + * This API is used to obtain the role of a component based on the role index. + * + * @param self Indicates the pointer to the target codec component. + * @param role Indicates the pointer to the role name. + * @param roleLen Indicates the length of the role, in bytes. + * @param index Indicates the index of a role. A component may support multiple roles. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*ComponentRoleEnum)(struct CodecComponentType *self, uint8_t *role, uint32_t roleLen, uint32_t index); +}; + +/** + * @brief Instantiates a CodecComponentType object. + * + * @param remote Indicates the pointer to the RemoteService. + * + * @return Returns the CodecComponentType object instantiated. + */ +struct CodecComponentType *CodecComponentTypeGet(struct HdfRemoteService *remote); + +/** + * @brief Releases a CodecComponentType object. + * + * @param instance Indicates the pointer to the CodecComponentType object to release. + */ +void CodecComponentTypeRelease(struct CodecComponentType *instance); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // CODEC_COMPONENT_H diff --git a/en/device_api/hdi/codec/codec_component_manager.h b/en/device_api/hdi/codec/codec_component_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..8ff03d51f23bb8aaa0bb770c4cced6611e181698 --- /dev/null +++ b/en/device_api/hdi/codec/codec_component_manager.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +/** + * @addtogroup Codec + * @{ + * + * @brief Defines APIs related to the Codec module. + * + * The Codec module provides APIs for initializing the custom data and audio and video codecs, setting codec parameters, and controlling and transferring data. + * + * @since 3.1 + */ + +/** + * @file codec_component_manager.h + * + * @brief Provides APIs for managing the Codec component. + * + * The APIs can be used to obtain the component encoding and decoding capability list, and create or destroy components for the Codec module. + * + * @since 3.1 + */ + +#ifndef CODEC_COMPONENT_MANAGER_H +#define CODEC_COMPONENT_MANAGER_H + +#include "codec_component_if.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +/** + * @brief Defines the APIs for managing the codec components. + * + * The APIs can be used to: + * Obtain the number of codec components and a codec capability list. + * Create or destroy a codec component. + */ +struct CodecComponentManager { + /** + * @brief Obtains the number of codec components. + * + * All codec capability sets can be further obtained based on the number of codec components. + * + * @return Returns the number of codec components obtained. + */ + int32_t (*GetComponentNum)(); + + /** + * @brief Obtains the codec capability list. + * + * You can use this API to obtain the encoding and decoding capabilities provided by the Codec module. The capability is represented in the {@link CodecCompCapability} structure. + * + * @param capList Indicates the pointer to the component capability list {@link CodecCompCapability} obtained. + * @param count Indicates the number of codec components, which is obtained by {@link GetComponentNum}. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*GetComponentCapabilityList)(CodecCompCapability *capList, int32_t count); + + /** + * @brief Creates a codec instance. + * + * You can use this API to create a codec component instance based on the component name. + * + * @param component Indicates the pointer to the codec component created. + * @param compName Indicates the name of the component to create. + * @param appData Indicates the pointer to the value defined by the application. The value is returned by the callback. + * @param appDataSize Indicates the length of appData, in bytes. + * @param callbacks Indicates the pointer to the callback defined by OMX_CALLBACKTYPE. For details, see {@link CodecCallbackType}. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*CreateComponent)(struct CodecComponentType **component, char *compName, void *appData, + int32_t appDataSize, struct CodecCallbackType *callbacks); + + /** + * @brief Destroys a codec component instance. + * + * + * + * @param component Indicates the codec component to destroy. + * + * @return Returns HDF_SUCCESS if the operation is successful. + * @return Returns HDF_ERR_INVALID_PARAM if the operation failed due to invalid parameters. + * @return Returns HDF_ERR_INVALID_OBJECT if the operation failed due to invalid objects. + * @return Returns HDF_ERR_MALLOC_FAIL if the operation failed due to insufficient memory. + */ + int32_t (*DestoryComponent)(struct CodecComponentType *component); +}; + +/** + * @brief Instantiates the CodecComponentManager object. + * + * @return Returns the CodecComponentManager object instantiated. + */ +struct CodecComponentManager *GetCodecComponentManager(void); + +/** + * @brief Releases the CodecComponentManager object. + */ +void CodecComponentManagerRelease(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* CODEC_COMPONENT_MANAGER_H */ +/** @} */ diff --git a/en/device_api/hdi/codec/codec_component_type.h b/en/device_api/hdi/codec/codec_component_type.h new file mode 100644 index 0000000000000000000000000000000000000000..85ac42be067a742ee61598c90f54dd7a5e76952e --- /dev/null +++ b/en/device_api/hdi/codec/codec_component_type.h @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +/** + * @addtogroup Codec + * @{ + * + * @brief Defines APIs related to the Codec module. + * + * The Codec module provides APIs for initializing the custom data and audio and video codecs, setting codec parameters, and controlling and transferring data. + * + * @since 3.1 + */ + +/** + * @file codec_component_type.h + * + * @brief Declares custom data types used in the Codec module APIs, including the codec types, audio and video parameters, and buffers. + * + * + * + * @since 3.1 + */ + +#ifndef CODEC_COMPONENT_TYPE_H +#define CODEC_COMPONENT_TYPE_H + +#include +#include +#include "OMX_Types.h" +#include "OMX_Index.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +/** + * @brief Defines the maximum value of the sampling format. + */ +#define SAMPLE_FMT_NUM 32 + +/** + * @brief Enumerates the codec types. + */ +typedef enum { + /** Video decoder */ + VIDEO_DECODER, + /** Video encoder */ + VIDEO_ENCODER, + /** Audio decoder */ + AUDIO_DECODER, + /** Audio encoder */ + AUDIO_ENCODER, + /** Invalid type */ + INVALID_TYPE +} CodecType; + +/** + * @brief Enumerates the types of audio and video encoding/decoding components. + */ +typedef enum { + /** JPEG image */ + MEDIA_ROLETYPE_IMAGE_JPEG = 0, + /** H.264 video */ + MEDIA_ROLETYPE_VIDEO_AVC, + /** H.265 video */ + MEDIA_ROLETYPE_VIDEO_HEVC, + /** Audio codec */ + MEDIA_ROLETYPE_AUDIO_FIRST = 0x10000, + /** Advanced Audio Coding (AAC) */ + MEDIA_ROLETYPE_AUDIO_AAC = 0x10000, + /** G711A audio */ + MEDIA_ROLETYPE_AUDIO_G711A, + /** G711U audio */ + MEDIA_ROLETYPE_AUDIO_G711U, + /** G726 audio */ + MEDIA_ROLETYPE_AUDIO_G726, + /** Pulse-Code Modulation (PCM) audio */ + MEDIA_ROLETYPE_AUDIO_PCM, + /** MP3 */ + MEDIA_ROLETYPE_AUDIO_MP3, + /** Invalid type */ + MEDIA_ROLETYPE_INVALID, +} AvCodecRole; + +/** + * @brief Enumerates the codec profiles. + */ +typedef enum { + /** Invalid profile */ + INVALID_PROFILE = 0, + /** AAC-Low Complex */ + AAC_LC_PROFILE = 0x1000, + /** AAC-Main */ + AAC_MAIN_PROFILE, + /** HEAAC, AAC+, or AACPlusV1 */ + AAC_HE_V1_PROFILE, + /** AAC++ or AACPlusV2 */ + AAC_HE_V2_PROFILE, + /** AAC-Low Delay */ + AAC_LD_PROFILE, + /** AAC-Enhanced Low Delay */ + AAC_ELD_PROFILE, + /** H.264 Baseline */ + AVC_BASELINE_PROFILE = 0x2000, + /** H.264 Main */ + AVC_MAIN_PROFILE, + /** H.264 High */ + AVC_HIGH_PROFILE, + /** H.265 Main */ + HEVC_MAIN_PROFILE = 0x3000, + /** H.265 Main 10 */ + HEVC_MAIN_10_PROFILE, +} Profile; + +/** +* @brief Defines the alignment. + */ +typedef struct { + int32_t widthAlginment; /** Value to align with the width */ + int32_t heightAlginment; /** Value to align with the height */ +} Alginment; + +/** + * @brief Defines a rectangle. + */ +typedef struct { + int32_t width; /** Width of the rectangle */ + int32_t height; /** Height of the rectangle */ +} Rect; + +/** + * @brief Defines a value range. + */ +typedef struct { + int32_t min; /** Minimum value */ + int32_t max; /** Maximum value */ +} RangeValue; + +/** + * @brief Enumerates the playback capabilities. + */ +typedef enum { + /** Adaptive playback */ + CODEC_CAP_ADAPTIVE_PLAYBACK = 0x1, + /** Secure playback */ + CODEC_CAP_SECURE_PLAYBACK = 0x2, + /** Tunnel playback */ + CODEC_CAP_TUNNEL_PLAYBACK = 0x4, + /** Multi-plane (video image plane and audio tunnel plane) playback */ + CODEC_CAP_MULTI_PLANE = 0x10000, +} CodecCapsMask; + +/** + * @brief Enumerates the audio sampling rates. + */ +typedef enum { + /** 8 kHz */ + AUD_SAMPLE_RATE_8000 = 8000, + /** 12 kHz */ + AUD_SAMPLE_RATE_12000 = 12000, + /** 11.025 kHz */ + AUD_SAMPLE_RATE_11025 = 11025, + /** 16 kHz */ + AUD_SAMPLE_RATE_16000 = 16000, + /** 22.050 kHz */ + AUD_SAMPLE_RATE_22050 = 22050, + /** 24 kHz */ + AUD_SAMPLE_RATE_24000 = 24000, + /** 32 kHz */ + AUD_SAMPLE_RATE_32000 = 32000, + /** 44.1 kHz */ + AUD_SAMPLE_RATE_44100 = 44100, + /** 48 kHz */ + AUD_SAMPLE_RATE_48000 = 48000, + /** 64 kHz */ + AUD_SAMPLE_RATE_64000 = 64000, + /** 96 kHz */ + AUD_SAMPLE_RATE_96000 = 96000, + /** Invalid sampling rate */ + AUD_SAMPLE_RATE_INVALID, +} AudioSampleRate; + +/** + * @brief Enumerate the audio sampling formats. + * + * For the planar sampling format, the data of each channel is independently stored in data. + * For the packed sampling format, only the first data is used, and the data of each channel is interleaved. + */ +typedef enum { + /** Unsigned 8 bits, packed */ + AUDIO_SAMPLE_FMT_U8, + /** Signed 16 bits, packed */ + AUDIO_SAMPLE_FMT_S16, + /** Signed 32 bits, packed */ + AUDIO_SAMPLE_FMT_S32, + /** Float, packed */ + AUDIO_SAMPLE_FMT_FLOAT, + /** Double, packed */ + AUDIO_SAMPLE_FMT_DOUBLE, + /** Unsigned 8 bits, planar */ + AUDIO_SAMPLE_FMT_U8P, + /** Signed 16 bits, planar */ + AUDIO_SAMPLE_FMT_S16P, + /** Signed 32 bits, planar */ + AUDIO_SAMPLE_FMT_S32P, + /** Float, planar */ + AUDIO_SAMPLE_FMT_FLOATP, + /** Double, planar */ + AUDIO_SAMPLE_FMT_DOUBLEP, + /** Invalid sampling format */ + AUDIO_SAMPLE_FMT_INVALID, +} AudioSampleFormat; + +/** + * @brief Defines the video encoding and decoding capabilities. + */ +#define PIX_FORMAT_NUM 16 /** Size of the supported pixel format array */ +typedef struct { + Rect minSize; /** Minimum resolution supported. */ + Rect maxSize; /** Maximum resolution supported. */ + Alignment whAlignment; /** Values to align with the width and height. */ + RangeValue blockCount; /** Number of blocks supported. */ + RangeValue blocksPerSecond; /** Number of blocks processed per second. */ + Rect blockSize; /** Block size supported. */ + int32_t supportPixFmts[PIX_FORMAT_NUM]; /** Supported pixel format. For details, see {@link OMX_COLOR_FORMATTYPE}. */ +} VideoPortCap; + +/** + * @brief Defines the video encoding and decoding capabilities. + */ +#define SAMPLE_FORMAT_NUM 12 /** Size of the audio sampling format array supported. */ +#define SAMPLE_RATE_NUM 16 /** Size of the audio sampling rate array supported. */ +#define CHANNEL_NUM 16 /** Size of the audio channel array supported. */ +typedef struct { + int32_t sampleFormats[SAMPLE_FMT_NUM]; /** Supported audio sampling formats. For details, see {@link AudioSampleFormat}. */ + int32_t sampleRate[SAMPLE_RATE_NUM]; /** Supported audio sampling rates. For details, see {@link AudioSampleRate}. */ + int32_t channelLayouts[CHANNEL_NUM]; /** Supported audio channel layouts. */ + int32_t channelCount[CHANNEL_NUM]; /** Supported audio channels. */ +} AudioPortCap; + +/** + * @brief Defines the audio and video encoding and decoding capabilities. + */ +typedef union { + VideoPortCap video; /** Video encoding and decoding capabilities */ + AudioPortCap audio; /** Audio encoding and decoding capabilities */ +} PortCap; + +/** + * @brief Enumerates the codec processing modes. + */ +typedef enum { + /** Input buffer in sync mode */ + PROCESS_BLOCKING_INPUT_BUFFER = 0X1, + /** Output buffer in sync mode */ + PROCESS_BLOCKING_OUTPUT_BUFFER = 0X2, + /** Control flow in sync mode */ + PROCESS_BLOCKING_CONTROL_FLOW = 0X4, + /** Input buffer in async mode */ + PROCESS_NONBLOCKING_INPUT_BUFFER = 0X100, + /** Output buffer in async mode */ + PROCESS_NONBLOCKING_OUTPUT_BUFFER = 0X200, + /** Control flow in async mode */ + PROCESS_NONBLOCKING_CONTROL_FLOW = 0X400, +} CodecProcessMode; + +/** + * @brief Defines the codec capabilities. + */ +#define NAME_LENGTH 32 /** Size of the component name. */ +#define PROFILE_NUM 256 /** Size of the profile array supported. */ +typedef struct { + AvCodecRole role; /** Media type. */ + CodecType type; /** Codec type. */ + char compName[NAME_LENGTH]; /** Codec component name. */ + int32_t supportProfiles[PROFILE_NUM]; /** Supported profiles. For details, see {@link Profile}. */ + int32_t maxInst; /** Maximum instance. */ + bool isSoftwareCodec; /** Whether it is software codec or hardware codec. */ + int32_t processModeMask; /** Codec processing mode mask. For details, see {@link CodecProcessMode}. */ + uint32_t capsMask; /** Codec playback capability mask. For details, see {@link CodecCapsMask}. */ + RangeValue bitRate; /** Supported bit rate range. */ + PortCap port; /** Supported audio and video encoding/decoding capabilities. */ +} CodecCompCapability; + +/** + * @brief Enumerates the buffer types. + */ +enum BufferType { + /** Invalid buffer type. */ + BUFFER_TYPE_INVALID = 0, + /** Virtual address type. */ + BUFFER_TYPE_VIRTUAL_ADDR = 0x1, + /** Shared memory. */ + BUFFER_TYPE_AVSHARE_MEM_FD = 0x2, + /** Handle. */ + BUFFER_TYPE_HANDLE = 0x4, + /** Dynamic handle. */ + BUFFER_TYPE_DYNAMIC_HANDLE = 0x8, +}; + +/** + * @brief Enumerate the shared memory types. + */ +enum ShareMemTypes { + /** Readable and writable shared memory */ + READ_WRITE_TYPE = 0x1, + /** Readable shared memory */ + READ_ONLY_TYPE = 0x2, +}; + +/** + * @brief Defines the codec buffer information. + */ +struct OmxCodecBuffer { + uint32_t bufferId; /** Buffer ID. */ + uint32_t size; /** Size of the structure. */ + union OMX_VERSIONTYPE version; /** Component version. */ + enum BufferType bufferType; /** Buffer type. */ + uint8_t *buffer; /** Buffer used for encoding or decoding. */ + uint32_t bufferLen; /** Size of the buffer. */ + uint32_t allocLen; /** Size of the buffer allocated. */ + uint32_t filledLen; /** Size of the buffer filled. */ + uint32_t offset; /** Offset to the start position of the valid data in the buffer. */ + int32_t fenceFd; /** Fence file descriptor used to signal when the input or output buffer is ready to consume. */ + enum ShareMemTypes type; /** Shared memory type. */ + int64_t pts; /** Timestamp. */ + uint32_t flag; /** Flag. */ +}; + +/** + * @brief Enumerates the extended codec indexes. + */ +enum OmxIndexCodecExType { + /** Extended BufferType index */ + OMX_IndexExtBufferTypeStartUnused = OMX_IndexKhronosExtensions + 0x00a00000, + /** SupportBuffer */ + OMX_IndexParamSupportBufferType, + /** UseBuffer */ + OMX_IndexParamUseBufferType, + /** GetBufferHandleUsage */ + OMX_IndexParamGetBufferHandleUsage, +}; + +/** + * @brief Defines the SupportBuffer. + */ +struct SupportBufferType { + uint32_t size; /** Size of the structure */ + union OMX_VERSIONTYPE version; /** Component version */ + uint32_t portIndex; /** Port index */ + uint32_t bufferTypes; /** Supported buffer types */ +}; + +/** + * @brief Define the UseBuffer. + */ +struct UseBufferType { + uint32_t size; /** Size of the structure */ + union OMX_VERSIONTYPE version; /** Component version */ + uint32_t portIndex; /** Port index */ + uint32_t bufferType; /** Buffer type */ +}; + +/** + * @brief Defines the BufferHandleUsage. + */ +struct GetBufferHandleUsageParams { + uint32_t size; /** Size of the structure */ + union OMX_VERSIONTYPE version; /** Component version */ + uint32_t portIndex; /** Port index */ + uint32_t usage; /** Usage */ +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* CODEC_COMPONENT_TYPE_H */ +/** @} */