/* 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: brianpc.huang $
 * $Date: 2015/05/29 $
 * $RCSfile: vdo_if.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

/** @file vdo_if.h
 *  NPTV Video interface, including input source select ,and timing information
 */

#ifndef _VDO_IF_H_
#define _VDO_IF_H_

#include "x_typedef.h"
#include "sv_const.h"


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



///-----------------------------------------------------------------------------
/// Public functions
///-----------------------------------------------------------------------------
/**
 * Sub Clone Modee -> Let Sub's source always be set to the same one with Main.
 *
 * @param fgOnOff  SV_ON/SV_OFF
 */
EXTERN void bSubSrcCloneMode(UINT8 fgOnOff);



/**
 * Trigger the action to select video input source.
 *
 * @param bPath SV_VP_MAIN / SV_VP_PIP
 * @param bSrc Select the video input source. SV_VS_TUNER1 / SV_VS_CVBS1
 * / SV_VS_CVBS2 / SV_VS_CVBS3 / SV_VS_S1 / SV_VS_S2 / SV_VS_S3
 * / SV_VS_YPbPr1 / SV_VS_YPbPr2 / SV_VS_SCART1 / SV_VS_SCART2
 * / SV_VS_VGA / SV_VS_DVI / SV_VS_HDMI
 * @return The exit status of this api.
 * @retval SV_FAIL
 * @retval SV_NO_CHANGE
 * @retval SV_SUCCESS
 */
EXTERN UINT8 bApiVideoSetVideoSrc(UINT8 bPath, UINT8 bSrc);

/**
 * Set the video sources of main and sub.
 *
 * @param bMainSrc Main video input source. SV_VS_TUNER1 / SV_VS_CVBS1
 * / SV_VS_CVBS2 / SV_VS_CVBS3 / SV_VS_S1 / SV_VS_S2 / SV_VS_S3
 * / SV_VS_YPbPr1 / SV_VS_YPbPr2 / SV_VS_SCART1 / SV_VS_SCART2
 * / SV_VS_VGA / SV_VS_DVI / SV_VS_HDMI
 * @param bSubSrc Sub video input source. SV_VS_TUNER1 / SV_VS_CVBS1
 * / SV_VS_CVBS2 / SV_VS_CVBS3 / SV_VS_S1 / SV_VS_S2 / SV_VS_S3
 * / SV_VS_YPbPr1 / SV_VS_YPbPr2 / SV_VS_SCART1 / SV_VS_SCART2
 * / SV_VS_VGA / SV_VS_DVI / SV_VS_HDMI
 * @return The exit status of this api.
 * @retval SV_FAIL
 * @retval SV_SUCCESS
 */
EXTERN UINT8 bApiVideoMainSubSrc(UINT8 bMainSrc, UINT8 bSubSrc);

/**
 * Select TV color system
 *
 * @param bColSys Select the color system. SV_CS_AUTO / SV_CS_PAL / SV_CS_PAL_M
 * / SV_CS_PAL_N / SV_CS_NTSC358 / SV_CS_NTSC443 / SV_CS_SECAM
 * @return NONE
 */
EXTERN UINT8 fgApiVideoColorSystem(UINT8 bColSys);

EXTERN UINT8 bApiVideoGetAnalogCopyProtect(UINT8 bPath, UINT8 *pu1Psp, UINT8 *pu1CStripe);

/**
 * Get Current TV color system
 *
 * @return Current Color System. SV_CS_AUTO / SV_CS_PAL / SV_CS_PAL_M
 * / SV_CS_PAL_N / SV_CS_NTSC358 / SV_CS_NTSC443 / SV_CS_SECAM
 */
EXTERN UINT8 bApiVideoGetColorSystem(void);

EXTERN UINT8 bApiVideoGetInputTimingID(UINT8 bPath);

/**
 * @brief bApiVideoGetVideoTiming(UINT8 bPath)
 * Get input video timing
 * @param  bPath :main/sub path (SV_VP_MAIN / SV_VP_PIP)
 * @retval   input timing (index)
 */
EXTERN UINT8 bApiVideoGetVideoTiming(UINT8 bPath);


EXTERN UINT8 bApiVideoGetInputPolarity(UINT8 bPath);

/**
 * @brief wApiVideoGetInputWidth(UINT8 bPath)
 * Get input video resolution width (in pixel)
 * @param  bPath :main/sub path (SV_VP_MAIN / SV_VP_PIP)
 * @retval  width (in pixel)
 */
EXTERN UINT16 wApiVideoGetInputWidth(UINT8 bPath);

/**
 * @brief wApiVideoGetInputHeight(UINT8 bPath)
 * Get input video resolution hight (in pixel)
 * @param  bPath :main/sub path (SV_VP_MAIN / SV_VP_PIP)
 * @retval  hight (in pixel)
 */
EXTERN UINT16 wApiVideoGetInputHeight(UINT8 bPath);

/**
 * @brief bApiVideoGetRefreshRate(UINT8 bPath)
 * Get input video refreh rate(in Hz)
 * @param  bPath :main/sub path (SV_VP_MAIN / SV_VP_PIP)
 * @retval  refreh rate (in Hz)
 */
EXTERN UINT8 bApiVideoGetRefreshRate(UINT8 bPath);

/**
 * Check if input video is interlace mode
 *
 *  @param  bPath path ID
 *  @retval TRUE for interlace input and FALSE for progressive input
 */
EXTERN UINT8 bApiVideoIsSrcInterlace(UINT8 bPath);

EXTERN void vApiVideoSetFixColorSpaceMode(UINT8 bPath, SV_FIXCOLORSPACE_MODE bMode);
EXTERN SV_FIXCOLORSPACE_MODE bApiVideoGetFixColorSpaceMode(UINT8 bPath);

EXTERN void vApiHdmiColorModeChg(UINT8 bPath);

/**
 * @brief fgApiVideoIsVgaTiming(UINT8 bPath)
 * check if current input source is VGA timing
 * @param  bPath :main/sub path (SV_VP_MAIN / SV_VP_PIP)
 * @retval   TRUE/FALSE
 */
EXTERN UINT8 fgApiVideoIsVgaTiming(UINT8 bPath);

// REMOVE ME!
EXTERN UINT8 fgApiVideoIsVgaMode(UINT8 bPath, UINT8 bChkFlg);

// REMOVE ME!
EXTERN UINT8 fgApiVideoIsVgaModeEx(UINT8 bPath, UINT8 bChkFlg);

/**
 * @brief fgApiVideoIsSourceCVBS(UINT8 bPath)
 * check if current input source is CVBS
 * @param  bPath :main/sub path (SV_VP_MAIN / SV_VP_PIP)
 * @retval   TRUE/FALSE
 */
EXTERN BOOL fgApiVideoIsSourceCVBS(UINT8 bPath);

/**
 * @brief Get main/sub path video source type
 * @param bPath SV_VP_MAIN/SV_VP_PIP
 */
EXTERN UINT8 bApiVideoGetSrcType(UINT8 bPath);

/**
 * @brief Set main/sub path video to tuner scanning mode
 * @param u4VdpId SV_VP_MAIN/SV_VP_PIP
 * @param u4Mode  scan mode on/off
 */
EXTERN void vApiVideoSetScanMode(UINT32 u4VdpId, UINT32 u4Mode);

/**
 * @brief Get tuner scanning mode status
 * @param u4VdpId SV_VP_MAIN/SV_VP_PIP
 * @retval  Scan mode on/off
 */
EXTERN UINT32 u4ApiVideoGetScanMode(UINT32 u4VdpId);

/**
 * @brief Set if show snow screen when ATV no signal
 * @param u4VdpId SV_VP_MAIN/SV_VP_PIP
 * @param u4Mode  scan mode on/off
 */
EXTERN void vApiVideoSetSnowScreen(UINT32 u4OnOff);

/**
 * @brief Get Snow screen current setting
 * @param N/A
 * @retval  Snow screen on/off
 */
EXTERN UINT32 u4ApiVideoGetSnowScreen(void);

/**
 * @brief Video init 
 * @param N/A
 * @retval  N/A
 */
EXTERN void vApiVideoInit(void);

/**
 * Setup the Monitor source
 *
 * @param bPath SV_VP_MAIN / SV_VP_PIP
 * @param b1MonSrc Select the video input source. SV_VS_TUNER1 / SV_VS_CVBS1
 * / SV_VS_CVBS2 / SV_VS_CVBS3 / SV_VS_S1 / SV_VS_S2 / SV_VS_S3
 * / SV_VS_YPbPr1 / SV_VS_YPbPr2 / SV_VS_SCART1 / SV_VS_SCART2
 * / SV_VS_VGA / SV_VS_DVI / SV_VS_HDMI
 * @retval SV_FAIL
 * @retval SV_SUCCESS
 */

UINT8 bApiMonitorSetup(UINT8 u1Path,UINT8 u1MonSrc);

#if 1//def CC_AUD_QUERY_VDO_INFO
typedef struct
{
    UINT16 u2Width;
    UINT16 u2Height;
    UINT8 u1Timing;
    UINT8 u1Interlace;
    UINT8 u1RefreshRate;
    UINT8 u1PanelDelay;
} VDO_INPUT_INFO;
EXTERN void DrvVideoGetInputTimingInfo(UINT8 bPath, VDO_INPUT_INFO* info);
#endif

void DisableVsyncInt( void );
void EnableVsyncInt( void );

#endif // _VDO_IF_H_
 
