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 _MP3DEC_H 171bd4fe43Sopenharmony_ci#define _MP3DEC_H 181bd4fe43Sopenharmony_ci 191bd4fe43Sopenharmony_ci#ifdef __cplusplus 201bd4fe43Sopenharmony_ci#if __cplusplus 211bd4fe43Sopenharmony_ciextern "C" { 221bd4fe43Sopenharmony_ci#endif /* __cpluscplus */ 231bd4fe43Sopenharmony_ci#endif /* __cpluscplus */ 241bd4fe43Sopenharmony_ci 251bd4fe43Sopenharmony_ci#include "hi_type.h" 261bd4fe43Sopenharmony_ci 271bd4fe43Sopenharmony_ci/********************************Macro Definition********************************/ 281bd4fe43Sopenharmony_ci/** \addtogroup MP3DEC */ 291bd4fe43Sopenharmony_ci/** @{ */ /** <!-- [MP3DEC] */ 301bd4fe43Sopenharmony_ci 311bd4fe43Sopenharmony_ci#define MP3_MAX_NCHANS 2 /**<mp3 max number of channels*/ 321bd4fe43Sopenharmony_ci 331bd4fe43Sopenharmony_ci#define MP3_MAX_OUT_NSAMPS 1152 /**<mp3 max output samples per-frame, per-channel*/ 341bd4fe43Sopenharmony_ci#define MP3_MAINBUF_SIZE 4096 /**<mp3 minium size of input buffer. UNIT:bytes*/ 351bd4fe43Sopenharmony_ci 361bd4fe43Sopenharmony_ci/** @} */ /** <!-- ==== Macro Definition end ==== */ 371bd4fe43Sopenharmony_ci 381bd4fe43Sopenharmony_ci/*************************** Structure Definition ****************************/ 391bd4fe43Sopenharmony_ci/** \addtogroup MP3DEC */ 401bd4fe43Sopenharmony_ci/** @{ */ /** <!-- [MP3DEC] */ 411bd4fe43Sopenharmony_ci 421bd4fe43Sopenharmony_ci/**Defines MP3DEC Version*/ 431bd4fe43Sopenharmony_citypedef enum { 441bd4fe43Sopenharmony_ci MPEG1 = 0, 451bd4fe43Sopenharmony_ci MPEG2 = 1, 461bd4fe43Sopenharmony_ci MPEG25 = 2 471bd4fe43Sopenharmony_ci} MPEGVersion; 481bd4fe43Sopenharmony_ci 491bd4fe43Sopenharmony_citypedef void *HMP3Decoder; 501bd4fe43Sopenharmony_ci 511bd4fe43Sopenharmony_ci/**Defines MP3DEC error*/ 521bd4fe43Sopenharmony_cienum { 531bd4fe43Sopenharmony_ci ERR_MP3_NONE = 0, /**<no decode error*/ 541bd4fe43Sopenharmony_ci ERR_MP3_INDATA_UNDERFLOW = -1, /**<not enough input data*/ 551bd4fe43Sopenharmony_ci ERR_MP3_MAINDATA_UNDERFLOW = -2, /**<not enough input main data*/ 561bd4fe43Sopenharmony_ci ERR_MP3_FREE_BITRATE_SYNC = -3, /**<free mode bitrate error*/ 571bd4fe43Sopenharmony_ci ERR_MP3_OUT_OF_MEMORY = -4, /**<decoder not enough memory*/ 581bd4fe43Sopenharmony_ci ERR_MP3_NULL_POINTER = -5, /**<input null pointer*/ 591bd4fe43Sopenharmony_ci ERR_MP3_INVALID_FRAMEHEADER = -6, /**<invalid frame header*/ 601bd4fe43Sopenharmony_ci ERR_MP3_INVALID_SIDEINFO = -7, /**<invalid side information*/ 611bd4fe43Sopenharmony_ci ERR_MP3_INVALID_SCALEFACT = -8, /**<invalid scale factors*/ 621bd4fe43Sopenharmony_ci ERR_MP3_INVALID_HUFFCODES = -9, /**<Huffman decoder error*/ 631bd4fe43Sopenharmony_ci ERR_MP3_FAIL_SYNC = -10, /**<find sync word error*/ 641bd4fe43Sopenharmony_ci 651bd4fe43Sopenharmony_ci ERR_MP3_UNKNOWN = -9999 /**<reserved*/ 661bd4fe43Sopenharmony_ci}; 671bd4fe43Sopenharmony_ci 681bd4fe43Sopenharmony_ci/**Defines MP3DEC frame infomation*/ 691bd4fe43Sopenharmony_citypedef struct _MP3FrameInfo { 701bd4fe43Sopenharmony_ci int bitrate; /**<output bitrate*/ 711bd4fe43Sopenharmony_ci int nChans; /**<output channels,range:1,2*/ 721bd4fe43Sopenharmony_ci int samprate; /**<output samplerate*/ 731bd4fe43Sopenharmony_ci int bitsPerSample; /**<output bitwidth*/ 741bd4fe43Sopenharmony_ci int outputSamps; /**<output samples,range:nChans*SamplePerFrame*/ 751bd4fe43Sopenharmony_ci int layer; /**<output layer*/ 761bd4fe43Sopenharmony_ci int version; /**<output version*/ 771bd4fe43Sopenharmony_ci} MP3FrameInfo; 781bd4fe43Sopenharmony_ci 791bd4fe43Sopenharmony_ci/** @} */ /** <!-- ==== Structure Definition End ==== */ 801bd4fe43Sopenharmony_ci 811bd4fe43Sopenharmony_ci/******************************* API declaration *****************************/ 821bd4fe43Sopenharmony_ci/** \addtogroup MP3DEC */ 831bd4fe43Sopenharmony_ci/** @{ */ /** <!-- [MP3DEC] */ 841bd4fe43Sopenharmony_ci 851bd4fe43Sopenharmony_ci/** 861bd4fe43Sopenharmony_ci\brief create and initial decoder device. 871bd4fe43Sopenharmony_ci\attention \n 881bd4fe43Sopenharmony_ciBefore before deocede,you must call this application programming interface (API) first. 891bd4fe43Sopenharmony_ci\param N/A 901bd4fe43Sopenharmony_ci\retval ::HMP3Decoder : Success 911bd4fe43Sopenharmony_ci\retval ::NULL : FAILURE. 921bd4fe43Sopenharmony_ci\see \n 931bd4fe43Sopenharmony_ciN/A 941bd4fe43Sopenharmony_ci*/ 951bd4fe43Sopenharmony_ciHMP3Decoder MP3InitDecoder(HI_VOID); 961bd4fe43Sopenharmony_ci 971bd4fe43Sopenharmony_ci/** 981bd4fe43Sopenharmony_ci\brief Free MP3 decoder. 991bd4fe43Sopenharmony_ci\attention \n 1001bd4fe43Sopenharmony_ci\param[in] hMP3Decoder MP3decode handle 1011bd4fe43Sopenharmony_ci\retval \n 1021bd4fe43Sopenharmony_ci\see \n 1031bd4fe43Sopenharmony_ciN/A 1041bd4fe43Sopenharmony_ci*/ 1051bd4fe43Sopenharmony_ciHI_VOID MP3FreeDecoder(HMP3Decoder hMP3Decoder); 1061bd4fe43Sopenharmony_ci 1071bd4fe43Sopenharmony_ci/** 1081bd4fe43Sopenharmony_ci\brief Find Sync word before decode. 1091bd4fe43Sopenharmony_ci\attention \n 1101bd4fe43Sopenharmony_ci\param[in] hMP3Decoder MP3-Decoder handle 1111bd4fe43Sopenharmony_ci\param[in] ppInbufPtr address of the pointer of start-point of the bitstream(little endian format) 1121bd4fe43Sopenharmony_ci\param[in] pBytesLeft pointer to BytesLeft that indicates bitstream numbers at input buffer,indicates the left bytes 1131bd4fe43Sopenharmony_ci\retval :: other : Success, return number bytes of current frame 1141bd4fe43Sopenharmony_ci\retval ::<0 ERR_MP3_INDATA_UNDERFLOW 1151bd4fe43Sopenharmony_ci\see \n 1161bd4fe43Sopenharmony_ciN/A 1171bd4fe43Sopenharmony_ci*/ 1181bd4fe43Sopenharmony_ciHI_S32 MP3DecodeFindSyncHeader(HMP3Decoder hMP3Decoder, HI_U8 **ppInbufPtr, HI_S32 *pBytesLeft); 1191bd4fe43Sopenharmony_ci 1201bd4fe43Sopenharmony_ci/** 1211bd4fe43Sopenharmony_ci\brief decoding MPEG frame and output 1152(L2/L3) OR 384(L1) 16bit PCM samples per channel. 1221bd4fe43Sopenharmony_ci\attention \n 1231bd4fe43Sopenharmony_ci\param[in] hMP3Decoder MP3-Decoder handle 1241bd4fe43Sopenharmony_ci\param[in] ppInbufPtr address of the pointer of start-point of the bitstream 1251bd4fe43Sopenharmony_ci\param[in] pBytesLeft pointer to BytesLeft that indicates bitstream numbers at input buffer,indicates the left bytes 1261bd4fe43Sopenharmony_ci\param[in] pOutPcm the address of the out pcm buffer,pcm data in noninterlaced fotmat: L/L/L/... R/R/R/... 1271bd4fe43Sopenharmony_ci\param[in] nReserved reserved 1281bd4fe43Sopenharmony_ci\retval :: ERR_MP3_NONE : Success 1291bd4fe43Sopenharmony_ci\retval :: ERROR_CODE :FAILURE 1301bd4fe43Sopenharmony_ci\see \n 1311bd4fe43Sopenharmony_ciN/A 1321bd4fe43Sopenharmony_ci*/ 1331bd4fe43Sopenharmony_ciHI_S32 MP3Decode(HMP3Decoder hMP3Decoder, HI_U8 **ppInbufPtr, HI_S32 *pBytesLeft, HI_S16 *pOutPcm, HI_S32 nReserved); 1341bd4fe43Sopenharmony_ci 1351bd4fe43Sopenharmony_ci/** 1361bd4fe43Sopenharmony_ci\brief get the frame information. 1371bd4fe43Sopenharmony_ci\attention \n 1381bd4fe43Sopenharmony_ci\param[in] hMP3Decoder MP3-Decoder handle 1391bd4fe43Sopenharmony_ci\param[out] mp3FrameInfo frame information 1401bd4fe43Sopenharmony_ci\retval \n 1411bd4fe43Sopenharmony_ci\see \n 1421bd4fe43Sopenharmony_ciN/A 1431bd4fe43Sopenharmony_ci*/ 1441bd4fe43Sopenharmony_ciHI_VOID MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo); 1451bd4fe43Sopenharmony_ci 1461bd4fe43Sopenharmony_ci/** @} */ /** <!-- ==== API declaration end ==== */ 1471bd4fe43Sopenharmony_ci 1481bd4fe43Sopenharmony_ci#ifdef __cplusplus 1491bd4fe43Sopenharmony_ci#if __cplusplus 1501bd4fe43Sopenharmony_ci} 1511bd4fe43Sopenharmony_ci#endif /* __cpluscplus */ 1521bd4fe43Sopenharmony_ci#endif /* __cpluscplus */ 1531bd4fe43Sopenharmony_ci 1541bd4fe43Sopenharmony_ci#endif /* _MP3DEC_H */