Codec

Overview

Defines codec-related APIs.

including custom data types and functions for initializing audio and video codecs, setting parameters, and controlling and transferring data.

Since:

1.0

Version:

1.0

Summary

Files

File Name

Description

codec_interface.h

Declares codec-related APIs, including functions for initializing audio and video codecs, setting parameters, and controlling and transferring data.

codec_type.h

Declares custom data types used in API declarations for the Codec module, including the codec types, audio and video parameters, input and output data, and callbacks.

Data Structures

Data Structure Name

Description

Param

Describes the dynamic parameter structure, which is mainly used by CodecCreate and CodecSetParameter.

BufferHandle

Defines the buffer handle type. The virtual address of a handle maps to its physical address.

CodecBufferInfo

Describes buffer information.

InputInfo

Describes input information.

OutputInfo

Describes output information.

ResizableArray

Defines a variable-length queue.

Alginment

Defines the alignment.

Rect

Defines a rectangle.

Capbility

Defines the codec capability.

CodecCallback

Defines callbacks and their parameters.

Macros

Macro Name and Value

Description

ELEMENT_MAX_LEN 50

Indicates the maximum number of reserved parameters in the array.

Typedefs

Typedef Name

Description

CODEC_HANDLETYPE

typedef void

Defines the pointer to the codec handle, which is the context information for function calls.

ValueType

typedef void

Defines the pointer to the type of the dynamic parameter value.

BufferHandle

typedef struct BufferHandle

Defines the buffer handle type. The virtual address of a handle maps to its physical address.

BufferType

typedef enum BufferType

Enumerates buffer types.

OutputInfo

typedef struct OutputInfo

Describes output information.

AllocateBufferMode

typedef enum AllocateBufferMode

Enumerates allocation modes of input and output buffers.

CapsMask

typedef enum CapsMask

Enumerates playback capabilities.

CodecCapbility

typedef struct Capbility

Defines the codec capability.

UINTPTR

typedef uintptr_t

Redefines the unsigned pointer type, which is used for pointer conversion.

Enumerations

Enumeration Name

Description

CodecType { VIDEO_DECODER, VIDEO_ENCODER, AUDIO_DECODER, AUDIO_ENCODER, INVALID_TYPE }

Enumerates codec types.

ParamKey { KEY_MIMETYPE = 0x01, KEY_BUFFERSIZE, KEY_LEFT_STREAM_FRAMES, KEY_CODEC_TYPE, KEY_DIRECTION_TYPE, KEY_BITRATE = 0x500, KEY_WIDTH = 0x1000, KEY_HEIGHT, KEY_STRIDE, KEY_VIDEO_FIELD, KEY_PIXEL_FORMAT, KEY_VIDEO_RC_MODE, KEY_VIDEO_GOP_MODE, KEY_VIDEO_PIC_SIZE, KEY_VIDEO_PROFILE, KEY_VIDEO_FRAME_RATE, KEY_SAMPLE_RATE = 0x1500, KEY_AUDIO_PROFILE, KEY_CHANNEL_COUNT, KEY_BITWITH, KEY_SOUND_MODE, KEY_POINT_NUM_PER_FRAME, KEY_DEVICE_ID }

Enumerates indexes of parameter types.

VenCodeRcMode { VENCOD_RC_CBR = 0, VENCOD_RC_VBR, VENCOD_RC_AVBR, VENCOD_RC_QVBR, VENCOD_RC_CVBR, VENCOD_RC_QPMAP, VENCOD_RC_FIXQP }

Enumerates control modes of the channel encoding rate.

PicSize { Resolution_CIF, Resolution_360P, Resolution_D1_PAL, Resolution_D1_NTSC, Resolution_720P, Resolution_1080P, Resolution_INVALID }

Enumerates resolutions.

VenCodeGopMode { VENCOD_GOPMODE_NORMALP = 0, VENCOD_GOPMODE_DUALP = 1, VENCOD_GOPMODE_SMARTP = 2, VENCOD_GOPMODE_ADVSMARTP = 3, VENCOD_GOPMODE_BIPREDB = 4, VENCOD_GOPMODE_LOWDELAYB = 5, VENCOD_GOPMODE_INVALID }

Enumerates types of group of pictures (GOP).

VideoField { VID_FIELD_TOP = 0x1, VID_FIELD_BOTTOM = 0x2, VID_FIELD_INTERLACED = 0x3, VID_FIELD_FRAME = 0x4, VID_FIELD_INVALID }

Enumerates video frame fields.

PixelFormat { YVU_SEMIPLANAR_420 = 0, YVU_SEMIPLANAR_420_TILE, PIX_FORMAT_INVALID }

Enumerates pixel formats.

AudioSoundMode { AUD_SOUND_MODE_MONO = 0, AUD_SOUND_MODE_STEREO = 1, AUD_SOUND_MODE_INVALID }

Enumerates audio channel modes.

AudioSampleRate { AUD_SAMPLE_RATE_8000 = 8000, AUD_SAMPLE_RATE_12000 = 12000, AUD_SAMPLE_RATE_11025 = 11025, AUD_SAMPLE_RATE_16000 = 16000, AUD_SAMPLE_RATE_22050 = 22050, AUD_SAMPLE_RATE_24000 = 24000, AUD_SAMPLE_RATE_32000 = 32000, AUD_SAMPLE_RATE_44100 = 44100, AUD_SAMPLE_RATE_48000 = 48000, AUD_SAMPLE_RATE_64000 = 64000, AUD_SAMPLE_RATE_96000 = 96000, AUD_SAMPLE_RATE_INVALID }

Enumerates audio sampling rates.

AudioBitRate { AUD_AAC_BPS_8K = 8000, AUD_AAC_BPS_16K = 16000, AUD_AAC_BPS_22K = 22000, AUD_AAC_BPS_24K = 24000, AUD_AAC_BPS_32K = 32000, AUD_AAC_BPS_48K = 48000, AUD_AAC_BPS_64K = 64000, AUD_AAC_BPS_96K = 96000, AUD_AAC_BPS_128K = 128000, AUD_AAC_BPS_256K = 256000, AUD_AAC_BPS_320K = 320000 }

Enumerates audio bit rates.

StreamFlagType { STREAM_FLAG_KEYFRAME = 1, STREAM_FLAG_CODEC_SPECIFIC_INF = 2, STREAM_FLAG_EOS = 4, STREAM_FLAG_PART_OF_FRAME = 8, STREAM_FLAG_END_OF_FRAME = 16 }

Enumerates stream flags.

BufferType { BUFFER_TYPE_VIRTUAL = 0, BUFFER_TYPE_FD, BUFFER_TYPE_HANDLE }

Enumerates buffer types.

AvCodecMime { MEDIA_MIMETYPE_IMAGE_JPEG = 0, MEDIA_MIMETYPE_VIDEO_AVC, MEDIA_MIMETYPE_VIDEO_HEVC, MEDIA_MIMETYPE_AUDIO_AAC, MEDIA_MIMETYPE_INVALID }

Enumerates MIME types.

Profile { INVALID_PROFILE = 0, AAC_LC_PROFILE = 0x1000, AAC_MAIN_PROFILE, AAC_HE_V1_PROFILE, AAC_HE_V2_PROFILE, AAC_LD_PROFILE, AAC_ELD_PROFILE, AVC_BASELINE_PROFILE = 0x2000, AVC_MAIN_PROFILE, AVC_HIGH_PROFILE, HEVC_MAIN_PROFILE = 0x3000, HEVC_MAIN_10_PROFILE }

Enumerates codec profiles.

Level { INVALID_LEVEL = 0, AVC_LEVEL_1 = 0x1000, HEVC_LEVEL_MAIN_1 = 0x2000, HEVC_LEVEL_MAIN_2 }

Enumerates codec levels.

AllocateBufferMode { ALLOCATE_INPUT_BUFFER_CODEC = 0x1, ALLOCATE_INPUT_BUFFER_USER = 0x2, ALLOCATE_OUTPUT_BUFFER_CODEC = 0x4, ALLOCATE_OUTPUT_BUFFER_USER = 0x8 }

Enumerates allocation modes of input and output buffers.

CapsMask { ADAPTIVE_PLAYBACK = 0x1, SECURE_PLAYBACK = 0x2 }

Enumerates playback capabilities.

EventType { EventError, EventFlushCompelte, EventStopCompelte, EventOutFormatChanged, EventMax = 0x1FFFFFFF }

Enumerates event types.

DirectionType { INPUT_TYPE, OUTPUT_TYPE, ALL_TYPE }

Enumerates input and output types.

BufferMode { INTERNAL, EXTERNAL }

Enumerates allocation types.

{ CODEC_ERR_STREAM_BUF_FULL = 100, CODEC_ERR_FRAME_BUF_EMPTY, CODEC_RECEIVE_EOS, CODEC_ERR_INVALID_OP }

Enumerates codec error types.

Functions

Function Name

Description

CodecInit ()

int32_t

Initializes the internal audio and video submodules of the codec.

CodecDeinit ()

int32_t

Deinitializes the internal audio and video submodules of the codec.

CodecEnumerateCapbility (uint32_t index, CodecCapbilitycap)

int32_t

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

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

int32_t

Obtains the capabilities of a specified media type.

CodecCreate (const char name, const Paramattr, int len, CODEC_HANDLETYPEhandle)

int32_t

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

CodecDestroy (CODEC_HANDLETYPE handle)

int32_t

Destroys a codec component.

CodecSetPortMode (CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode)

int32_t

Sets the input or output buffer mode.

CodecSetParameter (CODEC_HANDLETYPE handle, const Param params, int paramCnt)

int32_t

Sets parameters required by a codec component.

CodecGetParameter (CODEC_HANDLETYPE handle, Paramparams, int paramCnt)

int32_t

Obtains parameters from a codec component.

CodecStart (CODEC_HANDLETYPE handle)

int32_t

Starts a codec component.

CodecStop (CODEC_HANDLETYPE handle)

int32_t

Stops a codec component.

CodecFlush (CODEC_HANDLETYPE handle, DirectionType directType)

int32_t

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

CodecQueueInput (CODEC_HANDLETYPE handle, const InputInfo inputData, uint32_t timeoutMs)

int32_t

Queues input data.

CodecDequeInput (CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfoinputData)

int32_t

Dequeues input data that has been used.

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

int32_t

Queues output data.

CodecDequeueOutput (CODEC_HANDLETYPE handle, uint32_t timeoutMs, int acquireFd, OutputInfooutInfo)

int32_t

Dequeues output data.

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

int32_t

Sets the callback function.

Details

Enumeration Type Documentation

anonymous enum

  1. anonymous enum

Description:

Enumerates codec error types.

Enumerator

Description

CODEC_ERR_STREAM_BUF_FULL

Elementary stream buffer queue is full.

CODEC_ERR_FRAME_BUF_EMPTY

Frame buffer queue is empty.

CODEC_RECEIVE_EOS

End of streams

CODEC_ERR_INVALID_OP

Invalid operation

AllocateBufferMode

  1. enum[AllocateBufferMode]($api-api-SmartVision-Devices-Codec.md#gaeae808d52153b2e33c6815162bbd11e0)

Description:

Enumerates allocation modes of input and output buffers.

Enumerator

Description

ALLOCATE_INPUT_BUFFER_CODEC

Input buffer allocated within the Codec module

ALLOCATE_INPUT_BUFFER_USER

Input buffer allocated by an external user

ALLOCATE_OUTPUT_BUFFER_CODEC

Output buffer allocated within the Codec module

ALLOCATE_OUTPUT_BUFFER_USER

Output buffer allocated by an external user

AudioBitRate

  1. enum[AudioBitRate]($api-api-SmartVision-Devices-Codec.md#gac8cc627a9912e6a338396a6f19bbba5d)

Description:

Enumerates audio bit rates.

Enumerator

Description

AUD_AAC_BPS_8K

8 kbit/s

AUD_AAC_BPS_16K

16 kbit/s

AUD_AAC_BPS_22K

22 kbit/s

AUD_AAC_BPS_24K

24 kbit/s

AUD_AAC_BPS_32K

32 kbit/s

AUD_AAC_BPS_48K

48 kbit/s

AUD_AAC_BPS_64K

64 kbit/s

AUD_AAC_BPS_96K

96 kbit/s

AUD_AAC_BPS_128K

128 kbit/s

AUD_AAC_BPS_256K

256 kbit/s

AUD_AAC_BPS_320K

320 kbit/s

AudioSampleRate

  1. enum[AudioSampleRate]($api-api-SmartVision-Devices-Codec.md#gaa0280074adafe6d2581d31f71512b842)

Description:

Enumerates audio sampling rates.

Enumerator

Description

AUD_SAMPLE_RATE_8000

8 KHz

AUD_SAMPLE_RATE_12000

12 KHz

AUD_SAMPLE_RATE_11025

11.025 KHz

AUD_SAMPLE_RATE_16000

16 KHz

AUD_SAMPLE_RATE_22050

22.050 KHz

AUD_SAMPLE_RATE_24000

24 KHz

AUD_SAMPLE_RATE_32000

32 KHz

AUD_SAMPLE_RATE_44100

44.1 KHz

AUD_SAMPLE_RATE_48000

48 KHz

AUD_SAMPLE_RATE_64000

64 KHz

AUD_SAMPLE_RATE_96000

96 KHz

AUD_SAMPLE_RATE_INVALID

Invalid sampling rate

AudioSoundMode

  1. enum[AudioSoundMode]($api-api-SmartVision-Devices-Codec.md#gacecb40e35c431a27385f7b439fc7a76c)

Description:

Enumerates audio channel modes.

Enumerator

Description

AUD_SOUND_MODE_MONO

Mono channel

AUD_SOUND_MODE_STEREO

Stereo mode

AUD_SOUND_MODE_INVALID

Invalid mode

AvCodecMime

  1. enum[AvCodecMime]($api-api-SmartVision-Devices-Codec.md#ga1bee586eafa91dfb60f94ba40fc95faa)

Description:

Enumerates MIME types.

Enumerator

Description

MEDIA_MIMETYPE_IMAGE_JPEG

JPEG image

MEDIA_MIMETYPE_VIDEO_AVC

H.264 video

MEDIA_MIMETYPE_VIDEO_HEVC

H.265 video

MEDIA_MIMETYPE_AUDIO_AAC

AAC audio

MEDIA_MIMETYPE_INVALID

Invalid MIME type

BufferMode

  1. enum[BufferMode]($api-api-SmartVision-Devices-Codec.md#gacc0fd55192fd9f663121b037b06f41e8)

Description:

Enumerates allocation types.

Enumerator

Description

INTERNAL

Internal

EXTERNAL

External

BufferType

  1. enum[BufferType]($api-api-SmartVision-Devices-Codec.md#gadf8e136713c0691010d2bec6ba63e9cf)

Description:

Enumerates buffer types.

Enumerator

Description

BUFFER_TYPE_VIRTUAL

Virtual memory

BUFFER_TYPE_FD

File descriptor, which can be used cross processes

BUFFER_TYPE_HANDLE

Handle, which can be used cross processes

CapsMask

  1. enum[CapsMask]($api-api-SmartVision-Devices-Codec.md#gae5751aa8514dcaf2217df12db5ef57a1)

Description:

Enumerates playback capabilities.

Enumerator

Description

ADAPTIVE_PLAYBACK

Adaptive playback

SECURE_PLAYBACK

Secure playback

CodecType

  1. enum[CodecType]($api-api-SmartVision-Devices-Codec.md#ga03b4b6ae5fb82af68d46aaea3d3e4d79)

Description:

Enumerates codec types.

Enumerator

Description

VIDEO_DECODER

Video decoding

VIDEO_ENCODER

Video encoding

AUDIO_DECODER

Audio decoding

AUDIO_ENCODER

Audio encoding

INVALID_TYPE

Invalid type

DirectionType

  1. enum[DirectionType]($api-api-SmartVision-Devices-Codec.md#ga8ef30fa9c08e08c8706653571f9f5b81)

Description:

Enumerates input and output types.

Enumerator

Description

INPUT_TYPE

Input

OUTPUT_TYPE

Output

ALL_TYPE

Input and output

EventType

  1. enum[EventType]($api-api-SmartVision-Devices-Codec.md#ga2628ea8d12e8b2563c32f05dc7fff6fa)

Description:

Enumerates event types.

Enumerator

Description

EventError

Event error

EventFlushCompelte

Buffer flush completed

EventStopCompelte

Codec stopped

EventOutFormatChanged

Output format changed

EventMax

Maximum event value

Level

  1. enum[Level]($api-api-SmartVision-Devices-Codec.md#ga221b779e6bb7b8d40677d7642bfefac5)

Description:

Enumerates codec levels.

Enumerator

Description

INVALID_LEVEL

Invalid level

AVC_LEVEL_1

H.264 level 1

HEVC_LEVEL_MAIN_1

H.265 Main level 1

HEVC_LEVEL_MAIN_2

H.265 Main level 2

ParamKey

  1. enum[ParamKey]($api-api-SmartVision-Devices-Codec.md#ga575c56a2d6b42c48881cf47b0008d5a6)

Description:

Enumerates indexes of parameter types.

Enumerator

Description

KEY_MIMETYPE

MIME type. For the value type, see AvCodecMime.

KEY_BUFFERSIZE

Buffer size. The value type is uint32_t.

KEY_LEFT_STREAM_FRAMES

Number of frames in the remaining data streams. The value type is uint32_t.

KEY_CODEC_TYPE

Codec type. For the value type, see CodecType.

KEY_DIRECTION_TYPE

Input/Output type. For the value type, see DirectionType.

KEY_BITRATE

Bit rate. The value type is uint32_t.

KEY_WIDTH

Width. The value type is uint32_t.

KEY_HEIGHT

Hight. The value type is uint32_t.

KEY_STRIDE

Stride. The value type is uint32_t.

KEY_VIDEO_FIELD

Video field. For the value type, see VideoField.

KEY_PIXEL_FORMAT

Pixel format. For the value type, see PixelFormat.

KEY_VIDEO_RC_MODE

Rate control mode. For the value type, see VenCodeRcMode.

KEY_VIDEO_GOP_MODE

GOP mode. For the value type, see VenCodeGopMode.

KEY_VIDEO_PIC_SIZE

Image resolution. For the value type, see PicSize.

KEY_VIDEO_PROFILE

Codec profile. The value type is uint32_t.

KEY_VIDEO_FRAME_RATE

Frame rate. The value type is uint32_t.

KEY_SAMPLE_RATE

Sampling rate. The value type is uint32_t.

KEY_AUDIO_PROFILE

Audio encoding profile. The value type is uint32_t.

KEY_CHANNEL_COUNT

Number of channels. The value type is uint32_t.

KEY_BITWITH

Bit width. For the value type, see AudioBitWidth.

KEY_SOUND_MODE

Audio channel mode. For the value type, see AudioSoundMode.

KEY_POINT_NUM_PER_FRAME

Number of sampling points per frame. The value type is uint32_t.

KEY_DEVICE_ID

Device ID. The value type is uint32_t.

PicSize

  1. enum[PicSize]($api-api-SmartVision-Devices-Codec.md#ga94981b885085085ed5f9dea406519b48)

Description:

Enumerates resolutions.

Enumerator

Description

Resolution_CIF

352x288

Resolution_360P

640x360

Resolution_D1_PAL

720x576

Resolution_D1_NTSC

720x480

Resolution_720P

1280x720

Resolution_1080P

1920x1080

Resolution_INVALID

Invalid resolution

PixelFormat

  1. enum[PixelFormat]($api-api-SmartVision-Devices-Codec.md#ga60883d4958a60b91661e97027a85072a)

Description:

Enumerates pixel formats.

Enumerator

Description

YVU_SEMIPLANAR_420

YUV 420 SP

YVU_SEMIPLANAR_420_TILE

YUV SP 420 TILE

PIX_FORMAT_INVALID

Invalid format

Profile

  1. enum[Profile]($api-api-SmartVision-Devices-Codec.md#ga85b10143618f300ff4f5bc6d45c72c01)

Description:

Enumerates codec profiles.

Enumerator

Description

INVALID_PROFILE

Invalid profile

AAC_LC_PROFILE

AAC-Low Complex

AAC_MAIN_PROFILE

AAC-Main

AAC_HE_V1_PROFILE

HEAAC, AAC+, or AACPlusV1

AAC_HE_V2_PROFILE

AAC++ or AACPlusV2

AAC_LD_PROFILE

AAC-Low Delay

AAC_ELD_PROFILE

AAC-Enhanced Low Delay

AVC_BASELINE_PROFILE

H.264 Baseline

AVC_MAIN_PROFILE

H.264 Main

AVC_HIGH_PROFILE

H.264 High

HEVC_MAIN_PROFILE

H.265 Main

HEVC_MAIN_10_PROFILE

H.265 Main 10

StreamFlagType

  1. enum[StreamFlagType]($api-api-SmartVision-Devices-Codec.md#ga8a15793172118d64d8adeba0c8544e84)

Description:

Enumerates stream flags.

Enumerator

Description

STREAM_FLAG_KEYFRAME

Keyframe

STREAM_FLAG_CODEC_SPECIFIC_INF

Codec specifications

STREAM_FLAG_EOS

End of streams

STREAM_FLAG_PART_OF_FRAME

Partial frame

STREAM_FLAG_END_OF_FRAME

End of frames, used in pair with STREAM_FLAG_PART_OF_FRAME

VenCodeGopMode

  1. enum[VenCodeGopMode]($api-api-SmartVision-Devices-Codec.md#ga9532f651a003219a262c440f5621d129)

Description:

Enumerates types of group of pictures (GOP).

Enumerator

Description

VENCOD_GOPMODE_NORMALP

P-frames using only one reference frame during encoding

VENCOD_GOPMODE_DUALP

P-frames using two reference frames during encoding

VENCOD_GOPMODE_SMARTP

Smart P-frames for encoding

VENCOD_GOPMODE_ADVSMARTP

Advanced smart P-frames for encoding

VENCOD_GOPMODE_BIPREDB

B-frames for encoding

VENCOD_GOPMODE_LOWDELAYB

B-frames using only previous frames as references during encoding.

VENCOD_GOPMODE_INVALID

Invalid type

VenCodeRcMode

  1. enum[VenCodeRcMode]($api-api-SmartVision-Devices-Codec.md#ga94267d7ba495136561e1c65686b240f7)

Description:

Enumerates control modes of the channel encoding rate.

Enumerator

Description

VENCOD_RC_CBR

Fixed bit rate

VENCOD_RC_VBR

Variable bit rate

VENCOD_RC_AVBR

Adaptive variable bit rate

VENCOD_RC_QVBR

Quality-defined variable bit rate

VENCOD_RC_CVBR

Constrained variable bit rate

VENCOD_RC_QPMAP

Configuration-mapped quantization parameters

VENCOD_RC_FIXQP

Fixed quantization parameters

VideoField

  1. enum[VideoField]($api-api-SmartVision-Devices-Codec.md#ga1420ddfb066b941fb55a153b869d9ccf)

Description:

Enumerates video frame fields.

Enumerator

Description

VID_FIELD_TOP

Top fields on even-number lines

VID_FIELD_BOTTOM

Bottom fields on odd-number lines

VID_FIELD_INTERLACED

Interlaced fields

VID_FIELD_FRAME

Non-interlaced frames

VID_FIELD_INVALID

Invalid fields

Function Documentation

CodecCreate()

  1. int32_tCodecCreate(constchar* name,const[Param]($api-api-SmartVision-Devices-zh-cn_topic_0000001054718161.md)* attr,int len,[CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) * handle )

Description:

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

You can adjust the parameters required for creating a component based on service requirements.

Parameters:

Name

Description

name

Indicates the pointer to the unique name of the component, for example, codec.avc.hardware.decoder.

attr

Indicates the pointer to the parameters in the array required for creating the component.

len

Indicates the number of elements in the parameter array.

handle

Indicates the pointer to the codec handle returned.

Returns:

Returns 0 if the codec component is created and the handle is available; returns a non-zero value otherwise.

CodecDeinit()

  1. int32_tCodecDeinit()

Description:

Deinitializes the internal audio and video submodules of the codec.

This function needs to be called only once in a process.

Returns:

Returns 0 if the deinitialization is successful; returns a non-zero value otherwise.

See also:

CodecInit

CodecDequeInput()

  1. int32_tCodecDequeInput([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, uint32_t timeoutMs, [InputInfo]($api-api-SmartVision-Devices-zh-cn_topic_0000001054879536.md) * inputData )

Description:

Dequeues input data that has been used.

This function works with CodecQueueInput to implement input data transmission.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

timeoutMs

Indicates the timeout duration. Generally, the value is less than or equal to 3 seconds.

inputData

Indicates the pointer to the input data that is used.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.

CodecDequeueOutput()

  1. int32_tCodecDequeueOutput([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, uint32_t timeoutMs, int * acquireFd, [OutputInfo]($api-api-SmartVision-Devices-zh-cn_topic_0000001054918167.md) * outInfo )

Description:

Dequeues output data.

This function works with CodecQueueOutput to implement output data transmission.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

timeoutMs

Indicates the timeout duration.

acquireFd

Indicates that this parameter is derived from the codec mode. The output data can be used only after waiting for acquireFd is successful. The value -1 indicates that acquireFd is invalid.

outInfo

Indicates the pointer to the output data.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.

CodecDestroy()

  1. int32_tCodecDestroy([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle)

Description:

Destroys a codec component.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

Returns:

Returns 0 if the codec component is destroyed; returns a non-zero value otherwise.

See also:

CodecCreate

CodecEnumerateCapbility()

  1. int32_tCodecEnumerateCapbility(uint32_t index,[CodecCapbility]($api-api-SmartVision-Devices-Codec.md#ga1876710b1f2fe1d80e8b9de9ff28e0e3) * cap )

Description:

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

You can call this function repeatedly to obtain the codec capabilities until CODEC_END is returned. The corresponding capabilities are described in the Capability structure, including the maximum and minimum resolutions, maximum and minimum bit rates, and supported profiles and levels. After obtaining the capabilities, determine whether they can meet your requirements, for example, whether specific media files can be played and whether audio and video frames can be compressed.

Parameters:

Name

Description

index

Indicates the index of the capabilities.

cap

Indicates the pointer to the capabilities.

Returns:

Returns CODEC_SUCCESS if the capabilities corresponding to the index are available; returns CODEC_END otherwise.

CodecFlush()

  1. int32_tCodecFlush([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, [DirectionType]($api-api-SmartVision-Devices-Codec.md#ga8ef30fa9c08e08c8706653571f9f5b81) directType )

Description:

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

Generally, this function is called when the seek operation is performed during playback.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.

CodecGetCapbility()

  1. int32_tCodecGetCapbility([AvCodecMime]($api-api-SmartVision-Devices-Codec.md#ga1bee586eafa91dfb60f94ba40fc95faa) mime, [CodecType]($api-api-SmartVision-Devices-Codec.md#ga03b4b6ae5fb82af68d46aaea3d3e4d79) type, uint32_t flags, [CodecCapbility]($api-api-SmartVision-Devices-Codec.md#ga1876710b1f2fe1d80e8b9de9ff28e0e3) * cap )

Description:

Obtains the capabilities of a specified media type.

You can call this function to obtain the codec capabilities. The corresponding capabilities are described in the Capability structure, including the maximum and minimum resolutions, maximum and minimum bit rates, and supported profiles and levels. After obtaining the capabilities, determine whether they can meet your requirements, for example, whether specific media files can be played and whether audio and video frames can be compressed.

Parameters:

Name

Description

mime

Indicates the media type. For details, see AvCodecMime.

type

Indicates the audio and video codec types. For details, see CodecType.

flags

Indicates the audio and video codec flags. 0 indicates hardware codec, and 1 indicates software codec.

cap

Indicates the pointer to the capabilities.

Returns:

Returns 0 if the codec is supported and capabilities are available; returns a non-zero value if the codec is not supported or the capabilities are unavailable.

CodecGetParameter()

  1. int32_tCodecGetParameter([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, [Param]($api-api-SmartVision-Devices-zh-cn_topic_0000001054718161.md) * params, int paramCnt )

Description:

Obtains parameters from a codec component.

This function must be called after CodecCreate.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

params

Indicates the pointer to the parameters in the array used when the component is created.

paramCnt

Indicates the number of elements in the parameter array.

Returns:

Returns 0 if all parameters to obtain are supported; returns a non-zero value otherwise.

See also:

CodecSetParameter

CodecInit()

  1. int32_tCodecInit()

Description:

Initializes the internal audio and video submodules of the codec.

This function needs to be called only once in a process.

Returns:

Returns 0 if the initialization is successful; returns a non-zero value otherwise.

See also:

CodecDeinit

CodecQueueInput()

  1. int32_tCodecQueueInput([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, const [InputInfo]($api-api-SmartVision-Devices-zh-cn_topic_0000001054879536.md) * inputData, uint32_t timeoutMs )

Description:

Queues input data.

This function works with CodecDequeInput to implement input data transmission.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

inputData

Indicates the pointer to the input data.

timeoutMs

Indicates the timeout duration.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.

CodecQueueOutput()

  1. int32_tCodecQueueOutput([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, [OutputInfo]($api-api-SmartVision-Devices-zh-cn_topic_0000001054918167.md) * outInfo, uint32_t timeoutMs, int releaseFenceFd )

Description:

Queues output data.

This function works with CodecDequeueOutput to implement output data transmission.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

outInfo

Indicates the pointer to the output data.

timeoutMs

Indicates the timeout duration.

releaseFenceFd

Indicates that the descriptor comes from a buffer consumer. The output data can be used only after waiting for releaseFenceFd is successful. The value -1 indicates that releaseFenceFd is invalid.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.

CodecSetCallback()

  1. int32_tCodecSetCallback([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, const [CodecCallback]($api-api-SmartVision-Devices-zh-cn_topic_0000001055358102.md) * cb, [UINTPTR]($api-api-SmartVision-Devices-Codec.md#ga58d2f4a8d12daa1dcf4eb297f3ebaabc) instance )

Description:

Sets the callback function.

The codec uses the callback function to notify the upper layer of events and asynchronously report available input/output information.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

cb

Indicates the pointer to the callback function. For details, see CodecCallback.

instance

Indicates the upper-layer instance to be notified.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.

CodecSetParameter()

  1. int32_tCodecSetParameter([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, const [Param]($api-api-SmartVision-Devices-zh-cn_topic_0000001054718161.md) * params, int paramCnt )

Description:

Sets parameters required by a codec component.

You should call this function to set parameters after CodecCreate is called but before CodecStart is called.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

params

Indicates the pointer to the parameters to set in the array.

paramCnt

Indicates the number of elements in the parameter array.

Returns:

Returns 0 if the setting is successful; returns a non-zero value otherwise.

See also:

CodecGetParameter

CodecSetPortMode()

  1. int32_tCodecSetPortMode([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle, [DirectionType]($api-api-SmartVision-Devices-Codec.md#ga8ef30fa9c08e08c8706653571f9f5b81) type, [BufferMode]($api-api-SmartVision-Devices-Codec.md#gacc0fd55192fd9f663121b037b06f41e8) mode )

Description:

Sets the input or output buffer mode.

You can learn about the support of the codec input/output buffer for internal and external buffer modes by calling CodecGetCapbility. In this way, you can determine whether to use an internal or external buffer mode. If the current codec can use only the specific buffer mode, you do not need to set it.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

type

Specifies whether the buffer type is an input type or an output type.

mode

Specifies whether to use an internal or external buffer mode.

Returns:

Returns 0 if the setting is successful; returns a non-zero value otherwise.

CodecStart()

  1. int32_tCodecStart([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle)

Description:

Starts a codec component.

You can restart a component after it is stopped.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.

CodecStop()

  1. int32_tCodecStop([CODEC_HANDLETYPE]($api-api-SmartVision-Devices-Codec.md#ga9381a619f36ac8d5d7f467d2f0404183) handle)

Description:

Stops a codec component.

Parameters:

Name

Description

handle

Indicates the handle of the codec component.

Returns:

Returns 0 if the operation is successful; returns a non-zero value otherwise.