#pragma once
#include "afxcmn.h"
#include "RecordEx.h"
#include "afxwin.h"
#include "NetSDKDLL.h"
#include <vector>
using namespace std;

typedef vector<int> VEC_INT;

typedef struct __DLoadTask
{
	int iItemIndex;
	int iFileType; // 0标识日志，1标识录像
	CDevInfo* pDevInfo;
	char FileName[MAX_PATH];
	char SavePath[MAX_PATH];
}DLoadTask;

typedef enum __PLAYSPEED
{
	SPEED_NOMAL,
	SPEED_2X,
	SPEED_4X,
	SPEED_8X,
	SPEED_16X
}ENUM_PLAYSPEED;

// CRecordDlg 对话框

class CRecordDlg : public CDialog
{
	DECLARE_DYNAMIC(CRecordDlg)

public:
	CRecordDlg(CRect rcWnd, CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CRecordDlg();

// 对话框数据
	enum { IDD = IDD_DLG_RECORD };
	
	void EnableBotton(BOOL bEnable);
	void RestorePlayStatus();
	void GetPlayFile(CString &strFileName);
	void InvalidatePlayStatus(CString strFileName, int iPlayStatus);
	//void CloseMedia(CString strFileName);

private:
	int GetFile();
	int BeginDownLoad();
	int StopDownLoad();

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
	
private:
	CRect m_rcClient;
	CListCtrl m_ctlRecordList;
	virtual BOOL OnInitDialog();
	virtual BOOL PreTranslateMessage(MSG* pMsg);

	void ParseFileList(char *pXMLBuffer);
	int m_iFilePage;
	int m_iDevIndex;

	ENUM_PLAYSPEED m_eFastSpeed;
	ENUM_PLAYSPEED m_eSlowSpeed;
	int m_iPlayState; //播放状态 0:停止   1:播放    2:暂停

	afx_msg void OnBnClickedBtnQuery();
	afx_msg void OnBnClickedBtnDownload();
	afx_msg void OnBnClickedBtnPageup();
	afx_msg void OnBnClickedBtnPagedown();
	
	CString m_strSavePath;
	CString m_strFileDevIP; //当前列表中文件所属的设备IP
	BOOL m_bLogQuery;
	CStatic m_ctlDevIP;
	BOOL m_bDownLoad;
	CRITICAL_SECTION m_csList;
	HANDLE m_hHandel;
	unsigned int m_uiThreadID;
	DLoadTask m_hTask;

	

	static LONG __stdcall RecordDataCallBack(LONG lRealHandle,DWORD dwDataType,BYTE *pBuffer,DWORD dwBufSize,LPFRAME_EXTDATA  pExtData);
	static unsigned int __stdcall RecordProcessThread(void *pUser);
	static LONG __stdcall PlayActionEventCallBack(LONG lUser,LONG nType,LONG nFlag,char * pData,void * pUser);
public:
	BOOL SetLogQuery(BOOL bLogQuery);
	int	 OpenMedia(HWND hWnd, LPCTSTR strKey);
	long CloseMedia(LPCTSTR strKey);
	void SetSelIP(CString &strIP);
	static long CALLBACK OnPlayerEventRecv(long nPort,LONG nStateCode,char *pResponse,void *pUser);

	void UpdateUI();
	
public:
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	
	CList <DLoadTask> m_listDLTask;
public:
	CButton m_ctlBTNDownLoad;
	CButton m_ctlBTNPageUP;
	CButton m_ctlBTNPageDown;
public:
	afx_msg void OnNMDblclkListRecordlist(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedBtnAddlocfile();
public:
	CButton m_btnPause;
public:
	CButton m_btnFast;
public:
	CButton m_btnSlow;

public:
	afx_msg void OnBnClickedButtonPause();
public:
	afx_msg void OnBnClickedButtonFast();
public:
	afx_msg void OnBnClickedButtonSlow();
public:
	afx_msg void OnCbnSelchangeCombo1();
public:
	afx_msg void OnBnClickedButtonResumeSpeed();
public:
	CButton m_btnReSpeed;
};
