H.264 PC Decoding Library Software API Reference
H.264 PC Decoding Library Software API Reference
H.264 PC Decoding Library Software API Reference
API Reference
Issue 15
Date 2017-07-17
Copyright © HiSilicon Technologies Co., Ltd. 2016-2017. All rights reserved.
No part of this document may be reproduced or transmitted in any form or by any means without prior
written consent of HiSilicon Technologies Co., Ltd.
, , and other HiSilicon icons are trademarks of HiSilicon Technologies Co., Ltd.
All other trademarks and trade names mentioned in this document are the property of their respective
holders.
Notice
The purchased products, services and features are stipulated by the contract made between HiSilicon and
the customer. All or part of the products, services and features described in this document may not be
within the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,
information, and recommendations in this document are provided “AS IS” without warranties, guarantees or
representations of any kind, either express or implied.
The information in this document is subject to change without notice. Every effort has been made in the
preparation of this document to ensure accuracy of the contents, but all statements, information, and
recommendations in this document do not constitute a warranty of any kind, express or implied.
Website: http://www.hisilicon.com
Email: [email protected]
Purpose
This document describes the document contents, related product versions, intended audience,
conventions and update history.
Unless otherwise specified, this document applies to the Hi3516A and Hi3516D.
Unless otherwise specified, this document applies to the Hi3559 V100 and Hi3556 V100.
Unless otherwise specified, this document applies to the Hi3519 V101 and Hi3516A V200
Related Versions
The following table lists the product versions related to this document.
Hi3516 V100
Hi3531 V100
Hi3532 V100
Hi3521 V100
Hi3520A V100
Hi3518 V100
Hi3516C V100
Hi3520D V100
Hi3515A V100
Hi3516A V100
Hi3516D V100
Hi3518E V200
Hi3518E V201
Hi3516C V200
Hi3519 V100
Hi3519 V101
Hi3536 V100
Hi3531A V100
Hi3521A V100
Hi3559 V100
Hi3556 V100
Hi3516A V200
Hi3559A V100ES
Intended Audience
This document is intended for the programmers who meet the following requirements:
Be familiar with C/C++ programming language
Be familiar with 32-bit Windows environment
Conventions
Symbol Conventions
The following symbols may be found in this document. They are defined as follows.
Symbol Description
Symbol Description
General Conventions
Convention Description
Table Contents
Content Description
- Not applicable
* A wild card
Change History
Changes between document issues are cumulative. Therefore, the latest document issue
contains all changes made in previous issues.
Issue 15 (2017-07-17)
This issue is the fifth official release, which incorporates the following changes:
The description of the Hi3559A V100ES is added.
Section 2.1 is modified.
Issue 14 (2017-02-25)
This issue is the fourteenth official release, which incorporates the following changes:
The description of the Hi3556 V100 is added.
Issue 13 (2016-12-25)
This issue is the thirteenth official release, which incorporates the following changes:
Chapter 2 API Description
Issue 12 (2016-07-28)
This issue is the twelfth official release, which incorporates the following changes:
B frame decoding and SVC-T decoding are added. The maximum picture width and height
supported by the decoder is changed to 8192 x 8192.
Issue 11 (2014-12-20)
This issue is the eleventh official release, which incorporates the following changes:
The contents related to the Hi3516D are added.
Issue 10 (2014-08-06)
This issue is the tenth official release, which incorporates the following changes:
The product Hi3516A is added.
Issue 09 (2013-04-08)
This issue is the ninth official release, which incorporates the following changes:
Chapter 1 Overview
Table 1-2 is updated.
Chapter 2 API Description
The Parameter part of Hi264DecCreate is updated.
The Parameter part of Hi264DecGetInfo is updated.
The Parameter part of Hi264DecAU is updated.
The Parameter part of Hi264DecImageEnhance is updated.
Issue 07 (2011-07-05)
This issue is the seventh official release, which incorporates the following changes:
Chapter 3 Data Types and Data Structures
H264_OUTPUT_INFO_S is updated.
The Definition part of H264_DEC_FRAME_S is updated.
Issue 06 (2011-04-29)
This issue is the sixth official release, which incorporates the following changes:
Chapter 1 Overview
The number of library files to be ignored in Table 1-1 is changed from 4 to 6.
Chapter 2 API Description
The Note part of Hi264DecCreate is updated.
Issue 05 (2008-11-10)
This issue is the fifth official release, which incorporates the following changes:
Chapter 2 API Description
Descriptions of bit2 and bit1 of the parameter FunctionSet are changed in section 2.3
"Hi264DecGetInfoare."
Chapter 2 API Description
Information about the Hi3512 is added.
Chapter 3 Data Types and Data Structures
Descriptions of bit2 and bit1 of the decoding library function set are changed in section
3.2.1 "H264_LIBINFO_S."
Descriptions of bit2 and bit1 of the decoder mode are changed in section 3.2.3
"H264_DEC_ATTR_S."
Issue 04 (2008-05-26)
This issue is the fourth official release, which incorporates the following changes:
Chapter 2 API Description
Information about Hi264DecImageEnhance is added.
Chapter 4 API Application Instances
Application instances are changed and the "Picture Enhance" program is added in section 4.2
"Program Instances."
Issue 03 (2008-04-03)
This issue is the third official release, which incorporates the following changes:
Chapter 1 Overview
Descriptions of the dynamic library are deleted in table 1-1.
Chapter 2 API Description
Descriptions of the parameter uWorkMode are changed in section 2.1
"Hi264DecCreate."
Value range of the parameter *pUserData is changed in section 2.1 "Hi264DecCreate."
"Note" part is added in section 2.1 "Hi264DecCreate."
Descriptions of bit[10] of the parameter uFunctionSet are changed in section 2.3
"Hi264DecGetInfo."
Parameter *pUserData and descriptions are added in section 2.4 "Hi264DecFrame" and
section 2.5 "Hi264DecAU."
"Description" part is changed in section 2.5 "Hi264DecAU."
Issue 02 (2008-02-15)
This issue is the second official release, which incorporates the following changes:
Chapter 2 API Description
Return values are changed in section 2.4 "Hi264DecFrame."
Descriptions of the data structures are changed in section 2.4 "Hi264DecFrame."
API function Hi264DecAU is added.
Issue 01 (2007-11-30)
This issue is the first draft release.
Contents
1 Overview......................................................................................................................................... 1
1.1 Scope ................................................................................................................................................................ 1
1.2 Function List .................................................................................................................................................... 2
1.3 Function Description Fields ............................................................................................................................. 3
1.4 Data Structure Description Fields .................................................................................................................... 3
Figures
Tables
1 Overview
1.1 Scope
The H.264 PC decoding library software provided by Shenzhen Hisilicon Semiconductor Co.,
Ltd. is a set of decoding software with high efficiency, reliability, and compatibility. The
decoding library implements the H.264 decoding process internally and provides flexible
application programming interfaces (APIs) for users to develop application programs quickly.
The decoding library software provides two calling modes in Windows, the dynamic library
and the static library. As a result, the application program development becomes easier.
Table 1-1 describes the major components of the decoding library.
Static library hi_h264dec_w.lib When the static library is used, ignore the following
six library files in the compiler options: libm.lib,
libguide.lib, libirc.lib, libc.lib, libmmt.lib, and
svml_disp.lib. Otherwise, an alarm indicating failed
link is displayed during compilation.
Dynamic hi_h264dec_w.lib None
library hi_h264dec_w.dll
Demo hi_h264sample.c Taking decoding a stream file as an example,
demonstrate how to call the decoding library APIs.
Users can develop application programs based on the decoding library in multiple compiling
environments. The decoding library is compatible with Microsoft Windows 2000 or the
mainstream Windows operating systems of the later versions. The decoding library is also
compatible with most of the PC-oriented CPU chipsets launched by Intel or AMD since 2002.
Table 1-2 lists the major development and running environments of the decoding library.
Field Function
2 API Description
2.1 Hi264DecCreate
[Purpose]
To create and initialize the handle of a decoder.
[Syntax]
HI_HDL Hi264DecCreate(H264_DEC_ATTR_S *pDecAttr);
[Description]
Create the handle of a decoder.
Before decoding, the function performs the following operations:
Allocate the decoding space
Initialize the decoder-related variables and states
Set the input stream type, the output picture format, and decoder attributes such as the
maximum width and height and the maximum count of reference frames.
With this API, the upper application can create many decoders in multiple threads for
multi-channel decoding.
[Parameter]
[Return Value]
[Note]
The quick output mode is available only when the decoding order is the same as the
image output order. If the images do not contain B frames, the output delay time can be
reduced by using the quick output mode.
If the internal deinterlace function of a decoder is enabled, this function takes effect only
when the input video is encoded in field mode. When frame video images exist, the
decoder skips the deinterlace process automatically.
Multi-thread decoding is applicable only when a single channel is used for decoding and
each frame contains multiple slices.
To start multi-thread decoding, ensure that input streams are not deblocked at the slice
boundary. If the input streams do not meet the requirement, the decoder disables the
deblocking function at the slice boundary.
The decoding performance is improved by using multiple threads only when the
multi-core CPU decodes the pictures from one channel. This is because thread
scheduling occupies the CPU usage. Therefore, you are not advised to perform
multi-thread decoding when a single-core CPU is used.
The preceding working modes are independent. Therefore, the user can set a working
mode or multiple working modes.
You must ensure sufficient system memory when creating a decoder for decoding
oversized pictures. Otherwise, the decoder fails to be created.
2.2 Hi264DecDestroy
[Purpose]
To destroy the handle of a decoder.
[Syntax]
void Hi264DecDestroy(HI_HDL hDec);
[Description]
When decoding ends, the API destroys the memory space allocated to the decoder to avoid the
memory leakage.
[Parameter]
[Return Value]
None
[Note]
Users need to ensure the validity of the decoding library handle. The decoding library
cannot be repeatedly destroyed.
The destroyed handle should be set to null manually.
2.3 Hi264DecGetInfo
[Purpose]
To query the version information of the decoding library and the function set of the current
version.
[Syntax]
HI_S32 Hi264DecGetInfo(H264_LIBINFO_S *pLibInfo);
[Description]
Before creating the decoder, users can call this function to query the version information of
the decoding library and the function set of the current version.
[Parameter]
[Return Value]
[Note]
None
2.4 Hi264DecFrame
[Purpose]
To decode a segment of input stream and output pictures in the unit of frame.
[Syntax]
HI_S32 Hi264DecFrame
(
HI_HDL hDec
HI_U8 *pStream
HI_U32 iStreamLen
HI_U64 ullPTS
H264_DEC_FRAME_S *pDecFrame
HI_U32 uFlags
);
[Description]
The function supports only the stream decoding. For the continuous, linear H.264 stream with
the NALU separator 00 00 01, decoding can starts from any address and the decoding length
is customized.
[Parameter]
[Return Value]
[Note]
Please note the following two items when calling Hi264DecFrame:
− During the decoding process, the user should divide the stream into segments and
allocate them to the decoder in order. The user allocates segments of the stream to the
decode by calling the function and configures parameters as follows: pStream =
NULL; iStreamLen = 0; uFlags = 0. Then call the function repeatedly and configure a
new segment of stream till the function returns HI_H264DEC_NEED_MORE_BITS.
If the function returns HI_H264DEC_OK in the repeated calling process,, it indicates
that a remaining picture is output. The user must process and save the picture in
pDecFrame in time during the repeated calling process.
− To output the remaining pictures in the decoder when the decoding process ends, the
user can configure parameters as follows: uFlags = 1, pStream = NULL. Then call the
function repeatedly, and stop the decoder till the function returns
HI_H264DEC_NO_PICTURE.
If the function returns HI_H264DEC_OK in the repeated calling process,, it indicates
that a remaining picture is output. The user must process and save the picture in
pDecFrame in time during the repeated calling process.
This function can transmit the time stamp bypass, this is, the time stamp input with the
stream will be output with the decoded frame together. For details, see section
"H264_DEC_FRAME_S."
Users need to ensure the validity of the decoding library handle. The destroyed decoding
libraries and wild pointers cannot be used.
Users need to ensure the validity of the address (pStream) and length (iStreamLen) of
the input stream. Wild pointers cannot be entered, and the stream length cannot exceed
the maximum length of the allocated buffer.
2.5 Hi264DecAU
[Purpose]
To decode the stream containing one frame only and output this frame immediately.
[Syntax]
HI_S32 Hi264DecAU
(
HI_HDL hDec
HI_U8 *pStream
HI_U32 iStreamLen
HI_U64 ullPTS
H264_DEC_FRAME_S *pDecFrame
HI_U32 uFlags
);
[Description]
The Hi264DecAU only supports the input stream that has been split into frames before
decoding. The distributed stream with a frame only should be in the standard H.264 format
with "00 00 01" nalu delimiter.
[Parameter]
[Return Value]
[Note]
Hi264DecAU is similar with Hi264DecFrame, the user can call one of them as required.
− The user should split the stream in the unit of frame during the decoding process.
Each time the stream distributed to Hi264DecAU should contain one frame only.
Otherwise, an output exception may arise.
During the preceding cyclic calling process, if the function returns
HI_H264DEC_OK, it indicates a frame is output; if the function returns
HI_H264DEC_NO_PICTURE, it indicates the configured stream at this time cannot
generate any frame.
− This function supposes the stream input each time contains one frame only, and this
frame is output regardless of whether it is completed.
This function can transmit the time stamp bypass, this is, the time stamp input with the
stream will be output with the decoded frame together. For details, see section
"H264_DEC_FRAME_S."
Users need to ensure the validity of the decoding library handle. The destroyed decoding
libraries and wild pointers cannot be used.
Users need to ensure the validity of the address (pStream) and length (iStreamLen) of
the input stream. Wild pointers cannot be entered, and the stream length cannot exceed
the maximum length of the allocated buffer.
2.6 Hi264DecImageEnhance
[Purpose]
To enhance the decoded pictures.
[Syntax]
HI_S32 Hi264DecImageEnhance
(
HI_HDL hDec,
H264_DEC_FRAME_S *pDecFrame,
HI_U32 uEnhanceCoeff
);
[Description]
After a picture is decoded, you can process the picture to improve the picture quality in some
applications.
[Parameter]
[Return Value]
[Note]
The data structure pointer pDecFrame can function as an input or output parameter. After
obtaining a frame of picture, the user should use the output parameter pDecFrame of
Hi264DecFrame or Hi264DecAU as the input parameter of Hi264DecImageEnhance
without any modification.
Users need to ensure the validity of the decoding library handle. The destroyed decoding
libraries and wild pointers cannot be used.
[Note]
None
3.2.2 H264_USERDATA_S
[Description]
The user data information.
[Definition]
/*User data structure*/
typedef struct hiH264_USERDATA_S
{
HI_U32 uUserDataType; /*User data type */
[Note]
None
3.2.3 H264_DEC_ATTR_S
[Description]
The decoder attribute information.
[Definition]
/*Data structure of the decoder attribute information.*/
typedef struct hiH264_DEC_ATTR_S
{
HI_U32 uPictureFormat; /*Output picture format*/
/* 0x00: The decoder only supports only the YUV420
format at present*/
HI_U32 uStreamInType; /*Input stream format*/
/* 0x00: The decoder supports only the H.264*/
/*stream with the NALU separator 00 00 01*/
HI_U32 uPicWidthInMB; /*Picture width (in the unit of macro block)*/
HI_U32 uPicHeightInMB; /*Picture height (in the unit of macro block)*/
HI_U32 uBufNum; /*Count of the reference frames*/
HI_U32 uWorkMode; /*Decoder working mode*/
/* bit 0: 0: quick output mode; 1: Normal output
mode*/
/* bit 1 to bit 2: */
/* 00: Decode only pictures*/
/* 01: Reserved*/
/* 10: Decode the Hi351x digital watermark*/
/* 11: Reserved */
/* bit 4: 0: The field picture is not
deinterlaced.*/
/* 1: The field picture is
deinterlaced.*/
/* bit 5: 0: Single-thread decoding is
performed.*/
/* 1: Multi-thread decoding is
performed on multiple slices.*/
/* bit 6 to bit 31: reserved*/
H264_USERDATA_S *pUserData; /*User data*/
HI_U32 uReserved; /*Reserved */
} H264_DEC_ATTR_S;
[Note]
None
3.2.4 H264_OUTPUT_INFO_S
[Description]
The decoder output information for each frame.
[Definition]
/* Data structure of the decoder output information for each frame */
typedef struct hiH264_OUTPUT_INFO_S
{
HI_U32 uPicBytes; /*total bytes of one frame*/
HI_U32 uI4MbNum; /*number of I4x4 macroblocks in one frame*/
HI_U32 uI8MbNum; /*number of I8x8 macroblocks in one frame*/
HI_U32 uI16MbNum; /*number of I16x16 macroblocks in one frame*/
HI_U32 uP16MbNum; /*number of P16x16 macroblocks in one frame*/
HI_U32 uP16x8MbNum; /*number of P16x8 macroblocks in one frame*/
HI_U32 uP8x16MbNum; /*number of P8x16 macroblocks in one frame*/
HI_U32 uP8MbNum; /*number of P8x8 macroblocks in one frame*/
HI_U32 uPskipMbNum; /*number of PSkip macroblocks in one frame*/
HI_U32 uIpcmMbNum; /*number of IPCM macroblocks in one frame*/
} H264_OUTPUT_INFO_S;
[Note]
None
3.2.5 H264_DEC_FRAME_S
[Description]
The decoder output picture information.
[Definition]
/*Data structure of the decoder output picture information*/
typedef struct hiH264_DEC_FRAME_S
{
HI_U8 *pY; /*Address of the Y component*/
HI_U8 *pU; /*Address of the U component*/
HI_U8 *pV; /*Address of the V component*/
HI_U32 uWidth; /*The maximum picture width (in the unit of pixel)*/
HI_U32 uHeight; /*The maximum picture height (in the unit of pixel)*/
HI_U32 uYStride; /*Stride of the output Y component, (in the unit of pixel)*/
HI_U32 uUVStride; /*Stride of the output U/V component, (in the unit of
pixel)*/
[Note]
None
Start
Creat the
decoder
Read stream
No End of the
stream?
Yes
Decoding Decoding
No No
Output pictures? Remaining
Output pictures?
data
Yes Yes
End
/*Open the H.264 stream file and the file keeping the YUV picture*/
h264 = fopen(argv[1], "rb");
yuv = fopen(argv[2], "wb");
if(NULL == h264 || NULL == yuv)
{
goto exit;
}
HI_S32 result = 0;
Exit:
if(NULL != h264)
fclose(h264);
if(NULL != yuv)
fclose(yuv);