#include "stdafx.h"
#include "ImageCheck.h"
#include "CaiDX.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL g_bOneShot=FALSE;
BOOL g_bCutDone=FALSE;
DWORD g_dwGraphRegister=0;// For running object table
HWND g_hwnd=0;
// Structures
typedef struct _callbackinfo
{
double dblSampleTime;
long lBufferSize;
BYTE *pBuffer;
BITMAPINFOHEADER bih;
} CALLBACKINFO;
CALLBACKINFO cb={0};
// Note: this object is a SEMI-COM object, and can only be created statically.
// We use this little semi-com object to handle the sample-grab-callback,
// since the callback must provide a COM interface. We could have had an interface
// where you provided a function-call callback, but that's really messy, so we
// did it this way. You can put anything you want into this C++ object, even
// a pointer to a CDialog. Be aware of multi-thread issues though.
//
class CSampleGrabberCB : public ISampleGrabberCB
{
public:
// these will get set by the main thread below. We need to
// know this in order to write out the bmp
long lWidth;
long lHeight;
CCaiDX * pOwner;
BOOL bFileWritten;
CString m_strFilePath;
CRect m_rtROI;
CSampleGrabberCB( )
{
m_strFilePath = "";
pOwner = NULL;
bFileWritten = FALSE;
cb.pBuffer = NULL;
}
~CSampleGrabberCB( )
{
if (cb.pBuffer)
{
delete []cb.pBuffer;
cb.pBuffer = NULL;
}
}
// fake out any COM ref counting
//
STDMETHODIMP_(ULONG) AddRef() { return 2; }
STDMETHODIMP_(ULONG) Release() { return 1; }
// fake out any COM QI'ing
//
STDMETHODIMP QueryInterface(REFIID riid, void ** ppv)
{
if( riid == IID_ISampleGrabberCB || riid == IID_IUnknown )
{
*ppv = (void *) static_cast[I] ( this );
return NOERROR;
}
return E_NOINTERFACE;
}
// we don't implement this interface for this example
//
STDMETHODIMP SampleCB( double SampleTime, IMediaSample * pSample )
{
return 0;
}
// The sample grabber is calling us back on its deliver thread.
// This is NOT the main app thread!
//
//
!!!!! WARNING WARNING WARNING !!!!!
TDMETHODIMP BufferCB( double dblSampleTime, BYTE * pBuffer, long lBufferSize )
{
// this flag will get set to true in order to take a picture
//
if( !g_bOneShot )
return 0;
if (!pBuffer)
return E_POINTER;
if( cb.lBufferSize < lBufferSize )
{
delete [] cb.pBuffer;
cb.pBuffer = NULL;
cb.lBufferSize = 0;
}
|