


#ifndef _VDEC_TEE_INTERFACE_H_
#define _VDEC_TEE_INTERFACE_H_
#include <linux/types.h>

#define INVALID_TEE_PARSER_ID (0xFFFFFFFF)

#define VDEC_IF 0


struct tee_framing_param {
	uint64_t es_start;
	uint64_t es_end;
	uint8_t update_parser;	// update parser with ES data info or not
	uint32_t es_data_offset;
	uint32_t es_data_size;
	uint32_t find_ret;
	uint64_t unit_base;
	void *unit_table;
	uint32_t unit_table_size;
	uint32_t unit_entity_size;
	uint32_t unit_found_num;
	uint8_t find_last_unit;
};

struct tee_pre_parse_param {
	uint32_t u32CodecType;
	uint64_t u64EsDataStart;
	uint64_t u64EsDataEnd;
	uint32_t u32Width;
	uint32_t u32Height;
	uint32_t u32FrameRate;
	uint32_t u32BitDepth;
	uint32_t u32DpbSize;
};

struct tee_vcu_svp_call_arg {
	uint64_t u64Data;
	uint32_t u32Size;
};

#ifndef _EN_VES_PARSER_DV_TYPE_
#define _EN_VES_PARSER_DV_TYPE_
typedef enum {
	E_VES_PARSER_DV_BL = 0,
	E_VES_PARSER_DV_RPU = 1,
	E_VES_PARSER_DV_EL = 2,
} EN_VES_PARSER_DV_TYPE;
#endif

#define VES_FLAG_NOT_FIRST_UNIT          (1 << 0)
#define VES_FLAG_IS_PIC                  (1 << 1)
#define VES_FLAG_I_FRAME                 (1 << 2)

#ifndef _VES_PARSER_ES_UNIT_S_
#define _VES_PARSER_ES_UNIT_S_
typedef struct VES_PARSER_ES_UNIT_S {
	uint32_t offset;
	uint32_t size;
	uint8_t unitType;		// NAL byte raw data
	uint8_t unitInfo;		// Flags that contains VES_FLAG_XXXX
	// if hevc, reserved0, reserved1 store nalu header for hevc parsing
	uint8_t reserve0;
	uint8_t reserve1;
	EN_VES_PARSER_DV_TYPE dvType;	// Dolby vision type, EN_VIDEO_ESPARSER_DV_TYPE
} VES_PARSER_ES_UNIT;

struct MPEG_ES_UNIT {
	uint32_t offset;
	uint32_t size;
	uint8_t unitType;		// NAL byte raw data
	uint8_t unitInfo;		// Flags that contains VES_FLAG_XXXX
	uint8_t bFoundPicHeader;	// if mpeg, reserved0: 1 for found pic header, 0 not found
	uint8_t pic_struct;	// 1 top field, 2 bottom field, 3 frame
	EN_VES_PARSER_DV_TYPE dvType;	// Dolby vision type, EN_VIDEO_ESPARSER_DV_TYPE
};

struct avc_custom_flag {
	unsigned char  bIFrame:    1;
	unsigned char  field_pic_flag:    1;
	unsigned char  bottom_field_flag:    1;
	unsigned char  is_ref:    1;
	unsigned char  reserved:    4;
};

union avc_custom_union {
	unsigned char data;
	struct avc_custom_flag f;
};

struct AVC_ES_UNIT {
	uint32_t offset;
	uint32_t size;
	uint8_t unitType;		// NAL byte raw data
	union avc_custom_union unitInfo;
	uint16_t frame_num;
	EN_VES_PARSER_DV_TYPE dvType;	// Dolby vision type, EN_VIDEO_ESPARSER_DV_TYPE
};

struct hevc_custom_flag {
	unsigned char  bIFrame:    1;
	unsigned char  field_flag:    2;
	unsigned char  reserved:    5;
};

union hevc_custom_union {
	unsigned char data;
	struct hevc_custom_flag f;
};

struct HEVC_ES_UNIT {
	uint32_t offset;
	uint32_t size;
	uint8_t unitType;		// NAL byte raw data
	union hevc_custom_union unitInfo;
	uint16_t frame_num;
	EN_VES_PARSER_DV_TYPE dvType;	// Dolby vision type, EN_VIDEO_ESPARSER_DV_TYPE
};
#endif


int ves_parser_tee_create(uint32_t ree_parser_id,
	uint32_t codec_type,
	uint64_t es_start,
	uint64_t es_end,
	uint8_t incomplete_bs,
	uint32_t *parser_id,
	uint32_t u32UnitTableLength);

int parserAddEsData(uint32_t ree_parser_id,
	uint32_t u32ParserId,
	uint64_t u64DataStartAddr,
	uint32_t u32DataSize);


int parserFindEsUnits(uint32_t ree_parser_id,
	uint32_t u32ParserId,
	struct VES_PARSER_ES_UNIT_S **pUnitTable,
	uint32_t u32UnitTableLength,
	uint32_t *pFindRet,
	uint64_t *pUnitBaseAddr,
	uint32_t *pFoundUnitNum,
	uint8_t  *pFindLastUnit);

int ves_parser_tee_destroy(uint32_t ree_parser_id, uint32_t parser_id);

int ves_parser_tee_framing(uint32_t ree_parser_id, uint32_t parser_id,
	struct tee_framing_param *framing_param);

#endif
