11bd4fe43Sopenharmony_ci/*
21bd4fe43Sopenharmony_ci * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
31bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
41bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License.
51bd4fe43Sopenharmony_ci * You may obtain a copy of the License at
61bd4fe43Sopenharmony_ci *
71bd4fe43Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
81bd4fe43Sopenharmony_ci *
91bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
101bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
111bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and
131bd4fe43Sopenharmony_ci * limitations under the License.
141bd4fe43Sopenharmony_ci */
151bd4fe43Sopenharmony_ci
161bd4fe43Sopenharmony_ci#ifndef __AACENC_H__
171bd4fe43Sopenharmony_ci#define __AACENC_H__
181bd4fe43Sopenharmony_ci
191bd4fe43Sopenharmony_ci#include "hi_type.h"
201bd4fe43Sopenharmony_ci
211bd4fe43Sopenharmony_ci#ifdef __cplusplus
221bd4fe43Sopenharmony_ci#if __cplusplus
231bd4fe43Sopenharmony_ciextern "C" {
241bd4fe43Sopenharmony_ci#endif /* __cpluscplus */
251bd4fe43Sopenharmony_ci#endif /* __cpluscplus */
261bd4fe43Sopenharmony_ci
271bd4fe43Sopenharmony_ci/********************************Macro Definition********************************/
281bd4fe43Sopenharmony_ci/** \addtogroup      AACENC */
291bd4fe43Sopenharmony_ci/** @{ */ /** <!-- [AACENC] */
301bd4fe43Sopenharmony_ci
311bd4fe43Sopenharmony_ci#ifdef MONO_ONLY
321bd4fe43Sopenharmony_ci#define MAX_CHANNELS 1 /* aacenc encoder channels */
331bd4fe43Sopenharmony_ci#else
341bd4fe43Sopenharmony_ci#define MAX_CHANNELS 2
351bd4fe43Sopenharmony_ci#endif
361bd4fe43Sopenharmony_ci
371bd4fe43Sopenharmony_ci#define AACENC_BLOCKSIZE 1024 /* aacenc blocksize */
381bd4fe43Sopenharmony_ci
391bd4fe43Sopenharmony_ci#define AACENC_VERSION_MAX_BYTE 64 /* version max byte size */
401bd4fe43Sopenharmony_ci
411bd4fe43Sopenharmony_ci/** @} */                     /** <!-- ==== Macro Definition end ==== */
421bd4fe43Sopenharmony_ci
431bd4fe43Sopenharmony_ci/*************************** Structure Definition ****************************/
441bd4fe43Sopenharmony_ci/** \addtogroup      AACENC */
451bd4fe43Sopenharmony_ci/** @{ */ /** <!-- [AACENC] */
461bd4fe43Sopenharmony_ci
471bd4fe43Sopenharmony_citypedef enum {
481bd4fe43Sopenharmony_ci    HI_AACENC_OK                     = 0x0000,  /* No error happened. All fine. */
491bd4fe43Sopenharmony_ci
501bd4fe43Sopenharmony_ci    HI_AACENC_INVALID_HANDLE         = 0x0020,  /* Handle passed to function call was invalid. */
511bd4fe43Sopenharmony_ci    HI_AACENC_MEMORY_ERROR           = 0x0021,  /* Memory allocation failed. */
521bd4fe43Sopenharmony_ci    HI_AACENC_UNSUPPORTED_PARAMETER  = 0x0022,  /* Parameter not available. */
531bd4fe43Sopenharmony_ci    HI_AACENC_INVALID_CONFIG         = 0x0023,  /* Configuration not provided. */
541bd4fe43Sopenharmony_ci
551bd4fe43Sopenharmony_ci    HI_AACENC_INIT_ERROR             = 0x0040,  /* General initialization error. */
561bd4fe43Sopenharmony_ci    HI_AACENC_INIT_AAC_ERROR         = 0x0041,  /* AAC library initialization error. */
571bd4fe43Sopenharmony_ci    HI_AACENC_INIT_SBR_ERROR         = 0x0042,  /* SBR library initialization error. */
581bd4fe43Sopenharmony_ci    HI_AACENC_INIT_TP_ERROR          = 0x0043,  /* Transport library initialization error. */
591bd4fe43Sopenharmony_ci    HI_AACENC_INIT_META_ERROR        = 0x0044,  /* Meta data library initialization error. */
601bd4fe43Sopenharmony_ci
611bd4fe43Sopenharmony_ci    HI_AACENC_ENCODE_ERROR           = 0x0060,  /* The encoding process was interrupted by an unexpected error. */
621bd4fe43Sopenharmony_ci
631bd4fe43Sopenharmony_ci    HI_AACENC_ENCODE_EOF             = 0x0080   /* End of file reached. */
641bd4fe43Sopenharmony_ci} HI_AACENC_ERROR_E;
651bd4fe43Sopenharmony_ci
661bd4fe43Sopenharmony_ci/** Defines AACENC quality */
671bd4fe43Sopenharmony_citypedef enum {
681bd4fe43Sopenharmony_ci    AU_QualityExcellent = 0,
691bd4fe43Sopenharmony_ci    AU_QualityHigh = 1,
701bd4fe43Sopenharmony_ci    AU_QualityMedium = 2,
711bd4fe43Sopenharmony_ci    AU_QualityLow = 3,
721bd4fe43Sopenharmony_ci} AuQuality;
731bd4fe43Sopenharmony_ci
741bd4fe43Sopenharmony_ci/** Defines AACENC format */
751bd4fe43Sopenharmony_citypedef enum {
761bd4fe43Sopenharmony_ci    AACLC = 0,    /* AAC-LC format */
771bd4fe43Sopenharmony_ci    EAAC = 1,     /* HEAAC or AAC+  or aacPlusV1 */
781bd4fe43Sopenharmony_ci    EAACPLUS = 2, /* AAC++ or aacPlusV2 */
791bd4fe43Sopenharmony_ci    AACLD = 3,    /* AAC LD(Low Delay) */
801bd4fe43Sopenharmony_ci    AACELD = 4,   /* AAC ELD(Low Delay) */
811bd4fe43Sopenharmony_ci} AuEncoderFormat;
821bd4fe43Sopenharmony_ci
831bd4fe43Sopenharmony_ci/** Defines AACENC container */
841bd4fe43Sopenharmony_citypedef enum {
851bd4fe43Sopenharmony_ci    AACENC_ADTS = 0,
861bd4fe43Sopenharmony_ci    AACENC_LOAS = 1,
871bd4fe43Sopenharmony_ci    AACENC_LATM_MCP1 = 2,
881bd4fe43Sopenharmony_ci} AACENCTransportType;
891bd4fe43Sopenharmony_ci
901bd4fe43Sopenharmony_ci/** Defines AACENC configuration */
911bd4fe43Sopenharmony_citypedef struct {
921bd4fe43Sopenharmony_ci    AuQuality quality;
931bd4fe43Sopenharmony_ci    AuEncoderFormat coderFormat;
941bd4fe43Sopenharmony_ci    HI_S16 bitsPerSample;
951bd4fe43Sopenharmony_ci    HI_S32 sampleRate;   /* audio file sample rate */
961bd4fe43Sopenharmony_ci    HI_S32 bitRate;      /* encoder bit rate in bits/sec */
971bd4fe43Sopenharmony_ci    HI_S16 nChannelsIn;  /* number of channels on input (1,2) */
981bd4fe43Sopenharmony_ci    HI_S16 nChannelsOut; /* number of channels on output (1,2) */
991bd4fe43Sopenharmony_ci    HI_S16 bandWidth;    /* targeted audio bandwidth in Hz */
1001bd4fe43Sopenharmony_ci    AACENCTransportType transtype;
1011bd4fe43Sopenharmony_ci} AACENC_CONFIG;
1021bd4fe43Sopenharmony_ci
1031bd4fe43Sopenharmony_ci/* Defines AACENC version */
1041bd4fe43Sopenharmony_citypedef struct hiAACENC_VERSION_S {
1051bd4fe43Sopenharmony_ci    HI_U8 aVersion[AACENC_VERSION_MAX_BYTE];
1061bd4fe43Sopenharmony_ci} AACENC_VERSION_S;
1071bd4fe43Sopenharmony_ci
1081bd4fe43Sopenharmony_citypedef HI_U32 AAC_ENCODER_S;
1091bd4fe43Sopenharmony_ci
1101bd4fe43Sopenharmony_ci/** @} */ /** <!-- ==== Structure Definition End ==== */
1111bd4fe43Sopenharmony_ci
1121bd4fe43Sopenharmony_ci/******************************* API declaration *****************************/
1131bd4fe43Sopenharmony_ci/** \addtogroup      AACENC */
1141bd4fe43Sopenharmony_ci/** @{ */ /** <!--  [AACENC] */
1151bd4fe43Sopenharmony_ci
1161bd4fe43Sopenharmony_ci/**
1171bd4fe43Sopenharmony_ci\brief Get version information.
1181bd4fe43Sopenharmony_ci\attention \n
1191bd4fe43Sopenharmony_ciN/A
1201bd4fe43Sopenharmony_ci\param[in] pVersion       version describe struct
1211bd4fe43Sopenharmony_ci\retval ::HI_SUCCESS   : Success
1221bd4fe43Sopenharmony_ci\retval ::HI_FAILURE          : FAILURE
1231bd4fe43Sopenharmony_ci\see \n
1241bd4fe43Sopenharmony_ciN/A
1251bd4fe43Sopenharmony_ci*/
1261bd4fe43Sopenharmony_ciHI_S32 HI_AACENC_GetVersion(AACENC_VERSION_S *pVersion);
1271bd4fe43Sopenharmony_ci
1281bd4fe43Sopenharmony_ci/**
1291bd4fe43Sopenharmony_ci\brief get reasonable default configuration.
1301bd4fe43Sopenharmony_ci\attention \n
1311bd4fe43Sopenharmony_ciN/A
1321bd4fe43Sopenharmony_ci\param[in] pstConfig    pointer to an configuration information structure
1331bd4fe43Sopenharmony_ci\retval ::HI_SUCCESS   : Success
1341bd4fe43Sopenharmony_ci\retval ::HI_FAILURE          : FAILURE
1351bd4fe43Sopenharmony_ci\see \n
1361bd4fe43Sopenharmony_ciN/A
1371bd4fe43Sopenharmony_ci*/
1381bd4fe43Sopenharmony_ciHI_S32 AACInitDefaultConfig(AACENC_CONFIG *pstConfig);
1391bd4fe43Sopenharmony_ci
1401bd4fe43Sopenharmony_ci/**
1411bd4fe43Sopenharmony_ci\brief allocate and initialize a new encoder instance.
1421bd4fe43Sopenharmony_ci\attention \n
1431bd4fe43Sopenharmony_ciN/A
1441bd4fe43Sopenharmony_ci\param[in] phAacPlusEnc    pointer to an configuration information structure
1451bd4fe43Sopenharmony_ci\param[in] pstConfig    pointer to an configuration information structure
1461bd4fe43Sopenharmony_ci\retval ::HI_SUCCESS   : Success
1471bd4fe43Sopenharmony_ci\retval ::HI_FAILURE   : FAILURE
1481bd4fe43Sopenharmony_ci\see \n
1491bd4fe43Sopenharmony_ciN/A
1501bd4fe43Sopenharmony_ci*/
1511bd4fe43Sopenharmony_ciHI_S32 AACEncoderOpen(AAC_ENCODER_S **phAacPlusEnc, const AACENC_CONFIG *pstConfig);
1521bd4fe43Sopenharmony_ci
1531bd4fe43Sopenharmony_ci/**
1541bd4fe43Sopenharmony_ci\brief allocate and initialize a new encoder instance
1551bd4fe43Sopenharmony_ci\attention \n
1561bd4fe43Sopenharmony_ciN/A
1571bd4fe43Sopenharmony_ci\param[in] hAacPlusEnc    pointer to an configuration information structure
1581bd4fe43Sopenharmony_ci\param[in] ps16PcmBuf    BLOCKSIZE*nChannels audio samples,interleaved
1591bd4fe43Sopenharmony_ci\param[in] pu8Outbuf    pointer to output buffer,(must be 6144/8*MAX_CHANNELS bytes large)
1601bd4fe43Sopenharmony_ci\param[in] ps32NumOutBytes    number of bytes in output buffer after processing
1611bd4fe43Sopenharmony_ci\retval ::HI_SUCCESS   : Success
1621bd4fe43Sopenharmony_ci\retval ::HI_FAILURE   : FAILURE
1631bd4fe43Sopenharmony_ci\see \n
1641bd4fe43Sopenharmony_ciN/A
1651bd4fe43Sopenharmony_ci*/
1661bd4fe43Sopenharmony_ciHI_S32 AACEncoderFrame(AAC_ENCODER_S *hAacPlusEnc, HI_S16 *ps16PcmBuf,
1671bd4fe43Sopenharmony_ci                       HI_U8 *pu8Outbuf, HI_S32 *ps32NumOutBytes);
1681bd4fe43Sopenharmony_ci
1691bd4fe43Sopenharmony_ci/**
1701bd4fe43Sopenharmony_ci\brief close encoder device.
1711bd4fe43Sopenharmony_ci\attention \n
1721bd4fe43Sopenharmony_ciN/A
1731bd4fe43Sopenharmony_ci\param[in] hAacPlusEnc    pointer to an configuration information structure
1741bd4fe43Sopenharmony_ci\retval N/A
1751bd4fe43Sopenharmony_ci\see \n
1761bd4fe43Sopenharmony_ciN/A
1771bd4fe43Sopenharmony_ci*/
1781bd4fe43Sopenharmony_ciHI_VOID AACEncoderClose(AAC_ENCODER_S *hAacPlusEnc);
1791bd4fe43Sopenharmony_ci
1801bd4fe43Sopenharmony_ci/**
1811bd4fe43Sopenharmony_ci\brief register sbrenc module.
1821bd4fe43Sopenharmony_ci\attention \n
1831bd4fe43Sopenharmony_ciN/A
1841bd4fe43Sopenharmony_ci\param[in] pModuleHandle  pointer to WorkHandle of sbrenc module
1851bd4fe43Sopenharmony_ci\retval ::HI_SUCCESS   : Success
1861bd4fe43Sopenharmony_ci\retval ::HI_FAILURE   : FAILURE
1871bd4fe43Sopenharmony_ci\see \n
1881bd4fe43Sopenharmony_ciN/A
1891bd4fe43Sopenharmony_ci*/
1901bd4fe43Sopenharmony_ciHI_S32 AACEncoderRegisterModule(HI_VOID *pModuleHandle);
1911bd4fe43Sopenharmony_ci
1921bd4fe43Sopenharmony_ci/**
1931bd4fe43Sopenharmony_ci\brief Get WorkHandle of sbrenc module.
1941bd4fe43Sopenharmony_ci\attention \n
1951bd4fe43Sopenharmony_ciN/A
1961bd4fe43Sopenharmony_ci\retval ::HI_VOID *    : pointer to WorkHandle of sbrenc module
1971bd4fe43Sopenharmony_ci\see \n
1981bd4fe43Sopenharmony_ciN/A
1991bd4fe43Sopenharmony_ci*/
2001bd4fe43Sopenharmony_ciHI_VOID *HI_AAC_SBRENC_GetHandle(HI_VOID);
2011bd4fe43Sopenharmony_ci
2021bd4fe43Sopenharmony_ci/** @} */ /** <!-- ==== API declaration end ==== */
2031bd4fe43Sopenharmony_ci
2041bd4fe43Sopenharmony_ci#ifdef __cplusplus
2051bd4fe43Sopenharmony_ci#if __cplusplus
2061bd4fe43Sopenharmony_ci}
2071bd4fe43Sopenharmony_ci#endif /* __cpluscplus */
2081bd4fe43Sopenharmony_ci#endif /* __cpluscplus */
2091bd4fe43Sopenharmony_ci
2101bd4fe43Sopenharmony_ci#endif /* __AACENC_H__ */
211