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

/*----------------------------------------------------------------------------*/
/*! @file u_cap.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This file exports all capture library API and constant for 
 *         other module using.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_CAP Capture Logo
 *
 *  @ingroup groupMW
 *  @brief Provides external function TV Application
 *
 *  %MW Application API would be used by TV Application, lot of these APIs would
 *   be wrapped from Exported API
 *
 *  @see groupMW
 *  @{ 
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_CAP_H_
#define _U_CAP_H_


/*-----------------------------------------------------------------------------
                    include files
 ----------------------------------------------------------------------------*/
#include "u_common.h"
#include "u_handle.h"
#include "x_vid_plane.h"
#include "u_img.h"

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

#ifdef __cplusplus
extern "C" {
#endif

#define HT_CAP_TYPE           (HT_GROUP_CAP + 1)

/* Type Define For Capture Source *******************************/
typedef enum
{
    CAP_SRC_TYPE_DEFAULT = 0,
    CAP_SRC_TYPE_TV_VIDEO,
    CAP_SRC_TYPE_MM_VIDEO,
    CAP_SRC_TYPE_MM_IMAGE,
    CAP_SRC_TYPE_MM_IMAGE_ANDROID
}   CAP_SRC_TYPE_T;

/* Event Define For Capture Operation *******************************/
typedef enum
{
    CAP_EVENT_TYPE_OPEN_DONE = 1,
    CAP_EVENT_TYPE_OPEN_ERROR,
    CAP_EVENT_TYPE_CAP_DONE,
    CAP_EVENT_TYPE_CAP_ERR,
    CAP_EVENT_TYPE_SAVE_DONE,
    CAP_EVENT_TYPE_SAVE_ERROR,
    CAP_EVENT_TYPE_DO_CAPTURING,
    CAP_EVENT_TYPE_DO_SAVING 
    /*to be extend*/
}   CAP_EVENT_TYPE_T;

/* Event Define For Capture Format *******************************/
typedef enum
{
    CAP_IMG_FMT_TYPE_DEFAULT = 0,
    CAP_IMG_FMT_TYPE_MPEG,
    CAP_IMG_FMT_TYPE_JPEG,
    CAP_IMG_FMT_TYPE_RAW
    /*to be extend*/ 
}   CAP_IMG_FMT_TYPE_T;


/* Event Define For Capture Output Resolution *******************************/
typedef enum
{
    CAP_OUT_RES_TYPE_SD = 0,
    CAP_OUT_RES_TYPE_HD,
    CAP_OUT_RES_TYPE_USER
    /*to be extend*/ 
}   CAP_OUT_RES_TYPE_T;

#pragma pack(4)
/* Capture information definition *******************************/
typedef struct _CAP_CAPTURE_INFO_T
{
    CAP_IMG_FMT_TYPE_T      e_format;  
    UINT32                  ui4_quality;
    UINT32                  ui4_max_size;
    HANDLE_T                h_src_surf;/* For capture photo use*/
    HANDLE_T                h_working_surf;/* For capture photo use*/
    CAP_OUT_RES_TYPE_T      e_res_type;    
    UINT8                   ui1_video_path;

    GL_RECT_T               t_rec;
    UINT32                  ui4_moveable_width;
    UINT32                  ui4_moveable_height;

	//for android image
	UINT32	ui4_image_width;
	UINT32	ui4_image_height;
	UINT32	ui4_image_pitch;
	CAP_COLOR_FORMAT_T	e_colormode;
	INT32		i4_shm_id;
    union 
    {/* used for IMG_CAP_RESOLUTION(HW & SW) */        
        struct 
        {
            UINT32  ui4_res_width;
            UINT32  ui4_res_height;
        } t_resolution;
    }u;
} CAP_CAPTURE_INFO_T;
#pragma pack()

#pragma pack(4)
typedef struct _CAP_CAPABILITY_INFO_T
{
    BOOL    b_default;      /* enable default boot logo */
    BOOL    b_default_exist;/* is default boot logo exist*/
    UINT8   ui1_cur_logo_index;
    UINT8   ui1_nums_logo_slots;
    UINT16  ui2_logo_valid_tag;
  /*to be extend*/
} CAP_CAPABILITY_INFO_T;
#pragma pack()

/* Event Define For Capture Output Resolution *******************************/
typedef enum
{
    CAP_DEVICE_TYPE_DEFAULT,
    CAP_DEVICE_TYPE_EXTERNAL,
    CAP_DEVICE_TYPE_INTERNAL
    /*to be extend*/ 
} CAP_DEVICE_TYPE_T;


/* Capture information definition *******************************/
typedef struct _CAP_LOGO_SAVE_INFO_T
{
    CAP_DEVICE_TYPE_T       e_device_type;  
    union 
    {
        UINT32 ui4_logo_id;
        CHAR*  ps_path;
    } u;
} CAP_LOGO_SAVE_INFO_T;

#pragma pack(4)

typedef struct _CAP_LOGO_SAVE_INFO_EX_T
{
    CAP_DEVICE_TYPE_T       e_device_type;  
    union 
    {
        UINT32              ui4_logo_id;
        UNION_POINTER_T     ps_path;
    } u;
} CAP_LOGO_SAVE_INFO_EX_T;

#pragma pack()
typedef CAP_LOGO_SAVE_INFO_T CAP_LOGO_SELECT_INFO_T;
typedef CAP_LOGO_SAVE_INFO_EX_T CAP_LOGO_SELECT_INFO_EX_T;
/************************************************************************/
/* Error code                                                           */
/************************************************************************/
#define CAPR_OK                     ((INT32)     0)
#define CAPR_INSUFFICIENT_BUFFER    ((INT32)    -1)
#define CAPR_INV_HANDLE             ((INT32)    -2)
#define CAPR_OUT_OF_HANDLE          ((INT32)    -3)
#define CAPR_OUT_OF_MEMORY          ((INT32)    -4)
#define CAPR_FCT_NOT_SUPPORT        ((INT32)    -5)
#define CAPR_NAME_EXIST             ((INT32)    -6)
#define CAPR_INV_ARG                ((INT32)    -7)
#define CAPR_ENGINE_NOT_FOUND       ((INT32)    -8)
#define CAPR_INTERNAL_ERR           ((INT32)    -9)
#define CAPR_ENCODE_FAIL            ((INT32)   -10)
#define CAPR_INITIAL_ERR            ((INT32)   -11)
#define CAPR_MSG_Q_ERR              ((INT32)   -12)
#define CAPR_IO_ERROR               ((INT32)   -13)
#define CAPR_DRV_BUSY               ((INT32)   -14)
#define CAPR_CLI_ERROR              ((INT32)   -15)


/*-----------------------------------------------------------------------------
                    functions declarations
 ----------------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/*! @brief      x_cap_nfy_fct
 *              This function is the callback function of capture library.
 *  @param [in] h_handle     Specifies which handle will be notified. 
 *  @param [in] pv_tag       The client data specified by the client when callback has been called, the callback function will send it again.. 
 *  @param [in] e_event      It identifies the event type of notification. 
 *  @param [in] pv_data      Specified the notification data which is followed with the notification event. 
 */
/*------------------------------------------------------------------*/
typedef VOID (*x_cap_nfy_fct) (
                                HANDLE_T                h_handle,  /* (I) Specifies which handle will be notified. */
                                const VOID*             pv_tag,    /* (I) The client data specified by the client when callback has been called, the callback function will send it again.. */
                                CAP_EVENT_TYPE_T        e_event,   /* (I) It identifies the event type of notification. */
                                const VOID*             pv_data);   /* (I) specify the notification data which is followed with the notification event. */


/*------------------------------------------------------------------*/
/*! @brief      x_cap_cust_fct
 *              This function is the function of capture library.
 *  @param [in] e_source     Specifies the source which will be captured. 
 *  @param [in] e_event      It identifies the event type of notification. 
 *  @param [in] pv_data      Specified the notification data which is followed with the notification event. 
 */
/*------------------------------------------------------------------*/
typedef BOOL (*x_cap_cust_fct) (
                                CAP_SRC_TYPE_T          e_source,  /* (I) Specifies the source which will be captured. */
                                CAP_EVENT_TYPE_T        e_event,     /* (I) It identifies the event type of notification. */
                                const VOID*             pv_data);     /* (I) specify the notification data which is followed with the notification event. */




typedef struct
{
    HANDLE_T            h_cap;
    HANDLE_T            h_src_surf;/* For capture photo use*/    
    HANDLE_T            h_working_surf;/* For capture photo use*/    
    HANDLE_T            h_cap_cancel_exe_sema;/* For sync stop use*/    
    BOOL                b_cancel_exe_flag;/* For sync stop use*/  
    CAP_OUT_RES_TYPE_T  e_res_type; 
    CAP_EVENT_TYPE_T    e_cur_event;
    CAP_SRC_TYPE_T      e_source;           /* (I) specifies the open mode of the open operation*/ 
    x_cap_nfy_fct       pf_nfy;             /* (I) specify the callback function to receive the notification of image library. */ 
    const VOID*         pv_nfy_tag;         /* (I) The client data specified by the client and the callback function will send it again. */ 
    x_cap_cust_fct      pf_cust;            /* (I) Specified the function to customize user's operation when creating handle. */ 
    const VOID*         pv_cust_tag; 

    CAP_LOGO_SAVE_INFO_T t_save_info;
    CAP_INPUT_T         t_cap_input;
    CAP_OUTPUT_T        t_cap_output;

    UINT32                  ui4_moveable_width;
    UINT32                  ui4_moveable_height;
} CAP_OBJ_T;


#ifdef __cplusplus
}
#endif

#endif /* _U_CAP_H_ */
/*----------------------------------------------------------------------------*/
/*! @} */   /* end of  groupMW_CAP*/
/*----------------------------------------------------------------------------*/
