#include <windows.h>
#include <streams.h>
#include <initguid.h>
#if (1100 > _MSC_VER)
#include <olectlid.h>
#else
#include <olectl.h>
#endif
#include "FaceDTguid.h"
#include "FaceDT.h"
#include <math.h>
#include "tchar.h"
const int LENGTH = 7;
const int THETA = 4;
#include <opencv2/opencv.hpp>
#include "facedetect-dll.h"
#pragma comment(lib,"libfacedetect.lib")
#pragma comment(linker,"/nodefaultlib:LIBCMT.lib")
using namespace cv;
const AMOVIESETUP_MEDIATYPE sudPinTypes =
{
&MEDIATYPE_Video, // Major type
&MEDIASUBTYPE_NULL // Minor type
};
const AMOVIESETUP_PIN sudpPins[] =
{
{ L"Input", // Pins string name
FALSE, // Is it rendered
FALSE, // Is it an output
FALSE, // Are we allowed none
FALSE, // And allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes // Pin information
},
{ L"Output", // Pins string name
FALSE, // Is it rendered
TRUE, // Is it an output
FALSE, // Are we allowed none
FALSE, // And allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes // Pin information
}
};
const AMOVIESETUP_FILTER sudSlowMotionDT =
{
&CLSID_iTVSports_FaceDT, // Filter CLSID
L"iTVSports Face Detect", // String name
MERIT_DO_NOT_USE, // Filter merit
2, // Number of pins
sudpPins // Pin information
};
CFactoryTemplate g_Templates[] = {
{ L"iTVSports Face Detect"
, &CLSID_iTVSports_FaceDT
, CSlowMotionDT::CreateInstance
, NULL
, &sudSlowMotionDT }
};
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
////////////////////////////////////////////////////////////////////////
//
// Exported entry points for registration and unregistration
// (in this case they only call through to default implementations).
//
////////////////////////////////////////////////////////////////////////
// DllRegisterServer
// Handles sample registry and unregistry
//
STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2( TRUE );
} // DllRegisterServer
//
// DllUnregisterServer
//
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2( FALSE );
} // DllUnregisterServer
//
// DllEntryPoint
//
extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD dwReason,
LPVOID lpReserved)
{
return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved);
}
//constructor
CSlowMotionDT::CSlowMotionDT(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr):
CTransformFilter(tszName, punk, CLSID_iTVSports_FaceDT)
{
m_count=0;
prevData = NULL;
d = NULL;
}//constructor
CSlowMotionDT::~CSlowMotionDT()
{
if(prevData) delete prevData;
// if(d) delete d;
}
//CreateInstance
//Provide the way for COM to create a FieldSignDT object
CUnknown *CSlowMotionDT::CreateInstance(LPUNKNOWN punk, HRESULT *phr)
{
ASSERT(phr);
CSlowMotionDT *pNewObject = new CSlowMotionDT(NAME("Soccer Slow Motion Detect"),punk,phr);
if(pNewObject==NULL){
if(phr)
*phr=E_OUTOFMEMORY;
}
return pNewObject;
}//CreateInstance
//
// NonDelegatingQueryInterface
//
// Reveals IIPEffect and ISpecifyPropertyPages
//
STDMETHODIMP CSlowMotionDT::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
CheckPointer(ppv,E_POINTER);
// if (riid == IID_IIPEffect) {
// return GetInterface((IIPEffect *) this, ppv);
//
// } else if (riid == IID_ISpecifyPropertyPages) {
// return GetInterface((ISpecifyPropertyPages *) this, ppv);
//
// } else {
// return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
// }
return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
} // NonDelegatingQueryInterface
HRESULT CSlowMotionDT::Transform(IMediaSample *pIn, IMediaSample *pOut)
{
CheckPointer(pIn,E_POINTER);
CheckPointer(pOut,E_POINTER);
// Copy the properties across
HRESULT hr = Copy(pIn, pOut);
if (FAILED(hr)) {
return hr;
}
// Check to see if it is time to do the sample
CRefTime tStart, tStop ;
hr = pIn->GetTime((REFERENCE_TIME *) &tStart, (REFERENCE_TIME *) &tStop);
// if (tStart >= m_effectStartTime)
// {
// if (tStop <= (m_effectStartTime + m_effectTime))
// {
// return Transform(pOut);
// }
// }
return Transform(pOut);
// return NOERROR;
} // Transform
//
// Copy
//
// Make destination an identical copy of source
//
HRESULT CSlowMotionDT::Copy(IMediaSample *pSource, IMediaSample *pDest) const
{
CheckPointer(pSource,E_POINTER);
CheckPointer(pDest,E_POINTER);
// Copy the sample data
BYTE *pSourceBuffer, *pDestBuffer;
long lSourceSize = pSource->GetActualDataLength();
#ifdef DEBUG
long lDestSize = pDest->GetSize();
ASSERT(lDestSize >= lSourceSize);
#endif
pSource->GetPointer(&pSourceBuffer);
pDest->GetPointer(&pDestBuffer);
CopyMemory( (PVOID) pDestBuffer,(PVOID) pSourceBuffer,lSourceSize);
// Copy the sample times
REFERENCE_TIME TimeStart, TimeEnd;
if (NOERROR == pSource->GetTime(&TimeStart, &TimeEnd)) {
pDest->SetTime(&TimeStart, &TimeEnd);
}
LONGLONG MediaStart, MediaEnd;
if (pSource->GetMediaTime(&MediaStart,&MediaEnd) == NOERROR) {
pDest->SetMediaTime(&MediaStart,&MediaEnd);
}
// Copy the Sync point property
HRESULT hr = pSource->IsSyncPoint();
if (hr == S_OK) {
pDest->SetSyncPoint(TRUE);
}
else if (hr == S_FALSE) {
pDest->SetSyncPoint(FALSE);
}
else { // an unexpected error has occured...
return E_UNEXPECTED;
}
// Copy the media type
AM_MEDIA_TYPE *pMediaType;
pSource->GetMediaType(&pMediaType);
pDest->SetMediaType(pMediaType);
DeleteMediaType(pMediaType);
// Copy the preroll property
hr = pSource->IsPreroll();
if (hr == S_OK) {
pDest->SetPreroll(TRUE);
}
else if (hr == S_FALSE) {
pDest->SetPreroll(FALSE);
}
else { // an unexpected error has occured...
return E_UNEXPECTED;
}
// Copy the discontinuity property
hr = pSource->IsDiscontinuity();
if (hr == S_OK) {
pDest->SetDiscontinuity(TRUE);
}
else if (hr == S_FALSE) {
pDest->SetDiscontinuity(FALSE);
}
else { // an unexpected error has occured...
return E_UNEXPECTED;
}
// Copy the actual data length
long lDataLength = pSource->GetActualDataLength();
pDest->SetActualDataLength(lDataLength);
return NOERROR;
} // Copy
HRESULT CSlowMotionDT::Transform(IMediaSample *pMediaSample)
{
//BYTE *pData; // Pointer to the actual image buffer
long lDataLen; // Holds length of any given sample
unsigned int grey,grey2; // Used when applying greying effects
int iPixel; // Used to loop through the image pixels
int temp,x,y; // General loop counters for transforms
//RGBTRIPLE *prgb; // Holds a pointer to the current pixel
AM_MEDIA_TYPE* pType = &m_pInput->CurrentMediaType();
VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *) pType->pbFormat;
ASSERT(pvi);
CheckPointer(pMediaSample,E_POINTER);
pMediaSample->GetPointer(&pData);
lDataLen = pMediaSample->GetSize();
// Get the image properties from the BITMAPINFOHEADER