/**
 * @file hv_mw_Video.h
 * @brief Header file of dpu module.
 * 
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use hv_mw_Video(...) as a function handle. 
 * 
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-10
 */

#ifndef __SDK_MIDDLEWARE_VIDEO_INC_VIDEO_H__
#define __SDK_MIDDLEWARE_VIDEO_INC_VIDEO_H__

#include "hv_comm_DataType.h"
#include "hv_comm_Define.h"
#include "hv_comm_PqDef.h"
#include "../../inc/hv_mw_Channel_Manager.h"

typedef struct _DataPathSearchTable
{
    DisplayDataPathMode enDataPathMode;
    ColorFormatType     enColorFormat;
    CompressRatio       enCompressRatio;
}DataPathSearchElem;

/**
 * @brief Get default fake VideoConfigParams config param.
 * @param[in] none
 * @return VideoConfigParams.
 */
VOID Hv_Mw_Video_GetFakeVideoConfigParams(VideoTimingParam *pstVideoTiming, VideoConfigParams *pstVideoConfigParams);

/**
 * @brief Estimate Sub Channel ddr Size
 * @return ddr size.
 */
UINT32 Hv_Mw_Video_EstimateSubChannelMemSize(PxpMode enPxpMode);

/**
 * @brief video data patch is framesync
 * @return Status, 0-frc, 1-framesync.
 */
BOOL Hv_Mw_Video_CheckUseFrameSync(BOOL bVflipEnable, const VideoTimingParam* pstVideoTiming, const VideoConfigParams* pstVideoConfigParams);

/**
 * @brief Send Reconfig data path message to System task
 * @param[in] none
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_DataPathReconfig( VOID );

/**
 * @brief video Data path config
 * @param[in] ChannelType-main or sub, VideoConfigParams-param calc by preconfig,VdeTimingParam-param from RX.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_ConfigDisplayDataPath(ChannelData* pstChannelData, VideoConfigParams* pstVideoConfigParams, VideoTimingParam* pstRxVideoTiming);

/**
 * @brief set INP pattern frame rate for pq calibrate
 * @param[in] uiFrameRate frame rate.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetPqCalibrateFrameRate(UINT32 uiFrameRate);

/**
 * @brief Set video aspect ratio.
 * @param[in] enVideoRatio:read in hv_comm_Define.h
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetAspectRatio(VideoRatio enVideoRatio);

/**
 * @brief set main channel video inputport source.
 * @param[in] 0- HDMI0 1:HDMI1 2-DP0 3-DP1.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetMainVideoSource(LinkPortIndex enLinkPortIndex);


#ifdef CONFIG_USER_DOUBLE_CHANNEL_ON
/**
 * @brief Set PIP / PBP funciton enable.
 * @param[in] 0- close PIP or PBP 1-PIP enable 2-pbp enable.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetPxpMode(PxpMode enPxpMode);

/**
 * @brief set sub channel video inputport source.
 * @param[in] 0- HDMI0 1:HDMI1 2-DP0 3-DP1.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetSubVideoSource(LinkPortIndex enLinkPortIndex);


/**
 * @brief swap main and sub channel inputport source.
 * @param[in] none.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetMainSubVideoSourceSwap();


/**
 * @brief In pip Mode set sub window position.
 * @param[in] 0:左上 1：左下 2：右上 3右下
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetSubVideoWindowPosition(PipPos enPipPos);

/**
 * @brief set pip sub h position
 */
VOID Hv_Mw_Video_SetPipWindowHPosition(USHORT16 usHPosLevel);

/**
 * @brief set pip sub V position
 */
VOID Hv_Mw_Video_SetPipWindowVPosition(USHORT16 usVPosLevel);

/**
 * @brief get pip sub h position
 */
USHORT16 Hv_Mw_Video_GetPipWindowHPosition(VOID);

/**
 * @brief get pip sub V position
 */
USHORT16 Hv_Mw_Video_GetPipWindowVPosition(VOID);

/**
 * @brief set pbp window size.
 * @param[in] 0-small 1-middle 2-big
 */
Status Hv_Mw_Video_SetPbpSize(PbpSize enPbpSize);

/**
 * @brief set pip window size.
 * @param[in] 0-small 1-big
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetSubVideoWindowSize(PipSize enPipSize);
#endif

/**
 * @brief set professional esport funciton switch.
 * @param[in] HV_OFF-close HV_ON-open
 */
VOID Hv_Mw_Video_SetProEsportSwitch(UCHAR8 ucSw);

/**
 * @brief set FreeSync funciton switch.
 * @param[in] HV_OFF-close HV_ON-open
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetFreeSyncSwitch(UCHAR8 ucSw);

/**
 * @brief 需要修改EDID重新拉HPD的HDR开关类型
 * @param[in] 0-close 1-open
 */
VOID Hv_Mw_Video_SetEdidHdrSwitch(UINT32 uiValue);

/**
 * @brief Set h flip
 * @param[in] HV_OFF-close HV_ON-open
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetHflipSwitch(UCHAR8 ucSw);

/**
 * @brief Set v flip
 * @param[in] HV_OFF-close HV_ON-open
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetVflipSwitch(UCHAR8 ucSw);

/**
 * @brief set auto search signal source function enable .
 * @param[in] HV_OFF-close HV_ON-open
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetVideoAutoSelectSw(UCHAR8 ucSw);

/**
 * @brief calc dcw ddr size.
 */
VOID Hv_Mw_video_CalcDcwDdrOrWtrSize(VideoConfigParams* pstVideoConfigParams);

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAGNIFY)
/**
 * @brief Calc ddr video size.
 * @param[in] VideoConfigParams
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
VOID Hv_Mw_video_CalcMagniferDdrVideoSize(VideoConfigParams* pstVideoConfigParams);

/**
 * @brief set Magnify Glass function Switch .
 * @param[in] HV_OFF-close HV_ON-open
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetMagnifyGlassSwitch(UCHAR8 ucSw);

/**
 * @brief set Magnify Glass function ratio .
 * @param[in] 0-100
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetMagnifyGlassRatio(FLOAT32 fMgRatio);

/**
 * @brief set Magnify Glass  position
 * @param[in] range usMgPosH: 0-pannel Hactive, usMgPosV: 0-panel Vactive
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetMagnifyGlassPos(USHORT16 usMgPosH, USHORT16 usMgPosV);

/**
 * @brief set Magnify Glass  sampling location
 * @param[in] range usSampleLocH: 0-pannel Hactive, usSampleLocV: 0-panel Vactive
 */
VOID Hv_Mw_Video_SetMagnifyGlassSamplingLocation(USHORT16 usSampleLocH, USHORT16 usSampleLocV);

/**
 * @brief set Magnify Glass Size
 * @param[in] range usMgHsize:0-panne Havtive , usMgVsize: 0-panel Vactive
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */

Status Hv_Mw_Video_SetMagnifyGlassSize(USHORT16 usMgHsize, USHORT16 usMgVsize);
#endif

/**
 * @brief Set mprt enable.
 * @param[in] enMprtType:0-disable , 1: normal mprt, 2: vrr mprt
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
VOID Hv_Mw_Video_SetOutMprtPwmEnable(MprtType enMprtType);

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAIN_MONTAGE)
/**
 * @brief Set main channel montage enbale.
 * @param[in] bSw:0-disable , 1: enable
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetMainMontageSw(UCHAR8 ucSw);

/**
 * @brief Updata video param for montage setting.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_Video_SetMainMontageParam(USHORT16 usCutHsta, USHORT16 usCutHend, USHORT16 usCutVsta, USHORT16 usCutVend);
#endif

/**
 * @brief Set ALLM enable and return status.
 * @return Status, 0-HV_FALSE, 1-HV_TRUE.
 */
BOOL Hv_Mw_Video_SetMainALLMStatus(VOID);

/**
 * @brief Set main channel over scan enbale.
 * @param[in] HV_OFF-close HV_ON-open
 */
VOID Hv_Mw_Video_SetOverScanEn(UCHAR8 ucSw);

/**
 * @brief Set main channel over scan enbale.
 * @return Status, 0-HV_FALSE, 1-HV_TRUE.
 */
BOOL Hv_Mw_Video_GetOverScanEn(VOID);

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_OVER_PANEL_CLOCK_EN)
/**
 * @brief Set panel over clock en.
 */
VOID Hv_Mw_Video_SetOverClockEn(UCHAR8 ucSw);

/**
 * @brief Get panel over clock en.
 * @return Status, 0-HV_FALSE, 1-HV_TRUE.
 */
BOOL Hv_Mw_Video_GetOverClockEn(VOID);
#endif

/**
 * @brief Get dtc vtotal is in panel spec.
 * @return BOOL, 0-HV_FALSE, 1-HV_TRUE.
 */
BOOL Hv_Mw_Video_IsDtcVtotalInPanlSpec(VOID);

/**
 * @brief Get dtc dynamic htotal
 */
USHORT16 Hv_Mw_Video_GetDtcDynamicHtotal(VOID);

/**
 * @brief Updata panel param for video to used.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
VOID Hv_Mw_Video_SetVideoPanelParam(VOID);

/**
 * @brief Set Line interrupt
 * @param[in] ucIndex: one of 24 index
 * @param[in] usLine: Line number of Interrupt
 * @return Status, None
 */
VOID Hv_Mw_Video_SetLineInt(UCHAR8 ucIndex, USHORT16 usLine);

/**
 * @brief Set Line en 24bit
 * @param[in] uiEn, 24bit en
 * @return Status, None
 */
VOID Hv_Mw_Video_SetLineIntEn(UINT32 uiEn);

/**
 * @brief Set dpu int en
 * @param[in] ucEn, 5bits
 * @return Status, None
 */
VOID Hv_Mw_Video_SetDpuIntEn(UCHAR8 ucEn);

/**
 * @brief Set Main Channel pos if not full screen
 * @param[in] pstVideoConfigParams
 * @param[in] usHoffset
 * @param[in] usVoffset
 * @return Status, None
 */
VOID Hv_Mw_Video_SetMainPicPos(VideoConfigParams* pstVideoConfigParams, USHORT16 usHoffset, USHORT16 usVoffset);

#endif
