
// PlayDemo_VCDlg.h : header file
//

#pragma once
#include "afxwin.h"

#include "CLS_DlgVedio.h"
#include "CLS_MyPublic.h"
#include "CLS_DlgDrawPolygon.h"
#include "CLS_DlgEZoom.h"
#include "CLS_TDButton.h"
#include "afxcmn.h"
#include "FECDlg.h"
#include "CLS_CudaCoreApi.h"
#include "./CudaCore/RetValue.h"
#include <list>

using namespace std;
typedef struct __CudaVideoMsgInfo
{
	DecAVInfo tAvInfo;
	DecVideoOtherInfo tAvInfoEx;
}CudaVideoMsgInfo;

typedef struct
{
	unsigned short 		iYear;   				/* Year */
	unsigned short 		iMonth;  				/* Month */
	unsigned short 		iDay;    				/* Day */
	unsigned short 		iHour;   				/* Hour */
	unsigned short 		iMinute; 				/* Minute */
	unsigned short 		iSecond; 				/* Second */
}NVS_FILE_TIME,*PNVS_FILE_TIME;

typedef struct tagDemoUserData
{
	int        uiFrameNo;  
	int        uiTimeStamp;
	int        iUserDataType;
	void*	   pvUserData;
	int        iUserDataSize;
}DemoUserData, *pDemoUserData;

typedef struct
{
	unsigned short		m_usSegmentLength;  /*时间的数据长度*/
	int					m_CurrentTime;		/*当前时间，本地时间*/
}TUserDataTimeSegment;

typedef struct
{
	int 	m_width; 
	int		m_height; 
}TAnalysSize;


typedef struct
{
	unsigned int		uiScene;		//按私有协议
	unsigned char		ucType;			//算法类型
	unsigned char		ucRule;			//规则号
	unsigned char       ucOsd;          //是否显示报警规则
	unsigned char		ucLen;			// 单个TLineInfo长度
	unsigned char		ucLine_num;		//静态线个数
}TRuleData;

typedef struct
{
	short 	m_type;		//0-255为视频诊断结果，256-512为音频诊断结果；
	short	m_value;	//0-100
}TVcaAVanalys;

#define MAX_TVCAAVANALYS	10
typedef struct
{
	int					iNumOutputs;			// 输出结果的数目
	TVcaAVanalys		m_analysInfo[MAX_TVCAAVANALYS];
}TVcaAVanalysEx;

typedef struct
{
	Tvca_cpcInfo 	m_cpcInfo;		/*统计结果*/
	vca_TTargetSet	VCATarget;		/*目标位置*/
}Tvca_CpcDate;

#define MAX_ENVIRONMENT_DATA	10
typedef struct 
{
	int m_iType;		 //数据类型：0-温度、1-湿度
	int m_iValue;		 //数值
}TEnvironmentData;

typedef struct
{
	int iCount;
	TEnvironmentData 	m_strData[MAX_ENVIRONMENT_DATA];	/*环境数据*/
}TEnvironment;

typedef struct
{
	int m_iUserSignType;	//用户数据类型，0-无标记，1-重点标记，2-音频标记（后两个参数有效）
	int m_iChn;				//视频通道
	int m_iAudioTagStat;	//0-无音频(音频结束)  1-有音频(音频开始)
}TUserSignPara;

typedef struct
{
	unsigned short		x;	//0-10000
	unsigned short		y;	//0-10000
} TPoint;

#define MAX_RULE_LINE_POINT_NUM 8

typedef struct
{
	unsigned char		close;								//是否封闭，1-封闭，0-不封闭
	unsigned char		point_num;							/*顶点个数*/
	TPoint				points[MAX_RULE_LINE_POINT_NUM];	/*顶点信息*/
}TLineInfo;

typedef struct
{
	unsigned short 		m_sSize;			/*结构体TTargetAttr的大小*/
	unsigned short		m_sTarget_num;		/*目标个数<=MAX_SAVE_TARGET_NUM */
}TTargetAttr;

//用于保存行为分析目标属性，格式如下
typedef struct
{
	TTargetAttr			m_stTgtAttr;		/*目标属性*/
} TUserDataVcaAttr;

//结构体TTargetAttrInfo中包含坐标、速度、方向等：
typedef struct
{
	unsigned short 		m_sSize;			/*结构体TTargetAttrInfo的大小*/
	unsigned short		m_sId;				/*目标ID*/
	unsigned short		m_sAttrNum;			/*目标属性个数*/
	unsigned short		m_sAttrNumEx;		/* TTargetAttrParaEx 目标属性个数*/
}TTargetAttrInfo;

typedef struct
{
	unsigned short 		m_sSize;			/*结构体TTargetAttrInfo的大小*/
	unsigned short		m_sId;				/*目标ID*/
	unsigned short		m_sAttrNum;			/*目标属性个数*/
}TTargetAttrInfoV1;

//目标属性结构体TTargetAttrPara中存储目标的属性，需满足注释中的规则
typedef struct
{
	int				m_iAttrPara;	/*目标属性
									m_iAttrPara [31-24bit]表示属性类型
									m_iAttrPara [23-0bit]表示属性值
									最多支持256种属性类型,见附表*/
}TTargetAttrPara;

//目标属性结构体TTargetAttrParaEx中存储变长的目标属性，需满足注释中的规则
typedef struct
{
	unsigned short		m_iType;    		//属性类型
	unsigned short		m_iLength;  		// m_iAttrPara[0]的属性长度，注意4字节对齐
	char				m_cAttrPara;		/*目标属性数据。见附表*/

}TTargetAttrParaEx;

typedef struct
{
	unsigned short	 m_size;
	unsigned short	 m_AddPass;
}Tvca_cpcInfoV1;

typedef struct
{
	unsigned short   m_size;
	unsigned short   m_value;		//按位表示数据有效类型，bit0-in，bit1-out，bit2-pass
	unsigned short   m_countIn;
	unsigned short   m_countOut;
	unsigned short	 m_countPass;
}Tvca_cpcInfoV3;

typedef struct
{
	int   x;						//匹配点横坐标，十万分比
	int   y;						//匹配点纵坐标，十万分比
	unsigned int		time;		//匹配点时间戳，单位ms
}UserDataTWSPointInfo;


//水尺基本信息
typedef struct
{
	unsigned short		size;
	unsigned short		lineLength;			//刻度线长度（万分比）
	unsigned short		lineWidth;			//刻度线宽度（万分比）
	unsigned short		relativeUnit;		//相对刻度单位 0-m，1-dm，2-cm，3-mm
	unsigned short		absoluteUnit;		//绝对刻度单位 0-m，1-dm，2-cm，3-mm
	unsigned short		x;					//水尺横坐标位置（万分比）
	unsigned short		y;					//绝对刻度线坐标（万分比）
	unsigned short		relativeNum;		//相对刻度点个数
	float				absolute;			//绝对刻度值
	unsigned int		color;				//水尺颜色 rgb
}TGaugeBase;

//水尺刻度线信息
typedef struct
{
	unsigned short		size;
	unsigned short		y;				//水尺纵坐标（万分比）
	float				high;			//水尺相对刻度
}TGaugePoint;

typedef struct
{
	TGaugeBase		base;
	TGaugePoint		gauge;
}TUserData_Gauge;

#define MAX_AREA_NUM_EX  12				   //区域最大数量
#define MAX_ILLEGAL_PARKING_POINTNUM  16   //坐标最大点数
typedef struct
{
	unsigned short m_usX;
	unsigned short m_usY;
}TIllegalPark_POINT;

typedef struct
{
	unsigned short		m_usRIllegalParkNo;				 //区域编号 从0开始
	unsigned short		m_usIllegalParkAreaCounts;       //违停区域点数
	TIllegalPark_POINT  m_structAreaEx[MAX_ILLEGAL_PARKING_POINTNUM];	//违法停车区域的坐标
}TIllegalParkInfo;

// CPlayDemo_VCDlg dialog
class CPlayDemo_VCDlg : public CDialog
{
public:
	CPlayDemo_VCDlg(CWnd* pParent = NULL);	// standard constructor
	enum { IDD = IDD_PLAYDEMO_VC_DIALOG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	HICON m_hIcon;
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
private:
	SDK_VERSION    m_Version;
	CString        m_cstrVersionString;
	int            m_iSpeed[MAX_WINDOWNUM];
	bool		   m_bLeftMouseDown;
	bool		   m_bTotalTimeFocus;
public:
	bool			m_blStatus;
	int             m_iEZoomID;
	CLS_DlgVedio *m_pDlgVedio[MAX_WINDOWNUM];
	CLS_PlaySDK   m_PlaySDK;
	CLS_DlgDrawPolygon m_DlgDrawPolygon;
	CLS_DlgEZoom m_DlgEZoom;
	CLS_FECDlg m_FECDlg;
	void Init();
	void DisplayFrame();
	void ShutWindow();
	bool IsPlayOnCurWin(int _iWinNum);
	CStatic m_gpVedio;
	int m_iCurVedio_Count;//作为切换1.4.9.16窗口的变量
	int m_iCurWinNum;	  //-----当前选中的播放窗口的序号（0-15）
	int m_iWidth;
	int m_iHeight;
	CMenu   m_mnPopMenu;      //右键菜单
	CLS_TDButton m_btnOpenFile;
	FILE *m_fpSave;
	bool m_bGetIFrame;
	int m_iSputRetValue[MAX_WINDOWNUM + MAX_SPECIAL_PLAYER_NUM];
	std::map<int, CString>   m_mapInfo;
	char* m_cFileDataBuf[MAX_WINDOWNUM + MAX_SPECIAL_PLAYER_NUM];
	int m_iAudio[MAX_WINDOWNUM];			//记录音频状态
	int m_iBmpNum;                          //抓拍Bmp图片名称中递增的数值 
	afx_msg void OnBnClickedBtn1();
	afx_msg void OnBnClickedBtn4();
	afx_msg void OnBnClickedBtn9();
	afx_msg void OnBnClickedBtn16();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnClose();
	afx_msg void OnBnClickedBtnOpenFile();
    void openFileFFmpegSoftDecode(CString& cstrPath);
    void openFile(CString& cstrPath);
	afx_msg void OnBnClickedBtnOpenStream();
	afx_msg void OnBnClickedBtnClose();
	afx_msg void OnBnClickedBtnSet();
	afx_msg LRESULT OnEventMessage(WPARAM wParam, LPARAM lParam);
	void GetData(int _iID);
	void ChangePutSpeed(int _iSpeedType);
	int PsPack_StopRecord();
	int PsPack_StartRecord();
	int PsPack_InputData(unsigned char* _ucData, int _iSize, int _iType);
	static int __cdecl PsPackNotify(int _iPlayerID, unsigned char* _ucData, int _iSize, PSPACK_INFO* _pPsPackInfo, void* _pContext);
	static void __cdecl PlayEndFun(int _iID);
	static int __cdecl CommonEventNotify(int _iPlayerID, int _iEventMessage, void* _lpUserData);
	static void  __cdecl GetDecAVCbk(int _iID, const DecAVInfo *_pDecAVInfo);
	static void __cdecl OutPutAudio(unsigned char* _pucData, int _iLen, void* _pvUserData);
	static void __cdecl ShowMotionArea(long _iPlayFd, HDC _hDc, int _iUsr);	
protected:
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
public:
	virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);
	void OnBnClickedBtnOpenAll();
	CButton m_btnAudio;
	int m_iEditFrame;

//控件变量
	CButton		m_chkSync;

	CProgressCtrl m_prgPlay;
	CSliderCtrl m_sld_progress;
	afx_msg void OnBnClickedBtnCaptureyuv();
	afx_msg void OnBnClickedBtnCapturebmp();
	afx_msg void OnBnClickedBtnPlay();
	afx_msg void OnBnClickedBtnPause();
	afx_msg void OnBnClickedBtnStep();
	afx_msg void OnBnClickedBtnBackstep();
	afx_msg void OnBnClickedBtnHome();
	afx_msg void OnBnClickedBtnEnd();
	afx_msg void OnBnClickedBtnFast();
	afx_msg void OnBnClickedBtnSlow();
	afx_msg void OnBnClickedBtnSearch();
	afx_msg void OnBnClickedBtnAudio();
	afx_msg void OnBnClickedBtnSeek();
	afx_msg void OnNMCustomdrawSldProgress(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedBtnPlayVod();
	afx_msg void OnBnClickedBtnCleanBuffer();
	afx_msg void OnDeltaposSpinSpeed(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	unsigned int  m_uiTimerGetPlayTime;
	unsigned int  m_uiTimerInputStream;
	unsigned int  m_uiTimerMain;
	unsigned int  m_uiTimerBatchCudaTest;
	unsigned int  m_uiTimerBatchCaptureTest;
	CEdit m_edtMsg;
	int m_edtCurSpeed;
	int m_iCurPlayNum;
	int m_iEdtTotalTime;
	int m_iEdtVSync;
	CButton m_btnCaptureAudio;
	CSpinButtonCtrl m_SpinAudio;
	int m_iEdtAudio;
	afx_msg void OnBnClickedBtnGetdecdata();
	afx_msg void OnBnClickedBtnStopGetdecdata();
	afx_msg void OnEnSetfocusDectotaltime();
	afx_msg void OnEnKillfocusDectotaltime();
	afx_msg void OnBnClickedBtnVsync();
	afx_msg void OnBnClickedBtnRecord();
	afx_msg void OnBnClickedBtnStoprec();
	afx_msg void OnBnClickedBtnFindvca();
	afx_msg void OnBnClickedBtnCaptureaudio();
	afx_msg void OnBnClickedCheckDrawmotionarea();
	afx_msg void OnBnClickedBtnDrawpolygon();
	void UpdateUI_ShowAudioVolume(const int _iPlayerID);
	afx_msg void OnBnClickedBtnSetezoom();
	afx_msg void OnDeltaposSpinAudio(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedButtonSetFec();
	afx_msg void OnBnClickedBtnReverse();
	afx_msg void OnBnClickedBtnOpenStreamCuda();
	afx_msg void OnBnClickedChkCudaTest();
	void CudaFilePlayerTest();
	void StartPlayFileNormal(int _iPlayWindowIndex, CString _cstrFileName);
	void EnableWindowNumSelect(bool _blEnable);
	void StartPlayFileWithCuda(int _iPlayWindowIndex, CString _cstrFileName);
	void StopPlayFile(int _iPlayWindowIndex);
	void StopPlaySpecial(int _iSpecialPlayIndex);
	void StartBatchCudaTest();
	void StopBatchCudaTest();
	void OnTimerBatchCudaTest();
	void OnTimerBatchCaptureBmp();
	void CaptureBmp(int _iPlayWindowIndex);
	void StartPlayGetNotifyDataWithCuda(int _iPlayWindowIndex, CString _cstrFileName);
	void Notify_DecodeAudioVideo(int _iPlayerId, DecAVInfo* _pAVInfo);
	afx_msg void OnBnClickedBtnStartDrawrect();
	afx_msg void OnBnClickedBtnStopDrawrect();
private:
	
	CButton m_chkDxvaHardDecode;
	CButton m_chkPrivateSoftDecode;
	CButton m_chkFfmpegSoftDecode;
	CButton m_chkVideoRenderD3D;
	CButton m_chkVideoRenderDraw;
	CButton m_chkVideoDispalyYuv422;
	CButton m_chkVideoDispalyYuv420;
public:
	afx_msg void OnBnClickedCheckDxvaHw();
	afx_msg void OnBnClickedCheckPrivateDecoder();
	afx_msg void OnBnClickedCheckFfmpegDecoder();
	afx_msg void OnBnClickedCheckVideoRenderD3d();
	afx_msg void OnBnClickedCheckVideoRenderDraw();
	afx_msg void OnBnClickedCheckVideoDisplay422();
	afx_msg void OnBnClickedCheckVideoDisplay420();
	afx_msg void OnBnClickedCheckSync();
	afx_msg void OnBnClickedBtnReverseStep();
private:
    list <DemoUserData*> m_lstUsrData;
	CRITICAL_SECTION m_tLockLst;
	CButton m_chkUniversalPlayer;
	CButton m_chkSaveUserData;
	FILE* m_pfSaveUserDataFile;
	HANDLE m_hThreadHdl;
	int m_bIsUsrDataEnd;
public:
	afx_msg void OnBnClickedCheckSaveUserData();
	static void __stdcall DevUserDataNotify(unsigned int _uiID, int _iType, void* _pvData, int _iDataLen, CurrentFrameInfo* _ptInfo, void* _pvUdata);
	static unsigned int WINAPI SaveUserDataThread(LPVOID _Param);
	void SaveUserDataToLocalFile(DemoUserData*);
	CComboBox m_cboRecFileType;
	int seconds_to_file_time(NVS_FILE_TIME* filetime, long seconds);
};

