# Codec - [Introduction](#section11660541593) - [Directory Structure](#section161941989596) - [Available APIs](#section1551164914237) - [Usage Guidelines](#section129654513264) - [Repositories Involved](#section1371113476307) ## Introduction This repository mainly defines and implements the Hardware Driver Interfaces \(HDIs\) of the codec module, allowing upper-layer services to perform the following operations: - Creating and destroying a codec - Starting and stopping the codec - Encoding original code streams into compressed code streams - Decoding compressed code streams into original code streams - Flushing the cache ## Directory Structure The source code directory structure is as follows: ``` /drivers/peripheral/codec ├── interfaces # Driver capability APIs provided for upper-layer services │ └── include # APIs exposed externally ``` ### Available APIs The codec module provides APIs that can be directly called by the framework layer to create or destroy a codec, start or stop a codec, perform encoding or decoding operations, flush the cache, and set a callback. [Table 1](#table1513255710559) describes major HDI APIs provided by the codec module. **Table 1** Major HDI APIs of the codec module

Header File

API

Description

codec_interface.h

int32_t CodecInit();

Initializes the internal audio and video submodules of the codec.

int32_t CodecDeinit();

Deinitializes the internal audio and video submodules of the codec.

int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap);

Obtains the capabilities of a specified media type based on an index.

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

Obtains the capabilities of a specified media type.

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

Creates a specific codec component and returns the component context through a handle.

int32_t CodecDestroy(CODEC_HANDLETYPE handle);

Destroys a codec component.

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

Sets the input or output buffer mode.

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

Sets parameters required by a codec component.

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

Obtains parameters from a codec component.

int32_t CodecStart(CODEC_HANDLETYPE handle);

Starts a codec component.

int32_t CodecStop(CODEC_HANDLETYPE handle);

Stops a codec component.

int32_t CodecFlush(CODEC_HANDLETYPE handle, DirectionType directType);

Clears the cache when the codec component is the running state.

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

Queues input data.

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

Dequeues input data that has been used.

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

Queues output data.

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

Dequeues output data.

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

Sets the callback function.

### Usage Guidelines The core functionalities of this repository are as follows: - Provides codec HDIs that can be directly called by the framework layer to perform encoding and decoding-related operations. - Provides standard interfaces for device developers to ensure that the OEM vendors comply with the HDI adapter standard. This promises a healthy evolution of the ecosystem. For details about the invocation and implementation, see the API reference. ## Repositories Involved [Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver-subsystem.md) [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) [drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) drivers\_peripheral