/* 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.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 * $RCSfile: x_tv_enc.h,v $
 * $Revision: #1 $
 * $Date: 2015/11/10 $
 * $Author: dtvbm11 $
 *
 * Description:
 *         This header file contains video decoder driver specific
 *         definitions, which are exported.
 *---------------------------------------------------------------------------*/

#ifndef _X_TV_ENC_H_
#define _X_TV_ENC_H_


/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/

#include "x_common.h"
#include "x_rm.h"


/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/


/* Get operations */
#define TV_ENC_GET_TYPE_CTRL         (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 0))
#define TV_ENC_GET_TYPE_FMT          (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 1))
#define TV_ENC_GET_TYPE_FMT_CAP      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 2))
#define TV_ENC_GET_TYPE_TV_TYPE      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 3))
#define TV_ENC_GET_TYPE_MV           (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 4))
#define TV_ENC_GET_TYPE_CCI          (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 5))
#define TV_ENC_GET_TYPE_ENC_CAP      (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 6))   

/* Set operations */
#define TV_ENC_SET_TYPE_CTRL        ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 0)) | RM_SET_TYPE_ARG_NO_REF)
#define TV_ENC_SET_TYPE_FMT         ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 1)) | RM_SET_TYPE_ARG_NO_REF)
#define TV_ENC_SET_TYPE_VBI_CONTENT  (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 2))
#define TV_ENC_SET_TYPE_TV_TYPE     ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 3)) | RM_SET_TYPE_ARG_NO_REF)
#define TV_ENC_SET_TYPE_MV           (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 4))
#define TV_ENC_SET_TYPE_CCI         ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 5)) | RM_SET_TYPE_ARG_NO_REF)
#define TV_ENC_SET_TYPE_ENABLE_EU_VBI_FIELD_DATA_GEN    (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 6))
#define TV_ENC_SET_TYPE_EU_VBI_FIELD_DATA               ((RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 7)) | RM_SET_TYPE_ARG_NO_REF)

/* TV_ENC_GET_TYPE_CTRL/TV_ENC_SET_TYPE_CTRL data info ***********************/
/* Control settings. */
typedef enum
{
    TV_ENC_CTRL_RESET       = 0,
    TV_ENC_CTRL_DISABLE     = 0x1,  /* disable TV encoder */
    TV_ENC_CTRL_ENABLE      = 0x2   /* enable TV encoder */
}   TV_ENC_CTRL_T;

/* TV_ENC_GET_TYPE_FMT *******************************************************/
/* TV output format */
typedef enum
{
    TV_ENC_FMT_NULL = 0,
    TV_ENC_FMT_CVBS,
    TV_ENC_FMT_S_VIDEO,
    TV_ENC_FMT_YBR,
    TV_ENC_FMT_RGB
}   TV_ENC_FMT_T;

/* TV_ENC_GET_TYPE_FMT_CAP ***************************************************/
/* Capability of TV output formats */
#define TV_ENC_FMT_CAP_NULL			(((UINT32)1) << TV_ENC_FMT_NULL)
#define TV_ENC_FMT_CAP_CVBS			(((UINT32)1) << TV_ENC_FMT_CVBS)
#define TV_ENC_FMT_CAP_S_VIDEO		(((UINT32)1) << TV_ENC_FMT_S_VIDEO)
#define TV_ENC_FMT_CAP_YBR			(((UINT32)1) << TV_ENC_FMT_YBR)
#define TV_ENC_FMT_CAP_RGB			(((UINT32)1) << TV_ENC_FMT_RGB)

typedef UINT32 TV_ENC_FMT_CAP_INFO_T;

/* Capability of TV encoding contents */
#define TV_ENC_ENC_CAP_VBI          ((UINT32) 0x1)

typedef UINT32 TV_ENC_ENC_CAP_INFO_T;

/* TV_ENC_SET_TYPE_VBI_CONTENT data info *************************************/
/* Field types */
typedef enum
{
    TV_ENC_FIELD_ODD = 0,
    TV_ENC_FIELD_EVEN,
    TV_ENC_FIELD_BOTH
}   TV_ENC_FIELD_TYPE_T;

/* VBI content info */
typedef struct _TV_ENC_VBI_CONTENT_INFO_T
{
    TV_ENC_FIELD_TYPE_T e_field;
    CHAR *              ps_content;
}   TV_ENC_VBI_CONTENT_INFO_T;

/* TV_ENC_GET_TYPE_ASPECT_RATIO/TV_ENC_SET_TYPE_ASPECT_RATIO data info *******/
typedef enum
{
    TV_ENC_ASPECT_RATIO_4_3,
    TV_ENC_ASPECT_RATIO_14_9,
    TV_ENC_ASPECT_RATIO_16_9
}   TV_ENC_ASPECT_RATIO_INFO_T;

/* TV_ENC_GET_TYPE_TV_TYPE/TV_ENC_SET_TYPE_TV_TYPE data info *****************/
typedef enum
{
    TV_ENC_TV_TYPE_NTSC_M,
    TV_ENC_TV_TYPE_PAL_B,
    TV_ENC_TV_TYPE_PAL_G,
    TV_ENC_TV_TYPE_PAL_H,
    TV_ENC_TV_TYPE_PAL_I,
    TV_ENC_TV_TYPE_PAL_D,
    TV_ENC_TV_TYPE_PAL_N,
    TV_ENC_TV_TYPE_PAL_M,
    TV_ENC_TV_TYPE_SECAM_B,
    TV_ENC_TV_TYPE_SECAM_G,
    TV_ENC_TV_TYPE_SECAM_H,
    TV_ENC_TV_TYPE_SECAM_D,
    TV_ENC_TV_TYPE_SECAM_K,
    TV_ENC_TV_TYPE_SECAM_K1,
    TV_ENC_TV_TYPE_SECAM_L
}   TV_ENC_TV_TYPE_INFO_T;

/* TV_ENC_GET_TYPE_MV/TV_ENC_SET_TYPE_MV data info ***************************/
#define TV_ENC_MV_CPS_DATA_SIZE      ((SIZE_T) 17)

typedef enum
{
    TV_ENC_MV_TYPE_OFF                       = 0,
    TV_ENC_MV_TYPE_APS                       = 1,
    TV_ENC_MV_TYPE_CPC_CPS                   = 2
}   TV_ENC_MV_TYPE_T;

typedef enum
{
    TV_ENC_MV_APS_TYPE_OFF                   = 0,
    TV_ENC_MV_APS_TYPE_AGC_ONLY              = 1,
    TV_ENC_MV_APS_TYPE_AGC_WI_2L_SPLIT_BURST = 2,
    TV_ENC_MV_APS_TYPE_AGC_WI_4L_SPLIT_BURST = 3
}   TV_ENC_MV_APS_TYPE_T;

typedef struct _TV_ENC_MV_CPC_CPS_T
{
    UINT8               ui1_cpc_data;
    UINT8               aui1_cps_data[TV_ENC_MV_CPS_DATA_SIZE];
}   TV_ENC_MV_CPC_CPS_T;

typedef struct _TV_ENC_MV_INFO_T
{
    TV_ENC_MV_TYPE_T    e_mv_type;

    union
    {
        TV_ENC_MV_APS_TYPE_T     e_aps_type;
        TV_ENC_MV_CPC_CPS_T      t_cpc_cps_data;
    } u;
} TV_ENC_MV_INFO_T;

/* TV_ENC_GET_TYPE_CCI/TV_ENC_SET_TYPE_CCI data info *************************/
typedef enum
{
    TV_ENC_CCI_TYPE_NO_RESTRICT      = 0,
    TV_ENC_CCI_TYPE_NO_FURTHER_COPY  = 1,
    TV_ENC_CCI_TYPE_COPY_ONCE        = 2,
    TV_ENC_CCI_TYPE_COPY_NEVER       = 3
}   TV_ENC_CCI_TYPE_T;

typedef UINT32 TV_ENC_CCI_DATA_INFO_T;

/* TV_ENC_SET_TYPE_EU_VBI_FIELD_DATA data info *******************************/
typedef struct _TV_ENC_EU_VBI_DATA_TTX_LINE_T
{
    UINT8                   ui1_field_parity;   /* 1:odd, 0:even (same as 4.5.2 ETSI EN 301 775) */
    UINT8                   ui1_line_offset;    /* definition same as Table 5, ETSI EN 301 775 */
    UINT8                   ui1_framing_code;   /* definition same as 4.5.2 ETSI EN 301 775 */
    UINT8                   aui1_data[42];      
    
} TV_ENC_EU_VBI_DATA_TTX_LINE_T;

#define TV_ENC_TTX_FIELD_MAX_LINE_NUM    40
typedef struct _TV_ENC_EU_VBI_DATA_TTX_T
{
    UINT32                          ui4_num_line;
    TV_ENC_EU_VBI_DATA_TTX_LINE_T   at_lines_data[TV_ENC_TTX_FIELD_MAX_LINE_NUM];
    
} TV_ENC_EU_VBI_DATA_TTX_T;

typedef struct _TV_ENC_EU_VBI_DATA_VPS_T
{
    /* the VPS 13 bytes data must be at line 16 of the first field */
    UINT8                  aui1_vps_data[13];
    
} TV_ENC_EU_VBI_DATA_VPS_T;

typedef struct _TV_ENC_EU_VBI_DATA_WSS_T
{
    /* the WSS 14 bits data must be at line 23 of the first field */
    /* the bit 0 corresponds to the left-most bit of wss_data_block */
    UINT16                 ui2_wss;
    
} TV_ENC_EU_VBI_DATA_WSS_T;

typedef struct _TV_ENC_EU_VBI_DATA_CC_T
{
    /* 1:odd, 0:even (same as 4.5.2 ETSI EN 301 775) */
    UINT8                   ui1_field_parity;   
    
    /* the CC data must be at line 21 of the first field in 525-line video */
    /* CC bit b0 of character one corresponds to the left-most bit of ui2_cc_data */
    UINT16                  ui2_cc_data;
    
} TV_ENC_EU_VBI_DATA_CC_T;

/* TV_ENC_EU_VBI_FIELD_DATA_T.ui4_flag */
#define TV_ENC_EU_VBI_DATA_FLAG_TTX         MAKE_BIT_MASK_32(0)
#define TV_ENC_EU_VBI_DATA_FLAG_VPS         MAKE_BIT_MASK_32(1)
#define TV_ENC_EU_VBI_DATA_FLAG_WSS         MAKE_BIT_MASK_32(2)
#define TV_ENC_EU_VBI_DATA_FLAG_CC          MAKE_BIT_MASK_32(3)

/* TV_ENC_EU_VBI_FIELD_DATA_T.i4_result_ttx */
#define TV_ENC_EU_VBI_DATA_RESULT_TTX_OK         ((INT32)  0)
#define TV_ENC_EU_VBI_DATA_RESULT_TTX_OVERFLOW   ((INT32) -1)
#define TV_ENC_EU_VBI_DATA_RESULT_TTX_ERROR      ((INT32) -2)

/* TV_ENC_EU_VBI_FIELD_DATA_T.i4_result_vps */
#define TV_ENC_EU_VBI_DATA_RESULT_VPS_OK         ((INT32)  0)
#define TV_ENC_EU_VBI_DATA_RESULT_VPS_ERROR      ((INT32) -1)

/* TV_ENC_EU_VBI_FIELD_DATA_T.i4_result_wss */
#define TV_ENC_EU_VBI_DATA_RESULT_WSS_OK         ((INT32)  0)
#define TV_ENC_EU_VBI_DATA_RESULT_WSS_ERROR      ((INT32) -1)

/* TV_ENC_EU_VBI_FIELD_DATA_T.i4_result_cc */
#define TV_ENC_EU_VBI_DATA_RESULT_CC_OK          ((INT32)  0)
#define TV_ENC_EU_VBI_DATA_RESULT_CC_ERROR       ((INT32) -1)

typedef struct _TV_ENC_EU_VBI_FIELD_DATA_T
{
    PTS_T                       ui8_pts;            /* in */
    UINT32                      ui4_flag;           /* in */
    
    TV_ENC_EU_VBI_DATA_TTX_T    t_ttx;              /* in */
    TV_ENC_EU_VBI_DATA_VPS_T    t_vps;              /* in */
    TV_ENC_EU_VBI_DATA_WSS_T    t_wss;              /* in */
    TV_ENC_EU_VBI_DATA_CC_T     t_cc;               /* in */

    /* process result of each data type */
    INT32                       i4_result_ttx;      /* out */
    INT32                       i4_result_vps;      /* out */
    INT32                       i4_result_wss;      /* out */
    INT32                       i4_result_cc;       /* out */
    
} TV_ENC_EU_VBI_FIELD_DATA_T;    


#ifndef MW_TV_ENC_SCART_1
#define TV_ENC_SCART_1        (0)
#else
#define TV_ENC_SCART_1        (MW_TV_ENC_SCART_1)
#endif

#ifndef MW_TV_ENC_SCART_2
#define TV_ENC_SCART_2        (1)
#else
#define TV_ENC_SCART_2        (MW_TV_ENC_SCART_2)
#endif


#endif /* _X_TV_ENC_H_ */
