#ifndef __OMX_TYPE1_DECODER_COMPONENT_H__
#define __OMX_TYPE1_DECODER_COMPONENT_H__

#include "OMX_Types.h"
#include "OMX_Component.h"
#include "OMX_Core.h"
#include "string.h"
#include "omx_mtk_base_dec_component.h"
#include "omx_base_audio_port.h"
#include "omx_type1_dec_comp_ext.h"
#include "omx_type1_decoder_com_func.h"

#define AUD_DEC_MCPS_MEASUREMENT 0

#if (AUD_DEC_MCPS_MEASUREMENT)
#include "u_time.h"
#endif

typedef struct
{
    UINT32      u4StartTime;
    UINT32      u4EndTime;
    UINT32      u4DuringTime;
    UINT32      u4CurMIPS;
    UINT32      u4MaxMIPS;
    UINT32      u4MinMIPS;
    UINT32      u4AvgMIPS;
    UINT32      u4FrameCnt;
} AUD_DEC_MIPS;

#define TYPE1_DECODER_COMP_NAME    "OMX.st.audio.decoder.type1.ancestor"
#define TYPE1_DECODER_COMP_ROLE     "audio.decoder.type1.ancestor"
#define MAX_TYPE1_DECODER_COMPONENTS    3

#define TYPE1_MAX_SIDEINFO_NUM    6

#define TYPE1_DECODER_COMP_MAX_PORTS    2    // Maximum number of ports supported by the decoder. 1 input and 1 output

#define TYPE1_DECODER_COMP_OUTPUT_BUF_ALIGNED_SAMPLE_BYTE_SIZE    (4*64*16)
#define TYPE1_DECODER_COMP_OUTPUT_BUF_DATA_BYTE_SIZE    (4*1024)
#define TYPE1_DECODER_COMP_INPUT_BUF_BYTE_SIZE    (2*1024)

#define TYPE1_DECODER_COMP_DEFAULT_NUMBER_BUFFERS_PER_PORT    1
#define TYPE1_DECODER_COMP_DEFAULT_MIN_NUMBER_BUFFERS_PER_PORT    1

#define TYPE1_DECODER_COMP_LIST_DIRECTORY    "/usr/lib/riscdec/"
#define TYPE1_DECODER_COMP_LIST_FILENAME     ".omxtype1decomplist"
#define TYPE1_DECODER_COMP_MAX_NUM           100

#define TYPE1_DECODER_COMP_SUPPORT_MAX_CHANNEL_NUM    12

#define ATMOSDEC_COMP_NAME "omxatmosdec"
#define ATMOSDEC_COMP_ROLE "audio_decoder.atmos"


typedef struct OMX_ADAPTOR_CALLBACK_STRUCT
{
    void *pAdaptComp;
    UINT32 u4AfifoDecReadPtr;
    UINT32 u4QueryPTS;
    AUD_DEC_UPDATE_INFO rDecUpdateInfo;
}OMX_ADAPTOR_CALLBACK_STRUCT;

typedef struct OMX_AUDIO_ATMOS_APP_PARAM {
	OMX_S32 nDirectmode;						/**< ATMOS DIRECT MODE */
	OMX_S32 nDialogcontrol;						/**< ATMOS DIALOG CONTROL*/
	OMX_S32 nDrcpercent;						/**< ATMOS DRC PERCENT */
	OMX_U8  nspkconfig[128];					/**< ATMOS SPEAKER CONFIG */
    OMX_U32 u4Channels;
    OMX_S32 s4MatFlag;
} OMX_AUDIO_ATMOS_APP_PARAM;

typedef struct OMX_AUDIO_ATMOS_APP_PARAM_PROFILE
{
    OMX_U32 u4DecAudioProfile;
} OMX_AUDIO_ATMOS_APP_PARAM_PROFILE_T;

typedef struct OMX_AUDIO_ATMOS_APP_DYNAMIC_PARAM
{
    OMX_U32 u4DecAudioNolm;
    OMX_U32 u4DecAudioDrc;
    double DecAudioDrcCut;
    double DecAudioDrcBoost;
    OMX_U32 u4DecAudioNoupmix;
    OMX_U32 u4LogLevel;
    OMX_U32 u4LatencyLogCmd;
    OMX_U32 u4LatencyLogNum;
    OMX_U32 u4DataDumpCmd;
    OMX_S32 s4UseCase;
} OMX_AUDIO_ATMOS_APP_DYNAMIC_PARAM_T;

/** Audio Decoder port structure.
  */
DERIVEDCLASS(omx_type1_decoder_component_PortType, omx_base_audio_PortType)
#define omx_type1_decoder_component_PortType_FIELDS omx_base_audio_PortType_FIELDS
ENDCLASS(omx_type1_decoder_component_PortType)

DERIVEDCLASS(omx_type1_decoder_component_PrivateType, omx_mtk_base_dec_component_PrivateType)
#define omx_type1_decoder_component_PrivateType_FIELDS omx_mtk_base_dec_component_PrivateType_FIELDS \
    type1_dec_component *ptDecComp; \
    OMX_PTR pvDecSelfData; \
    OMX_BOOL eForceNfyDecInfoChg; \
    OMX_BOOL eNotResendData; \
    OMX_BOOL eIsIgnoreDecCurActionErr; \
    OMX_BUFFERHEADERTYPE tTmpInputBuf; \
    OMX_BUFFERHEADERTYPE tTmpOutputBuf; \
    OMX_U32 u4IsDecDownSampleOpen; \
    OMX_U32 u4IsDecDropSampleOpen; \
    OMX_U32 u4IsDecUpSampleOpen; \
    OMX_U32 u4CompSideinfoCfg; \
    OMX_U32 u4CompSideinfoRemainSize; \
    OMX_U32 u4CompSideinfoPreQueryPTS; \
    OMX_BOOL eIsCompFirstSideinfoUpdate; \
    OMX_U32 u4CompSideinfoFirstQueryPTS; \
    AUD_DOWNSAMPLE_OBJ_T atAudDownSampleObj[TYPE1_DECODER_COMP_SUPPORT_MAX_CHANNEL_NUM]; \
    AUD_DROPSAMPLE_OBJ_T atAudDropSampleObj[TYPE1_DECODER_COMP_SUPPORT_MAX_CHANNEL_NUM]; \
    OMX_U32 u4DownsampleRatio; \
    OMX_U32 u4UpsampleRatio; \
    AUD_UPSAMPLE_OBJ_T atAudUpSampleObj[TYPE1_DECODER_COMP_SUPPORT_MAX_CHANNEL_NUM]; \
    tsem_t tAudDropSampleSem; \
    AUD_DEC_MIPS tAudDecMips; \
    FILE* fpDecInputDump; \
    FILE* fpDecOutputDump; \
    OMX_S32 s4UseCase; \
    OMX_S32* atrace_log_level_p;
ENDCLASS(omx_type1_decoder_component_PrivateType)

/* Component private entry points declaration */
OMX_ERRORTYPE omx_type1_decoder_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName);
OMX_ERRORTYPE omx_type1_decoder_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp);

OMX_ERRORTYPE omx_type1_decoder_component_AllocateBuffer(
    OMX_HANDLETYPE hComponent,
    OMX_BUFFERHEADERTYPE** ppBuffer,
    OMX_U32 nPortIndex,
    OMX_PTR pAppPrivate,
    OMX_U32 nSizeBytes);

OMX_ERRORTYPE omx_type1_decoder_component_FreeBuffer(
    OMX_HANDLETYPE hComponent,
    OMX_U32 nPortIndex,
    OMX_BUFFERHEADERTYPE* pBuffer);

OMX_ERRORTYPE omx_type1_decoder_component_GetParameter(
    OMX_HANDLETYPE hComponent,
    OMX_INDEXTYPE nParamIndex,
    OMX_PTR ComponentParameterStructure);

OMX_ERRORTYPE omx_type1_decoder_component_SetParameter(
    OMX_HANDLETYPE hComponent,
    OMX_INDEXTYPE nParamIndex,
    OMX_PTR ComponentParameterStructure);

void* omx_type1_decoder_component_BufferMgmtFunction(void* param);

type1_dec_component* get_comp_from_name(OMX_STRING cComponentName);

#endif
