# Codec - [Codec](#codec) - [简介](#简介) - [目录](#目录) - [接口说明](#接口说明) - [使用说明](#使用说明) - [相关仓](#相关仓) - [相关仓](#section1371113476307) ## 简介 该仓下主要包含Codec模块HDI(Hardware Driver Interface)接口定义及其实现,对上层提供媒体编解码的驱动能力接口,HDI接口主要提供如下功能: - 创建、销毁编解码器对象; - 启停编解码器 - 原始码流编码为压缩码流; - 压缩码流恢复为原始码流 - 清除编解码缓存。 ## 目录 该仓下源代码目录结构如下所示 ``` /drivers/peripheral/codec ├── interfaces # codec模块对上层服务提供的驱动能力接口 │ └── include # codec模块对外提供的接口定义 ``` ### 接口说明 Codec驱动提供给framework层可直接调用的能力接口,主要功能有:创建、销毁编解码器对象,启停编解码器操作,编解码处理、清除缓存、事件上报等。 提供的部分接口说明如下表所示: **表 1** Codec HDI 1.0接口列表

头文件

接口名称

功能描述

codec_interface.h

int32_t CodecInit();

codec模块初始化处理

int32_t CodecDeinit();

codec模块去初始化处理

int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap);

获取某一个编解码能力

int32_t CodecGetCapbility(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapbility *cap);

获取指定编解码能力

int32_t CodecCreate(const char* name, const Param *attr, int len, CODEC_HANDLETYPE *handle);

创建编解码对象

int32_t CodecDestroy(CODEC_HANDLETYPE handle);

销毁编解码对象

int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode);

设置端口buffer模式:内部buffer或外部buffer

int32_t CodecSetParameter(CODEC_HANDLETYPE handle, const Param *params, int paramCnt);

扩展接口。设置编解码属性

int32_t CodecGetParameter(CODEC_HANDLETYPE handle, Param *params, int paramCnt);

扩展接口。获取编解码属性

int32_t CodecStart(CODEC_HANDLETYPE handle);

启动工作

int32_t CodecStop(CODEC_HANDLETYPE handle);

停止工作

int32_t CodecFlush(CODEC_HANDLETYPE handle, DirectionType directType);

清除缓存处理

int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const InputInfo *inputData, uint32_t timeoutMs);

送入输入buffer

int32_t CodecDequeInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfo *inputData);

取出输入buffer

int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, OutputInfo *outInfo, uint32_t timeoutMs, int releaseFenceFd);

送入输出buffer

int32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int *acquireFd, OutputInfo *outInfo);

取出输出buffer

int32_t CodecSetCallback(CODEC_HANDLETYPE handle, const CodecCallback *cb, UINTPTR instance);

设置回调函数

除了上述接口外,基于OMX接口提供了Codec HDI 2.0接口,接口说明如下表所示: **表 2** Codec HDI 2.0接口列表

头文件

接口名称

功能描述

codec_component _manager.h

int32_t (*GetComponentNum)();

获取Codec编解码组件数量

int32_t (*GetComponentCapabilityList)(CodecCompCapability *capList, int32_t count);

获取编解码能力集表

int32_t (*CreateComponent)(struct CodecComponentType **component, uint32_t *componentId, char *compName, int64_t appData, struct CodecCallbackType *callbacks);

创建Codec组件实例

int32_t (*DestroyComponent)(uint32_t componentId);

销毁组件实例

codec_component _if.h

int32_t (*GetComponentVersion)(struct CodecComponentType *self, struct CompVerInfo *verInfo);

获取Codec组件版本号

int32_t (*SendCommand)(struct CodecComponentType *self, enum OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen);

发送命令给组件

int32_t (*GetParameter)(struct CodecComponentType *self, uint32_t paramIndex, int8_t *paramStruct, uint32_t paramStructLen);

获取组件参数设置

int32_t (*SetParameter)(struct CodecComponentType *self, uint32_t index, int8_t *paramStruct, uint32_t paramStructLen);

设置组件需要的参数

int32_t (*GetConfig)(struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen);

获取组件的配置结构

int32_t (*SetConfig)(struct CodecComponentType *self, uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen);

设置组件的配置

int32_t (*GetExtensionIndex)(struct CodecComponentType *self, const char *paramName, uint32_t *indexType);

根据字符串获取组件的扩展索引

int32_t (*GetState)(struct CodecComponentType *self, enum OMX_STATETYPE *state);

获取组件的状态

int32_t (*ComponentTunnelRequest)(struct CodecComponentType *self, uint32_t port, int32_t tunneledComp, uint32_t tunneledPort, struct OMX_TUNNELSETUPTYPE *tunnelSetup);

设置组件Tunneled方式通信

int32_t (*UseBuffer)(struct CodecComponentType *self, uint32_t portIndex, struct OmxCodecBuffer *buffer);

指定组件端口的buffer

int32_t (*AllocateBuffer)(struct CodecComponentType *self, uint32_t portIndex, struct OmxCodecBuffer *buffer);

向组件申请端口buffer

int32_t (*FreeBuffer)(struct CodecComponentType *self, uint32_t portIndex, const struct OmxCodecBuffer *buffer);

释放buffer

int32_t (*EmptyThisBuffer)(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer);

编解码输入待处理buffer

int32_t (*FillThisBuffer)(struct CodecComponentType *self, const struct OmxCodecBuffer *buffer);

编解码输出填充buffer

int32_t (*SetCallbacks)(struct CodecComponentType *self, struct CodecCallbackType *callback, int64_t appData);

设置Codec组件的回调函数

int32_t (*ComponentDeInit)(struct CodecComponentType *self);

组件去初始化

int32_t (*UseEglImage)(struct CodecComponentType *self, struct OmxCodecBuffer *buffer, uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen);

使用已在ELG中申请的空间

int32_t (*ComponentRoleEnum)(struct CodecComponentType *self, uint8_t *role, uint32_t roleLen, uint32_t index);

获取组件角色

codec_callback_if.h

int32_t (*EventHandler)(struct CodecCallbackType *self, enum OMX_EVENTTYPE event, struct EventInfo *info);

事件上报

int32_t (*EmptyBufferDone)(struct CodecCallbackType *self, int64_t appData, const struct OmxCodecBuffer *buffer);

上报输入buffer编码或者解码处理完毕

int32_t (*FillBufferDone)(struct CodecCallbackType *self, int64_t appData, const struct OmxCodecBuffer *buffer);

上报输出buffer填充完毕

### 使用说明 该仓核心功能包括两个方面: - 提供Codec HDI接口供framework层调用,实现编码和解码基本功能。 - 作为标准南向接口,保证南向OEM产商实现HDI-adapter的规范性,保证生态良性演进。 具体接口调用及实现,以接口注释为准。 ## 相关仓 [驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md) [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) [drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md) [drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral)