#ifndef _UMF_CEC_H_
#define _UMF_CEC_H_

#include "cecd_interface.h"
#include <pthread.h>
#include <umf_ir.h>


typedef struct _SystemAudio_t
{
	LOGADDR	logAddr;
	PHYADDR	phyAddr;
	audio_status_t	state;
	UINT8		volLevel:7;
	UINT8		volMute:1;	
	audio_ARCstatus_t ARCstatus;
}SystemAudio_t;

typedef struct _CEC_t
{
	INT32				UMFtoCECMsqid;
	INT32 				CECtoUMFMsqid;
	pthread_t			cecthread;
	BOOL			bCECExecuted;
	#ifdef CONFIG_HDMI_ALL_PORT_TERMINATION_ON
	BOOL 			bActiveSrcCheck;
	#endif
	LOGADDR		LogAddr;	
	PHYADDR		PhyAddr;	
	tv_source_t 		inputSource;	
	cecd_status_t		cecState;
	deck_status_t		deckState;
	menu_status_t	menuState;
	menu_status_t	uccState;	
	SystemAudio_t	systemAudio;
	OSDSTRING 		osdString;
	tv_source_t 		PreSource;	
}CEC_t;

typedef INT32 (*CB_SETSOURCE)(UINT32 Input);
typedef INT32 (*CB_CECOSD)(UINT8 mode);

/*
HRESULT cec_Init(void);
HRESULT cec_Destroy(CEC_t *pcec);
HRESULT cec_Suspend(CEC_t *pcec);

HRESULT cec_NoticeStandby(CEC_t *pcec, BOOLEAN status);
HRESULT cec_NoticeSourceChange(CEC_t *pcec);
//HRESULT cec_NoticeMenuLanguage(CEC_t *pcec, UINT8 OsdLang);
HRESULT cec_NoticeMenuLanguage(char lang[3]);
HRESULT cec_NoticePowerStatus(CEC_t *pcec);
HRESULT cec_RefreshDeviceList(CEC_t *pcec);
HRESULT cec_AssignDisplayDevice(CEC_t *pcec, PHYADDR phyAddr, LOGADDR logAddr);
HRESULT cec_QueryDeckStatus(CEC_t *pcec);
HRESULT cec_DeckControl(CEC_t *pcec, Keycode_t keycode);

HRESULT cec_ChangeSource(CEC_t *pcec, UINT32 Input);

HRESULT cec_RequestAudioMode(CEC_t *pcec, BOOL bEnable);
HRESULT cec_RequestARC(CEC_t *pcec, UINT8 ARCstatus);
HRESULT cec_QueryARCStatus(CEC_t *pcec, UINT8 ARCstatus, UINT8 waitSecs);
menu_status_t cec_RequestDeviceMenuStatus(CEC_t *pcec, menu_request_t menuRequestType, UINT8 waitSecs);
CEC_t *cec_GetHandle(void);
HRESULT cec_SetHDMIControl(BOOLEAN status, BOOLEAN bDefault);
BOOL cec_GetHDMIControl(BOOLEAN bDefault);
BOOL cec_GetAudioARC(BOOLEAN bDefault);
BOOLEAN cec_GetHDMIAudioARCStatus();
void cec_Register(CB_SETSOURCE CB_setSrc, CB_CECOSD CB_OSDEvent);
void cec_SetVolumn(UINT8 value);
*/

void _Stop(void);
void cec_NoticeMenuLanguage(UINT8 OsdLang);
INT32 cec_KeyProcess(UINT8 CECTV_KEY);
INT32 cec_DeckControl(UINT8 CECTV_KEY);
INT32 cec_UserControlCode(UINT8 CECTV_KEY);
INT32 cec_RemoteControlPassThrough(UINT8 CECTV_KEY);
INT32 cec_SetAudioARC(BOOL bEnable);
void cec_EnableARCfunctionTimer(BOOL enableARC);
HRESULT cec_RequestAudioMode(BOOL bEnable);
//BOOL CECTV_GetAudioARC(void);
void cec_RefreshDeviceList(void);
void cec_SetTvAutoPwrOn(BOOL status);
INT32 cec_SetDevAutoPwrOff(BOOL status);
void cec_ChangeSource(tv_source_t tvsource);
void CECTV_GetDeviceList(PDEVICEINFO_LIST pdeviceList);
INT32 CECTV_SetDeviceNum(UINT8 DevIndex);
//int CECTV_HDMIPortStatus(UINT32 HdmiPortStatus);
void cec_SetCECenable(UINT32 status);
void cec_RequestAudioStatus(void);
HRESULT cec_SendDeactivedARCTX(CEC_t *pcec);
HRESULT cec_NoticeRoutingInfo(tv_source_t tvsource);


/*******************************************************************
* Constant
********************************************************************/

#define CECTV_KEY_SELECT                     0x00
#define CECTV_KEY_UP                         0x01
#define CECTV_KEY_DOWN                       0x02
#define CECTV_KEY_LEFT                       0x03
#define CECTV_KEY_RIGHT                      0x04
#define CECTV_KEY_RIGHT_UP                   0x05
#define CECTV_KEY_RIGHT_DOWN                 0x06
#define CECTV_KEY_LEFT_UP                    0x07
#define CECTV_KEY_LEFT_DOWN                  0x08
#define CECTV_KEY_ROOT_MENU                  0x09
#define CECTV_KEY_SETUP_MENU                 0x0a
#define CECTV_KEY_CONTENTS_MENU              0x0b
#define CECTV_KEY_FAVORITE_MENU              0x0c
#define CECTV_KEY_EXIT                       0x0d
#define CECTV_KEY_0                          0x20
#define CECTV_KEY_1                          0x21
#define CECTV_KEY_2                          0x22
#define CECTV_KEY_3                          0x23
#define CECTV_KEY_4                          0x24
#define CECTV_KEY_5                          0x25
#define CECTV_KEY_6                          0x26
#define CECTV_KEY_7                          0x27
#define CECTV_KEY_8                          0x28
#define CECTV_KEY_9                          0x29
#define CECTV_KEY_DOT                        0x2a
#define CECTV_KEY_ENTER                      0x2b
#define CECTV_KEY_CLEAR                      0x2c
#define CECTV_KEY_NEXT_FAVORITE              0x2f
#define CECTV_KEY_CHANNEL_UP                 0x30
#define CECTV_KEY_CHANNEL_DOWN               0x31
#define CECTV_KEY_PREVIOUS_CHANNEL           0x32
#define CECTV_KEY_SOUND_SELECT               0x33
#define CECTV_KEY_INPUT_SELECT               0x34
#define CECTV_KEY_DISPLAY_INFO               0x35
#define CECTV_KEY_HELP                       0x36
#define CECTV_KEY_PAGE_UP                    0x37
#define CECTV_KEY_PAGE_DOWN                  0x38
#define CECTV_KEY_POWER                      0x40
#define CECTV_KEY_VOLUME_UP                  0x41
#define CECTV_KEY_VOLUME_DOWN                0x42
#define CECTV_KEY_MUTE                       0x43
#define CECTV_KEY_PLAY                       0x44
#define CECTV_KEY_STOP                       0x45
#define CECTV_KEY_PAUSE                      0x46
#define CECTV_KEY_RECORD                     0x47
#define CECTV_KEY_REWIND                     0x48
#define CECTV_KEY_FAST_FORWARD               0x49
#define CECTV_KEY_EJECT                      0x4a
#define CECTV_KEY_FORWARD                    0x4b
#define CECTV_KEY_BACKWARD                   0x4c
#define CECTV_KEY_STOP_RECORD                0x4d
#define CECTV_KEY_PAUSE_RECORD               0x4e
#define CECTV_KEY_ANGLE                      0x50
#define CECTV_KEY_SUB_PICTURE                0x51
#define CECTV_KEY_VOD                        0x52
#define CECTV_KEY_EPG                        0x53
#define CECTV_KEY_TIMER_PGM                  0x54
#define CECTV_KEY_INITIAL_CFG                0x55
#define CECTV_KEY_SYSTEMAUDIOMODE_FUNC       0x56//Bryan@2010-0430 Add for CEC
#define CECTV_KEY_PLAY_FUNC                  0x60
#define CECTV_KEY_PAUSE_PLAY_FUNC            0x61
#define CECTV_KEY_RECORD_FUNC                0x62
#define CECTV_KEY_PAUSE_RECORD_FUNC          0x63
#define CECTV_KEY_STOP_FUNC                  0x64
#define CECTV_KEY_MUTE_FUNC                  0x65
#define CECTV_KEY_RESTORE_VOL_FUNC           0x66
#define CECTV_KEY_TUNE_FUNC                  0x67
#define CECTV_KEY_SELECT_MEDIA_FUNC          0x68
#define CECTV_KEY_SELECT_AV_INPUT_FUNC       0x69
#define CECTV_KEY_SELECT_AUDIO_INPUT_FUNC    0x6a
#define CECTV_KEY_POWER_TOGGLE_FUNC          0x6b
#define CECTV_KEY_F1_BLUE                    0x71
#define CECTV_KEY_F2_RED                     0x72
#define CECTV_KEY_F3_GREEN                   0x73
#define CECTV_KEY_F4_YELLOW                  0x74
#define CECTV_KEY_F5                         0x75
#define CECTV_KEY_DATA                       0x76
#define CECTV_KEY_VOLUME_UP_RELEASE          0x77
#define CECTV_KEY_VOLUME_DOWN_RELEASE        0x78
#define CECTV_KEY_MUTE_RELEASE          0x79

//******************************************************************************//
//New structure
//******************************************************************************//

#define CECTV_MULTI_ACT_CMD_TYPE                   (1<<13)
#define CECTV_SINGLE_ACT_CMD_TYPE                  (1<<12)
#define CECTV_CMD_TYPE_MASK                        (0xFFFF0000)
#define CECTV_CMD_MASK                             (0x0000FFFF)

typedef enum
{
    CECTV_MESSAGE_CHANGE_SOURCE ,
	CECTV_MESSAGE_STANDBY,		
	CECTV_MESSAGE_SET_MUTE_STATUS,	
	CECTV_MESSAGE_SET_SYSTEMAUDIO_STATUS,
	CECTV_MESSAGE_SET_DEVICE_OSDNAME,
	CECTV_MESSAGE_MAX,
} CECTV_Message_t;

typedef int (*CECTV_ModCbk_pf)(CECTV_Message_t message, UINT32 arg);

typedef struct CECTV_ModualCfg_t_
{
	CECTV_ModCbk_pf		pfCallBack;
} CECTV_ModualCfg_t;

typedef enum 
{
    CECTV_DISABLE = 0,
    CECTV_ENABLE,
} CECTVEnableStatus_t;

typedef struct CEC_CmdBody_t_ {
	UINT32 dMessage;
	UINT32 dParam;
} CEC_CmdBody_t;

typedef struct CECTV_MessageBody_t_ {
	UINT32 dMessage;
	UINT32 dParam;
} CECTV_MessageBody_t;

typedef enum
{
    CECTV_ACK_STAT_WAIT            = 0x00,
    CECTV_ACK_STAT_SUCCESS         = 0x01,
    CECTV_ACK_STAT_FAILED          = 0x02,
} CECTV_Ack_Stat_t;

typedef enum 
{
    CEC_TASK_IDLE = 0,
    CEC_TASK_SEND_MESAGE,
    CEC_TASK_Standby,
} CECTaskStatus_t;

typedef enum
{
	CECTV_SUCCESS,					// successful outcome
	CECTV_ERR_FAILURE,				// operation failed
	CECTV_ERR_NULL_PARAM,			// null parameter

} CECTV_Status_e;

typedef enum
{
	CEC_Daemon_Message_level_Normal = 0,
   	CEC_Daemon_Message_level_Detail
} CEC_DaemonMessageLevel_e;

typedef enum
{
    CECTV_ACT_CMD_NONE                            = 0x1000,
    CECTV_SINGLE_ACT_CMD_KEYPRESS                 = 0x1001,
    CECTV_SINGLE_ACT_CMD_KEYRELEASE               = 0x1002,
    CECTV_SINGLE_ACT_CMD_KEYREPEAT= 0x1003,
    CECTV_SINGLE_ACT_CMD_STANDBY= 0x1004,
    CECTV_SINGLE_ACT_CMD_SET_OSD_LANGUAGE= 0x1005,
    CECTV_SINGLE_ACT_CMD_CHGSRC_OUT_HDMI= 0x1006,
    CECTV_SINGLE_ACT_CMD_CHGSRC_TO_HDMI= 0x1007,
    CECTV_SINGLE_ACT_CMD_CHGSRC_BTW_HDMI= 0x1008,
    CECTV_SINGLE_ACT_CMD_SYSAUD_MODE_REQ_ON= 0x1009,
    CECTV_SINGLE_ACT_CMD_SYSAUD_MODE_REQ_OFF= 0x100a,
    CECTV_SINGLE_ACT_CMD_SET_ARC_OPTION_DISABLE= 0x100b,
    CECTV_SINGLE_ACT_CMD_REQUEST_ARC_INITIATION= 0x100c,
    CECTV_SINGLE_ACT_CMD_REQUEST_ARC_TERMINATION= 0x100d,
    CECTV_SINGLE_ACT_CMD_GIVE_DECK_STATUS= 0x100e,
    CECTV_SINGLE_ACT_CMD_PLAY= 0x100f,
    CECTV_SINGLE_ACT_CMD_DECK_CONTROL= 0x1010,
    CECTV_SINGLE_ACT_CMD_SET_DEVICENUM= 0x1011,
    CECTV_SINGLE_ACT_CMD_SET_CECENABLE= 0x1012,
    CECTV_SINGLE_ACT_CMD_SET_AUTOPOWERON= 0x1013,
    CECTV_SINGLE_ACT_CMD_SET_DEVAUTOPOWEROFF= 0x1014,
    CECTV_SINGLE_ACT_CMD_REQUEST_AUDIO_STATUS= 0x1015,
    CECTV_SINGLE_ACT_CMD_REQUEST_SYSTEMAUDIOMODE_ON= 0x1016,
    CECTV_SINGLE_ACT_CMD_REQUEST_SYSTEMAUDIOMODE_OFF= 0x1017,
    CECTV_SINGLE_HDMI_ARC_SWITCH = 0x1018,
    CECTV_SINGLE_ACT_ROUTING_INFO =0x1019,
    CECTV_MULTI_ACT_CMD_TESTMODE                  = 0x2001,
    CECTV_MULTI_ACT_CMD_AUDIO_SYSTEM_INITE        = 0x2002,

} CECTV_Act_Cmd_t;

typedef enum 
{
    AMP_OFF = 0x01,
    AMP_ON = 0x2,
    AMP_5V_OFF = 0x4,
    AMP    = 0x08,
    ARC_OFF = 0x10,
    ARC_ON = 0x20,
    AMP_ARC = 0x80,
    AMP_AUDIO_FORMAT = 0x100,
} CECSystemAudioStatus_t;

typedef enum 
{
    Audio_Format_Reserved = 0,
    Audio_Format_LPCM, //Linear PCM
    Audio_Format_AC3,
    Audio_Format_MPEG1,
    Audio_Format_MP3,
    Audio_Format_MPEG2,
    Audio_Format_AAC,
    Audio_Format_DTS,
    Audio_Format_ATRAC,
    Audio_Format_OBA, //One Bit Audio
    Audio_Format_DDPlus, //Dolby Digital +
    Audio_Format_DTSHD,
    Audio_Format_MAT,
    Audio_Format_DST,
    Audio_Format_WMAPro,
    Audio_Format_Format15,
    Audio_Format_Max,
} Audio_Format_Codes;

typedef enum 
{
	Audio_Output_Com_NA = 0x0,
	Audio_Output_Com_Delay = 0x1,
	Audio_Output_Com_NoDelay = 0x2,
	Audio_Output_Com_Partially = 0x3,
	Low_Latency_Mode_Normal = 0x0,
	Low_Latency_Mode_Low = 0x4,
	Reserved_Latency_Flags = 0x0,
}Latency_Flags;

typedef enum 
{
	Deprecated00 = 0x0,
	Deprecated01 = 0x1,
	Deprecated02 = 0x2,
	Deprecated03 = 0x3,
	Version13a = 0x4,
	Version14ab = 0x5,
	Version20 = 0x6,
	CECVersionReserved,
}CECVersion;

typedef enum 
{
	ADT_TV = 0x80,
	ADT_RecordDevice = 0x40,
	ADT_Tuner = 0x20,
	ADT_PlaybackDevice = 0x10,
	ADT_AudioSystem = 0x8,
	ADT_CECSwitch = 0x4,
	ADT_Reserved,
}ALL_Device_Type;


void CECTV_SetCECSrcIdx(tv_source_t src);
UINT32 CECTV_IsFirstPowerOn(void);
int  CECTV_GetPowerStatus(void);
CECTaskStatus_t  CECTV_GetAtmosVal(void);
CECTaskStatus_t  CECTV_GetDDPlusVal(void);
CECTaskStatus_t  CECTV_GetCECTaskStatus(void);
CECTV_Status_e CECTV_SetCECTaskStatus(CECTaskStatus_t CECTaskStatus);
CECTV_Status_e CECTV_SetCECEnable(CECTVEnableStatus_t fEn);
CECTVEnableStatus_t CECTV_GetCECEnable(void);
void CECTV_SetAudioARC(bool val);
BOOL CECTV_GetAudioARC(void);
CECTV_Status_e CECTV_SetSpeakerPreference(BOOL fEn);
BOOL CECTV_GetSpeakerPreference(void);
BOOL CECTV_GetHDMIAudioARCStatus(void);
BOOL CECTV_GetHDMISystemAudioMode(void);
BOOL CECTV_CheckARCDevice(void);
BOOL CECTV_CheckDeviceDiscover(void);
void CECTV_SetRequestARC(bool val);
void CECTV_Init(CECTV_ModualCfg_t *pCEC_ModualCfg);
CECTV_Status_e CECTV_SendCmd(UINT32 dMessage, UINT32 dParam);
UINT8 CECTV_GetAutoPwrOnSrc(void);
INT32 CECTV_HDMIPortStatus(UINT32 HdmiPortStatus);
tv_source_t cec_QueryPlayBackDeviceLogaddr(tv_source_t tvsource);
UINT32 cec_QueryPlayBackDevicePhyaddr(tv_source_t tvsource);
#ifdef CONFIG_SUPPORT_DOLBY_AUDIO
HRESULT cec_RequestShortAudioDescriptor(void);
#endif
HRESULT cec_Hdmi_ARC_Switch(UINT8 ARCstatus);


#endif
