/*
 *******************************************************************************
 *  Copyright (c) 2010-2022 VATICS(KNERON) Inc. All rights reserved.
 *
 *  +-----------------------------------------------------------------+
 *  | THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED |
 *  | AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH  |
 *  | A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. |
 *  | THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE   |
 *  | PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON. THE   |
 *  | OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.        |
 *  |                                                                 |
 *  | THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT   |
 *  | ANY PRIOR NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY |
 *  | VATICS(KNERON) INC.                                             |
 *  +-----------------------------------------------------------------+
 *
 *******************************************************************************
 */
#ifndef VIDEO_DISPLAY_MECHANISM_H
#define VIDEO_DISPLAY_MECHANISM_H

#include <comm/video_buf.h>

#ifdef __cplusplus
extern "C" {
#endif

#define VMF_VIDEO_DISPLAY_MIN_QUEUE_SIZE 3

typedef struct VMF_VDISP_HANDLE_T VMF_VDISP_HANDLE_T;

/*
 * An enumeration for video display type
 */
typedef enum
{
	//! normal type: video display on the second frame 
	VMF_VMF_VDISP_TYPE_NORMAL,    
	//! special type: video display on the first frame
	VMF_VMF_VDISP_TYPE_SPECIAL,
} VMF_VDISP_TYPE;

/*
 * A data structure for video display init option
 */
typedef struct
{
	//! A data for output display format
	unsigned int dwInPixFormat;
	//! A data for max video display buffer width
	unsigned int dwMaxInWidth;
	//! A data for max video display buffer heigth
	unsigned int dwMaxInHeight;
	//! A data for video display type, 0: display in second frame 1: display in first frame
	VMF_VDISP_TYPE eVdispType;
} VMF_VDISP_INITOPT_T;

/*
 * A data structure for pip video display config
 */
typedef struct
{
	//! A data for The output height of PIP video display
	unsigned int dwInPixFormat;
	//! A data for the output width of PIP video display
	unsigned int dwWidth;
	//! A data for the output height of PIP video display
	unsigned int dwHeight;
	//! A data for the output stride of PIP video display
	unsigned int dwStride;
	//! A data for PIP starting X position
	unsigned int dwStartX;
	//! A data for PIP starting Y position
	unsigned int dwStartY;
} VMF_VDISP_PIP_CONFIG_T;

/**
 * @brief Function to initialize the video display.
 *
 * @param[in] ptVideoOpt The point of VMF_VDISP_INITOPT_T structure.
 * @return The handle of video display.
 */
VMF_VDISP_HANDLE_T* VMF_VDISP_Init(const VMF_VDISP_INITOPT_T* ptVideoOpt);

/**
 * @brief Function to release the video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_Release(VMF_VDISP_HANDLE_T* ptHandle);

/**
 * @brief Function to stop video display.
 *
 * @note Please remember to use mutex to protect outside,
 *		 especially when you use multi-thread to handle display.
 * @param[in] ptHandle The handle of video display.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_Stop(VMF_VDISP_HANDLE_T* ptHandle);

/**
 * @brief Function to push one frame into the queue of video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] ptSrcBuf The point of VMF_FRAME_BUF_T structure.
 * @param[in] pdwIndex The point of process index of the image buffer.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_ProcessOneFrame(VMF_VDISP_HANDLE_T* ptHandle, const VMF_FRAME_BUF_T* ptSrcBuf, unsigned int* pdwIndex);

/**
 * @brief Function to set compress for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bCompressEn The boolean variable for enable/disable compress effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_SetCompress(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bCompressEn);

/**
 * @brief Function to get compress value for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbCompressEn Return whether the compress effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_GetCompress(VMF_VDISP_HANDLE_T* ptHandle, unsigned int *pbCompressEn);

/**
 * @brief Function to set mirror effect for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bMirrorEn The boolean variable for enable/disable mirror effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_SetMirror(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bMirrorEn);

/**
 * @brief Function to get mirror value for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbMirrorEn Return whether the mirror effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_GetMirror(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pbMirrorEn);

/**
 * @brief Function to set flip effect for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bFlipEn The boolean variable for enable/disable flip effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_SetFlip(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bFlipEn);

/**
 * @brief Function to get flip value for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbFlipEn Return whether the flip effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_GetFlip(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pbFlipEn);

/**
 * @brief Function to set contrast for YUV output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] sdwCont The value of contrast (range : -128~127).
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_YUVOutput_SetContrast(VMF_VDISP_HANDLE_T* ptHandle, int sdwCont);

/**
 * @brief Function to get contrast value for yuv output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] psdwCont Return the value of contrast.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_YUVOutput_GetContrast(VMF_VDISP_HANDLE_T* ptHandle, int* psdwCont);

/**
 * @brief Function to set brightness for YUV output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] sdwBri The value of brightness (range : -128~127).
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_YUVOutput_SetBrightness(VMF_VDISP_HANDLE_T* ptHandle, int sdwBri);

/**
 * @brief Function to get brightness value for yuv output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] psdwBri Return the value of brightness.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_YUVOutput_GetBrightness(VMF_VDISP_HANDLE_T* ptHandle, int* psdwBri);

/**
 * @brief Function to set saturation for YUV output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] dwSat The value of saturation (range : 0~511).
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_YUVOutput_SetSaturation(VMF_VDISP_HANDLE_T* ptHandle, unsigned int dwSat);

/**
 * @brief Function to get saturation value for yuv output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pdwSat Return the value of saturation.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_YUVOutput_GetSaturation(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pdwSat);

/**
 * @brief Function to set early interrupt for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] dwEarlyIntr The enumerate value of early interrupt.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_SetEarlyInterrupt(VMF_VDISP_HANDLE_T* ptHandle, unsigned int dwEarlyIntr);

/**
 * @brief Function to get early interrupt value for video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pdwEarlyIntr Return the enumerate value of early interrupt.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_GetEarlyInterrupt(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pdwEarlyIntr);

/**
 * @brief Function to set the PIP video display data.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] ptConfig The point of VMF_VDISP_PIP_CONFIG_T structure.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_SetInfo(VMF_VDISP_HANDLE_T* ptHandle, const VMF_VDISP_PIP_CONFIG_T* ptConfig);

/**
 * @brief Function to push one frame into the queue of PIP video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] ptSrcBuf The point of VMF_FRAME_BUF_T structure.
 * @param[in] pdwIndex The point of process index of the image buffer.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_ProcessOneFrame(VMF_VDISP_HANDLE_T* ptHandle, const VMF_FRAME_BUF_T* ptSrcBuf, unsigned int* pdwIndex);

/**
 * @brief Function to set compress for PIP video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bCompressEn The boolean variable for enable/disable compress effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_SetCompress(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bCompressEn);

/**
 * @brief Function to get compress value for PIP video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbCompressEn Return whether the compress effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_GetCompress(VMF_VDISP_HANDLE_T* ptHandle, unsigned int *pbCompressEn);

/**
 * @brief Function to set mirror effect for PIP video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bMirrorEn The boolean variable for enable/disable mirror effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_SetMirror(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bMirrorEn);

/**
 * @brief Function to get mirror value for PIP video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbMirrorEn Return whether the mirror effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_GetMirror(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pbMirrorEn);

/**
 * @brief Function to set flip effect for PIP video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bFlipEn The boolean variable for enable/disable flip effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_SetFlip(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bFlipEn);

/**
 * @brief Function to get flip value for PIP video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbFlipEn Return whether the flip effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_GetFlip(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pbFlipEn);

/**
 * @brief Function to set alpha for PIP YUV output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] dwAlpha The value of alpha (range : 0~255).
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_SetAlpha(VMF_VDISP_HANDLE_T* ptHandle, unsigned int dwAlpha);

/**
 * @brief Function to get alpha value for PIP yuv output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pdwAlpha Return the value of alpha.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_GetAlpha(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pdwAlpha);

/**
 * @brief Function to stop the PIP video display.
 *
 * @note Please remember to use mutex to protect outside,
 *		 especially when you use multi-thread to handle display.
 * @param[in] ptHandle The handle of video display.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP_Stop(VMF_VDISP_HANDLE_T* ptHandle);

/**
 * @brief Function to set the PIP 2 video display data.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] ptConfig The point of VMF_VDISP_PIP_CONFIG_T structure.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_SetInfo(VMF_VDISP_HANDLE_T* ptHandle, const VMF_VDISP_PIP_CONFIG_T* ptConfig);

/**
 * @brief Function to push one frame into the queue of PIP 2 video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] ptSrcBuf The point of VMF_FRAME_BUF_T structure.
 * @param[in] pdwIndex The point of process index of the image buffer.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_ProcessOneFrame(VMF_VDISP_HANDLE_T* ptHandle, const VMF_FRAME_BUF_T* ptSrcBuf, unsigned int* pdwIndex);

/**
 * @brief Function to set compress for PIP 2 video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bCompressEn The boolean variable for enable/disable compress effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_SetCompress(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bCompressEn);

/**
 * @brief Function to get compress value for PIP 2 video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbCompressEn Return whether the compress effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_GetCompress(VMF_VDISP_HANDLE_T* ptHandle, unsigned int *pbCompressEn);

/**
 * @brief Function to set mirror effect for PIP 2 video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bMirrorEn The boolean variable for enable/disable mirror effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_SetMirror(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bMirrorEn);

/**
 * @brief Function to get mirror value for PIP 2 video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbMirrorEn Return whether the mirror effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_GetMirror(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pbMirrorEn);

/**
 * @brief Function to set flip effect for PIP 2 video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] bFlipEn The boolean variable for enable/disable flip effect.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_SetFlip(VMF_VDISP_HANDLE_T* ptHandle, unsigned int bFlipEn);

/**
 * @brief Function to get flip value for PIP 2 video display.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pbFlipEn Return whether the flip effect is enabled or not.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_GetFlip(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pbFlipEn);

/**
 * @brief Function to set alpha for PIP 2 YUV output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[in] dwAlpha The value of alpha (range : 0~255).
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_SetAlpha(VMF_VDISP_HANDLE_T* ptHandle, unsigned int dwAlpha);

/**
 * @brief Function to get alpha value for PIP 2 yuv output.
 *
 * @param[in] ptHandle The handle of video display.
 * @param[out] pdwAlpha Return the value of alpha.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_GetAlpha(VMF_VDISP_HANDLE_T* ptHandle, unsigned int* pdwAlpha);

/**
 * @brief Function to stop the PIP 2 video display.
 *
 * @note Please remember to use mutex to protect outside,
 *		 especially when you use multi-thread to handle display.
 * @param[in] ptHandle The handle of video display.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_PIP2_Stop(VMF_VDISP_HANDLE_T* ptHandle);

/**
 * @brief Function to reset all settings.
 *
 * @param[in] ptHandle The handle of video display.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_VDISP_All_Setting_Reset(VMF_VDISP_HANDLE_T* ptHandle);

#ifdef __cplusplus
}
#endif

#endif
