• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _MP3DEC_H
17 #define _MP3DEC_H
18 
19 #ifdef __cplusplus
20 #if __cplusplus
21 extern "C" {
22 #endif  /* __cpluscplus */
23 #endif  /* __cpluscplus */
24 
25 #include "hi_type.h"
26 
27 /********************************Macro Definition********************************/
28 /** \addtogroup      MP3DEC */
29 /** @{ */  /** <!-- [MP3DEC] */
30 
31 #define MP3_MAX_NCHANS      2         /**<mp3 max number of channels*/
32 
33 #define MP3_MAX_OUT_NSAMPS  1152     /**<mp3 max output samples per-frame, per-channel*/
34 #define MP3_MAINBUF_SIZE    4096     /**<mp3 minium size of input buffer. UNIT:bytes*/
35 
36 /** @} */  /** <!-- ==== Macro Definition end ==== */
37 
38 /*************************** Structure Definition ****************************/
39 /** \addtogroup      MP3DEC */
40 /** @{ */  /** <!-- [MP3DEC] */
41 
42 /**Defines MP3DEC Version*/
43 typedef enum {
44     MPEG1 =  0,
45     MPEG2 =  1,
46     MPEG25 = 2
47 } MPEGVersion;
48 
49 typedef void *HMP3Decoder;
50 
51 /**Defines MP3DEC error*/
52 enum {
53     ERR_MP3_NONE =                 0,   /**<no decode error*/
54     ERR_MP3_INDATA_UNDERFLOW =    -1,   /**<not enough input data*/
55     ERR_MP3_MAINDATA_UNDERFLOW =  -2,   /**<not enough input main data*/
56     ERR_MP3_FREE_BITRATE_SYNC =   -3,   /**<free mode bitrate error*/
57     ERR_MP3_OUT_OF_MEMORY =       -4,   /**<decoder not enough memory*/
58     ERR_MP3_NULL_POINTER =        -5,   /**<input null pointer*/
59     ERR_MP3_INVALID_FRAMEHEADER = -6,   /**<invalid frame header*/
60     ERR_MP3_INVALID_SIDEINFO =    -7,   /**<invalid side information*/
61     ERR_MP3_INVALID_SCALEFACT =   -8,   /**<invalid scale factors*/
62     ERR_MP3_INVALID_HUFFCODES =   -9,   /**<Huffman decoder error*/
63     ERR_MP3_FAIL_SYNC =           -10,  /**<find sync word error*/
64 
65     ERR_MP3_UNKNOWN =             -9999 /**<reserved*/
66 };
67 
68 /**Defines MP3DEC frame infomation*/
69 typedef struct _MP3FrameInfo {
70     int bitrate;              /**<output bitrate*/
71     int nChans;               /**<output channels,range:1,2*/
72     int samprate;             /**<output samplerate*/
73     int bitsPerSample;        /**<output bitwidth*/
74     int outputSamps;          /**<output samples,range:nChans*SamplePerFrame*/
75     int layer;                /**<output layer*/
76     int version;              /**<output version*/
77 } MP3FrameInfo;
78 
79 /** @} */  /** <!-- ==== Structure Definition End ==== */
80 
81 /******************************* API declaration *****************************/
82 /** \addtogroup      MP3DEC */
83 /** @{ */  /** <!--  [MP3DEC] */
84 
85 /**
86 \brief create and initial decoder device.
87 \attention \n
88 Before before deocede,you must call this application programming interface (API) first.
89 \param N/A
90 \retval ::HMP3Decoder   : Success
91 \retval ::NULL          : FAILURE.
92 \see \n
93 N/A
94 */
95 HMP3Decoder MP3InitDecoder(HI_VOID);
96 
97 /**
98 \brief Free MP3 decoder.
99 \attention \n
100 \param[in] hMP3Decoder MP3decode handle
101 \retval \n
102 \see \n
103 N/A
104 */
105 HI_VOID MP3FreeDecoder(HMP3Decoder hMP3Decoder);
106 
107 /**
108 \brief Find Sync word before decode.
109 \attention \n
110 \param[in] hMP3Decoder    MP3-Decoder handle
111 \param[in] ppInbufPtr     address of the pointer of start-point of the bitstream(little endian format)
112 \param[in] pBytesLeft     pointer to BytesLeft that indicates bitstream numbers at input buffer,indicates the left bytes
113 \retval :: other : Success, return number bytes  of current frame
114 \retval ::<0 ERR_MP3_INDATA_UNDERFLOW
115 \see \n
116 N/A
117 */
118 HI_S32 MP3DecodeFindSyncHeader(HMP3Decoder hMP3Decoder, HI_U8 **ppInbufPtr, HI_S32 *pBytesLeft);
119 
120 /**
121 \brief decoding MPEG frame and output 1152(L2/L3) OR 384(L1) 16bit PCM samples per channel.
122 \attention \n
123 \param[in] hMP3Decoder    MP3-Decoder handle
124 \param[in] ppInbufPtr     address of the pointer of start-point of the bitstream
125 \param[in] pBytesLeft     pointer to BytesLeft that indicates bitstream numbers at input buffer,indicates the left bytes
126 \param[in] pOutPcm        the address of the out pcm buffer,pcm data in noninterlaced fotmat: L/L/L/... R/R/R/...
127 \param[in] nReserved      reserved
128 \retval :: ERR_MP3_NONE : Success
129 \retval :: ERROR_CODE :FAILURE
130 \see \n
131 N/A
132 */
133 HI_S32  MP3Decode(HMP3Decoder hMP3Decoder, HI_U8 **ppInbufPtr, HI_S32 *pBytesLeft, HI_S16 *pOutPcm, HI_S32 nReserved);
134 
135 /**
136 \brief get the frame information.
137 \attention \n
138 \param[in] hMP3Decoder    MP3-Decoder handle
139 \param[out] mp3FrameInfo  frame information
140 \retval \n
141 \see \n
142 N/A
143 */
144 HI_VOID MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo);
145 
146 /** @} */  /** <!-- ==== API declaration end ==== */
147 
148 #ifdef __cplusplus
149 #if __cplusplus
150 }
151 #endif  /* __cpluscplus */
152 #endif  /* __cpluscplus */
153 
154 #endif  /* _MP3DEC_H */