#pragma once

#include "..\\global\\Block.h"
#include <deque>
#include <Vfw.h>

#define CAMSTATUS_RUNNING		0x01
#define CAMSTATUS_STOPPED		0x02

class CImpBlockConfig;
class CImpBlockAutoTrigger;

class CImpBlock : public CBlock
{
private:

	// pratelske tridy
	friend class CImpBlockConfig;
	friend class CImpBlockAutoTrigger;
	// rozhrani
	CImpBlockConfig *m_pxConfig;
	CImpBlockAutoTrigger *m_pxAutoTrigger;

public:
	void* GetInterface(REFIID riid);
	static HRESULT CreateInstance(REFIID riid, void **ppv);

	CImpBlock();
	~CImpBlock();

	////////////////////////////////////////////////////////////////

	STDMETHODIMP InitInstance();
	STDMETHODIMP ExitInstance();
	STDMETHODIMP ProcessRev(const DWORD dwProcessId, REVDATAMAP &rRevDataMap);
	STDMETHODIMP ClearRevMap(REVDATAMAP &rRevDataMap);
	STDMETHODIMP ProcessData(const LPBLOCKDATA pInputData);
	STDMETHODIMP_(void) Serialize(CArchive &ar);

	////////////////////////////////////////////////////////////////

	HWND m_hWndC;

	DWORD m_dwRevSignalIdVideo;
	DWORD m_dwRevSignalIdAudio;
	INT m_nCameraIndex;
	std::deque<CString> m_dqDriverNames;
	LPVOID m_pBitmap;
	DWORD m_dwBitmapLen;
	LPVOID m_pRevDataBitmap;
	LPVOID m_pRevDataWave;
	HANDLE m_hEvent;
	HANDLE m_hEventQuit;
	DWORD m_dwStatus;
	BITMAPINFO m_bitmapInfo;

	CRITICAL_SECTION m_csCam;

	BOOL ConnectCamera(BOOL bDisconnect);
	BOOL SetDriverParams();

	static LRESULT CALLBACK fpProc(HWND hWnd, LPVIDEOHDR lpVHdr);
	static LRESULT CALLBACK fpStatus(HWND hWnd, int nID, LPCSTR lpsz);
	static LRESULT CALLBACK fpError(HWND hWnd, int nID, LPCSTR lpsz);
};