2019-01-05 20:21:43 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include "IOCPServer.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <Vfw.h>
|
|
|
|
|
|
|
|
|
|
|
|
#pragma comment(lib,"Vfw32.lib")
|
|
|
|
|
|
|
2019-01-26 10:35:10 +08:00
|
|
|
|
/************************************************************************
|
|
|
|
|
|
* @class CBmpToAvi
|
|
|
|
|
|
* @brief λͼתAVI֡
|
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
class CBmpToAvi
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
CBmpToAvi();
|
|
|
|
|
|
virtual ~CBmpToAvi();
|
|
|
|
|
|
bool Open(LPCTSTR szFile, LPBITMAPINFO lpbmi);
|
|
|
|
|
|
bool Write(LPVOID lpBuffer);
|
|
|
|
|
|
void Close();
|
|
|
|
|
|
private:
|
|
|
|
|
|
PAVIFILE m_pfile;
|
|
|
|
|
|
PAVISTREAM m_pavi;
|
|
|
|
|
|
int m_nFrames;
|
|
|
|
|
|
static AVISTREAMINFO m_si; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ǿ<EFBFBD>̬<EFBFBD><CCAC>
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-01-05 20:21:43 +08:00
|
|
|
|
class CVideoCodec
|
|
|
|
|
|
{
|
|
|
|
|
|
COMPVARS m_cv;
|
|
|
|
|
|
HIC m_hIC;
|
|
|
|
|
|
BITMAPINFO* m_lpbmiInput;
|
|
|
|
|
|
BITMAPINFO m_bmiOutput;
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
bool InitCompressor(BITMAPINFO* lpbmi, DWORD fccHandler)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lpbmi == NULL)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
m_lpbmiInput = lpbmi;
|
|
|
|
|
|
|
|
|
|
|
|
ZeroMemory(&m_cv, sizeof(m_cv));
|
|
|
|
|
|
m_cv.cbSize = sizeof(m_cv);
|
|
|
|
|
|
m_cv.dwFlags = ICMF_COMPVARS_VALID;
|
|
|
|
|
|
m_cv.hic = m_hIC;
|
|
|
|
|
|
m_cv.fccType = ICTYPE_VIDEO;
|
|
|
|
|
|
m_cv.fccHandler = fccHandler;
|
|
|
|
|
|
m_cv.lpbiOut = NULL;
|
|
|
|
|
|
m_cv.lKey = 10;
|
|
|
|
|
|
m_cv.lDataRate = 6;
|
|
|
|
|
|
m_cv.lQ = ICQUALITY_HIGH;
|
|
|
|
|
|
|
|
|
|
|
|
m_hIC = ICOpen(ICTYPE_VIDEO, m_cv.fccHandler, ICMODE_COMPRESS | ICMODE_DECOMPRESS);
|
|
|
|
|
|
|
|
|
|
|
|
if (m_hIC == NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ICCompressGetFormat(m_hIC, m_lpbmiInput, &m_bmiOutput);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
|
|
|
|
|
|
ICSendMessage(m_hIC, 0x60c9, 0xf7329ace, 0xacdeaea2);
|
|
|
|
|
|
|
|
|
|
|
|
m_cv.hic = m_hIC;
|
|
|
|
|
|
m_cv.dwFlags = ICMF_COMPVARS_VALID;
|
|
|
|
|
|
|
|
|
|
|
|
if (!ICSeqCompressFrameStart(&m_cv, m_lpbmiInput))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ICDecompressBegin(m_hIC, &m_bmiOutput , m_lpbmiInput);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DecodeVideoData(BYTE *pin, int len, BYTE* pout, int *lenr,DWORD flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!pin || !pout ||!m_hIC)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (ICDecompress(m_hIC, flag, &m_bmiOutput.bmiHeader, pin, &m_lpbmiInput->bmiHeader, pout) != ICERR_OK)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (lenr) *lenr = m_lpbmiInput->bmiHeader.biSizeImage;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EncodeVideoData(BYTE* pin, int len, BYTE* pout, int* lenr, bool* pKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
BYTE *p;
|
|
|
|
|
|
long s = 1;
|
|
|
|
|
|
BOOL k = true;
|
|
|
|
|
|
if ( !pin || !pout || len != (int)m_lpbmiInput->bmiHeader.biSizeImage || !m_hIC)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
p = (BYTE*)ICSeqCompressFrame(&m_cv, 0, pin, &k, &s);
|
|
|
|
|
|
|
|
|
|
|
|
if (!p) return false;
|
|
|
|
|
|
if (lenr) *lenr = s;
|
|
|
|
|
|
if (pKey) *pKey = k;
|
|
|
|
|
|
|
|
|
|
|
|
CopyMemory(pout, p, s);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CVideoCodec()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_lpbmiInput = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~CVideoCodec()
|
|
|
|
|
|
{
|
|
|
|
|
|
// No init yet or init error
|
|
|
|
|
|
if (m_hIC == NULL)
|
|
|
|
|
|
return;
|
|
|
|
|
|
ICDecompressEnd(m_hIC);
|
|
|
|
|
|
ICSeqCompressFrameEnd(&m_cv);
|
|
|
|
|
|
ICCompressorFree(&m_cv);
|
|
|
|
|
|
ICClose(m_hIC);
|
|
|
|
|
|
}
|
|
|
|
|
|
int MyEnumCodecs(int *fccHandler, char *strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
static int i = 0;
|
|
|
|
|
|
int nRet = 1;
|
|
|
|
|
|
HIC hIC;
|
|
|
|
|
|
ICINFO icInfo;
|
|
|
|
|
|
|
|
|
|
|
|
if (fccHandler == NULL)
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(!ICInfo(ICTYPE_VIDEO, i, &icInfo))
|
|
|
|
|
|
{
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
hIC = ICOpen(icInfo.fccType, icInfo.fccHandler, ICMODE_QUERY);
|
|
|
|
|
|
|
|
|
|
|
|
if (hIC)
|
|
|
|
|
|
{
|
|
|
|
|
|
ICGetInfo(hIC, &icInfo, sizeof(icInfo));
|
|
|
|
|
|
*fccHandler = icInfo.fccHandler;
|
|
|
|
|
|
//<2F><><EFBFBD>ڵõ<DAB5><C3B5><EFBFBD>szDescription<6F><6E>UNICODE˫<45>ֽ<EFBFBD><D6BD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫת<D2AA><D7AA>ΪASCII<49><49>
|
|
|
|
|
|
if (strName != NULL)
|
|
|
|
|
|
wcstombs(strName, icInfo.szDescription, 256);
|
|
|
|
|
|
}
|
|
|
|
|
|
else nRet = -1;
|
|
|
|
|
|
|
|
|
|
|
|
ICClose(hIC);
|
|
|
|
|
|
i++;
|
|
|
|
|
|
return nRet;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CVideoDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
class CVideoDlg : public CDialog
|
|
|
|
|
|
{
|
|
|
|
|
|
DECLARE_DYNAMIC(CVideoDlg)
|
2019-01-26 14:05:37 +08:00
|
|
|
|
HICON m_hIcon;
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
CVideoDlg(CWnd* pParent = NULL, IOCPServer* IOCPServer = NULL, CONTEXT_OBJECT *ContextObject = NULL); // <20><><EFBFBD><D7BC><EFBFBD>캯<EFBFBD><ECBAAF>
|
|
|
|
|
|
virtual ~CVideoDlg();
|
|
|
|
|
|
CONTEXT_OBJECT* m_ContextObject;
|
|
|
|
|
|
IOCPServer* m_iocpServer;
|
|
|
|
|
|
CString m_strIPAddress;
|
|
|
|
|
|
|
|
|
|
|
|
LPBITMAPINFO m_BitmapInfor_Full;
|
|
|
|
|
|
BYTE* m_BitmapData_Full;
|
|
|
|
|
|
BYTE* m_BitmapCompressedData_Full;
|
2019-01-18 17:37:15 +08:00
|
|
|
|
void ResetScreen(void);
|
|
|
|
|
|
void OnReceiveComplete(void);
|
|
|
|
|
|
void DrawDIB(void);
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
2019-01-26 10:35:10 +08:00
|
|
|
|
void SaveAvi(void);
|
2019-01-18 17:37:15 +08:00
|
|
|
|
void InitCodec(DWORD fccHandler);
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
2019-01-26 10:35:10 +08:00
|
|
|
|
CString m_aviFile; // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>վ<EFBFBD>д<EFBFBD><D0B4>
|
|
|
|
|
|
CBmpToAvi m_aviStream;
|
|
|
|
|
|
|
|
|
|
|
|
int m_nCount;
|
2019-01-05 20:21:43 +08:00
|
|
|
|
HDC m_hDC;
|
|
|
|
|
|
HDRAWDIB m_hDD;
|
|
|
|
|
|
|
|
|
|
|
|
CVideoCodec *m_pVideoCodec; // <20><>Ƶѹ<C6B5><D1B9><EFBFBD><EFBFBD>
|
|
|
|
|
|
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
enum { IDD = IDD_DIALOG_VIDEO };
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧<><D6A7>
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE_MESSAGE_MAP()
|
|
|
|
|
|
public:
|
|
|
|
|
|
virtual BOOL OnInitDialog();
|
|
|
|
|
|
afx_msg void OnClose();
|
|
|
|
|
|
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
|
|
|
|
|
|
afx_msg void OnPaint();
|
|
|
|
|
|
};
|