/* 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: dtvbm11 $
 * $Date: 2015/11/10 $
 * $RCSfile: vdo_if.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

/** @file vdp_venc_ctrl.h
 *  Venc VDP control interface
 */

#ifndef _VDP_VENC_CTRL_H_
#define _VDP_VENC_CTRL_H_

#ifdef CC_SUPPORT_VENC

//#include "mtvenc.h"
#include "venc_if.h"

/** MTVENC_VDP_RES_t
 *  Encoder input resolution
 */
typedef struct _VDP_VENC_INPUT_RES
{
    UINT32 u4EncInWidth;
    UINT32 u4EncInHeight;
    UINT8  fgInterlace;
    UINT32 u4Fps;
}VDP_VENC_INPUT_RES_t;


//VENC api
typedef enum{
    E_VDP_VENC_BOTH_FLD = 0,
    E_VDP_VENC_TOP_FLD,
    E_VDP_VENC_BOTTOM_FLD,
    E_VDP_VENC_PROGRESSIVE,  
} E_VDP_VENC_FIELD_MODE; 


/** MTVENC_SRC_TYPE_T
 *  set the record input point
 */
typedef enum
{
    E_VDP_VENC_MIXER = 0,                    ///< encoder MIXER
    E_VDP_VENC_MAIN_FSC_OUT,
    E_VDP_VENC_SUB_FSC_OUT,
    E_VDP_VENC_MAIN_MIB_OUT,
    E_VDP_VENC_SUB_MIB_OUT,
    E_VDP_VENC_MAIN_BEFORE_PRED ,           ///< encoder before MAIN predown
    E_VDP_VENC_SUB_BEFORE_PRED,             ///< encoder before SUB predown
    E_VDP_VENC_OSTG,                        ///< encode output stage
    E_VDP_VENC_OSTG_OSD  ,                  ///< encode output stage + OSD
    E_VDP_VENC_NOT_SELECTED,                ///< encode input is not selected
}E_VDP_VENC_INPUT;

typedef enum
{
    E_SUB_VENC_SUB_SCALER_IN = 0,          ///< encoder MIXER
    E_SUB_VENC_MAIN_BEFORE_PRED ,          ///< encoder MIXER
    E_SUB_VENC_SUB_BEFORE_PRED ,           ///< encoder MIXER
    E_SUB_VENC_OSTG,                       ///< encode input is not selected
    E_SUB_VENC_OSTG_OSD,                   ///< encode input is not selected
    E_SUB_VENC_NOT_SELECTED,               ///< encode input is not selected
}E_VDP_VENC_SUB_INPUT;


/** MTVENC_SRC_TYPE_T
 *  set the recording module
 */
typedef enum
{
    E_VDP_VENC_MAIN_SCALER = 0,                    ///< using main scaler to encode
    E_VDP_VENC_SUB_SCALER  = 1,                    ///< using sub scaler to encode
    E_VDP_VENC_MONITOR_OUT = 2,                    ///< using Monitor out to encode
    E_VDP_VENC_SUB_DI      = 3,                    ///< using sub DI to encode
} E_VDP_VENC_MODULE;

typedef struct VDP_VENC_INFO
{
    VENC_PROFILE_T           eProfileDef;
    E_VDP_VENC_INPUT         eEncInput; 
    E_VDP_VENC_SUB_INPUT     eSubEncInput;
    E_VDP_VENC_MODULE        eEncModule;
    E_VDP_VENC_FIELD_MODE    eEncFldType;
    UINT32                   u4TrgtWidth;    //recording width
    UINT32                   u4TrgtHeight;   //recording height
}VDP_VENC_INFO_t;


//#define VENC_SUB_SCALER_SCALING


void vDrvVencVDPDropFrame(UINT8 u1OnOff, UINT8 u1M, UINT8 u1N);
void vDrvVencVDPSetScalerBuf(UINT32 u4BaseAdd, UINT32 u4YBufSize);

void vDrvVencVDPSetParam(VENC_PROFILE_T eProfileDef, UINT32 u4RecWidth, UINT32 u4RecHeight);
void vDrvVencVDPStop(void);
void vDrvVencVDPStart(void *handle, void *ptFrmBuffMgr, void *ptResizeFrmBuffMgr, void *ptFilterPts);

UINT8 u1DrvVencVDPVRMReady(void);
UINT8 u1DrvVencVDPSignalReady(void);

void vDrvVencCtrlStopModule(void);
UINT8 bDrvVencVDPIsOneFldMode(void);
void vDrvVencVDPInit(void);
void vDrvVencVDPCtrlMLoop(void);

void vDrvVencVDPSetEncFldType(E_VDP_VENC_FIELD_MODE eEncFldType);
void vDrvVencVDPSetEncModule(E_VDP_VENC_MODULE eEncModule);
void vDrvVencVDPSetEncInput(E_VDP_VENC_INPUT eEncInput);
void vDrvVencVDPGetEncInRes(VDP_VENC_INPUT_RES_t* tRes);

E_VDP_VENC_MODULE     eDrvVencVDPGetEncModule(void);
E_VDP_VENC_INPUT      eDrvVencVDPGetEncInput(void);

UINT32 u4DrvVencVDPCtrlCheckFrameRate(UINT32 u4APFR, UINT32 u4InFR);

#endif // CC_SUPPORT_VENC

#endif // _VDP_VENC_CTRL_H_
 
