/* 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: fbm_drvif.h,v $
 * $Revision$

 *
 *---------------------------------------------------------------------------*/

/** @file fbm_drvif.h
 *  API of FBM (Frame Buffer Manager)
 *  Details of file fbm_drvif.h (optional).
 */

#ifndef FBM_DRVIF_H
#define FBM_DRVIF_H


//#define FBM_INHERITANCE

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

#include "stc_drvif.h"
#include "x_lint.h"
#include "x_typedef.h"
#include "x_timer.h"
#include "panel_cust.h"

#if defined(CC_MT5399) ||defined(CC_MT5890)||defined(CC_MT5891)||defined(CC_MT5886)
#define CC_FBM_2ND_CHANNEL
#endif
#if defined(CC_MT5890)||defined(CC_MT5891)||defined(CC_MT5886)
#define CC_FBM_3ND_CHANNEL
#endif

#define CC_SUPPORT_DIRECTION_ROTATE


/*
Capri and Lemur case:
formula:
(Ref+dec+lock)*W*H*1.5 + (Ref+dec)*W*H/4
ex.
(1920*1088)*1.5*9+(1920*1088)*7/4 = 31856640.0 = 0x1E61800 ~= 0x1F00000
C Total size:
  (1920*1088)*0.5*9 = 0x8F7000
  FBM_MPEG_C_SIZE : ~=0x90000
  (1920*1088)*0.5*7 = 0x6F9000
*/

//#define YC_MERGE_IN_CHB

#if defined(CC_FBM_SUPPORT_4K2K_SEAMLESS)
#define FBM_MPEG_SEAMLESS_SIZE (0x1B00000) // seamless buff (2FB,27M)
#elif defined(DIVX_PLUS_CER) || defined(CC_NETFLIX_CE3_SUPPORT) || defined(CC_ENABLE_SEAMLESS_FOR_2D)
#define FBM_MPEG_SEAMLESS_SIZE (0x600000) // seamless buff (2FB,6M)
#else
#define FBM_MPEG_SEAMLESS_SIZE (0x0) // seamless buff (0)
#endif


/*--------- MPEG Macro   -------*/
#define FBM_RESERVE_YSIZE   0xA00000  // 0xA00000 (5*YSize + 5*Ysize/256)
#define FBM_RESERVE_CSIZE   0x500000  // 0x500000 (5*CSize + 5*Csize/256)

/*--------- MPEG End   -------*/

//for H264
//#define FBM_MAX_FB_NS_PER_GROUP     18
#define FBM_MAX_FB_NS_PER_GROUP     (64)

// Reference buffer number per frame buffer group
#define FBM_REF_FB_NS_PER_GROUP     2

// cabac info buffer per frame buffer group for HEVC and H264
#define FBM_MAX_CABAC_BUF_NS_PER_GROUP 2
#define FBM_RPU_BUF_MAX_SIZE (4096)  //(1536)//1.5x1024



#ifndef NDEBUG
#define FBM_FB_LOG
#endif


#if defined( CC_SUPPORT_4K2K)||defined(CC_SUPPORT_HDMI_4K2K30)
#define FBM_4K2K_SUPPORT
#define FBM_4K2K_JPG_SUPPORT
#define FBM_4K1K_VIDEO_SUPPORT
#endif

#define INVALID_DISPTAG ((UINT64)-1)
#define OMX_PENDING_DISPTAG ((UINT64)0)
#define FBM_INVALID_PTS ((UINT32)-1)

#define MINJOR_BASE_FBID                     (20)

#define FBM_SEAMLESS_LVL                        (2)
#define FBM_MAJOR2MINORSTARTFBID(majorfb)       (MINJOR_BASE_FBID+(majorfb*FBM_SEAMLESS_LVL))
#define FBM_MINOR2MAJORFBID(minorfb)            ((minorfb - MINJOR_BASE_FBID)>>1)

#define FBM_MV_MAX_NS               (17) // working buffer max :17

//---------------------------------------------------------------------------
// Configurations
//---------------------------------------------------------------------------

// Video Plane Full ISR
// For DTV00007209, Tearing
//#define CC_VDP_FULL_ISR

//---------------------------------------------------------------------------
// Constant definitions
//---------------------------------------------------------------------------

// Frame Buffer Alignment
#define FBM_ALIGN_MASK(value, mask)     ((value + mask) & (~(mask)))
#define FBM_MAX_FB_COUNT (20)
#define FBM_VP9_MV_BUFFER_SIZE(width, high)       FBM_ALIGN_MASK(((((width + 63)>>6)*((high + 63)>>6) + 2)*576),(256-1))
#define FBM_VP9_SEGMENT_BUFFER_SIZE(width,high)   FBM_ALIGN_MASK((((width + 63)>>6)*((high + 63)>>6)*32 + 256),(256-1))
#define FBM_VP9_TITLE_BUFFER_SIZE                 (256*16)
#define FBM_MISC_BUFFER_SIZE(width,high)          (FBM_VP9_TITLE_BUFFER_SIZE + FBM_VP9_SEGMENT_BUFFER_SIZE(width, high) + 1024)


//av1
#define FBM_AV1_MV_BUFFER_SIZE(width, high)       (FBM_ALIGN_MASK(width,127)*FBM_ALIGN_MASK(high,127)>>4)
#define FBM_AV1_SEGMENT_BUFFER_SIZE(width,high)   (FBM_ALIGN_MASK((((width + 127)>>7)*((high + 127)>>7)*512),8191))
#define FBM_AV1_CDF_BUFFER_SIZE                  (FBM_ALIGN_MASK(16288,8191))
#define FBM_AV1_TITLE_BUFFER_SIZE                 (FBM_ALIGN_MASK(1536*64,8191))
#define FBM_AV1_IQ_BUFFER_SIZE                   (FBM_ALIGN_MASK(4640*16,8191))
#define FBM_MISC_BUFFER_SIZE_AV1                (FBM_AV1_TITLE_BUFFER_SIZE + FBM_AV1_IQ_BUFFER_SIZE)



typedef enum
{
    HDR_TYPE_SDR =0,
    HDR_TYPE_HDR10,
    HDR_TYPE_DOVI,
    HDR_TYPE_PHLP,
    HDR_TYPE_HLG,
    HDR_TYPE_RESVED
}HDR_TYPE_E;

typedef enum
{
    HDR_VDO_HDR_NONE = 0,
    HDR_VDO1_HDR2SDR = 1,
    HDR_VDO2_SDR2HDR = 2,
    HDR_VDO3_HDR2HDR = 3,
}HDR_CHANGE_FLAG_E;

typedef enum
{
    HDR_GAMMA_ST2084 =1,
    HDR_GAMMA_HLG    =2,
}HDR_EOTF_E;

typedef enum
{
    HDRSOURCEHEVCCOLORPRIMARIES_BT709        =1,
    HDRSOURCEHEVCCOLORPRIMARIES_UNSPECIFIED  =2,
    HDRSOURCEHEVCCOLORPRIMARIES_ITURBT470M   =4,
    HDRSOURCEHEVCCOLORPRIMARIES_ITURBT470BG  =5,
    HDRSOURCEHEVCCOLORPRIMARIES_SMPTE170M    =6,
    HDRSOURCEHEVCCOLORPRIMARIES_SMPTE240M    =7,
    HDRSOURCEHEVCCOLORPRIMARIES_FILM         =8,
    HDRSOURCEHEVCCOLORPRIMARIES_ITURBT2020   =9,
    HDRSOURCEHEVCCOLORPRIMARIES_SMPTEST428_1 =10,
    HDRSOURCEHEVCCOLORPRIMARIES_JEDEC_P22    =22,
    HDRSOURCECOLOURPRIMARIES_TypeReserved,
}HDR_COLOR_PRIMARIES_E;

typedef enum
{
    HDR_VDO_COLOR_SPACE     = 0,
    HDR_VDO_BT709_BT2020    = 1,
    HDR_VDO_BT2020_709      = 2,
    HDR_VDO_BT601_2020      = 3,
    HDR_VDO_BT2020_601      = 4,
}HDR_COLOR_PRIMARIES_CHANGE_FLAG_E;

typedef enum
{
    HDR_ITURBT709           = 1,
    HDR_UNSPECIFIED         = 2,
    HDR_GAMMA2_2CURVE       = 4,
    HDR_GAMMA2_8CURVE       = 5,
    HDR_SMPTE170M           = 6,
    HDR_SMPTE240M           = 7,
    HDR_LINEAR              = 8,
    HDR_LOG                 = 9,
    HDR_SQRT                = 10,
    HDR_IEC61966_2_4        = 11,
    HDR_ITURBT1361          = 12,
    HDR_IEC61966_2_1        = 13,
    HDR_ITURBT2020_10       = 14,
    HDR_ITURBT2020_12       = 15,
    HDR_SMPTEST2084         = 16,
    HDR_SMPTEST428_1        = 17,
    HDR_ARIBSTD_B67         = 18,
    HDR_RESVERD,
}EOTF_E;

typedef enum
{
    MATRIX_GBR                = 0,
    MATRIX_BT709              = 1,
    MATRIX_UNSPECIFIED        = 2,
    MATRIX_RESVERD            = 3,
    MATRIX_FCC                = 4,
    MATRIX_BT407BG            = 5,
    MATRIX_SMPTE170M          = 6,
    MATRIX_SMPTE240M          = 7,
    MATRIX_YCOCG              = 8,
    MATRIX_BT2020_NonCON      = 9,
    MATRIX_BT2020_CON         = 10,
}MATRIX_COEFFICIENTS_E;

/*! @enum IMTKPB_RANGE_E
 *  @brief  Range type
 */
typedef enum
{
    HDR_RANGE_UNSPECIFIED=0,                ///< encoder mode unspecified.
    HDR_RANGE_BROADCAST=1,                  ///< encoder mode is broadcast range.
    HDR_RANGE_FULL=2,                       ///< encoder mode is full range .
    HDR_RANGE_LIMIT=3,                      ///< encoder mode is limit range .
    HDR_RANGE_R_MATRIXCOEFFIENTS=4,         ///< encoder mode is r matrixcoeffients .
    HDR_RANGE_RESVERD,                      ///< Resverd .
}HDR_RANGE_E;

typedef struct
{
    HDR_TYPE_E                             e_HdrType;                      ///< HDR type
    HDR_CHANGE_FLAG_E                      e_VdoHdrChange;                 ///< HDR type change
    EOTF_E                                 e_VdoGamma;                     ///< Gamma type
    HDR_COLOR_PRIMARIES_E                  e_ColorSpaceTypeDef;            ///< ColorSpace type
    HDR_COLOR_PRIMARIES_CHANGE_FLAG_E      e_VdoColorSpaceChange;          ///< ColorSpace type change
    UINT32                                 u4TV_MaxLuma;                   ///< TV_MaxLuma
    MATRIX_COEFFICIENTS_E                  e_eTypeMatrixCoefficients;      ///< add by lihui.li for TV MatrixCoefficients type
    HDR_RANGE_E                            eTypeRange;                     ///< add by lihui.li for range type
#if defined(CC_SUPPORT_TECHNICOLOR_HDR)&& defined(CC_SUPPORT_TECHNICOLOR_I)
    UINT8  u1PayloadLength;
    UINT8  u1PayloadMode;
    UINT8  u1LDRContentCS;
    UINT8  u1HDRContentCS;
    UINT8  u1HDRContainerCS;
    UINT8  u1VideoRange;
    UINT8  u1PrimeMode;
    UINT16  u1PeakLuminance;
    UINT16  u2Ba;
#endif
}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;
}HDR10_METADATA_INFO_T;

typedef struct
{
    HDR10_INFO_T            tHdr10Info;
    HDR10_METADATA_INFO_T   tHdr10MetadataInfo;
    UINT32                  u4MetadataHandler;
    BOOL                    fgMetadataEncrypt;
}HDRSRC_PROFILE_T;

typedef enum
{
    FBM_TYPE_DMX,
    FBM_TYPE_MPEG,
    FBM_TYPE_FEEDER,
    FBM_TYPE_B2R,
    FBM_TYPE_JPEG,
    FBM_TYPE_TZ_DMX,
    FBM_TYPE_SML,
    FBM_TYPE_SML_C,
    FBM_TYPE_LAX1,
    FBM_TYPE_LAX2,
    FBM_TYPE_LAX3,
    FBM_TYPE_LAX4,
    FBM_TYPE_DYN_MPEG,
    FBM_TYPE_TOTAL,
} FBM_TYPE_T;

/** Brief of FBM_POOL_TYPE_T
 *  FBM Memory Pool Index
 */
typedef enum
{
    ColorSpace_NS,
    ColorSpace_BT709,
    ColorSpace_BT601,
    ColorSpace_BT2020,
    ColorSpace_sRGB,
    ColorSpace_sYCC,
    ColorSpace_AdobeRGB,
    ColorSpace_Normal,
    ColorSpace_XVColor,
    ColorSpace_BT202C
} FBM_COLOR_SPACE_ID;

typedef enum
{
    FBM_POOL_TYPE_DMX,
    FBM_POOL_TYPE_TDC,
    FBM_POOL_TYPE_TDC_2,
    FBM_POOL_TYPE_VBI,
    FBM_POOL_TYPE_VBI_2,
    FBM_POOL_TYPE_MPEG,
    FBM_POOL_TYPE_MJC_1,
    FBM_POOL_TYPE_MPEG_TV,
    FBM_POOL_TYPE_MPEG_NET,
    FBM_POOL_TYPE_SCPOS_MAIN,//
    FBM_POOL_TYPE_DMX_TV, //10
    FBM_POOL_TYPE_DMX_NET,
    FBM_POOL_TYPE_FEEDER_NET,
    FBM_POOL_TYPE_SCPOS_PIP,
    FBM_POOL_TYPE_FEEDER,
    FBM_POOL_TYPE_FEEDER_MMP,
    FBM_POOL_TYPE_MDDI_1,
    FBM_POOL_TYPE_PQ_MM,
    FBM_POOL_TYPE_PQ_NET,
    FBM_POOL_TYPE_PQ_TV,
    FBM_POOL_TYPE_NET_SWAP,
    FBM_POOL_TYPE_TDC_DYN,
    FBM_POOL_TYPE_SCPOS_DYN_MAIN,
    FBM_POOL_TYPE_MDDI_DYN_MAIN,
    FBM_POOL_TYPE_SCPOS_DYN_SUB,
    FBM_POOL_TYPE_MDDI_DYN_SUB,
    FBM_POOL_TYPE_MDDI_PIP,
    FBM_POOL_TYPE_NR_1,
    FBM_POOL_TYPE_DSP,
    FBM_POOL_TYPE_B2R,
    FBM_POOL_TYPE_JPEG,
    FBM_POOL_TYPE_JPEG_OSD1,
    FBM_POOL_TYPE_JPEG_OSD2,
    FBM_POOL_TYPE_JPEG_OSD3,
    FBM_POOL_TYPE_JPEG_OSD4,
    FBM_POOL_TYPE_PQ_TOOL,//
    FBM_POOL_TYPE_OD,
    FBM_POOL_TYPE_VENC,
    FBM_POOL_TYPE_SWDMX,
    FBM_POOL_TYPE_FACEDET,
    FBM_POOL_TYPE_MPEG_FREE, //40
    FBM_POOL_TYPE_DIVA,
    FBM_POOL_TYPE_FEEDER2,
    FBM_POOL_TYPE_DMX2,
    FBM_POOL_TYPE_MPEG2,  //44
    FBM_POOL_TYPE_PVR,
    FBM_POOL_TYPE_PVR2,
    FBM_POOL_TYPE_JPG_VDP,
    FBM_POOL_TYPE_PNG,
    FBM_POOL_TYPE_DIVX,
    FBM_POOL_TYPE_MPEG3,//   50
    FBM_POOL_TYPE_VSS,
    FBM_POOL_TYPE_DMXPID,
    FBM_POOL_TYPE_IMGRZ_3D_KR,
    FBM_POOL_TYPE_DRM,
    FBM_POOL_TYPE_MUXER,
    FBM_POOL_TYPE_PQ_3DC,
    FBM_POOL_TYPE_PQ_PSCAN,
    FBM_POOL_TYPE_SUBTITLE,
    FBM_POOL_TYPE_DMX3,
    FBM_POOL_TYPE_FEEDER3, //60
    FBM_POOL_TYPE_EDB,
    FBM_POOL_TYPE_TVE,
    FBM_POOL_TYPE_4K_2K_SCALER,
    FBM_POOL_TYPE_DSP_BIN,
    FBM_POOL_TYPE_PHOTO_SHARE,
    FBM_POOL_TYPE_BEIC,
    FBM_POOL_TYPE_MPEG4,//
    FBM_POOL_TYPE_FEEDER4,
    FBM_POOL_TYPE_DMX4,
    FBM_POOL_TYPE_MPEG_C, //70
    FBM_POOL_TYPE_MPEG2_C,
    FBM_POOL_TYPE_MPEG3_C,
    FBM_POOL_TYPE_MPEG4_C,
    FBM_POOL_TYPE_W2D_R2R,
    FBM_POOL_TYPE_W2D_R2R_Y,
    FBM_POOL_TYPE_SCPOS_PIP2,
    FBM_POOL_TYPE_SRS,
    FBM_POOL_TYPE_REMUX,
    FBM_POOL_TYPE_HW_DEMOD,
    FBM_POOL_TYPE_SECURE_FEEDER, //80
    FBM_POOL_TYPE_REST_MEM,
    FBM_POOL_TYPE_W2D_R2R_CHA,
    FBM_POOL_TYPE_GFX,
    FBM_POOL_TYPE_SEAML1,
    FBM_POOL_TYPE_SEAML2,
    FBM_POOL_TYPE_SEAML3,
    FBM_POOL_TYPE_SEAML4,
    FBM_POOL_TYPE_SEAML1_C,
    FBM_POOL_TYPE_SEAML2_C,
    FBM_POOL_TYPE_SEAML3_C,
    FBM_POOL_TYPE_SEAML4_C,
    FBM_POOL_TYPE_VENC_OUT,
    FBM_POOL_TYPE_SLT_GFX,
    FBM_POOL_TYPE_DRAMHOTBOOTCALIBR_A,
    FBM_POOL_TYPE_DRAMHOTBOOTCALIBR_B,
    FBM_POOL_TYPE_DRAMHOTBOOTCALIBR_C,
    FBM_POOL_TYPE_LAX1,
    FBM_POOL_TYPE_LAX2,
    FBM_POOL_TYPE_MJC1,
    FBM_POOL_TYPE_MJC2,//100
    FBM_POOL_TYPE_MJC3,
    FBM_POOL_TYPE_MJC1_C,
    FBM_POOL_TYPE_MJC2_C,
    FBM_POOL_TYPE_MJC3_C,
    FBM_POOL_TYPE_MJCMV,
    FBM_POOL_TYPE_TNR_DYN_MAIN,
    FBM_POOL_TYPE_DYN_MPEG,
    FBM_POOL_TYPE_DYN_MPEG2,
    FBM_POOL_TYPE_PAD,
    FBM_POOL_TYPE_RAMOOPS,
    FBM_POOL_TYPE_MTDFB,
    FBM_POOL_TYPE_MTFB,
    FBM_POOL_TYPE_SHMEWS, //113
    FBM_POOL_TYPE_SHMTSRQUE,
    FBM_POOL_TYPE_SHMISDBCC,
    FBM_POOL_TYPE_SHMSSMA,
    FBM_POOL_TYPE_SHMVBIF,
    FBM_POOL_TYPE_SHMATVTS,
    FBM_POOL_TYPE_SHMMUXER,
    FBM_POOL_TYPE_THUMBNAIL, //120
    FBM_POOL_TYPE_SOUNDCLIP,
    FBM_POOL_TYPE_DTCPIP,
    FBM_POOL_TYPE_LAX3,
    FBM_POOL_TYPE_LAX4,
    FBM_POOL_TYPE_MJCALL,
    FBM_POOL_TYPE_W2D_R2R_CR,
    FBM_POOL_TYPE_MJC_R20,
    FBM_POOL_TYPE_MJC_R21,
    FBM_POOL_TYPE_LD,
    FBM_POOL_TYPE_3DLUT, //130
    FBM_POOL_TYPE_ATSC30ALP,
    FBM_POOL_TYPE_MJC_R20_SHM,
    FBM_POOL_TYPE_HDMI_SHM, //133
    FBM_POOL_TYPE_SOUND_MODEL, //134
    FBM_POOL_TYPE_FILM_GRAIN,
    FBM_POOL_TYPE_TOTAL2,
    FBM_POOL_TYPE_TOTAL3,
    FBM_POOL_TYPE_TOTAL,
    FBM_POOL_TYPE_NS,
    FBM_POOL_TYPE_NS_A,
    FBM_POOL_TYPE_NONE = 0xFF
} FBM_POOL_TYPE_T;

typedef enum
{
    FBM_VDEC_FMT_MPV,
    FBM_VDEC_FMT_MP4,
    FBM_VDEC_FMT_H264,
    FBM_VDEC_FMT_WMV,
    FBM_VDEC_FMT_MJPEG,
    FBM_VDEC_FMT_RV,
    FBM_VDEC_FMT_AVS,
    FBM_VDEC_FMT_VP6,
    FBM_VDEC_FMT_VP8,
    FBM_VDEC_FMT_RAW,
    FBM_VDEC_FMT_OGG,
    FBM_VDEC_FMT_JPG,
    FBM_VDEC_FMT_PNG,
    FBM_VDEC_FMT_H265,
    FBM_VDEC_FMT_VP9,
    FBM_VDEC_FMT_DV_H264,
    FBM_VDEC_FMT_DV_H265,
    FBM_VDEC_FMT_AVS2,
    FBM_VDEC_FMT_SHVC,
    FBM_VDEC_FMT_AV1,
    FBM_VDEC_FMT_MAX
} FBM_VDEC_FMT_T;

#define FBM_ENABLE_LOG_UNKNOW                                            (0)
#define FBM_ENABLE_LOG_CRT_FBG                                           (1 << 0)
#define FBM_ENABLE_LOG_OMX                                               (1 << 1)
#define FBM_ENABLE_LOG_FB_STATUS                                         (1 << 2)
#define FBM_ENABLE_LOG_CHK_EMPTY                                         (1 << 3)
#define FBM_ENABLE_LOG_CHK_DISPQ                                         (1 << 4)
#define FBM_DISABLE_NPTV_SEAMLESS                                        (1 << 5)
#define FBM_ENABLE_LOG_SEQCHG                                            (1 << 6)
#define FBM_ENABLE_LOG_PENDINGQ                                          (1 << 7)

#define FBM_PAUSE_TYPE_UNKOWN                                            (0x0)
#define FBM_PAUSE_TYPE_1                                                 (0x1)
#define FBM_PAUSE_TYPE_2                                                 (0x2)
#define FBM_PAUSE_TYPE_3                                                 (0x3)

#define FBM_GETFBFROMDISPQ_DEFALUT                                       (0x0)
#define FBM_GETFBFROMDISPQ_STEP                                          (0x1)
#define FBM_GETFBFROMDISPQ_STEP_DONE                                     (0x2)
#define FBM_GETFBFROMDISPQ_FORCE_PAUSE                                   (0x3)

#define FBM_STEP_CMD_DEFALUT                                             (0x0)
#define FBM_STEP_CMD_SETTING                                             (0x1)

typedef enum
{
#if defined(CC_TRUSTZONE_SUPPORT) && defined(CC_SVP_SUPPORT)
    FBM_POOL_TYPE_TZ_DMX,
#if defined(CC_VOMX_TV_COEXIST) || defined(CC_FBM_TWO_FBP_SHARED_WITH_DFB)
    FBM_POOL_TYPE_TZ_DMX2,
#endif
#endif
    FBM_POOL_TYPE_TZ_NS,
    FBM_POOL_TYPE_TZ_NONE = 0xFF
} FBM_POOL_TYPE_TZ_T;


#define FBM_POOL_TYPE_NR FBM_POOL_TYPE_NR_1
#define FBM_POOL_TYPE_MJC FBM_POOL_TYPE_MJC_1
#define FBM_POOL_TYPE_MDDI_MAIN FBM_POOL_TYPE_MDDI_1

#define FBM_POOL_MODE_8BIT                                              (1 << 0)
#define FBM_POOL_MODE_9BIT                                              (1 << 1)
#define FBM_POOL_MODE_10BIT                                             (1 << 2)
#define FBM_POOL_MODE_C_10BIT                                           (1 << 3)
#define FBM_POOL_MODE_420_FB                                            (1 << 4)
#define FBM_POOL_MODE_422_FB                                            (1 << 5)
#define FBM_POOL_MODE_444_FB                                            (1 << 6)
#define FBM_POOL_MODE_SD                                                (1 << 8)
#define FBM_POOL_MODE_720HD                                             (1 << 9)
#define FBM_POOL_MODE_1080HD                                            (1 << 10)
#define FBM_POOL_MODE_EPG                                               (1 << 11)
#define FBM_POOL_MODE_SHARE                                             (1 << 13)
#define FBM_POOL_MODE_TOGGLE_TRIGGER                                    (1 << 14)
#define FBM_POOL_MODE_UNSTABLE                                          (1 << 15)

#define FBM_POOL_MODE_MPEG_NO_COMP                                      (1 << 16)
#define FBM_POOL_MODE_MPEG_COMP_75                                      (1 << 17)
#define FBM_POOL_MODE_MPEG_COMP_50                                      (1 << 18)
#define FBM_POOL_MODE_MPEG_DBK                                          (1 << 19)

#define FBM_POOL_MODE_MJC_DROP                                          (1 << 16)
#define FBM_POOL_MODE_MJC_NO_DROP                                       (1 << 17)
#define FBM_POOL_MODE_MJC_NO_COMP                                       (1 << 18)
#define FBM_POOL_MODE_MJC_Y_COMP4                                       (1 << 19)
#define FBM_POOL_MODE_MJC_Y_COMP3                                       (1 << 20)

#define FBM_POOL_MODE_NR_3D_Y_C                                         (1 << 16)
#define FBM_POOL_MODE_NR_3D_Y_ONLY                                      (1 << 17)
#define FBM_POOL_MODE_NR_2D                                             (1 << 18)
#define FBM_POOL_MODE_NR_BYPASS                                         (1 << 19)

#define FBM_POOL_MODE_SCPOS_1FB                                         (1 << 16)
#define FBM_POOL_MODE_SCPOS_2FB                                         (1 << 17)
#define FBM_POOL_MODE_SCPOS_3FB                                         (1 << 18)
#define FBM_POOL_MODE_SCPOS_DISP                                        (1 << 19)
#define FBM_POOL_MODE_SCPOS_FULL                                        (1 << 20)
#define FBM_POOL_MODE_SCPOS_PSCAN_DISP                                  (1 << 21)
#define FBM_POOL_MODE_SCPOS_MJC_DISP                                    (1 << 22)
//#define FBM_POOL_MODE_SCPOS_MODE_MASK                                   (0xf << 19)
#define FBM_POOL_MODE_SCPOS_MODE_MASK                                   (0x18f << 19)
#define FBM_POOL_MODE_SCPOS_MM_BUFCHG                                   (1 << 23)
#define FBM_POOL_MODE_SCPOS_BYPASS_PSCANNR                              (1 << 24)
#define FBM_POOL_MODE_SCPOS_PROG_DISP                                   (1 << 25)
#define FBM_POOL_MODE_SCPOS_LINESYNC_DISP                               (1 << 26)
#define FBM_POOL_MODE_SCPOS_HYBRID_DISP                                 (1 << 27)   //for gazelle hybrid mode
#define FBM_POOL_MODE_SCPOS_DUAL_HYBRID_DISP                            (1 << 28)   //for gazelle hybrid mode


#define FBM_POOL_MODE_MDDI_BOB                                          (1 << 16)
#define FBM_POOL_MODE_MDDI_FULL                                         (1 << 17)
#define FBM_POOL_MODE_MDDI_CBOB                                         (1 << 18)
#define FBM_POOL_MODE_MDDI_MODEMSK                                      (0x7 << 16)
// used in progressive mode
#define FBM_POOL_MODE_MDDI_NR_Y_C                                       (1 << 19)
#define FBM_POOL_MODE_MDDI_NR_Y_ONLY                                    (1 << 20)//Outdated, should not be used
#define FBM_POOL_MODE_MDDI_NR_OFF                                       (1 << 21)
#define FBM_POOL_MODE_MDDI_NR_MODEMSK                                   (0x7 << 19)
#define FBM_POOL_MODE_MDDI_NR_10BIT                                     (1 << 22)
#define FBM_POOL_MODE_MDDI_COMP                                         (1 << 23)
#define FBM_POOL_MODE_MDDI_DISP                                         (1 << 24)
#define FBM_POOL_MODE_MDDI_P2I                                          (1 << 25)
#define FBM_POOL_MODE_MDDI_MM_BUFCHG                                    (1 << 26)
#define FBM_POOL_MODE_MDDI_HYBRID                                       (1 << 27)
#define FBM_POOL_MODE_MDDI_DUAL_HYBRID                                  (1 << 28)
#define FBM_POOL_MODE_MDDI_TNR                                          (1 << 29)
#define FBM_POOL_MODE_MDDI_MAIN_UFO                                     (1 << 30)
#define FBM_POOL_MODE_MDDI_TNR_UFO                                      (1 << 31)



// TDC mode
#define FBM_POOL_MODE_TDC_FULL                                          (1 << 16)
#define FBM_POOL_MODE_TDC_GAME                                       (1 << 17)

//mjc dram buffer setting
#define FBM_MJC_DRAM_2D                                                 (1<<0)
#define FBM_MJC_DRAM_3D_SG                                              (1<<1)
#define FBM_MJC_DRAM_3D_HPR                                             (1<<2)
#define FBM_MJC_DRAM_OSMP_FPR                                           (1<<3)
#define FBM_MJC_DRAM_3D_CFG                                             FBM_MJC_DRAM_OSMP_FPR  //if is l2r2 pdp panel choose FBM_MJC_DRAM_3D_SG

#define FBM_POOL_MODE_MJC_GAME_MODE                                     (1 << 8)
#define FBM_POOL_MODE_MJC_REPEAT_MODE                                   (1 << 9)
#define FBM_POOL_MODE_MJC_MEMC_MODE                                     (1 << 10)

#define FBM_POOL_MODE_MJC_Y10_C10_422_0RDC_3FRM                         (1 << 16)
#define FBM_POOL_MODE_MJC_Y10_C10_422_1RDC_3FRM                         (1 << 17)
#define FBM_POOL_MODE_MJC_Y10_C10_420_0RDC_3FRM                         (1 << 18)
#define FBM_POOL_MODE_MJC_Y10_C10_420_1RDC_3FRM                         (1 << 19)
#define FBM_POOL_MODE_MJC_Y10_C08_422_0RDC_3FRM                         (1 << 20)
#define FBM_POOL_MODE_MJC_Y10_C08_422_1RDC_3FRM                         (1 << 21)
#define FBM_POOL_MODE_MJC_Y10_C08_420_0RDC_3FRM                         (1 << 22)
#define FBM_POOL_MODE_MJC_Y10_C08_420_1RDC_3FRM                         (1 << 23)
#define FBM_POOL_MODE_MJC_Y08_C08_422_0RDC_3FRM                         (1 << 24)
#define FBM_POOL_MODE_MJC_Y08_C08_422_1RDC_3FRM                         (1 << 25)
#define FBM_POOL_MODE_FRC_Y10_C10_444                                   (1 << 26)
#define FBM_POOL_MODE_FRC_Y08_C08_444                                   (1 << 27)
#define FBM_POOL_MODE_FRC_Y08_C08_422                                   (1 << 28) // add a type of y8c8-422 for 4kX 2K
//#define FBM_POOL_MODE_MJC_Y08_C08_420_0RDC_3FRM                         (1 << 28) // no 420 FMT for mustang, so mark it and instead by y8c8-422, due to no any other bit  can be used
#define FBM_POOL_MODE_MJC_Y08_C08_420_1RDC_3FRM                         (1 << 29)
#define FBM_POOL_MODE_FRC_Y10_C10_422                                   (1 << 30)

#define FBM_POOL_HYBRID_DRAM_FRAME_NUM        2


#define FBM_TV_MODE_TYPE_NORMAL                                         0
#define FBM_TV_MODE_TYPE_PIP                                            1
#define FBM_TV_MODE_TYPE_POP                                            2


#define FBM_POOL_INHERIT                                                1
#define FBM_POOL_ROOT                                                   0

#define B2R_MAX_HEIGHT                  (2304)
#define B2R_MAX_WIDTH                   (4096)

typedef enum
{
    FLAG_SET_TYPE_ENABLE,
    FLAG_SET_TYPE_DISABLE,
    FLAG_SET_TYPE_RESET,
    FLAG_SET_TYPE_CHECK
}FBM_FLAG_SET_TYPE;

typedef enum
{
    SEAMLESS_FB_FLAG_MEMREST = 1<<0
}FBM_SEAMLESS_FB_FLAG_TYPE;

#ifdef CC_B2R_RM_SUPPORT

#define  Max_Capability      (2)
#define  Limit_Capability    (1)
#define  No_Capability      (0)
#define  UFD_INPUT        (3840 * 2160) // (0x7E9000)
#define  FHD_INPUT       (1920 * 1088) //(0x1FE000)
#define  MaxB2RNum       2
#define  B2RHD           0
#define  B2RSD           1
#define  HD_INPUT        (1280 * 720) // (0x7E9000)

typedef enum
{
    VDEC_MPV,
    VDEC_MP4,
    VDEC_H264,
    VDEC_WMV,
    VDEC_H264VER,
    VDEC_MJPEG,
    VDEC_RV,
    VDEC_AVS,
    VDEC_VP6,
    VDEC_VP8,
    VDEC_RAW,
    VDEC_OGG,
    VDEC_JPG,
    VDEC_PNG,
    VDEC_H265,
    VDEC_AVS2,
    VDEC_MAX
}   VdecType_Table;

typedef struct
{
    UINT16 u2HActive;
    UINT16 u2VActive;
    UINT16 u2Fps;
    BOOL   fg8Bit;
    BOOL   fgUFOEnable;
    BOOL   fg4K2k;
    VdecType_Table eVdecType;
    UINT16 u2CapabilityLvl;
    UINT16 u2BlockMode;
    UCHAR  ucEsId;
} B2R_RM_T;


typedef struct
{
    B2R_RM_T NB2R_RM[MaxB2RNum];
    B2R_RM_T OldB2R_RM[MaxB2RNum];
    BOOL    ufgOldB2RStatus;
    BOOL    ufgNewB2RStatus;
    BOOL    fgconflict;
    UINT16  u2ConflictVdpid;
} B2R_Capability_Map;

typedef enum
{
    Old_B2R0 =0,
    Old_B2R1,
    New_B2R0,
    New_B2R1,
    B2R_NULL
} B2R_Table;
#endif

#ifdef CC_B2R_RES_SUPPORT

#define VDP_MAIN  0
#define VDP_SUB   1
#define VDP_MAX   2

#define GRP_1     0
#define GRP_2     1
#define GRP_MAX   2

#define  FHD_TIMING    (1920 * 1088)
#define  UHD_TIMING    (4096 * 4096)

#define B2R_HW_MAX_ID 4

#define RES_R    (1 << 0)
#define RES_RW   (1 << 1)

typedef enum
{
    VDEC_NONE,
    VDEC_H265,
    VDEC_JPEG,
    VDEC_OTHER
}   CODEC_INFO_T;

typedef struct
{
    BOOL  fgUfoEn;
    UINT8 u1PixDepth;
    UINT8 u1FrmRate;
    UINT32 u4Resolution;
    CODEC_INFO_T eCodec;
} B2R_VD_INFO_T;

typedef struct
{
    UINT8 u1VdpId;
    B2R_VD_INFO_T t_vd;
} B2R_IPT_INFO_T;

typedef struct
{
    UINT8 u1HwId;
    UINT8 u1GrpId;
    UINT8 u1AsscId;
    UINT32 u4MaxRes;
} B2R_HW_CFG_T;

typedef struct
{
    BOOL  b_used;
    UINT8 u1FbgId;
    UINT8 u1VdpId;
} B2R_HW_PRM_T;

typedef struct
{
    B2R_HW_CFG_T t_cfg;
    B2R_HW_PRM_T t_prm;
    B2R_VD_INFO_T t_src;
} B2R_HW_RES_T;
#endif

#if (defined(CC_S_PLATFORM) || defined(CC_FBM_CONFIG_WITH_3DTV_4K_SUPPORT))
/** Brief of FBM_POOL_T
 *  FBM Memory Pool Info
 */

typedef enum
{
    FBM_MPEG_TYPE_UNKOWN,
    FBM_MPEG_TYPE_PHOTO,
    FBM_MPEG_TYPE_VIDEO,
    FBM_MPEG_TYPE_NS
}   FBM_MPEG_TYPE_T;

typedef struct
{
    FBM_MPEG_TYPE_T eFbmMpegType;

} FBM_ALLOC_PAR_T;
#endif

/*pending Q for NPTV fast change sequence*/
#define PEND_NS     (64)

typedef struct _B2R_NPTV_PENDING_ITEM
{
    BOOL    fgPending;
	UINT32  u4ItemSOC;
    UINT32  u4PendingWdith;
    UINT32  u4PendingHeight;
	BOOL    fgNeedCheck;
} B2R_NPTV_PENDING_ITEM;

typedef struct _B2R_NPTV_PENDING_Q
{
    UCHAR                  ucQSize;
    B2R_NPTV_PENDING_ITEM  atPendingQ[PEND_NS];
} B2R_NPTV_PENDING_Q;

/** Brief of FBM_POOL_T
 *  FBM Memory Pool Info
 */
typedef struct
{
    union
    {
        UPTR u4Addr;
        UINT64 padding;
    };
    UINT32 u4Size;
    UINT32 u4Mode;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4Inherit;
    BOOL fgAlloced;//temp flag for FBM_Alloc/Free
    FBM_POOL_TYPE_T ePoolType;// feeder use it.
#if (defined(CC_S_PLATFORM) || defined(CC_FBM_CONFIG_WITH_3DTV_4K_SUPPORT))
    FBM_MPEG_TYPE_T eFbmMpegType;
    #endif
} FBM_POOL_T;

#define FBM_LAT_POOL_ALLOC_MAX 2
#define FBM_LAT_POOL_UESED     0
#define FBM_LAT_POOL_BACKUP    (FBM_LAT_POOL_ALLOC_MAX-1)
typedef struct
{
    FBM_POOL_T *pLATPoolAlloc[FBM_LAT_POOL_ALLOC_MAX];
    union
    {
        UPTR u4Addr;
        UINT64 padding;
    };
    UINT32 u4Size;
}FBM_POOL_LAT_T;

#if defined(CC_ENABLE_CMA_SUPPORT)
typedef struct
{
    UPTR u4PhyAddr;
	UPTR u4PhyAlignAddr;
	UPTR u4VirtAddr;
    UPTR u4VirtAlignAddr;
    UINT32 u4Size;
	UINT8 u1ChNum;// 0 chA   1 chB  2 chC
} CMA_POOL_T;
#endif

typedef struct
{
    UINT8 u1AspectRatioType;
    UINT16 u2AspectHorizSize;
    UINT16 u2AspectVertSize;
} FBM_ASPECT_RATIO_T;

/** Brief of FBM_POOL_MODULE_INFO_T
 *  FBM Memory Pool Info
 */
typedef struct
{
    UINT32 u4SourceType;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4Interlace;
    UINT32 u4ColorFormat444;
    UINT32 u4VgaTiming;
    UINT32 u4PipPop;
    UINT32 u4Resolution;
} FBM_POOL_MODULE_INFO_T;

/**
 *  FBM internal buf
 */
typedef struct
{
    UCHAR ucBuf[254];
    UCHAR ucFbgId;
    UCHAR ucFbId;
} FBM_INTERNAL_BUF_T;

//Pool padding pattern
#define FBM_POOL_PADDING                             0xAA
#ifndef CC_SUPPORT_PHOTO8K
#define FBM_POOL_PADDING_SIZE                        0x0
#else
#define FBM_POOL_PADDING_SIZE                        0x0
#endif

// Frame Buffer Group Id
#define FBM_FBG_ID_UNKNOWN                           0xFF

#define FBM_FBG_ID_CONFLICT                          0xFB

// Frame Buffer Id
#define FBM_FB_ID_UNKNOWN                            0xFF
#define FBM_FB_ID_ALL                                0xFE

// Frame Buffer Group Type
#define FBM_FBG_TYPE_UNKNOWN                         0xFF
#define FBM_FBG_TYPE_1080HD                          0
#define FBM_FBG_TYPE_720HD                           1
#define FBM_FBG_TYPE_PAL                             2
#define FBM_FBG_TYPE_NTSC                            3
#define FBM_FBG_TYPE_DEFAULT                         4    // query use

#define FBM_FBG_TYPE_1080HD_RR                       17      // RR
#define FBM_FBG_TYPE_720HD_RR                        18      // RR
#define FBM_FBG_TYPE_PAL_RR                          19      // RR
#define FBM_FBG_TYPE_SBSHD                           21
#define FBM_FBG_TYPE_TNBHD                           22
#define FBM_FBG_TYPE_4K2K_JPEG                       25   //FBM_SUPPORT_4K2K
#define FBM_FBG_TYPE_4K1K_VIDEO                      26   //FBM_SUPPORT_4K2K
#define FBM_FBG_TYPE_4K2K                            27   //FBM_SUPPORT_4K2K
#define FBM_FBG_TYPE_4K2K_EXTRA                      28   //FBM_SUPPORT_4K2K
#define FBM_FBG_TYPE_8K                              29
#define FBM_FBG_TYPE_8K_JPEG                         30

// Frame Buffer Alignment
#define FBM_FMG_Y_ALIGMENT                          (8192 - 1)
#define FBM_FMG_C_ALIGMENT                          (8192 - 1)
#define FBM_MPV_Y_ALIGMENT                          (8192 - 1)
#define FBM_MPV_C_ALIGMENT                          (8192 - 1)
#define FBM_GFX_Y_ALIGMENT                          (8192 - 1)
#define FBM_GFX_C_ALIGMENT                          (8192 - 1)

#define FBM_VDEC_WORKING_ALIGNMENT                  (8192 - 1)

#define FBM_B2R_H_PITCH                             (64-1)
#define FBM_MPV_V_ALIGMENT                          (32-1)
#define FBM_VP9_MV_ALIGMENT                         (256-1)

// Frame Buffer Line Size
#define FBM_FBG_SBSHD_H                              3840
#define FBM_FBG_SBSHD_V                              1088
#define FBM_FBG_TNBHD_H                              1920
#define FBM_FBG_TNBHD_V                              2176
#define FBM_FBG_1080HD_V                             1088
#define FBM_FBG_1080HD_H                             1920
#define FBM_FBG_720HD_H                              1280
#define FBM_FBG_720HD_V                               768
#define FBM_FBG_PAL_H                                 768
#define FBM_FBG_PAL_V                                 576
#define FBM_FBG_NTSC_H                                768
#define FBM_FBG_NTSC_V                                480
#define FBM_FBG_4K2K_H                               4096   //FBM_SUPPORT_4K2K
#define FBM_FBG_4K2K_V                               2304    //??
#define FBM_FBG_2048_H                               2048
#define FBM_FBG_8K_H                                 8192
#define FBM_FBG_8K_V                                 4352

#define FBM_FBG_4K_JPEG_H                            3840
#define FBM_FBG_4K_JPEG_V                            2176
#define FBM_FBG_8K_JPEG_H                           7680
#define FBM_FBG_8K_JPEG_V                           4352

#define FBM_FBG_1440_V                             1472
#define FBM_FBG_2560_H                             2560

#define FBM_NORMAL_FB_NS                              5 // 4, for b2r lock 2 fb,add 1!
#define FBM_DBK_FB_NS                                 5

#define FBM_LOCK_FB_NS                                (2)


// H.264 Reference Information
#define FBM_FBG_H264_MVC_FHD_REFERNCE_NS            (8)     // Reference Frame Number for 1920x1088
#define FBM_FBG_H264_MVC_REFERNCE_MAX_NS            (32)

#ifdef CC_FBM_SUPPORT_4K2K
#define FBM_FBG_H264_FHD_REFERNCE_NS                (9)     // Reference Frame Number for 1920x1088
#define FBM_FBG_H265_FHD_REFERNCE_NS                (9)     // Reference Frame Number for 1920x1088
#else
#define FBM_FBG_H264_FHD_REFERNCE_NS                (6)     // Reference Frame Number for 1920x1088
#define FBM_FBG_H265_FHD_REFERNCE_NS                (6)     // Reference Frame Number for 1920x1088

#endif

#define FBM_FBG_VP9_REFERNCE_NS                     (11)

#define FBM_FBG_VP9_4K_REFERENCE_NS                 (4)


#define FBM_FBG_H264_REFERNCE_MAX_NS                (16)
#define FBM_FBG_H264_4K2K_REFERNCE_NS               (6)     // Reference Frame Number for 4k2k
#define FBM_FBG_H265_4K2K_REFERNCE_NS               (6)     // Reference Frame Number for 4k2k

#define FBM_FBG_TYPE_1080HD_H264_R_NS            (FBM_FBG_H264_FHD_REFERNCE_NS)
#define FBM_FBG_TYPE_720HD_H264_R_NS             ((FBM_FBG_1080HD_H * FBM_FBG_1080HD_V * FBM_FBG_H264_FHD_REFERNCE_NS)/(1280 * 720))
#define FBM_FBG_TYPE_PAL_H264_R_NS               ((FBM_FBG_1080HD_H * FBM_FBG_1080HD_V * FBM_FBG_H264_FHD_REFERNCE_NS)/(FBM_FBG_PAL_H * FBM_FBG_PAL_V))

#define FBM_FBG_TYPE_1080HD_H265_R_NS            (FBM_FBG_H265_FHD_REFERNCE_NS)
#define FBM_FBG_TYPE_720HD_H265_R_NS             ((FBM_FBG_1080HD_H * FBM_FBG_1080HD_V * FBM_FBG_H265_FHD_REFERNCE_NS)/(1280 * 720))
#define FBM_FBG_TYPE_PAL_H265_R_NS               ((FBM_FBG_1080HD_H * FBM_FBG_1080HD_V * FBM_FBG_H265_FHD_REFERNCE_NS)/(FBM_FBG_PAL_H * FBM_FBG_PAL_V))




// Frame Buffer Size
#define FBM_FBG_TYPE_SBSHD_Y_SIZE                    FBM_ALIGN_MASK((FBM_FBG_SBSHD_H * FBM_FBG_SBSHD_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_SBSHD_C_SIZE                    FBM_ALIGN_MASK((FBM_FBG_TYPE_SBSHD_Y_SIZE >> 1),FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_TNBHD_Y_SIZE                    FBM_ALIGN_MASK((FBM_FBG_TNBHD_H * FBM_FBG_TNBHD_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_TNBHD_C_SIZE                    FBM_ALIGN_MASK((FBM_FBG_TYPE_TNBHD_Y_SIZE >> 1),FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_1080HD_Y_SIZE                    FBM_ALIGN_MASK((FBM_FBG_1080HD_H * FBM_FBG_1080HD_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_1080HD_C_SIZE                    FBM_ALIGN_MASK((FBM_FBG_TYPE_1080HD_Y_SIZE >> 1),FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_720HD_Y_SIZE                     FBM_ALIGN_MASK((FBM_FBG_720HD_H * FBM_FBG_720HD_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_720HD_C_SIZE                     FBM_ALIGN_MASK((FBM_FBG_TYPE_720HD_Y_SIZE >> 1),FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_PAL_Y_SIZE                       FBM_ALIGN_MASK((FBM_FBG_PAL_H * FBM_FBG_PAL_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_PAL_C_SIZE                       FBM_ALIGN_MASK((FBM_FBG_TYPE_PAL_Y_SIZE >> 1), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_NTSC_Y_SIZE                      FBM_ALIGN_MASK((FBM_FBG_NTSC_H * FBM_FBG_NTSC_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_NTSC_C_SIZE                      FBM_ALIGN_MASK((FBM_FBG_TYPE_NTSC_Y_SIZE >> 1), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_4K2K_Y_SIZE                      FBM_ALIGN_MASK((FBM_FBG_4K2K_H * FBM_FBG_4K2K_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_4K2K_C_SIZE                      FBM_ALIGN_MASK((FBM_FBG_TYPE_4K2K_Y_SIZE>>1), FBM_FMG_Y_ALIGMENT)  //FBM_SUPPORT_4K2K;C size will *2 in FBM_ConfigColorMode if 422 mode!
#define FBM_FBG_TYPE_4K1K_Y_SIZE                      FBM_FBG_TYPE_SBSHD_Y_SIZE   // FOR 4K1K VIDEO
#define FBM_FBG_TYPE_4K1K_C_SIZE                      FBM_FBG_TYPE_SBSHD_C_SIZE  //FBM_SUPPORT_4K2K
#define FBM_FBG_TYPE_8K_Y_SIZE                        FBM_ALIGN_MASK((FBM_FBG_8K_H * FBM_FBG_8K_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_8K_C_SIZE                        FBM_ALIGN_MASK((FBM_FBG_TYPE_8K_Y_SIZE>>1), FBM_FMG_Y_ALIGMENT)

#define FBM_FBG_JPEG_4K2K_Y_SIZE                      FBM_ALIGN_MASK((FBM_FBG_4K_JPEG_H * FBM_FBG_4K_JPEG_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_JPEG_4K2K_C_SIZE                      FBM_ALIGN_MASK((FBM_FBG_JPEG_4K2K_Y_SIZE>>1), FBM_FMG_Y_ALIGMENT)  //  4K photo w*h seting for capri us
#define FBM_FBG_JPEG_8K_Y_SIZE                        FBM_ALIGN_MASK((FBM_FBG_8K_JPEG_H * FBM_FBG_8K_JPEG_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_JPEG_8K_C_SIZE                        FBM_ALIGN_MASK((FBM_FBG_JPEG_8K_Y_SIZE>>1), FBM_FMG_Y_ALIGMENT)  //  8K photo w*h seting for capri us



#define FBM_FBG_TYPE_2560_Y_SIZE                    FBM_ALIGN_MASK((FBM_FBG_2560_H * FBM_FBG_1440_V), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_2560_C_SIZE                    FBM_ALIGN_MASK((FBM_FBG_TYPE_2560_Y_SIZE >> 1), FBM_FMG_Y_ALIGMENT)
#define FBM_FBG_TYPE_CABAC_SIZE                                         FBM_ALIGN_MASK(0x140000,FBM_FMG_C_ALIGMENT) // error table buffer:(2304/16*32) = 5K
#define FBM_FBG_TYPE_2048_Y_SIZE                    FBM_ALIGN_MASK((FBM_FBG_2048_H * FBM_FBG_1080HD_V), FBM_FMG_Y_ALIGMENT)
//cabac info buffer :(4096/16)*tile_number*896 = 2M
//tile_number = 16
//1.25M *2
//Extra 2 MB row buffer for B pic deblocking (field pic need 4 MB row)
#define FBM_TWO_MB_ROW_V                                                64

#define FBM_SBSHD_Y_EXTRA_SIZE                        FBM_ALIGN_MASK((FBM_FBG_SBSHD_H * FBM_TWO_MB_ROW_V), FBM_MPV_Y_ALIGMENT)
#define FBM_TBNHD_Y_EXTRA_SIZE                        FBM_ALIGN_MASK((FBM_FBG_TNBHD_H * FBM_TWO_MB_ROW_V), FBM_MPV_Y_ALIGMENT)
#define FBM_1080HD_Y_EXTRA_SIZE                       FBM_ALIGN_MASK((FBM_FBG_1080HD_H * FBM_TWO_MB_ROW_V), FBM_MPV_Y_ALIGMENT)
#define FBM_720HD_Y_EXTRA_SIZE                        FBM_ALIGN_MASK((FBM_FBG_720HD_H * FBM_TWO_MB_ROW_V), FBM_MPV_Y_ALIGMENT)
#define FBM_PAL_Y_EXTRA_SIZE                          FBM_ALIGN_MASK((FBM_FBG_PAL_H * FBM_TWO_MB_ROW_V), FBM_MPV_Y_ALIGMENT)
#define FBM_NTSC_Y_EXTRA_SIZE                         FBM_ALIGN_MASK((FBM_FBG_NTSC_H * FBM_TWO_MB_ROW_V), FBM_MPV_Y_ALIGMENT)
#define FBM_1080HD_C_EXTRA_SIZE                       FBM_ALIGN_MASK((FBM_1080HD_Y_EXTRA_SIZE>>1),FBM_MPV_C_ALIGMENT)
#define FBM_720HD_C_EXTRA_SIZE                        FBM_ALIGN_MASK((FBM_720HD_Y_EXTRA_SIZE>>1),FBM_MPV_C_ALIGMENT)
#define FBM_PAL_C_EXTRA_SIZE                          FBM_ALIGN_MASK((FBM_PAL_Y_EXTRA_SIZE>>1),FBM_MPV_C_ALIGMENT)
#define FBM_NTSC_C_EXTRA_SIZE                         FBM_ALIGN_MASK((FBM_NTSC_Y_EXTRA_SIZE>>1),FBM_MPV_C_ALIGMENT)

#define FBM_1080HD_EXTRA_SIZE                         (FBM_1080HD_Y_EXTRA_SIZE + FBM_1080HD_C_EXTRA_SIZE)
#define FBM_720HD_EXTRA_SIZE                          (FBM_720HD_Y_EXTRA_SIZE + FBM_720HD_C_EXTRA_SIZE)
#define FBM_PAL_EXTRA_SIZE                            (FBM_PAL_Y_EXTRA_SIZE + FBM_PAL_C_EXTRA_SIZE)
#define FBM_NTSC_EXTRA_SIZE                           (FBM_NTSC_Y_EXTRA_SIZE + FBM_NTSC_C_EXTRA_SIZE)

//MPEG4/VC1 working buffer size
#define FBM_WORK_BUF_SIZE                             (1152 * 1024)

//VP9 Start
#define FBM_WORK_BUF_VP9_FHD_SIZE                     (300 * 1024)

#define FBM_WORK_BUF_VP9_4K2K_SIZE                    (1024 * 1024 * 3 / 2)

#define FBM_WORK_BUF_VP9_MISC_TBL_SIZE                (0x49000)

#define FBM_WORK_BUF_VP9_ALL_SIZE  (((FBM_FBG_TYPE_CABAC_SIZE)<<2) + ((FBM_WORK_BUF_VP9_FHD_SIZE) <<1))

// V9 End

// Frame Buffer Group Size

#define FBM_FBG_TYPE_1080HD_H264_B_NS                                   4
#define FBM_FBG_TYPE_1080HD_H264_B_64M_NS                               3

// Size = (R + B) * (Y Size +C Size) + (R + 1) * (Y Size/4)
#define FBM_FBG_TYPE_1080HD_H264_FB_SIZE                                (((FBM_FBG_TYPE_1080HD_Y_SIZE * (FBM_FBG_TYPE_1080HD_H264_R_NS + FBM_FBG_TYPE_1080HD_H264_B_NS))  * 3) >> 1)
#define FBM_FBG_TYPE_1080HD_H264_MV_SIZE                                ((FBM_FBG_TYPE_1080HD_Y_SIZE * (FBM_FBG_TYPE_1080HD_H264_R_NS + 1)) >> 2)
//#define FBM_FBG_TYPE_1080HD_H264_SIZE                                   (FBM_FBG_TYPE_1080HD_H264_FB_SIZE + FBM_FBG_TYPE_1080HD_H264_MV_SIZE)

#define FBM_FBG_TYPE_1080HD_H264_FB_64M_SIZE                            (((FBM_FBG_TYPE_1080HD_Y_SIZE * (FBM_FBG_TYPE_1080HD_H264_R_NS + FBM_FBG_TYPE_1080HD_H264_B_64M_NS))  * 3) >> 1)
#define FBM_FBG_TYPE_1080HD_H264_64M_SIZE                               (FBM_FBG_TYPE_1080HD_H264_FB_64M_SIZE + FBM_FBG_TYPE_1080HD_H264_MV_SIZE)
#define FBM_FBG_TYPE_1080HD_H264_64M_C_SIZE                             (((FBM_FBG_TYPE_1080HD_Y_SIZE * (FBM_FBG_TYPE_1080HD_H264_R_NS + FBM_FBG_TYPE_1080HD_H264_B_64M_NS))) >> 1)


// size = (ref frame 12mb) + (decode frame+ two lock frame) + (ref frame + decoder)/4 ---> for motion vector

#if defined(DIVX_PLUS_CER) || defined(CC_NETFLIX_CE3_SUPPORT) || defined(CC_ENABLE_SEAMLESS_FOR_2D) || defined(CC_FBM_SUPPORT_FHD_SEAMLESS)
#ifndef CC_ENABLE_SEAMLESS_FOR_2D
#define CC_ENABLE_SEAMLESS_FOR_2D
#endif
#endif


#ifdef CC_H264_LV5_SUPPORT_SINGLE_POOL
#define FMB_EXTRA_FOR_SINGLE_H264_LV5 ((((FBM_FBG_H264_FHD_REFERNCE_NS_ONE_POOL - FBM_FBG_H264_FHD_REFERNCE_NS)*1920*1088*3)>>1) + (((FBM_FBG_H264_FHD_REFERNCE_NS_ONE_POOL - FBM_FBG_H264_FHD_REFERNCE_NS)*1920*1088)>>2))
#else
#define FMB_EXTRA_FOR_SINGLE_H264_LV5 (0)
#endif
#define FBM_FBG_TYPE_1080HD_VP9_SIZE ((((FBM_FBG_VP9_REFERNCE_NS)*FBM_FBG_TYPE_1080HD_Y_SIZE*3)>>1) + (FBM_WORK_BUF_VP9_ALL_SIZE))
#define FBM_FBG_TYPE_720HD_VP9_SIZE ((((FBM_FBG_VP9_REFERNCE_NS)*FBM_FBG_TYPE_720HD_Y_SIZE*3)>>1) + (FBM_WORK_BUF_VP9_ALL_SIZE))
#define FBM_FBG_TYPE_1080HD_H264_SIZE ((((FBM_FBG_TYPE_1080HD_H264_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_1080HD_Y_SIZE*3)>>1) + (((FBM_FBG_TYPE_1080HD_H264_R_NS+1)*FBM_FBG_TYPE_1080HD_Y_SIZE) >>2))
#define FBM_FBG_TYPE_1080HD_H264_C_SIZE ((((FBM_FBG_TYPE_1080HD_H264_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_1080HD_Y_SIZE)>>1) + ((FBM_FBG_TYPE_CABAC_SIZE)<<1))
#define FBM_FBG_TYPE_720HD_H264_SIZE  ((((FBM_FBG_TYPE_720HD_H264_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_720HD_Y_SIZE*3)>>1) + (((FBM_FBG_TYPE_720HD_H264_R_NS+1)*FBM_FBG_TYPE_720HD_Y_SIZE) >>2))
#define FBM_FBG_TYPE_720HD_H264_C_SIZE  (((((FBM_FBG_TYPE_720HD_H264_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_720HD_Y_SIZE)>>1)) + ((FBM_FBG_TYPE_CABAC_SIZE)<<1))
#define FBM_FBG_TYPE_PAL_H264_SIZE    ((((FBM_FBG_TYPE_PAL_H264_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_PAL_Y_SIZE*3)>>1) + (((FBM_FBG_TYPE_PAL_H264_R_NS+1)*FBM_FBG_TYPE_PAL_Y_SIZE) >>2))
#define FBM_FBG_TYPE_PAL_H264_C_SIZE    ((((FBM_FBG_TYPE_PAL_H264_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_PAL_Y_SIZE)>>1)+ ((FBM_FBG_TYPE_CABAC_SIZE)<<1))

#define FBM_FBG_TYPE_1080HD_H265_SIZE ((((FBM_FBG_TYPE_1080HD_H265_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_1080HD_Y_SIZE*3)>>1) + (((FBM_FBG_TYPE_1080HD_H265_R_NS+1)*FBM_FBG_TYPE_1080HD_Y_SIZE) >>2))
#define FBM_FBG_TYPE_1080HD_H265_C_SIZE ((((FBM_FBG_TYPE_1080HD_H265_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_1080HD_Y_SIZE)>>1) + ((FBM_FBG_TYPE_CABAC_SIZE)<<1))
#define FBM_FBG_TYPE_720HD_H265_SIZE  ((((FBM_FBG_TYPE_720HD_H265_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_720HD_Y_SIZE*3)>>1) + (((FBM_FBG_TYPE_720HD_H265_R_NS+1)*FBM_FBG_TYPE_720HD_Y_SIZE) >>2))
#define FBM_FBG_TYPE_720HD_H265_C_SIZE  (((((FBM_FBG_TYPE_720HD_H265_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_720HD_Y_SIZE)>>1)) + ((FBM_FBG_TYPE_CABAC_SIZE)<<1))
#define FBM_FBG_TYPE_PAL_H265_SIZE    ((((FBM_FBG_TYPE_PAL_H265_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_PAL_Y_SIZE*3)>>1) + (((FBM_FBG_TYPE_PAL_H265_R_NS+1)*FBM_FBG_TYPE_PAL_Y_SIZE) >>2))
#define FBM_FBG_TYPE_PAL_H265_C_SIZE    ((((FBM_FBG_TYPE_PAL_H265_R_NS+1+FBM_LOCK_FB_NS)*FBM_FBG_TYPE_PAL_Y_SIZE)>>1)+ ((FBM_FBG_TYPE_CABAC_SIZE)<<1))


#define FBM_FBG_TYPE_1080HD_H264_RR_FB_SIZE                             (FBM_FBG_TYPE_1080HD_H264_FB_SIZE >> 1)
#define FBM_FBG_TYPE_1080HD_H264_RR_SIZE                                   (FBM_FBG_TYPE_1080HD_H264_RR_FB_SIZE + FBM_FBG_TYPE_1080HD_H264_MV_SIZE)

#define FBM_FBG_TYPE_1080HD_H264_RR_FB_64M_SIZE                         (FBM_FBG_TYPE_1080HD_H264_FB_64M_SIZE >> 1)
#define FBM_FBG_TYPE_1080HD_H264_RR_64M_SIZE                            (FBM_FBG_TYPE_1080HD_H264_RR_FB_64M_SIZE + FBM_FBG_TYPE_1080HD_H264_MV_SIZE)
#define FBM_FBG_TYPE_1080HD_H264_RR_64M_C_SIZE                           (FBM_FBG_TYPE_1080HD_H264_64M_C_SIZE >> 1)

#define FBM_FBG_TYPE_PAL_H264_RR_FB_SIZE                                   (FBM_FBG_TYPE_PAL_H264_FB_SIZE >> 1)
#define FBM_FBG_TYPE_PAL_H264_RR_SIZE                                      (FBM_FBG_TYPE_PAL_H264_RR_FB_SIZE + FBM_FBG_TYPE_PAL_H264_MV_SIZE)


#define FBM_FBG_TYPE_1080HD_SIZE                                        (((FBM_FBG_TYPE_1080HD_Y_SIZE * (FBM_NORMAL_FB_NS*3))>>1) + FBM_WORK_BUF_SIZE)
#define FBM_FBG_TYPE_1080HD_C_TOTAL_SIZE                                ((FBM_FBG_TYPE_1080HD_Y_SIZE * (FBM_NORMAL_FB_NS))>>1)
#define FBM_FBG_TYPE_720HD_SIZE                                         (FBM_FBG_TYPE_720HD_Y_SIZE * ((FBM_NORMAL_FB_NS*3)>>1))
#define FBM_FBG_TYPE_720HD_C_TOTAL_SIZE                                 ((FBM_FBG_TYPE_720HD_Y_SIZE * FBM_NORMAL_FB_NS)>>1)
#define FBM_FBG_TYPE_PAL_SIZE                                           (FBM_FBG_TYPE_PAL_Y_SIZE * ((FBM_NORMAL_FB_NS*3)>>1))
#define FBM_FBG_TYPE_PAL_C_TOTAL_SIZE                                   ((FBM_FBG_TYPE_PAL_Y_SIZE * FBM_NORMAL_FB_NS)>>1)
#define FBM_FBG_TYPE_NTSC_SIZE                                          (FBM_FBG_TYPE_NTSC_Y_SIZE * ((FBM_NORMAL_FB_NS*3)>>1))
#define FBM_FBG_TYPE_1080HD_3FB_SIZE                                    ((FBM_FBG_TYPE_1080HD_Y_SIZE * 9) /2)
#define FBM_FBG_TYPE_720HD_3FB_SIZE                                     ((FBM_FBG_TYPE_720HD_Y_SIZE * 9) /2)
#define FBM_FBG_TYPE_PAL_3FB_SIZE                                       ((FBM_FBG_TYPE_PAL_Y_SIZE * 9) /2)
#define FBM_FBG_TYPE_PAL_2_5FB_SIZE                                     ((FBM_FBG_TYPE_PAL_Y_SIZE * 15) /4)

#define FBM_FBG_TYPE_1080HD_1_5FB_SIZE                                  (FBM_FBG_TYPE_1080HD_3FB_SIZE / 2)
#define FBM_FBG_TYPE_1080HD_2_FB_SIZE                                   (FBM_FBG_TYPE_1080HD_Y_SIZE * 3)

#define FBM_FBG_TYPE_1080HD_VOMX_ARGB_NS                                (4)
#define FBM_FBG_TYPE_1080HD_VOMX_ARGB_SIZE                              (FBM_FBG_TYPE_1080HD_Y_SIZE * 4) * (FBM_FBG_TYPE_1080HD_VOMX_ARGB_NS + 1)
#define FBM_FBG_TYPE_1080HD_VOMX_NV12_NS                                (4)
#define FBM_FBG_TYPE_1080HD_VOMX_NV12_SIZE                              (FBM_FBG_TYPE_1080HD_Y_SIZE * 3 / 2) * (FBM_FBG_TYPE_1080HD_VOMX_ARGB_NS)


#define FBM_FBG_TYPE_4K2K_JPEG_SIZE                                     (FBM_FBG_JPEG_4K2K_Y_SIZE*2*2) // 2 frame,422 mode.  this is for 4k2k jpeg!!!//FBM_SUPPORT_4K2K
#define FBM_FBG_TYPE_4K2K_JPEG_C_SIZE                                   ((FBM_FBG_JPEG_4K2K_Y_SIZE*2*2)/2)
#define FBM_FBG_TYPE_4K2K_MPEG_SIZE                                     (FBM_FBG_TYPE_1080HD_H264_SIZE*4)
#define FBM_FBG_TYPE_4K2K_1FB_SIZE                                      (FBM_FBG_TYPE_4K2K_JPEG_SIZE/2)
#define FBM_FBG_TYPE_4K2K_1FB_C_SIZE                                    (FBM_FBG_TYPE_4K2K_1FB_SIZE/2)
#define FBM_FBG_TYPE_2K_PHOTO_1FB_C_SIZE                                (FBM_ALIGN_MASK((FBM_FBG_1080HD_H * FBM_FBG_1080HD_V), FBM_FMG_Y_ALIGMENT))
#define FBM_FBG_TYPE_2K_PHOTO_1FB_SIZE                                  (FBM_FBG_TYPE_2K_PHOTO_1FB_C_SIZE*2)
#define FBM_FBG_TYPE_2K_PHOTO_2FB_SIZE                                  (FBM_FBG_TYPE_2K_PHOTO_1FB_SIZE*2)
#define FBM_FBG_TYPE_2K_PHOTO_2FB_C_SIZE                                (FBM_FBG_TYPE_2K_PHOTO_2FB_SIZE/2)




#define FBM_FBG_TYPE_4K2K_H264_MV_SIZE        ( (FBM_FBG_TYPE_4K2K_Y_SIZE) >> 2)
#define FBM_FBG_TYPE_4K2K_H264_FB_SIZE        (((FBM_FBG_TYPE_4K2K_Y_SIZE) * 3) >> 1)
#define FBM_FBG_TYPE_4K2K_H264_FB_NS          (FBM_FBG_H264_4K2K_REFERNCE_NS + FBM_LOCK_FB_NS + 1)//ref + stage fright lock + lock + decode
#define FBM_FBG_TYPE_4K2K_H264_TOTAL_SIZE     ((FBM_FBG_TYPE_4K2K_H264_FB_SIZE * FBM_FBG_TYPE_4K2K_H264_FB_NS) + \
                                               (FBM_FBG_TYPE_4K2K_H264_MV_SIZE * (FBM_FBG_H264_4K2K_REFERNCE_NS + 1)))
#define FBM_FBG_TYPE_4K2K_7FB_SIZE_PART1      (FBM_FBG_TYPE_4K2K_H264_FB_SIZE * (FBM_FBG_TYPE_4K2K_H264_FB_NS/2 + 1)) //TBD
#define FBM_FBG_TYPE_4K2K_7FB_SIZE_C_PART1    ((FBM_FBG_TYPE_4K2K_Y_SIZE >>1) * (FBM_FBG_TYPE_4K2K_H264_FB_NS/2 + 1)) //TBD
#define FBM_FBG_TYPE_4K2K_7FB_SIZE_PART2      (FBM_FBG_TYPE_4K2K_H264_TOTAL_SIZE - FBM_FBG_TYPE_4K2K_7FB_SIZE_PART1)
#define FBM_FBG_TYPE_4K2K_7FB_SIZE_C_PART2    ( (FBM_FBG_TYPE_4K2K_Y_SIZE >>1) * FBM_FBG_TYPE_4K2K_H264_FB_NS - FBM_FBG_TYPE_4K2K_7FB_SIZE_C_PART1)
#define FBM_FBG_TYPE_4K2K_H264_SIZE           (FBM_FBG_TYPE_4K2K_H264_TOTAL_SIZE) // 4 frame,422 mode.  this is for 4k2k jpeg!!!//FBM_SUPPORT_4K2K

/* VP9 */

#define FBM_FBG_TYPE_4K2K_VP9_MV_SIZE          ((FBM_FBG_TYPE_4K2K_Y_SIZE) >> 2)
#define FBM_FBG_TYPE_4K2K_VP9_FB_SIZE          (((FBM_FBG_TYPE_4K2K_Y_SIZE) * 3) >> 1)
#define FBM_FBG_TYPE_4K2K_VP9_FB_NS            (FBM_FBG_H264_4K2K_REFERNCE_NS + FBM_LOCK_FB_NS + 1 + 2)  // 11 FBs + 1(4K seamless)
#define FBM_FBG_TYPE_4K2K_VP9_TOTAL_SIZE       ((FBM_FBG_TYPE_4K2K_VP9_FB_SIZE * FBM_FBG_TYPE_4K2K_VP9_FB_NS) + (FBM_FBG_TYPE_4K2K_VP9_MV_SIZE * (1 + 1)))
#define FBM_FBG_TYPE_4K2K_SIZE_PART1           (FBM_FBG_TYPE_4K2K_VP9_FB_SIZE * (FBM_FBG_TYPE_4K2K_VP9_FB_NS/2 + 1)) //TBD
#define FBM_FBG_TYPE_4K2K_SIZE_C_PART1         ((FBM_FBG_TYPE_4K2K_Y_SIZE >>1) * (FBM_FBG_TYPE_4K2K_VP9_FB_NS/2 + 1)) //TBD
#define FBM_FBG_TYPE_4K2K_SIZE_PART2           (FBM_FBG_TYPE_4K2K_VP9_TOTAL_SIZE - FBM_FBG_TYPE_4K2K_SIZE_PART1)
#define FBM_FBG_TYPE_4K2K_SIZE_C_PART2         ( (FBM_FBG_TYPE_4K2K_Y_SIZE >>1) * FBM_FBG_TYPE_4K2K_VP9_FB_NS - FBM_FBG_TYPE_4K2K_SIZE_C_PART1)
#define FBM_FBG_TYPE_4K2K_VP9_SIZE             (FBM_FBG_TYPE_4K2K_VP9_TOTAL_SIZE) // 4 frame,422 mode.  this is for 4k2k jpeg!!!//FBM_SUPPORT_4K2K





// ES ID
#define FBM_VIN_ES_ID                                                4    // For Video Input Hardware, Mpeg 0~3
#define FBM_DV_ES_ID                                                 5    // For DV Hardware, Mpeg 0~3

// Frame Buffer Group Flag
#define FBM_FLAG_CLR_ALL                                             0xFFFFFFFF // Clear all flag
#define FBM_FLAG_DISP_READY                                          (1 << 0)   // Display Ready, video plane will get FB from queue
#define FBM_FLAG_RESET                                               (1 << 1)   // Reset corresponding FBG
#define FBM_FLAG_SEQ_CHG                                             (1 << 2)   // Sequence Header Change
#define FBM_FLAG_SKIP_PIC                                            (1 << 3)   // Skip one picture
#define FBM_FLAG_DIGEST_MODE                                         (1 << 4)   // Digest Mode, obsolete
#define FBM_FLAG_CLEAR_FRC_PRM                                       (1 << 5)   // After Mpv reset, ask vdp frc to reset prm
#define FBM_FLAG_DEINTERLACE                                         (1 << 6)   // Deinterlace, add one more frame buffer
#define FBM_FLAG_NOT_READY                                           (1 << 7)   // No FB status change in this mode
#define FBM_FLAG_THREE_B                                             (1 << 8)   // 3 B pics between two Ref pics in this sequence
#define FBM_FLAG_DISPLAYING                                          (1 << 9)   // Video plane displaying
#define FBM_FLAG_ES_FIFO_FULL                                        (1 << 10)  // MPEG Elementary Stream's FIFO Full
#define FBM_FLAG_FREEZE                                              (1 << 14)  // MPEG should still decode, if no empty fb, get fb from display Q
#define FBM_FLAG_SKIP_PIC_NO_PTS                                     (1 << 15)  // Skip one picture with PTS = 0
#define FBM_FLAG_DEBLOCKING                                          (1 << 16)  // Deblocking mode
#define FBM_FLAG_REDUCE_REF                                          (1 << 17)  // Reduce Reference mode
#define FBM_FLAG_RELEASE_FBG                                         (1 << 18)  // Release FBG
#define FBM_FLAG_SEEK_MODE                                           (1 << 19)  // MM seek mode
#define FBM_FLAG_SUPER_FREEZE                                        (1 << 20)  // middleware super freeze mode
#define FBM_FLAG_3D_SEQ_CHG                                          (1 << 21)  //3D state sequence change notify
#define FBM_FLAG_3D_ERROR_HANDLE_DISABLE                             (1 << 22)  // enable 3D error handling
#define FBM_FLAG_SEQ_CHG_SPEEDUP                                     (1 << 24)  // New Sequence header change, early notify start play to video path
#define FBM_FLAG_THUMBNAIL_MODE                                      (1 << 25)  // New Thumbnail mode without VDP.
#define FBM_FLAG_AUTO_RENDER                                         (1 << 26)  // FBG without render path, need auto consume dispQ FB.
#define FBM_FLAG_ADJUST_FPS                                          (1 << 27)  // Notify B2R this video has a better render fps

//Wfd Ajust STC Flag
#define FBM_WFD_FRAME_MONITOR                                         (1 << 0)
#define FBM_WFD_FRAME_COUNTING                                        (1 << 1)

// Picture Coding Type
#define MPEG_PIC_TYPE_I                                              1
#define MPEG_PIC_TYPE_P                                              2
#define MPEG_PIC_TYPE_B                                              3

// Picture Structure
#define MPEG_PIC_TOP_FIELD                                           1
#define MPEG_PIC_BOTTOM_FIELD                                        2
#define MPEG_PIC_FRAME                                               3
#define MPEG_PIC_FIELD                                               4


// Frame Rate Code
#define MPEG_FRAME_RATE_24_                                          1    // minus
#define MPEG_FRAME_RATE_24                                           2
#define MPEG_FRAME_RATE_25                                           3
#define MPEG_FRAME_RATE_30_                                          4    // minus
#define MPEG_FRAME_RATE_30                                           5
#define MPEG_FRAME_RATE_50                                           6
#define MPEG_FRAME_RATE_60_                                          7    // minus
#define MPEG_FRAME_RATE_60                                           8
#define MPEG_FRAME_RATE_12                                           9
#define MPEG_FRAME_RATE_15                                           10    // minus
#define MPEG_FRAME_RATE_20                                           11
#define MPEG_FRAME_RATE_120_                                         12
#define MPEG_FRAME_RATE_120                                          13
#define MPEG_FRAME_RATE_240_                                         14
#define MPEG_FRAME_RATE_240                                          15
#define MPEG_FRAME_RATE_100                                          16
#define MPEG_FRAME_RATE_12_                                          17
#define MPEG_FRAME_RATE_48_                                          18
#define MPEG_FRAME_RATE_48                                           19
#define MPEG_FRAME_RATE_5                                            20
#define MPEG_FRAME_RATE_10                                           21
#define MPEG_FRAME_RATE_UNKNOWN                                      0xFF

// Aspect Ratio
#define MPEG_ASPECT_RATIO_1_1          1   // SAR, 1:1
#define MPEG_ASPECT_RATIO_4_3          2   // DAR, 4:3
#define MPEG_ASPECT_RATIO_16_9         3   // DAR, 16:9
#define MPEG_ASPECT_RATIO_221_1        4   // DAR, 2.21:1

#define MPEG_ASPECT_RATIO_10_11        5 // SAR, 10:11
#define MPEG_ASPECT_RATIO_40_33        6 // SAR, 40:33
#define MPEG_ASPECT_RATIO_16_11        7 // SAR, 16:11
#define MPEG_ASPECT_RATIO_12_11        8 // SAR, 12:11
#define MPEG_ASPECT_RATIO_3_2          9 // SAR 3:2
#define MPEG_ASPECT_RATIO_24_11       10 // SAR 24:11
#define MPEG_ASPECT_RATIO_20_11       11 // SAR 20:11
#define MPEG_ASPECT_RATIO_32_11       12 // SAR 32:11
#define MPEG_ASPECT_RATIO_80_33       13 // SAR 80:33
#define MPEG_ASPECT_RATIO_18_11       14 // SAR 18:11
#define MPEG_ASPECT_RATIO_15_11       15 // SAR 15:11
#define MPEG_ASPECT_RATIO_64_33       16 // SAR 64:33
#define MPEG_ASPECT_RATIO_160_99      17 // SAR 160:99
#define MPEG_ASPECT_RATIO_TRANSMIT    18

//Duration
#define MPEG_DURATION_24_           1877
#define MPEG_DURATION_25            1800
#define MPEG_DURATION_30_           1502
#define MPEG_DURATION_30            1500

// Colour Primary
#define MPEG_COLOR_PRIMARY_709                                       1

// Frame Rate
#define FBM_FRAME_RATE_UNKNOWN                                       0xFF
#define FBM_FRAME_RATE_5                                             5
#define FBM_FRAME_RATE_10                                            10
#define FBM_FRAME_RATE_24                                            24
#define FBM_FRAME_RATE_25                                            25
#define FBM_FRAME_RATE_30                                            30
#define FBM_FRAME_RATE_48                                            48
#define FBM_FRAME_RATE_50                                            50
#define FBM_FRAME_RATE_60                                            60
#define FBM_FRAME_RATE_12                                            12
#define FBM_FRAME_RATE_15                                            15
#define FBM_FRAME_RATE_20                                            20
#define FBM_FRAME_RATE_100                                           100
#define FBM_FRAME_RATE_120                                           120
#define FBM_FRAME_RATE_240                                           240


// Frame Buffer Color Mode
#define FBM_CM_UNKNOWN                                               0xFF
#define FBM_CM_420                                                   0
#define FBM_CM_422                                                   1
#define FBM_CM_444                                                   2
#define FBM_CM_422C                                                  8
#define FBM_CM_YUV24                                                 12
#define FBM_CM_RGB24                                                 13
#define FBM_CM_YUV32                                                 14
#define FBM_CM_RGB32                                                 15
#define FBM_CM_DEFAULT                                               FBM_CM_420

// Frame Buffer Status
#define FBM_FB_STATUS_UNKNOWN                                        0xFF
#define FBM_FB_STATUS_EMPTY                                          0
#define FBM_FB_STATUS_DECODE                                         1
#define FBM_FB_STATUS_READY                                          2
#define FBM_FB_STATUS_DISPLAYQ                                       3
#define FBM_FB_STATUS_LOCK                                           4
#define FBM_FB_STATUS_DIGEST                                         5
#define FBM_FB_STATUS_FIELD_READY                                    6
#define FBM_FB_STATUS_RESIZE                                         7
#define FBM_FB_STATUS_RESIZE_DONE                                    8
#define FBM_FB_STATUS_RECYCLE                                        9

// Number of Pan Scan Vector
#define FBM_PANSCAN_VECTOR_NS                                        3

//Active format
#define ACT_FMT_DEFAULT                                              0x8

//MT539x Video decoder format
#define FBM_VDEC_UNKNOWN                                             0xFF
#define FBM_VDEC_H264                                                0x1
#define FBM_VDEC_MPEG2                                               0x2
#define FBM_VDEC_MPEG4                                               0x3
#define FBM_VDEC_VC1                                                 0x4
#define FBM_VDEC_JPEG                                                0x5
#define FBM_VDEC_RV                                                  0x6
#define FBM_VDEC_AVS                                                 0x7
#define FBM_VDEC_RAW                                                 0x8
#define FBM_VDEC_VP6                                                 0x9
#define FBM_VDEC_VP8                                                 0xA
#define FBM_VDEC_H265                                                0xB
#define FBM_VDEC_VP9                                                 0xC
#define FBM_VDEC_MJPEG                                               0xD
#define FBM_VDEC_AVS2                                                0xE
#define FBM_VDEC_AV1                                                 0xF



typedef struct
{
    UCHAR  ucType;   // UHD FHD HD PAL case
    UINT32 u4VDecFmt; // H265 H264 VP9....
    UINT32 u4Size;    /* request total size */
    UINT32 u4CTotalSizeInCHB;/* Total C size In CHB y/c seperate using it. and according to reference calculate size */
} FBP_MAP_LIST_T;


#define FBM_C_SIZE_IN_CHB  (FBM_FBG_TYPE_1080HD_C_SIZE + (FBM_FBG_TYPE_1080HD_C_SIZE>>8))  // FB+UFO
#define FBM_H265_C_TOTAL_SIZE_IN_CHB  FBM_ALIGN_MASK((((FBM_FBG_H265_FHD_REFERNCE_NS+1+2)*(((FBM_C_SIZE_IN_CHB*5)>>2) + 0x2000))), FBM_FMG_Y_ALIGMENT)
#define FBM_H264_C_TOTAL_SIZE_IN_CHB FBM_ALIGN_MASK((((FBM_FBG_H264_FHD_REFERNCE_NS+1+2)*(((FBM_C_SIZE_IN_CHB*5)>>2) + 0x2000))), FBM_FMG_Y_ALIGMENT)
#define FBM_VP9_C_TOTAL_SIZE_IN_CHB FBM_ALIGN_MASK((((FBM_FBG_VP9_REFERNCE_NS)*(((FBM_C_SIZE_IN_CHB*5)>>2) + 0x2000))), FBM_FMG_Y_ALIGMENT)

//FBM flag for MM
#define FBM_MM_EOS_FLAG                                              (1 << 0)
#define FBM_MM_SYNC_POINT_FLAG                                       (1 << 1)
#define FBM_MM_NOT_DISPLAY_FLAG                                      (1 << 2)
#define FBM_MM_PSEUDO_EOS_FLAG                                       (1 << 3)
#define FBM_MM_3D_CHG_FLAG                                           (1 << 4)
#define FBM_MM_BACKWARD_FLAG                                         (1 << 5) // only valid when EOS flag is on

// FBM Picture Header ucTrueZeroPTS
#define FBM_USE_ZERO_PTS_IF_ZERO    0x1
#define FBM_USE_LAST_PTS_IF_ZERO    0x0

// FBG Play mode
#define FBM_FBG_DTV_MODE        0
#define FBM_FBG_MM_MODE         1
#define FBM_FBG_NOTDISPLAY_MODE 2
#define FBM_FBG_MODE_NS         3

// Application Mode
#define FBM_FBG_APP_NORMAL          (0)
#define FBM_FBG_APP_MHP             (1)
#define FBM_FBG_APP_OMX             (2)
#define FBM_FBG_APP_SKYPE           (3)
#define FBM_FBG_APP_VP6_ALPHA       (4)
#define FBM_FBG_APP_Frame_Pack_3D   (5)
#define FBM_FBG_APP_OMX_DISP        (6)
#define FBM_FBG_APP_MTIMAGE         (7)
#define FBM_FBG_APP_DOLBY           (8)
#define FBM_FBG_APP_OMX_DOLBY       (9)


// Vdec profile
#define FBM_H264_LV5_PROFILE        (1 << 0)

// FBG AV sync mode
#define FBM_FBG_AVSYNC_DISABLE        0
#define FBM_FBG_AVSYNC_STC_INVALID    1
#define FBM_FBG_AVSYNC_WAIT_1ST       2
#define FBM_FBG_AVSYNC_RESERVE        3
#define FBM_FBG_AVSYNC_NORMAL         4
#define FBM_FBG_AVSYNC_REPEAT         5
#define FBM_FBG_AVSYNC_DROP           6
#define FBM_FBG_AVSYNC_PTS_JITTER     7
#define FBM_FBG_AVSYNC_NO_PTS         8
#define FBM_FBG_AVSYNC_UNKNOWN        9


/* FBM global flag, not related to FBG index */
#define FBM_FLAG_FB_NO_TIMEOUT        (UINT8)(1 << 0)  // FB wait not timeout
#define FBM_FLAG_FB_DECODE_ONLY       (UINT8)(1 << 1)  //

#define FBM_IMG_RESIZE_LIMITATION (112)
#define FBM_IMG_RESIZE_LIMITATION_MAX (1920)
#define FBM_IMG_RESIZE_NETFLIX_WIDTH (1280)
#define FBM_IMG_RESIZE_NETFLIX_HEIGHT (720)

//B2R 3D ERROR Detectation
#define B2R_3D_ERROR_COUNT (15)
#define B2R_3D_ERROR_RECOVER_COUNT (15)

//B2R 3D Type
#define B2R_3D_NONE (0)
#define B2R_3D_FRAME_SEQUENTIAL (1)
#define B2R_3D_SIDE_BY_SIDE_REAL_D (2)
#define B2R_3D_SIDE_BY_SIDE (3)
#define B2R_3D_TOP_N_BOTTOM (4)

#define B2R_3D_SUB_TYPE_NONE	(0)
#define B2R_3D_SUB_TYPE_BIVL	(1)

#define B2R_3D_MODE_ALWAYS_L_VIEW (1)
#define B2R_3D_MODE_AUTO_TOGGLE (2)
#define B2R_3D_MODE_MANUAL_SET (3)

//B2R Trick Mode Type
#define B2R_3D_TRICK_MODE_L_VIEW (0)
#define B2R_3D_TRICK_MODE_R_VIEW (1)
#define B2R_3D_TRICK_MODE_3D_VIEW (2)


//B2R force 2d type
#define B2R_FORCE_2D_L_VIEW (0)
#define B2R_FORCE_2D_R_VIEW (1)

//B2R option define
//#define B2R_SD_TEST
#define CC_NETFLIX_SUPPORT
//#define CC_B2R_ENABLE_SEAMLESS_THREAD
//#define CC_B2R_ENALBE_OUTPUT_FRC
//#define CC_B2R_DISABLE_PTS_IIR
//#define CC_B2R_FORCE_UPDATE_STC

//#define CC_B2R_3D_MVC_INTERLACE_SUPPORT
#define CC_B2R_DISABLE_ONE_SECOND_FRC
//#define CC_B2R_GFX_COPY_FIELD
//#define FBM_VIRTUAL_MPEG
//#define MAIN_SUB_OPEN
//#define CC_B2R_3D_SUPPROT
//#define VDP_AVS_ADJUST_STC
#define VERIFICATION_REALD  (FALSE)
#define CC_B2R_ENABLE_CHG_FRAME_MSG

#define FBM_DI_HYBRID_WIDTH     3840
#define FBM_DI_PIP_FIFO_WIDTH  1920
#define FBM_DI_POP_FIFO_WIDTH  960

#ifndef __MODEL_slt__
#define CC_B2R_WAIT_NPTV_STABLE
#endif


// Frame Buffer Pool Configuration
#ifdef CC_2HD_SYSTEM
// Maximum frame buffer group number
#define FBG_MAX_NS                  10

#elif defined (CC_1HD_1SD_SYSTEM)
// Maximum frame buffer group number
#define FBG_MAX_NS                  7

#elif defined (CC_1SD_SYSTEM)
// Maximum frame buffer group number
#define FBG_MAX_NS                  3

#else
// Maximum frame buffer group number
#define FBG_MAX_NS                  10
#endif

// Decoder puts this ascii into put buffer
#define FBG_INTERNAL_VOMX_BUFFER_ID    "FBG_INTERNAL_VOMX_BUFFER"
#define FBG_INTERNAL_VOMX_BUFFER_SIZE  (20)

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

typedef struct _VDP_CHAPTER_T
{
    UINT64      u8StartPts;
    UINT64      u8EndPts;
    BOOL        fgIsPending;
    BOOL        fgIsSetEndPts;
    BOOL        fgPending;
    BOOL        fgFirstSetChapter;
} VDP_CHAPTER_T;

//3D infromation update structure
typedef struct
{
    UINT8 u1B2R3DType;
    UINT8 u1B2RForce2DType;
    BOOL fgB2R3DEnable;
    BOOL fgB2RForce2D;
    UINT32 u4B2R3DWidthOffset;
    UINT32 u4B2R3DHeightOffset;
} FBM_3D_INFO_T;

typedef enum
{
    FBM_SM_NO_SWAP,
    FBM_SM_SWAP0,
    FBM_SM_MAX
} FBM_SWAP_MODE_T;

typedef enum
{
    FBM_LM_RASTER,
    FBM_LM_TILE,
    FBM_LM_MAX
} FBM_LSB_MODE_T;

typedef enum
{
    FBM_PM_NORMAL,
    FBM_PM_COMPACT,
    FBM_PM_UNPACK,
    FBM_PM_PACK,
    FBM_PM_MAX
} FBM_PACK_MODE_T;

typedef enum
{
    FBM_DOLBY_NONE = 0,
    FBM_DOLBY_SINGLE = 1,
    FBM_DOLBY_MEL = 1 << 1,
    FBM_DOLBY_DUAL = 1 << 2
} FBM_DOLBY_TYPE_T;

typedef enum
{
    FBM_IM_ONE_ADDR,
    FBM_IM_TWO_ADDR,
    FBM_IM_MAX
} FBM_INTERLACE_MODE_T;

typedef enum
{
    FBM_SEQ_CHG_QUE_STATUS_UNKWOWN,
    FBM_SEQ_CHG_QUE_STATUS_USED,
    FBM_SEQ_CHG_QUE_STATUS_USING,
    FBM_SEQ_CHG_QUE_STATUS_WILLUSE,
    FBM_SEQ_CHG_QUE_STATUS_MAX
} FBM_SEQ_CHG_QUE_STATUS_T;

typedef enum
{
    FBM_FBG_DOLBY_TYPE_NONE,
    FBM_FBG_DOLBY_TYPE_MAIN,
    FBM_FBG_DOLBY_TYPE_SUB
}FBM_FBG_DOLBY_TYPE;

typedef enum
{
    FBM_SEQ_360VIDEO_OUTPUT_FORMAT_UNKNOWN,
    FBM_SEQ_360VIDEO_OUTPUT_FORMAT_RGB,
    FBM_SEQ_360VIDEO_OUTPUT_FORMAT_NV12
}FBM_SEQ_360VIDEO_OUTPUT_FORMAT_T;

typedef struct
{
    BOOL   fgCropping;
    BOOL   fgRaster;
    UCHAR  ucBlockType;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4Pitch;
    UINT32 u4CropX;
    UINT32 u4CropY;
    UINT32 u4CropWidth;
    UINT32 u4CropHeight;
}FBM_PIC_POSTPROCESS_OUTPUT_T;

typedef struct
{
    UINT32 u4VUIHDRContent;
    UINT32 u4SEIHDRContent;
}FBM_HDR_TYPE_DETECT_INFO_T;

typedef enum
{
    FBM_FBG_DOLBY_DM_TYPE_NONE,
    FBM_FBG_DOLBY_DM_TYPE_ATSC,
    FBM_FBG_DOLBY_DM_TYPE_DVB,
    FBM_FBG_DOLBY_DM_TYPE_AV1,
}FBM_DOLBY_DM_TYPE;


/** Brief of FBM_SEQ_HDR_T
 *  Sequence & GOP Header Structure
 */
typedef struct
{
    BOOL fgLoadIntraMatrix;                         // load_intra_quantizer_matrix;
    BOOL fgLoadNonIntraMatrix;                      // load_non_intra_quantizer_matrix;
    BOOL fgProgressiveSeq;                          // progressive_sequence
    BOOL fgClosedGop;
    BOOL fgBrokenLink;
    BOOL fgYRatio34;
    BOOL fgCRatio34;
    BOOL fgRRYEn;
    BOOL fgRRCEn;
    BOOL fgNoOverScan;
    BOOL fgColorDescrip;
    BOOL fgNoPts;
    BOOL fgRasterOrder;
    BOOL fgB2R3DEnable;
    BOOL fgB2RForce2D;
    BOOL fg422Mode;
    BOOL fgRealDEnhance;                            // RealD enhancement
    BOOL fgPixelAspectRatio;
    BOOL fgSwDecoder;
    BOOL fgUfoEn;
    BOOL fgJumpModeEn;
    BOOL fgSeamlessPlay;
    BOOL fgNptvSmlStatusFlush;

    UCHAR ucBlockType;
    UCHAR ucAspRatInf;                              // aspect_ratio_information
    UCHAR ucOrgAsp;
    UCHAR ucFrmRatCod;                              // frame_rate_code
    UCHAR ucCrmaFmt;                                // chroma_format;
    UCHAR ucColourPrimaries;
    UCHAR ucTransCharacter;
    UCHAR ucMatrixCoeff;
    HDR_COLOR_PRIMARIES_E eColourPrimaries;
    EOTF_E eEotf;
    MATRIX_COEFFICIENTS_E eMatrixCoeff;
    UCHAR ucActFmt;                                 //active_format;
    UCHAR ucHours;
    UCHAR ucMinutes;
    UCHAR ucSeconds;
    UCHAR ucPictures;
    UINT8 u1B2R3DType;
    UINT8 u1B2R3DSubType;
    UINT8 u1B2RForce2DType;
    UINT8 u1B2R3DTrickModeType;
    UINT8 u1Depth;

    UINT16 u2DHS;                                 // display_horizontal_size in Sequence display extension
    UINT16 u2DVS;                                 // display_vertical_size in Sequence display extension

    UINT32 u4BitRatVal;                             // bit_rate_value;
    UINT32 u4LastPTS;                               //record the last PTS
    UINT32 u4Duration;
    UINT32 u4FrmCropTop;
    UINT32 u4FrmCropBtm;
    BOOL   bAspectRatioPresentFlag;
    UINT32 u4AspectRatioWidth;
    UINT32 u4AspectRatioHeight;
    UINT32 u4OrgAspWidth;
    UINT32 u4OrgAspHeight;
    UINT32 u4YAddrOffset;
    UINT32 u4CAddrOffset;
    UINT32 u4B2R3DWidthOffset;
    UINT32 u4B2R3DHeightOffset;
    UINT32 u4DispDirection;
    UINT32 u4AspectRatioIdc;
    UINT32 eSeamlessMode;
    UINT32 u4HDRContent;
    UINT32 u4PendingSOC;

    //cropping info
    BOOL fgCropping;
    UINT32 u4CropX;
    UINT32 u4CropY;
    UINT32 u4CropWidth;
    UINT32 u4CropHeight;
    UINT32 u4resolutionChg;
    UINT32 u4ChgPreStatus;
    //w/h info
    UINT32 u4SourceWidth;   //source width
    UINT32 u4SourceHeight;  //source height
    UINT32 u4TargetWidth;   //seamless target width
    UINT32 u4TargetHeight;  //seamless target height
    UINT32 u4ResizeWidth;   //seamless width with aspect ratio info
    UINT32 u4ResizeHeight;  //seamless height with aspect ratio info
    UINT32 u4PicPitch;      //picture pitch

    UINT64 u8LastPTS;                               //record the last PTS

    FBM_PACK_MODE_T ePackMode;
    FBM_SWAP_MODE_T eSwapMode;
    FBM_LSB_MODE_T  eLsbMode;
    FBM_INTERLACE_MODE_T eIntlaceMode;
    FBM_SEQ_CHG_QUE_STATUS_T eSeqChqQueStatus;
    FBM_HDR_TYPE_DETECT_INFO_T HdrTypeDetectInfo;
    FBM_PIC_POSTPROCESS_OUTPUT_T rPPOutput;
    HDRSRC_PROFILE_T rHDRInfo;
    FBM_DOLBY_TYPE_T eDolbyType;
    BOOL fgRpuBuffer;
    BOOL fgHdrBuffer;
    UINT32 u4TimeScale;
    FBM_DOLBY_DM_TYPE eDolbyDMType;
    FBM_SEQ_360VIDEO_OUTPUT_FORMAT_T eOutputModeFor360Video;
    FBM_COLOR_SPACE_ID eColorSpace;
    FBM_VDEC_FMT_T eCodecType;
} FBM_SEQ_HDR_T;
typedef struct
{
    UCHAR  ucNewFb;
	UCHAR  ucPicId;
	UINT32 u4PTS;
	FBM_SEQ_HDR_T rPendingSeqHdr;
}FBM_SeqChg_T;

typedef struct
{
    UCHAR  ucReadIdx;
    UCHAR  ucCount;
    FBM_SeqChg_T aucSeqChgQue[FBM_MAX_FB_NS_PER_GROUP];
} FBM_SEQ_CHG_QUE_T;


// This structure must be same with VDEC_PIC_EXTRA_INFO_T
/** Brief of FBM_PIC_EXTRA_HDR_T
 *  Picture Header Structure
 */
typedef struct
{
    BOOL fgValid;

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

//ruv info
typedef struct
{
    BOOL fgRvuInterlace;
    BOOL fgItop;  //1, top is I, 0,top is Bottom
    BOOL fgIsInterlaceI;
} FBM_RVU_INFO_T;

/*
  * The QP value of each layer
  */
typedef struct
{
    INT32 i4PPSLayerQp;
    INT32 i4SliceLayerQp;
    INT32 i4MBLayerQp;
    INT32 i4QpMin;
    INT32 i4QpMax;
}FBM_QP_VAL;

/*
 * Decoder info for sony
 */
typedef struct
{
    UINT8   u1PictureCodingType;
    UINT32  u4GeneratedBit;
    UINT8   u1ScalingListIntra[64];
    UINT8   u1ScalingListInter[64];
    UINT8   u1OddEven;
    UINT8   u1color_primaries;
    UINT8   u1transfer_characteristics;
    UINT8   u1matrix_coefficients;
    UINT8   u1UserData[128];
#if defined(CC_SUPPORT_TECHNICOLOR_HDR)&&defined(CC_SUPPORT_TECHNICOLOR_I)
    UINT16  u2Ba;
#endif

}FBM_DECODER_INFO_METER_T;

typedef struct
{
    UINT32 ui4MetadataInfoSize;
    UCHAR  u1Metadata[100];         ///< add by lihui.li for range type
    UINT32 ui4MetadataTimeStamp;
} HDR10PLUS_INFO_T;

typedef struct
{
    UINT8   uCountryCode;
    UINT16  u2ProviderCode;
    UINT16  u2OrientedCode;
    UINT8   uIdentifier;
    UINT8   uVersion;
    UINT8   uNumWindows;
    UINT16  u2WindowUpperLeftCornerX[3];
    UINT16  u2WindowUpperLeftCornerY[3];
    UINT16  u2WindowLowerRightCornerX[3];
    UINT16  u2WindowLowerRightCornerY[3];
    UINT16  u2CenterOfEllipseX[3];
    UINT16  u2CenterOfEllipseY[3];
    UINT8   uRotationAngle[3];
    UINT16  u2SemiMajorAxisInternalEllipse[3];
    UINT16  u2SemiMajorAxisExternalEllipse[3];
    UINT16  u2SemiMinorAxisExternalEllipse[3];
    UINT8   uOverlapProcessOption[3];

    UINT32  u4TargetSystemDisplayMaximumLuminance;
    BOOL    bTargetSystemDisplayActualPeakLuminanceFlag;
#if 1
    UINT8   uNumRowsTargetedSystemDisplayActualPeakLuminance;
    UINT8   uNumColsTargetedSystemDisplayActualPeakLuminance;
    UINT8   uTargetedSystemDisplayActualPeakLuminance[25][25];
#endif
    UINT32  u4Maxscl[3][3];
    UINT32  u4AverageMaxrgb[3];
    UINT8   uNumDistributionMaxrgbPercentiles[3];
    UINT8   uDistributionMaxrgbPercentages[3][15];
    UINT32  u4DistributionMaxrgbPercentiles[3][15];
    UINT16  u2FractionBrightPixels[3];

    BOOL    bMasteringDisplayActualPeakLuminanceFlag;
#if 1
    UINT8   uNumRowsMasteringDisplayActualPeakLuminance;
    UINT8   uNumColsMasteringDisplayActualPeakLuminance;
    UINT8   uMasteringDisplayActualPeakLuminance[25][25];
#endif
    BOOL    bToneMappingFlag[3];
    UINT16  u2KneePointX[3];
    UINT16  u2KneePointY[3];
    UINT8   uNumBezierCurveAnchors[3];
    UINT16  u2BezierCurveAnchors[3][15];
    BOOL    bColorSaturationMappingFlag[3];
    UINT8   uColorSaturationWeight[3];
}HDR10PLUS_METADATA_INFO_T;

typedef struct
{
    BOOL bHdr10Plus;
    HDR10PLUS_INFO_T   tHdr10PlusInfo;
    HDR10PLUS_METADATA_INFO_T   tHdr10PlusMetadataInfo;
}HDR10PLUS_SRC_PROFILE_T;

typedef struct {
    UINT8 uApplyGrain;
    UINT16 u2GrainSeed;
    UINT8 uUpdateGrain;
    UINT8 uFilmGrainParamsRefIdx;
    UINT8 uNumYPoints;
    UINT8 uPointYValue[14];
    UINT8 uPointYScaling[14];
    UINT8 uChromaScalingFromLuma;
    UINT8 uNumCbPoints;
    UINT8 uPointCbValue[10];
    UINT8 uPointCbScaling[10];
    UINT8 uNumCrPoints;
    UINT8 uPointCrValue[10];
    UINT8 uPointCrScaling[10];
    UINT8 uGrainScaling;
    UINT8 uArCoeffLag;
    INT32 i4ArCoeffsY[24];
    INT32 i4ArCoeffsCb[25];
    INT32 i4ArCoeffsCr[25];
    UINT8 uArCoeffShift;
    UINT8 uGrainScaleShift;
    UINT8 uCbMult;
    UINT8 uCbLumaMult;
    UINT16 u2CbOffset;
    UINT8 uCrMult;
    UINT8 uCrLumaMult;
    UINT16 u2CrOffset;
    UINT8 uOverlapFlag;
    UINT8 uClipToRestrictedRange;
    UINT8 uMcIdentity;
    UINT8 uBitDepth;
    UINT8 uMonochrome;
}FILM_GRAIN_METADATA_INFO_T;

typedef struct {
    BOOL bFilmGrain;
    FILM_GRAIN_METADATA_INFO_T tFilmGrainMetadataInfo;
} FILM_GRAIN_SRC_PROFILE_T;

/** Brief of FBM_PIC_HDR_T
 *  Picture Header Structure
 */
typedef struct
{
    UCHAR ucPicCdTp;
    UCHAR ucFullPelFordVec;
    UCHAR ucFordFCode;
    UCHAR ucFullPelBackVec;
    UCHAR ucBackFCode;
    UCHAR ucIntraDcPre;
    UCHAR ucPicStruct;
    UCHAR ucTrueZeroPTS; /* If set to 1, Not use last PTS if current is Zero */
    UCHAR ucSeamlessResizeFbid;
    UCHAR ucSeamlessResize2Fbid;
    UCHAR ucSeamlessTaskId;
	UCHAR ucPicId;
    UCHAR ucRzId;
    // for Gpu
    UCHAR ucGpuRzId;
    UCHAR ucSrcDepth;

    BOOL fgTopFldFirst;
    BOOL fgFrmPredFrmDct;
    BOOL fgConcMotionVec;
    BOOL fgQScaleType;
    BOOL fgIntraVlcFmt;
    BOOL fgAltScan;
    BOOL fgRepFirstFld;
    BOOL fgProgressiveFrm;
    BOOL fgSeamlessResized;
	BOOL fgPicFlush;  // TRUE:after flush,the first frame buffer for b2r nptv seamless using,defalt FALSE
    BOOL fgNotDisplay;
    BOOL fgBivl3DLR;
    BOOL fgPushModeTrick;
    BOOL fgUfoEn;

    //for image resizer (netflix and small resolution)
    BOOL fgSeamlessDisp;
    BOOL fgResizeDispFrm;
    BOOL fgDummyFrame;
    BOOL fgTrickTopField;
    BOOL fgSeqHeader;
    BOOL fgProgressive2Interlace;
    BOOL fgWFDTMSLogEnable;
    //for dash bandwidth change
    BOOL fgBandwidthChanged;
    BOOL fgWillSeqChg; // for VB1 seamless tell B2r will happen seq change after previous FB ;
    BOOL fgRVUSkip;
    BOOL fgIsTopField;

    UCHAR ucfcode[2][2];
    INT32 i4TemporalRef;
    UINT16 u2DecodingOrder;
    UINT16 au2HOffset[FBM_PANSCAN_VECTOR_NS];
    UINT16 au2VOffset[FBM_PANSCAN_VECTOR_NS];
    UINT64 u8MediaTimestamp;
    UINT32 u4TemiScale;
    UINT32 u4TemiRem;

    UINT64 u4PTS;                                   //  90 KHz PTS value, 33/32 bit ?
    UINT32 u4TimeScale;
    UINT32 u4QpAvg;
    UINT32 u4TotlaTimeOffset;
    UINT32 u4TickNum;
    UINT32 u4MmFlag;
    UINT32 u4Timestap;
    UINT32 u4PicSoc;
    UINT32 u4AddrOffset;

    UINT64 u8PTSInUs;
    UINT64 u8Offset;
    UINT64 u8OffsetDisp;
    UINT64 u8OffsetI;
    UINT64 u8_vid_pts;
    UINT64 u8_push_time;//ms
    HAL_TIME_T rTimePutDispQ;
    HAL_TIME_T rTimeB2rReleaseRzFB;
    HAL_TIME_T rTimeRzGetFB;
    HAL_TIME_T rTimeGotFBRzStart;
    HAL_TIME_T rTimeRzEnd;
    HAL_TIME_T rTimeB2rGotFB;
    HAL_TIME_T rTimeB2rReleaseFB;

    HAL_TIME_T rTimeHwS;
    HAL_TIME_T rTimeFromDecoder;

    BOOL fgCropping;
    UINT32 u4CropX;
    UINT32 u4CropY;
    UINT32 u4CropWidth;
    UINT32 u4CropHeight;
    //w/h info
    UINT32 u4SourceWidth;   //source width
    UINT32 u4SourceHeight;  //source height
    UINT32 u4TargetWidth;   //seamless target width
    UINT32 u4TargetHeight;  //seamless target height
    UINT32 u4ResizeWidth;   //seamless width with aspect ratio info
    UINT32 u4ResizeHeight;  //seamless height with aspect ratio info
    UINT32 u4PicPitch;      //picture pitch

    FBM_PIC_EXTRA_INFO_T rExtra;
    FBM_COLOR_SPACE_ID eColorSpace;
    FBM_QP_VAL  rQPVal;

	FBM_RVU_INFO_T rRvuInfo;
	//for sony to get decoder information.
    FBM_DECODER_INFO_METER_T rDecInfo;
    HDRSRC_PROFILE_T rHDRInfo;
    UINT32 u4RpuSize;
    union {
      UPTR u4RpuPhysicalAddr;
      UPTR u4HdrPhysicalAddr;
    };
    BOOL fgJumpModeEn;
	INT32	i4POC;

    // for hdr10+ info and debug
    HDR10PLUS_SRC_PROFILE_T  rHDR10PlusInfo;
    // for film grain info and debug
    FILM_GRAIN_SRC_PROFILE_T rFilmGrainInfo;

    UINT32 u4PicCnt;
    BOOL fgHdrBuffer;
    BOOL fgIsVpeek;

    BOOL fg422;
} FBM_PIC_HDR_T;

typedef struct
{
    UCHAR   ucFbgId;
    UCHAR   ucFbId;
    UPTR    u4BufferYAddr;
    UPTR    u4BufferCAddr;
    UINT64  u8Pts;
    BOOL    fgEos;
} FBM_PIC_OPERA_INFO_T;

/** Brief of FBM_PIC_NTF_INFO_T
 *  Picture Notify Infomation Structure
 */
typedef struct
{
    UCHAR   ucFbgId;
    UCHAR   ucFbId;
    BOOL    fgEos;
    FBM_FBG_DOLBY_TYPE eDolbyType;
} FBM_PIC_NTF_INFO_T;

typedef struct
{
    UINT8 u1VdpId;
    UINT8 u1B2rId;
    BOOL  b_change;
} B2R_CHG_INFO_T;

typedef struct
{
    BOOL  fgOmxSrc;
    UCHAR ucFbgId;
    UCHAR ucFbid;
} FB_CHG_INFO_T;

// FBM indication function
typedef VOID (*FBM_FBG_CHG_IND_FUNC)(UCHAR ucFbgId, UCHAR ucEsId);
typedef VOID (*FBM_PICSTRUCT_CHG_IND_FUNC)(UCHAR ucEsId, UCHAR ucPicStruct);
typedef VOID (*FBM_FB_READY_IND_FUNC)(FB_CHG_INFO_T *pt_fb);
//typedef VOID (*FBM_GFX_MEMSET_FUNC)(UINT8 *pu1Addr, UINT32 u4Size, UINT32 u4Color);
typedef VOID (*FBM_GFX_MEMSET_FUNC)(UINT8 *pu1Addr, UINT32 u4Width, UINT32 u4Height, UINT32 u4Color);
typedef UINT64 (*FBM_GFX_TASK_MEMSET_FUNC)(UINT8 *pu1Addr, UINT32 u4Width, UINT32 u4Height, UINT32 u4Color);
typedef UINT32 (*FBM_GFX_TASK_MEMSET_DONE_FUNC)(UINT64 u8TaskId);
typedef VOID (*FBM_CB_POOL_CHANGE_FUNC)(FBM_POOL_TYPE_T ePool);
typedef VOID (*FBM_FB_READY_IND_FUNC_EX)(UINT32 u4Tag, FBM_PIC_NTF_INFO_T *prPicNfy);
typedef BOOL (*FBM_FB_SEQ_CHG_PRE_FUNC)(UINT32 u4Tag);

typedef VOID* (*FBM_GDMA_MEMSET_FUNC)(VOID * s, UINT32 c , UINT32 n);
typedef UINT32 (*FBM_GDMA_TASK_MEMSET_FUNC)(VOID * s, UINT32 c , UINT32 n);
typedef UINT32 (*FBM_GDMA_TASK_MEMSET_DONE_FUNC)(UINT64 u8TaskId);

typedef INT32 (*FBM_B2R_RES_CHG_FUNC)(UCHAR ucFbgId, B2R_CHG_INFO_T* pt_change);

typedef VOID (*FBM_BLOCK2NV12_RESIZE_DONE)(UINT32 u4Tag, FBM_PIC_OPERA_INFO_T* rPicNfyInfo);

/** Brief of FBM_CB_FUNC_ENUM_T
 */
typedef enum
{
    FBM_CB_FUNC_FBG_CHG_IND,
    FBM_CB_FUNC_PICSTRUCT_CHG_IND,
    FBM_CB_FUNC_FB_READY_IND,
    FBM_CB_FUNC_GFX_MEMSET,
    FBM_CB_FUNC_POOL_CHANGE,
    FBM_CB_FUNC_FB_READY_EX_IND,
    FBM_CB_FUNC_FBG_CHG_EX_IND,
    FBM_CB_FUNC_GFX_TASK_MEMSET, //As 4K2K big pool memset take much long time, change async mode to memset.
    FBM_CB_FUNC_GFX_TASK_MEMSET_DONE, //Co-work with GFX_TASK_MEMSET, query task memset done or not
    FBM_CB_FUNC_SEQ_CHG_PRE_CB,  //Direct callback while FBM get seq chg info.
    FBM_CB_FUNC_GDMA_MEMSET,
    FBM_CB_FUNC_B2R_HW_CHG_CB,
    FBM_CB_FUNC_GDMA_TASK_MEMSET,
    FBM_CB_FUNC_GDMA_TASK_MEMSET_DONE,
    FBM_CB_FUNC_360_RESIZE_DONE,
    FBM_CB_FUNC_NS
} FBM_CB_FUNC_ENUM_T;

/** Brief of FBM_CB_FUNC_T
 *  FBM Call Back Function Structure
 */
typedef struct
{
    UPTR au4CbFunc[FBM_CB_FUNC_NS];
    UPTR au4CbFuncCRC[FBM_CB_FUNC_NS];
    UPTR aau4CbFunc[FBG_MAX_NS][FBM_CB_FUNC_NS];
    UPTR aau4CbFuncCRC[FBG_MAX_NS][FBM_CB_FUNC_NS];
    UPTR aau4CbFuncTag[FBG_MAX_NS][FBM_CB_FUNC_NS];
} FBM_CB_FUNC_T;

typedef enum
{
    FBM_FBG_MEMSET_1ST,
    FBM_FBG_MEMSET_ALL,
    FBM_FBG_MEMSET_NONE
}FBM_FBG_MEMSET_TYPE;


/** Brief of FBM_CREATE_FBG_PAR_T
 *  Create group parameter
 */
typedef struct
{
    UINT8 u1AppMode;
    UINT8 u1VdecProfile;
    UINT8 u1VdecId;
    BOOL fgThumbnailMode;
    BOOL fgCreateFromInst;
    BOOL fgSwHEVC;
    //Seamless Info
    UCHAR ucCftFbgId;
    UINT32 eSeamlessMode;
    UINT32 u4TargetW;
    UINT32 u4TargetH;
    BOOL fgUFO; /*TRUE: UFO,FALSE NOT UFO */
    BOOL fg10Bit; /*TRUE 10Bit,FALSE 8Bit */
    BOOL fgExternalAddr; // Not alloc Pool, FB addr set by external
    UINT8 u1RequestFbNs; // Set need FB Ns.
    BOOL fgIsSeamlessCft;
    BOOL fgIsGameMode;
    UINT8 u1RefNum;
    UINT8 u1Fps;
    BOOL fgRpuBuffer;
    BOOL fgHdrBuffer;
    FBM_FBG_MEMSET_TYPE u4FBMMemsetOption;
    FBM_FBG_DOLBY_TYPE eDolbyType;
    BOOL fgSecureBuf;
    BOOL fgNonBuf;
    BOOL fgTunnelMode;
    BOOL fgStillImage;
} FBM_CREATE_FBG_PAR_T;
#if 0
typedef struct
{
    UCHAR ucFbgType;
    UCHAR ucFbgId;
    UINT32 u4PoolSize;
    UINT32 u4YSize;
    UINT32 u4CSize;
    UPTR u4StartYAddr;
    UPTR u4StartCAddr;

}FBM_MV_PAR_T;

typedef struct
{
    UCHAR  ucFbgId;
    UCHAR  ucFbNs;
    UINT32 u4MajorBaseFbIdx;
    UINT32 u4MajorAddrY;
    UINT32 u4MajorAddrC;
    UINT32 u4FbStartPoolYAddr;
    UINT32 u4FbEndPoolYAddr;
    UINT32 u4FbStartPoolCAddr;
    UINT32 u4FbEndPoolCAddr;
    UINT32 u4FbStartPool2YAddr;
    UINT32 u4FbEndPool2YAddr;
    UINT32 u4FbStartPool2CAddr;
    UINT32 u4FbEndPool2CAddr;
} FBM_SEAMLESS_CFG_T;
#endif


typedef enum
{
    E_VDEC_CODEC_MPEG1,
    E_VDEC_CODEC_MPEG2,
    E_VDEC_CODEC_MPEG4_VISUAL,
    E_VDEC_CODEC_AVC,
    E_VDEC_CODEC_HEVC,
    E_VDEC_CODEC_AVS,
    E_VDEC_CODEC_XVID,
    E_VDEC_CODEC_VC1,
    E_VDEC_CODEC_REAL,
    E_VDEC_CODEC_VP8,
    E_VDEC_CODEC_MOTION_JPEG,
    E_VDEC_CODEC_JPEG,
    E_VDEC_CODEC_MPO,
    E_VDEC_CODEC_RAW,
    E_VDEC_CODEC_VP9,
    E_VDEC_CODEC_AVS2,
    E_VDEC_CODEC_AV1,
    E_VDEC_CODEC_UNKNOWN,
}   ENUM_CODEC_INFO_T;

typedef struct
{
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4OrgWidth;
    UINT32 u4OrgHeight;
} FBM_CODEC_RESOLUTION_T;



typedef enum
{
    FBM_FBID_TYPE_UNKWOWN,
    FBM_FBID_TYPE_MAJOR,
    FBM_FBID_TYPE_MINOR,
}   FBM_FBID_TYPE_T;

//---------------------------------------------------------------------------
// Macro definitions
//---------------------------------------------------------------------------

#define FBM_CHECK_CB_FUNC_VERIFY(func, crc)         ((UINT32)func == ~((UINT32)crc))


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


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

EXTERN VOID FBM_Init(VOID);

EXTERN UCHAR FBM_GetFbgNs(VOID);

EXTERN UCHAR FBM_SelectGroupType(UINT32 u4Width, UINT32 u4Height);

EXTERN UCHAR FBM_CreateGroupExt(UCHAR ucFbgType, UINT32 u4VDecFmt,
                                UINT32 u4HSize, UINT32 u4VSize, FBM_CREATE_FBG_PAR_T *prPar);

EXTERN VOID FBM_ReleaseGroup(UCHAR ucFbgId);

EXTERN VOID FBM_ResetGroup(UCHAR ucFbgId);


EXTERN VOID FBM_InvalidateRefFrameBuffer(UCHAR ucFbgId);

EXTERN VOID FBM_WaitUnlockFrameBuffer(UCHAR ucFbgId, UINT32 u4Timeout);


EXTERN VOID FBM_SetFrameBufferColor(UCHAR ucFbgId, UCHAR ucFbId, UINT32 u4Color);

EXTERN VOID FBM_SetFrameBufferZebraColor(UCHAR ucFbgId, UCHAR ucFbId);

EXTERN VOID FBM_SetFrameBufferFlag(UCHAR ucFbgId, UINT32 u4Flag);

EXTERN VOID FBM_SetRenderPts(UCHAR ucFbgId,UINT32 u4PTS);

EXTERN UCHAR FBM_ChkFrameBufferFlag(UCHAR ucFbgId, UINT32 u4Flag);

EXTERN UCHAR FBM_ChkFrameBufferFlagIsr(UCHAR ucFbgId, UINT32 u4Flag);

EXTERN VOID FBM_ClrFrameBufferFlag(UCHAR ucFbgId, UINT32 u4Flag);

EXTERN UCHAR FBM_ChkFrameBufferPicFlag(UCHAR ucFbgId, UCHAR ucFbId, UINT32 u4Flag);

EXTERN VOID FBM_SetFrameBufferPicFlag(UCHAR ucFbgId, UCHAR ucFbId, UINT32 u4Flag);

EXTERN VOID FBM_ClrFrameBufferPicFlag(UCHAR ucFbgId, UCHAR ucFbId, UINT32 u4Flag);

EXTERN UCHAR FBM_GetFrameBufferNs(UCHAR ucFbgId);

EXTERN UCHAR FBM_GetFrameBufferMvNs(UCHAR ucFbgId);

EXTERN VOID FBM_GetFrameBufferSize(UCHAR ucFbgId, UINT32 *pu4Width, UINT32 *pu4Height);

EXTERN UCHAR FBM_GetFrameBufferStatus(UCHAR ucFbgId, UCHAR ucFbId);

EXTERN UCHAR FBM_CheckFrameBufferStatus(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucFbStatus);
EXTERN UCHAR FBM_ChkFbDispTagInB2R(UCHAR ucFbgId, UCHAR ucFbId);

EXTERN void FBM_SetFrameBufferLayout(UCHAR ucFbgId, UCHAR ucFbId, UPTR u4Addr, BOOL fgIsY);

EXTERN VOID FBM_SetFrameBufferStatus(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucFbStatus);

#ifdef FBM_FB_LOG
EXTERN VOID FBM_SetFrameBufferStatus_dbg(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucFbStatus, const CHAR* sFunc, const UINT32 u4Line);

#define FBM_SetFrameBufferStatus(FbgId, FbId, Status) FBM_SetFrameBufferStatus_dbg(FbgId, FbId, Status, __func__, __LINE__)
EXTERN void FbmInitFbLog(void);
#endif

EXTERN VOID FBM_FlushLockFrameBuffer(UCHAR ucFbgId);

EXTERN UCHAR FBM_GetFrameBufferFromDispQ(UCHAR ucFbgId);

EXTERN UCHAR FBM_PreLookFrameBufferFromDispQ(UCHAR ucFbgId);

EXTERN UCHAR FBM_PreLookNthFBFromDispQ(UCHAR ucFbgId, UCHAR ucTheNth);

EXTERN UCHAR FBM_PreLook2ndFrameBufferFromDispQ(UCHAR ucFbgId);

EXTERN UCHAR FBM_ChkSeamlessMode(UCHAR ucFbgId, UINT32 u4Mode);
EXTERN UINT32 FBM_SetSeamlessMode(UCHAR ucFbgId, UINT32 u4Mode);
EXTERN UCHAR FBM_CheckFrameBufferDispQ(UCHAR ucFbgId);

EXTERN UINT32 FBM_GetNextDispQPts(UCHAR ucFbgId);

EXTERN UCHAR  FBM_CheckFbg(UCHAR ucFbgId);

EXTERN UCHAR FBM_CalFrmRate(UCHAR ucFbgId);

EXTERN VOID FBM_GetFrameBufferAtIsr(UCHAR ucFbgId, UPTR* pu4AddrY, UPTR* pu4AddrC);

EXTERN FBM_PIC_HDR_T *FBM_GetFrameBufferPicHdr(UCHAR ucFbgId, UCHAR ucFbId);

EXTERN FBM_SEQ_HDR_T *FBM_GetFrameBufferSeqHdr(UCHAR ucFbgId);
EXTERN FBM_SEQ_HDR_T *FBM_GetFrameBufferSeqHdrByB2R(UCHAR ucFbgId);
EXTERN FBM_SeqChg_T *FBM_GetLastSeqChgItem(UCHAR ucFbgId);

EXTERN VOID FbmPutToSeqChgQue(UCHAR ucFbgId, UCHAR ucFbId,FBM_SeqChg_T *pLastSeqChgItem);
EXTERN VOID FBM_GetFrameBufferAddr(UCHAR ucFbgId, UCHAR ucFbId, UPTR *pu4AddrY, UPTR *pu4AddrC);
EXTERN VOID FBM_GetFrameBufferAddrExt(UCHAR ucFbgId, UCHAR ucFbId, UPTR *pu4AddrYExt, UPTR *pu4AddrCExt);
EXTERN VOID FBM_GetFrameBufferAddrMv(UCHAR ucFbgId, UCHAR ucFbId, UPTR *pu4AddrMv);

EXTERN void FBM_GetWorkingBuffer(UCHAR ucFbgId, UPTR *pu4Addr, UINT32 *pu4Size);

EXTERN void FBM_GetExtraFrameBuffer(UCHAR ucFbgId, UPTR* pu4YAddr, UPTR* pu4CAddr);

EXTERN VOID FBM_QueryStatus(UCHAR ucFbgId);

EXTERN void FBM_DumpFB(UCHAR ucFbgId,UCHAR ucFbId);

EXTERN void FBM_DumpAllDispQFB(UCHAR ucFbgId);

EXTERN void FBM_SetDumpDir(const CHAR * dir);

EXTERN BOOL _FbmQueryFromEmptyQ(UCHAR ucFbgId,UCHAR ucChkFbId);

EXTERN BOOL _FbmQueryFromDisplayQ(UCHAR ucFbgId,UCHAR ucChkFbId);

EXTERN BOOL  FbmSetPauseType(UCHAR ucFbgId,UINT32 u4PauseType);
EXTERN BOOL  FbmStep(UCHAR ucFbgId,UINT32 u4Theshold);
EXTERN BOOL  FbmContinue(UCHAR ucFbgId);

#ifdef CC_VDEC_FBM_DYNAMIC_MAPPING
EXTERN VOID * FBM_WorkBufPartMap(UCHAR ucFbgId, UPTR u4Addr, UINT32 u4Size);
#endif

EXTERN void FBM_UpdateReferenceList(UCHAR ucFbgId, UCHAR ucFbId, BOOL fgReference);

EXTERN UCHAR FBM_GetDecFrameBuffer(UCHAR ucFbgId);

EXTERN VOID FBM_GetRefFrameBuffer(UCHAR ucFbgId, UCHAR* ucFRefFbId, UCHAR* ucBRefFbId);

EXTERN UCHAR FBM_GetEmptyRefFrameBuffer(UCHAR ucFbgId, UINT32 u4Delay);

EXTERN UCHAR FBM_GetEmptyBFrameBuffer(UCHAR ucFbgId, UINT32 u4Delay);

EXTERN UCHAR FBM_GetEmptyFrameBuffer(UCHAR ucFbgId, UINT32 u4Delay);

EXTERN UCHAR FBM_CanGetEmptyRefFrameBuffer(UCHAR ucFbgId);

EXTERN UCHAR FBM_CanGetEmptyBFrameBuffer(UCHAR ucFbgId);

EXTERN VOID FBM_SetFrameBufferPlayBackNs(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucPlayBackNs, UCHAR ucChangeFieldNs);

EXTERN UCHAR FBM_GetFrameBufferPlayBackNs(UCHAR ucFbgId, UCHAR ucFbId);

EXTERN UCHAR FBM_GetFrameBufferChangeFieldNs(UCHAR ucFbgId, UCHAR ucFbId);

EXTERN UCHAR FBM_ChkFrameBufferLastPlayBack(UCHAR ucFbgId, UCHAR ucFbId);

// This function is called back by mpeg decode to indicate that
// Frame buffer group ID is change. This function will by pass this notify
// to video plane drive
EXTERN VOID FBM_FbgChgNotify(UCHAR ucFbgId, UCHAR ucEsId);

EXTERN VOID FBM_PicStructChgNotify(UCHAR ucEsId, UCHAR ucPicStruct);

EXTERN VOID FBM_RegCbFunc(FBM_CB_FUNC_ENUM_T eFuncType, UPTR u4FuncPtr);
EXTERN VOID FBM_RegFbgCbFunc(UCHAR ucFbgId, FBM_CB_FUNC_ENUM_T eFuncType, UPTR u4FuncPtr, UINT32 u4Tag);

EXTERN FBM_CB_FUNC_T* FBM_GetCbFuncTbl(VOID);

// This function is implemented for mpeg error concealment, it will return FbId in
// display-q state or lock state
EXTERN UCHAR FBM_GetReadyFrameBuffer(UCHAR ucFbgId);

EXTERN VOID FBM_SetSyncStc(UCHAR ucFbgId, UCHAR ucMode, UCHAR ucStcId);

EXTERN VOID FBM_GetSyncStc(UCHAR ucFbgId, UCHAR* pucMode, UCHAR* pucStcId);

EXTERN void FBM_SetPlayMode(UCHAR ucFbgId, UCHAR ucPlayMode);
EXTERN void FBM_GetPlayMode(UCHAR ucFbgId, UCHAR* pucPlayMode);

EXTERN UINT8 FBM_GetDecoderSrcId(UCHAR ucFbgId);

EXTERN UINT8 FBM_GetFbgAppMode(UCHAR ucFbgId);


EXTERN void FBM_SetAVSyncStatus(UCHAR ucFbgId, UINT32 u4AVSyncStatus);

EXTERN void FBM_GetAVSyncStatus(UCHAR ucFbgId, UINT32* pu4AVSyncStatus);

EXTERN FBM_POOL_T *FBM_GetPoolInfo(UCHAR ucPoolType);

EXTERN FBM_POOL_T* FBM_GetPoolInfoAuto(UCHAR ucPoolType, const FBM_POOL_MODULE_INFO_T* pInfo);

EXTERN FBM_POOL_T* FBM_GetPoolMpeg(VOID);

EXTERN FBM_POOL_T* FBM_Alloc(UCHAR);

EXTERN VOID FBM_AllocLax(BOOL fgNeedAllocTwoLaxPool, FBM_POOL_LAT_T* prLatPoolAlloc);

EXTERN UINT32 FBM_FreeLax(FBM_POOL_LAT_T* prLatPoolAlloc);

#if (defined(CC_S_PLATFORM) || defined(CC_FBM_CONFIG_WITH_3DTV_4K_SUPPORT))
EXTERN FBM_POOL_T* FBM_AllocEx(FBM_TYPE_T eFbmType,FBM_ALLOC_PAR_T *prPar);

EXTERN BOOL FBM_Query(FBM_POOL_TYPE_T eFbmPoolType,FBM_ALLOC_PAR_T *prPar);
#endif

EXTERN UINT32 FBM_Free(FBM_POOL_T* pAllocedPool);

#if defined(CC_ENABLE_CMA_SUPPORT)
EXTERN CMA_POOL_T* CMA_GetPool(UCHAR ucPoolType);
EXTERN UINT32 CMA_FreePool(UCHAR ucPoolType);
EXTERN void CMA_QueryStatus(VOID);
EXTERN void CMA_Alloc(UCHAR ucPoolType, UCHAR u1ChNum, UINT32 u4Size);
EXTERN UINT32 CMA_Free(UCHAR ucPoolType);
#endif

EXTERN UCHAR FBM_GetPoolCurrent(UCHAR ucPoolType);

EXTERN VOID FBM_CheckPadding(VOID);
EXTERN VOID FBM_CheckBufferdefine(VOID);

EXTERN VOID FBM_ReleaseDispQ(UCHAR ucFbgId);

EXTERN void FBM_GetEmptyQCount(UCHAR ucFbgId, UCHAR* pucCount);

EXTERN UCHAR FBM_GetDbkSmallBFrameBuffer(UCHAR ucFbgId);

EXTERN UCHAR FBM_GetSyncMode(UCHAR ucFbgId);

EXTERN void FBM_SetFrameBufferFtrCnt(UCHAR ucFbgId, UCHAR ucFbId, UINT32 u4DbkOfStCnt, UINT32 u4Dbk4pCnt);

EXTERN VOID FBM_GetFrameBufferFtrCnt(UCHAR ucFbgId, UCHAR ucFbId, UINT32 *pu4DbkOfStCnt, UINT32 *pu4Dbk4pCnt);

EXTERN UCHAR FBM_GetDbkEmptyRefFrameBuffer(UCHAR ucFbgId, UINT32 u4Delay);

EXTERN INT32 FBM_ResetFbChangeField(UCHAR ucFbgId);

EXTERN INT32 FBM_WaitFbChangeField(UCHAR ucFbgId, UINT32 u4Timeout);

EXTERN VOID FBM_FbChangeField(UCHAR ucFbgId);
EXTERN void FBM_SetRenderEndFlag(UCHAR ucFbgId, BOOL flag);
EXTERN BOOL FBM_GetRenderEndFlag(UCHAR ucFbgId);
EXTERN void FBM_SetEOSFlag(UCHAR ucFbgId, UCHAR fbid, BOOL flag);
EXTERN BOOL FBM_GetEosFlag(UCHAR ucFbgId, UCHAR fbid);

EXTERN VOID FBM_SetFbNextFieldPlayBackNs(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucPlayBackNs);

EXTERN UCHAR FBM_GetFbNextFieldPlayBackNs(UCHAR ucFbgId, UCHAR ucFbId);

EXTERN void FBM_SetFrameBufferGlobalFlag(UCHAR ucFbgId, UINT8 ucFlag);
EXTERN UCHAR FBM_ChkFrameBufferGlobalFlagIsr(UCHAR ucFbgId, UINT8 ucFlag);
EXTERN void FBM_ClrFrameBufferGlobalFlag(UCHAR ucFbgId, UINT8 ucFlag);

EXTERN UINT32 FBM_GetVDecMemSize(UCHAR ucFbgId);
EXTERN UINT32 FBM_GetRunningVdecMemSize(UCHAR ucFbgId);

EXTERN UPTR  FBM_GetMiscMemAddr(UCHAR ucFbgId);

EXTERN BOOL FBM_ChkFbgCreateFromInst(UCHAR ucFbgId);
EXTERN void FBM_SetColorMode(UINT8 u1ColorMode);
EXTERN void FBM_SetDecoderFB(UINT8 u1DecoderType,UINT8 u1NumOfFB);

#ifdef FBM_VIRTUAL_DISPLAY
EXTERN VOID FBM_VirtualDispStart(UINT32 u4Delay, UINT32 u4VirtualDispPath);

EXTERN VOID FBM_VirtualDispStop(VOID);
#endif

#ifdef FBM_VIRTUAL_MPEG
EXTERN VOID FBM_VirtualMpegStart(UINT32 u4Delay, const CHAR* pcFile);
EXTERN VOID FBM_VirtualMpegStop(VOID);
EXTERN INT32 T32_HostExec(INT32 i4TargetFlag, const CHAR *szFormat, ...);
EXTERN VOID FBM_VirtualINTTest(VOID);
#endif

#ifdef FBM_FB_LOG
EXTERN VOID FBM_FlushFbLog(UINT8 u4FbIdx, UINT8 u4FbStatus);
#endif

#ifdef FBM_CS_LOG
EXTERN VOID FBM_FlushFbCsLog(void);
#endif

EXTERN void FBM_VdecMemProtect(UINT8 u1Mode, BOOL fgDBKDisable);

EXTERN CHAR* FBM_GetPoolName(UCHAR ucPoolType);
EXTERN UINT32 FBM_GetPoolSize(UCHAR ucPoolType);

EXTERN VOID FBM_SetSeqChgFbId(UCHAR ucFbgId, UCHAR ucFbId);
EXTERN BOOL FBM_InsertFB(UCHAR ucFbgId, UPTR u4Addr);
EXTERN UCHAR FBM_GetFreeFB(UCHAR ucFbgId);
EXTERN UCHAR FBM_GetDisplayFB(UCHAR ucFbgId);
EXTERN BOOL FBM_GetInsertFBCount(UCHAR ucFbgId, UINT32 *pu4Count);
EXTERN VOID FBM_GetFbByAddr(UPTR u4Addr, UCHAR *pucFbgId, UCHAR *pucFbId);
EXTERN BOOL FBM_ReleaseFBFlush(UCHAR ucFbgId);
EXTERN BOOL FBM_FlushEmptyBufToDispQ(UCHAR ucFbgId);

EXTERN void FBM_SetCodecInfo(UCHAR ucFbgId, ENUM_CODEC_INFO_T rCodecInfo);
EXTERN ENUM_CODEC_INFO_T FBM_GetCodecInfo(UCHAR ucFbgId);
EXTERN BOOL FBM_GetCodecResolution(UCHAR ucFbgId,FBM_CODEC_RESOLUTION_T* rResolution);
EXTERN BOOL FBM_Is10BitMode(UCHAR ucFbgId);


// New Seamless
EXTERN VOID FBM_TriggerSmlsByResizer(UCHAR ucFbgId, UCHAR ucFbId);
EXTERN UCHAR FBM_GetResizeFrameBufferNs(UCHAR ucFbgId);
EXTERN VOID FBM_GetResizeFrameBufferSize(UCHAR ucFbgId, UINT32 *pu4Width, UINT32 *pu4Height);
EXTERN UCHAR FBM_GetResizeFrameBufferStatus(UCHAR ucFbgId, UCHAR ucFbId);
EXTERN UCHAR FBM_CheckResizeFrameBufferStatus(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucFbStatus);
EXTERN VOID FBM_SetResizeFrameBufferStatus(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucFbStatus);
EXTERN VOID FBM_SetResize2FrameBufferStatus(UCHAR ucFbgId, UCHAR ucFbId, UCHAR ucFbStatus);
EXTERN VOID FBM_GetResizeFrameBufferAddr(UCHAR ucFbgId, UCHAR ucFbId, UPTR *pu4AddrY, UPTR *pu4AddrC);
EXTERN VOID FBM_GetResize2FrameBufferAddr(UCHAR ucFbgId, UCHAR ucFbId, UPTR *pu4AddrY, UPTR *pu4AddrC);
EXTERN UCHAR FBM_GetEmptyResizeFrameBuffer(UCHAR ucFbgId, UCHAR ucSrcFbId, UCHAR ucTaskId, UINT32 u4Delay, UCHAR* pucRetValue);
EXTERN UCHAR FBM_GetEmptyResize2FrameBuffer(UCHAR ucFbgId, UCHAR ucSrcFbId, UCHAR ucTaskId, UINT32 u4Delay, UCHAR* pucRetValue);
EXTERN BOOL FBM_SetResizeFrameBufferFlag(UCHAR ucFbgId, UCHAR ucFbId,
    UCHAR ucSetType,UINT32 u4Flag);
EXTERN BOOL FBM_SetResize2FrameBufferFlag(UCHAR ucFbgId, UCHAR ucFbId,
    UCHAR ucSetType,UINT32 u4Flag);

EXTERN void FBM_GetResizeEmptyQCount(UCHAR ucFbgId, UCHAR* pucCount);
EXTERN BOOL FBM_IsSeamlessFB(UCHAR ucFbgId, UCHAR ucFbId);

void FBM_SetWfdFrameBufferFlag(UCHAR ucFbgId, UINT32 u4Flag);

INT32 FBM_ChkWfdFrameBufferFlag(UCHAR ucFbgId, UINT32 u4Flag);

void FBM_ClrWfdFrameBufferFlag(UCHAR ucFbgId, UINT32 u4Flag);

void FBM_AccumulateWfdFrameCnt(UCHAR ucFbgId);

UINT32 FBM_WfdFrameStatistics(UCHAR ucFbgId);

EXTERN BOOL FBM_SetDispTag(UCHAR ucFbgId, UCHAR ucFbId,UINT64 u4Tag);
EXTERN VOID FBM_SetTagQValid(BOOL fgValid);
EXTERN BOOL FBM_GetFbByDispTag(UINT64 u4Tag, UCHAR *pucFbgId, UCHAR *pucFbId);
EXTERN BOOL FBM_GetFbByDispTag_Ex(UINT64 u4Tag, UCHAR *pucMainFbgId, UCHAR *pucMainFbId,UCHAR *pucSubFbgId, UCHAR *pucSubFbId);
EXTERN BOOL FBM_QueryFbByDispTag(UINT64 u4Tag, UCHAR *pucFbgId, UCHAR *pucFbId);
EXTERN BOOL FBM_ReleaseBufferByDispTag(UINT64 u4Tag);
EXTERN VOID FBM_ReleaseBufferByIndex(UCHAR ucFbgId, UCHAR ucFbId);
EXTERN UCHAR FBM_GetFbgByEs(UCHAR ucEsId);
EXTERN BOOL FBM_QueryLastFrameBuffer(UCHAR ucFbgId,UCHAR ucFbIdx);
EXTERN UINT32 FBM_GetVideoCodecType(UCHAR ucFbgId);
EXTERN VOID FBM_MemReset(VOID *pAddr, UINT32 u4Data, UINT32 u4Size);
EXTERN VOID _FBM_PostProcess_OutputInfo(UCHAR u4FbgId,FBM_SEQ_HDR_T* prFbmSeqHdr,FBM_PIC_POSTPROCESS_OUTPUT_T *pOutParam);

#ifdef CC_B2R_RES_SUPPORT
EXTERN UINT8 FBM_B2rResIdAccess(UCHAR ucFbgId,
                                UINT32 u4Mask,
                                B2R_IPT_INFO_T* pt_src);
#endif

EXTERN VOID FBM_B2RNTPVSavePendingItem(UCHAR ucFbgId,B2R_NPTV_PENDING_ITEM t_pending_item);
EXTERN VOID FBM_B2RNTPVRemovePendingItem(UCHAR ucFbgId,B2R_NPTV_PENDING_ITEM* pt_pending_item);
EXTERN VOID FBM_B2RNTPVGetPendingQSize(UCHAR ucFbgId,UCHAR* pucQsize);
EXTERN VOID FBM_B2RNTPVGetFirstPendingInfo(UCHAR ucFbgId,B2R_NPTV_PENDING_ITEM* pt_pending_item);
EXTERN VOID FBM_B2RNTPVClrPendingQ(UCHAR ucFbgId);

#ifdef CC_FBM_4K_SEAMLESS_NOT_SUPPORT
EXTERN VOID  FBM_GetSeamlessBuffer(UPTR* pu4Addr,UINT32* pu4Size);
EXTERN VOID  FBM_ReleaseSeamlessBuffer(UPTR u4Addr);
#endif

typedef enum
{
    SEAMLESS_NONE        = 0,           //None Seamless
    SEAMLESS_ONE_FBS     = (1<<1),      //Seamless with one FBs, Limitation is >ref 4 wll seamless fail.
    SEAMLESS_TWO_FBS     = (1<<2),      //Seamless with two FBs. Limitation is StageFright currenlty can't handle the FB Ns change.

    SEAMLESS_2FBS_1POOL  = SEAMLESS_TWO_FBS | (1<<3),      //Seamless with two FBs. with only MPEG 1 pool, conflict FB while seq chg.
    SEAMLESS_2FBS_2POOL  = SEAMLESS_TWO_FBS | (1<<4),      //Seamless with two FBs. with 2 pools. Make sure no multi instance while seq chg.

    SEAMLESS_BY_RESIZER  = (1<<5),      //Seamless by resizer.
    SEAMLESS_BY_NPTV     = (1<<6),      //Seamless by NPTV. Developing now. Limitation is 3D can't seamless by NPTV. and need add 4FB for prepare for NPTV.

    SEAMLESS_ONE_RESIZER = SEAMLESS_BY_RESIZER | (1<<7),      //Seamless with one resizer
    SEAMLESS_TWO_RESIZER = SEAMLESS_BY_RESIZER | (1<<8),      //Seamless with two resizer. Currently for 4K2K only.
    SEAMLESS_BY_VB1      = (1<<9),      // Seamlee by VB1
    SEAMLESS_BY_NONTUNNEL_NPTV     = (1<<10), // Android non-tunnel mode NPTV seamlss
    POST_PROCESS_DISPLAY_ROTATE    = (1 << 11),   // use pre-scale flow do rotate
    POST_PROCESS_SMALL_IMAGE_SCALE = (1 << 12),
    POST_PROCESS_360VIDEO          = (1 << 13),
    POST_PROCESS_SEAMLESS          = (SEAMLESS_BY_NPTV | SEAMLESS_BY_RESIZER | SEAMLESS_BY_VB1 | SEAMLESS_BY_NONTUNNEL_NPTV),
    POST_PROCESS_BEFORE_B2R        = (POST_PROCESS_DISPLAY_ROTATE | SEAMLESS_BY_RESIZER),
    POST_PROCESS_ENABLE            =  (SEAMLESS_BY_RESIZER | SEAMLESS_BY_NPTV | SEAMLESS_BY_VB1 | SEAMLESS_BY_NONTUNNEL_NPTV | POST_PROCESS_DISPLAY_ROTATE)
} FBM_SEAMLESS_MODE;


/* FBM calculated-once size table - begin */
typedef enum
{
    FBM_TYPE_MAIN_PIP_MODE_1080I,
    FBM_TYPE_MAIN_PIP_MODE_576I,
    FBM_TYPE_MAIN_PIP_MODE_1080P_422,
    FBM_TYPE_MAIN_PIP_MODE_1080P_444,
    FBM_TYPE_SUB_PIP_MODE_1080I,
    FBM_TYPE_SUB_PIP_MODE_576I,
    FBM_TYPE_SUB_PIP_MODE_1080P_422,
    FBM_TYPE_SUB_PIP_MODE_1080P_444,
    FBM_TYPE_MAIN_POP_MODE_1080I,
    FBM_TYPE_MAIN_POP_MODE_576I,
    FBM_TYPE_MAIN_POP_MODE_1080P_422,
    FBM_TYPE_MAIN_POP_MODE_1080P_444,
    FBM_TYPE_SUB_POP_MODE_1080I,
    FBM_TYPE_SUB_POP_MODE_576I,
    FBM_TYPE_SUB_POP_MODE_1080P_422,
    FBM_TYPE_SUB_POP_MODE_1080P_444,
    FBM_TYPE_MM_1080I_MODE,
    FBM_TYPE_MM_576I_MODE,
    FBM_TYPE_MM_1080P_MODE,
    FBM_TYPE_ENV_MAX
} FBM_POOL_ENV_TYPE_T;

typedef enum
{
    FBM_MAIN_PSCAN,
    FBM_MAIN_SCALER,
    FBM_SUB_PSCAN,
    FBM_SUB_SCALER,
    FBM_TDC,
    FBM_VIDEO_AGENT_MAX
} FBM_NPTV_VIDEO_AGNET_T;

// EXTERN FBM_POOL_T _FBM_NPTV_VIDEO_CONF[FBM_TYPE_ENV_MAX][FBM_VIDEO_AGENT_MAX];
EXTERN FBM_POOL_T (* _FBM_NPTV_VIDEO_CONF)[FBM_VIDEO_AGENT_MAX];

/* FBM calculated-once size table - end */

EXTERN UINT32 SRMFBM_GetConf(void);
#if defined(CC_DYNAMIC_FBMSRM_CONF)
EXTERN void SRMFBM_SetConf(UINT32 conf);
EXTERN void SRMFBM_CHB_SetConf(UINT32 conf);
EXTERN void SRMFBM_CHC_SetConf(UINT32 conf);
EXTERN UINT32 SRMFBM_CHB_GetConf(void);
EXTERN UINT32 SRMFBM_CHC_GetConf(void);

#endif

typedef enum
{
    FLIP_NONE =0,
    FLIP_BY_SCALER = 0x1,
    FLIP_BY_PSCAN  = 0x2,
    FLIP_BY_B2R    = 0x4,
    FLIP_BY_MJC    = 0x8,
    FLIP_BY_3D     = 0x10,
#ifdef DRV_USE_EXTERNAL_3D_FRC // MT8283_FLIP_MIRROR
    FLIP_BY_EXT3DFRC = 0x20
#endif

} FLIP_MODULE_T;
UINT32 u4QueryFlipModule(UINT32 u4VdpId);

EXTERN void FBM_SetPscanTestMode(BOOL fgIsTestMode);
EXTERN void FBM_SetPscanTestModeSubPIP(BOOL fgIsTestMode);
EXTERN void SRM_SetCurrentFBMMode(UINT32 u4FBMMode);
EXTERN VOID FBM_SetFirstSeqChgFlag(UCHAR ucFbgId,BOOL bFlag);

#if defined(CC_EDB_FBM_SHARE_MEM)
EXTERN VOID FBM_SetEDBSize(UINT8 u1EDBSize);
EXTERN VOID FBM_GetEDBAddr(UPTR* pu4EDBAddr);
#endif

#if defined(CC_FBM_2ND_CHANNEL)
EXTERN UPTR FBM_GetCHBStartAddr(void);
#define DRAM_CHB_START_ADDR FBM_GetCHBStartAddr()
#endif
#if defined(CC_FBM_3ND_CHANNEL)
EXTERN UPTR FBM_GetCHCStartAddr(void);
#define DRAM_CHC_START_ADDR FBM_GetCHCStartAddr()
#endif

EXTERN UPTR FBM_GetCaptureDstAddr(void);

void FBM_FixedScalerDram(UINT8 fgOnOff);
UINT8 FBM_GetFixedScalerDram(void);

BOOL fgFBM_MDDI_FIFO_LIMIT(UINT32 u4VdpId);
EXTERN BOOL FBM_ChkSeqChg(UCHAR ucFbgId,UCHAR ucFbId,BOOL bPeek);

#endif    // FBM_DRVIF_H

