From 8ced3e0d6279c4c80bd17bea38b2045bd348c7c4 Mon Sep 17 00:00:00 2001 From: crescent Date: Wed, 9 Mar 2022 09:06:48 +0000 Subject: [PATCH 1/3] add codec api Signed-off-by: crescent --- .../device_api/hdi/codec/codec_callback_if.h | 133 ++++++ .../device_api/hdi/codec/codec_component_if.h | 391 +++++++++++++++++ .../hdi/codec/codec_component_manager.h | 129 ++++++ .../hdi/codec/codec_component_type.h | 395 ++++++++++++++++++ 4 files changed, 1048 insertions(+) create mode 100755 zh-cn/device_api/hdi/codec/codec_callback_if.h create mode 100755 zh-cn/device_api/hdi/codec/codec_component_if.h create mode 100755 zh-cn/device_api/hdi/codec/codec_component_manager.h create mode 100755 zh-cn/device_api/hdi/codec/codec_component_type.h diff --git a/zh-cn/device_api/hdi/codec/codec_callback_if.h b/zh-cn/device_api/hdi/codec/codec_callback_if.h new file mode 100755 index 00000000..a1bdccaf --- /dev/null +++ b/zh-cn/device_api/hdi/codec/codec_callback_if.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 Codec模块接口定义 + * + * Codec模块涉及自定义类型、音视频编解码组件初始化、参数设置、数据的轮转和控制等。 + * + * @since 3.1 + */ + +/** + * @file codec_callback_if.h + * + * @brief 主要包括回调函数接口定义 + * + * Codec模块事件上报、上报输入buffer和输出buffer处理完毕等接口定义。 + * + * @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 Codec回调接口定义 + */ +struct CodecCallbackType { + struct HdfRemoteService *remote; + + /** + * @brief 事件上报 + * + * 组件运行过程中向上报告错误事件、命令完成事件、端口设置更改事件等。 + * + * @param self 输入参数, 指向要操作的callback指针 + * @param appData 输入参数, 上层数据, 通常是设置回调时给入的上层实例 + * @param appDataLen 输入参数, appData大小 + * @param eEvent 输入参数, 要通知的事件类型, 详见{@link OMX_EVENTTYPE} + * @param data1 输入参数, 事件上报携带的数据1 + * @param data2 输入参数, 事件上报携带的数据2 + * @param eventData 输入参数, 事件上报携带的数据信息 + * @param eventDataLen 输入参数, eventData大小 + * + * @return HDF_SUCCESS 表示事件上报成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 事件上报失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 事件上报失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 事件上报失败 + */ + 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 上报输入buffer编码或者解码处理完毕 + * + * 组件运行过程中向上报告输入buffer已经使用完毕。 + * + * @param self 输入参数, 指向要操作的callback指针 + * @param appData 输入参数, 上层数据, 通常是设置回调时给入的上层实例 + * @param appDataLen 输入参数, appData大小 + * @param buffer 输入参数, 已经处理完毕的输入buffer信息 + * + * @return HDF_SUCCESS 表示上报成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 上报失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 上报失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 上报失败 + */ + int32_t (*EmptyBufferDone)(struct CodecCallbackType *self, int8_t *appData, + uint32_t appDataLen, const struct OmxCodecBuffer *buffer); + + /** + * @brief 上报输出buffer填充完毕 + * + * 组件运行过程中向上报告输出buffer已经填充完毕。 + * + * @param self 输入参数, 指向要操作的callback指针 + * @param appData 输入参数, 上层数据, 通常是设置回调时给入的上层实例 + * @param appDataLen 输入参数, appData大小 + * @param buffer 输入参数, 已经填充完毕的buffer信息 + * + * @return HDF_SUCCESS 表示上报成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 上报失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 上报失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 上报失败 + */ + int32_t (*FillBufferDone)(struct CodecCallbackType *self, int8_t* appData, + uint32_t appDataLen, struct OmxCodecBuffer* buffer); +}; + +/** + * @brief 实例化CodecCallbackType对象 + * + * @param remote 输入参数, 指向RemoteService的指针 + * + * @return 实例化CodecCallbackType对象 + */ +struct CodecCallbackType *CodecCallbackTypeGet(struct HdfRemoteService *remote); + +/** + * @brief 释放CodecCallbackType对象 + * + * @param instance 输入参数, 指向CodecCallbackType实例的指针 + */ +void CodecCallbackTypeRelease(struct CodecCallbackType *instance); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // CODEC_CALLBACK_TYPE_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/codec/codec_component_if.h b/zh-cn/device_api/hdi/codec/codec_component_if.h new file mode 100755 index 00000000..072851f5 --- /dev/null +++ b/zh-cn/device_api/hdi/codec/codec_component_if.h @@ -0,0 +1,391 @@ +/* + * 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 Codec模块接口定义 + * + * Codec模块涉及自定义类型、音视频编解码组件初始化、参数设置、数据的轮转和控制等。 + * + * @since 3.1 + */ + +/** + * @file codec_component_if.h + * + * @brief 主要包括Codec组件接口定义 + * + * Codec模块获取组件信息、给组件发送命令、组件参数设置、buffer轮转和控制等接口定义。 + * + * @since 3.1 + */ + +#ifndef CODEC_COMPONENT_H +#define CODEC_COMPONENT_H + +#include "codec_callback_if.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Codec组件接口定义 + */ +struct CodecComponentType { + /** + * @brief 获取Codec组件版本号 + * + * 通过查询组件, 返回组件版本信息。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param compName 输出参数, 组件名称 + * @param compVersion 输出参数, OMX组件版本信息 + * @param specVersion 输出参数, 构建组件所依据的规范的版本信息 + * @param compUUID 输出参数, 指向唯一标识组件的UUID标识符的指针 + * @param compUUIDLen 输入参数, compUUID大小 + * + * @return HDF_SUCCESS 表示获取版本号成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取版本号失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 获取版本号失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 获取版本号失败 + */ + int32_t (*GetComponentVersion)(struct CodecComponentType *self, char *compName, + union OMX_VERSIONTYPE *compVersion, union OMX_VERSIONTYPE *specVersion, + uint8_t *compUUID, uint32_t compUUIDLen); + + /** + * @brief 发送命令给组件 + * + * 发送命令给组件, 当命令为设置状态时, 会有事件回调通知结果给上层, 其他命令则没有事件上报。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param cmd 输入参数, 组件要执行的命令, 详见{@link OMX_COMMANDTYPE} + * @param param 输入参数, 组件要执行的命令携带的参数 + * 当cmd为OMX_CommandStateSet时, param的值详见{@link OMX_STATETYPE} + * 当cmd为OMX_CommandFlush, OMX_CommandPortDisable, OMX_CommandPortEnable, OMX_CommandMarkBuffer时, param为目标端口 + * @param cmdData 输入参数, 当cmd为OMX_CommandMarkBuffer时, 指向OMX_MARKTYPE结构体指针 + * @param cmdDataLen 输入参数, cmdData大小 + * + * @return HDF_SUCCESS 表示发送命令成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 发送命令失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 发送命令失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 发送命令失败 + */ + int32_t (*SendCommand)(struct CodecComponentType *self, enum OMX_COMMANDTYPE cmd, uint32_t param, + int8_t *cmdData, uint32_t cmdDataLen); + + /** + * @brief 获取组件参数设置 + * + * 当组件处于除了OMX_StateInvalid状态之外的其他状态, 用户可通过此接口获取组件参数。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param paramIndex 输入参数, 待填充结构的索引, 详见{@link OMX_INDEXTYPE} + * @param paramStruct 输入输出参数, 指向由组件填充的应用程序分配的结构体指针 + * @param paramStructLen 输入参数, paramStruct大小 + * + * @return HDF_SUCCESS 表示获取参数成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取参数失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 获取参数失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 获取参数失败 + */ + int32_t (*GetParameter)(struct CodecComponentType *self, uint32_t paramIndex, int8_t *paramStruct, + uint32_t paramStructLen); + + /** + * @brief 设置组件需要的参数 + * + * 当组件处于OMX_StateLoaded状态或者端口是去使能状态, 用户可通过此接口设置组件参数。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param index 输入参数, 要设置的结构索引, 详见{@link OMX_INDEXTYPE} + * @param paramStruct 输入参数, 指向组件用于初始化的应用程序分配结构的指针 + * @param paramStructLen 输入参数, paramStruct大小 + * + * @return HDF_SUCCESS 表示设置参数成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置参数失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 设置参数失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 设置参数失败 + */ + int32_t (*SetParameter)(struct CodecComponentType *self, uint32_t index, int8_t *paramStruct, + uint32_t paramStructLen); + + /** + * @brief 获取组件的配置结构 + * + * 加载组件后可以随时调用此接口获取组件的配置。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param index 输入参数, 待填充结构的索引, 详见{@link OMX_INDEXTYPE} + * @param cfgStruct 输入输出参数, 指向由组件填充的应用程序分配的结构体指针 + * @param cfgStructLen 输入参数, cfgStruct大小 + * + * @return HDF_SUCCESS 表示获取配置成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取配置失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 获取配置失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 获取配置失败 + */ + int32_t (*GetConfig)(struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen); + + /** + * @brief 设置组件的配置 + * + * 加载组件后可以随时调用此接口设置组件的配置。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param index 输入参数, 要设置的结构索引, 详见{@link OMX_INDEXTYPE} + * @param cfgStruct 输入参数, 指向组件用于初始化的应用程序分配结构的指针 + * @param cfgStructLen 输入参数, cfgStruct大小 + * + * @return HDF_SUCCESS 表示设置配置成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 设置失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 设置失败 + */ + int32_t (*SetConfig)(struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen); + + /** + * @brief 根据字符串获取组件的扩展索引 + * + * 将扩展字符串转换为Openmax IL结构索引。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param paramName 输入参数, 组件用来转换为配置索引的字符串 + * @param indexType 输出参数, 由paramName转换的配置索引, 详见{@link OMX_INDEXTYPE} + * + * @return HDF_SUCCESS 表示获取扩展索引成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取扩展索引失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 获取扩展索引失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 获取扩展索引失败 + */ + int32_t (*GetExtensionIndex)(struct CodecComponentType *self, const char *paramName, uint32_t *indexType); + + /** + * @brief 获取组件的状态 + * + * 用户可调用此接口获取组件的当前状态。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param state 输出参数, 指向获取到的状态指针, 组件状态详见{@link OMX_STATETYPE} + * + * @return HDF_SUCCESS 表示获取状态成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取状态失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 获取状态失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 获取状态失败 + */ + int32_t (*GetState)(struct CodecComponentType *self, enum OMX_STATETYPE *state); + + /** + * @brief 设置组件Tunnel方式通信 + * + * 用户通过调用此接口确定组件是否可以进行Tunnel传输, 如果可以则设置组件的Tunnel传输。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param port 输入参数, 组件设置的端口 + * @param tunneledComp 输入参数, 组件tunnel handle + * @param tunneledPort 输入参数, 组件用来tunnel通信的端口 + * @param tunnelSetup 输入输出参数, 指向tunnel设置的结构体指针 + * + * @return HDF_SUCCESS 表示设置成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 设置失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 设置失败 + */ + int32_t (*ComponentTunnelRequest)(struct CodecComponentType *self, uint32_t port, + int32_t tunneledComp, uint32_t tunneledPort, struct OMX_TUNNELSETUPTYPE *tunnelSetup); + + /** + * @brief 指定组件端口的buffer + * + * 此接口在以下情况下使用: + * 当组件处于OMX_StateLoaded状态, 并且用户已经向组件发送OMX_StateIdle状态转换请求; + * 当组件处于OMX_StateWaitForResources状态, 所需的资源可用, 并且组件已准备好进入OMX_StateIdle状态; + * 在去使能端口上, 组件处于OMX_StateExecuting、OMX_StatePause或OMX_StateIdle状态。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param portIndex 输入参数, 指定的组件端口 + * @param buffer 输入输出参数, 指向要使用的buffer指针 + * + * @return HDF_SUCCESS 表示指定成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 指定失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 指定失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 指定失败 + */ + int32_t (*UseBuffer)(struct CodecComponentType *self, uint32_t portIndex, struct OmxCodecBuffer *buffer); + + /** + * @brief 向组件申请端口buffer + * + * 向组件申请分配新的buffer, 此接口在以下情况下使用: + * 当组件处于OMX_StateLoaded状态, 并且用户已经向组件发送OMX_StateIdle状态转换请求; + * 当组件处于OMX_StateWaitForResources状态, 所需的资源可用, 并且组件已准备好进入OMX_StateIdle状态; + * 在去使能端口上, 组件处于OMX_StateExecuting、OMX_StatePause或OMX_StateIdle状态。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param buffer 输入输出参数, 指向要申请的buffer指针 + * @param portIndex 输入参数, 指定的组件端口 + * + * @return HDF_SUCCESS 表示申请buffer成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 申请buffer失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 申请buffer失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 申请buffer失败 + */ + int32_t (*AllocateBuffer)(struct CodecComponentType *self, struct OmxCodecBuffer *buffer, uint32_t portIndex); + + /** + * @brief 释放buffer + * + * 此接口在以下情况下使用: + * 当组件处于OMX_StateIdle状态, 并且已经向组件发送OMX_StateLoaded状态转换请求; + * 在去使能端口上, 组件处于OMX_StateExecuting、OMX_StatePause或OMX_StateIdle时调用; + * 此接口调用可随时进行, 但是如果未在上述情况下执行, 可能会导致组件上报OMX_ErrorPortUnpopulated事件。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param portIndex 输入参数, 指定的组件端口 + * @param buffer 输入参数, 指向OmxCodecBuffer结构体的指针 + * + * @return HDF_SUCCESS 表示释放buffer成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 释放buffer失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 释放buffer失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 释放buffer失败 + */ + int32_t (*FreeBuffer)(struct CodecComponentType *self, uint32_t portIndex, const struct OmxCodecBuffer *buffer); + + /** + * @brief 编解码输入待处理buffer + * + * 此接口在组件处于OMX_StateExecuting或者OMX_StatePause状态时调用。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param buffer 输入参数, 指向OmxCodecBuffer结构体的指针 + * + * @return HDF_SUCCESS 表示输入buffer成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 输入buffer失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 输入buffer失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 输入buffer失败 + */ + int32_t (*EmptyThisBuffer)(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer); + + /** + * @brief 编解码输出填充buffer + * + * 此接口在组件处于OMX_StateExecuting或者OMX_StatePause状态时调用。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param buffer 输入参数, 指向OmxCodecBuffer结构体的指针 + * + * @return HDF_SUCCESS 表示填充buffer成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 填充buffer失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 填充buffer失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 填充buffer失败 + */ + int32_t (*FillThisBuffer)(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer); + + /** + * @brief 设置Codec组件的回调函数 + * + * 使用此回调函数向上通知事件以及上报可用的输入输出信息。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param callback 输入参数, 指向回调函数对象指针 + * @param appData 输入参数, 指向应用程序定义的值的指针, 该值将在回调期间返回 + * @param appDataLen 输入参数, appData大小 + * + * @return HDF_SUCCESS 表示设置回调成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置回调失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 设置回调失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 设置回调失败 + */ + int32_t (*SetCallbacks)(struct CodecComponentType *self, struct CodecCallbackType *callback, + int8_t *appData, uint32_t appDataLen); + + /** + * @brief 组件去初始化 + * + * 调用此接口使组件去初始化。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * + * @return HDF_SUCCESS 表示去初始化成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 去初始化失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 去初始化失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 去初始化失败 + */ + int32_t (*ComponentDeInit)(struct CodecComponentType *self); + + /** + * @brief 使用已在EGL中申请的空间 + * + * 此接口在以下情况下使用: + * 当组件处于OMX_StateLoaded状态, 并且已经向组件发送OMX_StateIdle状态转换请求; + * 当组件处于OMX_StateWaitForResources状态, 所需的资源可用, 并且组件已准备好进入OMX_StateIdle状态; + * 在去使能端口上, 组件处于OMX_StateExecuting、OMX_StatePause或OMX_StateIdle状态。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param buffer 输入输出参数, 指向OmxCodecBuffer结构体的指针 + * @param portIndex 输入参数, 指定的组件端口 + * @param eglImage 输入参数, EGL申请的图像指针 + * @param eglImageLen 输入参数, eglImage长度 + * + * @return HDF_SUCCESS 表示使用成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 使用失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 使用失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 使用失败 + */ + int32_t (*UseEglImage)(struct CodecComponentType *self, struct OmxCodecBuffer *buffer, uint32_t portIndex, + int8_t *eglImage, uint32_t eglImageLen); + + /** + * @brief 获取组件角色 + * + * 根据组件角色索引获取对应组件角色。 + * + * @param self 输入参数, 指向要操作的Codec组件指针 + * @param role 输出参数, 角色名称 + * @param roleLen 输入参数, role长度 + * @param index 输入参数, 角色的索引, 一个组件可能支持多种角色 + * + * @return HDF_SUCCESS 表示获取角色成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取角色失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 获取角色失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 获取角色失败 + */ + int32_t (*ComponentRoleEnum)(struct CodecComponentType *self, uint8_t *role, uint32_t roleLen, uint32_t index); +}; + +/** + * @brief 实例化CodecComponentType对象 + * + * @param remote 输入参数, 指向RemoteService的指针 + * + * @return 实例化CodecComponentType对象 + */ +struct CodecComponentType *CodecComponentTypeGet(struct HdfRemoteService *remote); + +/** + * @brief 释放CodecComponentType对象 + * + * @param instance 输入参数, 指向CodecComponentType实例的指针 + */ +void CodecComponentTypeRelease(struct CodecComponentType *instance); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // CODEC_COMPONENT_H \ No newline at end of file diff --git a/zh-cn/device_api/hdi/codec/codec_component_manager.h b/zh-cn/device_api/hdi/codec/codec_component_manager.h new file mode 100755 index 00000000..f86ee669 --- /dev/null +++ b/zh-cn/device_api/hdi/codec/codec_component_manager.h @@ -0,0 +1,129 @@ +/* + * 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 Codec模块接口定义 + * + * Codec模块涉及自定义类型、音视频编解码组件初始化、参数设置、数据的轮转和控制等。 + * + * @since 3.1 + */ + +/** + * @file codec_component_manager.h + * + * @brief 主要包括Codec组件管理类接口 + * + * Codec模块获取组件编解码能力集、创建组件和销毁组件等接口定义。 + * + * @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 Codec组件管理类接口定义 + */ +struct CodecComponentManager { + /** + * @brief 获取Codec编解码组件数量 + * + * 通过此接口获取Codec编解码组件数量, 用来获取全部编解码能力集。 + * + * @return Codec编解码组件数量 + */ + int32_t (*GetComponentNum)(); + + /** + * @brief 获取编解码能力集表 + * + * 用户可通过此接口了解Codec模块提供了哪些编解码能力, 对应的能力体现在{@link CodecCompCapability}结构体。 + * + * @param capList 输出参数, 返回全部组件的能力集表 + * @param count 输入参数, 编解码组件数量, 由{@link GetComponentNum}获得 + * + * @return HDF_SUCCESS 表示获取能力集表成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取能力集表失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 获取能力集表失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 获取能力集表失败 + */ + int32_t (*GetComponentCapabilityList)(CodecCompCapability *capList, int32_t count); + + /** + * @brief 创建Codec组件实例 + * + * 根据组件名称创建Codec组件实例。 + * + * @param component 输出参数, 指向Codec组件的指针 + * @param compName 输入参数, 组件名称 + * @param appData 输入参数, 指向应用程序定义的值的指针, 该值将在回调期间返回 + * @param appDataSize 输入参数, appData大小 + * @param callbacks 输入参数, 回调接口, 指向OMX_CALLBACKTYPE结构的指针, 详见{@link CodecCallbackType} + * + * @return HDF_SUCCESS 表示创建组件成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 创建组件失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 创建组件失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 创建组件失败 + */ + int32_t (*CreateComponent)(struct CodecComponentType **component, char *compName, void *appData, + int32_t appDataSize, struct CodecCallbackType *callbacks); + + /** + * @brief 销毁组件实例 + * + * 销毁指定的Codec组件。 + * + * @param component 输入参数, 需要销毁的Codec组件 + * + * @return HDF_SUCCESS 表示销毁组件成功 + * @return HDF_ERR_INVALID_PARAM 表示参数无效, 销毁组件失败 + * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 销毁组件失败 + * @return HDF_ERR_MALLOC_FAIL 表示申请内存失败, 销毁组件失败 + */ + int32_t (*DestoryComponent)(struct CodecComponentType *component); +}; + +/** + * @brief 实例化CodecComponentManager对象 + * + * @return 实例化CodecComponentManager对象 + */ +struct CodecComponentManager *GetCodecComponentManager(void); + +/** + * @brief 释放CodecComponentManager对象 + */ +void CodecComponentManagerRelease(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* CODEC_COMPONENT_MANAGER_H */ +/** @} */ \ No newline at end of file diff --git a/zh-cn/device_api/hdi/codec/codec_component_type.h b/zh-cn/device_api/hdi/codec/codec_component_type.h new file mode 100755 index 00000000..047f9682 --- /dev/null +++ b/zh-cn/device_api/hdi/codec/codec_component_type.h @@ -0,0 +1,395 @@ +/* + * 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 Codec模块接口定义 + * + * Codec模块涉及自定义类型、音视频编解码组件初始化、参数设置、数据的轮转和控制等。 + * + * @since 3.1 + */ + +/** + * @file codec_component_type.h + * + * @brief Codec模块接口定义中使用的自定义数据类型 + * + * Codec模块接口定义中使用的自定义数据类型, 包括编解码类型、音视频参数、buffer定义等。 + * + * @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 采样格式最大值 + */ +#define SAMPLE_FMT_NUM 32 + +/** + * @brief 枚举编解码的类型 + */ +typedef enum { + /** 视频解码类型 */ + VIDEO_DECODER, + /** 视频编码类型 */ + VIDEO_ENCODER, + /** 音频解码类型 */ + AUDIO_DECODER, + /** 音频编码类型 */ + AUDIO_ENCODER, + /** 无效类型 */ + INVALID_TYPE +} CodecType; + +/** + * @brief 枚举音视频编解码组件类型 + */ +typedef enum { + /** 图像 JPEG 媒体类型 */ + MEDIA_ROLETYPE_IMAGE_JPEG = 0, + /** 视频 H.264 媒体类型 */ + MEDIA_ROLETYPE_VIDEO_AVC, + /** 视频 H.265 媒体类型 */ + MEDIA_ROLETYPE_VIDEO_HEVC, + /** 音频编解码器类型 */ + MEDIA_ROLETYPE_AUDIO_FIRST = 0x10000, + /** 音频 AAC 媒体类型 */ + MEDIA_ROLETYPE_AUDIO_AAC = 0x10000, + /** 音频 G711A 媒体类型 */ + MEDIA_ROLETYPE_AUDIO_G711A, + /** 音频 G711U 媒体类型 */ + MEDIA_ROLETYPE_AUDIO_G711U, + /** 音频 G726 媒体类型 */ + MEDIA_ROLETYPE_AUDIO_G726, + /** 音频 PCM 媒体类型 */ + MEDIA_ROLETYPE_AUDIO_PCM, + /** 音频 MP3 媒体类型 */ + MEDIA_ROLETYPE_AUDIO_MP3, + /** 无效媒体类型 */ + MEDIA_ROLETYPE_INVALID, +} AvCodecRole; + +/** + * @brief 枚举Codec profiles. + */ +typedef enum { + /** 无效的 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 对齐结构定义, 包含宽高的对齐 + */ +typedef struct { + int32_t widthAlginment; /** 宽的对齐值 */ + int32_t heightAlginment; /** 高的对齐值 */ +} Alginment; + +/** + * @brief 矩形的定义 + */ +typedef struct { + int32_t width; /** 矩形的宽 */ + int32_t height; /** 矩形的高 */ +} Rect; + +/** + * @brief 取值范围的定义 + */ +typedef struct { + int32_t min; /** 最小值 */ + int32_t max; /** 最大值 */ +} RangeValue; + +/** + * @brief 枚举播放能力 + */ +typedef enum { + /** 自适应播放 */ + CODEC_CAP_ADAPTIVE_PLAYBACK = 0x1, + /** 安全播放 */ + CODEC_CAP_SECURE_PLAYBACK = 0x2, + /** 通道播放 */ + CODEC_CAP_TUNNEL_PLAYBACK = 0x4, + /** Video picture planes/audio channel planar */ + CODEC_CAP_MULTI_PLANE = 0x10000, +} CodecCapsMask; + +/** + * @brief 枚举音频采样率 + */ +typedef enum { + /** 8K采样率 */ + AUD_SAMPLE_RATE_8000 = 8000, + /** 12K采样率 */ + AUD_SAMPLE_RATE_12000 = 12000, + /** 11.025K采样率 */ + AUD_SAMPLE_RATE_11025 = 11025, + /** 16K采样率 */ + AUD_SAMPLE_RATE_16000 = 16000, + /** 22.050K采样率 */ + AUD_SAMPLE_RATE_22050 = 22050, + /** 24K采样率 */ + AUD_SAMPLE_RATE_24000 = 24000, + /** 32K采样率 */ + AUD_SAMPLE_RATE_32000 = 32000, + /** 44.1K采样率 */ + AUD_SAMPLE_RATE_44100 = 44100, + /** 48K采样率 */ + AUD_SAMPLE_RATE_48000 = 48000, + /** 64K采样率 */ + AUD_SAMPLE_RATE_64000 = 64000, + /** 96K采样率 */ + AUD_SAMPLE_RATE_96000 = 96000, + /** 无效采样率 */ + AUD_SAMPLE_RATE_INVALID, +} AudioSampleRate; + +/** + * @brief 枚举音频采样格式 + * For planar sample formats, each audio channel is in a seperate data plane. + * For packed sample formats, only the first data plane is used, and samples for each channel are 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 定义视频编解码能力 + */ +#define PIX_FORMAT_NUM 16 /** Indicates the array size of supported pixel formats */ +typedef struct { + Rect minSize; /** 支持的最小分辨率 */ + Rect maxSize; /** 支持的最大分辨率 */ + Alginment whAlignment; /** 宽高对齐值 */ + RangeValue blockCount; /** 宽高对齐值 */ + RangeValue blocksPerSecond; /** 宽高对齐值 */ + Rect blockSize; /** 宽高对齐值 */ + int32_t supportPixFmts[PIX_FORMAT_NUM]; /** 支持的像素格式, 详见{@link OMX_COLOR_FORMATTYPE} */ +} VideoPortCap; + +/** + * @brief 定义音频编解码能力 + */ +#define SAMPLE_FORMAT_NUM 12 /** 支持的音频采样格式数组大小 */ +#define SAMPLE_RATE_NUM 16 /** 支持的音频采样率数组大小 */ +#define CHANNEL_NUM 16 /** 支持的音频通道数组大小 */ +typedef struct { + int32_t sampleFormats[SAMPLE_FMT_NUM]; /** 支持的音频采样格式, 详见{@link AudioSampleFormat} */ + int32_t sampleRate[SAMPLE_RATE_NUM]; /** 支持的音频采样率, 详见{@link AudioSampleRate} */ + int32_t channelLayouts[CHANNEL_NUM]; /** 支持的音频通道数channel layouts */ + int32_t channelCount[CHANNEL_NUM]; /** 支持的音频通道数*/ +} AudioPortCap; + +/** + * @brief 定义音视频编解码能力 + */ +typedef union { + VideoPortCap video; /** 视频编解码能力 */ + AudioPortCap audio; /** 音频编解码能力 */ +} PortCap; + +/** + * @brief 枚举编解码处理模式 + */ +typedef enum { + /** 同步模式输入buffer */ + PROCESS_BLOCKING_INPUT_BUFFER = 0X1, + /** 同步模式输出buffer */ + PROCESS_BLOCKING_OUTPUT_BUFFER = 0X2, + /** 同步模式控制流 */ + PROCESS_BLOCKING_CONTROL_FLOW = 0X4, + /** 异步模式输入buffer */ + PROCESS_NONBLOCKING_INPUT_BUFFER = 0X100, + /** 异步模式输出buffer */ + PROCESS_NONBLOCKING_OUTPUT_BUFFER = 0X200, + /** 异步模式控制流 */ + PROCESS_NONBLOCKING_CONTROL_FLOW = 0X400, +} CodecProcessMode; + +/** + * @brief 定义Codec编解码能力 + */ +#define NAME_LENGTH 32 /** 组件名称大小 */ +#define PROFILE_NUM 256 /** 支持的profile数组大小 */ +typedef struct { + AvCodecRole role; /** 媒体类型 */ + CodecType type; /** 编解码类型 */ + char compName[NAME_LENGTH]; /** 编解码组件名称 */ + int32_t supportProfiles[PROFILE_NUM]; /** 支持的profiles, 详见{@link Profile} */ + int32_t maxInst; /** 最大实例 */ + bool isSoftwareCodec; /** 软件编解码还是硬件编解码 */ + int32_t processModeMask; /** 编解码处理模式掩码, 详见{@link CodecProcessMode}. */ + uint32_t capsMask; /** 编解码播放能力, 详见{@link CodecCapsMask}. */ + RangeValue bitRate; /** 支持的码率范围 */ + PortCap port; /** 支持的音视频编解码能力 */ +} CodecCompCapability; + +/** + * @brief 定义buffer类型 + */ +enum BufferType { + /** 无效buffer类型 */ + BUFFER_TYPE_INVALID = 0, + /** 虚拟地址类型 */ + BUFFER_TYPE_VIRTUAL_ADDR = 0x1, + /** 共享内存类型 */ + BUFFER_TYPE_AVSHARE_MEM_FD = 0x2, + /** handle类型 */ + BUFFER_TYPE_HANDLE = 0x4, + /** 动态handle类型 */ + BUFFER_TYPE_DYNAMIC_HANDLE = 0x8, +}; + +/** + * @brief 枚举共享内存类型 + */ +enum ShareMemTypes { + /** 可读可写的共享内存类型 */ + READ_WRITE_TYPE = 0x1, + /** 可读的共享内存类型 */ + READ_ONLY_TYPE = 0x2, +}; + +/** + * @brief Codec buffer信息的定义 + */ +struct OmxCodecBuffer { + uint32_t bufferId; /** buffer ID */ + uint32_t size; /** 结构体大小 */ + union OMX_VERSIONTYPE version; /** 组件版本信息 */ + enum BufferType bufferType; /** buffer类型 */ + uint8_t *buffer; /** buffer */ + uint32_t bufferLen; /** buffer大小 */ + uint32_t allocLen; /** 申请的buffer大小 */ + uint32_t filledLen; /** 填充的buffer大小 */ + uint32_t offset; /** 有效数据从缓冲区开始的起始偏移量 */ + int32_t fenceFd; /** fenceFd */ + enum ShareMemTypes type; /** 共享内存类型 */ + int64_t pts; /** 时间戳 */ + uint32_t flag; /** 标志 */ +}; + +/** + * @brief 枚举Codec扩展index + */ +enum OmxIndexCodecExType { + /** BufferType 扩展index */ + OMX_IndexExtBufferTypeStartUnused = OMX_IndexKhronosExtensions + 0x00a00000, + /** SupportBuffer类型 */ + OMX_IndexParamSupportBufferType, + /** UseBuffer类型 */ + OMX_IndexParamUseBufferType, + /** GetBufferHandleUsage类型 */ + OMX_IndexParamGetBufferHandleUsage, +}; + +/** + * @brief SupportBuffer类型定义 + */ +struct SupportBufferType { + uint32_t size; /** 结构体大小 */ + union OMX_VERSIONTYPE version; /** 组件版本信息 */ + uint32_t portIndex; /** 端口索引 */ + uint32_t bufferTypes; /** 支持的所有Buffer类型 */ +}; + +/** + * @brief UseBuffer类型定义 + */ +struct UseBufferType { + uint32_t size; /** 结构体大小 */ + union OMX_VERSIONTYPE version; /** 组件版本信息 */ + uint32_t portIndex; /** 端口索引 */ + uint32_t bufferType; /** Buffer类型 */ +}; + +/** + * @brief BufferHandleUsage类型定义 + */ +struct GetBufferHandleUsageParams { + uint32_t size; /** 结构体大小 */ + union OMX_VERSIONTYPE version; /** 组件版本信息 */ + uint32_t portIndex; /** 端口索引 */ + uint32_t usage; /** usage */ +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* CODEC_COMPONENT_TYPE_H */ +/** @} */ \ No newline at end of file -- Gitee From b79b4e353fc80417e5592009a9ce80340ee7eddc Mon Sep 17 00:00:00 2001 From: crescent Date: Thu, 10 Mar 2022 03:17:19 +0000 Subject: [PATCH 2/3] add codec api Signed-off-by: crescent --- .../device_api/hdi/codec/codec_callback_if.h | 31 +++++++--- .../device_api/hdi/codec/codec_component_if.h | 56 +++++++++++-------- .../hdi/codec/codec_component_manager.h | 8 ++- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/zh-cn/device_api/hdi/codec/codec_callback_if.h b/zh-cn/device_api/hdi/codec/codec_callback_if.h index a1bdccaf..39145852 100755 --- a/zh-cn/device_api/hdi/codec/codec_callback_if.h +++ b/zh-cn/device_api/hdi/codec/codec_callback_if.h @@ -47,6 +47,14 @@ extern "C" { /** * @brief Codec回调接口定义 + * + * 提供了以下3种回调函数: + * 1.组件错误事件、命令完成事件、端口设置等事件回调, 详见{@link EventHandler}; + * 2.输入端口处理完buffer回调, 详见{@link EmptyBufferDone}; + * 3.输出端口填充完buffer回调, 详见{@link FillBufferDone}; + * 通过以下两种方式注册回调: + * 1.创建组件时, 通过{@link CreateComponent}方法; + * 2.当组件处于OMX_StateLoaded状态时, 通过{@link SetCallbacks}方法注册回调。 */ struct CodecCallbackType { struct HdfRemoteService *remote; @@ -55,16 +63,23 @@ struct CodecCallbackType { * @brief 事件上报 * * 组件运行过程中向上报告错误事件、命令完成事件、端口设置更改事件等。 + * 当eEvent为OMX_EventCmdComplete, eventData为NULL, data1 数据为OMX_COMMANDTYPE, + * 此时, 当data1为OMX_CommandStateSet, data2表示状态, 其它情况下, data2表示端口; + * 当eEvent为OMX_EventError时, data1表示错误码, data2和eventData都为0; + * 当eEvent为OMX_EventMark时, data1和data2都为0, eventData指向mark指针; + * 当eEvent为OMX_EventPortSettingsChanged时, data1表示端口, data2和eventData为0; + * 当eEvent为OMX_EventBufferFlag时, data1表示端口, data2表示flag, eventData为0; + * 当eEvent为OMX_EventResourcesAcquired或OMX_EventDynamicResourcesAvailable时, data1、data2和eventData都为0。 * * @param self 输入参数, 指向要操作的callback指针 * @param appData 输入参数, 上层数据, 通常是设置回调时给入的上层实例 - * @param appDataLen 输入参数, appData大小 + * @param appDataLen 输入参数, appData字节数 * @param eEvent 输入参数, 要通知的事件类型, 详见{@link OMX_EVENTTYPE} * @param data1 输入参数, 事件上报携带的数据1 * @param data2 输入参数, 事件上报携带的数据2 * @param eventData 输入参数, 事件上报携带的数据信息 - * @param eventDataLen 输入参数, eventData大小 - * + * @param eventDataLen 输入参数, eventData字节数 + * * @return HDF_SUCCESS 表示事件上报成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 事件上报失败 * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 事件上报失败 @@ -80,8 +95,8 @@ struct CodecCallbackType { * * @param self 输入参数, 指向要操作的callback指针 * @param appData 输入参数, 上层数据, 通常是设置回调时给入的上层实例 - * @param appDataLen 输入参数, appData大小 - * @param buffer 输入参数, 已经处理完毕的输入buffer信息 + * @param appDataLen 输入参数, appData字节数 + * @param buffer 输入参数, 已经处理完毕的输入buffer信息{@link OmxCodecBuffer} * * @return HDF_SUCCESS 表示上报成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 上报失败 @@ -98,8 +113,8 @@ struct CodecCallbackType { * * @param self 输入参数, 指向要操作的callback指针 * @param appData 输入参数, 上层数据, 通常是设置回调时给入的上层实例 - * @param appDataLen 输入参数, appData大小 - * @param buffer 输入参数, 已经填充完毕的buffer信息 + * @param appDataLen 输入参数, appData字节数 + * @param buffer 输入参数, 已经填充完毕的buffer信息{@link OmxCodecBuffer} * * @return HDF_SUCCESS 表示上报成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 上报失败 @@ -113,7 +128,7 @@ struct CodecCallbackType { /** * @brief 实例化CodecCallbackType对象 * - * @param remote 输入参数, 指向RemoteService的指针 + * @param remote 输入参数, 指向HdfRemoteService的指针 * * @return 实例化CodecCallbackType对象 */ diff --git a/zh-cn/device_api/hdi/codec/codec_component_if.h b/zh-cn/device_api/hdi/codec/codec_component_if.h index 072851f5..499d3c43 100755 --- a/zh-cn/device_api/hdi/codec/codec_component_if.h +++ b/zh-cn/device_api/hdi/codec/codec_component_if.h @@ -45,6 +45,15 @@ extern "C" { /** * @brief Codec组件接口定义 + * + * 主要提供以下功能: + * 获取组件的版本; + * 组件参数配置的获取和设置; + * 发送命令至组件, 获取组件状态; + * 设置回调函数; + * 设置/释放组件使用的buffer; + * 编解码输入输出buffer处理; + * 具体方法使用详见函数说明。 */ struct CodecComponentType { /** @@ -54,10 +63,10 @@ struct CodecComponentType { * * @param self 输入参数, 指向要操作的Codec组件指针 * @param compName 输出参数, 组件名称 - * @param compVersion 输出参数, OMX组件版本信息 - * @param specVersion 输出参数, 构建组件所依据的规范的版本信息 + * @param compVersion 输出参数, OMX组件版本信息{@link OMX_VERSIONTYPE} + * @param specVersion 输出参数, 构建组件所依据的规范的版本信息{@link OMX_VERSIONTYPE} * @param compUUID 输出参数, 指向唯一标识组件的UUID标识符的指针 - * @param compUUIDLen 输入参数, compUUID大小 + * @param compUUIDLen 输入参数, compUUID字节数 * * @return HDF_SUCCESS 表示获取版本号成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取版本号失败 @@ -79,8 +88,7 @@ struct CodecComponentType { * 当cmd为OMX_CommandStateSet时, param的值详见{@link OMX_STATETYPE} * 当cmd为OMX_CommandFlush, OMX_CommandPortDisable, OMX_CommandPortEnable, OMX_CommandMarkBuffer时, param为目标端口 * @param cmdData 输入参数, 当cmd为OMX_CommandMarkBuffer时, 指向OMX_MARKTYPE结构体指针 - * @param cmdDataLen 输入参数, cmdData大小 - * + * @param cmdDataLen 输入参数, cmdData字节数 * @return HDF_SUCCESS 表示发送命令成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 发送命令失败 * @return HDF_ERR_INVALID_OBJECT 表示对象无效, 发送命令失败 @@ -97,7 +105,7 @@ struct CodecComponentType { * @param self 输入参数, 指向要操作的Codec组件指针 * @param paramIndex 输入参数, 待填充结构的索引, 详见{@link OMX_INDEXTYPE} * @param paramStruct 输入输出参数, 指向由组件填充的应用程序分配的结构体指针 - * @param paramStructLen 输入参数, paramStruct大小 + * @param paramStructLen 输入参数, paramStruct字节数 * * @return HDF_SUCCESS 表示获取参数成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取参数失败 @@ -110,12 +118,12 @@ struct CodecComponentType { /** * @brief 设置组件需要的参数 * - * 当组件处于OMX_StateLoaded状态或者端口是去使能状态, 用户可通过此接口设置组件参数。 + * 当组件处于OMX_StateLoaded、OMX_StateWaitForResources状态或者端口是去使能状态, 用户可通过此接口设置组件参数。 * * @param self 输入参数, 指向要操作的Codec组件指针 * @param index 输入参数, 要设置的结构索引, 详见{@link OMX_INDEXTYPE} * @param paramStruct 输入参数, 指向组件用于初始化的应用程序分配结构的指针 - * @param paramStructLen 输入参数, paramStruct大小 + * @param paramStructLen 输入参数, paramStruct字节数 * * @return HDF_SUCCESS 表示设置参数成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置参数失败 @@ -133,7 +141,7 @@ struct CodecComponentType { * @param self 输入参数, 指向要操作的Codec组件指针 * @param index 输入参数, 待填充结构的索引, 详见{@link OMX_INDEXTYPE} * @param cfgStruct 输入输出参数, 指向由组件填充的应用程序分配的结构体指针 - * @param cfgStructLen 输入参数, cfgStruct大小 + * @param cfgStructLen 输入参数, cfgStruct字节数 * * @return HDF_SUCCESS 表示获取配置成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 获取配置失败 @@ -150,7 +158,7 @@ struct CodecComponentType { * @param self 输入参数, 指向要操作的Codec组件指针 * @param index 输入参数, 要设置的结构索引, 详见{@link OMX_INDEXTYPE} * @param cfgStruct 输入参数, 指向组件用于初始化的应用程序分配结构的指针 - * @param cfgStructLen 输入参数, cfgStruct大小 + * @param cfgStructLen 输入参数, cfgStruct字节数 * * @return HDF_SUCCESS 表示设置配置成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置失败 @@ -193,13 +201,13 @@ struct CodecComponentType { /** * @brief 设置组件Tunnel方式通信 * - * 用户通过调用此接口确定组件是否可以进行Tunnel传输, 如果可以则设置组件的Tunnel传输。 + * 当组件处于OMX_StateLoaded 状态时,用户通过调用此接口确定组件是否可以进行Tunnel传输, 如果可以则设置组件的Tunnel传输。 * * @param self 输入参数, 指向要操作的Codec组件指针 * @param port 输入参数, 组件设置的端口 * @param tunneledComp 输入参数, 组件tunnel handle * @param tunneledPort 输入参数, 组件用来tunnel通信的端口 - * @param tunnelSetup 输入输出参数, 指向tunnel设置的结构体指针 + * @param tunnelSetup 输入输出参数, 指向tunnel设置的结构体{@link OMX_TUNNELSETUPTYPE}指针 * * @return HDF_SUCCESS 表示设置成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置失败 @@ -219,7 +227,7 @@ struct CodecComponentType { * * @param self 输入参数, 指向要操作的Codec组件指针 * @param portIndex 输入参数, 指定的组件端口 - * @param buffer 输入输出参数, 指向要使用的buffer指针 + * @param buffer 输入输出参数, 指向要使用的buffer结构体{@link OmxCodecBuffer}指针 * * @return HDF_SUCCESS 表示指定成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 指定失败 @@ -237,7 +245,7 @@ struct CodecComponentType { * 在去使能端口上, 组件处于OMX_StateExecuting、OMX_StatePause或OMX_StateIdle状态。 * * @param self 输入参数, 指向要操作的Codec组件指针 - * @param buffer 输入输出参数, 指向要申请的buffer指针 + * @param buffer 输入输出参数, 指向要申请的buffer结构体{@link OmxCodecBuffer}指针 * @param portIndex 输入参数, 指定的组件端口 * * @return HDF_SUCCESS 表示申请buffer成功 @@ -257,7 +265,7 @@ struct CodecComponentType { * * @param self 输入参数, 指向要操作的Codec组件指针 * @param portIndex 输入参数, 指定的组件端口 - * @param buffer 输入参数, 指向OmxCodecBuffer结构体的指针 + * @param buffer 输入参数, 指向{@link OmxCodecBuffer}结构体的指针 * * @return HDF_SUCCESS 表示释放buffer成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 释放buffer失败 @@ -272,7 +280,7 @@ struct CodecComponentType { * 此接口在组件处于OMX_StateExecuting或者OMX_StatePause状态时调用。 * * @param self 输入参数, 指向要操作的Codec组件指针 - * @param buffer 输入参数, 指向OmxCodecBuffer结构体的指针 + * @param buffer 输入参数, 指向{@link OmxCodecBuffer}结构体的指针 * * @return HDF_SUCCESS 表示输入buffer成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 输入buffer失败 @@ -287,7 +295,7 @@ struct CodecComponentType { * 此接口在组件处于OMX_StateExecuting或者OMX_StatePause状态时调用。 * * @param self 输入参数, 指向要操作的Codec组件指针 - * @param buffer 输入参数, 指向OmxCodecBuffer结构体的指针 + * @param buffer 输入参数, 指向{@link OmxCodecBuffer}结构体的指针 * * @return HDF_SUCCESS 表示填充buffer成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 填充buffer失败 @@ -299,12 +307,12 @@ struct CodecComponentType { /** * @brief 设置Codec组件的回调函数 * - * 使用此回调函数向上通知事件以及上报可用的输入输出信息。 + * 当组件处于OMX_StateLoaded状态时,使用此回调函数向上通知事件以及上报可用的输入输出信息。 * * @param self 输入参数, 指向要操作的Codec组件指针 - * @param callback 输入参数, 指向回调函数对象指针 + * @param callback 输入参数, 指向回调函数{@link CodecCallbackType}对象指针 * @param appData 输入参数, 指向应用程序定义的值的指针, 该值将在回调期间返回 - * @param appDataLen 输入参数, appData大小 + * @param appDataLen 输入参数, appData字节数 * * @return HDF_SUCCESS 表示设置回调成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 设置回调失败 @@ -317,7 +325,7 @@ struct CodecComponentType { /** * @brief 组件去初始化 * - * 调用此接口使组件去初始化。 + * 调用此接口使组件去初始化,但组件处于OMX_StateLoaded状态时,将直接关闭组件 * * @param self 输入参数, 指向要操作的Codec组件指针 * @@ -337,10 +345,10 @@ struct CodecComponentType { * 在去使能端口上, 组件处于OMX_StateExecuting、OMX_StatePause或OMX_StateIdle状态。 * * @param self 输入参数, 指向要操作的Codec组件指针 - * @param buffer 输入输出参数, 指向OmxCodecBuffer结构体的指针 + * @param buffer 输入输出参数, 指向{@link OmxCodecBuffer}结构体的指针 * @param portIndex 输入参数, 指定的组件端口 * @param eglImage 输入参数, EGL申请的图像指针 - * @param eglImageLen 输入参数, eglImage长度 + * @param eglImageLen 输入参数, eglImage字节数 * * @return HDF_SUCCESS 表示使用成功 * @return HDF_ERR_INVALID_PARAM 表示参数无效, 使用失败 @@ -357,7 +365,7 @@ struct CodecComponentType { * * @param self 输入参数, 指向要操作的Codec组件指针 * @param role 输出参数, 角色名称 - * @param roleLen 输入参数, role长度 + * @param roleLen 输入参数, role字节数 * @param index 输入参数, 角色的索引, 一个组件可能支持多种角色 * * @return HDF_SUCCESS 表示获取角色成功 diff --git a/zh-cn/device_api/hdi/codec/codec_component_manager.h b/zh-cn/device_api/hdi/codec/codec_component_manager.h index f86ee669..91494535 100755 --- a/zh-cn/device_api/hdi/codec/codec_component_manager.h +++ b/zh-cn/device_api/hdi/codec/codec_component_manager.h @@ -47,6 +47,10 @@ extern "C" { /** * @brief Codec组件管理类接口定义 + * + * 主要提供以下功能: + * 获取Codec编解码组件数量以及编解码能力集表; + * 创建/销毁Codec组件。 */ struct CodecComponentManager { /** @@ -63,7 +67,7 @@ struct CodecComponentManager { * * 用户可通过此接口了解Codec模块提供了哪些编解码能力, 对应的能力体现在{@link CodecCompCapability}结构体。 * - * @param capList 输出参数, 返回全部组件的能力集表 + * @param capList 输出参数, 返回全部组件的能力集表{@link CodecCompCapability} * @param count 输入参数, 编解码组件数量, 由{@link GetComponentNum}获得 * * @return HDF_SUCCESS 表示获取能力集表成功 @@ -81,7 +85,7 @@ struct CodecComponentManager { * @param component 输出参数, 指向Codec组件的指针 * @param compName 输入参数, 组件名称 * @param appData 输入参数, 指向应用程序定义的值的指针, 该值将在回调期间返回 - * @param appDataSize 输入参数, appData大小 + * @param appDataSize 输入参数, appData字节数 * @param callbacks 输入参数, 回调接口, 指向OMX_CALLBACKTYPE结构的指针, 详见{@link CodecCallbackType} * * @return HDF_SUCCESS 表示创建组件成功 -- Gitee From c4a5324e8313a6b6654b8cb8d5a518f701e09536 Mon Sep 17 00:00:00 2001 From: crescent Date: Fri, 11 Mar 2022 04:07:27 +0000 Subject: [PATCH 3/3] add codec api Signed-off-by: crescent --- zh-cn/device_api/hdi/codec/codec_component_if.h | 4 ++-- zh-cn/device_api/hdi/codec/codec_component_type.h | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/zh-cn/device_api/hdi/codec/codec_component_if.h b/zh-cn/device_api/hdi/codec/codec_component_if.h index 499d3c43..50aeb456 100755 --- a/zh-cn/device_api/hdi/codec/codec_component_if.h +++ b/zh-cn/device_api/hdi/codec/codec_component_if.h @@ -186,7 +186,7 @@ struct CodecComponentType { /** * @brief 获取组件的状态 * - * 用户可调用此接口获取组件的当前状态。 + * 用户可调用此接口获取组件的当前状态, 组件状态详见{@link OMX_STATETYPE}。 * * @param self 输入参数, 指向要操作的Codec组件指针 * @param state 输出参数, 指向获取到的状态指针, 组件状态详见{@link OMX_STATETYPE} @@ -325,7 +325,7 @@ struct CodecComponentType { /** * @brief 组件去初始化 * - * 调用此接口使组件去初始化,但组件处于OMX_StateLoaded状态时,将直接关闭组件 + * 调用此接口使组件去初始化,当组件处于OMX_StateLoaded状态时,将直接关闭组件。 * * @param self 输入参数, 指向要操作的Codec组件指针 * diff --git a/zh-cn/device_api/hdi/codec/codec_component_type.h b/zh-cn/device_api/hdi/codec/codec_component_type.h index 047f9682..b2c2a9b2 100755 --- a/zh-cn/device_api/hdi/codec/codec_component_type.h +++ b/zh-cn/device_api/hdi/codec/codec_component_type.h @@ -161,7 +161,7 @@ typedef enum { CODEC_CAP_SECURE_PLAYBACK = 0x2, /** 通道播放 */ CODEC_CAP_TUNNEL_PLAYBACK = 0x4, - /** Video picture planes/audio channel planar */ + /** 视频图像平面/音频通道平面 */ CODEC_CAP_MULTI_PLANE = 0x10000, } CodecCapsMask; @@ -197,8 +197,9 @@ typedef enum { /** * @brief 枚举音频采样格式 - * For planar sample formats, each audio channel is in a seperate data plane. - * For packed sample formats, only the first data plane is used, and samples for each channel are interleaved. + * + * 对于planar的采样格式, 每个声道的数据是独立存储在data中; + * 对于packed的采样格式, 只使用第一个data, 每个声道的数据是交错存储的。 */ typedef enum { /** Unsigned 8 bits, packed */ @@ -228,7 +229,7 @@ typedef enum { /** * @brief 定义视频编解码能力 */ -#define PIX_FORMAT_NUM 16 /** Indicates the array size of supported pixel formats */ +#define PIX_FORMAT_NUM 16 /** 支持的像素格式数组大小 */ typedef struct { Rect minSize; /** 支持的最小分辨率 */ Rect maxSize; /** 支持的最大分辨率 */ @@ -330,12 +331,12 @@ struct OmxCodecBuffer { uint32_t size; /** 结构体大小 */ union OMX_VERSIONTYPE version; /** 组件版本信息 */ enum BufferType bufferType; /** buffer类型 */ - uint8_t *buffer; /** buffer */ + uint8_t *buffer; /** 编码或者解码使用的buffer */ uint32_t bufferLen; /** buffer大小 */ uint32_t allocLen; /** 申请的buffer大小 */ uint32_t filledLen; /** 填充的buffer大小 */ uint32_t offset; /** 有效数据从缓冲区开始的起始偏移量 */ - int32_t fenceFd; /** fenceFd */ + int32_t fenceFd; /** 该描述符来自buffer消费者, Codec等待成功后才可以使用输入或者输出buffer */ enum ShareMemTypes type; /** 共享内存类型 */ int64_t pts; /** 时间戳 */ uint32_t flag; /** 标志 */ -- Gitee