Files
SimpleRemoter/client/CaptureVideo.h
2019-01-10 19:35:03 +08:00

187 lines
4.5 KiB
C++

// CaptureVideo.h: interface for the CCaptureVideo class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CAPTUREVIDEO_H__0984BB8E_6DCB_4A5C_8E03_1217AE6E409D__INCLUDED_)
#define AFX_CAPTUREVIDEO_H__0984BB8E_6DCB_4A5C_8E03_1217AE6E409D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <Objbase.h>
#include <uuids.h>
#include <strmif.h>
#include <CONTROL.H>
#include <ATLBASE.H>
#include <qedit.h>
#include <amvideo.h>
#include <DShow.h>
#pragma comment(lib,"Strmiids.lib")
enum{
CMD_CAN_COPY,
CMD_CAN_SEND
};
#ifndef SAFE_RELEASE
#define SAFE_RELEASE( x ) if ( NULL != x ){ x->Release(); x = NULL; }
#endif
class CSampleGrabberCB : public ISampleGrabberCB
{
public:
ULONG m_ulFullWidth;
ULONG m_ulFullHeight;
LPBITMAPINFO m_BitmapInfor_Full;
BYTE* m_BitmapData_Full;
BOOL bStact;
DWORD m_dwSize;
CSampleGrabberCB()
{
m_ulFullWidth = 0 ;
m_ulFullHeight = 0 ;
m_BitmapInfor_Full = NULL;
m_BitmapData_Full = NULL;
m_dwSize = 0;
bStact = CMD_CAN_COPY;
}
~CSampleGrabberCB()
{
if (m_BitmapInfor_Full!=NULL)
{
delete[] m_BitmapInfor_Full;
}
if (m_BitmapData_Full!=NULL)
{
delete[] m_BitmapData_Full;
}
m_ulFullWidth = 0 ;
m_ulFullHeight = 0 ;
}
LPBITMAPINFO GetBmpInfor() //
{
if (m_BitmapInfor_Full==NULL) //Í·ÐÅÏ¢
{
ConstructBI(24);
}
return m_BitmapInfor_Full;
}
LPBITMAPINFO ConstructBI(ULONG ulbiBitCount)
{
int ColorNum = ulbiBitCount <= 8 ? 1 << ulbiBitCount : 0;
ULONG ulBitmapLength = sizeof(BITMAPINFOHEADER) + (ColorNum * sizeof(RGBQUAD)); //BITMAPINFOHEADER +¡¡µ÷É«°åµÄ¸öÊý
m_BitmapInfor_Full = (BITMAPINFO *) new BYTE[ulBitmapLength];
BITMAPINFOHEADER* BitmapInforHeader = &(m_BitmapInfor_Full->bmiHeader);
BitmapInforHeader->biSize = sizeof(BITMAPINFOHEADER);//pi si
BitmapInforHeader->biWidth = m_ulFullWidth;
BitmapInforHeader->biHeight = m_ulFullHeight;
BitmapInforHeader->biPlanes = 1;
BitmapInforHeader->biBitCount = ulbiBitCount;
BitmapInforHeader->biCompression = BI_RGB;
BitmapInforHeader->biXPelsPerMeter = 0;
BitmapInforHeader->biYPelsPerMeter = 0;
BitmapInforHeader->biClrUsed = 0;
BitmapInforHeader->biClrImportant = 0;
BitmapInforHeader->biSizeImage = //ͼÏñÊý¾Ý
(((BitmapInforHeader->biWidth * BitmapInforHeader->biBitCount + 31) & ~31) >> 3)
* BitmapInforHeader->biHeight;
// 16λºÍÒÔºóµÄûÓÐÑÕÉ«±í£¬Ö±½Ó·µ»Ø
//!!
m_dwSize=BitmapInforHeader->biSizeImage; //Êý¾Ý´óС
m_BitmapData_Full=new BYTE[m_dwSize+10];
ZeroMemory(m_BitmapData_Full,m_dwSize+10);
return m_BitmapInfor_Full;
}
STDMETHODIMP_(ULONG) AddRef() { return 2;}
STDMETHODIMP_(ULONG) Release() { return 1;}
STDMETHODIMP QueryInterface(REFIID riid, void ** lParam)
{
//???
if( riid == IID_ISampleGrabberCB || riid == IID_IUnknown ){
*lParam = (void *) static_cast<ISampleGrabberCB*> ( this );
return NOERROR;
}
return E_NOINTERFACE;
}
BYTE* GetNextScreen(DWORD &dwSize)
{
dwSize=m_dwSize;
return (BYTE*)m_BitmapData_Full;
}
STDMETHODIMP SampleCB(double dbSampleTime, IMediaSample * Sample)
{
return 0;
}
//»Øµ÷º¯Êý ÔÚÕâÀïµÃµ½ bmp µÄÊý¾Ý
STDMETHODIMP BufferCB(double dblSampleTime, BYTE * szBuffer, long ulBufferSize)
{
if (!szBuffer)
{
return E_POINTER;
}
if (bStact==CMD_CAN_COPY) //δ³õʼ»¯ ·¢Ë͵Äͬ²îÒìµÄÒ»Ñù
{
//½«Í¼ÏñÊý¾Ý¿½±´µÄÎÒÃǵÄÄÚ´æ
memcpy(m_BitmapData_Full,szBuffer,ulBufferSize); //λͼ
InterlockedExchange((LPLONG)&bStact,CMD_CAN_SEND); //Ô­×Ó×ÔÔö¿ÉÒÔ·¢ËÍ
return S_OK;
}
return -1;
}
};
class CCaptureVideo
{
public:
CCaptureVideo();
virtual ~CCaptureVideo();
LPBITMAPINFO CCaptureVideo::GetBmpInfor();
HRESULT CCaptureVideo::InitCaptureGraphBuilder();
HRESULT CCaptureVideo::Open(int iDeviceID,int iPress);
BOOL CCaptureVideo::BindVideoFilter(int deviceId, IBaseFilter **pFilter);
LPBYTE CCaptureVideo::GetDIB(DWORD& dwSize);
HWND m_hWnd;
IGraphBuilder * m_pGB; //ͨ¹ý¸ÃÖµ¿ÉÒÔ·ÃÎÊ FCDO Filter Control Device Object
ICaptureGraphBuilder2* m_pCapture; //ͨ¹ý¸ÃÖµ¿ÉÒÔ·ÃÎÊ ÕæÊµCDO
IMediaControl* m_pMC; //¹ýÂËÉ豸µÄ½Ó¿Ú
IVideoWindow* m_pVW;
IBaseFilter* m_pBF; //FDO
ISampleGrabber* m_pGrabber; //Òý½Å 24Color
void CCaptureVideo::FreeMediaType(AM_MEDIA_TYPE& mt);
void CCaptureVideo::ResizeVideoWindow();
HRESULT CCaptureVideo::SetupVideoWindow();
void CCaptureVideo::SendEnd();
};
#endif // !defined(AFX_CAPTUREVIDEO_H__0984BB8E_6DCB_4A5C_8E03_1217AE6E409D__INCLUDED_)