/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 * $Author$
 * $Date$
 * $RCSfile: vdec_drvif.h,v $
 * $Revision$
 *---------------------------------------------------------------------------*/

/** @file vdec_drvif.h
 *  This header file declares exported APIs of MPV.
 */

#ifndef VDEC_DRVIF_H
#define VDEC_DRVIF_H


//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------

#include "vdec_if.h"
#include "vdp_if.h"
#include "dmx_if.h"
#ifdef ENABLE_MULTIMEDIA
#include "swdmx_drvif.h"
#endif
#include "mpv_if.h"  // for PFN_DEC_NFY_FCT... etc.....  will change it.
#include "drv_tdtv_drvif.h"
#include "drv_dbase.h"
#include "x_os.h"
#include "x_timer.h"
#include "x_mm_common.h"
#include "vdo_misc.h"
#ifdef __KERNEL__
#include <linux/time.h>
#include <linux/sched.h>
#endif
#include "def_vdec.h"

//-----------------------------------------------------------------------------
// Constant definitions
//-----------------------------------------------------------------------------
#define DYNAMIC_MEM_ALLOC_DRV_INFO

// in time-shift, usb device is not fast enough to send 2x data to us.
// use I frame mode to send data.
#ifdef ENABLE_MULTIMEDIA
#define VDEC_TIME_SHIFT_2X_I_MODE
#endif

//-----------------------------------------------------------------------------
// Type definitions
//-----------------------------------------------------------------------------

#define VDEC_FMT_MCORE_SUPPORT(eFmt)  ((eFmt == VDEC_FMT_H264) || (eFmt == VDEC_FMT_H265) || (eFmt == VDEC_FMT_VP9) || (eFmt == VDEC_FMT_DV_H264) || (eFmt == VDEC_FMT_DV_H265) || (eFmt == VDEC_FMT_SHVC))
#define VDEC_FMT_UFO_SUPPORT(eFmt)  ((eFmt == VDEC_FMT_H264) || (eFmt == VDEC_FMT_H265) || (eFmt == VDEC_FMT_VP9) || (eFmt == VDEC_FMT_AVS2) || (eFmt == VDEC_FMT_DV_H264) || (eFmt == VDEC_FMT_DV_H265) || (eFmt == VDEC_FMT_SHVC))

#define VDEC_FMT_LAT_SUPPORT(eFmt)  ((eFmt == VDEC_FMT_H264) || (eFmt == VDEC_FMT_H265) || (eFmt == VDEC_FMT_VP9) || (eFmt == VDEC_FMT_AVS2) || (eFmt == VDEC_FMT_DV_H264) || (eFmt == VDEC_FMT_DV_H265) || (eFmt == VDEC_FMT_SHVC))
#define VDEC_FMT_DV(eFmt) (((eFmt) == VDEC_FMT_DV_H264) || ((eFmt) == VDEC_FMT_DV_H265))

#define VDEC_4K2K_EFUSE_WIDTH   2048
#define VDEC_4K2K_EFUSE_HEIGHT  1088
#define VDEC_8K4K_EFUSE_WIDTH   4096
#define VDEC_8K4K_EFUSE_HEIGHT  2176

#ifndef VLD_ID
#define VLD_ID
typedef enum {
    VLD_Core0 = 0,
    VLD_Core1,
    VLD_Core2,
    VLD_LAE0,
    VLD_LAE1,
    VLD_IMG,
    VLD_MAX,
} ENUM_VLD_ID;
#endif

// VLD ID
#ifndef VLD0 //Remove VLD0 VLD1 later.
#define VLD0   VLD_Core0
#define VLD1   VLD_Core1
#define VLD2   VLD_Core2
#define LAE0   VLD_LAE0
#define LAE1   VLD_LAE1
#endif

// ES ID
#ifndef ES0
#define ES0     0  // in the case, other don't expect we could decode have more than on es
#define ES1     1
#define ES2     2
#define ES3     3
#endif

#ifdef VDEC_WAIT_DISP
#define VDEC_WAIT_DISP_TIME           150         // 100 ms
//    #define MPV_WAIT_DISP_TIME           100         // 100 ms
#define VDEC_AVSYNC_WAIT_DISP_TIME    1000         // 1000 ms
#else
#define VDEC_WAIT_DISP_TIME           0           // Don't wait display, push mode
#define VDEC_AVSYNC_WAIT_DISP_TIME    0
#endif

// Maximum VLD number
//#define LAT_CHIP
#define VDEC_MAX_VLD            6
#ifdef CC_FBM_SUPPORT_8K
#define MAX_SUPPORT_W           8192
#define MAX_SUPPORT_H           4352
#else
#define MAX_SUPPORT_W           4096
#define MAX_SUPPORT_H           2304
#endif

// Maximum Elementary Stream number
#define VDEC_MAX_ES         4
#define VDEC_MAX_INST     VDEC_MAX_ES
#if defined(CC_FBM_FOUR_INST_SUPPORT)
#define SYSTEM_MAX_ES       4
#else
#define SYSTEM_MAX_ES       2
#endif

// Picture Coding Type
#ifndef I_TYPE
#define I_TYPE            1
#endif
#ifndef P_TYPE
#define P_TYPE            2
#endif
#ifndef B_TYPE
#define B_TYPE            3
#endif
#ifndef SEQ_TYPE
#define SEQ_TYPE          4
#endif
#ifndef UNKNOWN_TYPE
#define UNKNOWN_TYPE 255
#endif

// Skip Mode
#ifndef IPBMode
#define IPBMode 0x0
#endif
#ifndef IPMode
#define IPMode 0x1
#endif
#ifndef IMode
#define IMode 0x2
#endif

#define UBE_BUFFER_SZ_4K    (15*1024*1024)
#define UBE_BUFFER_SZ_FHD    (8*1024*1024)

#define TRS_BUFFER_SZ_FHD   (1024*1024*(2))
#define TRS_BUFFER_SZ_4K    (1024*1024*3)

#ifdef CC_FBM_SUPPORT_8K
#define TRS_BUFFER_SZ_8K    (1024*1024*(19))
#define SlICE_BUFFER_SZ     (1024*640)
#define ERR_BUFFER_SZ       ((8192 / 16) * (4352 / 16) / 8)
//#define ROW_BUFFER_SZ       (4320 / 16 * 20 * 512)
// for hevc case
// 512 * num_of_tile_column * ((num_of_row + 2) / 3 * 3) (HEVC 3core)
#define ROW_BUFFER_SZ       (4320 / 16 * 32 * 512)
#else
#define TRS_BUFFER_SZ_8K    0//easy to debug
#define SlICE_BUFFER_SZ     (1024*320) //AVS2 need large slice buffer
#define ERR_BUFFER_SZ       (32*(2304 + 15)/16)//(32*((2304 + 63)/64))/*VP9: (32*((2304 + 63)/64)), H264/HEVC: (32*((2304 + 15)/16))*/
#define ROW_BUFFER_SZ       (2*1024*1024)
#endif

#define LAX_BUFFER_CNT     (3)
#define LAX_MSG_RECYCLE    (LAX_BUFFER_CNT+2)/*For two data worklet + 1or2 cmd worklet*/

#define VDEC_MSG_PRI_LOW    (255)
#define VDEC_MSG_PRI_HIGH   (254)

// 64k for VP9/HEVC/AVC
#define CODEC_PRIVATE_SIZE (64 * 1024)
#define CT_ASSERT(x) struct CT_ASSERT_##__LINE__ { VOID *data[!!(x) ? 1 : -1]; }
#define CT_ASSERT_CODEC_PRIVATE_SIZE(x) CT_ASSERT(sizeof(x) <= CODEC_PRIVATE_SIZE)

/* VDEC_ISWORKER for flow control */
#define VDEC_ISWORKER(x) ((VLD_MODE_SCORE_LAT == x)||(VLD_MODE_MULTI == x))  /* Worker thread flow */
#define VDEC_ISREALDEC(x) ((VLD_MODE_REAL & x))                              /*Multi core/LAT single core/single core thread flow */
#define VDEC_ISCONTROL(x) ((VLD_MODE_LAX & x)||(VLD_MODE_SINGLE == x))       /* Control thread flow */
#define VDEC_ISSCORE(x) ((VLD_MODE_SINGLE == x))                             /* Single core thread flow, Tmp */
#define VDEC_ISLAX(x) ((VLD_MODE_LAX & x))                                   /* LAX thread flow */

/* VDEC_ISREALDEC for reg setting */
#define VDEC_ISSCORE_LATMODE(x) ((VLD_MODE_SCORE_LAT == x))   /* LAT single core reg setting */
#define VDEC_ISMCORE(x) ((VLD_MODE_MULTI == x))           /* Multi core reg setting */

#define VDEC_ISLAE(x) ((VLD_MODE_LAE == x))               /* LAE reg setting */
#define VDEC_ISLAT_SCORE(x) ((VLD_MODE_LAT_SCORE & x) == VLD_MODE_LAT_SCORE)               /* LAT reg setting */
#define VDEC_ISLAT_MCORE(x) (VLD_MODE_LAT_MCORE == ((x) & VLD_MODE_LAT_MCORE))               /* LAT reg setting */
#define VDEC_ISLAT_TCORE(x) (VLD_MODE_LAT_TCORE == ((x) & VLD_MODE_LAT_TCORE))               /* LAT tricore reg setting */
#define VDEC_ISMLAT(x) ((VLD_MODE_MLAT & x) == VLD_MODE_MLAT)

typedef enum
{
    VLD_MODE_NONE = 0,
    VLD_MODE_REAL = (1<<1),
    VLD_MODE_SINGLE = VLD_MODE_REAL | (1<<2),
    VLD_MODE_MULTI = VLD_MODE_REAL | (1<<3),
    VLD_MODE_SCORE_LAT = VLD_MODE_REAL | (1<<4),
    VLD_MODE_TRICORE = VLD_MODE_REAL | (1<<11),
    VLD_MODE_LAX = (1<<5),
    VLD_MODE_LAE = VLD_MODE_LAX | (1<<6),
    VLD_MODE_LAT_SCORE = VLD_MODE_LAX | (1<<7),
    VLD_MODE_LAT_MCORE = VLD_MODE_LAX | (1<<8),
    VLD_MODE_MLAT = VLD_MODE_LAX | (1<<9),
	VLD_MODE_LAT_TCORE = VLD_MODE_LAT_MCORE | (1<<10),
} ENUM_VDEC_VLD_MODE;

#define VDEC_SEQINFO_SIZE 300

// config section
//After dectecting all Intra slice in No I bitstream, wait 1 P to display.
#define MPV_WAIT_P                       1

#ifdef __MODEL_slt__
#define MPV_FIFO_CTRL_INIT              3000         // for SLT
#define H264_FIFO_CTRL_INIT             3000         // for SLT
#else
#define H264_FIFO_CTRL_INIT             9000         // 200 ms, 18000/90000
#define MPV_FIFO_CTRL_INIT               9000         // 100ms , for audio pops noise issue
#endif

// ESM Q Underflow Number
#define MPV_UDF_PES_NS                   8

// Maximum PES Info number in ESM queue
#define MPV_MAX_PES_NS_PER_QUEUE         1800
#define H264_MAX_PES_NS_PER_QUEUE        1800

#define VDEC_MSG_Q_SIZE                    2048//255//80 // es queue

#define VDEC_AVG_PIC_COUNT               200
#define VDEC_AVG_PIC_SIZE               (20*1024)

#define VDEC_BIG_B_LEVEL1               (33000)
#define VDEC_BIG_B_LEVEL2               (35000)
#define VDEC_BIG_B_LEVEL3               (37000)
#define VDEC_BIG_B_BASE_COUNT           (2)


// Frame Rate
#define VDEC_FRAME_RATE_1000_UNKNOWN                                       (60000)
#define VDEC_FRAME_RATE_1000_23_976                                        (23976)
#define VDEC_FRAME_RATE_1000_24                                            (24000)
#define VDEC_FRAME_RATE_1000_25                                            (25000)
#define VDEC_FRAME_RATE_1000_29_97                                         (29970)
#define VDEC_FRAME_RATE_1000_30                                            (30000)
#define VDEC_FRAME_RATE_1000_50                                            (50000)
#define VDEC_FRAME_RATE_1000_59_94                                         (59940)
#define VDEC_FRAME_RATE_1000_60                                            (60000)
#define MAX_FRAME_RATE 240

#define MAX_USERDATA_SIZE          2400

#define CODEC_DETECT_THRD    15

#define DATA_DUMP_EXTDATA_SIZE (2 * 1024)
// for slt es pattern
#define ES_FILE_SYNC_CODE 0xAABBCCDD

//Max RPR SIZE
#define RV_MAX_NUM_RPR_SIZES 8

//Vdec Alignment
#define VDEC_ALIGN_MASK(value, mask)     ((value + mask) & (~mask))

#define VDEC_ALIGN_MASK_DOWN(value, mask)     ((value) & (~mask))

#define VDEC_PUSH_CB_PUT_DATA_DONE  (1<<0)
#define VDEC_PUSH_CB_DECODE_DONE    (1<<1)
#define VDEC_PUSH_CB_STOP_DONE      (1<<2)
#define VDEC_PUSH_CB_IMG_FRAME_DONE (1<<3)
#define VDEC_PUSH_CB_FLUSH_DONE     (1<<4)
#define VDEC_PUSH_CB_VDEC_ERR       (1<<5)
#define VDEC_PUSH_CB_UNDERRUN       (1<<6)
#define VDEC_PUSH_CB_THUMBNAIL      (1<<7)
#define VDEC_PUSH_CB_HDR10INFO      (1<<8)

#define VDEC_PUSH_SET_INFO_DECODE_ONLY  (1<<0)
#define VDEC_PUSH_SET_INFO_VDEC_ID      (1<<1)
#define VDEC_PUSH_SET_INFO_DECRYIPT     (1<<2)
//add for stagefright porting back
#define VDEC_PUSH_SET_INFO_FBG_FROM_INST    (1<<3)
#define VDEC_PUSH_SET_INFO_DECODE_MODE      (1<<4)
#define VDEC_PUSH_SET_INFO_PLAY_MODE        (1<<5)
#define VDEC_PUSH_SET_INFO_SECURE_INPUT     (1<<6)
#define VDEC_PUSH_SET_INFO_VDP_ID            (1<<7)
#define VDEC_PUSH_SET_INFO_LOW_LATENCY      (1<<8)
#define VDEC_PUSH_SET_INFO_SIDE_BAND         (1<<9)
#define VDEC_PUSH_SET_INFO_TYPE_THUMBNAIL    (1<<10)

#define VDEC_POWERON_TRIGGER_EVENTS_DEC_START       (1 << 0)
#define VDEC_POWERON_TRIGGER_EVENTS_DEC_STOP        (1 << 1)
#define VDEC_POWERON_TRIGGER_EVENTS_FRAME_DECODED   (1 << 2)

// VP6 alpha
#define VP6_ALPHA_ENABLE    (0x01 << 0)
#define VP6_ALPHA_FRAME     (0x01 << 1)

#define INVALID_THUMBNAIL_PTS   ((UINT32)(-1))
#define MAX_THUMBNAIL_PIC_CNT   ((UINT32)(0xffffffff))

#define VDEC_FRAME_RATE_60_120(bFraRate) ((bFraRate == MPEG_FRAME_RATE_100) ||(bFraRate == MPEG_FRAME_RATE_120_) || (bFraRate == MPEG_FRAME_RATE_120))


#define VDEC_LOADL_DWRD(p, arg2) \
    ((arg2) = ((UINT32)(p)[0])   \
        | ((UINT32)(p)[1] <<  8) \
        | ((UINT32)(p)[2] << 16) \
        | ((UINT32)(p)[3] << 24) )

#define VDEC_LOADB_DWRD(p, arg2) \
    ((arg2) = ((UINT32)(p)[3])   \
        | ((UINT32)(p)[2] <<  8) \
        | ((UINT32)(p)[1] << 16) \
        | ((UINT32)(p)[0] << 24) )

#define VDEC_LOADL_WORD(p, arg2) \
    ((arg2) = ((UINT16)(p)[0])   \
        | ((UINT16)(p)[1] <<  8) )

#define VDEC_ABS(x) ( (x>0) ? (x) : (-(x)) )


#define VDEC_U8_SECOND_CLOCK ((UINT64)1000000)

#define VDEC_IS_SEAMLESS(type) \
    (((type) == SWDMX_SRC_TYPE_NETWORK_NETFLIX_3D) || \
     ((type) == SWDMX_SRC_TYPE_NETWORK_NETFLIX) || \
     ((type) == SWDMX_SRC_TYPE_NETWORK_LIVE_STREAMING) || \
     ((type) == SWDMX_SRC_TYPE_NETWORK_HLS) || \
     ((type) == SWDMX_SRC_TYPE_YOUTUBE) || \
     ((type) == SWDMX_SRC_TYPE_NETWORK_MSS) || \
     ((type) == SWDMX_SRC_TYPE_NETWORK_DASH) || \
     ((type) == SWDMX_SRC_TYPE_NETWORK_VUDU) || \
     ((type) == SWDMX_SRC_TYPE_AMAZON))

// even number is Main
// odd number is Sub, only used for dual track's enhancement layer
// currently, we only support es0/es1
#define VDEC_MAIN_ID(__id)  ((__id) & ~1)
#define VDEC_SUB_ID(__id)  (VDEC_MAIN_ID(__id) + 1)
#define VDEC_IS_MAIN(__id) (VDEC_MAIN_ID(__id) == (__id))

//#define TEST_ONOFF_RUNTIME
//-----------------------------------------------------------------------------
// Macro definitions
//-----------------------------------------------------------------------------

typedef BOOL (*PFN_PUTDATADONE)(UINT64 u8Tag);
typedef BOOL (*PFN_STOPDONE)(UINT64 u8Tag);
typedef BOOL (*PFN_FLUSHDONE)(UINT64 u8Tag);
typedef BOOL (*PFN_DECODEDONE)(UINT64 u8Tag, UINT32 u4FbgId, UINT32 u4FbId, UINT32 u4DolbyType, BOOL fgEos);
typedef BOOL (*PFN_IMGFRMDONE)(UINT64 u8Tag, VOID* pvData);
typedef BOOL (*PFN_ERRORHANDLER)(UINT64 u8Tag, VOID* pvData);
typedef BOOL (*PFN_UNDERRUN_CB)(UINT64 u8Tag);
typedef BOOL (*PFN_THUMB_CB)(UINT64 u8Tag, VOID* pvData);
typedef BOOL (*PFN_HDR10INFO_CB)(UINT64 u8Tag);

struct _VDEC_ES_INFO_T_;
struct VDEC_WORKLET_T;
struct VDEC_LAX_BUF_INFO_T;
typedef struct _VDEC_DV_LAYER_PROPERTY_T_ VDEC_DV_LAYER_PROPERTY_T;
typedef struct _VDEC_DECODER_TYPE_T_ VDEC_DECODER_TYPE_T;
typedef struct _VDEC_DECODER_MEM_ITEM_T_ VDEC_DECODER_MEM_ITEM_T;
typedef struct _VDEC_DECODER_HANDLE_T_ VDEC_DECODER_HANDLE_T;
typedef struct _VDEC_DECODER_OPS_T_ VDEC_DECODER_OPS_T;

/** vpush command.
*/
typedef enum
{
    VPUSH_CMD_PLAY,
    VPUSH_CMD_STOP,
    VPUSH_CMD_PAUSE,
    VPUSH_CMD_FLUSH,
    VPUSH_CMD_PLAY_SYNC,
    VPUSH_CMD_STOP_SYNC,
    VPUSH_CMD_PAUSE_SYNC,
    VPUSH_CMD_FLUSH_SYNC,
    VPUSH_CMD_MAX
}   VPUSH_CMD_T;

/** decoding state.
*/
typedef enum
{
    VPUSH_ST_STOP,

    VPUSH_ST_PLAY,

    VPUSH_ST_IDLE,
    VPUSH_ST_MAX
}   ENUM_VPUSH_STATE_T;

typedef void* VDEC_HDLR;

/** the notify conditions.
*/
typedef enum
{
    VDEC_EVT_DEC_FINISH,
    VDEC_EVT_DISP_READY,
    VDEC_EVT_DEC_ERROR,
    VDEC_EVT_DEC_BS_END
}   VDEC_EVENT_T;


/**Decoding mode of video decoder
 */
typedef enum
{
    VDEC_RM_ALLOC_OK,     ///< VDEC Decode RM alloc HW OK
    VDEC_RM_ALLOC_NG,     ///< VDEC Decode RM alloc HW Fail
    VDEC_RM_ALLOC_CFT,    ///< VDEC Decode RM alloc HW conflict
    VDEC_RM_IMGRZ_REQ,    ///< VDEC Decode RM require to add imgrz number
    VDEC_RM_UNKNOWN  ,    ///< VDEC Decode MSG Unknown
}VDEC_RM_COND_T;       ///MTVDEC_RM_COND_T


typedef enum
{
    VDEC_RM_BLK_NONE,               ///< VDEC Decode RM: block none
    VDEC_RM_BLK_VDEC_WAIT       = (1<<0), ///< VDEC Decode RM: wait for kick
    VDEC_RM_BLK_VDEC_DONE       = (1<<1), ///< VDEC Decode RM: kick back

    VDEC_RM_BLK_B2R_WAIT        = (1<<2), ///< VDEC Decode RM: b2r wait for kick
    VDEC_RM_BLK_B2R_DONE        = (1<<3), ///< VDEC Decode RM: b2r kick back

    VDEC_RM_BLK_IMGRZ_WAIT      = (1<<4), ///< VDEC Decode RM: imgrz kick back
    VDEC_RM_BLK_IMGRZ_DONE      = (1<<5), ///< VDEC Decode RM: imgrz wait for kick

    VDEC_RM_BLK_FORCE_CLR       = (1<<7), ///< VDEC Decode RM:  force clear block status, such as stop
    VDEC_RM_BLK_KICK_FAIL       = (1<<8), ///< VDEC Decode RM: kick fail
}VDEC_RM_BLOCK_E;


/** vdec command.
*/
typedef enum
{
    VDEC_CMD_PLAY,
    VDEC_CMD_PLAY_I_FRAME,
    VDEC_CMD_PLAY_ONE_FRAME,
    VDEC_CMD_STOP,
    VDEC_CMD_AVSYNC,
    VDEC_CMD_DEBLOCK,
    VDEC_CMD_PAUSE,
    VDEC_CMD_CAPTURE,
    VDEC_CMD_FLUSH,
    VDEC_CMD_FLUSH_ESMQ,
    VDEC_CMD_3D_MODE_CHANGE,
    VDEC_CMD_MAX
}   VDEC_CMD_T;

typedef enum
{
    VDEC_LOG_INFO          = 1 << 0,
    VDEC_LOG_DEBUG         = 1 << 1,
    VDEC_LOG_ERROR         = 1 << 2,
    VDEC_LOG_DECINFO      = 1 << 3,
    VDEC_LOG_FBMST        = 1 << 4,
    VDEC_LOG_INPUT        = 1 << 5,
    VDEC_LOG_VDEC2VDP     = 1 << 6,
    VDEC_LOG_DROPPIC      = 1 << 7,
    VDEC_LOG_SEQINFO      = 1 << 8,
    VDEC_LOG_VDEC_CRC     = 1 << 9,
    VDEC_LOG_DECREF       = 1 << 10,
    VDEC_LOG_PICINFO      = 1 << 11,
    VDEC_LOG_BANDWIDTH    = 1 << 12,
    VDEC_LOG_DecTime      = 1 << 13,
    VDEC_LOG_ColorSpace   = 1 << 14,
    VDEC_LOG_CCDATA       = 1 << 15,
    VDEC_LOG_ERRACC       = 1 << 16,
    VDEC_LOG_REG          = 1 << 17,
    VDEC_LOG_OUTPUT       = 1 << 18,
    VDEC_LOG_TZ_Ret       = 1 << 19,
    VDEC_LOG_MEM          = 1 << 20,
    VDEC_LOG_INPUT_CHKSUM = 1 << 21,
    VDEC_LOG_QP           = 1 << 22,
    VDEC_LOG_DV_PTS       = 1 << 23,
    VDEC_LOG_INWIND       = 1 << 24,
    VDEC_LOG_DMX2VDEC     = 1 << 25,
    VDEC_LOG_DMX2VDEC_DV  = 1 << 26,
    VDEC_LOG_HDR          = 1 << 27,
    VDEC_LOG_DPB          = 1 << 28,
    VDEC_LOG_DUMPREG      = 1 << 29,
    VDEC_LOG_HDR10PLUS    = 1 << 30,
    VDEC_LOG_MAX_NUM      = 31,
} VDEC_LOG_LEVEL_T;

/** decoding state.
*/
typedef enum
{
    VDEC_ST_STOP,
    VDEC_ST_INIT,
    VDEC_ST_PLAY,
    VDEC_ST_IDLE,
    VDEC_ST_MAX
}   ENUM_VDEC_STATE_T;

/** play state.
*/
typedef enum
{
    VDEC_DEC_PRE_PARSE,          //CC_SUPPORT_VDEC_PREPARSE: For CPU pre-parser W/H fps ...info.
    VDEC_DEC_FPS_CALC,
    VDEC_DEC_RES_ALLOC,           //Alloc Resource status, maybe block as resource conflict.
    VDEC_DEC_HEADER_PARSE,
    VDEC_DEC_START_DECODE,
    VDEC_DEC_WAIT_DECODE,
    VDEC_DEC_DECODE_DONE,        //
    VDEC_DEC_FATAL,           //
}   ENUM_VDEC_DEC_STATE_T;

typedef enum
{
    E_VDEC_OK,
    E_VDEC_DISP_NOT_READY,
    E_VDEC_PARSE_NOT_READY,
    E_VDEC_FAIL,
    E_VDEC_NOT_SUPPORT,  // for emulation
    E_VDEC_BITSTREAM_NOT_SUPPORT,
    E_VDEC_NEED_RM_IMGRZ,
    E_VDEC_SKIPFRAME,
    E_VDEC_NOT_CODED_FRAME,
    E_VDEC_RES_NOT_SUPPORT,
    E_VDEC_ALLOCATEFB,
    E_VDEC_RETRY,
    E_VDEC_INVALID_START_CODE,  // for dmx error
    E_VDEC_FRAME_RATE_NOT_SUPPORT,
    E_VDEC_DROP,
    E_VDEC_NOT_IMPL,
    // invalid type between svp remote call
    E_VDEC_PROTOCOL_ERROR,
    E_VDEC_MAX
} ENUM_VDEC_AVC_RET;

/** the frame rate of video source.
*/
typedef enum
{
    VDEC_SRC_FRAME_RATE_UNKNOWN = 0,
    VDEC_SRC_FRAME_RATE_23_976, /* 24000/1001 (23.976...) */
    VDEC_SRC_FRAME_RATE_24,
    VDEC_SRC_FRAME_RATE_25,
    VDEC_SRC_FRAME_RATE_29_97, /* 30000/1001 (29.97...) */
    VDEC_SRC_FRAME_RATE_30,
    VDEC_SRC_FRAME_RATE_50,
    VDEC_SRC_FRAME_RATE_59_94, /* 60000/1001 (59.94...) */
    VDEC_SRC_FRAME_RATE_60,
    VDEC_SRC_FRAME_RATE_120,
    VDEC_SRC_FRAME_RATE_1,
    VDEC_SRC_FRAME_RATE_5,
    VDEC_SRC_FRAME_RATE_8,
    VDEC_SRC_FRAME_RATE_10,
    VDEC_SRC_FRAME_RATE_12,
    VDEC_SRC_FRAME_RATE_15,
    VDEC_SRC_FRAME_RATE_2,
    VDEC_SRC_FRAME_RATE_6,
    VDEC_SRC_FRAME_RATE_48,
    VDEC_SRC_FRAME_RATE_70,
    VDEC_SRC_FRAME_RATE_20,
    VDEC_SRC_FRAME_RATE_240,
    VDEC_SRC_FRAME_RATE_100,
    VDEC_SRC_FRAME_RATE_VARIABLE
} ENUM_VDEC_FRAME_RATE_T;


/* from MW VID_DEC_SET_TYPE_CODEC settings *******************************************/
typedef enum
{
    VDEC_CODEC_UNKNOWN = 0,
    VDEC_CODEC_MPEG_1,
    VDEC_CODEC_MPEG_2,
    VDEC_CODEC_MPEG_4,
    VDEC_CODEC_DIVX_311,
    VDEC_CODEC_DIVX_4,
    VDEC_CODEC_DIVX_5,
    VDEC_CODEC_XVID,
    VDEC_CODEC_WMV1,
    VDEC_CODEC_WMV2,
    VDEC_CODEC_WMV3,
    VDEC_CODEC_WVC1,
    VDEC_CODEC_H264,
    VDEC_CODEC_H263,
    VDEC_CODEC_MJPEG,
    VDEC_CODEC_RV8,
    VDEC_CODEC_RV9,
    VDEC_CODEC_VP6,
    VDEC_CODEC_VP8
}   ENUM_VDEC_CODEC_T;


/* */
typedef enum
{
    VPUSH_MSG_NONE = 0,
    VPUSH_MSG_CMD,
    VPUSH_MSG_DATA,
    VPUSH_MSG_ALLOC_DATA,
    VPUSH_MSG_MAX,
}   ENUM_VPUSH_MSG_T;

typedef enum
{
    VPUSH_IO_MSG_NONE = 0,
    VPUSH_IO_MSG_DUMMY,
    VPUSH_IO_MSG_DATA,
    VPUSH_IO_MSG_EOS,
    VPUSH_IO_MSG_EOS_DONE,
    VPUSH_IO_MSG_MAX,
}   ENUM_VPUSH_IO_MSG_T;

typedef enum
{
    VDEC_DECODE_MODE_UNKNOWN = 0,       ///< Unknown
    VDEC_DECODE_MODE_NORMAL,            ///< decode all frames (no drop)
    VDEC_DECODE_MODE_I_ONLY,            ///< skip P and B frame
    VDEC_DECODE_MODE_B_SKIP,            ///< skip B frame
    VDEC_DECODE_MODE_NO_REORDER         ///< output display ASAP without reroder
} VDEC_DECODE_MODE_T;

typedef enum _VDE_PUSH_MODE_T
{
    VDEC_PUSH_MODE_UNKNOWN = 0,
    VDEC_PUSH_MODE_ASYNC,
    VDEC_PUSH_MODE_TUNNEL
} VDEC_PUSH_MODE_T;

typedef enum
{
    SUPER_DATA_DUMP_POINT_RECEIVE_ES,
    SUPER_DATA_DUMP_POINT_SEND_ES,
    SUPER_DATA_DUMP_POINT_VPUSH_EMPTY,
    SUPER_DATA_DUMP_POINT_TEMP_WRITE,
    SUPER_DATA_DUMP_POINT_MAX
}SUPER_DATA_DUMP_POINT_TYPE;

typedef enum
{
    ES_FILE_FLAG_SEQINFO             = 1,
    ES_FILE_FLAG_RV_RPR              = 2,
    ES_FILE_FLAG_RV_SLICE_SIZE_ARRAY = 4,
} ES_FILE_FLAG;

typedef struct _VDEC_APP_TYPE_T
{
    CHAR *pcAppType;
    UINT32 u4AppTypeSize;
#ifdef ENABLE_MULTIMEDIA
    SWDMX_SOURCE_TYPE_T eMMSrcType;
#endif
} VDEC_APP_TYPE_T;

typedef struct _VDEC_CONTAINER_TYPE_T
{
    CHAR *pcContainerType;
    UINT32 u4ContainerTypeSize;
#ifdef ENABLE_MULTIMEDIA
    ENUM_SWDMX_FMT_T eContainerType;
#endif
} VDEC_CONTAINER_TYPE_T;

// This structure must be same with FBM_PIC_EXTRA_T
typedef struct
{
    BOOL fgValid;

    UINT64 u8PTSI;                                  //  I frame pts
    UINT64 u8AudPTS;
    UINT64 u8AudOffset;
} VDEC_PIC_EXTRA_INFO_T;

typedef struct {
    UINT64 u8BytesPTS;         // PTS
    UINT32 u4BytesTag;         // caller's tag
    UPTR  u4BytesAddr;        // data address
    UINT32 u4BytesSize;        // data size
    UINT32 u4EncryptOffset;
    UINT32 u4EncryptLen;
    UPTR u4SecureInputBufStartAddr;
    UPTR u4SecureInputBufEndAddr;
    BOOL fgEos;                // EOS
    BOOL fgAppend;             // Append data to previous buffer
    BOOL fgCodecConfigData;
    BOOL fgEncryptReset;
    BOOL fgMoveBufDone;
    //add for dmx iommu
    BOOL fgDmxIommu;
    UINT32 u4Pgd;
    UINT32 u4Iova;
    UPTR  u4BytesAddrOrg;      // data address
    UINT32 u4BytesSizeOrg;        // data size
} VDEC_BYTES_INTO_T;

typedef struct {
    ENUM_VPUSH_MSG_T eMsgType;
    union
    {
        VPUSH_CMD_T eCmd;
        VDEC_BYTES_INTO_T rBytesInfo;
    }u;
} VDEC_MSG_INTO_T;

typedef struct
{
    UINT32  u4BufferCount;          //[output param] The number of buffers this port requires, default set as 5
    UINT32  u4BufferSize;           //[output param] Size, in bytes, for buffers to be used for this channel, alignment of nFrameWidth * nFrameHeight * n
} VDEC_VFIFO_INTO_T;

typedef struct {
    UINT32 u4TotalSize;
    UINT32 u4BufferCount;
    UINT32 u4BufferSize;
} VDEC_FEEDER_INTO_T;

typedef struct {
    BOOL   fgAUSeqHdr;        // contain sequence header
    BOOL   fgEos;             // EOS
    UCHAR  ucAUPicType;       // picture type
    UINT32 u4AUTag;           // caller's tag
    UINT32 u4AUPTS;           // PTS
    UINT32 u4AUAddr;
    UINT32 u4AUSize;
} VDEC_AU_INTO_T;


typedef struct {
    UINT32 u4Mask;
    UINT64 u8StopTag;
    UINT64 u8FlushTag;
    UINT64 u8PutTag;
    UINT64 u8DecodeTag;
    UINT64 u8ImageTag;
    UINT64 u8VdecErrTag;
    UINT64 u8VdecUnderrunTag;
    UINT64 u8VdecThumbTag;
    UINT64 u8VdecHdr10infoTag;
    PFN_STOPDONE pfnVdecStopDone;
    PFN_FLUSHDONE pfnVdecFlushDone;
    PFN_PUTDATADONE pfnVdecPutDataDone;
    PFN_DECODEDONE pfnVdecDecodeDone;
    PFN_IMGFRMDONE pfnVdecImgFrmDone;
    PFN_ERRORHANDLER pfnVdecErrHandler;
    PFN_UNDERRUN_CB pfnVdecUnderrunCb;
    PFN_THUMB_CB pfnVdecThumbCb;
    PFN_HDR10INFO_CB pfnVdecHdr10infoCb;
} VDEC_PUSH_CB_T;


typedef struct {
    UINT16 u2DisplayedStartX;
    UINT16 u2DisplayedStartY;
    UINT16 u2ExpandedWidth;
    UINT16 u2ExpandedHeight;
    UINT16 u2OriginalWidth;
    UINT16 u2OriginalHeight;
    UINT16 u2OutputWidth;
    UINT16 u2OutputHeight;
    UINT8* pBuffer;
} VDEC_IMG_FRMDONE_DATA;


typedef struct {
    UINT32 u4InfoMask;
    VDEC_DECODE_MODE_T eDecodeMode;
    UCHAR ucVdecId;
    BOOL fgVPushDecodeOnly;
    BOOL fgVPushDecrypt;
    VDEC_PUSH_MODE_T eVpushPlayMode;
    UCHAR ucVdpId;
    UINT32 reserved;
} VDEC_SET_INTO_T;

typedef struct {
    UCHAR ucVdecId;
    UCHAR ucVPushId;
    UINT32 reserved;
} VDEC_GET_INTO_T;

typedef struct
{
    UINT32    u4HdrType;                      ///< HDR type
    UINT32    u4VdoHdrChange;                 ///< HDR type change
    UINT32    u4VdoGamma;                     ///< Gamma type
    UINT32    u4ColorSpaceTypeDef;            ///< ColorSpace type
    UINT32    u4VdoColorSpaceChange;          ///< ColorSpace type change
    UINT32    u4TV_MaxLuma;                   ///< TV_MaxLuma
    UINT32    u4TypeMatrixCoefficients;      ///< add by lihui.li for TV MatrixCoefficients type
    UINT32    u4TypeRange;                     ///< add by lihui.li for range type
} VDEC_HDR10_INFO_T;

typedef struct
{
    UINT16  ui2DisplayPrimaries_x[3];
    UINT16  ui2DisplayPrimaries_y[3];
    UINT16  ui2WhitePoint_x;
    UINT16  ui2WhitePoint_y;
    UINT16  ui2MaxDisplayMasteringLum;
    UINT16  ui2MinDisplayMasteringLum;
    UINT16  ui2MaxCll;
    UINT16  ui2MaxFall;
} VDEC_HDR10_METADATA_INFO_T;

typedef struct
{
    VDEC_HDR10_METADATA_INFO_T   tHdr10MetadataInfo;
    VDEC_HDR10_INFO_T            tHdr10Info;
    UINT32                       u4MetadataHandler;
    BOOL                         fgMetadataEncrypt;
} VDEC_HDRSRC_PROFILE_T;

typedef struct
{
    VDEC_HDR10_METADATA_INFO_T tHdr10MetadataInfo;
    UINT32 u4HdrType;
    UINT32 u4MetadataHandler;
    BOOL fgMetadataEncrypt;
} VDEC_HDR_DYNAMIC_METADATA_INFO_T;

// Dolby Vision information
//!!!keep it aligned with the one in vdec_drv_if.h
typedef struct
{
    UINT32 u4DVProfile;
    UINT32 u4LayerPresentFlag;
    UINT32 u4DVContainer;
    BOOL fgSingleTrack;
    BOOL fgReorderRPUWithEnhancementLayer;
}VDEC_DV_INFO_T;

//!!!keep it aligned with the one in vdec_drv_if.h
typedef struct {
    UCHAR u1Version;
    UCHAR u1Profile;
    UCHAR u1Level;
    UCHAR u1RPUAssocFlag;
    UCHAR u1Reserved1;
    UCHAR u1Reserved2;
}VDEC_DV_CSD_INFO_T;

// ES Info in ESMQ
typedef struct
{
    // reorder it to avoid alignment issue.
    VDEC_PIC_EXTRA_INFO_T  rExtra;
    HAL_TIME_T rTime;
    UINT64 u8Offset;
    UINT64 u8OffsetI;
    UINT64 u8PTSInUs;
    UINT32 u4PesExtBufStart;
    UINT32 u4PesExtBufEnd;
    UINT32 u4PesExtBufCurrentRp;
    UINT32 u4PesExtBufCurrentWp;
    UINT32 u4BitRate;
    UINT64 u4RenderPts;
    UINT32 u4TotalTimeOffset;
    UINT32 u4TickNum;
    UINT32 u4Timestap;
    union {
        UPTR u4FifoStart;
        UINT64 u4FifoStartPadding;
    };
    union {
        UPTR u4FifoEnd;
        UINT64 u4FifoEndPadding;
    };
    union {
        UPTR u4VldReadPtr;
        UINT64 u4VldReadPtrPadding;
    };
    union {
        UPTR u4VldReadPtrEnd;
        UINT64 u4VldReadPtrEndPadding;
    };
    union {
        UPTR u4DmxWritePtr;
        UINT64 u4DmxWritePtrPadding;
    };
    union {
        UPTR upRPU;
        UINT64 upRPUPadding;
    };
    union {
        UPTR upRPUEnd;
        UINT64 upRPUEndPadding;
    };
    BOOL fgAnnexB;           //for av1
    UINT32 u4FrameSize;      //for av1
    UINT64 u4PTS;
    UINT32 u4TimeScale;
    UINT32 u4DTS;
    UINT32 u4VideoType;
    UINT32 u4DmxFrameType;
    UINT16 u2DecodingOrder;
    UINT16 u2SkipVidCount;
    UINT8 u1SliceCount;
    UINT8  u1AlphaFlag;
    UCHAR ucMpvId;
    UCHAR ucEsId;
    union
    {
        UINT16 ucPicType;
        UINT16 u2PicType;
    };
    UINT16 u2DolbyType;
    UCHAR au1PicInfo[DMX_PICINFO_SIZE];
    BOOL fgSeqHdr;
    BOOL fgGop;
    BOOL fgDtsValid;      //DTS is valid
    BOOL fgNoVdecCalPts;
    BOOL fgBackward;
    BOOL fgEos;
    BOOL fgIBCEos; /* for use hls seamless playback */
    BOOL fgSeqEnd;
    BOOL fgNonBuffer;
    //BOOL fgSkipFrame;  // only enable this for WMV emulation!
    BOOL fgNotUpdateDmxRp;
    BOOL fgMoveComplete;

    BOOL fgWFDTMSLogEnable;
    UINT64 u8_vid_pts;
    UINT64 u8_push_time;//ms
    //for dash framerate change & bandwidth change
    BOOL fgFrmChanged;
    BOOL fgBandwidthChanged;
    BOOL fgHdrInfo;
    //TEMS
    UINT64 u8MediaTimestamp;
    UINT32 u4TemiScale;
    UINT32 u4TemiRem;
    UINT32 u4DelayTime;
    VDEC_HDR_DYNAMIC_METADATA_INFO_T rHdrMetaDataInfo;
    BOOL fgBLEL;
} VDEC_PES_INFO_T;

typedef struct _ES_FILE_DATA_INFO_T_
{
    UINT32 u4SyncCode;
    UINT32 u4DataSize;
    UINT32 u4ReadPtrOffset;
    UINT32 u4RenderPts;
    UINT32 u4TickNum;
    UINT32 u4Timestap;
    // for slt
    UINT32 u4PTS;
    UINT32 u4DTS;
    UINT32 u4VideoType;
    UINT32 u4DmxFrameType;
    UINT64 u8_vid_pts;
    UINT64 u8_push_time;  // ms
    UINT16 u2DecodingOrder;
    UINT8  u1SliceCount;
    UINT8  u1AlphaFlag;
    UCHAR  ucPicType;
    BOOL   fgSeqHdr;
    BOOL   fgGop;
    BOOL   fgDtsValid;  // DTS is valid
    BOOL   fgSeqEnd;
    BOOL   fgMoveComplete;
    BOOL   fgEos;
    BOOL   fgNonBuffer;
    UCHAR  au1PicInfo[DMX_PICINFO_SIZE];
} ES_FILE_DATA_INFO;

#ifdef CC_EMULATION_CRC
typedef struct
{
  UINT8   u1PicCRCCnt;
  UINT32 u4PicCRC_0[8];   // 4 For Y, 4 For C
  UINT32 u4PicCRC_1[8];   // 4 For Y, 4 For C
} VDEC_PIC_CRC_T;
#endif

//for emulation
typedef struct
{
    void* pvYAddr;
    void* pvCAddr;
    void* pvYDbkAddr;
    void* pvCDbkAddr;
    void* pvMVAddr;
    UINT32 u4YSize;
    UINT32 u4CSize;
    UINT32 u4W;
    UINT32 u4H;
    UINT32 u4Ycrc[11];
    UINT32 u4Ccrc[8];
    UINT32 u4ChromaFormatIdc;
    UINT32 u4VLDidx;
    UINT8 u1PicStruct;
    //for wmv
    UINT32 u4CurrentPicNo;
    UINT8  u1FrameCodingMode;
    UINT32 i4CurrentTemporalField;
    UINT32 u4W_Cmp;
    UINT32 u4H_Cmp;
    // for vp6
    BOOL   fgAlphaFrame;
#ifdef CC_EMULATION_CRC
    VDEC_PIC_CRC_T rPicCRC;
#endif
    //dual core
    UCHAR ucDualMode;
    UCHAR ucUFOEnable;
}VDEC_DISP_PIC_INFO_T;

/* this struct must match with ENUM_TZ_VDEC_FB_OPERATION_T in tz.h */
typedef enum
{
    TZ_VDEC_FB_MEMCPY,
    TZ_VDEC_FB_MEMSET,
    TZ_VDEC_FB_FLUSHMUTILINE,
    TZ_VDEC_FB_HALFLUSH,
    TZ_VDEC_FB_GETVALUE,
    TZ_VDEC_FB_SETVALUE
} ENUM_VDEC_TO_TZ_FB_OPERATION_T;
/* this struct must match with TZ_VDEC_FB_OPERATION_T in tz.h */
typedef struct
{
    ENUM_VDEC_TO_TZ_FB_OPERATION_T eOperation;
    UINT32 u4SrcAddr;
    UINT32 u4DesAddr;
    UINT32 u4Size;
    UINT32 u4Value;
} VDEC_TO_TZ_FB_OPERATION_T;
typedef struct
{
    void* pvYAddr;
    void* pvCAddr;
    UINT8 u1QuincunxCnt;
    BOOL bIsCur2D;
    UINT32 u4W;
    UINT32 u4H;
    UINT32 u4W_Cmp;
    UINT32 u4H_Cmp;
    UINT32 u4UnqualifiedCnt;
} VDEC_TO_TZ_DISP_PIC_INFO_T;

typedef enum
{
    TZ_E_VDEC_OK,
    TZ_E_VDEC_FAIL,
    TZ_E_VDEC_NOT_READY,
    TZ_E_VDEC_NOT_SUPPORT,
    TZ_E_VDEC_SKIPFRAME,
    TZ_E_VDEC_MAX
} ENUM_TZ_VDEC_PARSE_RET_T;

//!!!keep this aligned with the one in tz.h
typedef enum
{
    TZ_VDEC_PARSE_TYPE_UNKNOWN,
    TZ_VDEC_PRE_PARSE,
    TZ_VDEC_VP9_TILE_PARSE,
    TZ_VDEC_VP9_SUPER_FRAME_PARSE,
    TZ_VDEC_VP9_TILE_BUFFER_WRITE,
    TZ_VDEC_H264_MVC_HEADER_PARSE,
    TZ_VDEC_MPEG4_HEADER_PARSE,
    TZ_VDEC_WMV_HEADER_PARSE,
    TZ_VDEC_H264_WRITE_ERR_MAP,
    TZ_VDEC_DV_INFO_PARSE,
    TZ_VDEC_VP9_SEG_MEMSET
} ENUM_TZ_VDEC_PARSE_TYPE_T;

//!!!keep it aligned with the one in tz.h
typedef struct
{
    UCHAR   ucInstID;
    UCHAR   ucParseType;
    UINT32  u4InputStart;  //--> es vld readptr
    UINT32  u4InputEnd;  //--> es vld readptr end
    UINT32  u4FifoStart;
    UINT32  u4FifoEnd;
    UCHAR   ucPicType;  //--> nal type from pes.picType
    UCHAR   ucFmt;
    UINT32  u4KnownWidth;
    UINT32  u4KnownHeight;
    UINT32  u4Width;
    UINT32  u4Height;
    UINT32  u4FrameRate;
    UINT32  u4BitDepth;
    BOOL    fgProgressive;
    BOOL    fgPlayIFrame;
    UCHAR   ucRetType;
    UINT32  u4FrameSize;
    BOOL    fgAnnexB;
    UINT32  u4Reserved1;
    UINT32  u4Reserved2;
    UINT32  u4Reserved3;
    UINT32  u4Reserved4;
} VDEC_TO_TZ_HEADER_PARSE_T;

typedef struct
{
    UINT32  u4DecErrNs;
    UCHAR u1EsId;
}VDEC_DECERR_CB_T;

typedef struct
{
    UINT32  u4BufferAddr;
    UINT32  u4Pts;
}VDEC_DECOPERAOUTPUT_CB_T;

typedef struct
{
    UINT32 u4CurHDR;
    UINT32 u4LastHDR;
}VDEC_HDR_CB_T;


typedef struct
{
    UINT32 u4Pts;
    UCHAR u1PicType;
    UCHAR u1EsId;
}VDEC_PICTYPE_CB_T;

typedef struct
{
    UINT32 u4Status;
    UCHAR u1EsId;
}VDEC_STATUS_CB_T;


typedef struct _VDEC_LOG_PIC_INFO_T
{
    INT32   i4ShowErrLevel;
    UINT32  u4LastErrCount;
    UINT64  u8DumpPicPTS;
    UINT64  u8DumpPicOffset;
    UINT64  u8DumpGroupPicStartPTS;
    UINT64  u8DumpGroupPicEndPTS;
    UINT64  u8DumpGroupPicStartOffset;
    UINT64  u8DumpGroupPicEndOffset;
    UINT32  u4DumpGroupPicAll;
    UINT64  u8DumpGroupVFifoStartPTS;
    UINT64  u8DumpGroupVFifoEndPTS;
    UINT64  u8DumpGroupVFifoStartOffset;
    UINT64  u8DumpGroupVFifoEndOffset;
    UINT32  u4DumpGroupVFifoAll;
    UINT32  u4PosixMem;
    UINT32  u4PosixMemSize;
    //HANDLE_T h_YFileHandle;
    //HANDLE_T h_CFileHandle;
    //HANDLE_T h_VFifoHandle[2];
    CHAR * pcFileName;
}VDEC_LOG_PIC_INFO_T;
//status mask
#define VDEC_DATA_ERROR  (0x1 << 0)
#define VDEC_PIC_DECODING_ERROR  (0x1 << 1)
#define VDEC_BUF_OVERFLOW  (0x1 << 2)
#define VDEC_BUF_UNDERFLOW  (0x1 << 3)
#define VDEC_FRM_DROP  (0x1 << 4)
#define VDEC_FRM_REPEAT  (0x1 << 5)

//Flags for op code
#define VDEC_OP_DISABLE_MPEG2    (0x1 << 0)
#define VDEC_OP_DISABLE_H264     (0x1 << 1)
#define VDEC_OP_DISABLE_MPEG4    (0x1 << 2)
#define VDEC_OP_DISABLE_VC1      (0x1 << 3)
#define VDEC_OP_DISABLE_MJPEG    (0x1 << 4)
#define VDEC_OP_DISABLE_RV       (0x1 << 5)
#define VDEC_OP_DISABLE_VP6      (0x1 << 6)
#define VDEC_OP_DISABLE_VP8      (0x1 << 7)

//Flags for decoding
#define DEC_FLG_2ND_FLD_PIC     (0x1 << 0)
#define DEC_FLG_WAIT_NEXT_I     (0x1 << 1)
#define DEC_FLAG_REDUCE_REF     (0x1 << 4)
#define DEC_FLAG_DBK            (0x1 << 5)
#define DEC_FLG_WAIT_AVC_RAP    (0x1 << 6)


#define SET_DECFLAG(prVdecEsInfo,arg)      (prVdecEsInfo->u4DecFlag |= (arg))
#define CLR_DECFLAG(prVdecEsInfo,arg)      (prVdecEsInfo->u4DecFlag &= (~(arg)))
#define TOGGLE_DECFLAG(prVdecEsInfo,arg)   (prVdecEsInfo->u4DecFlag ^= (arg))
#define IS_DECFLAG_SET(prVdecEsInfo,arg)   ((prVdecEsInfo->u4DecFlag & (arg)) > 0)
/**
*/
typedef void (*PFN_VDEC_SW_RST)(
    UCHAR ucMpvId,
    UCHAR ucEsId
);

/**
*/
typedef INT32 (*PFN_VDEC_HEADER_PARSE)(
    UCHAR ucMpvId,
    UCHAR ucEsId,
    VDEC_DECODER_HANDLE_T *prHandle
);

/**
*/
typedef INT32 (*PFN_VDEC_DEC_START)(
    UCHAR ucMpvId,
    UCHAR ucEsId,
    VDEC_DECODER_HANDLE_T *prHandle
);

/**
*/
typedef INT32 (*PFN_VDEC_DEC_FINISH)(
    UCHAR ucMpvId,
    UCHAR ucEsId,
    VDEC_DECODER_HANDLE_T *prHandle
);

/**
*/
typedef INT32 (*PFN_VDEC_DEC_FIN_BOT)(
    struct VDEC_WORKLET_T *prHandle
);

/**
*/
typedef void (*PFN_VDEC_DEC_DROP)(
    UCHAR ucEsId
);


/**
*/
typedef void (*PFN_VDEC_STOP)(
    UCHAR ucEsId,
    VDEC_DECODER_HANDLE_T *prHandle
);

/**
*/
typedef void (*PFN_VDEC_GET_PES_STRUCT)(
    UCHAR ucEsId,
    void **ppvPesInfo,
    VDEC_DECODER_HANDLE_T *prHandle
);

/** for emulation
*/
typedef void (*PFN_VDEC_GET_DISP_PIC)(
    UCHAR ucEsId,
    void* pvInfo,
    VDEC_DECODER_HANDLE_T *prHandle
);

typedef void (*PFN_VDEC_SET_PARAM)(
    UCHAR ucEsId,
    UINT32 u4Type, UPTR u4Param1, UPTR u4Param2, UPTR u4Param3,
    VDEC_DECODER_HANDLE_T *prHandle
);

typedef void (*PFN_VDEC_GET_PARAM)(
    UCHAR ucEsId,
    UINT32 u4Type, UINT32* u4Param1, UINT32* u4Param2, UINT32* u4Param3,
    VDEC_DECODER_HANDLE_T *prHandle
);

typedef void (*PFN_VDEC_UPD_RPTR)(
    UCHAR ucEsId
);

/*typedef void (*PFN_VDEC_EVENT_NOTIFY)(
    UINT32 u4Arg1,
    UINT32 u4Arg2,
    UINT32 u4Arg3,
    UINT32 u4Arg4
);*/

/**
*/
typedef BOOL (*PFN_VDEC_ES_FLW_CTRL)(
    UCHAR ucEsId,
    UCHAR* ucMpvId,
    INT8 i1EsBufStatus,
    UCHAR ucSkipMode,
    VDEC_DECODER_HANDLE_T *prHandle
);

typedef BOOL (*PFN_VDEC_WAIT_RANDOM_AP)(
    const void* prPesInfo
);

typedef UCHAR (*PFN_VDEC_HANDLE_OVERFLW)(
    UCHAR ucMpvId,
    UCHAR ucEsmQId,
    HANDLE_T hMutex,
    HANDLE_T hMsgQueue,
    const void* pvPesInfo
);

typedef void (*PFN_VDEC_DECERR_CB)
(
    VDEC_DECERR_CB_T* prDecErr
);

typedef void (*PFN_VDEC_DECHDR_CB)
(
    VDEC_HDR_CB_T* prHDRInfo
);

typedef void (*PFN_VDEC_STATUS_CB)
(
    VDEC_STATUS_CB_T* prStatus
);

/**Resource manager notify function.
*@param ucEsId                     ES id.
*@param ucCond                    Cond.
*@param pvData                    Data.
*/
typedef VOID (*PFN_VDEC_RM_CB)
(
    UCHAR ucEsId, VDEC_RM_COND_T eCond, void *pVData
);

typedef void (*PFN_VDEC_RENDER_PTS_CB)
(
    UINT32 u4Pts,
    UINT8 u1AttachedSrcId
);


typedef void (*PFN_VDEC_TRICK_PTS_CB)
(
    UINT8 u1SrcId,
    UINT32 u4Pts,
    BOOL fgAgain
);

typedef void (*PFN_VDEC_START_PTS)(
    UCHAR ucEsId,
    BOOL fgEnCalPTS,
    UINT32 u4Pts,
    UPTR u4PtsDiff,
    VDEC_DECODER_HANDLE_T *prHandle
);

typedef BOOL (*PFN_VDEC_IS_PIC)(
    UCHAR ucEsId,
    VDEC_PES_INFO_T *prPes
);

typedef void (*PFN_VDEC_FLUSH)(
    UCHAR ucEsId,
    BOOL fgIsDisp
);

typedef void (*PFN_VDEC_ISR)(
    UINT16 vldId
);

typedef void (*PFN_VDEC_CHK_SLOT_STATUS)(
    UCHAR ucEsId,
    void* prArg,
    VDEC_DECODER_HANDLE_T *prHandle
);

typedef struct _MPV_EXT_INFO_T
{
    UCHAR           aucUserDataBuf[VDEC_MAX_ES][MAX_USERDATA_SIZE];
    BOOL            fgUserData[VDEC_MAX_ES];
    BOOL            fgPesUserData[VDEC_MAX_ES];
    BOOL            fgAfd[VDEC_MAX_ES];
    //BOOL            fgSdUserDataFilter[VDEC_MAX_ES];
    //UINT32          u4FilterMask[VDEC_MAX_ES];
    UINT32          au4UserDataRptr[VDEC_MAX_ES];
    UINT32          au4UserDataWptr[VDEC_MAX_ES];
    PFN_MPV_AVDEC_CB   pfAVDecCb[VDEC_MAX_ES];
    PFN_MPV_USERDATA_CB   pfUserDataCb;

} MPV_EXT_INFO_T;

typedef enum
{
    DISP_IDX = 0,
    BS_TYPE,
    OUTPUT_DISP_ORDER,
    REPEAT_FRM,
    LOG_SIMU_PAT,
    WAIT_FB_TIME,
    AV_SYNC_INFO,
    TIME_PROFILE3,
    MM_PARAM,
    SEQ_HDR_INFO,
    RECORD_CRC,
    CRC_CHK,
    MM_PLAY_DTV,
    MM_PVR_PLAY_MODE,
    VDEC_DECODE_MODE,
    VDEC_DECODE_HW_RES,
    VDEC_UFO_MODE,
    VDEC_DUMP_FRM_No,
    VDEC_SLICE_QP,
    VDEC_CLK_SET,
    VDEC_SET_MIC_BUF,
    VDEC_GET_MIC_BUF_SIZE,
    VDEC_GET_WORKLET,
    VDEC_ALLOC_CODEC_PRIVATE,
    VDEC_FREE_CODEC_PRIVATE,
    VDEC_HW_PARAM,
    VDEC_GCE_PARAM
}VDEC_PARAM_T;

//-----------------------------------------------------------------------------
// Inter-file functions
//-----------------------------------------------------------------------------

EXTERN void _VDEC_SendCmd(UCHAR ucEsId, UINT32 u4Cmd);

/** Send Es Info.
*@param .
 */
EXTERN UCHAR VDEC_SendEs(const VDEC_PES_INFO_T* pvPesInfo);
EXTERN UINT32 VDEC_RTSendEsInterval(BOOL fgGet);
EXTERN BOOL VDEC_SetRptr(UCHAR ucEsId, UINT32 u4Rp, UPTR u4FrameAddr);
EXTERN VOID VDEC_SetWptr(UINT8 u1VdecId, UPTR u4Wptr);
EXTERN BOOL _VDEC_CkgenSel(UCHAR ucEsId, ENUM_VDEC_FMT_T eCurFMT, UINT32 u4App);
EXTERN BOOL _VDEC_SocPndSet(UCHAR ucVdecId, BOOL fgUfoOn, BOOL fgOn, BOOL isMcore);
EXTERN VOID _Vdec_ClearDPB(UCHAR ucEsId);

//-----------------------------------------------------------------------------
// Public functions
//-----------------------------------------------------------------------------

typedef struct
{
    UINT16                     u2_width;      /* horizontal_size_value */
    UINT16                     u2_height;     /* vertical_size_value */
    ENUM_VDEC_FRAME_RATE_T   e_frame_rate;   /* Frame Rate */
    VDEC_ASPECT_RATIO_T e_src_asp;      /* Display Aspect Ratio (DAR) */
    VDEC_ASP_USR_TYPE_T e_asp_usr_type; /* source or display asp */
    UINT16                     u2_asp_usr_h;
    UINT16                     u2_asp_usr_w;
    UINT32                      u4SequenceHeader;
    UINT16                      u2SequenceHeaderSize;
    BOOL                        b_chk_frmrate;
} VDEC_SEQUENCE_DATA_T;

typedef struct
{
    UINT16                   u2DataSize;
    UINT16                   u2_width;      /* horizontal_size_value */
    UINT16                   u2_height;     /* vertical_size_value */
    ENUM_VDEC_FRAME_RATE_T   e_frame_rate;   /* Frame Rate */
    VDEC_ASPECT_RATIO_T      e_src_asp;      /* Display Aspect Ratio (DAR) */
    VDEC_ASP_USR_TYPE_T      e_asp_usr_type; /* source or display asp */
    UINT16                   u2_asp_usr_h;
    UINT16                   u2_asp_usr_w;
    UINT32                   u4SequenceHeader;
    UINT16                   u2SequenceHeaderSize;
    BOOL                     b_chk_frmrate;
} ES_FILE_SEQ_DATA;

#if 1//def CC_VDEC_RM_SUPPORT
typedef enum{
    VLDM_COMB_NONE = 0,
    VLDM_COMB_CORE0_FIRST = 0x01,
    VLDM_COMB_CORE1_FIRST = 0x02,
    VLDM_COMB_USED_FIRST = 0x40,
    VLDM_COMB_USED_FIRST_CORE0_THEN = VLDM_COMB_USED_FIRST | VLDM_COMB_CORE0_FIRST,
    VLDM_COMB_USED_FIRST_CORE1_THEN = VLDM_COMB_USED_FIRST | VLDM_COMB_CORE1_FIRST,
}ENUM_VLDM_COMB_T;


typedef struct{
    //Decode performance related info
    CHAR*   acName;
    UINT32  u4FmtMsk;       //ENUM_VDEC_FMT_T codec mask
    UINT32  u4TimMsk;       // Fbg type mask  FBM_FBG_TYPE_1080HD

    //Decode
    UINT32 u4Core0Fps;     // Core 0 decode n frame per second
    UINT32 u4Core1Fps;     // Core 1 decode n frame per second
    UINT32 u4DCoreFps;     // Dual Core decode n frame per second
    UINT32 uc1stChoice;    // 1st Choice decode core: 0 or 1 or 2(dual core)
}VDEC_RMNGR_TIM_T;


typedef struct{
    BOOL   fgProgressive;
    BOOL   fg10Bit;
    ENUM_VDEC_FMT_T eFmt;
    UINT32 u4Priority;  //Es priority
    UINT32 u4FrmRatCod;
    UINT32 u4Width;
    UINT32 u4Height;
}VDEC_VLDM_INPUT_T;

typedef struct{
    UINT32  ucVLD0Percent;   //50: need 50 precent capacity to decode. 100: need whole to decode
    UINT32  ucVLD1Percent;
    UCHAR  aucConflictEsId[VDEC_MAX_ES-1];  //The conflict EsId, get by lower priority
    ENUM_VLDM_COMB_T  ucVLDComType;    //[1:0] ==> 0_0: none; 1_1: or;  2_2: and; 1_2: vld0 first; 2_1: vld1 first
    VDEC_RMNGR_TIM_T* ptVldP4Info;
}VDEC_VLDM_OUTPUT_T;
#endif

typedef enum
{
    VDEC_FBSTSTUS_NORMAL        = 0,            ///< normal type
    VDEC_FBSTSTUS_REPEAT_LAST   = (1 << 0),     ///<
    VDEC_FBSTSTUS_NOT_DISPLAY   = (1 << 1),     ///< YCbCr 420 block in three planar
    VDEC_FBSTSTUS_NOT_USED      = (1 << 2)     ///< for H.264 multi-slice
} VDEC_DISP_FRAME_STATUS;

typedef struct
{
    UINT64 u8Timestamp;
    UPTR u4BufAddr;
    UPTR u4BufAddrC;
    UINT32 u4BufSize;
    UINT32 u4BufWidth;
    UINT32 u4BufHeight;
    UINT32 u4Pitch;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4ParWidth;
    UINT32 u4ParHeight;
    UINT32 u4DarWidth;
    UINT32 u4DarHeight;
    UINT32 u4FrameBufferStatus; // no display, repeat...
    BOOL   fgEos;               // eos

    // crop info
    BOOL fgCropping;
    UINT32 u4CropX;
    UINT32 u4CropY;
    UINT32 u4CropWidth;
    UINT32 u4CropHeight;

} VDEC_DISP_FRAME_T;

//add for calculate bitrate
typedef struct {
    UINT32 u4PicSize[MAX_FRAME_RATE];
    UINT8    u1CurIdx;
    UINT32 u4FrameRate;
    UINT32 u4NonePicSize;
    BOOL fgValidData;
}BITRATE_INFO;

typedef enum {
    VDEC_STATE_UNKNOW,                    /*unknow status*/
    VDEC_STATE_INIT,                      /*vdec cfg*/
    VDEC_STATE_RECEIVING_ES,              /*trying recv es from msg queue*/
    VDEC_STATE_ES_RECEIVED,             /*es received from msg queue*/
    VDEC_STATE_PRE_PARSING,               /*pre parse start*/
    VDEC_STATE_PRE_PARSER_DONE,           /*pre parse finish*/
    VDEC_STATE_GETTING_WK,                /*getting lae buff from msg queue*/
    VDEC_STATE_WK_RECEIVED,               /*lae buffer received*/
    VDEC_STATE_LOCKING_VLD,               /*get vld lock*/
    VDEC_STATE_PARSING,                   /*header parse start*/
    VDEC_STATE_PARSER_DONE,               /*header parse finish*/
    VDEC_STATE_TRIGGER_DONE,              /*trigger decode*/
    VDEC_STATE_WAITTING_DECODE,           /*waitting HW decode done*/
    VDEC_STATE_ISR_RECEIVED,              /*received ISR,HW decode finish*/
    VDEC_STATE_DECODE_DONE,               /*decoded finish*/
    VDEC_STATE_DELIVERING_EOS,            /*delivering EOS start*/
    VDEC_STATE_EOS_DELIVER_DONE,          /*deliver EOS finish*/
    VDEC_STATE_RECV_CMD,                  /*try recv cmd*/
    VDEC_STATE_CMD_RECEIVED,              /*cmd received*/
    VDEC_STATE_CMD_PROCESSING,            /*cmd in processing*/
    VDEC_STATE_CMD_FINISH                 /*cmd process finished*/
}ENUM_VDEC_STATUS_TYPE;

typedef enum
{
    VDEC_DECODER_MODE_NORMAL,
    VDEC_DECODER_MODE_SECURE,
} ENUM_VDEC_DECODER_MODE;

struct _VDEC_DECODER_MEM_ITEM_T_
{
    UINT32 u4Id;
    UINT32 u4Size;
    UINT32 u4TargetDecoderSize;
    BOOL fgSecure;
    BOOL fgActive;
    VOID *pvMain;
    VOID *pvWorker;
    VOID *pvTargetDecoder;
    VOID *pvData;
};

struct _VDEC_DECODER_TYPE_T_
{
    CHAR acName[8];

    INT32 i4Codec;

    // decoder context, lax and worker
    union {
        UINT32 u4DecoderSize;
        UINT32 u4LocalDecoderSize;
    };

    // memory used by local and target
    // codec private
    UINT32 u4SharedDecoderSize;

    // memory used by target
    UINT32 u4TargetDecoderSize;

    VDEC_DECODER_HANDLE_T *(*pfnOpen)(UCHAR ucEsId, VDEC_DECODER_TYPE_T *prType, BOOL fgSecure);
    INT32 (*pfnInit)(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);
    VOID (*pfnDeInit)(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);
    INT32 (*pfnClose)(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);
};

struct _VDEC_DECODER_OPS_T_;

INT32 i4VDecSendPes(UCHAR ucEsId, const VDEC_PES_INFO_T *prPesInfo, HANDLE_T hMsgQ);
INT32 VdecHdrPreParse(UCHAR ucMpvId, UCHAR ucEsId, ENUM_VDEC_FMT_T eCurFMT);

BOOL fgVDecIsPesQueueEmpty(struct _VDEC_ES_INFO_T_ *prVdecEsInfo);
INT32 i4VDecQueuePes(const VDEC_PES_INFO_T *prPesInfo, struct _VDEC_ES_INFO_T_ *prVdecEsInfo);
INT32 i4VDecFlushPes(UCHAR ucEsId, const VDEC_PES_INFO_T *prPesInfo, HANDLE_T hMsgQ, struct _VDEC_ES_INFO_T_ *prVdecEsInfo);
VOID vVDecDrainPes(struct _VDEC_ES_INFO_T_ *prVdecEsInfo);
UINT32 u4VDecMPEGFrmMapFrameRate(UCHAR ucMPEGFrameRate);

INT32 i4VDecDVRegisterLayerProperty(VDEC_DV_LAYER_PROPERTY_T *prDVProperty);
INT32 i4VDecDVUnregisterLayerProperty(UINT32 i4CodecType);
VDEC_DV_LAYER_PROPERTY_T *prVDecDVGetLayerProperty(UINT32 i4CodecType);

struct _VDEC_DV_LAYER_PROPERTY_T_
{
    CHAR szName[32];
    UINT32 u4CodecType;

    BOOL (*pfnIsAud)(UINT32 u4NalType);
    BOOL (*pfnIsSlice)(UINT32 u4NalType);
    BOOL (*pfnIsIDR)(UINT32 u4NalType);
    BOOL (*pfnIsCRA)(UINT32 u4NalType);
    BOOL (*pfnIsNonIDRSlice)(UINT32 u4NalType);

    UINT64 (*pfnGetDPBOutputTime)(UINT32 u4NalType, VDEC_DECODER_HANDLE_T *prHandle);
    UINT32 (*pfnGetTimeScale)(VDEC_DECODER_HANDLE_T *prHandle);
    UINT32 (*pfnGetNumReorderFrame)(VDEC_DECODER_HANDLE_T *prHandle);
    UINT32 (*pfnGetNumUnitsInTick)(VDEC_DECODER_HANDLE_T *prHandle);

    VOID (*pfnInitHandle)(VDEC_DECODER_HANDLE_T *prHandle);
};

struct _VDEC_DECODER_OPS_T_
{
    VOID (*pfnGetPesInfo)(UCHAR ucEsId, VOID **ppvPesInfo, VDEC_DECODER_HANDLE_T *prHandle);

    VOID (*pfnGetParam)(UCHAR ucEsId, UINT32 u4Type, UINT32 *pu4Param1, UINT32 *pu4Param2, UINT32 *pu4Param3, VDEC_DECODER_HANDLE_T *prHandle);
    VOID (*pfnSetParam)(UCHAR ucEsId, UINT32 u4Type, UPTR u4Param1, UPTR u4Param2, UPTR u4Param3, VDEC_DECODER_HANDLE_T *prHandle);

    INT32 (*pfnHdrPsr)(UCHAR ucVdecId, UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);
    INT32 (*pfnDecStart)(UCHAR ucVdecId, UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);
    INT32 (*pfnDecFin)(UCHAR ucVdecId, UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);

    VOID (*pfnEos)(UCHAR ucEsId, VDEC_PES_INFO_T *prPesInfo, VDEC_DECODER_HANDLE_T *prHandle);

    VOID (*pfnStop)(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);

    VOID (*pfnFlush)(UCHAR ucEsId, BOOL fgDisp, VDEC_DECODER_HANDLE_T *prHandle);
    VOID (*pfnClearDPB)(UCHAR ucEsId, BOOL fgDisp, VDEC_DECODER_HANDLE_T *prHandle);
    VOID (*pfnReleaseDisplayQ)(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);

    VOID (*pfnStartPTS)(UCHAR ucEsId, BOOL fgEnCalPTS, UINT32 u4Pts, UPTR u4PtsDiff, VDEC_DECODER_HANDLE_T *prHandle);
    BOOL (*pfnIsPic)(UCHAR ucEsId, VDEC_PES_INFO_T *prPesInfo, VDEC_DECODER_HANDLE_T *prHandle);

    VOID (*pfnBumpingProcess)(UCHAR ucEsId, VOID *pvArg, VDEC_DECODER_HANDLE_T *prHandle);

    // msgQ policy
    INT32 (*pfnSendPes)(UCHAR ucEsId, HANDLE_T hMsgQ, const VDEC_PES_INFO_T *prPesInfo, VDEC_DECODER_HANDLE_T *prHandle);
    HANDLE_T (*pfnPickMsgQ)(UCHAR ucEsId, HANDLE_T hMsgQ, VDEC_DECODER_HANDLE_T *prHandle);

    BOOL (*pfnEsFlwCtrl)(UCHAR ucEsId, UCHAR *pucVldId, INT8 i1EsBufStatus, UCHAR ucSkipMode, VDEC_DECODER_HANDLE_T *prHandle);

    INT32 (*pfnPreParse)(UCHAR ucMpvId, UCHAR ucEsId);
};

struct _VDEC_DECODER_HANDLE_T_
{
    VDEC_DECODER_OPS_T *prOps;

    //union {
        VDEC_DECODER_HANDLE_T *prLax;
        VDEC_DECODER_HANDLE_T *prWorker;
    //}
    VDEC_DECODER_TYPE_T *prType;

    //VOID (*pfnClose)(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);

    //VDEC_DECODER_MEM_POOL_T *prMemPool;
    VDEC_DECODER_MEM_ITEM_T *prMemItem;
    //UINT32 u4MemId;

    // UINT32 u4HandleEos;
    VOID *pvData;

    VOID *pvTargetDecoder;

    UCHAR ucEsId;

    BOOL fgSecure;
    BOOL fgInitWorker;

    // main/sub?
    BOOL fgSub;
    // for worker thread
    BOOL fgWorker;
};

/// for secure mode

VOID vVDecForceDebugSecureMode(INT32 i4SecureMode);

BOOL fgVDecIsSecureMode(UCHAR ucEsId);

// for cli
VOID vVDecHalSetDebugLevel(INT32 i4Level);
INT32 i4VDecHalBypassSvp(BOOL fgBypass);
INT32 i4VDecHalSetSecureMode(BOOL fgEnable);
INT32 i4VDecHalGetSecureMode(VOID);

VOID vVDecSvpEnablePerfLog(BOOL fgEnable);

/// decoder type API

INT32 i4VDecRegisterDecoderType(INT32 i4Codec, VDEC_DECODER_TYPE_T *prType);
INT32 i4VDecUnregisterDecoderType(INT32 i4Codec);
VDEC_DECODER_TYPE_T *prVDecGetDecoderType(INT32 i4Codec);

/// decoder memory/handle API

VOID vVDecInitHandleOps(VDEC_DECODER_HANDLE_T *prHandle,
    VDEC_DECODER_OPS_T *prOps);

VOID vVDecQueryMemItem(VOID);

INT32 i4VDecInitDecoderMemPool(VOID);

INT32 i4VDecAllocMemItemHandle(UCHAR ucEsId, VDEC_DECODER_MEM_ITEM_T *prMemItem, UINT32 u4Id, UINT32 u4DecoderSize, UINT32 u4TargetDecoderSize, BOOL fgSecure);
VOID vVDecInitMemItemHandle(UCHAR ucEsId, VDEC_DECODER_MEM_ITEM_T *prMemItem, VDEC_DECODER_TYPE_T *prType, BOOL fgSub, BOOL fgSecure);

VDEC_DECODER_HANDLE_T *prVDecCreateDecoderHandle(UCHAR ucEsId, VDEC_DECODER_TYPE_T *prType, UINT32 u4Offset, BOOL fgSub, BOOL fgSecure);
INT32 i4VDecDestroyDecoderHandle(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);

VDEC_DECODER_HANDLE_T *prVDecOpenDecoderHandle(UCHAR ucEsId, ENUM_VDEC_FMT_T eFmt, BOOL fgSub, BOOL fgSecure);
VDEC_DECODER_HANDLE_T *prVDecInitDecoderWorkerHandle(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);
INT32 i4VDecCloseDecoderHandle(UCHAR ucEsId, VDEC_DECODER_HANDLE_T *prHandle);

typedef struct _DISPLAYQ_STATUS_T_
{
    UINT32 u4Display;
    UINT32 u4Drop;
} DISPLAYQ_STATUS_T;

typedef struct
{
    UINT32 u4RetrieveNs;
    UINT32 u4EsmSkipNs;
    UINT32 u4VpsrDropNs;
    UINT32 u4DecOkNs;
    UINT32 u4TimeOutNs;
} COUNTS_STATUS_T;

/**
 *    Input compressed image and output destination information.
 */
typedef struct _VDEC_ES_INFO_T_
{
    // one each esid
    /****a flag, when it is true, need to clear v msg Q, use _VDEC_FlushEs****/
    BOOL fgFlushEsmQ;
    /****only used for H.264, flush pictures in DPB****/
    BOOL fgFlushFB;
    /****used for 3D(VDEC_3D_MVC, VDEC_3D_REALD_DUAL_STREAM), left pic match right pic or not*****/
    BOOL fgMvcMismatch;
    BOOL fgIPSeamless;                         // only for ap display while use Interlace to show progressive.

    // comes from PesInfo
    /****dts is valid or not, when it is true, mpv will check the dts value to judge decode the frame or drop it****/
    BOOL fgDtsValid;
    /****it means the pes msg is a sequence header or not****/
    BOOL fgSeqHdr;
    /****only used for H.264****/
    BOOL fgSeqHdrH264;
    BOOL fgChgThrsd;
    BOOL fgSetDmxIntThrsd;
    BOOL fgCalDmxIntThrsd;
    BOOL fgCanDisp;
    //BOOL afgIntraSlice[0xAE];
    BOOL fgAllIntraSlice;
    BOOL fgBisOk;
    UINT32 u4NALUSizeErrThrsd;
    /*************************************
    *for pic display quickly after decoded when start to play
    *when it is false, should use current frame's pts update stc
    ****************************************/
    BOOL fgSetStartPts;
    BOOL fgRefNoDbk;
    BOOL fgIFrameDec;  // for mpeg2 MHEG5 only
    BOOL fgRefInfo;
    BOOL fgKeepPes;
    BOOL fgPlaybackNotDisplay;
    /****means current source is MM or DTV****/
    BOOL fgMMPlayback;
    BOOL fgMMSeqInfoValid;
    BOOL fgMMTPTSeqInfoValid;
    BOOL fgTricking;
    // for main and sub
    DISPLAYQ_STATUS_T rDisplayQStatus[2];
    /**********************************************************
    *a special case, after decode one frame, decoder should pause itself when the flag is true
    *mainly used for swdmx_mpg(ps/ts/video es)
    ************************************************************/
    BOOL fgPlayOneFrm;
    BOOL fgPlayIFrame;
    BOOL fgRenderFromFirstPic; // trick/seek used.
    BOOL fgRenderPicCntOrPts;   // digest used.
    /****work with u8RenderFromPos, if the pic offset < u8RenderFromPos, should not display****/
    BOOL fgRenderFromPos;  // trick 2x up -> 1x.
    BOOL fgRenderPts;
    BOOL fgRenderBackStep;
    BOOL fgRenderFromPts;
    BOOL fgRenderLastFrame;
    /****only used for MM, means decoder send eos(comes from swdmx) to b2r or not****/
    BOOL fgSendedEos;
    BOOL fgBigBForceEnable;
    BOOL fgOnlyGotSeqHeader;
    BOOL fgDetectIntra;
    BOOL fgIsTPT;
    BOOL fgSpeedChg;
#ifdef CC_IPTV_SUPPORT
    BOOL fgDropDecodeTimeoutFrm;//HISENSE &CHANGHONG IPTV
#endif
    BOOL fgIsMVCPtsCmp;
    //mpeg2
    BOOL fgLowDelay;
    BOOL fgContrained;
    BOOL fgMPEG2; // mpeg1 or mpeg2
    BOOL fgSeqDispExt;
    BOOL fgSuperFreeze;
    BOOL fgNormalAfterFreeze;
    BOOL fgRsvSps;
    BOOL fgRsvSpsMvc;
    BOOL fgRsvData;
    //~mpeg2
    BOOL fgDeblocking;
    BOOL fgSeamlessPlay;
    BOOL fgRetry;
    BOOL fgIsReDec;
    BOOL fgMoreData; //for av1,one pes has more frames case

    BOOL fgPrintOutput;
    BOOL fgPrintReceiveEs;

    BOOL fgEnableUFO;
    BOOL fgLAEBufAllocated;
    BOOL fgParseredFromInput;  //For hdr parsered from swdmx,last memory on

    UCHAR ucDropBNs;
    /****I/P/B****/
    UCHAR ucPicType;
    UCHAR ucFbgId;
    UCHAR ucSubFbgId;
    UCHAR ucFbId;
    UCHAR ucSubFbId;
    BOOL fgExtraData;
    BOOL fgSubExtraData;
    UCHAR ucSyncMode;
    UCHAR ucStcId;
    UCHAR ucDbkRefId;
    UCHAR ucDbkFbId;
    UCHAR ucSequenceHdrFound;
    UCHAR ucVideoFmt;
    //mpeg2
    UCHAR ucProfileId;
    UCHAR ucLevelId;
    UCHAR ucPicTypeLast;
    UCHAR ucUnsupportProLvlCnt;
    //~mpeg2
    UCHAR ucPriority;  //Es priority
    UINT8 u1PVRWaitSps;
    VDEC_STREAM_TYPE_T eStreamType;
    UINT8 u1LastSkipType;
    UINT16 u2Count;
    UINT16 u2CountMvc;
    UINT16 u2UdfNs;
    UINT16 u2DecodingOrder;
    //UINT16 u2TempRef;
    UINT16 u2RenderDecodingOrder;
    UINT16 u2Disp2EmptyCnt;

    /****the patch size, a pic line should used, must not smaller than the width of the pic****/
    UINT16 u2LineSize;                              // horizontal line size, due to block color mode
    UINT16 u2HSize;                                 // horizontal size value to dispaly
    UINT16 u2VSize;                                 // vertical size value to display
    UINT16 u2DHS;                                 // display_horizontal_size in Sequence display extension
    UINT16 u2DVS;                                 // display_vertical_size in Sequence display extension
    UINT16 u2OrgHSize;                              // original horizontal size value in Sequence Header
    UINT16 u2OrgVSize;                              // original vertical size value in Sequence Header

    UINT16 u2SubOrgHSize;                              // original horizontal size value in Sequence Header
    UINT16 u2SubOrgVSize;                              // original vertical size value in Sequence Header

    BOOL fg10Bit;  // for bit depth change
    BOOL fgSub10Bit;

    UINT8 u1Fps;

    UINT32 u4PrevOutputFbTime;
    UINT32 u4GetFbTime;
    UINT32 u4VdecLogOutput;

    INT32 i4RenderTempRef;

    //UINT32 u4EsId;
    UINT32 u4VldId;   //The connect 1st
    UINT32 u4Vld2Id;  //The connect 2nd
    UINT32 u4LaxId;  //The connect 2nd
    UINT32 u4Lax2Id;  //The connect 2nd
    INT32   i4WorkerPid;
    UINT32 u4NextVldMsk;  //ptVldP4Info
   /*cli control vld/ufo */
    UINT32 u4VldIdUsage;
    UINT32 u4UfoForceOn;
    UINT32 u4JumpForceOn;
    UINT32 u4MlatForceOn;
    BOOL   fgForceSupport4k120;
    BOOL   fgForceAvcOutputOldWay;
    BOOL   fgForceThumbOldWay;

    UINT32 u4FifoStart;
    UINT32 u4FifoEnd;
    UINT32 u4VldReadPtr;
    UINT32 u4VldReadPtrEnd;
    UINT32 u4GopLength;
    /****the pts of current frame****/
    UINT64 u4PTS;
    UINT64 u4PTSLast;
    UINT64 u4PTSLastNoneZero;
    /****the DTS of current frame****/
    UINT32 u4DTS;
    // will update pts with this delta PTS after receiving pesinfo
    INT32 i4DeltaPts;
    UINT32 u4LastVldRptr;
    UINT32 u4DmxIntThrsd;
    UINT32 u4TotalPicSize;
    UINT32 u4AvgPicSize;
    UINT32 u4PicCnt;
    UINT32 u4DecFlag;
    UINT32 u4DropDecFlag;
    UINT32 u4WaitP;
    UINT32 u4DecReadPtr;
    UINT32 u4WaitDispTime;
    UINT32 u4MaxEsCnt;
    UINT32 u4FailCnt;
    UINT32 u4FbgFailCnt;
    UINT32 u4NsAtTimeout;
    UINT32 u4NsAtThumbTimeout;
    UINT32 u4FrameRate;
    UINT32 u4LastFrameRate;
    BOOL   fgNotDynamicFrameRate;
    UINT32 u4VdecDelayTime;
    /****the playing speed, only for MM****/
    UINT32 u4MMSpeed;
    UINT64 u4RenderPts;
    UINT32 u4RenderPicCnt;
    UINT32 u4DisplayQPicCnt;
    UINT64 u4FirstDispPTS;
    UINT64 u4RenderFromPts;
    /****only for MM, the total time of the MM file****/
    UINT32 u4TotalTime;
    UINT32 u4TotlaTimeOffset;
    UINT32 u4TickNum;

    UINT32 u4IpFrameNum;       //record I/P frame Num for notify I/P frame cc data to mw
    UINT32 u4BigBLevel1;
    UINT32 u4BigBLevel2;
    UINT32 u4BigBLevel3;
    UINT32 u4BigBBaseCnt;

    UINT32 u4Dbk1PixelCnt;
    UINT32 u4Dbk2PixelCnt;
    UINT32 u4Dbk3PixelCnt;
    UINT32 u4SeamlessWidth;
    UINT32 u4SeamlessHeight;
    UINT32 u4FBGWidth;
    UINT32 u4FBGHeight;
    UINT32 u4H264IdcInfo;

    //mpeg2
    UINT32 u4VbvSizeExt;
    //~mpeg2
    UINT32 u4Timestap;
    /****work with fgRenderFromPos, if the pic offset < u8RenderFromPos, should not display****/
    UINT64 u8RenderFromPos;
    UINT64 u8Offset;
    UINT64 u8OffsetLast;
    UINT64 u8OffsetI;
    UINT64 u8FileSize;
    UINT64 u8LatestPTS;
    UINT64 u8PTSInUs;
    UINT64 u8PTSLast;

    VDEC_PIC_EXTRA_INFO_T rExtra;
    VDEC_SEQUENCE_DATA_T rMMSeqInfo;
    VDEC_SEQUENCE_DATA_T rMMTPTSeqInfo;
    VDEC_RMNGR_TIM_T* ptVldP4Info;

    // Should be name to VDEC instead of MPV
    // change it when 264 use it?
    MPV_AVDEC_STATUS_T rAVDecStatus;
    VDEC_DEC_DECODE_STATUS_T eNotifyStatus;
    VDEC_AB_INTO_T rABInfo;

    VDEC_DECODE_MODE_T eDecodeMode;
    ENUM_VDEC_VLD_MODE eVldMode;
    BOOL fgWorkletNotUsed;

    COUNTS_STATUS_T rVdecCounter;// PARAM_MPV_T

#ifdef MPV_REPEAT_TEST
    BOOL fgParseOnRepeat;
#endif
    //for slt
    UCHAR fgCountPicNs;
    UCHAR fgCountPicFinish;
    UINT32 u4StartPts;
    UINT32 u4EndPts;
    UINT32 u4PicNs;

    //for video digest thumbnail
    UINT16 u2CompId;
    VDP_THUMBNAIL_INFO_T rCapDstInfo;
    VDP_CAPTURE_INTO_T rCapSrcInfo;
    UPTR     u4WorkingBufAddr;
    UINT32 u4WorkingBufSize;
    UINT32 u4ThumbRetrieveNs;
    BOOL bIsOnePass;
    BOOL fgKeepRation;  //keep the ration of frame org Hsize/Vsize
    BOOL fgThumbMethod2;     //use thumbnail2, get thumbnail runtime
    BOOL fgThumbStartTime;   //use thumbnail2, record the start time
    BOOL fgSensio3D;//sensio format

    //mm start PTS
    BOOL fgEnCalPTS;
    BOOL fgSwdmxSendEosDone;
    BOOL fgMpvNoFlush;
    BOOL fgProgressive;         // def CC_SUPPORT_VDEC_PREPARSE: save I/P for preparser
    // for CC_VDEC_RM_SUPPORT
    BOOL  fgIsVDPRender;        //Use VDP render or not
    BOOL  fgTextureMode;        //CC_INPUTSOURCE_VIDEO_ON_TEXTURE
    UINT32 u4BlockAsNoResource;  //Block as no resource to decode.

    // ratio for dual layer case
    // rm use this ratio to calculate framerate (1:1 or 4:1 ...)
    UINT32 u4RmRatioX;
    UINT32 u4RmRatioY;

    INT64  i8BandWidth;
    UCHAR ucImgrzId;            //Imgrz ID for imgrz seamless
    UINT32 u4RenderVDPId;            //Imgrz ID for imgrz seamless
    UINT64 u4StartPTS;
    UPTR u4VFifoPrevWptr;
    VDEC_PTS_INFO_T rPTSInfo;

    // auto pause after "PlayUntilPTS" (for Adobe)
    BOOL fgAutoPause;

    //pass DivX4 info to vdec.
    BOOL fgSetDivX4;
    //pass XVID info to vdec.
    BOOL fgXVID;

    //Container Type
#ifdef ENABLE_MULTIMEDIA
    ENUM_SWDMX_FMT_T eContainerType;
    SWDMX_SOURCE_TYPE_T eMMSrcType;
    // for CC_VDEC_RV_DISABLE
    //rv RPR info
    BOOL   fgRV9;
    UINT32 u4SzOfPicSz;
    UINT32 au4RPRSizes[2 * RV_MAX_NUM_RPR_SIZES];

#endif
    UINT8 arRcvPesCnt[VDEC_FMT_MAX];

    UINT8 u1SwdmxSrcId;            ///< swdmxsrc ID for supporting multiple instances

    INT16 i2VdecThreadPriority;                    //record thread priority
    INT16 i2VdecThreadWorkingCycles;                //record thread working cycles

//for CC_REALD_3D_SUPPORT
    BOOL fgIsRealD3DFmt;
    UINT8 u13DUsrCtrlMode;
    UINT8 u13DUsrCtrlModeNtfy;
    BOOL fgIsSimpleFilterType;
    UINT32 u43DInOut;
    E_TDTV_DECODER_INPUT eDetectedMode;
    UINT8 u1IsForceLView;
    UINT8 u1IsForceLViewNtfy;
    BOOL fgB2rResLimitation;

    VDEC_3D_TYPE_T e3DType;
    VDEC_3D_FORCE2D_TYPE_T e3DForce2DType;  // off, 0: Left, 1: Right
    UINT32 u43DSkipDuration;
    BOOL fgIs3DHalfWidth;
    BOOL fgIs3DHalfHeight;
    BOOL fgIsDependView;
    UINT64 u4BasePTS;
    UINT64 u4LatestPTS;
    UINT8 u13DTrickModeType;

    HAL_TIME_T rThumbStartTime;   //use thumbnail2, record the start time

    HAL_TIME_T rPlayStartTime;   //use thumbnail2, record the start time
    HAL_TIME_T rPlayEndTime;   //use thumbnail2, record the start time

    HAL_TIME_T rLatStartTime;   //use thumbnail2, record the start time
    HAL_TIME_T rLatEndTime;   //use thumbnail2, record the start time


    UINT32 u4CoreTotalProcTime;
    UINT32 u4LatTotalTime;

    UINT32 u4LatWaitWorkletTotalTime;

    UINT32 DecodePicCnt;
    UINT32 DecodeLatPicCnt;

    UINT32 DecodeTotalRegCnt;


    UINT32 u4PesRecvTimeTotal;

    UINT32 u4HWDecodeTimeTotal;
    UINT32 u4LatHWDecodeTimeTotal;


    BOOL  fgRVUSkip;
    BOOL  fgRVUSkipOut;
    UCHAR ucRVUSkipMode;

    //Calculate bitrate
    BOOL fgCalEachPicSize;
    UINT32 u4CurrPicSize;
    UINT32 u4StatisticPicSize;
    BITRATE_INFO rBitRateInfo;

    //JPEG related
    BOOL fgIsThumbnail;     // 0: full image, 1: thumbnail
    BOOL fgNotClearBuffer;
    UINT32 u4OutputPicW;    // only for thumbnail, output width
    UINT32 u4OutputPicH;    // only for thumbnail, output height
    UINT32 u4RotationDegree;  // 0, 90, 180, 270
    UINT32 u4Imagefilesize;
    //end JPEG related

    //H264 PVR related
    BOOL fgSPSValid;
    BOOL fgVUIValid;
    BOOL fgSEIValid;
    BOOL fgSPSFrameMbsOnlyFlag;
    UINT32 u4VUITimeScale;
    UINT32 u4VUINumUnitsInTick;
    UINT8 u1SEIPicStruct;
    UINT32 u4OutputWidthFor360Video;
    UINT32 u4OutputHeightFor360Video;
    UINT32 u4OutputModeFor360Video;
    //end H264 PVR related
    //MPEG2 PVR related
    BOOL fgSeqValid;
    UINT16 u2SeqFrmRate;
    //end MPEG2 PVR related
    // Error Report
    BOOL fgDecodeErr;
    VDEC_3D_RESOLUTION_TYPE_T e3DResType;
    //IPTV
    BOOL fgIPTVPlayback;
    //resize display frame, for encoder flow
    BOOL fgResizeDispFrm;
    UCHAR ucRzId;

    BOOL fgPvrPlayBack;
    UINT8 u1PvrPlayMode;
    //bitstream info
    ENUM_VDEC_PROFILE_T eProfile;
    ENUM_VDEC_LEVEL_T eLevel;
    UINT32 u4BitDepth;

    // enabled sub?
    BOOL fgEnableSub;

    // Dolby Vision information
    BOOL fgReorderRPUWithEnhancementLayer;
    BOOL fgSingleTrack;
    UINT32 u4DVProfile;
    UINT32 u4LayerPresentFlag;
    // only for vpush
    UINT32 u4DVContainer;

    UINT32 eSeamlessMode;
    UCHAR ucLaeEsInfoId;
    UCHAR ucLaeId;
    BOOL fgSetTargetRdptr;
    UINT32 u4TargetRdptr;
    BOOL fgProgressiveSeq;
    UINT32 u4Bitrate;
    BOOL fgIsGameMode;
    ENUM_VDEC_STATUS_TYPE VdecDecodeStatus;
    ENUM_VDEC_STATUS_TYPE VdecDecodeStatus_Worker;

    ENUM_VDEC_STATUS_TYPE VdecDecodeStatus_LatBot;
    ENUM_VDEC_STATUS_TYPE VdecDecodeStatus_CoreBot;
    UINT32 u4HDRContent;
    UINT32 u4VUIHDRContent;
    UINT32 u4SEIHDRContent;
    UINT32 u4LastHDRContent;
    BOOL fgSeamlessReCreate;
    BOOL fgLogoFlw;//for showlogo flow, main thread use this to alloc imgrz id.
    BOOL fgIsSet3DInfo;
    VDEC_HDRSRC_PROFILE_T VdecHdrInfo;
    UINT32 u4PowerOnTriggerEvents;
    BOOL bHeif;
    BOOL bHeifGrid;
    UCHAR HeifGridCols;
    UCHAR HeifGridRows;
    UINT32 u4SubIdx;

    // LAT
    VDEC_DECODER_HANDLE_T *prHandle;

    BOOL fgSet3DInfo;
    BOOL fgLastSet3DInfo;
    BOOL fgLastApset3Dinfo;

    BOOL fgDynamicDash;
    BOOL fgDynamicFpsCal;


#define VDEC_MAX_PES_BUF_CNT 32
    BOOL fgKeepRPU;
    UINT32 u4PesBufCnt;
    VDEC_PES_INFO_T arPesBuffer[VDEC_MAX_PES_BUF_CNT];
    BOOL fgSecureBuf;
    BOOL fgDropWorklet;
    BOOL fgRapParsed;
    BOOL fgIsDolbyMELMode;

    BOOL fgAsyncMode;
    BOOL fgEnableDumpInput;
    BOOL fgBeginDump;
    UCHAR ucParseMode;
    BOOL fgIsVpeek;
} VDEC_ES_INFO_T;

/**
 *    Input compressed image and output destination information.
 */
typedef struct
{
    HANDLE_T hCmdQ;
    HANDLE_T hMsgQ;
    HANDLE_T hMwFbmOutMsgQ;
    //#if defined(CC_MVC_SUPPORT) && !defined(CC_VDEC_MVC_DISABLE)
    HANDLE_T hMsgQSub;
    //#endif
    HANDLE_T hCacheMsgQ;
    HANDLE_T hWorkerMsgQ;
    HANDLE_T hRecycleMsgQ;
    //HANDLE_T hGceMsgQ;
    HANDLE_T hVdecCmdHwSema;
    HANDLE_T hWorkerThread;
    HANDLE_T hFlushMutex;         // lock for fgFlushEsmQ variable
    HANDLE_T hFlushSema;         //  lock for cli??
    HANDLE_T hReplaySema;         //  lock for cli??
    HANDLE_T hUBESema;         //  lock for cli??
    HANDLE_T hCcSema;
    HANDLE_T hWaitKickSema;
    HANDLE_T hWorkerQSema;
    HANDLE_T hLatHwResSema;
    HANDLE_T hDataTimer;        // timer to keep watching input data
    HANDLE_T hCodecChkTimer;        // timer to check if codec type error

    HANDLE_T hVdecSetPriSema;        // multi instance, protection  when load thread working cycles
    HANDLE_T hVdecScheMsg;           //multi instance to schedule thread
    //for CC_REALD_3D_SUPPORT
    HANDLE_T hVdec3DModeChange;

    HANDLE_T hControlBotThread;
    HANDLE_T hWorkerBotThread;
    HANDLE_T hControlBotTMsgQ;
    HANDLE_T hWorkerBotTMsgQ;


    BOOL fgThreadActive;
    BOOL fgDmxPartialPes;
    BOOL fgTimerStarted;
    BOOL fgCodecTypeChecking;
    BOOL fgVdecMidEnable;
    BOOL fgMidDBKDisable;
    BOOL fgVPush;
    BOOL fgLowLatency;
    BOOL fgVPushDecodeOnly; // output to OSD plane, we does not use b2r output
    BOOL fgPatternMode;
    BOOL fgLaxStopSync;
    BOOL fgRmReqImgrz;

    UINT8 u1FbmMidMode;
    UINT32 u4AvSyncCnt;
    UINT32 u4Ycrc[4];
    UINT32 u4Ccrc[4];
    VDEC_PUSH_MODE_T eVPushPlayMode;       // vpush play mode

    VDEC_VLD_STATUS_T arThreadStatus[VDEC_MAX_VLD];    //record the status of vld --->VDEC_VLD_STATUS;    //record the status of vld --->VDEC_VLD_STATUS
    void*           pvDecNfyTag;
    PFN_VDEC_DEC_NFY_FCT pfDecNfyFct;
    UCHAR           ucSyncMode;
    UCHAR           ucStcId;
    INT16           i2DBKAdjust; // -29 ~ + 29
    UINT16          u2DBKLevel;  // 0~100

    UINT32          u4DBKValue;  //for MPEG deblocking, P1~P4

     // comes from rVdecInfo
    UINT8 u1AttachedSrcId;

    BOOL fgWaitIFrame;
    BOOL fgFrameToUser;   //decoder frame send to user
    UINT32 u4CurStopId;
    UINT32 u4PreviousStopId;

    //chroma simple position info
    BOOL fgChromaLocationInfoPresentFlag;
    UINT32 u4ChromaFormatIdc;
    UINT32 u4ChromaSampleLocTypeTopField;
    UINT32 u4ChromaSampleLocTypeBottomField;
    UINT32 u4TimeoutCnt;
    UINT32 u4PreparseRcvCnt;
    UINT64 u4EsPTS[17];
    ENUM_VDEC_STATE_T eCurState;
    ENUM_VDEC_STATE_T ePreviousState; // to prevent stop twice
    ENUM_VDEC_DEC_STATE_T eDecStatus;
    ENUM_VDEC_FMT_T eCurFMT;

    VDEC_PES_INFO_T rPesInfo;
    FBM_POOL_LAT_T rLaxPool;
    FBM_POOL_LAT_T rLaxPool1;
    UPTR u4LaxVAddr;
    struct VDEC_WORKLET_T* prCurWorklet;

    VOID *pvCodecPrivate;

    UINT32 u4Priority;
    PFN_VDEC_SW_RST pfnVdecSWRst;
    PFN_VDEC_HEADER_PARSE pfnVdecHdrParse;
    PFN_VDEC_DEC_START pfnVdecDecStart;
    PFN_VDEC_DEC_FINISH pfnVdecDecFin;
    PFN_VDEC_DEC_FIN_BOT pfnVdecDecFinBot;
    PFN_VDEC_DEC_DROP pfnVdecDecDrop;
    PFN_VDEC_STOP pfnVdecStop;
    PFN_VDEC_GET_PES_STRUCT pfnVdecGetPesStruct;
    PFN_VDEC_SET_PARAM pfnVdecSetParam;
    PFN_VDEC_GET_PARAM pfnVdecGetParam;
    PFN_VDEC_ES_FLW_CTRL pfnVdecEsFlwCtrl;
    PFN_VDEC_WAIT_RANDOM_AP pfnVdecWaitRandomAP;
    PFN_VDEC_START_PTS pfnVdecStartPts;
    PFN_VDEC_IS_PIC pfnVdecIsPic;
    PFN_VDEC_RENDER_PTS_CB pfnRenderPtsCb;
    PFN_VDEC_TRICK_PTS_CB pfnTrickPtsCb;
    PFN_VDEC_CHK_SLOT_STATUS pfnChkSlotStatus;
    // ~comes
    struct VDEC_WORKLET_T *rTmpWorkletWorker;
    struct VDEC_WORKLET_T *rTmpWorkletLax[LAX_MSG_RECYCLE];
    struct VDEC_LAX_BUF_INFO_T *rUBEInfo;
    BOOL fgSerialDec; // for debug
    BOOL fgGCEMode;
} VDEC_ES_INFO_KEEP_T;

typedef struct
{
    UINT32  u4Pts;
    UPTR  u4BufYaddr;
    UPTR  u4BufCaddr;
    BOOL  fgEos;
}VDEC_OPERA_OUTPUT_T;

typedef void (*PFN_VDEC_OPERA_OUTPUT_NFY_FCT) (
    UINT32              u4BufferAddr
);

typedef struct
{
    UCHAR ucConnTmpEsId;
        //Multi Core
    UINT32 u4ConnEsIdMask;
    UINT32  au1EsLoading[VDEC_MAX_ES]; //Record each Es occupy the VLD loading percent
    UINT32  u1TotalLoading;            //VLD all loading
}VDEC_RM_LOADING_INFO_T;

typedef struct
{
    BOOL fgPowerOn;
    UINT32 u4PowerOnRef;
    HANDLE_T hVldSemaphore;
// for debug
    BOOL fgSwrst;
    UCHAR ucLockEsId;
    UINT32 u4LockCount;
    PFN_VDEC_ISR pfnVdecIsr;
} VDEC_VLD_INFO_T;

typedef struct
{
    VDEC_ES_INFO_T arVdecEsInfo[VDEC_MAX_ES];
    VDEC_ES_INFO_KEEP_T arVdecEsInfoKeep[VDEC_MAX_ES]; // we don't reset this variable
    VDEC_VLD_INFO_T arVdecVldInfo[VDEC_MAX_VLD];
    VDEC_RM_LOADING_INFO_T arRmLoadingInfo[VDEC_MAX_VLD];
    HANDLE_T hVldInfoSemaphore;  //Sema for VLD info protect.

    // VDEC
    volatile BOOL fgVDecInitiated;
    UINT8 uLastEsId;
    UINT32 u4OpCode;

/*
    BOOL fgWaitIFrame;

    UINT32 u4CurStopId;
    UINT32 u4PreviousStopId;

    ENUM_VDEC_STATE_T eCurState;
    ENUM_VDEC_STATE_T ePreviousState; // to prevent stop twice
    ENUM_VDEC_DEC_STATE_T eDecStatus;
    ENUM_VDEC_FMT_T eCurFMT;

    //UINT32 u4DataSize;
    VDEC_PES_INFO_T rPesInfo;
*/

    PFN_VDEC_EVENT_NOTIFY pfErrNotify;

/*
    PFN_VDEC_SW_RST pfnVdecSWRst;
    PFN_VDEC_HEADER_PARSE pfnVdecHdrParse;
    PFN_VDEC_DEC_START pfnVdecDecStart;
    PFN_VDEC_DEC_FINISH pfnVdecDecFin;
    PFN_VDEC_DEC_DROP pfnVdecDecDrop;
    PFN_VDEC_STOP pfnVdecStop;
    PFN_VDEC_GET_PES_STRUCT pfnVdecGetPesStruct;
    PFN_VDEC_SET_PARAM pfnVdecSetParam;
    PFN_VDEC_GET_PARAM pfnVdecGetParam;
    PFN_VDEC_ES_FLW_CTRL pfnVdecEsFlwCtrl;
    PFN_VDEC_WAIT_RANDOM_AP pfnVdecWaitRandomAP;
    PFN_VDEC_START_PTS pfnVdecStartPts;
*/

    UINT32 u4ErrDuration;
    PFN_VDEC_DECERR_CB pfnDecErrCb;
    PFN_VDEC_STATUS_CB pfnStatusCb;

    PFN_VDEC_RM_CB pfnRmCb;
    PFN_VDEC_HDR_NFY_FCT pfHDRInfoCb;
    PFN_VDEC_OPERA_OUTPUT_NFY_FCT pfnOperaOutCb;
/*
    PFN_VDEC_RENDER_PTS_CB pfnRenderPtsCb;
    PFN_VDEC_TRICK_PTS_CB pfnTrickPtsCb;
*/
} VDEC_INFO_T;

typedef struct _VDEC_GCE_CMDQ_MSG_{
    UCHAR ucInstId;
    UCHAR CmdqIdx;
}VdecGceCmdqMsg;

#define IS_WORKER_OF(EsId) (_VDEC_GetEsInfo(EsId)->i4WorkerPid == current->pid)
EXTERN BOOL VDEC_RegOperaOutputCb(PFN_VDEC_OPERA_OUTPUT_NFY_FCT pfnOperaOutCb);
EXTERN VOID _Vdec_OperaOutputNotify(UCHAR ucEsId, VOID *pPicNfyInfo);
EXTERN VDEC_ES_INFO_T* _VDEC_GetEsInfo(UCHAR ucEsId);
EXTERN VDEC_ES_INFO_KEEP_T* _VDEC_GetEsInfoKeep(UCHAR ucEsId);
EXTERN BOOL _VDEC_GetVdecUBEValue(UCHAR ucEsId);
EXTERN BOOL _VDEC_SetVdecUBEValue(UCHAR ucEsId, BOOL fgUBEStatus);
EXTERN BOOL _VDEC_SetVdecHeifValue(UCHAR ucEsId, UCHAR ucRowCnt, UCHAR ucColCnt);
EXTERN BOOL _VDEC_GetVdecAsyncModeValue(UCHAR ucEsId);
EXTERN BOOL _VDEC_SetVdecAsyncModeValue(UCHAR ucEsId, BOOL fgAsyncMode);
EXTERN BOOL _VDEC_GetVdecRedecValue(void);
EXTERN BOOL _VDEC_SetVdecRedecValue(BOOL fgRecDecStatus);
EXTERN VDEC_INFO_T* _VDEC_GetInfo(void);
//EXTERN VDEC_PES_INFO_T* _VDEC_GetPesInfo(void);
EXTERN void _VDEC_LockCcSema(UCHAR ucEsId);
EXTERN void _VDEC_UnlockCcSema(UCHAR ucEsId);
EXTERN void _VDEC_CreateEsmSema(UCHAR ucEsId);
EXTERN void _VDEC_DeleteEsmSema(UCHAR ucEsId);
EXTERN void _VDEC_InitInfo(void);
EXTERN void _VDEC_ClearInfo(UCHAR ucVldId);
EXTERN void _VDEC_ClearMpvCc(UCHAR ucEsId);
EXTERN void* _VDEC_GetMpvCc(UCHAR ucEsId);
EXTERN void _VDEC_FlushEs(UCHAR ucEsId);
EXTERN void _VDEC_ClearEsInfo(UCHAR ucEsId);
EXTERN VOID _VDEC_DispatchEos(UCHAR ucEsId, BOOL fgSub);
EXTERN void _VDEC_UpdateTemi(BOOL fgIsMMPlay, VDEC_PES_INFO_T *prPesInfo, FBM_PIC_HDR_T * prFbmPicHdr);

EXTERN void _VDEC_LockReplaySema(UCHAR ucEsId);
EXTERN void _VDEC_UnlockReplaySema(UCHAR ucEsId);

EXTERN void _VDEC_LockUBESema(UCHAR ucEsId);
EXTERN void _VDEC_UnlockUBESema(UCHAR ucEsId);

EXTERN void _VDEC_LockFlushSema(UCHAR ucEsId);
EXTERN void _VDEC_UnlockFlushSema(UCHAR ucEsId);
EXTERN void _VDEC_LockFlushMutex(UCHAR ucEsId);
EXTERN void _VDEC_UnlockFlushMutex(UCHAR ucEsId);
EXTERN VDEC_ASPECT_RATIO_T _VdecDecideAspectRatio(ENUM_VDEC_FMT_T eFmt,UCHAR ucAspectRatio,UINT32 u4Width, UINT32 u4Height, BOOL fgMMPlay);
EXTERN UINT32 _VDEC_LockVld(UCHAR ucEsId, UCHAR ucUnuseVldId);
EXTERN void _VDEC_UnlockVld(UCHAR ucEsId, UCHAR ucVldId);
EXTERN VOID _VDEC_CheckLockStatus(UCHAR ucVldId);

EXTERN BOOL VDEC_VLDMngrAllocVld(UCHAR ucEsId, UCHAR *paucConflictEsId);
EXTERN BOOL _VDEC_ChkUFO(UCHAR ucEsId,ENUM_VDEC_FMT_T eCurFMT,BOOL fgFrameOnly, UINT32 u4Width, UINT32 u4Height);
EXTERN BOOL _VDEC_ChkJump(UCHAR ucEsId,BOOL fgUfo, BOOL fg10bit);
EXTERN VOID VDEC_VLDMngrFreeVld(UCHAR ucEsId);
EXTERN UCHAR VDEC_VLDAllocShortUse(UCHAR ucEsId, ENUM_VDEC_FMT_T eFmt, INT32 i4TimeOut);
EXTERN UCHAR VDEC_VLDFreeShortUse(UCHAR ucEsId, UCHAR ucVldId);
EXTERN BOOL VDEC_VLDMngrQueryCap(ENUM_VDEC_FMT_T eFMT, UINT32 u4Width, UINT32 u4Height, UINT32 u4Fps);
EXTERN VOID _VDEC_RMKickRet(UCHAR ucEsId, VDEC_RM_BLOCK_E eCond);
EXTERN UCHAR VDEC_VLDAllocLAX(UCHAR ucEsId);
EXTERN BOOL VDEC_VLDAllocVldImg(UCHAR ucEsId, UCHAR *paucConflictEsId);
EXTERN BOOL _VDEC_VLDMngrChkUFO(UCHAR ucEsId, VDEC_VLDM_INPUT_T *ptInCond);


VOID VDEC_VLDMngrMapping(UCHAR ucEsId, UCHAR ucVldUsage, UCHAR ucUfoForceOn,UCHAR ucJumpForceOn, BOOL fgForceSupport4k120, BOOL fgForceAvcOutputOldWay);
VOID VDEC_ThumbUse(UCHAR ucEsId, BOOL fgThumbOldWay);

// vdec_flw.c
EXTERN void _VdecCheckStatus(UCHAR ucEsId, BOOL fgDecodeOK);

#if 0
EXTERN void VDEC_WaitSyncPoint(UCHAR ucEsId, BOOL fgTricking);
EXTERN UINT32 VDEC_GetDecPicCount(UCHAR ucEsId);
#endif
EXTERN UINT32 VDEC_GetAvgPicSize(UCHAR ucEsId);

EXTERN void VDEC_GetDecStatus(UCHAR ucEsId, BOOL* pfgLock
    , BOOL* pfgTopFldFirst, BOOL* pfgRepFirstFld, BOOL* pfgProgressiveFrm
    , UCHAR* pucPicType, UCHAR* pucPicStruture, UCHAR* pucTemporalRef
    , UINT32* pu4ReceiveNs, UINT32* pu4DecOkNs);

EXTERN void VDEC_GetDecErrInfo(UCHAR ucEsId, BOOL* pfgError, BOOL* pfgDisplayStatus);

EXTERN BOOL VDEC_RegDecErrCb(PFN_VDEC_DECERR_CB pfDecErrCb, UINT32 u4ErrDuration);
EXTERN BOOL VDEC_RegHDRInfoCb(PFN_VDEC_HDR_NFY_FCT pfnHDRInfoCb);
EXTERN BOOL VDEC_RegStatusCb(PFN_VDEC_STATUS_CB pfnStatusCb);
EXTERN VOID VDEC_RegRmCb(PFN_VDEC_RM_CB pfnRmCb);
EXTERN BOOL VDEC_PlayOneFrm(UCHAR ucEsId, ENUM_VDEC_FMT_T eFmt);
EXTERN BOOL VDEC_RegRenderPtsCb(UCHAR ucEsId, PFN_VDEC_RENDER_PTS_CB pfnRenderPtsCb, UINT8 u1AttachedSrcId);
EXTERN BOOL VDEC_RegTrickPtsCb(UCHAR ucEsId, PFN_VDEC_TRICK_PTS_CB pfnTrickPtsCb, UINT8 u1AttachedSrcId);
EXTERN BOOL VDEC_SetRenderPts(UCHAR ucEsId, UINT64 u4Pts);
EXTERN BOOL VDEC_SetTotalTime(UCHAR ucEsId, UINT32 u4TotalTime);
EXTERN BOOL VDEC_SetFileSize(UCHAR ucEsId, UINT64 u8FileSize);
EXTERN BOOL  VDEC_SetRenderBackStep(UCHAR ucEsId, BOOL fgRenderBackStep, UINT64 u8Pos,
    INT32 i4TempRef, UINT16 u2DecodingOrder);
EXTERN BOOL VDEC_SetRenderFromPos(UCHAR ucEsId, BOOL fgRenderFromPos,
    UINT64 u8Pos, INT32 i4TempRef, UINT16 u2DecodingOrder);
EXTERN BOOL  VDEC_SetRenderFromPtsAdv(UCHAR ucEsId, UINT64 u4Pts, BOOL fgPtsOnly);
EXTERN VOID VDEC_SetVdecVpeek(UCHAR ucEsId, BOOL fgIsVpeek);
EXTERN BOOL VDEC_SetRenderFromPts(UCHAR ucEsId, UINT64 u4Pts);
EXTERN BOOL VDEC_SetRenderFromPtsAutoPause(UCHAR ucEsId, UINT64 u4Pts, BOOL fgAutoPause);
EXTERN BOOL  VDEC_SetRenderFromPtsAutoPauseStartPts(UCHAR ucEsId, UINT64 u4Pts, BOOL fgAutoPause, BOOL fgStartPts);
EXTERN BOOL VDEC_SetRenderFromFirstPic(UCHAR ucEsId, BOOL fgRenderFromFirstPic,
    UINT64 u8LastRenderPos);
EXTERN BOOL VDEC_SetRenderPicCntAndPts(UCHAR ucEsId, BOOL fgRenderPicCntOrPts, UINT32 u4Count, UINT64 u4Pts);
EXTERN BOOL VDEC_SetGetSeqHdrOnlyBegin(UCHAR ucEsId,
ENUM_VDEC_FMT_T eFmt, BOOL *pfgPowerOff, UCHAR *ucMpvId);
EXTERN BOOL VDEC_SetGetSeqHdrOnlyEnd(UCHAR ucEsId, BOOL fgPowerOff, UCHAR ucMpvId);
EXTERN BOOL VDEC_SetSuperFreeze(UCHAR ucEsId, BOOL fgSuperFreeze);
EXTERN BOOL VDEC_CheckStopStatus(UCHAR ucEsId, UINT64 u4PTS, INT32 i4TempRef);
EXTERN BOOL VDEC_IsNotDisplay(UCHAR ucEsId, UINT64 u4PTS, INT32 i4TempRef, UINT64 u8Offset);
EXTERN BOOL VDEC_IsNotDisplayEx(UCHAR ucEsId, BOOL fgSub, UINT64 u4PTS, INT32 i4TempRef, UINT64 u8Offset);
EXTERN BOOL VDEC_ReleaseDispQ(UCHAR ucEsId);
EXTERN BOOL VDEC_PowerOn(UCHAR ucEsId, UCHAR ucVldId);
EXTERN BOOL VDEC_PowerOff(UCHAR ucEsId, UCHAR ucVldId);
EXTERN void VDEC_StartPTS(UCHAR ucEsId, BOOL fgEnCalPTS, UINT32 u4Pts, VDEC_PTS_INFO_T* prPTSInfo);
EXTERN BOOL VDEC_PrsSeqHdr(UCHAR ucEsId, ENUM_VDEC_FMT_T eFmt,
    VDEC_PES_INFO_T* prPesInfo, VDEC_SEQUENCE_DATA_T* prSeqInfo);

EXTERN void VDEC_FbmMidTest(UCHAR ucEsId, UINT8 u1Mode, BOOL fgDBKDisable);
EXTERN void VDEC_FbgChgHdlr(UCHAR ucEsId, UCHAR ucFbgId, UINT32 u4FBStart, UINT32 u4FBEnd);
EXTERN void VDEC_FbgReleaseHdlr(UCHAR ucEsId);
EXTERN INT32 _VDEC_DecCfg(UCHAR ucEsId);
EXTERN VOID _VDEC_Check2D3DSwitch(UCHAR ucEsId, UCHAR ucFbId);
EXTERN INT32 _VDEC_PrepareFb(UCHAR ucEsId, ENUM_VDEC_FMT_T eCurFMT, void* pvArg, UINT32 u4GetFbTime);
EXTERN VOID _VDEC_ShouldSendWorkLetToWorker(UCHAR ucEsId, BOOL fgShouldSend);
extern INT32 CLI_Parser(const CHAR *szCmdBuf);

EXTERN VOID _VDEC_JobBeforePutDispQ(UCHAR ucEsId, UCHAR ucFbId);
EXTERN UINT64 _VDEC_Div6464(UINT64 u8Dividend, UINT64 u8Divider);
EXTERN VOID _Vdec_DisplayQueueNotify(UCHAR ucEsId, VOID *pPicNfyInfo);
EXTERN BOOL _Vdec_GetThumbInfo(UCHAR ucEsId, VDP_THUMBNAIL_T *pThumbInfo);
EXTERN BOOL _Vdec_SetThumbInfo(UCHAR ucEsId, VDP_THUMBNAIL_INFO_T rThumbInfo);
EXTERN BOOL VDEC_GetNv12Output(UCHAR ucEsId, VDEC_OPERA_OUTPUT_T* prVdecOutPutInfo);


/* for oryx sony project, width is 704 dtv source need to handle with black at left and right
  * for 64*32 mode, just left both 64 at left and right, so 64*2 is add to allocate fbm buffer
  * and real Y/C pointer is reset to +64*32 /+32*32 in this case
  */
#define HSIZE_TO_FILL   704
#define HSIZE_TO_FILL_352   352

EXTERN BOOL _VPUSH_Play(VOID* prdec);
EXTERN BOOL _VPUSH_PlayOneFrm(VOID* prdec);
EXTERN VOID _VPUSH_ClearOneFrm(VOID* prdec);
EXTERN BOOL _VPUSH_Stop(VOID* prdec);
EXTERN BOOL _VPUSH_StopSync(VOID* prdec);
EXTERN BOOL _VPUSH_PauseVdec(VOID* prdec);
EXTERN BOOL _VPUSH_PlayVdec(VOID* prdec);
EXTERN VOID _VPUSH_SetAvSyncMode(VOID* prdec, UCHAR ucStcId, UINT32 u4AVSyncMode);
EXTERN BOOL _VPUSH_Flush(VOID* prdec);
EXTERN BOOL _VPUSH_FlushSync(VOID* prdec);
EXTERN INT32 _VPUSH_PutData(VOID* prdec, VDEC_BYTES_INTO_T *prBytesInfo);
EXTERN BOOL _VPUSH_PutDataSync(VOID* prdec, VDEC_BYTES_INTO_T *prBytesInfo);
EXTERN BOOL _VPUSH_PutDataDone(VOID* prdec, UINT64 u8Tag);
EXTERN VOID* _VPUSH_AllocVideoDecoder(ENUM_VDEC_FMT_T eFmt, UCHAR ucVdecId, BOOL fgEnableDmxIommu);
EXTERN VOID _VPUSH_ReleaseVideoDecoder(VOID* prdec);
EXTERN VOID _VPUSH_DecodeInit(VOID);
EXTERN BOOL _VPUSH_DecodeReset(VOID* prdec);
EXTERN VOID _VPUSH_DecodeDone(UCHAR ucEsId, VOID *prPicNfyInfo);
EXTERN VOID _VPUSH_CreateFbgDone(UCHAR ucEsId, VOID *pVoid);
EXTERN BOOL _VPUSH_RegCb(VOID* prdec, VDEC_PUSH_CB_T *prVdecPushCb);
EXTERN BOOL _VPUSH_GetVFifoInfo(VDEC_VFIFO_INTO_T *prVfifoInfo);
EXTERN BOOL _VPUSH_GetFeederInfo(VOID* prdec, VDEC_FEEDER_INTO_T *prFeederInfo);
EXTERN BOOL _VPUSH_SetInfo(VOID* prdec, VDEC_SET_INTO_T *prVdecSetInfo);
EXTERN BOOL _VPUSH_GetInfo(VOID* prdec, VDEC_GET_INTO_T *prVdecGetInfo);
EXTERN BOOL _VPUSH_SetRvType(VOID* prdec, BOOL fgIsRv8);
EXTERN BOOL _VPUSH_SetPushType(VOID* prdec, ENUM_VDEC_PUSH_FMT_T ePushFmt);
EXTERN VOID _VPUSH_SetPicSz(VOID* prdec, UINT32 u4Width, UINT32 u4Height,UINT32 u4FrameRate);
EXTERN BOOL _VPUSH_SetRptr(UCHAR ucEsId, UINT32 u4Rp, UPTR u4FrameAddr);
EXTERN BOOL _VPUSH_SetSeamlessMode(VOID* prdec, UINT32 u4MaxWidth, UINT32 u4MaxHeight, UINT32 u4ResizerId);
EXTERN VOID VOID_VPUSH_SetSeamlessInfo(VOID* prdec,BOOL fgSeamlessPlay, UINT32 u4SeamlessWidth, UINT32 u4SeamlessHeight);
EXTERN VOID VOID_VPUSH_Set3DType(VOID* prdec,UINT32 u43DType);
EXTERN BOOL _VPUSH_AllocVFifo(VOID* prdec,
    UPTR *pu4BufSA, UINT32 u4Size, ENUM_VDEC_FMT_T eFmt);
EXTERN BOOL _VPUSH_FreeVFifo(VOID* prdec, UPTR u4BufSA);
EXTERN BOOL _VPUSH_GetDecSize(VOID* prdec, UINT64 *pu8DecSize, UINT64 *pu8UndecSize);
EXTERN BOOL _VPUSH_ResetDecSize(VOID* prdec);
EXTERN BOOL _VPUSH_SetAppType(VOID* prdec, char *pcAppType, UINT32 u4AppTypeLen);
EXTERN BOOL _VPUSH_SetContainerType(VOID* prdec, char *pcContainerType, UINT32 u4ContainerTypeLen, UINT32 u4Metadata);
EXTERN BOOL _VPUSH_PrsSeqHdr(VOID* prdec,
    VDEC_BYTES_INTO_T *prBytesInfo, FBM_SEQ_HDR_T *prSeqInfo);
EXTERN BOOL _VPUSH_SetBLEL(VOID* prdec, BOOL fgBLEL);
EXTERN BOOL _VPUSH_GetDisplayInfor(VOID* prdec, VDEC_DISP_FRAME_T *prDispFrame,UINT8 u1FbgId,UINT8 u1FbId);
EXTERN UCHAR _VPUSH_GetAvailableVdec(BOOL fgZeroFirst);
EXTERN UINT32 _VPUSH_GetDecoderCnt(void);
EXTERN ENUM_VDEC_STATE_T _VPUSH_GetDecoderStatus(UINT8 uDecId);
EXTERN BOOL _VPUSH_AllocDmx(VOID* prdec);
EXTERN BOOL _VPUSH_ReleaseDmx(VOID* prdec);
EXTERN BOOL _VPUSH_SetGameMode(VOID* prdec);
EXTERN BOOL _VPUSH_SetHDR10Info(VOID* prdec, VDEC_HDR10_INFO_T *pInfo);
EXTERN BOOL _VPUSH_GetHDR10Info(VOID* prdec, VDEC_HDR10_INFO_T *pInfo);
EXTERN BOOL _VPUSH_SetHDR10MetadataInfo(VOID* prdec, VDEC_HDR10_METADATA_INFO_T *pInfo);
EXTERN BOOL _VPUSH_GetHDR10MetadataInfo(VOID* prdec, VDEC_HDR10_METADATA_INFO_T *pInfo);
EXTERN BOOL _VPUSH_SetDVInfo(VOID* prdec, VDEC_DV_INFO_T *pInfo);
EXTERN BOOL _VPUSH_ParseDVInfo(VOID* prdec, VDEC_BYTES_INTO_T *prBytesInfo, VDEC_DV_CSD_INFO_T *pInfo);
EXTERN BOOL _VPUSH_SpeedIsSeek(VOID* prdec);
EXTERN void _VPUSH_SetTrickMode(VOID* prdec, UINT32 u4TrickMode);
EXTERN VOID _VPUSH_SetVdecVpeek(VOID* prdec, BOOL fgIsVpeek);
EXTERN UCHAR _VPUSH_GetFbgId(VOID* prdec);
EXTERN VOID _VPUSH_ChangeVideoFormat(VOID* prdec, ENUM_VDEC_FMT_T eFmt);
EXTERN BOOL _VPUSH_SetHeif(VOID* prdec, UINT32 u4GridRows, UINT32 u4GridCols, BOOL fgHeif);
EXTERN VOID _VPUSH_SetPtpId(VOID* prdec, INT32 i4PtpID);
EXTERN VOID _VPUSH_SetAutoFpsDet(VOID* prdec, INT32 i4AutoFpsDet);

EXTERN VDEC_MODELOG_INFO_T* VDec_GetModeLogInfo(UCHAR ucEsId);
EXTERN void VDec_InitModeLogInfo(void);
EXTERN char* VDEC_CMD_TO_STR(VDEC_CMD_T eCmd);
EXTERN char* VDEC_STATE_TO_STR(ENUM_VDEC_STATE_T eState);
EXTERN char* VDEC_FMT_TO_STR(ENUM_VDEC_FMT_T eFmt);
void VDEC_PRINT(UINT32 u4EsId, UINT32 ucLogType, const CHAR *format, ...);
void VDEC_PRINT_NOID(UINT32 ucLogType, const CHAR *format, ...);

EXTERN VOID vVDecDVInitRPUData(VDEC_PES_INFO_T *prPesInfo, FBM_PIC_HDR_T *prPicHdr, VDEC_DECODER_HANDLE_T *prHandle);
EXTERN VOID vVDecDVSetDebugRpu(BOOL fgEnableDebug);

INT32 VDEC_GetDeltaPts(UCHAR ucEsId);
VOID VDEC_SetDeltaPts(UCHAR ucEsId, INT32 i4DeltaPts);
extern INT32 VDEC_GetSecureMode(UCHAR ucEsId);
EXTERN void _VDEC_MPEG2ApiSetQpScaleMode(UCHAR mode);
EXTERN BOOL fgVDECCheckIsMELMode(UCHAR ucEsId);
EXTERN UINT32 _VDEC_Es2Vdp(UCHAR ucEsId);

#endif //VDEC_DRVIF_H

