1/*
2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef  __HI_COMM_ADEC_H__
17#define  __HI_COMM_ADEC_H__
18
19
20#include "hi_type.h"
21#include "hi_common.h"
22#include "hi_comm_aio.h"
23
24#ifdef __cplusplus
25#if __cplusplus
26extern "C" {
27#endif
28#endif /* End of #ifdef __cplusplus */
29
30typedef struct hiADEC_ATTR_G711_S {
31    HI_U32 resv;
32} ADEC_ATTR_G711_S;
33
34typedef struct hiADEC_ATTR_G726_S {
35    G726_BPS_E enG726bps;
36} ADEC_ATTR_G726_S;
37
38typedef struct hiADEC_ATTR_ADPCM_S {
39    ADPCM_TYPE_E enADPCMType;
40} ADEC_ATTR_ADPCM_S;
41
42typedef struct hiADEC_ATTR_LPCM_S {
43    HI_U32 resv;
44} ADEC_ATTR_LPCM_S;
45
46typedef enum hiADEC_MODE_E {
47    ADEC_MODE_PACK = 0, /* require input is valid dec pack(a
48                           complete frame encode result),
49                           e.g.the stream get from AENC is a
50                           valid dec pack, the stream know actually
51                           pack len from file is also a dec pack.
52                           this mode is high-performative */
53    ADEC_MODE_STREAM,   /* input is stream, low-performative,
54                           if you couldn't find out whether a stream is
55                           vaild dec pack,you could use
56                           this mode */
57    ADEC_MODE_BUTT
58} ADEC_MODE_E;
59
60typedef struct hiADEC_CH_ATTR_S {
61    PAYLOAD_TYPE_E enType;
62    HI_U32         u32BufSize;  /* buf size[2~MAX_AUDIO_FRAME_NUM] */
63    ADEC_MODE_E    enMode;      /* decode mode */
64    HI_VOID ATTRIBUTE      *pValue;
65} ADEC_CHN_ATTR_S;
66
67typedef struct hiADEC_CHN_STATE_S {
68    HI_BOOL bEndOfStream;             /* EOS flag */
69    HI_U32 u32BufferFrmNum;           /* total number of channel buffer */
70    HI_U32 u32BufferFreeNum;          /* free number of channel buffer */
71    HI_U32 u32BufferBusyNum;          /* busy number of channel buffer */
72} ADEC_CHN_STATE_S;
73
74typedef struct hiADEC_DECODER_S {
75    PAYLOAD_TYPE_E  enType;
76    HI_CHAR         aszName[17]; /* 17: name length */
77    /* struct ppDecoder is packed by user, user malloc and free memory for this struct */
78    HI_S32          (*pfnOpenDecoder)(HI_VOID *pDecoderAttr, HI_VOID **ppDecoder);
79    HI_S32          (*pfnDecodeFrm)(HI_VOID *pDecoder, HI_U8 **pu8Inbuf, HI_S32 *ps32LeftByte,
80                        HI_U16 *pu16Outbuf, HI_U32 *pu32OutLen, HI_U32 *pu32Chns);
81    HI_S32          (*pfnGetFrmInfo)(HI_VOID *pDecoder, HI_VOID *pInfo);
82    HI_S32          (*pfnCloseDecoder)(HI_VOID *pDecoder);
83    HI_S32          (*pfnResetDecoder)(HI_VOID *pDecoder);
84} ADEC_DECODER_S;
85
86typedef enum hiEN_ADEC_ERR_CODE_E {
87    ADEC_ERR_DECODER_ERR     = 64,
88    ADEC_ERR_BUF_LACK,
89} EN_ADEC_ERR_CODE_E;
90
91
92/* invalid device ID */
93#define HI_ERR_ADEC_INVALID_DEVID     HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_INVALID_DEVID)
94/* invalid channel ID */
95#define HI_ERR_ADEC_INVALID_CHNID     HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_INVALID_CHNID)
96/* at lease one parameter is illagal ,eg, an illegal enumeration value  */
97#define HI_ERR_ADEC_ILLEGAL_PARAM     HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_ILLEGAL_PARAM)
98/* channel exists */
99#define HI_ERR_ADEC_EXIST             HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_EXIST)
100/* channel unexists */
101#define HI_ERR_ADEC_UNEXIST           HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_UNEXIST)
102/* using a NULL point */
103#define HI_ERR_ADEC_NULL_PTR          HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_NULL_PTR)
104/* try to enable or initialize system,device or channel, before configing attribute */
105#define HI_ERR_ADEC_NOT_CONFIG        HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_CONFIG)
106/* operation is not supported by NOW */
107#define HI_ERR_ADEC_NOT_SUPPORT       HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_SUPPORT)
108/* operation is not permitted ,eg, try to change static attribute */
109#define HI_ERR_ADEC_NOT_PERM          HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_PERM)
110/* failure caused by malloc memory */
111#define HI_ERR_ADEC_NOMEM             HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOMEM)
112/* failure caused by malloc buffer */
113#define HI_ERR_ADEC_NOBUF             HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOBUF)
114/* no data in buffer */
115#define HI_ERR_ADEC_BUF_EMPTY         HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_EMPTY)
116/* no buffer for new data */
117#define HI_ERR_ADEC_BUF_FULL          HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_FULL)
118/* system is not ready,had not initialed or loaded */
119#define HI_ERR_ADEC_SYS_NOTREADY      HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, EN_ERR_SYS_NOTREADY)
120/* decoder internal err */
121#define HI_ERR_ADEC_DECODER_ERR       HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, ADEC_ERR_DECODER_ERR)
122/* input buffer not enough to decode one frame */
123#define HI_ERR_ADEC_BUF_LACK          HI_DEF_ERR(HI_ID_ADEC, EN_ERR_LEVEL_ERROR, ADEC_ERR_BUF_LACK)
124
125#ifdef __cplusplus
126#if __cplusplus
127}
128#endif
129#endif /* End of #ifdef __cplusplus */
130
131#endif /* End of #ifndef __HI_COMM_ADEC_H__ */
132
133