/*
 *******************************************************************************
 *  Copyright (c) 2010-2021 VATICS 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 INC.                                                     |
 *  +-----------------------------------------------------------------+
 *
 *******************************************************************************
 */

#ifndef FEC_API_H
#define FEC_API_H

#include <sys/stat.h>
#include <iniparser/iniparser.h>
#include <vmf/video_source.h>
#include <vmf/gyro_daemon.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @struct   FEC_MODE
 * @brief    The structure for FEC MODE.
 */
typedef enum
{
	FEC_MODE_1O = 0,
	FEC_MODE_1R,
	FEC_MODE_180_A,
	FEC_MODE_180_O,
	FEC_MODE_180_T,
	FEC_MODE_PT
} FEC_MODE;

/**
 * @struct	Extra_PT
 * @brief	The structure for Extra_PT structure
 */
typedef struct
{
    unsigned int bExtraPtEn;
    unsigned int dwX[4];
    unsigned int dwY[4];
} Extra_PT;

typedef struct
{
	//! FEC default parameters
	unsigned int lens_type;
	unsigned int app_type;

    float orig_zoom;
    Extra_PT orig_extra_pt;
    float orig_src_radius;
    float orig_dst_radius;

	//! p180 all direction mode
    float p180a_tilt;
    float p180a_zoom;
    float p180a_focal;
    float p180a_spin;
    Extra_PT p180a_extra_pt;

	//! p180 one direction mode
    float p180o_tilt;
    float p180o_zoom;
    float p180o_focal;
    float p180o_spin;
    Extra_PT p180o_extra_pt;

	//! p180 two direction mode
    float p180t_tilt;
	float p180t_zoom;
	float p180t_focal;
	float p180t_curvature;
	float p180t_slope;
	float p180t_spin;

	//! p180 offset
	float p180_dst_offset_x;
	float p180_dst_offset_y;
	float p180_dst_xy_ratio; //! range:  0.1 ~ 2

	//! 1r mode
    float m1r_tilt;
    float m1r_zoom;
    float m1r_focal;
    float m1r_pan_wall;
    float m1r_tilt_wall;
    float m1r_dst_rotate;
    Extra_PT m1r_extra_pt;

	//! PT mode
	char* pszDatFile;
	char* pszComplexDatFile;
	char* pszMrfDatFile;

} FECDefValue;

/**
 * @struct	EIS_T
 * @brief	The structure for EIS structure
 */
typedef struct
{
	char* pszCurveNodesPath;
	float fGyroDataGain;
	unsigned int dwGridSection;
	unsigned int dwMaxGridSection;
	float fCropRatio;
	unsigned int dwImageType;
	unsigned int dwProcessMode;
	unsigned int dwCoordinateTransform[3];
	long long sqwTimeOffset;
	unsigned int bImageRotate180;
	int sdwReadoutTimeOffset;              //! Offset of VIC readout time
	float fReadoutTimeRatio;               //! Ratio of fusion readout time. Default: 1.0
    unsigned int bForceOriRs;
    VMF_VSRC_GYRO_CONFIG_T tGyroConfig;
} EIS_T;

int setup_fec_mode(VMF_VSRC_HANDLE_T*, VMF_LAYOUT_T*, FEC_MODE, unsigned int);
int loadFECConfig(HOST_STREAM_INIT_OPT_T*, VMF_VSRC_FRONTEND_CONFIG_T *);
int loadCalibrateConfig(HOST_STREAM_INIT_OPT_T*, VMF_VSRC_FRONTEND_CONFIG_T *);
void free_fec_def_str(void);

#ifdef __cplusplus
}
#endif

#endif
